mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-14 01:03:08 -07:00
Make 'TorrentPersistentData' similar to 'Preferences' class.
This commit is contained in:
parent
70985480d6
commit
eeee24a0b3
11 changed files with 235 additions and 223 deletions
|
@ -39,6 +39,7 @@
|
||||||
#include "fs_utils.h"
|
#include "fs_utils.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "torrentpersistentdata.h"
|
||||||
|
|
||||||
class HeadlessLoader: public QObject {
|
class HeadlessLoader: public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -69,6 +70,7 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void shutdownCleanUp() {
|
void shutdownCleanUp() {
|
||||||
QBtSession::drop();
|
QBtSession::drop();
|
||||||
|
TorrentPersistentData::drop();
|
||||||
Preferences::drop();
|
Preferences::drop();
|
||||||
Logger::drop();
|
Logger::drop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
#include "trackerlist.h"
|
#include "trackerlist.h"
|
||||||
#include "peerlistwidget.h"
|
#include "peerlistwidget.h"
|
||||||
|
#include "torrentpersistentdata.h"
|
||||||
#include "transferlistfilterswidget.h"
|
#include "transferlistfilterswidget.h"
|
||||||
#include "propertieswidget.h"
|
#include "propertieswidget.h"
|
||||||
#include "statusbar.h"
|
#include "statusbar.h"
|
||||||
|
@ -505,6 +506,7 @@ void MainWindow::shutdownCleanUp()
|
||||||
delete switchRSSShortcut;
|
delete switchRSSShortcut;
|
||||||
delete toolbarMenu;
|
delete toolbarMenu;
|
||||||
IconProvider::drop();
|
IconProvider::drop();
|
||||||
|
TorrentPersistentData::drop();
|
||||||
Preferences::drop();
|
Preferences::drop();
|
||||||
Logger::drop();
|
Logger::drop();
|
||||||
qDebug("Finished GUI destruction");
|
qDebug("Finished GUI destruction");
|
||||||
|
@ -667,7 +669,7 @@ void MainWindow::balloonClicked()
|
||||||
// called when a torrent has finished
|
// called when a torrent has finished
|
||||||
void MainWindow::finishedTorrent(const QTorrentHandle& h) const
|
void MainWindow::finishedTorrent(const QTorrentHandle& h) const
|
||||||
{
|
{
|
||||||
if (TorrentPersistentData::instance().isSeed(h.hash()))
|
if (TorrentPersistentData::instance()->isSeed(h.hash()))
|
||||||
showNotificationBaloon(tr("Download completion"), tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(h.name()));
|
showNotificationBaloon(tr("Download completion"), tr("%1 has finished downloading.", "e.g: xxx.avi has finished downloading.").arg(h.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "qtorrenthandle.h"
|
#include "qtorrenthandle.h"
|
||||||
#include "torrentpersistentdata.h"
|
|
||||||
#include "statsdialog.h"
|
#include "statsdialog.h"
|
||||||
|
|
||||||
class QBtSession;
|
class QBtSession;
|
||||||
|
@ -217,7 +216,6 @@ private:
|
||||||
bool has_python;
|
bool has_python;
|
||||||
#endif
|
#endif
|
||||||
QMenu* toolbarMenu;
|
QMenu* toolbarMenu;
|
||||||
TorrentPersistentData persistentData;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionSearch_engine_triggered();
|
void on_actionSearch_engine_triggered();
|
||||||
|
|
|
@ -227,7 +227,7 @@ void QBtSession::processBigRatios() {
|
||||||
if (h.is_seed()) {
|
if (h.is_seed()) {
|
||||||
const QString hash = h.hash();
|
const QString hash = h.hash();
|
||||||
const qreal ratio = getRealRatio(h.status(torrent_handle::query_accurate_download_counters));
|
const qreal ratio = getRealRatio(h.status(torrent_handle::query_accurate_download_counters));
|
||||||
qreal ratio_limit = TorrentPersistentData::instance().getRatioLimit(hash);
|
qreal ratio_limit = TorrentPersistentData::instance()->getRatioLimit(hash);
|
||||||
if (ratio_limit == TorrentPersistentData::USE_GLOBAL_RATIO)
|
if (ratio_limit == TorrentPersistentData::USE_GLOBAL_RATIO)
|
||||||
ratio_limit = global_ratio_limit;
|
ratio_limit = global_ratio_limit;
|
||||||
if (ratio_limit == TorrentPersistentData::NO_RATIO_LIMIT)
|
if (ratio_limit == TorrentPersistentData::NO_RATIO_LIMIT)
|
||||||
|
@ -830,7 +830,7 @@ void QBtSession::deleteTorrent(const QString &hash, bool delete_local_files) {
|
||||||
foreach (const QString &file, files) {
|
foreach (const QString &file, files) {
|
||||||
fsutils::forceRemove(torrentBackup.absoluteFilePath(file));
|
fsutils::forceRemove(torrentBackup.absoluteFilePath(file));
|
||||||
}
|
}
|
||||||
TorrentPersistentData::instance().deletePersistentData(hash);
|
TorrentPersistentData::instance()->deletePersistentData(hash);
|
||||||
TorrentTempData::deleteTempData(hash);
|
TorrentTempData::deleteTempData(hash);
|
||||||
HiddenData::deleteData(hash);
|
HiddenData::deleteData(hash);
|
||||||
// Remove tracker errors
|
// Remove tracker errors
|
||||||
|
@ -981,7 +981,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
|
||||||
}
|
}
|
||||||
if (savePath.isEmpty())
|
if (savePath.isEmpty())
|
||||||
savePath = getSavePath(hash, false);
|
savePath = getSavePath(hash, false);
|
||||||
if (!defaultTempPath.isEmpty() && !TorrentPersistentData::instance().isSeed(hash)) {
|
if (!defaultTempPath.isEmpty() && !TorrentPersistentData::instance()->isSeed(hash)) {
|
||||||
qDebug("addMagnetURI: Temp folder is enabled.");
|
qDebug("addMagnetURI: Temp folder is enabled.");
|
||||||
QString torrent_tmp_path = defaultTempPath;
|
QString torrent_tmp_path = defaultTempPath;
|
||||||
p.save_path = fsutils::toNativePath(torrent_tmp_path).toUtf8().constData();
|
p.save_path = fsutils::toNativePath(torrent_tmp_path).toUtf8().constData();
|
||||||
|
@ -1175,7 +1175,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
|
||||||
} else {
|
} else {
|
||||||
savePath = getSavePath(hash, fromScanDir, path, imported);
|
savePath = getSavePath(hash, fromScanDir, path, imported);
|
||||||
}
|
}
|
||||||
if (!imported && !defaultTempPath.isEmpty() && !TorrentPersistentData::instance().isSeed(hash)) {
|
if (!imported && !defaultTempPath.isEmpty() && !TorrentPersistentData::instance()->isSeed(hash)) {
|
||||||
qDebug("addTorrent::Temp folder is enabled.");
|
qDebug("addTorrent::Temp folder is enabled.");
|
||||||
QString torrent_tmp_path = defaultTempPath;
|
QString torrent_tmp_path = defaultTempPath;
|
||||||
p.save_path = fsutils::toNativePath(torrent_tmp_path).toUtf8().constData();
|
p.save_path = fsutils::toNativePath(torrent_tmp_path).toUtf8().constData();
|
||||||
|
@ -1340,9 +1340,9 @@ void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool m
|
||||||
// Save persistent data for new torrent
|
// Save persistent data for new torrent
|
||||||
qDebug("Saving torrent persistant data");
|
qDebug("Saving torrent persistant data");
|
||||||
if (defaultTempPath.isEmpty())
|
if (defaultTempPath.isEmpty())
|
||||||
TorrentPersistentData::instance().saveTorrentPersistentData(h, QString::null, magnet);
|
TorrentPersistentData::instance()->saveTorrentPersistentData(h, QString::null, magnet);
|
||||||
else
|
else
|
||||||
TorrentPersistentData::instance().saveTorrentPersistentData(h, fsutils::fromNativePath(savePath), magnet);
|
TorrentPersistentData::instance()->saveTorrentPersistentData(h, fsutils::fromNativePath(savePath), magnet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QBtSession::mergeTorrents(QTorrentHandle& h_ex, const QString& magnet_uri)
|
void QBtSession::mergeTorrents(QTorrentHandle& h_ex, const QString& magnet_uri)
|
||||||
|
@ -1661,7 +1661,7 @@ void QBtSession::saveFastResumeData() {
|
||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
if (isQueueingEnabled())
|
if (isQueueingEnabled())
|
||||||
TorrentPersistentData::instance().savePriority(h);
|
TorrentPersistentData::instance()->savePriority(h);
|
||||||
if (!h.has_metadata())
|
if (!h.has_metadata())
|
||||||
continue;
|
continue;
|
||||||
// Actually with should save fast resume data for paused files too
|
// Actually with should save fast resume data for paused files too
|
||||||
|
@ -1850,7 +1850,7 @@ void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append
|
||||||
void QBtSession::changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label) {
|
void QBtSession::changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label) {
|
||||||
if (!h.is_valid()) return;
|
if (!h.is_valid()) return;
|
||||||
if (!appendLabelToSavePath) return;
|
if (!appendLabelToSavePath) return;
|
||||||
QString old_save_path = fsutils::fromNativePath(TorrentPersistentData::instance().getSavePath(h.hash()));
|
QString old_save_path = fsutils::fromNativePath(TorrentPersistentData::instance()->getSavePath(h.hash()));
|
||||||
if (!old_save_path.startsWith(defaultSavePath)) return;
|
if (!old_save_path.startsWith(defaultSavePath)) return;
|
||||||
QString new_save_path = fsutils::updateLabelInSavePath(defaultSavePath, old_save_path, old_label, new_label);
|
QString new_save_path = fsutils::updateLabelInSavePath(defaultSavePath, old_save_path, old_label, new_label);
|
||||||
if (new_save_path != old_save_path) {
|
if (new_save_path != old_save_path) {
|
||||||
|
@ -1863,10 +1863,11 @@ void QBtSession::changeLabelInTorrentSavePath(const QTorrentHandle &h, QString o
|
||||||
|
|
||||||
void QBtSession::appendLabelToTorrentSavePath(const QTorrentHandle& h) {
|
void QBtSession::appendLabelToTorrentSavePath(const QTorrentHandle& h) {
|
||||||
if (!h.is_valid()) return;
|
if (!h.is_valid()) return;
|
||||||
const QString label = TorrentPersistentData::instance().getLabel(h.hash());
|
const TorrentPersistentData* const TorPersistent = TorrentPersistentData::instance();
|
||||||
|
const QString label = TorPersistent->getLabel(h.hash());
|
||||||
if (label.isEmpty()) return;
|
if (label.isEmpty()) return;
|
||||||
// Current save path
|
// Current save path
|
||||||
QString old_save_path = fsutils::fromNativePath(TorrentPersistentData::instance().getSavePath(h.hash()));
|
QString old_save_path = fsutils::fromNativePath(TorPersistent->getSavePath(h.hash()));
|
||||||
QString new_save_path = fsutils::updateLabelInSavePath(defaultSavePath, old_save_path, "", label);
|
QString new_save_path = fsutils::updateLabelInSavePath(defaultSavePath, old_save_path, "", label);
|
||||||
if (old_save_path != new_save_path) {
|
if (old_save_path != new_save_path) {
|
||||||
// Move storage
|
// Move storage
|
||||||
|
@ -1992,20 +1993,20 @@ void QBtSession::setMaxRatioPerTorrent(const QString &hash, qreal ratio)
|
||||||
ratio = MAX_RATIO;
|
ratio = MAX_RATIO;
|
||||||
qDebug("* Set individual max ratio for torrent %s to %.1f.",
|
qDebug("* Set individual max ratio for torrent %s to %.1f.",
|
||||||
qPrintable(hash), ratio);
|
qPrintable(hash), ratio);
|
||||||
TorrentPersistentData::instance().setRatioLimit(hash, ratio);
|
TorrentPersistentData::instance()->setRatioLimit(hash, ratio);
|
||||||
updateRatioTimer();
|
updateRatioTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QBtSession::removeRatioPerTorrent(const QString &hash)
|
void QBtSession::removeRatioPerTorrent(const QString &hash)
|
||||||
{
|
{
|
||||||
qDebug("* Remove individual max ratio for torrent %s.", qPrintable(hash));
|
qDebug("* Remove individual max ratio for torrent %s.", qPrintable(hash));
|
||||||
TorrentPersistentData::instance().setRatioLimit(hash, TorrentPersistentData::USE_GLOBAL_RATIO);
|
TorrentPersistentData::instance()->setRatioLimit(hash, TorrentPersistentData::USE_GLOBAL_RATIO);
|
||||||
updateRatioTimer();
|
updateRatioTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QBtSession::getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const
|
qreal QBtSession::getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const
|
||||||
{
|
{
|
||||||
qreal ratio_limit = TorrentPersistentData::instance().getRatioLimit(hash);
|
qreal ratio_limit = TorrentPersistentData::instance()->getRatioLimit(hash);
|
||||||
if (ratio_limit == TorrentPersistentData::USE_GLOBAL_RATIO) {
|
if (ratio_limit == TorrentPersistentData::USE_GLOBAL_RATIO) {
|
||||||
ratio_limit = global_ratio_limit;
|
ratio_limit = global_ratio_limit;
|
||||||
if (usesGlobalRatio)
|
if (usesGlobalRatio)
|
||||||
|
@ -2019,7 +2020,7 @@ qreal QBtSession::getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRat
|
||||||
|
|
||||||
void QBtSession::updateRatioTimer()
|
void QBtSession::updateRatioTimer()
|
||||||
{
|
{
|
||||||
if (global_ratio_limit == -1 && !TorrentPersistentData::instance().hasPerTorrentRatioLimit()) {
|
if (global_ratio_limit == -1 && !TorrentPersistentData::instance()->hasPerTorrentRatioLimit()) {
|
||||||
if (BigRatioTimer->isActive())
|
if (BigRatioTimer->isActive())
|
||||||
BigRatioTimer->stop();
|
BigRatioTimer->stop();
|
||||||
} else if (!BigRatioTimer->isActive()) {
|
} else if (!BigRatioTimer->isActive()) {
|
||||||
|
@ -2099,7 +2100,7 @@ void QBtSession::sendNotificationEmail(const QTorrentHandle &h) {
|
||||||
// Prepare mail content
|
// Prepare mail content
|
||||||
QString content = tr("Torrent name: %1").arg(h.name()) + "\n";
|
QString content = tr("Torrent name: %1").arg(h.name()) + "\n";
|
||||||
content += tr("Torrent size: %1").arg(misc::friendlyUnit(status.total_wanted)) + "\n";
|
content += tr("Torrent size: %1").arg(misc::friendlyUnit(status.total_wanted)) + "\n";
|
||||||
content += tr("Save path: %1").arg(TorrentPersistentData::instance().getSavePath(h.hash())) + "\n\n";
|
content += tr("Save path: %1").arg(TorrentPersistentData::instance()->getSavePath(h.hash())) + "\n\n";
|
||||||
content += tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds").arg(misc::userFriendlyDuration(status.active_time)) + "\n\n\n";
|
content += tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds").arg(misc::userFriendlyDuration(status.active_time)) + "\n\n\n";
|
||||||
content += tr("Thank you for using qBittorrent.") + "\n";
|
content += tr("Thank you for using qBittorrent.") + "\n";
|
||||||
// Send the notification email
|
// Send the notification email
|
||||||
|
@ -2213,7 +2214,8 @@ void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert*
|
||||||
if (appendqBExtension)
|
if (appendqBExtension)
|
||||||
appendqBextensionToTorrent(h, false);
|
appendqBextensionToTorrent(h, false);
|
||||||
|
|
||||||
const bool was_already_seeded = TorrentPersistentData::instance().isSeed(hash);
|
TorrentPersistentData* const TorPersistent = TorrentPersistentData::instance();
|
||||||
|
const bool was_already_seeded = TorPersistent->isSeed(hash);
|
||||||
qDebug("Was already seeded: %d", was_already_seeded);
|
qDebug("Was already seeded: %d", was_already_seeded);
|
||||||
if (!was_already_seeded) {
|
if (!was_already_seeded) {
|
||||||
h.save_resume_data();
|
h.save_resume_data();
|
||||||
|
@ -2256,7 +2258,7 @@ void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert*
|
||||||
}
|
}
|
||||||
// Remember finished state
|
// Remember finished state
|
||||||
qDebug("Saving seed status");
|
qDebug("Saving seed status");
|
||||||
TorrentPersistentData::instance().saveSeedStatus(h);
|
TorPersistent->saveSeedStatus(h);
|
||||||
// Recheck if the user asked to
|
// Recheck if the user asked to
|
||||||
Preferences* const pref = Preferences::instance();
|
Preferences* const pref = Preferences::instance();
|
||||||
if (pref->recheckTorrentsOnCompletion()) {
|
if (pref->recheckTorrentsOnCompletion()) {
|
||||||
|
@ -2418,7 +2420,7 @@ void QBtSession::handleStorageMovedAlert(libtorrent::storage_moved_alert* p) {
|
||||||
}
|
}
|
||||||
if (defaultTempPath.isEmpty() || !new_save_path.startsWith(defaultTempPath)) {
|
if (defaultTempPath.isEmpty() || !new_save_path.startsWith(defaultTempPath)) {
|
||||||
qDebug("Storage has been moved, updating save path to %s", qPrintable(new_save_path));
|
qDebug("Storage has been moved, updating save path to %s", qPrintable(new_save_path));
|
||||||
TorrentPersistentData::instance().saveSavePath(h.hash(), new_save_path);
|
TorrentPersistentData::instance()->saveSavePath(h.hash(), new_save_path);
|
||||||
}
|
}
|
||||||
emit savePathChanged(h);
|
emit savePathChanged(h);
|
||||||
//h.force_recheck();
|
//h.force_recheck();
|
||||||
|
@ -2657,11 +2659,11 @@ void QBtSession::handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_a
|
||||||
QTorrentHandle h(p->handle);
|
QTorrentHandle h(p->handle);
|
||||||
if (h.is_valid()) {
|
if (h.is_valid()) {
|
||||||
qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str());
|
qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str());
|
||||||
if (p->error.value() == 134 && TorrentPersistentData::instance().isSeed(h.hash()) && h.has_missing_files()) {
|
if (p->error.value() == 134 && TorrentPersistentData::instance()->isSeed(h.hash()) && h.has_missing_files()) {
|
||||||
const QString hash = h.hash();
|
const QString hash = h.hash();
|
||||||
// Mismatching file size (files were probably moved
|
// Mismatching file size (files were probably moved
|
||||||
logger->addMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name()));
|
logger->addMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name()));
|
||||||
TorrentPersistentData::instance().setErrorState(hash, true);
|
TorrentPersistentData::instance()->setErrorState(hash, true);
|
||||||
pauseTorrent(hash);
|
pauseTorrent(hash);
|
||||||
} else {
|
} else {
|
||||||
logger->addMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), Log::CRITICAL);
|
logger->addMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), Log::CRITICAL);
|
||||||
|
@ -2723,7 +2725,7 @@ void QBtSession::handleTorrentCheckedAlert(libtorrent::torrent_checked_alert* p)
|
||||||
const QString hash = h.hash();
|
const QString hash = h.hash();
|
||||||
qDebug("%s have just finished checking", qPrintable(hash));
|
qDebug("%s have just finished checking", qPrintable(hash));
|
||||||
// Save seed status
|
// Save seed status
|
||||||
TorrentPersistentData::instance().saveSeedStatus(h);
|
TorrentPersistentData::instance()->saveSeedStatus(h);
|
||||||
// Move to temp directory if necessary
|
// Move to temp directory if necessary
|
||||||
if (!h.is_seed() && !defaultTempPath.isEmpty()) {
|
if (!h.is_seed() && !defaultTempPath.isEmpty()) {
|
||||||
// Check if directory is different
|
// Check if directory is different
|
||||||
|
@ -2846,7 +2848,7 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f
|
||||||
}
|
}
|
||||||
qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath));
|
qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath));
|
||||||
} else {
|
} else {
|
||||||
savePath = fsutils::fromNativePath(TorrentPersistentData::instance().getSavePath(hash));
|
savePath = fsutils::fromNativePath(TorrentPersistentData::instance()->getSavePath(hash));
|
||||||
qDebug("SavePath got from persistant data is %s", qPrintable(savePath));
|
qDebug("SavePath got from persistant data is %s", qPrintable(savePath));
|
||||||
if (savePath.isEmpty()) {
|
if (savePath.isEmpty()) {
|
||||||
if (fromScanDir && m_scanFolders->downloadInTorrentFolder(filePath)) {
|
if (fromScanDir && m_scanFolders->downloadInTorrentFolder(filePath)) {
|
||||||
|
@ -2856,7 +2858,7 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!fromScanDir && appendLabelToSavePath) {
|
if (!fromScanDir && appendLabelToSavePath) {
|
||||||
const QString label = TorrentPersistentData::instance().getLabel(hash);
|
const QString label = TorrentPersistentData::instance()->getLabel(hash);
|
||||||
if (!label.isEmpty()) {
|
if (!label.isEmpty()) {
|
||||||
qDebug("Torrent label is %s", qPrintable(label));
|
qDebug("Torrent label is %s", qPrintable(label));
|
||||||
savePath = fsutils::updateLabelInSavePath(defaultSavePath, savePath, "", label);
|
savePath = fsutils::updateLabelInSavePath(defaultSavePath, savePath, "", label);
|
||||||
|
@ -3011,7 +3013,8 @@ qreal QBtSession::getPayloadUploadRate() const {
|
||||||
void QBtSession::startUpTorrents() {
|
void QBtSession::startUpTorrents() {
|
||||||
qDebug("Resuming unfinished torrents");
|
qDebug("Resuming unfinished torrents");
|
||||||
const QDir torrentBackup(fsutils::BTBackupLocation());
|
const QDir torrentBackup(fsutils::BTBackupLocation());
|
||||||
const QStringList known_torrents = TorrentPersistentData::instance().knownTorrents();
|
const TorrentPersistentData* const TorPersistent = TorrentPersistentData::instance();
|
||||||
|
const QStringList known_torrents = TorPersistent->knownTorrents();
|
||||||
|
|
||||||
// Safety measure because some people reported torrent loss since
|
// Safety measure because some people reported torrent loss since
|
||||||
// we switch the v1.5 way of resuming torrents on startup
|
// we switch the v1.5 way of resuming torrents on startup
|
||||||
|
@ -3032,7 +3035,7 @@ void QBtSession::startUpTorrents() {
|
||||||
if (isQueueingEnabled()) {
|
if (isQueueingEnabled()) {
|
||||||
priority_queue<QPair<int, QString>, vector<QPair<int, QString> >, std::greater<QPair<int, QString> > > torrent_queue;
|
priority_queue<QPair<int, QString>, vector<QPair<int, QString> >, std::greater<QPair<int, QString> > > torrent_queue;
|
||||||
foreach (const QString &hash, known_torrents) {
|
foreach (const QString &hash, known_torrents) {
|
||||||
const int prio = TorrentPersistentData::instance().getPriority(hash);
|
const int prio = TorPersistent->getPriority(hash);
|
||||||
torrent_queue.push(qMakePair(prio, hash));
|
torrent_queue.push(qMakePair(prio, hash));
|
||||||
}
|
}
|
||||||
qDebug("Priority_queue size: %ld", (long)torrent_queue.size());
|
qDebug("Priority_queue size: %ld", (long)torrent_queue.size());
|
||||||
|
@ -3041,8 +3044,8 @@ void QBtSession::startUpTorrents() {
|
||||||
const QString hash = torrent_queue.top().second;
|
const QString hash = torrent_queue.top().second;
|
||||||
torrent_queue.pop();
|
torrent_queue.pop();
|
||||||
qDebug("Starting up torrent %s", qPrintable(hash));
|
qDebug("Starting up torrent %s", qPrintable(hash));
|
||||||
if (TorrentPersistentData::instance().isMagnet(hash)) {
|
if (TorPersistent->isMagnet(hash)) {
|
||||||
addMagnetUri(TorrentPersistentData::instance().getMagnetUri(hash), true);
|
addMagnetUri(TorPersistent->getMagnetUri(hash), true);
|
||||||
} else {
|
} else {
|
||||||
addTorrent(torrentBackup.path()+"/"+hash+".torrent", false, QString(), true);
|
addTorrent(torrentBackup.path()+"/"+hash+".torrent", false, QString(), true);
|
||||||
}
|
}
|
||||||
|
@ -3051,8 +3054,8 @@ void QBtSession::startUpTorrents() {
|
||||||
// Resume downloads
|
// Resume downloads
|
||||||
foreach (const QString &hash, known_torrents) {
|
foreach (const QString &hash, known_torrents) {
|
||||||
qDebug("Starting up torrent %s", qPrintable(hash));
|
qDebug("Starting up torrent %s", qPrintable(hash));
|
||||||
if (TorrentPersistentData::instance().isMagnet(hash))
|
if (TorPersistent->isMagnet(hash))
|
||||||
addMagnetUri(TorrentPersistentData::instance().getMagnetUri(hash), true);
|
addMagnetUri(TorPersistent->getMagnetUri(hash), true);
|
||||||
else
|
else
|
||||||
addTorrent(torrentBackup.path()+"/"+hash+".torrent", false, QString(), true);
|
addTorrent(torrentBackup.path()+"/"+hash+".torrent", false, QString(), true);
|
||||||
}
|
}
|
||||||
|
@ -3106,7 +3109,8 @@ void QBtSession::handleIPFilterError()
|
||||||
}
|
}
|
||||||
|
|
||||||
void QBtSession::recoverPersistentData(const QString &hash, const std::vector<char> &buf) {
|
void QBtSession::recoverPersistentData(const QString &hash, const std::vector<char> &buf) {
|
||||||
if (TorrentPersistentData::instance().isKnownTorrent(hash) || TorrentTempData::hasTempData(hash) || buf.empty())
|
TorrentPersistentData* const TorPersistent = TorrentPersistentData::instance();
|
||||||
|
if (TorPersistent->isKnownTorrent(hash) || TorrentTempData::hasTempData(hash) || buf.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
libtorrent::lazy_entry fast;
|
libtorrent::lazy_entry fast;
|
||||||
|
@ -3123,20 +3127,21 @@ void QBtSession::recoverPersistentData(const QString &hash, const std::vector<ch
|
||||||
int priority = fast.dict_find_int_value("qBt-queuePosition");
|
int priority = fast.dict_find_int_value("qBt-queuePosition");
|
||||||
bool seedStatus = fast.dict_find_int_value("qBt-seedStatus");
|
bool seedStatus = fast.dict_find_int_value("qBt-seedStatus");
|
||||||
|
|
||||||
TorrentPersistentData::instance().saveSavePath(hash, savePath);
|
TorPersistent->saveSavePath(hash, savePath);
|
||||||
TorrentPersistentData::instance().setRatioLimit(hash, ratioLimit);
|
TorPersistent->setRatioLimit(hash, ratioLimit);
|
||||||
TorrentPersistentData::instance().setAddedDate(hash, addedDate);
|
TorPersistent->setAddedDate(hash, addedDate);
|
||||||
TorrentPersistentData::instance().saveLabel(hash, label);
|
TorPersistent->saveLabel(hash, label);
|
||||||
TorrentPersistentData::instance().savePriority(hash, priority);
|
TorPersistent->savePriority(hash, priority);
|
||||||
TorrentPersistentData::instance().saveSeedStatus(hash, seedStatus);
|
TorPersistent->saveSeedStatus(hash, seedStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QBtSession::backupPersistentData(const QString &hash, boost::shared_ptr<libtorrent::entry> data) {
|
void QBtSession::backupPersistentData(const QString &hash, boost::shared_ptr<libtorrent::entry> data) {
|
||||||
(*data)["qBt-savePath"] = fsutils::fromNativePath(TorrentPersistentData::instance().getSavePath(hash)).toUtf8().constData();
|
const TorrentPersistentData* const TorPersistent = TorrentPersistentData::instance();
|
||||||
(*data)["qBt-ratioLimit"] = QString::number(TorrentPersistentData::instance().getRatioLimit(hash)).toUtf8().constData();
|
(*data)["qBt-savePath"] = fsutils::fromNativePath(TorPersistent->getSavePath(hash)).toUtf8().constData();
|
||||||
(*data)["qBt-label"] = TorrentPersistentData::instance().getLabel(hash).toUtf8().constData();
|
(*data)["qBt-ratioLimit"] = QString::number(TorPersistent->getRatioLimit(hash)).toUtf8().constData();
|
||||||
(*data)["qBt-queuePosition"] = TorrentPersistentData::instance().getPriority(hash);
|
(*data)["qBt-label"] = TorPersistent->getLabel(hash).toUtf8().constData();
|
||||||
(*data)["qBt-seedStatus"] = (int)TorrentPersistentData::instance().isSeed(hash);
|
(*data)["qBt-queuePosition"] = TorPersistent->getPriority(hash);
|
||||||
|
(*data)["qBt-seedStatus"] = (int)TorPersistent->isSeed(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QBtSession::unhideMagnet(const QString &hash) {
|
void QBtSession::unhideMagnet(const QString &hash) {
|
||||||
|
@ -3191,7 +3196,7 @@ void QBtSession::unhideMagnet(const QString &hash) {
|
||||||
}
|
}
|
||||||
|
|
||||||
h.queue_position_bottom();
|
h.queue_position_bottom();
|
||||||
loadTorrentTempData(h, h.save_path(), !h.has_metadata()); //TempData are deleted by a call to TorrentPersistentData::instance().saveTorrentPersistentData()
|
loadTorrentTempData(h, h.save_path(), !h.has_metadata()); //TempData are deleted by a call to TorrentPersistentData::instance()->saveTorrentPersistentData()
|
||||||
if (!add_paused)
|
if (!add_paused)
|
||||||
h.resume();
|
h.resume();
|
||||||
h.move_storage(save_path);
|
h.move_storage(save_path);
|
||||||
|
|
|
@ -86,7 +86,7 @@ QString QTorrentHandle::hash() const
|
||||||
|
|
||||||
QString QTorrentHandle::name() const
|
QString QTorrentHandle::name() const
|
||||||
{
|
{
|
||||||
QString name = TorrentPersistentData::instance().getName(hash());
|
QString name = TorrentPersistentData::instance()->getName(hash());
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
#if LIBTORRENT_VERSION_NUM < 10000
|
#if LIBTORRENT_VERSION_NUM < 10000
|
||||||
name = misc::toQStringU(torrent_handle::name());
|
name = misc::toQStringU(torrent_handle::name());
|
||||||
|
@ -201,7 +201,7 @@ QString QTorrentHandle::save_path_parsed() const
|
||||||
p = firstFileSavePath();
|
p = firstFileSavePath();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p = fsutils::fromNativePath(TorrentPersistentData::instance().getSavePath(hash()));
|
p = fsutils::fromNativePath(TorrentPersistentData::instance()->getSavePath(hash()));
|
||||||
if (p.isEmpty())
|
if (p.isEmpty())
|
||||||
p = save_path();
|
p = save_path();
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ bool QTorrentHandle::priv() const
|
||||||
QString QTorrentHandle::firstFileSavePath() const
|
QString QTorrentHandle::firstFileSavePath() const
|
||||||
{
|
{
|
||||||
Q_ASSERT(has_metadata());
|
Q_ASSERT(has_metadata());
|
||||||
QString fsave_path = fsutils::fromNativePath(TorrentPersistentData::instance().getSavePath(hash()));
|
QString fsave_path = fsutils::fromNativePath(TorrentPersistentData::instance()->getSavePath(hash()));
|
||||||
if (fsave_path.isEmpty())
|
if (fsave_path.isEmpty())
|
||||||
fsave_path = save_path();
|
fsave_path = save_path();
|
||||||
if (!fsave_path.endsWith("/"))
|
if (!fsave_path.endsWith("/"))
|
||||||
|
@ -520,13 +520,14 @@ void QTorrentHandle::resume() const
|
||||||
torrent_handle::clear_error();
|
torrent_handle::clear_error();
|
||||||
|
|
||||||
const QString torrent_hash = hash();
|
const QString torrent_hash = hash();
|
||||||
bool has_persistant_error = TorrentPersistentData::instance().hasError(torrent_hash);
|
TorrentPersistentData* const TorPersistent = TorrentPersistentData::instance();
|
||||||
TorrentPersistentData::instance().setErrorState(torrent_hash, false);
|
bool has_persistant_error = TorPersistent->hasError(torrent_hash);
|
||||||
|
TorPersistent->setErrorState(torrent_hash, false);
|
||||||
bool temp_path_enabled = Preferences::instance()->isTempPathEnabled();
|
bool temp_path_enabled = Preferences::instance()->isTempPathEnabled();
|
||||||
if (has_persistant_error && temp_path_enabled) {
|
if (has_persistant_error && temp_path_enabled) {
|
||||||
// Torrent was supposed to be seeding, checking again in final destination
|
// Torrent was supposed to be seeding, checking again in final destination
|
||||||
qDebug("Resuming a torrent with error...");
|
qDebug("Resuming a torrent with error...");
|
||||||
const QString final_save_path = TorrentPersistentData::instance().getSavePath(torrent_hash);
|
const QString final_save_path = TorPersistent->getSavePath(torrent_hash);
|
||||||
qDebug("Torrent final path is: %s", qPrintable(final_save_path));
|
qDebug("Torrent final path is: %s", qPrintable(final_save_path));
|
||||||
if (!final_save_path.isEmpty())
|
if (!final_save_path.isEmpty())
|
||||||
move_storage(final_save_path);
|
move_storage(final_save_path);
|
||||||
|
@ -691,7 +692,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const
|
||||||
if (was_seed && !is_seed()) {
|
if (was_seed && !is_seed()) {
|
||||||
qDebug() << "Torrent is no longer SEEDING";
|
qDebug() << "Torrent is no longer SEEDING";
|
||||||
// Save seed status
|
// Save seed status
|
||||||
TorrentPersistentData::instance().saveSeedStatus(*this);
|
TorrentPersistentData::instance()->saveSeedStatus(*this);
|
||||||
// Move to temp folder if necessary
|
// Move to temp folder if necessary
|
||||||
const Preferences* const pref = Preferences::instance();
|
const Preferences* const pref = Preferences::instance();
|
||||||
if (pref->isTempPathEnabled()) {
|
if (pref->isTempPathEnabled()) {
|
||||||
|
|
|
@ -84,9 +84,9 @@ QIcon get_error_icon() {
|
||||||
TorrentModelItem::TorrentModelItem(const QTorrentHandle &h)
|
TorrentModelItem::TorrentModelItem(const QTorrentHandle &h)
|
||||||
: m_torrent(h)
|
: m_torrent(h)
|
||||||
, m_lastStatus(h.status(torrent_handle::query_accurate_download_counters))
|
, m_lastStatus(h.status(torrent_handle::query_accurate_download_counters))
|
||||||
, m_addedTime(TorrentPersistentData::instance().getAddedDate(h.hash()))
|
, m_addedTime(TorrentPersistentData::instance()->getAddedDate(h.hash()))
|
||||||
, m_label(TorrentPersistentData::instance().getLabel(h.hash()))
|
, m_label(TorrentPersistentData::instance()->getLabel(h.hash()))
|
||||||
, m_name(TorrentPersistentData::instance().getName(h.hash()))
|
, m_name(TorrentPersistentData::instance()->getName(h.hash()))
|
||||||
, m_hash(h.hash())
|
, m_hash(h.hash())
|
||||||
{
|
{
|
||||||
if (m_name.isEmpty())
|
if (m_name.isEmpty())
|
||||||
|
@ -202,14 +202,14 @@ bool TorrentModelItem::setData(int column, const QVariant &value, int role)
|
||||||
switch(column) {
|
switch(column) {
|
||||||
case TR_NAME:
|
case TR_NAME:
|
||||||
m_name = value.toString();
|
m_name = value.toString();
|
||||||
TorrentPersistentData::instance().saveName(m_torrent.hash(), m_name);
|
TorrentPersistentData::instance()->saveName(m_torrent.hash(), m_name);
|
||||||
return true;
|
return true;
|
||||||
case TR_LABEL: {
|
case TR_LABEL: {
|
||||||
QString new_label = value.toString();
|
QString new_label = value.toString();
|
||||||
if (m_label != new_label) {
|
if (m_label != new_label) {
|
||||||
QString old_label = m_label;
|
QString old_label = m_label;
|
||||||
m_label = new_label;
|
m_label = new_label;
|
||||||
TorrentPersistentData::instance().saveLabel(m_torrent.hash(), new_label);
|
TorrentPersistentData::instance()->saveLabel(m_torrent.hash(), new_label);
|
||||||
emit labelChanged(old_label, new_label);
|
emit labelChanged(old_label, new_label);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -241,59 +241,89 @@ void HiddenData::gotMetadata(const QString &hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentPersistentData::TorrentPersistentData()
|
TorrentPersistentData::TorrentPersistentData()
|
||||||
: all_data(QIniSettings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")).value("torrents").toHash())
|
: m_data(QIniSettings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")).value("torrents").toHash())
|
||||||
, dirty(false)
|
, dirty(false)
|
||||||
{
|
{
|
||||||
connect(&timer, SIGNAL(timeout()), SLOT(saveImpl()));
|
timer.setSingleShot(true);
|
||||||
m_instance = this;
|
timer.setInterval(5*1000);
|
||||||
|
connect(&timer, SIGNAL(timeout()), SLOT(save()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentPersistentData::~TorrentPersistentData()
|
TorrentPersistentData::~TorrentPersistentData()
|
||||||
{
|
{
|
||||||
save();
|
save();
|
||||||
m_instance = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::save()
|
void TorrentPersistentData::save()
|
||||||
{
|
{
|
||||||
if (dirty)
|
if (!dirty)
|
||||||
saveImpl();
|
return;
|
||||||
|
|
||||||
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||||
|
settings.setValue("torrents", m_data);
|
||||||
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentPersistentData& TorrentPersistentData::instance()
|
const QVariant TorrentPersistentData::value(const QString &key, const QVariant &defaultValue) const {
|
||||||
{
|
QReadLocker locker(&lock);
|
||||||
Q_ASSERT(m_instance);
|
return m_data.value(key, defaultValue);
|
||||||
return *m_instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentPersistentData::isKnownTorrent(QString hash)
|
void TorrentPersistentData::setValue(const QString &key, const QVariant &value) {
|
||||||
{
|
QWriteLocker locker(&lock);
|
||||||
return all_data.contains(hash);
|
if (m_data.value(key) == value)
|
||||||
|
return;
|
||||||
|
dirty = true;
|
||||||
|
timer.start();
|
||||||
|
m_data.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList TorrentPersistentData::knownTorrents()
|
TorrentPersistentData* TorrentPersistentData::instance()
|
||||||
{
|
{
|
||||||
return all_data.keys();
|
if (!m_instance)
|
||||||
|
m_instance = new TorrentPersistentData;
|
||||||
|
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TorrentPersistentData::drop()
|
||||||
|
{
|
||||||
|
if (m_instance) {
|
||||||
|
delete m_instance;
|
||||||
|
m_instance = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TorrentPersistentData::isKnownTorrent(QString hash) const
|
||||||
|
{
|
||||||
|
QReadLocker locker(&lock);
|
||||||
|
return m_data.contains(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList TorrentPersistentData::knownTorrents() const
|
||||||
|
{
|
||||||
|
QReadLocker locker(&lock);
|
||||||
|
return m_data.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::setRatioLimit(const QString &hash, const qreal &ratio)
|
void TorrentPersistentData::setRatioLimit(const QString &hash, const qreal &ratio)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
data["max_ratio"] = ratio;
|
torrent["max_ratio"] = ratio;
|
||||||
all_data[hash] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal TorrentPersistentData::getRatioLimit(const QString &hash)
|
qreal TorrentPersistentData::getRatioLimit(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
return data.value("max_ratio", USE_GLOBAL_RATIO).toReal();
|
return torrent.value("max_ratio", USE_GLOBAL_RATIO).toReal();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentPersistentData::hasPerTorrentRatioLimit()
|
bool TorrentPersistentData::hasPerTorrentRatioLimit() const
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant>::ConstIterator it = all_data.constBegin();
|
QReadLocker locker(&lock);
|
||||||
QHash<QString, QVariant>::ConstIterator itend = all_data.constEnd();
|
QHash<QString, QVariant>::ConstIterator it = m_data.constBegin();
|
||||||
|
QHash<QString, QVariant>::ConstIterator itend = m_data.constEnd();
|
||||||
for (; it != itend; ++it)
|
for (; it != itend; ++it)
|
||||||
if (it.value().toHash().value("max_ratio", USE_GLOBAL_RATIO).toReal() >= 0)
|
if (it.value().toHash().value("max_ratio", USE_GLOBAL_RATIO).toReal() >= 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -302,206 +332,181 @@ bool TorrentPersistentData::hasPerTorrentRatioLimit()
|
||||||
|
|
||||||
void TorrentPersistentData::setAddedDate(const QString &hash, const QDateTime &time)
|
void TorrentPersistentData::setAddedDate(const QString &hash, const QDateTime &time)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
if (!data.contains("add_date")) {
|
if (!torrent.contains("add_date")) {
|
||||||
data["add_date"] = time;
|
torrent["add_date"] = time;
|
||||||
all_data[hash] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime TorrentPersistentData::getAddedDate(const QString &hash)
|
QDateTime TorrentPersistentData::getAddedDate(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
QDateTime dt = data.value("add_date").toDateTime();
|
QDateTime dt = torrent.value("add_date").toDateTime();
|
||||||
if (!dt.isValid()) {
|
if (!dt.isValid())
|
||||||
setAddedDate(hash, QDateTime::currentDateTime());
|
|
||||||
dt = QDateTime::currentDateTime();
|
dt = QDateTime::currentDateTime();
|
||||||
}
|
|
||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::setErrorState(const QString &hash, const bool has_error)
|
void TorrentPersistentData::setErrorState(const QString &hash, const bool has_error)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
data["has_error"] = has_error;
|
torrent["has_error"] = has_error;
|
||||||
all_data[hash] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentPersistentData::hasError(const QString &hash)
|
bool TorrentPersistentData::hasError(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
return data.value("has_error", false).toBool();
|
return torrent.value("has_error", false).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime TorrentPersistentData::getSeedDate(const QString &hash)
|
QDateTime TorrentPersistentData::getSeedDate(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
return data.value("seed_date").toDateTime();
|
return torrent.value("seed_date").toDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::deletePersistentData(const QString &hash)
|
void TorrentPersistentData::deletePersistentData(const QString &hash)
|
||||||
{
|
{
|
||||||
if (all_data.contains(hash)) {
|
QWriteLocker locker(&lock);
|
||||||
all_data.remove(hash);
|
if (m_data.contains(hash)) {
|
||||||
markDirty();
|
m_data.remove(hash);
|
||||||
|
dirty = true;
|
||||||
|
timer.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path, const bool is_magnet)
|
void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path, const bool is_magnet)
|
||||||
{
|
{
|
||||||
Q_ASSERT(h.is_valid());
|
Q_ASSERT(h.is_valid());
|
||||||
qDebug("Saving persistent data for %s", qPrintable(h.hash()));
|
QString hash = h.hash();
|
||||||
|
qDebug("Saving persistent data for %s", qPrintable(hash));
|
||||||
// Save persistent data
|
// Save persistent data
|
||||||
QHash<QString, QVariant> data = all_data.value(h.hash()).toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
data["is_magnet"] = is_magnet;
|
torrent["is_magnet"] = is_magnet;
|
||||||
if (is_magnet)
|
if (is_magnet)
|
||||||
data["magnet_uri"] = misc::toQString(make_magnet_uri(h));
|
torrent["magnet_uri"] = misc::toQString(make_magnet_uri(h));
|
||||||
data["seed"] = h.is_seed();
|
torrent["seed"] = h.is_seed();
|
||||||
data["priority"] = h.queue_position();
|
torrent["priority"] = h.queue_position();
|
||||||
if (save_path.isEmpty()) {
|
if (save_path.isEmpty()) {
|
||||||
qDebug("TorrentPersistantData: save path is %s", qPrintable(h.save_path()));
|
qDebug("TorrentPersistantData: save path is %s", qPrintable(h.save_path()));
|
||||||
data["save_path"] = h.save_path();
|
torrent["save_path"] = h.save_path();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug("TorrentPersistantData: overriding save path is %s", qPrintable(save_path));
|
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)
|
torrent["save_path"] = save_path; // Override torrent save path (e.g. because it is a temp dir)
|
||||||
}
|
}
|
||||||
// Label
|
// Label
|
||||||
data["label"] = TorrentTempData::getLabel(h.hash());
|
torrent["label"] = TorrentTempData::getLabel(hash);
|
||||||
// Save data
|
// Save data
|
||||||
all_data[h.hash()] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(hash));
|
||||||
qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(h.hash()));
|
|
||||||
// Set Added date
|
// Set Added date
|
||||||
setAddedDate(h.hash(), QDateTime::currentDateTime());
|
setAddedDate(hash, QDateTime::currentDateTime());
|
||||||
// Finally, remove temp data
|
// Finally, remove temp data
|
||||||
TorrentTempData::deleteTempData(h.hash());
|
TorrentTempData::deleteTempData(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::saveSavePath(const QString &hash, const QString &save_path)
|
void TorrentPersistentData::saveSavePath(const QString &hash, const QString &save_path)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!hash.isEmpty());
|
Q_ASSERT(!hash.isEmpty());
|
||||||
qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path));
|
qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path));
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
data["save_path"] = save_path;
|
torrent["save_path"] = save_path;
|
||||||
all_data[hash] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", qPrintable(save_path), qPrintable(hash));
|
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", qPrintable(save_path), qPrintable(hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::saveLabel(const QString &hash, const QString &label)
|
void TorrentPersistentData::saveLabel(const QString &hash, const QString &label)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!hash.isEmpty());
|
Q_ASSERT(!hash.isEmpty());
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
data["label"] = label;
|
torrent["label"] = label;
|
||||||
all_data[hash] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::saveName(const QString &hash, const QString &name)
|
void TorrentPersistentData::saveName(const QString &hash, const QString &name)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!hash.isEmpty());
|
Q_ASSERT(!hash.isEmpty());
|
||||||
QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
data["name"] = name;
|
torrent["name"] = name;
|
||||||
all_data[hash] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::savePriority(const QTorrentHandle &h)
|
void TorrentPersistentData::savePriority(const QTorrentHandle &h)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
QString hash = h.hash();
|
||||||
data["priority"] = h.queue_position();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
all_data[h.hash()] = data;
|
torrent["priority"] = h.queue_position();
|
||||||
markDirty();
|
setValue(hash, torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::savePriority(const QString &hash, const int &queue_pos)
|
void TorrentPersistentData::savePriority(const QString &hash, const int &queue_pos)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
data["priority"] = queue_pos;
|
torrent["priority"] = queue_pos;
|
||||||
all_data[hash] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::saveSeedStatus(const QTorrentHandle &h)
|
void TorrentPersistentData::saveSeedStatus(const QTorrentHandle &h)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
QString hash = h.hash();
|
||||||
bool was_seed = data.value("seed", false).toBool();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
|
bool was_seed = torrent.value("seed", false).toBool();
|
||||||
if (was_seed != h.is_seed()) {
|
if (was_seed != h.is_seed()) {
|
||||||
data["seed"] = !was_seed;
|
torrent["seed"] = !was_seed;
|
||||||
all_data[h.hash()] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentPersistentData::saveSeedStatus(const QString &hash, const bool seedStatus)
|
void TorrentPersistentData::saveSeedStatus(const QString &hash, const bool seedStatus)
|
||||||
{
|
{
|
||||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
data["seed"] = seedStatus;
|
torrent["seed"] = seedStatus;
|
||||||
all_data[hash] = data;
|
setValue(hash, torrent);
|
||||||
markDirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TorrentPersistentData::getSavePath(const QString &hash)
|
QString TorrentPersistentData::getSavePath(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
//qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data());
|
//qDebug("TorrentPersistentData: getSavePath %s", data["save_path"].toString().toLocal8Bit().data());
|
||||||
return data.value("save_path").toString();
|
return torrent.value("save_path").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TorrentPersistentData::getLabel(const QString &hash)
|
QString TorrentPersistentData::getLabel(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
return data.value("label", "").toString();
|
return torrent.value("label", "").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TorrentPersistentData::getName(const QString &hash)
|
QString TorrentPersistentData::getName(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
return data.value("name", "").toString();
|
return torrent.value("name", "").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentPersistentData::getPriority(const QString &hash)
|
int TorrentPersistentData::getPriority(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
return data.value("priority", -1).toInt();
|
return torrent.value("priority", -1).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentPersistentData::isSeed(const QString &hash)
|
bool TorrentPersistentData::isSeed(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
return data.value("seed", false).toBool();
|
return torrent.value("seed", false).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentPersistentData::isMagnet(const QString &hash)
|
bool TorrentPersistentData::isMagnet(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
return data.value("is_magnet", false).toBool();
|
return torrent.value("is_magnet", false).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TorrentPersistentData::getMagnetUri(const QString &hash)
|
QString TorrentPersistentData::getMagnetUri(const QString &hash) const
|
||||||
{
|
{
|
||||||
const QHash<QString, QVariant> data = all_data.value(hash).toHash();
|
const QHash<QString, QVariant> torrent = value(hash).toHash();
|
||||||
Q_ASSERT(data.value("is_magnet", false).toBool());
|
Q_ASSERT(torrent.value("is_magnet", false).toBool());
|
||||||
return data.value("magnet_uri").toString();
|
return torrent.value("magnet_uri").toString();
|
||||||
}
|
|
||||||
|
|
||||||
void TorrentPersistentData::markDirty()
|
|
||||||
{
|
|
||||||
if (!dirty) {
|
|
||||||
dirty = true;
|
|
||||||
timer.start(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TorrentPersistentData::saveImpl()
|
|
||||||
{
|
|
||||||
Q_ASSERT(dirty);
|
|
||||||
|
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
|
||||||
settings.setValue("torrents", all_data);
|
|
||||||
dirty = false;
|
|
||||||
timer.stop();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QReadWriteLock>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ class TorrentPersistentData: QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DISABLE_COPY(TorrentPersistentData)
|
Q_DISABLE_COPY(TorrentPersistentData)
|
||||||
// This class stores strings w/o modifying separators
|
|
||||||
public:
|
public:
|
||||||
enum RatioLimit
|
enum RatioLimit
|
||||||
{
|
{
|
||||||
|
@ -126,24 +127,20 @@ public:
|
||||||
NO_RATIO_LIMIT = -1
|
NO_RATIO_LIMIT = -1
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
static TorrentPersistentData* instance();
|
||||||
TorrentPersistentData();
|
static void drop();
|
||||||
~TorrentPersistentData();
|
~TorrentPersistentData();
|
||||||
void save();
|
|
||||||
|
|
||||||
public:
|
bool isKnownTorrent(QString hash) const;
|
||||||
static TorrentPersistentData& instance();
|
QStringList knownTorrents() const;
|
||||||
|
|
||||||
bool isKnownTorrent(QString hash);
|
|
||||||
QStringList knownTorrents();
|
|
||||||
void setRatioLimit(const QString &hash, const qreal &ratio);
|
void setRatioLimit(const QString &hash, const qreal &ratio);
|
||||||
qreal getRatioLimit(const QString &hash);
|
qreal getRatioLimit(const QString &hash) const;
|
||||||
bool hasPerTorrentRatioLimit();
|
bool hasPerTorrentRatioLimit() const;
|
||||||
void setAddedDate(const QString &hash, const QDateTime &time);
|
void setAddedDate(const QString &hash, const QDateTime &time);
|
||||||
QDateTime getAddedDate(const QString &hash);
|
QDateTime getAddedDate(const QString &hash) const;
|
||||||
void setErrorState(const QString &hash, const bool has_error);
|
void setErrorState(const QString &hash, const bool has_error);
|
||||||
bool hasError(const QString &hash);
|
bool hasError(const QString &hash) const;
|
||||||
QDateTime getSeedDate(const QString &hash);
|
QDateTime getSeedDate(const QString &hash) const;
|
||||||
void deletePersistentData(const QString &hash);
|
void deletePersistentData(const QString &hash);
|
||||||
void saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path = QString::null, const bool is_magnet = false);
|
void saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path = QString::null, const bool is_magnet = false);
|
||||||
|
|
||||||
|
@ -157,25 +154,27 @@ public:
|
||||||
void saveSeedStatus(const QString &hash, const bool seedStatus);
|
void saveSeedStatus(const QString &hash, const bool seedStatus);
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
QString getSavePath(const QString &hash);
|
QString getSavePath(const QString &hash) const;
|
||||||
QString getLabel(const QString &hash);
|
QString getLabel(const QString &hash) const;
|
||||||
QString getName(const QString &hash);
|
QString getName(const QString &hash) const;
|
||||||
int getPriority(const QString &hash);
|
int getPriority(const QString &hash) const;
|
||||||
bool isSeed(const QString &hash);
|
bool isSeed(const QString &hash) const;
|
||||||
bool isMagnet(const QString &hash);
|
bool isMagnet(const QString &hash) const;
|
||||||
QString getMagnetUri(const QString &hash);
|
QString getMagnetUri(const QString &hash) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void save();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void markDirty();
|
TorrentPersistentData();
|
||||||
|
static TorrentPersistentData* m_instance;
|
||||||
private slots:
|
QHash<QString, QVariant> m_data;
|
||||||
void saveImpl();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QHash<QString, QVariant> all_data;
|
|
||||||
bool dirty;
|
bool dirty;
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
static TorrentPersistentData* m_instance;
|
mutable QReadWriteLock lock;
|
||||||
|
const QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||||
|
void setValue(const QString &key, const QVariant &value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TORRENTPERSISTENTDATA_H
|
#endif // TORRENTPERSISTENTDATA_H
|
||||||
|
|
|
@ -251,7 +251,7 @@ void TransferListWidget::setSelectedTorrentsLocation()
|
||||||
const QStringList hashes = getSelectedTorrentsHashes();
|
const QStringList hashes = getSelectedTorrentsHashes();
|
||||||
if (hashes.isEmpty()) return;
|
if (hashes.isEmpty()) return;
|
||||||
QString dir;
|
QString dir;
|
||||||
const QDir saveDir(TorrentPersistentData::instance().getSavePath(hashes.first()));
|
const QDir saveDir(TorrentPersistentData::instance()->getSavePath(hashes.first()));
|
||||||
qDebug("Old save path is %s", qPrintable(saveDir.absolutePath()));
|
qDebug("Old save path is %s", qPrintable(saveDir.absolutePath()));
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.absolutePath(),
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.absolutePath(),
|
||||||
QFileDialog::DontConfirmOverwrite | QFileDialog::ShowDirsOnly | QFileDialog::HideNameFilterDetails);
|
QFileDialog::DontConfirmOverwrite | QFileDialog::ShowDirsOnly | QFileDialog::HideNameFilterDetails);
|
||||||
|
@ -268,7 +268,7 @@ void TransferListWidget::setSelectedTorrentsLocation()
|
||||||
h.move_storage(savePath.absolutePath());
|
h.move_storage(savePath.absolutePath());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TorrentPersistentData::instance().saveSavePath(h.hash(), savePath.absolutePath());
|
TorrentPersistentData::instance()->saveSavePath(h.hash(), savePath.absolutePath());
|
||||||
main_window->getProperties()->updateSavePath(h);
|
main_window->getProperties()->updateSavePath(h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -415,7 +415,7 @@ QByteArray btjson::getPropertiesForTorrent(const QString& hash)
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
|
|
||||||
// Save path
|
// Save path
|
||||||
QString save_path = fsutils::toNativePath(TorrentPersistentData::instance().getSavePath(hash));
|
QString save_path = fsutils::toNativePath(TorrentPersistentData::instance()->getSavePath(hash));
|
||||||
if (save_path.isEmpty())
|
if (save_path.isEmpty())
|
||||||
save_path = fsutils::toNativePath(h.save_path());
|
save_path = fsutils::toNativePath(h.save_path());
|
||||||
data[KEY_PROP_SAVE_PATH] = save_path;
|
data[KEY_PROP_SAVE_PATH] = save_path;
|
||||||
|
@ -554,7 +554,7 @@ QVariantMap toMap(const QTorrentHandle& h)
|
||||||
ret[KEY_TORRENT_SEQUENTIAL_DOWNLOAD] = status.sequential_download;
|
ret[KEY_TORRENT_SEQUENTIAL_DOWNLOAD] = status.sequential_download;
|
||||||
if (h.has_metadata())
|
if (h.has_metadata())
|
||||||
ret[KEY_TORRENT_FIRST_LAST_PIECE_PRIO] = h.first_last_piece_first();
|
ret[KEY_TORRENT_FIRST_LAST_PIECE_PRIO] = h.first_last_piece_first();
|
||||||
ret[KEY_TORRENT_LABEL] = TorrentPersistentData::instance().getLabel(h.hash());
|
ret[KEY_TORRENT_LABEL] = TorrentPersistentData::instance()->getLabel(h.hash());
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,5 +116,5 @@ bool QTorrentFilter::torrentHasLabel(const QTorrentHandle &h) const
|
||||||
if (label_.isNull())
|
if (label_.isNull())
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return TorrentPersistentData::instance().getLabel(h.hash()) == label_;
|
return TorrentPersistentData::instance()->getLabel(h.hash()) == label_;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue