Added ability to add widgets from command-line.
authormar637 <mar637@loki.(none)>
Mon, 21 Mar 2011 12:38:19 +0000 (23:38 +1100)
committermar637 <mar637@loki.(none)>
Mon, 21 Mar 2011 12:38:19 +0000 (23:38 +1100)
ProcessObject.cpp [changed from symlink to file mode: 0644]
ProcessObject.h [changed from symlink to file mode: 0644]
appeventlistener.cpp
appeventlistener.hpp
debian/changelog
debian/control
main.cpp
quickwidget.cpp

deleted file mode 120000 (symlink)
index e64c8a186da7ab430138937558d3d1419c8d8585..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-plugins/qmlprocess/ProcessObject.cpp
\ No newline at end of file
new file mode 100644 (file)
index 0000000000000000000000000000000000000000..a921af985a2af5acd09dae3565cf3f203f2d6aba
--- /dev/null
@@ -0,0 +1,159 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include <signal.h>
+#include <sys/types.h>
+
+#include <QtCore/QTime>
+#include <QtDeclarative/qdeclarative.h>
+#include <QtCore/QDebug>
+#include <QtCore/QTextCodec>
+
+#include "ProcessObject.h"
+
+ProcessObject::ProcessObject(QObject *parent):
+        QObject(parent),
+        m_suspend(false), m_started(false)
+{
+    m_process = new QProcess(this);
+    connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
+            this,
+            SLOT(processFinished(int, QProcess::ExitStatus)));
+    connect(m_process, SIGNAL(error(QProcess::ProcessError)),this,
+            SLOT(processErrored(QProcess::ProcessError)));
+}
+
+ProcessObject::~ProcessObject()
+{
+    if (m_started)
+    {
+        terminate();
+    }
+    delete m_process;
+}
+
+void ProcessObject::processErrored(QProcess::ProcessError error) {
+    QString err(m_process->readAllStandardError());
+    qDebug() << "failed with exitCode" << m_process->exitCode();
+    emit failed(m_process->exitCode(), err, error);
+    m_started = false;
+}
+
+void ProcessObject::processFinished(int exitCode,
+                                    QProcess::ExitStatus exitStatus)
+{
+    QTextCodec* codec = QTextCodec::codecForName("utf-8");
+    if (exitStatus == QProcess::NormalExit)
+    {
+        if (exitCode == 0)
+        {       
+         QString out = codec->toUnicode(m_process->readAllStandardOutput());
+         qDebug() << "normal";
+         emit completed(out.trimmed());
+        }
+        else
+        {
+         QString err = codec->toUnicode(m_process->readAllStandardError());
+         qDebug() << "failed";
+         emit failed(exitCode, err.trimmed(), m_process->error());
+        }
+    }
+    else
+    {
+       QString err = codec->toUnicode(m_process->readAllStandardError());
+        qDebug() << "failed";
+        emit failed(exitCode, err, m_process->error());
+    }
+    m_started = false;
+}
+
+QString ProcessObject::command() const
+{
+    return m_command;
+}
+
+void ProcessObject::setCommand(const QString &command)
+{
+    if (m_command != command) {
+        m_command = command;
+    }
+}
+
+void ProcessObject::run()
+{
+    if (m_started)
+    {
+        return;
+        qDebug() << "already started";
+    }
+    qDebug() << m_command;
+    m_process->start(m_command);
+    qDebug() << "started";
+    m_started = true;
+}
+
+bool ProcessObject::isSuspended() const
+{
+    return m_suspend;
+}
+
+void ProcessObject::setSuspend(bool suspend)
+{
+    if (!m_started || m_process->pid() == 0)
+    {
+        qDebug() << "No process running";
+        return;
+    }
+    if (m_suspend != suspend)
+    {
+        if (m_suspend)
+        {
+            ::kill(m_process->pid(), SIGCONT);
+            qDebug() << "Process resumed";
+
+        } else {
+            ::kill(m_process->pid(), SIGSTOP);
+            qDebug() << "Process suspended";
+
+        }
+        emit suspendChanged(suspend);
+        m_suspend = suspend;
+    }
+}
+
+void ProcessObject::terminate()
+{
+    if (m_started && m_process->pid() != 0)
+    {
+        m_process->kill();
+    }
+}
+
+
+QML_DECLARE_TYPE(ProcessObject);
deleted file mode 120000 (symlink)
index a243678d33b6b51643391f26a44687ed8d1ac0f7..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-plugins/qmlprocess/ProcessObject.h
\ No newline at end of file
new file mode 100644 (file)
index 0000000000000000000000000000000000000000..572bfee342303bd3554f0572656f3d32228e33fa
--- /dev/null
@@ -0,0 +1,77 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef EXAMPLEITEM_H
+#define EXAMPLEITEM_H
+
+#include <QtCore/QObject>
+#include <QtCore/QString>
+#include <QtCore/QProcess>
+
+class ProcessObject : public QObject
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QString command READ command WRITE setCommand)
+    Q_PROPERTY(bool suspend READ isSuspended WRITE setSuspend NOTIFY suspendChanged)
+
+public:
+    ProcessObject(QObject *parent = 0);
+    ~ProcessObject();
+
+    Q_INVOKABLE void run();
+    Q_INVOKABLE void terminate();
+
+    QString command() const;
+    void setCommand(const QString &command);
+    bool isSuspended() const;
+    void setSuspend(bool suspend);
+
+signals:
+    void completed(const QString& stdout);
+    void failed(int exitCode, const QString& stderr,
+                QProcess::ProcessError error);
+    void suspendChanged(bool);
+
+private slots:
+    void processFinished(int exitCode,
+                         QProcess::ExitStatus exitStatus);
+    void processErrored(QProcess::ProcessError error);
+
+private:
+
+    QString m_command;
+    QProcess* m_process;
+    bool m_suspend;
+    bool m_started;
+
+    Q_DISABLE_COPY(ProcessObject)
+};
+
+#endif // EXAMPLEITEM_H
index 4dfdd81..8d1d302 100644 (file)
@@ -4,6 +4,7 @@
 \r
 #include "appeventlistener.hpp"\r
 #include "quickwidgetsettings.hpp"\r
+#include "quickwidget.hpp"\r
 \r
 static AppEventListener *_instance = NULL;\r
 \r
@@ -19,14 +20,17 @@ AppEventListener::AppEventListener(QObject *parent) :
     QObject(parent)\r
 {\r
     // Connect to the QtSingleApplication's event\r
-    QObject::connect(QtSingleApplication::instance(), SIGNAL(messageReceived(const QString&)), this, SLOT(receiveMessage(const QString&)));\r
+    QObject::connect(QtSingleApplication::instance(), SIGNAL(messageReceived(const QString&)), \r
+                    this, SLOT(receiveMessage(const QString&)));\r
 }\r
 \r
 void AppEventListener::receiveMessage(const QString& message)\r
 {\r
-    if (message == APP_MESSAGE_ADDWIDGET)\r
+    if (message.endsWith(".qml")) {\r
+      QuickWidget::createAndShowNew(message);\r
+      \r
+    } else if (message == APP_MESSAGE_SETWIDGET)\r
     {\r
-        qDebug() << "TTTTTTEEEEST";\r
         QuickWidgetSettings settings;\r
         settings.exec();\r
     }\r
index 9b5e76e..5e5a952 100644 (file)
@@ -3,7 +3,7 @@
 \r
 #include <QObject>\r
 \r
-#define APP_MESSAGE_ADDWIDGET "Add widget"\r
+#define APP_MESSAGE_SETWIDGET "Add widget"\r
 #define APP_MESSAGE_CLOSE "Close"\r
 \r
 class AppEventListener : public QObject\r
index 65799f0..526b133 100644 (file)
@@ -1,3 +1,15 @@
+quick-widgets (0.2.4) unstable; urgency=low
+
+  * enabled adding widgets from the command-line
+
+ -- Malte Marquarding <malte@marquarding.com>  Mon, 21 Mar 2011 23:29:30 +1100
+
+quick-widgets (0.2.3) unstable; urgency=low
+
+  * added qt-mobility imports to search locations
+
+ -- Malte Marquarding <malte@marquarding.com>  Thu, 17 Mar 2011 09:45:14 +1100
+
 quick-widgets (0.2.2) unstable; urgency=low
 
   * added unicode support for standard output
index 923087c..9286bfc 100644 (file)
@@ -8,7 +8,7 @@ Homepage: http://quick-widgets.garage.maemo.org/
 
 Package: quick-widgets
 Architecture: any
-Depends: ${shlibs:Depends}, libhildon-extras1, q-extras (>=1.0.5)
+Depends: ${shlibs:Depends}, libhildon-extras1, q-extras (>=1.0.5), libqtm-12-declarative (>=1.2.0)
 XB-Maemo-Display-Name: Quick Widgets
 Description: This application simplifies running Qt Quick applications as
  home desktop widgets. It only needs the file. Thanks to Timur Kristóf (Venemo)
index 24a201f..5e99551 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -36,7 +36,13 @@ int main(int argc, char *argv[])
         else
         {
             qDebug() << "Asking it to offer to create a new widget.";
-            app.sendMessage(APP_MESSAGE_ADDWIDGET);
+           QStringList result;
+           result = app.arguments().filter(".qml");
+           if (result.size() == 1 && QFile(result.last()).exists()) {
+             app.sendMessage(QFileInfo(result.last()).absoluteFilePath());
+           } else {
+             app.sendMessage(APP_MESSAGE_SETWIDGET);         
+           }
             return 0;
         }
     }
@@ -54,13 +60,16 @@ int main(int argc, char *argv[])
         qDebug() << "Restoring all widgets";
         QeMaemo5DynamicWidgetHelper::globalInstance()->restoreWidgets<QuickWidget>();
     }
-
-    if (!app.arguments().contains("in-background"))
+    QStringList result;
+    result = app.arguments().filter(".qml");
+    if (result.size() == 1 && QFile(result.last()).exists()) {
+      app.sendMessage(QFileInfo(result.last()).absoluteFilePath());
+    } else if (!app.arguments().contains("in-background"))
     {
         // setting for new widget
         QuickWidgetSettings settingsDialog;
         settingsDialog.exec();
-        //app.sendMessage(APP_MESSAGE_ADDWIDGET);
+        //app.sendMessage(APP_MESSAGE_SETWIDGET);
     }
     return app.exec();
 }
index 6047117..9c9dffd 100644 (file)
@@ -61,6 +61,7 @@ QuickWidget::QuickWidget(QWidget *parent)
     }
     //layout()->setSizeConstraint(QLayout::SetNoConstraint);
     view_ = new QDeclarativeView(this);
+    view_->engine()->addImportPath(QString("/opt/qtm12/imports"));
     view_->setStyleSheet("background:transparent");
     view_->setAttribute(Qt::WA_TranslucentBackground);
     wrapper_ = new QuickWidgetWrapper(this);