~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kdm/kfrontend/kdmconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Config for kdm
 
4
 
 
5
Copyright (C) 1997, 1998 Steffen Hansen <hansen@kde.org>
 
6
Copyright (C) 2000-2003 Oswald Buddenhagen <ossi@kde.org>
 
7
 
 
8
 
 
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.
 
13
 
 
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.
 
18
 
 
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.
 
22
 
 
23
*/
 
24
 
 
25
#include "kdmconfig.h"
 
26
#include "kdm_greet.h"
 
27
#include "utils.h"
 
28
 
 
29
#include <kconfiggroup.h>
 
30
#include <kglobal.h>
 
31
#include <klocale.h>
 
32
 
 
33
#include <stdio.h>
 
34
#include <stdlib.h>
 
35
#include <unistd.h>
 
36
#include <sys/utsname.h>
 
37
 
 
38
#define WANT_GREET_DEFS
 
39
#include <config.ci>
 
40
 
 
41
CONF_GREET_DEFS
 
42
 
 
43
QString _stsFile;
 
44
bool _isLocal;
 
45
bool _isReserve;
 
46
bool _authorized;
 
47
int _grabInput;
 
48
 
 
49
static QString
 
50
getCfgQStr(int id)
 
51
{
 
52
    return qString(getCfgStr(id));
 
53
}
 
54
 
 
55
static QStringList
 
56
getCfgQStrList(int id)
 
57
{
 
58
    return qStringList(getCfgStrArr(id, 0));
 
59
}
 
60
 
 
61
// Based on kconfiggroupgui.cpp
 
62
static QFont *
 
63
str2Font(const QString &aValue)
 
64
{
 
65
    QFont *aRetFont = new QFont();
 
66
 
 
67
    QStringList sl = aValue.split(QString::fromLatin1(","), QString::SkipEmptyParts);
 
68
    if (sl.count() == 1) {
 
69
        /* X11 font spec */
 
70
        aRetFont->setRawMode(true);
 
71
        aRetFont->setRawName(aValue);
 
72
    } else {
 
73
        aRetFont->fromString(aValue);
 
74
    }
 
75
    aRetFont->setStyleStrategy((QFont::StyleStrategy)
 
76
       (QFont::PreferMatch |
 
77
        (_antiAliasing ? QFont::PreferAntialias : QFont::NoAntialias)));
 
78
 
 
79
    return aRetFont;
 
80
}
 
81
 
 
82
extern "C"
 
83
void initConfig(void)
 
84
{
 
85
    CONF_GREET_INIT
 
86
 
 
87
    _isLocal = getCfgInt(C_isLocal);
 
88
    _isReserve = _isLocal && getCfgInt(C_isReserve);
 
89
    _hasConsole = _hasConsole && _isLocal && getCfgInt(C_hasConsole);
 
90
    _authorized = getCfgInt(C_isAuthorized);
 
91
    _grabInput =
 
92
        (_grabInputPre == GRAB_NEVER) ? 0 :
 
93
        (_grabInputPre == GRAB_ALWAYS) ? 1 :
 
94
        !_authorized;
 
95
 
 
96
    QByteArray dd = _dataDir.toUtf8();
 
97
    if (access(dd.constData(), W_OK))
 
98
        logError("Data directory %\"s not accessible: %m\n", dd.constData());
 
99
    _stsFile = _dataDir + "/kdmsts";
 
100
 
 
101
    // Greet String
 
102
    char hostname[256], *ptr;
 
103
    hostname[0] = '\0';
 
104
    if (!gethostname(hostname, sizeof(hostname)))
 
105
        hostname[sizeof(hostname)-1] = '\0';
 
106
    struct utsname tuname;
 
107
    uname(&tuname);
 
108
    QString gst = _greetString;
 
109
    _greetString.clear();
 
110
    int i, j, l = gst.length();
 
111
    for (i = 0; i < l; i++) {
 
112
        if (gst[i] == '%') {
 
113
            switch (gst[++i].cell()) {
 
114
            case '%': _greetString += gst[i]; continue;
 
115
            case 'd': ptr = dname; break;
 
116
            case 'h': ptr = hostname; break;
 
117
            case 'n': ptr = tuname.nodename;
 
118
                for (j = 0; ptr[j]; j++)
 
119
                    if (ptr[j] == '.') {
 
120
                        ptr[j] = 0;
 
121
                        break;
 
122
                    }
 
123
                break;
 
124
            case 's': ptr = tuname.sysname; break;
 
125
            case 'r': ptr = tuname.release; break;
 
126
            case 'm': ptr = tuname.machine; break;
 
127
            default: _greetString += i18nc("@item:intext substitution for "
 
128
                                           "an undefined %X placeholder wrongly "
 
129
                                           "given in the config file 'kdmrc', "
 
130
                                           "telling the user to fix it",
 
131
                                           "[fix kdmrc]"); continue;
 
132
            }
 
133
            _greetString += QString::fromLocal8Bit(ptr);
 
134
        } else {
 
135
            _greetString += gst[i];
 
136
        }
 
137
    }
 
138
}
 
139
 
 
140
void initQAppConfig(void)
 
141
{
 
142
    CONF_GREET_INIT_QAPP
 
143
 
 
144
    KConfigGroup cfg(KGlobal::config(), "General");
 
145
    cfg.writeEntry("nopaletteChange", true);
 
146
    cfg.writeEntry("font", *_normalFont);
 
147
    if (!_GUIStyle.isEmpty())
 
148
        cfg.writeEntry("widgetStyle", _GUIStyle);
 
149
}
 
150