From: Mohammed Sameer Date: Mon, 24 Jun 2013 19:42:18 +0000 (+0300) Subject: Replace maemo-meegotouch interfaces with DBus calls. X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=commitdiff_plain;h=5524755e320d7049a6ea6fcb6fd11bed51affc0f Replace maemo-meegotouch interfaces with DBus calls. Drop share ui and gallery usage via interfaces and use configurable DBus method calls instead. This drops 2 harmattan specific packages from our dependencies. --- diff --git a/data/n9/cameraplus.ini b/data/n9/cameraplus.ini index a68b276..6bc3995 100644 --- a/data/n9/cameraplus.ini +++ b/data/n9/cameraplus.ini @@ -10,3 +10,19 @@ backgroundRenderingColor = @Variant(\0\0\0\x43\x1\xff\xff\0\0\0\0\0\0\0\0) # temporaryFilePath = dbusThumbnailingEnabled = true thumbnailCreationEnabled = true + +[gallery] +enabled = true +type = dbus +path = / +interface = com.nokia.maemo.meegotouch.GalleryInterface +dest = com.nokia.Gallery +method = camera-roll:showCameraRoll|show-media:showMediaInFullScreen + +[share] +enabled = true +type = dbus +path = / +interface = com.nokia.maemo.meegotouch.ShareUiInterface +dest = com.nokia.ShareUi +method = share:share diff --git a/debian/control b/debian/control index 7cf8406..0336d0c 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,7 @@ Build-Depends: debhelper (>= 7.1), applauncherd-dev, libqmsystem2-dev, libresour libquill-dev, meego-gstreamer0.10-interfaces-dev, libgstreamer0.10-dev, libgstreamer-plugins-base0.10-dev, gstreamer0.10-plugins-bad-dev, libcanberra-dev, libcontextsubscriber-dev, libqtm-location-dev, - libqtsparql-dev, maemo-meegotouch-interfaces-dev, libqtm-systeminfo-dev, + libqtsparql-dev, libqtm-systeminfo-dev, aegis-builder Standards-Version: 3.9.1 diff --git a/qml/PostCapturePage.qml b/qml/PostCapturePage.qml index d3a4546..4b1f13c 100644 --- a/qml/PostCapturePage.qml +++ b/qml/PostCapturePage.qml @@ -129,10 +129,12 @@ CameraPage { ShareHelper { id: share + settings: platformSettings } GalleryHelper { id: gallery + settings: platformSettings } Rectangle { diff --git a/src/dbusservice.cpp b/src/dbusservice.cpp new file mode 100644 index 0000000..6c10d3f --- /dev/null +++ b/src/dbusservice.cpp @@ -0,0 +1,152 @@ +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "dbusservice.h" +#include +#include "platformsettings.h" +#include +#include + +// We cannot use ADBusInterface because it will try to introspect the service upon +// creation. This will lead to services being launched when we create the interfaces. +DbusService::DbusService(QObject *parent) : + QObject(parent), m_settings(0), m_enabled(false) { + +} + +DbusService::~DbusService() { + +} + +PlatformSettings *DbusService::settings() const { + return m_settings; +} + +void DbusService::setSettings(PlatformSettings *settings) { + if (m_settings != settings) { + m_settings = settings; + + init(); + + emit settingsChanged(); + } +} + +void DbusService::setName(const QString& name) { + if (m_name != name) { + m_name = name; + + init(); + + emit nameChanged(); + } +} + +bool DbusService::isEnabled() const { + return m_enabled; +} + +void DbusService::init() { + if (m_name.isEmpty() || !m_settings) { + return; + } + + PlatformSettings::Service service = m_settings->service(m_name); + + if (service.m_type != "dbus") { + qmlInfo(this) << "Unknown service type" << service.m_type; + return; + } + + if (!service.m_enabled) { + qmlInfo(this) << "Not initializing a disabled service"; + return; + } + + m_path = service.m_path; + m_interface = service.m_interface; + m_dest = service.m_dest; + + QStringList methods = service.m_method.split('|'); + foreach (const QString& method, methods) { + QStringList parts = method.split(':'); + if (parts.size() != 2) { + qmlInfo(this) << "Cannot parse dbus method description" << method; + continue; + } + + QString id = parts[0].trimmed(); + QString val = parts[1].trimmed(); + if (id.isEmpty() || val.isEmpty()) { + qmlInfo(this) << "Empty id or value"; + continue; + } + + m_methods[id] = val; + } + + m_enabled = service.m_enabled; + emit isEnabledChanged(); +} + +bool DbusService::asyncCall(const QString& method, const QVariant& arg) { + if (!m_settings) { + qmlInfo(this) << "Empty settings."; + return false; + } + + if (!m_enabled) { + qmlInfo(this) << "Service is not enabled."; + return false; + } + + if (m_dest.isEmpty() || m_path.isEmpty() || m_interface.isEmpty()) { + qmlInfo(this) << "Unable to construct DBus method call."; + return false; + } + + if (method.isEmpty()) { + qmlInfo(this) << "Empty method call"; + return false; + } + + if (!m_methods.contains(method)) { + qmlInfo(this) << "Unknown method call ID" << method; + return false; + } + + QString call = m_methods[method]; + + QDBusMessage msg = QDBusMessage::createMethodCall(m_dest, m_path, m_interface, call); + msg.setAutoStartService(true); + if (arg.isValid()) { + msg.setArguments(QList() << arg); + } + + QDBusConnection conn = QDBusConnection::sessionBus(); + if (!conn.isConnected()) { + qmlInfo(this) << "Unable to connect to DBus session bus."; + return false; + } + + conn.asyncCall(msg); + + return true; +} diff --git a/src/dbusservice.h b/src/dbusservice.h new file mode 100644 index 0000000..7ef5c2c --- /dev/null +++ b/src/dbusservice.h @@ -0,0 +1,71 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef DBUS_SERVICE_H +#define DBUS_SERVICE_H + +#include +#include +#include + +class PlatformSettings; + +class DbusService : public QObject { + Q_OBJECT + + Q_PROPERTY(PlatformSettings* settings READ settings WRITE setSettings NOTIFY settingsChanged); + Q_PROPERTY(bool enabled READ isEnabled NOTIFY isEnabledChanged); + +public: + DbusService(QObject *parent = 0); + ~DbusService(); + + PlatformSettings *settings() const; + void setSettings(PlatformSettings *settings); + + void setName(const QString& name); + + bool isEnabled() const; + + bool asyncCall(const QString& method, const QVariant& arg = QVariant()); + +signals: + void settingsChanged(); + void nameChanged(); + void isEnabledChanged(); + +private: + void init(); + + PlatformSettings *m_settings; + QString m_name; + + QString m_path; + QString m_interface; + QString m_dest; + + bool m_enabled; + + QMap m_methods; +}; + +#endif /* DBUS_SERVICE_H */ diff --git a/src/galleryhelper.cpp b/src/galleryhelper.cpp index 724550a..fc886f4 100644 --- a/src/galleryhelper.cpp +++ b/src/galleryhelper.cpp @@ -19,35 +19,28 @@ */ #include "galleryhelper.h" -#include #include #include -#include GalleryHelper::GalleryHelper(QObject *parent) : - QObject(parent), - m_iface(new GalleryInterface) { - + DbusService(parent) { + setName("gallery"); } GalleryHelper::~GalleryHelper() { - delete m_iface; + } bool GalleryHelper::show(const QUrl& path) { - if (!m_iface->isValid()) { - qmlInfo(this) << "Failed to get gallery interface"; - return false; - } + // TODO: this is not working and I don't know why. + QStringList args; + args << path.toLocalFile(); - return m_iface->showMediaInFullScreen(QStringList() << path.toLocalFile()); + QVariant var(args); + + return asyncCall("show-media", var); } bool GalleryHelper::launch() { - if (!m_iface->isValid()) { - qmlInfo(this) << "Failed to get gallery interface"; - return false; - } - - return m_iface->showCameraRoll(); + return asyncCall("camera-roll"); } diff --git a/src/galleryhelper.h b/src/galleryhelper.h index eec42bf..80e7c77 100644 --- a/src/galleryhelper.h +++ b/src/galleryhelper.h @@ -23,12 +23,11 @@ #ifndef GALLERY_HELPER_H #define GALLERY_HELPER_H -#include +#include "dbusservice.h" class QUrl; -class GalleryInterface; -class GalleryHelper : public QObject { +class GalleryHelper : public DbusService { Q_OBJECT public: @@ -37,9 +36,6 @@ public: Q_INVOKABLE bool show(const QUrl& path); Q_INVOKABLE bool launch(); - -private: - GalleryInterface *m_iface; }; #endif /* GALLERY_HELPER_H */ diff --git a/src/main.cpp b/src/main.cpp index 13beeca..9f83baa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,6 +46,7 @@ #include "deviceinfo.h" #include "devicekeys.h" #include "platformsettings.h" +#include "dbusservice.h" #ifdef QMLJSDEBUGGER #include "qt_private/qdeclarativedebughelper_p.h" diff --git a/src/platformsettings.cpp b/src/platformsettings.cpp index d739695..2d20498 100644 --- a/src/platformsettings.cpp +++ b/src/platformsettings.cpp @@ -107,3 +107,19 @@ void PlatformSettings::init() { QDir().mkpath(tempPath); Quill::setTemporaryFilePath(tempPath); } + +PlatformSettings::Service PlatformSettings::service(const QString& id) { + PlatformSettings::Service service; + m_settings->beginGroup(id); + + service.m_enabled = m_settings->value("enabled", false).toBool(); + service.m_type = m_settings->value("type").toString(); + service.m_path = m_settings->value("path").toString(); + service.m_interface = m_settings->value("interface").toString(); + service.m_dest = m_settings->value("dest").toString(); + service.m_method = m_settings->value("method").toString(); + + m_settings->endGroup(); + + return service; +} diff --git a/src/platformsettings.h b/src/platformsettings.h index 20ca2f9..cb51a12 100644 --- a/src/platformsettings.h +++ b/src/platformsettings.h @@ -36,6 +36,16 @@ public: PlatformSettings(QObject *parent = 0); ~PlatformSettings(); + class Service { + public: + bool m_enabled; + QString m_type; + QString m_path; + QString m_interface; + QString m_dest; + QString m_method; + }; + QSize previewSize(); QString thumbnailFlavorName(); @@ -45,6 +55,8 @@ public: bool isThumbnailCreationEnabled(); QString temporaryFilePath(); + Service service(const QString& id); + public slots: void init(); diff --git a/src/sharehelper.cpp b/src/sharehelper.cpp index 5f4b3ef..85b4db5 100644 --- a/src/sharehelper.cpp +++ b/src/sharehelper.cpp @@ -19,28 +19,24 @@ */ #include "sharehelper.h" -#include #include #include -#include +#include ShareHelper::ShareHelper(QObject *parent) : - QObject(parent), - m_iface(new ShareUiInterface) { + DbusService(parent) { + setName("share"); } ShareHelper::~ShareHelper() { - delete m_iface; } bool ShareHelper::share(const QUrl& path) { - if (!m_iface->isValid()) { - qmlInfo(this) << "Failed to get share interface"; - return false; - } + QStringList args; + args << path.toLocalFile(); - m_iface->share(QStringList() << path.toLocalFile()); + QVariant var(args); - return true; + return asyncCall("share", args); } diff --git a/src/sharehelper.h b/src/sharehelper.h index cf64704..f80707c 100644 --- a/src/sharehelper.h +++ b/src/sharehelper.h @@ -23,12 +23,11 @@ #ifndef SHARE_HELPER_H #define SHARE_HELPER_H -#include +#include "dbusservice.h" class QUrl; -class ShareUiInterface; -class ShareHelper : public QObject { +class ShareHelper : public DbusService { Q_OBJECT public: @@ -36,9 +35,6 @@ public: ~ShareHelper(); Q_INVOKABLE bool share(const QUrl& path); - -private: - ShareUiInterface *m_iface; }; #endif /* SHARE_HELPER_H */ diff --git a/src/src.pro b/src/src.pro index fbddb4d..ababc84 100644 --- a/src/src.pro +++ b/src/src.pro @@ -5,8 +5,7 @@ INCLUDEPATH += . ../ QT += declarative opengl dbus -CONFIG += link_pkgconfig mobility qtsparql galleryinterface-maemo-meegotouch \ - shareuiinterface-maemo-meegotouch +CONFIG += link_pkgconfig mobility qtsparql MOBILITY += location systeminfo @@ -16,13 +15,13 @@ SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp displaystate.cpp f cameraresources.cpp compass.cpp orientation.cpp geocode.cpp mountprotector.cpp \ trackerstore.cpp focusrectangle.cpp sharehelper.cpp deletehelper.cpp galleryhelper.cpp \ postcapturemodel.cpp batteryinfo.cpp gridlines.cpp deviceinfo.cpp devicekeys.cpp \ - platformsettings.cpp + platformsettings.cpp dbusservice.cpp HEADERS += settings.h filenaming.h quillitem.h displaystate.h fsmonitor.h \ cameraresources.h compass.h orientation.h geocode.h mountprotector.h \ trackerstore.h focusrectangle.h sharehelper.h deletehelper.h galleryhelper.h \ postcapturemodel.h batteryinfo.h gridlines.h deviceinfo.h devicekeys.h \ - platformsettings.h + platformsettings.h dbusservice.h RESOURCES += ../qml/qml.qrc