gget r27 - trunk/gget



Author: johans
Date: Thu Jul 10 23:25:38 2008
New Revision: 27
URL: http://svn.gnome.org/viewvc/gget?rev=27&view=rev

Log:
Added notification bubbles on completed downloads.

Added:
   trunk/gget/Notification.py
Modified:
   trunk/gget/Download.py
   trunk/gget/MainWindow.py
   trunk/gget/Makefile.am

Modified: trunk/gget/Download.py
==============================================================================
--- trunk/gget/Download.py	(original)
+++ trunk/gget/Download.py	Thu Jul 10 23:25:38 2008
@@ -23,11 +23,13 @@
 
 import gtk
 import gobject
+import gnomevfs
 
 import Utils
 import GUI
 import metalink
 from Configuration import Configuration
+from Notification import Notification
 from gget import NAME
 
 CONNECTING = 0
@@ -72,6 +74,11 @@
 
         self.status = -1
 
+        self.mime_type = gnomevfs.get_file_mime_type(self.file_name)
+        self.pixbuf = GUI.load_icon_from_mime_type(self.mime_type, 32)
+
+        self.connect("status-changed", self.__status_changed)
+
     def __str__(self):
         return self.uri
 
@@ -129,4 +136,8 @@
         else:
             return _("N/A")
 
+    def __status_changed(self, download, status):
+        if status == COMPLETED:
+            Notification(download)
+
 # 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 Jul 10 23:25:38 2008
@@ -227,9 +227,7 @@
     def __image_cell_data_func(self, column, cell, model, iter):
         """Data function for the image of the download."""
         download = model.get_value(iter, 0)
-        mime_type = gnomevfs.get_file_mime_type(download.file_name)
-        pixbuf = GUI.load_icon_from_mime_type(mime_type, 32)
-        cell.props.pixbuf = pixbuf
+        cell.props.pixbuf = download.pixbuf
 
     def __name_cell_data_func(self, column, cell, model, iter):
         """Data function for the name of downloads."""

Modified: trunk/gget/Makefile.am
==============================================================================
--- trunk/gget/Makefile.am	(original)
+++ trunk/gget/Makefile.am	Thu Jul 10 23:25:38 2008
@@ -11,6 +11,7 @@
 	metalink.py		\
 	Main.py			\
 	MainWindow.py		\
+	Notification.py		\
 	PreferencesDialog.py	\
 	StatusIcon.py		\
 	Utils.py

Added: trunk/gget/Notification.py
==============================================================================
--- (empty file)
+++ trunk/gget/Notification.py	Thu Jul 10 23:25:38 2008
@@ -0,0 +1,88 @@
+# -*- 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 sys
+from gettext import gettext as _
+
+import gobject
+import gnomevfs
+
+import GUI
+from gget import NAME
+from StatusIcon import StatusIcon
+from Configuration import Configuration
+try:
+    import pynotify
+except ImportError, ie:
+    if str(ie) == "No module named pynotify":
+        ed = GUI.ErrorDialog(_("Error while importing pynotify module"),
+                             _("Could not find python-notify."))
+        ed.run()
+        sys.exit(1)
+
+TIMEOUT = 60000
+
+class Notification:
+    def __init__(self, download):
+        self.download = download
+
+        self.config = Configuration()
+        self.status_icon = StatusIcon()
+
+        pynotify.init(NAME)
+
+        self.notification = pynotify.Notification(_("Download Completed!"),
+                _("%s has been downloaded successfully.") %
+                self.download.file_name)
+
+        if self.download.pixbuf:
+            self.notification.set_icon_from_pixbuf(self.download.pixbuf)
+        else:
+            pixbuf = GUI.load_icon(NAME.lower(), 32, 32)
+            self.notification.set_icon_from_pixbuf(pixbuf)
+
+        # Position notification at status icon if its shown
+        if self.config.show_status_icon:
+            self.notification.attach_to_status_icon(self.status_icon.icon)
+
+        self.notification.set_timeout(TIMEOUT) # One minute
+
+        self.notification.add_action("file", _("Open"),
+                                     self.__action_invoked)
+        self.notification.add_action("folder", _("Open folder"),
+                                     self.__action_invoked)
+        self.notification.connect("closed", self.__closed)
+
+        if not self.notification.show():
+            print "Failed to show notification."
+
+    def __action_invoked(self, notification, action):
+        """Called when buttons in the notification is pressed."""
+        if action == "file":
+            uri = gnomevfs.make_uri_from_input_with_dirs(self.download.file, 2)
+            gnomevfs.url_show(uri)
+        elif action == "folder":
+            uri = gnomevfs.make_uri_from_input(self.download.path)
+            gnomevfs.url_show(uri)
+
+    def __closed(self, notification):
+        notification.close()
+
+# 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]