mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
#7643: option to copy one db's 'structure' to the new DB when creating a new library.
This commit is contained in:
parent
b12e505f5c
commit
a932009832
@ -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)
|
||||
|
@ -49,11 +49,26 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="3">
|
||||
<widget class="QRadioButton" name="empty_library">
|
||||
<property name="text">
|
||||
<string>&Create an empty library at the new location</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="hbox1">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="empty_library">
|
||||
<property name="text">
|
||||
<string>&Create an empty library at the new location</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="copy_structure">
|
||||
<property name="text">
|
||||
<string>&Copy structure from the current library</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Copy the custom columns, saved searches, column widths, plugboards,
|
||||
user categories, and other information from the old to the new library</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="3">
|
||||
<widget class="QRadioButton" name="move_library">
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user