diff options
Diffstat (limited to 'src/GreetingSetting.hpp')
| -rw-r--r-- | src/GreetingSetting.hpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/GreetingSetting.hpp b/src/GreetingSetting.hpp new file mode 100644 index 0000000..d3d6617 --- /dev/null +++ b/src/GreetingSetting.hpp @@ -0,0 +1,100 @@ +#pragma once + +#include <QString> + +#include "ClientInterface.hpp" + +class GreetingSetting { +public: + ClientInterface interface; + QString target = ""; + bool negative = false; + + GreetingSetting() { } + inline bool operator==(const GreetingSetting& other) + { + return other.interface == interface && other.negative == negative && other.target == target; + } + inline bool operator!=(const GreetingSetting& other) + { + return !operator==(other); + } + + inline GreetingSetting& invert() + { + negative = !negative; + return *this; + } + + static GreetingSetting clonk() + { + GreetingSetting ret; + ret.interface = Clonk; + return ret; + } + + static GreetingSetting irc(QString target = "") + { + GreetingSetting ret; + ret.interface = IRC; + ret.target = target; + return ret; + } +}; + +template <> +class ConfigValue<GreetingSetting> : ConfigValueBase { + GreetingSetting& conf; +public: + ConfigValue(GreetingSetting& conf) : conf(conf) { } + + void setValue(const QString& value) + { + QString val = value; + bool negative = (value.at(0) == '!'); + if(negative) + { + val.remove(0, 1); + } + + const QStringList& parts = Util::splitEscaped(val, ':'); + if(parts.first() == "Clonk" && parts.length() == 1) + { + conf.interface = Clonk; + conf.target.clear(); + } + else if(parts.first() == "IRC" && parts.length() <= 2) + { + conf.interface = IRC; + if(parts.length() == 2) + { + conf.target = parts.at(1); + } + else + { + conf.target.clear(); + } + } + else + { + throw ConfigException("Can not parse corrupt GreetingSetting"); + } + + conf.negative = negative; + } + + QString value() + { + QString ret; + if(conf.negative) + { + ret = "!"; + } + QStringList parts = {(conf.interface == Clonk ? "Clonk" : "IRC")}; + if(!conf.target.isEmpty()) + { + parts.append(conf.target); + } + return ret + Util::joinEscape(parts, ':'); + } +}; |
