SVN_SILENT made messages (.desktop file)
[kdeadmin.git] / ksysv / ksv_conf.cpp
blob21241d436700b05e1fdd5ac052195a664ff34b7d
1 /***************************************************************************
2 begin : Sun Oct 3 1999
3 copyright : (C) 1997-99 by Peter Putzer
4 email : putzer@kde.org
5 ***************************************************************************/
7 /*
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 // KSysV Config Object
25 #include <kglobal.h>
26 #include <kglobalsettings.h>
27 #include <kmainwindow.h>
28 #include <kconfig.h>
30 #include "ksv_core.h"
31 #include "ksv_conf.h"
32 //Added by qt3to4:
33 #include <Q3ValueList>
35 KSVConfig::KSVConfig ()
36 : mConfig (KGlobal::config())
38 readSettings();
41 void KSVConfig::setPanningFactor (int val)
43 mPanningFactor = val > 100 ? 100 : val;
44 mPanningFactor = mPanningFactor < 0 ? 0 : mPanningFactor;
47 void KSVConfig::readSettings()
49 mConfig->setGroup("Path Settings");
50 mScriptPath = mConfig->readEntry("ScriptPath", "/etc/rc.d/init.d");
51 mRunlevelPath = mConfig->readEntry("RunlevelPath", "/etc/rc.d");
53 mConfig->setGroup("Other Settings");
54 mShowLog = mConfig->readEntry("ShowLog", true);
55 mConfigured = mConfig->readEntry("Configured", false);
56 mPanningFactor = mConfig->readNumEntry("PanningFactor", 80);
57 mShowDescription = mConfig->readEntry("ShowDescription", true);
59 mConfig->setGroup("Colors");
60 mNewNormalColor = mConfig->readColorEntry ("New Text", Qt::blue);
61 mNewSelectedColor = mConfig->readColorEntry ("New Selected Text", Qt::blue);
62 mChangedNormalColor = mConfig->readColorEntry ("Changed Text", Qt::red);
63 mChangedSelectedColor = mConfig->readColorEntry ("Changed Selected Text", Qt::red);
65 mConfig->setGroup("Fonts");
66 QFont tmp = KGlobalSettings::generalFont();
67 mServiceFont = mConfig->readFontEntry ("Service Font", &tmp);
68 tmp = KGlobalSettings::fixedFont();
69 mNumberFont = mConfig->readFontEntry ("Number Font", &tmp);
71 readRunlevels();
74 void KSVConfig::readLegacySettings ()
76 mConfig->setGroup("Path Settings");
78 mScriptPath = mConfig->readEntry("ScriptPath", "/etc/rc.d/init.d");
79 mRunlevelPath = mConfig->readEntry("RunlevelPath", "/etc/rc.d");
81 mConfig->setGroup("Other Settings");
83 mShowLog = mConfig->readEntry("ShowLog", true);
84 mConfigured = mConfig->readEntry("Configured", false);
85 mPanningFactor = mConfig->readEntry("PanningFactor", 80);
86 mShowDescription = mConfig->readEntry("ShowDescription", true);
87 mConfig->setGroup("Colors");
88 mNewNormalColor = mConfig->readColorEntry("New", Qt::blue);
89 mChangedNormalColor = mConfig->readColorEntry("Changed", Qt::red);
92 void KSVConfig::writeSettings() {
93 mConfig->setGroup("Path Settings");
94 mConfig->writeEntry("ScriptPath", mScriptPath);
95 mConfig->writeEntry("RunlevelPath", mRunlevelPath);
97 mConfig->setGroup("Other Settings");
98 mConfig->writeEntry("ShowLog", mShowLog);
99 mConfig->writeEntry("Configured", mConfigured);
100 mConfig->writeEntry("PanningFactor", mPanningFactor);
101 mConfig->writeEntry("ShowDescription", mShowDescription);
103 mConfig->setGroup("Colors");
104 mConfig->writeEntry("New Text", mNewNormalColor);
105 mConfig->writeEntry("New Selected Text", mNewSelectedColor);
106 mConfig->writeEntry("Changed Text", mChangedNormalColor);
107 mConfig->writeEntry("Changed Selected Text", mChangedSelectedColor);
109 mConfig->setGroup("Fonts");
110 mConfig->writeEntry("Service Font", mServiceFont);
111 mConfig->writeEntry("Number Font", mNumberFont);
113 // save screen geometry
114 KMainWindow* mw = static_cast<KMainWindow*>(kapp->mainWidget());
116 if (mw)
118 mConfig->setGroup("Geometry");
119 mConfig->writeEntry("X-Position", mw->x());
120 mConfig->writeEntry("Y-Position", mw->y());
123 writeRunlevels();
125 // flush everything
126 mConfig->sync();
129 bool KSVConfig::showRunlevel (int index) const
131 if (mShowRunlevel.contains (index))
132 return mShowRunlevel[index];
133 else
134 return false;
137 void KSVConfig::readRunlevels ()
139 mConfig->setGroup ("Runlevels");
141 Q3ValueList<int> list = mConfig->readIntListEntry ("Show Runlevels");
143 for (Q3ValueList<int>::Iterator it = list.begin(); it != list.end(); ++it)
144 mShowRunlevel[*it] = true;
146 if (mShowRunlevel.isEmpty())
147 for (int i = 0; i < ksv::runlevelNumber; ++i)
148 mShowRunlevel[i] = true;
151 void KSVConfig::writeRunlevels ()
153 Q3ValueList<int> list;
155 for (QMap<int,bool>::Iterator it = mShowRunlevel.begin(); it != mShowRunlevel.end(); ++it)
156 if (it.data())
157 list.append (it.key());
159 mConfig->setGroup ("Runlevels");
160 mConfig->writeEntry ("Show Runlevels", list);
163 void KSVConfig::setShowRunlevel (int index, bool state)
165 mShowRunlevel[index] = state;
168 QPoint KSVConfig::position() const
170 mConfig->setGroup("Geometry");
172 return QPoint(mConfig->readNumEntry("X-Position", 0),
173 mConfig->readNumEntry("Y-Position", 0));
176 void KSVConfig::setScriptPath (const QString& path)
178 mScriptPath = path;
181 void KSVConfig::setRunlevelPath (const QString& path)
183 mRunlevelPath = path;
186 KSVConfig* KSVConfig::self()
188 static KSVConfig conf;
190 return &conf;
193 void KSVConfig::setNewNormalColor (const QColor& col)
195 mNewNormalColor = col;
198 void KSVConfig::setNewSelectedColor (const QColor& col)
200 mNewSelectedColor = col;
203 void KSVConfig::setChangedNormalColor (const QColor& col)
205 mChangedNormalColor = col;
208 void KSVConfig::setChangedSelectedColor (const QColor& col)
210 mChangedSelectedColor = col;
213 void KSVConfig::setNumberFont (const QFont& font)
215 mNumberFont = font;
218 void KSVConfig::setServiceFont (const QFont& font)
220 mServiceFont = font;
223 void KSVConfig::setShowMessage (ksv::Messages msg, bool on)
225 mConfig->setGroup("Notification Messages");
226 mConfig->writeEntry (ksv::notifications[msg], on);
229 bool KSVConfig::showMessage (ksv::Messages msg) const
231 mConfig->setGroup("Notification Messages");
232 return mConfig->readEntry (ksv::notifications[msg], true);