Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > 61c5d6c9f539de52b55ca9cba9224b2c > files > 6

kdebase4-4.2.4-0.4mdv2009.0.src.rpm

#
# SVN commit 948413 by fredrik:
# 
# Add the contextual actions from the default desktop containment as a temporary
# solution for KDE 4.3.
# 
# Suggested by Chani since the menu plugins won't be available until KDE 4.4.
# 

Index: apps/plasma/applets/folderview/folderview.h
===================================================================
--- apps/plasma/applets/folderview/folderview.h	(revision 948412)
+++ apps/plasma/applets/folderview/folderview.h	(revision 948413)
@@ -99,6 +99,11 @@
     void updateIconWidget();
     void iconWidgetClicked();
 
+    void addPanel();
+    void runCommand();
+    void lockScreen();
+    void logout();
+
     void activated(const QModelIndex &index);
     void indexesMoved(const QModelIndexList &indexes);
     void contextMenuRequest(QWidget *widget, const QPoint &screenPos);
Index: apps/plasma/applets/folderview/folderview.cpp
===================================================================
--- apps/plasma/applets/folderview/folderview.cpp	(revision 948412)
+++ apps/plasma/applets/folderview/folderview.cpp	(revision 948413)
@@ -20,7 +20,6 @@
 
 #include "folderview.h"
 
-#include <QApplication>
 #include <QClipboard>
 #include <QDebug>
 #include <QDesktopServices>
@@ -32,6 +31,7 @@
 #include <QScrollBar>
 
 #include <KAction>
+#include <KApplication>
 #include <KAuthorized>
 #include <KBookmarkManager>
 #include <KConfigDialog>
@@ -60,6 +60,11 @@
 
 #include <limits.h>
 
+#ifdef Q_OS_WIN
+#  define _WIN32_WINNT 0x0500 // require NT 5.0 (win 2k pro)
+#  include <windows.h>
+#endif // Q_OS_WIN
+
 #include "plasma/corona.h"
 #include "plasma/paintutils.h"
 #include "plasma/theme.h"
@@ -984,6 +989,13 @@
         }
     }
 
+    if (constraints & Plasma::ImmutableConstraint) {
+        // We need to update the menu items that have already been created
+        if (QAction *addPanel = m_actionCollection.action("add panel")) {
+            addPanel->setVisible(immutability() == Plasma::Mutable);
+        }
+    }
+
     if (constraints & Plasma::ScreenConstraint) {
         Plasma::Corona *c = corona();
         disconnect(c, SIGNAL(availableScreenRegionChanged()), this, SLOT(updateScreenRegion()));
@@ -1162,6 +1174,28 @@
     m_actionCollection.addAction("trash", trash);
     m_actionCollection.addAction("del", del);
 
+    QAction *addPanelAction = new QAction(i18n("Add Panel"), this);
+    connect(addPanelAction, SIGNAL(triggered(bool)), this, SLOT(addPanel()));
+    addPanelAction->setIcon(KIcon("list-add"));
+    addPanelAction->setVisible(immutability() == Plasma::Mutable);
+
+    QAction *runCommandAction = new QAction(i18n("Run Command..."), this);
+    connect(runCommandAction, SIGNAL(triggered(bool)), this, SLOT(runCommand()));
+    runCommandAction->setIcon(KIcon("system-run"));
+
+    QAction *lockScreenAction = new QAction(i18n("Lock Screen"), this);
+    lockScreenAction->setIcon(KIcon("system-lock-screen"));
+    connect(lockScreenAction, SIGNAL(triggered(bool)), this, SLOT(lockScreen()));
+
+    QAction *logoutAction = new QAction(i18n("Leave..."), this);
+    logoutAction->setIcon(KIcon("system-shutdown"));
+    connect(logoutAction, SIGNAL(triggered(bool)), this, SLOT(logout()));
+
+    m_actionCollection.addAction("add panel", addPanelAction);
+    m_actionCollection.addAction("run command", runCommandAction);
+    m_actionCollection.addAction("lock screen", lockScreenAction);
+    m_actionCollection.addAction("logout", logoutAction);
+
     if (KAuthorized::authorize("editable_desktop_icons")) {
         KAction *alignToGrid = new KAction(i18n("Align to Grid"), this);
         alignToGrid->setCheckable(true);
@@ -1278,9 +1312,113 @@
         actions.append(separator);
     }
 
+    if (isContainment()) {
+        actions.append(action("add widgets"));
+        actions.append(m_actionCollection.action("add panel"));
+        if (KAuthorized::authorizeKAction("run_command")) {
+            actions.append(m_actionCollection.action("run command"));
+        }
+        if (screen() == -1) {
+            actions.append(action("remove"));
+        }   
+        actions.append(action("lock widgets"));
+
+        QAction *separator = new QAction(this);
+        separator->setSeparator(true);
+        actions.append(separator);
+ 
+        if (KAuthorized::authorizeKAction("lock_screen")) {
+            actions.append(m_actionCollection.action("lock screen"));
+        }
+        if (KAuthorized::authorizeKAction("logout")) {
+            actions.append(m_actionCollection.action("logout"));
+        }
+
+        separator = new QAction(this);
+        separator->setSeparator(true);
+        actions.append(separator);
+    } 
+
     return actions;
 }
 
+void FolderView::addPanel()
+{
+    if (corona()) {
+        // make a panel at the top
+        Containment* panel = corona()->addContainment("panel");
+        panel->showConfigurationInterface();
+
+        panel->setScreen(screen());
+
+        QList<Plasma::Location> freeEdges = corona()->freeEdges(screen());
+        kDebug() << freeEdges;
+        Plasma::Location destination;
+        if (freeEdges.contains(Plasma::TopEdge)) {
+            destination = Plasma::TopEdge;
+        } else if (freeEdges.contains(Plasma::BottomEdge)) {
+            destination = Plasma::BottomEdge;
+        } else if (freeEdges.contains(Plasma::LeftEdge)) {
+            destination = Plasma::LeftEdge;
+        } else if (freeEdges.contains(Plasma::RightEdge)) {
+            destination = Plasma::RightEdge;
+        } else destination = Plasma::TopEdge;
+
+        panel->setLocation(destination);
+
+        // trigger an instant layout so we immediately have a proper geometry
+        // rather than waiting around for the event loop
+        panel->updateConstraints(Plasma::StartupCompletedConstraint);
+        panel->flushPendingConstraintsEvents();
+        if (destination == Plasma::LeftEdge || destination == Plasma::RightEdge) {
+            panel->setMinimumSize(10, 35);
+            panel->setMaximumSize(35, corona()->screenGeometry(screen()).height());
+            panel->resize(QSize(35, corona()->screenGeometry(screen()).height()));
+        }
+    }
+}
+
+void FolderView::runCommand()
+{
+    if (!KAuthorized::authorizeKAction("run_command")) {
+        return;
+    }
+
+    QDBusInterface krunner("org.kde.krunner", "/App", "org.kde.krunner.App", QDBusConnection::sessionBus());
+    krunner.call("display");
+}
+
+void FolderView::lockScreen()
+{
+    if (!KAuthorized::authorizeKAction("lock_screen")) {
+        return;
+    }
+
+#ifndef Q_OS_WIN
+    QDBusInterface screensaver("org.freedesktop.ScreenSaver", "/ScreenSaver",
+                               "org.freedesktop.ScreenSaver", QDBusConnection::sessionBus());
+    if (screensaver.isValid()) {
+        screensaver.call("Lock");
+    }
+#else
+    LockWorkStation();
+#endif
+}
+
+void FolderView::logout()
+{
+    if (!KAuthorized::authorizeKAction("logout")) {
+        return;
+    }
+
+#ifndef Q_WS_WIN
+    QApplication::syncX();
+    static_cast<KApplication*>(QApplication::instance())->updateRemoteUserTimestamp("org.kde.ksmserver");
+    QDBusInterface ksmserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface", QDBusConnection::sessionBus());
+    ksmserver.call("logout", -1, -1, -1);
+#endif
+}
+
 void FolderView::aboutToShowCreateNew()
 {
     if (m_newMenu) {