diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index d7c05a7807..8175e6cbac 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -685,7 +685,16 @@ class LookAndFeel(PreferencesPlugin): name_order = 1 config_widget = 'calibre.gui2.preferences.look_feel' -plugins += [LookAndFeel] +class Behavior(PreferencesPlugin): + name = 'Behavior' + gui_name = _('Behavior') + category = 'Interface' + gui_category = _('Interface') + category_order = 1 + name_order = 2 + config_widget = 'calibre.gui2.preferences.behavior' + +plugins += [LookAndFeel, Behavior] #}}} diff --git a/src/calibre/gui2/preferences/__init__.py b/src/calibre/gui2/preferences/__init__.py index fa4c2da328..7629d9c710 100644 --- a/src/calibre/gui2/preferences/__init__.py +++ b/src/calibre/gui2/preferences/__init__.py @@ -117,6 +117,21 @@ class Setting(object): val = unicode(self.gui_obj.itemData(idx).toString()) return val +class CommaSeparatedList(Setting): + + def set_gui_val(self, val): + x = '' + if val: + x = u', '.join(val) + self.gui_obj.setText(x) + + def get_gui_val(self): + val = unicode(self.gui_obj.text()).strip() + ans = [] + if val: + ans = [x.strip() for x in val.split(',')] + ans = [x for x in ans if x] + return ans class ConfigWidgetBase(QWidget, ConfigWidgetInterface): diff --git a/src/calibre/gui2/preferences/behavior.py b/src/calibre/gui2/preferences/behavior.py new file mode 100644 index 0000000000..17b3927422 --- /dev/null +++ b/src/calibre/gui2/preferences/behavior.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai + +__license__ = 'GPL v3' +__copyright__ = '2010, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + + +from calibre.gui2.preferences import ConfigWidgetBase, test_widget, \ + CommaSeparatedList +from calibre.gui2.preferences.behavior_ui import Ui_Form +from calibre.gui2 import config, info_dialog, dynamic +from calibre.utils.config import prefs +from calibre.customize.ui import available_output_formats +from calibre.utils.search_query_parser import saved_searches + +class ConfigWidget(ConfigWidgetBase, Ui_Form): + + def genesis(self, gui): + self.gui = gui + db = gui.library_view.model().db + + r = self.register + + r('worker_process_priority', prefs, choices= + [(_('Low'), 'low'), (_('Normal'), 'normal'), (_('High'), 'high')]) + + r('network_timeout', prefs) + + + r('overwrite_author_title_metadata', config) + r('get_social_metadata', config) + r('new_version_notification', config) + r('upload_news_to_device', config) + r('delete_news_from_library_on_upload', config) + + output_formats = list(sorted(available_output_formats())) + output_formats.remove('oeb') + choices = [(x.upper(), x) for x in output_formats] + r('output_format', prefs, choices=choices) + + restrictions = sorted(saved_searches().names(), + cmp=lambda x,y: cmp(x.lower(), y.lower())) + choices = [('', '')] + [(x, x) for x in restrictions] + r('gui_restriction', db.prefs, choices=choices) + r('new_book_tags', prefs, setting=CommaSeparatedList) + self.reset_confirmation_button.clicked.connect(self.reset_confirmation_dialogs) + + def reset_confirmation_dialogs(self, *args): + for key in dynamic.keys(): + if key.endswith('_again') and dynamic[key] is False: + dynamic[key] = True + info_dialog(self, _('Done'), + _('Confirmation dialogs have all been reset'), show=True) + +if __name__ == '__main__': + from PyQt4.Qt import QApplication + app = QApplication([]) + test_widget('Interface', 'Behavior') + diff --git a/src/calibre/gui2/preferences/behavior.ui b/src/calibre/gui2/preferences/behavior.ui index c6c07a1220..bc44391238 100644 --- a/src/calibre/gui2/preferences/behavior.ui +++ b/src/calibre/gui2/preferences/behavior.ui @@ -29,21 +29,21 @@ - + Show notification when &new version is available - + Automatically send downloaded &news to ebook reader - + &Delete news from library when it is automatically sent to reader @@ -57,12 +57,12 @@ Default network &timeout: - timeout + opt_network_timeout - + Set the default timeout for network fetches (i.e. anytime we go out to the internet to get information) @@ -81,7 +81,7 @@ - + QComboBox::AdjustToMinimumContentsLengthWithIcon @@ -111,7 +111,7 @@ Job &priority: - priority + opt_worker_process_priority @@ -121,12 +121,12 @@ Preferred &output format: - output_format + opt_output_format - + QComboBox::AdjustToMinimumContentsLengthWithIcon @@ -196,7 +196,7 @@ - + true @@ -208,7 +208,7 @@ - + ... @@ -232,7 +232,7 @@ - + ... @@ -256,7 +256,7 @@ - + true diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index c42cf7d6c3..142fa11c59 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -233,7 +233,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ ######################### Search Restriction ########################## SearchRestrictionMixin.__init__(self) - self.apply_named_search_restriction(db.prefs.get('gui_restriction', '')) + self.apply_named_search_restriction(db.prefs['gui_restriction']) ########################### Cover Flow ################################ @@ -378,7 +378,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{ self.set_window_title() self.apply_named_search_restriction('') # reset restriction to null self.saved_searches_changed() # reload the search restrictions combo box - self.apply_named_search_restriction(db.prefs.get('gui_restriction', '')) + self.apply_named_search_restriction(db.prefs['gui_restriction']) def set_window_title(self): self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name()) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 192a45cccb..4b6fb2f7f2 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -145,6 +145,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): def initialize_dynamic(self): self.prefs = DBPrefs(self) + defs = self.prefs.defaults + defs['gui_restriction'] = defs['cs_restriction'] = '' # Migrate saved search and user categories to db preference scheme def migrate_preference(key, default):