23 #include "ircconfig.h"
25 #include "irc/configuration/chatnetworkscfg.h"
26 #include "ini/settingsproviderqt.h"
27 #include "plugins/engineplugin.h"
28 #include "plugins/pluginloader.h"
29 #include "datapaths.h"
33 #include <QMessageBox>
37 IRCConfig::IRCConfig()
41 IRCConfig::~IRCConfig()
64 void IRCConfig::loadNetworksFromPlugins()
67 bool shouldSave =
false;
69 for(
unsigned int i = 0;i < gPlugins->numPlugins();i++)
71 if(gPlugins->plugin(i)->info()->data()->ircChannels.size() == 0)
75 IniVariable registered = gPlugins->plugin(i)->info()->data()->pConfig->createSetting(
"IRCRegistered",
false);
81 foreach(
const IRCNetworkEntity &entity, gPlugins->plugin(i)->info()->data()->ircChannels)
84 if(!networks.contains(entity))
95 if(QMessageBox::question(NULL, QObject::tr(
"Add plugin's IRC channel?"),
96 QObject::tr(
"Would you like the %1 plugin to add its channel to %2's auto join?")
98 QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::No)
122 section = pIni->section(AppearanceCfg::SECTION_NAME);
123 appearance.load(section);
125 section = pIni->section(GeneralCfg::SECTION_NAME);
126 general.load(section);
128 section = pIni->section(PersonalCfg::SECTION_NAME);
129 personal.load(section);
131 section = pIni->section(SoundsCfg::SECTION_NAME);
132 sounds.load(section);
134 loadNetworksFromPlugins();
148 section = pIni->section(AppearanceCfg::SECTION_NAME);
149 appearance.save(section);
151 section = pIni->section(GeneralCfg::SECTION_NAME);
152 general.save(section);
154 section = pIni->section(PersonalCfg::SECTION_NAME);
155 personal.save(section);
157 section = pIni->section(SoundsCfg::SECTION_NAME);
158 sounds.save(section);
160 if (settings->isWritable())
171 settingsProvider.reset();
174 gLog << QObject::tr(
"Setting IRC INI file: %1").arg(filePath);
175 settings.reset(
new QSettings(filePath, QSettings::IniFormat));
177 pIni.reset(
new Ini(settingsProvider.data()));
181 section = this->pIni->section(AppearanceCfg::SECTION_NAME);
182 appearance.init(section);
188 const QString IRCConfig::AppearanceCfg::SECTION_NAME =
"Appearance";
190 IRCConfig::AppearanceCfg::AppearanceCfg()
192 this->backgroundColor =
"#000000";
193 this->channelActionColor =
"#008000";
194 this->ctcpColor =
"#de5aff";
195 this->defaultTextColor =
"#b9b9b9";
196 this->errorColor =
"#ff0000";
197 this->mainFont = QFont(
"Courier");
198 this->networkActionColor =
"#079CFF";
199 this->timestamps =
true;
200 this->userListFont = QFont(
"Courier");
201 this->userListSelectedTextColor =
"#cbcb0f";
202 this->userListSelectedBackgroundColor =
"#B74600";
203 this->urlColor =
"#00F6FF";
204 windowAlertOnImportantChatEvent =
true;
207 void IRCConfig::AppearanceCfg::init(
IniSection& section)
209 section.
createSetting(
"BackgroundColor", this->backgroundColor);
210 section.
createSetting(
"ChannelActionColor", this->channelActionColor);
212 section.
createSetting(
"DefaultTextColor", this->defaultTextColor);
214 section.
createSetting(
"MainFont", this->mainFont.toString());
215 section.
createSetting(
"NetworkActionColor", this->networkActionColor);
217 section.
createSetting(
"UserListFont", this->userListFont.toString());
218 section.
createSetting(
"UserListSelectedTextColor", this->userListSelectedTextColor);
219 section.
createSetting(
"UserListSelectedBackgroundColor", this->userListSelectedBackgroundColor);
223 void IRCConfig::AppearanceCfg::load(
IniSection& section)
225 this->backgroundColor = (
const QString &)section[
"BackgroundColor"];
226 this->channelActionColor = (
const QString &)section[
"ChannelActionColor"];
227 this->ctcpColor = (
const QString &)section[
"CtcpColor"];
228 this->defaultTextColor = (
const QString &)section[
"DefaultTextColor"];
229 this->errorColor = (
const QString &)section[
"ErrorColor"];
230 this->mainFont.fromString(section[
"MainFont"]);
231 this->networkActionColor = (
const QString &)section[
"NetworkActionColor"];
232 this->timestamps = section[
"TimeStamps"];
233 this->userListFont.fromString(section[
"UserListFont"]);
234 this->urlColor = (
const QString &)section[
"UrlColor"];
235 this->userListSelectedTextColor = (
const QString &)section[
"UserListSelectedTextColor"];
236 this->userListSelectedBackgroundColor = (
const QString &)section[
"UserListSelectedBackgroundColor"];
237 windowAlertOnImportantChatEvent = section.
value(
"WindowAlertOnImportantChatEvent",
true).toBool();
240 void IRCConfig::AppearanceCfg::save(
IniSection& section)
242 section[
"BackgroundColor"] = this->backgroundColor;
243 section[
"ChannelActionColor"] = this->channelActionColor;
244 section[
"CtcpColor"] = this->ctcpColor;
245 section[
"DefaultTextColor"] = this->defaultTextColor;
246 section[
"ErrorColor"] = this->errorColor;
247 section[
"MainFont"] = this->mainFont.toString();
248 section[
"NetworkActionColor"] = this->networkActionColor;
249 section[
"TimeStamps"] = this->timestamps;
250 section[
"UserListFont"] = this->userListFont.toString();
251 section[
"UserListSelectedTextColor"] = this->userListSelectedTextColor;
252 section[
"UserListSelectedBackgroundColor"] = this->userListSelectedBackgroundColor;
253 section[
"UrlColor"] = this->urlColor;
254 section.
setValue(
"WindowAlertOnImportantChatEvent", windowAlertOnImportantChatEvent);
258 const QString IRCConfig::GeneralCfg::SECTION_NAME =
"General";
260 IRCConfig::GeneralCfg::GeneralCfg()
265 void IRCConfig::GeneralCfg::load(
IniSection& section)
269 void IRCConfig::GeneralCfg::save(
IniSection& section)
274 const QString IRCConfig::PersonalCfg::SECTION_NAME =
"Personal";
276 IRCConfig::PersonalCfg::PersonalCfg()
280 void IRCConfig::PersonalCfg::load(
IniSection& section)
282 this->alternativeNickname = (
const QString &)section[
"AlternativeNickname"];
283 this->fullName = (
const QString &)section[
"FullName"];
284 this->nickname = (
const QString &)section[
"Nickname"];
285 this->quitMessage = (
const QString &)section.
value(
"QuitMessage",
"Doomseeker End of Line").toString();
288 void IRCConfig::PersonalCfg::save(
IniSection& section)
290 section[
"AlternativeNickname"] = this->alternativeNickname;
291 section[
"FullName"] = this->fullName;
292 section[
"Nickname"] = this->nickname;
293 section[
"QuitMessage"] = this->quitMessage;
296 const QString IRCConfig::SoundsCfg::SECTION_NAME =
"Sounds";
298 IRCConfig::SoundsCfg::SoundsCfg()
300 this->bUseNicknameUsedSound =
false;
301 this->bUsePrivateMessageReceivedSound =
false;
304 void IRCConfig::SoundsCfg::load(
IniSection& section)
306 this->bUseNicknameUsedSound = section[
"bUseNicknameUsedSound"];
307 this->bUsePrivateMessageReceivedSound = section[
"bUsePrivateMessageReceivedSound"];
308 this->nicknameUsedSound = (
const QString&)section[
"NicknameUsedSound"];
309 this->privateMessageReceivedSound = (
const QString&)section[
"PrivateMessageReceivedSound"];
312 void IRCConfig::SoundsCfg::save(
IniSection& section)
314 section[
"bUseNicknameUsedSound"] = this->bUseNicknameUsedSound;
315 section[
"bUsePrivateMessageReceivedSound"] = this->bUsePrivateMessageReceivedSound;
316 section[
"NicknameUsedSound"] = this->nicknameUsedSound;
317 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.