1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
//===========================================================================
//
// This file is part of the KDE project
//
// Copyright 2004 Chris Howells <howells@kde.org>
#include "autologout.h"
#include "lockwindow.h"
#include <kapplication.h>
#include <klocale.h>
#include <kglobalsettings.h>
#include <kconfig.h>
#include <kiconloader.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kdialog.h>
#include <ksmserver_interface.h>
#include <QLayout>
#include <QMessageBox>
#include <QLabel>
#include <QStyle>
#include <QApplication>
#include <QDialog>
#include <QAbstractEventDispatcher>
#include <QtGui/QProgressBar>
#include <QtDBus/QtDBus>
#define COUNTDOWN 30
AutoLogout::AutoLogout(ScreenLocker::LockWindow *parent) : QDialog(NULL, Qt::X11BypassWindowManagerHint)
{
QLabel *pixLabel = new QLabel( this );
pixLabel->setObjectName( QLatin1String( "pixlabel" ) );
pixLabel->setPixmap(DesktopIcon(QLatin1String( "application-exit" )));
QLabel *greetLabel = new QLabel(i18n("<qt><nobr><b>Automatic Log Out</b></nobr></qt>"), this);
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);
mStatusLabel = new QLabel(QLatin1String( "<b> </b>" ), this);
mStatusLabel->setAlignment(Qt::AlignCenter);
QLabel *mProgressLabel = new QLabel(i18n("Time Remaining:"), this);
mProgressRemaining = new QProgressBar(this);
mProgressRemaining->setTextVisible(false);
frameLayout = new QGridLayout(this);
frameLayout->setSpacing(KDialog::spacingHint());
frameLayout->setMargin(KDialog::marginHint() * 2);
frameLayout->addWidget(pixLabel, 0, 0, 3, 1, Qt::AlignCenter | Qt::AlignTop);
frameLayout->addWidget(greetLabel, 0, 1);
frameLayout->addWidget(mStatusLabel, 1, 1);
frameLayout->addWidget(infoLabel, 2, 1);
frameLayout->addWidget(mProgressLabel, 3, 1);
frameLayout->addWidget(mProgressRemaining, 4, 1);
// get the time remaining in seconds for the status label
mRemaining = COUNTDOWN * 25;
mProgressRemaining->setMaximum(COUNTDOWN * 25);
updateInfo(mRemaining);
mCountdownTimerId = startTimer(1000/25);
connect(parent, SIGNAL(userActivity()), SLOT(slotActivity()));
}
AutoLogout::~AutoLogout()
{
hide();
}
void AutoLogout::updateInfo(int timeout)
{
mStatusLabel->setText(i18np("<qt><nobr>You will be automatically logged out in 1 second</nobr></qt>",
"<qt><nobr>You will be automatically logged out in %1 seconds</nobr></qt>",
timeout / 25) );
mProgressRemaining->setValue(timeout);
}
void AutoLogout::timerEvent(QTimerEvent *ev)
{
if (ev->timerId() == mCountdownTimerId)
{
updateInfo(mRemaining);
--mRemaining;
if (mRemaining < 0)
{
killTimer(mCountdownTimerId);
logout();
}
}
}
void AutoLogout::slotActivity()
{
if (mRemaining >= 0)
accept();
}
void AutoLogout::logout()
{
QAbstractEventDispatcher::instance()->unregisterTimers(this);
org::kde::KSMServerInterface ksmserver(QLatin1String( "org.kde.ksmserver" ), QLatin1String( "/KSMServer" ), QDBusConnection::sessionBus());
ksmserver.logout( 0, 0, 0 );
}
void AutoLogout::setVisible(bool visible)
{
QDialog::setVisible(visible);
if (visible)
QApplication::flush();
}
#include "autologout.moc"
|