jsonserializable.cpp \
libHPCS/libhpcs.c \
gui/failedfilesdialog.cpp \
- helpers.cpp
+ helpers.cpp \
+ usersettings.cpp
HEADERS += \
datafilesloader.h \
jsonserializable.h \
helpers.h \
libHPCS/libhpcs.h \
- gui/failedfilesdialog.h
+ gui/failedfilesdialog.h \
+ usersettings.h
FORMS += \
gui/mainwindow.ui \
const int GlobalInfo::APP_VERSION_MAJ(0);
const int GlobalInfo::APP_VERSION_MIN(3);
const QString GlobalInfo::APP_VERSION_REV("e");
+const QString GlobalInfo::APP_NAME("Anyanka");
+const QString GlobalInfo::ORG_NAME("devoid-pointer.net");
static const int APP_VERSION_MAJ;
static const int APP_VERSION_MIN;
static const QString APP_VERSION_REV;
+ static const QString APP_NAME;
+ static const QString ORG_NAME;
};
#endif // GLOBALINFO_H
#include "gui/mainwindow.h"
#include "ui_mainwindow.h"
+#include "usersettings.h"
#include <QVBoxLayout>
#include <QDebug>
m_loadDataFileDialog = new QFileDialog(this);
m_loadDataFileDialog->setFileMode(QFileDialog::Directory);
- m_loadDataFileDialog->setOptions(QFileDialog::ReadOnly);
+ m_loadDataFileDialog->setOptions(QFileDialog::ReadOnly | QFileDialog::DontUseNativeDialog);
}
/* Public methods */
void MainWindow::onLoadSequence()
{
+ QVariant path = UserSettings::get("last_sequence_directory");
+ if (path.isValid())
+ m_loadDataFileDialog->setDirectory(path.toString());
m_loadDataFileDialog->setWindowTitle("Load sequence");
- if (m_loadDataFileDialog->exec() == QDialog::Accepted)
+ if (m_loadDataFileDialog->exec() == QDialog::Accepted) {
emit loadSequence(m_loadDataFileDialog->selectedFiles()[0]);
+ UserSettings::set("last_sequence_directory", QVariant(m_loadDataFileDialog->directory().absolutePath()));
+ }
}
void MainWindow::onLoadSingleRun()
{
+ QVariant path = UserSettings::get("last_singlerun_directory");
+ if (path.isValid())
+ m_loadDataFileDialog->setDirectory(path.toString());
m_loadDataFileDialog->setWindowTitle("Load single run");
if (m_loadDataFileDialog->exec() == QDialog::Accepted) {
qDebug() << "Chosen file" << m_loadDataFileDialog->selectedFiles();
emit loadSingleRun(m_loadDataFileDialog->selectedFiles()[0]);
+ UserSettings::set("last_singlerun_directory", QVariant(m_loadDataFileDialog->directory().absolutePath()));
}
}
#include "gui/mainwindow.h"
#include "datamanager.h"
#include "logger.h"
+#include "usersettings.h"
#include <QApplication>
#include <QtWidgets/QMessageBox>
{
int ret;
QApplication a(argc, argv);
+ a.setApplicationName(GlobalInfo::APP_NAME);
+ a.setOrganizationName(GlobalInfo::ORG_NAME);
+ UserSettings::initialize();
#ifndef _MSC_VER
#warning Revisit the metatype shared_ptr<SignalView> registration
ret = a.exec();
dMgr->saveUserDataOnExit();
+ UserSettings::dispose();
return ret;
}
--- /dev/null
+#include "globalinfo.h"
+#include "logger.h"
+#include "usersettings.h"
+
+UserSettings* UserSettings::s_me = nullptr;
+const QStringList UserSettings::KNOWN_KEYS = QStringList() << "last_sequence_directory" /* Directory from which the last sequence was loaded */
+ << "last_singlerun_directory"; /* Directory from which the last single run was loaded */
+void UserSettings::dispose()
+{
+ delete s_me;
+ s_me = nullptr;
+}
+
+QVariant UserSettings::get(const QString key)
+{
+ if (s_me == nullptr) {
+ Logger::log(Logger::Level::ERROR, "UserSettings", __QFUNC__ + "UserSettings not initialized");
+ return QVariant();
+ }
+
+ std::lock_guard<std::mutex> lk(s_me->m_lock);
+ QVariant v = s_me->m_settings[key.toLower()];
+ Logger::log(Logger::Level::DEBUG, "UserSettings ", __QFUNC__ + QString("Key: %1, Value: %2").arg(key).arg(v.toString()));
+ return v;
+}
+
+void UserSettings::initialize()
+{
+ if (s_me == nullptr)
+ s_me = new UserSettings;
+}
+
+void UserSettings::set(const QString key, const QVariant value)
+{
+ if (s_me == nullptr) {
+ Logger::log(Logger::Level::ERROR, "UserSettings", __QFUNC__ + "UserSettings not initialized");
+ return;
+ }
+
+ QString lkey = key.toLower();
+ std::lock_guard<std::mutex> lk(s_me->m_lock);
+ if (!KNOWN_KEYS.contains(lkey))
+ return;
+
+ QVariant svalue;
+ if (value.type() == QVariant::String) {
+ QString s = value.toString();
+ s.replace("\\", "\\\\"); /* Propery escape backslashes in Windows paths */
+ svalue = QVariant(s);
+ } else
+ svalue = value;
+
+ s_me->m_settings[lkey] = svalue;
+}
+
+UserSettings::UserSettings()
+{
+ QSettings* settings = openSettingsFile();
+
+ for (const QString& k : KNOWN_KEYS) {
+ QVariant v = settings->value(k);
+ m_settings.insert(k, v);
+ }
+
+ delete settings;
+}
+
+QSettings* UserSettings::openSettingsFile()
+{
+ return new QSettings(QSettings::IniFormat, QSettings::UserScope, GlobalInfo::ORG_NAME, GlobalInfo::APP_NAME);
+}
+
+UserSettings::~UserSettings()
+{
+ QSettings* settings = openSettingsFile();
+
+ for (const QString& k : KNOWN_KEYS) {
+ QVariant v = m_settings[k];
+ settings->setValue(k, v);
+ }
+ settings->sync();
+
+ delete settings;
+}
--- /dev/null
+#ifndef USERSETTINGS_H
+#define USERSETTINGS_H
+
+#include <mutex>
+#include <QMap>
+#include <QSettings>
+#include <QVariant>
+
+class UserSettings
+{
+public:
+ static void dispose();
+ static QVariant get(const QString key);
+ static void initialize();
+ static void set(const QString key, const QVariant value);
+ ~UserSettings();
+
+private:
+ UserSettings();
+ QSettings* openSettingsFile();
+
+ QMap<QString, QVariant> m_settings;
+ std::mutex m_lock;
+
+
+ static UserSettings* s_me;
+ static const QStringList KNOWN_KEYS;
+};
+
+#endif // USERSETTINGS_H