mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-24 09:54:16 +08:00
refs #198 , added utility methods for read/write settings
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include "settingutilities.h"
|
#include "settingutilities.h"
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -29,6 +31,24 @@ namespace BlackMisc
|
|||||||
return rps;
|
return rps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Value not changed
|
||||||
|
*/
|
||||||
|
CStatusMessage CSettingUtilities::valueNotChangedMessage(const QString &valueName)
|
||||||
|
{
|
||||||
|
return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityWarning,
|
||||||
|
QString("Value %1 not changed").arg(valueName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Value changed
|
||||||
|
*/
|
||||||
|
CStatusMessage CSettingUtilities::valueChangedMessage(const QString &valueName)
|
||||||
|
{
|
||||||
|
return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityInfo,
|
||||||
|
QString("Value %1 changed").arg(valueName));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leading path
|
* leading path
|
||||||
*/
|
*/
|
||||||
@@ -52,5 +72,34 @@ namespace BlackMisc
|
|||||||
p.append('/').append(part3);
|
p.append('/').append(part3);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Init settings dir, if required create it
|
||||||
|
*/
|
||||||
|
bool CSettingUtilities::initSettingsDirectory()
|
||||||
|
{
|
||||||
|
QDir dir(CSettingUtilities::getSettingsDirectory());
|
||||||
|
if (dir.exists()) return true;
|
||||||
|
return dir.mkpath(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Directory
|
||||||
|
*/
|
||||||
|
const QString &CSettingUtilities::getSettingsDirectory()
|
||||||
|
{
|
||||||
|
static QString dir = QStandardPaths::writableLocation(QStandardPaths::DataLocation).append("/BlackBox");
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* File
|
||||||
|
*/
|
||||||
|
const QString &CSettingUtilities::getSettingsFile()
|
||||||
|
{
|
||||||
|
static QString file(QString(CSettingUtilities::getSettingsDirectory()).append("/settings.json"));
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,12 +49,27 @@ namespace BlackMisc
|
|||||||
//! \brief Wrong path messages
|
//! \brief Wrong path messages
|
||||||
static BlackMisc::CStatusMessageList wrongPathMessages(const QString &path = "");
|
static BlackMisc::CStatusMessageList wrongPathMessages(const QString &path = "");
|
||||||
|
|
||||||
|
//! \brief Value not changed message
|
||||||
|
static BlackMisc::CStatusMessage valueNotChangedMessage(const QString &valueName);
|
||||||
|
|
||||||
|
//! \brief Value changed message
|
||||||
|
static BlackMisc::CStatusMessage valueChangedMessage(const QString &valueName);
|
||||||
|
|
||||||
//! \brief Remove leading path
|
//! \brief Remove leading path
|
||||||
static QString removeLeadingPath(const QString &path);
|
static QString removeLeadingPath(const QString &path);
|
||||||
|
|
||||||
//! \brief Append setting paths
|
//! \brief Append setting paths
|
||||||
static QString appendPaths(const QString &part1, const QString &part2, const QString &part3 = "");
|
static QString appendPaths(const QString &part1, const QString &part2, const QString &part3 = "");
|
||||||
|
|
||||||
|
//! \brief prepare the settings directory, if required create it
|
||||||
|
static bool initSettingsDirectory();
|
||||||
|
|
||||||
|
//! \brief get the settings directory
|
||||||
|
static const QString &getSettingsDirectory();
|
||||||
|
|
||||||
|
//! \brief get the settings directory
|
||||||
|
static const QString &getSettingsFile();
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user