--- ./kdesktop/krootwm.h-- 2005-04-19 14:43:02.246359099 +0200 +++ ./kdesktop/krootwm.h 2005-04-19 14:45:43.455486599 +0200 @@ -118,6 +118,8 @@ public slots: void slotNewSession(); void slotLockNNewSession(); + void slotSuspendToDisk(); + private: KDesktop* m_pDesktop; --- ./kdesktop/krootwm.cc-- 2005-04-19 14:45:49.322248599 +0200 +++ ./kdesktop/krootwm.cc 2005-04-19 14:47:55.929112467 +0200 @@ -178,6 +178,16 @@ KRootWm::KRootWm(KDesktop* _desktop) : Q new KAction(i18n("Refresh Desktop"), "desktop", 0, this, SLOT( slotRefreshDesktop() ), m_actionCollection, "refresh" ); } + + KGlobal::locale()->insertCatalogue("gtk+mdk"); + QString path = QString::fromLocal8Bit(getenv("PATH")) + QString::fromLatin1(":/usr/sbin"); + QString exe = KStandardDirs::findExe( "pmsuspend", path ); + if (!exe.isEmpty() && (QFile("/proc/acpi").exists()|| QFile("/proc/apm").exists())) + { + new KAction(i18n("Suspend To Disk"), "suspend_mdk", 0, this, SLOT( slotSuspendToDisk() ), + m_actionCollection, "suspend_to_disk" ); + } + // Icons in sync with kicker if (kapp->authorize("lock_screen")) { @@ -211,6 +221,14 @@ KRootWm::~KRootWm() delete windowListMenu; } +void KRootWm::slotSuspendToDisk() +{ + QApplication::syncX(); + kapp->dcopClient()->send( "ksmserver", "ksmserver", + "suspendToDisk()", "" ); +} + + void KRootWm::initConfig() { // kdDebug() << "KRootWm::initConfig" << endl; @@ -319,6 +337,10 @@ void KRootWm::buildMenus() if (action) action->plug( file ); + action = m_actionCollection->action("suspend_to_disk"); + if (action) + action->plug( file ); + action = m_actionCollection->action("logout"); if (action) action->plug( file ); @@ -447,6 +469,9 @@ void KRootWm::buildMenus() action->plug( desktopMenu ); needSeparator = true; } + action = m_actionCollection->action("suspend_to_disk"); + if (action) + action->plug( desktopMenu ); action = m_actionCollection->action("logout"); if (action) --- ./kicker/core/kicker.h-- 2005-04-19 14:48:52.101833677 +0200 +++ ./kicker/core/kicker.h 2005-04-19 14:49:12.515005564 +0200 @@ -48,7 +48,8 @@ public: k_dcop: void configure(); void restart(); - void addExtension( const QString &desktopFile ); + void suspendToDisk(); + void addExtension( const QString &desktopFile ); void popupKMenu( const QPoint &globalPos ); void clearQuickStartMenu(); bool highlightMenuItem( const QString &menuId ); --- ./kicker/core/kicker.cpp-- 2005-04-19 14:49:21.860626435 +0200 +++ ./kicker/core/kicker.cpp 2005-04-19 14:50:23.272135120 +0200 @@ -61,6 +61,8 @@ #include "kickerSettings.h" #include "kicker.moc" +#include <krun.h> + Kicker* Kicker::the() { return static_cast<Kicker*>(kapp); } @@ -379,3 +381,14 @@ KWinModule* Kicker::kwinModule() return m_kwinModule; } +void Kicker::suspendToDisk() +{ + QString path = QString::fromLocal8Bit(getenv("PATH")) + QString::fromLatin1(":/usr/sbin"); + QString exe = KStandardDirs::findExe( "pmsuspend", path ); + if (!exe.isEmpty()) + { + KRun::runCommand( exe ); + } +} + + --- ./kicker/ui/k_mnu.cpp-- 2005-04-19 14:50:39.418480102 +0200 +++ ./kicker/ui/k_mnu.cpp 2005-04-19 14:51:49.024656349 +0200 @@ -54,6 +54,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE #include "menuinfo.h" #include "popupmenutitle.h" #include "quickbrowser_mnu.h" +#include <kprocess.h> #include "k_mnu.h" #include "k_mnu.moc" @@ -170,6 +171,7 @@ void PanelKMenu::paletteChanged() void PanelKMenu::initialize() { // kdDebug(1210) << "PanelKMenu::initialize()" << endl; + KGlobal::locale()->insertCatalogue("gtk+mdk"); updateRecent(); if (initialized()) @@ -378,6 +380,13 @@ void PanelKMenu::initialize() insertItem(i18n("Lock Session"), this, SLOT(slotLock())); } } + QString path = QString::fromLocal8Bit(getenv("PATH")) + QString::fromLatin1(":/usr/sbin"); + QString exe = KStandardDirs::findExe( "pmsuspend", path ); + if (!exe.isEmpty() && (QFile("/proc/acpi").exists()|| QFile("/proc/apm").exists())) + { + insertItem(SmallIconSet("suspend_mdk"), i18n("Suspend To Disk"), this, SLOT(slotSuspendToDisk())); + } + if (kapp->authorize("logout")) { @@ -405,6 +414,14 @@ void PanelKMenu::initialize() setInitialized(true); } +void PanelKMenu::slotSuspendToDisk() +{ + QApplication::syncX(); + kapp->dcopClient()->send( "ksmserver", "ksmserver", + "suspendToDisk()", "" ); +} + + int PanelKMenu::insertClientMenu(KickerClientMenu *p) { int id = client_id; --- ./kicker/ui/k_mnu.h-- 2005-04-19 14:51:55.071411047 +0200 +++ ./kicker/ui/k_mnu.h 2005-04-19 14:52:20.129394505 +0200 @@ -67,7 +67,8 @@ protected slots: void slotRunCommand(); void slotEditUserContact(); void paletteChanged(); - + void slotSuspendToDisk(); + protected: QRect sideImageRect(); QMouseEvent translateMouseEvent( QMouseEvent* e ); --- ./ksmserver/shutdown.cpp-- 2005-04-19 14:52:30.324980895 +0200 +++ ./ksmserver/shutdown.cpp 2005-04-19 14:54:04.004180558 +0200 @@ -266,3 +266,64 @@ void KSMDelayedPushButton::slotTimeout() popt->stop(); setDown(false); } + +bool KSMSuspendToDiskDlg::confirmSuspendToDisk() +{ + kapp->enableStyles(); + KSMSuspendToDiskDlg* l = new KSMSuspendToDiskDlg( 0 ); + + // Show dialog (will save the background in showEvent) + QSize sh = l->sizeHint(); + QDesktopWidget *desktop = KApplication::desktop(); + QRect rect = desktop->screenGeometry(desktop->screenNumber(QCursor::pos())); + l->move(rect.x() + (rect.width() - sh.width())/2, + rect.y() + (rect.height() - sh.height())/2); + bool result = l->exec(); + delete l; + kapp->disableStyles(); + return result; +} + +KSMSuspendToDiskDlg::KSMSuspendToDiskDlg( QWidget* parent) + : QDialog( parent, 0, TRUE, WType_Popup ) + // this is a WType_Popup on purpose. Do not change that! Not + // having a popup here has severe side effects. +{ + KGlobal::locale()->insertCatalogue("gtk+mdk"); + QVBoxLayout* vbox = new QVBoxLayout( this ); + QFrame* frame = new QFrame( this ); + frame->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); + frame->setLineWidth( style().pixelMetric( QStyle::PM_DefaultFrameWidth, frame ) ); + vbox->addWidget( frame ); + vbox = new QVBoxLayout( frame, 15, 11 ); + + QLabel* label = new QLabel(i18n("Do you really want to suspend to disk?"),frame); + QFont fnt = label->font(); + fnt.setBold( true ); + fnt.setPixelSize( fnt.pixelSize() * 3 / 2 ); + label->setFont( fnt ); + vbox->addWidget( label, 0, AlignHCenter ); + + //QLabel* label2 = new QLabel(i18n("Do you really want to suspend to disk?"),frame); + //fnt = label2->font(); + //fnt.setPixelSize( fnt.pixelSize() * 3 / 2 ); + //label2->setFont( fnt ); + //vbox->addWidget( label2, 0); + + vbox->addStretch(); + + QHBoxLayout* hbox = new QHBoxLayout( vbox ); + hbox->addStretch(); + KPushButton* yes = new KPushButton( KStdGuiItem::ok(), + frame ); + connect( yes, SIGNAL( clicked() ), SLOT( accept() ) ); + hbox->addWidget( yes ); + hbox->addStretch(); + KPushButton* cancel = new KPushButton( KStdGuiItem::cancel(), frame ); + connect( cancel, SIGNAL( clicked() ), SLOT( reject() ) ); + cancel->setDefault( TRUE ); + + hbox->addWidget( cancel ); + hbox->addStretch(); +} + --- ./ksmserver/shutdown.h-- 2005-04-19 14:54:12.070853313 +0200 +++ ./ksmserver/shutdown.h 2005-04-19 14:54:33.343990314 +0200 @@ -84,4 +84,18 @@ private: QTimer *popt; }; +// The suspend to disk dialog +class KSMSuspendToDiskDlg : public QDialog +{ + Q_OBJECT +public: + static bool confirmSuspendToDisk(); +protected: + ~KSMSuspendToDiskDlg() {}; + +private: + KSMSuspendToDiskDlg( QWidget* parent ); +}; + + #endif --- ./ksmserver/server.h-- 2005-04-19 14:54:39.982720997 +0200 +++ ./ksmserver/server.h 2005-04-19 14:54:58.415973205 +0200 @@ -166,7 +166,7 @@ private: QString currentSession(); void saveCurrentSession(); void saveCurrentSessionAs( QString ); - + void suspendToDisk(); private: QPtrList<KSMListener> listener; QPtrList<KSMClient> clients; --- ./ksmserver/server.cpp-- 2005-04-19 14:55:28.565750102 +0200 +++ ./ksmserver/server.cpp 2005-04-19 14:56:27.281368152 +0200 @@ -84,6 +84,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE #include "server.moc" #include <kdebug.h> +#include <kprocess.h> + +#include <X11/Xlib.h> + const int XNone = None; #undef None @@ -1976,6 +1980,36 @@ WId KSMServer::windowWmClientLeader(WId return result; } +void KSMServer::suspendToDisk() +{ + KSMShutdownFeedback::start(); // make the screen gray + bool suspendToDiskConfirmed = KSMSuspendToDiskDlg::confirmSuspendToDisk(); + // ###### We can't make the screen remain gray while talking to the apps, + // because this prevents interaction ("do you want to save", etc.) + // TODO: turn the feedback widget into a list of apps to be closed, + // with an indicator of the current status for each. + KSMShutdownFeedback::stop(); // make the screen become normal again + + if( suspendToDiskConfirmed ) + { + int kickerconfig_screen_number = 0; + if (qt_xdisplay()) + kickerconfig_screen_number = DefaultScreen(qt_xdisplay()); + // Tell kicker about the new config file. + if (!kapp->dcopClient()->isAttached()) + kapp->dcopClient()->attach(); + QByteArray data; + + QCString appname; + if (kickerconfig_screen_number == 0) + appname = "kicker"; + else + appname.sprintf("kicker-screen-%d", kickerconfig_screen_number); + kapp->dcopClient()->send( appname, "Panel", "suspendToDisk()", data ); + } +} + + /* Returns sessionId for this client, --- ./ksmserver/KSMServerInterface.h-- 2005-04-19 14:55:05.288694395 +0200 +++ ./ksmserver/KSMServerInterface.h 2005-04-19 14:55:23.017975161 +0200 @@ -19,6 +19,7 @@ k_dcop: virtual void saveCurrentSessionAs( QString ) = 0; virtual void autoStart2() = 0; + virtual void suspendToDisk() = 0; }; #endif