23 #include "ircconfig.h" 25 #include "datapaths.h" 26 #include "ini/settingsproviderqt.h" 27 #include "irc/configuration/chatnetworkscfg.h" 29 #include "plugins/engineplugin.h" 30 #include "plugins/pluginloader.h" 33 #include <QMessageBox> 37 IRCConfig::IRCConfig()
41 IRCConfig::~IRCConfig()
47 if (instance ==
nullptr)
55 if (instance !=
nullptr)
62 void IRCConfig::loadNetworksFromPlugins()
65 bool shouldSave =
false;
67 for (
unsigned int i = 0; i < gPlugins->numPlugins(); i++)
69 if (gPlugins->plugin(i)->info()->data()->ircChannels.size() == 0)
73 IniVariable registered = gPlugins->plugin(i)->info()->data()->pConfig->createSetting(
"IRCRegistered",
false);
79 for (
const IRCNetworkEntity &entity : gPlugins->plugin(i)->info()->data()->ircChannels)
82 if (!networks.contains(entity))
88 if (existingEntity.
autojoinChannels().contains(entity.autojoinChannels()[0]))
93 if (QMessageBox::question(
nullptr, QObject::tr(
"Add plugin's IRC channel?"),
94 QObject::tr(
"Would you like the %1 plugin to add its channel to %2's auto join?")
95 .arg(entity.description()).arg(existingEntity.
description()),
96 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::No)
116 section = pIni->section(AppearanceCfg::SECTION_NAME);
117 appearance.load(section);
119 section = pIni->section(GeneralCfg::SECTION_NAME);
120 general.load(section);
122 section = pIni->section(PersonalCfg::SECTION_NAME);
123 personal.load(section);
125 section = pIni->section(SoundsCfg::SECTION_NAME);
126 sounds.load(section);
128 loadNetworksFromPlugins();
140 section = pIni->section(AppearanceCfg::SECTION_NAME);
141 appearance.save(section);
143 section = pIni->section(GeneralCfg::SECTION_NAME);
144 general.save(section);
146 section = pIni->section(PersonalCfg::SECTION_NAME);
147 personal.save(section);
149 section = pIni->section(SoundsCfg::SECTION_NAME);
150 sounds.save(section);
152 if (settings->isWritable())
163 settingsProvider.reset();
166 gLog << QObject::tr(
"Setting IRC INI file: %1").arg(filePath);
167 settings.reset(
new QSettings(filePath, QSettings::IniFormat));
169 pIni.reset(
new Ini(settingsProvider.data()));
173 section = this->pIni->section(AppearanceCfg::SECTION_NAME);
174 appearance.init(section);
180 const QString IRCConfig::AppearanceCfg::SECTION_NAME =
"Appearance";
182 IRCConfig::AppearanceCfg::AppearanceCfg()
184 this->backgroundColor =
"#000000";
185 this->channelActionColor =
"#008000";
186 this->ctcpColor =
"#de5aff";
187 this->defaultTextColor =
"#b9b9b9";
188 this->errorColor =
"#ff0000";
189 this->mainFont = QFont(
"Courier");
190 this->networkActionColor =
"#079CFF";
191 this->timestamps =
true;
192 this->userListFont = QFont(
"Courier");
193 this->userListSelectedTextColor =
"#cbcb0f";
194 this->userListSelectedBackgroundColor =
"#B74600";
195 this->urlColor =
"#00F6FF";
196 windowAlertOnImportantChatEvent =
true;
199 void IRCConfig::AppearanceCfg::init(
IniSection §ion)
201 section.
createSetting(
"BackgroundColor", this->backgroundColor);
202 section.
createSetting(
"ChannelActionColor", this->channelActionColor);
204 section.
createSetting(
"DefaultTextColor", this->defaultTextColor);
206 section.
createSetting(
"MainFont", this->mainFont.toString());
207 section.
createSetting(
"NetworkActionColor", this->networkActionColor);
209 section.
createSetting(
"UserListFont", this->userListFont.toString());
210 section.
createSetting(
"UserListSelectedTextColor", this->userListSelectedTextColor);
211 section.
createSetting(
"UserListSelectedBackgroundColor", this->userListSelectedBackgroundColor);
215 void IRCConfig::AppearanceCfg::load(
IniSection §ion)
217 this->backgroundColor = (
const QString &)section[
"BackgroundColor"];
218 this->channelActionColor = (
const QString &)section[
"ChannelActionColor"];
219 this->ctcpColor = (
const QString &)section[
"CtcpColor"];
220 this->defaultTextColor = (
const QString &)section[
"DefaultTextColor"];
221 this->errorColor = (
const QString &)section[
"ErrorColor"];
222 this->mainFont.fromString(section[
"MainFont"]);
223 this->networkActionColor = (
const QString &)section[
"NetworkActionColor"];
224 this->timestamps = section[
"TimeStamps"];
225 this->userListFont.fromString(section[
"UserListFont"]);
226 this->urlColor = (
const QString &)section[
"UrlColor"];
227 this->userListSelectedTextColor = (
const QString &)section[
"UserListSelectedTextColor"];
228 this->userListSelectedBackgroundColor = (
const QString &)section[
"UserListSelectedBackgroundColor"];
229 windowAlertOnImportantChatEvent = section.
value(
"WindowAlertOnImportantChatEvent",
true).toBool();
232 void IRCConfig::AppearanceCfg::save(
IniSection §ion)
234 section[
"BackgroundColor"] = this->backgroundColor;
235 section[
"ChannelActionColor"] = this->channelActionColor;
236 section[
"CtcpColor"] = this->ctcpColor;
237 section[
"DefaultTextColor"] = this->defaultTextColor;
238 section[
"ErrorColor"] = this->errorColor;
239 section[
"MainFont"] = this->mainFont.toString();
240 section[
"NetworkActionColor"] = this->networkActionColor;
241 section[
"TimeStamps"] = this->timestamps;
242 section[
"UserListFont"] = this->userListFont.toString();
243 section[
"UserListSelectedTextColor"] = this->userListSelectedTextColor;
244 section[
"UserListSelectedBackgroundColor"] = this->userListSelectedBackgroundColor;
245 section[
"UrlColor"] = this->urlColor;
246 section.
setValue(
"WindowAlertOnImportantChatEvent", windowAlertOnImportantChatEvent);
250 const QString IRCConfig::GeneralCfg::SECTION_NAME =
"General";
252 IRCConfig::GeneralCfg::GeneralCfg()
256 void IRCConfig::GeneralCfg::load(
IniSection §ion)
261 void IRCConfig::GeneralCfg::save(
IniSection §ion)
266 const QString IRCConfig::PersonalCfg::SECTION_NAME =
"Personal";
268 IRCConfig::PersonalCfg::PersonalCfg()
272 void IRCConfig::PersonalCfg::load(
IniSection §ion)
274 this->alternativeNickname =
static_cast<QString
>(section[
"AlternativeNickname"]);
275 this->fullName =
static_cast<QString
>(section[
"FullName"]);
276 this->nickname =
static_cast<QString
>(section[
"Nickname"]);
277 this->quitMessage = section.
value(
"QuitMessage",
"Doomseeker End of Line").toString();
278 this->userName =
static_cast<QString
>(section[
"UserName"]);
281 void IRCConfig::PersonalCfg::save(
IniSection §ion)
283 section[
"AlternativeNickname"] = this->alternativeNickname;
284 section[
"FullName"] = this->fullName;
285 section[
"Nickname"] = this->nickname;
286 section[
"QuitMessage"] = this->quitMessage;
287 section[
"UserName"] = this->userName;
290 const QString IRCConfig::SoundsCfg::SECTION_NAME =
"Sounds";
292 IRCConfig::SoundsCfg::SoundsCfg()
294 this->bUseNicknameUsedSound =
false;
295 this->bUsePrivateMessageReceivedSound =
false;
298 void IRCConfig::SoundsCfg::load(
IniSection §ion)
300 this->bUseNicknameUsedSound = section[
"bUseNicknameUsedSound"];
301 this->bUsePrivateMessageReceivedSound = section[
"bUsePrivateMessageReceivedSound"];
302 this->nicknameUsedSound = (
const QString &)section[
"NicknameUsedSound"];
303 this->privateMessageReceivedSound = (
const QString &)section[
"PrivateMessageReceivedSound"];
306 void IRCConfig::SoundsCfg::save(
IniSection §ion)
308 section[
"bUseNicknameUsedSound"] = this->bUseNicknameUsedSound;
309 section[
"bUsePrivateMessageReceivedSound"] = this->bUsePrivateMessageReceivedSound;
310 section[
"NicknameUsedSound"] = this->nicknameUsedSound;
311 section[
"PrivateMessageReceivedSound"] = this->privateMessageReceivedSound;
IniVariable createSetting(const QString &name, const QVariant &data)
Inits specified variable with specified data.
static IRCConfig & config()
Returns the Singleton.
INI variable representation.
const QStringList & autojoinChannels() const
List of channels to which a /join command will be issued automatically when a connection with this ne...
This Singleton holds most of Doomseeker IRC configuration in memory.
const QString & description() const
A short, human-readable description for the network. (Preferably a single word).
bool isAutojoinNetwork() const
Join this network when Doomseeker starts up.
QVariant value(const QString &key) const
Retrieves a variable directly; omits the IniVariable system.
bool saveToFile()
Saves current settings to ini file. This file must be previously set by setIniFile() method...
bool readFromFile()
Reads settings from ini file. This file must be previously set by setIniFile() method.
static void dispose()
Disposes of the Singleton.
void setValue(const QString &key, const QVariant &value)
Sets a variable directly. Omits the IniVariable system.
Data structure that describes and defines a connection to an IRC network or server.
INI section representation.
bool setIniFile(const QString &filePath)
Initializes the Ini class instance to point to a file.