Skip to content

Commit

Permalink
Added feature to load last selected device
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola02nb committed Dec 20, 2024
1 parent c3c1d1e commit 87e78cc
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 101 deletions.
16 changes: 13 additions & 3 deletions src/DataTypes/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Settings loadSettingsFromFile(const QString &filePath)
if (json.contains("styleName")) {
s.styleName = json["styleName"].toString();
}
if (json.contains("lastSelectedVendorID")) {
s.lastSelectedVendorID = json["lastSelectedVendorID"].toString();
}
if (json.contains("lastSelectedProductID")) {
s.lastSelectedProductID = json["lastSelectedProductID"].toString();
}
qDebug() << "Settings Loaded:\t" << json;
qDebug();
}
Expand All @@ -57,16 +63,20 @@ void saveSettingstoFile(const Settings &settings, const QString &filePath)
json["batteryLowThreshold"] = settings.batteryLowThreshold;
json["msecUpdateIntervalTime"] = settings.msecUpdateIntervalTime;
json["styleName"] = settings.styleName;
json["lastSelectedVendorID"] = settings.lastSelectedVendorID;
json["lastSelectedProductID"] = settings.lastSelectedProductID;

QJsonDocument doc(json);
QFile file(filePath);

qDebug() << "Saving settings:";
qDebug() << "Destination:\t" << filePath;
if (!file.open(QIODevice::WriteOnly)) {
qWarning("Couldn't open save file.");
qWarning("Error:\tCouldn't open save file.");
}

file.write(doc.toJson());
file.close();
qDebug() << "Settings Saved:\t" << json;

//qDebug() << "Content:\t" << json;
qDebug();
}
11 changes: 7 additions & 4 deletions src/DataTypes/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

#include <QApplication>
#include <QCoreApplication>
#include <QDir>
#include <QStandardPaths>
#include <QString>

#ifdef QT_DEBUG
const QString PROGRAM_CONFIG_PATH = "./DEBUG-Config";
#else
const QString PROGRAM_CONFIG_PATH = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
+ "/HeadsetControl-GUI";
+ QDir::separator() + "HeadsetControl-GUI";
#endif
const QString PROGRAM_STYLES_PATH = PROGRAM_CONFIG_PATH + "/styles";
const QString PROGRAM_SETTINGS_FILEPATH = PROGRAM_CONFIG_PATH + "/settings.json";
const QString DEVICES_SETTINGS_FILEPATH = PROGRAM_CONFIG_PATH + "/devices.json";
const QString PROGRAM_STYLES_PATH = PROGRAM_CONFIG_PATH + QDir::separator() + "styles";
const QString PROGRAM_SETTINGS_FILEPATH = PROGRAM_CONFIG_PATH + QDir::separator() + "settings.json";
const QString DEVICES_SETTINGS_FILEPATH = PROGRAM_CONFIG_PATH + QDir::separator() + "devices.json";

class Settings
{
Expand All @@ -31,6 +32,8 @@ class Settings
int msecUpdateIntervalTime = 30000;

QString styleName = "Default";

QString lastSelectedVendorID = "", lastSelectedProductID = "";
};

Settings loadSettingsFromFile(const QString &filePath);
Expand Down
Loading

0 comments on commit 87e78cc

Please sign in to comment.