# # torrentdetails.py # # Copyright (C) 2007 Andrew Resch ('andar') # # Deluge is free software. # # You may 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 of the License, or (at your option) # any later version. # # deluge 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 deluge. If not, write to: # The Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor # Boston, MA 02110-1301, USA. # # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the OpenSSL # library. # You must obey the GNU General Public License in all respects for all of # the code used other than OpenSSL. If you modify file(s) with this # exception, you may extend this exception to your version of the file(s), # but you are not obligated to do so. If you do not wish to do so, delete # this exception statement from your version. If you delete this exception # statement from all source files in the program, then also delete it here. """The torrent details component shows info about the selected torrent.""" import pygtk pygtk.require('2.0') import gtk, gtk.glade import gettext import deluge.component as component import deluge.ui.client as client import deluge.common from deluge.log import LOG as log class TorrentDetails(component.Component): def __init__(self): component.Component.__init__(self, "TorrentDetails") self.window = component.get("MainWindow") glade = self.window.main_glade self.notebook = glade.get_widget("torrent_info") self.details_tab = glade.get_widget("torrentdetails_tab") # Don't show tabs if there is only 1 if self.notebook.get_n_pages() < 2: self.notebook.set_show_tabs(False) else: self.notebook.set_show_tabs(True) self.is_visible = True # Get the labels we need to update. self.progress_bar = glade.get_widget("progressbar") self.name = glade.get_widget("summary_name") self.total_size = glade.get_widget("summary_total_size") self.num_files = glade.get_widget("summary_num_files") self.pieces = glade.get_widget("summary_pieces") self.availability = glade.get_widget("summary_availability") self.total_downloaded = glade.get_widget("summary_total_downloaded") self.total_uploaded = glade.get_widget("summary_total_uploaded") self.download_speed = glade.get_widget("summary_download_speed") self.upload_speed = glade.get_widget("summary_upload_speed") self.seeders = glade.get_widget("summary_seeders") self.peers = glade.get_widget("summary_peers") self.percentage_done = glade.get_widget("summary_percentage_done") self.share_ratio = glade.get_widget("summary_share_ratio") self.tracker = glade.get_widget("summary_tracker") self.tracker_status = glade.get_widget("summary_tracker_status") self.next_announce = glade.get_widget("summary_next_announce") self.eta = glade.get_widget("summary_eta") self.torrent_path = glade.get_widget("summary_torrent_path") def visible(self, visible): if visible: self.notebook.show() else: self.notebook.hide() self.window.vpaned.set_position(-1) self.is_visible = visible def stop(self): self.clear() def update(self): # Show tabs if more than 1 page if self.notebook.get_n_pages() > 1: self.notebook.set_show_tabs(True) # Only update if this page is showing if self.notebook.page_num(self.details_tab) is \ self.notebook.get_current_page() and \ self.notebook.get_property("visible"): # Get the first selected torrent #selected = self.window.torrentview.get_selected_torrents() selected = component.get("TorrentView").get_selected_torrents() # Only use the first torrent in the list or return if None selected if len(selected) != 0: selected = selected[0] else: # No torrent is selected in the torrentview return # Get the torrent status status_keys = ["progress", "name", "total_size", "num_files", "num_pieces", "piece_length", "distributed_copies", "total_done", "total_payload_download", "total_uploaded", "total_payload_upload", "download_payload_rate", "upload_payload_rate", "num_peers", "num_seeds", "total_peers", "total_seeds", "eta", "ratio", "tracker", "next_announce", "tracker_status", "save_path"] client.get_torrent_status( self._on_get_torrent_status, selected, status_keys) def _on_get_torrent_status(self, status): # Check to see if we got valid data from the core if status is None: return # We need to adjust the value core gives us for progress try: progress = status["progress"]/100 self.progress_bar.set_fraction(progress) self.progress_bar.set_text(deluge.common.fpcnt(progress)) self.name.set_text(status["name"]) self.total_size.set_text( deluge.common.fsize(status["total_size"])) self.num_files.set_text(str(status["num_files"])) self.pieces.set_text("%s (%s)" % (status["num_pieces"], deluge.common.fsize(status["piece_length"]))) self.availability.set_text( "%.3f" % status["distributed_copies"]) self.total_downloaded.set_text("%s (%s)" % \ (deluge.common.fsize(status["total_done"]), deluge.common.fsize(status["total_payload_download"]))) self.total_uploaded.set_text("%s (%s)" % \ (deluge.common.fsize(status["total_uploaded"]), deluge.common.fsize(status["total_payload_upload"]))) self.download_speed.set_text( deluge.common.fspeed(status["download_payload_rate"])) self.upload_speed.set_text( deluge.common.fspeed(status["upload_payload_rate"])) self.seeders.set_text(deluge.common.fpeer(status["num_seeds"], status["total_seeds"])) self.peers.set_text(deluge.common.fpeer(status["num_peers"], status["total_peers"])) self.eta.set_text(deluge.common.ftime(status["eta"])) self.share_ratio.set_text("%.3f" % status["ratio"]) self.tracker.set_text(status["tracker"]) self.tracker_status.set_text(status["tracker_status"]) self.next_announce.set_text( deluge.common.ftime(status["next_announce"])) self.torrent_path.set_text(status["save_path"]) except KeyError, e: log.debug(e) def clear(self): # Only update if this page is showing if self.notebook.page_num(self.details_tab) is \ self.notebook.get_current_page(): self.name.set_text("") self.total_size.set_text("") self.num_files.set_text("") self.pieces.set_text("") self.availability.set_text("") self.total_downloaded.set_text("") self.total_uploaded.set_text("") self.download_speed.set_text("") self.upload_speed.set_text("") self.seeders.set_text("") self.peers.set_text("") self.progress_bar.set_fraction(0.0) self.progress_bar.set_text("") self.share_ratio.set_text("") self.tracker.set_text("") self.tracker_status.set_text("") self.next_announce.set_text("") self.eta.set_text("") self.torrent_path.set_text("")