Index: sources/storage/Settings.h =================================================================== diff -u -rc9f8f8cf3c6c37fc6460d8675c62c9442c4d4263 -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- sources/storage/Settings.h (.../Settings.h) (revision c9f8f8cf3c6c37fc6460d8675c62c9442c4d4263) +++ sources/storage/Settings.h (.../Settings.h) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -51,7 +51,46 @@ QString content; }; +// TODO make this the SettingsError class +// { Class SettingsError +public: + enum Settings_Error { + eError_None , + eError_POST , + eError_PathEmpty , + eError_MkDir , + eError_Write , + eError_Copy , + eError_Remove , + eError_No_SettingsFolder , + eError_No_SettingsFile , + eError_SettingNotExists , + }; private: + const QHash settingsError_Message { // no translation for the error. My experience shows the error messages if translated is not useful for serviceability and debugging. + { eError_None , "" }, + { eError_POST , "The configuration source check failed." }, + { eError_PathEmpty , "The settings path is empty." }, + { eError_MkDir , "The configuration folder '%1' cannot be created." }, + { eError_Write , "The settings file %1 can't be written." }, + { eError_Copy , "The configuration folder '%1' cannot be copied." }, + { eError_Remove , "The configuration folder '%1' cannot be removed." }, + { eError_No_SettingsFolder , "No settings folder in the %1 path found." }, + { eError_No_SettingsFile , "No settings file in the %1 folder found." }, + { eError_SettingNotExists , "The setting file %1 doesn't exists." }, + }; +public: + const QString errorMessage(int vErr, QString vArg1 = "", QString vArg2 = "") { + if ( settingsError_Message.contains(vErr) ) { + if ( ! vArg1.isEmpty() ) return QString(settingsError_Message[vErr]).arg(vArg1); + if ( ! vArg2.isEmpty() ) return QString(settingsError_Message[vErr]).arg(vArg1).arg(vArg2); + /* default */ return QString(settingsError_Message[vErr]); + } + return "[unknown]"; + } +// } Class SettingsError + +private: const QString makeSetting(const char *vPath, const char *vFile) { QString literal(_settingsFormat); return QString(literal.arg(vPath).arg(vFile).arg(_settingsExt)); @@ -66,9 +105,6 @@ public: Settings() {} - int read(); - int save(const QString &vCategory, const QString &vGroup, const QString &vKey, const QString &vValue); - enum Category_Enum { eInstructions , eConfigurationsDataList , // TODO: the category for this conf is not used. may need to be merged into the Settings, but since it is list, It needs a little more thought. @@ -85,6 +121,16 @@ eKeyCancel , }; + enum Location_Enum { + eInit , + eSecured , + }; + + int read (); + int save (const QString &vCategory, const QString &vGroup, const QString &vKey, const QString &vValue); + int configurationsMove ( QString *vMessage = nullptr); + int configurationsPOST (Location_Enum vLoc = Location_Enum::eSecured) { Q_UNUSED(vLoc); return true; } + static QString category(Category_Enum vCategory) { switch (vCategory) { // NOTE: don't use default case eInstructions : return Storage::Settings_Category_Instructions ; @@ -107,6 +153,14 @@ return ""; } + static QString location(Location_Enum vLoc) { + switch (vLoc) { // NOTE: don't use default + case eInit : return Storage::Settings_Path_Init; + case eSecured : return Storage::Settings_Path_Name; + } + return Storage::Settings_Path_Name; + } + static bool isCategoryInstructions (const QString &vCategory) { return vCategory == category( eInstructions ); } static bool isCategoryConfigurationsDataList (const QString &vCategory) { return vCategory == category( eConfigurationsDataList ); } static bool isCategoryAlarms (const QString &vCategory) { return vCategory == category( eAlarms ); }