diff --git a/deluge/plugins/label/label/core.py b/deluge/plugins/label/label/core.py index 4eca73f21..27d1b8ac7 100644 --- a/deluge/plugins/label/label/core.py +++ b/deluge/plugins/label/label/core.py @@ -57,8 +57,22 @@ CONFIG_DEFAULTS = { "hide_zero_hits":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" @@ -84,6 +98,7 @@ class Core(CorePluginBase): self.labels = self.config.get("labels") self.torrent_labels = self.config.get("torrent_labels") + self.clean_initial_config() log.debug("Label plugin enabled..") def clean_config(self): @@ -93,11 +108,23 @@ class Core(CorePluginBase): log.debug("label: rm %s:%s" % (torrent_id,label_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): self.clean_config() self.config.save() def set_config_defaults(self): + #TODO : there is a deluge builtin for this, use it! changed = False for key, value in CONFIG_DEFAULTS.iteritems(): if not key in self.config.config: @@ -154,7 +181,6 @@ class Core(CorePluginBase): #specialized-state: #todo: traffic. - #log.debug("hide-z:%s" % self.config["hide_zero_hits"]) if self.config["hide_zero_hits"]: for state in set(KNOWN_STATES): log.debug(states.keys()) @@ -246,17 +272,8 @@ class Core(CorePluginBase): CheckInput(label_id, _("Empty Label")) CheckInput(not (label_id in self.labels) , _("Label already exists")) - - #default to current global per-torrent settings. - 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 - } + self.labels[label_id] = OPTIONS_DEFAULTS + log.debug("this is the file!") def export_remove(self, label_id): "remove a label" @@ -265,6 +282,17 @@ class Core(CorePluginBase): self.clean_config() 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): """update the label options @@ -282,21 +310,14 @@ class Core(CorePluginBase): """ CheckInput(label_id in self.labels , _("Unknown Label")) 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) self.labels[label_id].update(options_dict) - options = self.labels[label_id] - if apply: - for torrent_id,label in self.torrent_labels.iteritems(): - if label_id == label: - 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"]) + for torrent_id,label in self.torrent_labels.iteritems(): + if label_id == label: + self._set_torrent_options(torrent_id , label_id) self.config.save() @@ -321,19 +342,10 @@ class Core(CorePluginBase): self.clean_config() else: self.torrent_labels[torrent_id] = label_id - #set speeds, etc: - 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._set_torrent_options(torrent_id, label_id) self.config.save() - def export_get_global_options(self): "see : label_set_global_options" return { diff --git a/deluge/plugins/label/label/data/label_options.glade b/deluge/plugins/label/label/data/label_options.glade index 8f53b44a1..592fba759 100644 --- a/deluge/plugins/label/label/data/label_options.glade +++ b/deluge/plugins/label/label/data/label_options.glade @@ -1,6 +1,6 @@ - + 5 @@ -51,13 +51,16 @@ - - - - - - - + + True + True + Apply max settings: + 0 + True + + + 4 + @@ -70,15 +73,6 @@ 6 - - - True - - - 1 - 2 - - True @@ -234,7 +228,7 @@ True - Bandwith + Maximum tab @@ -242,9 +236,140 @@ - + True - todo + 7 + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + warning : not effective yet + + + 3 + 6 + 7 + + + + + True + True + Apply Queue settings: + 0 + True + + + 3 + + + + + True + True + 2 1 100 1 10 10 + + + 2 + 3 + 2 + 3 + + + + + True + True + Remove at ratio + 0 + True + + + 1 + 2 + 3 + 4 + + + + + True + True + Stop seed at ratio: + 0 + True + + + 1 + 2 + 2 + 3 + + + + + True + True + Auto Managed + 0 + True + + + 1 + 2 + 1 + 2 + + + + + True + + + 1 + 2 + 4 + 5 + + + + + True + + + 1 + 2 + 5 + 6 + + 1 @@ -262,10 +387,58 @@ - + True - todo - + + + True + True + Move completed to: + 0 + True + + + + + True + + + 1 + + + + + True + warning : not effective yet + + + 2 + + + + + True + + + 3 + + + + + True + + + 4 + + + + + True + + + 5 + + 2 diff --git a/deluge/plugins/label/label/gtkui/__init__.py b/deluge/plugins/label/label/gtkui/__init__.py index 9f6c23e8c..597cc7b38 100644 --- a/deluge/plugins/label/label/gtkui/__init__.py +++ b/deluge/plugins/label/label/gtkui/__init__.py @@ -76,7 +76,6 @@ class GtkUI(ui.UI): self.sidebar.unload() log.debug(2) - def get_pixmap(self, fname): """Returns a pixmap file included with plugin""" return pkg_resources.resource_filename("blocklist", os.path.join("data", fname)) @@ -84,13 +83,9 @@ class GtkUI(ui.UI): def load_interface(self): #sidebar - log.debug("replace sidebar") - try : - if not self.sidebar: - self.sidebar = sidebar.LabelSideBar() - self.sidebar.load() - except Exception, e: - log.debug(e) + if not self.sidebar: + self.sidebar = sidebar.LabelSideBar() + self.sidebar.load() #menu: log.debug("add items to torrentview-popup menu.") @@ -112,11 +107,6 @@ class GtkUI(ui.UI): def load_columns(self): log.debug("add columns") - component.get("TorrentView").add_func_column(_("Label"), - cell_data_label, - [str], - status_field=["label"]) - - component.get("TorrentView").create_model_filter() #todo:improve. + component.get("TorrentView").add_text_column(_("Label"), status_field=["label"]) diff --git a/deluge/plugins/label/label/gtkui/sidebar.py b/deluge/plugins/label/label/gtkui/sidebar.py index 65eed64ec..faff66e24 100644 --- a/deluge/plugins/label/label/gtkui/sidebar.py +++ b/deluge/plugins/label/label/gtkui/sidebar.py @@ -86,7 +86,7 @@ class LabelMenu(gtk.Menu): aclient.label_remove(None, self.label) 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): "No Label:disable options/del" @@ -100,7 +100,7 @@ class AddDialog(object): def __init__(self): pass - def show(self, label): + def show(self, label ): self.glade = gtk.glade.XML(get_resource("label_options.glade")) self.dialog = self.glade.get_widget("dlg_label_add") self.glade.signal_autoconnect({ @@ -119,12 +119,19 @@ class AddDialog(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): pass - def show(self, label): + def show(self, label , position): self.label = label self.glade = gtk.glade.XML(get_resource("label_options.glade")) self.dialog = self.glade.get_widget("dlg_label_options") @@ -132,20 +139,59 @@ class OptionsDialog(object): "on_options_ok":self.on_ok, "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) + self.dialog.move(*position) self.dialog.run() 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: 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): + "save options.." options = {} for id in self.spin_ids: 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) 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): self.dialog.destroy()