Skip to content

Commit

Permalink
0.2: Add right-click popup to change seed time.
Browse files Browse the repository at this point in the history
  • Loading branch information
gazpachoking committed Apr 19, 2012
1 parent 47e4e78 commit be9bdf6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
7 changes: 5 additions & 2 deletions seedtime/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from deluge.core.rpcserver import export

CONFIG_DEFAULT = {
"default_stop_time": 48,
"default_stop_time": 7,
"apply_stop_time": False,
"torrent_stop_times":{} # torrent_id: stop_time (in hours)
}
Expand Down Expand Up @@ -123,7 +123,10 @@ def get_config(self):

@export
def set_torrent(self, torrent_id , stop_time):
self.torrent_stop_times[torrent_id] = stop_time
if stop_time is None:
del self.torrent_stop_times[torrent_id]
else:
self.torrent_stop_times[torrent_id] = stop_time
self.config.save()

def _status_get_seed_stop_time(self, torrent_id):
Expand Down
48 changes: 48 additions & 0 deletions seedtime/gtkui.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,28 @@ def enable(self):
component.get("Preferences").add_page("SeedTime", self.glade.get_widget("prefs_box"))
component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs)
component.get("PluginManager").register_hook("on_show_prefs", self.on_show_prefs)
# Columns
torrentview = component.get("TorrentView")
torrentview.add_func_column(_("Seed Time"), cell_data_time, [int], status_field=["seeding_time"])
torrentview.add_func_column(_("Stop Seed Time"), cell_data_time, [int], status_field=["seed_stop_time"])
# Submenu
log.debug("add items to torrentview-popup menu.")
torrentmenu = component.get("MenuBar").torrentmenu
self.seedtime_menu = SeedTimeMenu()
torrentmenu.append(self.seedtime_menu)
self.seedtime_menu.show_all()

def disable(self):
component.get("Preferences").remove_page("SeedTime")
component.get("PluginManager").deregister_hook("on_apply_prefs", self.on_apply_prefs)
component.get("PluginManager").deregister_hook("on_show_prefs", self.on_show_prefs)
try:
# Columns
component.get("TorrentView").remove_column(_("Seed Time"))
component.get("TorrentView").remove_column(_("Stop Seed Time"))
# Submenu
torrentmenu = component.get("MenuBar").torrentmenu
torrentmenu.remove(self.seedtime_menu)
except Exception, e:
log.debug(e)

Expand Down Expand Up @@ -93,3 +104,40 @@ def cb_get_config(self, config):
log.debug('cb get config seedtime')
self.glade.get_widget("chk_apply_stop_time").set_active(config["apply_stop_time"])
self.glade.get_widget("txt_default_stop_time").set_text(str(config["default_stop_time"]))

class SeedTimeMenu(gtk.MenuItem):
def __init__(self):
gtk.MenuItem.__init__(self, "Seed Stop Time")

self.sub_menu = gtk.Menu()
self.set_submenu(self.sub_menu)
self.items = []

#attach..
torrentmenu = component.get("MenuBar").torrentmenu
self.sub_menu.connect("show", self.on_show, None)

def get_torrent_ids(self):
return component.get("TorrentView").get_selected_torrents()

def on_show(self, widget=None, data=None):
try:
for child in self.sub_menu.get_children():
self.sub_menu.remove(child)
# TODO: Make thise times customizable, and/or add a custom popup
for time in (None, 1, 2, 3, 7, 14, 30):
if time is None:
item = gtk.MenuItem('Never')
else:
item = gtk.MenuItem(str(time) + ' days')
item.connect("activate", self.on_select_time, time)
self.sub_menu.append(item)
self.show_all()
except Exception, e:
log.exception('AHH!')

def on_select_time(self, widget=None, time=None):
log.debug("select seed stop time:%s,%s" % (time ,self.get_torrent_ids()) )
for torrent_id in self.get_torrent_ids():
client.seedtime.set_torrent(torrent_id, time)

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
__plugin_name__ = "SeedTime"
__author__ = "Chase Sterling"
__author_email__ = "[email protected]"
__version__ = "0.1"
__version__ = "0.2"
__url__ = ""
__license__ = "GPLv3"
__description__ = ""
Expand Down

0 comments on commit be9bdf6

Please sign in to comment.