dbus changes
This commit is contained in:
79
delugegtk.py
79
delugegtk.py
@@ -20,16 +20,23 @@
|
|||||||
# 51 Franklin Street, Fifth Floor
|
# 51 Franklin Street, Fifth Floor
|
||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
import sys, os, gettext
|
import sys, os, os.path, gettext
|
||||||
import deluge, dcommon, dgtk
|
import deluge, dcommon, dgtk
|
||||||
import pygtk
|
import pygtk
|
||||||
pygtk.require('2.0')
|
pygtk.require('2.0')
|
||||||
import gtk, gtk.glade, gobject
|
import gtk, gtk.glade, gobject
|
||||||
import xdg, xdg.BaseDirectory
|
import xdg, xdg.BaseDirectory
|
||||||
|
import dbus, dbus.service
|
||||||
|
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
|
||||||
|
import dbus.glib
|
||||||
|
|
||||||
|
|
||||||
class DelugeGTK:
|
class DelugeGTK(dbus.service.Object):
|
||||||
def __init__(self):
|
def __init__(self, bus_name=dbus.service.BusName('org.deluge_torrent.Deluge',
|
||||||
|
bus=dbus.SessionBus()), object_path='/org/deluge_torrent/DelugeObject'):
|
||||||
|
dbus.service.Object.__init__(self, bus_name, object_path)
|
||||||
|
self.is_running = False
|
||||||
|
self.torrent_file_queue = []
|
||||||
#Start the Deluge Manager:
|
#Start the Deluge Manager:
|
||||||
self.manager = deluge.Manager("DE", "0500", "Deluge 0.5.0",
|
self.manager = deluge.Manager("DE", "0500", "Deluge 0.5.0",
|
||||||
os.path.expanduser("~") + "/Temp")
|
os.path.expanduser("~") + "/Temp")
|
||||||
@@ -38,6 +45,7 @@ class DelugeGTK:
|
|||||||
self.gladefile = dcommon.get_glade_file("delugegtk.glade")
|
self.gladefile = dcommon.get_glade_file("delugegtk.glade")
|
||||||
self.wtree = gtk.glade.XML(self.gladefile)
|
self.wtree = gtk.glade.XML(self.gladefile)
|
||||||
self.window = self.wtree.get_widget("main_window")
|
self.window = self.wtree.get_widget("main_window")
|
||||||
|
self.window.hide()
|
||||||
self.toolbar = self.wtree.get_widget("tb_middle")
|
self.toolbar = self.wtree.get_widget("tb_middle")
|
||||||
if(self.window):
|
if(self.window):
|
||||||
self.window.connect("destroy", self.quit)
|
self.window.connect("destroy", self.quit)
|
||||||
@@ -53,11 +61,11 @@ class DelugeGTK:
|
|||||||
## Create the preferences dialog
|
## Create the preferences dialog
|
||||||
self.prf = dgtk.PreferencesDialog()
|
self.prf = dgtk.PreferencesDialog()
|
||||||
|
|
||||||
actions = {
|
self.wtree.signal_autoconnect({
|
||||||
## File Menu
|
## File Menu
|
||||||
"new_torrent": self.new_torrent,
|
"new_torrent": self.new_torrent_clicked,
|
||||||
"add_torrent": self.add_torrent,
|
"add_torrent": self.add_torrent_clicked,
|
||||||
"remove_torrent" : self.remove_torrent,
|
"remove_torrent" : self.remove_torrent_clicked,
|
||||||
"menu_quit": self.quit,
|
"menu_quit": self.quit,
|
||||||
## Edit Menu
|
## Edit Menu
|
||||||
"pref_clicked": self.prf.show_pref,
|
"pref_clicked": self.prf.show_pref,
|
||||||
@@ -73,10 +81,11 @@ class DelugeGTK:
|
|||||||
"share_toggle": self.share_toggle,
|
"share_toggle": self.share_toggle,
|
||||||
## Help Menu
|
## Help Menu
|
||||||
"show_about_dialog": self.abt.show,
|
"show_about_dialog": self.abt.show,
|
||||||
|
## Toolbar
|
||||||
|
"update_tracker": self.update_tracker,
|
||||||
## Other events
|
## Other events
|
||||||
"torrentrow_click": self.torrentview_clicked,
|
"torrentrow_click": self.torrentview_clicked,
|
||||||
}
|
})
|
||||||
self.wtree.signal_autoconnect(actions)
|
|
||||||
|
|
||||||
## Create the torrent listview
|
## Create the torrent listview
|
||||||
self.view = self.wtree.get_widget("torrent_view")
|
self.view = self.wtree.get_widget("torrent_view")
|
||||||
@@ -87,7 +96,8 @@ class DelugeGTK:
|
|||||||
|
|
||||||
|
|
||||||
## Initializes the columns for the torrent_view
|
## Initializes the columns for the torrent_view
|
||||||
|
# Just found out there are built-in pygtk methods with similar functionality
|
||||||
|
# to these, perhaps I should look into using those.
|
||||||
self.queue_column = dgtk.add_text_column(self.view, "#", 1)
|
self.queue_column = dgtk.add_text_column(self.view, "#", 1)
|
||||||
self.name_column = dgtk.add_text_column(self.view, "Name", 2)
|
self.name_column = dgtk.add_text_column(self.view, "Name", 2)
|
||||||
self.size_column = dgtk.add_text_column(self.view, "Size", 3)
|
self.size_column = dgtk.add_text_column(self.view, "Size", 3)
|
||||||
@@ -124,6 +134,7 @@ class DelugeGTK:
|
|||||||
self.peer_upload_column = dgtk.add_text_column(self.peer_view, "Upload Rate", 4)
|
self.peer_upload_column = dgtk.add_text_column(self.peer_view, "Upload Rate", 4)
|
||||||
|
|
||||||
#Torrent Summary tab
|
#Torrent Summary tab
|
||||||
|
# Look into glade's widget prefix function
|
||||||
self.text_summary_title = self.wtree.get_widget("summary_title")
|
self.text_summary_title = self.wtree.get_widget("summary_title")
|
||||||
self.text_summary_total_size = self.wtree.get_widget("summary_total_size")
|
self.text_summary_total_size = self.wtree.get_widget("summary_total_size")
|
||||||
self.text_summary_pieces = self.wtree.get_widget("summary_pieces")
|
self.text_summary_pieces = self.wtree.get_widget("summary_pieces")
|
||||||
@@ -144,14 +155,46 @@ class DelugeGTK:
|
|||||||
|
|
||||||
## Interface created
|
## Interface created
|
||||||
|
|
||||||
## add torrents in manager to interface
|
## external_add_torrent should only be called from outside the class
|
||||||
for uid in self.manager.get_unique_IDs():
|
@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))
|
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)
|
||||||
|
|
||||||
|
|
||||||
## Start the timer that updates the interface
|
## Start the timer that updates the interface
|
||||||
def start(self):
|
def start(self, hidden=False):
|
||||||
|
if not hidden:
|
||||||
|
self.window.show()
|
||||||
|
# go through torrent files to add
|
||||||
|
#dummy preferences values:
|
||||||
|
use_default_download_location = True
|
||||||
|
default_download_location = "."
|
||||||
|
for torrent_file in self.torrent_file_queue:
|
||||||
|
print "adding torrent", torrent_file
|
||||||
|
try:
|
||||||
|
self.manager.add_torrent(torrent_file, ".", True)
|
||||||
|
except deluge.DelugeError:
|
||||||
|
print "duplicate torrent found, ignoring", torrent_file
|
||||||
|
## add torrents in manager to interface
|
||||||
|
for uid in self.manager.get_unique_IDs():
|
||||||
|
self.store.append(self.get_list_from_unique_id(uid))
|
||||||
gobject.timeout_add(1000, self.update)
|
gobject.timeout_add(1000, self.update)
|
||||||
|
try:
|
||||||
|
self.is_running = True
|
||||||
|
gtk.main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
self.manager.quit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Call via a timer to update the interface
|
## Call via a timer to update the interface
|
||||||
def update(self):
|
def update(self):
|
||||||
@@ -241,18 +284,21 @@ class DelugeGTK:
|
|||||||
return [unique_id, queue, name, size, progress, message,
|
return [unique_id, queue, name, size, progress, message,
|
||||||
seeds, peers, dlrate, ulrate, eta, share]
|
seeds, peers, dlrate, ulrate, eta, share]
|
||||||
|
|
||||||
def new_torrent(self, obj=None):
|
def new_torrent_clicked(self, obj=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def add_torrent(self, obj=None):
|
def add_torrent_clicked(self, obj=None):
|
||||||
torrent = dgtk.show_file_open_dialog()
|
torrent = dgtk.show_file_open_dialog()
|
||||||
if torrent is not None:
|
if torrent is not None:
|
||||||
uid = self.manager.add_torrent(torrent, ".", True)
|
uid = self.manager.add_torrent(torrent, ".", True)
|
||||||
self.store.append(self.get_list_from_unique_id(uid))
|
self.store.append(self.get_list_from_unique_id(uid))
|
||||||
|
|
||||||
def remove_torrent(self, obj=None):
|
def remove_torrent_clicked(self, obj=None):
|
||||||
self.manager.remove_torrent(self.get_selected_torrent(), False)
|
self.manager.remove_torrent(self.get_selected_torrent(), False)
|
||||||
|
|
||||||
|
def update_tracker(self, obj=None):
|
||||||
|
self.manager.update_tracker(get_selected_torrent())
|
||||||
|
|
||||||
def torrentview_clicked(self, widget, event):
|
def torrentview_clicked(self, widget, event):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -293,4 +339,3 @@ class DelugeGTK:
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
interface = DelugeGTK()
|
interface = DelugeGTK()
|
||||||
interface.start()
|
interface.start()
|
||||||
gtk.main()
|
|
@@ -25,8 +25,10 @@
|
|||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
import sys
|
||||||
|
import os, os.path
|
||||||
|
|
||||||
parser = OptionParser(usage="%prog [options] [actions]", version="%prog 0.5")
|
parser = OptionParser(usage="%prog [options] [actions]", version="%prog 0.5.0")
|
||||||
parser.add_option("--tray", dest="tray", help="start Deluge hidden in system tray",
|
parser.add_option("--tray", dest="tray", help="start Deluge hidden in system tray",
|
||||||
metavar="TRAY", action="store_true")
|
metavar="TRAY", action="store_true")
|
||||||
|
|
||||||
@@ -35,5 +37,38 @@ parser.add_option("--tray", dest="tray", help="start Deluge hidden in system tra
|
|||||||
if options.tray:
|
if options.tray:
|
||||||
print "Deluge will start in the system tray if available"
|
print "Deluge will start in the system tray if available"
|
||||||
|
|
||||||
|
print options
|
||||||
|
print args
|
||||||
|
|
||||||
|
import dbus
|
||||||
|
|
||||||
|
bus = dbus.SessionBus()
|
||||||
|
|
||||||
|
dbus_objects = dbus.Interface(bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus'), 'org.freedesktop.DBus').ListNames()
|
||||||
|
|
||||||
|
interface = None
|
||||||
|
|
||||||
|
if not "org.deluge_torrent.Deluge" in dbus_objects:
|
||||||
|
print "no existing Deluge session"
|
||||||
|
import delugegtk
|
||||||
|
interface = delugegtk.DelugeGTK()
|
||||||
|
for arg in args:
|
||||||
|
apath = os.path.abspath(arg)
|
||||||
|
if apath.endswith(".torrent"):
|
||||||
|
interface.external_add_torrent(apath)
|
||||||
|
else:
|
||||||
|
print "Error,", arg, " does not seem to be a .torrent file"
|
||||||
|
interface.start(hidden=options.tray)
|
||||||
|
else:
|
||||||
|
## This connects to the deluge interface
|
||||||
|
print "create proxy object"
|
||||||
|
proxy = bus.get_object('org.deluge_torrent.Deluge', '/org/deluge_torrent/DelugeObject')
|
||||||
|
print "create iface"
|
||||||
|
deluge_iface = dbus.Interface(proxy, 'org.deluge_torrent.DelugeInterface')
|
||||||
|
print "send to iface"
|
||||||
|
for arg in args:
|
||||||
|
apath = os.path.abspath(arg)
|
||||||
|
if apath.endswith(".torrent"):
|
||||||
|
deluge_iface.external_add_torrent(apath)
|
||||||
|
else:
|
||||||
|
print "Error,", arg, " does not seem to be a .torrent file"
|
||||||
|
Reference in New Issue
Block a user