2014-06-28 17:50:56 +04:00
|
|
|
/*
|
2018-04-14 22:53:45 +03:00
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
2018-07-10 00:37:44 +03:00
|
|
|
* Copyright (C) 2014 sledgehammer999 <hammered999@gmail.com>
|
2018-04-14 22:53:45 +03:00
|
|
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
2014-06-28 17:50:56 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-09-27 20:55:20 +03:00
|
|
|
#include "preferences.h"
|
|
|
|
|
2014-06-28 17:50:56 +04:00
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QDir>
|
2016-12-18 09:33:59 +03:00
|
|
|
#include <QLocale>
|
2017-12-07 04:32:50 +03:00
|
|
|
#include <QMutableListIterator>
|
2016-02-09 11:56:48 +03:00
|
|
|
#include <QSettings>
|
2014-06-28 17:50:56 +04:00
|
|
|
|
|
|
|
#ifndef DISABLE_GUI
|
|
|
|
#include <QApplication>
|
|
|
|
#else
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
2016-01-05 23:29:26 +03:00
|
|
|
#include <shlobj.h>
|
2018-05-24 18:41:03 +03:00
|
|
|
#include <QRegularExpression>
|
2014-06-28 17:50:56 +04:00
|
|
|
#endif
|
|
|
|
|
2015-12-27 07:02:31 +03:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#endif
|
|
|
|
|
2017-09-27 20:55:20 +03:00
|
|
|
#include "logger.h"
|
|
|
|
#include "settingsstorage.h"
|
2016-02-09 11:55:02 +03:00
|
|
|
#include "utils/fs.h"
|
|
|
|
#include "utils/misc.h"
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2018-04-15 13:06:31 +03:00
|
|
|
Preferences *Preferences::m_instance = nullptr;
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2017-02-12 04:14:01 +03:00
|
|
|
Preferences::Preferences() = default;
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
Preferences *Preferences::instance()
|
|
|
|
{
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::initInstance()
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
|
|
|
if (!m_instance)
|
|
|
|
m_instance = new Preferences;
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
void Preferences::freeInstance()
|
2014-06-28 17:50:56 +04:00
|
|
|
{
|
2015-02-23 20:44:29 +03:00
|
|
|
if (m_instance) {
|
|
|
|
delete m_instance;
|
2018-04-15 13:06:31 +03:00
|
|
|
m_instance = nullptr;
|
2015-02-23 20:44:29 +03:00
|
|
|
}
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
const QVariant Preferences::value(const QString &key, const QVariant &defaultValue) const
|
|
|
|
{
|
2016-02-09 11:55:02 +03:00
|
|
|
return SettingsStorage::instance()->loadValue(key, defaultValue);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setValue(const QString &key, const QVariant &value)
|
|
|
|
{
|
2016-02-09 11:55:02 +03:00
|
|
|
SettingsStorage::instance()->storeValue(key, value);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// General options
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getLocale() const
|
|
|
|
{
|
2018-10-27 20:59:08 +03:00
|
|
|
const QString localeName = value("Preferences/General/Locale").toString();
|
|
|
|
return (localeName.isEmpty() ? QLocale::system().name() : localeName);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setLocale(const QString &locale)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/Locale", locale);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::deleteTorrentFilesAsDefault() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/DeleteTorrentsFilesAsDefault", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setDeleteTorrentFilesAsDefault(bool del)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/DeleteTorrentsFilesAsDefault", del);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::confirmOnExit() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/ExitConfirm", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setConfirmOnExit(bool confirm)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/ExitConfirm", confirm);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::speedInTitleBar() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/SpeedInTitleBar", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::showSpeedInTitleBar(bool show)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/SpeedInTitleBar", show);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::useAlternatingRowColors() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/AlternatingRowColors", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setAlternatingRowColors(bool b)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/AlternatingRowColors", b);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2016-01-24 11:01:33 +03:00
|
|
|
bool Preferences::getHideZeroValues() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/HideZeroValues", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setHideZeroValues(bool b)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/HideZeroValues", b);
|
|
|
|
}
|
|
|
|
|
2016-02-01 15:19:28 +03:00
|
|
|
int Preferences::getHideZeroComboValues() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/HideZeroComboValues", 0).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setHideZeroComboValues(int n)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/HideZeroComboValues", n);
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
// In Mac OS X the dock is sufficient for our needs so we disable the sys tray functionality.
|
|
|
|
// See extensive discussion in https://github.com/qbittorrent/qBittorrent/pull/3018
|
|
|
|
#ifndef Q_OS_MAC
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::systrayIntegration() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/SystrayEnabled", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setSystrayIntegration(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/SystrayEnabled", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
bool Preferences::minimizeToTray() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-06-12 22:47:28 +03:00
|
|
|
return value("Preferences/General/MinimizeToTray", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
void Preferences::setMinimizeToTray(bool b)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-06-12 22:47:28 +03:00
|
|
|
setValue("Preferences/General/MinimizeToTray", b);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-08-03 14:55:20 +03:00
|
|
|
bool Preferences::minimizeToTrayNotified() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/MinimizeToTrayNotified", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setMinimizeToTrayNotified(bool b)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/MinimizeToTrayNotified", b);
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
bool Preferences::closeToTray() const
|
2015-10-30 16:03:44 +03:00
|
|
|
{
|
2018-08-03 14:21:55 +03:00
|
|
|
return value("Preferences/General/CloseToTray", true).toBool();
|
2015-10-30 16:03:44 +03:00
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
void Preferences::setCloseToTray(bool b)
|
2015-10-30 16:03:44 +03:00
|
|
|
{
|
2017-06-12 22:47:28 +03:00
|
|
|
setValue("Preferences/General/CloseToTray", b);
|
2015-10-30 16:03:44 +03:00
|
|
|
}
|
2018-08-03 14:55:20 +03:00
|
|
|
|
|
|
|
bool Preferences::closeToTrayNotified() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/CloseToTrayNotified", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setCloseToTrayNotified(bool b)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/CloseToTrayNotified", b);
|
|
|
|
}
|
2017-06-12 22:47:28 +03:00
|
|
|
#endif
|
2015-10-30 16:03:44 +03:00
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
bool Preferences::isToolbarDisplayed() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-06-12 22:47:28 +03:00
|
|
|
return value("Preferences/General/ToolbarDisplayed", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
void Preferences::setToolbarDisplayed(bool displayed)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-06-12 22:47:28 +03:00
|
|
|
setValue("Preferences/General/ToolbarDisplayed", displayed);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
bool Preferences::isStatusbarDisplayed() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-06-12 22:47:28 +03:00
|
|
|
return value("Preferences/General/StatusbarDisplayed", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
void Preferences::setStatusbarDisplayed(bool displayed)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-06-12 22:47:28 +03:00
|
|
|
setValue("Preferences/General/StatusbarDisplayed", displayed);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::startMinimized() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/StartMinimized", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setStartMinimized(bool b)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/StartMinimized", b);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isSplashScreenDisabled() const
|
|
|
|
{
|
2016-02-07 05:48:51 +03:00
|
|
|
return value("Preferences/General/NoSplashScreen", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setSplashScreenDisabled(bool b)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/NoSplashScreen", b);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Preventing from system suspend while active torrents are presented.
|
2018-08-02 22:45:21 +03:00
|
|
|
bool Preferences::preventFromSuspendWhenDownloading() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2018-08-02 22:45:21 +03:00
|
|
|
return value("Preferences/General/PreventFromSuspendWhenDownloading", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-08-02 22:45:21 +03:00
|
|
|
void Preferences::setPreventFromSuspendWhenDownloading(bool b)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2018-08-02 22:45:21 +03:00
|
|
|
setValue("Preferences/General/PreventFromSuspendWhenDownloading", b);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Preferences::preventFromSuspendWhenSeeding() const
|
|
|
|
{
|
|
|
|
return value("Preferences/General/PreventFromSuspendWhenSeeding", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setPreventFromSuspendWhenSeeding(bool b)
|
|
|
|
{
|
|
|
|
setValue("Preferences/General/PreventFromSuspendWhenSeeding", b);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::WinStartup() const
|
|
|
|
{
|
|
|
|
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
|
|
|
return settings.contains("qBittorrent");
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setWinStartup(bool b)
|
|
|
|
{
|
|
|
|
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
|
|
|
if (b) {
|
2018-07-21 08:28:13 +03:00
|
|
|
const QString binPath = '"' + Utils::Fs::toNativePath(qApp->applicationFilePath()) + '"';
|
2018-06-14 14:46:50 +03:00
|
|
|
settings.setValue("qBittorrent", binPath);
|
2015-02-23 20:44:29 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
settings.remove("qBittorrent");
|
|
|
|
}
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Downloads
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::lastLocationPath() const
|
|
|
|
{
|
2015-05-06 14:53:27 +03:00
|
|
|
return Utils::Fs::fromNativePath(value("Preferences/Downloads/LastLocationPath").toString());
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setLastLocationPath(const QString &path)
|
|
|
|
{
|
2015-05-06 14:53:27 +03:00
|
|
|
setValue("Preferences/Downloads/LastLocationPath", Utils::Fs::fromNativePath(path));
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-12-12 23:26:17 +03:00
|
|
|
QVariantHash Preferences::getScanDirs() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2015-12-12 23:26:17 +03:00
|
|
|
return value("Preferences/Downloads/ScanDirsV2").toHash();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This must be called somewhere with data from the model
|
2015-12-12 23:26:17 +03:00
|
|
|
void Preferences::setScanDirs(const QVariantHash &dirs)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2015-12-12 23:26:17 +03:00
|
|
|
setValue("Preferences/Downloads/ScanDirsV2", dirs);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getScanDirsLastPath() const
|
|
|
|
{
|
2015-05-06 14:53:27 +03:00
|
|
|
return Utils::Fs::fromNativePath(value("Preferences/Downloads/ScanDirsLastPath").toString());
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setScanDirsLastPath(const QString &path)
|
|
|
|
{
|
2015-05-06 14:53:27 +03:00
|
|
|
setValue("Preferences/Downloads/ScanDirsLastPath", Utils::Fs::fromNativePath(path));
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isMailNotificationEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/MailNotification/enabled", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMailNotificationEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/MailNotification/enabled", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-10-25 15:58:01 +03:00
|
|
|
QString Preferences::getMailNotificationSender() const
|
|
|
|
{
|
|
|
|
return value("Preferences/MailNotification/sender", "qBittorrent_notification@example.com").toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setMailNotificationSender(const QString &mail)
|
|
|
|
{
|
|
|
|
setValue("Preferences/MailNotification/sender", mail);
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getMailNotificationEmail() const
|
|
|
|
{
|
|
|
|
return value("Preferences/MailNotification/email").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMailNotificationEmail(const QString &mail)
|
|
|
|
{
|
|
|
|
setValue("Preferences/MailNotification/email", mail);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getMailNotificationSMTP() const
|
|
|
|
{
|
|
|
|
return value("Preferences/MailNotification/smtp_server", "smtp.changeme.com").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMailNotificationSMTP(const QString &smtp_server)
|
|
|
|
{
|
|
|
|
setValue("Preferences/MailNotification/smtp_server", smtp_server);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::getMailNotificationSMTPSSL() const
|
|
|
|
{
|
|
|
|
return value("Preferences/MailNotification/req_ssl", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMailNotificationSMTPSSL(bool use)
|
|
|
|
{
|
|
|
|
setValue("Preferences/MailNotification/req_ssl", use);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::getMailNotificationSMTPAuth() const
|
|
|
|
{
|
|
|
|
return value("Preferences/MailNotification/req_auth", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMailNotificationSMTPAuth(bool use)
|
|
|
|
{
|
|
|
|
setValue("Preferences/MailNotification/req_auth", use);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getMailNotificationSMTPUsername() const
|
|
|
|
{
|
|
|
|
return value("Preferences/MailNotification/username").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMailNotificationSMTPUsername(const QString &username)
|
|
|
|
{
|
|
|
|
setValue("Preferences/MailNotification/username", username);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getMailNotificationSMTPPassword() const
|
|
|
|
{
|
|
|
|
return value("Preferences/MailNotification/password").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMailNotificationSMTPPassword(const QString &password)
|
|
|
|
{
|
|
|
|
setValue("Preferences/MailNotification/password", password);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
int Preferences::getActionOnDblClOnTorrentDl() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Downloads/DblClOnTorDl", 0).toInt();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setActionOnDblClOnTorrentDl(int act)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Downloads/DblClOnTorDl", act);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
int Preferences::getActionOnDblClOnTorrentFn() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Downloads/DblClOnTorFn", 1).toInt();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setActionOnDblClOnTorrentFn(int act)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Downloads/DblClOnTorFn", act);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QTime Preferences::getSchedulerStartTime() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Scheduler/start_time", QTime(8,0)).toTime();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setSchedulerStartTime(const QTime &time)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Scheduler/start_time", time);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QTime Preferences::getSchedulerEndTime() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Scheduler/end_time", QTime(20,0)).toTime();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setSchedulerEndTime(const QTime &time)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Scheduler/end_time", time);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
SchedulerDays Preferences::getSchedulerDays() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2018-04-14 22:53:45 +03:00
|
|
|
return static_cast<SchedulerDays>(value("Preferences/Scheduler/days", EVERY_DAY).toInt());
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
void Preferences::setSchedulerDays(SchedulerDays days)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-05-29 15:10:31 +03:00
|
|
|
setValue("Preferences/Scheduler/days", static_cast<int>(days));
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Search
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isSearchEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Search/SearchEnabled", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setSearchEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Search/SearchEnabled", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isWebUiEnabled() const
|
|
|
|
{
|
2015-04-27 21:44:12 +03:00
|
|
|
#ifdef DISABLE_GUI
|
|
|
|
return true;
|
|
|
|
#else
|
2015-02-23 20:44:29 +03:00
|
|
|
return value("Preferences/WebUI/Enabled", false).toBool();
|
2015-04-27 21:44:12 +03:00
|
|
|
#endif
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setWebUiEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/Enabled", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isWebUiLocalAuthEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/LocalHostAuth", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setWebUiLocalAuthEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/LocalHostAuth", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-09-27 20:55:20 +03:00
|
|
|
bool Preferences::isWebUiAuthSubnetWhitelistEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/AuthSubnetWhitelistEnabled", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setWebUiAuthSubnetWhitelistEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/AuthSubnetWhitelistEnabled", enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
|
|
|
|
{
|
|
|
|
QList<Utils::Net::Subnet> subnets;
|
|
|
|
foreach (const QString &rawSubnet, value("Preferences/WebUI/AuthSubnetWhitelist").toStringList()) {
|
|
|
|
bool ok = false;
|
|
|
|
const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(rawSubnet.trimmed(), &ok);
|
|
|
|
if (ok)
|
|
|
|
subnets.append(subnet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return subnets;
|
|
|
|
}
|
|
|
|
|
2017-12-07 04:32:50 +03:00
|
|
|
void Preferences::setWebUiAuthSubnetWhitelist(QStringList subnets)
|
2017-09-27 20:55:20 +03:00
|
|
|
{
|
2017-12-07 04:32:50 +03:00
|
|
|
QMutableListIterator<QString> i(subnets);
|
|
|
|
while (i.hasNext()) {
|
2017-12-06 10:02:54 +03:00
|
|
|
bool ok = false;
|
2017-12-07 04:32:50 +03:00
|
|
|
const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(i.next().trimmed(), &ok);
|
|
|
|
if (!ok)
|
|
|
|
i.remove();
|
2017-12-06 10:02:54 +03:00
|
|
|
}
|
2017-09-27 20:55:20 +03:00
|
|
|
|
2017-12-07 04:32:50 +03:00
|
|
|
setValue("Preferences/WebUI/AuthSubnetWhitelist", subnets);
|
2017-09-27 20:55:20 +03:00
|
|
|
}
|
|
|
|
|
2017-07-02 13:23:10 +03:00
|
|
|
QString Preferences::getServerDomains() const
|
|
|
|
{
|
2018-08-18 22:28:41 +03:00
|
|
|
return value("Preferences/WebUI/ServerDomains", QChar('*')).toString();
|
2017-07-02 13:23:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setServerDomains(const QString &str)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/ServerDomains", str);
|
|
|
|
}
|
|
|
|
|
2017-10-12 05:28:31 +03:00
|
|
|
QString Preferences::getWebUiAddress() const
|
|
|
|
{
|
2018-08-18 22:28:41 +03:00
|
|
|
return value("Preferences/WebUI/Address", QChar('*')).toString().trimmed();
|
2017-10-12 05:28:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setWebUiAddress(const QString &addr)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/Address", addr.trimmed());
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
quint16 Preferences::getWebUiPort() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/Port", 8080).toInt();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setWebUiPort(quint16 port)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/Port", port);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::useUPnPForWebUIPort() const
|
|
|
|
{
|
2017-02-10 10:42:33 +03:00
|
|
|
#ifdef DISABLE_GUI
|
2015-02-23 20:44:29 +03:00
|
|
|
return value("Preferences/WebUI/UseUPnP", true).toBool();
|
2017-02-10 10:42:33 +03:00
|
|
|
#else
|
|
|
|
return value("Preferences/WebUI/UseUPnP", false).toBool();
|
|
|
|
#endif
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setUPnPForWebUIPort(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/UseUPnP", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getWebUiUsername() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/Username", "admin").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setWebUiUsername(const QString &username)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/Username", username);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getWebUiPassword() const
|
|
|
|
{
|
2018-06-14 14:46:50 +03:00
|
|
|
QString passHa1 = value("Preferences/WebUI/Password_ha1").toString();
|
|
|
|
if (passHa1.isEmpty()) {
|
2015-02-23 20:44:29 +03:00
|
|
|
QCryptographicHash md5(QCryptographicHash::Md5);
|
|
|
|
md5.addData("adminadmin");
|
2018-06-14 14:46:50 +03:00
|
|
|
passHa1 = md5.result().toHex();
|
2015-02-23 20:44:29 +03:00
|
|
|
}
|
2018-06-14 14:46:50 +03:00
|
|
|
return passHa1;
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-06-14 14:46:50 +03:00
|
|
|
void Preferences::setWebUiPassword(const QString &newPassword)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
|
|
|
// Do not overwrite current password with its hash
|
2018-06-14 14:46:50 +03:00
|
|
|
if (newPassword == getWebUiPassword())
|
2015-02-23 20:44:29 +03:00
|
|
|
return;
|
2014-12-04 20:47:45 +03:00
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
// Encode to md5 and save
|
|
|
|
QCryptographicHash md5(QCryptographicHash::Md5);
|
2018-06-14 14:46:50 +03:00
|
|
|
md5.addData(newPassword.toLocal8Bit());
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
setValue("Preferences/WebUI/Password_ha1", md5.result().toHex());
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-05-21 18:33:44 +03:00
|
|
|
bool Preferences::isWebUiClickjackingProtectionEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/ClickjackingProtection", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setWebUiClickjackingProtectionEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/ClickjackingProtection", enabled);
|
|
|
|
}
|
|
|
|
|
2018-05-21 19:43:33 +03:00
|
|
|
bool Preferences::isWebUiCSRFProtectionEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/CSRFProtection", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setWebUiCSRFProtectionEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/CSRFProtection", enabled);
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isWebUiHttpsEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/HTTPS/Enabled", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setWebUiHttpsEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/HTTPS/Enabled", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getWebUiHttpsCertificate() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/HTTPS/Certificate").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setWebUiHttpsCertificate(const QByteArray &data)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/HTTPS/Certificate", data);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getWebUiHttpsKey() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/HTTPS/Key").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setWebUiHttpsKey(const QByteArray &data)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/HTTPS/Key", data);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-10-14 16:27:21 +03:00
|
|
|
bool Preferences::isAltWebUiEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/AlternativeUIEnabled", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setAltWebUiEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/AlternativeUIEnabled", enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Preferences::getWebUiRootFolder() const
|
|
|
|
{
|
|
|
|
return value("Preferences/WebUI/RootFolder").toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setWebUiRootFolder(const QString &path)
|
|
|
|
{
|
|
|
|
setValue("Preferences/WebUI/RootFolder", path);
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isDynDNSEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/DynDNS/Enabled", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setDynDNSEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/DynDNS/Enabled", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
DNS::Service Preferences::getDynDNSService() const
|
|
|
|
{
|
|
|
|
return DNS::Service(value("Preferences/DynDNS/Service", DNS::DYNDNS).toInt());
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setDynDNSService(int service)
|
|
|
|
{
|
|
|
|
setValue("Preferences/DynDNS/Service", service);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getDynDomainName() const
|
|
|
|
{
|
|
|
|
return value("Preferences/DynDNS/DomainName", "changeme.dyndns.org").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setDynDomainName(const QString &name)
|
|
|
|
{
|
|
|
|
setValue("Preferences/DynDNS/DomainName", name);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getDynDNSUsername() const
|
|
|
|
{
|
|
|
|
return value("Preferences/DynDNS/Username").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setDynDNSUsername(const QString &username)
|
|
|
|
{
|
|
|
|
setValue("Preferences/DynDNS/Username", username);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getDynDNSPassword() const
|
|
|
|
{
|
|
|
|
return value("Preferences/DynDNS/Password").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setDynDNSPassword(const QString &password)
|
|
|
|
{
|
|
|
|
setValue("Preferences/DynDNS/Password", password);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Advanced settings
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::clearUILockPassword()
|
|
|
|
{
|
|
|
|
setValue("Locking/password", QString());
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getUILockPasswordMD5() const
|
|
|
|
{
|
|
|
|
return value("Locking/password").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-04-14 22:53:45 +03:00
|
|
|
void Preferences::setUILockPassword(const QString &clearPassword)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
|
|
|
QCryptographicHash md5(QCryptographicHash::Md5);
|
2018-04-14 22:53:45 +03:00
|
|
|
md5.addData(clearPassword.toLocal8Bit());
|
|
|
|
QString md5Password = md5.result().toHex();
|
|
|
|
setValue("Locking/password", md5Password);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isUILocked() const
|
|
|
|
{
|
|
|
|
return value("Locking/locked", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setUILocked(bool locked)
|
|
|
|
{
|
|
|
|
return setValue("Locking/locked", locked);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isAutoRunEnabled() const
|
|
|
|
{
|
|
|
|
return value("AutoRun/enabled", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setAutoRunEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
return setValue("AutoRun/enabled", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getAutoRunProgram() const
|
|
|
|
{
|
2016-02-23 12:10:43 +03:00
|
|
|
return value("AutoRun/program").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setAutoRunProgram(const QString &program)
|
|
|
|
{
|
2016-02-23 12:10:43 +03:00
|
|
|
setValue("AutoRun/program", program);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::shutdownWhenDownloadsComplete() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Downloads/AutoShutDownOnCompletion", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setShutdownWhenDownloadsComplete(bool shutdown)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Downloads/AutoShutDownOnCompletion", shutdown);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::suspendWhenDownloadsComplete() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Downloads/AutoSuspendOnCompletion", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setSuspendWhenDownloadsComplete(bool suspend)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Downloads/AutoSuspendOnCompletion", suspend);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::hibernateWhenDownloadsComplete() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Downloads/AutoHibernateOnCompletion", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setHibernateWhenDownloadsComplete(bool hibernate)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Downloads/AutoHibernateOnCompletion", hibernate);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::shutdownqBTWhenDownloadsComplete() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Downloads/AutoShutDownqBTOnCompletion", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setShutdownqBTWhenDownloadsComplete(bool shutdown)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Downloads/AutoShutDownqBTOnCompletion", shutdown);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-12-09 11:01:48 +03:00
|
|
|
bool Preferences::dontConfirmAutoExit() const
|
|
|
|
{
|
2016-03-21 00:54:07 +03:00
|
|
|
return value("ShutdownConfirmDlg/DontConfirmAutoExit", false).toBool();
|
2015-12-09 11:01:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setDontConfirmAutoExit(bool dontConfirmAutoExit)
|
|
|
|
{
|
2016-03-21 00:54:07 +03:00
|
|
|
setValue("ShutdownConfirmDlg/DontConfirmAutoExit", dontConfirmAutoExit);
|
2015-12-09 11:01:48 +03:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::recheckTorrentsOnCompletion() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Advanced/RecheckOnCompletion", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::recheckTorrentsOnCompletion(bool recheck)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/RecheckOnCompletion", recheck);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::resolvePeerCountries() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Connection/ResolvePeerCountries", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::resolvePeerCountries(bool resolve)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Connection/ResolvePeerCountries", resolve);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::resolvePeerHostNames() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Connection/ResolvePeerHostNames", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::resolvePeerHostNames(bool resolve)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Connection/ResolvePeerHostNames", resolve);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::useSystemIconTheme() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Advanced/useSystemIconTheme", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::useSystemIconTheme(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/useSystemIconTheme", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::recursiveDownloadDisabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Advanced/DisableRecursiveDownload", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::disableRecursiveDownload(bool disable)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/DisableRecursiveDownload", disable);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::neverCheckFileAssoc() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Win32/NeverCheckFileAssocation", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setNeverCheckFileAssoc(bool check)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Win32/NeverCheckFileAssocation", check);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isTorrentFileAssocSet()
|
|
|
|
{
|
|
|
|
QSettings settings("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat);
|
|
|
|
if (settings.value(".torrent/Default").toString() != "qBittorrent") {
|
|
|
|
qDebug(".torrent != qBittorrent");
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
return true;
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isMagnetLinkAssocSet()
|
|
|
|
{
|
|
|
|
QSettings settings("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat);
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
// Check magnet link assoc
|
2018-05-24 18:41:03 +03:00
|
|
|
const QString shellCommand = Utils::Fs::toNativePath(settings.value("magnet/shell/open/command/Default", "").toString());
|
|
|
|
|
|
|
|
const QRegularExpressionMatch exeRegMatch = QRegularExpression("\"([^\"]+)\".*").match(shellCommand);
|
|
|
|
if (!exeRegMatch.hasMatch())
|
2015-02-23 20:44:29 +03:00
|
|
|
return false;
|
2018-05-24 18:41:03 +03:00
|
|
|
|
|
|
|
const QString assocExe = exeRegMatch.captured(1);
|
|
|
|
if (assocExe.compare(Utils::Fs::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0)
|
2015-02-23 20:44:29 +03:00
|
|
|
return false;
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
return true;
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setTorrentFileAssoc(bool set)
|
|
|
|
{
|
|
|
|
QSettings settings("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat);
|
|
|
|
|
|
|
|
// .Torrent association
|
|
|
|
if (set) {
|
2018-06-14 14:46:50 +03:00
|
|
|
QString oldProgId = settings.value(".torrent/Default").toString();
|
|
|
|
if (!oldProgId.isEmpty() && (oldProgId != "qBittorrent"))
|
|
|
|
settings.setValue(".torrent/OpenWithProgids/" + oldProgId, "");
|
2015-02-23 20:44:29 +03:00
|
|
|
settings.setValue(".torrent/Default", "qBittorrent");
|
|
|
|
}
|
|
|
|
else if (isTorrentFileAssocSet()) {
|
|
|
|
settings.setValue(".torrent/Default", "");
|
|
|
|
}
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMagnetLinkAssoc(bool set)
|
|
|
|
{
|
|
|
|
QSettings settings("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat);
|
|
|
|
|
|
|
|
// Magnet association
|
|
|
|
if (set) {
|
2018-07-21 08:28:13 +03:00
|
|
|
const QString commandStr = '"' + qApp->applicationFilePath() + "\" \"%1\"";
|
|
|
|
const QString iconStr = '"' + qApp->applicationFilePath() + "\",1";
|
2015-02-23 20:44:29 +03:00
|
|
|
|
|
|
|
settings.setValue("magnet/Default", "URL:Magnet link");
|
|
|
|
settings.setValue("magnet/Content Type", "application/x-magnet");
|
|
|
|
settings.setValue("magnet/URL Protocol", "");
|
2018-06-14 14:46:50 +03:00
|
|
|
settings.setValue("magnet/DefaultIcon/Default", Utils::Fs::toNativePath(iconStr));
|
2015-02-23 20:44:29 +03:00
|
|
|
settings.setValue("magnet/shell/Default", "open");
|
2018-06-14 14:46:50 +03:00
|
|
|
settings.setValue("magnet/shell/open/command/Default", Utils::Fs::toNativePath(commandStr));
|
2015-02-23 20:44:29 +03:00
|
|
|
}
|
|
|
|
else if (isMagnetLinkAssocSet()) {
|
|
|
|
settings.remove("magnet");
|
|
|
|
}
|
2014-06-28 17:50:56 +04:00
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-27 07:02:31 +03:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
CFStringRef torrentExtension = CFSTR("torrent");
|
|
|
|
CFStringRef magnetUrlScheme = CFSTR("magnet");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Preferences::isTorrentFileAssocSet()
|
|
|
|
{
|
|
|
|
bool isSet = false;
|
|
|
|
CFStringRef torrentId = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, torrentExtension, NULL);
|
|
|
|
if (torrentId != NULL) {
|
|
|
|
CFStringRef defaultHandlerId = LSCopyDefaultRoleHandlerForContentType(torrentId, kLSRolesViewer);
|
|
|
|
if (defaultHandlerId != NULL) {
|
|
|
|
CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
|
|
|
|
isSet = CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo;
|
|
|
|
CFRelease(defaultHandlerId);
|
2016-01-24 11:01:33 +03:00
|
|
|
}
|
2015-12-27 07:02:31 +03:00
|
|
|
CFRelease(torrentId);
|
|
|
|
}
|
|
|
|
return isSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Preferences::isMagnetLinkAssocSet()
|
|
|
|
{
|
|
|
|
bool isSet = false;
|
|
|
|
CFStringRef defaultHandlerId = LSCopyDefaultHandlerForURLScheme(magnetUrlScheme);
|
|
|
|
if (defaultHandlerId != NULL) {
|
|
|
|
CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
|
|
|
|
isSet = CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo;
|
|
|
|
CFRelease(defaultHandlerId);
|
|
|
|
}
|
|
|
|
return isSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setTorrentFileAssoc()
|
|
|
|
{
|
|
|
|
if (isTorrentFileAssocSet())
|
|
|
|
return;
|
|
|
|
CFStringRef torrentId = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, torrentExtension, NULL);
|
|
|
|
if (torrentId != NULL) {
|
|
|
|
CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
|
|
|
|
LSSetDefaultRoleHandlerForContentType(torrentId, kLSRolesViewer, myBundleId);
|
|
|
|
CFRelease(torrentId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setMagnetLinkAssoc()
|
|
|
|
{
|
|
|
|
if (isMagnetLinkAssocSet())
|
|
|
|
return;
|
|
|
|
CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle());
|
|
|
|
LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
int Preferences::getTrackerPort() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Advanced/trackerPort", 9000).toInt();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setTrackerPort(int port)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/trackerPort", port);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::isUpdateCheckEnabled() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Advanced/updateCheck", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setUpdateCheckEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/updateCheck", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::confirmTorrentDeletion() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Advanced/confirmTorrentDeletion", true).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setConfirmTorrentDeletion(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/confirmTorrentDeletion", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-07-08 23:29:31 +03:00
|
|
|
bool Preferences::confirmTorrentRecheck() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Advanced/confirmTorrentRecheck", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setConfirmTorrentRecheck(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/confirmTorrentRecheck", enabled);
|
|
|
|
}
|
|
|
|
|
2017-06-05 03:22:17 +03:00
|
|
|
bool Preferences::confirmRemoveAllTags() const
|
|
|
|
{
|
|
|
|
return value("Preferences/Advanced/confirmRemoveAllTags", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setConfirmRemoveAllTags(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/confirmRemoveAllTags", enabled);
|
|
|
|
}
|
|
|
|
|
2017-06-12 22:47:28 +03:00
|
|
|
#ifndef Q_OS_MAC
|
2015-02-23 20:44:29 +03:00
|
|
|
TrayIcon::Style Preferences::trayIconStyle() const
|
|
|
|
{
|
|
|
|
return TrayIcon::Style(value("Preferences/Advanced/TrayIconStyle", TrayIcon::NORMAL).toInt());
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setTrayIconStyle(TrayIcon::Style style)
|
|
|
|
{
|
|
|
|
setValue("Preferences/Advanced/TrayIconStyle", style);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
2017-06-12 22:47:28 +03:00
|
|
|
#endif
|
2014-06-28 17:50:56 +04:00
|
|
|
|
|
|
|
// Stuff that don't appear in the Options GUI but are saved
|
|
|
|
// in the same file.
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QDateTime Preferences::getDNSLastUpd() const
|
|
|
|
{
|
|
|
|
return value("DNSUpdater/lastUpdateTime").toDateTime();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setDNSLastUpd(const QDateTime &date)
|
|
|
|
{
|
|
|
|
setValue("DNSUpdater/lastUpdateTime", date);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getDNSLastIP() const
|
|
|
|
{
|
|
|
|
return value("DNSUpdater/lastIP").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setDNSLastIP(const QString &ip)
|
|
|
|
{
|
|
|
|
setValue("DNSUpdater/lastIP", ip);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::getAcceptedLegal() const
|
|
|
|
{
|
|
|
|
return value("LegalNotice/Accepted", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setAcceptedLegal(const bool accepted)
|
|
|
|
{
|
|
|
|
setValue("LegalNotice/Accepted", accepted);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getMainGeometry() const
|
|
|
|
{
|
|
|
|
return value("MainWindow/geometry").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMainGeometry(const QByteArray &geometry)
|
|
|
|
{
|
|
|
|
setValue("MainWindow/geometry", geometry);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getMainVSplitterState() const
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
return value("MainWindow/qt5/vsplitterState").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMainVSplitterState(const QByteArray &state)
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
setValue("MainWindow/qt5/vsplitterState", state);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getMainLastDir() const
|
|
|
|
{
|
|
|
|
return value("MainWindowLastDir", QDir::homePath()).toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setMainLastDir(const QString &path)
|
|
|
|
{
|
|
|
|
setValue("MainWindowLastDir", path);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-12-03 10:32:58 +03:00
|
|
|
QSize Preferences::getPrefSize() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-12-03 10:32:58 +03:00
|
|
|
return value("Preferences/State/size").toSize();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setPrefSize(const QSize &size)
|
|
|
|
{
|
|
|
|
setValue("Preferences/State/size", size);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QStringList Preferences::getPrefHSplitterSizes() const
|
|
|
|
{
|
|
|
|
return value("Preferences/State/hSplitterSizes").toStringList();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setPrefHSplitterSizes(const QStringList &sizes)
|
|
|
|
{
|
|
|
|
setValue("Preferences/State/hSplitterSizes", sizes);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getPeerListState() const
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
return value("TorrentProperties/Peers/qt5/PeerListState").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setPeerListState(const QByteArray &state)
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
setValue("TorrentProperties/Peers/qt5/PeerListState", state);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getPropSplitterSizes() const
|
|
|
|
{
|
|
|
|
return value("TorrentProperties/SplitterSizes").toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setPropSplitterSizes(const QString &sizes)
|
|
|
|
{
|
|
|
|
setValue("TorrentProperties/SplitterSizes", sizes);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getPropFileListState() const
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
return value("TorrentProperties/qt5/FilesListState").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setPropFileListState(const QByteArray &state)
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
setValue("TorrentProperties/qt5/FilesListState", state);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
int Preferences::getPropCurTab() const
|
|
|
|
{
|
|
|
|
return value("TorrentProperties/CurrentTab", -1).toInt();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setPropCurTab(const int &tab)
|
|
|
|
{
|
|
|
|
setValue("TorrentProperties/CurrentTab", tab);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
bool Preferences::getPropVisible() const
|
|
|
|
{
|
|
|
|
return value("TorrentProperties/Visible", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setPropVisible(const bool visible)
|
|
|
|
{
|
|
|
|
setValue("TorrentProperties/Visible", visible);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getPropTrackerListState() const
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
return value("TorrentProperties/Trackers/qt5/TrackerListState").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setPropTrackerListState(const QByteArray &state)
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
setValue("TorrentProperties/Trackers/qt5/TrackerListState", state);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-12-03 10:32:58 +03:00
|
|
|
QSize Preferences::getRssGeometrySize() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-12-03 10:32:58 +03:00
|
|
|
return value("RssFeedDownloader/geometrySize").toSize();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-10-27 11:45:11 +03:00
|
|
|
void Preferences::setRssGeometrySize(const QSize &geometry)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2015-10-27 11:45:11 +03:00
|
|
|
setValue("RssFeedDownloader/geometrySize", geometry);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getRssHSplitterSizes() const
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
return value("RssFeedDownloader/qt5/hsplitterSizes").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setRssHSplitterSizes(const QByteArray &sizes)
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
setValue("RssFeedDownloader/qt5/hsplitterSizes", sizes);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QStringList Preferences::getRssOpenFolders() const
|
|
|
|
{
|
2017-03-07 16:10:42 +03:00
|
|
|
return value("GUI/RSSWidget/OpenedFolders").toStringList();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setRssOpenFolders(const QStringList &folders)
|
|
|
|
{
|
2017-03-07 16:10:42 +03:00
|
|
|
setValue("GUI/RSSWidget/OpenedFolders", folders);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2016-11-17 06:11:48 +03:00
|
|
|
QByteArray Preferences::getRssSideSplitterState() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-03-07 16:10:42 +03:00
|
|
|
return value("GUI/RSSWidget/qt5/splitter_h").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2016-11-17 06:11:48 +03:00
|
|
|
void Preferences::setRssSideSplitterState(const QByteArray &state)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-03-07 16:10:42 +03:00
|
|
|
setValue("GUI/RSSWidget/qt5/splitter_h", state);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2016-11-17 06:11:48 +03:00
|
|
|
QByteArray Preferences::getRssMainSplitterState() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-03-07 16:10:42 +03:00
|
|
|
return value("GUI/RSSWidget/qt5/splitterMain").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2016-11-17 06:11:48 +03:00
|
|
|
void Preferences::setRssMainSplitterState(const QByteArray &state)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-03-07 16:10:42 +03:00
|
|
|
setValue("GUI/RSSWidget/qt5/splitterMain", state);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2016-06-22 16:34:53 +03:00
|
|
|
QByteArray Preferences::getSearchTabHeaderState() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-01-21 03:48:51 +03:00
|
|
|
return value("SearchTab/qt5/HeaderState").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2016-06-22 16:34:53 +03:00
|
|
|
void Preferences::setSearchTabHeaderState(const QByteArray &state)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-01-21 03:48:51 +03:00
|
|
|
setValue("SearchTab/qt5/HeaderState", state);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-08-12 17:40:17 +03:00
|
|
|
bool Preferences::getRegexAsFilteringPatternForSearchJob() const
|
|
|
|
{
|
|
|
|
return value("SearchTab/UseRegexAsFilteringPattern", false).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setRegexAsFilteringPatternForSearchJob(const bool checked)
|
|
|
|
{
|
|
|
|
setValue("SearchTab/UseRegexAsFilteringPattern", checked);
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QStringList Preferences::getSearchEngDisabled() const
|
|
|
|
{
|
|
|
|
return value("SearchEngines/disabledEngines").toStringList();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setSearchEngDisabled(const QStringList &engines)
|
|
|
|
{
|
|
|
|
setValue("SearchEngines/disabledEngines", engines);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QString Preferences::getTorImportLastContentDir() const
|
|
|
|
{
|
|
|
|
return value("TorrentImport/LastContentDir", QDir::homePath()).toString();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setTorImportLastContentDir(const QString &path)
|
|
|
|
{
|
|
|
|
setValue("TorrentImport/LastContentDir", path);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getTorImportGeometry() const
|
|
|
|
{
|
|
|
|
return value("TorrentImportDlg/dimensions").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setTorImportGeometry(const QByteArray &geometry)
|
|
|
|
{
|
|
|
|
setValue("TorrentImportDlg/dimensions", geometry);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-03-28 02:59:20 +03:00
|
|
|
bool Preferences::getStatusFilterState() const
|
|
|
|
{
|
|
|
|
return value("TransferListFilters/statusFilterState", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setStatusFilterState(const bool checked)
|
|
|
|
{
|
|
|
|
setValue("TransferListFilters/statusFilterState", checked);
|
|
|
|
}
|
|
|
|
|
2016-02-09 11:56:48 +03:00
|
|
|
bool Preferences::getCategoryFilterState() const
|
2015-03-28 02:59:20 +03:00
|
|
|
{
|
2016-02-09 11:56:48 +03:00
|
|
|
return value("TransferListFilters/CategoryFilterState", true).toBool();
|
2015-03-28 02:59:20 +03:00
|
|
|
}
|
|
|
|
|
2016-02-09 11:56:48 +03:00
|
|
|
void Preferences::setCategoryFilterState(const bool checked)
|
2015-03-28 02:59:20 +03:00
|
|
|
{
|
2016-02-09 11:56:48 +03:00
|
|
|
setValue("TransferListFilters/CategoryFilterState", checked);
|
2017-06-05 03:22:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Preferences::getTagFilterState() const
|
|
|
|
{
|
|
|
|
return value("TransferListFilters/TagFilterState", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setTagFilterState(const bool checked)
|
|
|
|
{
|
|
|
|
setValue("TransferListFilters/TagFilterState", checked);
|
2015-03-28 02:59:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Preferences::getTrackerFilterState() const
|
|
|
|
{
|
|
|
|
return value("TransferListFilters/trackerFilterState", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setTrackerFilterState(const bool checked)
|
|
|
|
{
|
|
|
|
setValue("TransferListFilters/trackerFilterState", checked);
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
int Preferences::getTransSelFilter() const
|
|
|
|
{
|
|
|
|
return value("TransferListFilters/selectedFilterIndex", 0).toInt();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setTransSelFilter(const int &index)
|
|
|
|
{
|
|
|
|
setValue("TransferListFilters/selectedFilterIndex", index);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
QByteArray Preferences::getTransHeaderState() const
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
return value("TransferList/qt5/HeaderState").toByteArray();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setTransHeaderState(const QByteArray &state)
|
|
|
|
{
|
2015-04-05 20:49:26 +03:00
|
|
|
setValue("TransferList/qt5/HeaderState", state);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2018-08-12 17:46:16 +03:00
|
|
|
bool Preferences::getRegexAsFilteringPatternForTransferList() const
|
2018-07-29 15:46:19 +03:00
|
|
|
{
|
|
|
|
return value("TransferList/UseRegexAsFilteringPattern", false).toBool();
|
|
|
|
}
|
|
|
|
|
2018-08-12 17:46:16 +03:00
|
|
|
void Preferences::setRegexAsFilteringPatternForTransferList(const bool checked)
|
2018-07-29 15:46:19 +03:00
|
|
|
{
|
|
|
|
setValue("TransferList/UseRegexAsFilteringPattern", checked);
|
|
|
|
}
|
|
|
|
|
2017-09-11 21:09:58 +03:00
|
|
|
// From old RssSettings class
|
2017-03-07 16:10:42 +03:00
|
|
|
bool Preferences::isRSSWidgetEnabled() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-03-07 16:10:42 +03:00
|
|
|
return value("GUI/RSSWidget/Enabled", false).toBool();
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2017-03-07 16:10:42 +03:00
|
|
|
void Preferences::setRSSWidgetVisible(const bool enabled)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2017-03-07 16:10:42 +03:00
|
|
|
setValue("GUI/RSSWidget/Enabled", enabled);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
int Preferences::getToolbarTextPosition() const
|
|
|
|
{
|
|
|
|
return value("Toolbar/textPosition", -1).toInt();
|
2014-10-18 18:18:58 +04:00
|
|
|
}
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
void Preferences::setToolbarTextPosition(const int position)
|
|
|
|
{
|
|
|
|
setValue("Toolbar/textPosition", position);
|
2014-10-18 18:18:58 +04:00
|
|
|
}
|
|
|
|
|
2015-12-18 14:30:31 +03:00
|
|
|
QList<QNetworkCookie> Preferences::getNetworkCookies() const
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
|
|
|
QList<QNetworkCookie> cookies;
|
2015-12-18 14:30:31 +03:00
|
|
|
QStringList rawCookies = value("Network/Cookies").toStringList();
|
|
|
|
foreach (const QString &rawCookie, rawCookies)
|
|
|
|
cookies << QNetworkCookie::parseCookies(rawCookie.toUtf8());
|
|
|
|
|
2015-02-23 20:44:29 +03:00
|
|
|
return cookies;
|
|
|
|
}
|
|
|
|
|
2015-12-18 14:30:31 +03:00
|
|
|
void Preferences::setNetworkCookies(const QList<QNetworkCookie> &cookies)
|
2015-02-23 20:44:29 +03:00
|
|
|
{
|
2015-12-18 14:30:31 +03:00
|
|
|
QStringList rawCookies;
|
|
|
|
foreach (const QNetworkCookie &cookie, cookies)
|
|
|
|
rawCookies << cookie.toRawForm();
|
|
|
|
|
|
|
|
setValue("Network/Cookies", rawCookies);
|
2014-06-28 17:50:56 +04:00
|
|
|
}
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2018-09-23 09:20:05 +03:00
|
|
|
bool Preferences::isSpeedWidgetEnabled() const
|
|
|
|
{
|
|
|
|
return value("SpeedWidget/Enabled", true).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setSpeedWidgetEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
setValue("SpeedWidget/Enabled", enabled);
|
|
|
|
}
|
|
|
|
|
2015-12-18 14:30:31 +03:00
|
|
|
int Preferences::getSpeedWidgetPeriod() const
|
|
|
|
{
|
2014-08-25 15:58:48 +04:00
|
|
|
return value("SpeedWidget/period", 1).toInt();
|
|
|
|
}
|
|
|
|
|
2015-12-18 14:30:31 +03:00
|
|
|
void Preferences::setSpeedWidgetPeriod(const int period)
|
|
|
|
{
|
2014-08-25 15:58:48 +04:00
|
|
|
setValue("SpeedWidget/period", period);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Preferences::getSpeedWidgetGraphEnable(int id) const
|
|
|
|
{
|
|
|
|
// UP and DOWN graphs enabled by default
|
|
|
|
return value("SpeedWidget/graph_enable_" + QString::number(id), (id == 0 || id == 1)).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Preferences::setSpeedWidgetGraphEnable(int id, const bool enable)
|
|
|
|
{
|
|
|
|
setValue("SpeedWidget/graph_enable_" + QString::number(id), enable);
|
|
|
|
}
|
|
|
|
|
2016-02-09 11:55:02 +03:00
|
|
|
void Preferences::upgrade()
|
|
|
|
{
|
2018-08-02 22:45:21 +03:00
|
|
|
SettingsStorage *settingsStorage = SettingsStorage::instance();
|
|
|
|
|
2016-02-09 11:56:48 +03:00
|
|
|
QStringList labels = value("TransferListFilters/customLabels").toStringList();
|
|
|
|
if (!labels.isEmpty()) {
|
|
|
|
QVariantMap categories = value("BitTorrent/Session/Categories").toMap();
|
2017-09-11 21:32:11 +03:00
|
|
|
foreach (const QString &label, labels) {
|
2016-02-09 11:56:48 +03:00
|
|
|
if (!categories.contains(label))
|
|
|
|
categories[label] = "";
|
2017-09-11 21:32:11 +03:00
|
|
|
}
|
2016-02-09 11:56:48 +03:00
|
|
|
setValue("BitTorrent/Session/Categories", categories);
|
2018-08-02 22:45:21 +03:00
|
|
|
settingsStorage->removeValue("TransferListFilters/customLabels");
|
2016-02-09 11:56:48 +03:00
|
|
|
}
|
|
|
|
|
2018-08-02 22:45:21 +03:00
|
|
|
settingsStorage->removeValue("Preferences/Downloads/AppendLabel");
|
|
|
|
|
|
|
|
// Inhibit sleep based on running downloads/available seeds rather than network activity.
|
|
|
|
if (value("Preferences/General/PreventFromSuspend", false).toBool()) {
|
|
|
|
setPreventFromSuspendWhenDownloading(true);
|
|
|
|
setPreventFromSuspendWhenSeeding(true);
|
|
|
|
}
|
|
|
|
settingsStorage->removeValue("Preferences/General/PreventFromSuspend");
|
2016-02-09 11:55:02 +03:00
|
|
|
}
|
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
void Preferences::apply()
|
|
|
|
{
|
2016-02-09 11:55:02 +03:00
|
|
|
if (SettingsStorage::instance()->save())
|
2015-04-19 18:17:47 +03:00
|
|
|
emit changed();
|
|
|
|
}
|