From 0ce83eaec01e173cb4765562c82b1d7b313b81b0 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Tue, 2 Oct 2012 18:58:33 +0200 Subject: Add ignore rules. --- .bzrignore | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .bzrignore diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 0000000..e6d67c2 --- /dev/null +++ b/.bzrignore @@ -0,0 +1,18 @@ +CMakeCache.txt +CMakeFiles/ +CTestTestfile.cmake +Makefile +Testing/ +cmake_install.cmake + +moc_*.cxx + +examples/run-example.sh + +tests/client/*.moc +tests/client/actiongrouptest +tests/client/convertertest +tests/client/menuchangestest +tests/client/modeltest +tests/client/servicetest + -- cgit v1.2.3 From 63c4e470df7701eeaf26c748ab0c0d2b413dd07c Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 08:30:40 +0200 Subject: Updated ignore rules. --- .bzrignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.bzrignore b/.bzrignore index e6d67c2..0fbb439 100644 --- a/.bzrignore +++ b/.bzrignore @@ -16,3 +16,10 @@ tests/client/menuchangestest tests/client/modeltest tests/client/servicetest +obj-* +debian/files +debian/qmenumodel-qml +debian/*.debhelper.log +debian/*.substvars +debian/stamp-* + -- cgit v1.2.3 From 90bd3a7ca55307380766036c9eaac058f5e3b4f5 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 08:49:47 +0200 Subject: Fix a typo. --- tests/script/menuscript.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/menuscript.py b/tests/script/menuscript.py index f50aacd..ba67560 100644 --- a/tests/script/menuscript.py +++ b/tests/script/menuscript.py @@ -127,7 +127,7 @@ class ActionList(object): self._actions = [] self._actions_bk = [] self._objectPath = objectPath - self._bux = None + self._bus = None self._exportMenuID = None self._exportActionID = None self._ownNameID = None -- cgit v1.2.3 From 57b1e3f69f7d1bb05ebc958dd27cc6743e063fb4 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 08:51:45 +0200 Subject: =?UTF-8?q?Remove=20the=20implementation=20of=20columnCount.=20Acc?= =?UTF-8?q?ording=20to=20the=20documentation=20(http://doc.qt.digia.com/st?= =?UTF-8?q?able/model-view-programming.html#model-subclassing-reference),?= =?UTF-8?q?=20=C2=AB=20List=20models=20do=20not=20provide=20this=20functio?= =?UTF-8?q?n=20because=20it=20is=20already=20implemented=20in=20QAbstractL?= =?UTF-8?q?istModel.=20=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/qmenumodel.cpp | 6 ------ src/common/qmenumodel.h | 1 - tests/client/modeltest.cpp | 8 -------- 3 files changed, 15 deletions(-) diff --git a/src/common/qmenumodel.cpp b/src/common/qmenumodel.cpp index cc760c1..e88bc66 100644 --- a/src/common/qmenumodel.cpp +++ b/src/common/qmenumodel.cpp @@ -90,12 +90,6 @@ GMenuModel *QMenuModel::menuModel() const return m_menuModel; } -/*! \internal */ -int QMenuModel::columnCount(const QModelIndex &) const -{ - return 1; -} - /*! \internal */ QVariant QMenuModel::data(const QModelIndex &index, int role) const { diff --git a/src/common/qmenumodel.h b/src/common/qmenumodel.h index ba5696d..598efd6 100644 --- a/src/common/qmenumodel.h +++ b/src/common/qmenumodel.h @@ -39,7 +39,6 @@ public: ~QMenuModel(); /* QAbstractItemModel */ - int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QModelIndex parent (const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index ee3e0f4..76a3e97 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -56,14 +56,6 @@ private Q_SLOTS: m_script.unpublishMenu(); } - /* - * Test if columnCount is always 1 - */ - void testColumnCount() - { - QCOMPARE(m_model.columnCount(), 1); - } - /* * Test if parent function always return a empty QModelIndex */ -- cgit v1.2.3 From facb9bfef3ceb7de01e3c0f66db2dc45ea86a08a Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 09:31:10 +0200 Subject: Fix a typo. --- src/common/qdbusmenumodel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/qdbusmenumodel.h b/src/common/qdbusmenumodel.h index 8308268..9af516d 100644 --- a/src/common/qdbusmenumodel.h +++ b/src/common/qdbusmenumodel.h @@ -52,7 +52,7 @@ protected: virtual void serviceVanish(GDBusConnection *connection); private: - // workaround to support int as bustType + // workaround to support int as busType void setIntBusType(int busType); }; -- cgit v1.2.3 From a9416ebfa48082278abd2a237964989334fc24c5 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 10:40:43 +0200 Subject: Fix signal parameter type, unaccessible in QMl otherwise. --- src/common/qdbusactiongroup.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/qdbusactiongroup.h b/src/common/qdbusactiongroup.h index 2f46f8f..dd3726c 100644 --- a/src/common/qdbusactiongroup.h +++ b/src/common/qdbusactiongroup.h @@ -50,7 +50,7 @@ Q_SIGNALS: void busTypeChanged(BusType type); void busNameChanged(const QString &busNameChanged); void objectPathChanged(const QString &objectPath); - void statusChanged(ConnectionStatus status); + void statusChanged(QDBusObject::ConnectionStatus status); void actionAppear(const QString &name); void actionVanish(const QString &name); void actionStateChanged(const QString &name, QVariant state); @@ -69,7 +69,7 @@ private: int m_signalActionRemovedId; int m_signalStateChangedId; - // workaround to support int as bustType + // workaround to support int as busType void setIntBusType(int busType); void setActionGroup(GDBusActionGroup *ag); -- cgit v1.2.3 From 36426c5ef4e8d3c8e850996c447d6999e21479c6 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 12:04:46 +0200 Subject: Move the enums into a class that inherits QObject, so they can be exposed and used directly from QML. --- src/QMenuModel/plugin.cpp | 2 ++ src/common/CMakeLists.txt | 1 + src/common/dbus-enums.h | 53 ++++++++++++++++++++++++++++++++++++++++ src/common/qdbusactiongroup.cpp | 4 +-- src/common/qdbusactiongroup.h | 4 +-- src/common/qdbusmenumodel.cpp | 4 +-- src/common/qdbusmenumodel.h | 4 +-- src/common/qdbusobject.cpp | 36 +++++++++++++-------------- src/common/qdbusobject.h | 31 ++++++++--------------- tests/client/actiongrouptest.cpp | 22 ++++++++--------- tests/client/menuchangestest.cpp | 2 +- tests/client/modeltest.cpp | 14 +++++------ tests/client/servicetest.cpp | 20 +++++++-------- 13 files changed, 121 insertions(+), 76 deletions(-) create mode 100644 src/common/dbus-enums.h diff --git a/src/QMenuModel/plugin.cpp b/src/QMenuModel/plugin.cpp index 494dd2c..ec51ae9 100644 --- a/src/QMenuModel/plugin.cpp +++ b/src/QMenuModel/plugin.cpp @@ -32,6 +32,8 @@ void QMenuModelQmlPlugin::registerTypes(const char *uri) "QMenuModel is a interface"); qmlRegisterUncreatableType(uri, 0, 1, "QStateAction", "QStateAction must be created by QDBusActionGroup::action"); + qmlRegisterUncreatableType(uri, 0, 1, "DBus", + "DBus is only a namespace"); qmlRegisterType(uri, 0, 1, "QDBusMenuModel"); qmlRegisterType(uri, 0, 1, "QDBusActionGroup"); diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index ad3343a..2b831b7 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -11,6 +11,7 @@ set(QMENUMODELCOMMON_SRC set(QMENUMODELCOMMON_HEADERS converter.h + dbus-enums.h qmenumodel.h qdbusobject.h qdbusmenumodel.h diff --git a/src/common/dbus-enums.h b/src/common/dbus-enums.h new file mode 100644 index 0000000..76149da --- /dev/null +++ b/src/common/dbus-enums.h @@ -0,0 +1,53 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Olivier Tilloy + */ + +#ifndef __DBUS_ENUMS__ +#define __DBUS_ENUMS__ + +#include + +// This class acts as a namespace only, with the addition that its enums +// are registered to be exposed on the QML side. +class DBusEnums : public QObject +{ + Q_OBJECT + + Q_ENUMS(BusType) + Q_ENUMS(ConnectionStatus) + +public: + enum BusType { + None = 0, + SessionBus, + SystemBus, + LastBusType + }; + + enum ConnectionStatus { + Disconnected = 0, + Connecting, + Connected + }; + +private: + DBusEnums() {} +}; + +#endif // __DBUS_ENUMS__ + diff --git a/src/common/qdbusactiongroup.cpp b/src/common/qdbusactiongroup.cpp index 629915b..d25f2de 100644 --- a/src/common/qdbusactiongroup.cpp +++ b/src/common/qdbusactiongroup.cpp @@ -143,8 +143,8 @@ void QDBusActionGroup::stop() /*! \internal */ void QDBusActionGroup::setIntBusType(int busType) { - if ((busType > None) && (busType < LastBusType)) { - setBusType(static_cast(busType)); + if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) { + setBusType(static_cast(busType)); } } diff --git a/src/common/qdbusactiongroup.h b/src/common/qdbusactiongroup.h index dd3726c..2bd0a15 100644 --- a/src/common/qdbusactiongroup.h +++ b/src/common/qdbusactiongroup.h @@ -47,10 +47,10 @@ public: Q_INVOKABLE QVariant actionState(const QString &name); Q_SIGNALS: - void busTypeChanged(BusType type); + void busTypeChanged(DBusEnums::BusType type); void busNameChanged(const QString &busNameChanged); void objectPathChanged(const QString &objectPath); - void statusChanged(QDBusObject::ConnectionStatus status); + void statusChanged(DBusEnums::ConnectionStatus status); void actionAppear(const QString &name); void actionVanish(const QString &name); void actionStateChanged(const QString &name, QVariant state); diff --git a/src/common/qdbusmenumodel.cpp b/src/common/qdbusmenumodel.cpp index 9b824b4..354b10b 100644 --- a/src/common/qdbusmenumodel.cpp +++ b/src/common/qdbusmenumodel.cpp @@ -104,7 +104,7 @@ void QDBusMenuModel::serviceAppear(GDBusConnection *connection) /*! \internal */ void QDBusMenuModel::setIntBusType(int busType) { - if ((busType > None) && (busType < LastBusType)) { - setBusType(static_cast(busType)); + if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) { + setBusType(static_cast(busType)); } } diff --git a/src/common/qdbusmenumodel.h b/src/common/qdbusmenumodel.h index 9af516d..2660ffe 100644 --- a/src/common/qdbusmenumodel.h +++ b/src/common/qdbusmenumodel.h @@ -38,10 +38,10 @@ public: ~QDBusMenuModel(); Q_SIGNALS: - void busTypeChanged(BusType type); + void busTypeChanged(DBusEnums::BusType type); void busNameChanged(const QString &busNameChanged); void objectPathChanged(const QString &objectPath); - void statusChanged(QDBusObject::ConnectionStatus status); + void statusChanged(DBusEnums::ConnectionStatus status); public Q_SLOTS: void start(); diff --git a/src/common/qdbusobject.cpp b/src/common/qdbusobject.cpp index d5ac44b..ff2a4a6 100644 --- a/src/common/qdbusobject.cpp +++ b/src/common/qdbusobject.cpp @@ -70,10 +70,10 @@ QDBusObject::QDBusObject() :m_watchId(0), - m_busType(None), - m_status(QDBusObject::Disconnected) + m_busType(DBusEnums::None), + m_status(DBusEnums::Disconnected) { - qRegisterMetaType("QDBusObject::ConnectionStatus"); + qRegisterMetaType("DBusEnums::ConnectionStatus"); } QDBusObject::~QDBusObject() @@ -84,15 +84,15 @@ QDBusObject::~QDBusObject() } } -QDBusObject::BusType QDBusObject::busType() const +DBusEnums::BusType QDBusObject::busType() const { return m_busType; } -void QDBusObject::setBusType(QDBusObject::BusType type) +void QDBusObject::setBusType(DBusEnums::BusType type) { if (m_busType != type) { - if (m_status != QDBusObject::Disconnected) + if (m_status != DBusEnums::Disconnected) disconnect(); m_busType = type; busTypeChanged(m_busType); @@ -107,7 +107,7 @@ QString QDBusObject::busName() const void QDBusObject::setBusName(const QString &busName) { if (m_busName != busName) { - if (m_status != QDBusObject::Disconnected) + if (m_status != DBusEnums::Disconnected) disconnect(); m_busName = busName; busNameChanged(m_busName); @@ -122,14 +122,14 @@ QString QDBusObject::objectPath() const void QDBusObject::setObjectPath(const QString &objectPath) { if (m_objectPath != objectPath) { - if (m_status != QDBusObject::Disconnected) + if (m_status != DBusEnums::Disconnected) disconnect(); m_objectPath = objectPath; objectPathChanged(m_objectPath); } } -void QDBusObject::setStatus(QDBusObject::ConnectionStatus status) +void QDBusObject::setStatus(DBusEnums::ConnectionStatus status) { if (m_status != status) { m_status = status; @@ -137,17 +137,17 @@ void QDBusObject::setStatus(QDBusObject::ConnectionStatus status) } } -QDBusObject::ConnectionStatus QDBusObject::status() const +DBusEnums::ConnectionStatus QDBusObject::status() const { return m_status; } void QDBusObject::connect() { - if (m_status != QDBusObject::Disconnected) { + if (m_status != DBusEnums::Disconnected) { return; - } else if ((m_busType > None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { - GBusType type = m_busType == SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; + } else if ((m_busType > DBusEnums::None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { + GBusType type = m_busType == DBusEnums::SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; m_watchId = g_bus_watch_name (type, m_busName.toLatin1(), G_BUS_NAME_WATCHER_FLAGS_NONE, @@ -156,7 +156,7 @@ void QDBusObject::connect() this, NULL); - setStatus(QDBusObject::Connecting); + setStatus(DBusEnums::Connecting); } else { qWarning() << "Invalid dbus connection args"; } @@ -164,10 +164,10 @@ void QDBusObject::connect() void QDBusObject::disconnect() { - if (m_status != QDBusObject::Disconnected) { + if (m_status != DBusEnums::Disconnected) { g_bus_unwatch_name (m_watchId); m_watchId = 0; - setStatus(QDBusObject::Disconnected); + setStatus(DBusEnums::Disconnected); } } @@ -175,7 +175,7 @@ void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, { QDBusObject *self = reinterpret_cast(data); - self->setStatus(QDBusObject::Connected); + self->setStatus(DBusEnums::Connected); self->serviceAppear(connection); } @@ -183,6 +183,6 @@ void QDBusObject::onServiceFanished(GDBusConnection *connection, const gchar *, { QDBusObject *self = reinterpret_cast(data); - self->setStatus(QDBusObject::Connecting); + self->setStatus(DBusEnums::Connecting); self->serviceVanish(connection); } diff --git a/src/common/qdbusobject.h b/src/common/qdbusobject.h index c50d540..cad6658 100644 --- a/src/common/qdbusobject.h +++ b/src/common/qdbusobject.h @@ -24,27 +24,16 @@ #include +#include "dbus-enums.h" + class QDBusObject { public: - enum BusType { - None = 0, - SessionBus, - SystemBus, - LastBusType - }; - - enum ConnectionStatus { - Disconnected = 0, - Connecting, - Connected - }; - QDBusObject(); ~QDBusObject(); - BusType busType() const; - void setBusType(BusType type); + DBusEnums::BusType busType() const; + void setBusType(DBusEnums::BusType type); QString busName() const; void setBusName(const QString &busName); @@ -52,7 +41,7 @@ public: QString objectPath() const; void setObjectPath(const QString &busName); - ConnectionStatus status() const; + DBusEnums::ConnectionStatus status() const; void connect(); void disconnect(); @@ -62,19 +51,19 @@ protected: virtual void serviceVanish(GDBusConnection *connection) = 0; // notify functions - virtual void busTypeChanged(BusType type) = 0; + virtual void busTypeChanged(DBusEnums::BusType type) = 0; virtual void busNameChanged(const QString &busNameChanged) = 0; virtual void objectPathChanged(const QString &objectPath) = 0; - virtual void statusChanged(ConnectionStatus status) = 0; + virtual void statusChanged(DBusEnums::ConnectionStatus status) = 0; private: guint m_watchId; - BusType m_busType; + DBusEnums::BusType m_busType; QString m_busName; QString m_objectPath; - ConnectionStatus m_status; + DBusEnums::ConnectionStatus m_status; - void setStatus(ConnectionStatus status); + void setStatus(DBusEnums::ConnectionStatus status); // glib slots static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data); diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp index c77c3d5..116bd44 100644 --- a/tests/client/actiongrouptest.cpp +++ b/tests/client/actiongrouptest.cpp @@ -49,12 +49,12 @@ private Q_SLOTS: void init() { m_model.stop(); - m_model.setBusType(QDBusObject::SessionBus); + m_model.setBusType(DBusEnums::SessionBus); m_model.setBusName(MENU_SERVICE_NAME); m_model.setObjectPath(MENU_OBJECT_PATH); m_actionGroup.stop(); - m_actionGroup.setBusType(QDBusObject::SessionBus); + m_actionGroup.setBusType(DBusEnums::SessionBus); m_actionGroup.setBusName(MENU_SERVICE_NAME); m_actionGroup.setObjectPath(MENU_OBJECT_PATH); } @@ -70,16 +70,16 @@ private Q_SLOTS: void testBusTypeProperty() { m_actionGroup.setProperty("busType", 1); - QCOMPARE(m_actionGroup.busType(), QDBusObject::SessionBus); + QCOMPARE(m_actionGroup.busType(), DBusEnums::SessionBus); m_actionGroup.setProperty("busType", 2); - QCOMPARE(m_actionGroup.busType(), QDBusObject::SystemBus); + QCOMPARE(m_actionGroup.busType(), DBusEnums::SystemBus); m_actionGroup.setProperty("busType", 0); - QCOMPARE(m_actionGroup.busType(), QDBusObject::SystemBus); + QCOMPARE(m_actionGroup.busType(), DBusEnums::SystemBus); m_actionGroup.setProperty("busType", 10); - QCOMPARE(m_actionGroup.busType(), QDBusObject::SystemBus); + QCOMPARE(m_actionGroup.busType(), DBusEnums::SystemBus); } /* @@ -90,12 +90,12 @@ private Q_SLOTS: { m_model.start(); m_actionGroup.start(); - QCOMPARE(m_actionGroup.status(), QDBusObject::Connecting); + QCOMPARE(m_actionGroup.status(), DBusEnums::Connecting); // Make menu available m_script.publishMenu(); - QCOMPARE(m_actionGroup.status(), QDBusObject::Connected); + QCOMPARE(m_actionGroup.status(), DBusEnums::Connected); } /* @@ -109,17 +109,17 @@ private Q_SLOTS: // Make menu available m_script.publishMenu(); - QCOMPARE(m_actionGroup.status(), QDBusObject::Connected); + QCOMPARE(m_actionGroup.status(), DBusEnums::Connected); // Append menus m_script.walk(2); // Remove menu from dbus m_script.unpublishMenu(); - QCOMPARE(m_actionGroup.status(), QDBusObject::Connecting); + QCOMPARE(m_actionGroup.status(), DBusEnums::Connecting); m_actionGroup.stop(); - QCOMPARE(m_actionGroup.status(), QDBusObject::Disconnected); + QCOMPARE(m_actionGroup.status(), DBusEnums::Disconnected); } /* diff --git a/tests/client/menuchangestest.cpp b/tests/client/menuchangestest.cpp index 64c1729..2015582 100644 --- a/tests/client/menuchangestest.cpp +++ b/tests/client/menuchangestest.cpp @@ -46,7 +46,7 @@ private Q_SLOTS: void init() { m_model.stop(); - m_model.setBusType(QDBusObject::SessionBus); + m_model.setBusType(DBusEnums::SessionBus); m_model.setBusName(MENU_SERVICE_NAME); m_model.setObjectPath(MENU_OBJECT_PATH); } diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index 76a3e97..b1f2090 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -46,7 +46,7 @@ private Q_SLOTS: void init() { m_model.stop(); - m_model.setBusType(QDBusObject::SessionBus); + m_model.setBusType(DBusEnums::SessionBus); m_model.setBusName(MENU_SERVICE_NAME); m_model.setObjectPath(MENU_OBJECT_PATH); } @@ -70,16 +70,16 @@ private Q_SLOTS: void testBusTypeProperty() { m_model.setProperty("busType", 1); - QCOMPARE(m_model.busType(), QDBusObject::SessionBus); + QCOMPARE(m_model.busType(), DBusEnums::SessionBus); m_model.setProperty("busType", 2); - QCOMPARE(m_model.busType(), QDBusObject::SystemBus); + QCOMPARE(m_model.busType(), DBusEnums::SystemBus); m_model.setProperty("busType", 0); - QCOMPARE(m_model.busType(), QDBusObject::SystemBus); + QCOMPARE(m_model.busType(), DBusEnums::SystemBus); m_model.setProperty("busType", 10); - QCOMPARE(m_model.busType(), QDBusObject::SystemBus); + QCOMPARE(m_model.busType(), DBusEnums::SystemBus); } @@ -98,7 +98,7 @@ private Q_SLOTS: // Wait for dbus sync QTest::qWait(500); - QCOMPARE(m_model.status(), QDBusObject::Connected); + QCOMPARE(m_model.status(), DBusEnums::Connected); QCOMPARE(m_model.rowCount(), 4); // Label (String) @@ -146,7 +146,7 @@ private Q_SLOTS: // Wait for dbus sync QTest::qWait(500); - QCOMPARE(m_model.status(), QDBusObject::Connected); + QCOMPARE(m_model.status(), DBusEnums::Connected); QCOMPARE(m_model.rowCount(), 4); QVariant e = m_model.data(m_model.index(0, 0), QMenuModel::Extra); diff --git a/tests/client/servicetest.cpp b/tests/client/servicetest.cpp index cc47334..a8b0c2a 100644 --- a/tests/client/servicetest.cpp +++ b/tests/client/servicetest.cpp @@ -34,7 +34,7 @@ private: void setupModel(QDBusMenuModel *model) { - model->setBusType(QDBusObject::SessionBus); + model->setBusType(DBusEnums::SessionBus); model->setBusName(MENU_SERVICE_NAME); model->setObjectPath(MENU_OBJECT_PATH); } @@ -53,7 +53,7 @@ private Q_SLOTS: void init() { m_model.stop(); - m_model.setBusType(QDBusObject::SessionBus); + m_model.setBusType(DBusEnums::SessionBus); m_model.setBusName(MENU_SERVICE_NAME); m_model.setObjectPath(MENU_OBJECT_PATH); } @@ -66,10 +66,10 @@ private Q_SLOTS: void testMenuStartStopWithNoService() { m_model.start(); - QCOMPARE(m_model.status(), QDBusObject::Connecting); + QCOMPARE(m_model.status(), DBusEnums::Connecting); m_model.stop(); - QCOMPARE(m_model.status(), QDBusObject::Disconnected); + QCOMPARE(m_model.status(), DBusEnums::Disconnected); } void testMenuStartStopWithService() @@ -83,33 +83,33 @@ private Q_SLOTS: // Wait for dbus sync QTest::qWait(500); - QCOMPARE(m_model.status(), QDBusObject::Connected); + QCOMPARE(m_model.status(), DBusEnums::Connected); // Diconnect model m_model.stop(); - QCOMPARE(m_model.status(), QDBusObject::Disconnected); + QCOMPARE(m_model.status(), DBusEnums::Disconnected); } void testMenuServiceAppearAndDissapear() { m_model.start(); - QCOMPARE(m_model.status(), QDBusObject::Connecting); + QCOMPARE(m_model.status(), DBusEnums::Connecting); - QSignalSpy spy(&m_model, SIGNAL(statusChanged(QDBusObject::ConnectionStatus))); + QSignalSpy spy(&m_model, SIGNAL(statusChanged(DBusEnums::ConnectionStatus))); // Make menu available m_script.publishMenu(); // singal changed to connected QCOMPARE(spy.count(), 1); - QCOMPARE(m_model.status(), QDBusObject::Connected); + QCOMPARE(m_model.status(), DBusEnums::Connected); // remove menu service m_script.unpublishMenu(); // signal changed to connecting QCOMPARE(spy.count(), 2); - QCOMPARE(m_model.status(), QDBusObject::Connecting); + QCOMPARE(m_model.status(), DBusEnums::Connecting); } }; -- cgit v1.2.3 From c2d5761cd1b788abdc8035a2da355ef7791f0b85 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 12:08:54 +0200 Subject: Fix a typo. --- src/common/qdbusobject.cpp | 4 ++-- src/common/qdbusobject.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/qdbusobject.cpp b/src/common/qdbusobject.cpp index ff2a4a6..abc68b4 100644 --- a/src/common/qdbusobject.cpp +++ b/src/common/qdbusobject.cpp @@ -152,7 +152,7 @@ void QDBusObject::connect() m_busName.toLatin1(), G_BUS_NAME_WATCHER_FLAGS_NONE, QDBusObject::onServiceAppeared, - QDBusObject::onServiceFanished, + QDBusObject::onServiceVanished, this, NULL); @@ -179,7 +179,7 @@ void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, self->serviceAppear(connection); } -void QDBusObject::onServiceFanished(GDBusConnection *connection, const gchar *, gpointer data) +void QDBusObject::onServiceVanished(GDBusConnection *connection, const gchar *, gpointer data) { QDBusObject *self = reinterpret_cast(data); diff --git a/src/common/qdbusobject.h b/src/common/qdbusobject.h index cad6658..a3cef38 100644 --- a/src/common/qdbusobject.h +++ b/src/common/qdbusobject.h @@ -67,7 +67,7 @@ private: // glib slots static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data); - static void onServiceFanished(GDBusConnection *connection, const gchar *name, gpointer data); + static void onServiceVanished(GDBusConnection *connection, const gchar *name, gpointer data); }; #endif -- cgit v1.2.3 From 244ec0549fc57adb462276bbc5a3581487ae9e70 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 12:12:13 +0200 Subject: Removed leftover examples infrastructure. --- .bzrignore | 2 -- CMakeLists.txt | 1 - examples/CMakeLists.txt | 4 ---- examples/run-example.sh.in | 1 - 4 files changed, 8 deletions(-) delete mode 100644 examples/CMakeLists.txt delete mode 100755 examples/run-example.sh.in diff --git a/.bzrignore b/.bzrignore index 0fbb439..b2c3d4b 100644 --- a/.bzrignore +++ b/.bzrignore @@ -7,8 +7,6 @@ cmake_install.cmake moc_*.cxx -examples/run-example.sh - tests/client/*.moc tests/client/actiongrouptest tests/client/convertertest diff --git a/CMakeLists.txt b/CMakeLists.txt index fe36672..220c7d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,6 @@ if(BUILD_WITH_COVERAGE) endif() add_subdirectory(src) -add_subdirectory(examples) # Tests Tools if(NOT DBUS_RUNNER) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt deleted file mode 100644 index fda5683..0000000 --- a/examples/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -project(examples) - -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/run-example.sh.in" - "${CMAKE_CURRENT_BINARY_DIR}/run-example.sh" @ONLY) diff --git a/examples/run-example.sh.in b/examples/run-example.sh.in deleted file mode 100755 index 4843f49..0000000 --- a/examples/run-example.sh.in +++ /dev/null @@ -1 +0,0 @@ -gdb --args qmlviewer -I @src_BINARY_DIR@ $1 -- cgit v1.2.3 From 37dd62592264d4e3faf7f46d3f1ae74ed57e70ae Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 12:39:55 +0200 Subject: Remove a leftover dependency. --- .bzrignore | 2 ++ cmake/lcov.cmake | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bzrignore b/.bzrignore index b2c3d4b..fa8f70d 100644 --- a/.bzrignore +++ b/.bzrignore @@ -7,6 +7,8 @@ cmake_install.cmake moc_*.cxx +coverage/ + tests/client/*.moc tests/client/actiongrouptest tests/client/convertertest diff --git a/cmake/lcov.cmake b/cmake/lcov.cmake index 5758859..a422094 100644 --- a/cmake/lcov.cmake +++ b/cmake/lcov.cmake @@ -63,6 +63,4 @@ ADD_CUSTOM_COMMAND(TARGET lcov COMMAND echo "Open ${CMAKE_BINARY_DIR}/coverage/index.html to view the coverage analysis results." WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) -ADD_DEPENDENCIES(lcov helloworld) - -- cgit v1.2.3 From 445945df9d3ee9fff836d1c76b6a1d7316668775 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 13:40:02 +0200 Subject: Add examples. --- examples/README | 11 ++++ examples/exportactiongroup.py | 57 ++++++++++++++++++ examples/exportmenu.py | 63 +++++++++++++++++++ examples/render-menumodel.qml | 136 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 267 insertions(+) create mode 100644 examples/README create mode 100755 examples/exportactiongroup.py create mode 100755 examples/exportmenu.py create mode 100644 examples/render-menumodel.qml diff --git a/examples/README b/examples/README new file mode 100644 index 0000000..945da8b --- /dev/null +++ b/examples/README @@ -0,0 +1,11 @@ +This directory contains examples that demonstrate how to use the QMenuModel +QML binding in applications. + +To export an example menu model on the bus, run 'exportmenu.py'. + +To render this menu in a QML application, run 'render-menumodel.qml' in +qmlviewer. You will need to inform qmlviewer of the location of the QMenuModel +if it’s not installed system-wide, e.g.: + + qmlviewer -I src examples/render-menumodel.qml + diff --git a/examples/exportactiongroup.py b/examples/exportactiongroup.py new file mode 100755 index 0000000..f69416e --- /dev/null +++ b/examples/exportactiongroup.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +""" +This example script exports an action group on the session bus under the name +com.canonical.testactiongroup and at the object path +/com/canonical/testactiongroup. +""" + +import sys + +from gi.repository import Gio +from gi.repository import GLib + + +BUS_NAME = 'com.canonical.testactiongroup' +BUS_OBJECT_PATH = '/com/canonical/testactiongroup' + + +def action_activated(action, data): + name = action.get_name() + if action.get_state_type() is None: + print 'stateless action activated: %s' % name + else: + print 'stateful action activated: %s (current state: %s)' % + (name, action.get_state()) + + +if __name__ == '__main__': + bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) + # Claim well-known bus name and ensure only one instance of self is running + # at any given time. + # http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-names + proxy = Gio.DBusProxy.new_sync(bus, 0, None, + 'org.freedesktop.DBus', + '/org/freedesktop/DBus', + 'org.freedesktop.DBus', None) + result = proxy.RequestName('(su)', BUS_NAME, 0x4) + if result != 1 : + print >> sys.stderr, ("Name '%s' is already owned on the session bus." + "Aborting.") % BUS_NAME + sys.exit(1) + + group = Gio.SimpleActionGroup() + foo = Gio.SimpleAction.new('foo', None) + group.insert(foo) + bar = Gio.SimpleAction.new_stateful('bar', None, GLib.Variant.new_boolean(False)) + group.insert(bar) + bleh = Gio.SimpleAction.new_stateful('bleh', None, GLib.Variant.new_string('bleh')) + group.insert(bleh) + for name in group.list_actions(): + action = group.lookup_action(name) + action.connect('activate', action_activated) + bus.export_action_group(BUS_OBJECT_PATH, group) + + GLib.MainLoop().run() + diff --git a/examples/exportmenu.py b/examples/exportmenu.py new file mode 100755 index 0000000..831f995 --- /dev/null +++ b/examples/exportmenu.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +""" +This example script exports a menu model on the session bus under the name +com.canonical.testmenu and at the object path /com/canonical/testmenu. +The menu model contains items that have attributes with custom values, as well +as sub-menus. +""" + +import sys + +from gi.repository import Gio +from gi.repository import GLib + + +BUS_NAME = 'com.canonical.testmenu' +BUS_OBJECT_PATH = '/com/canonical/testmenu' + + +if __name__ == '__main__': + bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) + # Claim well-known bus name and ensure only one instance of self is running + # at any given time. + # http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-names + proxy = Gio.DBusProxy.new_sync(bus, 0, None, + 'org.freedesktop.DBus', + '/org/freedesktop/DBus', + 'org.freedesktop.DBus', None) + result = proxy.RequestName('(su)', BUS_NAME, 0x4) + if result != 1 : + print >> sys.stderr, ("Name '%s' is already owned on the session bus." + "Aborting.") % BUS_NAME + sys.exit(1) + + menu = Gio.Menu() + foo = Gio.MenuItem.new('foo', 'app.foo') + foo.set_attribute_value('x-additionaltext', + GLib.Variant.new_string('lorem ipsum')) + foo.set_attribute_value('x-enabled', GLib.Variant.new_boolean(True)) + menu.append_item(foo) + bar = Gio.MenuItem.new('bar', 'app.bar') + bar.set_attribute_value('x-defaultvalue', + GLib.Variant.new_string('Hello World!')) + bar.set_attribute_value('x-canonical-currentvalue', + GLib.Variant.new_string('awesome')) + bar.set_attribute_value('x-velocity', GLib.Variant.new_uint64(83374)) + menu.append_item(bar) + menu.append('bleh', 'app.bleh') + submenu = Gio.Menu() + submenu.append('submenu A', 'app.suba') + submenu2 = Gio.Menu() + submenu2.append('submenu2 A', 'app.sub2a') + submenu2.append('submenu2 B', 'app.sub2b') + submenu2.append('submenu2 C', 'app.sub2c') + submenu.append_submenu('submenu submenu', submenu2) + submenu.append('submenu C', 'app.subc') + menu.append_submenu('submenu', submenu) + menu.append('baz', 'app.baz') + bus.export_menu_model(BUS_OBJECT_PATH, menu) + + GLib.MainLoop().run() + diff --git a/examples/render-menumodel.qml b/examples/render-menumodel.qml new file mode 100644 index 0000000..0128b37 --- /dev/null +++ b/examples/render-menumodel.qml @@ -0,0 +1,136 @@ +// This example QML application renders a menu model exposed on the session bus +// under the well-known name com.canonical.testmenu and at the object path +// /com/canonical/testmenu. + +import QtQuick 1.1 +import QMenuModel 0.1 // uninstalled, run qmlviewer with "-I ../src" + +Item { + id: container + width: 300 + height: 300 + + QDBusMenuModel { + id: menuModel + busType: DBus.SessionBus + busName: "com.canonical.testmenu" + objectPath: "/com/canonical/testmenu" + onStatusChanged: console.log("status of menu model changed to", status) + } + + ListView { + id: view + property variant __back: [] + anchors.left: parent.left + anchors.right:parent.right + anchors.top: parent.top + anchors.bottom: backbutton.top + anchors.margins: 10 + spacing: 3 + model: menuModel + Component.onCompleted: menuModel.start() + delegate: Rectangle { + width: parent.width + height: 30 + radius: 3 + color: { + if (linkSubMenu == null) return "lightgrey" + if (delegatearea.containsMouse) return "steelblue" + return "lightsteelblue" + } + Text { + anchors.fill: parent + anchors.margins: 5 + verticalAlignment: Text.AlignVCenter + color: (linkSubMenu == null) ? "grey" : "black" + text: { + if (linkSubMenu == null) return "%1 (%2)".arg(label).arg(action) + else return "submenu" + } + } + MouseArea { + id: delegatearea + anchors.fill: parent + //enabled: linkSubMenu != null + hoverEnabled: true + onClicked: { + var newback = view.__back + newback.push(view.model) + view.__back = newback + view.model = linkSubMenu + } + onEntered: { + var text = "" + for (var prop in extra) { + text += "%1 = %2\n".arg(prop).arg(extra[prop].toString()) + } + if (text != "") { + tooltip.text = text + tooltip.visible = true + } + } + onExited: { + tooltip.visible = false + } + onPositionChanged: { + var pos = container.mapFromItem(delegatearea, mouse.x, mouse.y) + tooltip.x = pos.x + 10 + tooltip.y = pos.y + 10 + } + } + } + function goback() { + var newback = view.__back + model = newback[newback.length - 1] + newback.pop() + view.__back = newback + } + } + + Rectangle { + id: backbutton + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.margins: 5 + radius: 4 + height: 50 + color: (mousearea.enabled && mousearea.containsMouse) ? "steelblue" : "lightsteelblue" + Text { + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: "back" + color: mousearea.enabled ? "black" : "grey" + } + MouseArea { + id: mousearea + anchors.fill: parent + enabled: view.__back.length > 0 + hoverEnabled: true + onClicked: { + view.goback() + } + } + } + + Rectangle { + id: tooltip + property alias text: t.text + visible: false + width: t.width + 10 + height: t.height + 10 + radius: 4 + color: "lightyellow" + Text { + id: t + height: paintedHeight + width: paintedWidth + x: 5 + y: 5 + anchors.margins: 4 + font.pixelSize: 12 + } + } +} + -- cgit v1.2.3 From ba89bb27ac5ff18d237dc88608bfbeb3071ac25c Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 13:56:02 +0200 Subject: Remove useless code from the Converter namespace. --- src/common/converter.cpp | 5 +++-- src/common/converter.h | 9 ++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/common/converter.cpp b/src/common/converter.cpp index 54d4665..365f891 100644 --- a/src/common/converter.cpp +++ b/src/common/converter.cpp @@ -60,7 +60,7 @@ QVariant Converter::toQVariant(GVariant *value) return result; } -GVariant* Converter::toGVariant(const QString &typeName, const QVariant &value) +static GVariant* toGVariant(const QString &typeName, const QVariant &value) { if (typeName == "uchar") { return g_variant_new_byte(value.value()); @@ -105,8 +105,9 @@ GVariant* Converter::toGVariant(const QVariant &value) result = g_variant_new_uint32(value.toUInt()); break; default: - result = toGVariant(value.typeName(), value); + result = ::toGVariant(value.typeName(), value); } return result; } + diff --git a/src/common/converter.h b/src/common/converter.h index 3029b0d..f4d7e08 100644 --- a/src/common/converter.h +++ b/src/common/converter.h @@ -28,12 +28,7 @@ class Converter public: static QVariant toQVariant(GVariant *value); static GVariant* toGVariant(const QVariant &value); - -private: - Converter(); - Converter(const Converter &other); - - static GVariant* toGVariant(const QString &typeName, const QVariant &value); }; -#endif +#endif // CONVERTER_H + -- cgit v1.2.3 From e14ab1e03bf40e5f63329f8ed26b3f11cc15fb0a Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 14:52:34 +0200 Subject: Replace #include statements with forward declarations in converter.h. --- src/common/converter.cpp | 5 +++++ src/common/converter.h | 4 ++-- tests/client/convertertest.cpp | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/converter.cpp b/src/common/converter.cpp index 365f891..a060618 100644 --- a/src/common/converter.cpp +++ b/src/common/converter.cpp @@ -1,6 +1,11 @@ +extern "C" { +#include +} + #include "converter.h" #include +#include /*! \internal */ QVariant Converter::toQVariant(GVariant *value) diff --git a/src/common/converter.h b/src/common/converter.h index f4d7e08..5f05bc7 100644 --- a/src/common/converter.h +++ b/src/common/converter.h @@ -20,8 +20,8 @@ #ifndef CONVERTER_H #define CONVERTER_H -#include -#include +typedef struct _GVariant GVariant; +class QVariant; class Converter { diff --git a/tests/client/convertertest.cpp b/tests/client/convertertest.cpp index 496b62a..72b6a87 100644 --- a/tests/client/convertertest.cpp +++ b/tests/client/convertertest.cpp @@ -17,6 +17,10 @@ * Renato Araujo Oliveira Filho */ +extern "C" { +#include +} + #include "converter.h" #include -- cgit v1.2.3 From af778cf94bbd8a36cc77e0c6ab2452e5a8044e0a Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 15:35:16 +0200 Subject: Minor doc fixes. --- .bzrignore | 3 +++ doc/CMakeLists.txt | 2 +- doc/qmenumodel.qdocconf.in | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.bzrignore b/.bzrignore index fa8f70d..6ac94f3 100644 --- a/.bzrignore +++ b/.bzrignore @@ -16,6 +16,9 @@ tests/client/menuchangestest tests/client/modeltest tests/client/servicetest +doc/html/ +doc/qmenumodel.qdocconf + obj-* debian/files debian/qmenumodel-qml diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index e5772ba..ea5b1cb 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -7,4 +7,4 @@ add_custom_target(qdoc) add_custom_command(TARGET qdoc COMMAND ${QDOC_BIN} ${QMENUMODEL_DOC_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "QDoc working...") + COMMENT "QDoc running...") diff --git a/doc/qmenumodel.qdocconf.in b/doc/qmenumodel.qdocconf.in index 3070b1e..5ab30f4 100644 --- a/doc/qmenumodel.qdocconf.in +++ b/doc/qmenumodel.qdocconf.in @@ -1,4 +1,4 @@ -project = QMenuModel QLM elements +project = QMenuModel QML elements sourcedirs = @qmenumodelcommon_SOURCE_DIR@ sources.fileextensions = "*.cpp" outputdir = html -- cgit v1.2.3 From 7a410b589e8c7b15bcc15ec6b2275ffe7e6a7db0 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 15:35:35 +0200 Subject: Add instructions. --- README | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..e8e6b75 --- /dev/null +++ b/README @@ -0,0 +1,54 @@ +QMenuModel - a Qt/QML binding for GMenuModel +(see http://developer.gnome.org/gio/unstable/GMenuModel.html) + + += Building = + +The build system uses cmake. +To compile, simply invoke cmake and then make, e.g.: + + $ cmake . + $ make + + += Running unit tests = + +To run the unit tests, you will need dbus-test-runner. If it wasn’t previously +installed, install it and then re-run cmake. Then run either of these commands: + + $ make test + + - or - + + $ ctest + + += Getting code coverage information = + +To run the unit tests and generate code coverage information, you need to re-run +cmake with BUILD_WITH_COVERAGE set to ON and then invoke `make lcov`. +This requires lcov to be installed. + + $ cmake -DBUILD_WITH_COVERAGE=ON . + $ make lcov + +This will generate a report (coverage/index.html) which you can view in a +browser. + + += API documentation = + +To generate API documentation, you need to re-run cmake with GENERATE_DOC set to +ON and then invoke `make qdoc`. This requires qdoc3 to be installed. + + $ cmake -DGENERATE_DOC=ON . + $ make qdoc + +The documentation is generated in the HTML format under doc/html/. + + += Examples = + +There are examples of how to use QDBusMenuModel in QML, refer to the README file +under the examples/ directory for instructions. + -- cgit v1.2.3 From 1e045bbea3e1f8037ea92e449bbce94ed7408c7c Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 15:53:06 +0200 Subject: Fixed some #include statements. --- src/common/qdbusactiongroup.cpp | 4 ++-- src/common/qdbusactiongroup.h | 3 +-- src/common/qdbusmenumodel.cpp | 1 - src/common/qdbusmenumodel.h | 2 ++ src/common/qdbusobject.h | 6 ++++-- src/common/qmenumodel.h | 3 +++ 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/common/qdbusactiongroup.cpp b/src/common/qdbusactiongroup.cpp index d25f2de..5a9e0bd 100644 --- a/src/common/qdbusactiongroup.cpp +++ b/src/common/qdbusactiongroup.cpp @@ -21,9 +21,9 @@ #include "qstateaction.h" #include "converter.h" -#include - +extern "C" { #include +} /*! \qmlclass QDBusActionGroup diff --git a/src/common/qdbusactiongroup.h b/src/common/qdbusactiongroup.h index 2bd0a15..518f78c 100644 --- a/src/common/qdbusactiongroup.h +++ b/src/common/qdbusactiongroup.h @@ -23,8 +23,7 @@ #include "qdbusobject.h" #include -#include -#include +#include class QStateAction; diff --git a/src/common/qdbusmenumodel.cpp b/src/common/qdbusmenumodel.cpp index 354b10b..88a6084 100644 --- a/src/common/qdbusmenumodel.cpp +++ b/src/common/qdbusmenumodel.cpp @@ -18,7 +18,6 @@ */ #include "qdbusmenumodel.h" -#include /*! \qmlclass QDBusMenuModel diff --git a/src/common/qdbusmenumodel.h b/src/common/qdbusmenumodel.h index 2660ffe..fdf23f7 100644 --- a/src/common/qdbusmenumodel.h +++ b/src/common/qdbusmenumodel.h @@ -23,7 +23,9 @@ #include "qdbusobject.h" #include "qmenumodel.h" +extern "C" { #include +} class QDBusMenuModel : public QMenuModel, public QDBusObject { diff --git a/src/common/qdbusobject.h b/src/common/qdbusobject.h index a3cef38..ef2b42f 100644 --- a/src/common/qdbusobject.h +++ b/src/common/qdbusobject.h @@ -20,9 +20,11 @@ #ifndef QDBUSOBJECT_H #define QDBUSOBJECT_H -#include - +extern "C" { #include +} + +#include #include "dbus-enums.h" diff --git a/src/common/qmenumodel.h b/src/common/qmenumodel.h index 598efd6..7520480 100644 --- a/src/common/qmenumodel.h +++ b/src/common/qmenumodel.h @@ -21,7 +21,10 @@ #define QMENUMODEL_H #include + +extern "C" { #include +} class QMenuModel : public QAbstractListModel { -- cgit v1.2.3 From 62d2c4b30435bff7dc25441dd1ce55d519d80b05 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 16:48:48 +0200 Subject: Add a TODO file. --- TODO | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..bb361e1 --- /dev/null +++ b/TODO @@ -0,0 +1,7 @@ += TODO = + + • Expose a plain Qt library as well as the QML plugin, so that QDBusMenuModel + can be used from C++ too + • Add a server-side API to allow applications to export their menus on the bus + • … + -- cgit v1.2.3 From 36cebbb3e17b0b9df03a3a288e56b5d1e1fedee1 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:12:09 +0200 Subject: Rename the source directories. --- CMakeLists.txt | 2 +- libqmenumodel/CMakeLists.txt | 4 + libqmenumodel/QMenuModel/CMakeLists.txt | 45 +++++++ libqmenumodel/QMenuModel/plugin.cpp | 43 ++++++ libqmenumodel/QMenuModel/plugin.h | 33 +++++ libqmenumodel/QMenuModel/qmldir | 1 + libqmenumodel/src/CMakeLists.txt | 46 +++++++ libqmenumodel/src/converter.cpp | 118 ++++++++++++++++ libqmenumodel/src/converter.h | 34 +++++ libqmenumodel/src/dbus-enums.h | 53 ++++++++ libqmenumodel/src/qdbusactiongroup.cpp | 232 ++++++++++++++++++++++++++++++++ libqmenumodel/src/qdbusactiongroup.h | 85 ++++++++++++ libqmenumodel/src/qdbusmenumodel.cpp | 109 +++++++++++++++ libqmenumodel/src/qdbusmenumodel.h | 61 +++++++++ libqmenumodel/src/qdbusobject.cpp | 188 ++++++++++++++++++++++++++ libqmenumodel/src/qdbusobject.h | 75 +++++++++++ libqmenumodel/src/qmenumodel.cpp | 225 +++++++++++++++++++++++++++++++ libqmenumodel/src/qmenumodel.h | 66 +++++++++ libqmenumodel/src/qstateaction.cpp | 145 ++++++++++++++++++++ libqmenumodel/src/qstateaction.h | 61 +++++++++ src/CMakeLists.txt | 4 - src/QMenuModel/CMakeLists.txt | 46 ------- src/QMenuModel/plugin.cpp | 43 ------ src/QMenuModel/plugin.h | 33 ----- src/QMenuModel/qmldir | 1 - src/common/CMakeLists.txt | 47 ------- src/common/converter.cpp | 118 ---------------- src/common/converter.h | 34 ----- src/common/dbus-enums.h | 53 -------- src/common/qdbusactiongroup.cpp | 232 -------------------------------- src/common/qdbusactiongroup.h | 85 ------------ src/common/qdbusmenumodel.cpp | 109 --------------- src/common/qdbusmenumodel.h | 61 --------- src/common/qdbusobject.cpp | 188 -------------------------- src/common/qdbusobject.h | 75 ----------- src/common/qmenumodel.cpp | 225 ------------------------------- src/common/qmenumodel.h | 66 --------- src/common/qstateaction.cpp | 145 -------------------- src/common/qstateaction.h | 61 --------- tests/client/CMakeLists.txt | 6 +- 40 files changed, 1628 insertions(+), 1630 deletions(-) create mode 100644 libqmenumodel/CMakeLists.txt create mode 100644 libqmenumodel/QMenuModel/CMakeLists.txt create mode 100644 libqmenumodel/QMenuModel/plugin.cpp create mode 100644 libqmenumodel/QMenuModel/plugin.h create mode 100644 libqmenumodel/QMenuModel/qmldir create mode 100644 libqmenumodel/src/CMakeLists.txt create mode 100644 libqmenumodel/src/converter.cpp create mode 100644 libqmenumodel/src/converter.h create mode 100644 libqmenumodel/src/dbus-enums.h create mode 100644 libqmenumodel/src/qdbusactiongroup.cpp create mode 100644 libqmenumodel/src/qdbusactiongroup.h create mode 100644 libqmenumodel/src/qdbusmenumodel.cpp create mode 100644 libqmenumodel/src/qdbusmenumodel.h create mode 100644 libqmenumodel/src/qdbusobject.cpp create mode 100644 libqmenumodel/src/qdbusobject.h create mode 100644 libqmenumodel/src/qmenumodel.cpp create mode 100644 libqmenumodel/src/qmenumodel.h create mode 100644 libqmenumodel/src/qstateaction.cpp create mode 100644 libqmenumodel/src/qstateaction.h delete mode 100644 src/CMakeLists.txt delete mode 100644 src/QMenuModel/CMakeLists.txt delete mode 100644 src/QMenuModel/plugin.cpp delete mode 100644 src/QMenuModel/plugin.h delete mode 100644 src/QMenuModel/qmldir delete mode 100644 src/common/CMakeLists.txt delete mode 100644 src/common/converter.cpp delete mode 100644 src/common/converter.h delete mode 100644 src/common/dbus-enums.h delete mode 100644 src/common/qdbusactiongroup.cpp delete mode 100644 src/common/qdbusactiongroup.h delete mode 100644 src/common/qdbusmenumodel.cpp delete mode 100644 src/common/qdbusmenumodel.h delete mode 100644 src/common/qdbusobject.cpp delete mode 100644 src/common/qdbusobject.h delete mode 100644 src/common/qmenumodel.cpp delete mode 100644 src/common/qmenumodel.h delete mode 100644 src/common/qstateaction.cpp delete mode 100644 src/common/qstateaction.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 220c7d3..4cba967 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ if(BUILD_WITH_COVERAGE) include(${CMAKE_SOURCE_DIR}/cmake/lcov.cmake) endif() -add_subdirectory(src) +add_subdirectory(libqmenumodel) # Tests Tools if(NOT DBUS_RUNNER) diff --git a/libqmenumodel/CMakeLists.txt b/libqmenumodel/CMakeLists.txt new file mode 100644 index 0000000..d01cf10 --- /dev/null +++ b/libqmenumodel/CMakeLists.txt @@ -0,0 +1,4 @@ +project(libqmenumodel) + +add_subdirectory(src) +add_subdirectory(QMenuModel) diff --git a/libqmenumodel/QMenuModel/CMakeLists.txt b/libqmenumodel/QMenuModel/CMakeLists.txt new file mode 100644 index 0000000..891c89c --- /dev/null +++ b/libqmenumodel/QMenuModel/CMakeLists.txt @@ -0,0 +1,45 @@ +project(qmlplugin) + +set(QMLPLUGIN_SRC + plugin.cpp +) + +set(QMLPLUGIN_HEADERS + plugin.h +) + +qt4_wrap_cpp(QMLPLUGIN_MOC + ${QMLPLUGIN_HEADERS} +) + +add_library(qmenumodel-qml MODULE + ${QMLPLUGIN_SRC} + ${QMLPLUGIN_MOC} +) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${src_SOURCE_DIR} + ${QT_INCLUDE_DIR} + ${QT_QTCORE_INCLUDE_DIR} + ${QT_QTGUI_INCLUDE_DIR} + ${QT_QTDECLARATIVE_INCLUDE_DIR} + ${GLIB_INCLUDE_DIRS} + ${GIO_INCLUDE_DIRS} +) + +target_link_libraries(qmenumodel-qml + qmenumodel + ${QT_QTCORE_LIBRARY} + ${QT_QTDCLARATIVE_LIBRARY} + ${GLIB_LDFLAGS} + ${GIO_LDFLAGS} +) + +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" + "${CMAKE_CURRENT_BINARY_DIR}/qmldir") + +set(QMLPLUGIN_INSTALL_PREFIX "${QT_IMPORTS_DIR}/Ubuntu/QMenuModel/") +install(TARGETS qmenumodel-qml DESTINATION ${QMLPLUGIN_INSTALL_PREFIX}) +install(FILES qmldir DESTINATION ${QMLPLUGIN_INSTALL_PREFIX}) + diff --git a/libqmenumodel/QMenuModel/plugin.cpp b/libqmenumodel/QMenuModel/plugin.cpp new file mode 100644 index 0000000..ec51ae9 --- /dev/null +++ b/libqmenumodel/QMenuModel/plugin.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#include "plugin.h" +#include "qmenumodel.h" +#include "qdbusmenumodel.h" +#include "qdbusactiongroup.h" +#include "qstateaction.h" + +#include + + +void QMenuModelQmlPlugin::registerTypes(const char *uri) +{ + qmlRegisterUncreatableType(uri, 0, 1, "QMenuModel", + "QMenuModel is a interface"); + qmlRegisterUncreatableType(uri, 0, 1, "QStateAction", + "QStateAction must be created by QDBusActionGroup::action"); + qmlRegisterUncreatableType(uri, 0, 1, "DBus", + "DBus is only a namespace"); + + qmlRegisterType(uri, 0, 1, "QDBusMenuModel"); + qmlRegisterType(uri, 0, 1, "QDBusActionGroup"); + +} + +Q_EXPORT_PLUGIN2(qmenumodel, QMenuModelQmlPlugin) diff --git a/libqmenumodel/QMenuModel/plugin.h b/libqmenumodel/QMenuModel/plugin.h new file mode 100644 index 0000000..e9d6850 --- /dev/null +++ b/libqmenumodel/QMenuModel/plugin.h @@ -0,0 +1,33 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#ifndef QMENUMODELQMLPLUGIN_H +#define QMENUMODELQMLPLUGIN_H + +#include + + +class QMenuModelQmlPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT +public: + void registerTypes(const char *uri); +}; + +#endif diff --git a/libqmenumodel/QMenuModel/qmldir b/libqmenumodel/QMenuModel/qmldir new file mode 100644 index 0000000..32de804 --- /dev/null +++ b/libqmenumodel/QMenuModel/qmldir @@ -0,0 +1 @@ +plugin qmenumodel-qml diff --git a/libqmenumodel/src/CMakeLists.txt b/libqmenumodel/src/CMakeLists.txt new file mode 100644 index 0000000..17d11f1 --- /dev/null +++ b/libqmenumodel/src/CMakeLists.txt @@ -0,0 +1,46 @@ +project(src) + +set(QMENUMODEL_SRC + converter.cpp + qmenumodel.cpp + qdbusobject.cpp + qdbusmenumodel.cpp + qdbusactiongroup.cpp + qstateaction.cpp +) + +set(QMENUMODEL_HEADERS + converter.h + dbus-enums.h + qmenumodel.h + qdbusobject.h + qdbusmenumodel.h + qdbusactiongroup.h + qstateaction.h +) + +qt4_wrap_cpp(QMENUMODEL_MOC + ${QMENUMODEL_HEADERS} +) + +add_library(qmenumodel STATIC + ${QMENUMODEL_SRC} + ${QMENUMODEL_MOC} +) + +set_target_properties(qmenumodel PROPERTIES COMPILE_FLAGS -fPIC) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${QT_INCLUDE_DIR} + ${QT_QTCORE_INCLUDE_DIR} + ${QT_QTGUI_INCLUDE_DIR} + ${GLIB_INCLUDE_DIRS} + ${GIO_INCLUDE_DIRS} +) + +target_link_libraries(qmenumodel + ${QT_QTCORE_LIBRARY} + ${GLIB_LDFLAGS} + ${GIO_LDFLAGS} +) diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp new file mode 100644 index 0000000..a060618 --- /dev/null +++ b/libqmenumodel/src/converter.cpp @@ -0,0 +1,118 @@ +extern "C" { +#include +} + +#include "converter.h" + +#include +#include + +/*! \internal */ +QVariant Converter::toQVariant(GVariant *value) +{ + QVariant result; + if (value == NULL) { + return result; + } + + const GVariantType *type = g_variant_get_type(value); + if (g_variant_type_equal(type, G_VARIANT_TYPE_BOOLEAN)) { + result.setValue((bool)g_variant_get_boolean(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTE)) { + result.setValue(g_variant_get_byte(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT16)) { + result.setValue(g_variant_get_int16(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT16)) { + result.setValue(g_variant_get_uint16(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT32)) { + result.setValue(g_variant_get_int32(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT32)) { + result.setValue(g_variant_get_uint32(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT64)) { + result.setValue(g_variant_get_int64(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64)) { + result.setValue(g_variant_get_uint64(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_DOUBLE)) { + result.setValue(g_variant_get_double(value)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_STRING)) { + gsize size = 0; + const gchar *v = g_variant_get_string(value, &size); + result.setValue(QString::fromLatin1(v, size)); + } else { + qWarning() << "Unsupported GVariant value"; + } + + /* TODO: implement convertions to others types + * G_VARIANT_TYPE_HANDLE + * G_VARIANT_TYPE_OBJECT_PATH + * G_VARIANT_TYPE_SIGNATURE + * G_VARIANT_TYPE_VARIANT + * G_VARIANT_TYPE_ANY + * G_VARIANT_TYPE_BASIC + * G_VARIANT_TYPE_MAYBE + * G_VARIANT_TYPE_ARRAY + * G_VARIANT_TYPE_TUPLE + * G_VARIANT_TYPE_UNIT + * G_VARIANT_TYPE_DICT_ENTRY + * G_VARIANT_TYPE_DICTIONARY + * G_VARIANT_TYPE_STRING_ARRAY + * G_VARIANT_TYPE_BYTESTRING + * G_VARIANT_TYPE_OBJECT_PATH_ARRAY + * G_VARIANT_TYPE_BYTESTRING_ARRAY + * G_VARIANT_TYPE_VARDICT + */ + + return result; +} + +static GVariant* toGVariant(const QString &typeName, const QVariant &value) +{ + if (typeName == "uchar") { + return g_variant_new_byte(value.value()); + } else if (typeName == "short") { + return g_variant_new_int16(value.value()); + } else if (typeName == "ushort") { + return g_variant_new_uint16(value.value()); + } else if (typeName == "long") { + return g_variant_new_int64(value.value()); + } else if (typeName == "ulong") { + return g_variant_new_uint64(value.value()); + } else { + qWarning() << "QVariant type not supported:" << typeName; + } + + return NULL; +} + +GVariant* Converter::toGVariant(const QVariant &value) +{ + GVariant *result = NULL; + if (value.isNull() || !value.isValid()) + return result; + + switch(value.type()) { + case QVariant::Bool: + result = g_variant_new_boolean(value.toBool()); + break; + case QVariant::ByteArray: + result = g_variant_new_bytestring(value.toByteArray()); + break; + case QVariant::Double: + result = g_variant_new_double(value.toDouble()); + break; + case QVariant::Int: + result = g_variant_new_int32(value.toInt()); + break; + case QVariant::String: + result = g_variant_new_string(value.toString().toLatin1()); + break; + case QVariant::UInt: + result = g_variant_new_uint32(value.toUInt()); + break; + default: + result = ::toGVariant(value.typeName(), value); + } + + return result; +} + diff --git a/libqmenumodel/src/converter.h b/libqmenumodel/src/converter.h new file mode 100644 index 0000000..5f05bc7 --- /dev/null +++ b/libqmenumodel/src/converter.h @@ -0,0 +1,34 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#ifndef CONVERTER_H +#define CONVERTER_H + +typedef struct _GVariant GVariant; +class QVariant; + +class Converter +{ +public: + static QVariant toQVariant(GVariant *value); + static GVariant* toGVariant(const QVariant &value); +}; + +#endif // CONVERTER_H + diff --git a/libqmenumodel/src/dbus-enums.h b/libqmenumodel/src/dbus-enums.h new file mode 100644 index 0000000..76149da --- /dev/null +++ b/libqmenumodel/src/dbus-enums.h @@ -0,0 +1,53 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Olivier Tilloy + */ + +#ifndef __DBUS_ENUMS__ +#define __DBUS_ENUMS__ + +#include + +// This class acts as a namespace only, with the addition that its enums +// are registered to be exposed on the QML side. +class DBusEnums : public QObject +{ + Q_OBJECT + + Q_ENUMS(BusType) + Q_ENUMS(ConnectionStatus) + +public: + enum BusType { + None = 0, + SessionBus, + SystemBus, + LastBusType + }; + + enum ConnectionStatus { + Disconnected = 0, + Connecting, + Connected + }; + +private: + DBusEnums() {} +}; + +#endif // __DBUS_ENUMS__ + diff --git a/libqmenumodel/src/qdbusactiongroup.cpp b/libqmenumodel/src/qdbusactiongroup.cpp new file mode 100644 index 0000000..5a9e0bd --- /dev/null +++ b/libqmenumodel/src/qdbusactiongroup.cpp @@ -0,0 +1,232 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#include "qdbusactiongroup.h" +#include "qstateaction.h" +#include "converter.h" + +extern "C" { +#include +} + +/*! + \qmlclass QDBusActionGroup + \inherits QDBusObject + + \brief A DBusActionGroup implementation to be used with \l QDBusMenuModel + + \bold {This component is under heavy development.} + + This class can be used as a proxy for an action group that is exported over D-Bus + + \code + QDBusActionGroup { + id: actionGroup + busType: 1 + busName: "com.ubuntu.menu" + objectPath: "com/ubuntu/menu/actions" + } + + Button { + onClicked: actionGroup.getAction("app.quit").trigger() + } + \endcode +*/ + +/*! \internal */ +QDBusActionGroup::QDBusActionGroup(QObject *parent) + :QObject(parent), + m_actionGroup(NULL) +{ +} + +/*! \internal */ +QDBusActionGroup::~QDBusActionGroup() +{ + clear(); +} + +/*! + \qmlmethod QDBusActionGroup::action(QString name) + + Look for a action with the same name and return a \l QStateAction object. + + \bold Note: methods should only be called after the Component has completed. +*/ +QStateAction *QDBusActionGroup::action(const QString &name) +{ + QStateAction *act = actionImpl(name); + if (act == 0) { + act = new QStateAction(this, name); + } + + return act; +} + +QVariant QDBusActionGroup::actionState(const QString &name) +{ + QVariant result; + GVariant *state = g_action_group_get_action_state(m_actionGroup, name.toLatin1()); + result = Converter::toQVariant(state); + if (state) { + g_variant_unref(state); + } + return result; +} + + +bool QDBusActionGroup::hasAction(const QString &name) +{ + if (m_actionGroup) { + return g_action_group_has_action(m_actionGroup, name.toLatin1()); + } else { + return false; + } +} + +QStateAction *QDBusActionGroup::actionImpl(const QString &name) +{ + Q_FOREACH(QStateAction *act, this->findChildren()) { + if (act->text() == name) { + return act; + } + } + return 0; +} + +/*! \internal */ +void QDBusActionGroup::serviceVanish(GDBusConnection *) +{ + setActionGroup(NULL); +} + +/*! \internal */ +void QDBusActionGroup::serviceAppear(GDBusConnection *connection) +{ + GDBusActionGroup *ag = g_dbus_action_group_get(connection, + busName().toLatin1(), + objectPath().toLatin1()); + setActionGroup(ag); + if (ag == NULL) { + stop(); + } +} + +/*! \internal */ +void QDBusActionGroup::start() +{ + QDBusObject::connect(); +} + +/*! \internal */ +void QDBusActionGroup::stop() +{ + QDBusObject::disconnect(); +} + +/*! \internal */ +void QDBusActionGroup::setIntBusType(int busType) +{ + if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) { + setBusType(static_cast(busType)); + } +} + +/*! \internal */ +void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag) +{ + if (m_actionGroup == reinterpret_cast(ag)) { + return; + } + + if (m_actionGroup) { + g_signal_handler_disconnect(m_actionGroup, m_signalActionAddId); + g_signal_handler_disconnect(m_actionGroup, m_signalActionRemovedId); + g_signal_handler_disconnect(m_actionGroup, m_signalStateChangedId); + m_signalActionAddId = m_signalActionRemovedId = m_signalStateChangedId = 0; + clear(); + } + + m_actionGroup = reinterpret_cast(ag); + + if (m_actionGroup) { + m_signalActionAddId = g_signal_connect(m_actionGroup, + "action-added", + G_CALLBACK(QDBusActionGroup::onActionAdded), + this); + + m_signalActionRemovedId = g_signal_connect(m_actionGroup, + "action-removed", + G_CALLBACK(QDBusActionGroup::onActionRemoved), + this); + + m_signalStateChangedId = g_signal_connect(m_actionGroup, + "action-state-changed", + G_CALLBACK(QDBusActionGroup::onActionStateChanged), + this); + + gchar **actions = g_action_group_list_actions(m_actionGroup); + for(guint i=0; i < g_strv_length(actions); i++) { + Q_EMIT actionAppear(actions[i]); + } + g_strfreev(actions); + } +} + +/*! \internal */ +void QDBusActionGroup::clear() +{ + Q_FOREACH(QStateAction *act, this->findChildren()) { + Q_EMIT actionVanish(act->text()); + } + + if (m_actionGroup != NULL) { + g_object_unref(m_actionGroup); + m_actionGroup = NULL; + } +} + +/*! \internal */ +void QDBusActionGroup::updateActionState(const QString &name, const QVariant &state) +{ + if (m_actionGroup != NULL) { + g_action_group_activate_action(m_actionGroup, name.toLatin1(), Converter::toGVariant(state)); + } +} + +/*! \internal */ +void QDBusActionGroup::onActionAdded(GDBusActionGroup *, gchar *name, gpointer data) +{ + QDBusActionGroup *self = reinterpret_cast(data); + Q_EMIT self->actionAppear(name); +} + +/*! \internal */ +void QDBusActionGroup::onActionRemoved(GDBusActionGroup *, gchar *name, gpointer data) +{ + QDBusActionGroup *self = reinterpret_cast(data); + Q_EMIT self->actionVanish(name); +} + +/*! \internal */ +void QDBusActionGroup::onActionStateChanged(GDBusActionGroup *, gchar *name, GVariant *value, gpointer data) +{ + QDBusActionGroup *self = reinterpret_cast(data); + Q_EMIT self->actionStateChanged(name, Converter::toQVariant(value)); +} diff --git a/libqmenumodel/src/qdbusactiongroup.h b/libqmenumodel/src/qdbusactiongroup.h new file mode 100644 index 0000000..518f78c --- /dev/null +++ b/libqmenumodel/src/qdbusactiongroup.h @@ -0,0 +1,85 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#ifndef QDBUSACTIONGROUP_H +#define QDBUSACTIONGROUP_H + +#include "qdbusobject.h" + +#include +#include + +class QStateAction; + +class QDBusActionGroup : public QObject, public QDBusObject +{ + Q_OBJECT + Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged) + Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged) + Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged) + Q_PROPERTY(int status READ status NOTIFY statusChanged) + +public: + QDBusActionGroup(QObject *parent=0); + ~QDBusActionGroup(); + + void updateActionState(const QString &name, const QVariant &state); + bool hasAction(const QString &name); + + Q_INVOKABLE QStateAction *action(const QString &name); + Q_INVOKABLE QVariant actionState(const QString &name); + +Q_SIGNALS: + void busTypeChanged(DBusEnums::BusType type); + void busNameChanged(const QString &busNameChanged); + void objectPathChanged(const QString &objectPath); + void statusChanged(DBusEnums::ConnectionStatus status); + void actionAppear(const QString &name); + void actionVanish(const QString &name); + void actionStateChanged(const QString &name, QVariant state); + +public Q_SLOTS: + void start(); + void stop(); + +protected: + virtual void serviceAppear(GDBusConnection *connection); + virtual void serviceVanish(GDBusConnection *connection); + +private: + GActionGroup *m_actionGroup; + int m_signalActionAddId; + int m_signalActionRemovedId; + int m_signalStateChangedId; + + // workaround to support int as busType + void setIntBusType(int busType); + + void setActionGroup(GDBusActionGroup *ag); + QStateAction *actionImpl(const QString &name); + + void clear(); + + // glib slots + static void onActionAdded(GDBusActionGroup *ag, gchar *name, gpointer data); + static void onActionRemoved(GDBusActionGroup *ag, gchar *name, gpointer data); + static void onActionStateChanged(GDBusActionGroup *ag, gchar *name, GVariant *value, gpointer data); +}; + +#endif diff --git a/libqmenumodel/src/qdbusmenumodel.cpp b/libqmenumodel/src/qdbusmenumodel.cpp new file mode 100644 index 0000000..88a6084 --- /dev/null +++ b/libqmenumodel/src/qdbusmenumodel.cpp @@ -0,0 +1,109 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#include "qdbusmenumodel.h" + +/*! + \qmlclass QDBusMenuModel + \inherits QDBusObject + + \brief The QDBusMenuModel class defines the list model for DBus menus + + \bold {This component is under heavy development.} + + This class expose the menu previous exported over DBus. + + \code + QDBusMenuModel { + id: menuModel + busType: 1 + busName: "com.ubuntu.menu" + objectPath: "com/ubuntu/menu" + } + + ListView { + id: view + model: menuModel + Component.onCompleted: menuModel.start() + } + \endcode +*/ + +/*! \internal */ +QDBusMenuModel::QDBusMenuModel(QObject *parent) + :QMenuModel(0, parent) +{ +} + +/*! \internal */ +QDBusMenuModel::~QDBusMenuModel() +{ +} + +/*! + \qmlmethod QDBusMenuModel::start() + + Start dbus watch for the busName and wait until it appears. + The status will change to connecting after call this function, and as soon the busName + apperas and the objectPat was found this will change to Connected. + + \bold Note: methods should only be called after the Component has completed. +*/ +void QDBusMenuModel::start() +{ + QDBusObject::connect(); +} + +/*! + \qmlmethod QDBusMenuModel::stop() + + Stops dbus watch and clear the model, the status wil change to Disconnected. + + \bold Note: methods should only be called after the Component has completed. +*/ +void QDBusMenuModel::stop() +{ + QDBusObject::disconnect(); +} + +/*! \internal */ +void QDBusMenuModel::serviceVanish(GDBusConnection *) +{ + setMenuModel(NULL); +} + +/*! \internal */ +void QDBusMenuModel::serviceAppear(GDBusConnection *connection) +{ + GMenuModel *model = reinterpret_cast(g_dbus_menu_model_get(connection, + busName().toLatin1(), + objectPath().toLatin1())); + setMenuModel(model); + if (model == NULL) { + stop(); + } +} + +/*! \internal */ +void QDBusMenuModel::setIntBusType(int busType) +{ + if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) { + setBusType(static_cast(busType)); + } +} diff --git a/libqmenumodel/src/qdbusmenumodel.h b/libqmenumodel/src/qdbusmenumodel.h new file mode 100644 index 0000000..fdf23f7 --- /dev/null +++ b/libqmenumodel/src/qdbusmenumodel.h @@ -0,0 +1,61 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#ifndef QDBUSMENUMODEL_H +#define QDBUSMENUMODEL_H + +#include "qdbusobject.h" +#include "qmenumodel.h" + +extern "C" { +#include +} + +class QDBusMenuModel : public QMenuModel, public QDBusObject +{ + Q_OBJECT + Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged) + Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged) + Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged) + Q_PROPERTY(int status READ status NOTIFY statusChanged) + +public: + QDBusMenuModel(QObject *parent=0); + ~QDBusMenuModel(); + +Q_SIGNALS: + void busTypeChanged(DBusEnums::BusType type); + void busNameChanged(const QString &busNameChanged); + void objectPathChanged(const QString &objectPath); + void statusChanged(DBusEnums::ConnectionStatus status); + +public Q_SLOTS: + void start(); + void stop(); + +protected: + virtual void serviceAppear(GDBusConnection *connection); + virtual void serviceVanish(GDBusConnection *connection); + +private: + // workaround to support int as busType + void setIntBusType(int busType); +}; + +#endif diff --git a/libqmenumodel/src/qdbusobject.cpp b/libqmenumodel/src/qdbusobject.cpp new file mode 100644 index 0000000..abc68b4 --- /dev/null +++ b/libqmenumodel/src/qdbusobject.cpp @@ -0,0 +1,188 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#include "qdbusobject.h" + +#include + +/*! + \qmlclass QDBusObject + \brief The QDBusObject is a base class + + \bold {This component is under heavy development.} + + This is a abstracted class used by QDBusMenuModel and QDBusActionGroup +*/ + +/*! + \qmlproperty int QDBusObject::busType + This property holds the dbus session type which will be used during the connection. + + This must be seteed before call start method + The valid values are: + \list + \o 1 - SessionBus + \o 2 - SystemBus + \endlist +*/ + +/*! + \qmlproperty int QDBusObject::busName + This property holds the dbus service name related with menu. + + This must be seteed before call start method +*/ + +/*! + \qmlproperty int QDBusObject::objectPath + This property holds the dbus object path related with the menu. + + This must be seteed before call start method +*/ + +/*! + \qmlproperty int QDBusObject::status + This property holds current dbus connection status + + Te velid status are: + \list + \o 0 - Disconnected + \o 1 - Connecting + \o 2 - Connected + \endlist +*/ + +QDBusObject::QDBusObject() + :m_watchId(0), + m_busType(DBusEnums::None), + m_status(DBusEnums::Disconnected) +{ + qRegisterMetaType("DBusEnums::ConnectionStatus"); +} + +QDBusObject::~QDBusObject() +{ + if (m_watchId != 0) { + g_bus_unwatch_name (m_watchId); + m_watchId = 0; + } +} + +DBusEnums::BusType QDBusObject::busType() const +{ + return m_busType; +} + +void QDBusObject::setBusType(DBusEnums::BusType type) +{ + if (m_busType != type) { + if (m_status != DBusEnums::Disconnected) + disconnect(); + m_busType = type; + busTypeChanged(m_busType); + } +} + +QString QDBusObject::busName() const +{ + return m_busName; +} + +void QDBusObject::setBusName(const QString &busName) +{ + if (m_busName != busName) { + if (m_status != DBusEnums::Disconnected) + disconnect(); + m_busName = busName; + busNameChanged(m_busName); + } +} + +QString QDBusObject::objectPath() const +{ + return m_objectPath; +} + +void QDBusObject::setObjectPath(const QString &objectPath) +{ + if (m_objectPath != objectPath) { + if (m_status != DBusEnums::Disconnected) + disconnect(); + m_objectPath = objectPath; + objectPathChanged(m_objectPath); + } +} + +void QDBusObject::setStatus(DBusEnums::ConnectionStatus status) +{ + if (m_status != status) { + m_status = status; + statusChanged(m_status); + } +} + +DBusEnums::ConnectionStatus QDBusObject::status() const +{ + return m_status; +} + +void QDBusObject::connect() +{ + if (m_status != DBusEnums::Disconnected) { + return; + } else if ((m_busType > DBusEnums::None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { + GBusType type = m_busType == DBusEnums::SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; + m_watchId = g_bus_watch_name (type, + m_busName.toLatin1(), + G_BUS_NAME_WATCHER_FLAGS_NONE, + QDBusObject::onServiceAppeared, + QDBusObject::onServiceVanished, + this, + NULL); + + setStatus(DBusEnums::Connecting); + } else { + qWarning() << "Invalid dbus connection args"; + } +} + +void QDBusObject::disconnect() +{ + if (m_status != DBusEnums::Disconnected) { + g_bus_unwatch_name (m_watchId); + m_watchId = 0; + setStatus(DBusEnums::Disconnected); + } +} + +void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, const gchar *, gpointer data) +{ + QDBusObject *self = reinterpret_cast(data); + + self->setStatus(DBusEnums::Connected); + self->serviceAppear(connection); +} + +void QDBusObject::onServiceVanished(GDBusConnection *connection, const gchar *, gpointer data) +{ + QDBusObject *self = reinterpret_cast(data); + + self->setStatus(DBusEnums::Connecting); + self->serviceVanish(connection); +} diff --git a/libqmenumodel/src/qdbusobject.h b/libqmenumodel/src/qdbusobject.h new file mode 100644 index 0000000..ef2b42f --- /dev/null +++ b/libqmenumodel/src/qdbusobject.h @@ -0,0 +1,75 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#ifndef QDBUSOBJECT_H +#define QDBUSOBJECT_H + +extern "C" { +#include +} + +#include + +#include "dbus-enums.h" + +class QDBusObject +{ +public: + QDBusObject(); + ~QDBusObject(); + + DBusEnums::BusType busType() const; + void setBusType(DBusEnums::BusType type); + + QString busName() const; + void setBusName(const QString &busName); + + QString objectPath() const; + void setObjectPath(const QString &busName); + + DBusEnums::ConnectionStatus status() const; + + void connect(); + void disconnect(); + +protected: + virtual void serviceAppear(GDBusConnection *connection) = 0; + virtual void serviceVanish(GDBusConnection *connection) = 0; + + // notify functions + virtual void busTypeChanged(DBusEnums::BusType type) = 0; + virtual void busNameChanged(const QString &busNameChanged) = 0; + virtual void objectPathChanged(const QString &objectPath) = 0; + virtual void statusChanged(DBusEnums::ConnectionStatus status) = 0; + +private: + guint m_watchId; + DBusEnums::BusType m_busType; + QString m_busName; + QString m_objectPath; + DBusEnums::ConnectionStatus m_status; + + void setStatus(DBusEnums::ConnectionStatus status); + + // glib slots + static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data); + static void onServiceVanished(GDBusConnection *connection, const gchar *name, gpointer data); +}; + +#endif diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp new file mode 100644 index 0000000..e88bc66 --- /dev/null +++ b/libqmenumodel/src/qmenumodel.cpp @@ -0,0 +1,225 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#include "qmenumodel.h" +#include "converter.h" + +#include + +/*! + \qmlclass QMenuModel + \brief The QMenuModel class implements the base list model for menus + + \bold {This component is under heavy development.} + + This is a abstracted class used by \l QDBusMenuModel. +*/ + +/*! \internal */ +QMenuModel::QMenuModel(GMenuModel *other, QObject *parent) + : QAbstractListModel(parent), + m_menuModel(0), + m_signalChangedId(0) +{ + static QHash rolesNames; + if (rolesNames.empty()) { + rolesNames[Action] = "action"; + rolesNames[Label] = "label"; + rolesNames[LinkSection] = "linkSection"; + rolesNames[LinkSubMenu] = "linkSubMenu"; + rolesNames[Extra] = "extra"; + } + setRoleNames(rolesNames); + setMenuModel(other); +} + +/*! \internal */ +QMenuModel::~QMenuModel() +{ + setMenuModel(NULL); +} + +/*! \internal */ +void QMenuModel::setMenuModel(GMenuModel *other) +{ + if (m_menuModel == other) { + return; + } + + beginResetModel(); + + if (m_menuModel) { + g_signal_handler_disconnect(m_menuModel, m_signalChangedId); + m_signalChangedId = 0; + g_object_unref(m_menuModel); + } + + m_menuModel = other; + + if (m_menuModel) { + // this will trigger the menu load + (void) g_menu_model_get_n_items(m_menuModel); + m_signalChangedId = g_signal_connect(m_menuModel, + "items-changed", + G_CALLBACK(QMenuModel::onItemsChanged), + this); + } + + endResetModel(); +} + +/*! \internal */ +GMenuModel *QMenuModel::menuModel() const +{ + return m_menuModel; +} + +/*! \internal */ +QVariant QMenuModel::data(const QModelIndex &index, int role) const +{ + QVariant attribute; + int rowCountValue = rowCount(); + + if ((rowCountValue > 0) && (index.row() >= 0) && (index.row() < rowCountValue)) { + if (m_menuModel) { + switch (role) { + case Action: + attribute = getStringAttribute(index, G_MENU_ATTRIBUTE_ACTION); + break; + case Label: + attribute = getStringAttribute(index, G_MENU_ATTRIBUTE_LABEL); + break; + case LinkSection: + attribute = getLink(index, G_MENU_LINK_SECTION); + break; + case LinkSubMenu: + attribute = getLink(index, G_MENU_LINK_SUBMENU); + break; + case Extra: + attribute = getExtraProperties(index); + break; + default: + break; + } + } + } + return attribute; +} + +/*! \internal */ +QModelIndex QMenuModel::parent(const QModelIndex &index) const +{ + return QModelIndex(); +} + +/*! \internal */ +int QMenuModel::rowCount(const QModelIndex &) const +{ + if (m_menuModel) { + return g_menu_model_get_n_items(m_menuModel); + } + return 0; +} + +/*! \internal */ +QVariant QMenuModel::getStringAttribute(const QModelIndex &index, + const QString &attribute) const +{ + QVariant result; + gchar* value = NULL; + g_menu_model_get_item_attribute(m_menuModel, + index.row(), + attribute.toLatin1(), + "s", &value); + if (value) { + result = QVariant(QString::fromLatin1(value)); + g_free(value); + } + return result; +} + +/*! \internal */ +QVariant QMenuModel::getLink(const QModelIndex &index, + const QString &linkName) const +{ + GMenuModel *link; + + link = g_menu_model_get_item_link(m_menuModel, + index.row(), + linkName.toLatin1()); + + if (link) { + QMenuModel *other = new QMenuModel(link, const_cast(this)); + return QVariant::fromValue(other); + } + + return QVariant(); +} + +/*! \internal */ +QString QMenuModel::parseExtraPropertyName(const QString &name) const +{ + QString newName(name); + if (name.startsWith("x-")) { + newName = name.mid(2); + } + return newName.replace("-", "_"); +} + +/*! \internal */ +QVariant QMenuModel::getExtraProperties(const QModelIndex &index) const +{ + GMenuAttributeIter *iter = g_menu_model_iterate_item_attributes(m_menuModel, index.row()); + if (iter == NULL) { + return QVariant(); + } + + QVariantMap extra; + const gchar *attrName = NULL; + GVariant *value = NULL; + while (g_menu_attribute_iter_get_next (iter, &attrName, &value)) { + if (strncmp("x-", attrName, 2) == 0) { + extra.insert(parseExtraPropertyName(attrName), + Converter::toQVariant(value)); + } + } + + return extra; +} + +/*! \internal */ +void QMenuModel::onItemsChanged(GMenuModel *, + gint position, + gint removed, + gint added, + gpointer data) +{ + QMenuModel *self = reinterpret_cast(data); + + if (removed > 0) { + self->beginRemoveRows(QModelIndex(), position, position + removed - 1); + self->endRemoveRows(); + } + + if (added > 0) { + self->beginInsertRows(QModelIndex(), position, position + added - 1); + self->endInsertRows(); + } +} + diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h new file mode 100644 index 0000000..7520480 --- /dev/null +++ b/libqmenumodel/src/qmenumodel.h @@ -0,0 +1,66 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#ifndef QMENUMODEL_H +#define QMENUMODEL_H + +#include + +extern "C" { +#include +} + +class QMenuModel : public QAbstractListModel +{ + Q_OBJECT + +public: + enum MenuRoles { + Action = 0, + Label, + LinkSection, + LinkSubMenu, + Extra + }; + + ~QMenuModel(); + + /* QAbstractItemModel */ + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QModelIndex parent (const QModelIndex &index) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + +protected: + QMenuModel(GMenuModel *other=0, QObject *parent=0); + void setMenuModel(GMenuModel *model); + GMenuModel *menuModel() const; + +private: + GMenuModel *m_menuModel; + guint m_signalChangedId; + + QVariant getStringAttribute(const QModelIndex &index, const QString &attribute) const; + QVariant getLink(const QModelIndex &index, const QString &linkName) const; + QVariant getExtraProperties(const QModelIndex &index) const; + QString parseExtraPropertyName(const QString &name) const; + + static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data); +}; + +#endif diff --git a/libqmenumodel/src/qstateaction.cpp b/libqmenumodel/src/qstateaction.cpp new file mode 100644 index 0000000..3629fce --- /dev/null +++ b/libqmenumodel/src/qstateaction.cpp @@ -0,0 +1,145 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#include "qstateaction.h" + +#include "qdbusactiongroup.h" + +/*! + \qmlclass QStateAction + \inherits QAction + + \brief A QStateAction implementation to be used with \l QDBusActionGroup + + \bold {This component is under heavy development.} + + This class can be used as a proxy for an action that is exported over D-Bus + + \code + QDBusActionGroup { + id: actionGroup + busType: 1 + busName: "com.ubuntu.menu" + objectPath: "com/ubuntu/menu/actions" + } + + Button { + visible: actionGroup.getAction("button.bvisible").status + } + \endcode +*/ + +/*! \internal */ +QStateAction::QStateAction(QDBusActionGroup *group, const QString &name) + : QAction(name, group), + m_group(group) +{ + QObject::connect(this, SIGNAL(triggered()), this, SLOT(onTriggered())); + + // This keep the code clean + // But maybe we need move the action state control to QActionGroup to optimizations + QObject::connect(m_group, SIGNAL(actionAppear(QString)), + this, SLOT(onActionAppear(QString))); + QObject::connect(m_group, SIGNAL(actionVanish(QString)), + this, SLOT(onActionVanish(QString))); + QObject::connect(m_group, SIGNAL(actionStateChanged(QString,QVariant)), + this, SLOT(onActionStateChanged(QString,QVariant))); + + + + bool isValid = m_group->hasAction(name); + setValid(isValid); + if (isValid) { + setState(m_group->actionState(name)); + } +} + +/*! + \qmlproperty int QStateAction::state + This property holds the current action state +*/ +QVariant QStateAction::state() const +{ + return m_state; +} + +/*! + \qmlproperty int QStateAction::isValid + This property return if the current Action is valid or not + A valid Action is a action which has a DBus action linked +*/ +bool QStateAction::isValid() const +{ + return m_valid; +} + +void QStateAction::updateState(const QVariant &state) +{ + m_group->updateActionState(text(), state); +} + +/*! \internal */ +void QStateAction::setValid(bool valid) +{ + if (m_valid != valid) { + m_valid = valid; + Q_EMIT validChanged(m_valid); + } +} + +/*! \internal */ +void QStateAction::setState(const QVariant &state) +{ + if (m_state != state) { + m_state = state; + Q_EMIT stateChanged(m_state); + } +} + +/*! \internal */ +void QStateAction::onTriggered() +{ + updateState(QVariant()); +} + +/*! \internal */ +void QStateAction::onActionAppear(const QString &name) +{ + if (text() == name) { + setState(m_group->actionState(name)); + setValid(true); + } +} + +/*! \internal */ +void QStateAction::onActionVanish(const QString &name) +{ + if (text() == name) { + setState(QVariant()); + setValid(false); + } +} + +/*! \internal */ +void QStateAction::onActionStateChanged(const QString &name, const QVariant &state) +{ + if (text() == name) { + setState(state); + } +} diff --git a/libqmenumodel/src/qstateaction.h b/libqmenumodel/src/qstateaction.h new file mode 100644 index 0000000..1a5a0fa --- /dev/null +++ b/libqmenumodel/src/qstateaction.h @@ -0,0 +1,61 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program 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; version 3. + * + * This program 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 program. If not, see . + * + * Authors: + * Renato Araujo Oliveira Filho + */ + +#ifndef QDBUSACTION_H +#define QDBUSACTION_H + +#include +#include + +class QDBusActionGroup; + +class QStateAction : public QAction +{ + Q_OBJECT + Q_PROPERTY(QVariant state READ state WRITE setState NOTIFY stateChanged) + Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) +public: + QVariant state() const; + bool isValid() const; + + Q_INVOKABLE void updateState(const QVariant &state); + +Q_SIGNALS: + void stateChanged(QVariant state); + void validChanged(bool valid); + +private Q_SLOTS: + void onActionAppear(const QString &name); + void onActionVanish(const QString &name); + void onActionStateChanged(const QString &name, const QVariant &state); + void onTriggered(); + +private: + QDBusActionGroup *m_group; + QVariant m_state; + bool m_valid; + + QStateAction(QDBusActionGroup *group, const QString &name); + void setValid(bool valid); + void setState(const QVariant &state); + + friend class QDBusActionGroup; +}; + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 7215efc..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -project(src) - -add_subdirectory(common) -add_subdirectory(QMenuModel) diff --git a/src/QMenuModel/CMakeLists.txt b/src/QMenuModel/CMakeLists.txt deleted file mode 100644 index bf3bb5a..0000000 --- a/src/QMenuModel/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ - -project(qmenumodelqmlplugin) - -set(QMENUMODEL_SRC - plugin.cpp -) - -set(QMENUMODEL_HEADERS - plugin.h -) - -qt4_wrap_cpp(QMENUMODEL_MOC - ${QMENUMODEL_HEADERS} -) - -add_library(qmenumodel MODULE - ${QMENUMODEL_SRC} - ${QMENUMODEL_MOC} -) - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${qmenumodelcommon_SOURCE_DIR} - ${QT_INCLUDE_DIR} - ${QT_QTCORE_INCLUDE_DIR} - ${QT_QTGUI_INCLUDE_DIR} - ${QT_QTDECLARATIVE_INCLUDE_DIR} - ${GLIB_INCLUDE_DIRS} - ${GIO_INCLUDE_DIRS} -) - -target_link_libraries(qmenumodel - qmenumodelcommon - ${QT_QTCORE_LIBRARY} - ${QT_QTGUI_LIBRARY} - ${QT_QTDCLARATIVE_LIBRARY} - ${GLIB_LDFLAGS} - ${GIO_LDFLAGS} -) - -execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" - "${CMAKE_CURRENT_BINARY_DIR}/qmldir") - -set(QMENUMODEL_INSTALL_PREFIX "${QT_IMPORTS_DIR}/Ubuntu/QMenuModel/") -install(TARGETS qmenumodel DESTINATION ${QMENUMODEL_INSTALL_PREFIX}) -install(FILES qmldir DESTINATION ${QMENUMODEL_INSTALL_PREFIX}) diff --git a/src/QMenuModel/plugin.cpp b/src/QMenuModel/plugin.cpp deleted file mode 100644 index ec51ae9..0000000 --- a/src/QMenuModel/plugin.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#include "plugin.h" -#include "qmenumodel.h" -#include "qdbusmenumodel.h" -#include "qdbusactiongroup.h" -#include "qstateaction.h" - -#include - - -void QMenuModelQmlPlugin::registerTypes(const char *uri) -{ - qmlRegisterUncreatableType(uri, 0, 1, "QMenuModel", - "QMenuModel is a interface"); - qmlRegisterUncreatableType(uri, 0, 1, "QStateAction", - "QStateAction must be created by QDBusActionGroup::action"); - qmlRegisterUncreatableType(uri, 0, 1, "DBus", - "DBus is only a namespace"); - - qmlRegisterType(uri, 0, 1, "QDBusMenuModel"); - qmlRegisterType(uri, 0, 1, "QDBusActionGroup"); - -} - -Q_EXPORT_PLUGIN2(qmenumodel, QMenuModelQmlPlugin) diff --git a/src/QMenuModel/plugin.h b/src/QMenuModel/plugin.h deleted file mode 100644 index e9d6850..0000000 --- a/src/QMenuModel/plugin.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#ifndef QMENUMODELQMLPLUGIN_H -#define QMENUMODELQMLPLUGIN_H - -#include - - -class QMenuModelQmlPlugin : public QDeclarativeExtensionPlugin -{ - Q_OBJECT -public: - void registerTypes(const char *uri); -}; - -#endif diff --git a/src/QMenuModel/qmldir b/src/QMenuModel/qmldir deleted file mode 100644 index c8f525f..0000000 --- a/src/QMenuModel/qmldir +++ /dev/null @@ -1 +0,0 @@ -plugin qmenumodel diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt deleted file mode 100644 index 2b831b7..0000000 --- a/src/common/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -project(qmenumodelcommon) - -set(QMENUMODELCOMMON_SRC - converter.cpp - qmenumodel.cpp - qdbusobject.cpp - qdbusmenumodel.cpp - qdbusactiongroup.cpp - qstateaction.cpp -) - -set(QMENUMODELCOMMON_HEADERS - converter.h - dbus-enums.h - qmenumodel.h - qdbusobject.h - qdbusmenumodel.h - qdbusactiongroup.h - qstateaction.h -) - -qt4_wrap_cpp(QMENUMODELCOMMON_MOC - ${QMENUMODELCOMMON_HEADERS} -) - -add_library(qmenumodelcommon STATIC - ${QMENUMODELCOMMON_SRC} - ${QMENUMODELCOMMON_MOC} -) - -set_target_properties(qmenumodelcommon PROPERTIES COMPILE_FLAGS -fPIC) - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${QT_INCLUDE_DIR} - ${QT_QTCORE_INCLUDE_DIR} - ${QT_QTGUI_INCLUDE_DIR} - ${GLIB_INCLUDE_DIRS} - ${GIO_INCLUDE_DIRS} -) - -target_link_libraries(qmenumodelcommon - ${QT_QTCORE_LIBRARY} - ${QT_QTGUI_LIBRARY} - ${GLIB_LDFLAGS} - ${GIO_LDFLAGS} -) diff --git a/src/common/converter.cpp b/src/common/converter.cpp deleted file mode 100644 index a060618..0000000 --- a/src/common/converter.cpp +++ /dev/null @@ -1,118 +0,0 @@ -extern "C" { -#include -} - -#include "converter.h" - -#include -#include - -/*! \internal */ -QVariant Converter::toQVariant(GVariant *value) -{ - QVariant result; - if (value == NULL) { - return result; - } - - const GVariantType *type = g_variant_get_type(value); - if (g_variant_type_equal(type, G_VARIANT_TYPE_BOOLEAN)) { - result.setValue((bool)g_variant_get_boolean(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTE)) { - result.setValue(g_variant_get_byte(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT16)) { - result.setValue(g_variant_get_int16(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT16)) { - result.setValue(g_variant_get_uint16(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT32)) { - result.setValue(g_variant_get_int32(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT32)) { - result.setValue(g_variant_get_uint32(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT64)) { - result.setValue(g_variant_get_int64(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64)) { - result.setValue(g_variant_get_uint64(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_DOUBLE)) { - result.setValue(g_variant_get_double(value)); - } else if (g_variant_type_equal(type, G_VARIANT_TYPE_STRING)) { - gsize size = 0; - const gchar *v = g_variant_get_string(value, &size); - result.setValue(QString::fromLatin1(v, size)); - } else { - qWarning() << "Unsupported GVariant value"; - } - - /* TODO: implement convertions to others types - * G_VARIANT_TYPE_HANDLE - * G_VARIANT_TYPE_OBJECT_PATH - * G_VARIANT_TYPE_SIGNATURE - * G_VARIANT_TYPE_VARIANT - * G_VARIANT_TYPE_ANY - * G_VARIANT_TYPE_BASIC - * G_VARIANT_TYPE_MAYBE - * G_VARIANT_TYPE_ARRAY - * G_VARIANT_TYPE_TUPLE - * G_VARIANT_TYPE_UNIT - * G_VARIANT_TYPE_DICT_ENTRY - * G_VARIANT_TYPE_DICTIONARY - * G_VARIANT_TYPE_STRING_ARRAY - * G_VARIANT_TYPE_BYTESTRING - * G_VARIANT_TYPE_OBJECT_PATH_ARRAY - * G_VARIANT_TYPE_BYTESTRING_ARRAY - * G_VARIANT_TYPE_VARDICT - */ - - return result; -} - -static GVariant* toGVariant(const QString &typeName, const QVariant &value) -{ - if (typeName == "uchar") { - return g_variant_new_byte(value.value()); - } else if (typeName == "short") { - return g_variant_new_int16(value.value()); - } else if (typeName == "ushort") { - return g_variant_new_uint16(value.value()); - } else if (typeName == "long") { - return g_variant_new_int64(value.value()); - } else if (typeName == "ulong") { - return g_variant_new_uint64(value.value()); - } else { - qWarning() << "QVariant type not supported:" << typeName; - } - - return NULL; -} - -GVariant* Converter::toGVariant(const QVariant &value) -{ - GVariant *result = NULL; - if (value.isNull() || !value.isValid()) - return result; - - switch(value.type()) { - case QVariant::Bool: - result = g_variant_new_boolean(value.toBool()); - break; - case QVariant::ByteArray: - result = g_variant_new_bytestring(value.toByteArray()); - break; - case QVariant::Double: - result = g_variant_new_double(value.toDouble()); - break; - case QVariant::Int: - result = g_variant_new_int32(value.toInt()); - break; - case QVariant::String: - result = g_variant_new_string(value.toString().toLatin1()); - break; - case QVariant::UInt: - result = g_variant_new_uint32(value.toUInt()); - break; - default: - result = ::toGVariant(value.typeName(), value); - } - - return result; -} - diff --git a/src/common/converter.h b/src/common/converter.h deleted file mode 100644 index 5f05bc7..0000000 --- a/src/common/converter.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#ifndef CONVERTER_H -#define CONVERTER_H - -typedef struct _GVariant GVariant; -class QVariant; - -class Converter -{ -public: - static QVariant toQVariant(GVariant *value); - static GVariant* toGVariant(const QVariant &value); -}; - -#endif // CONVERTER_H - diff --git a/src/common/dbus-enums.h b/src/common/dbus-enums.h deleted file mode 100644 index 76149da..0000000 --- a/src/common/dbus-enums.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Olivier Tilloy - */ - -#ifndef __DBUS_ENUMS__ -#define __DBUS_ENUMS__ - -#include - -// This class acts as a namespace only, with the addition that its enums -// are registered to be exposed on the QML side. -class DBusEnums : public QObject -{ - Q_OBJECT - - Q_ENUMS(BusType) - Q_ENUMS(ConnectionStatus) - -public: - enum BusType { - None = 0, - SessionBus, - SystemBus, - LastBusType - }; - - enum ConnectionStatus { - Disconnected = 0, - Connecting, - Connected - }; - -private: - DBusEnums() {} -}; - -#endif // __DBUS_ENUMS__ - diff --git a/src/common/qdbusactiongroup.cpp b/src/common/qdbusactiongroup.cpp deleted file mode 100644 index 5a9e0bd..0000000 --- a/src/common/qdbusactiongroup.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#include "qdbusactiongroup.h" -#include "qstateaction.h" -#include "converter.h" - -extern "C" { -#include -} - -/*! - \qmlclass QDBusActionGroup - \inherits QDBusObject - - \brief A DBusActionGroup implementation to be used with \l QDBusMenuModel - - \bold {This component is under heavy development.} - - This class can be used as a proxy for an action group that is exported over D-Bus - - \code - QDBusActionGroup { - id: actionGroup - busType: 1 - busName: "com.ubuntu.menu" - objectPath: "com/ubuntu/menu/actions" - } - - Button { - onClicked: actionGroup.getAction("app.quit").trigger() - } - \endcode -*/ - -/*! \internal */ -QDBusActionGroup::QDBusActionGroup(QObject *parent) - :QObject(parent), - m_actionGroup(NULL) -{ -} - -/*! \internal */ -QDBusActionGroup::~QDBusActionGroup() -{ - clear(); -} - -/*! - \qmlmethod QDBusActionGroup::action(QString name) - - Look for a action with the same name and return a \l QStateAction object. - - \bold Note: methods should only be called after the Component has completed. -*/ -QStateAction *QDBusActionGroup::action(const QString &name) -{ - QStateAction *act = actionImpl(name); - if (act == 0) { - act = new QStateAction(this, name); - } - - return act; -} - -QVariant QDBusActionGroup::actionState(const QString &name) -{ - QVariant result; - GVariant *state = g_action_group_get_action_state(m_actionGroup, name.toLatin1()); - result = Converter::toQVariant(state); - if (state) { - g_variant_unref(state); - } - return result; -} - - -bool QDBusActionGroup::hasAction(const QString &name) -{ - if (m_actionGroup) { - return g_action_group_has_action(m_actionGroup, name.toLatin1()); - } else { - return false; - } -} - -QStateAction *QDBusActionGroup::actionImpl(const QString &name) -{ - Q_FOREACH(QStateAction *act, this->findChildren()) { - if (act->text() == name) { - return act; - } - } - return 0; -} - -/*! \internal */ -void QDBusActionGroup::serviceVanish(GDBusConnection *) -{ - setActionGroup(NULL); -} - -/*! \internal */ -void QDBusActionGroup::serviceAppear(GDBusConnection *connection) -{ - GDBusActionGroup *ag = g_dbus_action_group_get(connection, - busName().toLatin1(), - objectPath().toLatin1()); - setActionGroup(ag); - if (ag == NULL) { - stop(); - } -} - -/*! \internal */ -void QDBusActionGroup::start() -{ - QDBusObject::connect(); -} - -/*! \internal */ -void QDBusActionGroup::stop() -{ - QDBusObject::disconnect(); -} - -/*! \internal */ -void QDBusActionGroup::setIntBusType(int busType) -{ - if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) { - setBusType(static_cast(busType)); - } -} - -/*! \internal */ -void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag) -{ - if (m_actionGroup == reinterpret_cast(ag)) { - return; - } - - if (m_actionGroup) { - g_signal_handler_disconnect(m_actionGroup, m_signalActionAddId); - g_signal_handler_disconnect(m_actionGroup, m_signalActionRemovedId); - g_signal_handler_disconnect(m_actionGroup, m_signalStateChangedId); - m_signalActionAddId = m_signalActionRemovedId = m_signalStateChangedId = 0; - clear(); - } - - m_actionGroup = reinterpret_cast(ag); - - if (m_actionGroup) { - m_signalActionAddId = g_signal_connect(m_actionGroup, - "action-added", - G_CALLBACK(QDBusActionGroup::onActionAdded), - this); - - m_signalActionRemovedId = g_signal_connect(m_actionGroup, - "action-removed", - G_CALLBACK(QDBusActionGroup::onActionRemoved), - this); - - m_signalStateChangedId = g_signal_connect(m_actionGroup, - "action-state-changed", - G_CALLBACK(QDBusActionGroup::onActionStateChanged), - this); - - gchar **actions = g_action_group_list_actions(m_actionGroup); - for(guint i=0; i < g_strv_length(actions); i++) { - Q_EMIT actionAppear(actions[i]); - } - g_strfreev(actions); - } -} - -/*! \internal */ -void QDBusActionGroup::clear() -{ - Q_FOREACH(QStateAction *act, this->findChildren()) { - Q_EMIT actionVanish(act->text()); - } - - if (m_actionGroup != NULL) { - g_object_unref(m_actionGroup); - m_actionGroup = NULL; - } -} - -/*! \internal */ -void QDBusActionGroup::updateActionState(const QString &name, const QVariant &state) -{ - if (m_actionGroup != NULL) { - g_action_group_activate_action(m_actionGroup, name.toLatin1(), Converter::toGVariant(state)); - } -} - -/*! \internal */ -void QDBusActionGroup::onActionAdded(GDBusActionGroup *, gchar *name, gpointer data) -{ - QDBusActionGroup *self = reinterpret_cast(data); - Q_EMIT self->actionAppear(name); -} - -/*! \internal */ -void QDBusActionGroup::onActionRemoved(GDBusActionGroup *, gchar *name, gpointer data) -{ - QDBusActionGroup *self = reinterpret_cast(data); - Q_EMIT self->actionVanish(name); -} - -/*! \internal */ -void QDBusActionGroup::onActionStateChanged(GDBusActionGroup *, gchar *name, GVariant *value, gpointer data) -{ - QDBusActionGroup *self = reinterpret_cast(data); - Q_EMIT self->actionStateChanged(name, Converter::toQVariant(value)); -} diff --git a/src/common/qdbusactiongroup.h b/src/common/qdbusactiongroup.h deleted file mode 100644 index 518f78c..0000000 --- a/src/common/qdbusactiongroup.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#ifndef QDBUSACTIONGROUP_H -#define QDBUSACTIONGROUP_H - -#include "qdbusobject.h" - -#include -#include - -class QStateAction; - -class QDBusActionGroup : public QObject, public QDBusObject -{ - Q_OBJECT - Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged) - Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged) - Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged) - Q_PROPERTY(int status READ status NOTIFY statusChanged) - -public: - QDBusActionGroup(QObject *parent=0); - ~QDBusActionGroup(); - - void updateActionState(const QString &name, const QVariant &state); - bool hasAction(const QString &name); - - Q_INVOKABLE QStateAction *action(const QString &name); - Q_INVOKABLE QVariant actionState(const QString &name); - -Q_SIGNALS: - void busTypeChanged(DBusEnums::BusType type); - void busNameChanged(const QString &busNameChanged); - void objectPathChanged(const QString &objectPath); - void statusChanged(DBusEnums::ConnectionStatus status); - void actionAppear(const QString &name); - void actionVanish(const QString &name); - void actionStateChanged(const QString &name, QVariant state); - -public Q_SLOTS: - void start(); - void stop(); - -protected: - virtual void serviceAppear(GDBusConnection *connection); - virtual void serviceVanish(GDBusConnection *connection); - -private: - GActionGroup *m_actionGroup; - int m_signalActionAddId; - int m_signalActionRemovedId; - int m_signalStateChangedId; - - // workaround to support int as busType - void setIntBusType(int busType); - - void setActionGroup(GDBusActionGroup *ag); - QStateAction *actionImpl(const QString &name); - - void clear(); - - // glib slots - static void onActionAdded(GDBusActionGroup *ag, gchar *name, gpointer data); - static void onActionRemoved(GDBusActionGroup *ag, gchar *name, gpointer data); - static void onActionStateChanged(GDBusActionGroup *ag, gchar *name, GVariant *value, gpointer data); -}; - -#endif diff --git a/src/common/qdbusmenumodel.cpp b/src/common/qdbusmenumodel.cpp deleted file mode 100644 index 88a6084..0000000 --- a/src/common/qdbusmenumodel.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#include "qdbusmenumodel.h" - -/*! - \qmlclass QDBusMenuModel - \inherits QDBusObject - - \brief The QDBusMenuModel class defines the list model for DBus menus - - \bold {This component is under heavy development.} - - This class expose the menu previous exported over DBus. - - \code - QDBusMenuModel { - id: menuModel - busType: 1 - busName: "com.ubuntu.menu" - objectPath: "com/ubuntu/menu" - } - - ListView { - id: view - model: menuModel - Component.onCompleted: menuModel.start() - } - \endcode -*/ - -/*! \internal */ -QDBusMenuModel::QDBusMenuModel(QObject *parent) - :QMenuModel(0, parent) -{ -} - -/*! \internal */ -QDBusMenuModel::~QDBusMenuModel() -{ -} - -/*! - \qmlmethod QDBusMenuModel::start() - - Start dbus watch for the busName and wait until it appears. - The status will change to connecting after call this function, and as soon the busName - apperas and the objectPat was found this will change to Connected. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QDBusMenuModel::start() -{ - QDBusObject::connect(); -} - -/*! - \qmlmethod QDBusMenuModel::stop() - - Stops dbus watch and clear the model, the status wil change to Disconnected. - - \bold Note: methods should only be called after the Component has completed. -*/ -void QDBusMenuModel::stop() -{ - QDBusObject::disconnect(); -} - -/*! \internal */ -void QDBusMenuModel::serviceVanish(GDBusConnection *) -{ - setMenuModel(NULL); -} - -/*! \internal */ -void QDBusMenuModel::serviceAppear(GDBusConnection *connection) -{ - GMenuModel *model = reinterpret_cast(g_dbus_menu_model_get(connection, - busName().toLatin1(), - objectPath().toLatin1())); - setMenuModel(model); - if (model == NULL) { - stop(); - } -} - -/*! \internal */ -void QDBusMenuModel::setIntBusType(int busType) -{ - if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) { - setBusType(static_cast(busType)); - } -} diff --git a/src/common/qdbusmenumodel.h b/src/common/qdbusmenumodel.h deleted file mode 100644 index fdf23f7..0000000 --- a/src/common/qdbusmenumodel.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#ifndef QDBUSMENUMODEL_H -#define QDBUSMENUMODEL_H - -#include "qdbusobject.h" -#include "qmenumodel.h" - -extern "C" { -#include -} - -class QDBusMenuModel : public QMenuModel, public QDBusObject -{ - Q_OBJECT - Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged) - Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged) - Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged) - Q_PROPERTY(int status READ status NOTIFY statusChanged) - -public: - QDBusMenuModel(QObject *parent=0); - ~QDBusMenuModel(); - -Q_SIGNALS: - void busTypeChanged(DBusEnums::BusType type); - void busNameChanged(const QString &busNameChanged); - void objectPathChanged(const QString &objectPath); - void statusChanged(DBusEnums::ConnectionStatus status); - -public Q_SLOTS: - void start(); - void stop(); - -protected: - virtual void serviceAppear(GDBusConnection *connection); - virtual void serviceVanish(GDBusConnection *connection); - -private: - // workaround to support int as busType - void setIntBusType(int busType); -}; - -#endif diff --git a/src/common/qdbusobject.cpp b/src/common/qdbusobject.cpp deleted file mode 100644 index abc68b4..0000000 --- a/src/common/qdbusobject.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#include "qdbusobject.h" - -#include - -/*! - \qmlclass QDBusObject - \brief The QDBusObject is a base class - - \bold {This component is under heavy development.} - - This is a abstracted class used by QDBusMenuModel and QDBusActionGroup -*/ - -/*! - \qmlproperty int QDBusObject::busType - This property holds the dbus session type which will be used during the connection. - - This must be seteed before call start method - The valid values are: - \list - \o 1 - SessionBus - \o 2 - SystemBus - \endlist -*/ - -/*! - \qmlproperty int QDBusObject::busName - This property holds the dbus service name related with menu. - - This must be seteed before call start method -*/ - -/*! - \qmlproperty int QDBusObject::objectPath - This property holds the dbus object path related with the menu. - - This must be seteed before call start method -*/ - -/*! - \qmlproperty int QDBusObject::status - This property holds current dbus connection status - - Te velid status are: - \list - \o 0 - Disconnected - \o 1 - Connecting - \o 2 - Connected - \endlist -*/ - -QDBusObject::QDBusObject() - :m_watchId(0), - m_busType(DBusEnums::None), - m_status(DBusEnums::Disconnected) -{ - qRegisterMetaType("DBusEnums::ConnectionStatus"); -} - -QDBusObject::~QDBusObject() -{ - if (m_watchId != 0) { - g_bus_unwatch_name (m_watchId); - m_watchId = 0; - } -} - -DBusEnums::BusType QDBusObject::busType() const -{ - return m_busType; -} - -void QDBusObject::setBusType(DBusEnums::BusType type) -{ - if (m_busType != type) { - if (m_status != DBusEnums::Disconnected) - disconnect(); - m_busType = type; - busTypeChanged(m_busType); - } -} - -QString QDBusObject::busName() const -{ - return m_busName; -} - -void QDBusObject::setBusName(const QString &busName) -{ - if (m_busName != busName) { - if (m_status != DBusEnums::Disconnected) - disconnect(); - m_busName = busName; - busNameChanged(m_busName); - } -} - -QString QDBusObject::objectPath() const -{ - return m_objectPath; -} - -void QDBusObject::setObjectPath(const QString &objectPath) -{ - if (m_objectPath != objectPath) { - if (m_status != DBusEnums::Disconnected) - disconnect(); - m_objectPath = objectPath; - objectPathChanged(m_objectPath); - } -} - -void QDBusObject::setStatus(DBusEnums::ConnectionStatus status) -{ - if (m_status != status) { - m_status = status; - statusChanged(m_status); - } -} - -DBusEnums::ConnectionStatus QDBusObject::status() const -{ - return m_status; -} - -void QDBusObject::connect() -{ - if (m_status != DBusEnums::Disconnected) { - return; - } else if ((m_busType > DBusEnums::None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) { - GBusType type = m_busType == DBusEnums::SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM; - m_watchId = g_bus_watch_name (type, - m_busName.toLatin1(), - G_BUS_NAME_WATCHER_FLAGS_NONE, - QDBusObject::onServiceAppeared, - QDBusObject::onServiceVanished, - this, - NULL); - - setStatus(DBusEnums::Connecting); - } else { - qWarning() << "Invalid dbus connection args"; - } -} - -void QDBusObject::disconnect() -{ - if (m_status != DBusEnums::Disconnected) { - g_bus_unwatch_name (m_watchId); - m_watchId = 0; - setStatus(DBusEnums::Disconnected); - } -} - -void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, const gchar *, gpointer data) -{ - QDBusObject *self = reinterpret_cast(data); - - self->setStatus(DBusEnums::Connected); - self->serviceAppear(connection); -} - -void QDBusObject::onServiceVanished(GDBusConnection *connection, const gchar *, gpointer data) -{ - QDBusObject *self = reinterpret_cast(data); - - self->setStatus(DBusEnums::Connecting); - self->serviceVanish(connection); -} diff --git a/src/common/qdbusobject.h b/src/common/qdbusobject.h deleted file mode 100644 index ef2b42f..0000000 --- a/src/common/qdbusobject.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#ifndef QDBUSOBJECT_H -#define QDBUSOBJECT_H - -extern "C" { -#include -} - -#include - -#include "dbus-enums.h" - -class QDBusObject -{ -public: - QDBusObject(); - ~QDBusObject(); - - DBusEnums::BusType busType() const; - void setBusType(DBusEnums::BusType type); - - QString busName() const; - void setBusName(const QString &busName); - - QString objectPath() const; - void setObjectPath(const QString &busName); - - DBusEnums::ConnectionStatus status() const; - - void connect(); - void disconnect(); - -protected: - virtual void serviceAppear(GDBusConnection *connection) = 0; - virtual void serviceVanish(GDBusConnection *connection) = 0; - - // notify functions - virtual void busTypeChanged(DBusEnums::BusType type) = 0; - virtual void busNameChanged(const QString &busNameChanged) = 0; - virtual void objectPathChanged(const QString &objectPath) = 0; - virtual void statusChanged(DBusEnums::ConnectionStatus status) = 0; - -private: - guint m_watchId; - DBusEnums::BusType m_busType; - QString m_busName; - QString m_objectPath; - DBusEnums::ConnectionStatus m_status; - - void setStatus(DBusEnums::ConnectionStatus status); - - // glib slots - static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data); - static void onServiceVanished(GDBusConnection *connection, const gchar *name, gpointer data); -}; - -#endif diff --git a/src/common/qmenumodel.cpp b/src/common/qmenumodel.cpp deleted file mode 100644 index e88bc66..0000000 --- a/src/common/qmenumodel.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#include "qmenumodel.h" -#include "converter.h" - -#include - -/*! - \qmlclass QMenuModel - \brief The QMenuModel class implements the base list model for menus - - \bold {This component is under heavy development.} - - This is a abstracted class used by \l QDBusMenuModel. -*/ - -/*! \internal */ -QMenuModel::QMenuModel(GMenuModel *other, QObject *parent) - : QAbstractListModel(parent), - m_menuModel(0), - m_signalChangedId(0) -{ - static QHash rolesNames; - if (rolesNames.empty()) { - rolesNames[Action] = "action"; - rolesNames[Label] = "label"; - rolesNames[LinkSection] = "linkSection"; - rolesNames[LinkSubMenu] = "linkSubMenu"; - rolesNames[Extra] = "extra"; - } - setRoleNames(rolesNames); - setMenuModel(other); -} - -/*! \internal */ -QMenuModel::~QMenuModel() -{ - setMenuModel(NULL); -} - -/*! \internal */ -void QMenuModel::setMenuModel(GMenuModel *other) -{ - if (m_menuModel == other) { - return; - } - - beginResetModel(); - - if (m_menuModel) { - g_signal_handler_disconnect(m_menuModel, m_signalChangedId); - m_signalChangedId = 0; - g_object_unref(m_menuModel); - } - - m_menuModel = other; - - if (m_menuModel) { - // this will trigger the menu load - (void) g_menu_model_get_n_items(m_menuModel); - m_signalChangedId = g_signal_connect(m_menuModel, - "items-changed", - G_CALLBACK(QMenuModel::onItemsChanged), - this); - } - - endResetModel(); -} - -/*! \internal */ -GMenuModel *QMenuModel::menuModel() const -{ - return m_menuModel; -} - -/*! \internal */ -QVariant QMenuModel::data(const QModelIndex &index, int role) const -{ - QVariant attribute; - int rowCountValue = rowCount(); - - if ((rowCountValue > 0) && (index.row() >= 0) && (index.row() < rowCountValue)) { - if (m_menuModel) { - switch (role) { - case Action: - attribute = getStringAttribute(index, G_MENU_ATTRIBUTE_ACTION); - break; - case Label: - attribute = getStringAttribute(index, G_MENU_ATTRIBUTE_LABEL); - break; - case LinkSection: - attribute = getLink(index, G_MENU_LINK_SECTION); - break; - case LinkSubMenu: - attribute = getLink(index, G_MENU_LINK_SUBMENU); - break; - case Extra: - attribute = getExtraProperties(index); - break; - default: - break; - } - } - } - return attribute; -} - -/*! \internal */ -QModelIndex QMenuModel::parent(const QModelIndex &index) const -{ - return QModelIndex(); -} - -/*! \internal */ -int QMenuModel::rowCount(const QModelIndex &) const -{ - if (m_menuModel) { - return g_menu_model_get_n_items(m_menuModel); - } - return 0; -} - -/*! \internal */ -QVariant QMenuModel::getStringAttribute(const QModelIndex &index, - const QString &attribute) const -{ - QVariant result; - gchar* value = NULL; - g_menu_model_get_item_attribute(m_menuModel, - index.row(), - attribute.toLatin1(), - "s", &value); - if (value) { - result = QVariant(QString::fromLatin1(value)); - g_free(value); - } - return result; -} - -/*! \internal */ -QVariant QMenuModel::getLink(const QModelIndex &index, - const QString &linkName) const -{ - GMenuModel *link; - - link = g_menu_model_get_item_link(m_menuModel, - index.row(), - linkName.toLatin1()); - - if (link) { - QMenuModel *other = new QMenuModel(link, const_cast(this)); - return QVariant::fromValue(other); - } - - return QVariant(); -} - -/*! \internal */ -QString QMenuModel::parseExtraPropertyName(const QString &name) const -{ - QString newName(name); - if (name.startsWith("x-")) { - newName = name.mid(2); - } - return newName.replace("-", "_"); -} - -/*! \internal */ -QVariant QMenuModel::getExtraProperties(const QModelIndex &index) const -{ - GMenuAttributeIter *iter = g_menu_model_iterate_item_attributes(m_menuModel, index.row()); - if (iter == NULL) { - return QVariant(); - } - - QVariantMap extra; - const gchar *attrName = NULL; - GVariant *value = NULL; - while (g_menu_attribute_iter_get_next (iter, &attrName, &value)) { - if (strncmp("x-", attrName, 2) == 0) { - extra.insert(parseExtraPropertyName(attrName), - Converter::toQVariant(value)); - } - } - - return extra; -} - -/*! \internal */ -void QMenuModel::onItemsChanged(GMenuModel *, - gint position, - gint removed, - gint added, - gpointer data) -{ - QMenuModel *self = reinterpret_cast(data); - - if (removed > 0) { - self->beginRemoveRows(QModelIndex(), position, position + removed - 1); - self->endRemoveRows(); - } - - if (added > 0) { - self->beginInsertRows(QModelIndex(), position, position + added - 1); - self->endInsertRows(); - } -} - diff --git a/src/common/qmenumodel.h b/src/common/qmenumodel.h deleted file mode 100644 index 7520480..0000000 --- a/src/common/qmenumodel.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#ifndef QMENUMODEL_H -#define QMENUMODEL_H - -#include - -extern "C" { -#include -} - -class QMenuModel : public QAbstractListModel -{ - Q_OBJECT - -public: - enum MenuRoles { - Action = 0, - Label, - LinkSection, - LinkSubMenu, - Extra - }; - - ~QMenuModel(); - - /* QAbstractItemModel */ - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - QModelIndex parent (const QModelIndex &index) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - -protected: - QMenuModel(GMenuModel *other=0, QObject *parent=0); - void setMenuModel(GMenuModel *model); - GMenuModel *menuModel() const; - -private: - GMenuModel *m_menuModel; - guint m_signalChangedId; - - QVariant getStringAttribute(const QModelIndex &index, const QString &attribute) const; - QVariant getLink(const QModelIndex &index, const QString &linkName) const; - QVariant getExtraProperties(const QModelIndex &index) const; - QString parseExtraPropertyName(const QString &name) const; - - static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data); -}; - -#endif diff --git a/src/common/qstateaction.cpp b/src/common/qstateaction.cpp deleted file mode 100644 index 3629fce..0000000 --- a/src/common/qstateaction.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#include "qstateaction.h" - -#include "qdbusactiongroup.h" - -/*! - \qmlclass QStateAction - \inherits QAction - - \brief A QStateAction implementation to be used with \l QDBusActionGroup - - \bold {This component is under heavy development.} - - This class can be used as a proxy for an action that is exported over D-Bus - - \code - QDBusActionGroup { - id: actionGroup - busType: 1 - busName: "com.ubuntu.menu" - objectPath: "com/ubuntu/menu/actions" - } - - Button { - visible: actionGroup.getAction("button.bvisible").status - } - \endcode -*/ - -/*! \internal */ -QStateAction::QStateAction(QDBusActionGroup *group, const QString &name) - : QAction(name, group), - m_group(group) -{ - QObject::connect(this, SIGNAL(triggered()), this, SLOT(onTriggered())); - - // This keep the code clean - // But maybe we need move the action state control to QActionGroup to optimizations - QObject::connect(m_group, SIGNAL(actionAppear(QString)), - this, SLOT(onActionAppear(QString))); - QObject::connect(m_group, SIGNAL(actionVanish(QString)), - this, SLOT(onActionVanish(QString))); - QObject::connect(m_group, SIGNAL(actionStateChanged(QString,QVariant)), - this, SLOT(onActionStateChanged(QString,QVariant))); - - - - bool isValid = m_group->hasAction(name); - setValid(isValid); - if (isValid) { - setState(m_group->actionState(name)); - } -} - -/*! - \qmlproperty int QStateAction::state - This property holds the current action state -*/ -QVariant QStateAction::state() const -{ - return m_state; -} - -/*! - \qmlproperty int QStateAction::isValid - This property return if the current Action is valid or not - A valid Action is a action which has a DBus action linked -*/ -bool QStateAction::isValid() const -{ - return m_valid; -} - -void QStateAction::updateState(const QVariant &state) -{ - m_group->updateActionState(text(), state); -} - -/*! \internal */ -void QStateAction::setValid(bool valid) -{ - if (m_valid != valid) { - m_valid = valid; - Q_EMIT validChanged(m_valid); - } -} - -/*! \internal */ -void QStateAction::setState(const QVariant &state) -{ - if (m_state != state) { - m_state = state; - Q_EMIT stateChanged(m_state); - } -} - -/*! \internal */ -void QStateAction::onTriggered() -{ - updateState(QVariant()); -} - -/*! \internal */ -void QStateAction::onActionAppear(const QString &name) -{ - if (text() == name) { - setState(m_group->actionState(name)); - setValid(true); - } -} - -/*! \internal */ -void QStateAction::onActionVanish(const QString &name) -{ - if (text() == name) { - setState(QVariant()); - setValid(false); - } -} - -/*! \internal */ -void QStateAction::onActionStateChanged(const QString &name, const QVariant &state) -{ - if (text() == name) { - setState(state); - } -} diff --git a/src/common/qstateaction.h b/src/common/qstateaction.h deleted file mode 100644 index 1a5a0fa..0000000 --- a/src/common/qstateaction.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program 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; version 3. - * - * This program 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 program. If not, see . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -#ifndef QDBUSACTION_H -#define QDBUSACTION_H - -#include -#include - -class QDBusActionGroup; - -class QStateAction : public QAction -{ - Q_OBJECT - Q_PROPERTY(QVariant state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(bool valid READ isValid NOTIFY validChanged) -public: - QVariant state() const; - bool isValid() const; - - Q_INVOKABLE void updateState(const QVariant &state); - -Q_SIGNALS: - void stateChanged(QVariant state); - void validChanged(bool valid); - -private Q_SLOTS: - void onActionAppear(const QString &name); - void onActionVanish(const QString &name); - void onActionStateChanged(const QString &name, const QVariant &state); - void onTriggered(); - -private: - QDBusActionGroup *m_group; - QVariant m_state; - bool m_valid; - - QStateAction(QDBusActionGroup *group, const QString &name); - void setValid(bool valid); - void setState(const QVariant &state); - - friend class QDBusActionGroup; -}; - -#endif diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt index c427f54..2c48a07 100644 --- a/tests/client/CMakeLists.txt +++ b/tests/client/CMakeLists.txt @@ -4,7 +4,7 @@ macro(declare_test testname) add_executable(${testname} ${testname}.cpp ${TEST_MOC_FILE}) target_link_libraries(${testname} - qmenumodelcommon + qmenumodel dbusmenuscript ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} @@ -30,7 +30,7 @@ macro(declare_simple_test testname) add_executable(${testname} ${testname}.cpp ${TEST_MOC_FILE}) target_link_libraries(${testname} - qmenumodelcommon + qmenumodel ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} @@ -45,7 +45,7 @@ macro(declare_simple_test testname) TIMEOUT ${CTEST_TESTING_TIMEOUT}) endmacro(declare_simple_test testname) -include_directories(${qmenumodelcommon_SOURCE_DIR} +include_directories(${src_SOURCE_DIR} ${dbusmenuscript_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDE_DIR} -- cgit v1.2.3 From 3fbfb27d55e0d1e4359a295d2dff42984497fa13 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:15:27 +0200 Subject: Updated examples/README to reflect name changes. --- examples/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README b/examples/README index 945da8b..c2516e3 100644 --- a/examples/README +++ b/examples/README @@ -7,5 +7,5 @@ To render this menu in a QML application, run 'render-menumodel.qml' in qmlviewer. You will need to inform qmlviewer of the location of the QMenuModel if it’s not installed system-wide, e.g.: - qmlviewer -I src examples/render-menumodel.qml + qmlviewer -I libqmenumodel examples/render-menumodel.qml -- cgit v1.2.3 From 8e65ebba7d53f5ea59b567e31edc64f06db62796 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:15:44 +0200 Subject: Updated TODO list. --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index bb361e1..cb3cfe6 100644 --- a/TODO +++ b/TODO @@ -2,6 +2,7 @@ • Expose a plain Qt library as well as the QML plugin, so that QDBusMenuModel can be used from C++ too + • Use PIMPLs to clean up the headers (see point above) • Add a server-side API to allow applications to export their menus on the bus • … -- cgit v1.2.3 From 957046e27eafa963e828b2c9b80d8d4bc6a36084 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:16:14 +0200 Subject: Ignore clicks on menu items that do not have a submenu. --- examples/render-menumodel.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/render-menumodel.qml b/examples/render-menumodel.qml index 0128b37..45daf0d 100644 --- a/examples/render-menumodel.qml +++ b/examples/render-menumodel.qml @@ -3,7 +3,7 @@ // /com/canonical/testmenu. import QtQuick 1.1 -import QMenuModel 0.1 // uninstalled, run qmlviewer with "-I ../src" +import QMenuModel 0.1 Item { id: container @@ -51,9 +51,9 @@ Item { MouseArea { id: delegatearea anchors.fill: parent - //enabled: linkSubMenu != null hoverEnabled: true onClicked: { + if (linkSubMenu == null) return var newback = view.__back newback.push(view.model) view.__back = newback -- cgit v1.2.3 From 9fab6d5e340ef892e62ce18343e542ac5a191594 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:26:06 +0200 Subject: Do not install under "Ubuntu" prefix. --- libqmenumodel/QMenuModel/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libqmenumodel/QMenuModel/CMakeLists.txt b/libqmenumodel/QMenuModel/CMakeLists.txt index 891c89c..5fb1d9f 100644 --- a/libqmenumodel/QMenuModel/CMakeLists.txt +++ b/libqmenumodel/QMenuModel/CMakeLists.txt @@ -39,7 +39,7 @@ target_link_libraries(qmenumodel-qml execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/qmldir" "${CMAKE_CURRENT_BINARY_DIR}/qmldir") -set(QMLPLUGIN_INSTALL_PREFIX "${QT_IMPORTS_DIR}/Ubuntu/QMenuModel/") +set(QMLPLUGIN_INSTALL_PREFIX "${QT_IMPORTS_DIR}/QMenuModel") install(TARGETS qmenumodel-qml DESTINATION ${QMLPLUGIN_INSTALL_PREFIX}) install(FILES qmldir DESTINATION ${QMLPLUGIN_INSTALL_PREFIX}) -- cgit v1.2.3 From c81ecae7867c6228989be6428a870848131d242c Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:26:16 +0200 Subject: Updated ignore rules. --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index 6ac94f3..42090bc 100644 --- a/.bzrignore +++ b/.bzrignore @@ -4,6 +4,7 @@ CTestTestfile.cmake Makefile Testing/ cmake_install.cmake +install_manifest.txt moc_*.cxx -- cgit v1.2.3 From 5292d53b16cf375537109917966d62258c7c2f1f Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:31:08 +0200 Subject: Updated ignore rules. --- .bzrignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.bzrignore b/.bzrignore index 42090bc..fe5eb7b 100644 --- a/.bzrignore +++ b/.bzrignore @@ -23,6 +23,7 @@ doc/qmenumodel.qdocconf obj-* debian/files debian/qmenumodel-qml +debian/*.debhelper debian/*.debhelper.log debian/*.substvars debian/stamp-* -- cgit v1.2.3 From 795bf87a2e1e9d362a8ff0f55628021410964f3e Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:42:30 +0200 Subject: Renamed source package to 'qmenumodel', and removed useless build dependencies. --- debian/changelog | 6 ++++++ debian/control | 13 ++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/debian/changelog b/debian/changelog index e178128..c855594 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +qmenumodel (0.1.1) UNRELEASED; urgency=low + + * Renaming source package to qmenumodel + + -- Olivier Tilloy Thu, 04 Oct 2012 17:37:23 +0200 + qmenumodel-qml (0.1.0) quantal; urgency=low * Initial package; diff --git a/debian/control b/debian/control index c28f2b5..e07ea3a 100644 --- a/debian/control +++ b/debian/control @@ -1,19 +1,18 @@ -Source: qmenumodel-qml +Source: qmenumodel Section: libs Priority: optional Maintainer: Renato Araujo Oliveira Filho -Build-Depends: debhelper (>= 7.0.50~), - libqt4-dev, +Build-Depends: debhelper (>= 8.0.0), cdbs, cmake, libglib2.0-dev, - dbus-test-runner, - lcov, - zip + libqt4-dev, Standards-Version: 3.9.2 Package: qmenumodel-qml +Section: libs Architecture: any Depends: ${shlibs:Depends}, - ${misc:Depends} + ${misc:Depends}, Description: QML bindings for GMenuModel + -- cgit v1.2.3 From 5fb1863497f1d02ea2f9eb1ad6c73e652d19d59f Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Thu, 4 Oct 2012 17:53:52 +0200 Subject: Fix variant conversion on 32-bits platforms. --- libqmenumodel/src/converter.cpp | 12 ++++++------ tests/client/modeltest.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index a060618..452f68c 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -21,17 +21,17 @@ QVariant Converter::toQVariant(GVariant *value) } else if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTE)) { result.setValue(g_variant_get_byte(value)); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT16)) { - result.setValue(g_variant_get_int16(value)); + result.setValue(qint16(g_variant_get_int16(value))); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT16)) { - result.setValue(g_variant_get_uint16(value)); + result.setValue(quint16(g_variant_get_uint16(value))); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT32)) { - result.setValue(g_variant_get_int32(value)); + result.setValue(qint32(g_variant_get_int32(value))); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT32)) { - result.setValue(g_variant_get_uint32(value)); + result.setValue(quint32(g_variant_get_uint32(value))); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT64)) { - result.setValue(g_variant_get_int64(value)); + result.setValue(qint64(g_variant_get_int64(value))); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64)) { - result.setValue(g_variant_get_uint64(value)); + result.setValue(quint64(g_variant_get_uint64(value))); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_DOUBLE)) { result.setValue(g_variant_get_double(value)); } else if (g_variant_type_equal(type, G_VARIANT_TYPE_STRING)) { diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index b1f2090..9f6ee76 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -185,12 +185,12 @@ private Q_SLOTS: // Int64 v = extra["int64"]; - QCOMPARE(v.typeName(), "long"); + QCOMPARE(v.type(), QVariant::LongLong); QCOMPARE(v.value(), (long) -42); // UInt64 v = extra["uint64"]; - QCOMPARE(v.typeName(), "ulong"); + QCOMPARE(v.type(), QVariant::ULongLong); QCOMPARE(v.value(), (ulong) 42); // Double -- cgit v1.2.3 From 696fba50395807c344325af11e71ec74cf370c3d Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Fri, 5 Oct 2012 11:50:07 +0200 Subject: Fix source dir for documentation generation. --- doc/qmenumodel.qdocconf.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/qmenumodel.qdocconf.in b/doc/qmenumodel.qdocconf.in index 5ab30f4..97b560c 100644 --- a/doc/qmenumodel.qdocconf.in +++ b/doc/qmenumodel.qdocconf.in @@ -1,5 +1,5 @@ project = QMenuModel QML elements -sourcedirs = @qmenumodelcommon_SOURCE_DIR@ +sourcedirs = @src_SOURCE_DIR@ sources.fileextensions = "*.cpp" outputdir = html outputformats = HTML -- cgit v1.2.3