From 27856879bf962f178d88e79144e37a47e731b122 Mon Sep 17 00:00:00 2001 From: tpearson Date: Fri, 3 Sep 2010 09:14:57 +0000 Subject: * Massive import of OpenSUSE patches, primarily for bugfixes * Added some infrastructure created by OpenSUSE to allow for future addition of the Kickoff menu as an option * Minor Slackware compilation fixes git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1171255 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- ksmserver/KSMServerInterface.h | 2 + ksmserver/Makefile.am | 4 +- ksmserver/server.h | 12 ++ ksmserver/shutdown.cpp | 78 +++++++-- ksmserver/shutdowndlg.cpp | 70 +++++++- ksmserver/shutdowndlg.h | 19 +++ ksmserver/test.cpp | 7 +- ksmserver/timed.ui | 352 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 529 insertions(+), 15 deletions(-) create mode 100644 ksmserver/timed.ui (limited to 'ksmserver') diff --git a/ksmserver/KSMServerInterface.h b/ksmserver/KSMServerInterface.h index 52fdf0942..a628b92ba 100644 --- a/ksmserver/KSMServerInterface.h +++ b/ksmserver/KSMServerInterface.h @@ -22,6 +22,8 @@ k_dcop: virtual void suspendStartup( TQCString ) = 0; virtual void resumeStartup( TQCString ) = 0; + + virtual void logoutTimed( int, int, TQString ) = 0; }; #endif diff --git a/ksmserver/Makefile.am b/ksmserver/Makefile.am index 62f9d8976..19b328bc5 100644 --- a/ksmserver/Makefile.am +++ b/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) $(HAL_LIBS) $(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 $(HAL_LIBS) $(DBUS_LIBS) diff --git a/ksmserver/server.h b/ksmserver/server.h index 3d5904e53..0fc900042 100644 --- a/ksmserver/server.h +++ b/ksmserver/server.h @@ -85,6 +85,7 @@ public: // public API void restoreSession( TQString sessionName ); void startDefaultSession(); + void shutdown( KApplication::ShutdownConfirm confirm, KApplication::ShutdownType sdtype, KApplication::ShutdownMode sdmode ); @@ -92,6 +93,11 @@ public: virtual void suspendStartup( TQCString app ); virtual void resumeStartup( TQCString 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, + TQString bootOption = TQString::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, TQString ); TQStringList sessionList(); TQString currentSession(); void saveCurrentSession(); diff --git a/ksmserver/shutdown.cpp b/ksmserver/shutdown.cpp index 16fab8b4d..a850d40be 100644 --- a/ksmserver/shutdown.cpp +++ b/ksmserver/shutdown.cpp @@ -93,14 +93,16 @@ void KSMServer::logout( int confirm, int sdtype, int sdmode ) (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::ShutdownConfirm confirm, 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, + TQString 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::ShutdownConfirm confirm, sdmode = KApplication::ShutdownModeInteractive; dialogActive = true; - TQString bopt; if ( !logoutConfirmed ) { KSMShutdownFeedback::start(); // make the screen gray logoutConfirmed = @@ -204,6 +224,42 @@ void KSMServer::shutdown( KApplication::ShutdownConfirm confirm, 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, TQString 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 ); diff --git a/ksmserver/shutdowndlg.cpp b/ksmserver/shutdowndlg.cpp index 7b0493559..f6295a158 100644 --- a/ksmserver/shutdowndlg.cpp +++ b/ksmserver/shutdowndlg.cpp @@ -29,6 +29,7 @@ Copyright (C) 2000 Matthias Ettrich #include #include +#include #include #include #include @@ -340,6 +341,7 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent, buttonlay->addStretch( 1 ); // End session KPushButton* btnLogout = new KPushButton( KGuiItem( i18n("&End Current Session"), "undo"), frame ); + TQToolTip::add( btnLogout, i18n( "

End Current Session

Log out of the current session to login with a different user

" ) ); btnFont = btnLogout->font(); buttonlay->addWidget( btnLogout ); connect(btnLogout, TQT_SIGNAL(clicked()), TQT_SLOT(slotLogout())); @@ -510,14 +512,16 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent, { // Shutdown KPushButton* btnHalt = new KPushButton( KGuiItem( i18n("&Turn Off Computer"), "exit"), frame ); + TQToolTip::add( btnHalt, i18n( "

Turn Off Computer

Log out of the current session and turn off the computer

" ) ); btnHalt->setFont( btnFont ); buttonlay->addWidget( btnHalt ); connect(btnHalt, TQT_SIGNAL(clicked()), TQT_SLOT(slotHalt())); - if ( sdtype == KApplication::ShutdownTypeHalt ) + if ( sdtype == KApplication::ShutdownTypeHalt || getenv("KDM_AUTOLOGIN") ) btnHalt->setFocus(); // Reboot KSMDelayedPushButton* btnReboot = new KSMDelayedPushButton( KGuiItem( i18n("&Restart Computer"), "reload"), frame ); + TQToolTip::add( btnReboot, i18n( "

Restart Computer

Log out of the current session and restart the computer

Hold the mouse button or the space bar for a short while to get a list of options what to boot

" ) ); btnReboot->setFont( btnFont ); buttonlay->addWidget( btnReboot ); @@ -761,6 +765,70 @@ void KSMDelayedPushButton::slotTimeout() setDown(false); } +KSMDelayedMessageBox::KSMDelayedMessageBox( KApplication::ShutdownType sdtype, const TQString &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(); + } + TQTimer *timer = new TQTimer( this ); + timer->start( 1000 ); + connect( timer, TQT_SIGNAL( timeout() ), TQT_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 TQString &bootOption, int confirmDelay ) +{ + kapp->enableStyles(); + KSMDelayedMessageBox msg( sdtype, bootOption, confirmDelay ); + TQSize sh = msg.sizeHint(); + TQRect rect = KGlobalSettings::desktopGeometry(TQCursor::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; +} + KSMPushButton::KSMPushButton( const KGuiItem &item, TQWidget *parent, const char *name) diff --git a/ksmserver/shutdowndlg.h b/ksmserver/shutdowndlg.h index a1d720669..79ee8ca37 100644 --- a/ksmserver/shutdowndlg.h +++ b/ksmserver/shutdowndlg.h @@ -26,6 +26,7 @@ class TQString; class KAction; +#include "timed.h" #include #include @@ -165,4 +166,22 @@ class FlatButton : public QToolButton +class TQLabel; + +class KSMDelayedMessageBox : public TimedLogoutDlg +{ + Q_OBJECT + +public: + KSMDelayedMessageBox( KApplication::ShutdownType sdtype, const TQString &bootOption, int confirmDelay ); + static bool showTicker( KApplication::ShutdownType sdtype, const TQString &bootOption, int confirmDelay ); + +protected slots: + void updateText(); + +private: + TQString m_template; + int m_remaining; +}; + #endif diff --git a/ksmserver/test.cpp b/ksmserver/test.cpp index 846c449db..8f248725f 100644 --- a/ksmserver/test.cpp +++ b/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; TQString bopt; + KSMDelayedMessageBox::showTicker( sdtype ); + /* (void)KSMShutdownDlg::confirmShutdown( true, sdtype, - bopt ); + bopt );*/ /* (void)KSMShutdownDlg::confirmShutdown( false, sdtype, bopt ); */ diff --git a/ksmserver/timed.ui b/ksmserver/timed.ui new file mode 100644 index 000000000..23d7aa2a0 --- /dev/null +++ b/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() + + + + -- cgit v1.2.3