sidebar: show/hide root nodes
This commit is contained in:
parent
53f6909b6e
commit
6133903608
|
@ -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()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!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>
|
||||
<widget class="GtkWindow" id="window1">
|
||||
<child>
|
||||
|
@ -73,18 +73,122 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label3">
|
||||
<widget class="GtkFrame" id="frame2">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><i>Use the sidebar to add,edit and remove labels.</i>
|
||||
</property>
|
||||
<property name="use_markup">True</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">GTK_SHADOW_NONE</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>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<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"><b>Sidebar</b></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>
|
||||
<placeholder/>
|
||||
<widget class="GtkLabel" id="label3">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><i>( Use the sidebar to add,edit and remove labels. )</i>
|
||||
</property>
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue