diff --git a/src/calibre/gui2/dialogs/choose_library.py b/src/calibre/gui2/dialogs/choose_library.py
index 32d45c6043..033b038b65 100644
--- a/src/calibre/gui2/dialogs/choose_library.py
+++ b/src/calibre/gui2/dialogs/choose_library.py
@@ -32,6 +32,11 @@ class ChooseLibrary(QDialog, Ui_Dialog):
loc = unicode(self.old_location.text()).format(lp)
self.old_location.setText(loc)
self.browse_button.clicked.connect(self.choose_loc)
+ self.empty_library.toggled.connect(self.empty_library_toggled)
+ self.copy_structure.setEnabled(False)
+
+ def empty_library_toggled(self, to_what):
+ self.copy_structure.setEnabled(to_what)
def choose_loc(self, *args):
loc = choose_dir(self, 'choose library location',
@@ -64,7 +69,7 @@ class ChooseLibrary(QDialog, Ui_Dialog):
def perform_action(self, ac, loc):
if ac in ('new', 'existing'):
prefs['library_path'] = loc
- self.callback(loc)
+ self.callback(loc, copy_structure=self.copy_structure.isChecked())
else:
move_library(self.db.library_path, loc, self.parent(),
self.callback)
diff --git a/src/calibre/gui2/dialogs/choose_library.ui b/src/calibre/gui2/dialogs/choose_library.ui
index 6cf1b4386c..c281ecc0f4 100644
--- a/src/calibre/gui2/dialogs/choose_library.ui
+++ b/src/calibre/gui2/dialogs/choose_library.ui
@@ -49,11 +49,26 @@
-
-
-
- &Create an empty library at the new location
-
-
+
+
-
+
+
+ &Create an empty library at the new location
+
+
+
+ -
+
+
+ &Copy structure from the current library
+
+
+ Copy the custom columns, saved searches, column widths, plugboards,
+user categories, and other information from the old to the new library
+
+
+
+
-
diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py
index dd3925e732..f97589e466 100644
--- a/src/calibre/gui2/ui.py
+++ b/src/calibre/gui2/ui.py
@@ -378,13 +378,16 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
def booklists(self):
return self.memory_view.model().db, self.card_a_view.model().db, self.card_b_view.model().db
- def library_moved(self, newloc):
+ def library_moved(self, newloc, copy_structure=False):
if newloc is None: return
+ default_prefs = None
try:
olddb = self.library_view.model().db
+ if copy_structure:
+ default_prefs = olddb.prefs
except:
olddb = None
- db = LibraryDatabase2(newloc)
+ db = LibraryDatabase2(newloc, default_prefs=default_prefs)
if self.content_server is not None:
self.content_server.set_database(db)
self.library_path = newloc
diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py
index b9ab54b80a..27266f2f9a 100644
--- a/src/calibre/library/database2.py
+++ b/src/calibre/library/database2.py
@@ -113,7 +113,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
def exists_at(cls, path):
return path and os.path.exists(os.path.join(path, 'metadata.db'))
- def __init__(self, library_path, row_factory=False):
+ def __init__(self, library_path, row_factory=False, default_prefs=None):
self.field_metadata = FieldMetadata()
self.dirtied_queue = Queue()
if not os.path.exists(library_path):
@@ -127,10 +127,29 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if isinstance(self.dbpath, unicode) and not iswindows:
self.dbpath = self.dbpath.encode(filesystem_encoding)
+ apply_default_prefs = not os.path.exists(self.dbpath)
self.connect()
+
self.is_case_sensitive = not iswindows and not isosx and \
not os.path.exists(self.dbpath.replace('metadata.db', 'MeTAdAtA.dB'))
SchemaUpgrade.__init__(self)
+
+ # if we are to copy the prefs and structure from some other DB, then
+ # we need to do it before we call initialize_dynamic
+ if apply_default_prefs and default_prefs is not None:
+ prefs = DBPrefs(self)
+ for key in default_prefs:
+ # be sure that prefs not to be copied are listed below
+ if key in ['news_to_be_synced']:
+ continue
+ try:
+ prefs[key] = default_prefs[key]
+ except:
+ pass # ignore options that don't exist anymore
+ fmvals = [f for f in default_prefs['field_metadata'].values() if f['is_custom']]
+ for f in fmvals:
+ self.create_custom_column(f['label'], f['name'], f['datatype'],
+ f['is_multiple'] is not None, f['is_editable'], f['display'])
self.initialize_dynamic()
def get_property(self, idx, index_is_id=False, loc=-1):