1
//===========================================================================
3
// This file is part of the KDE project
5
// Copyright 2004 Chris Howells <howells@kde.org>
7
#include "lockprocess.h"
8
#include "autologout.h"
10
#include <kapplication.h>
12
#include <kglobalsettings.h>
14
#include <kiconloader.h>
16
#include <kmessagebox.h>
18
#include <ksmserver_interface.h>
21
#include <QMessageBox>
24
#include <QApplication>
26
#include <QAbstractEventDispatcher>
27
#include <QtGui/QProgressBar>
28
#include <QtDBus/QtDBus>
32
AutoLogout::AutoLogout(LockProcess *parent) : QDialog(parent, Qt::X11BypassWindowManagerHint)
34
QLabel *pixLabel = new QLabel( this );
35
pixLabel->setObjectName( QLatin1String( "pixlabel" ) );
36
pixLabel->setPixmap(DesktopIcon(QLatin1String( "application-exit" )));
38
QLabel *greetLabel = new QLabel(i18n("<qt><nobr><b>Automatic Log Out</b></nobr></qt>"), this);
39
QLabel *infoLabel = new QLabel(i18n("<qt>To prevent being logged out, resume using this session by moving the mouse or pressing a key.</qt>"), this);
41
mStatusLabel = new QLabel(QLatin1String( "<b> </b>" ), this);
42
mStatusLabel->setAlignment(Qt::AlignCenter);
44
QLabel *mProgressLabel = new QLabel(i18n("Time Remaining:"), this);
45
mProgressRemaining = new QProgressBar(this);
46
mProgressRemaining->setTextVisible(false);
48
frameLayout = new QGridLayout(this);
49
frameLayout->setSpacing(KDialog::spacingHint());
50
frameLayout->setMargin(KDialog::marginHint() * 2);
51
frameLayout->addWidget(pixLabel, 0, 0, 3, 1, Qt::AlignCenter | Qt::AlignTop);
52
frameLayout->addWidget(greetLabel, 0, 1);
53
frameLayout->addWidget(mStatusLabel, 1, 1);
54
frameLayout->addWidget(infoLabel, 2, 1);
55
frameLayout->addWidget(mProgressLabel, 3, 1);
56
frameLayout->addWidget(mProgressRemaining, 4, 1);
58
// get the time remaining in seconds for the status label
59
mRemaining = COUNTDOWN * 25;
61
mProgressRemaining->setMaximum(COUNTDOWN * 25);
63
updateInfo(mRemaining);
65
mCountdownTimerId = startTimer(1000/25);
67
connect(qApp, SIGNAL(activity()), SLOT(slotActivity()));
70
AutoLogout::~AutoLogout()
75
void AutoLogout::updateInfo(int timeout)
77
mStatusLabel->setText(i18np("<qt><nobr>You will be automatically logged out in 1 second</nobr></qt>",
78
"<qt><nobr>You will be automatically logged out in %1 seconds</nobr></qt>",
80
mProgressRemaining->setValue(timeout);
83
void AutoLogout::timerEvent(QTimerEvent *ev)
85
if (ev->timerId() == mCountdownTimerId)
87
updateInfo(mRemaining);
91
killTimer(mCountdownTimerId);
97
void AutoLogout::slotActivity()
103
void AutoLogout::logout()
105
QAbstractEventDispatcher::instance()->unregisterTimers(this);
106
org::kde::KSMServerInterface ksmserver(QLatin1String( "org.kde.ksmserver" ), QLatin1String( "/KSMServer" ), QDBusConnection::sessionBus());
107
ksmserver.logout( 0, 0, 0 );
110
void AutoLogout::setVisible(bool visible)
112
QDialog::setVisible(visible);
115
QApplication::flush();
118
#include "autologout.moc"