Index: ksmserver/KSMServerInterface.h =================================================================== --- ksmserver/KSMServerInterface.h.orig +++ ksmserver/KSMServerInterface.h @@ -22,6 +22,8 @@ k_dcop: virtual void suspendStartup( QCString ) = 0; virtual void resumeStartup( QCString ) = 0; + + virtual void logoutTimed( int, int, QString ) = 0; }; #endif Index: ksmserver/Makefile.am =================================================================== --- ksmserver/Makefile.am.orig +++ ksmserver/Makefile.am @@ -28,7 +28,7 @@ ksmserver_la_METASOURCES = AUTO # Order is important for --enable-final! ksmserver_la_SOURCES = main.cpp server.cpp shutdowndlg.cpp \ legacy.cpp startup.cpp shutdown.cpp client.cpp \ - KSMServerInterface.skel server.skel + KSMServerInterface.skel server.skel timed.ui ksmserver_la_LDFLAGS = $(all_libraries) -avoid-version -module ksmserver_la_LIBADD = ../kdmlib/libdmctl.la $(LIB_KDEUI) -llazy $(DBUS_LIBS) @@ -42,7 +42,7 @@ updatedir = $(kde_datadir)/kconf_update EXTRA_PROGRAMS = testsh -testsh_SOURCES = test.cpp +testsh_SOURCES = test.cpp timed.ui testsh_LDFLAGS = $(all_libraries) $(KDE_RPATH) testsh_LDADD = $(LIB_KDEUI) shutdowndlg.lo ../kdmlib/libdmctl.la -llazy $(DBUS_LIBS) Index: ksmserver/server.h =================================================================== --- ksmserver/server.h.orig +++ ksmserver/server.h @@ -85,6 +85,7 @@ public: // public API void restoreSession( QString sessionName ); void startDefaultSession(); + void shutdown( KApplication::ShutdownConfirm confirm, KApplication::ShutdownType sdtype, KApplication::ShutdownMode sdmode ); @@ -92,6 +93,11 @@ public: virtual void suspendStartup( QCString app ); virtual void resumeStartup( QCString app ); + bool checkStatus( bool &logoutConfirmed, bool &maysd, + KApplication::ShutdownConfirm confirm, + KApplication::ShutdownType sdtype, + KApplication::ShutdownMode sdmode ); + public slots: void cleanUp(); @@ -142,6 +148,11 @@ private: bool defaultSession() const; // empty session void setupXIOErrorHandler(); + void shutdownInternal( KApplication::ShutdownConfirm confirm, + KApplication::ShutdownType sdtype, + KApplication::ShutdownMode sdmode, + QString bootOption = QString::null ); + void performLegacySessionSave(); void storeLegacySession( KConfig* config ); void restoreLegacySession( KConfig* config ); @@ -157,6 +168,7 @@ private: // public dcop interface void logout( int, int, int ); + virtual void logoutTimed( int, int, QString ); QStringList sessionList(); QString currentSession(); void saveCurrentSession(); Index: ksmserver/shutdown.cpp =================================================================== --- ksmserver/shutdown.cpp.orig +++ ksmserver/shutdown.cpp @@ -93,14 +93,16 @@ void KSMServer::logout( int confirm, int (KApplication::ShutdownMode)sdmode ); } -void KSMServer::shutdown( KApplication::ShutdownConfirm confirm, - KApplication::ShutdownType sdtype, KApplication::ShutdownMode sdmode ) +bool KSMServer::checkStatus( bool &logoutConfirmed, bool &maysd, + KApplication::ShutdownConfirm confirm, + KApplication::ShutdownType sdtype, + KApplication::ShutdownMode sdmode ) { pendingShutdown.stop(); if( dialogActive ) - return; + return false; if( state >= Shutdown ) // already performing shutdown - return; + return false; if( state != Idle ) // performing startup { // perform shutdown as soon as startup is finished, in order to avoid saving partial session @@ -111,25 +113,44 @@ void KSMServer::shutdown( KApplication:: pendingShutdown_sdtype = sdtype; pendingShutdown_sdmode = sdmode; } - return; + return false; } KConfig *config = KGlobal::config(); config->reparseConfiguration(); // config may have changed in the KControl module config->setGroup("General" ); - bool logoutConfirmed = + logoutConfirmed = (confirm == KApplication::ShutdownConfirmYes) ? false : - (confirm == KApplication::ShutdownConfirmNo) ? true : - !config->readBoolEntry( "confirmLogout", true ); - bool maysd = false; + (confirm == KApplication::ShutdownConfirmNo) ? true : + !config->readBoolEntry( "confirmLogout", true ); + maysd = false; if (config->readBoolEntry( "offerShutdown", true ) && DM().canShutdown()) maysd = true; if (!maysd) { if (sdtype != KApplication::ShutdownTypeNone && sdtype != KApplication::ShutdownTypeDefault && logoutConfirmed) - return; /* unsupported fast shutdown */ + return false; /* unsupported fast shutdown */ + } + + return true; +} + +void KSMServer::shutdownInternal( KApplication::ShutdownConfirm confirm, + KApplication::ShutdownType sdtype, + KApplication::ShutdownMode sdmode, + QString bopt ) +{ + bool maysd = false; + bool logoutConfirmed = false; + if ( !checkStatus( logoutConfirmed, maysd, confirm, sdtype, sdmode ) ) + return; + + KConfig *config = KGlobal::config(); + + config->setGroup("General" ); + if (!maysd) { sdtype = KApplication::ShutdownTypeNone; } else if (sdtype == KApplication::ShutdownTypeDefault) sdtype = (KApplication::ShutdownType) @@ -138,7 +159,6 @@ void KSMServer::shutdown( KApplication:: sdmode = KApplication::ShutdownModeInteractive; dialogActive = true; - QString bopt; if ( !logoutConfirmed ) { KSMShutdownFeedback::start(); // make the screen gray logoutConfirmed = @@ -204,6 +224,42 @@ void KSMServer::shutdown( KApplication:: dialogActive = false; } +void KSMServer::shutdown( KApplication::ShutdownConfirm confirm, + KApplication::ShutdownType sdtype, KApplication::ShutdownMode sdmode ) +{ + shutdownInternal( confirm, sdtype, sdmode ); +} + +#include + +void KSMServer::logoutTimed( int sdtype, int sdmode, QString bootOption ) +{ + int confirmDelay; + + KConfig* config = KGlobal::config(); + config->setGroup( "General" ); + + if ( sdtype == KApplication::ShutdownTypeHalt ) + confirmDelay = config->readNumEntry( "confirmShutdownDelay", 31 ); + else if ( sdtype == KApplication::ShutdownTypeReboot ) + confirmDelay = config->readNumEntry( "confirmRebootDelay", 31 ); + else + confirmDelay = config->readNumEntry( "confirmLogoutDelay", 31 ); + + bool result = true; + if (confirmDelay) { + KSMShutdownFeedback::start(); // make the screen gray + result = KSMDelayedMessageBox::showTicker( (KApplication::ShutdownType)sdtype, bootOption, confirmDelay ); + KSMShutdownFeedback::stop(); // make the screen become normal again + } + + if ( result ) + shutdownInternal( KApplication::ShutdownConfirmNo, + (KApplication::ShutdownType)sdtype, + (KApplication::ShutdownMode)sdmode, + bootOption ); +} + void KSMServer::pendingShutdownTimeout() { shutdown( pendingShutdown_confirm, pendingShutdown_sdtype, pendingShutdown_sdmode ); Index: ksmserver/shutdowndlg.cpp =================================================================== --- ksmserver/shutdowndlg.cpp.orig +++ ksmserver/shutdowndlg.cpp @@ -25,6 +25,7 @@ Copyright (C) 2000 Matthias Ettrich #include +#include #include #include #include @@ -488,3 +489,67 @@ void KSMDelayedPushButton::slotTimeout() popt->stop(); setDown(false); } + +KSMDelayedMessageBox::KSMDelayedMessageBox( KApplication::ShutdownType sdtype, const QString &bootOption, int confirmDelay ) + : TimedLogoutDlg( 0, 0, true, WType_Popup ), m_remaining(confirmDelay) +{ + if ( sdtype == KApplication::ShutdownTypeHalt ) + { + m_title->setText( i18n( "Would you like to turn off your computer?" ) ); + m_template = i18n( "This computer will turn off automatically\n" + "after %1 seconds." ); + m_logo->setPixmap( BarIcon( "exit", 48 ) ); + } else if ( sdtype == KApplication::ShutdownTypeReboot ) + { + if (bootOption.isEmpty()) + m_title->setText( i18n( "Would you like to reboot your computer?" ) ); + else + m_title->setText( i18n( "Would you like to reboot to \"%1\"?" ).arg(bootOption) ); + m_template = i18n( "This computer will reboot automatically\n" + "after %1 seconds." ); + m_logo->setPixmap( BarIcon( "reload", 48 ) ); + } else { + m_title->setText( i18n( "Would you like to end your current session?" ) ); + m_template = i18n( "This session will end\n" + "after %1 seconds automatically." ); + m_logo->setPixmap( BarIcon( "previous", 48 ) ); + } + + updateText(); + adjustSize(); + if ( double( height() ) / width() < 0.25 ) + { + setFixedHeight( qRound( width() * 0.3 ) ); + adjustSize(); + } + QTimer *timer = new QTimer( this ); + timer->start( 1000 ); + connect( timer, SIGNAL( timeout() ), SLOT( updateText() ) ); + KDialog::centerOnScreen(this); +} + +void KSMDelayedMessageBox::updateText() +{ + m_remaining--; + if ( m_remaining == 0 ) + { + accept(); + return; + } + m_text->setText( m_template.arg( m_remaining ) ); +} + +bool KSMDelayedMessageBox::showTicker( KApplication::ShutdownType sdtype, const QString &bootOption, int confirmDelay ) +{ + kapp->enableStyles(); + KSMDelayedMessageBox msg( sdtype, bootOption, confirmDelay ); + QSize sh = msg.sizeHint(); + QRect rect = KGlobalSettings::desktopGeometry(QCursor::pos()); + + msg.move(rect.x() + (rect.width() - sh.width())/2, + rect.y() + (rect.height() - sh.height())/2); + bool result = msg.exec(); + + kapp->disableStyles(); + return result; +} Index: ksmserver/shutdowndlg.h =================================================================== --- ksmserver/shutdowndlg.h.orig +++ ksmserver/shutdowndlg.h @@ -17,6 +17,7 @@ class QVButtonGroup; class QPopupMenu; class QTimer; +#include "timed.h" #include // The (singleton) widget that makes the desktop gray. @@ -94,4 +95,22 @@ private: QTimer *popt; }; +class QLabel; + +class KSMDelayedMessageBox : public TimedLogoutDlg +{ + Q_OBJECT + +public: + KSMDelayedMessageBox( KApplication::ShutdownType sdtype, const QString &bootOption, int confirmDelay ); + static bool showTicker( KApplication::ShutdownType sdtype, const QString &bootOption, int confirmDelay ); + +protected slots: + void updateText(); + +private: + QString m_template; + int m_remaining; +}; + #endif Index: ksmserver/test.cpp =================================================================== --- ksmserver/test.cpp.orig +++ ksmserver/test.cpp @@ -14,11 +14,16 @@ main(int argc, char *argv[]) a.iconLoader()->addAppDir("ksmserver"); KSMShutdownFeedback::start(); + // ShutdownTypeNone == Logout == 0 + // ShutdownTypeReboot == 1 + // ShutdownTypeHalt == 2 KApplication::ShutdownType sdtype = KApplication::ShutdownTypeNone; QString bopt; + KSMDelayedMessageBox::showTicker( sdtype ); + /* (void)KSMShutdownDlg::confirmShutdown( true, sdtype, - bopt ); + bopt );*/ /* (void)KSMShutdownDlg::confirmShutdown( false, sdtype, bopt ); */ Index: ksmserver/timed.ui =================================================================== --- /dev/null +++ ksmserver/timed.ui @@ -0,0 +1,352 @@ + +TimedLogoutDlg + + + TimedLogoutDlg + + + + 0 + 0 + 381 + 131 + + + + + 5 + 5 + 0 + 0 + + + + Confirmation + + + + unnamed + + + 0 + + + 0 + + + + frame3 + + + + 5 + 5 + 0 + 0 + + + + StyledPanel + + + Raised + + + 2 + + + 0 + + + 0 + + + + unnamed + + + + layout10 + + + + unnamed + + + 0 + + + 0 + + + + layout8 + + + + unnamed + + + + layout6 + + + + unnamed + + + 0 + + + 0 + + + + spacer3_2 + + + Vertical + + + MinimumExpanding + + + + 20 + 2 + + + + + + m_logo + + + + 1 + 1 + 0 + 0 + + + + + 48 + 48 + + + + true + + + + + spacer3 + + + Vertical + + + MinimumExpanding + + + + 20 + 2 + + + + + + + + layout7 + + + + unnamed + + + 7 + + + + m_title + + + + 7 + 0 + 0 + 0 + + + + + 1 + + + + Would you like to shutdown your computer? + + + PlainText + + + AlignVCenter|AlignLeft + + + + + m_text + + + + 7 + 5 + 0 + 0 + + + + If you do not act, your computer will shutdown +after X automatically. + + + RichText + + + WordBreak|AlignVCenter + + + + + spacer4 + + + Vertical + + + Preferred + + + + 30 + 0 + + + + + + + + + + layout9 + + + + unnamed + + + + spacer2 + + + Horizontal + + + Expanding + + + + 90 + 20 + + + + + + pushButton1 + + + Confirm + + + false + + + + + spacer2_2 + + + Horizontal + + + Expanding + + + + 90 + 20 + + + + + + pushButton2 + + + + 1 + 5 + 0 + 0 + + + + Cancel + + + + + spacer2_2_2 + + + Horizontal + + + Expanding + + + + 90 + 20 + + + + + + + + + + + + + + pushButton1 + clicked() + TimedLogoutDlg + accept() + + + pushButton2 + clicked() + TimedLogoutDlg + reject() + + + +