add more spacing
[personal-kdebase.git] / workspace / kdm / kfrontend / kdmconfig.cpp
blob3370c88bdaaca04def697f05b32d943df35c47b4
1 /*
3 Config for kdm
5 Copyright (C) 1997, 1998 Steffen Hansen <hansen@kde.org>
6 Copyright (C) 2000-2003 Oswald Buddenhagen <ossi@kde.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "kdmconfig.h"
26 #include "kdm_greet.h"
27 #include "utils.h"
29 #include <kconfiggroup.h>
30 #include <kglobal.h>
31 #include <klocale.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <sys/utsname.h>
38 #define WANT_GREET_DEFS
39 #include <config.ci>
41 CONF_GREET_DEFS
43 QString _stsFile;
44 bool _isLocal;
45 bool _isReserve;
46 bool _authorized;
48 static QString
49 getCfgQStr( int id )
51 return qString( getCfgStr( id ) );
54 static QStringList
55 getCfgQStrList( int id )
57 return qStringList( getCfgStrArr( id, 0 ) );
60 // Based on kconfiggroupgui.cpp
61 static QFont *
62 str2Font( const QString &aValue )
64 uint nFontBits;
65 QString chStr;
66 QFont *aRetFont = new QFont();
68 QStringList sl = aValue.split( QString::fromLatin1(","), QString::SkipEmptyParts );
70 if (sl.count() == 1) {
71 /* X11 font spec */
72 aRetFont->setRawMode( true );
73 aRetFont->setRawName( aValue );
74 } else if (sl.count() == 10) {
75 /* qt3 font spec */
76 aRetFont->fromString( aValue );
77 } else if (sl.count() == 6) {
78 /* backward compatible kde2 font spec */
79 aRetFont->setFamily( sl[0] );
80 aRetFont->setPointSize( sl[1].toInt() );
81 aRetFont->setWeight( sl[4].toUInt() );
83 aRetFont->setStyleHint( (QFont::StyleHint)sl[2].toUInt() );
85 nFontBits = sl[5].toUInt();
86 aRetFont->setItalic( (nFontBits & 0x01) != 0 );
87 aRetFont->setUnderline( (nFontBits & 0x02) != 0 );
88 aRetFont->setStrikeOut( (nFontBits & 0x04) != 0 );
89 aRetFont->setFixedPitch( (nFontBits & 0x08) != 0 );
90 aRetFont->setRawMode( (nFontBits & 0x20) != 0 );
92 aRetFont->setStyleStrategy( (QFont::StyleStrategy)
93 (QFont::PreferMatch |
94 (_antiAliasing ? QFont::PreferAntialias : QFont::NoAntialias)) );
96 return aRetFont;
99 extern "C"
100 void initConfig( void )
102 CONF_GREET_INIT
104 _isLocal = getCfgInt( C_isLocal );
105 _isReserve = _isLocal && getCfgInt( C_isReserve );
106 _hasConsole = _hasConsole && _isLocal && getCfgInt( C_hasConsole );
107 _authorized = getCfgInt( C_isAuthorized );
109 _stsFile = _dataDir + "/kdmsts";
111 // Greet String
112 char hostname[256], *ptr;
113 hostname[0] = '\0';
114 if (!gethostname( hostname, sizeof(hostname) ))
115 hostname[sizeof(hostname)-1] = '\0';
116 struct utsname tuname;
117 uname( &tuname );
118 QString gst = _greetString;
119 _greetString.clear();
120 int i, j, l = gst.length();
121 for (i = 0; i < l; i++) {
122 if (gst[i] == '%') {
123 switch (gst[++i].cell()) {
124 case '%': _greetString += gst[i]; continue;
125 case 'd': ptr = dname; break;
126 case 'h': ptr = hostname; break;
127 case 'n': ptr = tuname.nodename;
128 for (j = 0; ptr[j]; j++)
129 if (ptr[j] == '.') {
130 ptr[j] = 0;
131 break;
133 break;
134 case 's': ptr = tuname.sysname; break;
135 case 'r': ptr = tuname.release; break;
136 case 'm': ptr = tuname.machine; break;
137 default: _greetString += i18nc("@item:intext substitution for "
138 "an undefined %X placeholder wrongly "
139 "given in the config file 'kdmrc', "
140 "telling the user to fix it",
141 "[fix kdmrc]"); continue;
143 _greetString += QString::fromLocal8Bit( ptr );
144 } else
145 _greetString += gst[i];
149 void initQAppConfig( void )
151 CONF_GREET_INIT_QAPP
153 KConfigGroup cfg( KGlobal::config(), "General" );
154 cfg.writeEntry( "nopaletteChange", true );
155 cfg.writeEntry( "font", *_normalFont );
156 if (!_GUIStyle.isEmpty())
157 cfg.writeEntry( "widgetStyle", _GUIStyle );