Merge lp:~fresh13/dockmanager/deluge_helper into lp:dockmanager

Proposed by Igor Gevka
Status: Merged
Merged at revision: 94
Proposed branch: lp:~fresh13/dockmanager/deluge_helper
Merge into: lp:dockmanager
Diff against target: 164 lines (+77/-28)
2 files modified
metadata/deluge_badge.py.info (+1/-1)
scripts/deluge_badge.py (+76/-27)
To merge this branch: bzr merge lp:~fresh13/dockmanager/deluge_helper
Reviewer Review Type Date Requested Status
Dockers Pending
Review via email: mp+51229@code.launchpad.net

Commit message

Updated deluge helper to work with new deluge api (1.2+), added Pause All/Resume All helper context menu items and made helper display only bandwiths over 5kbps (so when deluge runs with no active downloads, overhead bandwidths of 1-2kbps do not pop up on the badge.

Description of the change

Updated deluge helper to work with new deluge api (1.2+), added Pause All/Resume All helper context menu items and made helper display only bandwiths over 5kbps (so when deluge runs with no active downloads, overhead bandwidths of 1-2kbps do not pop up on the badge.

Deluge version 1.2 (from jan 10, 2010) changed deluge API considerably, and deluge helper stopped working (bug#507184 https://bugs.launchpad.net/docky/+bug/507184). Based on the work of launchpad user Cas, I have released a patch that later got featured on OMGUbuntu: http://www.omgubuntu.co.uk/2010/10/deluge-docky-helper-fix-working/

Somebody in the comments suggested that the patch gets proposed into dockmanager trunk, so (after 4 months) I finally got my hands into this issue, patched the original helper (before it was a standalone helper called deluge 1.2) and am now committing it to launchpad.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'metadata/deluge_badge.py.info'
2--- metadata/deluge_badge.py.info 2010-06-05 13:03:27 +0000
3+++ metadata/deluge_badge.py.info 2011-02-24 23:12:49 +0000
4@@ -1,5 +1,5 @@
5 [DockmanagerHelper]
6 Name=Deluge
7-Description=Show transfer rates
8+Description=Show transfer rates and Pause All/Resume All buttons. You have to run deluge daemonized: sudo apt-get install deluged && deluged
9 Icon=deluge
10 AppName=deluge
11
12=== modified file 'scripts/deluge_badge.py'
13--- scripts/deluge_badge.py 2010-08-06 23:14:20 +0000
14+++ scripts/deluge_badge.py 2011-02-24 23:12:49 +0000
15@@ -1,7 +1,7 @@
16 #!/usr/bin/env python
17
18 #
19-# Copyright (C) 2010 Rico Tzschichholz, Robert Dyer
20+# Copyright (C) 2010 Rico Tzschichholz, Robert Dyer, Igor Gevka
21 #
22 # This program is free software: you can redistribute it and/or modify
23 # it under the terms of the GNU General Public License as published by
24@@ -18,24 +18,59 @@
25 #
26
27 import atexit
28-import gobject
29-import dbus
30-import dbus.glib
31-import glib
32-import sys
33-import os
34-import math
35+
36+from twisted.internet import glib2reactor # for gtk-2.0
37+glib2reactor.install()
38
39 try:
40- from deluge.ui.client import sclient
41+ from deluge.ui.client import client
42+ from twisted.internet import reactor
43 from dockmanager.dockmanager import DockManagerItem, DockManagerSink, DOCKITEM_IFACE
44 from signal import signal, SIGTERM
45 from sys import exit
46+ from gobject import timeout_add
47 except ImportError, e:
48 print e
49 exit()
50
51-ShowUploadRate = False
52+debugConnections = False
53+showRateOver = 5000
54+rate = 0
55+
56+delugeDaemon = None
57+
58+def daemon_disconnect_callback():
59+ if debugConnections:
60+ print "Disconnected from deluge daemon. Will try to reconnect."
61+ ConnectToDaemon()
62+
63+def ConnectToDaemon():
64+ global delugeDaemon
65+ host="localhost"
66+ port=58846
67+ user=""
68+ password=""
69+ client.set_disconnect_callback(daemon_disconnect_callback)
70+ if debugConnections:
71+ print "Connecting to deluge daemon..."
72+ delugeDaemon = client.connect(host, port, user, password)
73+
74+ConnectToDaemon()
75+
76+def on_connect_success(result):
77+ def on_get_config_value(value, key):
78+ global rate
79+ rate=value[key]
80+ client.core.get_session_status(["download_rate"]).addCallback(on_get_config_value,"download_rate")
81+
82+def on_connect_fail(result):
83+ if debugConnections:
84+ print "Connection failed with result ", result, ", reconnecting."
85+ global rate
86+ rate = 0
87+ ConnectToDaemon()
88+ return False
89+
90
91
92 def bytes2ratestr(bytes):
93@@ -57,30 +92,46 @@
94 DockManagerItem.__init__(self, sink, path)
95
96 self.timer = 0
97-
98- sclient.set_core_uri()
99-
100+
101 if not self.timer > 0:
102- self.timer = gobject.timeout_add (2000, self.update_badge)
103+ self.timer = timeout_add (2000, self.update_badge)
104+
105+ self.set_menu_buttons()
106
107 def update_badge(self):
108- rate = 0
109+ global delugeDaemon
110+ global rate
111 try:
112- if ShowUploadRate:
113- rate = round(sclient.get_upload_rate())
114- else:
115- rate = round(sclient.get_download_rate())
116-
117- if rate > 0:
118- self.set_badge("%s" % bytes2ratestr(rate))
119+ delugeDaemon.addCallback(on_connect_success)
120+ delugeDaemon.addErrback(on_connect_fail)
121+
122+ if rate > showRateOver:
123+ self.set_badge("%s" % bytes2ratestr(round(rate)))
124 else:
125 self.reset_badge()
126 return True
127 except Exception, e:
128- print e
129+ print "Deluge badge exception:", e
130 self.reset_badge()
131 return False
132
133+ def clear_menu_buttons(self):
134+ for k in self.id_map.keys():
135+ self.remove_menu_item(k)
136+
137+ def set_menu_buttons(self):
138+ self.clear_menu_buttons()
139+
140+ self.add_menu_item("Pause All", "media-playback-pause")
141+ self.add_menu_item("Resume All", "media-playback-start")
142+
143+ def menu_pressed(self, menu_id):
144+
145+ if self.id_map[menu_id] == "Pause All":
146+ client.core.pause_all_torrents()
147+ elif self.id_map[menu_id] == "Resume All":
148+ client.core.resume_all_torrents()
149+
150
151 class DelugeSink(DockManagerSink):
152 def item_path_found(self, pathtoitem, item):
153@@ -93,9 +144,7 @@
154 delugesink.dispose ()
155
156 if __name__ == "__main__":
157- mainloop = gobject.MainLoop(is_running=True)
158-
159 atexit.register (cleanup)
160 signal(SIGTERM, lambda signum, stack_frame: exit(1))
161-
162- mainloop.run()
163+ reactor.run()
164+

Subscribers

People subscribed via source and target branches

to status/vote changes: