2014-10-25 15:49:57 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "torrentpersistentdata.h"
|
|
|
|
|
2014-10-25 16:11:18 +04:00
|
|
|
#include <QDateTime>
|
2014-10-25 15:49:57 +04:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include "qinisettings.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "qtorrenthandle.h"
|
|
|
|
|
|
|
|
#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;
|
2014-11-02 16:52:26 +03:00
|
|
|
TorrentPersistentData* TorrentPersistentData::m_instance = 0;
|
2014-10-25 15:49:57 +04:00
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
TorrentTempData::TorrentData::TorrentData()
|
|
|
|
: sequential(false)
|
|
|
|
, seed(false)
|
|
|
|
, add_paused(Preferences::instance()->addTorrentsInPause())
|
|
|
|
{
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
TorrentTempData::TorrentMoveState::TorrentMoveState(QString oldPath, QString newPath)
|
|
|
|
: oldPath(oldPath)
|
|
|
|
, newPath(newPath)
|
|
|
|
{
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
bool TorrentTempData::hasTempData(const QString &hash)
|
|
|
|
{
|
|
|
|
return data.contains(hash);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentTempData::deleteTempData(const QString &hash)
|
|
|
|
{
|
|
|
|
data.remove(hash);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentTempData::setFilesPriority(const QString &hash, const std::vector<int> &pp)
|
|
|
|
{
|
|
|
|
data[hash].files_priority = pp;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentTempData::setFilesPath(const QString &hash, const QStringList &path_list)
|
|
|
|
{
|
|
|
|
data[hash].path_list = path_list;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
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;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
bool TorrentTempData::isSequential(const QString &hash)
|
|
|
|
{
|
|
|
|
return data.value(hash).sequential;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentTempData::setSeedingMode(const QString &hash, const bool &seed)
|
|
|
|
{
|
|
|
|
data[hash].seed = seed;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
bool TorrentTempData::isSeedingMode(const QString &hash)
|
|
|
|
{
|
|
|
|
return data.value(hash).seed;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
QString TorrentTempData::getSavePath(const QString &hash)
|
|
|
|
{
|
|
|
|
return data.value(hash).save_path;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
QStringList TorrentTempData::getFilesPath(const QString &hash)
|
|
|
|
{
|
|
|
|
return data.value(hash).path_list;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
QString TorrentTempData::getLabel(const QString &hash)
|
|
|
|
{
|
|
|
|
return data.value(hash).label;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentTempData::getFilesPriority(const QString &hash, std::vector<int> &fp)
|
|
|
|
{
|
|
|
|
fp = data.value(hash).files_priority;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
bool TorrentTempData::isMoveInProgress(const QString &hash)
|
|
|
|
{
|
|
|
|
return torrentMoveStates.find(hash) != torrentMoveStates.end();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
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;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
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;
|
|
|
|
}
|
2014-10-25 15:49:57 +04:00
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
torrentMoveStates.insert(hash, TorrentMoveState(oldPath, newPath));
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
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);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
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;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
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;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
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;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentTempData::setAddPaused(const QString &hash, const bool &paused)
|
|
|
|
{
|
|
|
|
data[hash].add_paused = paused;
|
2014-03-30 16:29:51 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
bool TorrentTempData::isAddPaused(const QString &hash)
|
|
|
|
{
|
|
|
|
return data.value(hash).add_paused;
|
2014-03-30 16:29:51 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void HiddenData::addData(const QString &hash)
|
|
|
|
{
|
|
|
|
data[hash] = false;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
bool HiddenData::hasData(const QString &hash)
|
|
|
|
{
|
|
|
|
return data.contains(hash);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void HiddenData::deleteData(const QString &hash)
|
|
|
|
{
|
|
|
|
if (data.value(hash, false))
|
|
|
|
metadata_counter--;
|
|
|
|
data.remove(hash);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
int HiddenData::getSize()
|
|
|
|
{
|
|
|
|
return data.size();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
int HiddenData::getDownloadingSize()
|
|
|
|
{
|
|
|
|
return data.size() - metadata_counter;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void HiddenData::gotMetadata(const QString &hash)
|
|
|
|
{
|
|
|
|
if (!data.contains(hash))
|
|
|
|
return;
|
|
|
|
data[hash] = true;
|
|
|
|
metadata_counter++;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2014-11-02 16:52:26 +03:00
|
|
|
TorrentPersistentData::TorrentPersistentData()
|
2015-01-27 18:28:21 +03:00
|
|
|
: m_data(QIniSettings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")).value("torrents").toHash())
|
2015-01-27 16:30:49 +03:00
|
|
|
, dirty(false)
|
2014-11-02 16:52:26 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
timer.setSingleShot(true);
|
2015-01-08 22:19:46 +03:00
|
|
|
timer.setInterval(5 * 1000);
|
2015-01-27 18:28:21 +03:00
|
|
|
connect(&timer, SIGNAL(timeout()), SLOT(save()));
|
2014-11-02 16:52:26 +03:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
TorrentPersistentData::~TorrentPersistentData()
|
|
|
|
{
|
|
|
|
save();
|
2014-11-01 20:41:30 +03:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentPersistentData::save()
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
if (!dirty)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
|
|
settings.setValue("torrents", m_data);
|
|
|
|
dirty = false;
|
|
|
|
}
|
|
|
|
|
2015-01-08 22:19:46 +03:00
|
|
|
const QVariant TorrentPersistentData::value(const QString &key, const QVariant &defaultValue) const
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QReadLocker locker(&lock);
|
|
|
|
return m_data.value(key, defaultValue);
|
|
|
|
}
|
|
|
|
|
2015-01-08 22:19:46 +03:00
|
|
|
void TorrentPersistentData::setValue(const QString &key, const QVariant &value)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QWriteLocker locker(&lock);
|
|
|
|
if (m_data.value(key) == value)
|
|
|
|
return;
|
|
|
|
dirty = true;
|
|
|
|
timer.start();
|
|
|
|
m_data.insert(key, value);
|
2014-11-02 16:52:26 +03:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
TorrentPersistentData* TorrentPersistentData::instance()
|
2014-11-02 16:52:26 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
if (!m_instance)
|
|
|
|
m_instance = new TorrentPersistentData;
|
|
|
|
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorrentPersistentData::drop()
|
|
|
|
{
|
|
|
|
if (m_instance) {
|
|
|
|
delete m_instance;
|
|
|
|
m_instance = 0;
|
|
|
|
}
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
bool TorrentPersistentData::isKnownTorrent(QString hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QReadLocker locker(&lock);
|
|
|
|
return m_data.contains(hash);
|
2014-11-01 20:41:30 +03:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
QStringList TorrentPersistentData::knownTorrents() const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QReadLocker locker(&lock);
|
|
|
|
return m_data.keys();
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TorrentPersistentData::setRatioLimit(const QString &hash, const qreal &ratio)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["max_ratio"] = ratio;
|
|
|
|
setValue(hash, torrent);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
qreal TorrentPersistentData::getRatioLimit(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("max_ratio", USE_GLOBAL_RATIO).toReal();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
bool TorrentPersistentData::hasPerTorrentRatioLimit() const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QReadLocker locker(&lock);
|
|
|
|
QHash<QString, QVariant>::ConstIterator it = m_data.constBegin();
|
|
|
|
QHash<QString, QVariant>::ConstIterator itend = m_data.constEnd();
|
2015-01-27 16:30:49 +03:00
|
|
|
for (; it != itend; ++it)
|
|
|
|
if (it.value().toHash().value("max_ratio", USE_GLOBAL_RATIO).toReal() >= 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentPersistentData::setAddedDate(const QString &hash, const QDateTime &time)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
if (!torrent.contains("add_date")) {
|
|
|
|
torrent["add_date"] = time;
|
|
|
|
setValue(hash, torrent);
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
QDateTime TorrentPersistentData::getAddedDate(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
QDateTime dt = torrent.value("add_date").toDateTime();
|
|
|
|
if (!dt.isValid())
|
2015-01-27 16:30:49 +03:00
|
|
|
dt = QDateTime::currentDateTime();
|
|
|
|
return dt;
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentPersistentData::setErrorState(const QString &hash, const bool has_error)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["has_error"] = has_error;
|
|
|
|
setValue(hash, torrent);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
bool TorrentPersistentData::hasError(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("has_error", false).toBool();
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
QDateTime TorrentPersistentData::getSeedDate(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("seed_date").toDateTime();
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TorrentPersistentData::deletePersistentData(const QString &hash)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QWriteLocker locker(&lock);
|
|
|
|
if (m_data.contains(hash)) {
|
|
|
|
m_data.remove(hash);
|
|
|
|
dirty = true;
|
|
|
|
timer.start();
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path, const bool is_magnet)
|
|
|
|
{
|
|
|
|
Q_ASSERT(h.is_valid());
|
2015-01-27 18:28:21 +03:00
|
|
|
QString hash = h.hash();
|
|
|
|
qDebug("Saving persistent data for %s", qPrintable(hash));
|
2015-01-27 16:30:49 +03:00
|
|
|
// Save persistent data
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["is_magnet"] = is_magnet;
|
2015-01-27 16:30:49 +03:00
|
|
|
if (is_magnet)
|
2015-01-27 18:28:21 +03:00
|
|
|
torrent["magnet_uri"] = misc::toQString(make_magnet_uri(h));
|
|
|
|
torrent["seed"] = h.is_seed();
|
|
|
|
torrent["priority"] = h.queue_position();
|
2015-01-27 16:30:49 +03:00
|
|
|
if (save_path.isEmpty()) {
|
|
|
|
qDebug("TorrentPersistantData: save path is %s", qPrintable(h.save_path()));
|
2015-01-27 18:28:21 +03:00
|
|
|
torrent["save_path"] = h.save_path();
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
qDebug("TorrentPersistantData: overriding save path is %s", qPrintable(save_path));
|
2015-01-27 18:28:21 +03:00
|
|
|
torrent["save_path"] = save_path; // Override torrent save path (e.g. because it is a temp dir)
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
// Label
|
2015-01-27 18:28:21 +03:00
|
|
|
torrent["label"] = TorrentTempData::getLabel(hash);
|
2015-01-27 16:30:49 +03:00
|
|
|
// Save data
|
2015-01-27 18:28:21 +03:00
|
|
|
setValue(hash, torrent);
|
|
|
|
qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(hash));
|
2015-01-27 16:30:49 +03:00
|
|
|
// Set Added date
|
2015-01-27 18:28:21 +03:00
|
|
|
setAddedDate(hash, QDateTime::currentDateTime());
|
2015-01-27 16:30:49 +03:00
|
|
|
// Finally, remove temp data
|
2015-01-27 18:28:21 +03:00
|
|
|
TorrentTempData::deleteTempData(hash);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentPersistentData::saveSavePath(const QString &hash, const QString &save_path)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!hash.isEmpty());
|
|
|
|
qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path));
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["save_path"] = save_path;
|
|
|
|
setValue(hash, torrent);
|
2015-01-27 16:30:49 +03:00
|
|
|
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", qPrintable(save_path), qPrintable(hash));
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentPersistentData::saveLabel(const QString &hash, const QString &label)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!hash.isEmpty());
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["label"] = label;
|
|
|
|
setValue(hash, torrent);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentPersistentData::saveName(const QString &hash, const QString &name)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!hash.isEmpty());
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["name"] = name;
|
|
|
|
setValue(hash, torrent);
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TorrentPersistentData::savePriority(const QTorrentHandle &h)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QString hash = h.hash();
|
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["priority"] = h.queue_position();
|
|
|
|
setValue(hash, torrent);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 16:30:49 +03:00
|
|
|
void TorrentPersistentData::savePriority(const QString &hash, const int &queue_pos)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["priority"] = queue_pos;
|
|
|
|
setValue(hash, torrent);
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TorrentPersistentData::saveSeedStatus(const QTorrentHandle &h)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QString hash = h.hash();
|
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
bool was_seed = torrent.value("seed", false).toBool();
|
2015-01-27 16:30:49 +03:00
|
|
|
if (was_seed != h.is_seed()) {
|
2015-01-27 18:28:21 +03:00
|
|
|
torrent["seed"] = !was_seed;
|
|
|
|
setValue(hash, torrent);
|
2015-01-27 16:30:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorrentPersistentData::saveSeedStatus(const QString &hash, const bool seedStatus)
|
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["seed"] = seedStatus;
|
|
|
|
setValue(hash, torrent);
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-08 22:19:46 +03:00
|
|
|
void TorrentPersistentData::setHasMissingFiles(const QString& hash, bool missing)
|
|
|
|
{
|
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
torrent["has_missing_files"] = missing;
|
|
|
|
setValue(hash, torrent);
|
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
QString TorrentPersistentData::getSavePath(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
2015-01-27 16:30:49 +03:00
|
|
|
//qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data());
|
2015-01-27 18:28:21 +03:00
|
|
|
return torrent.value("save_path").toString();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
QString TorrentPersistentData::getLabel(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("label", "").toString();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
QString TorrentPersistentData::getName(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("name", "").toString();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
int TorrentPersistentData::getPriority(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("priority", -1).toInt();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
bool TorrentPersistentData::isSeed(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("seed", false).toBool();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
bool TorrentPersistentData::isMagnet(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("is_magnet", false).toBool();
|
2014-10-25 15:49:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-27 18:28:21 +03:00
|
|
|
QString TorrentPersistentData::getMagnetUri(const QString &hash) const
|
2015-01-27 16:30:49 +03:00
|
|
|
{
|
2015-01-27 18:28:21 +03:00
|
|
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
Q_ASSERT(torrent.value("is_magnet", false).toBool());
|
|
|
|
return torrent.value("magnet_uri").toString();
|
2014-11-02 16:52:26 +03:00
|
|
|
}
|
2015-01-08 22:19:46 +03:00
|
|
|
|
|
|
|
bool TorrentPersistentData::getHasMissingFiles(const QString& hash)
|
|
|
|
{
|
|
|
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
|
|
|
return torrent.value("has_missing_files").toBool();
|
|
|
|
}
|