55
55
int KDMShutdownBase::curPlugin = -1;
56
56
PluginList KDMShutdownBase::pluginList;
58
KDMShutdownBase::KDMShutdownBase( int _uid, QWidget *_parent )
59
: inherited( _parent )
60
, box( new QVBoxLayout( this ) )
58
KDMShutdownBase::KDMShutdownBase(int _uid, QWidget *_parent)
60
, box(new QVBoxLayout(this))
75
75
KDMShutdownBase::~KDMShutdownBase()
82
KDMShutdownBase::complete( QWidget *prevWidget )
82
KDMShutdownBase::complete(QWidget *prevWidget)
84
QSizePolicy fp( QSizePolicy::Fixed, QSizePolicy::Fixed );
87
((willShut && _allowShutdown == SHUT_ROOT) ||
88
(mayNuke && _allowNuke == SHUT_ROOT)))
90
rootlab = new QLabel( i18n("Root authorization required."), this );
91
box->addWidget( rootlab );
94
pluginList = KGVerify::init( _pluginsShutdown );
96
verify = new KGStdVerify( this, this,
98
pluginList, KGreeterPlugin::Authenticate,
99
KGreeterPlugin::Shutdown );
100
verify->selectPlugin( curPlugin );
101
box->addLayout( verify->getLayout() );
102
QAction *action = new QAction( this );
103
action->setShortcut( Qt::ALT+Qt::Key_A );
104
connect( action, SIGNAL(triggered( bool )), SLOT(slotActivatePlugMenu()) );
107
box->addWidget( new KSeparator( Qt::Horizontal, this ) );
109
QBoxLayout *hlay = new QHBoxLayout();
110
box->addLayout( hlay );
111
hlay->addStretch( 1 );
113
okButton = new KPushButton( KStandardGuiItem::ok(), this );
114
okButton->setSizePolicy( fp );
115
okButton->setDefault( true );
116
hlay->addWidget( okButton );
117
hlay->addStretch( 1 );
118
connect( okButton, SIGNAL(clicked()), SLOT(accept()) );
121
KPushButton *schedButton =
122
new KPushButton( KGuiItem( i18nc("@action:inmenu verb", "&Schedule...") ), this );
123
schedButton->setSizePolicy( fp );
124
hlay->addWidget( schedButton );
125
hlay->addStretch( 1 );
126
connect( schedButton, SIGNAL(clicked()), SLOT(slotSched()) );
128
cancelButton = new KPushButton( KStandardGuiItem::cancel(), this );
129
cancelButton->setSizePolicy( fp );
131
cancelButton->setDefault( true );
132
hlay->addWidget( cancelButton );
133
hlay->addStretch( 1 );
134
connect( cancelButton, SIGNAL(clicked()), SLOT(reject()) );
139
layout()->activate();
84
QSizePolicy fp(QSizePolicy::Fixed, QSizePolicy::Fixed);
87
((willShut && _allowShutdown == SHUT_ROOT) ||
88
(mayNuke && _allowNuke == SHUT_ROOT)))
90
rootlab = new QLabel(i18n("Root authorization required."), this);
91
box->addWidget(rootlab);
94
pluginList = KGVerify::init(_pluginsShutdown);
96
verify = new KGStdVerify(this, this,
98
pluginList, KGreeterPlugin::Authenticate,
99
KGreeterPlugin::Shutdown);
100
verify->selectPlugin(curPlugin);
101
box->addLayout(verify->getLayout());
102
QAction *action = new QAction(this);
103
action->setShortcut(Qt::ALT + Qt::Key_A);
104
connect(action, SIGNAL(triggered(bool)), SLOT(slotActivatePlugMenu()));
107
box->addWidget(new KSeparator(Qt::Horizontal, this));
109
QBoxLayout *hlay = new QHBoxLayout();
110
box->addLayout(hlay);
113
okButton = new KPushButton(KStandardGuiItem::ok(), this);
114
okButton->setSizePolicy(fp);
115
okButton->setDefault(true);
116
hlay->addWidget(okButton);
118
connect(okButton, SIGNAL(clicked()), SLOT(accept()));
121
KPushButton *schedButton =
122
new KPushButton(KGuiItem(i18nc("@action:inmenu verb", "&Schedule...")), this);
123
schedButton->setSizePolicy(fp);
124
hlay->addWidget(schedButton);
126
connect(schedButton, SIGNAL(clicked()), SLOT(slotSched()));
128
cancelButton = new KPushButton(KStandardGuiItem::cancel(), this);
129
cancelButton->setSizePolicy(fp);
131
cancelButton->setDefault(true);
132
hlay->addWidget(cancelButton);
134
connect(cancelButton, SIGNAL(clicked()), SLOT(reject()));
139
layout()->activate();
143
143
KDMShutdownBase::slotActivatePlugMenu()
146
QMenu *cmnu = verify->getPlugMenu();
149
QSize sh( cmnu->sizeHint() / 2 );
150
cmnu->exec( geometry().center() - QPoint( sh.width(), sh.height() ) );
146
QMenu *cmnu = verify->getPlugMenu();
149
QSize sh(cmnu->sizeHint() / 2);
150
cmnu->exec(geometry().center() - QPoint(sh.width(), sh.height()));
155
155
KDMShutdownBase::accept()
164
164
KDMShutdownBase::slotSched()
170
170
KDMShutdownBase::updateNeedRoot()
172
int nNeedRoot = uid &&
173
(((willShut && _allowShutdown == SHUT_ROOT) ||
174
(_allowNuke == SHUT_ROOT && doesNuke)));
175
if (verify && nNeedRoot != needRoot) {
178
needRoot = nNeedRoot;
179
rootlab->setEnabled( needRoot );
180
verify->setEnabled( needRoot );
172
int nNeedRoot = uid &&
173
(((willShut && _allowShutdown == SHUT_ROOT) ||
174
(_allowNuke == SHUT_ROOT && doesNuke)));
175
if (verify && nNeedRoot != needRoot) {
178
needRoot = nNeedRoot;
179
rootlab->setEnabled(needRoot);
180
verify->setEnabled(needRoot);
187
187
KDMShutdownBase::accepted()
189
inherited::done( needRoot ? (int)Authed : (int)Accepted );
189
inherited::done(needRoot ? (int)Authed : (int)Accepted);
193
KDMShutdownBase::verifyPluginChanged( int id )
193
KDMShutdownBase::verifyPluginChanged(int id)
200
200
KDMShutdownBase::verifyOk()
206
206
KDMShutdownBase::verifyFailed()
208
okButton->setEnabled( false );
209
cancelButton->setEnabled( false );
208
okButton->setEnabled(false);
209
cancelButton->setEnabled(false);
213
213
KDMShutdownBase::verifyRetry()
215
okButton->setEnabled( true );
216
cancelButton->setEnabled( true );
215
okButton->setEnabled(true);
216
cancelButton->setEnabled(true);
220
KDMShutdownBase::verifySetUser( const QString & )
220
KDMShutdownBase::verifySetUser(const QString &)
226
doShutdown( int type, const QString &os )
226
doShutdown(int type, const QString &os)
229
gSendInt( G_Shutdown );
233
gSendInt( SHUT_FORCE );
234
gSendInt( 0 ); /* irrelevant, will timeout immediately anyway */
235
gSendStr( os.toUtf8().data() );
229
gSendInt(G_Shutdown);
233
gSendInt(SHUT_FORCE);
234
gSendInt(0); /* irrelevant, will timeout immediately anyway */
235
gSendStr(os.toUtf8().data());
241
getBootOptions( QStringList *options, int *defaultTarget, int *oldTarget )
241
getBootOptions(QStringList *options, int *defaultTarget, int *oldTarget)
245
gSendInt( G_ListBootOpts );
246
if (gRecvInt() == BO_OK) {
247
*options = qStringList( gRecvStrArr( 0 ) );
248
*defaultTarget = gRecvInt();
249
*oldTarget = gRecvInt();
245
gSendInt(G_ListBootOpts);
246
if (gRecvInt() == BO_OK) {
247
*options = qStringList(gRecvStrArr(0));
248
*defaultTarget = gRecvInt();
249
*oldTarget = gRecvInt();
256
KDMShutdown::KDMShutdown( int _uid, QWidget *_parent )
257
: inherited( _uid, _parent )
256
KDMShutdown::KDMShutdown(int _uid, QWidget *_parent)
257
: inherited(_uid, _parent)
259
QSizePolicy fp( QSizePolicy::Fixed, QSizePolicy::Fixed );
261
QHBoxLayout *hlay = new QHBoxLayout();
262
box->addLayout( hlay );
264
howGroup = new QGroupBox( i18n("Shutdown Type"), this );
265
hlay->addWidget( howGroup, 0, Qt::AlignTop );
268
rb = new KDMRadioButton( i18n("&Turn off computer"), howGroup );
269
rb->setChecked( true );
272
restart_rb = new KDMRadioButton( i18n("&Restart computer"), howGroup );
274
QBoxLayout *hwlay = new QVBoxLayout( howGroup );
275
hwlay->addWidget( rb );
276
hwlay->addWidget( restart_rb );
278
connect( rb, SIGNAL(doubleClicked()), SLOT(accept()) );
279
connect( restart_rb, SIGNAL(doubleClicked()), SLOT(accept()) );
283
if (getBootOptions( &options, &defaultTarget, &oldTarget )) { /* XXX show dialog on failure */
284
targets = new QComboBox();
285
targets->addItems( options );
286
targets->setCurrentIndex( oldTarget == -1 ? defaultTarget : oldTarget );
287
QHBoxLayout *hb = new QHBoxLayout();
288
hwlay->addLayout( hb );
290
style()->pixelMetric( QStyle::PM_ExclusiveIndicatorWidth )
292
hb->addWidget( targets );
293
connect( targets, SIGNAL(activated( int )), SLOT(slotTargetChanged()) );
296
howGroup->setSizePolicy( fp );
298
schedGroup = new QGroupBox( i18nc("@title:group ... of shutdown", "Scheduling"), this );
299
hlay->addWidget( schedGroup, 0, Qt::AlignTop );
301
le_start = new QLineEdit( schedGroup );
302
QLabel *lab1 = new QLabel( i18n("&Start:"), schedGroup );
303
lab1->setBuddy( le_start );
305
le_timeout = new QLineEdit( schedGroup );
306
QLabel *lab2 = new QLabel( i18n("T&imeout:"), schedGroup );
307
lab2->setBuddy( le_timeout );
309
cb_force = new QCheckBox( i18n("&Force after timeout"), schedGroup );
310
if (_allowNuke != SHUT_NONE) {
311
connect( cb_force, SIGNAL(clicked()), SLOT(slotWhenChanged()) );
314
cb_force->setEnabled( false );
316
QGridLayout *grid = new QGridLayout( schedGroup );
317
grid->addWidget( lab1, 0, 0, Qt::AlignRight );
318
grid->addWidget( le_start, 0, 1 );
319
grid->addWidget( lab2, 1, 0, Qt::AlignRight );
320
grid->addWidget( le_timeout, 1, 1 );
321
grid->addWidget( cb_force, 2, 0, 1, 2 );
323
schedGroup->setSizePolicy( fp );
325
le_start->setText( "0" );
326
if (_defSdMode == SHUT_SCHEDULE)
327
le_timeout->setText( "-1" );
329
le_timeout->setText( "0" );
330
if (_defSdMode == SHUT_FORCENOW && cb_force->isEnabled())
331
cb_force->setChecked( true );
334
complete( schedGroup );
259
QSizePolicy fp(QSizePolicy::Fixed, QSizePolicy::Fixed);
261
QHBoxLayout *hlay = new QHBoxLayout();
262
box->addLayout(hlay);
264
howGroup = new QGroupBox(i18n("Shutdown Type"), this);
265
hlay->addWidget(howGroup, 0, Qt::AlignTop);
268
rb = new KDMRadioButton(i18n("&Turn off computer"), howGroup);
269
rb->setChecked(true);
272
restart_rb = new KDMRadioButton(i18n("&Restart computer"), howGroup);
274
QBoxLayout *hwlay = new QVBoxLayout(howGroup);
275
hwlay->addWidget(rb);
276
hwlay->addWidget(restart_rb);
278
connect(rb, SIGNAL(doubleClicked()), SLOT(accept()));
279
connect(restart_rb, SIGNAL(doubleClicked()), SLOT(accept()));
283
if (getBootOptions(&options, &defaultTarget, &oldTarget)) { /* XXX show dialog on failure */
284
targets = new QComboBox();
285
targets->addItems(options);
286
targets->setCurrentIndex(oldTarget == -1 ? defaultTarget : oldTarget);
287
QHBoxLayout *hb = new QHBoxLayout();
288
hwlay->addLayout(hb);
290
style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth)
292
hb->addWidget(targets);
293
connect(targets, SIGNAL(activated(int)), SLOT(slotTargetChanged()));
296
howGroup->setSizePolicy(fp);
298
schedGroup = new QGroupBox(i18nc("@title:group ... of shutdown", "Scheduling"), this);
299
hlay->addWidget(schedGroup, 0, Qt::AlignTop);
301
le_start = new QLineEdit(schedGroup);
302
QLabel *lab1 = new QLabel(i18n("&Start:"), schedGroup);
303
lab1->setBuddy(le_start);
305
le_timeout = new QLineEdit(schedGroup);
306
QLabel *lab2 = new QLabel(i18n("T&imeout:"), schedGroup);
307
lab2->setBuddy(le_timeout);
309
cb_force = new QCheckBox(i18n("&Force after timeout"), schedGroup);
310
if (_allowNuke != SHUT_NONE) {
311
connect(cb_force, SIGNAL(clicked()), SLOT(slotWhenChanged()));
314
cb_force->setEnabled(false);
317
QGridLayout *grid = new QGridLayout(schedGroup);
318
grid->addWidget(lab1, 0, 0, Qt::AlignRight);
319
grid->addWidget(le_start, 0, 1);
320
grid->addWidget(lab2, 1, 0, Qt::AlignRight);
321
grid->addWidget(le_timeout, 1, 1);
322
grid->addWidget(cb_force, 2, 0, 1, 2);
324
schedGroup->setSizePolicy(fp);
326
le_start->setText("0");
327
if (_defSdMode == SHUT_SCHEDULE) {
328
le_timeout->setText("-1");
330
le_timeout->setText("0");
331
if (_defSdMode == SHUT_FORCENOW && cb_force->isEnabled())
332
cb_force->setChecked(true);
335
complete(schedGroup);
338
getDate( const char *str )
339
getDate(const char *str)
341
prc.setOutputChannelMode( KProcess::OnlyStdoutChannel );
342
prc << "/bin/date" << "+%s" << "-d" << str;
345
return prc.readAll().simplified().toInt();
342
prc.setOutputChannelMode(KProcess::OnlyStdoutChannel);
343
prc << "/bin/date" << "+%s" << "-d" << str;
346
return prc.readAll().simplified().toInt();
349
350
KDMShutdown::accept()
351
if (le_start->text() == "0" || le_start->text() == "now")
353
else if (le_start->text()[0] == '+')
354
sch_st = time( 0 ) + le_start->text().toInt();
355
else if ((sch_st = getDate( le_start->text().toLatin1() )) < 0) {
356
KFMsgBox::box( this, errorbox, i18n("Entered start date is invalid.") );
357
le_start->setFocus();
360
if (le_timeout->text() == "-1" || le_timeout->text().startsWith( "inf" ))
362
else if (le_timeout->text()[0] == '+')
363
sch_to = sch_st + le_timeout->text().toInt();
364
else if ((sch_to = getDate( le_timeout->text().toLatin1() )) < 0) {
365
KFMsgBox::box( this, errorbox, i18n("Entered timeout date is invalid.") );
366
le_timeout->setFocus();
352
if (le_start->text() == "0" || le_start->text() == "now") {
354
} else if (le_start->text()[0] == '+') {
355
sch_st = time(0) + le_start->text().toInt();
356
} else if ((sch_st = getDate(le_start->text().toLatin1())) < 0) {
357
KFMsgBox::box(this, errorbox, i18n("Entered start date is invalid."));
358
le_start->setFocus();
361
if (le_timeout->text() == "-1" || le_timeout->text().startsWith("inf")) {
363
} else if (le_timeout->text()[0] == '+') {
364
sch_to = sch_st + le_timeout->text().toInt();
365
} else if ((sch_to = getDate(le_timeout->text().toLatin1())) < 0) {
366
KFMsgBox::box(this, errorbox, i18n("Entered timeout date is invalid."));
367
le_timeout->setFocus();
374
375
KDMShutdown::slotTargetChanged()
376
restart_rb->setChecked( true );
377
restart_rb->setChecked(true);
380
381
KDMShutdown::slotWhenChanged()
382
doesNuke = cb_force->isChecked();
383
doesNuke = cb_force->isChecked();
387
388
KDMShutdown::accepted()
390
gSendInt( G_Shutdown );
391
gSendInt( restart_rb->isChecked() ? SHUT_REBOOT : SHUT_HALT );
394
gSendInt( cb_force->isChecked() ? SHUT_FORCE : SHUT_CANCEL );
395
gSendInt( _allowShutdown == SHUT_ROOT ? 0 : -2 );
396
gSendStr( (restart_rb->isChecked() &&
397
targets && targets->currentIndex() != oldTarget) ?
398
targets->currentText().toLocal8Bit().data() : 0 );
400
inherited::accepted();
404
KDMShutdown::scheduleShutdown( QWidget *_parent )
407
gSendInt( G_QueryShutdown );
408
int how = gRecvInt();
409
int start = gRecvInt();
410
int timeout = gRecvInt();
411
int force = gRecvInt();
412
int uid = gRecvInt();
413
char *os = gRecvStr();
417
KDMCancelShutdown( how, start, timeout, force, uid, os,
422
uid = ret == Authed ? 0 : -1;
426
KDMShutdown( uid, _parent ).exec();
430
KDMRadioButton::KDMRadioButton( const QString &label, QWidget *parent )
431
: inherited( label, parent )
436
KDMRadioButton::mouseDoubleClickEvent( QMouseEvent * )
438
emit doubleClicked();
442
KDMDelayedPushButton::KDMDelayedPushButton( const KGuiItem &item,
444
: inherited( item, parent )
446
popt.setSingleShot( true );
447
popt.setInterval( style()->styleHint( QStyle::SH_ToolButton_PopupDelay, 0, this ) );
450
void KDMDelayedPushButton::setDelayedMenu( QMenu *p )
453
disconnect( this, 0, this, 0 ); // Internal button -> popup connection
455
connect( this, SIGNAL(pressed()), &popt, SLOT(start()) );
456
connect( this, SIGNAL(released()), &popt, SLOT(stop()) );
457
connect( &popt, SIGNAL(timeout()), SLOT(showMenu()) );
461
KDMSlimShutdown::KDMSlimShutdown( QWidget *_parent )
462
: inherited( _parent )
464
QHBoxLayout *hbox = new QHBoxLayout( this );
466
QFrame *lfrm = new QFrame( this );
467
hbox->addWidget( lfrm, Qt::AlignCenter );
468
QLabel *icon = new QLabel( lfrm );
469
icon->setPixmap( QPixmap( KStandardDirs::locate( "data", "kdm/pics/shutdown.png" ) ) );
470
icon->setFixedSize( icon->sizeHint() );
471
lfrm->setFixedSize( icon->sizeHint() );
473
QVBoxLayout *buttonlay = new QVBoxLayout();
474
hbox->addLayout( buttonlay );
476
buttonlay->addStretch( 1 );
478
KPushButton *btnHalt = new
479
KPushButton( KGuiItem( i18n("&Turn Off Computer"), "system-shutdown" ), this );
480
buttonlay->addWidget( btnHalt );
481
connect( btnHalt, SIGNAL(clicked()), SLOT(slotHalt()) );
483
buttonlay->addSpacing( KDialog::spacingHint() );
485
KDMDelayedPushButton *btnReboot = new
486
KDMDelayedPushButton( KGuiItem( i18n("&Restart Computer"), "system-reboot" ), this );
487
buttonlay->addWidget( btnReboot );
488
connect( btnReboot, SIGNAL(clicked()), SLOT(slotReboot()) );
491
if (getBootOptions( &targetList, &dummy, &cur )) {
492
QMenu *targets = new QMenu( this );
493
for (int i = 0; i < targetList.size(); i++)
494
(targets->addAction( i == cur ?
495
i18nc( "current option in boot loader",
496
"%1 (current)", targetList[i] ) :
497
targetList[i] ))->setData( i );
498
btnReboot->setDelayedMenu( targets );
499
connect( targets, SIGNAL(triggered( QAction * )),
500
SLOT(slotReboot( QAction * )) );
503
buttonlay->addStretch( 1 );
505
if (_scheduledSd != SHUT_NEVER) {
506
KPushButton *btnSched = new
507
KPushButton( KGuiItem( i18nc("@action:button verb", "&Schedule...") ), this );
508
buttonlay->addWidget( btnSched );
509
connect( btnSched, SIGNAL(clicked()), SLOT(slotSched()) );
511
buttonlay->addStretch( 1 );
514
buttonlay->addWidget( new KSeparator( this ) );
516
buttonlay->addSpacing( 0 );
518
KPushButton *btnBack = new KPushButton( KStandardGuiItem::cancel(), this );
519
buttonlay->addWidget( btnBack );
520
connect( btnBack, SIGNAL(clicked()), SLOT(reject()) );
522
buttonlay->addSpacing( KDialog::spacingHint() );
391
gSendInt(G_Shutdown);
392
gSendInt(restart_rb->isChecked() ? SHUT_REBOOT : SHUT_HALT);
395
gSendInt(cb_force->isChecked() ? SHUT_FORCE : SHUT_CANCEL);
396
gSendInt(_allowShutdown == SHUT_ROOT ? 0 : -2);
397
gSendStr((restart_rb->isChecked() &&
398
targets && targets->currentIndex() != oldTarget) ?
399
targets->currentText().toLocal8Bit().data() : 0);
401
inherited::accepted();
405
KDMShutdown::scheduleShutdown(QWidget *_parent)
408
gSendInt(G_QueryShutdown);
409
int how = gRecvInt();
410
int start = gRecvInt();
411
int timeout = gRecvInt();
412
int force = gRecvInt();
413
int uid = gRecvInt();
414
char *os = gRecvStr();
418
KDMCancelShutdown(how, start, timeout, force, uid, os,
423
uid = ret == Authed ? 0 : -1;
428
KDMShutdown(uid, _parent).exec();
432
KDMRadioButton::KDMRadioButton(const QString &label, QWidget *parent)
433
: inherited(label, parent)
438
KDMRadioButton::mouseDoubleClickEvent(QMouseEvent *)
440
emit doubleClicked();
444
KDMDelayedPushButton::KDMDelayedPushButton(const KGuiItem &item, QWidget *parent)
445
: inherited(item, parent)
447
popt.setSingleShot(true);
448
popt.setInterval(style()->styleHint(QStyle::SH_ToolButton_PopupDelay, 0, this));
451
void KDMDelayedPushButton::setDelayedMenu(QMenu *p)
454
disconnect(this, 0, this, 0); // Internal button -> popup connection
456
connect(this, SIGNAL(pressed()), &popt, SLOT(start()));
457
connect(this, SIGNAL(released()), &popt, SLOT(stop()));
458
connect(&popt, SIGNAL(timeout()), SLOT(showMenu()));
462
KDMSlimShutdown::KDMSlimShutdown(QWidget *_parent)
465
QHBoxLayout *hbox = new QHBoxLayout(this);
467
QFrame *lfrm = new QFrame(this);
468
hbox->addWidget(lfrm, Qt::AlignCenter);
469
QLabel *icon = new QLabel(lfrm);
470
icon->setPixmap(QPixmap(KStandardDirs::locate("data", "kdm/pics/shutdown.png")));
471
icon->setFixedSize(icon->sizeHint());
472
lfrm->setFixedSize(icon->sizeHint());
474
QVBoxLayout *buttonlay = new QVBoxLayout();
475
hbox->addLayout(buttonlay);
477
buttonlay->addStretch(1);
479
KPushButton *btnHalt = new
480
KPushButton(KGuiItem(i18n("&Turn Off Computer"), "system-shutdown"), this);
481
buttonlay->addWidget(btnHalt);
482
connect(btnHalt, SIGNAL(clicked()), SLOT(slotHalt()));
484
buttonlay->addSpacing(KDialog::spacingHint());
486
KDMDelayedPushButton *btnReboot = new
487
KDMDelayedPushButton(KGuiItem(i18n("&Restart Computer"), "system-reboot"), this);
488
buttonlay->addWidget(btnReboot);
489
connect(btnReboot, SIGNAL(clicked()), SLOT(slotReboot()));
492
if (getBootOptions(&targetList, &dummy, &cur)) {
493
QMenu *targets = new QMenu(this);
494
for (int i = 0; i < targetList.size(); i++)
495
(targets->addAction(i == cur ?
496
i18nc("current option in boot loader",
497
"%1 (current)", targetList[i]) :
498
targetList[i]))->setData(i);
499
btnReboot->setDelayedMenu(targets);
500
connect(targets, SIGNAL(triggered(QAction *)),
501
SLOT(slotReboot(QAction *)));
504
buttonlay->addStretch(1);
506
if (_scheduledSd != SHUT_NEVER) {
507
KPushButton *btnSched = new
508
KPushButton(KGuiItem(i18nc("@action:button verb", "&Schedule...")), this);
509
buttonlay->addWidget(btnSched);
510
connect(btnSched, SIGNAL(clicked()), SLOT(slotSched()));
512
buttonlay->addStretch(1);
515
buttonlay->addWidget(new KSeparator(this));
517
buttonlay->addSpacing(0);
519
KPushButton *btnBack = new KPushButton(KStandardGuiItem::cancel(), this);
520
buttonlay->addWidget(btnBack);
521
connect(btnBack, SIGNAL(clicked()), SLOT(reject()));
523
buttonlay->addSpacing(KDialog::spacingHint());
526
527
KDMSlimShutdown::slotSched()
529
KDMShutdown::scheduleShutdown();
530
KDMShutdown::scheduleShutdown();
533
534
KDMSlimShutdown::slotHalt()
535
if (checkShutdown( SHUT_HALT, 0 ))
536
doShutdown( SHUT_HALT, 0 );
536
if (checkShutdown(SHUT_HALT, 0))
537
doShutdown(SHUT_HALT, 0);
540
541
KDMSlimShutdown::slotReboot()
542
if (checkShutdown( SHUT_REBOOT, 0 ))
543
doShutdown( SHUT_REBOOT, 0 );
543
if (checkShutdown(SHUT_REBOOT, 0))
544
doShutdown(SHUT_REBOOT, 0);
547
KDMSlimShutdown::slotReboot( QAction *action )
548
KDMSlimShutdown::slotReboot(QAction *action)
549
int opt = action->data().toInt();
550
if (checkShutdown( SHUT_REBOOT, targetList[opt] ))
551
doShutdown( SHUT_REBOOT, targetList[opt] );
550
int opt = action->data().toInt();
551
if (checkShutdown(SHUT_REBOOT, targetList[opt]))
552
doShutdown(SHUT_REBOOT, targetList[opt]);
555
KDMSlimShutdown::checkShutdown( int type, const QString &os )
556
KDMSlimShutdown::checkShutdown(int type, const QString &os)
558
QList<DpySpec> sess = fetchSessions( lstRemote | lstTTY );
559
if (sess.isEmpty() && _allowShutdown != SHUT_ROOT)
561
int ret = KDMConfShutdown( -1, sess, type, os ).exec();
562
if (ret == Schedule) {
563
KDMShutdown::scheduleShutdown();
559
QList<DpySpec> sess = fetchSessions(lstRemote | lstTTY);
560
if (sess.isEmpty() && _allowShutdown != SHUT_ROOT)
562
int ret = KDMConfShutdown(-1, sess, type, os).exec();
563
if (ret == Schedule) {
564
KDMShutdown::scheduleShutdown();
570
KDMSlimShutdown::externShutdown( int type, const QString &os, int uid, bool ask )
572
QList<DpySpec> sess = fetchSessions( lstRemote | lstTTY );
573
if (ask || !sess.isEmpty() || (uid && _allowShutdown == SHUT_ROOT)) {
574
int ret = KDMConfShutdown( uid, sess, type, os ).exec();
575
if (ret == Schedule) {
576
KDMShutdown( uid ).exec();
582
doShutdown( type, os );
585
#define SHUT_CONSOLE_HELP I18N_NOOP( \
586
"<br/>Switching to console mode will terminate all local X servers and" \
587
" leave you with console logins only. Graphical mode is automatically" \
588
" resumed 10 seconds after the last console session ends or after" \
589
" 40 seconds if no-one logs in in the first place.<br/>")
591
KDMConfShutdown::KDMConfShutdown( int _uid, const QList<DpySpec> &sessions, int type,
592
const QString &os, QWidget *_parent )
593
: inherited( _uid, _parent )
596
if (type == SHUT_CONSOLE)
599
QLabel *lbl = new QLabel( QString( "<qt><center><b><nobr>"
601
"</nobr></b></center>"
606
.arg( (type == SHUT_HALT) ?
607
i18n("Turn Off Computer") :
609
(type == SHUT_CONSOLE) ?
610
i18n("Switch to Console") :
612
i18n("Restart Computer") )
613
.arg( !os.isEmpty() ?
614
i18n("<br/>(Next boot: %1)", os ) :
617
.arg( (type == SHUT_CONSOLE) ?
618
i18n(SHUT_CONSOLE_HELP) :
622
lbl->setWordWrap( true );
623
box->addWidget( lbl );
625
if (!sessions.isEmpty()) {
626
if (willShut && _scheduledSd != SHUT_NEVER)
628
mayNuke = doesNuke = true;
629
if (_allowNuke == SHUT_NONE)
631
QLabel *lab = new QLabel( mayOk ?
632
i18n("Abort active sessions:") :
633
i18n("No permission to abort active sessions:"),
635
box->addWidget( lab );
636
QTreeWidget *lv = new QTreeWidget( this );
637
lv->setRootIsDecorated( false );
638
lv->setSelectionMode( QAbstractItemView::NoSelection );
639
lv->setAllColumnsShowFocus( true );
640
lv->setUniformRowHeights( true );
641
lv->setEditTriggers( QAbstractItemView::NoEditTriggers );
642
lv->setColumnCount( 2 );
643
lv->setHeaderLabels( QStringList()
644
<< i18nc("@title:column", "Session")
645
<< i18nc("@title:column ... of session", "Location") );
648
foreach (const DpySpec &sess, sessions) {
649
decodeSession( sess, user, loc );
650
new QTreeWidgetItem( lv, QStringList() << user << loc );
653
int fw = lv->frameWidth() * 2;
654
int hh = lv->header()->sizeHint().height();
655
int ih = lv->itemDelegate()->sizeHint(
656
QStyleOptionViewItem(), lv->model()->index( 0, 0 ) ).height();
657
lv->setFixedHeight( fw + hh + ih * (ns < 3 ? 3 : ns > 10 ? 10 : ns) );
658
box->addWidget( lv );
661
for (int i = 0; i < 2; i++)
662
cw[i] = qMax( static_cast<QAbstractItemView *>(lv)->sizeHintForColumn( i ),
663
lv->header()->sectionSizeHint( i ) );
664
int w = lv->maximumViewportSize().width(), w2 = w / 2;
665
int m = (w < cw[0] + cw[1]) ?
666
(cw[0] + (w - cw[1])) / 2 :
667
(cw[0] > w2) ? cw[0] : (cw[1] > w2) ? (w - cw[1]) : w2;
668
lv->header()->resizeSection( 0, m );
674
KDMCancelShutdown::KDMCancelShutdown( int how, int start, int timeout,
675
int force, int uid, const QString &os,
677
: inherited( -1, _parent )
679
if (force == SHUT_FORCE) {
680
if (_allowNuke == SHUT_NONE)
682
else if (_allowNuke == SHUT_ROOT)
683
mayNuke = doesNuke = true;
685
QLabel *lab = new QLabel( mayOk ?
686
i18n("Cancel pending shutdown:") :
687
i18n("No permission to cancel pending shutdown:"),
689
box->addWidget( lab );
692
if (start < time( 0 ))
693
strt = i18nc("start of shutdown:", "now");
695
qdt.setTime_t( start );
696
strt = qdt.toString( Qt::LocalDate );
698
if (timeout == TO_INF)
699
end = i18nc("timeout of shutdown:", "infinite");
701
qdt.setTime_t( timeout );
702
end = qdt.toString( Qt::LocalDate );
710
i18nc("owner of shutdown:", "console user") :
712
i18nc("owner of shutdown:", "control socket") :
713
KUser( uid ).loginName() ,
715
i18n("turn off computer") :
716
i18n("restart computer") ,
719
i18n("\nNext boot: %1", os ) :
721
if (timeout != TO_INF)
722
trg += i18n("\nAfter timeout: %1",
723
force == SHUT_FORCE ?
724
i18nc("after timeout:", "abort all sessions") :
725
force == SHUT_FORCEMY ?
726
i18nc("after timeout:", "abort own sessions") :
727
i18nc("after timeout:", "cancel shutdown") );
728
lab = new QLabel( trg, this );
729
box->addWidget( lab );
571
KDMSlimShutdown::externShutdown(int type, const QString &os, int uid, bool ask)
573
QList<DpySpec> sess = fetchSessions(lstRemote | lstTTY);
574
if (ask || !sess.isEmpty() || (uid && _allowShutdown == SHUT_ROOT)) {
575
int ret = KDMConfShutdown(uid, sess, type, os).exec();
576
if (ret == Schedule) {
577
KDMShutdown(uid).exec();
583
doShutdown(type, os);
586
#define SHUT_CONSOLE_HELP I18N_NOOP(\
587
"<br/>Switching to console mode will terminate all local X servers and" \
588
" leave you with console logins only. Graphical mode is automatically" \
589
" resumed 10 seconds after the last console session ends or after" \
590
" 40 seconds if no-one logs in in the first place.<br/>")
592
KDMConfShutdown::KDMConfShutdown(int _uid, const QList<DpySpec> &sessions, int type,
593
const QString &os, QWidget *_parent)
594
: inherited(_uid, _parent)
597
if (type == SHUT_CONSOLE)
600
QLabel *lbl = new QLabel(QString("<qt><center><b><nobr>"
602
"</nobr></b></center>"
607
.arg((type == SHUT_HALT) ?
608
i18n("Turn Off Computer") :
610
(type == SHUT_CONSOLE) ?
611
i18n("Switch to Console") :
613
i18n("Restart Computer"))
615
i18n("<br/>(Next boot: %1)", os) :
618
.arg((type == SHUT_CONSOLE) ?
619
i18n(SHUT_CONSOLE_HELP) :
623
lbl->setWordWrap(true);
626
if (!sessions.isEmpty()) {
627
if (willShut && _scheduledSd != SHUT_NEVER)
629
mayNuke = doesNuke = true;
630
if (_allowNuke == SHUT_NONE)
632
QLabel *lab = new QLabel(mayOk ?
633
i18n("Abort active sessions:") :
634
i18n("No permission to abort active sessions:"),
637
QTreeWidget *lv = new QTreeWidget(this);
638
lv->setRootIsDecorated(false);
639
lv->setSelectionMode(QAbstractItemView::NoSelection);
640
lv->setAllColumnsShowFocus(true);
641
lv->setUniformRowHeights(true);
642
lv->setEditTriggers(QAbstractItemView::NoEditTriggers);
643
lv->setColumnCount(2);
644
lv->setHeaderLabels(QStringList()
645
<< i18nc("@title:column", "Session")
646
<< i18nc("@title:column ... of session", "Location"));
649
foreach (const DpySpec &sess, sessions) {
650
decodeSession(sess, user, loc);
651
new QTreeWidgetItem(lv, QStringList() << user << loc);
654
int fw = lv->frameWidth() * 2;
655
int hh = lv->header()->sizeHint().height();
656
int ih = lv->itemDelegate()->sizeHint(
657
QStyleOptionViewItem(), lv->model()->index(0, 0)).height();
658
lv->setFixedHeight(fw + hh + ih * (ns < 3 ? 3 : ns > 10 ? 10 : ns));
662
for (int i = 0; i < 2; i++)
663
cw[i] = qMax(static_cast<QAbstractItemView *>(lv)->sizeHintForColumn(i),
664
lv->header()->sectionSizeHint(i));
665
int w = lv->maximumViewportSize().width(), w2 = w / 2;
666
int m = (w < cw[0] + cw[1]) ?
667
(cw[0] + (w - cw[1])) / 2 :
668
(cw[0] > w2) ? cw[0] : (cw[1] > w2) ? (w - cw[1]) : w2;
669
lv->header()->resizeSection(0, m);
676
KDMCancelShutdown::KDMCancelShutdown(int how, int start, int timeout,
677
int force, int uid, const QString &os,
679
: inherited(-1, _parent)
681
if (force == SHUT_FORCE) {
682
if (_allowNuke == SHUT_NONE)
684
else if (_allowNuke == SHUT_ROOT)
685
mayNuke = doesNuke = true;
687
QLabel *lab = new QLabel(mayOk ?
688
i18n("Cancel pending shutdown:") :
689
i18n("No permission to cancel pending shutdown:"),
694
if (start < time(0)) {
695
strt = i18nc("start of shutdown:", "now");
697
qdt.setTime_t(start);
698
strt = qdt.toString(Qt::LocalDate);
700
if (timeout == TO_INF) {
701
end = i18nc("timeout of shutdown:", "infinite");
703
qdt.setTime_t(timeout);
704
end = qdt.toString(Qt::LocalDate);
712
i18nc("owner of shutdown:", "console user") :
714
i18nc("owner of shutdown:", "control socket") :
715
KUser(uid).loginName() ,
717
i18n("turn off computer") :
718
i18n("restart computer") ,
721
i18n("\nNext boot: %1", os) :
723
if (timeout != TO_INF)
724
trg += i18n("\nAfter timeout: %1",
725
force == SHUT_FORCE ?
726
i18nc("after timeout:", "abort all sessions") :
727
force == SHUT_FORCEMY ?
728
i18nc("after timeout:", "abort own sessions") :
729
i18nc("after timeout:", "cancel shutdown"));
730
lab = new QLabel(trg, this);
733
735
#include "kdmshutdown.moc"