Pieces plugin updates from eternalswd, thanks.

This commit is contained in:
Alex Dedul 2007-08-07 03:17:30 +00:00
parent 48bdbbb060
commit 2c45b379fc
2 changed files with 19 additions and 12 deletions

View File

@ -69,9 +69,7 @@ class TorrentPieces:
self.tab_pieces = PiecesTabManager(self.manager)
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)
self.tab_pieces.disconnect_handlers()
self.tab_pieces.clear_pieces_store()
numPages = self.parentNotebook.get_n_pages()
for page in xrange(numPages):
@ -84,10 +82,12 @@ class TorrentPieces:
unique_id = self.parent.get_selected_torrent()
if unique_id is None:
#if no torrents added or more than one torrent selected
self.tab_pieces.disconnect_handlers()
self.tab_pieces.clear_pieces_store()
return
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.
self.tab_pieces.disconnect_handlers()
self.tab_pieces.clear_pieces_store()
numPages = self.parentNotebook.get_n_pages()
for page in xrange(numPages):
@ -112,10 +112,6 @@ pieces tab.
scrolledWindow.show_all()
if switch_page:
self.parentNotebook.set_current_page(page)
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)
self.topWidget = self.tab_pieces.prepare_pieces_store()
switch_page = False
@ -127,6 +123,4 @@ pieces tab.
self.topWidget.show_all()
if switch_page:
self.parentNotebook.set_current_page(page)
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)
self.tab_pieces.connect_handlers()

View File

@ -24,6 +24,7 @@ class PiecesTabManager(object):
self.num_files = 0
self.current_first_index = None
self.current_last_index = None
self.handlers_connected = False
def set_unique_id(self, unique_id):
self.unique_id = unique_id
@ -130,10 +131,9 @@ class PiecesTabManager(object):
diff = 0
temp_range = self.current_last_index-self.current_first_index
#last piece handled outside of loop, skip it from range
temp_first_index = self.current_first_index
for index in xrange(temp_range):
gtk.main_iteration_do(False)
main_index = diff+temp_first_index+index
main_index = diff+self.current_first_index+index
if temp_prev_priority > 0:
#normal behavior
self.piece_info.append({'blocks_total':0, 'blocks_finished':0, 'blocks_requested':0})
@ -231,6 +231,19 @@ class PiecesTabManager(object):
self.tooltips.append(None)
self.peer_speed.append(None)
def connect_handlers(self):
self.handlers_connected = True
self.manager.connect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.handle_event)
self.manager.connect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.handle_event)
self.manager.connect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.handle_event)
def disconnect_handlers(self):
if self.handlers_connected:
self.manager.disconnect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.handle_event)
self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.handle_event)
self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.handle_event)
self.handlers_connected = False
def handle_event(self, event):
#protect against pieces trying to display after file priority changed
#or different torrent selected