From 6133903608ce6c8a8575d4b93fcf934b3f7d1e96 Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Sun, 3 Aug 2008 22:02:06 +0000 Subject: [PATCH] sidebar: show/hide root nodes --- deluge/plugins/label/label/core.py | 32 ++--- .../plugins/label/label/data/label_pref.glade | 116 +++++++++++++++++- .../plugins/label/label/gtkui/label_config.py | 14 ++- deluge/plugins/label/label/gtkui/sidebar.py | 11 ++ 4 files changed, 148 insertions(+), 25 deletions(-) diff --git a/deluge/plugins/label/label/core.py b/deluge/plugins/label/label/core.py index aed97c7fe..50622b7fb 100644 --- a/deluge/plugins/label/label/core.py +++ b/deluge/plugins/label/label/core.py @@ -55,9 +55,15 @@ CONFIG_DEFAULTS = { "torrent_labels":{}, #torrent_id:label_id "labels":{}, #label_id:{name:value} "hide_zero_hits":False, - "gtk_alfa":False + "gtk_alfa":False, + "show_states":True, + "show_trackers":True, + "show_labels":True, + "show_search":True } +CORE_OPTIONS = ["hide_zero_hits", "gtk_alfa", "show_states", "show_trackers", "show_labels", "show_search"] + OPTIONS_DEFAULTS = { "max_download_speed":-1, "max_upload_speed":-1, @@ -111,7 +117,6 @@ class Core(CorePluginBase): def clean_initial_config(self): "add any new keys in OPTIONS_DEFAULTS" - log.debug("--here--") log.debug(self.labels.keys()) for key in self.labels.keys(): options = dict(OPTIONS_DEFAULTS) @@ -132,9 +137,7 @@ class Core(CorePluginBase): self.config.config[key] = value changed = True if changed: - pass - #self.config.save() - log.debug("label_config=%s" % self.config.config) + self.config.save() def disable(self): # De-register the label field @@ -148,7 +151,6 @@ class Core(CorePluginBase): ## Filters ## def filter_state(self, torrents, value): "in/out: a list of torrent objects." - log.debug("filter-state:%s" % value) for t in torrents: log.debug("s=%s" % t.state) return [t for t in torrents if t.state == value] @@ -173,6 +175,7 @@ class Core(CorePluginBase): def get_state_filter_items(self): states = dict([(state, 0) for state in KNOWN_STATES]) state_order = list(KNOWN_STATES) + #state-simple: for t in self.torrents.values(): if not t.state in state_order: @@ -237,9 +240,12 @@ class Core(CorePluginBase): """ result = {} - result[STATE] = self.get_state_filter_items() - result[TRACKER] = self.get_tracker_filter_items() - result[LABEL] = self.get_label_filter_items() + if self.config.get("show_states"): + result[STATE] = self.get_state_filter_items() + if self.config.get("show_trackers"): + result[TRACKER] = self.get_tracker_filter_items() + if self.config.get("show_labels"): + result[LABEL] = self.get_label_filter_items() return result @@ -277,7 +283,6 @@ class Core(CorePluginBase): CheckInput(not (label_id in self.labels) , _("Label already exists")) self.labels[label_id] = dict(OPTIONS_DEFAULTS) - log.debug("this is the file!") def export_remove(self, label_id): "remove a label" @@ -362,10 +367,7 @@ class Core(CorePluginBase): def export_get_global_options(self): "see : label_set_global_options" - return { - "hide_zero_hits":self.config.get("hide_zero_hits"), - "gtk_alfa":self.config.get("gtk_alfa") - } + return dict ( (k,self.config.get(k) ) for k in CORE_OPTIONS) def export_set_global_options(self, options): """global_options: @@ -373,7 +375,7 @@ class Core(CorePluginBase): "hide_zero":bool() #label_filter_items only returns items with more than 0 hits. } """ - for key in ["hide_zero_hits", "gtk_alfa"]: + for key in CORE_OPTIONS: if options.has_key(key): self.config.set(key, options[key]) self.config.save() diff --git a/deluge/plugins/label/label/data/label_pref.glade b/deluge/plugins/label/label/data/label_pref.glade index c69608a6b..21c7c077b 100644 --- a/deluge/plugins/label/label/data/label_pref.glade +++ b/deluge/plugins/label/label/data/label_pref.glade @@ -1,6 +1,6 @@ - + @@ -73,18 +73,122 @@ - + True - <i>Use the sidebar to add,edit and remove labels.</i> - - True + 0 + GTK_SHADOW_NONE + + + True + 12 + + + True + 5 + + + True + 5 + + + True + + + False + False + + + + + True + + + True + True + Show states + 0 + True + + + + + True + True + Show trackers + 0 + True + + + 1 + + + + + True + True + Show labels + 0 + True + + + 2 + + + + + True + True + Show keyword search(todo) + 0 + True + + + 3 + + + + + 1 + + + + + False + False + + + + + + + + + True + 5 + <b>Sidebar</b> + True + + + label_item + + + False + False 1 - + + True + <i>( Use the sidebar to add,edit and remove labels. )</i> + + True + + + 2 + diff --git a/deluge/plugins/label/label/gtkui/label_config.py b/deluge/plugins/label/label/gtkui/label_config.py index 8ae295aaf..19f64453c 100644 --- a/deluge/plugins/label/label/gtkui/label_config.py +++ b/deluge/plugins/label/label/gtkui/label_config.py @@ -42,6 +42,8 @@ from deluge.ui.client import aclient class LabelConfig(object): + chk_ids = ["hide_zero_hits","show_labels","show_trackers","show_states","show_search"] + def __init__(self, plugin): self.plugin = plugin self.labels = [] @@ -61,7 +63,6 @@ class LabelConfig(object): def unload(self): self.plugin.remove_preferences_page("Label") - self.plugin.deregister_hook("on_apply_prefs", self.on_apply_prefs) self.plugin.deregister_hook("on_show_prefs", self.load_settings) def get_resource(self, filename): @@ -70,10 +71,15 @@ class LabelConfig(object): def load_settings(self ,widget = None , data = None): aclient.label_get_global_options(self.cb_global_options) - def cb_global_options(self, data): - self.glade.get_widget("hide_zero_hits").set_active(data["hide_zero_hits"]) + def cb_global_options(self, options): + log.debug("options=%s" % options) + for id in self.chk_ids: + self.glade.get_widget(id).set_active(bool(options[id])) def on_apply_prefs(self): - options = {"hide_zero_hits":self.glade.get_widget("hide_zero_hits").get_active()} + options = {} + for id in self.chk_ids: + options[id] = self.glade.get_widget(id).get_active() + aclient.label_set_global_options(None, options) diff --git a/deluge/plugins/label/label/gtkui/sidebar.py b/deluge/plugins/label/label/gtkui/sidebar.py index 01c2917ed..bab843f72 100644 --- a/deluge/plugins/label/label/gtkui/sidebar.py +++ b/deluge/plugins/label/label/gtkui/sidebar.py @@ -275,9 +275,20 @@ class LabelSideBar(component.Component): self.update_row(cat, value , count) visible_filters.append((cat, value)) + # hide root-categories not returned by core-part of the plugin. + for cat in self.cat_nodes: + if cat in filter_items: + self.treestore.set_value(self.cat_nodes[cat], 4, True) + + else: + self.treestore.set_value(self.cat_nodes[cat], 4, False) + + # hide items not returned by core-plugin. for f in self.filters: if not f in visible_filters: self.treestore.set_value(self.filters[f], 4, False) + + # kind of a hack. if self.first_expand: self.label_view.expand_all() self.first_expand = False