mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-27 23:14:31 +00:00
- Remove useless code in torrentpersistentdata since libtorrent is saving and restoring this for us
This commit is contained in:
parent
332a4121c8
commit
aa0c2e611f
@ -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<int> 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<QString, QVariant> tiers = TorrentPersistentData::getTrackers(hash);
|
||||
std::vector<announce_entry> 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) {
|
||||
|
@ -128,7 +128,6 @@ public:
|
||||
float getRealRatio(QString hash) const;
|
||||
session* getSession() const;
|
||||
QHash<QString, TrackerInfos> 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();
|
||||
|
||||
|
@ -217,8 +217,7 @@ void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
|
||||
// List files in torrent
|
||||
PropListModel->clear();
|
||||
PropListModel->setupModelData(h.get_torrent_info());
|
||||
std::vector<int> 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<int> PropertiesWidget::loadFilesPriorities(){
|
||||
std::vector<int> fp;
|
||||
QVariantList files_priority = TorrentPersistentData::getFilesPriority(h.hash());
|
||||
if(files_priority.empty()) {
|
||||
for(int i=0; i<h.num_files(); ++i) {
|
||||
fp.push_back(1);
|
||||
}
|
||||
} else {
|
||||
foreach(const QVariant &var_prio, files_priority) {
|
||||
int priority = var_prio.toInt();
|
||||
if( priority < 0 || priority > 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<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
|
||||
h.prioritize_files(priorities);
|
||||
TorrentPersistentData::saveFilesPriority(h);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,6 @@ private:
|
||||
|
||||
protected:
|
||||
QPushButton* getButtonFromIndex(int index);
|
||||
std::vector<int> loadFilesPriorities();
|
||||
bool savePiecesPriorities();
|
||||
|
||||
protected slots:
|
||||
|
@ -179,71 +179,15 @@ public:
|
||||
}
|
||||
data["seed"] = h.is_seed();
|
||||
data["priority"] = h.queue_position();
|
||||
QVariantList files_priority;
|
||||
std::vector<int> fp = h.file_priorities();
|
||||
std::vector<int>::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<QString, QVariant> trackers;
|
||||
std::vector<announce_entry> tr = h.trackers();
|
||||
std::vector<announce_entry>::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<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
||||
QVariantList trackers;
|
||||
std::vector<announce_entry> tr = h.trackers();
|
||||
std::vector<announce_entry>::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<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
||||
std::vector<int> fp = h.file_priorities();
|
||||
std::vector<int>::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<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> 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<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
@ -287,20 +218,6 @@ public:
|
||||
}
|
||||
|
||||
// Getters
|
||||
static QHash<QString, QVariant> getTrackers(QString hash) {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
||||
return data["trackers"].toHash();
|
||||
}
|
||||
|
||||
static QVariantList getFilesPriority(QString hash) {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> 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<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).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<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> 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<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
|
Loading…
x
Reference in New Issue
Block a user