label options ui

This commit is contained in:
Martijn Voncken 2008-07-31 21:02:53 +00:00
parent d6928f7520
commit d76c6b991e
4 changed files with 297 additions and 76 deletions

View File

@ -57,8 +57,22 @@ CONFIG_DEFAULTS = {
"hide_zero_hits":False, "hide_zero_hits":False,
"gtk_alfa":False "gtk_alfa":False
} }
OPTIONS_KEYS = ["max_download_speed", "max_upload_speed",
"max_connections", "max_upload_slots", "prioritize_first_last","apply_max","move_completed_to"] OPTIONS_DEFAULTS = {
"max_download_speed":-1,
"max_upload_speed":-1,
"max_connections":-1,
"max_upload_slots":-1,
"prioritize_first_last":False,
"apply_max":False,
"move_completed_to":"",
"apply_queue":False,
"is_auto_managed":False,
"stop_at_ratio":False,
"stop_ratio":2.0,
"remove_at_ratio":False
}
NO_LABEL = "No Label" NO_LABEL = "No Label"
@ -84,6 +98,7 @@ class Core(CorePluginBase):
self.labels = self.config.get("labels") self.labels = self.config.get("labels")
self.torrent_labels = self.config.get("torrent_labels") self.torrent_labels = self.config.get("torrent_labels")
self.clean_initial_config()
log.debug("Label plugin enabled..") log.debug("Label plugin enabled..")
def clean_config(self): def clean_config(self):
@ -93,11 +108,23 @@ class Core(CorePluginBase):
log.debug("label: rm %s:%s" % (torrent_id,label_id)) log.debug("label: rm %s:%s" % (torrent_id,label_id))
del self.torrent_labels[torrent_id] del self.torrent_labels[torrent_id]
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)
options.update(self.labels[key])
self.labels[key] = options
def save_config(self): def save_config(self):
self.clean_config() self.clean_config()
self.config.save() self.config.save()
def set_config_defaults(self): def set_config_defaults(self):
#TODO : there is a deluge builtin for this, use it!
changed = False changed = False
for key, value in CONFIG_DEFAULTS.iteritems(): for key, value in CONFIG_DEFAULTS.iteritems():
if not key in self.config.config: if not key in self.config.config:
@ -154,7 +181,6 @@ class Core(CorePluginBase):
#specialized-state: #specialized-state:
#todo: traffic. #todo: traffic.
#log.debug("hide-z:%s" % self.config["hide_zero_hits"])
if self.config["hide_zero_hits"]: if self.config["hide_zero_hits"]:
for state in set(KNOWN_STATES): for state in set(KNOWN_STATES):
log.debug(states.keys()) log.debug(states.keys())
@ -246,17 +272,8 @@ class Core(CorePluginBase):
CheckInput(label_id, _("Empty Label")) CheckInput(label_id, _("Empty Label"))
CheckInput(not (label_id in self.labels) , _("Label already exists")) CheckInput(not (label_id in self.labels) , _("Label already exists"))
self.labels[label_id] = OPTIONS_DEFAULTS
#default to current global per-torrent settings. log.debug("this is the file!")
self.labels[label_id] = {
"max_download_speed":self.core_cfg.config["max_download_speed_per_torrent"],
"max_upload_speed":self.core_cfg.config["max_upload_speed_per_torrent"],
"max_connections":self.core_cfg.config["max_connections_per_torrent"],
"max_upload_slots":self.core_cfg.config["max_upload_slots_per_torrent"],
"prioritize_first_last":self.core_cfg.config["prioritize_first_last_pieces"],
"apply_max":False,
"move_completed_to":None
}
def export_remove(self, label_id): def export_remove(self, label_id):
"remove a label" "remove a label"
@ -265,6 +282,17 @@ class Core(CorePluginBase):
self.clean_config() self.clean_config()
self.config.save() self.config.save()
def _set_torrent_options(self, torrent_id, label_id):
options = self.labels[label_id]
torrent = self.torrents[torrent_id]
torrent.set_max_download_speed(options["max_download_speed"])
torrent.set_max_upload_speed(options["max_upload_speed"])
torrent.set_max_connections(options["max_connections"])
torrent.set_max_upload_slots(options["max_upload_slots"])
torrent.set_prioritize_first_last(options["prioritize_first_last"])
def export_set_options(self, label_id, options_dict , apply = False): def export_set_options(self, label_id, options_dict , apply = False):
"""update the label options """update the label options
@ -282,21 +310,14 @@ class Core(CorePluginBase):
""" """
CheckInput(label_id in self.labels , _("Unknown Label")) CheckInput(label_id in self.labels , _("Unknown Label"))
for key in options_dict.keys(): for key in options_dict.keys():
if not key in OPTIONS_KEYS: if not key in OPTIONS_DEFAULTS:
raise Exception("label: Invalid options_dict key:%s" % key) raise Exception("label: Invalid options_dict key:%s" % key)
self.labels[label_id].update(options_dict) self.labels[label_id].update(options_dict)
options = self.labels[label_id]
if apply:
for torrent_id,label in self.torrent_labels.iteritems(): for torrent_id,label in self.torrent_labels.iteritems():
if label_id == label: if label_id == label:
torrent = self.torrents[torrent_id] self._set_torrent_options(torrent_id , label_id)
torrent.set_max_download_speed(options["max_download_speed"])
torrent.set_max_upload_speed(options["max_upload_speed"])
torrent.set_max_connections(options["max_connections"])
torrent.set_max_upload_slots(options["max_upload_slots"])
torrent.set_prioritize_first_last(options["prioritize_first_last"])
self.config.save() self.config.save()
@ -321,19 +342,10 @@ class Core(CorePluginBase):
self.clean_config() self.clean_config()
else: else:
self.torrent_labels[torrent_id] = label_id self.torrent_labels[torrent_id] = label_id
#set speeds, etc: self._set_torrent_options(torrent_id, label_id)
options = self.labels[label_id]
if ("apply_max" in options) and options["apply_max"]:
torrent = self.torrents[torrent_id]
torrent.set_max_download_speed(options["max_download_speed"])
torrent.set_max_upload_speed(options["max_upload_speed"])
torrent.set_max_connections(options["max_connections"])
torrent.set_max_upload_slots(options["max_upload_slots"])
torrent.set_prioritize_first_last(options["prioritize_first_last"])
self.config.save() self.config.save()
def export_get_global_options(self): def export_get_global_options(self):
"see : label_set_global_options" "see : label_set_global_options"
return { return {

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:20:04 2008 --> <!--Generated with glade3 3.4.5 on Thu Jul 31 22:43:12 2008 -->
<glade-interface> <glade-interface>
<widget class="GtkDialog" id="dlg_label_options"> <widget class="GtkDialog" id="dlg_label_options">
<property name="border_width">5</property> <property name="border_width">5</property>
@ -51,13 +51,16 @@
<placeholder/> <placeholder/>
</child> </child>
<child> <child>
<placeholder/> <widget class="GtkCheckButton" id="apply_max">
</child> <property name="visible">True</property>
<child> <property name="can_focus">True</property>
<placeholder/> <property name="label" translatable="yes">Apply max settings:</property>
</child> <property name="response_id">0</property>
<child> <property name="draw_indicator">True</property>
<placeholder/> </widget>
<packing>
<property name="right_attach">4</property>
</packing>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="label14"> <widget class="GtkLabel" id="label14">
@ -70,15 +73,6 @@
<property name="bottom_attach">6</property> <property name="bottom_attach">6</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child> <child>
<widget class="GtkSpinButton" id="max_connections"> <widget class="GtkSpinButton" id="max_connections">
<property name="visible">True</property> <property name="visible">True</property>
@ -234,17 +228,148 @@
<child> <child>
<widget class="GtkLabel" id="label7"> <widget class="GtkLabel" id="label7">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Bandwith</property> <property name="label" translatable="yes">Maximum</property>
</widget> </widget>
<packing> <packing>
<property name="type">tab</property> <property name="type">tab</property>
<property name="tab_fill">False</property> <property name="tab_fill">False</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="n_rows">7</property>
<property name="n_columns">3</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="label" translatable="yes">warning : not effective yet</property>
</widget>
<packing>
<property name="right_attach">3</property>
<property name="top_attach">6</property>
<property name="bottom_attach">7</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="apply_queue">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Apply Queue settings:</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="stop_ratio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">2 1 100 1 10 10</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="remove_at_ratio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Remove at ratio</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="stop_at_ratio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Stop seed at ratio:</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="is_auto_managed">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Auto Managed</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label15">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child> <child>
<widget class="GtkLabel" id="label10"> <widget class="GtkLabel" id="label10">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">todo</property> </widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">5</property>
<property name="bottom_attach">6</property>
</packing>
</child>
</widget> </widget>
<packing> <packing>
<property name="position">1</property> <property name="position">1</property>
@ -261,11 +386,59 @@
<property name="tab_fill">False</property> <property name="tab_fill">False</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<child>
<widget class="GtkCheckButton" id="chk_move_completed_to">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Move completed to:</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
</child>
<child>
<widget class="GtkFileChooserButton" id="move_completed_to">
<property name="visible">True</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child> <child>
<widget class="GtkLabel" id="label11"> <widget class="GtkLabel" id="label11">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">todo <property name="label" translatable="yes">warning : not effective yet</property>
</property> </widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label18">
<property name="visible">True</property>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label19">
<property name="visible">True</property>
</widget>
<packing>
<property name="position">4</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label20">
<property name="visible">True</property>
</widget>
<packing>
<property name="position">5</property>
</packing>
</child>
</widget> </widget>
<packing> <packing>
<property name="position">2</property> <property name="position">2</property>

View File

@ -76,7 +76,6 @@ class GtkUI(ui.UI):
self.sidebar.unload() self.sidebar.unload()
log.debug(2) log.debug(2)
def get_pixmap(self, fname): def get_pixmap(self, fname):
"""Returns a pixmap file included with plugin""" """Returns a pixmap file included with plugin"""
return pkg_resources.resource_filename("blocklist", os.path.join("data", fname)) return pkg_resources.resource_filename("blocklist", os.path.join("data", fname))
@ -84,13 +83,9 @@ class GtkUI(ui.UI):
def load_interface(self): def load_interface(self):
#sidebar #sidebar
log.debug("replace sidebar")
try :
if not self.sidebar: if not self.sidebar:
self.sidebar = sidebar.LabelSideBar() self.sidebar = sidebar.LabelSideBar()
self.sidebar.load() self.sidebar.load()
except Exception, e:
log.debug(e)
#menu: #menu:
log.debug("add items to torrentview-popup menu.") log.debug("add items to torrentview-popup menu.")
@ -112,11 +107,6 @@ class GtkUI(ui.UI):
def load_columns(self): def load_columns(self):
log.debug("add columns") log.debug("add columns")
component.get("TorrentView").add_func_column(_("Label"), component.get("TorrentView").add_text_column(_("Label"), status_field=["label"])
cell_data_label,
[str],
status_field=["label"])
component.get("TorrentView").create_model_filter() #todo:improve.

View File

@ -86,7 +86,7 @@ class LabelMenu(gtk.Menu):
aclient.label_remove(None, self.label) aclient.label_remove(None, self.label)
def on_options (self, event=None): def on_options (self, event=None):
self.options_dialog.show(self.label) self.options_dialog.show(self.label, (200,250))
def set_label(self,label): def set_label(self,label):
"No Label:disable options/del" "No Label:disable options/del"
@ -119,12 +119,19 @@ class AddDialog(object):
class OptionsDialog(object): class OptionsDialog(object):
spin_ids = ["max_download_speed","max_upload_speed","max_upload_slots","max_connections"] spin_ids = ["max_download_speed","max_upload_speed","max_upload_slots","max_connections","stop_ratio"]
chk_ids = ["apply_max","apply_queue","stop_at_ratio","apply_queue","remove_at_ratio","chk_move_completed_to"]
sensitive_groups = { #keys must be checkboxes , value-list is to be enabled on checked.
"apply_max": ["max_download_speed","max_upload_speed","max_upload_slots","max_connections"],
"apply_queue":["is_auto_managed","remove_at_ratio","stop_at_ratio","stop_ratio"],
#"stop_at_ratio":["stop_at_ratio","remove_at_ratio"], #nested from apply_queue, will probably cause bugs.
"chk_move_completed_to":["move_completed_to"]
}
def __init__(self): def __init__(self):
pass pass
def show(self, label): def show(self, label , position):
self.label = label self.label = label
self.glade = gtk.glade.XML(get_resource("label_options.glade")) self.glade = gtk.glade.XML(get_resource("label_options.glade"))
self.dialog = self.glade.get_widget("dlg_label_options") self.dialog = self.glade.get_widget("dlg_label_options")
@ -132,20 +139,59 @@ class OptionsDialog(object):
"on_options_ok":self.on_ok, "on_options_ok":self.on_ok,
"on_options_cancel":self.on_cancel, "on_options_cancel":self.on_cancel,
}) })
for chk_id in self.sensitive_groups:
log.debug(chk_id)
chk = self.glade.get_widget(chk_id)
chk.connect("toggled",self.apply_sensitivity)
aclient.label_get_options(self.load_options, self.label) aclient.label_get_options(self.load_options, self.label)
self.dialog.move(*position)
self.dialog.run() self.dialog.run()
def load_options(self, options): def load_options(self, options):
log.debug(options.keys())
options["chk_move_completed_to"] = bool(options["move_completed_to"])
for id in self.spin_ids: for id in self.spin_ids:
self.glade.get_widget(id).set_value(options[id]) self.glade.get_widget(id).set_value(options[id])
for id in self.chk_ids:
self.glade.get_widget(id).set_active(bool(options[id]))
if options["move_completed_to"]:
self.glade.get_widget("move_completed_to").set_filename(options["move_completed_to"])
self.apply_sensitivity()
def on_ok(self, event=None): def on_ok(self, event=None):
"save options.."
options = {} options = {}
for id in self.spin_ids: for id in self.spin_ids:
options[id] = self.glade.get_widget(id).get_value() options[id] = self.glade.get_widget(id).get_value()
for id in self.chk_ids:
options[id] = self.glade.get_widget(id).get_active()
if options["chk_move_completed_to"]:
options["move_completed_to"] = self.glade.get_widget("move_completed_to").get_filename()
else:
options["move_completed_to"] = None
del options["chk_move_completed_to"] #not mapped.
aclient.label_set_options(None, self.label, options) aclient.label_set_options(None, self.label, options)
self.dialog.destroy() self.dialog.destroy()
def apply_sensitivity(self, event=None):
log.debug("apply-sensitivity")
for chk_id , sensitive_list in self.sensitive_groups.iteritems():
sens = self.glade.get_widget(chk_id).get_active()
for widget_id in sensitive_list:
log.debug(widget_id)
self.glade.get_widget(widget_id).set_sensitive(sens)
def on_cancel(self, event=None): def on_cancel(self, event=None):
self.dialog.destroy() self.dialog.destroy()