From 9a0a26dae12cf00231ec563e70ccf56cdc93a43e Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 4 May 2013 15:01:24 +0300 Subject: [PATCH] Store TorrentTempData only in memory. Partially implements #583. --- src/qtlibtorrent/qbtsession.cpp | 3 + src/torrentpersistentdata.h | 115 +++++++++----------------------- 2 files changed, 33 insertions(+), 85 deletions(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 2249f61a4..ff885a731 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -82,6 +82,9 @@ #include #include "dnsupdater.h" +//initialize static member variables +QHash TorrentTempData::data = QHash(); + using namespace libtorrent; QBtSession* QBtSession::m_instance = 0; diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index 23365edf2..c60e897ea 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -44,129 +44,74 @@ class TorrentTempData { public: - static bool hasTempData(QString hash) { - QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - const QHash all_data = settings.value("torrents-tmp").toHash(); - return all_data.contains(hash); + static bool hasTempData(QString hash) { + return data.contains(hash); } static void deleteTempData(QString hash) { - QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - QHash 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 &pp) { - QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - QHash all_data = settings.value("torrents-tmp").toHash(); - QHash data = all_data.value(hash).toHash(); - QStringList pieces_priority; - - std::vector::const_iterator pp_it = pp.begin(); - std::vector::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 all_data = settings.value("torrents-tmp").toHash(); - QHash 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 all_data = settings.value("torrents-tmp").toHash(); - QHash 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 all_data = settings.value("torrents-tmp").toHash(); - QHash 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 all_data = settings.value("torrents-tmp").toHash(); - QHash 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 all_data = settings.value("torrents-tmp").toHash(); - const QHash 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 all_data = settings.value("torrents-tmp").toHash(); - QHash 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 all_data = settings.value("torrents-tmp").toHash(); - const QHash 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 all_data = settings.value("torrents-tmp").toHash(); - const QHash 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 all_data = settings.value("torrents-tmp").toHash(); - const QHash 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 all_data = settings.value("torrents-tmp").toHash(); - const QHash 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 &fp) { - QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); - const QHash all_data = settings.value("torrents-tmp").toHash(); - const QHash data = all_data.value(hash).toHash(); - const QList 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 files_priority; + QStringList path_list; + QString save_path; + QString label; + bool sequential; + bool seed; + }; + + static QHash data; }; class TorrentPersistentData {