From 4cde033d6600da8f44fe900c5a1b1266a2bceb07 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Tue, 22 Feb 2011 18:59:39 +0000 Subject: [PATCH] Add to preferences/look & feel a list of fields for which items are hierarchical. --- src/calibre/gui2/preferences/look_feel.py | 13 +++++++++- src/calibre/gui2/preferences/look_feel.ui | 29 +++++++++++++++++++++++ src/calibre/gui2/tag_view.py | 3 ++- src/calibre/library/database2.py | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 196ef16b08..f7d76f2b70 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -7,17 +7,19 @@ __docformat__ = 'restructuredtext en' from PyQt4.Qt import QApplication, QFont, QFontInfo, QFontDialog -from calibre.gui2.preferences import ConfigWidgetBase, test_widget +from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList from calibre.gui2.preferences.look_feel_ui import Ui_Form from calibre.gui2 import config, gprefs, qt_app from calibre.utils.localization import available_translations, \ get_language, get_lang from calibre.utils.config import prefs +from calibre.utils.icu import sort_key class ConfigWidget(ConfigWidgetBase, Ui_Form): def genesis(self, gui): self.gui = gui + db = gui.library_view.model().db r = self.register @@ -61,6 +63,15 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): r('tags_browser_partition_method', gprefs, choices=choices) r('tags_browser_collapse_at', gprefs) + choices = set([k for k in db.field_metadata.all_field_keys() + if db.field_metadata[k]['is_category'] and + db.field_metadata[k]['datatype'] in ['text', 'series', 'enumeration']]) + choices -= set(['authors', 'publisher', 'formats', 'news']) + self.opt_categories_using_hierarchy.update_items_cache(choices) + r('categories_using_hierarchy', db.prefs, setting=CommaSeparatedList, + choices=sorted(list(choices), key=sort_key)) + + self.current_font = None self.change_font_button.clicked.connect(self.change_font) diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 3f2bb3e145..a1fc5bb490 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -190,6 +190,28 @@ up into sub-categories. If the partition method is set to disable, this value is + + + + Categories with hierarchical items: + + + opt_categories_using_hierarchy + + + + + + + A comma-separated list of columns in which items containing +periods are displayed in the tag browser trees. For example, if +this box contains 'tags' then tags of the form 'mystery.English' +and 'mystery.Thriller' will be displayed with English and Thriller +both under the label 'mystery'. If 'tags' is not in this box, +then the tags will be displayed each on their own line. + + + @@ -275,6 +297,13 @@ up into sub-categories. If the partition method is set to disable, this value is + + + MultiCompleteLineEdit + QLineEdit +
calibre/gui2/complete.h
+
+
diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index 15ff986f2e..04b336d791 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -914,7 +914,8 @@ class TagsModel(QAbstractItemModel): # {{{ node_parent = category components = [t for t in tag.name.split('.')] - if key in ['authors', 'publisher', 'title'] or len(components) == 1 or \ + if key not in self.db.prefs.get('categories_using_hierarchy', []) \ + or len(components) == 1 or \ self.db.field_metadata[key]['kind'] == 'user': self.beginInsertRows(category_index, 999999, 1) TagTreeItem(parent=node_parent, data=tag, tooltip=tt, diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 5a0935c2c8..e515abd709 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -174,6 +174,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.prefs = DBPrefs(self) defs = self.prefs.defaults defs['gui_restriction'] = defs['cs_restriction'] = '' + defs['categories_using_hierarchy'] = '' # Migrate saved search and user categories to db preference scheme def migrate_preference(key, default):