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.
22 #include "kbackedcombobox.h"
28 #include <KUrlRequester>
32 #include <QGridLayout>
33 #include <QVBoxLayout>
35 extern KConfig
*config
;
37 KDMSessionsWidget::KDMSessionsWidget( QWidget
*parent
)
43 QGroupBox
*group0
= new QGroupBox( i18n("Allow Shutdown"), this );
45 sdlcombo
= new KComboBox( group0
);
46 sdlcombo
->setEditable( false );
47 sdllabel
= new QLabel( i18nc("shutdown request origin", "&Local:"), group0
);
48 sdllabel
->setBuddy( sdlcombo
);
49 sdlcombo
->insertItem( SdAll
, i18nc("@item:inlistbox allow shutdown", "Everybody") );
50 sdlcombo
->insertItem( SdRoot
, i18nc("@item:inlistbox allow shutdown", "Only Root") );
51 sdlcombo
->insertItem( SdNone
, i18nc("@item:inlistbox allow shutdown", "Nobody") );
52 connect( sdlcombo
, SIGNAL(activated( int )), SIGNAL(changed()) );
53 sdrcombo
= new KComboBox( group0
);
54 sdrcombo
->setEditable( false );
55 sdrlabel
= new QLabel( i18nc("shutdown request origin", "&Remote:"), group0
);
56 sdrlabel
->setBuddy( sdrcombo
);
57 sdrcombo
->insertItem( SdAll
, i18nc("@item:inlistbox allow shutdown", "Everybody") );
58 sdrcombo
->insertItem( SdRoot
, i18nc("@item:inlistbox allow shutdown", "Only Root") );
59 sdrcombo
->insertItem( SdNone
, i18nc("@item:inlistbox allow shutdown", "Nobody") );
60 connect( sdrcombo
, SIGNAL(activated( int )), SIGNAL(changed()) );
61 group0
->setWhatsThis( i18n(
62 "Here you can select who is allowed to shutdown the computer using KDM. "
63 "You can specify different values for local (console) and remote displays. "
64 "Possible values are:<ul>"
65 " <li><em>Everybody:</em> everybody can shutdown the computer using KDM</li>"
66 " <li><em>Only root:</em> KDM will only allow shutdown after the user has "
67 "entered the root password</li>"
68 " <li><em>Nobody:</em> nobody can shutdown the computer using KDM</li></ul>") );
71 QGroupBox
*group1
= new QGroupBox( i18nc(
72 "@title:group shell commands for shutdown", "Commands"), this );
74 shutdown_lined
= new KUrlRequester( group1
);
75 QLabel
*shutdown_label
= new QLabel( i18nc("command for ...", "H&alt:"), group1
);
76 shutdown_label
->setBuddy( shutdown_lined
);
77 connect( shutdown_lined
, SIGNAL(textChanged( const QString
& )),
79 wtstr
= i18n("Command to initiate the system halt. Typical value: /sbin/halt");
80 shutdown_label
->setWhatsThis( wtstr
);
81 shutdown_lined
->setWhatsThis( wtstr
);
83 restart_lined
= new KUrlRequester( group1
);
84 QLabel
*restart_label
= new QLabel( i18nc("command for ...", "Reb&oot:"), group1
);
85 restart_label
->setBuddy( restart_lined
);
86 connect( restart_lined
, SIGNAL(textChanged( const QString
& )),
88 wtstr
= i18n("Command to initiate the system reboot. Typical value: /sbin/reboot");
89 restart_label
->setWhatsThis( wtstr
);
90 restart_lined
->setWhatsThis( wtstr
);
93 QGroupBox
*group4
= new QGroupBox( i18nc("@title:group", "Miscellaneous"), this );
95 bm_combo
= new KBackedComboBox( group4
);
96 bm_combo
->insertItem( "None", i18nc("boot manager", "None") );
97 bm_combo
->insertItem( "Grub", i18n("Grub") );
98 #if defined(__linux__) && ( defined(__i386__) || defined(__amd64__) )
99 bm_combo
->insertItem( "Lilo", i18n("Lilo") );
101 QLabel
*bm_label
= new QLabel( i18n("Boot manager:"), group4
);
102 bm_label
->setBuddy( bm_combo
);
103 connect( bm_combo
, SIGNAL(activated( int )), SIGNAL(changed()) );
104 wtstr
= i18n("Enable boot options in the \"Shutdown...\" dialog.");
105 bm_label
->setWhatsThis( wtstr
);
106 bm_combo
->setWhatsThis( wtstr
);
108 QBoxLayout
*main
= new QVBoxLayout( this );
109 main
->setMargin( 10 );
110 QGridLayout
*lgroup0
= new QGridLayout( group0
);
111 lgroup0
->setSpacing( 10 );
112 QGridLayout
*lgroup1
= new QGridLayout( group1
);
113 lgroup1
->setSpacing( 10 );
114 QGridLayout
*lgroup4
= new QGridLayout( group4
);
115 lgroup4
->setSpacing( 10 );
117 main
->addWidget( group0
);
118 main
->addWidget( group1
);
119 main
->addWidget( group4
);
122 lgroup0
->setColumnMinimumWidth( 2, KDialog::spacingHint() * 2 );
123 lgroup0
->setColumnStretch( 1, 1 );
124 lgroup0
->setColumnStretch( 4, 1 );
125 lgroup0
->addWidget( sdllabel
, 1, 0 );
126 lgroup0
->addWidget( sdlcombo
, 1, 1 );
127 lgroup0
->addWidget( sdrlabel
, 1, 3 );
128 lgroup0
->addWidget( sdrcombo
, 1, 4 );
130 lgroup1
->setColumnMinimumWidth( 2, KDialog::spacingHint() * 2 );
131 lgroup1
->setColumnStretch( 1, 1 );
132 lgroup1
->setColumnStretch( 4, 1 );
133 lgroup1
->addWidget( shutdown_label
, 1, 0 );
134 lgroup1
->addWidget( shutdown_lined
, 1, 1 );
135 lgroup1
->addWidget( restart_label
, 1, 3 );
136 lgroup1
->addWidget( restart_lined
, 1, 4 );
138 lgroup4
->addWidget( bm_label
, 1, 0 );
139 lgroup4
->addWidget( bm_combo
, 1, 1 );
140 lgroup4
->setColumnStretch( 2, 1 );
146 void KDMSessionsWidget::makeReadOnly()
148 sdlcombo
->setEnabled( false );
149 sdrcombo
->setEnabled( false );
151 restart_lined
->lineEdit()->setReadOnly( true );
152 restart_lined
->button()->setEnabled( false );
153 shutdown_lined
->lineEdit()->setReadOnly( true );
154 shutdown_lined
->button()->setEnabled( false );
156 bm_combo
->setEnabled( false );
159 void KDMSessionsWidget::writeSD( KComboBox
*combo
, KConfigGroup group
)
162 switch (combo
->currentIndex()) {
163 case SdAll
: what
= "All"; break;
164 case SdRoot
: what
= "Root"; break;
165 default: what
= "None"; break;
167 group
.writeEntry( "AllowShutdown", what
);
170 void KDMSessionsWidget::save()
172 writeSD( sdlcombo
, config
->group( "X-:*-Core" ) );
174 writeSD( sdrcombo
, config
->group( "X-*-Core" ) );
176 KConfigGroup configGrp
= config
->group( "Shutdown" );
177 configGrp
.writeEntry( "HaltCmd", shutdown_lined
->url().path(), KConfig::Persistent
);
178 configGrp
.writeEntry( "RebootCmd", restart_lined
->url().path(), KConfig::Persistent
);
180 configGrp
.writeEntry( "BootManager", bm_combo
->currentId() );
183 void KDMSessionsWidget::readSD( KComboBox
*combo
, const QString
&def
, KConfigGroup group
)
185 QString str
= group
.readEntry( "AllowShutdown", def
);
189 else if (str
== "Root")
193 combo
->setCurrentIndex( sdMode
);
196 void KDMSessionsWidget::load()
198 readSD( sdlcombo
, "All", config
->group( "X-:*-Core" ) );
200 readSD( sdrcombo
, "Root", config
->group( "X-*-Core" ) );
202 KConfigGroup configGrp
= config
->group( "Shutdown" );
203 restart_lined
->setUrl( configGrp
.readEntry( "RebootCmd", "/sbin/reboot" ) );
204 shutdown_lined
->setUrl( configGrp
.readEntry( "HaltCmd", "/sbin/halt" ) );
206 bm_combo
->setCurrentId( configGrp
.readEntry( "BootManager", "None" ) );
209 void KDMSessionsWidget::defaults()
211 restart_lined
->setUrl( KUrl( "/sbin/reboot" ) );
212 shutdown_lined
->setUrl( KUrl( "/sbin/halt" ) );
214 sdlcombo
->setCurrentIndex( SdAll
);
215 sdrcombo
->setCurrentIndex( SdRoot
);
217 bm_combo
->setCurrentId( "None" );
220 #include "kdm-shut.moc"