aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore25
-rw-r--r--CMakeLists.txt1
-rw-r--r--cmake/lcov.cmake2
-rw-r--r--examples/CMakeLists.txt4
-rw-r--r--examples/README11
-rwxr-xr-xexamples/exportactiongroup.py57
-rwxr-xr-xexamples/exportmenu.py63
-rw-r--r--examples/render-menumodel.qml136
-rwxr-xr-xexamples/run-example.sh.in1
-rw-r--r--src/QMenuModel/plugin.cpp2
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/converter.cpp10
-rw-r--r--src/common/converter.h13
-rw-r--r--src/common/dbus-enums.h53
-rw-r--r--src/common/qdbusactiongroup.cpp4
-rw-r--r--src/common/qdbusactiongroup.h6
-rw-r--r--src/common/qdbusmenumodel.cpp4
-rw-r--r--src/common/qdbusmenumodel.h6
-rw-r--r--src/common/qdbusobject.cpp40
-rw-r--r--src/common/qdbusobject.h33
-rw-r--r--src/common/qmenumodel.cpp6
-rw-r--r--src/common/qmenumodel.h1
-rw-r--r--tests/client/actiongrouptest.cpp22
-rw-r--r--tests/client/convertertest.cpp4
-rw-r--r--tests/client/menuchangestest.cpp2
-rw-r--r--tests/client/modeltest.cpp22
-rw-r--r--tests/client/servicetest.cpp20
-rw-r--r--tests/script/menuscript.py2
28 files changed, 435 insertions, 116 deletions
diff --git a/.bzrignore b/.bzrignore
new file mode 100644
index 0000000..fa8f70d
--- /dev/null
+++ b/.bzrignore
@@ -0,0 +1,25 @@
+CMakeCache.txt
+CMakeFiles/
+CTestTestfile.cmake
+Makefile
+Testing/
+cmake_install.cmake
+
+moc_*.cxx
+
+coverage/
+
+tests/client/*.moc
+tests/client/actiongrouptest
+tests/client/convertertest
+tests/client/menuchangestest
+tests/client/modeltest
+tests/client/servicetest
+
+obj-*
+debian/files
+debian/qmenumodel-qml
+debian/*.debhelper.log
+debian/*.substvars
+debian/stamp-*
+
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/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)
-
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/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
+ }
+ }
+}
+
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
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<QStateAction>(uri, 0, 1, "QStateAction",
"QStateAction must be created by QDBusActionGroup::action");
+ qmlRegisterUncreatableType<DBusEnums>(uri, 0, 1, "DBus",
+ "DBus is only a namespace");
qmlRegisterType<QDBusMenuModel>(uri, 0, 1, "QDBusMenuModel");
qmlRegisterType<QDBusActionGroup>(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/converter.cpp b/src/common/converter.cpp
index 54d4665..a060618 100644
--- a/src/common/converter.cpp
+++ b/src/common/converter.cpp
@@ -1,6 +1,11 @@
+extern "C" {
+#include <glib.h>
+}
+
#include "converter.h"
#include <QDebug>
+#include <QVariant>
/*! \internal */
QVariant Converter::toQVariant(GVariant *value)
@@ -60,7 +65,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<uchar>());
@@ -105,8 +110,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..5f05bc7 100644
--- a/src/common/converter.h
+++ b/src/common/converter.h
@@ -20,20 +20,15 @@
#ifndef CONVERTER_H
#define CONVERTER_H
-#include <QVariant>
-#include <glib.h>
+typedef struct _GVariant GVariant;
+class QVariant;
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
+
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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Olivier Tilloy <olivier.tilloy@canonical.com>
+ */
+
+#ifndef __DBUS_ENUMS__
+#define __DBUS_ENUMS__
+
+#include <QObject>
+
+// 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>(busType));
+ if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) {
+ setBusType(static_cast<DBusEnums::BusType>(busType));
}
}
diff --git a/src/common/qdbusactiongroup.h b/src/common/qdbusactiongroup.h
index 2f46f8f..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(ConnectionStatus status);
+ void statusChanged(DBusEnums::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);
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>(busType));
+ if ((busType > DBusEnums::None) && (busType < DBusEnums::LastBusType)) {
+ setBusType(static_cast<DBusEnums::BusType>(busType));
}
}
diff --git a/src/common/qdbusmenumodel.h b/src/common/qdbusmenumodel.h
index 8308268..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();
@@ -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);
};
diff --git a/src/common/qdbusobject.cpp b/src/common/qdbusobject.cpp
index d5ac44b..abc68b4 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>("QDBusObject::ConnectionStatus");
+ qRegisterMetaType<DBusEnums::ConnectionStatus>("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,26 +137,26 @@ 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,
QDBusObject::onServiceAppeared,
- QDBusObject::onServiceFanished,
+ QDBusObject::onServiceVanished,
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,14 +175,14 @@ void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *,
{
QDBusObject *self = reinterpret_cast<QDBusObject*>(data);
- self->setStatus(QDBusObject::Connected);
+ self->setStatus(DBusEnums::Connected);
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<QDBusObject*>(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..a3cef38 100644
--- a/src/common/qdbusobject.h
+++ b/src/common/qdbusobject.h
@@ -24,27 +24,16 @@
#include <gio/gio.h>
+#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,23 +51,23 @@ 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);
- static void onServiceFanished(GDBusConnection *connection, const gchar *name, 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
index cc760c1..e88bc66 100644
--- a/src/common/qmenumodel.cpp
+++ b/src/common/qmenumodel.cpp
@@ -91,12 +91,6 @@ GMenuModel *QMenuModel::menuModel() const
}
/*! \internal */
-int QMenuModel::columnCount(const QModelIndex &) const
-{
- return 1;
-}
-
-/*! \internal */
QVariant QMenuModel::data(const QModelIndex &index, int role) const
{
QVariant attribute;
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/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/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 <renato@canonical.com>
*/
+extern "C" {
+#include <glib.h>
+}
+
#include "converter.h"
#include <QObject>
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 ee3e0f4..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);
}
@@ -57,14 +57,6 @@ private Q_SLOTS:
}
/*
- * Test if columnCount is always 1
- */
- void testColumnCount()
- {
- QCOMPARE(m_model.columnCount(), 1);
- }
-
- /*
* Test if parent function always return a empty QModelIndex
*/
void testParent()
@@ -78,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);
}
@@ -106,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)
@@ -154,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);
}
};
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