deluge/plugins/TorrentPieces/__init__.py

133 lines
6.0 KiB
Python
Raw Normal View History

2007-07-31 06:04:40 +00:00
# Copyright (C) 2007 - Micah Bucy <eternalsword@gmail.com>
#
# 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 = _("Torrent Pieces")
plugin_author = "Micah Bucy"
2007-08-03 17:59:32 +00:00
plugin_version = "0.2"
2007-07-31 06:04:40 +00:00
plugin_description = _("""
Adds a pieces tab which gives piece by piece progress for a torrent.
Each piece is represented by a small progress bar.
Pieces currently downloading show up as partially filled progress bars,
but this does not represent percentage done.
More information is provided as a tooltip for each piece.
For currently downloading pieces, the tooltip contains the number
of blocks finished as well as the peer speed for that piece.
When the plugin initializes, such as when enabling the plugin or
when a different torrent is selected, the cpu will spike. This is normal,
as initialization must get information on every piece from libtorrent,
2007-08-03 17:59:32 +00:00
and the cpu will normalize once all of the information is retrieved.
This plugin supports multifile torrents. If a file is skipped, it does not
show up in the pieces tab.
""")
2007-07-31 06:04:40 +00:00
def deluge_init(deluge_path):
global path
path = deluge_path
def enable(core, interface):
global path
return TorrentPieces(path, core, interface)
### The Plugin ###
import deluge
import gtk
from TorrentPieces.tab_pieces import PiecesManager
class TorrentPieces:
def __init__(self, path, core, interface):
print "Loading TorrentPieces plugin..."
self.manager = core
self.parent = interface
2007-08-04 07:41:27 +00:00
scrolledWindow = gtk.ScrolledWindow()
scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.topWidget = scrolledWindow
2007-07-31 06:04:40 +00:00
self.parentNotebook = self.parent.notebook
self.parentNotebook.append_page(self.topWidget, gtk.Label(_("Pieces")))
2007-08-04 07:41:27 +00:00
self.topWidget.show_all()
self.tab_pieces = PiecesManager(self.manager)
2007-07-31 06:04:40 +00:00
def unload(self):
self.manager.disconnect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.tab_pieces.handle_event)
self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_pieces.handle_event)
self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_pieces.handle_event)
2007-07-31 21:54:11 +00:00
self.tab_pieces.clear_pieces_store()
2007-07-31 06:04:40 +00:00
numPages = self.parentNotebook.get_n_pages()
for page in xrange(numPages):
if self.parentNotebook.get_nth_page(page) == self.topWidget:
self.parentNotebook.remove_page(page)
break
def update(self):
2007-08-03 17:59:32 +00:00
update_files_removed = self.manager.update_files_removed
2007-07-31 06:04:40 +00:00
unique_id = self.parent.get_selected_torrent()
if unique_id is None:
2007-08-03 17:59:32 +00:00
#if no torrents added or more than one torrent selected
self.tab_pieces.clear_pieces_store()
2007-07-31 06:04:40 +00:00
return
2007-08-03 17:59:32 +00:00
if unique_id != self.tab_pieces.unique_id or unique_id in update_files_removed.keys():
#if different torrent was selected or file priorities were changed.
2007-08-04 07:41:27 +00:00
self.tab_pieces.clear_pieces_store()
numPages = self.parentNotebook.get_n_pages()
for page in xrange(numPages):
if self.parentNotebook.get_nth_page(page) == self.topWidget:
break
switch_page = False
if self.parentNotebook.get_current_page() == page:
switch_page = True
self.parentNotebook.remove_page(page)
viewport = gtk.Viewport()
scrolledWindow = gtk.ScrolledWindow()
scrolledWindow.add(viewport)
scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
label = gtk.Label(_("""
This is a temporary page used while the pieces tab gets built.
When operations are complete this will automatically become the
pieces tab.
"""))
label.set_alignment(0,0)
viewport.add(label)
self.parentNotebook.insert_page(scrolledWindow,gtk.Label(_("Pieces")),page)
scrolledWindow.show_all()
if switch_page:
self.parentNotebook.set_current_page(page)
2007-07-31 06:04:40 +00:00
self.manager.disconnect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.tab_pieces.handle_event)
self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_pieces.handle_event)
self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_pieces.handle_event)
self.tab_pieces.clear_pieces_store()
self.tab_pieces.set_unique_id(unique_id)
2007-08-04 07:41:27 +00:00
self.topWidget = self.tab_pieces.prepare_pieces_store()
switch_page = False
if self.parentNotebook.get_current_page() == page:
switch_page = True
self.parentNotebook.remove_page(page)
self.parentNotebook = self.parent.notebook
self.parentNotebook.insert_page(self.topWidget, gtk.Label(_("Pieces")), page)
self.topWidget.show_all()
if switch_page:
self.parentNotebook.set_current_page(page)
2007-07-31 06:04:40 +00:00
self.manager.connect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.tab_pieces.handle_event)
self.manager.connect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_pieces.handle_event)
self.manager.connect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_pieces.handle_event)