gget r42 - in trunk: . gget
- From: johans svn gnome org
- To: svn-commits-list gnome org
- Subject: gget r42 - in trunk: . gget
- Date: Fri, 1 Aug 2008 11:52:00 +0000 (UTC)
Author: johans
Date: Fri Aug 1 11:52:00 2008
New Revision: 42
URL: http://svn.gnome.org/viewvc/gget?rev=42&view=rev
Log:
Redesigned DBus interface to be more object oriented based on comments from Luiz Dentz. Still not totally stable as I would like to use dbus properties, but not sure how to implement that yet.
Modified:
trunk/configure.ac
trunk/gget/DBusService.py
trunk/gget/Download.py
trunk/gget/Main.py
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Fri Aug 1 11:52:00 2008
@@ -53,6 +53,7 @@
pygobject-2.0 >= 2.12.0
gnome-python-2.0 >= 2.16.0
gnome-python-extras-2.0 >= 2.14.2
+ dbus-python >= 0.82
notify-python >= 0.1.1)
AC_OUTPUT([
Modified: trunk/gget/DBusService.py
==============================================================================
--- trunk/gget/DBusService.py (original)
+++ trunk/gget/DBusService.py Fri Aug 1 11:52:00 2008
@@ -18,6 +18,8 @@
# along with gget; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+import os.path
+
import gtk.gdk
import AddDownloadDialog
@@ -39,8 +41,12 @@
sys.exit(1)
SERVICE = "org.gnome.GGet"
-OBJECT_PATH = "/org/gnome/GGet"
-INTERFACE = "org.gnome.GGet"
+MAIN_WINDOW_OBJ_PATH = "/org/gnome/GGet/MainWindow"
+MAIN_WINDOW_IFACE = "org.gnome.GGet.MainWindow"
+DOWNLOAD_MGR_OBJ_PATH = "/org/gnome/GGet/DownloadManager"
+DOWNLOAD_MGR_IFACE = "org.gnome.GGet.DownloadManager"
+DOWNLOADS_OBJ_PATH = "/org/gnome/GGet/downloads"
+DOWNLOAD_IFACE = "org.gnome.GGet.Download"
class DBusService(object):
"""Singleton representing the DBus service"""
@@ -54,7 +60,7 @@
return DBusService.instance
def __init(self, *args):
- self.download_list = args[0]
+ self.download_objects = []
def register(self):
"""Tries to registers the DBus service and its exposed objects. Returns
@@ -65,24 +71,58 @@
try:
Utils.take_dbus_name(SERVICE, bus=self.session_bus)
except Utils.DBusNameExistsException, e:
- obj = self.session_bus.get_object(SERVICE, OBJECT_PATH)
- self.gget_object = dbus.Interface(obj, INTERFACE)
+ self.download_manager = self.get_interface(DOWNLOAD_MGR_OBJ_PATH,
+ DOWNLOAD_MGR_IFACE)
+
Utils.debug_print("The %s DBus service (%s) is already registered on the session bus." % (NAME, SERVICE))
return False
Utils.debug_print("The %s DBus service (%s) was sucessfully registered on the session bus." % (NAME, SERVICE))
- self.__register_objects()
+ self.bus_name = dbus.service.BusName(SERVICE, bus=self.session_bus)
return True
- def __register_objects(self):
- """Registers the GGet DBus service object."""
- bus_name = dbus.service.BusName(SERVICE, bus=self.session_bus)
- self.gget_object = GGetObject(bus_name, self.download_list)
-
-class GGetObject(dbus.service.Object):
- def __init__(self, bus_name, download_list):
- dbus.service.Object.__init__(self, bus_name, OBJECT_PATH)
+ def get_interface(self, object_path, interface):
+ """Returns a DBus interface from an object path."""
+ obj = self.session_bus.get_object(SERVICE, object_path)
+ return dbus.Interface(obj, interface)
+
+ def register_object(self, path, *args):
+ """Register the GGet DBus service object specified by path."""
+ if path == MAIN_WINDOW_OBJ_PATH:
+ self.main_window = MainWindowObject(self.bus_name, args[0])
+ elif path == DOWNLOAD_MGR_OBJ_PATH:
+ self.download_manager = DownloadManagerObject(self,
+ args[0])
+ elif path == DOWNLOADS_OBJ_PATH:
+ d = DownloadObject(self.bus_name, args[0])
+ self.download_objects.append(d)
+
+class MainWindowObject(dbus.service.Object):
+ def __init__(self, bus_name, main_window):
+ dbus.service.Object.__init__(self, bus_name, MAIN_WINDOW_OBJ_PATH)
+ self.main_window = main_window
+ self.config = Configuration()
+
+ # Methods
+
+ @dbus.service.method(MAIN_WINDOW_IFACE, in_signature='', out_signature='')
+ def Present(self):
+ Utils.debug_print("Invoked DBus method: %s.%s" % (MAIN_WINDOW_IFACE,
+ "Present"))
+ self.main_window.window.present()
+
+ @dbus.service.method(MAIN_WINDOW_IFACE, in_signature='', out_signature='')
+ def Hide(self):
+ Utils.debug_print("Invoked DBus method: %s.%s" % (MAIN_WINDOW_IFACE,
+ "Hide"))
+ self.main_window.window.hide()
+
+class DownloadManagerObject(dbus.service.Object):
+ def __init__(self, dbus_service, download_list):
+ dbus.service.Object.__init__(self, dbus_service.bus_name,
+ DOWNLOAD_MGR_OBJ_PATH)
+ self.dbus_service = dbus_service
self.download_list = download_list
self.config = Configuration()
@@ -90,45 +130,37 @@
self.download_list.connect("download-removed", self.__download_removed)
def __download_added(self, download_list, download):
- self.DownloadAdded(download.id)
+ self.dbus_service.register_object(DOWNLOADS_OBJ_PATH, download)
+ obj_path = DOWNLOADS_OBJ_PATH + "/" + download.id
+ self.DownloadAdded(obj_path)
def __download_removed(self, download_list, download):
- self.DownloadRemoved(download.id)
+ obj_path = DOWNLOADS_OBJ_PATH + "/" + download.id
+ for download_obj in self.dbus_service.download_objects:
+ if download_obj.download == download:
+ download_obj.remove_from_connection()
+ self.dbus_service.download_objects.remove(download_obj)
+ self.DownloadRemoved(obj_path)
# Signals
- @dbus.service.signal(INTERFACE, signature='s')
- def DownloadAdded(self, id):
- Utils.debug_print("Emitted DBus DownloadAdded signal.")
-
- @dbus.service.signal(INTERFACE, signature='s')
- def DownloadRemoved(self, id):
- Utils.debug_print("Emitted DBus DownloadRemoved signal.")
-
- @dbus.service.signal(INTERFACE, signature='ss')
- def DownloadStatusChanged(self, id, status):
- Utils.debug_print("Emitted DBus DownloadStatusChanged signal.")
+ @dbus.service.signal(DOWNLOAD_MGR_IFACE, signature='s')
+ def DownloadAdded(self, obj_path):
+ Utils.debug_print("Emitted DBus signal: %s.%s" % (DOWNLOAD_MGR_IFACE,
+ "DownloadAdded"))
+
+ @dbus.service.signal(DOWNLOAD_MGR_IFACE, signature='s')
+ def DownloadRemoved(self, obj_path):
+ Utils.debug_print("Emitted DBus signal: %s.%s" % (DOWNLOAD_MGR_IFACE,
+ "DownloadRemoved"))
# Methods
- @dbus.service.method(INTERFACE, in_signature='', out_signature='')
- def Quit(self):
- Utils.debug_print("DBus Quit method was invoked.")
- self.main_window.quit()
-
- @dbus.service.method(INTERFACE, in_signature='', out_signature='')
- def Present(self):
- Utils.debug_print("DBus Present method was invoked.")
- self.main_window.window.present()
-
- @dbus.service.method(INTERFACE, in_signature='', out_signature='')
- def Hide(self):
- Utils.debug_print("DBus Hide method was invoked.")
- self.main_window.window.hide()
-
- @dbus.service.method(INTERFACE, in_signature='ss', out_signature='s')
+ @dbus.service.method(DOWNLOAD_MGR_IFACE, in_signature='ss',
+ out_signature='s')
def AddDownload(self, uri, path):
- Utils.debug_print("DBus AddDownload method was invoked.")
+ Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
+ "AddDownload"))
r = ""
if self.config.ask_for_location:
gtk.gdk.threads_enter()
@@ -136,70 +168,87 @@
if add.dialog.run() == 1:
download = add.download
if download:
- r = download.id
+ r = DOWNLOADS_OBJ_PATH + "/" + download.id
gtk.gdk.threads_leave()
else:
download = self.download_list.add_download(uri, path)
- r = download.id
+ r = DOWNLOADS_OBJ_PATH + "/" + download.id
return r
- @dbus.service.method(INTERFACE, in_signature='s', out_signature='b')
- def RemoveDownload(self, id):
- Utils.debug_print("DBus RemoveDownload method was invoked.")
- download = self.download_list.get_download(id)
+ @dbus.service.method(DOWNLOAD_MGR_IFACE, in_signature='s',
+ out_signature='b')
+ def RemoveDownload(self, obj_path):
+ Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
+ "RemoveDownload"))
+ download = self.download_list.get_download(os.path.basename(obj_path))
if download:
self.download_list.remove_download(download)
return True
return False
- @dbus.service.method(INTERFACE, in_signature='', out_signature='')
+ @dbus.service.method(DOWNLOAD_MGR_IFACE, in_signature='', out_signature='')
def RemoveCompletedDownloads(self):
- Utils.debug_print("DBus RemoveCompletedDownloads method was invoked.")
+ Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
+ "RemoveCompletedDownloads"))
self.download_list.remove_completed_downloads()
- @dbus.service.method(INTERFACE, in_signature='', out_signature='as')
+ @dbus.service.method(DOWNLOAD_MGR_IFACE, in_signature='',
+ out_signature='as')
def ListDownloads(self):
- Utils.debug_print("DBus RemoveDownload method was invoked.")
+ Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
+ "ListDownloads"))
r = []
for download in self.download_list.downloads:
- r.append(download.id)
+ r.append(DOWNLOADS_OBJ_PATH + "/" + download.id)
return r
- @dbus.service.method(INTERFACE, in_signature='s', out_signature='b')
- def PauseDownload(self, id):
- Utils.debug_print("DBus PauseDownload method was invoked.")
- download = self.download_list.get_download(id)
- if download:
- return download.pause()
+class DownloadObject(dbus.service.Object):
+ def __init__(self, bus_name, download):
+ path = DOWNLOADS_OBJ_PATH + "/" + download.id
+ dbus.service.Object.__init__(self, bus_name, path)
+ self.download = download
+ self.config = Configuration()
- @dbus.service.method(INTERFACE, in_signature='s', out_signature='b')
- def ResumeDownload(self, id):
- Utils.debug_print("DBus ResumeDownload method was invoked.")
- download = self.download_list.get_download(id)
- if download:
- return download.resume()
+ # Signals
- @dbus.service.method(INTERFACE, in_signature='s', out_signature='b')
- def CancelDownload(self, id):
- Utils.debug_print("DBus CancelDownload method was invoked.")
- download = self.download_list.get_download(id)
- if download:
- return download.cancel()
+ @dbus.service.signal(DOWNLOAD_IFACE, signature='s')
+ def StatusChanged(self, status):
+ Utils.debug_print("Emitted DBus signal: %s.%s" % (DOWNLOAD_IFACE,
+ "StatusChanged"))
- @dbus.service.method(INTERFACE, in_signature='s', out_signature='a{ss}')
- def GetDownloadInformation(self, id):
- Utils.debug_print("DBus GetDownloadInformation method was invoked.")
+ # Methods
+
+ @dbus.service.method(DOWNLOAD_IFACE, in_signature='', out_signature='b')
+ def Pause(self):
+ Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_IFACE,
+ "Pause"))
+ return self.download.pause()
+
+ @dbus.service.method(DOWNLOAD_IFACE, in_signature='', out_signature='b')
+ def Resume(self):
+ Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_IFACE,
+ "Resume"))
+ return self.download.resume()
+
+ @dbus.service.method(DOWNLOAD_IFACE, in_signature='', out_signature='b')
+ def Cancel(self):
+ Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_IFACE,
+ "Cancel"))
+ return self.download.cancel()
+
+ @dbus.service.method(DOWNLOAD_IFACE, in_signature='', out_signature='a{ss}')
+ def GetProperties(self):
+ Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_IFACE,
+ "GetProperties"))
r = {}
- download = self.download_list.get_download(id)
- if download:
- r["uri"] = download.uri
- r["path"] = download.path
- r["file"] = download.file_name
- r["status"] = Download.STATUS_STRINGS[download.status]
- r["mime-type"] = download.mime_type
- r["total size"] = str(download.total_size)
- r["date started"] = download.get_date_str("started")
- r["date completed"] = download.get_date_str("completed")
+ r["uri"] = self.download.uri
+ r["path"] = self.download.path
+ r["file"] = self.download.file_name
+ r["status"] = Download.STATUS_STRINGS[self.download.status]
+ r["mime-type"] = self.download.mime_type
+ r["total size"] = str(self.download.total_size)
+ r["date started"] = self.download.get_date_str("started")
+ r["date completed"] = self.download.get_date_str("completed")
return r
# vim: set sw=4 et sts=4 tw=79 fo+=l:
Modified: trunk/gget/Download.py
==============================================================================
--- trunk/gget/Download.py (original)
+++ trunk/gget/Download.py Fri Aug 1 11:52:00 2008
@@ -27,11 +27,11 @@
import gobject
import gnomevfs
-import Utils
+import DBusService
import GUI
+import Utils
import metalink
from Configuration import Configuration
-from DBusService import DBusService
from Notification import Notification
from gget import NAME
@@ -59,7 +59,7 @@
def __init__(self, uri, path, date_started="", date_completed=""):
gobject.GObject.__init__(self)
self.config = Configuration()
- self.dbus_service = DBusService()
+ self.dbus_service = DBusService.DBusService()
self.uri = gnomevfs.make_uri_from_shell_arg(uri)
self.file_name = os.path.basename(self.uri)
@@ -230,8 +230,9 @@
self.status = status
Utils.debug_print("Download status for %s changed to: %s (%s)" % (self,
self.get_status_string(), status))
- self.dbus_service.gget_object.DownloadStatusChanged(self.id,
- STATUS_STRINGS[status])
+ for download_obj in self.dbus_service.download_objects:
+ if download_obj.download == self:
+ download_obj.StatusChanged(STATUS_STRINGS[status])
self.emit("status-changed", status)
def get_status_string(self):
Modified: trunk/gget/Main.py
==============================================================================
--- trunk/gget/Main.py (original)
+++ trunk/gget/Main.py Fri Aug 1 11:52:00 2008
@@ -30,9 +30,9 @@
import gtk
import gnome
+import DBusService
import GUI
from AddDownloadDialog import AddDownloadDialog
-from DBusService import DBusService
from DownloadList import DownloadList
from DownloadManager import DownloadManager
from MainWindow import MainWindow
@@ -68,14 +68,17 @@
download_list = DownloadList()
download_manager = DownloadManager()
- dbus_service = DBusService(download_list)
+ dbus_service = DBusService.DBusService()
if not dbus_service.register():
for uri in args:
- dbus_service.gget_object.AddDownload(uri, os.getcwd())
+ dbus_service.download_manager.AddDownload(uri, os.getcwd())
return 0
+ dbus_service.register_object(DBusService.DOWNLOAD_MGR_OBJ_PATH,
+ download_list)
+
main_window = MainWindow(config, download_list)
- dbus_service.gget_object.main_window = main_window
+ dbus_service.register_object(DBusService.MAIN_WINDOW_OBJ_PATH, main_window)
if config.show_main_window:
main_window.window.show()
@@ -83,7 +86,7 @@
if not config.show_status_icon:
status_icon.icon.set_visible(False)
- # sys.excepthook = main_window.on_unhandled_exception
+ sys.excepthook = main_window.on_unhandled_exception
download_list.load_from_xml()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]