gget r17 - trunk/gget



Author: johans
Date: Thu Jun 26 00:27:29 2008
New Revision: 17
URL: http://svn.gnome.org/viewvc/gget?rev=17&view=rev

Log:
Added support for dropping links on the main window.

Modified:
   trunk/gget/AddDownloadDialog.py
   trunk/gget/MainWindow.py

Modified: trunk/gget/AddDownloadDialog.py
==============================================================================
--- trunk/gget/AddDownloadDialog.py	(original)
+++ trunk/gget/AddDownloadDialog.py	Thu Jun 26 00:27:29 2008
@@ -23,12 +23,13 @@
 import gtk
 
 import GUI
+from Configuration import Configuration
 from DownloadManager import DownloadManager
 from gget import NAME
 
 class AddDownloadDialog:
-    def __init__(self, config):
-        self.config = config
+    def __init__(self, uri=""):
+        self.config = Configuration()
 
         self.__get_widgets()
         self.__connect_widgets()
@@ -37,9 +38,12 @@
         self.clipboard.connect("owner-change", self.__clipboard_owner_change)
 
         self.__valid_url = False
-        self.__set_url_from_clipboard(self.clipboard)
+        if uri != "":
+            self.url_entry.set_text(uri)
+        else:
+            self.__set_url_from_clipboard(self.clipboard)
 
-        self.download_filechooserbutton.set_current_folder(config.default_folder)
+        self.download_filechooserbutton.set_current_folder(self.config.default_folder)
 
     def __get_widgets(self):
         xml = gtk.glade.XML(GUI.glade_file, domain=NAME.lower())

Modified: trunk/gget/MainWindow.py
==============================================================================
--- trunk/gget/MainWindow.py	(original)
+++ trunk/gget/MainWindow.py	Thu Jun 26 00:27:29 2008
@@ -35,6 +35,10 @@
 from PreferencesDialog import PreferencesDialog
 from gget import NAME
 
+# D&D targets
+TARGET_URI_LIST = 0
+TARGET_NETSCAPE_URL = 1
+
 class MainWindow:
     def __init__(self, config, download_manager):
         self.config = config
@@ -43,6 +47,13 @@
 
         self.__get_widgets()
 
+        targets = [("text/uri-list", 0, TARGET_URI_LIST),
+                ("x-url/http", 0, TARGET_NETSCAPE_URL),
+                ("x-url/ftp", 0, TARGET_NETSCAPE_URL),
+                ("_NETSCAPE_URL", 0, TARGET_NETSCAPE_URL)]
+        self.window.drag_dest_set(gtk.DEST_DEFAULT_ALL |
+                gtk.DEST_DEFAULT_HIGHLIGHT, targets, gtk.gdk.ACTION_COPY)
+
         self.__make_downloads_treeview()
 
         self.__connect_widgets()
@@ -208,6 +219,8 @@
         """Connect widgets to various signals."""
         self.window.connect("destroy", self.quit)
         self.window.connect("configure-event", self.__window_configure_event)
+        self.window.connect("drag_data_received",
+                self.__window_drag_data_received)
 
         # File menu
         self.add_menu_item.connect("activate", self.show_add_download_dialog)
@@ -254,9 +267,32 @@
         self.config.window_position_y = position_y
         return False # Propagate signal further
 
+    def __window_drag_data_received(self, widget, context, x, y, selection,
+            target_type, time):
+        if target_type == TARGET_URI_LIST:
+            # TODO: Need gnome_vfs_uri_list_parse and gnome_vfs_uri_to_string
+            # but they seem to be missing in the binding
+            pass
+        elif target_type == TARGET_NETSCAPE_URL:
+            uri = selection.data.split()[0]
+        else:
+            context.finish(False, True, time)
+            return True
+
+        if self.config.ask_for_location:
+            add = AddDownloadDialog(uri)
+            add.dialog.show()
+        else:
+            # print uri
+            # print self.config.default_folder
+            self.download_manager.start_download(uri,
+                    self.config.default_folder)
+
+            context.finish(True, False, time)
+
     def show_add_download_dialog(self, widget):
         """Show the dialog used for adding a new download."""
-        add = AddDownloadDialog(self.config)
+        add = AddDownloadDialog()
         add.dialog.show()
 
     def preferences_menu_item_activate(self, menu_item):
@@ -281,11 +317,18 @@
         """When selection changes set sensitivity appropriately."""
         (downloads_model, downloads_iter) = selection.get_selected()
         if downloads_iter:
+            # Enable tool buttons and menu items
             self.pause_tool_button.set_sensitive(True)
             self.pause_imi.set_sensitive(True)
             self.cancel_tool_button.set_sensitive(True)
             self.cancel_imi.set_sensitive(True)
+
+            # Set informative window title
+            # download = downloads_model.get_value(downloads_iter, 0)
+            # if download:
+                # self.window.set_title("%s %s (%.2f%%)" % (NAME, download.file_name, download.percent_complete))
         else:
+            # Disable tool buttons and menu items
             self.pause_tool_button.set_sensitive(False)
             self.pause_imi.set_sensitive(False)
             self.cancel_tool_button.set_sensitive(False)
@@ -384,6 +427,7 @@
     def __download_update(self, download, block_count, block_size, total_size):
         """Called on download updates. Finds the associated treeview row and
         fires a row changed signal."""
+        # self.window.set_title("%s %s (%.2f%%)" % (NAME, download.file_name, download.percent_complete))
         downloads_iter = self.downloads_model.get_iter_first()
         for row in self.downloads_model:
             if row[0] is download:



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