2
Copyright (C) 1997-1998 Thomas Tanghus (tanghus@earthling.net)
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.
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.
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.
24
#include "kbackedcombobox.h"
30
#include <KUrlRequester>
34
#include <QGridLayout>
35
#include <QVBoxLayout>
37
extern KConfig *config;
39
KDMSessionsWidget::KDMSessionsWidget(QWidget *parent)
45
QGroupBox *group0 = new QGroupBox(i18n("Allow Shutdown"), this);
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>"));
73
QGroupBox *group1 = new QGroupBox(i18nc(
74
"@title:group shell commands for shutdown", "Commands"), this);
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 &)),
81
wtstr = i18n("Command to initiate the system halt. Typical value: /sbin/halt");
82
shutdown_label->setWhatsThis(wtstr);
83
shutdown_lined->setWhatsThis(wtstr);
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 &)),
90
wtstr = i18n("Command to initiate the system reboot. Typical value: /sbin/reboot");
91
restart_label->setWhatsThis(wtstr);
92
restart_lined->setWhatsThis(wtstr);
95
QGroupBox *group4 = new QGroupBox(i18nc("@title:group", "Miscellaneous"), this);
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"));
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);
111
QBoxLayout *main = new QVBoxLayout(this);
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);
120
main->addWidget(group0);
121
main->addWidget(group1);
122
main->addWidget(group4);
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);
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);
141
lgroup4->addWidget(bm_label, 1, 0);
142
lgroup4->addWidget(bm_combo, 1, 1);
143
lgroup4->setColumnStretch(2, 1);
149
void KDMSessionsWidget::writeSD(KComboBox *combo, KConfigGroup group)
152
switch (combo->currentIndex()) {
153
case SdAll: what = "All"; break;
154
case SdRoot: what = "Root"; break;
155
default: what = "None"; break;
157
group.writeEntry("AllowShutdown", what);
160
void KDMSessionsWidget::save()
162
writeSD(sdlcombo, config->group("X-:*-Core"));
164
writeSD(sdrcombo, config->group("X-*-Core"));
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);
170
configGrp.writeEntry("BootManager", bm_combo->currentId());
173
void KDMSessionsWidget::readSD(KComboBox *combo, const QString &def, KConfigGroup group)
175
QString str = group.readEntry("AllowShutdown", def);
179
else if (str == "Root")
183
combo->setCurrentIndex(sdMode);
186
void KDMSessionsWidget::load()
188
readSD(sdlcombo, "All", config->group("X-:*-Core"));
190
readSD(sdrcombo, "Root", config->group("X-*-Core"));
192
KConfigGroup configGrp = config->group("Shutdown");
193
restart_lined->setUrl(configGrp.readEntry("RebootCmd", REBOOT_CMD));
194
shutdown_lined->setUrl(configGrp.readEntry("HaltCmd", HALT_CMD));
196
bm_combo->setCurrentId(configGrp.readEntry("BootManager", "None"));
199
void KDMSessionsWidget::defaults()
201
restart_lined->setUrl(KUrl(REBOOT_CMD));
202
shutdown_lined->setUrl(KUrl(HALT_CMD));
204
sdlcombo->setCurrentIndex(SdAll);
205
sdrcombo->setCurrentIndex(SdRoot);
207
bm_combo->setCurrentId("None");
210
#include "kdm-shut.moc"