Skip to content

Commit 66b7cb5

Browse files
committed
Save window geometry into correct file
�# Please enter the commit message for your changes. Lines starting
1 parent 486d501 commit 66b7cb5

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/MainWindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ MainWindow::MainWindow(bool statupInTray,
107107
this->setWindowIcon(QIcon::fromTheme("jamesdsp", QIcon(":/icons/icon.png")));
108108

109109
// Restore window size and position
110-
const QByteArray geometry = QSettings().value("geometry", QByteArray()).toByteArray();
110+
const QByteArray geometry = AppConfig::instance().get<QByteArray>(AppConfig::LastWindowGeometry);
111111
if (!geometry.isEmpty())
112112
{
113113
restoreGeometry(geometry);
@@ -422,7 +422,7 @@ MainWindow::~MainWindow()
422422
// Overrides
423423
void MainWindow::closeEvent(QCloseEvent *event)
424424
{
425-
QSettings().setValue("geometry", saveGeometry());
425+
AppConfig::instance().setBytes(AppConfig::LastWindowGeometry, saveGeometry());
426426
saveGraphicEQView();
427427

428428
#ifdef Q_OS_OSX
@@ -444,7 +444,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
444444
void MainWindow::resizeEvent(QResizeEvent *event)
445445
{
446446
QMainWindow::resizeEvent(event);
447-
QSettings().setValue("geometry", saveGeometry());
447+
AppConfig::instance().setBytes(AppConfig::LastWindowGeometry, saveGeometry());
448448
}
449449

450450

src/config/AppConfig.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ AppConfig::AppConfig()
2727
DEFINE_KEY(SetupDone, false);
2828
DEFINE_KEY(ExecutablePath, "");
2929
DEFINE_KEY(VdcLastDatabaseId, -1);
30+
DEFINE_KEY(LastWindowGeometry, QByteArray());
3031

3132
DEFINE_KEY(AudioOutputUseDefault, true);
3233
DEFINE_KEY(AudioOutputDevice, "");
@@ -46,6 +47,11 @@ AppConfig::AppConfig()
4647
load();
4748
}
4849

50+
void AppConfig::setBytes(const Key &key, const QByteArray &value)
51+
{
52+
set(key, QVariant(QString::fromLocal8Bit(value.toBase64())));
53+
}
54+
4955
void AppConfig::set(const Key &key, const QStringList &value)
5056
{
5157
set(key, value.join(';'));

src/config/AppConfig.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <QObject>
2323
#include <QMetaEnum>
24+
#include <optional>
2425

2526
using namespace std;
2627

@@ -57,6 +58,7 @@ class AppConfig :
5758
SetupDone,
5859
ExecutablePath,
5960
VdcLastDatabaseId,
61+
LastWindowGeometry,
6062

6163
AudioOutputUseDefault,
6264
AudioOutputDevice,
@@ -73,6 +75,9 @@ class AppConfig :
7375
};
7476
Q_ENUM(Key);
7577

78+
void setBytes(const Key &key,
79+
const QByteArray &value);
80+
7681
void set(const Key &key,
7782
const QStringList &value);
7883

@@ -84,6 +89,9 @@ class AppConfig :
8489
if constexpr (std::is_same_v<T, QVariant>) {
8590
return variant;
8691
}
92+
if constexpr (std::is_same_v<T, QByteArray>) {
93+
return QByteArray::fromBase64(variant.toString().toLocal8Bit());
94+
}
8795
if constexpr (std::is_same_v<T, std::string>) {
8896
return variant.toString().toStdString();
8997
}
@@ -113,11 +121,9 @@ class AppConfig :
113121
auto skey = QVariant::fromValue(key).toString();
114122
auto variant = _appconf->getVariant(skey, true, &exists);
115123

116-
QVariant defaultValue = definitions[key];
117-
118-
if(!exists)
124+
if(!exists && definitions.contains(key))
119125
{
120-
return convertVariant<T>(defaultValue);
126+
return convertVariant<T>(definitions[key]);
121127
}
122128

123129
return convertVariant<T>(variant);

0 commit comments

Comments
 (0)