Browse Source

Store TorrentTempData only in memory. Partially implements #583.

adaptive-webui-19844
sledgehammer999 12 years ago
parent
commit
9a0a26dae1
  1. 3
      src/qtlibtorrent/qbtsession.cpp
  2. 113
      src/torrentpersistentdata.h

3
src/qtlibtorrent/qbtsession.cpp

@ -82,6 +82,9 @@ @@ -82,6 +82,9 @@
#include <string.h>
#include "dnsupdater.h"
//initialize static member variables
QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QString, TorrentTempData::TorrentData>();
using namespace libtorrent;
QBtSession* QBtSession::m_instance = 0;

113
src/torrentpersistentdata.h

@ -45,128 +45,73 @@ @@ -45,128 +45,73 @@
class TorrentTempData {
public:
static bool hasTempData(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
return all_data.contains(hash);
return data.contains(hash);
}
static void deleteTempData(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
if (all_data.contains(hash)) {
all_data.remove(hash);
settings.setValue("torrents-tmp", all_data);
}
data.remove(hash);
}
static void setFilesPriority(QString hash, const std::vector<int> &pp) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data.value(hash).toHash();
QStringList pieces_priority;
std::vector<int>::const_iterator pp_it = pp.begin();
std::vector<int>::const_iterator pp_itend = pp.end();
while(pp_it != pp_itend) {
pieces_priority << QString::number(*pp_it);
++pp_it;
}
data["files_priority"] = pieces_priority;
all_data[hash] = data;
settings.setValue("torrents-tmp", all_data);
data[hash].files_priority = pp;
}
static void setFilesPath(QString hash, const QStringList &path_list) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["files_path"] = path_list;
all_data[hash] = data;
settings.setValue("torrents-tmp", all_data);
data[hash].path_list = path_list;
}
static void setSavePath(QString hash, QString save_path) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["save_path"] = save_path;
all_data[hash] = data;
settings.setValue("torrents-tmp", all_data);
data[hash].save_path = save_path;
}
static void setLabel(QString hash, QString label) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data.value(hash).toHash();
qDebug("Saving label %s to tmp data", label.toLocal8Bit().data());
data["label"] = label;
all_data[hash] = data;
settings.setValue("torrents-tmp", all_data);
data[hash].label = label;
}
static void setSequential(QString hash, bool sequential) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["sequential"] = sequential;
all_data[hash] = data;
settings.setValue("torrents-tmp", all_data);
data[hash].sequential = sequential;
}
static bool isSequential(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("sequential", false).toBool();
return data.value(hash).sequential;
}
static void setSeedingMode(QString hash,bool seed) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
QHash<QString, QVariant> data = all_data.value(hash).toHash();
data["seeding"] = seed;
all_data[hash] = data;
settings.setValue("torrents-tmp", all_data);
static void setSeedingMode(QString hash, bool seed) {
data[hash].seed = seed;
}
static bool isSeedingMode(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("seeding", false).toBool();
return data.value(hash).seed;
}
static QString getSavePath(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("save_path").toString();
return data.value(hash).save_path;
}
static QStringList getFilesPath(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
return data.value("files_path").toStringList();
return data.value(hash).path_list;
}
static QString getLabel(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
qDebug("Got label %s from tmp data", data.value("label", "").toString().toLocal8Bit().data());
return data.value("label", "").toString();
return data.value(hash).label;
}
static void getFilesPriority(QString hash, std::vector<int> &fp) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
const QList<int> list_var = misc::intListfromStringList(data.value("files_priority").toStringList());
foreach (const int &var, list_var) {
fp.push_back(var);
}
}
fp = data.value(hash).files_priority;
}
private:
struct TorrentData {
TorrentData(): sequential(false), seed(false) {}
std::vector<int> files_priority;
QStringList path_list;
QString save_path;
QString label;
bool sequential;
bool seed;
};
static QHash<QString, TorrentData> data;
};
class TorrentPersistentData {

Loading…
Cancel
Save