gget r35 - trunk/gget



Author: johans
Date: Sun Jul 20 21:23:20 2008
New Revision: 35
URL: http://svn.gnome.org/viewvc/gget?rev=35&view=rev

Log:
Fixed build error. Added a dbus service. Need to think more about the API though.

Added:
   trunk/gget/DBusService.py
Modified:
   trunk/gget/Download.py
   trunk/gget/DownloadManager.py
   trunk/gget/Main.py
   trunk/gget/Makefile.am

Added: trunk/gget/DBusService.py
==============================================================================
--- (empty file)
+++ trunk/gget/DBusService.py	Sun Jul 20 21:23:20 2008
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2008 Johan Svedberg <johan svedberg com>
+
+# This file is part of gget.
+
+# gget is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# gget is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with gget; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+
+import GUI
+
+try:
+    import dbus
+    import dbus.service
+    from dbus.mainloop.glib import DBusGMainLoop
+except ImportError, ie:
+    if str(ie) == "No module named dbus":
+        ed = GUI.ErrorDialog(_("Error while importing dbus module"),
+                             _("Could not find python-dbus."))
+        ed.run()
+        sys.exit(1)
+
+SERVICE = "org.gnome.GGet"
+OBJECT_PATH = "/org/gnome/GGet"
+INTERFACE = "org.gnome.GGet"
+
+class DBusService(object):
+    """Singleton representing the DBus service"""
+
+    instance = None
+
+    def __new__(type, *args):
+        if DBusService.instance is None:
+            DBusService.instance = object.__new__(type)
+            DBusService.instance.__init(*args)
+        return DBusService.instance
+
+    def __init(self, *args):
+        dbus_loop = DBusGMainLoop()
+        self.session_bus = dbus.SessionBus(mainloop=dbus_loop)
+
+        bus_name = dbus.service.BusName(SERVICE, bus=self.session_bus)
+        self.gget_object = GGetObject(bus_name, args[0])
+
+class GGetObject(dbus.service.Object):
+    def __init__(self, bus_name, download_list):
+        dbus.service.Object.__init__(self, bus_name, OBJECT_PATH)
+        self.download_list = download_list
+
+        self.download_list = download_list
+        self.download_list.connect("download-added", self.__download_added)
+        self.download_list.connect("download-removed", self.__download_removed)
+
+    def __download_added(self, download_list, download):
+        self.DownloadAdded(download.uri, download.path)
+
+    def __download_removed(self, download_list, download):
+        self.DownloadRemoved(download.uri)
+
+    @dbus.service.signal(INTERFACE, signature='ss')
+    def DownloadAdded(self, uri, path):
+        pass
+
+    @dbus.service.signal(INTERFACE, signature='s')
+    def DownloadRemoved(self, uri):
+        pass
+
+    @dbus.service.signal(INTERFACE, signature='s')
+    def DownloadStatusChanged(self, status):
+        pass
+
+    @dbus.service.method(INTERFACE, in_signature='ss', out_signature='')
+    def AddDownload(self, uri, path):
+        self.download_list.add_download(uri, path)
+
+# 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	Sun Jul 20 21:23:20 2008
@@ -31,6 +31,7 @@
 import GUI
 import metalink
 from Configuration import Configuration
+from DBusService import DBusService
 from Notification import Notification
 from gget import NAME
 
@@ -41,6 +42,13 @@
 COMPLETED = 4
 ERROR = 5
 
+STATUS_STRINGS = { CONNECTING: "Connecting",
+        DOWNLOADING: "Downloading",
+        CANCELED: "Canceled",
+        PAUSED: "Paused",
+        COMPLETED: "Completed",
+        ERROR: "Error"}
+
 class Download(gobject.GObject):
     __gsignals__ = {"update":   (gobject.SIGNAL_RUN_LAST, None, (int, int,
                                  int)),
@@ -50,6 +58,7 @@
     def __init__(self, uri, path, date_started="", date_completed=""):
         gobject.GObject.__init__(self)
         self.config = Configuration()
+        self.dbus_service = DBusService()
 
         self.uri = uri
         self.file_name = os.path.basename(self.uri)
@@ -184,9 +193,10 @@
         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(STATUS_STRINGS[status])
         self.emit("status-changed", status)
 
-    def get_status_string(self, status=None):
+    def get_status_string(self):
         if self.status == CONNECTING:
             return _("Connecting")
         elif self.status == DOWNLOADING:

Modified: trunk/gget/DownloadManager.py
==============================================================================
--- trunk/gget/DownloadManager.py	(original)
+++ trunk/gget/DownloadManager.py	Sun Jul 20 21:23:20 2008
@@ -32,6 +32,7 @@
 import GUI
 import Utils
 from Configuration import Configuration
+from DownloadList import DownloadList
 from gget import NAME, VERSION
 
 class DownloadManager(gobject.GObject):
@@ -51,6 +52,8 @@
     def __init(self, *args):
         gobject.GObject.__init__(self)
         self.config = Configuration()
+        self.download_list = DownloadList()
+        self.download_list.connect("download-added", self.__download_added)
 
         metalink.USER_AGENT = "%s %s" % (NAME, VERSION)
 
@@ -72,7 +75,7 @@
             else:
                 metalink.HTTP_PROXY = "http://%s:%s"; % (self.config.proxy_host, self.config.proxy_port)
 
-    def download_added(self, download_list, download):
+    def __download_added(self, download_list, download):
         """Called when a new download is added to DownloadList. Starts the
         download if its not already completed."""
         if not download.status == Download.COMPLETED:

Modified: trunk/gget/Main.py
==============================================================================
--- trunk/gget/Main.py	(original)
+++ trunk/gget/Main.py	Sun Jul 20 21:23:20 2008
@@ -31,6 +31,7 @@
 
 import GUI
 from AddDownloadDialog import AddDownloadDialog
+from DBusService import DBusService
 from DownloadList import DownloadList
 from DownloadManager import DownloadManager
 from MainWindow import MainWindow
@@ -65,7 +66,8 @@
     config = Configuration(debug)
     download_list = DownloadList()
     download_manager = DownloadManager()
-    download_list.connect("download-added", download_manager.download_added)
+
+    dbus_service = DBusService(download_list)
 
     main_window = MainWindow(config, download_list)
     if config.show_main_window:

Modified: trunk/gget/Makefile.am
==============================================================================
--- trunk/gget/Makefile.am	(original)
+++ trunk/gget/Makefile.am	Sun Jul 20 21:23:20 2008
@@ -3,6 +3,8 @@
 	AboutDialog.py		\
 	AddDownloadDialog.py	\
 	Configuration.py	\
+	DBusService.py		\
+	DetailsDialog.py	\
 	Download.py		\
 	DownloadList.py		\
 	DownloadManager.py	\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]