diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index d9cbef42a..c65353287 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -83,7 +83,7 @@ //initialize static member variables QHash TorrentTempData::data = QHash(); -QStringList HiddenData::hashes = QStringList(); +QHash HiddenData::data = QHash(); unsigned int HiddenData::metadata_counter = 0; using namespace libtorrent; @@ -428,9 +428,17 @@ void QBtSession::configureSession() { #endif // Queueing System if (pref.isQueueingSystemEnabled()) { - sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize(); + int max_downloading = pref.getMaxActiveDownloads(); + int max_active = pref.getMaxActiveTorrents(); + if (max_downloading > -1) + sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize(); + else + sessionSettings.active_downloads = max_downloading; + if (max_active > -1) + sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize(); + else + sessionSettings.active_limit = max_active; sessionSettings.active_seeds = pref.getMaxActiveUploads(); - sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize(); sessionSettings.dont_count_slow_torrents = pref.ignoreSlowTorrentsForQueueing(); setQueueingEnabled(true); } else { @@ -991,8 +999,16 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f if (HiddenData::hasData(hash) && pref.isQueueingSystemEnabled()) { //Internally increase the queue limits to ensure that the magnet is started libtorrent::session_settings sessionSettings(s->settings()); - sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize(); - sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize(); + int max_downloading = pref.getMaxActiveDownloads(); + int max_active = pref.getMaxActiveTorrents(); + if (max_downloading > -1) + sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize(); + else + sessionSettings.active_downloads = max_downloading; + if (max_active > -1) + sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize(); + else + sessionSettings.active_limit = max_active; s->set_settings(sessionSettings); h.queue_position_top(); } @@ -2403,12 +2419,20 @@ void QBtSession::readAlerts() { if (h.is_valid()) { QString hash(h.hash()); if (HiddenData::hasData(hash)) { - HiddenData::gotMetadata(); + HiddenData::gotMetadata(hash); if (pref.isQueueingSystemEnabled()) { //Internally decrease the queue limits to ensure that that other queued items aren't started libtorrent::session_settings sessionSettings(s->settings()); - sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize(); - sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize(); + int max_downloading = pref.getMaxActiveDownloads(); + int max_active = pref.getMaxActiveTorrents(); + if (max_downloading > -1) + sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize(); + else + sessionSettings.active_downloads = max_downloading; + if (max_active > -1) + sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize(); + else + sessionSettings.active_limit = max_active; s->set_settings(sessionSettings); } h.pause(); @@ -2958,16 +2982,26 @@ void QBtSession::backupPersistentData(const QString &hash, boost::shared_ptrsettings()); - sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize(); - sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize(); + int max_downloading = pref.getMaxActiveDownloads(); + int max_active = pref.getMaxActiveTorrents(); + if (max_downloading > -1) + sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize(); + else + sessionSettings.active_downloads = max_downloading; + if (max_active > -1) + sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize(); + else + sessionSettings.active_limit = max_active; s->set_settings(sessionSettings); - } - HiddenData::deleteData(hash); + } TorrentTempData::deleteTempData(hash); return; } @@ -2976,8 +3010,16 @@ void QBtSession::unhideMagnet(const QString &hash) { if (pref.isQueueingSystemEnabled()) { //Internally decrease the queue limits to ensure that other queued items aren't started libtorrent::session_settings sessionSettings(s->settings()); - sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize(); - sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize(); + int max_downloading = pref.getMaxActiveDownloads(); + int max_active = pref.getMaxActiveTorrents(); + if (max_downloading > -1) + sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize(); + else + sessionSettings.active_downloads = max_downloading; + if (max_active > -1) + sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize(); + else + sessionSettings.active_limit = max_active; s->set_settings(sessionSettings); } if (pref.addTorrentsInPause()) @@ -2985,12 +3027,10 @@ void QBtSession::unhideMagnet(const QString &hash) { } h.queue_position_bottom(); - loadTorrentTempData(h, h.save_path(), !h.has_metadata()); - + loadTorrentTempData(h, h.save_path(), !h.has_metadata()); //TempData are deleted by a call to TorrentPersistentData::saveTorrentPersistentData() if (!pref.addTorrentsInPause()) h.resume(); - HiddenData::deleteData(hash); - h.move_storage(TorrentTempData::getSavePath(hash)); - TorrentTempData::deleteTempData(hash); + h.move_storage(save_path); + emit addedTorrent(h); } diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index b36a81460..6f560cbe4 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -117,32 +117,36 @@ private: class HiddenData { public: static void addData(const QString &hash) { - hashes.append(hash); + data[hash] = false; } static bool hasData(const QString &hash) { - return hashes.contains(hash, Qt::CaseInsensitive); + return data.contains(hash); } static void deleteData(const QString &hash) { - if (hashes.removeAll(hash)) + if (data.value(hash, false)) metadata_counter--; + data.remove(hash); } static int getSize() { - return hashes.size(); + return data.size(); } static int getDownloadingSize() { - return hashes.size() - metadata_counter; + return data.size() - metadata_counter; } - static void gotMetadata() { + static void gotMetadata(const QString &hash) { + if (!data.contains(hash)) + return; + data[hash] = true; metadata_counter++; } private: - static QStringList hashes; + static QHash data; static unsigned int metadata_counter; };