From 9805054fa1cf22f95d95d6d03315ca5df86111fe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 14 Aug 2010 23:13:20 -0600 Subject: [PATCH] Remove entry from list of known libraries when quick switching, if no library found --- src/calibre/gui2/actions/choose_library.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index bc22c93c27..713136029d 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -13,7 +13,7 @@ from PyQt4.Qt import QMenu from calibre import isbytestring from calibre.constants import filesystem_encoding from calibre.utils.config import prefs -from calibre.gui2 import gprefs +from calibre.gui2 import gprefs, warning_dialog from calibre.gui2.actions import InterfaceAction class LibraryUsageStats(object): @@ -34,6 +34,10 @@ class LibraryUsageStats(object): self.stats.pop(key) gprefs.set('library_usage_stats', self.stats) + def remove(self, location): + self.stats.pop(location, None) + self.write_stats() + def canonicalize_path(self, lpath): if isbytestring(lpath): lpath = lpath.decode(filesystem_encoding) @@ -123,6 +127,16 @@ class ChooseLibraryAction(InterfaceAction): def switch_requested(self, location): loc = location.replace('/', os.sep) + exists = self.gui.library_view.model().db.exists_at(loc) + if not exists: + warning_dialog(self.gui, _('No library found'), + _('No existing calibre library was found at %s.' + ' It will be removed from the list of known ' + ' libraries.')%loc, show=True) + self.stats.remove(location) + self.build_menus() + return + prefs['library_path'] = loc self.gui.library_moved(loc)