File indexing completed on 2025-01-05 04:37:26
0001 /* 0002 SPDX-FileCopyrightText: 2009 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "torrentstats.h" 0007 #include <klocalizedstring.h> 0008 #include <util/functions.h> 0009 0010 namespace bt 0011 { 0012 TorrentStats::TorrentStats() 0013 : imported_bytes(0) 0014 , bytes_downloaded(0) 0015 , bytes_uploaded(0) 0016 , bytes_left(0) 0017 , bytes_left_to_download(0) 0018 , total_bytes(0) 0019 , total_bytes_to_download(0) 0020 , download_rate(0) 0021 , upload_rate(0) 0022 , num_peers(0) 0023 , num_chunks_downloading(0) 0024 , total_chunks(0) 0025 , num_chunks_downloaded(0) 0026 , num_chunks_excluded(0) 0027 , num_chunks_left(0) 0028 , chunk_size(0) 0029 , seeders_total(0) 0030 , seeders_connected_to(0) 0031 , leechers_total(0) 0032 , leechers_connected_to(0) 0033 , status(NOT_STARTED) 0034 , session_bytes_downloaded(0) 0035 , session_bytes_uploaded(0) 0036 , running(false) 0037 , started(false) 0038 , queued(false) 0039 , autostart(false) 0040 , stopped_by_error(false) 0041 , completed(false) 0042 , paused(false) 0043 , auto_stopped(false) 0044 , superseeding(false) 0045 , qm_can_start(false) 0046 , multi_file_torrent(false) 0047 , priv_torrent(false) 0048 , max_share_ratio(0.0f) 0049 , max_seed_time(0.0f) 0050 , num_corrupted_chunks(0) 0051 { 0052 last_download_activity_time = last_upload_activity_time = bt::CurrentTime(); 0053 } 0054 0055 float TorrentStats::shareRatio() const 0056 { 0057 if (bytes_downloaded == 0) 0058 return 0.0f; 0059 else 0060 return (float)bytes_uploaded / (bytes_downloaded /*+ stats.imported_bytes*/); 0061 } 0062 0063 bool TorrentStats::overMaxRatio() const 0064 { 0065 return (completed && max_share_ratio > 0) && (shareRatio() - max_share_ratio > 0.00001); 0066 } 0067 0068 QString TorrentStats::statusToString() const 0069 { 0070 switch (status) { 0071 case NOT_STARTED: 0072 return i18n("Not started"); 0073 case DOWNLOAD_COMPLETE: 0074 return i18n("Download completed"); 0075 case SEEDING_COMPLETE: 0076 return i18n("Seeding completed"); 0077 case SEEDING: 0078 return i18nc("Status of a torrent file", "Seeding"); 0079 case DOWNLOADING: 0080 return i18n("Downloading"); 0081 case STALLED: 0082 return i18n("Stalled"); 0083 case STOPPED: 0084 return i18n("Stopped"); 0085 case ERROR: 0086 return i18n("Error: %1", error_msg); 0087 case ALLOCATING_DISKSPACE: 0088 return i18n("Allocating diskspace"); 0089 case QUEUED: 0090 return completed ? i18n("Queued for seeding") : i18n("Queued for downloading"); 0091 case CHECKING_DATA: 0092 return i18n("Checking data"); 0093 case NO_SPACE_LEFT: 0094 return i18n("Stopped. No space left on device."); 0095 case PAUSED: 0096 return i18n("Paused"); 0097 case SUPERSEEDING: 0098 return i18n("Superseeding"); 0099 default: 0100 return QString(); 0101 } 0102 } 0103 }