diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2015-11-15 01:44:05 +0100 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2015-11-15 02:03:23 +0100 |
| commit | db9734adda107e1b417a77311f2194471274a223 (patch) | |
| tree | 41c8e6307036305ff08578be729ad129261d404c /src/GreetingSetting.hpp | |
| parent | b871ac2c887da8993316e48d2090b334248fc97d (diff) | |
| download | manager-db9734adda107e1b417a77311f2194471274a223.tar.gz manager-db9734adda107e1b417a77311f2194471274a223.zip | |
Allow enabling/disabling greeting for Clonk, IRC, IRC-User and IRC-
Channels
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, ':'); + } +}; |
