//=========================================================================== // // This file is part of the KDE project // // Copyright (c) 2004 Chris Howells #include "lockprocess.h" #include "autologout.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define COUNTDOWN 30 AutoLogout::AutoLogout(LockProcess *parent) : TQDialog(parent, "password dialog", true, WX11BypassWM) { frame = new TQFrame(this); frame->setFrameStyle(TQFrame::Panel | TQFrame::Raised); frame->setLineWidth(2); TQLabel *pixLabel = new TQLabel( frame, "pixlabel" ); pixLabel->setPixmap(DesktopIcon("exit")); TQLabel *greetLabel = new TQLabel(i18n("Automatic Log Out"), frame); TQLabel *infoLabel = new TQLabel(i18n("To prevent being logged out, resume using this session by moving the mouse or pressing a key."), frame); mStatusLabel = new TQLabel(" ", frame); mStatusLabel->setAlignment(TQLabel::AlignCenter); TQLabel *mProgressLabel = new TQLabel("Time Remaining:", frame); mProgressRemaining = new TQProgressBar(frame); mProgressRemaining->setPercentageVisible(false); TQVBoxLayout *unlockDialogLayout = new TQVBoxLayout( this ); unlockDialogLayout->addWidget( frame ); frameLayout = new TQGridLayout(frame, 1, 1, KDialog::marginHint(), KDialog::spacingHint()); frameLayout->addMultiCellWidget(pixLabel, 0, 2, 0, 0, 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->setTotalSteps(COUNTDOWN * 25); updateInfo(mRemaining); mCountdownTimerId = startTimer(1000/25); connect(qApp, TQT_SIGNAL(activity()), TQT_SLOT(slotActivity())); } AutoLogout::~AutoLogout() { hide(); } void AutoLogout::updateInfo(int timeout) { mStatusLabel->setText(i18n("You will be automatically logged out in 1 second", "You will be automatically logged out in %n seconds", timeout / 25) ); mProgressRemaining->setProgress(timeout); } void AutoLogout::timerEvent(TQTimerEvent *ev) { if (ev->timerId() == mCountdownTimerId) { updateInfo(mRemaining); --mRemaining; if (mRemaining < 0) { logout(); } } } void AutoLogout::slotActivity() { accept(); } void AutoLogout::logout() { killTimers(); DCOPRef("ksmserver","ksmserver").send("logout", 0, 0, 0); } void AutoLogout::show() { TQDialog::show(); TQApplication::flushX(); } #include "autologout.moc"