#pragma once #include #include "qt-config/ConfigBase.hpp" #include "ClientInterface.hpp" class GreetingSetting { public: ClientInterface interface; bool negative = false; QString target = ""; 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 : 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, ':'); } };