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

« back to all changes in this revision

Viewing changes to kdm/kcm/kdm-shut.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
    Copyright (C) 1997-1998 Thomas Tanghus (tanghus@earthling.net)
 
3
 
 
4
    This program is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU General Public
 
6
    License as published by the Free Software Foundation; either
 
7
    version 2 of the License, or (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
    General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to
 
16
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
    Boston, MA 02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "kdm-shut.h"
 
21
 
 
22
#include <config.ci>
 
23
 
 
24
#include "kbackedcombobox.h"
 
25
 
 
26
#include <KDialog>
 
27
#include <KLineEdit>
 
28
#include <KLocale>
 
29
#include <KConfig>
 
30
#include <KUrlRequester>
 
31
 
 
32
#include <QGroupBox>
 
33
#include <QLabel>
 
34
#include <QGridLayout>
 
35
#include <QVBoxLayout>
 
36
 
 
37
extern KConfig *config;
 
38
 
 
39
KDMSessionsWidget::KDMSessionsWidget(QWidget *parent)
 
40
    : QWidget(parent)
 
41
{
 
42
    QString wtstr;
 
43
 
 
44
 
 
45
    QGroupBox *group0 = new QGroupBox(i18n("Allow Shutdown"), this);
 
46
 
 
47
    sdlcombo = new KComboBox(group0);
 
48
    sdlcombo->setEditable(false);
 
49
    sdllabel = new QLabel(i18nc("shutdown request origin", "&Local:"), group0);
 
50
    sdllabel->setBuddy(sdlcombo);
 
51
    sdlcombo->insertItem(SdAll, i18nc("@item:inlistbox allow shutdown", "Everybody"));
 
52
    sdlcombo->insertItem(SdRoot, i18nc("@item:inlistbox allow shutdown", "Only Root"));
 
53
    sdlcombo->insertItem(SdNone, i18nc("@item:inlistbox allow shutdown", "Nobody"));
 
54
    connect(sdlcombo, SIGNAL(activated(int)), SIGNAL(changed()));
 
55
    sdrcombo = new KComboBox(group0);
 
56
    sdrcombo->setEditable(false);
 
57
    sdrlabel = new QLabel(i18nc("shutdown request origin", "&Remote:"), group0);
 
58
    sdrlabel->setBuddy(sdrcombo);
 
59
    sdrcombo->insertItem(SdAll, i18nc("@item:inlistbox allow shutdown", "Everybody"));
 
60
    sdrcombo->insertItem(SdRoot, i18nc("@item:inlistbox allow shutdown", "Only Root"));
 
61
    sdrcombo->insertItem(SdNone, i18nc("@item:inlistbox allow shutdown", "Nobody"));
 
62
    connect(sdrcombo, SIGNAL(activated(int)), SIGNAL(changed()));
 
63
    group0->setWhatsThis(i18n(
 
64
        "Here you can select who is allowed to shutdown the computer using KDM. "
 
65
        "You can specify different values for local (console) and remote displays. "
 
66
        "Possible values are:<ul>"
 
67
        " <li><em>Everybody:</em> everybody can shutdown the computer using KDM</li>"
 
68
        " <li><em>Only root:</em> KDM will only allow shutdown after the user has "
 
69
            "entered the root password</li>"
 
70
        " <li><em>Nobody:</em> nobody can shutdown the computer using KDM</li></ul>"));
 
71
 
 
72
 
 
73
    QGroupBox *group1 = new QGroupBox(i18nc(
 
74
        "@title:group shell commands for shutdown", "Commands"), this);
 
75
 
 
76
    shutdown_lined = new KUrlRequester(group1);
 
77
    QLabel *shutdown_label = new QLabel(i18nc("command for ...", "H&alt:"), group1);
 
78
    shutdown_label->setBuddy(shutdown_lined);
 
79
    connect(shutdown_lined, SIGNAL(textChanged(const QString &)),
 
80
            SIGNAL(changed()));
 
81
    wtstr = i18n("Command to initiate the system halt. Typical value: /sbin/halt");
 
82
    shutdown_label->setWhatsThis(wtstr);
 
83
    shutdown_lined->setWhatsThis(wtstr);
 
84
 
 
85
    restart_lined = new KUrlRequester(group1);
 
86
    QLabel *restart_label = new QLabel(i18nc("command for ...", "Reb&oot:"), group1);
 
87
    restart_label->setBuddy(restart_lined);
 
88
    connect(restart_lined, SIGNAL(textChanged(const QString &)),
 
89
            SIGNAL(changed()));
 
90
    wtstr = i18n("Command to initiate the system reboot. Typical value: /sbin/reboot");
 
91
    restart_label->setWhatsThis(wtstr);
 
92
    restart_lined->setWhatsThis(wtstr);
 
93
 
 
94
 
 
95
    QGroupBox *group4 = new QGroupBox(i18nc("@title:group", "Miscellaneous"), this);
 
96
 
 
97
    bm_combo = new KBackedComboBox(group4);
 
98
    bm_combo->insertItem("None", i18nc("boot manager", "None"));
 
99
    bm_combo->insertItem("Grub", i18n("Grub"));
 
100
    bm_combo->insertItem("Grub2", i18n("Grub2"));
 
101
#if defined(__linux__) && (defined(__i386__) || defined(__amd64__))
 
102
    bm_combo->insertItem("Lilo", i18n("Lilo"));
 
103
#endif
 
104
    QLabel *bm_label = new QLabel(i18n("Boot manager:"), group4);
 
105
    bm_label->setBuddy(bm_combo);
 
106
    connect(bm_combo, SIGNAL(activated(int)), SIGNAL(changed()));
 
107
    wtstr = i18n("Enable boot options in the \"Shutdown...\" dialog.");
 
108
    bm_label->setWhatsThis(wtstr);
 
109
    bm_combo->setWhatsThis(wtstr);
 
110
 
 
111
    QBoxLayout *main = new QVBoxLayout(this);
 
112
    main->setMargin(10);
 
113
    QGridLayout *lgroup0 = new QGridLayout(group0);
 
114
    lgroup0->setSpacing(10);
 
115
    QGridLayout *lgroup1 = new QGridLayout(group1);
 
116
    lgroup1->setSpacing(10);
 
117
    QGridLayout *lgroup4 = new QGridLayout(group4);
 
118
    lgroup4->setSpacing(10);
 
119
 
 
120
    main->addWidget(group0);
 
121
    main->addWidget(group1);
 
122
    main->addWidget(group4);
 
123
    main->addStretch();
 
124
 
 
125
    lgroup0->setColumnMinimumWidth(2, KDialog::spacingHint() * 2);
 
126
    lgroup0->setColumnStretch(1, 1);
 
127
    lgroup0->setColumnStretch(4, 1);
 
128
    lgroup0->addWidget(sdllabel, 1, 0);
 
129
    lgroup0->addWidget(sdlcombo, 1, 1);
 
130
    lgroup0->addWidget(sdrlabel, 1, 3);
 
131
    lgroup0->addWidget(sdrcombo, 1, 4);
 
132
 
 
133
    lgroup1->setColumnMinimumWidth(2, KDialog::spacingHint() * 2);
 
134
    lgroup1->setColumnStretch(1, 1);
 
135
    lgroup1->setColumnStretch(4, 1);
 
136
    lgroup1->addWidget(shutdown_label, 1, 0);
 
137
    lgroup1->addWidget(shutdown_lined, 1, 1);
 
138
    lgroup1->addWidget(restart_label, 1, 3);
 
139
    lgroup1->addWidget(restart_lined, 1, 4);
 
140
 
 
141
    lgroup4->addWidget(bm_label, 1, 0);
 
142
    lgroup4->addWidget(bm_combo, 1, 1);
 
143
    lgroup4->setColumnStretch(2, 1);
 
144
 
 
145
    main->activate();
 
146
 
 
147
}
 
148
 
 
149
void KDMSessionsWidget::writeSD(KComboBox *combo, KConfigGroup group)
 
150
{
 
151
    QString what;
 
152
    switch (combo->currentIndex()) {
 
153
    case SdAll: what = "All"; break;
 
154
    case SdRoot: what = "Root"; break;
 
155
    default: what = "None"; break;
 
156
    }
 
157
    group.writeEntry("AllowShutdown", what);
 
158
}
 
159
 
 
160
void KDMSessionsWidget::save()
 
161
{
 
162
    writeSD(sdlcombo, config->group("X-:*-Core"));
 
163
 
 
164
    writeSD(sdrcombo, config->group("X-*-Core"));
 
165
 
 
166
    KConfigGroup configGrp = config->group("Shutdown");
 
167
    configGrp.writeEntry("HaltCmd", shutdown_lined->url().path(), KConfig::Persistent);
 
168
    configGrp.writeEntry("RebootCmd", restart_lined->url().path(), KConfig::Persistent);
 
169
 
 
170
    configGrp.writeEntry("BootManager", bm_combo->currentId());
 
171
}
 
172
 
 
173
void KDMSessionsWidget::readSD(KComboBox *combo, const QString &def, KConfigGroup group)
 
174
{
 
175
    QString str = group.readEntry("AllowShutdown", def);
 
176
    SdModes sdMode;
 
177
    if (str == "All")
 
178
        sdMode = SdAll;
 
179
    else if (str == "Root")
 
180
        sdMode = SdRoot;
 
181
    else
 
182
        sdMode = SdNone;
 
183
    combo->setCurrentIndex(sdMode);
 
184
}
 
185
 
 
186
void KDMSessionsWidget::load()
 
187
{
 
188
    readSD(sdlcombo, "All", config->group("X-:*-Core"));
 
189
 
 
190
    readSD(sdrcombo, "Root", config->group("X-*-Core"));
 
191
 
 
192
    KConfigGroup configGrp = config->group("Shutdown");
 
193
    restart_lined->setUrl(configGrp.readEntry("RebootCmd", REBOOT_CMD));
 
194
    shutdown_lined->setUrl(configGrp.readEntry("HaltCmd", HALT_CMD));
 
195
 
 
196
    bm_combo->setCurrentId(configGrp.readEntry("BootManager", "None"));
 
197
}
 
198
 
 
199
void KDMSessionsWidget::defaults()
 
200
{
 
201
    restart_lined->setUrl(KUrl(REBOOT_CMD));
 
202
    shutdown_lined->setUrl(KUrl(HALT_CMD));
 
203
 
 
204
    sdlcombo->setCurrentIndex(SdAll);
 
205
    sdrcombo->setCurrentIndex(SdRoot);
 
206
 
 
207
    bm_combo->setCurrentId("None");
 
208
}
 
209
 
 
210
#include "kdm-shut.moc"