cleanup QSettings usage a bit

This commit is contained in:
Nicolas Werner 2021-08-29 14:57:32 +02:00
parent ef068ac2b3
commit 47c7c4c777
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 17 additions and 19 deletions

View file

@ -6,7 +6,6 @@
#include <QApplication> #include <QApplication>
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QSettings>
#include <mtx/responses.hpp> #include <mtx/responses.hpp>
@ -277,15 +276,15 @@ ChatPage::resetUI()
void void
ChatPage::deleteConfigs() ChatPage::deleteConfigs()
{ {
QSettings settings; auto settings = UserSettings::instance()->qsettings();
if (UserSettings::instance()->profile() != "") { if (UserSettings::instance()->profile() != "") {
settings.beginGroup("profile"); settings->beginGroup("profile");
settings.beginGroup(UserSettings::instance()->profile()); settings->beginGroup(UserSettings::instance()->profile());
} }
settings.beginGroup("auth"); settings->beginGroup("auth");
settings.remove(""); settings->remove("");
settings.endGroup(); // auth settings->endGroup(); // auth
http::client()->shutdown(); http::client()->shutdown();
cache::deleteData(); cache::deleteData();

View file

@ -7,7 +7,6 @@
#include <QLayout> #include <QLayout>
#include <QMessageBox> #include <QMessageBox>
#include <QPluginLoader> #include <QPluginLoader>
#include <QSettings>
#include <QShortcut> #include <QShortcut>
#include <mtx/requests.hpp> #include <mtx/requests.hpp>
@ -188,9 +187,10 @@ MainWindow::event(QEvent *event)
void void
MainWindow::restoreWindowSize() MainWindow::restoreWindowSize()
{ {
QSettings settings; int savedWidth = userSettings_->qsettings()->value("window/width").toInt();
int savedWidth = settings.value("window/width").toInt(); int savedheight = userSettings_->qsettings()->value("window/height").toInt();
int savedheight = settings.value("window/height").toInt();
nhlog::ui()->info("Restoring window size {}x{}", savedWidth, savedheight);
if (savedWidth == 0 || savedheight == 0) if (savedWidth == 0 || savedheight == 0)
resize(conf::window::width, conf::window::height); resize(conf::window::width, conf::window::height);
@ -201,11 +201,11 @@ MainWindow::restoreWindowSize()
void void
MainWindow::saveCurrentWindowSize() MainWindow::saveCurrentWindowSize()
{ {
QSettings settings; auto settings = userSettings_->qsettings();
QSize current = size(); QSize current = size();
settings.setValue("window/width", current.width()); settings->setValue("window/width", current.width());
settings.setValue("window/height", current.height()); settings->setValue("window/height", current.height());
} }
void void
@ -301,14 +301,14 @@ MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
bool bool
MainWindow::hasActiveUser() MainWindow::hasActiveUser()
{ {
QSettings settings; auto settings = userSettings_->qsettings();
QString prefix; QString prefix;
if (userSettings_->profile() != "") if (userSettings_->profile() != "")
prefix = "profile/" + userSettings_->profile() + "/"; prefix = "profile/" + userSettings_->profile() + "/";
return settings.contains(prefix + "auth/access_token") && return settings->contains(prefix + "auth/access_token") &&
settings.contains(prefix + "auth/home_server") && settings->contains(prefix + "auth/home_server") &&
settings.contains(prefix + "auth/user_id"); settings->contains(prefix + "auth/user_id");
} }
void void

View file

@ -18,7 +18,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPoint> #include <QPoint>
#include <QScreen> #include <QScreen>
#include <QSettings>
#include <QStandardPaths> #include <QStandardPaths>
#include <QTranslator> #include <QTranslator>