This commit is contained in:
Zach Tibbitts 2007-02-14 22:43:48 +00:00
parent 3c0ab4a0f2
commit 8cacacb3bb
6 changed files with 316 additions and 254 deletions

View File

@ -44,18 +44,6 @@
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
<child>
<widget class="GtkCheckButton" id="chk_use_tray">
<property name="visible">True</property>
<property name="label" translatable="yes">Enable system tray icon</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="tray_toggle"/>
</widget>
<packing>
<property name="right_attach">2</property>
</packing>
</child>
<child> <child>
<widget class="GtkCheckButton" id="chk_min_on_close"> <widget class="GtkCheckButton" id="chk_min_on_close">
<property name="visible">True</property> <property name="visible">True</property>
@ -69,6 +57,18 @@
<property name="x_padding">12</property> <property name="x_padding">12</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkCheckButton" id="chk_use_tray">
<property name="visible">True</property>
<property name="label" translatable="yes">Enable system tray icon</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="tray_toggle"/>
</widget>
<packing>
<property name="right_attach">2</property>
</packing>
</child>
</widget> </widget>
</child> </child>
<child> <child>
@ -95,15 +95,13 @@
<property name="n_rows">2</property> <property name="n_rows">2</property>
<property name="n_columns">2</property> <property name="n_columns">2</property>
<child> <child>
<widget class="GtkFileChooserButton" id="download_path_button"> <widget class="GtkRadioButton" id="radio_ask_save">
<property name="visible">True</property> <property name="visible">True</property>
<property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property> <property name="label" translatable="yes">Ask me where to save each download</property>
<property name="draw_indicator">True</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -119,13 +117,15 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkRadioButton" id="radio_ask_save"> <widget class="GtkFileChooserButton" id="download_path_button">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Ask me where to save each download</property> <property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER</property>
<property name="draw_indicator">True</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing> </packing>
</child> </child>
</widget> </widget>
@ -154,6 +154,14 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="n_rows">1</property> <property name="n_rows">1</property>
<property name="n_columns">2</property> <property name="n_columns">2</property>
<child>
<widget class="GtkCheckButton" id="chk_autoseed">
<property name="visible">True</property>
<property name="label" translatable="yes">Stop seeding torrents when
their share ratio reaches:</property>
<property name="draw_indicator">True</property>
</widget>
</child>
<child> <child>
<widget class="GtkSpinButton" id="ratio_spinner"> <widget class="GtkSpinButton" id="ratio_spinner">
<property name="visible">True</property> <property name="visible">True</property>
@ -171,14 +179,6 @@
<property name="x_options"></property> <property name="x_options"></property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkCheckButton" id="chk_autoseed">
<property name="visible">True</property>
<property name="label" translatable="yes">Stop seeding torrents when
their share ratio reaches:</property>
<property name="draw_indicator">True</property>
</widget>
</child>
</widget> </widget>
</child> </child>
<child> <child>
@ -272,53 +272,13 @@ their share ratio reaches:</property>
<placeholder/> <placeholder/>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="label25"> <widget class="GtkButton" id="btn_test_port">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Try from:</property> <property name="label" translatable="yes">Test Port</property>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label26">
<property name="visible">True</property>
<property name="label" translatable="yes">to:</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_port_min">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0.5</property>
<property name="adjustment">0 0 65535 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_port_max">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0.5</property>
<property name="adjustment">0 0 65535 1 10 10</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">3</property> <property name="left_attach">3</property>
<property name="right_attach">4</property> <property name="right_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label27">
<property name="visible">True</property>
<property name="label" translatable="yes">Active port:</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property> <property name="top_attach">1</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">2</property>
</packing> </packing>
@ -336,17 +296,57 @@ their share ratio reaches:</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkButton" id="btn_test_port"> <widget class="GtkLabel" id="label27">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Test Port</property> <property name="label" translatable="yes">Active port:</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="GtkSpinButton" id="spin_port_max">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0.5</property>
<property name="adjustment">0 0 65535 1 10 10</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">3</property> <property name="left_attach">3</property>
<property name="right_attach">4</property> <property name="right_attach">4</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkSpinButton" id="spin_port_min">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="xalign">0.5</property>
<property name="adjustment">0 0 65535 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label26">
<property name="visible">True</property>
<property name="label" translatable="yes">to:</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label25">
<property name="visible">True</property>
<property name="label" translatable="yes">Try from:</property>
</widget>
</child>
</widget> </widget>
</child> </child>
<child> <child>
@ -373,94 +373,62 @@ their share ratio reaches:</property>
<property name="n_rows">5</property> <property name="n_rows">5</property>
<property name="n_columns">3</property> <property name="n_columns">3</property>
<child> <child>
<widget class="GtkLabel" id="label9"> <widget class="GtkLabel" id="label4">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">&lt;i&gt;(0 is unlimited)&lt;/i&gt;</property> <property name="xalign">0</property>
<property name="use_markup">True</property> <property name="label" translatable="yes">Maximum Upload Rate:</property>
</widget> </widget>
<packing> <packing>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="label" translatable="yes">KB/s</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label7">
<property name="visible">True</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>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">KB/s</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property> <property name="top_attach">1</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">2</property>
<property name="x_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="label5"> <widget class="GtkLabel" id="label3">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum number of Uploads:</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">2</property> <property name="top_attach">2</property>
<property name="right_attach">3</property> <property name="bottom_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkSpinButton" id="spin_num_download"> <widget class="GtkLabel" id="label2">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="xalign">0</property>
<property name="width_chars">10</property> <property name="label" translatable="yes">Maximum Download Rate:</property>
<property name="xalign">1</property>
<property name="adjustment">0 0 100 1 10 10</property>
</widget> </widget>
<packing> <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>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_download">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width_chars">10</property>
<property name="xalign">1</property>
<property name="adjustment">0 0 100 1 10 10</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property> <property name="top_attach">3</property>
<property name="bottom_attach">4</property> <property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum number of Downloads:</property>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_upload">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width_chars">10</property>
<property name="xalign">1</property>
<property name="adjustment">0 0 100 1 10 10</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>
<property name="x_options"></property> <property name="x_options"></property>
</packing> </packing>
</child> </child>
@ -481,7 +449,7 @@ their share ratio reaches:</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkSpinButton" id="spin_max_upload"> <widget class="GtkSpinButton" id="spin_max_download">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="width_chars">10</property> <property name="width_chars">10</property>
@ -491,53 +459,85 @@ their share ratio reaches:</property>
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_num_download">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width_chars">10</property>
<property name="xalign">1</property>
<property name="adjustment">0 0 100 1 10 10</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>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label5">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">KB/s</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property> <property name="top_attach">1</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">2</property>
<property name="x_options"></property> <property name="x_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="label1"> <widget class="GtkLabel" id="label7">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum number of Downloads:</property>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Download Rate:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum number of Uploads:</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property> <property name="top_attach">2</property>
<property name="bottom_attach">3</property> <property name="bottom_attach">3</property>
<property name="x_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="label4"> <widget class="GtkLabel" id="label8">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0</property> <property name="label" translatable="yes">KB/s</property>
<property name="label" translatable="yes">Maximum Upload Rate:</property>
</widget> </widget>
<packing> <packing>
<property name="top_attach">1</property> <property name="left_attach">2</property>
<property name="bottom_attach">2</property> <property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;i&gt;(0 is unlimited)&lt;/i&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="right_attach">3</property>
</packing> </packing>
</child> </child>
</widget> </widget>
@ -640,16 +640,11 @@ their share ratio reaches:</property>
<property name="n_rows">2</property> <property name="n_rows">2</property>
<property name="n_columns">2</property> <property name="n_columns">2</property>
<child> <child>
<widget class="GtkTextView" id="plugin_text1"> <widget class="GtkTreeView" id="plugin_view">
<property name="visible">True</property> <property name="visible">True</property>
<property name="editable">False</property>
<property name="wrap_mode">GTK_WRAP_WORD</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">1</property> <property name="bottom_attach">2</property>
<property name="right_attach">2</property>
<property name="x_padding">10</property>
<property name="y_padding">10</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -684,11 +679,16 @@ their share ratio reaches:</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkTreeView" id="plugin_view1"> <widget class="GtkTextView" id="plugin_text">
<property name="visible">True</property> <property name="visible">True</property>
<property name="editable">False</property>
<property name="wrap_mode">GTK_WRAP_WORD</property>
</widget> </widget>
<packing> <packing>
<property name="bottom_attach">2</property> <property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_padding">10</property>
<property name="y_padding">10</property>
</packing> </packing>
</child> </child>
</widget> </widget>
@ -718,16 +718,12 @@ their share ratio reaches:</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
<property name="layout_style">GTK_BUTTONBOX_END</property> <property name="layout_style">GTK_BUTTONBOX_END</property>
<child> <child>
<widget class="GtkButton" id="button9"> <placeholder/>
<property name="visible">True</property>
<property name="label" translatable="yes">gtk-cancel</property>
<property name="use_stock">True</property>
</widget>
</child> </child>
<child> <child>
<widget class="GtkButton" id="button10"> <widget class="GtkButton" id="button10">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">gtk-ok</property> <property name="label" translatable="yes">gtk-close</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
</widget> </widget>
<packing> <packing>

View File

@ -4,16 +4,23 @@ class plugin_Example:
def __init__(self, deluge_core, deluge_interface): def __init__(self, deluge_core, deluge_interface):
self.core = deluge_core self.core = deluge_core
self.interface = deluge_interface self.interface = deluge_interface
print "Example Plugin loaded"
def unload(self): def unload(self):
pass print "Example Plugin unloaded"
def update(self): def update(self):
pass print "Hello World, from Example Plugin"
register_plugin("Example", register_plugin("Example Plugin",
plugin_Example, plugin_Example,
"0.2", "0.2",
"An example plugin", "An example plugin",
requires="0.5.0") config=True,
default=False,
requires="0.5.0",
interface="gtk",
required_plugins=None)

View File

@ -19,10 +19,13 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
import sys, os, os.path, webbrowser import sys, os, os.path, webbrowser
import xdg, xdg.BaseDirectory
PROGRAM_NAME = "Deluge" PROGRAM_NAME = "Deluge"
PROGRAM_VERSION = "0.4.9.0" PROGRAM_VERSION = "0.4.9.0"
CONFIG_DIR = xdg.BaseDirectory.save_config_path('deluge-svn')
GLADE_DIR = sys.prefix + '/share/deluge/glade' GLADE_DIR = sys.prefix + '/share/deluge/glade'
PIXMAP_DIR = sys.prefix + '/share/deluge/pixmaps' PIXMAP_DIR = sys.prefix + '/share/deluge/pixmaps'
PLUGIN_DIR = sys.prefix + '/share/deluge/plugins' PLUGIN_DIR = sys.prefix + '/share/deluge/plugins'

View File

@ -21,7 +21,7 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
import sys, os, os.path, gettext, urllib import sys, os, os.path, gettext, urllib
import deluge, dcommon, dgtk import deluge, dcommon, dgtk, delugeplugins
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk, gtk.glade, gobject import gtk, gtk.glade, gobject
@ -33,13 +33,27 @@ if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
_ = gettext.gettext _ = gettext.gettext
class DelugeGTK(dbus.service.Object): class DelugeGTK(dbus.service.Object):
## external_add_torrent should only be called from outside the class
@dbus.service.method('org.deluge_torrent.DelugeInterface')
def external_add_torrent(self, torrent_file):
print "Ding!"
print "Got torrent externally:", os.path.basename(torrent_file)
print "\tNow, what to do with it?"
if self.is_running:
print "\t\tthe client seems to already be running, i'll try and add the torrent"
uid = self.manager.add_torrent(torrent_file, ".", True)
self.store.append(self.get_list_from_unique_id(uid))
else:
print "\t\tthe client hasn't started yet, I'll queue the torrent"
self.torrent_file_queue.append(torrent_file)
def __init__(self, bus_name=dbus.service.BusName('org.deluge_torrent.Deluge', def __init__(self, bus_name=dbus.service.BusName('org.deluge_torrent.Deluge',
bus=dbus.SessionBus()), object_path='/org/deluge_torrent/DelugeObject'): bus=dbus.SessionBus()), object_path='/org/deluge_torrent/DelugeObject'):
dbus.service.Object.__init__(self, bus_name, object_path) dbus.service.Object.__init__(self, bus_name, object_path)
self.is_running = False self.is_running = False
self.torrent_file_queue = [] self.torrent_file_queue = []
#Load up a config file: #Load up a config file:
self.conf_file = xdg.BaseDirectory.save_config_path("deluge-svn") + '/deluge.conf' self.conf_file = dcommon.CONFIG_DIR + '/deluge.conf'
if os.path.isdir(self.conf_file): if os.path.isdir(self.conf_file):
print 'Weird, the file I was trying to write to, %s, is an existing directory'%(self.conf_file) print 'Weird, the file I was trying to write to, %s, is an existing directory'%(self.conf_file)
sys.exit(0) sys.exit(0)
@ -51,8 +65,7 @@ class DelugeGTK(dbus.service.Object):
self.load_default_settings() self.load_default_settings()
self.pref.load_from_file(self.conf_file) self.pref.load_from_file(self.conf_file)
#Start the Deluge Manager: #Start the Deluge Manager:
self.manager = deluge.Manager("DE", "0490", "Deluge 0.4.9", self.manager = deluge.Manager("DE", "0490", "Deluge 0.4.9", dcommon.CONFIG_DIR)
xdg.BaseDirectory.save_config_path("deluge-svn"))
#Set up the interface: #Set up the interface:
self.wtree = gtk.glade.XML(dcommon.get_glade_file("delugegtk.glade")) self.wtree = gtk.glade.XML(dcommon.get_glade_file("delugegtk.glade"))
self.window = self.wtree.get_widget("main_window") self.window = self.wtree.get_widget("main_window")
@ -63,11 +76,16 @@ class DelugeGTK(dbus.service.Object):
self.window.set_title('%s %s'%(dcommon.PROGRAM_NAME, dcommon.PROGRAM_VERSION)) self.window.set_title('%s %s'%(dcommon.PROGRAM_NAME, dcommon.PROGRAM_VERSION))
self.window.set_icon_from_file(dcommon.get_pixmap("deluge32.png")) self.window.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
self.plugins = delugeplugins.PluginManager(self.manager, self)
self.plugins.add_plugin_dir(dcommon.PLUGIN_DIR)
if os.path.isdir(dcommon.CONFIG_DIR + '/plugins'):
self.plugins.add_plugin_dir(dcommon.CONFIG_DIR + '/plugins')
self.plugins.scan_for_plugins()
## Construct the Interface ## Construct the Interface
self.build_tray_icon() self.build_tray_icon()
self.build_about_dialog() self.build_about_dialog()
self.build_pref_dialog() self.build_pref_dialog()
self.build_plugin_dialog()
self.build_torrent_table() self.build_torrent_table()
self.build_summary_tab() self.build_summary_tab()
self.build_file_tab() self.build_file_tab()
@ -164,9 +182,14 @@ class DelugeGTK(dbus.service.Object):
self.prf = self.prf_glade.get_widget("pref_dialog") self.prf = self.prf_glade.get_widget("pref_dialog")
self.prf.set_icon_from_file(dcommon.get_pixmap("deluge32.png")) self.prf.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
self.prf_glade.signal_autoconnect({"tray_toggle": self.tray_toggle,}) self.prf_glade.signal_autoconnect({"tray_toggle": self.tray_toggle,})
self.plugin_dlg = self.prf_glade.get_widget("plugin_dialog")
def build_plugin_dialog(self): self.plugin_dlg.set_icon_from_file(dcommon.get_pixmap("deluge32.png"))
pass self.plugin_view = self.prf_glade.get_widget("plugin_view")
self.plugin_store = gtk.ListStore(str, bool)
self.plugin_view.set_model(self.plugin_store)
dgtk.add_text_column(self.plugin_view, "Name", 0)
dgtk.add_toggle_column(self.plugin_view, "Enabled", 1, toggled_signal=self.plugin_toggled)
def build_torrent_table(self): def build_torrent_table(self):
## Create the torrent listview ## Create the torrent listview
@ -312,8 +335,26 @@ class DelugeGTK(dbus.service.Object):
self.apply_prefs() self.apply_prefs()
def show_plugin_dialog(self, arg=None): def show_plugin_dialog(self, arg=None):
pass self.plugin_store.clear()
for plugin in self.plugins.get_available_plugins():
self.plugin_store.append( (plugin, False) )
self.plugin_dlg.show()
self.plugin_dlg.run()
self.plugin_dlg.hide()
def plugin_toggled(self, renderer, path):
plugin_iter = self.plugin_store.get_iter_from_string(path)
plugin_name = self.plugin_store.get_value(plugin_iter, 0)
plugin_value = not self.plugin_store.get_value(plugin_iter, 1)
self.plugin_store.set_value(plugin_iter, 1, plugin_value)
print "Plugin:", plugin_name, renderer.get_active()
if plugin_value:
self.plugins.enable_plugin(plugin_name)
else:
self.plugins.disable_plugin(plugin_name)
def tray_toggle(self, obj): def tray_toggle(self, obj):
if obj.get_active(): if obj.get_active():
self.prf_glade.get_widget("chk_min_on_close").set_sensitive(True) self.prf_glade.get_widget("chk_min_on_close").set_sensitive(True)
@ -321,22 +362,28 @@ class DelugeGTK(dbus.service.Object):
self.prf_glade.get_widget("chk_min_on_close").set_sensitive(False) self.prf_glade.get_widget("chk_min_on_close").set_sensitive(False)
def apply_prefs(self):
pass
## external_add_torrent should only be called from outside the class # UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
@dbus.service.method('org.deluge_torrent.DelugeInterface') def get_list_from_unique_id(self, unique_id):
def external_add_torrent(self, torrent_file): state = self.manager.get_torrent_state(unique_id)
print "Ding!" queue = int(state['queue_pos']) + 1
print "Got torrent externally:", os.path.basename(torrent_file) name = state['name']
print "\tNow, what to do with it?" size = dcommon.fsize(state['total_size'])
if self.is_running: progress = float(state['progress'] * 100)
print "\t\tthe client seems to already be running, i'll try and add the torrent" message = '%s %d%%'%(deluge.STATE_MESSAGES[state['state']], int(state['progress'] * 100))
uid = self.manager.add_torrent(torrent_file, ".", True) seeds = dcommon.fseed(state)
self.store.append(self.get_list_from_unique_id(uid)) peers = dcommon.fpeer(state)
else: dlrate = dcommon.frate(state['download_rate'])
print "\t\tthe client hasn't started yet, I'll queue the torrent" ulrate = dcommon.frate(state['upload_rate'])
self.torrent_file_queue.append(torrent_file) eta = dcommon.estimate_eta(state)
share = self.calc_share_ratio(unique_id, state)
return [unique_id, queue, name, size, progress, message,
seeds, peers, dlrate, ulrate, eta, share]
## Start the timer that updates the interface ## Start the timer that updates the interface
def start(self, hidden=False): def start(self, hidden=False):
if not hidden: if not hidden:
@ -360,34 +407,7 @@ class DelugeGTK(dbus.service.Object):
gtk.main() gtk.main()
except KeyboardInterrupt: except KeyboardInterrupt:
self.manager.quit() self.manager.quit()
def show_pref(self, o=None):
self.pref = self.prf.show_dlg(self.pref)
def show_plugins(self, o=None):
pass
def apply_prefs(self):
for k in self.pref.keys():
print k, self.pref.get(k)
# UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
def get_list_from_unique_id(self, unique_id):
state = self.manager.get_torrent_state(unique_id)
queue = int(state['queue_pos']) + 1
name = state['name']
size = dcommon.fsize(state['total_size'])
progress = float(state['progress'] * 100)
message = '%s %d%%'%(deluge.STATE_MESSAGES[state['state']], int(state['progress'] * 100))
seeds = dcommon.fseed(state)
peers = dcommon.fpeer(state)
dlrate = dcommon.frate(state['download_rate'])
ulrate = dcommon.frate(state['upload_rate'])
eta = dcommon.estimate_eta(state)
share = self.calc_share_ratio(unique_id, state)
return [unique_id, queue, name, size, progress, message,
seeds, peers, dlrate, ulrate, eta, share]
## Call via a timer to update the interface ## Call via a timer to update the interface
def update(self): def update(self):
@ -396,6 +416,9 @@ class DelugeGTK(dbus.service.Object):
tab = self.wtree.get_widget("torrent_info").get_current_page() tab = self.wtree.get_widget("torrent_info").get_current_page()
except AttributeError: except AttributeError:
return False return False
self.plugins.update_active_plugins()
# If no torrent is selected, select the first torrent: # If no torrent is selected, select the first torrent:
(temp, selection) = self.view.get_selection().get_selected() (temp, selection) = self.view.get_selection().get_selected()
if selection is None: if selection is None:
@ -404,6 +427,7 @@ class DelugeGTK(dbus.service.Object):
itr = self.store.get_iter_first() itr = self.store.get_iter_first()
if itr is None: if itr is None:
return True return True
while itr is not None: while itr is not None:
uid = self.store.get_value(itr, 0) uid = self.store.get_value(itr, 0)
try: try:
@ -419,6 +443,8 @@ class DelugeGTK(dbus.service.Object):
self.saved_peer_info = None self.saved_peer_info = None
if tab == 0: #Details Pane if tab == 0: #Details Pane
try: try:
state = self.manager.get_torrent_state(self.get_selected_torrent()) state = self.manager.get_torrent_state(self.get_selected_torrent())

View File

@ -23,9 +23,12 @@
import os import os
class PluginManager: class PluginManager:
def __init__(self): def __init__(self, deluge_core, deluge_interface):
self.plugin_dirs = [] self.plugin_dirs = []
self.plugins = {} self.available_plugins = {}
self.enabled_plugins = {}
self.core = deluge_core
self.interface = deluge_interface
def add_plugin_dir(self, directory): def add_plugin_dir(self, directory):
self.plugin_dirs.append(directory) self.plugin_dirs.append(directory)
@ -33,11 +36,30 @@ class PluginManager:
def scan_for_plugins(self): def scan_for_plugins(self):
register_plugin = self.register_plugin register_plugin = self.register_plugin
for folder in self.plugin_dirs: for folder in self.plugin_dirs:
print "Looking in", folder
plugin_folders = os.listdir(folder) plugin_folders = os.listdir(folder)
for plugin in plugin_folders: for plugin in plugin_folders:
if os.path.isfile(folder + plugin + "/plugin.py"): if os.path.isfile(folder + "/" + plugin + "/plugin.py"):
execfile(folder + plugin + "/plugin.py") execfile(folder + "/" + plugin + "/plugin.py")
def get_available_plugins(self):
return self.available_plugins.keys()
def get_plugin(self, name):
return self.available_plugins[name]
def enable_plugin(self, name):
self.enabled_plugins[name] = self.available_plugins[name]['class'](self.core, self.interface)
def get_enabled_plugins(self):
return self.enabled_plugins.keys()
def disable_plugin(self, name):
self.enabled_plugins[name].unload()
self.enabled_plugins.pop(name)
def update_active_plugins(self):
for name in self.enabled_plugins.keys():
self.enabled_plugins[name].update()
def register_plugin(self, def register_plugin(self,
name, name,
@ -49,7 +71,15 @@ class PluginManager:
requires=None, requires=None,
interface=None, interface=None,
required_plugins=None): required_plugins=None):
self.plugins[name] = (plugin_class, version, description, config, default, requires, interface, required_plugins) self.available_plugins[name] = {'class': plugin_class,
'version': version,
'description': description,
'config': config,
'default': default,
'requires': requires,
'interface': interface,
'req plugins': required_plugins
}
## Few lines of code to test functionality ## Few lines of code to test functionality
if __name__ == "__main__": if __name__ == "__main__":
@ -59,4 +89,4 @@ if __name__ == "__main__":
for x in p.plugins: for x in p.plugins:
print x print x
for y in p.plugins[x]: for y in p.plugins[x]:
print "\t", y print "\t", y

View File

@ -91,5 +91,5 @@ def add_toggle_column(view, header, cid, toggled_signal=None):
column.set_expand(False) column.set_expand(False)
view.append_column(column) view.append_column(column)
if toggled_signal is not None: if toggled_signal is not None:
render.connect("toggled", toggled_signal, cid) render.connect("toggled", toggled_signal)
return column return column