~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to krunner/lock/autologout.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

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