diff --git a/plugins/MoveTorrent/__init__.py b/plugins/MoveTorrent/__init__.py new file mode 100644 index 000000000..5b6a75c86 --- /dev/null +++ b/plugins/MoveTorrent/__init__.py @@ -0,0 +1,72 @@ +# Copyright (C) 2007 - Marcos Pinto +# +# This program 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, or (at your option) +# any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + +### Initialization ### + +plugin_name = _("Move Torrent") +plugin_author = "Marcos Pinto" +plugin_version = "0.1" +plugin_description = _("This plugin allows users to move the torrent to a \ + different directory without having to remove and re-add the torrent. This \ + feature can be found by right-clicking on a torrent.") + +def deluge_init(deluge_path): + global path + path = deluge_path + +def enable(core, interface): + global path + return movetorrentMenu(path, core, interface) + + +import deluge +from deluge import dialogs +import gtk +import os + +class movetorrentMenu: + + def __init__(self, path, core, interface): + print "Loading Move Torrent plugin..." + self.path = path + self.core = core + self.interface = interface + self.dialogs = deluge.dialogs + + # Add menu item to torrent context menu + self.menuitem_image = gtk.Image() + self.menuitem_image.set_from_stock(gtk.STOCK_SAVE_AS, gtk.ICON_SIZE_MENU) + + self.menuitem = gtk.ImageMenuItem(_("_Move Torrent")) + self.menuitem.set_image(self.menuitem_image) + self.menuitem.connect("activate", self.movetorrent_clicked) + self.interface.torrent_menu.append(self.menuitem) + self.menuitem.show_all() + + def update(self): + pass + + def unload(self): + self.interface.torrent_menu.remove(self.menuitem) + + def movetorrent_clicked(self, widget): + unique_ids = self.interface.get_selected_torrent_rows() + + path = self.dialogs.show_directory_chooser_dialog(None, \ + _("Choose a directory to move files to")) + if path: + for unique_id in unique_ids: + self.core.move_storage(unique_id, path) diff --git a/src/core.py b/src/core.py index 177772e40..ad7a2d67b 100644 --- a/src/core.py +++ b/src/core.py @@ -624,10 +624,10 @@ class Manager: if event['event_type'] is self.constants['EVENT_STORAGE_MOVED']: if event['message'] == self.unique_IDs[event['unique_ID']].save_dir: - raise StorageMoveFailed(_("You cannot move torrent to a different partition. Please fix your preferences")) - elif event['message'] == self.get_pref('default_finished_path'): - self.unique_IDs[event['unique_ID']].save_dir = self.get_pref('default_finished_path') - self.pickle_state() + raise StorageMoveFailed(_("You cannot move torrent to a different partition. Please check your preferences. Or maybe you are trying to move torrent's files to the same directory they are already stored ?")) + + self.unique_IDs[event['unique_ID']].save_dir = event['message'] + self.pickle_state() elif event['event_type'] is self.constants['EVENT_FINISHED']: if event['message'] == "torrent has finished downloading": @@ -636,7 +636,7 @@ class Manager: self.get_pref('default_download_path') and \ self.unique_IDs[event['unique_ID']].save_dir != \ self.get_pref('default_finished_path'): - deluge_core.move_storage(event['unique_ID'], + self.move_storage(event['unique_ID'], self.get_pref('default_finished_path')) # Queue seeding torrent to bottom if needed @@ -765,6 +765,9 @@ class Manager: if torrent_state['is_paused']: self.set_user_pause(unique_ID, False, enforce_queue=True) + def move_storage(self, unique_ID, directory): + deluge_core.move_storage(unique_ID, directory) + #################### # Internal functions #################### diff --git a/src/dialogs.py b/src/dialogs.py index 27eeec08f..df73782f4 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -504,18 +504,16 @@ def show_file_open_dialog(parent=None, title=None): chooser.destroy() return result -def show_directory_chooser_dialog(parent=None, title=None): - if title is None: - title = _("Choose a download directory") +def show_directory_chooser_dialog(parent, title): chooser = gtk.FileChooserDialog(title, parent, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) chooser.set_icon_from_file(common.get_pixmap("deluge32.png")) chooser.set_property("skip-taskbar-hint", True) config = pref.Preferences() - chooser.set_current_folder(config.get("choose_download_directory_dialog_path")) + chooser.set_current_folder(config.get("choose_directory_dialog_path")) if chooser.run() == gtk.RESPONSE_OK: result = chooser.get_filename() - config.set("choose_download_directory_dialog_path", result) + config.set("choose_directory_dialog_path", result) else: result = None chooser.destroy() diff --git a/src/interface.py b/src/interface.py index d0ef1b6bc..b7ffd9c25 100644 --- a/src/interface.py +++ b/src/interface.py @@ -868,7 +868,7 @@ class DelugeGTK: self.manager.handle_events() except core.StorageMoveFailed, e: print "StorageMoveFailed", e - dialogs.show_popup_warning(self.window, _("You cannot move torrent to a different partition. Please fix your preferences")) + dialogs.show_popup_warning(self.window, e.value) # Make sure that the interface still exists try: @@ -1075,7 +1075,8 @@ class DelugeGTK: if self.config.get('use_default_dir'): path = self.config.get('default_download_path') else: - path = dialogs.show_directory_chooser_dialog(self.window) + path = dialogs.show_directory_chooser_dialog(self.window, + _("Choose a download directory")) if path is None: return diff --git a/src/pref.py b/src/pref.py index 7e482d62c..5cf94163c 100644 --- a/src/pref.py +++ b/src/pref.py @@ -52,7 +52,7 @@ DEFAULT_PREFS = { "clear_max_ratio_torrents" : False, "default_download_path" : os.path.expanduser("~/"), "open_torrent_dialog_path" : os.path.expanduser("~/"), - "choose_download_directory_dialog_path": os.path.expanduser("~/"), + "choose_directory_dialog_path": os.path.expanduser("~/"), "default_finished_path" : os.path.expanduser("~/"), "enable_move_completed" : False, "enable_dht" : True,