gget r101 - in trunk: bin gget



Author: johans
Date: Thu Aug 21 09:50:17 2008
New Revision: 101
URL: http://svn.gnome.org/viewvc/gget?rev=101&view=rev

Log:
More refactoring.

Added:
   trunk/gget/application.py
      - copied, changed from r100, /trunk/gget/Application.py
   trunk/gget/status_icon.py
      - copied, changed from r97, /trunk/gget/StatusIcon.py
   trunk/gget/utils.py
      - copied unchanged from r100, /trunk/gget/Utils.py
Removed:
   trunk/gget/Application.py
   trunk/gget/StatusIcon.py
   trunk/gget/TrayIcon.py
   trunk/gget/Utils.py
Modified:
   trunk/bin/gget.in
   trunk/gget/DBusService.py
   trunk/gget/Download.py
   trunk/gget/DownloadList.py
   trunk/gget/DownloadManager.py
   trunk/gget/MainWindow.py
   trunk/gget/Makefile.am
   trunk/gget/Notification.py
   trunk/gget/config.py
   trunk/gget/dialogs.py
   trunk/gget/gui.py

Modified: trunk/bin/gget.in
==============================================================================
--- trunk/bin/gget.in	(original)
+++ trunk/bin/gget.in	Thu Aug 21 09:50:17 2008
@@ -35,7 +35,7 @@
 elif PYTHON_DIR not in sys.path:
     sys.path.insert(0, os.path.abspath(PYTHON_DIR))
 
-from gget.Application import Application
+from gget.application import Application
 
 if __name__ == "__main__":
     application = Application()

Modified: trunk/gget/DBusService.py
==============================================================================
--- trunk/gget/DBusService.py	(original)
+++ trunk/gget/DBusService.py	Thu Aug 21 09:50:17 2008
@@ -25,7 +25,7 @@
 import Download
 import config
 import dialogs
-import Utils
+import utils
 from dialogs import AddDownloadDialog
 from gget import NAME
 
@@ -69,15 +69,15 @@
         self.session_bus = dbus.SessionBus(mainloop=dbus_loop)
 
         try:
-            Utils.take_dbus_name(SERVICE, bus=self.session_bus)
-        except Utils.DBusNameExistsException, e:
+            utils.take_dbus_name(SERVICE, bus=self.session_bus)
+        except utils.DBusNameExistsException, e:
             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))
+            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))
+        utils.debug_print("The %s DBus service (%s) was sucessfully registered on the session bus." % (NAME, SERVICE))
 
         self.bus_name = dbus.service.BusName(SERVICE, bus=self.session_bus)
         return True
@@ -108,13 +108,13 @@
 
     @dbus.service.method(MAIN_WINDOW_IFACE, in_signature='', out_signature='')
     def Present(self):
-        Utils.debug_print("Invoked DBus method: %s.%s" % (MAIN_WINDOW_IFACE,
+        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,
+        utils.debug_print("Invoked DBus method: %s.%s" % (MAIN_WINDOW_IFACE,
                                                           "Hide"))
         self.main_window.window.hide()
 
@@ -146,12 +146,12 @@
 
     @dbus.service.signal(DOWNLOAD_MGR_IFACE, signature='s')
     def DownloadAdded(self, obj_path):
-        Utils.debug_print("Emitted DBus signal: %s.%s" % (DOWNLOAD_MGR_IFACE,
+        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,
+        utils.debug_print("Emitted DBus signal: %s.%s" % (DOWNLOAD_MGR_IFACE,
                                                           "DownloadRemoved"))
 
     # Methods
@@ -159,7 +159,7 @@
     @dbus.service.method(DOWNLOAD_MGR_IFACE, in_signature='ss',
                          out_signature='s')
     def AddDownload(self, uri, path):
-        Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
+        utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
                                                           "AddDownload"))
         r = ""
         if self.config.ask_for_location:
@@ -178,7 +178,7 @@
     @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,
+        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:
@@ -188,14 +188,14 @@
 
     @dbus.service.method(DOWNLOAD_MGR_IFACE, in_signature='', out_signature='')
     def RemoveCompletedDownloads(self):
-        Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
+        utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
                           "RemoveCompletedDownloads"))
         self.download_list.remove_completed_downloads()
 
     @dbus.service.method(DOWNLOAD_MGR_IFACE, in_signature='',
                          out_signature='as')
     def ListDownloads(self):
-        Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
+        utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_MGR_IFACE,
                                                           "ListDownloads"))
         r = []
         for download in self.download_list.downloads:
@@ -213,32 +213,32 @@
 
     @dbus.service.signal(DOWNLOAD_IFACE, signature='s')
     def StatusChanged(self, status):
-        Utils.debug_print("Emitted DBus signal: %s.%s" % (DOWNLOAD_IFACE,
+        utils.debug_print("Emitted DBus signal: %s.%s" % (DOWNLOAD_IFACE,
                                                           "StatusChanged"))
 
     # Methods
 
     @dbus.service.method(DOWNLOAD_IFACE, in_signature='', out_signature='b')
     def Pause(self):
-        Utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_IFACE,
+        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,
+        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,
+        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,
+        utils.debug_print("Invoked DBus method: %s.%s" % (DOWNLOAD_IFACE,
                                                           "GetProperties"))
         r = {}
         r["uri"] = self.download.uri

Modified: trunk/gget/Download.py
==============================================================================
--- trunk/gget/Download.py	(original)
+++ trunk/gget/Download.py	Thu Aug 21 09:50:17 2008
@@ -29,7 +29,7 @@
 
 import DBusService
 import gui
-import Utils
+import utils
 import metalink
 from config import Configuration
 from Notification import Notification
@@ -72,7 +72,7 @@
         self.path = path
 
         if not self.config.ask_for_location:
-            folder = Utils.get_folder_for_extension(uri)
+            folder = utils.get_folder_for_extension(uri)
             if folder:
                 self.path = folder
 
@@ -154,7 +154,7 @@
     def update(self, block_count, block_size, total_size):
         """Callback with count of blocks transferred so far, block size in
         bytes and the total size of the file in bytes."""
-        Utils.debug_print("Download.update called with block_count: %s \
+        utils.debug_print("Download.update called with block_count: %s \
                 block_size: %s total_size: %s" % (block_count, block_size,
                     total_size))
         current_size = block_count * block_size
@@ -183,7 +183,7 @@
         if self.status != COMPLETED and self.percent_complete == 100:
             self.set_status(COMPLETED)
 
-        Utils.debug_print("Percent complete: %s" % self.percent_complete)
+        utils.debug_print("Percent complete: %s" % self.percent_complete)
 
         self.emit("update", int(block_count), int(block_size), int(total_size))
 
@@ -242,7 +242,7 @@
     def set_status(self, status):
         self.old_status = self.status
         self.status = status
-        Utils.debug_print("Download status for %s changed to: %s (%s)" % (self,
+        utils.debug_print("Download status for %s changed to: %s (%s)" % (self,
             self.get_status_string(), status))
         for download_obj in self.dbus_service.download_objects:
             if download_obj.download == self:

Modified: trunk/gget/DownloadList.py
==============================================================================
--- trunk/gget/DownloadList.py	(original)
+++ trunk/gget/DownloadList.py	Thu Aug 21 09:50:17 2008
@@ -26,7 +26,7 @@
 
 import config
 import Download
-import Utils
+import utils
 
 XML_HEADER = '<?xml version="1.0" encoding="UTF-8" ?>\n'
 DOWNLOADS_FILE = "downloads.xml"
@@ -105,7 +105,7 @@
         download.connect("update", self.__download_update)
         download.connect("status-changed", self.__download_status_changed)
         self.downloads.append(download)
-        Utils.debug_print("Appended download %s to list of downloads." %
+        utils.debug_print("Appended download %s to list of downloads." %
                 download)
         self.emit("download-added", (download))
 
@@ -183,7 +183,7 @@
         self.downloads.remove(download)
         download_element = self.__get_download_element(download)
         self.tree.getroot().remove(download_element)
-        Utils.debug_print("Removed download %s from list of downloads." %
+        utils.debug_print("Removed download %s from list of downloads." %
                 download)
         self.emit("download-removed", (download))
         self.__save_xml()
@@ -205,11 +205,11 @@
 
     def __save_xml(self):
         """Adds a header and indents the xml tree before saving it to disk."""
-        Utils.debug_print("Saved download list to: %s" %
+        utils.debug_print("Saved download list to: %s" %
                 self.download_file_path)
         file = open(self.download_file_path, "w")
         file.write(XML_HEADER)
-        Utils.indent(self.tree.getroot())
+        utils.indent(self.tree.getroot())
         self.tree.write(file)
         file.close()
 

Modified: trunk/gget/DownloadManager.py
==============================================================================
--- trunk/gget/DownloadManager.py	(original)
+++ trunk/gget/DownloadManager.py	Thu Aug 21 09:50:17 2008
@@ -30,7 +30,7 @@
 
 import config
 import Download
-import Utils
+import utils
 from DownloadList import DownloadList
 from gget import NAME, VERSION
 
@@ -116,7 +116,7 @@
 
     def start_download(self, download):
         """Starts a download in a new thread."""
-        Utils.debug_print("Starting download %s" % download)
+        utils.debug_print("Starting download %s" % download)
         thread.start_new_thread(self.__start_download, (download,))
         self.emit("download-started", (download))
 
@@ -145,12 +145,12 @@
         """Sets the proxy to use for the specified protocol."""
         if protocol == "http":
             metalink.HTTP_PROXY = proxy
-            Utils.debug_print("HTTP proxy: %s" % metalink.HTTP_PROXY)
+            utils.debug_print("HTTP proxy: %s" % metalink.HTTP_PROXY)
         elif protocol == "https":
             metalink.HTTPS_PROXY = proxy
-            Utils.debug_print("HTTPS proxy: %s" % metalink.HTTPS_PROXY)
+            utils.debug_print("HTTPS proxy: %s" % metalink.HTTPS_PROXY)
         elif protocol == "ftp":
             metalink.FTP_PROXY = proxy
-            Utils.debug_print("FTP proxy: %s" % metalink.FTP_PROXY)
+            utils.debug_print("FTP proxy: %s" % metalink.FTP_PROXY)
 
 # vim: set sw=4 et sts=4 tw=79 fo+=l:

Modified: trunk/gget/MainWindow.py
==============================================================================
--- trunk/gget/MainWindow.py	(original)
+++ trunk/gget/MainWindow.py	Thu Aug 21 09:50:17 2008
@@ -32,7 +32,7 @@
 import config
 import Download
 import gui
-import Utils
+import utils
 from dialogs import AboutDialog, AddDownloadDialog, DetailsDialog, ErrorDialog, PreferencesDialog, QuitDialog
 from gget import NAME
 
@@ -272,12 +272,12 @@
     def __size_cell_data_func(self, column, cell, model, iter):
         """Data function for the file size of downloads."""
         download = model.get_value(iter, 0)
-        cell.props.text = Utils.get_readable_size(download.current_size)
+        cell.props.text = utils.get_readable_size(download.current_size)
 
     def __total_size_cell_data_func(self, column, cell, model, iter):
         """Data function for the file size of downloads."""
         download = model.get_value(iter, 0)
-        cell.props.text = Utils.get_readable_size(download.total_size)
+        cell.props.text = utils.get_readable_size(download.total_size)
 
     def __progress_cell_data_func(self, column, cell, model, iter):
         """Data function for the progress bar of downloads."""
@@ -287,13 +287,13 @@
     def __speed_cell_data_func(self, column, cell, model, iter):
         """Data function for the speed of downloads."""
         download = model.get_value(iter, 0)
-        cell.props.text = Utils.get_readable_speed(download.bit_rate)
+        cell.props.text = utils.get_readable_speed(download.bit_rate)
 
     def __eta_cell_data_func(self, column, cell, model, iter):
         """Data function for estemated time of arrival (ETA) of downloads."""
         download = model.get_value(iter, 0)
         size = download.total_size - download.current_size
-        cell.props.text = Utils.get_readable_eta(size, download.bit_rate)
+        cell.props.text = utils.get_readable_eta(size, download.bit_rate)
 
     def __connect_widgets(self):
         """Connect to the widget signals we are interested in."""

Modified: trunk/gget/Makefile.am
==============================================================================
--- trunk/gget/Makefile.am	(original)
+++ trunk/gget/Makefile.am	Thu Aug 21 09:50:17 2008
@@ -1,6 +1,6 @@
 ggetdir = $(pythondir)/gget
 gget_PYTHON =			\
-	Application.py		\
+	application.py		\
 	config.py		\
 	DBusService.py		\
 	dialogs.py		\
@@ -12,9 +12,8 @@
 	metalink.py		\
 	MainWindow.py		\
 	Notification.py		\
-	StatusIcon.py		\
-	TrayIcon.py		\
-	Utils.py
+	status_icon.py		\
+	utils.py
 
 DISTCLEANFILES = __init__.py
 EXTRA_DATA = __init__.py.in

Modified: trunk/gget/Notification.py
==============================================================================
--- trunk/gget/Notification.py	(original)
+++ trunk/gget/Notification.py	Thu Aug 21 09:50:17 2008
@@ -26,9 +26,10 @@
 
 import gui
 import dialogs
-from gget import NAME
-from TrayIcon import TrayIcon
+from status_icon import TrayIcon
 from config import Configuration
+from gget import NAME
+
 try:
     import pynotify
 except ImportError, ie:

Copied: trunk/gget/application.py (from r100, /trunk/gget/Application.py)
==============================================================================
--- /trunk/gget/Application.py	(original)
+++ trunk/gget/application.py	Thu Aug 21 09:50:17 2008
@@ -37,7 +37,7 @@
 from DownloadList import DownloadList
 from DownloadManager import DownloadManager
 from MainWindow import MainWindow
-from TrayIcon import TrayIcon
+from status_icon import TrayIcon
 from gget import NAME, VERSION, LOCALE_DIR
 
 class Application:

Modified: trunk/gget/config.py
==============================================================================
--- trunk/gget/config.py	(original)
+++ trunk/gget/config.py	Thu Aug 21 09:50:17 2008
@@ -26,7 +26,7 @@
 import gconf
 
 import dialogs
-import Utils
+import utils
 
 DIR_GGET       = "/apps/gget"
 DIR_GNOME      = "/desktop/gnome"
@@ -146,9 +146,9 @@
         if self.client.dir_exists(DIR_GGET):
             self.client.add_dir(DIR_GGET, gconf.CLIENT_PRELOAD_RECURSIVE)
         else:
-            if Utils.runned_from_source():
+            if utils.runned_from_source():
                 os.system("gconftool-2 --install-schema-file %s" %
-                        os.path.join(Utils.get_data_dir(), "gget.schemas"))
+                        os.path.join(utils.get_data_dir(), "gget.schemas"))
             else:
                 ed = dialogs.ErrorDialog(_("Could not find configuration directory in GConf"), _("Please make sure that gget.schemas was correctly installed."))
                 ed.run()

Modified: trunk/gget/dialogs.py
==============================================================================
--- trunk/gget/dialogs.py	(original)
+++ trunk/gget/dialogs.py	Thu Aug 21 09:50:17 2008
@@ -31,9 +31,9 @@
 import config
 import gui
 import Download
-import Utils
+import utils
 from DownloadManager import DownloadManager
-from TrayIcon import TrayIcon
+from status_icon import TrayIcon
 from DownloadList import DownloadList
 from gget import NAME, VERSION
 
@@ -77,7 +77,7 @@
             # self.uri_entry.paste_clipboard()
             # self.uri_entry.select_region(0, -1)
 
-        folder = Utils.get_folder_for_extension(uri)
+        folder = utils.get_folder_for_extension(uri)
         if not folder:
             folder = self.config.default_folder
         self.download_filechooserbutton.set_current_folder(folder)
@@ -110,7 +110,7 @@
 
     def __uri_entry_changed(self, entry):
         uri = entry.get_text()
-        if len(uri) > 0 and Utils.is_supported_uri(uri):
+        if len(uri) > 0 and utils.is_supported_uri(uri):
             self.add_button.set_sensitive(True)
         else:
             self.add_button.set_sensitive(False)
@@ -154,10 +154,10 @@
         self.name_label.set_text(download.file_name)
         self.folder_label.set_text(download.path)
         self.current_size_label.set_text("%s (%s bytes)" % \
-                (Utils.get_readable_size(download.current_size),
+                (utils.get_readable_size(download.current_size),
                     download.current_size))
         self.total_size_label.set_text("%s (%s bytes)" % \
-            (Utils.get_readable_size(download.total_size),
+            (utils.get_readable_size(download.total_size),
                 download.total_size))
         self.mime_type_label.set_text(download.mime_type)
         self.date_started_label.set_text(download.get_date_str("started"))
@@ -200,7 +200,7 @@
 
     def __download_update(self, download, block_count, block_size, total_size):
         self.current_size_label.set_text("%s (%s bytes)" %
-                (Utils.get_readable_size(download.current_size),
+                (utils.get_readable_size(download.current_size),
                     download.current_size))
 
     def __download_status_changed(self, download, status):

Modified: trunk/gget/gui.py
==============================================================================
--- trunk/gget/gui.py	(original)
+++ trunk/gget/gui.py	Thu Aug 21 09:50:17 2008
@@ -27,12 +27,12 @@
 import gnomevfs
 import gnome.ui
 
-import Utils
+import utils
 from gget import NAME, LOCALE_DIR
 
 gtk.glade.bindtextdomain(NAME.lower(), LOCALE_DIR)
 
-glade_file = os.path.join(Utils.get_data_dir(), "gget.glade")
+glade_file = os.path.join(utils.get_data_dir(), "gget.glade")
 
 icon_theme = gtk.icon_theme_get_default()
 
@@ -46,7 +46,7 @@
     pixbuf = None
     if icon != None and icon != "":
         try:
-            icon_file = os.path.join(Utils.get_images_dir(), icon)
+            icon_file = os.path.join(utils.get_images_dir(), icon)
             if os.path.exists(icon_file):
                 pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_file, width,
                                                               height)
@@ -67,9 +67,9 @@
     return pixbuf
 
 # Register our icon with the icon theme if running from source
-if Utils.runned_from_source():
+if utils.runned_from_source():
     for size in [16, 22, 24, 32]:
-        icon_dir = os.path.join(Utils.get_images_dir(), "%sx%s" % (size, size))
+        icon_dir = os.path.join(utils.get_images_dir(), "%sx%s" % (size, size))
         icon_file = os.path.join(icon_dir, "gget.png")
         pixbuf = load_icon(icon_file, size, size)
         gtk.icon_theme_add_builtin_icon(NAME.lower(), size, pixbuf)
@@ -122,7 +122,7 @@
     clipboard = gtk.Clipboard(selection="PRIMARY")
     if clipboard.wait_is_text_available():
         uri = clipboard.wait_for_text()
-        if uri and Utils.is_supported_uri(uri):
+        if uri and utils.is_supported_uri(uri):
             return uri
     return None
 

Copied: trunk/gget/status_icon.py (from r97, /trunk/gget/StatusIcon.py)
==============================================================================
--- /trunk/gget/StatusIcon.py	(original)
+++ trunk/gget/status_icon.py	Thu Aug 21 09:50:17 2008
@@ -19,6 +19,11 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
 import gtk
+import egg.trayicon
+
+import config
+import dialogs
+import gui
 
 from gget import NAME
 
@@ -86,4 +91,97 @@
         menu.popup(None, None, gtk.status_icon_position_menu, button,
                 activate_time, icon)
 
+class TrayIcon(object):
+    """Singleton representing the tray icon"""
+
+    instance = None
+
+    def __new__(type, *args):
+        if TrayIcon.instance is None:
+            TrayIcon.instance = object.__new__(type)
+            TrayIcon.instance.__init(*args)
+        return TrayIcon.instance
+
+    def __init(self, *args):
+        self.main_window = args[0]
+        self.config = config.Configuration()
+
+        self.icon = egg.trayicon.TrayIcon(NAME)
+
+        self.eb = gtk.EventBox()
+        self.eb.set_visible_window(False)
+        self.eb.set_events(gtk.gdk.POINTER_MOTION_MASK)
+
+        self.image = gtk.Image()
+        self.image.set_from_icon_name(NAME.lower(), gtk.ICON_SIZE_BUTTON)
+        self.eb.add(self.image)
+        self.icon.add(self.eb)
+
+        self.__build_context_menu()
+
+        self.__connect_widgets()
+
+        self.icon.show_all()
+
+    def __build_context_menu(self):
+        self.context_menu = gtk.Menu()
+
+        self.add_imi = gtk.ImageMenuItem(gtk.STOCK_ADD)
+        self.add_imi.show()
+        self.context_menu.append(self.add_imi)
+
+        separator = gtk.SeparatorMenuItem()
+        separator.show()
+        self.context_menu.append(separator)
+
+        self.preferences_imi = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
+        self.preferences_imi.show()
+        self.context_menu.append(self.preferences_imi)
+
+        separator = gtk.SeparatorMenuItem()
+        separator.show()
+        self.context_menu.append(separator)
+
+        self.quit_imi = gtk.ImageMenuItem(gtk.STOCK_QUIT)
+        self.quit_imi.show()
+        self.context_menu.append(self.quit_imi)
+
+    def __connect_widgets(self):
+        self.eb.connect('button-press-event', self.__button_press_event)
+
+        self.add_imi.connect("activate",
+                self.main_window.show_add_download_dialog)
+        self.preferences_imi.connect("activate",
+                self.main_window.preferences_menu_item_activate)
+        self.quit_imi.connect("activate", self.main_window.quit)
+
+    def __button_press_event(self, widget, event):
+        if event.type != gtk.gdk.BUTTON_PRESS:
+            return
+        if event.button == 1: # Left click
+            self.__left_click()
+        elif event.button == 2: # Middle click
+            self.__middle_click()
+        elif event.button == 3: # Right click
+            self.__right_click(event)
+
+    def __left_click(self):
+        if self.main_window.window.get_property("visible"):
+            self.main_window.window.hide()
+        else:
+            self.main_window.window.present()
+
+    def __middle_click(self):
+        if self.config.ask_for_location:
+            add = dialogs.AddDownloadDialog()
+            add.dialog.show()
+        else:
+            uri = gui.get_uri_from_clipboard()
+            if uri:
+                self.main_window.download_list.add_download(uri,
+                        self.config.default_folder)
+
+    def __right_click(self, event):
+        self.context_menu.popup(None, None, None, event.button, event.time)
+
 # vim: set sw=4 et sts=4 tw=79 fo+=l:



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