add function to get cache file path

This commit is contained in:
Jussi Kuokkanen 2023-11-22 15:41:29 +02:00
parent 2ff1873de9
commit b922186489
3 changed files with 11 additions and 4 deletions

View File

@ -129,8 +129,7 @@ QMenu *MainWindow::createTrayMenu() {
}
void MainWindow::restoreGeometryFromCache(QWidget *widget) {
auto cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
auto cacheFilePath = QString("%1/tuxclocker.conf").arg(cacheDir);
auto cacheFilePath = Utils::cacheFilePath();
QSettings settings{cacheFilePath, QSettings::NativeFormat};
widget->restoreGeometry(settings.value("geometry").toByteArray());
@ -138,8 +137,7 @@ void MainWindow::restoreGeometryFromCache(QWidget *widget) {
void MainWindow::closeEvent(QCloseEvent *event) {
// Save window geometry to user cache dir (XDG_CACHE_HOME on Linux)
auto cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
auto cacheFilePath = QString("%1/tuxclocker.conf").arg(cacheDir);
auto cacheFilePath = Utils::cacheFilePath();
QSettings settings{cacheFilePath, QSettings::NativeFormat};
settings.setValue("geometry", saveGeometry());

View File

@ -7,6 +7,7 @@
#include <functional>
#include <QDebug>
#include <QSettings>
#include <QStandardPaths>
#include <Settings.hpp>
namespace Utils {
@ -139,4 +140,9 @@ void writeAssignableSetting(SettingsData data, AssignableSetting setting) {
settings.setValue(toSettingsPath(setting.assignablePath), setting.value);
}
QString cacheFilePath() {
auto cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
return QString("%1/tuxclocker.conf").arg(cacheDir);
}
} // namespace Utils

View File

@ -11,6 +11,9 @@ using ModelTraverseCallback =
std::function<std::optional<QModelIndex>(QAbstractItemModel *, const QModelIndex &, int)>;
using NodePath = QString;
// File path to save non-setting persistent data, eg. window geometry
QString cacheFilePath();
// Conversion for saving in settings
NodePath fromSettingsPath(QString);
QString toSettingsPath(NodePath);