Skip to content

Commit

Permalink
Merge pull request #4784 from glassez/asm
Browse files Browse the repository at this point in the history
Implement Advanced Saving Management subsystem
  • Loading branch information
sledgehammer999 committed Mar 4, 2016
2 parents 654c8ed + dd34663 commit 6ff929e
Show file tree
Hide file tree
Showing 62 changed files with 2,144 additions and 1,534 deletions.
7 changes: 5 additions & 2 deletions src/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

#include "application.h"
#include "base/logger.h"
#include "base/settingsstorage.h"
#include "base/preferences.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
Expand All @@ -80,6 +81,7 @@ Application::Application(const QString &id, int &argc, char **argv)
#endif
{
Logger::initInstance();
SettingsStorage::initInstance();
Preferences::initInstance();

#if defined(Q_OS_MACX) && !defined(DISABLE_GUI)
Expand Down Expand Up @@ -146,7 +148,7 @@ void Application::torrentFinished(BitTorrent::TorrentHandle *const torrent)
QString program = pref->getAutoRunProgram();

program.replace("%N", torrent->name());
program.replace("%L", torrent->label());
program.replace("%L", torrent->category());
program.replace("%F", Utils::Fs::toNativePath(torrent->contentPath()));
program.replace("%R", Utils::Fs::toNativePath(torrent->rootPath()));
program.replace("%D", Utils::Fs::toNativePath(torrent->savePath()));
Expand Down Expand Up @@ -227,7 +229,7 @@ void Application::processParams(const QStringList &params)
foreach (QString param, params) {
param = param.trimmed();
#ifndef DISABLE_GUI
if (Preferences::instance()->useAdditionDialog())
if (AddNewTorrentDialog::isEnabled())
AddNewTorrentDialog::show(param, m_window);
else
#endif
Expand Down Expand Up @@ -466,6 +468,7 @@ void Application::cleanup()
#endif
Net::DownloadManager::freeInstance();
Preferences::freeInstance();
SettingsStorage::freeInstance();
Logger::freeInstance();
IconProvider::freeInstance();
#ifndef DISABLE_GUI
Expand Down
4 changes: 2 additions & 2 deletions src/app/upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ bool upgradeResumeFile(const QString &filepath, const QVariantHash &oldTorrent =

bool upgrade(bool ask = true)
{
// Move RSS cookies to common storage
Preferences::instance()->moveRSSCookies();
// Upgrade preferences
Preferences::instance()->upgrade();

QString backupFolderPath = Utils::Fs::expandPathAbs(Utils::Fs::QDesktopServicesDataLocation() + "BT_backup");
QDir backupFolderDir(backupFolderPath);
Expand Down
2 changes: 2 additions & 0 deletions src/base/base.pri
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ HEADERS += \
$$PWD/filesystemwatcher.h \
$$PWD/qinisettings.h \
$$PWD/logger.h \
$$PWD/settingsstorage.h \
$$PWD/preferences.h \
$$PWD/iconprovider.h \
$$PWD/http/irequesthandler.h \
Expand Down Expand Up @@ -58,6 +59,7 @@ SOURCES += \
$$PWD/tristatebool.cpp \
$$PWD/filesystemwatcher.cpp \
$$PWD/logger.cpp \
$$PWD/settingsstorage.cpp \
$$PWD/preferences.cpp \
$$PWD/iconprovider.cpp \
$$PWD/http/connection.cpp \
Expand Down
34 changes: 1 addition & 33 deletions src/base/bittorrent/private/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <libtorrent/session.hpp>

#include "base/qinisettings.h"
#include "base/preferences.h"
#include "base/bittorrent/sessionstatus.h"
#include "base/bittorrent/session.h"
#include "statistics.h"
Expand Down Expand Up @@ -76,40 +75,9 @@ void Statistics::save() const

void Statistics::load()
{
// Temp code. Versions v3.1.4 and v3.1.5 saved the data in the qbittorrent.ini file.
// This code reads the data from there, writes it to the new file, and removes the keys
// from the old file. This code should be removed after some time has passed.
// e.g. When we reach v3.3.0
// Don't forget to remove:
// 1. Preferences::getStats()
// 2. Preferences::removeStats()
// 3. #include "base/preferences.h"
Preferences* const pref = Preferences::instance();
QIniSettings s("qBittorrent", "qBittorrent-data");
QVariantHash v = pref->getStats();

// Let's test if the qbittorrent.ini holds the key
if (!v.isEmpty()) {
m_dirty = true;

// If the user has used qbt > 3.1.5 and then reinstalled/used
// qbt < 3.1.6, there will be stats in qbittorrent-data.ini too
// so we need to merge those 2.
if (s.contains("Stats/AllStats")) {
QVariantHash tmp = s.value("Stats/AllStats").toHash();
v["AlltimeDL"] = v["AlltimeDL"].toULongLong() + tmp["AlltimeDL"].toULongLong();
v["AlltimeUL"] = v["AlltimeUL"].toULongLong() + tmp["AlltimeUL"].toULongLong();
}
}
else {
v = s.value("Stats/AllStats").toHash();
}
QVariantHash v = s.value("Stats/AllStats").toHash();

m_alltimeDL = v["AlltimeDL"].toULongLong();
m_alltimeUL = v["AlltimeUL"].toULongLong();

if (m_dirty) {
save();
pref->removeStats();
}
}
Loading

0 comments on commit 6ff929e

Please sign in to comment.