1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2007-2010, 2013 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #include "conf.h"
21 
22 #include <licq/inifile.h>
23 
24 template <typename T, typename U>
getOrSet(Licq::IniFile & conf,const std::string & key,T & value,const U & defaultValue)25 static void getOrSet(Licq::IniFile& conf, const std::string& key,
26                      T& value, const U& defaultValue)
27 {
28   if (!conf.get(key, value, defaultValue))
29     conf.set(key, value);
30 }
31 
32 template <typename T, typename U>
getOrSetWithLimit(Licq::IniFile & conf,const std::string & key,T & value,const U & defaultValue,const U & limit)33 static void getOrSetWithLimit(Licq::IniFile& conf, const std::string& key,
34                               T& value, const U& defaultValue, const U& limit)
35 {
36   unsigned int temp;
37   if (!conf.get(key, temp, static_cast<unsigned int>(defaultValue))
38       || temp > static_cast<unsigned int>(limit))
39   {
40     temp = defaultValue;
41     conf.set(key, temp);
42   }
43 
44   value = static_cast<T>(temp);
45 }
46 
loadConfig()47 void Conf::loadConfig()
48 {
49   Licq::IniFile conf("licq_aosd.ini");
50   conf.loadFile();
51 
52   conf.setSection("Appearance");
53 
54   getOrSet(conf, "Font", font, "");
55   getOrSet(conf, "MarkSecureMessages", markSecure, true);
56 
57   conf.setSection("Colouring");
58 
59   getOrSet(conf, "Background", backColor, "");
60   getOrSet(conf, "Message", textColor, "yellow");
61   getOrSet(conf, "Control", textControlColor, "gray");
62   getOrSet(conf, "Shadow", shadowColor, "black");
63   getOrSetWithLimit(conf, "BackOpacity", backOpacity, 0, 255);
64   getOrSetWithLimit(conf, "TextOpacity", textOpacity, 255, 255);
65   getOrSetWithLimit(conf, "ShadowOpacity", shadowOpacity, 255, 255);
66 
67   conf.setSection("Geometry");
68 
69   getOrSetWithLimit(conf, "HPosition", posHorizontal,
70                     COORDINATE_MINIMUM, COORDINATE_MAXIMUM);
71   getOrSetWithLimit(conf, "VPosition", posVertical,
72                     COORDINATE_MINIMUM, COORDINATE_MAXIMUM);
73 
74   getOrSet(conf, "HOffset", offsetHorizontal, 0);
75   getOrSet(conf, "VOffset", offsetVertical, 0);
76 
77   getOrSet(conf, "HMargin", marginHorizontal, 0);
78   getOrSet(conf, "VMargin", marginVertical, 0);
79 
80   getOrSet(conf, "ShadowOffset", shadowOffset, 2);
81   getOrSet(conf, "Width", wrapWidth, 0);
82   getOrSet(conf, "Lines", maxLines, 0);
83 
84   conf.setSection("Timing");
85 
86   getOrSet(conf, "FadeIn", fadeIn, 150);
87   getOrSet(conf, "FadeFull", fadeFull, 3000);
88   getOrSet(conf, "FadeOut", fadeOut, 150);
89   getOrSet(conf, "DelayPerCharacter", delayPerChar, 0);
90 
91   conf.setSection("Behavior");
92 
93   getOrSet(conf, "Wait", wait, true);
94   getOrSet(conf, "MouseActive", mouseActive, true);
95   getOrSet(conf, "QuietTimeout", quietTimeout, 0);
96 
97   conf.setSection("Filtering");
98 
99   getOrSetWithLimit(conf, "ShowLogonLogoff", logonLogoff,
100                     GROUP_TYPE_ALL, GROUP_TYPE_ALL);
101   getOrSetWithLimit(conf, "ShowStatusChange", statusChange,
102                     GROUP_TYPE_ALL, GROUP_TYPE_ALL);
103   getOrSetWithLimit(conf, "ShowAutoResponseCheck", autoResponse,
104                     GROUP_TYPE_ALL, GROUP_TYPE_ALL);
105   getOrSetWithLimit(conf, "ShowMessages", showMessage,
106                     GROUP_TYPE_ALL, GROUP_TYPE_ALL);
107 
108   getOrSet(conf, "ShowMessagesNotification", notifyOnly, false);
109   getOrSet(conf, "ShowInModes", ownerModes, "");
110   getOrSet(conf, "ShowMsgsInModes", ownerModesMsg, "");
111 
112   conf.writeFile();
113 }
114 
115 /* vim: set ts=2 sw=2 et : */
116