diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py
index 4a6ff9bb93..1c8ce880fe 100644
--- a/src/calibre/gui2/__init__.py
+++ b/src/calibre/gui2/__init__.py
@@ -110,6 +110,7 @@ defs['bd_overlay_cover_size'] = False
defs['tags_browser_category_icons'] = {}
defs['cover_browser_reflections'] = True
defs['extra_row_spacing'] = 0
+defs['many_libraries'] = False
del defs
# }}}
diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py
index d830970057..80dae2a917 100644
--- a/src/calibre/gui2/actions/choose_library.py
+++ b/src/calibre/gui2/actions/choose_library.py
@@ -16,6 +16,7 @@ from calibre import isbytestring, sanitize_file_name_unicode
from calibre.constants import (filesystem_encoding, iswindows,
get_portable_base)
from calibre.utils.config import prefs
+from calibre.utils.icu import sort_key
from calibre.gui2 import (gprefs, warning_dialog, Dispatcher, error_dialog,
question_dialog, info_dialog, open_local_file, choose_dir)
from calibre.library.database2 import LibraryDatabase2
@@ -46,7 +47,7 @@ class LibraryUsageStats(object): # {{{
locs = list(self.stats.keys())
locs.sort(cmp=lambda x, y: cmp(self.stats[x], self.stats[y]),
reverse=True)
- for key in locs[25:]:
+ for key in locs[(10000 if gprefs['many_libraries'] else 25):]:
self.stats.pop(key)
gprefs.set('library_usage_stats', self.stats)
@@ -72,8 +73,10 @@ class LibraryUsageStats(object): # {{{
locs = list(self.stats.keys())
if lpath in locs:
locs.remove(lpath)
- locs.sort(cmp=lambda x, y: cmp(self.stats[x], self.stats[y]),
- reverse=True)
+ if gprefs['many_libraries']:
+ locs.sort(key=sort_key)
+ else:
+ locs.sort(key=lambda x: self.stats[x], reverse=True)
for loc in locs:
yield self.pretty(loc), loc
diff --git a/src/calibre/gui2/preferences/behavior.py b/src/calibre/gui2/preferences/behavior.py
index b5070cbdea..caab2d8dd6 100644
--- a/src/calibre/gui2/preferences/behavior.py
+++ b/src/calibre/gui2/preferences/behavior.py
@@ -60,6 +60,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
signal.connect(self.internally_viewed_formats_changed)
r('bools_are_tristate', db.prefs, restart_required=True)
+ r('many_libraries', gprefs, restart_required=True)
r = self.register
choices = [(_('Default'), 'default'), (_('Compact Metadata'), 'alt1'),
(_('All on 1 tab'), 'alt2')]
diff --git a/src/calibre/gui2/preferences/behavior.ui b/src/calibre/gui2/preferences/behavior.ui
index ffd59d72bb..533ee96c4d 100644
--- a/src/calibre/gui2/preferences/behavior.ui
+++ b/src/calibre/gui2/preferences/behavior.ui
@@ -284,6 +284,18 @@ If not checked, the values can be Yes or No.
+ -
+
+
+ Optimizes the interface for use with a large number of libraries. calibre will
+now remeber unlimited numbers of libraries in its Quick Switch and Copy to Library
+menus, and the libraries will be sorted alphabetically.
+
+
+ Optimize for use with many &libraries (Requires restart)
+
+
+