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 setObjectName("password dialog");
36 frame
= new QFrame(this);
37 frame
->setFrameStyle(QFrame::Panel
| QFrame::Raised
);
38 frame
->setLineWidth(2);
40 QLabel
*pixLabel
= new QLabel( frame
);
41 pixLabel
->setObjectName( "pixlabel" );
42 pixLabel
->setPixmap(DesktopIcon("application-exit"));
44 QLabel
*greetLabel
= new QLabel(i18n("<qt><nobr><b>Automatic Log Out</b></nobr></qt>"), frame
);
45 QLabel
*infoLabel
= new QLabel(i18n("<qt>To prevent being logged out, resume using this session by moving the mouse or pressing a key.</qt>"), frame
);
47 mStatusLabel
= new QLabel("<b> </b>", frame
);
48 mStatusLabel
->setAlignment(Qt::AlignCenter
);
50 QLabel
*mProgressLabel
= new QLabel(i18n("Time Remaining:"), frame
);
51 mProgressRemaining
= new QProgressBar(frame
);
52 mProgressRemaining
->setTextVisible(false);
54 QVBoxLayout
*unlockDialogLayout
= new QVBoxLayout( this );
55 unlockDialogLayout
->addWidget( frame
);
57 frameLayout
= new QGridLayout(frame
);
58 frameLayout
->setSpacing(KDialog::spacingHint());
59 frameLayout
->setMargin(KDialog::marginHint());
60 frameLayout
->addWidget(pixLabel
, 0, 0, 3, 1, Qt::AlignCenter
| Qt::AlignTop
);
61 frameLayout
->addWidget(greetLabel
, 0, 1);
62 frameLayout
->addWidget(mStatusLabel
, 1, 1);
63 frameLayout
->addWidget(infoLabel
, 2, 1);
64 frameLayout
->addWidget(mProgressLabel
, 3, 1);
65 frameLayout
->addWidget(mProgressRemaining
, 4, 1);
67 // get the time remaining in seconds for the status label
68 mRemaining
= COUNTDOWN
* 25;
70 mProgressRemaining
->setMaximum(COUNTDOWN
* 25);
72 updateInfo(mRemaining
);
74 mCountdownTimerId
= startTimer(1000/25);
76 connect(qApp
, SIGNAL(activity()), SLOT(slotActivity()));
79 AutoLogout::~AutoLogout()
84 void AutoLogout::updateInfo(int timeout
)
86 mStatusLabel
->setText(i18np("<qt><nobr>You will be automatically logged out in 1 second</nobr></qt>",
87 "<qt><nobr>You will be automatically logged out in %1 seconds</nobr></qt>",
89 mProgressRemaining
->setValue(timeout
);
92 void AutoLogout::timerEvent(QTimerEvent
*ev
)
94 if (ev
->timerId() == mCountdownTimerId
)
96 updateInfo(mRemaining
);
105 void AutoLogout::slotActivity()
110 void AutoLogout::logout()
112 QAbstractEventDispatcher::instance()->unregisterTimers(this);
113 org::kde::KSMServerInterface
ksmserver("org.kde.ksmserver", "/KSMServer", QDBusConnection::sessionBus());
114 ksmserver
.logout( 0, 0, 0 );
117 void AutoLogout::setVisible(bool visible
)
119 QDialog::setVisible(visible
);
122 QApplication::flush();
125 #include "autologout.moc"