add 'switch torrent source' to movetorrent plugin

This commit is contained in:
Marcos Pinto 2008-02-12 20:57:46 +00:00
parent cb493591f1
commit 05240945a7
2 changed files with 79 additions and 54 deletions

View File

@ -70,20 +70,27 @@ class movetorrentMenu:
except IOError:
pass
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()
self.moveitem_image = gtk.Image()
self.moveitem_image.set_from_stock(gtk.STOCK_SAVE_AS, gtk.ICON_SIZE_MENU)
self.moveitem = gtk.ImageMenuItem(_("_Move Torrent"))
self.moveitem.set_image(self.moveitem_image)
self.moveitem.connect("activate", self.movetorrent_clicked)
self.interface.torrent_menu.append(self.moveitem)
self.moveitem.show_all()
self.switchitem_image = gtk.Image()
self.switchitem_image.set_from_stock(gtk.STOCK_CONVERT, gtk.ICON_SIZE_MENU)
self.switchitem = gtk.ImageMenuItem(_("_Switch Torrent Source"))
self.switchitem.set_image(self.switchitem_image)
self.switchitem.connect("activate", self.switchtorrent_clicked)
self.interface.torrent_menu.append(self.switchitem)
self.switchitem.show_all()
def update(self):
pass
def unload(self):
self.interface.torrent_menu.remove(self.menuitem)
self.interface.torrent_menu.remove(self.moveitem)
self.interface.torrent_menu.remove(self.switchitem)
self.core.disconnect_event(self.core.constants['EVENT_STORAGE_MOVED'], self.handle_event)
self.core.disconnect_event(self.core.constants['EVENT_FINISHED'], self.handle_event)
self.config.save(self.config_file)
@ -98,6 +105,9 @@ class movetorrentMenu:
for unique_id in unique_ids:
self.core.move_storage(unique_id, path)
def switchtorrent_clicked(self, widget):
self.interface.torrent_switch_recheck(switch=True)
def configure(self, window):
try:
self.glade.get_widget("chk_move_completed").set_active(self.config.get("enable_move_completed"))

View File

@ -564,7 +564,7 @@ window, please enter your password"))
"remove_torrent": self.remove_torrent_clicked,
"edit_trackers": self.list_of_trackers,
"tor_start": self.tor_start,
"torrent_recheck": self.torrent_recheck,
"torrent_switch_recheck": self.torrent_switch_recheck,
"tor_pause": self.tor_pause,
"update_tracker": self.update_tracker,
"clear_finished": self.clear_finished,
@ -760,13 +760,24 @@ window, please enter your password"))
except KeyError:
pass
def torrent_recheck(self, widget):
def torrent_switch_recheck(self, widget=None, switch=False):
unique_ids = self.get_selected_torrent_rows()
for uid in unique_ids:
torrent_state = self.manager.get_torrent_state(uid)
order = torrent_state['queue_pos']
path = self.manager.unique_IDs[uid].filename
if not switch:
save_dir = self.manager.unique_IDs[uid].save_dir
else:
save_dir = dialogs.show_directory_chooser_dialog(self.window, \
_("Choose a directory to switch torrent source to" + " - %s" % \
self.manager.get_torrent_state(uid)['name']))
if save_dir:
delete_old = dialogs.show_popup_question(self.window, \
_("Delete the old torrent source?"))
else:
delete_old = False
if save_dir:
trackerslist = self.manager.unique_IDs[uid].trackers
try:
trackers_changed = self.manager.unique_IDs[uid].trackers_changed
@ -776,11 +787,15 @@ window, please enter your password"))
uploaded_memory = self.manager.unique_IDs[uid].uploaded_memory
priorities = self.manager.get_priorities(uid)
save_info = [path, save_dir, order, trackerslist, \
uploaded_memory, priorities, trackers_changed]
uploaded_memory, priorities, trackers_changed, \
delete_old]
try:
os.remove(self.manager.unique_IDs[uid].filename + ".fastresume")
except:
pass
if save_info[7]:
self.manager.remove_torrent(uid, True, False)
else:
self.manager.remove_torrent(uid, False, False)
self.torrent_model_remove(uid)
self.update()