Browse Source

- Got rid of .speedlimits file and use new TorrentPersistantData system

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
63761afd0a
  1. 57
      src/bittorrent.cpp
  2. 1
      src/bittorrent.h
  3. 29
      src/torrentPersistentData.h

57
src/bittorrent.cpp

@ -147,9 +147,10 @@ void bittorrent::deleteBigRatios() {
void bittorrent::setDownloadLimit(QString hash, long val) { void bittorrent::setDownloadLimit(QString hash, long val) {
QTorrentHandle h = getTorrentHandle(hash); QTorrentHandle h = getTorrentHandle(hash);
if(h.is_valid()) if(h.is_valid()) {
h.set_download_limit(val); h.set_download_limit(val);
saveTorrentSpeedLimits(hash); TorrentPersistentData::saveSpeedLimits(h);
}
} }
bool bittorrent::isQueueingEnabled() const { bool bittorrent::isQueueingEnabled() const {
@ -172,9 +173,10 @@ void bittorrent::decreaseDlTorrentPriority(QString hash) {
void bittorrent::setUploadLimit(QString hash, long val) { void bittorrent::setUploadLimit(QString hash, long val) {
qDebug("Set upload limit rate to %ld", val); qDebug("Set upload limit rate to %ld", val);
QTorrentHandle h = getTorrentHandle(hash); QTorrentHandle h = getTorrentHandle(hash);
if(h.is_valid()) if(h.is_valid()) {
h.set_upload_limit(val); h.set_upload_limit(val);
saveTorrentSpeedLimits(hash); TorrentPersistentData::saveSpeedLimits(h);
}
} }
void bittorrent::handleDownloadFailure(QString url, QString reason) { void bittorrent::handleDownloadFailure(QString url, QString reason) {
@ -821,36 +823,11 @@ bool bittorrent::enableDHT(bool b) {
return true; return true;
} }
void bittorrent::saveTorrentSpeedLimits(QString hash) {
qDebug("Saving speedLimits file for %s", hash.toLocal8Bit().data());
QTorrentHandle h = getTorrentHandle(hash);
int download_limit = h.download_limit();
int upload_limit = h.upload_limit();
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits");
if(!speeds_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug("* Error: Couldn't open speed limits file for torrent: %s", hash.toLocal8Bit().data());
return;
}
speeds_file.write(misc::toQByteArray(download_limit)+QByteArray(" ")+misc::toQByteArray(upload_limit));
speeds_file.close();
}
void bittorrent::loadTorrentSpeedLimits(QString hash) { void bittorrent::loadTorrentSpeedLimits(QString hash) {
// qDebug("Loading speedLimits file for %s", hash.toLocal8Bit().data());
QTorrentHandle h = getTorrentHandle(hash); QTorrentHandle h = getTorrentHandle(hash);
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits"); qDebug("Loading speedLimits file for %s", hash.toLocal8Bit().data());
if(!speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) { h.set_download_limit(TorrentPersistentData::getDownloadLimit(hash));
return; h.set_upload_limit(TorrentPersistentData::getUploadLimit(hash));
}
QByteArray speed_limits = speeds_file.readAll();
speeds_file.close();
QList<QByteArray> speeds = speed_limits.split(' ');
if(speeds.size() != 2) {
std::cerr << "Invalid .speedLimits file for " << hash.toStdString() << '\n';
return;
}
h.set_download_limit(speeds.at(0).toInt());
h.set_upload_limit(speeds.at(1).toInt());
} }
// Read pieces priorities from hard disk // Read pieces priorities from hard disk
@ -1674,6 +1651,22 @@ void bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
} }
urlseeds_file.remove(); urlseeds_file.remove();
} }
// Load speed limits
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+h.hash()+".speedLimits");
if(speeds_file.exists()) {
if(speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QByteArray speed_limits = speeds_file.readAll();
speeds_file.close();
QList<QByteArray> speeds = speed_limits.split(' ');
if(speeds.size() != 2) {
std::cerr << "Invalid .speedLimits file for " << h.hash().toStdString() << '\n';
return;
}
h.set_download_limit(speeds.at(0).toInt());
h.set_upload_limit(speeds.at(1).toInt());
}
speeds_file.remove();
}
} }
// Import torrents from v1.4.0 or earlier // Import torrents from v1.4.0 or earlier

1
src/bittorrent.h

@ -136,7 +136,6 @@ class bittorrent : public QObject {
void enableIPFilter(QString filter); void enableIPFilter(QString filter);
void disableIPFilter(); void disableIPFilter();
void setQueueingEnabled(bool enable); void setQueueingEnabled(bool enable);
void saveTorrentSpeedLimits(QString hash);
void loadTorrentSpeedLimits(QString hash); void loadTorrentSpeedLimits(QString hash);
void handleDownloadFailure(QString url, QString reason); void handleDownloadFailure(QString url, QString reason);
void loadWebSeeds(QString fileHash); void loadWebSeeds(QString fileHash);

29
src/torrentPersistentData.h

@ -183,7 +183,11 @@ public:
} }
data["url_seeds"] = url_seeds; data["url_seeds"] = url_seeds;
} }
// Sequential download
data["sequential"] = h.is_sequential_download(); data["sequential"] = h.is_sequential_download();
// Speed limits
data["up_speed"] = h.upload_limit();
data["dl_speed"] = h.download_limit();
// Save data // Save data
all_data[h.hash()] = data; all_data[h.hash()] = data;
settings.setValue("torrents", all_data); settings.setValue("torrents", all_data);
@ -236,6 +240,17 @@ public:
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", save_path.toLocal8Bit().data(), hash.toLocal8Bit().data()); qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", save_path.toLocal8Bit().data(), hash.toLocal8Bit().data());
} }
static void saveSpeedLimits(QTorrentHandle h) {
Q_ASSERT(!hash.isEmpty());
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();
data["up_speed"] = h.upload_limit();
data["dl_speed"] = h.download_limit();
all_data[h.hash()] = data;
settings.setValue("torrents", all_data);
}
static void saveUrlSeeds(QTorrentHandle h) { static void saveUrlSeeds(QTorrentHandle h) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
@ -291,6 +306,20 @@ public:
return data["files_priority"].toList(); return data["files_priority"].toList();
} }
static int getUploadLimit(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.value("up_speed", -1).toInt();
}
static int getDownloadLimit(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.value("dl_speed", -1).toInt();
}
static QString getSavePath(QString hash) { static QString getSavePath(QString hash) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();

Loading…
Cancel
Save