1) add restriction on startup to GUI

2) fix sorting problem in restriction combobx
This commit is contained in:
Charles Haley 2010-08-18 10:11:11 +01:00
parent d3e2c90a23
commit fa17a92c2c
4 changed files with 48 additions and 19 deletions

View File

@ -36,6 +36,7 @@ from calibre.gui2.convert.structure_detection import StructureDetectionWidget
from calibre.ebooks.conversion.plumber import Plumber from calibre.ebooks.conversion.plumber import Plumber
from calibre.utils.logging import Log from calibre.utils.logging import Log
from calibre.gui2.convert.toc import TOCWidget from calibre.gui2.convert.toc import TOCWidget
from calibre.utils.search_query_parser import saved_searches
class ConfigTabs(QTabWidget): class ConfigTabs(QTabWidget):
@ -447,7 +448,7 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
self.password.setText(opts.password if opts.password else '') self.password.setText(opts.password if opts.password else '')
self.opt_max_opds_items.setValue(opts.max_opds_items) self.opt_max_opds_items.setValue(opts.max_opds_items)
self.opt_max_opds_ungrouped_items.setValue(opts.max_opds_ungrouped_items) self.opt_max_opds_ungrouped_items.setValue(opts.max_opds_ungrouped_items)
self.opt_restriction.setText(self.db.prefs.get('cs_restriction', '')) self.opt_cs_restriction.setText(self.db.prefs.get('cs_restriction', ''))
self.auto_launch.setChecked(config['autolaunch_server']) self.auto_launch.setChecked(config['autolaunch_server'])
self.systray_icon.setChecked(config['systray_icon']) self.systray_icon.setChecked(config['systray_icon'])
self.sync_news.setChecked(config['upload_news_to_device']) self.sync_news.setChecked(config['upload_news_to_device'])
@ -494,6 +495,12 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
if x == config['gui_layout']: if x == config['gui_layout']:
li = i li = i
self.opt_gui_layout.setCurrentIndex(li) self.opt_gui_layout.setCurrentIndex(li)
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)
self.opt_disable_animations.setChecked(config['disable_animations']) self.opt_disable_animations.setChecked(config['disable_animations'])
self.opt_show_donate_button.setChecked(config['show_donate_button']) self.opt_show_donate_button.setChecked(config['show_donate_button'])
idx = 0 idx = 0
@ -907,7 +914,7 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
sc.set('max_opds_items', self.opt_max_opds_items.value()) sc.set('max_opds_items', self.opt_max_opds_items.value())
sc.set('max_opds_ungrouped_items', sc.set('max_opds_ungrouped_items',
self.opt_max_opds_ungrouped_items.value()) self.opt_max_opds_ungrouped_items.value())
self.db.prefs.set('cs_restriction', unicode(self.opt_restriction.text())) self.db.prefs.set('cs_restriction', unicode(self.opt_cs_restriction.text()))
config['delete_news_from_library_on_upload'] = self.delete_news.isChecked() config['delete_news_from_library_on_upload'] = self.delete_news.isChecked()
config['upload_news_to_device'] = self.sync_news.isChecked() config['upload_news_to_device'] = self.sync_news.isChecked()
config['search_as_you_type'] = self.search_as_you_type.isChecked() config['search_as_you_type'] = self.search_as_you_type.isChecked()
@ -929,6 +936,7 @@ class ConfigDialog(ResizableDialog, Ui_Dialog):
config['internally_viewed_formats'] = fmts config['internally_viewed_formats'] = fmts
val = self.opt_gui_layout.itemData(self.opt_gui_layout.currentIndex()).toString() val = self.opt_gui_layout.itemData(self.opt_gui_layout.currentIndex()).toString()
config['gui_layout'] = unicode(val) config['gui_layout'] = unicode(val)
self.db.prefs.set('gui_restriction', unicode(self.opt_gui_restriction.currentText()))
if must_restart: if must_restart:
warning_dialog(self, _('Must restart'), warning_dialog(self, _('Must restart'),

View File

@ -295,7 +295,7 @@
</widget> </widget>
<widget class="QWidget" name="page"> <widget class="QWidget" name="page">
<layout class="QGridLayout" name="gridLayout_8"> <layout class="QGridLayout" name="gridLayout_8">
<item row="1" column="0"> <item row="2" column="0">
<widget class="QCheckBox" name="roman_numerals"> <widget class="QCheckBox" name="roman_numerals">
<property name="text"> <property name="text">
<string>Use &amp;Roman numerals for series number</string> <string>Use &amp;Roman numerals for series number</string>
@ -305,35 +305,35 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="3" column="0">
<widget class="QCheckBox" name="systray_icon"> <widget class="QCheckBox" name="systray_icon">
<property name="text"> <property name="text">
<string>Enable system &amp;tray icon (needs restart)</string> <string>Enable system &amp;tray icon (needs restart)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="3" column="1">
<widget class="QCheckBox" name="systray_notifications"> <widget class="QCheckBox" name="systray_notifications">
<property name="text"> <property name="text">
<string>Show &amp;notifications in system tray</string> <string>Show &amp;notifications in system tray</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="4" column="0">
<widget class="QCheckBox" name="show_splash_screen"> <widget class="QCheckBox" name="show_splash_screen">
<property name="text"> <property name="text">
<string>Show &amp;splash screen at startup</string> <string>Show &amp;splash screen at startup</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="2"> <item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="separate_cover_flow"> <widget class="QCheckBox" name="separate_cover_flow">
<property name="text"> <property name="text">
<string>Show cover &amp;browser in a separate window (needs restart)</string> <string>Show cover &amp;browser in a separate window (needs restart)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="show_avg_rating"> <widget class="QCheckBox" name="show_avg_rating">
<property name="text"> <property name="text">
<string>Show &amp;average ratings in the tags browser</string> <string>Show &amp;average ratings in the tags browser</string>
@ -343,7 +343,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="7" column="0">
<widget class="QCheckBox" name="search_as_you_type"> <widget class="QCheckBox" name="search_as_you_type">
<property name="text"> <property name="text">
<string>Search as you type</string> <string>Search as you type</string>
@ -353,21 +353,21 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0" colspan="2"> <item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="sync_news"> <widget class="QCheckBox" name="sync_news">
<property name="text"> <property name="text">
<string>Automatically send downloaded &amp;news to ebook reader</string> <string>Automatically send downloaded &amp;news to ebook reader</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="0" colspan="2"> <item row="10" column="0" colspan="2">
<widget class="QCheckBox" name="delete_news"> <widget class="QCheckBox" name="delete_news">
<property name="text"> <property name="text">
<string>&amp;Delete news from library when it is automatically sent to reader</string> <string>&amp;Delete news from library when it is automatically sent to reader</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="0" colspan="2"> <item row="11" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
@ -384,7 +384,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="11" column="0" colspan="2"> <item row="12" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
@ -570,7 +570,27 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="label_170">
<property name="text">
<string>Restriction to apply when the current library is opened (startup or change library):</string>
</property>
<property name="buddy">
<cstring>opt_gui_restriction</cstring>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="opt_gui_restriction">
<property name="maximumSize">
<size>
<width>250</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="opt_disable_animations"> <widget class="QCheckBox" name="opt_disable_animations">
<property name="toolTip"> <property name="toolTip">
<string>Disable all animations. Useful if you have a slow/old computer.</string> <string>Disable all animations. Useful if you have a slow/old computer.</string>
@ -580,14 +600,14 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="4" column="1">
<widget class="QCheckBox" name="opt_show_donate_button"> <widget class="QCheckBox" name="opt_show_donate_button">
<property name="text"> <property name="text">
<string>Show &amp;donate button (restart)</string> <string>Show &amp;donate button (restart)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0" colspan="2"> <item row="8" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>&amp;Toolbar</string> <string>&amp;Toolbar</string>
@ -1041,7 +1061,7 @@
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="7" column="1">
<widget class="QLineEdit" name="opt_restriction"> <widget class="QLineEdit" name="opt_cs_restriction">
<property name="toolTip"> <property name="toolTip">
<string>Provides a restriction to be used by the content server</string> <string>Provides a restriction to be used by the content server</string>
</property> </property>
@ -1056,7 +1076,7 @@
<string>Restriction (saved search) to apply:</string> <string>Restriction (saved search) to apply:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>opt_restriction</cstring> <cstring>opt_cs_restriction</cstring>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -402,8 +402,7 @@ class SavedSearchBoxMixin(object):
b.setStatusTip(b.toolTip()) b.setStatusTip(b.toolTip())
def saved_searches_changed(self): def saved_searches_changed(self):
p = saved_searches().names() p = sorted(saved_searches().names(), cmp=lambda x,y: cmp(x.lower(), y.lower()))
p.sort()
t = unicode(self.search_restriction.currentText()) t = unicode(self.search_restriction.currentText())
self.search_restriction.clear() # rebuild the restrictions combobox using current saved searches self.search_restriction.clear() # rebuild the restrictions combobox using current saved searches
self.search_restriction.addItem('') self.search_restriction.addItem('')

View File

@ -230,6 +230,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
######################### Search Restriction ########################## ######################### Search Restriction ##########################
SearchRestrictionMixin.__init__(self) SearchRestrictionMixin.__init__(self)
self.apply_named_search_restriction(db.prefs.get('gui_restriction', ''))
########################### Cover Flow ################################ ########################### Cover Flow ################################
@ -373,6 +374,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
self.set_window_title() self.set_window_title()
self.apply_named_search_restriction('') # reset restriction to null self.apply_named_search_restriction('') # reset restriction to null
self.saved_searches_changed() # reload the search restrictions combo box self.saved_searches_changed() # reload the search restrictions combo box
self.apply_named_search_restriction(db.prefs.get('gui_restriction', ''))
def set_window_title(self): def set_window_title(self):
self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name()) self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name())