#pragma once #include #include "qt-config/ConfigBase.hpp" #include "ClientInterface.hpp" class GreetingSetting { public: enum Mode {Normal, Notice, Disabled, Unset} mode = Normal; ClientInterface interface; QString target = ""; GreetingSetting() { } inline bool operator==(const GreetingSetting& other) { return other.interface == interface && other.mode == mode && other.target == target; } inline bool operator!=(const GreetingSetting& other) { return !operator==(other); } inline GreetingSetting& invert() { mode = (mode == Disabled) ? Normal : Disabled; 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; GreetingSetting::Mode mode = (value.at(0) == '!') ? GreetingSetting::Disabled : (value.at(0) == '-') ? GreetingSetting::Notice : GreetingSetting::Normal; if(mode != GreetingSetting::Normal) { val.remove(0, 1); } const QStringList& parts = Util::splitEscaped(val, ':'); if(parts.first() == "Clonk" && parts.length() == 1) { conf.interface = Clonk; conf.mode = mode == GreetingSetting::Disabled ? GreetingSetting::Disabled : GreetingSetting::Normal; 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(); } conf.mode = mode; } else { throw ConfigException("Can not parse corrupt GreetingSetting"); } } QString value() { QString ret; switch(conf.mode) { case GreetingSetting::Disabled: ret = "!"; break; case GreetingSetting::Notice: ret = "-"; break; case GreetingSetting::Normal: case GreetingSetting::Unset: break; } QStringList parts = {(conf.interface == Clonk ? "Clonk" : "IRC")}; if(!conf.target.isEmpty()) { parts.append(conf.target); } return ret + Util::joinEscape(parts, ':'); } };