[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [plasmate] plasmate: KonsolePreviewer works now properly for the KWin Scripts
From:       Antonis Tsiapaliokas <kok3rs () gmail ! com>
Date:       2014-03-17 12:29:18
Message-ID: E1WPWfO-0006Wi-GT () scm ! kde ! org
[Download RAW message or body]

Git commit ffd9812133b1c16b3b7727f27a6dc59de30c8f62 by Antonis Tsiapaliokas.
Committed on 17/03/2014 at 11:22.
Pushed by tsiapaliokas into branch 'master'.

KonsolePreviewer works now properly for the KWin Scripts

REVIEW: 106118

M  +64   -3    plasmate/konsole/konsolepreviewer.cpp
M  +6    -1    plasmate/konsole/konsolepreviewer.h
M  +13   -3    plasmate/mainwindow.cpp
M  +1    -1    plasmate/mainwindow.h

http://commits.kde.org/plasmate/ffd9812133b1c16b3b7727f27a6dc59de30c8f62

diff --git a/plasmate/konsole/konsolepreviewer.cpp \
b/plasmate/konsole/konsolepreviewer.cpp index 76c533e..3785aa1 100644
--- a/plasmate/konsole/konsolepreviewer.cpp
+++ b/plasmate/konsole/konsolepreviewer.cpp
@@ -12,6 +12,8 @@
 
 #include <QVBoxLayout>
 #include <QFile>
+#include <QDBusMessage>
+#include <QDBusConnection>
 #include <QCoreApplication>
 #include <QMutexLocker>
 #include <QTextEdit>
@@ -24,21 +26,36 @@
 #include <KToolBar>
 #include <KUrl>
 #include <KUser>
+#include <klocalizedstring.h>
 
 #include <iostream>
 
 QWeakPointer<KonsolePreviewer> KonsolePreviewer::msgHandler;
 
-KonsolePreviewer::KonsolePreviewer(const QString & title, QWidget *parent)
+KonsolePreviewer::KonsolePreviewer(const QString & title, QWidget *parent, const \
QString& projectType, +                                   const QString& packagePath)
         : QDockWidget(title, parent),
-        m_textEdit(0)
+        m_textEdit(0),
+        m_projectType(projectType),
+        m_packagePath(packagePath)
 {
     QVBoxLayout *layout = new QVBoxLayout();
     KToolBar *toolBar = new KToolBar(this, true, true);
-    toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
 
     KAction *clear = KStandardAction::clear(this, SLOT(clearOutput()), this);
     KAction *save = KStandardAction::save(this, SLOT(saveOutput()), this);
+
+    //we want those only for the kwin scripts
+    if (m_projectType == "KWin/Script") {
+        KAction *execute = new KAction(this);
+        execute->setText("Execute");
+        execute->setIcon(KIcon("system-run"));
+        connect(execute, SIGNAL(triggered(bool)), this, SLOT(executeKWinScript()));
+
+        //add it to toolbar
+        toolBar->addAction(execute);
+    }
+
     toolBar->addAction(clear);
     toolBar->addAction(save);
 
@@ -60,6 +77,50 @@ KonsolePreviewer::~KonsolePreviewer()
 {
 }
 
+QString KonsolePreviewer::packageMainFile(const QString& packagePath)
+{
+    KConfig c(packagePath  + '/' + "metadata.desktop");
+    KConfigGroup projectInformation(&c, "Desktop Entry");
+    const QString relativeFilenamePath = \
projectInformation.readEntry("X-Plasma-MainScript"); +    QString fullFilenamePath = \
KStandardDirs::locate("data", packagePath + "/contents" + '/' + \
relativeFilenamePath); +    return fullFilenamePath;
+}
+
+void KonsolePreviewer::executeKWinScript()
+{
+    QString KWinScriptOutput;
+    const QString mainFileName = packageMainFile(m_packagePath);
+    QFile mainFile(mainFileName);
+    if (!mainFile.exists()) {
+        KWinScriptOutput.append(i18n("The main source file doesn't exist."));
+        KMessageBox::error(0, i18n("There is a problem with your package."
+        "Please check your metada.desktop file,"
+        "and verify that the %1 exists.").arg(mainFileName));
+        m_textEdit->append(KWinScriptOutput);
+        return;
+    } else {
+        QDBusMessage message = QDBusMessage::createMethodCall("org.kde.kwin", \
"/Scripting", "org.kde.kwin.Scripting", "loadScript"); +        QList<QVariant> \
arguments; +        arguments << QVariant(mainFileName);
+        message.setArguments(arguments);
+        QDBusMessage reply = QDBusConnection::sessionBus().call(message);
+        if (reply.type() == QDBusMessage::ErrorMessage) {
+            KWinScriptOutput.append(reply.errorMessage());
+        } else {
+            message = QDBusMessage::createMethodCall("org.kde.kwin", "/Scripting", \
"org.kde.kwin.Scripting", "start"); +            reply = \
QDBusConnection::sessionBus().call(message); +            if (reply.type() == \
QDBusMessage::ErrorMessage) { +                \
KWinScriptOutput.append(reply.errorMessage()); +            } else {
+                //successful message must been put here
+                KWinScriptOutput.append(i18n("The KWin Script has been executed \
successfully")); +            }
+        }
+    }
+
+    m_textEdit->append(KWinScriptOutput);
+}
+
 void KonsolePreviewer::clearOutput()
 {
     m_textEdit->clear();
diff --git a/plasmate/konsole/konsolepreviewer.h \
b/plasmate/konsole/konsolepreviewer.h index 31c3858..b7e2de0 100644
--- a/plasmate/konsole/konsolepreviewer.h
+++ b/plasmate/konsole/konsolepreviewer.h
@@ -31,7 +31,8 @@ class KonsolePreviewer : public QDockWidget {
     Q_OBJECT
 
 public:
-    KonsolePreviewer(const QString & title, QWidget *parent = 0);
+    KonsolePreviewer(const QString & title, QWidget *parent = 0, const QString \
&projectType = "Plasma/Applet", +                     const QString &packagePath = \
0);  ~KonsolePreviewer();
 
     enum EventType {
@@ -48,9 +49,13 @@ protected:
 public Q_SLOTS:
     void clearOutput();
     void saveOutput();
+    void executeKWinScript();
 
 private:
     QTextEdit *m_textEdit;
+    QString packageMainFile(const QString& packagePath);
+    QString m_projectType;
+    QString m_packagePath;
 };
 
 class KonsolePreviewerDebugEvent: public QEvent
diff --git a/plasmate/mainwindow.cpp b/plasmate/mainwindow.cpp
index 19e7c9d..bca6c6b 100644
--- a/plasmate/mainwindow.cpp
+++ b/plasmate/mainwindow.cpp
@@ -26,7 +26,6 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include <QTextStream>
 
 #include <KTextEdit>
-
 #include <KAction>
 #include <KActionCollection>
 #include <KConfig>
@@ -273,6 +272,14 @@ void MainWindow::toggleActions()
         if (m_konsoleWidget) {
             m_konsoleWidget.data()->setVisible(false);
         }
+    } else if (m_packageType == "KWin/Script") {
+        //On KWin Scripts we don't have a previewer.
+        //So we are hiding it from the toolbar.
+        actionCollection()->action("preview")->setVisible(false);
+        //We want only the KWin scripts to have the ability to
+        //show or hide the konsole previewer from the toolbar.
+        //The rest packages can do that inside from the previewer.
+        //The Konsole is visible by default
     }
 }
 
@@ -858,7 +865,7 @@ void MainWindow::loadProject(const QString &path)
     }
 
     //initialize the konsole previewer
-    m_konsoleWidget.reset(createKonsoleFor(previewerType));
+    m_konsoleWidget.reset(createKonsoleFor(previewerType, packagePath));
 
     // initialize previewer
     delete m_previewerWidget;
@@ -1014,7 +1021,7 @@ Previewer* MainWindow::createPreviewerFor(const QString& \
projectType)  return ret;
 }
 
-KonsolePreviewer* MainWindow::createKonsoleFor(const QString& projectType)
+KonsolePreviewer* MainWindow::createKonsoleFor(const QString& projectType, const \
QString &packagePath)  {
     KonsolePreviewer *konsole = 0;
     if (projectType.contains("KWin/WindowSwitcher")) {
@@ -1023,6 +1030,9 @@ KonsolePreviewer* MainWindow::createKonsoleFor(const QString& \
projectType)  konsole = new KonsolePreviewer(i18n("Previewer Output"));
     } else if (projectType == "Plasma/Runner") {
         konsole = new KonsolePreviewer(i18n("Previewer Output"));
+    } else if (projectType == "KWin/Script") {
+        //we need to specify the serviceType and path of our package
+        konsole = new KonsolePreviewer(i18nc("Window Title", "KWin Scripting \
Konsole"), this, projectType, packagePath);  }
 
     if (konsole) {
diff --git a/plasmate/mainwindow.h b/plasmate/mainwindow.h
index 9b98777..441440a 100644
--- a/plasmate/mainwindow.h
+++ b/plasmate/mainwindow.h
@@ -150,7 +150,7 @@ private:
     void setupTextEditor(KTextEditor::Document *editorPart, KTextEditor::View \
*view);  void loadNotesEditor(QDockWidget *container);
     Previewer* createPreviewerFor(const QString& projectType);
-    KonsolePreviewer* createKonsoleFor(const QString& projectType);
+    KonsolePreviewer* createKonsoleFor(const QString& projectType, const QString \
&projectPath = 0);  
     KAction *addAction(QString text, const char * icon,const  char *slot, const char \
*name, const KShortcut &shortcut = KShortcut());  


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic