diff --git a/src/calibre/ebooks/epub/split.py b/src/calibre/ebooks/epub/split.py index da8d6487f4..135ae626b9 100644 --- a/src/calibre/ebooks/epub/split.py +++ b/src/calibre/ebooks/epub/split.py @@ -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): diff --git a/src/calibre/ebooks/metadata/__init__.py b/src/calibre/ebooks/metadata/__init__.py index 33fea3b3ab..4460fea4a0 100644 --- a/src/calibre/ebooks/metadata/__init__.py +++ b/src/calibre/ebooks/metadata/__init__.py @@ -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() diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 191969023b..0811e10e18 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -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) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 3e040988de..f11835845f 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -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'

Copying books to %s

')%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 %s')%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) - shutil.copytree(srcdir, 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):