Factor settings into new Settings class
parent
c5df09494f
commit
97a1d13ad9
|
@ -40,6 +40,7 @@
|
|||
#include "Kaidan.h"
|
||||
#include "MessageModel.h"
|
||||
#include "RosterModel.h"
|
||||
#include "Settings.h"
|
||||
#include "VCardCache.h"
|
||||
|
||||
AccountManager *AccountManager::s_instance = nullptr;
|
||||
|
@ -49,9 +50,10 @@ AccountManager *AccountManager::instance()
|
|||
return s_instance;
|
||||
}
|
||||
|
||||
AccountManager::AccountManager(QSettings *settings, VCardCache *cache, QObject *parent)
|
||||
AccountManager::AccountManager(Settings *settings, VCardCache *cache, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_settings(settings)
|
||||
m_settings(settings),
|
||||
m_port(NON_CUSTOM_PORT)
|
||||
{
|
||||
Q_ASSERT(!s_instance);
|
||||
s_instance = this;
|
||||
|
@ -192,16 +194,15 @@ bool AccountManager::loadCredentials()
|
|||
{
|
||||
if (!hasEnoughCredentialsForLogin()) {
|
||||
// Load the credentials from the settings file.
|
||||
setJid(m_settings->value(KAIDAN_SETTINGS_AUTH_JID).toString());
|
||||
setPassword(QByteArray::fromBase64(m_settings->value(KAIDAN_SETTINGS_AUTH_PASSWD).toString().toUtf8()));
|
||||
setJid(m_settings->authJid());
|
||||
setPassword(m_settings->authPassword());
|
||||
|
||||
// Use a default prefix for the JID's resource part if no prefix is already set.
|
||||
setJidResourcePrefix(m_settings->value(KAIDAN_SETTINGS_AUTH_JID_RESOURCE_PREFIX,
|
||||
KAIDAN_JID_RESOURCE_DEFAULT_PREFIX).toString());
|
||||
setJidResourcePrefix(m_settings->authJidResourcePrefix());
|
||||
|
||||
// Load the custom connection setings.
|
||||
setHost(m_settings->value(KAIDAN_SETTINGS_AUTH_HOST).toString());
|
||||
setPort(m_settings->value(KAIDAN_SETTINGS_AUTH_PORT, NON_CUSTOM_PORT).toInt());
|
||||
setHost(m_settings->authHost());
|
||||
setPort(m_settings->authPort());
|
||||
|
||||
// This method is only used to load old credentials. Therefore,
|
||||
// "m_hasNewCredentials" which was set to "true" by setting the credentials in this
|
||||
|
@ -219,25 +220,25 @@ bool AccountManager::loadCredentials()
|
|||
|
||||
void AccountManager::storeJid()
|
||||
{
|
||||
m_settings->setValue(KAIDAN_SETTINGS_AUTH_JID, jid());
|
||||
m_settings->setAuthJid(jid());
|
||||
}
|
||||
|
||||
void AccountManager::storePassword()
|
||||
{
|
||||
m_settings->setValue(KAIDAN_SETTINGS_AUTH_PASSWD, QString::fromUtf8(password().toUtf8().toBase64()));
|
||||
m_settings->setAuthPassword(password());
|
||||
}
|
||||
|
||||
void AccountManager::storeCustomConnectionSettings()
|
||||
{
|
||||
if (m_host.isEmpty())
|
||||
m_settings->remove(KAIDAN_SETTINGS_AUTH_HOST);
|
||||
m_settings->resetAuthHost();
|
||||
else
|
||||
m_settings->setValue(KAIDAN_SETTINGS_AUTH_HOST, m_host);
|
||||
m_settings->setAuthHost(m_host);
|
||||
|
||||
if (m_port == NON_CUSTOM_PORT)
|
||||
m_settings->remove(KAIDAN_SETTINGS_AUTH_PORT);
|
||||
if (m_settings->isDefaultAuthPort())
|
||||
m_settings->resetAuthPort();
|
||||
else
|
||||
m_settings->setValue(KAIDAN_SETTINGS_AUTH_PORT, m_port);
|
||||
m_settings->setAuthPort(m_port);
|
||||
}
|
||||
|
||||
void AccountManager::storeCredentials()
|
||||
|
@ -249,7 +250,7 @@ void AccountManager::storeCredentials()
|
|||
|
||||
void AccountManager::deleteCredentials()
|
||||
{
|
||||
deleteSettingsInSettingsFile({
|
||||
m_settings->remove({
|
||||
KAIDAN_SETTINGS_AUTH_JID,
|
||||
KAIDAN_SETTINGS_AUTH_JID_RESOURCE_PREFIX,
|
||||
KAIDAN_SETTINGS_AUTH_PASSWD,
|
||||
|
@ -269,7 +270,7 @@ void AccountManager::deleteCredentials()
|
|||
|
||||
void AccountManager::deleteSettings()
|
||||
{
|
||||
deleteSettingsInSettingsFile({
|
||||
m_settings->remove({
|
||||
KAIDAN_SETTINGS_AUTH_ONLINE,
|
||||
KAIDAN_SETTINGS_NOTIFICATIONS_MUTED,
|
||||
KAIDAN_SETTINGS_FAVORITE_EMOJIS
|
||||
|
@ -285,12 +286,6 @@ void AccountManager::removeAccount(const QString &accountJid)
|
|||
emit RosterModel::instance()->removeItemsRequested(accountJid);
|
||||
}
|
||||
|
||||
void AccountManager::deleteSettingsInSettingsFile(const QStringList &keys) const
|
||||
{
|
||||
for (const QString &key : keys)
|
||||
m_settings->remove(key);
|
||||
}
|
||||
|
||||
QString AccountManager::generateJidResourceWithRandomSuffix(unsigned int numberOfRandomSuffixCharacters) const
|
||||
{
|
||||
return m_jidResourcePrefix % "." % QXmppUtils::generateStanzaHash(numberOfRandomSuffixCharacters);
|
||||
|
|
|
@ -34,11 +34,9 @@
|
|||
#include <QMutex>
|
||||
#include <QObject>
|
||||
|
||||
class QSettings;
|
||||
class Settings;
|
||||
class VCardCache;
|
||||
|
||||
constexpr quint16 NON_CUSTOM_PORT = 0;
|
||||
|
||||
/**
|
||||
* This class manages account-related settings.
|
||||
*/
|
||||
|
@ -56,7 +54,7 @@ class AccountManager : public QObject
|
|||
public:
|
||||
static AccountManager *instance();
|
||||
|
||||
AccountManager(QSettings *settings, VCardCache *cache, QObject *parent = nullptr);
|
||||
AccountManager(Settings *settings, VCardCache *cache, QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* Returns the bare JID of the account.
|
||||
|
@ -226,7 +224,7 @@ public:
|
|||
*
|
||||
* Settings stored in the settings file are also removed from it.
|
||||
*/
|
||||
void deleteSettings();
|
||||
void deleteSettings();
|
||||
|
||||
/**
|
||||
* Removes an account.
|
||||
|
@ -274,13 +272,6 @@ signals:
|
|||
void removeAccountRequested(const QString &accountJid);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Deletes settings in the settings / configuration file.
|
||||
*
|
||||
* @param keys keys of the settings being deleted
|
||||
*/
|
||||
void deleteSettingsInSettingsFile(const QStringList &keys) const;
|
||||
|
||||
/**
|
||||
* Generates the JID's resource part with the set JID resource prefix and a suffix
|
||||
* consisting of a dot followed by random alphanumeric characters.
|
||||
|
@ -291,14 +282,14 @@ private:
|
|||
QString generateJidResourceWithRandomSuffix(unsigned int numberOfRandomSuffixCharacters = 4) const;
|
||||
|
||||
QMutex m_mutex;
|
||||
QSettings *m_settings;
|
||||
Settings *m_settings;
|
||||
|
||||
QString m_jid;
|
||||
QString m_jidResourcePrefix;
|
||||
QString m_jidResource;
|
||||
QString m_password;
|
||||
QString m_host;
|
||||
quint16 m_port = NON_CUSTOM_PORT;
|
||||
quint16 m_port;
|
||||
|
||||
bool m_hasNewCredentials;
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ set(KAIDAN_SOURCES
|
|||
src/RegistrationDataFormModel.cpp
|
||||
src/ServerListModel.cpp
|
||||
src/ServerListItem.cpp
|
||||
src/Settings.cpp
|
||||
src/AccountManager.cpp
|
||||
src/VCardCache.cpp
|
||||
|
||||
|
|
|
@ -57,9 +57,10 @@
|
|||
#include "VCardCache.h"
|
||||
#include "VCardManager.h"
|
||||
#include "VersionManager.h"
|
||||
#include "Settings.h"
|
||||
|
||||
ClientWorker::Caches::Caches(QObject *parent)
|
||||
: settings(new QSettings(APPLICATION_NAME, APPLICATION_NAME)),
|
||||
: settings(new Settings(parent)),
|
||||
vCardCache(new VCardCache(parent)),
|
||||
accountManager(new AccountManager(settings, vCardCache, parent)),
|
||||
msgModel(new MessageModel(parent)),
|
||||
|
@ -74,7 +75,6 @@ ClientWorker::Caches::Caches(QObject *parent)
|
|||
|
||||
ClientWorker::Caches::~Caches()
|
||||
{
|
||||
delete settings;
|
||||
}
|
||||
|
||||
ClientWorker::ClientWorker(Caches *caches, bool enableLogging, QObject* parent)
|
||||
|
@ -83,7 +83,7 @@ ClientWorker::ClientWorker(Caches *caches, bool enableLogging, QObject* parent)
|
|||
m_client(new QXmppClient(this)),
|
||||
m_logger(new LogHandler(m_client, enableLogging, this)),
|
||||
m_enableLogging(enableLogging),
|
||||
m_registrationManager(new RegistrationManager(this, m_client, m_caches->settings, this)),
|
||||
m_registrationManager(new RegistrationManager(this, m_client, this)),
|
||||
m_vCardManager(new VCardManager(this, m_client, m_caches->avatarStorage, this)),
|
||||
m_rosterManager(new RosterManager(m_client, m_caches->avatarStorage, m_vCardManager, this)),
|
||||
m_messageHandler(new MessageHandler(this, m_client, this)),
|
||||
|
@ -148,9 +148,9 @@ void ClientWorker::finishTask()
|
|||
|
||||
void ClientWorker::logIn()
|
||||
{
|
||||
if (!m_isFirstLoginAfterStart || m_caches->settings->value(KAIDAN_SETTINGS_AUTH_ONLINE, true).toBool()) {
|
||||
if (!m_isFirstLoginAfterStart || m_caches->settings->authOnline()) {
|
||||
// Store the latest online state which is restored when opening Kaidan again after closing.
|
||||
m_caches->settings->setValue(KAIDAN_SETTINGS_AUTH_ONLINE, true);
|
||||
m_caches->settings->setAuthOnline(true);
|
||||
|
||||
QXmppConfiguration config;
|
||||
config.setResource(AccountManager::instance()->jidResource());
|
||||
|
@ -218,7 +218,7 @@ void ClientWorker::logOut(bool isApplicationBeingClosed)
|
|||
{
|
||||
// Store the latest online state which is restored when opening Kaidan again after closing.
|
||||
if (!isApplicationBeingClosed)
|
||||
m_caches->settings->setValue(KAIDAN_SETTINGS_AUTH_ONLINE, false);
|
||||
m_caches->settings->setAuthOnline(false);
|
||||
|
||||
switch (m_client->state()) {
|
||||
case QXmppClient::DisconnectedState:
|
||||
|
|
|
@ -53,7 +53,7 @@ class UploadManager;
|
|||
class VCardCache;
|
||||
class VCardManager;
|
||||
class VersionManager;
|
||||
class QSettings;
|
||||
class Settings;
|
||||
|
||||
/**
|
||||
* The ClientWorker is used as a QObject-based worker on the ClientThread.
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
Caches(QObject *parent = nullptr);
|
||||
~Caches();
|
||||
|
||||
QSettings *settings;
|
||||
Settings *settings;
|
||||
VCardCache *vCardCache;
|
||||
AccountManager *accountManager;
|
||||
MessageModel *msgModel;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "EmojiModel.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include "Settings.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Kaidan.h"
|
||||
|
@ -1501,8 +1501,8 @@ QHash<int, QByteArray> EmojiModel::roleNames() const
|
|||
EmojiProxyModel::EmojiProxyModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
QSettings *settings = Kaidan::instance()->settings();
|
||||
QStringList list = settings->value(QLatin1String(KAIDAN_SETTINGS_FAVORITE_EMOJIS)).toStringList();
|
||||
Settings *settings = Kaidan::instance()->settings();
|
||||
const QStringList list = settings->favoriteEmojis();
|
||||
m_favoriteEmojis = QSet<QString>(list.begin(), list.end());
|
||||
}
|
||||
|
||||
|
@ -1559,8 +1559,8 @@ void EmojiProxyModel::addFavoriteEmoji(int proxyRow)
|
|||
invalidateFilter();
|
||||
}
|
||||
|
||||
QSettings *settings = Kaidan::instance()->settings();
|
||||
settings->setValue(QLatin1String(KAIDAN_SETTINGS_FAVORITE_EMOJIS), QStringList(m_favoriteEmojis.values()));
|
||||
Settings *settings = Kaidan::instance()->settings();
|
||||
settings->setFavoriteEmojis(m_favoriteEmojis.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "MessageDb.h"
|
||||
#include "Notifications.h"
|
||||
#include "RosterDb.h"
|
||||
#include "Settings.h"
|
||||
|
||||
Kaidan *Kaidan::s_instance;
|
||||
|
||||
|
@ -74,12 +75,12 @@ Kaidan::~Kaidan()
|
|||
|
||||
QSize Kaidan::applicationWindowSize() const
|
||||
{
|
||||
return m_caches->settings->value(KAIDAN_SETTINGS_WINDOW_SIZE).toSize();
|
||||
return m_caches->settings->windowSize();
|
||||
}
|
||||
|
||||
void Kaidan::storeApplicationWindowSize(const QSize &size) const
|
||||
{
|
||||
m_caches->settings->setValue(KAIDAN_SETTINGS_WINDOW_SIZE, size);
|
||||
m_caches->settings->setWindowSize(size);
|
||||
}
|
||||
|
||||
void Kaidan::logIn()
|
||||
|
@ -138,26 +139,24 @@ void Kaidan::setConnectionError(ClientWorker::ConnectionError error)
|
|||
|
||||
bool Kaidan::notificationsMuted(const QString &jid)
|
||||
{
|
||||
return m_caches->settings->value(QString(KAIDAN_SETTINGS_NOTIFICATIONS_MUTED) + jid, false).toBool();
|
||||
return m_caches->settings->notificationsMuted(jid);
|
||||
}
|
||||
|
||||
void Kaidan::setNotificationsMuted(const QString &jid, bool muted)
|
||||
{
|
||||
m_caches->settings->setValue(QString(KAIDAN_SETTINGS_NOTIFICATIONS_MUTED) + jid, muted);
|
||||
m_caches->settings->setNotificationsMuted(jid, muted);
|
||||
emit notificationsMutedChanged(jid);
|
||||
}
|
||||
|
||||
void Kaidan::setPasswordVisibility(PasswordVisibility passwordVisibility)
|
||||
{
|
||||
m_caches->settings->setValue(KAIDAN_SETTINGS_AUTH_PASSWD_VISIBILITY, quint8(passwordVisibility));
|
||||
m_caches->settings->setAuthPasswordVisibility(passwordVisibility);
|
||||
emit passwordVisibilityChanged();
|
||||
}
|
||||
|
||||
Kaidan::PasswordVisibility Kaidan::passwordVisibility() const
|
||||
{
|
||||
return m_caches->settings
|
||||
->value(KAIDAN_SETTINGS_AUTH_PASSWD_VISIBILITY, PasswordVisible)
|
||||
.value<Kaidan::PasswordVisibility>();
|
||||
return m_caches->settings->authPasswordVisibility();
|
||||
}
|
||||
|
||||
quint8 Kaidan::connectionError() const
|
||||
|
|
|
@ -60,7 +60,6 @@ class Kaidan : public QObject
|
|||
Q_PROPERTY(PresenceCache* presenceCache READ presenceCache CONSTANT)
|
||||
Q_PROPERTY(TransferCache* transferCache READ transferCache CONSTANT)
|
||||
Q_PROPERTY(ServerFeaturesCache* serverFeaturesCache READ serverFeaturesCache CONSTANT)
|
||||
Q_PROPERTY(QSettings* settings READ settings CONSTANT)
|
||||
Q_PROPERTY(quint8 connectionState READ connectionState NOTIFY connectionStateChanged)
|
||||
Q_PROPERTY(QString connectionStateText READ connectionStateText NOTIFY connectionStateChanged)
|
||||
Q_PROPERTY(quint8 connectionError READ connectionError NOTIFY connectionErrorChanged)
|
||||
|
@ -178,7 +177,7 @@ public:
|
|||
return m_caches->vCardCache;
|
||||
}
|
||||
|
||||
QSettings* settings() const
|
||||
Settings *settings() const
|
||||
{
|
||||
return m_caches->settings;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include <QFile>
|
||||
#include <QSettings>
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
/*
|
||||
* NOTES: Codecs and containers supported list are available as soon as the object is created.
|
||||
* Resolutions, frame rates etc are populated once the objects become *ready*.
|
||||
|
@ -774,7 +776,7 @@ void MediaRecorder::saveUserSettings()
|
|||
Q_UNREACHABLE();
|
||||
break;
|
||||
case MediaRecorder::Type::Image: {
|
||||
QSettings &settings(*Kaidan::instance()->settings());
|
||||
QSettings &settings(Kaidan::instance()->settings()->raw());
|
||||
|
||||
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
|
||||
settings.setValue(SETTING_DEFAULT_CAMERA_DEVICE_NAME, m_mediaSettings.camera.deviceName());
|
||||
|
@ -789,7 +791,7 @@ void MediaRecorder::saveUserSettings()
|
|||
break;
|
||||
}
|
||||
case MediaRecorder::Type::Audio: {
|
||||
QSettings &settings(*Kaidan::instance()->settings());
|
||||
QSettings &settings(Kaidan::instance()->settings()->raw());
|
||||
|
||||
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
|
||||
settings.setValue(SETTING_DEFAULT_AUDIO_INPUT_DEVICE_NAME, m_mediaSettings.audioInputDevice.deviceName());
|
||||
|
@ -802,7 +804,7 @@ void MediaRecorder::saveUserSettings()
|
|||
break;
|
||||
}
|
||||
case MediaRecorder::Type::Video: {
|
||||
QSettings &settings(*Kaidan::instance()->settings());
|
||||
QSettings &settings(Kaidan::instance()->settings()->raw());
|
||||
|
||||
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
|
||||
settings.setValue(SETTING_DEFAULT_CAMERA_DEVICE_NAME, m_mediaSettings.camera.deviceName());
|
||||
|
@ -931,7 +933,7 @@ CameraInfo MediaRecorder::userDefaultCamera() const
|
|||
return CameraInfo();
|
||||
}
|
||||
|
||||
QSettings &settings(*Kaidan::instance()->settings());
|
||||
QSettings &settings(Kaidan::instance()->settings()->raw());
|
||||
CameraInfo cameraInfo = m_cameraModel->defaultCamera();
|
||||
|
||||
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
|
||||
|
@ -955,7 +957,7 @@ AudioDeviceInfo MediaRecorder::userDefaultAudioInput() const
|
|||
return AudioDeviceInfo();
|
||||
}
|
||||
|
||||
QSettings &settings(*Kaidan::instance()->settings());
|
||||
QSettings &settings(Kaidan::instance()->settings()->raw());
|
||||
AudioDeviceInfo audioInput = m_audioDeviceModel->defaultAudioInputDevice();
|
||||
|
||||
settings.beginGroup(settingsKey(m_type, SETTING_USER_DEFAULT));
|
||||
|
@ -987,7 +989,7 @@ void MediaRecorder::resetSettings(const CameraInfo &camera, const AudioDeviceInf
|
|||
m_videoEncoderSettings = VideoEncoderSettings();
|
||||
break;
|
||||
case MediaRecorder::Type::Image: {
|
||||
QSettings &settings(*Kaidan::instance()->settings());
|
||||
QSettings &settings(Kaidan::instance()->settings()->raw());
|
||||
MediaSettings mediaSettings(camera, AudioDeviceInfo());
|
||||
ImageEncoderSettings imageSettings;
|
||||
|
||||
|
@ -1001,7 +1003,7 @@ void MediaRecorder::resetSettings(const CameraInfo &camera, const AudioDeviceInf
|
|||
break;
|
||||
}
|
||||
case MediaRecorder::Type::Audio: {
|
||||
QSettings &settings(*Kaidan::instance()->settings());
|
||||
QSettings &settings(Kaidan::instance()->settings()->raw());
|
||||
MediaSettings mediaSettings(CameraInfo(), audioInput);
|
||||
AudioEncoderSettings audioSettings;
|
||||
|
||||
|
@ -1015,7 +1017,7 @@ void MediaRecorder::resetSettings(const CameraInfo &camera, const AudioDeviceInf
|
|||
break;
|
||||
}
|
||||
case MediaRecorder::Type::Video: {
|
||||
QSettings &settings(*Kaidan::instance()->settings());
|
||||
QSettings &settings(Kaidan::instance()->settings()->raw());
|
||||
MediaSettings mediaSettings(camera, AudioDeviceInfo());
|
||||
AudioEncoderSettings audioSettings;
|
||||
VideoEncoderSettings videoSettings;
|
||||
|
|
|
@ -42,11 +42,10 @@
|
|||
#include "RegistrationDataFormModel.h"
|
||||
#include "ServerFeaturesCache.h"
|
||||
|
||||
RegistrationManager::RegistrationManager(ClientWorker *clientWorker, QXmppClient *client, QSettings *settings, QObject *parent)
|
||||
RegistrationManager::RegistrationManager(ClientWorker *clientWorker, QXmppClient *client, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_clientWorker(clientWorker),
|
||||
m_client(client),
|
||||
m_settings(settings),
|
||||
m_manager(new QXmppRegistrationManager),
|
||||
m_dataFormModel(new RegistrationDataFormModel())
|
||||
{
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
class ClientWorker;
|
||||
class RegistrationDataFormModel;
|
||||
class DataFormModel;
|
||||
class QSettings;
|
||||
class QXmppRegistrationManager;
|
||||
class QXmppClient;
|
||||
class QXmppDataForm;
|
||||
|
@ -63,7 +62,7 @@ public:
|
|||
};
|
||||
Q_ENUM(RegistrationError)
|
||||
|
||||
RegistrationManager(ClientWorker *clientWorker, QXmppClient *client, QSettings *settings, QObject *parent = nullptr);
|
||||
RegistrationManager(ClientWorker *clientWorker, QXmppClient *client, QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* Sets whether a registration is requested for the next time when the client connects to the server.
|
||||
|
@ -168,7 +167,6 @@ private:
|
|||
|
||||
ClientWorker *m_clientWorker;
|
||||
QXmppClient *m_client;
|
||||
QSettings *m_settings;
|
||||
QXmppRegistrationManager *m_manager;
|
||||
RegistrationDataFormModel *m_dataFormModel;
|
||||
QVector<QXmppBitsOfBinaryContentId> m_contentIdsToRemove;
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* Kaidan - A user-friendly XMPP client for every device!
|
||||
*
|
||||
* Copyright (C) 2016-2021 Kaidan developers and contributors
|
||||
* (see the LICENSE file for a full list of copyright authors)
|
||||
*
|
||||
* Kaidan 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* In addition, as a special exception, the author of Kaidan gives
|
||||
* permission to link the code of its release 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 this file, you may extend this exception to your version of
|
||||
* the file, but you are not obligated to do so. If you do not wish to
|
||||
* do so, delete this exception statement from your version.
|
||||
*
|
||||
* Kaidan 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 Kaidan. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
Settings::Settings(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_settings(QStringLiteral(APPLICATION_NAME), QStringLiteral(APPLICATION_NAME))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QSettings &Settings::raw()
|
||||
{
|
||||
return m_settings;
|
||||
}
|
||||
|
||||
bool Settings::authOnline() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_AUTH_ONLINE), true).toBool();
|
||||
}
|
||||
|
||||
void Settings::setAuthOnline(bool online)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_AUTH_ONLINE), online);
|
||||
emit authOnlineChanged();
|
||||
}
|
||||
|
||||
QString Settings::authJid() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_AUTH_JID)).toString();
|
||||
}
|
||||
|
||||
void Settings::setAuthJid(const QString &jid)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_AUTH_JID), jid);
|
||||
emit authJidChanged();
|
||||
}
|
||||
|
||||
QString Settings::authJidResourcePrefix() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_AUTH_JID_RESOURCE_PREFIX), KAIDAN_JID_RESOURCE_DEFAULT_PREFIX).toString();
|
||||
}
|
||||
|
||||
void Settings::setAuthJidResourcePrefix(const QString &prefix)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_AUTH_JID_RESOURCE_PREFIX), prefix);
|
||||
emit authJidResourcePrefixChanged();
|
||||
}
|
||||
|
||||
QString Settings::authPassword() const
|
||||
{
|
||||
return QByteArray::fromBase64(m_settings.value(QStringLiteral(KAIDAN_SETTINGS_AUTH_PASSWD)).toString().toUtf8());
|
||||
}
|
||||
|
||||
void Settings::setAuthPassword(const QString &password)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_AUTH_PASSWD), QString::fromUtf8(password.toUtf8().toBase64()));
|
||||
emit authPasswordChanged();
|
||||
}
|
||||
|
||||
QString Settings::authHost() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_AUTH_HOST)).toString();
|
||||
}
|
||||
|
||||
void Settings::setAuthHost(const QString &host)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_AUTH_HOST), host);
|
||||
emit authHostChanged();
|
||||
}
|
||||
|
||||
void Settings::resetAuthHost()
|
||||
{
|
||||
m_settings.remove(QStringLiteral(KAIDAN_SETTINGS_AUTH_PORT));
|
||||
}
|
||||
|
||||
quint16 Settings::authPort() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_AUTH_PORT), NON_CUSTOM_PORT).value<quint16>();
|
||||
}
|
||||
|
||||
void Settings::setAuthPort(quint16 port)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_AUTH_PORT), port);
|
||||
emit authPortChanged();
|
||||
}
|
||||
|
||||
void Settings::resetAuthPort()
|
||||
{
|
||||
m_settings.remove(QStringLiteral(KAIDAN_SETTINGS_AUTH_PORT));
|
||||
}
|
||||
|
||||
bool Settings::isDefaultAuthPort()
|
||||
{
|
||||
return authPort() == NON_CUSTOM_PORT;
|
||||
}
|
||||
|
||||
Kaidan::PasswordVisibility Settings::authPasswordVisibility() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_AUTH_PASSWD_VISIBILITY), Kaidan::PasswordVisible).value<Kaidan::PasswordVisibility>();
|
||||
}
|
||||
|
||||
void Settings::setAuthPasswordVisibility(Kaidan::PasswordVisibility visibility)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_AUTH_PASSWD_VISIBILITY), visibility);
|
||||
emit authPasswordVisibilityChanged();
|
||||
}
|
||||
|
||||
bool Settings::notificationsMuted(const QString &bareJid) const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_NOTIFICATIONS_MUTED) + bareJid, false).toBool();
|
||||
}
|
||||
|
||||
void Settings::setNotificationsMuted(const QString &bareJid, bool muted)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_NOTIFICATIONS_MUTED) + bareJid, muted);
|
||||
emit notificationsMutedChanged(bareJid);
|
||||
}
|
||||
|
||||
QStringList Settings::favoriteEmojis() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_FAVORITE_EMOJIS)).toStringList();
|
||||
}
|
||||
|
||||
void Settings::setFavoriteEmojis(const QStringList &emoji)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_FAVORITE_EMOJIS), emoji);
|
||||
emit favoriteEmojisChanged();
|
||||
}
|
||||
|
||||
QSize Settings::windowSize() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral(KAIDAN_SETTINGS_WINDOW_SIZE)).toSize();
|
||||
}
|
||||
|
||||
void Settings::setWindowSize(const QSize size)
|
||||
{
|
||||
m_settings.setValue(QStringLiteral(KAIDAN_SETTINGS_WINDOW_SIZE), size);
|
||||
emit windowSizeChanged();
|
||||
}
|
||||
|
||||
void Settings::remove(const QStringList &keys)
|
||||
{
|
||||
for (const QString &key : keys)
|
||||
m_settings.remove(key);
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Kaidan - A user-friendly XMPP client for every device!
|
||||
*
|
||||
* Copyright (C) 2016-2021 Kaidan developers and contributors
|
||||
* (see the LICENSE file for a full list of copyright authors)
|
||||
*
|
||||
* Kaidan 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* In addition, as a special exception, the author of Kaidan gives
|
||||
* permission to link the code of its release 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 this file, you may extend this exception to your version of
|
||||
* the file, but you are not obligated to do so. If you do not wish to
|
||||
* do so, delete this exception statement from your version.
|
||||
*
|
||||
* Kaidan 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 Kaidan. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QSize>
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Kaidan.h"
|
||||
|
||||
constexpr quint16 NON_CUSTOM_PORT = 0;
|
||||
|
||||
class Settings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Settings(QObject *parent = nullptr);
|
||||
|
||||
///
|
||||
/// Avoid using this in favour of adding methods here,
|
||||
/// but it is useful if you need to manually manage config groups
|
||||
///
|
||||
QSettings &raw();
|
||||
|
||||
bool authOnline() const;
|
||||
void setAuthOnline(bool online);
|
||||
|
||||
QString authJid() const;
|
||||
void setAuthJid(const QString &jid);
|
||||
|
||||
QString authJidResourcePrefix() const;
|
||||
void setAuthJidResourcePrefix(const QString &prefix);
|
||||
|
||||
QString authPassword() const;
|
||||
void setAuthPassword(const QString &password);
|
||||
|
||||
QString authHost() const;
|
||||
void setAuthHost(const QString &host);
|
||||
void resetAuthHost();
|
||||
|
||||
quint16 authPort() const;
|
||||
void setAuthPort(quint16 port);
|
||||
void resetAuthPort();
|
||||
bool isDefaultAuthPort();
|
||||
|
||||
Kaidan::PasswordVisibility authPasswordVisibility() const;
|
||||
void setAuthPasswordVisibility(Kaidan::PasswordVisibility visibility);
|
||||
|
||||
bool notificationsMuted(const QString &bareJid) const;
|
||||
void setNotificationsMuted(const QString &bareJid, bool muted);
|
||||
|
||||
QStringList favoriteEmojis() const;
|
||||
void setFavoriteEmojis(const QStringList &emoji);
|
||||
|
||||
QSize windowSize() const;
|
||||
void setWindowSize(const QSize size);
|
||||
|
||||
void remove(const QStringList &keys);
|
||||
|
||||
signals:
|
||||
void authOnlineChanged();
|
||||
void authJidChanged();
|
||||
void authJidResourcePrefixChanged();
|
||||
void authPasswordChanged();
|
||||
void authHostChanged();
|
||||
void authPortChanged();
|
||||
void authPasswordVisibilityChanged();
|
||||
void notificationsMutedChanged(const QString &bareJid);
|
||||
void favoriteEmojisChanged();
|
||||
void windowSizeChanged();
|
||||
|
||||
private:
|
||||
QSettings m_settings;
|
||||
};
|
||||
|
||||
#endif // SETTINGS_H
|
Loading…
Reference in New Issue