diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py
index 6791c4b015..bc79a3c9de 100644
--- a/src/calibre/gui2/device.py
+++ b/src/calibre/gui2/device.py
@@ -626,10 +626,10 @@ class DeviceMixin(object): # {{{
self.default_thumbnail = (pixmap.width(), pixmap.height(),
pixmap_to_data(pixmap))
- def connect_to_folder_named(self, dir):
- if os.path.isdir(dir):
- kls = FOLDER_DEVICE
- self.device_manager.mount_device(kls=kls, kind='folder', path=dir)
+ def connect_to_folder_named(self, folder):
+ if os.path.exists(folder) and os.path.isdir(folder):
+ self.device_manager.mount_device(kls=FOLDER_DEVICE, kind='folder',
+ path=folder)
def connect_to_folder(self):
dir = choose_dir(self, 'Select Device Folder',
diff --git a/src/calibre/gui2/dialogs/config/__init__.py b/src/calibre/gui2/dialogs/config/__init__.py
index 2caaabc2cc..f183d0871b 100644
--- a/src/calibre/gui2/dialogs/config/__init__.py
+++ b/src/calibre/gui2/dialogs/config/__init__.py
@@ -448,7 +448,6 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
self.password.setText(opts.password if opts.password else '')
self.opt_max_opds_items.setValue(opts.max_opds_items)
self.opt_max_opds_ungrouped_items.setValue(opts.max_opds_ungrouped_items)
- self.opt_cs_restriction.setText(self.db.prefs.get('cs_restriction', ''))
self.auto_launch.setChecked(config['autolaunch_server'])
self.systray_icon.setChecked(config['systray_icon'])
self.sync_news.setChecked(config['upload_news_to_device'])
@@ -498,9 +497,11 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
restrictions = sorted(saved_searches().names(),
cmp=lambda x,y: cmp(x.lower(), y.lower()))
restrictions.insert(0, '')
- self.opt_gui_restriction.addItems(restrictions)
- idx = self.opt_gui_restriction.findText(self.db.prefs.get('gui_restriction', ''))
- self.opt_gui_restriction.setCurrentIndex(0 if idx < 0 else idx)
+ for x in ('gui', 'cs'):
+ w = getattr(self, 'opt_%s_restriction'%x)
+ w.addItems(restrictions)
+ idx = w.findText(self.db.prefs.get(x+'_restriction', ''))
+ w.setCurrentIndex(0 if idx < 0 else idx)
self.opt_disable_animations.setChecked(config['disable_animations'])
self.opt_show_donate_button.setChecked(config['show_donate_button'])
idx = 0
@@ -914,7 +915,6 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
sc.set('max_opds_items', self.opt_max_opds_items.value())
sc.set('max_opds_ungrouped_items',
self.opt_max_opds_ungrouped_items.value())
- self.db.prefs.set('cs_restriction', unicode(self.opt_cs_restriction.text()))
config['delete_news_from_library_on_upload'] = self.delete_news.isChecked()
config['upload_news_to_device'] = self.sync_news.isChecked()
config['search_as_you_type'] = self.search_as_you_type.isChecked()
@@ -936,7 +936,9 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
config['internally_viewed_formats'] = fmts
val = self.opt_gui_layout.itemData(self.opt_gui_layout.currentIndex()).toString()
config['gui_layout'] = unicode(val)
- self.db.prefs.set('gui_restriction', unicode(self.opt_gui_restriction.currentText()))
+ for x in ('gui', 'cs'):
+ w = getattr(self, 'opt_%s_restriction'%x)
+ self.db.prefs.set(x+'_restriction', unicode(w.currentText()))
if must_restart:
warning_dialog(self, _('Must restart'),
diff --git a/src/calibre/gui2/dialogs/config/config.ui b/src/calibre/gui2/dialogs/config/config.ui
index 3c5c109e04..79917760ab 100644
--- a/src/calibre/gui2/dialogs/config/config.ui
+++ b/src/calibre/gui2/dialogs/config/config.ui
@@ -7,7 +7,7 @@
0
0
- 1000
+ 1001
730
@@ -89,8 +89,8 @@
0
0
- 720
- 679
+ 725
+ 683
@@ -573,7 +573,7 @@
-
- Restriction to apply when the current library is opened (startup or change library):
+ Restriction to apply when the current library is opened:
opt_gui_restriction
@@ -588,6 +588,15 @@
16777215
+
+ Apply this restriction on calibre startup if the current library is being used. Also applied when switching to this library. Note that this setting is per library.
+
+
+ QComboBox::AdjustToMinimumContentsLengthWithIcon
+
+
+ 20
+
-
@@ -1060,23 +1069,23 @@
- -
-
-
- Provides a restriction to be used by the content server
-
-
-
-
-
-
-
Restriction (saved search) to apply:
-
- opt_cs_restriction
+
+
+ -
+
+
+ This restriction (based on a saved search) will restrict the books the content server makes available to those matching the search. This setting is per library (i.e. you can have a different restriction per library).
+
+
+ QComboBox::AdjustToMinimumContentsLengthWithIcon
+
+
+ 20
diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py
index ad1cd5b13a..7f808b008c 100644
--- a/src/calibre/library/server/base.py
+++ b/src/calibre/library/server/base.py
@@ -95,9 +95,9 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache):
'tools.digest_auth.users' : {opts.username.strip():opts.password.strip()},
}
- self.set_search_restriction(db.prefs.get('cs_restriction', ''))
- if opts.restriction is not None:
- self.set_search_restriction(opts.restriction)
+ sr = db.prefs.get('cs_restriction', '') if opts.restriction is None \
+ else opts.restriction
+ self.set_search_restriction(sr)
self.is_running = False
self.exception = None
diff --git a/src/calibre/library/server/main.py b/src/calibre/library/server/main.py
index e87d2d75d7..54dd205b35 100644
--- a/src/calibre/library/server/main.py
+++ b/src/calibre/library/server/main.py
@@ -34,7 +34,8 @@ def option_parser():
help='Run process in background as a daemon. No effect on windows.')
parser.add_option('--restriction', default=None,
help=_('Specifies a restriction to be used for this invocation. '
- 'This option overrides the default set in the GUI'))
+ 'This option overrides any per-library settings specified'
+ ' in the GUI'))
return parser
def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
diff --git a/src/calibre/library/server/mobile.py b/src/calibre/library/server/mobile.py
index 8ea9a04515..aa7a740972 100644
--- a/src/calibre/library/server/mobile.py
+++ b/src/calibre/library/server/mobile.py
@@ -181,7 +181,9 @@ class MobileServer(object):
num = int(num)
except ValueError:
raise cherrypy.HTTPError(400, 'num: %s is not an integer'%num)
- ids = self.db.search_getting_ids(search, self.search_restriction)
+ if not search:
+ search = ''
+ ids = self.db.search_getting_ids(search.strip(), self.search_restriction)
FM = self.db.FIELD_MAP
items = [r for r in iter(self.db) if r[FM['id']] in ids]
if sort is not None:
diff --git a/src/calibre/library/server/xml.py b/src/calibre/library/server/xml.py
index 18370ab641..9db786953e 100644
--- a/src/calibre/library/server/xml.py
+++ b/src/calibre/library/server/xml.py
@@ -45,7 +45,10 @@ class XMLServer(object):
order = order.lower().strip() == 'ascending'
- ids = self.db.search_getting_ids(search, self.search_restriction)
+ if not search:
+ search = ''
+
+ ids = self.db.search_getting_ids(search.strip(), self.search_restriction)
FM = self.db.FIELD_MAP