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. 111
      src/torrentpersistentdata.h

3
src/qtlibtorrent/qbtsession.cpp

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

111
src/torrentpersistentdata.h

@ -45,128 +45,73 @@
class TorrentTempData { class TorrentTempData {
public: public:
static bool hasTempData(QString hash) { static bool hasTempData(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); return data.contains(hash);
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
return all_data.contains(hash);
} }
static void deleteTempData(QString hash) { static void deleteTempData(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); data.remove(hash);
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);
}
} }
static void setFilesPriority(QString hash, const std::vector<int> &pp) { static void setFilesPriority(QString hash, const std::vector<int> &pp) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); data[hash].files_priority = pp;
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);
} }
static void setFilesPath(QString hash, const QStringList &path_list) { static void setFilesPath(QString hash, const QStringList &path_list) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); data[hash].path_list = path_list;
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);
} }
static void setSavePath(QString hash, QString save_path) { static void setSavePath(QString hash, QString save_path) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); data[hash].save_path = save_path;
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);
} }
static void setLabel(QString hash, QString label) { static void setLabel(QString hash, QString label) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); data[hash].label = label;
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);
} }
static void setSequential(QString hash, bool sequential) { static void setSequential(QString hash, bool sequential) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); data[hash].sequential = sequential;
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);
} }
static bool isSequential(QString hash) { static bool isSequential(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); return data.value(hash).sequential;
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();
} }
static void setSeedingMode(QString hash, bool seed) { static void setSeedingMode(QString hash, bool seed) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); data[hash].seed = seed;
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 bool isSeedingMode(QString hash) { static bool isSeedingMode(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); return data.value(hash).seed;
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();
} }
static QString getSavePath(QString hash) { static QString getSavePath(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); return data.value(hash).save_path;
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();
} }
static QStringList getFilesPath(QString hash) { static QStringList getFilesPath(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); return data.value(hash).path_list;
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();
} }
static QString getLabel(QString hash) { static QString getLabel(QString hash) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); return data.value(hash).label;
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();
} }
static void getFilesPriority(QString hash, std::vector<int> &fp) { static void getFilesPriority(QString hash, std::vector<int> &fp) {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); fp = data.value(hash).files_priority;
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()); private:
foreach (const int &var, list_var) { struct TorrentData {
fp.push_back(var); 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 { class TorrentPersistentData {

Loading…
Cancel
Save