diff options
Diffstat (limited to 'src/main_window.cpp')
-rw-r--r-- | src/main_window.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main_window.cpp b/src/main_window.cpp index 5c0c401..4feb240 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -21,8 +21,9 @@ std::optional<std::string> getEnvVar(const char* envVar); void getEnvVar(const std::string envVar, std::string& envValue, const char* backup); GetEnvResult getEnvironment(); -GetsuyomiApp::GetsuyomiApp() : m_getsuyomi{new Getsuyomi()}, m_qtSettings{new QSettings(AppVendor, AppName)} +GetsuyomiApp::GetsuyomiApp() : m_getsuyomi{new Getsuyomi()} { + readSettings(); } FudStatus GetsuyomiApp::setup() @@ -46,8 +47,6 @@ FudStatus GetsuyomiApp::setup() constexpr int minimumHeight = 480; setMinimumSize(minimumWidth, minimumHeight); - readSettings(); - show(); return FudStatus::Success; @@ -124,6 +123,7 @@ void GetsuyomiApp::openFile() } filename = filenames[0]; m_lastOpenedDirectory = dialog.directory().absolutePath(); + qDebug("Last opened directory is %s", qPrintable(m_lastOpenedDirectory)); } else { qWarning("File dialog did not execute"); return; @@ -186,22 +186,28 @@ void GetsuyomiApp::back() void GetsuyomiApp::closeEvent(QCloseEvent* event) { + writeSettings(); QMainWindow::closeEvent(event); } void GetsuyomiApp::readSettings() { - restoreGeometry(m_qtSettings->value("geometry").toByteArray()); - restoreState(m_qtSettings->value("windowState").toByteArray()); - m_lastOpenedDirectory = m_qtSettings->value("lastOpenedDirectory", QDir::homePath()).toString(); + + QSettings settings{AppVendor, AppName}; + restoreGeometry(settings.value("geometry").toByteArray()); + restoreState(settings.value("windowState").toByteArray()); + m_lastOpenedDirectory = settings.value("lastOpenedDirectory", QDir::homePath()).toString(); qDebug("ReadSettings - last directory is %s", qPrintable(m_lastOpenedDirectory)); } void GetsuyomiApp::writeSettings() { - m_qtSettings->setValue("geometry", saveGeometry()); - m_qtSettings->setValue("windowState", saveState()); - m_qtSettings->setValue("lastOpenedDirectory", m_lastOpenedDirectory); + QSettings settings{AppVendor, AppName}; + settings.setValue("geometry", saveGeometry()); + settings.setValue("windowState", saveState()); + settings.setValue("lastOpenedDirectory", m_lastOpenedDirectory); + settings.sync(); + qDebug() << "Called writeSettings, last dir is " << settings.value("lastOpenedDirectory"); } std::optional<std::string> getEnvVar(const char* envVar) |