aboutsummaryrefslogtreecommitdiff
path: root/mappletrunner
diff options
context:
space:
mode:
authorTomas Junnonen <tomas.junnonen@nokia.com>2010-04-12 13:50:25 +0300
committerTomas Junnonen <tomas.junnonen@nokia.com>2010-04-12 13:52:31 +0300
commitda73676c8a5af66b55523a9cdfbfbea2baa88a2a (patch)
tree0a3b8933a1817c152116da5fa8a7b5cdd8102e60 /mappletrunner
parent8832674482d3b9a7fcf77b0cfdcb8e6fe4960b4d (diff)
Changes: Renamed dui to meegotouch
By: Holger, Daniel, Janne RevBy: Tomas, Holger
Diffstat (limited to 'mappletrunner')
-rw-r--r--mappletrunner/.gitignore2
-rw-r--r--mappletrunner/main.cpp106
-rw-r--r--mappletrunner/mappletrunner.cpp189
-rw-r--r--mappletrunner/mappletrunner.h100
-rw-r--r--mappletrunner/mappletrunner.pro41
5 files changed, 438 insertions, 0 deletions
diff --git a/mappletrunner/.gitignore b/mappletrunner/.gitignore
new file mode 100644
index 00000000..81c0e597
--- /dev/null
+++ b/mappletrunner/.gitignore
@@ -0,0 +1,2 @@
+duiappletrunner
+
diff --git a/mappletrunner/main.cpp b/mappletrunner/main.cpp
new file mode 100644
index 00000000..d4d7976e
--- /dev/null
+++ b/mappletrunner/main.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it 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.
+**
+****************************************************************************/
+
+/**
+* \defgroup appletrunner M applet runner
+*
+* Runner process for the out-of-process (oop) applets.
+*/
+
+/**
+* \file
+* \ingroup appletrunner
+*/
+
+#include <QApplication>
+#include <QStringList>
+#include <QProcess>
+
+#include "mappletrunner.h"
+#include <MApplication>
+#include <MApplicationService>
+#include <QPluginLoader>
+#include <QDebug>
+#include <mappletmetadata.h>
+
+/// Error code for applet initialization failure
+static const int ERROR_APPLET_INIT_FAILED = -2;
+/// Error code for invalid command line arguments
+static const int ERROR_INVALID_ARGUMENTS = -3;
+
+class MyApplicationService: public MApplicationService
+{
+public:
+ MyApplicationService(QObject *parent = 0) :
+ MApplicationService(QString(), parent) {
+ }
+
+ void launch() {
+ launchAnotherWithQProcess();
+ }
+
+ virtual void handleServiceRegistrationFailure() {
+ qDebug() << "MyApplicationService::handleServiceRegistrationFailure()";
+ }
+
+ virtual QString registeredName() {
+ return QString();
+ }
+
+ virtual bool isRegistered() {
+ return false;
+ }
+
+ virtual bool registerService() {
+ return true;
+ }
+
+};
+
+/**
+ * The arguments to the executable must be:
+ * - applet communication server name
+ * - metadata file name
+ * - applet ID as a string
+ * - applet instance file data path
+ */
+int main(int argc, char **argv)
+{
+ // Check for correct number of arguments
+ if (argc != 5) {
+ qWarning() << "Invalid number of arguments";
+ return ERROR_INVALID_ARGUMENTS;
+ }
+
+ // Load applet metadata
+ MAppletMetaData metadata(argv[2]);
+ if (!metadata.isValid()) {
+ qWarning() << "Applet metadata " << argv[2] << "is not valid";
+ return ERROR_APPLET_INIT_FAILED;
+ }
+
+ MApplication app(argc, argv, metadata.resourceIdentifier(), new MyApplicationService());
+ MAppletRunner runner;
+ if (!runner.init(argv[1], metadata, argv[3], argv[4])) {
+ qWarning() << "Applet initialization failed";
+ return ERROR_APPLET_INIT_FAILED;
+ }
+
+ return app.exec();
+}
diff --git a/mappletrunner/mappletrunner.cpp b/mappletrunner/mappletrunner.cpp
new file mode 100644
index 00000000..44140cde
--- /dev/null
+++ b/mappletrunner/mappletrunner.cpp
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it 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.
+**
+****************************************************************************/
+
+#include "mappletrunner.h"
+#include <mappletmetadata.h>
+#include <mappletsettings.h>
+#include <mappleticonchangedmessage.h>
+#include <mapplettitlechangedmessage.h>
+#include <mapplettextchangedmessage.h>
+#include <mappletclient.h>
+#include <mappletloader.h>
+#include <mfiledatastore.h>
+#include <mwidget.h>
+#include <QMetaProperty>
+#include <QGraphicsLinearLayout>
+#include <QDebug>
+
+MAppletRunner::MAppletRunner() : MExtensionRunner(),
+ appletInstanceDataStore(NULL),
+ appletSettings(NULL)
+{
+}
+
+MAppletRunner::~MAppletRunner()
+{
+ delete appletSettings;
+}
+
+bool MAppletRunner::init(const QString &serverName, MAppletMetaData &metaData, const QString &appletId, const QString &appletInstanceFileDataPath)
+{
+ // Check whether the applet ID is valid
+ if (appletId.isEmpty()) {
+ qWarning() << "Applet ID is not valid.";
+ return false;
+ }
+
+ // Check whether the metadata is valid
+ if (!metaData.isValid()) {
+ qWarning() << "Applet metadata is not valid.";
+ return false;
+ }
+
+ // Try to construct a valid instance data store and bail out if not successful
+ appletInstanceDataStore = new MFileDataStore(appletInstanceFileDataPath);
+ if (!appletInstanceDataStore->isReadable() || !appletInstanceDataStore->isWritable()) {
+ qWarning() << "Couldn't create applet instance data store";
+ teardown();
+ return false;
+ }
+
+ appletSettings = new MAppletSettings(metaData.fileName(), appletId);
+
+ bool success = MExtensionRunner::init(serverName);
+
+ if (success) {
+ // Instantiate the applet and get the applet's widget
+ widget = MAppletLoader::loadApplet(metaData, *appletInstanceDataStore, *appletSettings->dataAccess());
+ success = false;
+
+ if (widget != NULL) {
+ // Put the widget into the parent widget's layout for layout request watching
+ QGraphicsLinearLayout *layout = dynamic_cast<QGraphicsLinearLayout *>(parentWidget->layout());
+ if (layout != NULL) {
+ layout->addItem(widget);
+ success = true;
+ }
+ }
+
+ if (success) {
+ setAppletProperties();
+ }
+ }
+
+ return success;
+}
+
+void MAppletRunner::setAppletProperties()
+{
+ if (widget == NULL) {
+ return;
+ }
+
+ const QMetaObject *mob = widget->metaObject();
+
+ // use applet properties to fill header of the container
+ int iconProperty = mob->indexOfProperty("appletIcon");
+ int titleProperty = mob->indexOfProperty("appletTitle");
+ int textProperty = mob->indexOfProperty("appletText");
+
+ int iconSignal = mob->indexOfSignal("appletIconChanged(QString)");
+ int titleSignal = mob->indexOfSignal("appletTitleChanged(QString)");
+ int textSignal = mob->indexOfSignal("appletTextChanged(QString)");
+
+ if (iconProperty != -1) {
+ QString icon((mob->property(iconProperty).read(widget)).toString());
+ if (!icon.isNull()) {
+ appletIconChanged(icon);
+ }
+ }
+
+ if (titleProperty != -1) {
+ QString title((mob->property(titleProperty).read(widget)).toString());
+ if (!title.isNull()) {
+ appletTitleChanged(title);
+ }
+ }
+
+ if (textProperty != -1) {
+ QString text((mob->property(textProperty).read(widget)).toString());
+ if (!text.isNull()) {
+ appletTextChanged(text);
+ }
+ }
+
+ if (iconSignal != -1) {
+ connect(widget, SIGNAL(appletIconChanged(QString)), this, SLOT(appletIconChanged(QString)));
+ }
+
+ if (titleSignal != -1) {
+ connect(widget, SIGNAL(appletTitleChanged(QString)), this, SLOT(appletTitleChanged(QString)));
+ }
+
+ if (textSignal != -1) {
+ connect(widget, SIGNAL(appletTextChanged(QString)), this, SLOT(appletTextChanged(QString)));
+ }
+
+ // Connect the deprecated signals
+ // TODO remove these after the deprecation period
+ iconSignal = mob->indexOfSignal("setAppletIcon(QString)");
+ titleSignal = mob->indexOfSignal("setAppletTitle(QString)");
+ textSignal = mob->indexOfSignal("setAppletText(QString)");
+ if (iconSignal != -1) {
+ connect(widget, SIGNAL(setAppletIcon(QString)), this, SLOT(appletIconChanged(QString)));
+ }
+ if (titleSignal != -1) {
+ connect(widget, SIGNAL(setAppletTitle(QString)), this, SLOT(appletTitleChanged(QString)));
+ }
+ if (textSignal != -1) {
+ connect(widget, SIGNAL(setAppletText(QString)), this, SLOT(appletTextChanged(QString)));
+ }
+
+ connect(this, SIGNAL(visibilityChanged(bool)), widget, SIGNAL(visibilityChanged(bool)));
+ connect(view, SIGNAL(orientationChanged(M::Orientation)), widget, SIGNAL(orientationChanged(M::Orientation)));
+}
+
+void MAppletRunner::teardown()
+{
+ MExtensionRunner::teardown();
+
+ delete appletInstanceDataStore;
+ appletInstanceDataStore = NULL;
+}
+
+void MAppletRunner::appletIconChanged(const QString &newIcon)
+{
+ MAppletIconChangedMessage m;
+ m.setIcon(newIcon);
+ communicator->sendMessage(m);
+}
+
+void MAppletRunner::appletTitleChanged(const QString &newTitle)
+{
+ MAppletTitleChangedMessage m;
+ m.setTitle(newTitle);
+ communicator->sendMessage(m);
+}
+
+void MAppletRunner::appletTextChanged(const QString &newText)
+{
+ MAppletTextChangedMessage m;
+ m.setText(newText);
+ communicator->sendMessage(m);
+}
diff --git a/mappletrunner/mappletrunner.h b/mappletrunner/mappletrunner.h
new file mode 100644
index 00000000..3126c490
--- /dev/null
+++ b/mappletrunner/mappletrunner.h
@@ -0,0 +1,100 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it 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.
+**
+****************************************************************************/
+
+#ifndef MAPPLETRUNNER_H
+#define MAPPLETRUNNER_H
+
+#include "mextensionrunner.h"
+
+class MFileDataStore;
+class MDataAccess;
+class MGConfDataStore;
+class MSettingsLanguageBinary;
+class MAppletSettings;
+
+/**
+ * \ingroup appletrunner
+ *
+ * MAppletRunner is a class that is used to start and run oop (out of process)
+ * applet widgets.
+ */
+class MAppletRunner : public MExtensionRunner
+{
+public:
+ /*!
+ * MAppletRunner constructor
+ */
+ MAppletRunner();
+
+ //! MAppletRunner destructor
+ virtual ~MAppletRunner();
+
+ /*!
+ * Initialize the applet and establish an IPC connection between the runner and
+ * the host application.
+ * \param serverName the name of the host process's server.
+ * \param metaData Metadata of the applet.
+ * \param appletId applet ID as a string
+ * \param appletInstanceFileDataPath path to data file used to store instance specific data about this applet.
+ * \return \c true if the applet and ipc connection was initialized correctly,
+ * \c false if something went wrong.
+ */
+ bool init(const QString &serverName, MAppletMetaData &metaData, const QString &appletId, const QString &appletInstanceFileDataPath);
+
+protected:
+ //! Data for the applet instance
+ MFileDataStore *appletInstanceDataStore;
+
+ //! An interface for applets to access their settings
+ MAppletSettings *appletSettings;
+
+protected slots:
+ /*!
+ * \brief Applet changed its icon, part of container communication API
+ */
+ void appletIconChanged(const QString &newIcon);
+
+ /*!
+ * \brief Applet changed its title, part of container communication API
+ */
+ void appletTitleChanged(const QString &newTitle);
+
+ /*!
+ * \brief Applet changed its additional text, part of container communication API
+ */
+ void appletTextChanged(const QString &newText);
+
+protected:
+ /*!
+ * Sets the icon, title and text properties of an applet and connects any
+ * related signals to slots so the changes in the properties are handled
+ * correctly.
+ */
+ void setAppletProperties();
+
+ //! \reimp
+ virtual void teardown();
+ //! \reimp_end
+
+#ifdef UNIT_TEST
+ friend class Ut_MAppletRunner;
+#endif
+};
+
+#endif // MAPPLETRUNNER_H
diff --git a/mappletrunner/mappletrunner.pro b/mappletrunner/mappletrunner.pro
new file mode 100644
index 00000000..81af8d98
--- /dev/null
+++ b/mappletrunner/mappletrunner.pro
@@ -0,0 +1,41 @@
+include(../mkspecs/common.pri)
+
+INCLUDEPATH += . \
+ ../src/extensions/mashup/mashup \
+ ../src/include \
+ ../src/extensions/mashup/appletcommunication \
+ ../src/extensions/mashup/appletinterface \
+ ../src/extensions/applicationextension
+DEPENDPATH += $$INCLUDEPATH
+QMAKE_LIBDIR += ../lib
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+
+LIBS += \
+ -lmeegotouchcore \
+ -lmeegotouchviews \
+ -lmeegotouchsettings \
+ -lmeegotouchextensions \
+
+QT += core \
+ network \
+ gui \
+ svg \
+ dbus \
+ xml
+
+# Input
+SOURCES += main.cpp \
+ mappletrunner.cpp
+
+HEADERS += mappletrunner.h
+
+QMAKE_EXTRA_TARGETS += check
+check.depends = $$TARGET
+check.commands = $$system(true)
+QMAKE_EXTRA_TARGETS += check-xml
+check-xml.depends = $$TARGET
+check-xml.commands = $$system(true)
+target.path = $$M_APPLET_DIR
+INSTALLS += target