|
|
|
@ -1,6 +1,104 @@ |
|
|
|
|
#include "ConfigMgr.h" |
|
|
|
|
#include "config.h" |
|
|
|
|
#include <QHashIterator> |
|
|
|
|
#include <unordered_map> |
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
using DefaultMap = std::unordered_map<std::string,std::string>; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Default settings in case it is not found in the config file. |
|
|
|
|
* scripts and prefix-colors have no default settings. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN32) | defined(Q_OS_WIN64) |
|
|
|
|
constexpr auto DefaultFontName = "Fixedsys"; |
|
|
|
|
#else |
|
|
|
|
constexpr auto DefaultFontName = "Monospace"; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
const DefaultMap defaultGeometry { |
|
|
|
|
{ "X", "-1" }, |
|
|
|
|
{ "Y", "-1" }, |
|
|
|
|
{ "Width", "1024" }, |
|
|
|
|
{ "Height", "768" }, |
|
|
|
|
{ "Maximized", "0" } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const DefaultMap defaultConnection { |
|
|
|
|
{ "SSL", "0" } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const DefaultMap defaultCommon { |
|
|
|
|
{ "ShowOptions", "1" }, |
|
|
|
|
{ "Reconnect", "0" }, |
|
|
|
|
{ "RejoinChannelsOnConnect", "0" }, |
|
|
|
|
{ "ShowWhoisActiveWindow", "1" }, |
|
|
|
|
{ "ShowModeInMessage", "1" }, |
|
|
|
|
{ "TrayNotify", "1" }, |
|
|
|
|
{ "TrayNotifyDelay", "5" }, |
|
|
|
|
{ "ShowTimestamp", "1" }, |
|
|
|
|
{ "TimestampFormat", "[HH:mm]" }, |
|
|
|
|
{ "ManualKeepaliveEnabled", "0" }, |
|
|
|
|
{ "ManualKeepalive", "10" }, |
|
|
|
|
{ "Font", DefaultFontName }, |
|
|
|
|
{ "FontSize", "12" }, |
|
|
|
|
{ "BgImageEnabled", "0" }, |
|
|
|
|
{ "BgImageOpacity", "100" }, |
|
|
|
|
{ "SSLSelfsigned", "0" }, |
|
|
|
|
{ "SSLCNMismatch", "0" }, |
|
|
|
|
{ "ButtonBarPosition", "N" } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const DefaultMap defaultColor { |
|
|
|
|
{ "Action", "#840084" }, |
|
|
|
|
{ "CTCP", "#FF0000" }, |
|
|
|
|
{ "Highlight", "#848400" }, |
|
|
|
|
{ "Invite", "#008400" }, |
|
|
|
|
{ "Join", "#008400" }, |
|
|
|
|
{ "Kick", "#008400" }, |
|
|
|
|
{ "Mode", "#008400" }, |
|
|
|
|
{ "Nick", "#008400" }, |
|
|
|
|
{ "Normal", "#000000" }, |
|
|
|
|
{ "Notice", "#840000" }, |
|
|
|
|
{ "OwnText", "#008484" }, |
|
|
|
|
{ "Part", "#008400" }, |
|
|
|
|
{ "ProgramInfo", "#000084" }, |
|
|
|
|
{ "Quit", "#000084" }, |
|
|
|
|
{ "ServerInfo", "#008400" }, |
|
|
|
|
{ "Topic", "#008400" }, |
|
|
|
|
{ "Wallops", "#FF0000" }, |
|
|
|
|
{ "TextviewBackground", "#FFFFFF" }, |
|
|
|
|
{ "InputBackground", "#FFFFFF" }, |
|
|
|
|
{ "InputForeground", "#000000" }, |
|
|
|
|
{ "ListboxBackground", "#FFFFFF" }, |
|
|
|
|
{ "ListboxForeground", "#000000" }, |
|
|
|
|
{ "Links", "#0000FF" }, |
|
|
|
|
{ "WindowButtonNormal", "#000000" }, |
|
|
|
|
{ "WindowButtonActivity", "#000088" }, |
|
|
|
|
{ "WindowButtonMessage", "#0000FF" }, |
|
|
|
|
{ "WindowButtonAttention", "#FF0000" } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const DefaultMap defaultLogging { |
|
|
|
|
{ "Channels", "0" }, |
|
|
|
|
{ "Privates", "0" }, |
|
|
|
|
{ "Path", "Path" } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const std::string& getDefault(const DefaultMap& map, const std::string& key) |
|
|
|
|
{ |
|
|
|
|
static const std::string empty; |
|
|
|
|
try { |
|
|
|
|
return map.at(key); |
|
|
|
|
} |
|
|
|
|
catch (const std::out_of_range&) { |
|
|
|
|
return empty; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConfigMgr& ConfigMgr::instance() |
|
|
|
|
{ |
|
|
|
@ -10,293 +108,168 @@ ConfigMgr& ConfigMgr::instance() |
|
|
|
|
|
|
|
|
|
// Constructor is private, use static instance()
|
|
|
|
|
ConfigMgr::ConfigMgr() |
|
|
|
|
{ |
|
|
|
|
load(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::load() |
|
|
|
|
{ |
|
|
|
|
IniFile ini(LOCAL_PATH+"/iirc.ini"); |
|
|
|
|
loadGeometry(ini); |
|
|
|
|
loadConnection(ini); |
|
|
|
|
loadCommon(ini); |
|
|
|
|
loadColor(ini); |
|
|
|
|
loadPrefixColor(ini); |
|
|
|
|
loadLogging(ini); |
|
|
|
|
loadScripts(ini); |
|
|
|
|
} |
|
|
|
|
: ini( QString(LOCAL_PATH+"/iirc.ini").toStdString() ) |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::save() |
|
|
|
|
{ |
|
|
|
|
IniFile ini(LOCAL_PATH+"/iirc.ini"); |
|
|
|
|
saveGeometry(ini); |
|
|
|
|
saveConnection(ini); |
|
|
|
|
saveCommon(ini); |
|
|
|
|
saveColor(ini); |
|
|
|
|
savePrefixColor(ini); |
|
|
|
|
saveLogging(ini); |
|
|
|
|
saveScripts(ini); |
|
|
|
|
ini.flush(); |
|
|
|
|
emit saved(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString ConfigMgr::geometry(const QString& key) const |
|
|
|
|
{ |
|
|
|
|
return geometryData.value(key, ""); |
|
|
|
|
const auto keystdstr = key.toStdString(); |
|
|
|
|
const auto& defaultValue = getDefault(defaultGeometry, keystdstr); |
|
|
|
|
return QString::fromStdString( ini.read("Geometry", keystdstr, defaultValue) ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString ConfigMgr::connection(const QString& key) const |
|
|
|
|
{ |
|
|
|
|
return connectionData.value(key, ""); |
|
|
|
|
const auto keystdstr = key.toStdString(); |
|
|
|
|
const auto& defaultValue = getDefault(defaultConnection, keystdstr); |
|
|
|
|
return QString::fromStdString( ini.read("Connection", keystdstr, defaultValue) ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString ConfigMgr::common(const QString& key) const |
|
|
|
|
{ |
|
|
|
|
return commonData.value(key, ""); |
|
|
|
|
const auto keystdstr = key.toStdString(); |
|
|
|
|
const auto& defaultValue = getDefault(defaultCommon, keystdstr); |
|
|
|
|
return QString::fromStdString( ini.read("Common", keystdstr, defaultValue) ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString ConfigMgr::color(const QString& key) const |
|
|
|
|
{ |
|
|
|
|
return colorData.value(key, ""); |
|
|
|
|
const auto keystdstr = key.toStdString(); |
|
|
|
|
const auto& defaultValue = getDefault(defaultColor, keystdstr); |
|
|
|
|
return QString::fromStdString( ini.read("Color", keystdstr, defaultValue) ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::optional<QColor> ConfigMgr::prefixColor(const QChar prefix) const |
|
|
|
|
std::optional<QColor> ConfigMgr::prefixColor(const QChar& prefix) const |
|
|
|
|
{ |
|
|
|
|
for (const auto& pair : prefixColorData) |
|
|
|
|
if (pair.first == prefix) |
|
|
|
|
return std::make_optional(pair.second); |
|
|
|
|
return std::nullopt; |
|
|
|
|
const std::string key = std::to_string(prefix.toLatin1()); |
|
|
|
|
if (!ini.exist("PrefixColor", key)) |
|
|
|
|
return {}; |
|
|
|
|
|
|
|
|
|
const auto colorStr = QString::fromStdString( ini.read("PrefixColor", key) ); |
|
|
|
|
return QColor(colorStr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QHash<QString, QString> ConfigMgr::color() const |
|
|
|
|
{ |
|
|
|
|
return colorData; |
|
|
|
|
QHash<QString, QString> ret; |
|
|
|
|
const int sectSize = ini.count("Color"); |
|
|
|
|
for (int i = 0; i < sectSize; ++i) { |
|
|
|
|
const auto key = QString::fromStdString( ini.item("Color", i) ); |
|
|
|
|
const auto val = QString::fromStdString( ini.read("Color", i) ); |
|
|
|
|
ret.insert(key, val); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QVector<std::pair<QChar, QColor> > ConfigMgr::prefixColor() const |
|
|
|
|
{ |
|
|
|
|
return prefixColorData; |
|
|
|
|
QVector<std::pair<QChar, QColor>> ret; |
|
|
|
|
const int sectSize = ini.count("PrefixColor"); |
|
|
|
|
for (int i = 0; i < sectSize; ++i) { |
|
|
|
|
const auto code = ini.item("PrefixColor", i); |
|
|
|
|
const auto first = std::stoi(code); |
|
|
|
|
const auto second = QString::fromStdString( ini.read("PrefixColor", i) ); |
|
|
|
|
ret.push_back( std::make_pair(first, second) ); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString ConfigMgr::logging(const QString& key) const |
|
|
|
|
{ |
|
|
|
|
return loggingData.value(key, ""); |
|
|
|
|
const auto keystdstr = key.toStdString(); |
|
|
|
|
const auto& defaultValue = getDefault(defaultLogging, keystdstr); |
|
|
|
|
return QString::fromStdString( ini.read("Logging", keystdstr, defaultValue) ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const QStringList& ConfigMgr::scripts() const |
|
|
|
|
QStringList ConfigMgr::scripts() const |
|
|
|
|
{ |
|
|
|
|
return scriptsData; |
|
|
|
|
QStringList ret; |
|
|
|
|
const int sectSize = ini.count("Scripts"); |
|
|
|
|
for (int i = 0; i < sectSize; ++i) { |
|
|
|
|
const auto path = ini.read("Scripts", i); |
|
|
|
|
ret.push_back( QString::fromStdString(path) ); |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::setGeometry(const QString& key, const QString& value) |
|
|
|
|
{ |
|
|
|
|
if (geometryData.contains(key)) |
|
|
|
|
geometryData.insert(key, value); |
|
|
|
|
ini.write("Geometry", key.toStdString(), value.toStdString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::setConnection(const QString& key, const QString& value) |
|
|
|
|
{ |
|
|
|
|
if (connectionData.contains(key)) |
|
|
|
|
connectionData.insert(key, value); |
|
|
|
|
ini.write("Connection", key.toStdString(), value.toStdString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::setCommon(const QString& key, const QString& value) |
|
|
|
|
{ |
|
|
|
|
if (commonData.contains(key)) |
|
|
|
|
commonData.insert(key, value); |
|
|
|
|
ini.write("Common", key.toStdString(), value.toStdString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::setLogging(const QString& key, const QString& value) |
|
|
|
|
{ |
|
|
|
|
if (loggingData.contains(key)) |
|
|
|
|
loggingData.insert(key, value); |
|
|
|
|
ini.write("Logging", key.toStdString(), value.toStdString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::setColorPalette(const QHash<QString, QString>& palette) |
|
|
|
|
{ |
|
|
|
|
colorData = palette; |
|
|
|
|
QHashIterator<QString,QString> it(palette); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
it.next(); |
|
|
|
|
const auto& key = it.key(); |
|
|
|
|
const auto& val = it.value(); |
|
|
|
|
ini.write("Color", key.toStdString(), val.toStdString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::setPrefixColorPalette(const QVector<std::pair<QChar, QColor>>& palette) |
|
|
|
|
{ |
|
|
|
|
prefixColorData = palette; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::addScript(const QString& path) |
|
|
|
|
{ |
|
|
|
|
scriptsData << path; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::delScript(const QString& path) |
|
|
|
|
{ |
|
|
|
|
scriptsData.removeAll(path); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::loadGeometry(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
geometryData.insert("X", ini.value("Geometry", "X", "-1")); |
|
|
|
|
geometryData.insert("Y", ini.value("Geometry", "Y", "-1")); |
|
|
|
|
geometryData.insert("Width", ini.value("Geometry", "Width", "1000")); |
|
|
|
|
geometryData.insert("Height", ini.value("Geometry", "Height", "768")); |
|
|
|
|
geometryData.insert("Maximized", ini.value("Geometry", "Maximized", "0")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::loadConnection(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
connectionData.insert("Realname", ini.value("Connection", "Realname")); |
|
|
|
|
connectionData.insert("Username", ini.value("Connection", "Username")); |
|
|
|
|
connectionData.insert("Nickname", ini.value("Connection", "Nickname")); |
|
|
|
|
connectionData.insert("AltNickname", ini.value("Connection", "AltNickname")); |
|
|
|
|
connectionData.insert("Server", ini.value("Connection", "Server")); |
|
|
|
|
connectionData.insert("Password", ini.value("Connection", "Password")); |
|
|
|
|
connectionData.insert("SSL", ini.value("Connection", "SSL", "0")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::loadCommon(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
#if defined(Q_OS_WIN32) | defined(Q_OS_WIN64) |
|
|
|
|
QString defaultFontName = "Fixedsys"; |
|
|
|
|
#else |
|
|
|
|
QString defaultFontName = "Monospace"; |
|
|
|
|
#endif |
|
|
|
|
commonData.insert("ShowOptions", ini.value("Common", "ShowOptions", "1")); |
|
|
|
|
commonData.insert("Reconnect", ini.value("Common", "Reconnect", "0")); |
|
|
|
|
commonData.insert("RejoinChannelsOnConnect", ini.value("Common", "RejoinChannelsOnConnect", "0")); |
|
|
|
|
commonData.insert("ShowWhoisActiveWindow", ini.value("Common", "ShowWhoisActiveWindow", "1")); |
|
|
|
|
commonData.insert("ShowModeInMessage", ini.value("Common", "ShowModeInMessage", "1")); |
|
|
|
|
commonData.insert("TrayNotify", ini.value("Common", "TrayNotify", "1")); |
|
|
|
|
commonData.insert("TrayNotifyDelay", ini.value("Common", "TrayNotifyDelay", "5")); |
|
|
|
|
commonData.insert("ShowTimestamp", ini.value("Common", "ShowTimestamp", "1")); |
|
|
|
|
commonData.insert("TimestampFormat", ini.value("Common", "TimestampFormat", "[HH:mm]")); |
|
|
|
|
commonData.insert("ManualKeepaliveEnabled", ini.value("Common", "ManualKeepaliveEnabled", "0")); |
|
|
|
|
commonData.insert("ManualKeepalive", ini.value("Common", "ManualKeepalive", "10")); |
|
|
|
|
commonData.insert("QuitMessage", ini.value("Common", "QuitMessage")); |
|
|
|
|
commonData.insert("Font", ini.value("Common", "Font", defaultFontName)); |
|
|
|
|
commonData.insert("FontSize", ini.value("Common", "FontSize", "12")); |
|
|
|
|
commonData.insert("BgImageEnabled", ini.value("Common", "BgImageEnabled", "0")); |
|
|
|
|
commonData.insert("BgImagePath", ini.value("Common", "BgImagePath")); |
|
|
|
|
commonData.insert("BgImageOpacity", ini.value("Common", "BgImageOpacity", "100")); |
|
|
|
|
commonData.insert("BgImageScaling", ini.value("Common", "BgImageScaling")); |
|
|
|
|
commonData.insert("SSLSelfsigned", ini.value("Common", "SSLSelfSigned", "0")); |
|
|
|
|
commonData.insert("SSLExpired", "0"); |
|
|
|
|
commonData.insert("SSLCNMismatch", ini.value("Common", "SSLCNMismatch", "0")); |
|
|
|
|
commonData.insert("ButtonBarPosition", ini.value("Common", "ButtonBarPosition", "N")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::loadColor(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
colorData.insert("Action", ini.value("Color", "Action", "#840084")); |
|
|
|
|
colorData.insert("CTCP", ini.value("Color", "CTCP", "#FF0000")); |
|
|
|
|
colorData.insert("Highlight", ini.value("Color", "Highlight", "#848400")); |
|
|
|
|
colorData.insert("Invite", ini.value("Color", "Invite", "#008400")); |
|
|
|
|
colorData.insert("Join", ini.value("Color", "Join", "#008400")); |
|
|
|
|
colorData.insert("Kick", ini.value("Color", "Kick", "#008400")); |
|
|
|
|
colorData.insert("Mode", ini.value("Color", "Mode", "#008400")); |
|
|
|
|
colorData.insert("Nick", ini.value("Color", "Nick", "#008400")); |
|
|
|
|
colorData.insert("Normal", ini.value("Color", "Normal", "#000000")); |
|
|
|
|
colorData.insert("Notice", ini.value("Color", "Notice", "#840000")); |
|
|
|
|
colorData.insert("OwnText", ini.value("Color", "OwnText", "#008484")); |
|
|
|
|
colorData.insert("Part", ini.value("Color", "Part", "#008400")); |
|
|
|
|
colorData.insert("ProgramInfo", ini.value("Color", "ProgramInfo", "#000084")); |
|
|
|
|
colorData.insert("Quit", ini.value("Color", "Quit", "#000084")); |
|
|
|
|
colorData.insert("ServerInfo", ini.value("Color", "ServerInfo", "#008400")); |
|
|
|
|
colorData.insert("Topic", ini.value("Color", "Topic", "#008400")); |
|
|
|
|
colorData.insert("Wallops", ini.value("Color", "Wallops", "#FF0000")); |
|
|
|
|
colorData.insert("TextviewBackground", ini.value("Color", "TextviewBackground", "#FFFFFF")); |
|
|
|
|
colorData.insert("InputBackground", ini.value("Color", "InputBackground", "#FFFFFF")); |
|
|
|
|
colorData.insert("InputForeground", ini.value("Color", "InputForeground", "#000000")); |
|
|
|
|
colorData.insert("ListboxBackground", ini.value("Color", "ListboxBackground", "#FFFFFF")); |
|
|
|
|
colorData.insert("ListboxForeground", ini.value("Color", "ListboxForeground", "#000000")); |
|
|
|
|
colorData.insert("Links", ini.value("Color", "Links", "#0000FF")); |
|
|
|
|
colorData.insert("WindowButtonNormal", ini.value("Color", "WindowButtonNormal", "#000000")); |
|
|
|
|
colorData.insert("WindowButtonActivity", ini.value("Color", "WindowButtonActivity", "#000088")); |
|
|
|
|
colorData.insert("WindowButtonMessage", ini.value("Color", "WindowButtonMessage", "#0000FF")); |
|
|
|
|
colorData.insert("WindowButtonAttention", ini.value("Color", "WindowButtonAttention", "#FF0000")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::loadPrefixColor(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
QString defaultColor = color("ListboxForeground"); |
|
|
|
|
const int ItemCount = ini.countItems("PrefixColor"); |
|
|
|
|
for (int i = 0; i < ItemCount; ++i) { |
|
|
|
|
int key = ini.key("PrefixColor", i).toInt(); // Stored as ascii-value of given prefix
|
|
|
|
|
QColor color(ini.value("PrefixColor", i, defaultColor)); |
|
|
|
|
QChar prefix = static_cast<char>(key); |
|
|
|
|
prefixColorData.push_back(std::make_pair(prefix, color)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::loadLogging(IniFile &ini) |
|
|
|
|
{ |
|
|
|
|
loggingData.insert("Channels", ini.value("Logging", "Channels", "0")); |
|
|
|
|
loggingData.insert("Privates", ini.value("Logging", "Privates", "0")); |
|
|
|
|
loggingData.insert("Path", ini.value("Logging", "Path")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::loadScripts(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
scriptsData.clear(); |
|
|
|
|
const int slen = ini.countItems("Scripts"); |
|
|
|
|
for (int i = 0; i < slen; ++i) { |
|
|
|
|
scriptsData << ini.value("Scripts", i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::saveGeometry(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
QHashIterator<QString,QString> it(geometryData); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
it.next(); |
|
|
|
|
ini.write("Geometry", it.key(), it.value()); |
|
|
|
|
for (const auto& item : palette) { |
|
|
|
|
const auto key = std::to_string(item.first.toLatin1()); |
|
|
|
|
const auto val = item.second.name(); |
|
|
|
|
ini.write("PrefixColor", key, val.toStdString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::saveConnection(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
QHashIterator<QString,QString> it(connectionData); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
it.next(); |
|
|
|
|
ini.write("Connection", it.key(), it.value()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::saveCommon(IniFile& ini) |
|
|
|
|
void ConfigMgr::addScript(const QString& path) |
|
|
|
|
{ |
|
|
|
|
QHashIterator<QString,QString> it(commonData); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
it.next(); |
|
|
|
|
ini.write("Common", it.key(), it.value()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
* Scripts are stored to ini file with a number for key. |
|
|
|
|
* Find the highest available number and use that. |
|
|
|
|
*/ |
|
|
|
|
QStringList scripts; |
|
|
|
|
const int sectSize = ini.count("Scripts"); |
|
|
|
|
for (int i = 0; i < sectSize; ++i) { |
|
|
|
|
scripts << QString::fromStdString( ini.read("Scripts", i) ); |
|
|
|
|
} |
|
|
|
|
scripts << path; |
|
|
|
|
|
|
|
|
|
void ConfigMgr::saveColor(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
QHashIterator<QString,QString> it(colorData); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
it.next(); |
|
|
|
|
ini.write("Color", it.key(), it.value()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ini.remove("Scripts"); |
|
|
|
|
|
|
|
|
|
void ConfigMgr::savePrefixColor(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
for (const auto& pair : prefixColorData) { |
|
|
|
|
int keynum = pair.first.toLatin1(); |
|
|
|
|
ini.write("PrefixColor", QString::number(keynum), pair.second.name()); |
|
|
|
|
} |
|
|
|
|
int n = 1; |
|
|
|
|
for (const auto& script : scripts) { |
|
|
|
|
ini.write("Scripts", std::to_string(n), script.toStdString()); |
|
|
|
|
++n; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::saveLogging(IniFile& ini) |
|
|
|
|
void ConfigMgr::delScript(const QString& path) |
|
|
|
|
{ |
|
|
|
|
QHashIterator<QString,QString> it(loggingData); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
it.next(); |
|
|
|
|
ini.write("Logging", it.key(), it.value()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
std::string n; |
|
|
|
|
const int sectSize = ini.count("Scripts"); |
|
|
|
|
for (int i = 0; i < sectSize; ++i) { |
|
|
|
|
n = ini.item("Scripts", i); |
|
|
|
|
if (ini.read("Scripts", i) == path.toStdString()) |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConfigMgr::saveScripts(IniFile& ini) |
|
|
|
|
{ |
|
|
|
|
ini.delSection("Scripts"); |
|
|
|
|
for (int i = 0; i < scriptsData.length(); ++i) |
|
|
|
|
ini.write("Scripts", QString::number(i), scriptsData[i]); |
|
|
|
|
if (!n.empty()) |
|
|
|
|
ini.remove("Scripts", n); |
|
|
|
|
} |
|
|
|
|