sidebar: show/hide root nodes

This commit is contained in:
Martijn Voncken 2008-08-03 22:02:06 +00:00
parent 53f6909b6e
commit 6133903608
4 changed files with 148 additions and 25 deletions

View File

@ -55,9 +55,15 @@ CONFIG_DEFAULTS = {
"torrent_labels":{}, #torrent_id:label_id "torrent_labels":{}, #torrent_id:label_id
"labels":{}, #label_id:{name:value} "labels":{}, #label_id:{name:value}
"hide_zero_hits":False, "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 = { OPTIONS_DEFAULTS = {
"max_download_speed":-1, "max_download_speed":-1,
"max_upload_speed":-1, "max_upload_speed":-1,
@ -111,7 +117,6 @@ class Core(CorePluginBase):
def clean_initial_config(self): def clean_initial_config(self):
"add any new keys in OPTIONS_DEFAULTS" "add any new keys in OPTIONS_DEFAULTS"
log.debug("--here--")
log.debug(self.labels.keys()) log.debug(self.labels.keys())
for key in self.labels.keys(): for key in self.labels.keys():
options = dict(OPTIONS_DEFAULTS) options = dict(OPTIONS_DEFAULTS)
@ -132,9 +137,7 @@ class Core(CorePluginBase):
self.config.config[key] = value self.config.config[key] = value
changed = True changed = True
if changed: if changed:
pass self.config.save()
#self.config.save()
log.debug("label_config=%s" % self.config.config)
def disable(self): def disable(self):
# De-register the label field # De-register the label field
@ -148,7 +151,6 @@ class Core(CorePluginBase):
## Filters ## ## Filters ##
def filter_state(self, torrents, value): def filter_state(self, torrents, value):
"in/out: a list of torrent objects." "in/out: a list of torrent objects."
log.debug("filter-state:%s" % value)
for t in torrents: for t in torrents:
log.debug("s=%s" % t.state) log.debug("s=%s" % t.state)
return [t for t in torrents if t.state == value] return [t for t in torrents if t.state == value]
@ -173,6 +175,7 @@ class Core(CorePluginBase):
def get_state_filter_items(self): def get_state_filter_items(self):
states = dict([(state, 0) for state in KNOWN_STATES]) states = dict([(state, 0) for state in KNOWN_STATES])
state_order = list(KNOWN_STATES) state_order = list(KNOWN_STATES)
#state-simple: #state-simple:
for t in self.torrents.values(): for t in self.torrents.values():
if not t.state in state_order: if not t.state in state_order:
@ -237,8 +240,11 @@ class Core(CorePluginBase):
""" """
result = {} result = {}
if self.config.get("show_states"):
result[STATE] = self.get_state_filter_items() result[STATE] = self.get_state_filter_items()
if self.config.get("show_trackers"):
result[TRACKER] = self.get_tracker_filter_items() result[TRACKER] = self.get_tracker_filter_items()
if self.config.get("show_labels"):
result[LABEL] = self.get_label_filter_items() result[LABEL] = self.get_label_filter_items()
return result return result
@ -277,7 +283,6 @@ class Core(CorePluginBase):
CheckInput(not (label_id in self.labels) , _("Label already exists")) CheckInput(not (label_id in self.labels) , _("Label already exists"))
self.labels[label_id] = dict(OPTIONS_DEFAULTS) self.labels[label_id] = dict(OPTIONS_DEFAULTS)
log.debug("this is the file!")
def export_remove(self, label_id): def export_remove(self, label_id):
"remove a label" "remove a label"
@ -362,10 +367,7 @@ class Core(CorePluginBase):
def export_get_global_options(self): def export_get_global_options(self):
"see : label_set_global_options" "see : label_set_global_options"
return { return dict ( (k,self.config.get(k) ) for k in CORE_OPTIONS)
"hide_zero_hits":self.config.get("hide_zero_hits"),
"gtk_alfa":self.config.get("gtk_alfa")
}
def export_set_global_options(self, options): def export_set_global_options(self, options):
"""global_options: """global_options:
@ -373,7 +375,7 @@ class Core(CorePluginBase):
"hide_zero":bool() #label_filter_items only returns items with more than 0 hits. "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): if options.has_key(key):
self.config.set(key, options[key]) self.config.set(key, options[key])
self.config.save() self.config.save()

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Wed Jul 30 20:32:12 2008 --> <!--Generated with glade3 3.4.5 on Mon Aug 4 00:08:54 2008 -->
<glade-interface> <glade-interface>
<widget class="GtkWindow" id="window1"> <widget class="GtkWindow" id="window1">
<child> <child>
@ -73,18 +73,122 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="label3"> <widget class="GtkFrame" id="frame2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">&lt;i&gt;Use the sidebar to add,edit and remove labels.&lt;/i&gt; <property name="label_xalign">0</property>
</property> <property name="shadow_type">GTK_SHADOW_NONE</property>
<property name="use_markup">True</property> <child>
<widget class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="spacing">5</property>
<child>
<widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="spacing">5</property>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox3">
<property name="visible">True</property>
<child>
<widget class="GtkCheckButton" id="show_states">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Show states</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
</child>
<child>
<widget class="GtkCheckButton" id="show_trackers">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Show trackers</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget> </widget>
<packing> <packing>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child> <child>
<placeholder/> <widget class="GtkCheckButton" id="show_labels">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Show labels</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="show_search">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Show keyword search(todo)</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="ypad">5</property>
<property name="label" translatable="yes">&lt;b&gt;Sidebar&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;i&gt;( Use the sidebar to add,edit and remove labels. )&lt;/i&gt;
</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child> </child>
</widget> </widget>
</child> </child>

View File

@ -42,6 +42,8 @@ from deluge.ui.client import aclient
class LabelConfig(object): class LabelConfig(object):
chk_ids = ["hide_zero_hits","show_labels","show_trackers","show_states","show_search"]
def __init__(self, plugin): def __init__(self, plugin):
self.plugin = plugin self.plugin = plugin
self.labels = [] self.labels = []
@ -61,7 +63,6 @@ class LabelConfig(object):
def unload(self): def unload(self):
self.plugin.remove_preferences_page("Label") 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) self.plugin.deregister_hook("on_show_prefs", self.load_settings)
def get_resource(self, filename): def get_resource(self, filename):
@ -70,10 +71,15 @@ class LabelConfig(object):
def load_settings(self ,widget = None , data = None): def load_settings(self ,widget = None , data = None):
aclient.label_get_global_options(self.cb_global_options) aclient.label_get_global_options(self.cb_global_options)
def cb_global_options(self, data): def cb_global_options(self, options):
self.glade.get_widget("hide_zero_hits").set_active(data["hide_zero_hits"]) 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): 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) aclient.label_set_global_options(None, options)

View File

@ -275,9 +275,20 @@ class LabelSideBar(component.Component):
self.update_row(cat, value , count) self.update_row(cat, value , count)
visible_filters.append((cat, value)) 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: for f in self.filters:
if not f in visible_filters: if not f in visible_filters:
self.treestore.set_value(self.filters[f], 4, False) self.treestore.set_value(self.filters[f], 4, False)
# kind of a hack.
if self.first_expand: if self.first_expand:
self.label_view.expand_all() self.label_view.expand_all()
self.first_expand = False self.first_expand = False