mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-08 21:04:26 +00:00
Split src/torrentpersistentdata into .h and .cpp
This commit is contained in:
parent
e1b4c5534e
commit
16eb407453
@ -41,6 +41,7 @@
|
|||||||
#include "autoexpandabledialog.h"
|
#include "autoexpandabledialog.h"
|
||||||
#include "messageboxraised.h"
|
#include "messageboxraised.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
* Contact : chris@qbittorrent.org
|
* Contact : chris@qbittorrent.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
* Contact : chris@qbittorrent.org
|
* Contact : chris@qbittorrent.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@ -73,6 +74,7 @@
|
|||||||
#include <libtorrent/alert_types.hpp>
|
#include <libtorrent/alert_types.hpp>
|
||||||
#include <libtorrent/session.hpp>
|
#include <libtorrent/session.hpp>
|
||||||
#include <libtorrent/ip_filter.hpp>
|
#include <libtorrent/ip_filter.hpp>
|
||||||
|
#include <libtorrent/magnet_uri.hpp>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "dnsupdater.h"
|
#include "dnsupdater.h"
|
||||||
@ -82,12 +84,6 @@
|
|||||||
#include <libtorrent/natpmp.hpp>
|
#include <libtorrent/natpmp.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//initialize static member variables
|
|
||||||
QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QString, TorrentTempData::TorrentData>();
|
|
||||||
QHash<QString, TorrentTempData::TorrentMoveState> TorrentTempData::torrentMoveStates = QHash<QString, TorrentTempData::TorrentMoveState>();
|
|
||||||
QHash<QString, bool> HiddenData::data = QHash<QString, bool>();
|
|
||||||
unsigned int HiddenData::metadata_counter = 0;
|
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
QBtSession* QBtSession::m_instance = 0;
|
QBtSession* QBtSession::m_instance = 0;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
* Contact : chris@qbittorrent.org
|
* Contact : chris@qbittorrent.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -114,6 +114,7 @@ HEADERS += misc.h \
|
|||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
downloadthread.cpp \
|
downloadthread.cpp \
|
||||||
scannedfoldersmodel.cpp \
|
scannedfoldersmodel.cpp \
|
||||||
|
torrentpersistentdata.cpp \
|
||||||
misc.cpp \
|
misc.cpp \
|
||||||
fs_utils.cpp \
|
fs_utils.cpp \
|
||||||
smtp.cpp \
|
smtp.cpp \
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
* Contact : chris@qbittorrent.org
|
* Contact : chris@qbittorrent.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
440
src/torrentpersistentdata.cpp
Normal file
440
src/torrentpersistentdata.cpp
Normal file
@ -0,0 +1,440 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "torrentpersistentdata.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "qinisettings.h"
|
||||||
|
#include "misc.h"
|
||||||
|
#include "qtorrenthandle.h"
|
||||||
|
|
||||||
|
#include <libtorrent/version.hpp>
|
||||||
|
#include <libtorrent/magnet_uri.hpp>
|
||||||
|
|
||||||
|
QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QString, TorrentTempData::TorrentData>();
|
||||||
|
QHash<QString, TorrentTempData::TorrentMoveState> TorrentTempData::torrentMoveStates = QHash<QString, TorrentTempData::TorrentMoveState>();
|
||||||
|
QHash<QString, bool> HiddenData::data = QHash<QString, bool>();
|
||||||
|
unsigned int HiddenData::metadata_counter = 0;
|
||||||
|
|
||||||
|
bool TorrentTempData::hasTempData(const QString &hash) {
|
||||||
|
return data.contains(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::deleteTempData(const QString &hash) {
|
||||||
|
data.remove(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::setFilesPriority(const QString &hash, const std::vector<int> &pp) {
|
||||||
|
data[hash].files_priority = pp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::setFilesPath(const QString &hash, const QStringList &path_list) {
|
||||||
|
data[hash].path_list = path_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::setSavePath(const QString &hash, const QString &save_path) {
|
||||||
|
data[hash].save_path = save_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::setLabel(const QString &hash, const QString &label) {
|
||||||
|
data[hash].label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::setSequential(const QString &hash, const bool &sequential) {
|
||||||
|
data[hash].sequential = sequential;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentTempData::isSequential(const QString &hash) {
|
||||||
|
return data.value(hash).sequential;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::setSeedingMode(const QString &hash, const bool &seed) {
|
||||||
|
data[hash].seed = seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentTempData::isSeedingMode(const QString &hash) {
|
||||||
|
return data.value(hash).seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentTempData::getSavePath(const QString &hash) {
|
||||||
|
return data.value(hash).save_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList TorrentTempData::getFilesPath(const QString &hash) {
|
||||||
|
return data.value(hash).path_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentTempData::getLabel(const QString &hash) {
|
||||||
|
return data.value(hash).label;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::getFilesPriority(const QString &hash, std::vector<int> &fp) {
|
||||||
|
fp = data.value(hash).files_priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentTempData::isMoveInProgress(const QString &hash) {
|
||||||
|
return torrentMoveStates.find(hash) != torrentMoveStates.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::enqueueMove(const QString &hash, const QString &queuedPath) {
|
||||||
|
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
||||||
|
if (i == torrentMoveStates.end()) {
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i->queuedPath = queuedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::startMove(const QString &hash, const QString &oldPath, const QString& newPath) {
|
||||||
|
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
||||||
|
if (i != torrentMoveStates.end()) {
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
torrentMoveStates.insert(hash, TorrentMoveState(oldPath, newPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentTempData::finishMove(const QString &hash) {
|
||||||
|
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
||||||
|
if (i == torrentMoveStates.end()) {
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
torrentMoveStates.erase(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentTempData::getOldPath(const QString &hash) {
|
||||||
|
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
||||||
|
if (i == torrentMoveStates.end()) {
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
return i->oldPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentTempData::getNewPath(const QString &hash) {
|
||||||
|
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
||||||
|
if (i == torrentMoveStates.end()) {
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
return i->newPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentTempData::getQueuedPath(const QString &hash) {
|
||||||
|
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
||||||
|
if (i == torrentMoveStates.end()) {
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
return i->queuedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HiddenData::addData(const QString &hash) {
|
||||||
|
data[hash] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HiddenData::hasData(const QString &hash) {
|
||||||
|
return data.contains(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HiddenData::deleteData(const QString &hash) {
|
||||||
|
if (data.value(hash, false))
|
||||||
|
metadata_counter--;
|
||||||
|
data.remove(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
int HiddenData::getSize() {
|
||||||
|
return data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int HiddenData::getDownloadingSize() {
|
||||||
|
return data.size() - metadata_counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HiddenData::gotMetadata(const QString &hash) {
|
||||||
|
if (!data.contains(hash))
|
||||||
|
return;
|
||||||
|
data[hash] = true;
|
||||||
|
metadata_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentPersistentData::isKnownTorrent(QString hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
return all_data.contains(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList TorrentPersistentData::knownTorrents() {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
return all_data.keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::setRatioLimit(const QString &hash, const qreal &ratio) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
data["max_ratio"] = ratio;
|
||||||
|
all_data[hash] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal TorrentPersistentData::getRatioLimit(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
return data.value("max_ratio", USE_GLOBAL_RATIO).toReal();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentPersistentData::hasPerTorrentRatioLimit() {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant>::ConstIterator it = all_data.constBegin();
|
||||||
|
QHash<QString, QVariant>::ConstIterator itend = all_data.constEnd();
|
||||||
|
for ( ; it != itend; ++it) {
|
||||||
|
if (it.value().toHash().value("max_ratio", USE_GLOBAL_RATIO).toReal() >= 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::setAddedDate(const QString &hash, const QDateTime &time) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
if (!data.contains("add_date")) {
|
||||||
|
data["add_date"] = time;
|
||||||
|
all_data[hash] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime TorrentPersistentData::getAddedDate(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
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();
|
||||||
|
if (!dt.isValid()) {
|
||||||
|
setAddedDate(hash);
|
||||||
|
dt = QDateTime::currentDateTime();
|
||||||
|
}
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::setErrorState(const QString &hash, const bool has_error) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
data["has_error"] = has_error;
|
||||||
|
all_data[hash] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentPersistentData::hasError(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
return data.value("has_error", false).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime TorrentPersistentData::getSeedDate(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::deletePersistentData(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
if (all_data.contains(hash)) {
|
||||||
|
all_data.remove(hash);
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path, const bool is_magnet) {
|
||||||
|
Q_ASSERT(h.is_valid());
|
||||||
|
qDebug("Saving persistent data for %s", qPrintable(h.hash()));
|
||||||
|
// Save persistent data
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data.value(h.hash()).toHash();
|
||||||
|
data["is_magnet"] = is_magnet;
|
||||||
|
if (is_magnet) {
|
||||||
|
data["magnet_uri"] = misc::toQString(make_magnet_uri(h));
|
||||||
|
}
|
||||||
|
data["seed"] = h.is_seed();
|
||||||
|
data["priority"] = h.queue_position();
|
||||||
|
if (save_path.isEmpty()) {
|
||||||
|
qDebug("TorrentPersistantData: save path is %s", qPrintable(h.save_path()));
|
||||||
|
data["save_path"] = h.save_path();
|
||||||
|
} else {
|
||||||
|
qDebug("TorrentPersistantData: overriding save path is %s", qPrintable(save_path));
|
||||||
|
data["save_path"] = save_path; // Override torrent save path (e.g. because it is a temp dir)
|
||||||
|
}
|
||||||
|
// Label
|
||||||
|
data["label"] = TorrentTempData::getLabel(h.hash());
|
||||||
|
// Save data
|
||||||
|
all_data[h.hash()] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(h.hash()));
|
||||||
|
// Set Added date
|
||||||
|
setAddedDate(h.hash());
|
||||||
|
// Finally, remove temp data
|
||||||
|
TorrentTempData::deleteTempData(h.hash());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::saveSavePath(const QString &hash, const QString &save_path) {
|
||||||
|
Q_ASSERT(!hash.isEmpty());
|
||||||
|
qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path));
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
data["save_path"] = save_path;
|
||||||
|
all_data[hash] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", qPrintable(save_path), qPrintable(hash));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::saveLabel(const QString &hash, const QString &label) {
|
||||||
|
Q_ASSERT(!hash.isEmpty());
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
data["label"] = label;
|
||||||
|
all_data[hash] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::saveName(const QString &hash, const QString &name) {
|
||||||
|
Q_ASSERT(!hash.isEmpty());
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
data["name"] = name;
|
||||||
|
all_data[hash] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::savePriority(const QTorrentHandle &h) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
||||||
|
data["priority"] = h.queue_position();
|
||||||
|
all_data[h.hash()] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::savePriority(const QString &hash, const int &queue_pos) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data[hash].toHash();
|
||||||
|
data["priority"] = queue_pos;
|
||||||
|
all_data[hash] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::saveSeedStatus(const QTorrentHandle &h) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::saveSeedStatus(const QString &hash, const bool seedStatus) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
QHash<QString, QVariant> data = all_data[hash].toHash();
|
||||||
|
data["seed"] = seedStatus;
|
||||||
|
all_data[hash] = data;
|
||||||
|
settings.setValue("torrents", all_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentPersistentData::getSavePath(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
//qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data());
|
||||||
|
return data.value("save_path").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentPersistentData::getLabel(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
return data.value("label", "").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentPersistentData::getName(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
return data.value("name", "").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
int TorrentPersistentData::getPriority(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentPersistentData::isSeed(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
||||||
|
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
||||||
|
return data.value("seed", false).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentPersistentData::isMagnet(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TorrentPersistentData::getMagnetUri(const QString &hash) {
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
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();
|
||||||
|
}
|
@ -31,134 +31,37 @@
|
|||||||
#ifndef TORRENTPERSISTENTDATA_H
|
#ifndef TORRENTPERSISTENTDATA_H
|
||||||
#define TORRENTPERSISTENTDATA_H
|
#define TORRENTPERSISTENTDATA_H
|
||||||
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
|
||||||
#include <libtorrent/version.hpp>
|
|
||||||
#include <libtorrent/magnet_uri.hpp>
|
|
||||||
#include "qtorrenthandle.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include <vector>
|
|
||||||
#include "qinisettings.h"
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class QTorrentHandle;
|
||||||
|
|
||||||
class TorrentTempData {
|
class TorrentTempData {
|
||||||
// This class stores strings w/o modifying separators
|
// This class stores strings w/o modifying separators
|
||||||
public:
|
public:
|
||||||
static bool hasTempData(const QString &hash) {
|
static bool hasTempData(const QString &hash);
|
||||||
return data.contains(hash);
|
static void deleteTempData(const QString &hash);
|
||||||
}
|
static void setFilesPriority(const QString &hash, const std::vector<int> &pp);
|
||||||
|
static void setFilesPath(const QString &hash, const QStringList &path_list);
|
||||||
static void deleteTempData(const QString &hash) {
|
static void setSavePath(const QString &hash, const QString &save_path);
|
||||||
data.remove(hash);
|
static void setLabel(const QString &hash, const QString &label);
|
||||||
}
|
static void setSequential(const QString &hash, const bool &sequential);
|
||||||
|
static bool isSequential(const QString &hash);
|
||||||
static void setFilesPriority(const QString &hash, const std::vector<int> &pp) {
|
static void setSeedingMode(const QString &hash, const bool &seed);
|
||||||
data[hash].files_priority = pp;
|
static bool isSeedingMode(const QString &hash);
|
||||||
}
|
static QString getSavePath(const QString &hash);
|
||||||
|
static QStringList getFilesPath(const QString &hash);
|
||||||
static void setFilesPath(const QString &hash, const QStringList &path_list) {
|
static QString getLabel(const QString &hash);
|
||||||
data[hash].path_list = path_list;
|
static void getFilesPriority(const QString &hash, std::vector<int> &fp);
|
||||||
}
|
static bool isMoveInProgress(const QString &hash);
|
||||||
|
static void enqueueMove(const QString &hash, const QString &queuedPath);
|
||||||
static void setSavePath(const QString &hash, const QString &save_path) {
|
static void startMove(const QString &hash, const QString &oldPath, const QString& newPath);
|
||||||
data[hash].save_path = save_path;
|
static void finishMove(const QString &hash);
|
||||||
}
|
static QString getOldPath(const QString &hash);
|
||||||
|
static QString getNewPath(const QString &hash);
|
||||||
static void setLabel(const QString &hash, const QString &label) {
|
static QString getQueuedPath(const QString &hash);
|
||||||
data[hash].label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setSequential(const QString &hash, const bool &sequential) {
|
|
||||||
data[hash].sequential = sequential;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isSequential(const QString &hash) {
|
|
||||||
return data.value(hash).sequential;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setSeedingMode(const QString &hash, const bool &seed) {
|
|
||||||
data[hash].seed = seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isSeedingMode(const QString &hash) {
|
|
||||||
return data.value(hash).seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getSavePath(const QString &hash) {
|
|
||||||
return data.value(hash).save_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QStringList getFilesPath(const QString &hash) {
|
|
||||||
return data.value(hash).path_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getLabel(const QString &hash) {
|
|
||||||
return data.value(hash).label;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getFilesPriority(const QString &hash, std::vector<int> &fp) {
|
|
||||||
fp = data.value(hash).files_priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isMoveInProgress(const QString &hash) {
|
|
||||||
return torrentMoveStates.find(hash) != torrentMoveStates.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void enqueueMove(const QString &hash, const QString &queuedPath) {
|
|
||||||
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
|
||||||
if (i == torrentMoveStates.end()) {
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
i->queuedPath = queuedPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void startMove(const QString &hash, const QString &oldPath, const QString& newPath) {
|
|
||||||
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
|
||||||
if (i != torrentMoveStates.end()) {
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
torrentMoveStates.insert(hash, TorrentMoveState(oldPath, newPath));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void finishMove(const QString &hash) {
|
|
||||||
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
|
||||||
if (i == torrentMoveStates.end()) {
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
torrentMoveStates.erase(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getOldPath(const QString &hash) {
|
|
||||||
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
|
||||||
if (i == torrentMoveStates.end()) {
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return i->oldPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getNewPath(const QString &hash) {
|
|
||||||
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
|
||||||
if (i == torrentMoveStates.end()) {
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return i->newPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getQueuedPath(const QString &hash) {
|
|
||||||
QHash<QString, TorrentMoveState>::iterator i = torrentMoveStates.find(hash);
|
|
||||||
if (i == torrentMoveStates.end()) {
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
return i->queuedPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct TorrentData {
|
struct TorrentData {
|
||||||
@ -190,34 +93,12 @@ private:
|
|||||||
|
|
||||||
class HiddenData {
|
class HiddenData {
|
||||||
public:
|
public:
|
||||||
static void addData(const QString &hash) {
|
static void addData(const QString &hash);
|
||||||
data[hash] = false;
|
static bool hasData(const QString &hash);
|
||||||
}
|
static void deleteData(const QString &hash);
|
||||||
|
static int getSize();
|
||||||
static bool hasData(const QString &hash) {
|
static int getDownloadingSize();
|
||||||
return data.contains(hash);
|
static void gotMetadata(const QString &hash);
|
||||||
}
|
|
||||||
|
|
||||||
static void deleteData(const QString &hash) {
|
|
||||||
if (data.value(hash, false))
|
|
||||||
metadata_counter--;
|
|
||||||
data.remove(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getSize() {
|
|
||||||
return data.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getDownloadingSize() {
|
|
||||||
return data.size() - metadata_counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void gotMetadata(const QString &hash) {
|
|
||||||
if (!data.contains(hash))
|
|
||||||
return;
|
|
||||||
data[hash] = true;
|
|
||||||
metadata_counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QHash<QString, bool> data;
|
static QHash<QString, bool> data;
|
||||||
@ -233,259 +114,36 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool isKnownTorrent(QString hash) {
|
static bool isKnownTorrent(QString hash);
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
static QStringList knownTorrents();
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
static void setRatioLimit(const QString &hash, const qreal &ratio);
|
||||||
return all_data.contains(hash);
|
static qreal getRatioLimit(const QString &hash);
|
||||||
}
|
static bool hasPerTorrentRatioLimit() ;
|
||||||
|
static void setAddedDate(const QString &hash, const QDateTime &time = QDateTime::currentDateTime());
|
||||||
static QStringList knownTorrents() {
|
static QDateTime getAddedDate(const QString &hash);
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
static void setErrorState(const QString &hash, const bool has_error);
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
static bool hasError(const QString &hash);
|
||||||
return all_data.keys();
|
static QDateTime getSeedDate(const QString &hash);
|
||||||
}
|
static void deletePersistentData(const QString &hash);
|
||||||
|
static void saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path = QString::null, const bool is_magnet = false);
|
||||||
static void setRatioLimit(const QString &hash, const qreal &ratio) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
data["max_ratio"] = ratio;
|
|
||||||
all_data[hash] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static qreal getRatioLimit(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
return data.value("max_ratio", USE_GLOBAL_RATIO).toReal();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hasPerTorrentRatioLimit() {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant>::ConstIterator it = all_data.constBegin();
|
|
||||||
QHash<QString, QVariant>::ConstIterator itend = all_data.constEnd();
|
|
||||||
for ( ; it != itend; ++it) {
|
|
||||||
if (it.value().toHash().value("max_ratio", USE_GLOBAL_RATIO).toReal() >= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setAddedDate(const QString &hash, const QDateTime &time = QDateTime::currentDateTime()) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
if (!data.contains("add_date")) {
|
|
||||||
data["add_date"] = time;
|
|
||||||
all_data[hash] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static QDateTime getAddedDate(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
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();
|
|
||||||
if (!dt.isValid()) {
|
|
||||||
setAddedDate(hash);
|
|
||||||
dt = QDateTime::currentDateTime();
|
|
||||||
}
|
|
||||||
return dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setErrorState(const QString &hash, const bool has_error) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
data["has_error"] = has_error;
|
|
||||||
all_data[hash] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hasError(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
return data.value("has_error", false).toBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
static QDateTime getSeedDate(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void deletePersistentData(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
if (all_data.contains(hash)) {
|
|
||||||
all_data.remove(hash);
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path = QString::null, const bool is_magnet = false) {
|
|
||||||
Q_ASSERT(h.is_valid());
|
|
||||||
qDebug("Saving persistent data for %s", qPrintable(h.hash()));
|
|
||||||
// Save persistent data
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data.value(h.hash()).toHash();
|
|
||||||
data["is_magnet"] = is_magnet;
|
|
||||||
if (is_magnet) {
|
|
||||||
data["magnet_uri"] = misc::toQString(make_magnet_uri(h));
|
|
||||||
}
|
|
||||||
data["seed"] = h.is_seed();
|
|
||||||
data["priority"] = h.queue_position();
|
|
||||||
if (save_path.isEmpty()) {
|
|
||||||
qDebug("TorrentPersistantData: save path is %s", qPrintable(h.save_path()));
|
|
||||||
data["save_path"] = h.save_path();
|
|
||||||
} else {
|
|
||||||
qDebug("TorrentPersistantData: overriding save path is %s", qPrintable(save_path));
|
|
||||||
data["save_path"] = save_path; // Override torrent save path (e.g. because it is a temp dir)
|
|
||||||
}
|
|
||||||
// Label
|
|
||||||
data["label"] = TorrentTempData::getLabel(h.hash());
|
|
||||||
// Save data
|
|
||||||
all_data[h.hash()] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(h.hash()));
|
|
||||||
// Set Added date
|
|
||||||
setAddedDate(h.hash());
|
|
||||||
// Finally, remove temp data
|
|
||||||
TorrentTempData::deleteTempData(h.hash());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
|
static void saveSavePath(const QString &hash, const QString &save_path);
|
||||||
static void saveSavePath(const QString &hash, const QString &save_path) {
|
static void saveLabel(const QString &hash, const QString &label);
|
||||||
Q_ASSERT(!hash.isEmpty());
|
static void saveName(const QString &hash, const QString &name);
|
||||||
qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path));
|
static void savePriority(const QTorrentHandle &h);
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
static void savePriority(const QString &hash, const int &queue_pos);
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
static void saveSeedStatus(const QTorrentHandle &h);
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
static void saveSeedStatus(const QString &hash, const bool seedStatus);
|
||||||
data["save_path"] = save_path;
|
|
||||||
all_data[hash] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", qPrintable(save_path), qPrintable(hash));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void saveLabel(const QString &hash, const QString &label) {
|
|
||||||
Q_ASSERT(!hash.isEmpty());
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
data["label"] = label;
|
|
||||||
all_data[hash] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void saveName(const QString &hash, const QString &name) {
|
|
||||||
Q_ASSERT(!hash.isEmpty());
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
data["name"] = name;
|
|
||||||
all_data[hash] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void savePriority(const QTorrentHandle &h) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
|
||||||
data["priority"] = h.queue_position();
|
|
||||||
all_data[h.hash()] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void savePriority(const QString &hash, const int &queue_pos) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
|
||||||
data["priority"] = queue_pos;
|
|
||||||
all_data[hash] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void saveSeedStatus(const QTorrentHandle &h) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void saveSeedStatus(const QString &hash, const bool seedStatus) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
|
||||||
data["seed"] = seedStatus;
|
|
||||||
all_data[hash] = data;
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
static QString getSavePath(const QString &hash) {
|
static QString getSavePath(const QString &hash);
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
static QString getLabel(const QString &hash);
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
static QString getName(const QString &hash);
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
static int getPriority(const QString &hash);
|
||||||
//qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data());
|
static bool isSeed(const QString &hash);
|
||||||
return data.value("save_path").toString();
|
static bool isMagnet(const QString &hash);
|
||||||
}
|
static QString getMagnetUri(const QString &hash);
|
||||||
|
|
||||||
static QString getLabel(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
return data.value("label", "").toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getName(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
return data.value("name", "").toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getPriority(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isSeed(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
const QHash<QString, QVariant> all_data = settings.value("torrents").toHash();
|
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
|
||||||
return data.value("seed", false).toBool();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool isMagnet(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString getMagnetUri(const QString &hash) {
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TORRENTPERSISTENTDATA_H
|
#endif // TORRENTPERSISTENTDATA_H
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "transferlistfilterswidget.h"
|
#include "transferlistfilterswidget.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
* Contact : chris@qbittorrent.org
|
* Contact : chris@qbittorrent.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
@ -42,6 +43,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include <libtorrent/version.hpp>
|
#include <libtorrent/version.hpp>
|
||||||
|
#include <libtorrent/magnet_uri.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
#include "torrentpersistentdata.h"
|
#include "torrentpersistentdata.h"
|
||||||
#include "jsonutils.h"
|
#include "jsonutils.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QVariant>
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#ifndef JSONUTILS_H
|
#ifndef JSONUTILS_H
|
||||||
#define JSONUTILS_H
|
#define JSONUTILS_H
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user