mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 12:59:56 -07:00
Add support for different configurations. Partially closes #465
It may be useful to have different configurations either for portable versions or for debugging purposes. To implement this we add two options, avaliable via command line switches 1. An option to change configuration name ("--configuration"). The name supplied via this option is appended to QCoreApplication::applicationName() to form "qBittorrent_<conf_name>" name for the configuration files. 2. An option to provide a path do directory where all the settings are stored (kind of profile directory). There is a shortcut "--portable" which means "use directory 'profile' near the executable location". In order to implement that we have to perform initialisation of the profile directories before the SettingStorage and Preferences singletones are initialised. Thus, options parsing shall be performed without defaults read from preferences.
This commit is contained in:
parent
6ad8a4d8b1
commit
0f746ffd5a
20 changed files with 901 additions and 398 deletions
|
@ -33,9 +33,9 @@
|
|||
#include <QFile>
|
||||
#include <QHash>
|
||||
#include <QStringList>
|
||||
#include <QSettings>
|
||||
|
||||
#include "logger.h"
|
||||
#include "profile.h"
|
||||
#include "utils/fs.h"
|
||||
|
||||
namespace
|
||||
|
@ -62,16 +62,6 @@ namespace
|
|||
QString deserialize(const QString &name, QVariantHash &data);
|
||||
QString serialize(const QString &name, const QVariantHash &data);
|
||||
|
||||
using SettingsPtr = std::unique_ptr<QSettings>;
|
||||
SettingsPtr createSettings(const QString &name)
|
||||
{
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||
return SettingsPtr(new QSettings(QSettings::IniFormat, QSettings::UserScope, "qBittorrent", name));
|
||||
#else
|
||||
return SettingsPtr(new QSettings("qBittorrent", name));
|
||||
#endif
|
||||
}
|
||||
|
||||
QString m_name;
|
||||
};
|
||||
|
||||
|
@ -290,7 +280,7 @@ bool TransactionalSettings::write(const QVariantHash &data)
|
|||
|
||||
QString TransactionalSettings::deserialize(const QString &name, QVariantHash &data)
|
||||
{
|
||||
SettingsPtr settings = createSettings(name);
|
||||
SettingsPtr settings = Profile::instance().applicationSettings(name);
|
||||
|
||||
if (settings->allKeys().isEmpty())
|
||||
return QString();
|
||||
|
@ -306,7 +296,7 @@ QString TransactionalSettings::deserialize(const QString &name, QVariantHash &da
|
|||
|
||||
QString TransactionalSettings::serialize(const QString &name, const QVariantHash &data)
|
||||
{
|
||||
SettingsPtr settings = createSettings(name);
|
||||
SettingsPtr settings = Profile::instance().applicationSettings(name);
|
||||
for (auto i = data.begin(); i != data.end(); ++i)
|
||||
settings->setValue(i.key(), i.value());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue