From aa0c2e611fc2755cf67a23eaab22d483c5f46116 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 20 Nov 2009 18:29:13 +0000 Subject: [PATCH] - Remove useless code in torrentpersistentdata since libtorrent is saving and restoring this for us --- src/bittorrent.cpp | 107 +----------------------------------- src/bittorrent.h | 5 -- src/propertieswidget.cpp | 32 +---------- src/propertieswidget.h | 1 - src/torrentpersistentdata.h | 93 ------------------------------- 5 files changed, 5 insertions(+), 233 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 9c89930dc..9001812dc 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -628,32 +628,6 @@ void Bittorrent::resumeTorrent(QString hash) { } } -void Bittorrent::loadWebSeeds(QString hash) { - QVariantList url_seeds = TorrentPersistentData::getUrlSeeds(hash); - QTorrentHandle h = getTorrentHandle(hash); - // First remove from the torrent the url seeds that were deleted - // in a previous session - QStringList seeds_to_delete; - QStringList existing_seeds = h.url_seeds(); - foreach(const QString &existing_seed, existing_seeds) { - if(!url_seeds.contains(existing_seed.toLocal8Bit())) { - seeds_to_delete << existing_seed; - } - } - foreach(const QString &existing_seed, seeds_to_delete) { - h.remove_url_seed(existing_seed); - } - // Add the ones that were added in a previous session - foreach(const QVariant &var_url_seed, url_seeds) { - QString url_seed = var_url_seed.toString(); - if(!url_seed.isEmpty()) { - // XXX: Should we check if it is already in the list before adding it - // or is libtorrent clever enough to know - h.add_url_seed(url_seed); - } - } -} - QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { QTorrentHandle h; QString hash = misc::magnetUriToHash(magnet_uri); @@ -734,14 +708,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { // Resolve countries h.resolve_countries(resolve_countries); // Load filtered files - if(resumed) { - // Load custom url seeds - loadWebSeeds(hash); - // Load trackers - loadTrackerFile(hash); - // XXX: only when resuming because torrentAddition dialog is not supported yet - loadFilesPriorities(h); - } else { + if(!resumed) { // Sequential download if(TorrentTempData::hasTempData(hash)) { qDebug("addMagnetUri: Setting download as sequential (from tmp data)"); @@ -907,14 +874,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr // Resolve countries qDebug("AddTorrent: Resolve_countries: %d", (int)resolve_countries); h.resolve_countries(resolve_countries); - // Load filtered files - loadFilesPriorities(h); - if(resumed) { - // Load custom url seeds - loadWebSeeds(hash); - // Load trackers - loadTrackerFile(hash); - } else { + if(!resumed) { // Sequential download if(TorrentTempData::hasTempData(hash)) { qDebug("addTorrent: Setting download as sequential (from tmp data)"); @@ -962,22 +922,6 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr return h; } - - -// Check if the user filtered files in this torrent. -bool Bittorrent::has_filtered_files(QString hash) const{ - QVariantList files_priority = TorrentPersistentData::getFilesPriority(hash); - foreach(QVariant var_prio, files_priority) { - int priority = var_prio.toInt(); - if( priority < 0 || priority > 7) { - priority = 1; - } - if(!priority) - return true; - } - return false; -} - // Set the maximum number of opened connections void Bittorrent::setMaxConnections(int maxConnec) { s->set_max_connections(maxConnec); @@ -1117,33 +1061,6 @@ bool Bittorrent::enableDHT(bool b) { return true; } -// Read pieces priorities from hard disk -// and ask QTorrentHandle to consider them -void Bittorrent::loadFilesPriorities(QTorrentHandle &h) { - qDebug("Applying files priority"); - if(!h.is_valid()) { - qDebug("/!\\ Error: Invalid handle"); - return; - } - std::vector v; - QVariantList files_priority; - if(TorrentTempData::hasTempData(h.hash())) { - files_priority = TorrentTempData::getFilesPriority(h.hash()); - } else { - files_priority = TorrentPersistentData::getFilesPriority(h.hash()); - } - foreach(const QVariant &var_prio, files_priority) { - int priority = var_prio.toInt(); - if( priority < 0 || priority > 7) { - priority = 1; - } - //qDebug("Setting file piority to %d", priority); - v.push_back(priority); - } - if(v.size() == (unsigned int)h.num_files()) - h.prioritize_files(v); -} - float Bittorrent::getRealRatio(QString hash) const{ QTorrentHandle h = getTorrentHandle(hash); Q_ASSERT(h.all_time_download() >= 0); @@ -1308,11 +1225,6 @@ void Bittorrent::setDefaultTempPath(QString temppath) { defaultTempPath = temppath; } -void Bittorrent::saveTrackerFile(QString hash) { - QTorrentHandle h = getTorrentHandle(hash); - TorrentPersistentData::saveTrackers(h); -} - // Enable directory scanning void Bittorrent::enableDirectoryScanning(QString scan_dir) { if(!scan_dir.isEmpty()) { @@ -1411,21 +1323,6 @@ void Bittorrent::setDeleteRatio(float ratio) { } } -void Bittorrent::loadTrackerFile(QString hash) { - QHash tiers = TorrentPersistentData::getTrackers(hash); - std::vector trackers; - foreach(const QString tracker_url, tiers.keys()) { - announce_entry t(tracker_url.toStdString()); - t.tier = tiers[tracker_url].toInt(); - trackers.push_back(t); - } - if(!trackers.empty()) { - QTorrentHandle h = getTorrentHandle(hash); - h.replace_trackers(trackers); - h.force_reannounce(); - } -} - // Set DHT port (>= 1000 or 0 if same as BT) void Bittorrent::setDHTPort(int dht_port) { if(dht_port == 0 or dht_port >= 1000) { diff --git a/src/bittorrent.h b/src/bittorrent.h index a156593dd..c12027d64 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -128,7 +128,6 @@ public: float getRealRatio(QString hash) const; session* getSession() const; QHash getTrackersInfo(QString hash) const; - bool has_filtered_files(QString hash) const; bool hasActiveTorrents() const; bool isQueueingEnabled() const; int getMaximumActiveDownloads() const; @@ -166,7 +165,6 @@ public slots: void disableIPFilter(); void setQueueingEnabled(bool enable); void handleDownloadFailure(QString url, QString reason); - void loadWebSeeds(QString fileHash); void downloadUrlAndSkipDialog(QString url, QString save_path=QString::null); // Session configuration - Setters void setListeningPort(int port); @@ -183,7 +181,6 @@ public slots: void startTorrentsInPause(bool b); void setDefaultTempPath(QString temppath); void applyEncryptionSettings(pe_settings se); - void loadFilesPriorities(QTorrentHandle& h); void setDownloadLimit(QString hash, long val); void setUploadLimit(QString hash, long val); void enableUPnP(bool b); @@ -193,7 +190,6 @@ public slots: void addConsoleMessage(QString msg, QColor color=QApplication::palette().color(QPalette::WindowText)); void addPeerBanMessage(QString msg, bool from_ipfilter); void processDownloadedFile(QString, QString); - void saveTrackerFile(QString hash); void addMagnetSkipAddDlg(QString uri); void downloadFromURLList(const QStringList& urls); void configureSession(); @@ -202,7 +198,6 @@ public slots: protected slots: void addTorrentsFromScanFolder(QStringList&); void readAlerts(); - void loadTrackerFile(QString hash); void deleteBigRatios(); void takeETASamples(); diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index 256e9873f..0faf53ed1 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -217,8 +217,7 @@ void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) { // List files in torrent PropListModel->clear(); PropListModel->setupModelData(h.get_torrent_info()); - std::vector files_priority = loadFilesPriorities(); - PropListModel->updateFilesPriorities(files_priority); + PropListModel->updateFilesPriorities(h.file_priorities()); // Expand first item if possible filesList->expand(PropListModel->index(0, 0)); } catch(invalid_handle e) { @@ -343,9 +342,8 @@ void PropertiesWidget::loadDynamicData() { void PropertiesWidget::loadUrlSeeds(){ QStringList already_added; listWebSeeds->clear(); - QVariantList url_seeds = TorrentPersistentData::getUrlSeeds(h.hash()); - foreach(const QVariant &var_url_seed, url_seeds){ - QString url_seed = var_url_seed.toString(); + QStringList url_seeds = h.url_seeds(); + foreach(const QString &url_seed, url_seeds){ if(!url_seed.isEmpty()) { new QListWidgetItem(url_seed, listWebSeeds); already_added << url_seed; @@ -432,26 +430,6 @@ void PropertiesWidget::on_files_button_clicked() { } } -std::vector PropertiesWidget::loadFilesPriorities(){ - std::vector fp; - QVariantList files_priority = TorrentPersistentData::getFilesPriority(h.hash()); - if(files_priority.empty()) { - for(int i=0; i 7){ - // Normal priority as default - priority = 1; - } - fp.push_back(priority); - } - } - return fp; -} - void PropertiesWidget::displayFilesListMenu(const QPoint&){ //if(h.get_torrent_info().num_files() == 1) return; QMenu myFilesLlistMenu(this); @@ -530,7 +508,6 @@ void PropertiesWidget::askWebSeed(){ return; } h.add_url_seed(url_seed); - TorrentPersistentData::saveUrlSeeds(h); // Refresh the seeds list loadUrlSeeds(); } @@ -544,8 +521,6 @@ void PropertiesWidget::deleteSelectedUrlSeeds(){ change = true; } if(change){ - // Save them to disk - TorrentPersistentData::saveUrlSeeds(h); // Refresh list loadUrlSeeds(); } @@ -555,7 +530,6 @@ bool PropertiesWidget::savePiecesPriorities() { qDebug("Saving pieces priorities"); std::vector priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files()); h.prioritize_files(priorities); - TorrentPersistentData::saveFilesPriority(h); return true; } diff --git a/src/propertieswidget.h b/src/propertieswidget.h index b7bd9a7a3..580848c2e 100644 --- a/src/propertieswidget.h +++ b/src/propertieswidget.h @@ -74,7 +74,6 @@ private: protected: QPushButton* getButtonFromIndex(int index); - std::vector loadFilesPriorities(); bool savePiecesPriorities(); protected slots: diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index 5a30d405a..a9a88cdd3 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -179,71 +179,15 @@ public: } data["seed"] = h.is_seed(); data["priority"] = h.queue_position(); - QVariantList files_priority; - std::vector fp = h.file_priorities(); - std::vector::iterator fp_it = fp.begin(); - while(fp_it != fp.end()) { - files_priority << *fp_it; - fp_it++; - } - data["files_priority"] = files_priority; data["save_path"] = h.save_path(); - QHash trackers; - std::vector tr = h.trackers(); - std::vector::iterator tr_it = tr.begin(); - while(tr_it != tr.end()) { - trackers[misc::toQString((*tr_it).url)] = (*tr_it).tier; - tr_it++; - } - data["trackers"] = trackers; - if(!is_magnet) { - QVariantList url_seeds; - foreach(QString url_seed, h.url_seeds()) { - url_seeds << url_seed; - } - data["url_seeds"] = url_seeds; - } // Save data all_data[h.hash()] = data; settings.setValue("torrents", all_data); qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", h.save_path().toLocal8Bit().data(), h.hash().toLocal8Bit().data()); } - static void saveTrackers(QTorrentHandle h) { - QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - QHash all_data = settings.value("torrents", QHash()).toHash(); - QHash data = all_data[h.hash()].toHash(); - QVariantList trackers; - std::vector tr = h.trackers(); - std::vector::iterator tr_it = tr.begin(); - while(tr_it != tr.end()) { - trackers << misc::toQString((*tr_it).url); - tr_it++; - } - data["trackers"] = trackers; - // Save data - all_data[h.hash()] = data; - settings.setValue("torrents", all_data); - } - // Setters - static void saveFilesPriority(QTorrentHandle h) { - QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - QHash all_data = settings.value("torrents", QHash()).toHash(); - QHash data = all_data[h.hash()].toHash(); - std::vector fp = h.file_priorities(); - std::vector::iterator fp_it = fp.begin(); - QVariantList files_priority; - while(fp_it != fp.end()) { - files_priority << *fp_it; - fp_it++; - } - data["files_priority"] = files_priority; - all_data[h.hash()] = data; - settings.setValue("torrents", all_data); - } - static void saveSavePath(QString hash, QString save_path) { Q_ASSERT(!hash.isEmpty()); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); @@ -255,19 +199,6 @@ public: qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", save_path.toLocal8Bit().data(), hash.toLocal8Bit().data()); } - static void saveUrlSeeds(QTorrentHandle h) { - QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - QHash all_data = settings.value("torrents", QHash()).toHash(); - QHash data = all_data[h.hash()].toHash(); - QVariantList url_seeds; - foreach(QString url_seed, h.url_seeds()) { - url_seeds << url_seed; - } - data["url_seeds"] = url_seeds; - all_data[h.hash()] = data; - settings.setValue("torrents", all_data); - } - static void savePriority(QTorrentHandle h) { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents", QHash()).toHash(); @@ -287,20 +218,6 @@ public: } // Getters - static QHash getTrackers(QString hash) { - QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - QHash all_data = settings.value("torrents", QHash()).toHash(); - QHash data = all_data[hash].toHash(); - return data["trackers"].toHash(); - } - - static QVariantList getFilesPriority(QString hash) { - QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - QHash all_data = settings.value("torrents", QHash()).toHash(); - QHash data = all_data[hash].toHash(); - return data["files_priority"].toList(); - } - static QString getSavePath(QString hash) { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents", QHash()).toHash(); @@ -316,16 +233,6 @@ public: return data["priority"].toInt(); } - static QVariantList getUrlSeeds(QString hash) { - QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - QHash all_data = settings.value("torrents", QHash()).toHash(); - QHash data = all_data[hash].toHash(); - if(data.contains("url_seeds")) { - return data["url_seeds"].toList(); - } - return QVariantList(); - } - static bool isSeed(QString hash) { QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents", QHash()).toHash();