/*! * * Copyright (c) 2021-2022 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file Settings.h * \author (last) Behrouz NematiPour * \date (last) 05-Apr-2022 * \author (original) Behrouz NematiPour * \date (original) 29-Mar-2021 * */ #pragma once // Qt #include #include #include // Project #include "main.h" // Doxygen : do not remove #include "StorageGlobals.h" #include "Threads.h" // forward declarations class tst_initializations; namespace Storage { // TODO - IMPORTANT: this MVC needs to change to configurations in oppose to Settings. // It named settings because it suppose to be like QSettings, // but since we have settings it is mixing up with that and is very confusing. // FIXME- IMPORTANT: This set of Settings (MVC) design is not correct: // - the data structure should change in Model from column based (keys, values) to tree/map based // - the singleton should be the controller not the Model, to protect the model usage, and avoid the shared memory issues. // - the model class should be private class, or an object defined in this class, not a global class. class Settings { // Settings const char *_settingsExt = "conf"; const char *_settingsFormat = "%1/%2.%3"; struct Detail { QString category; QString location; QString content; }; private: const QString makeSetting(const char *vPath, const char *vFile) { QString literal(_settingsFormat); return QString(literal.arg(vPath).arg(vFile).arg(_settingsExt)); } bool isValid(const QString &vSettingFile); QString fileName(const QString &vCategory); void update(); public: Settings() {} int read(); int save(const QString &vCategory, const QString &vGroup, const QString &vKey, const QString &vValue); }; }