mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Show progress when moving library to a new location
This commit is contained in:
parent
f277f2b870
commit
1961b39387
@ -147,6 +147,13 @@ def fix_opf(opf, orig_file, files, anchor_map):
|
||||
ids = []
|
||||
for f in files:
|
||||
ids.append(opf.manifest.add_item(f))
|
||||
index = None
|
||||
for i, item in enumerate(opf.spine):
|
||||
if item.id == orig.id:
|
||||
index = i
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
def split(pathtoopf, opts):
|
||||
|
@ -142,6 +142,9 @@ class ResourceCollection(object):
|
||||
def remove(self, resource):
|
||||
self._resources.remove(resource)
|
||||
|
||||
def replace(self, start, end, items):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def from_directory_contents(top, topdown=True):
|
||||
collection = ResourceCollection()
|
||||
|
@ -1158,10 +1158,16 @@ class Main(MainWindow, Ui_MainWindow):
|
||||
newloc = d.database_location
|
||||
if not os.path.exists(os.path.join(newloc, 'metadata.db')):
|
||||
if os.access(self.library_path, os.R_OK):
|
||||
from PyQt4.QtGui import QProgressDialog
|
||||
pd = QProgressDialog('', '', 0, 100, self)
|
||||
pd.setWindowModality(Qt.ApplicationModal)
|
||||
pd.setCancelButton(None)
|
||||
pd.setWindowTitle(_('Copying database'))
|
||||
pd.show()
|
||||
self.status_bar.showMessage(_('Copying library to ')+newloc)
|
||||
self.setCursor(Qt.BusyCursor)
|
||||
self.library_view.setEnabled(False)
|
||||
self.library_view.model().db.move_library_to(newloc)
|
||||
self.library_view.model().db.move_library_to(newloc, pd)
|
||||
else:
|
||||
try:
|
||||
db = LibraryDatabase2(newloc)
|
||||
|
@ -908,11 +908,21 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
self.data.books_added([id], self.conn)
|
||||
self.notify('add', [id])
|
||||
|
||||
def move_library_to(self, newloc):
|
||||
def move_library_to(self, newloc, progress=None):
|
||||
header = _(u'<p>Copying books to %s<br><center>')%newloc
|
||||
books = self.conn.execute('SELECT id, path, title FROM books').fetchall()
|
||||
if progress is not None:
|
||||
progress.setValue(0)
|
||||
progress.setLabelText(header)
|
||||
QCoreApplication.processEvents()
|
||||
progress.setAutoReset(False)
|
||||
progress.setRange(0, len(books))
|
||||
if not os.path.exists(newloc):
|
||||
os.makedirs(newloc)
|
||||
old_dirs = set([])
|
||||
for book in self.conn.execute('SELECT id, path FROM books').fetchall():
|
||||
for i, book in enumerate(books):
|
||||
if progress is not None:
|
||||
progress.setLabelText(header+_(u'Copying <b>%s</b>')%book[2])
|
||||
path = book[1]
|
||||
if not path:
|
||||
continue
|
||||
@ -921,8 +931,11 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
tdir = os.path.join(newloc, dir)
|
||||
if os.path.exists(tdir):
|
||||
shutil.rmtree(tdir)
|
||||
if os.path.exists(srcdir):
|
||||
shutil.copytree(srcdir, tdir)
|
||||
old_dirs.add(srcdir)
|
||||
if progress is not None:
|
||||
progress.setValue(i+1)
|
||||
|
||||
dbpath = os.path.join(newloc, os.path.basename(self.dbpath))
|
||||
shutil.copyfile(self.dbpath, dbpath)
|
||||
@ -936,6 +949,9 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
shutil.rmtree(dir)
|
||||
except:
|
||||
pass
|
||||
if progress is not None:
|
||||
progress.reset()
|
||||
progress.hide()
|
||||
|
||||
|
||||
def migrate_old(self, db, progress):
|
||||
|
Loading…
x
Reference in New Issue
Block a user