From e84d6cf5885f0f823e5ce14c82c426422c85e5d3 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sun, 15 Jul 2007 09:20:45 +0000 Subject: [PATCH] adding First/Last piece priority plugin --- libtorrent/include/libtorrent/alert_types.hpp | 1 - plugins/FirstLast/__init__.py | 113 ++++ po/deluge.pot | 604 +++++++++--------- src/core.py | 3 + src/deluge_core.cpp | 22 + src/interface.py | 73 ++- 6 files changed, 482 insertions(+), 334 deletions(-) create mode 100644 plugins/FirstLast/__init__.py diff --git a/libtorrent/include/libtorrent/alert_types.hpp b/libtorrent/include/libtorrent/alert_types.hpp index 7b32d2502..006e3a547 100755 --- a/libtorrent/include/libtorrent/alert_types.hpp +++ b/libtorrent/include/libtorrent/alert_types.hpp @@ -166,7 +166,6 @@ namespace libtorrent virtual std::auto_ptr clone() const { return std::auto_ptr(new invalid_request_alert(*this)); } - tcp::endpoint ip; peer_request request; peer_id pid; diff --git a/plugins/FirstLast/__init__.py b/plugins/FirstLast/__init__.py new file mode 100644 index 000000000..2e3c6f1f6 --- /dev/null +++ b/plugins/FirstLast/__init__.py @@ -0,0 +1,113 @@ +# Copyright (C) 2007 - Marcos Pinto +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + +### Initialization ### + +plugin_name = _("First/Last Priority") +plugin_author = "Marcos Pinto" +plugin_version = "0.1" +plugin_description = _("Set the highest priority to the first and last pieces.") + +def deluge_init(deluge_path): + global path + path = deluge_path + +def enable(core, interface): + global path + return FirstLast(path, core, interface) + +### The Plugin ### + +DEFAULT_PREFS = { + "flpriorities": [7] +} + +import deluge +import gtk, gtk.glade + +class FirstLast: + + def __init__(self, path, core, interface): + self.path = path + self.core = core + self.interface = interface + self.set_flpriorities = {} + self.callback_ids = [] + + # Setup preferences + self.config = deluge.pref.Preferences(filename=deluge.common.CONFIG_DIR + "/firstlast_priorty.conf", global_defaults=False, defaults=DEFAULT_PREFS) + + # Connect to events for the torrent menu so we know when to build and remove our sub-menu + self.callback_ids.append(self.interface.torrent_menu.connect_after("realize", self.torrent_menu_show)) + self.callback_ids.append(self.interface.torrent_menu.connect("show", self.torrent_menu_show)) + self.callback_ids.append(self.interface.torrent_menu.connect("hide", self.torrent_menu_hide)) + + def torrent_menu_show(self, widget, data=None): + # Get the selected torrent + self.unique_ID = self.interface.get_selected_torrent() + + # Make the sub-menu for the torrent menu + self.flp_menuitem = gtk.MenuItem(_("_First/Last Priority")) + + self.flp_menu = self.interface.build_menu_radio_list(self.config.get("flpriorities"), self.flp_clicked, self.get_torrent_flp(), None, True, _("_Not Set"), 1, None, True) + + self.flp_menuitem.set_submenu(self.flp_menu) + self.interface.torrent_menu.append(self.flp_menuitem) + + self.flp_menuitem.show_all() + + def torrent_menu_hide(self, widget): + try: + self.interface.torrent_menu.remove(self.flp_menuitem) + except AttributeError: + pass + + def update(self): + pass + + def unload(self): + # Disconnect all callbacks + for callback_id in self.callback_ids: + self.interface.torrent_menu.disconnect(callback_id) + + self.callback_ids = [] + + # Reset all desired flpriorities in the core + for unique_ID, flp in self.set_flpriorities.items(): + if flp > 1: + self.core.set_flp(unique_ID, flp) + + self.set_flpriorities = {} + + def flp_clicked(self, widget): + value = widget.get_children()[0].get_text() + if value == _("Not Set"): + value = 1 + + if value == _("Activated"): + value = 7 + + value = int(value) # Make sure the value is an int + + # Set the flp in the core and remember the setting + self.core.set_flp(self.unique_ID, value) + self.set_flpriorities[self.unique_ID] = value + + def get_torrent_flp(self): + if self.set_flpriorities.has_key(self.unique_ID): + return self.set_flpriorities[self.unique_ID] + else: + return 1 diff --git a/po/deluge.pot b/po/deluge.pot index 5e57c0223..9dd92e6f5 100644 --- a/po/deluge.pot +++ b/po/deluge.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-07-12 15:08-0500\n" +"POT-Creation-Date: 2007-07-14 21:30-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,225 +16,196 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: glade/delugegtk.glade:22 -msgid "Add Torrent" -msgstr "" - -#: glade/delugegtk.glade:23 -msgid "Add" -msgstr "" - -#: glade/delugegtk.glade:36 glade/dgtkpopups.glade:6 -msgid "Remove Torrent" -msgstr "" - -#: glade/delugegtk.glade:37 -msgid "Remove" -msgstr "" - -#: glade/delugegtk.glade:49 -msgid "Clear Finished Torrents" -msgstr "" - -#: glade/delugegtk.glade:50 -msgid "Clear" -msgstr "" - -#: glade/delugegtk.glade:72 -msgid "Start or Pause torrent" -msgstr "" - -#: glade/delugegtk.glade:73 -msgid "Start" -msgstr "" - -#: glade/delugegtk.glade:86 -msgid "Queue Torrent Up" -msgstr "" - -#: glade/delugegtk.glade:87 -msgid "Up" -msgstr "" - -#: glade/delugegtk.glade:100 -msgid "Queue Torrent Down" -msgstr "" - -#: glade/delugegtk.glade:101 -msgid "Down" -msgstr "" - -#: glade/delugegtk.glade:122 -msgid "Change Deluge preferences" -msgstr "" - -#: glade/delugegtk.glade:123 -msgid "Preferences" -msgstr "" - -#: glade/delugegtk.glade:135 -msgid "Open the plugins dialog" -msgstr "" - -#: glade/delugegtk.glade:136 glade/dgtkpopups.glade:209 -#: glade/plugin_dialog.glade:80 -msgid "Plugins" -msgstr "" - -#: glade/delugegtk.glade:185 -msgid "_File" -msgstr "" - -#: glade/delugegtk.glade:192 glade/tray_menu.glade:27 -msgid "_Add Torrent" -msgstr "" - -#: glade/delugegtk.glade:207 -msgid "Add _URL" -msgstr "" - -#: glade/delugegtk.glade:215 -msgid "_Clear Completed" -msgstr "" - -#: glade/delugegtk.glade:248 -msgid "_Edit" -msgstr "" - -#: glade/delugegtk.glade:265 -msgid "Pl_ugins" -msgstr "" - -#: glade/delugegtk.glade:284 -msgid "_Torrent" -msgstr "" - -#: glade/delugegtk.glade:291 -msgid "_View" -msgstr "" - -#: glade/delugegtk.glade:299 -msgid "_Toolbar" -msgstr "" - -#: glade/delugegtk.glade:308 -msgid "_Details" -msgstr "" - -#: glade/delugegtk.glade:317 -msgid "Columns" -msgstr "" - -#: glade/delugegtk.glade:325 src/interface.py:459 src/interface.py:625 -msgid "Size" -msgstr "" - -#: glade/delugegtk.glade:334 src/interface.py:460 -msgid "Status" -msgstr "" - -#: glade/delugegtk.glade:343 src/interface.py:461 -msgid "Seeders" -msgstr "" - -#: glade/delugegtk.glade:352 glade/delugegtk.glade:1093 src/interface.py:462 -msgid "Peers" -msgstr "" - -#: glade/delugegtk.glade:361 src/interface.py:463 src/interface.py:596 -#: src/interface.py:943 src/interface.py:957 -msgid "Down Speed" -msgstr "" - -#: glade/delugegtk.glade:370 src/interface.py:464 src/interface.py:597 -#: src/interface.py:944 src/interface.py:958 -msgid "Up Speed" -msgstr "" - -#: glade/delugegtk.glade:379 -msgid "Time Remaining" -msgstr "" - -#: glade/delugegtk.glade:388 -msgid "Share Ratio" -msgstr "" - -#: glade/delugegtk.glade:405 -msgid "_Help" -msgstr "" - -#: glade/delugegtk.glade:422 glade/delugegtk.glade:423 -msgid "Help translate this application" -msgstr "" - -#: glade/delugegtk.glade:535 -msgid "Next Announce:" -msgstr "" - -#: glade/delugegtk.glade:556 -msgid "Tracker Status:" -msgstr "" - -#: glade/delugegtk.glade:578 -msgid "Tracker:" -msgstr "" - -#: glade/delugegtk.glade:599 -msgid "Pieces:" -msgstr "" - -#: glade/delugegtk.glade:620 -msgid "Total Size:" -msgstr "" - -#: glade/delugegtk.glade:642 -msgid "Name:" -msgstr "" - -#: glade/delugegtk.glade:739 -msgid "Torrent Info" -msgstr "" - -#: glade/delugegtk.glade:793 -msgid "ETA:" -msgstr "" - -#: glade/delugegtk.glade:814 -msgid "Peers:" -msgstr "" - -#: glade/delugegtk.glade:835 glade/delugegtk.glade:856 -msgid "Speed:" -msgstr "" - -#: glade/delugegtk.glade:874 -msgid "Share Ratio:" -msgstr "" - -#: glade/delugegtk.glade:892 -msgid "Seeders:" -msgstr "" - -#: glade/delugegtk.glade:910 -msgid "Uploaded:" -msgstr "" - -#: glade/delugegtk.glade:928 +#: glade/delugegtk.glade:201 msgid "Downloaded:" msgstr "" -#: glade/delugegtk.glade:1040 +#: glade/delugegtk.glade:215 +msgid "Uploaded:" +msgstr "" + +#: glade/delugegtk.glade:233 +msgid "Seeders:" +msgstr "" + +#: glade/delugegtk.glade:251 +msgid "Share Ratio:" +msgstr "" + +#: glade/delugegtk.glade:270 glade/delugegtk.glade:289 +msgid "Speed:" +msgstr "" + +#: glade/delugegtk.glade:310 +msgid "Peers:" +msgstr "" + +#: glade/delugegtk.glade:331 +msgid "ETA:" +msgstr "" + +#: glade/delugegtk.glade:357 msgid "Statistics" msgstr "" -#: glade/delugegtk.glade:1065 +#: glade/delugegtk.glade:480 +msgid "Name:" +msgstr "" + +#: glade/delugegtk.glade:499 +msgid "Total Size:" +msgstr "" + +#: glade/delugegtk.glade:520 +msgid "Pieces:" +msgstr "" + +#: glade/delugegtk.glade:542 +msgid "Tracker:" +msgstr "" + +#: glade/delugegtk.glade:563 +msgid "Tracker Status:" +msgstr "" + +#: glade/delugegtk.glade:584 +msgid "Next Announce:" +msgstr "" + +#: glade/delugegtk.glade:603 +msgid "Torrent Info" +msgstr "" + +#: glade/delugegtk.glade:629 msgid "Details" msgstr "" -#: glade/delugegtk.glade:1123 +#: glade/delugegtk.glade:656 glade/delugegtk.glade:893 src/interface.py:464 +msgid "Peers" +msgstr "" + +#: glade/delugegtk.glade:685 msgid "Files" msgstr "" +#: glade/delugegtk.glade:726 +msgid "_File" +msgstr "" + +#: glade/delugegtk.glade:733 glade/tray_menu.glade:27 +msgid "_Add Torrent" +msgstr "" + +#: glade/delugegtk.glade:748 +msgid "Add _URL" +msgstr "" + +#: glade/delugegtk.glade:756 +msgid "_Clear Completed" +msgstr "" + +#: glade/delugegtk.glade:789 +msgid "_Edit" +msgstr "" + +#: glade/delugegtk.glade:806 +msgid "Pl_ugins" +msgstr "" + +#: glade/delugegtk.glade:825 +msgid "_Torrent" +msgstr "" + +#: glade/delugegtk.glade:832 +msgid "_View" +msgstr "" + +#: glade/delugegtk.glade:840 +msgid "_Toolbar" +msgstr "" + +#: glade/delugegtk.glade:849 +msgid "_Details" +msgstr "" + +#: glade/delugegtk.glade:858 +msgid "Columns" +msgstr "" + +#: glade/delugegtk.glade:866 src/interface.py:461 src/interface.py:653 +msgid "Size" +msgstr "" + +#: glade/delugegtk.glade:875 src/interface.py:462 +msgid "Status" +msgstr "" + +#: glade/delugegtk.glade:884 src/interface.py:463 +msgid "Seeders" +msgstr "" + +#: glade/delugegtk.glade:902 src/interface.py:465 src/interface.py:615 +#: src/interface.py:986 src/interface.py:1000 +msgid "Down Speed" +msgstr "" + +#: glade/delugegtk.glade:911 src/interface.py:466 src/interface.py:616 +#: src/interface.py:987 src/interface.py:1001 +msgid "Up Speed" +msgstr "" + +#: glade/delugegtk.glade:920 +msgid "Time Remaining" +msgstr "" + +#: glade/delugegtk.glade:929 +msgid "Share Ratio" +msgstr "" + +#: glade/delugegtk.glade:946 +msgid "_Help" +msgstr "" + +#: glade/delugegtk.glade:954 +msgid "Help translate this application" +msgstr "" + +#: glade/delugegtk.glade:955 +msgid "Translate This Application..." +msgstr "" + +#: glade/delugegtk.glade:1027 +msgid "Add Torrent" +msgstr "" + +#: glade/delugegtk.glade:1041 glade/dgtkpopups.glade:6 +msgid "Remove Torrent" +msgstr "" + +#: glade/delugegtk.glade:1054 +msgid "Clear Finished Torrents" +msgstr "" + +#: glade/delugegtk.glade:1077 +msgid "Start or Pause torrent" +msgstr "" + +#: glade/delugegtk.glade:1091 +msgid "Queue Torrent Up" +msgstr "" + +#: glade/delugegtk.glade:1105 +msgid "Queue Torrent Down" +msgstr "" + +#: glade/delugegtk.glade:1127 +msgid "Change Deluge preferences" +msgstr "" + +#: glade/delugegtk.glade:1140 +msgid "Open the plugins dialog" +msgstr "" + #: glade/dgtkpopups.glade:41 msgid "" "Are you sure you want to remove the selected torrent" @@ -261,6 +232,10 @@ msgstr "" msgid "Clear Finished" msgstr "" +#: glade/dgtkpopups.glade:209 glade/plugin_dialog.glade:80 +msgid "Plugins" +msgstr "" + #: glade/dgtkpopups.glade:260 msgid "Speed:" msgstr "" @@ -650,191 +625,194 @@ msgstr "" msgid "_Quit" msgstr "" -#: src/common.py:58 src/interface.py:436 +#: src/common.py:59 src/interface.py:438 msgid "Infinity" msgstr "" -#: src/common.py:71 +#: src/common.py:72 #, python-format msgid "%.1f KiB" msgstr "" -#: src/common.py:74 +#: src/common.py:75 #, python-format msgid "%.1f MiB" msgstr "" -#: src/common.py:76 +#: src/common.py:77 #, python-format msgid "%.1f GiB" msgstr "" -#: src/common.py:124 +#: src/common.py:127 msgid "Error: no webbrowser found" msgstr "" -#: src/core.py:129 -#, python-format -msgid "%d %d bytes needed" +#: src/core.py:128 +msgid "bytes needed" msgstr "" #: src/core.py:346 msgid "File was not found" msgstr "" -#: src/interface.py:206 src/interface.py:212 src/interface.py:266 -#: src/interface.py:288 -msgid "KiB/s" +#: src/core.py:394 +msgid "Asked for a torrent that doesn't exist" msgstr "" -#: src/interface.py:259 src/interface.py:270 src/interface.py:292 -msgid "Other..." -msgstr "" - -#: src/interface.py:267 src/interface.py:289 src/interface.py:927 -#: src/interface.py:933 src/interface.py:937 -msgid "Unlimited" -msgstr "" - -#: src/interface.py:315 -msgid "Deluge is locked" -msgstr "" - -#: src/interface.py:317 -msgid "" -"Deluge is password protected.\n" -"To show the Deluge window, please enter your password" -msgstr "" - -#: src/interface.py:444 -msgid "Unknown" -msgstr "" - -#: src/interface.py:458 -msgid "Name" -msgstr "" - -#: src/interface.py:465 -msgid "ETA" -msgstr "" - -#: src/interface.py:466 -msgid "Ratio" -msgstr "" - -#: src/interface.py:515 src/interface.py:554 src/interface.py:916 -msgid "Resume" -msgstr "" - -#: src/interface.py:518 src/interface.py:557 src/interface.py:919 -msgid "Pause" -msgstr "" - -#: src/interface.py:544 -msgid "Pause/Resume" -msgstr "" - -#: src/interface.py:593 -msgid "IP Address" -msgstr "" - -#: src/interface.py:594 -msgid "Client" -msgstr "" - -#: src/interface.py:595 -msgid "Percent Complete" -msgstr "" - -#: src/interface.py:623 -msgid "Download" -msgstr "" - -#: src/interface.py:624 -msgid "Filename" -msgstr "" - -#: src/interface.py:626 -msgid "Progress" -msgstr "" - -#: src/interface.py:737 -#, python-format -msgid "Paused %s" -msgstr "" - -#: src/interface.py:833 +#: src/core.py:552 src/interface.py:876 msgid "" "You cannot move torrent to a different partition. Please fix your " "preferences" msgstr "" -#: src/interface.py:943 src/interface.py:956 +#: src/interface.py:203 src/interface.py:209 src/interface.py:264 +#: src/interface.py:286 +msgid "KiB/s" +msgstr "" + +#: src/interface.py:227 src/interface.py:265 src/interface.py:287 +#: src/interface.py:970 src/interface.py:976 src/interface.py:980 +msgid "Unlimited" +msgstr "" + +#: src/interface.py:257 src/interface.py:268 src/interface.py:290 +msgid "Other..." +msgstr "" + +#: src/interface.py:313 +msgid "Deluge is locked" +msgstr "" + +#: src/interface.py:315 +msgid "" +"Deluge is password protected.\n" +"To show the Deluge window, please enter your password" +msgstr "" + +#: src/interface.py:446 +msgid "Unknown" +msgstr "" + +#: src/interface.py:460 +msgid "Name" +msgstr "" + +#: src/interface.py:467 +msgid "ETA" +msgstr "" + +#: src/interface.py:468 +msgid "Ratio" +msgstr "" + +#: src/interface.py:531 src/interface.py:570 src/interface.py:959 +msgid "Resume" +msgstr "" + +#: src/interface.py:534 src/interface.py:573 src/interface.py:962 +msgid "Pause" +msgstr "" + +#: src/interface.py:560 +msgid "Pause/Resume" +msgstr "" + +#: src/interface.py:612 +msgid "IP Address" +msgstr "" + +#: src/interface.py:613 +msgid "Client" +msgstr "" + +#: src/interface.py:614 +msgid "Percent Complete" +msgstr "" + +#: src/interface.py:651 +msgid "Download" +msgstr "" + +#: src/interface.py:652 +msgid "Filename" +msgstr "" + +#: src/interface.py:654 +msgid "Progress" +msgstr "" + +#: src/interface.py:781 +#, python-format +msgid "Paused %s" +msgstr "" + +#: src/interface.py:986 src/interface.py:999 msgid "Connections" msgstr "" -#: src/interface.py:956 +#: src/interface.py:999 msgid "Deluge Bittorrent Client" msgstr "" -#: src/interface.py:1121 +#: src/interface.py:1147 msgid "" "An error occured while trying to add the torrent. It's possible your ." "torrent file is corrupted." msgstr "" -#: src/interface.py:1123 +#: src/interface.py:1149 msgid "The torrent you've added seems to already be in Deluge." msgstr "" -#: src/interface.py:1127 +#: src/interface.py:1153 msgid "There is not enough free disk space to complete your download." msgstr "" -#: src/interface.py:1128 +#: src/interface.py:1154 msgid "Space Needed:" msgstr "" -#: src/interface.py:1129 +#: src/interface.py:1155 msgid "Available Space:" msgstr "" -#: src/interface.py:1141 +#: src/interface.py:1170 msgid "Add torrent from URL" msgstr "" -#: src/interface.py:1145 +#: src/interface.py:1174 msgid "Enter the URL of the .torrent to download" msgstr "" -#: src/interface.py:1246 +#: src/interface.py:1269 msgid "Warning - all downloaded files for this torrent will be deleted!" msgstr "" -#: src/dialogs.py:183 +#: src/dialogs.py:184 msgid "Plugin" msgstr "" -#: src/dialogs.py:185 +#: src/dialogs.py:186 msgid "Enabled" msgstr "" -#: src/dialogs.py:252 +#: src/dialogs.py:253 msgid "translator-credits" msgstr "" -#: src/dialogs.py:292 +#: src/dialogs.py:293 msgid "Choose a .torrent file" msgstr "" -#: src/dialogs.py:297 +#: src/dialogs.py:298 msgid "Torrent files" msgstr "" -#: src/dialogs.py:301 +#: src/dialogs.py:302 msgid "All files" msgstr "" -#: src/dialogs.py:322 +#: src/dialogs.py:323 msgid "Choose a download directory" msgstr "" diff --git a/src/core.py b/src/core.py index f1fed87f8..2df250b4e 100644 --- a/src/core.py +++ b/src/core.py @@ -860,3 +860,6 @@ class Manager: def replace_trackers(self, unique_ID, trackers): return deluge_core.replace_trackers(unique_ID, trackers) + + def set_flp(self, unique_ID, num): + return deluge_core.set_flp(unique_ID, int(num)) diff --git a/src/deluge_core.cpp b/src/deluge_core.cpp index 9cb3e9132..f80b076d3 100644 --- a/src/deluge_core.cpp +++ b/src/deluge_core.cpp @@ -1422,6 +1422,27 @@ static PyObject *torrent_replace_trackers(PyObject *self, PyObject *args) h.force_reannounce(); return Py_None; } +static PyObject *torrent_set_flp(PyObject *self, PyObject *args) +{ + python_long unique_ID; + int num; + if (!PyArg_ParseTuple(args, "ii", &unique_ID, &num)) + return NULL; + long index = get_index_from_unique_ID(unique_ID); + if (PyErr_Occurred()) + return NULL; + + torrent_t &t = M_torrents->at(index); + torrent_status s = t.handle.status(); + const torrent_info &i = t.handle.get_torrent_info(); + + int npieces = i.num_pieces(); + + t.handle.piece_priority(0, num); + t.handle.piece_priority(npieces, num); + + return Py_None; +} //==================== // Python Module data //==================== @@ -1468,6 +1489,7 @@ static PyMethodDef deluge_core_methods[] = {"proxy_settings", torrent_proxy_settings, METH_VARARGS, "."}, {"get_trackers", torrent_get_trackers, METH_VARARGS, "."}, {"replace_trackers", torrent_replace_trackers, METH_VARARGS, "."}, + {"set_flp", torrent_set_flp, METH_VARARGS, "."}, {NULL} }; diff --git a/src/interface.py b/src/interface.py index d112544af..058631eb8 100644 --- a/src/interface.py +++ b/src/interface.py @@ -202,13 +202,13 @@ class DelugeGTK: self.submenu_bwdownset = self.build_menu_radio_list( self.config.get("tray_downloadspeedlist"), self.tray_setbwdown, self.config.get("max_download_speed"), _("KiB/s"), - show_notset=True) + show_notset=True, show_other=True) # Create the Upload speed list sub-menu self.submenu_bwupset = self.build_menu_radio_list( self.config.get("tray_uploadspeedlist"), self.tray_setbwup, self.config.get("max_upload_speed"), _("KiB/s"), - show_notset=True) + show_notset=True, show_other=True) # Add the sub-menus to the tray menu self.tray_glade.get_widget("download_limit").set_submenu(self.submenu_bwdownset) @@ -220,44 +220,77 @@ class DelugeGTK: def build_menu_radio_list(self, value_list, callback, pref_value=None, suffix=None, show_notset=False, - notset_label=None, notset_lessthan=0, show_other=False): + notset_label=None, notset_lessthan=0, show_other=False, show_activated=False, activated_label=None): # Build a menu with radio menu items from a list and connect them to the callback # The pref_value is what you would like to test for the default active radio item # Setting show_unlimited will include an Unlimited radio item if notset_label is None: notset_label = _("Unlimited") + + if activated_label is None: + activated_label = _("Activated") + menu = gtk.Menu() - group = None - for value in sorted(value_list): - if suffix != None: - menuitem = gtk.RadioMenuItem(group, str(value) + " " + suffix) - else: - menuitem = gtk.RadioMenuItem(group, str(value)) + if show_activated is False: + for value in sorted(value_list): + if suffix != None: + menuitem = gtk.RadioMenuItem(group, str(value) + " " + suffix) + else: + menuitem = gtk.RadioMenuItem(group, str(value)) - group = menuitem + group = menuitem - if value == pref_value and pref_value != None: - menuitem.set_active(True) + if value == pref_value and pref_value != None: + menuitem.set_active(True) - if callback != None: - menuitem.connect("toggled", callback) + if callback != None: + menuitem.connect("toggled", callback) - menu.append(menuitem) + menu.append(menuitem) + + if show_activated is True: + for value in sorted(value_list): + menuitem = gtk.RadioMenuItem(group, str(activated_label)) + + group = menuitem + + if value == pref_value and pref_value != None: + menuitem.set_active(True) + + if callback != None: + menuitem.connect("toggled", callback) + + menu.append(menuitem) + + # if show_activated is True: +# for value in sorted(value_list): + # menuitem = gtk.RadioMenuItem(group, activated_label) + # group = menuitem +# + # if value == 1: + # menuitem.set_active(False) + # else: + # menuitem.set_active(True) + # menuitem.connect("toggled", callback) + # menu.append(menuitem) if show_notset: menuitem = gtk.RadioMenuItem(group, notset_label) if pref_value < notset_lessthan and pref_value != None: menuitem.set_active(True) + if show_activated and pref_value == 1: + menuitem.set_active(True) menuitem.connect("toggled", callback) menu.append(menuitem) # Add the Other... menuitem - menuitem = gtk.SeparatorMenuItem() - menu.append(menuitem) - menuitem = gtk.MenuItem(_("Other...")) - menuitem.connect("activate", callback) - menu.append(menuitem) + if show_other is True: + menuitem = gtk.SeparatorMenuItem() + menu.append(menuitem) + menuitem = gtk.MenuItem(_("Other...")) + menuitem.connect("activate", callback) + menu.append(menuitem) return menu