aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libqmenumodel/src/qdbusmenumodel.cpp11
-rw-r--r--libqmenumodel/src/qmenumodel.cpp3
-rw-r--r--libqmenumodel/src/qmenumodel.h1
-rw-r--r--tests/client/modeltest.cpp14
-rw-r--r--tests/script/menuscript.py3
5 files changed, 24 insertions, 8 deletions
diff --git a/libqmenumodel/src/qdbusmenumodel.cpp b/libqmenumodel/src/qdbusmenumodel.cpp
index 97990b4..b404d0b 100644
--- a/libqmenumodel/src/qdbusmenumodel.cpp
+++ b/libqmenumodel/src/qdbusmenumodel.cpp
@@ -95,13 +95,12 @@ void QDBusMenuModel::serviceVanish(GDBusConnection *)
/*! \internal */
void QDBusMenuModel::serviceAppear(GDBusConnection *connection)
{
- GMenuModel *model = reinterpret_cast<GMenuModel*>(g_dbus_menu_model_get(connection,
- busName().toUtf8().data(),
- objectPath().toUtf8().data()));
+ GMenuModel *model = G_MENU_MODEL(g_dbus_menu_model_get(connection,
+ busName().toUtf8().data(),
+ objectPath().toUtf8().data()));
setMenuModel(model);
- if (model == NULL) {
- stop();
- }
+ //setModel take care of the ref
+ g_object_unref(model);
}
/*! \internal */
diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp
index 8735e6c..ec5570f 100644
--- a/libqmenumodel/src/qmenumodel.cpp
+++ b/libqmenumodel/src/qmenumodel.cpp
@@ -64,6 +64,7 @@ void QMenuModel::setMenuModel(GMenuModel *other)
m_menuModel = other;
if (m_menuModel) {
+ g_object_ref(m_menuModel);
// this will trigger the menu load
(void) g_menu_model_get_n_items(m_menuModel);
m_signalChangedId = g_signal_connect(m_menuModel,
@@ -185,7 +186,7 @@ QVariant QMenuModel::getLink(const QModelIndex &index,
index.row(),
linkName.toUtf8().data());
- if (link) {
+ if (link) {
QMenuModel *other = new QMenuModel(link, const_cast<QMenuModel*>(this));
return QVariant::fromValue<QObject*>(other);
}
diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h
index beec7ba..1ab1e7a 100644
--- a/libqmenumodel/src/qmenumodel.h
+++ b/libqmenumodel/src/qmenumodel.h
@@ -26,6 +26,7 @@ typedef int gint;
typedef unsigned int guint;
typedef void* gpointer;
typedef struct _GMenuModel GMenuModel;
+typedef struct _GObject GObject;
class QMenuModel : public QAbstractListModel
{
diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp
index 1b0ea95..8be92a6 100644
--- a/tests/client/modeltest.cpp
+++ b/tests/client/modeltest.cpp
@@ -25,6 +25,19 @@
#include <QtTest>
#include <QDebug>
+extern "C" {
+#include <gio/gio.h>
+}
+
+class TestMenuModel : public QMenuModel
+{
+public:
+ TestMenuModel(GMenuModel *other, QObject *parent=0)
+ : QMenuModel(other, parent)
+ {
+ }
+};
+
class ModelTest : public QObject
{
Q_OBJECT
@@ -247,7 +260,6 @@ private Q_SLOTS:
delete model;
}
-
};
QTEST_MAIN(ModelTest)
diff --git a/tests/script/menuscript.py b/tests/script/menuscript.py
index d30adc5..542308a 100644
--- a/tests/script/menuscript.py
+++ b/tests/script/menuscript.py
@@ -207,6 +207,9 @@ class ActionList(object):
if self._ownNameID:
Gio.bus_unown_name(self._ownNameID)
self._ownNameID = None
+
+ self._root = None
+ self._rootAction = None
self._restore()
def _onActionActivated(self, action, parameter):