aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-10-15 09:54:06 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-10-15 09:54:06 -0300
commit5c56d1288ba905ab162246c65fffbc69a831a14e (patch)
tree5043b5daf97aa9e2bb2e87e7d5809b3a762e556e
parente243399cba32f939eccdcb55fe093b7c57f31161 (diff)
parent5999e7a42962140b6479995d77a178186b6b2fcc (diff)
downloadqmenumodel-5c56d1288ba905ab162246c65fffbc69a831a14e.tar.gz
qmenumodel-5c56d1288ba905ab162246c65fffbc69a831a14e.tar.bz2
qmenumodel-5c56d1288ba905ab162246c65fffbc69a831a14e.zip
Merged mainline.
-rw-r--r--.bzrignore8
-rw-r--r--CMakeLists.txt3
-rw-r--r--TODO7
-rw-r--r--debian/changelog9
-rw-r--r--debian/control28
-rw-r--r--debian/libqmenumodel-dev.install4
-rw-r--r--debian/libqmenumodel0.install2
-rw-r--r--debian/qmenumodel-qml.install2
-rwxr-xr-xdebian/rules1
-rw-r--r--examples/CMakeLists.txt20
-rw-r--r--examples/README16
-rw-r--r--examples/info-menumodel.cpp87
-rw-r--r--libqmenumodel/QMenuModel/plugin.cpp5
-rw-r--r--libqmenumodel/src/CMakeLists.txt39
-rw-r--r--libqmenumodel/src/qdbusmenumodel.h2
-rw-r--r--libqmenumodel/src/qdbusobject.cpp11
-rw-r--r--libqmenumodel/src/qmenumodel.pc.in13
-rw-r--r--tests/client/actiongrouptest.cpp5
-rw-r--r--tests/client/menuchangestest.cpp5
-rw-r--r--tests/client/modeltest.cpp5
-rw-r--r--tests/client/servicetest.cpp5
21 files changed, 236 insertions, 41 deletions
diff --git a/.bzrignore b/.bzrignore
index 6097094..8dfdfff 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -6,6 +6,9 @@ Testing/
cmake_install.cmake
install_manifest.txt
+libqmenumodel/src/libqmenumodel.so*
+libqmenumodel/src/qmenumodel.pc
+
moc_*.cpp
*_automoc.cpp
@@ -25,7 +28,10 @@ doc/qmenumodel.qdocconf
obj-*
debian/files
-debian/qmenumodel-qml
+debian/tmp
+debian/libqmenumodel0/
+debian/libqmenumodel-dev/
+debian/qmenumodel-qml/
debian/*.debhelper
debian/*.debhelper.log
debian/*.substvars
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f51f637..261335a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,9 @@ project(qmenumodel)
cmake_minimum_required(VERSION 2.8.9)
+# Standard install paths
+include(GNUInstallDirs)
+
find_package(Qt5Core REQUIRED)
include(FindPkgConfig)
pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
diff --git a/TODO b/TODO
index cb3cfe6..e3880fb 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,9 @@
= TODO =
- • 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)
+ • Use PIMPLs to clean up the headers
• Add a server-side API to allow applications to export their menus on the bus
+ • [optional] Add a ProjectConfig.cmake file to allow other projects using
+ cmake to express a dependency on libqmenumodel without requesting pkgconfig
+ (see http://www.vtk.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file)
• …
diff --git a/debian/changelog b/debian/changelog
index 8c2daf7..acdf0fc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+qmenumodel (0.1.4) UNRELEASED; urgency=low
+
+ * Expose a C++ library, and separate into 3 binary packages:
+ - libqmenumodel0: C++ library
+ - libqmenumodel-dev: development headers for the C++ library
+ - qmenumodel-qml: QML module
+
+ -- Olivier Tilloy <olivier.tilloy@canonical.com> Mon, 15 Oct 2012 11:51:13 +0200
+
qmenumodel (0.1.3) quantal; urgency=low
* Rebuild for armhf
diff --git a/debian/control b/debian/control
index 211a3c1..0e5d4c1 100644
--- a/debian/control
+++ b/debian/control
@@ -10,10 +10,36 @@ Build-Depends: debhelper (>= 8.0.0),
qtdeclarative (>= 5.0),
Standards-Version: 3.9.2
+Package: libqmenumodel0
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends},
+ ${misc:Depends},
+Pre-Depends: ${misc:Pre-Depends}
+Description: Qt binding for GMenuModel - shared library
+ Qt binding for GMenuModel that allows connecting to a menu model exposed on
+ D-Bus and presents it as a list model.
+
+Package: libqmenumodel-dev
+Section: libdevel
+Architecture: any
+Depends: ${shlibs:Depends},
+ ${misc:Depends},
+ libqmenumodel0 (= ${binary:Version}),
+ qtbase (>= 5.0),
+Description: Qt binding for GMenuModel - development files
+ Qt binding for GMenuModel that allows connecting to a menu model exposed on
+ D-Bus and presents it as a list model.
+ .
+ This package contains the development headers for libqmenumodel.
+
Package: qmenumodel-qml
Section: libs
Architecture: any
Depends: ${shlibs:Depends},
${misc:Depends},
-Description: QML bindings for GMenuModel
+ libqmenumodel0 (= ${binary:Version}),
+Description: Qt binding for GMenuModel - QML module
+ QML module that allows connecting to a menu model exposed on D-Bus and presents
+ it as a list model.
diff --git a/debian/libqmenumodel-dev.install b/debian/libqmenumodel-dev.install
new file mode 100644
index 0000000..31c0d09
--- /dev/null
+++ b/debian/libqmenumodel-dev.install
@@ -0,0 +1,4 @@
+usr/include/qmenumodel/*.h
+usr/lib/*/pkgconfig/qmenumodel.pc
+usr/lib/*/libqmenumodel.so
+
diff --git a/debian/libqmenumodel0.install b/debian/libqmenumodel0.install
new file mode 100644
index 0000000..bea61ce
--- /dev/null
+++ b/debian/libqmenumodel0.install
@@ -0,0 +1,2 @@
+usr/lib/*/libqmenumodel.so.*
+
diff --git a/debian/qmenumodel-qml.install b/debian/qmenumodel-qml.install
new file mode 100644
index 0000000..58ec19a
--- /dev/null
+++ b/debian/qmenumodel-qml.install
@@ -0,0 +1,2 @@
+opt/qt5/imports/QMenuModel/*
+
diff --git a/debian/rules b/debian/rules
index 2756628..7e8093d 100755
--- a/debian/rules
+++ b/debian/rules
@@ -2,6 +2,7 @@
# -*- makefile -*-
DEB_CMAKE_EXTRA_FLAGS = -DCMAKE_PREFIX_PATH=/opt/qt5/lib/cmake
+DEB_DH_MAKESHLIBS_ARGS_qmenumodel-qml = -Xlibqmenumodel-qml.so
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/utils.mk
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..028c6ef
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Standalone CMakeLists.txt to generate the info-menumodel executable.
+# This is not built as part of libqmenumodel, it has to be built separately
+# and it assumes libqmenumodel-dev is installed on the system.
+
+cmake_minimum_required(VERSION 2.8.9)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+
+find_package(Qt5Core REQUIRED)
+
+include(FindPkgConfig)
+pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
+
+add_executable(info-menumodel info-menumodel.cpp)
+
+qt5_use_modules(info-menumodel Core)
+include_directories(${QMENUMODEL_INCLUDE_DIRS})
+target_link_libraries(info-menumodel ${QMENUMODEL_LDFLAGS})
+
diff --git a/examples/README b/examples/README
index 1ecac0e..ab683f3 100644
--- a/examples/README
+++ b/examples/README
@@ -1,11 +1,23 @@
This directory contains examples that demonstrate how to use the QMenuModel
-QML binding in applications.
+binding in Qt and QML 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
qmlscene. You will need to inform qmlscene of the location of the QMenuModel
plugin if it’s not installed system-wide, e.g.:
- qmlscene -I libqmenumodel examples/render-menumodel.qml
+ $ qmlscene -I libqmenumodel examples/render-menumodel.qml
+
+
+To compile a C++ executable that uses libqmenumodel to monitor and print
+information about the exported menu, run `cmake` and then `make` from this
+directory. This assumes that libqmenumodel-dev is installed on the system
+(it won’t work with a local copy). Then, run the executable generated:
+
+ $ cmake .
+ $ make
+ $ ./info-menumodel
diff --git a/examples/info-menumodel.cpp b/examples/info-menumodel.cpp
new file mode 100644
index 0000000..d370731
--- /dev/null
+++ b/examples/info-menumodel.cpp
@@ -0,0 +1,87 @@
+/*
+ * Example executable that links against libqmenumodel to monitor
+ * and print information about a menu model exported on D-Bus.
+ */
+
+// QMenuModel
+#include "qmenumodel/qdbusmenumodel.h"
+
+// stdlib
+#include <iostream>
+
+// Qt
+#include <QtCore/QCoreApplication>
+#include <QtCore/QObject>
+
+
+#define BUS_NAME "com.canonical.testmenu"
+#define BUS_OBJECT_PATH "/com/canonical/testmenu"
+
+
+class MenuModelMonitor : public QDBusMenuModel
+{
+ Q_OBJECT
+
+public:
+ MenuModelMonitor(QObject* parent=0)
+ : QDBusMenuModel(parent)
+ {
+ setProperty("busType", DBusEnums::SessionBus);
+ setProperty("busName", BUS_NAME);
+ setProperty("objectPath", BUS_OBJECT_PATH);
+ QObject::connect(this, SIGNAL(statusChanged(DBusEnums::ConnectionStatus)),
+ SLOT(onStatusChanged(DBusEnums::ConnectionStatus)));
+ QObject::connect(this, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
+ SLOT(onModelChanged()));
+ QObject::connect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
+ SLOT(onModelChanged()));
+ std::cout << "Monitoring menu model "
+ << property("objectPath").toString().toUtf8().constData()
+ << " on the well-known name "
+ << property("busName").toString().toUtf8().constData()
+ << std::endl;
+ }
+
+private Q_SLOTS:
+ void onStatusChanged(DBusEnums::ConnectionStatus status)
+ {
+ std::cout << "Status of menu model changed to " << status << std::endl;
+ if (status == DBusEnums::Connected) {
+ printModel(this);
+ }
+ }
+
+ void onModelChanged()
+ {
+ printModel(this);
+ }
+
+private:
+ void printModel(QMenuModel* model, int indent=0)
+ {
+ int count = model->rowCount();
+ for (int i = 0; i < count; ++i) {
+ QModelIndex index = model->index(i, 0);
+ QString label = model->data(index, QMenuModel::Label).toString();
+ QVariant submenu = model->data(index, QMenuModel::LinkSubMenu);
+ for (int j = 0; j < indent * 2; ++j) std::cout << " ";
+ std::cout << " > " << label.toUtf8().constData() << std::endl;
+ if (submenu.isValid()) {
+ printModel(qobject_cast<QMenuModel*>(submenu.value<QObject*>()), indent + 1);
+ }
+ }
+ }
+};
+
+#include "info-menumodel.moc"
+
+
+int main(int argc, char** argv)
+{
+ MenuModelMonitor monitor;
+ monitor.start();
+ int result = QCoreApplication(argc, argv).exec();
+ monitor.stop();
+ return result;
+}
+
diff --git a/libqmenumodel/QMenuModel/plugin.cpp b/libqmenumodel/QMenuModel/plugin.cpp
index 26650eb..ee05fff 100644
--- a/libqmenumodel/QMenuModel/plugin.cpp
+++ b/libqmenumodel/QMenuModel/plugin.cpp
@@ -17,10 +17,6 @@
* Renato Araujo Oliveira Filho <renato@canonical.com>
*/
-extern "C" {
-#include <glib-object.h>
-}
-
#include "plugin.h"
#include "qmenumodel.h"
#include "qdbusmenumodel.h"
@@ -31,7 +27,6 @@ extern "C" {
void QMenuModelQmlPlugin::registerTypes(const char *uri)
{
- g_type_init();
qmlRegisterUncreatableType<QMenuModel>(uri, 0, 1, "QMenuModel",
"QMenuModel is a interface");
qmlRegisterUncreatableType<QStateAction>(uri, 0, 1, "QStateAction",
diff --git a/libqmenumodel/src/CMakeLists.txt b/libqmenumodel/src/CMakeLists.txt
index 373d11b..8edb3e1 100644
--- a/libqmenumodel/src/CMakeLists.txt
+++ b/libqmenumodel/src/CMakeLists.txt
@@ -10,15 +10,48 @@ set(QMENUMODEL_SRC
qstateaction.cpp
)
-add_library(qmenumodel STATIC
+set(SHAREDLIBNAME qmenumodel)
+add_library(${SHAREDLIBNAME} SHARED
${QMENUMODEL_SRC}
)
-set_target_properties(qmenumodel PROPERTIES COMPILE_FLAGS -fPIC)
+set_target_properties(${SHAREDLIBNAME} PROPERTIES
+ COMPILE_FLAGS -fPIC
+ SOVERSION 0
+ VERSION 0.1.1
+)
include_directories(
${GLIB_INCLUDE_DIRS}
+ ${GIO_INCLUDE_DIRS}
+)
+
+target_link_libraries(${SHAREDLIBNAME}
+ ${GLIB_LDFLAGS}
+ ${GIO_LDFLAGS}
)
-qt5_use_modules(qmenumodel Core Widgets)
+qt5_use_modules(${SHAREDLIBNAME} Core Widgets)
+
+install(TARGETS ${SHAREDLIBNAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+set(QMENUMODEL_HEADERS
+ dbus-enums.h
+ qdbusactiongroup.h
+ qdbusmenumodel.h
+ qdbusobject.h
+ qmenumodel.h
+ qstateaction.h
+)
+
+set(INCLUDEDIR qmenumodel)
+install(FILES ${QMENUMODEL_HEADERS}
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${INCLUDEDIR}
+)
+
+set(PCFILE qmenumodel.pc)
+configure_file(${PCFILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${PCFILE} @ONLY)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PCFILE}
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
+)
diff --git a/libqmenumodel/src/qdbusmenumodel.h b/libqmenumodel/src/qdbusmenumodel.h
index 5beb3b9..6943613 100644
--- a/libqmenumodel/src/qdbusmenumodel.h
+++ b/libqmenumodel/src/qdbusmenumodel.h
@@ -33,7 +33,7 @@ class QDBusMenuModel : public QMenuModel, public QDBusObject
public:
QDBusMenuModel(QObject *parent=0);
- ~QDBusMenuModel();
+ ~QDBusMenuModel();
Q_SIGNALS:
void busTypeChanged(DBusEnums::BusType type);
diff --git a/libqmenumodel/src/qdbusobject.cpp b/libqmenumodel/src/qdbusobject.cpp
index 929aec0..5a5a14b 100644
--- a/libqmenumodel/src/qdbusobject.cpp
+++ b/libqmenumodel/src/qdbusobject.cpp
@@ -78,6 +78,7 @@ QDBusObject::QDBusObject()
m_busType(DBusEnums::None),
m_status(DBusEnums::Disconnected)
{
+ g_type_init();
qRegisterMetaType<DBusEnums::ConnectionStatus>("DBusEnums::ConnectionStatus");
}
@@ -100,7 +101,7 @@ void QDBusObject::setBusType(DBusEnums::BusType type)
if (m_status != DBusEnums::Disconnected)
disconnect();
m_busType = type;
- busTypeChanged(m_busType);
+ Q_EMIT busTypeChanged(m_busType);
}
}
@@ -115,7 +116,7 @@ void QDBusObject::setBusName(const QString &busName)
if (m_status != DBusEnums::Disconnected)
disconnect();
m_busName = busName;
- busNameChanged(m_busName);
+ Q_EMIT busNameChanged(m_busName);
}
}
@@ -130,7 +131,7 @@ void QDBusObject::setObjectPath(const QString &objectPath)
if (m_status != DBusEnums::Disconnected)
disconnect();
m_objectPath = objectPath;
- objectPathChanged(m_objectPath);
+ Q_EMIT objectPathChanged(m_objectPath);
}
}
@@ -138,7 +139,7 @@ void QDBusObject::setStatus(DBusEnums::ConnectionStatus status)
{
if (m_status != status) {
m_status = status;
- statusChanged(m_status);
+ Q_EMIT statusChanged(m_status);
}
}
@@ -180,8 +181,8 @@ void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *,
{
QDBusObject *self = reinterpret_cast<QDBusObject*>(data);
- self->setStatus(DBusEnums::Connected);
self->serviceAppear(connection);
+ self->setStatus(DBusEnums::Connected);
}
void QDBusObject::onServiceVanished(GDBusConnection *connection, const gchar *, gpointer data)
diff --git a/libqmenumodel/src/qmenumodel.pc.in b/libqmenumodel/src/qmenumodel.pc.in
new file mode 100644
index 0000000..1c410bc
--- /dev/null
+++ b/libqmenumodel/src/qmenumodel.pc.in
@@ -0,0 +1,13 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=@CMAKE_INSTALL_PREFIX@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+
+Name: qmenumodel
+Description: Qt binding for GMenuModel.
+Version: 0.1
+
+Requires.private: QtCore QtWidgets gio-2.0
+Libs: -L${libdir} -l@SHAREDLIBNAME@
+Cflags: -I${includedir}/@INCLUDEDIR@
+
diff --git a/tests/client/actiongrouptest.cpp b/tests/client/actiongrouptest.cpp
index 958ddc7..116bd44 100644
--- a/tests/client/actiongrouptest.cpp
+++ b/tests/client/actiongrouptest.cpp
@@ -17,10 +17,6 @@
* Renato Araujo Oliveira Filho <renato@canonical.com>
*/
-extern "C" {
-#include <glib-object.h>
-}
-
#include "qdbusmenumodel.h"
#include "qdbusactiongroup.h"
#include "dbusmenuscript.h"
@@ -42,7 +38,6 @@ private:
private Q_SLOTS:
void initTestCase()
{
- g_type_init();
Q_ASSERT(m_script.connect());
}
diff --git a/tests/client/menuchangestest.cpp b/tests/client/menuchangestest.cpp
index bc7dcbd..2015582 100644
--- a/tests/client/menuchangestest.cpp
+++ b/tests/client/menuchangestest.cpp
@@ -17,10 +17,6 @@
* Renato Araujo Oliveira Filho <renato@canonical.com>
*/
-extern "C" {
-#include <glib-object.h>
-}
-
#include "qdbusmenumodel.h"
#include "dbusmenuscript.h"
@@ -39,7 +35,6 @@ private:
private Q_SLOTS:
void initTestCase()
{
- g_type_init();
Q_ASSERT(m_script.connect());
}
diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp
index 8f20bc3..03629ca 100644
--- a/tests/client/modeltest.cpp
+++ b/tests/client/modeltest.cpp
@@ -17,10 +17,6 @@
* Renato Araujo Oliveira Filho <renato@canonical.com>
*/
-extern "C" {
-#include <glib-object.h>
-}
-
#include "qdbusmenumodel.h"
#include "dbusmenuscript.h"
@@ -39,7 +35,6 @@ private:
private Q_SLOTS:
void initTestCase()
{
- g_type_init();
Q_ASSERT(m_script.connect());
}
diff --git a/tests/client/servicetest.cpp b/tests/client/servicetest.cpp
index d34ba79..a8b0c2a 100644
--- a/tests/client/servicetest.cpp
+++ b/tests/client/servicetest.cpp
@@ -17,10 +17,6 @@
* Renato Araujo Oliveira Filho <renato@canonical.com>
*/
-extern "C" {
-#include <glib-object.h>
-}
-
#include "qdbusmenumodel.h"
#include "dbusmenuscript.h"
@@ -46,7 +42,6 @@ private:
private Q_SLOTS:
void initTestCase()
{
- g_type_init();
Q_ASSERT(m_script.connect());
}