2009-08-16 07:09:20 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TORRENTPERSISTENTDATA_H
|
|
|
|
#define TORRENTPERSISTENTDATA_H
|
|
|
|
|
|
|
|
#include <QVariant>
|
2010-03-20 22:09:27 +03:00
|
|
|
#include <QDateTime>
|
2010-10-31 19:05:59 +03:00
|
|
|
#include <QDebug>
|
2010-06-07 12:32:41 +04:00
|
|
|
#include <libtorrent/version.hpp>
|
2009-08-16 07:09:20 +04:00
|
|
|
#include <libtorrent/magnet_uri.hpp>
|
|
|
|
#include "qtorrenthandle.h"
|
|
|
|
#include "misc.h"
|
2009-12-08 20:20:28 +03:00
|
|
|
#include <vector>
|
2010-07-16 19:03:18 +04:00
|
|
|
#include "qinisettings.h"
|
2010-03-04 21:40:11 +03:00
|
|
|
#include <QHash>
|
2009-11-29 00:46:46 +03:00
|
|
|
|
2009-08-16 07:09:20 +04:00
|
|
|
class TorrentTempData {
|
|
|
|
public:
|
|
|
|
static bool hasTempData(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
return all_data.contains(hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deleteTempData(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
if(all_data.contains(hash)) {
|
|
|
|
all_data.remove(hash);
|
|
|
|
settings.setValue("torrents-tmp", all_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 23:19:25 +03:00
|
|
|
static void setFilesPriority(QString hash, const std::vector<int> &pp) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2010-03-04 23:19:25 +03:00
|
|
|
std::vector<int>::const_iterator pp_it = pp.begin();
|
2010-06-05 22:59:05 +04:00
|
|
|
QStringList pieces_priority;
|
2009-08-16 07:09:20 +04:00
|
|
|
while(pp_it != pp.end()) {
|
2010-06-05 22:59:05 +04:00
|
|
|
pieces_priority << QString::number(*pp_it);
|
2009-08-16 07:09:20 +04:00
|
|
|
pp_it++;
|
|
|
|
}
|
|
|
|
data["files_priority"] = pieces_priority;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents-tmp", all_data);
|
|
|
|
}
|
|
|
|
|
2010-03-04 23:19:25 +03:00
|
|
|
static void setFilesPath(QString hash, const QStringList &path_list) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2010-01-01 13:55:13 +03:00
|
|
|
data["files_path"] = path_list;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents-tmp", all_data);
|
|
|
|
}
|
|
|
|
|
2009-08-16 07:09:20 +04:00
|
|
|
static void setSavePath(QString hash, QString save_path) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
data["save_path"] = save_path;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents-tmp", all_data);
|
|
|
|
}
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
static void setLabel(QString hash, QString label) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-12-18 19:32:26 +03:00
|
|
|
qDebug("Saving label %s to tmp data", label.toLocal8Bit().data());
|
2009-12-15 22:52:43 +03:00
|
|
|
data["label"] = label;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents-tmp", all_data);
|
|
|
|
}
|
|
|
|
|
2009-08-16 07:09:20 +04:00
|
|
|
static void setSequential(QString hash, bool sequential) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
data["sequential"] = sequential;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents-tmp", all_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isSequential(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
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();
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2009-11-05 21:39:27 +03:00
|
|
|
static void setSeedingMode(QString hash,bool seed){
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-11-05 21:39:27 +03:00
|
|
|
data["seeding"] = seed;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents-tmp", all_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isSeedingMode(QString hash){
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
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();
|
2009-11-05 21:39:27 +03:00
|
|
|
}
|
2009-11-18 13:29:20 +03:00
|
|
|
#endif
|
2009-11-05 21:39:27 +03:00
|
|
|
|
2009-08-16 07:09:20 +04:00
|
|
|
static QString getSavePath(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
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();
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
2010-01-01 13:55:13 +03:00
|
|
|
static QStringList getFilesPath(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
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();
|
2010-01-01 13:55:13 +03:00
|
|
|
}
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
static QString getLabel(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents-tmp").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-12-18 19:32:26 +03:00
|
|
|
qDebug("Got label %s from tmp data", data.value("label", "").toString().toLocal8Bit().data());
|
|
|
|
return data.value("label", "").toString();
|
2009-12-15 22:52:43 +03:00
|
|
|
}
|
|
|
|
|
2010-10-17 18:46:01 +04:00
|
|
|
static void getFilesPriority(QString hash, std::vector<int> &fp) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
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);
|
2009-12-08 20:20:28 +03:00
|
|
|
}
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TorrentPersistentData {
|
|
|
|
public:
|
|
|
|
|
|
|
|
static bool isKnownTorrent(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
return all_data.contains(hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
static QStringList knownTorrents() {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
return all_data.keys();
|
|
|
|
}
|
|
|
|
|
2010-01-30 19:28:07 +03:00
|
|
|
static void setAddedDate(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2010-01-30 19:28:07 +03:00
|
|
|
if(!data.contains("add_date")) {
|
2010-10-17 18:46:01 +04:00
|
|
|
data["add_date"] = QDateTime::currentDateTime();
|
2010-01-30 19:28:07 +03:00
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static QDateTime getAddedDate(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
QDateTime dt = data.value("add_date").toDateTime();
|
2010-01-30 19:28:07 +03:00
|
|
|
if(!dt.isValid()) {
|
|
|
|
setAddedDate(hash);
|
|
|
|
dt = QDateTime::currentDateTime();
|
|
|
|
}
|
|
|
|
return dt;
|
|
|
|
}
|
2010-07-16 23:53:47 +04:00
|
|
|
|
2010-07-25 18:55:30 +04:00
|
|
|
static void setErrorState(QString hash, bool has_error) {
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
data["has_error"] = has_error;
|
2010-07-25 18:55:30 +04:00
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hasError(QString hash) {
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2010-07-25 18:55:30 +04:00
|
|
|
return data.value("has_error", false).toBool();
|
|
|
|
}
|
|
|
|
|
2010-07-16 23:53:47 +04:00
|
|
|
static void setRootFolder(QString hash, QString root_folder) {
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
data["root_folder"] = root_folder;
|
2010-07-16 23:53:47 +04:00
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString getRootFolder(QString hash) {
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
return data.value("root_folder").toString();
|
2010-07-16 23:53:47 +04:00
|
|
|
}
|
2010-07-18 01:35:00 +04:00
|
|
|
|
|
|
|
static void setPreviousSavePath(QString hash, QString previous_path) {
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
data["previous_path"] = previous_path;
|
2010-07-18 01:35:00 +04:00
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString getPreviousPath(QString hash) {
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
return data.value("previous_path").toString();
|
2010-07-18 01:35:00 +04:00
|
|
|
}
|
2010-01-30 19:28:07 +03:00
|
|
|
|
2010-03-04 23:19:25 +03:00
|
|
|
static void saveSeedDate(const QTorrentHandle &h) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
2010-01-30 19:28:07 +03:00
|
|
|
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
|
|
|
if(h.is_seed())
|
2010-10-17 18:46:01 +04:00
|
|
|
data["seed_date"] = QDateTime::currentDateTime();
|
2010-01-30 19:28:07 +03:00
|
|
|
else
|
2010-10-17 18:46:01 +04:00
|
|
|
data.remove("seed_date");
|
2010-01-30 19:28:07 +03:00
|
|
|
all_data[h.hash()] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static QDateTime getSeedDate(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
return data.value("seed_date").toDateTime();
|
2010-01-30 19:28:07 +03:00
|
|
|
}
|
|
|
|
|
2009-08-16 07:09:20 +04:00
|
|
|
static void deletePersistentData(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
if(all_data.contains(hash)) {
|
|
|
|
all_data.remove(hash);
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-17 18:46:01 +04:00
|
|
|
static void saveTorrentPersistentData(const QTorrentHandle &h, QString save_path = QString::null, bool is_magnet = false) {
|
2009-08-17 09:14:03 +04:00
|
|
|
Q_ASSERT(h.is_valid());
|
2010-10-17 18:46:01 +04:00
|
|
|
qDebug("Saving persistent data for %s", qPrintable(h.hash()));
|
2009-08-16 07:09:20 +04:00
|
|
|
// Save persistent data
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
QHash<QString, QVariant> data;
|
|
|
|
data["is_magnet"] = is_magnet;
|
|
|
|
if(is_magnet) {
|
2010-10-20 00:00:50 +04:00
|
|
|
data["magnet_uri"] = misc::toQString(make_magnet_uri(h));
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
data["seed"] = h.is_seed();
|
|
|
|
data["priority"] = h.queue_position();
|
2010-10-23 20:21:56 +04:00
|
|
|
if(save_path.isEmpty()) {
|
|
|
|
qDebug("TorrentPersistantData: save path is %s", qPrintable(h.save_path()));
|
2010-10-17 18:46:01 +04:00
|
|
|
data["save_path"] = h.save_path();
|
2010-10-23 20:21:56 +04:00
|
|
|
} else {
|
|
|
|
qDebug("TorrentPersistantData: overriding save path is %s", qPrintable(save_path));
|
2010-10-17 18:46:01 +04:00
|
|
|
data["save_path"] = save_path; // Override torrent save path (e.g. because it is a temp dir)
|
2010-10-23 20:21:56 +04:00
|
|
|
}
|
2010-10-17 18:46:01 +04:00
|
|
|
// Label
|
|
|
|
data["label"] = TorrentTempData::getLabel(h.hash());
|
2009-08-16 07:09:20 +04:00
|
|
|
// Save data
|
|
|
|
all_data[h.hash()] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
2010-10-17 18:46:01 +04:00
|
|
|
qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(h.hash()));
|
2010-01-30 19:28:07 +03:00
|
|
|
// Set Added date
|
|
|
|
setAddedDate(h.hash());
|
2010-10-17 18:46:01 +04:00
|
|
|
// Finally, remove temp data
|
|
|
|
TorrentTempData::deleteTempData(h.hash());
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setters
|
|
|
|
|
|
|
|
static void saveSavePath(QString hash, QString save_path) {
|
2009-08-17 09:14:03 +04:00
|
|
|
Q_ASSERT(!hash.isEmpty());
|
2010-07-19 22:17:37 +04:00
|
|
|
qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path));
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
data["save_path"] = save_path;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
2010-10-23 20:21:56 +04:00
|
|
|
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", qPrintable(save_path), qPrintable(hash));
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
static void saveLabel(QString hash, QString label) {
|
|
|
|
Q_ASSERT(!hash.isEmpty());
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-12-15 22:52:43 +03:00
|
|
|
data["label"] = label;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
|
2010-01-01 16:25:59 +03:00
|
|
|
static void saveName(QString hash, QString name) {
|
|
|
|
Q_ASSERT(!hash.isEmpty());
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2010-01-01 16:25:59 +03:00
|
|
|
data["name"] = name;
|
|
|
|
all_data[hash] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
|
2010-03-04 23:19:25 +03:00
|
|
|
static void savePriority(const QTorrentHandle &h) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
|
|
|
data["priority"] = h.queue_position();
|
|
|
|
all_data[h.hash()] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
}
|
|
|
|
|
2010-03-04 23:19:25 +03:00
|
|
|
static void saveSeedStatus(const QTorrentHandle &h) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
2009-08-16 07:09:20 +04:00
|
|
|
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
2010-10-02 16:52:06 +04:00
|
|
|
bool was_seed = data.value("seed", false).toBool();
|
|
|
|
if(was_seed != h.is_seed()) {
|
|
|
|
data["seed"] = !was_seed;
|
|
|
|
all_data[h.hash()] = data;
|
|
|
|
settings.setValue("torrents", all_data);
|
|
|
|
if(!was_seed) {
|
|
|
|
// Save completion date
|
|
|
|
saveSeedDate(h);
|
|
|
|
}
|
|
|
|
}
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Getters
|
|
|
|
static QString getSavePath(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-11-24 22:41:31 +03:00
|
|
|
//qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data());
|
2010-10-17 18:46:01 +04:00
|
|
|
return data.value("save_path").toString();
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
static QString getLabel(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2009-12-15 22:52:43 +03:00
|
|
|
return data.value("label", "").toString();
|
|
|
|
}
|
|
|
|
|
2010-01-01 16:25:59 +03:00
|
|
|
static QString getName(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2010-01-01 16:25:59 +03:00
|
|
|
return data.value("name", "").toString();
|
|
|
|
}
|
|
|
|
|
2009-08-16 07:09:20 +04:00
|
|
|
static int getPriority(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
return data.value("priority", -1).toInt();
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isSeed(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
2010-01-05 00:16:33 +03:00
|
|
|
return data.value("seed", false).toBool();
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isMagnet(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
return data.value("is_magnet", false).toBool();
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static QString getMagnetUri(QString hash) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
2010-10-17 18:46:01 +04:00
|
|
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
|
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
|
|
Q_ASSERT(data.value("is_magnet", false).toBool());
|
|
|
|
return data.value("magnet_uri").toString();
|
2009-08-16 07:09:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2009-11-29 00:46:46 +03:00
|
|
|
|
2009-08-16 07:09:20 +04:00
|
|
|
#endif // TORRENTPERSISTENTDATA_H
|