diff --git a/GUI/Application/Application.cpp b/GUI/Application/Application.cpp index 641e3bf81888b52af2bf54d08feb7e8ea1b6eece..f2c991480084a03177226d550e546ac0d4ecd4b9 100644 --- a/GUI/Application/Application.cpp +++ b/GUI/Application/Application.cpp @@ -17,6 +17,7 @@ #include "GUI/utils/hostosinfo.h" #include <QFile> #include <QIcon> +#include <QStandardPaths> Application::Application(int& argc, char** argv) : QApplication(argc, argv), m_currentStyle(ApplicationSettings::Style::native) @@ -100,3 +101,13 @@ InstrumentLibrary& Application::instrumentLibrary() { return m_instrumentLibrary; } + +QString Application::instrumentLibraryFilePath() const +{ + return appDataFolder() + "/BornAgainInstrumentLibrary.balib"; +} + +QString Application::appDataFolder() const +{ + return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); +} diff --git a/GUI/Application/Application.h b/GUI/Application/Application.h index 940bb7237ba1b2a93280c43d6c7a16d9cbbeb7b8..88a9dc864d070ee8fa885ca4c3559ced0b76f5b7 100644 --- a/GUI/Application/Application.h +++ b/GUI/Application/Application.h @@ -40,6 +40,13 @@ public: InstrumentLibrary& instrumentLibrary(); + QString instrumentLibraryFilePath() const; + + //! The folder where persistent application data shall be stored. E.g. in Windows this is the + //! AppData/Roaming location. + //! Used e.g. for storing the instrument library. + QString appDataFolder() const; + private: ApplicationSettings m_settings; InstrumentLibrary m_instrumentLibrary; diff --git a/GUI/main/main.cpp b/GUI/main/main.cpp index 50fca7a3ab9984dac194d9f7c8179ac12409395f..65e261079bfe061556630ead0fd36c9fdee2914d 100644 --- a/GUI/main/main.cpp +++ b/GUI/main/main.cpp @@ -20,7 +20,6 @@ #include <QDir> #include <QLocale> #include <QMetaType> -#include <QStandardPaths> void messageHandler(QtMsgType, const QMessageLogContext&, const QString&) {} @@ -44,15 +43,10 @@ int main(int argc, char* argv[]) app.loadStyle(app.settings().styleToUse()); - const QString folderForInstrumentLibrary = - QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); - const QString filePathForInstrumentLibrary = - folderForInstrumentLibrary + "/BornAgainInstrumentLibrary.balib"; + if (!QDir().exists(app.appDataFolder())) + QDir().mkpath(app.appDataFolder()); - if (!QDir().exists(folderForInstrumentLibrary)) - QDir().mkpath(folderForInstrumentLibrary); - - app.instrumentLibrary().load(filePathForInstrumentLibrary); + app.instrumentLibrary().load(app.instrumentLibraryFilePath()); MainWindow win; if (options.find("geometry")) @@ -62,7 +56,7 @@ int main(int argc, char* argv[]) int ret = QApplication::exec(); - app.instrumentLibrary().saveIfModified(filePathForInstrumentLibrary); + app.instrumentLibrary().saveIfModified(app.instrumentLibraryFilePath()); return ret; }