ircconfig.h
1 //------------------------------------------------------------------------------
2 // ircconfig.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __IRCCONFIG_H__
24 #define __IRCCONFIG_H__
25 
26 #define gIRCConfig IRCConfig::config()
27 
28 #include "ini/ini.h"
29 #include "irc/entities/ircnetworkentity.h"
30 #include <QFont>
31 #include <QScopedPointer>
32 #include <QSettings>
33 
34 class SettingsProviderQt;
35 
44 class IRCConfig
45 {
46 public:
48  {
49  public:
50  static const QString SECTION_NAME;
51 
52  QString backgroundColor;
53  QString channelActionColor;
54  QString ctcpColor;
55  QString defaultTextColor;
56  QString errorColor;
57  QFont mainFont;
58  QString networkActionColor;
59  bool timestamps;
60  QString urlColor;
61  QFont userListFont;
62  QString userListSelectedTextColor;
63  QString userListSelectedBackgroundColor;
64  bool windowAlertOnImportantChatEvent;
65 
66  AppearanceCfg();
67 
68  void init(IniSection &section);
69  void load(IniSection &section);
70  void save(IniSection &section);
71  };
72 
73  class GeneralCfg
74  {
75  public:
76  static const QString SECTION_NAME;
77 
78  GeneralCfg();
79 
80  void load(IniSection &section);
81  void save(IniSection &section);
82  };
83 
85  {
86  public:
87  static const QString SECTION_NAME;
88 
89  QString alternativeNickname;
90  QString fullName;
91  QString nickname;
92  QString quitMessage;
93  QString userName;
94 
95  PersonalCfg();
96 
97  // This does not require a init since all values are meant
98  // to be empty by default.
99 
100  void load(IniSection &section);
101  void save(IniSection &section);
102  };
103 
104  class SoundsCfg
105  {
106  public:
107  static const QString SECTION_NAME;
108 
109  bool bUseNicknameUsedSound;
110  bool bUsePrivateMessageReceivedSound;
111  QString nicknameUsedSound;
112  QString privateMessageReceivedSound;
113 
114  SoundsCfg();
115 
116  void load(IniSection &section);
117  void save(IniSection &section);
118  };
119 
123  static IRCConfig &config();
124 
132  static void dispose();
133 
134  AppearanceCfg appearance;
135  GeneralCfg general;
136  PersonalCfg personal;
137  SoundsCfg sounds;
138 
139  Ini *ini()
140  {
141  return this->pIni.data();
142  }
143 
148  bool readFromFile();
149 
154  bool saveToFile();
155 
164  bool setIniFile(const QString &filePath);
165 
166 
167 private:
168  static IRCConfig *instance;
169 
170  QScopedPointer<QSettings> settings;
171  QScopedPointer<SettingsProviderQt> settingsProvider;
172  QScopedPointer<Ini> pIni;
173 
174  IRCConfig();
175  ~IRCConfig();
176 
177  void loadNetworksFromPlugins();
178 };
179 
180 #endif