From c37748989142ae4f9ee1e1cab4cbcff605302970 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 22 Nov 2012 17:39:25 -0300 Subject: Implemented support to tuple conversions. --- tests/client/modeltest.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/client/modeltest.cpp') diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index c6b2f0e..1b0ea95 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -218,6 +218,12 @@ private Q_SLOTS: QCOMPARE(v.type(), QVariant::String); QCOMPARE(v.toString(), QString("dança")); + // Tuple + v = extra["tuple"]; + QVariantList lst; + lst << "1" << 2 << 3.3; + QCOMPARE(v.type(), QVariant::List); + QCOMPARE(v.toList(), lst); } /* -- cgit v1.2.3 From 6078bd7ddc6819d2650435313bb824442bbe033d Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 23 Nov 2012 12:03:07 -0300 Subject: Fixed QMenumodel behaviour when the GMenuModel is destroyed. --- libqmenumodel/src/qdbusmenumodel.cpp | 6 +++++- libqmenumodel/src/qmenumodel.cpp | 19 ++++++++++++++++++- libqmenumodel/src/qmenumodel.h | 3 +++ tests/client/modeltest.cpp | 27 +++++++++++++++++++++++++++ tests/script/menuscript.py | 3 +++ 5 files changed, 56 insertions(+), 2 deletions(-) (limited to 'tests/client/modeltest.cpp') diff --git a/libqmenumodel/src/qdbusmenumodel.cpp b/libqmenumodel/src/qdbusmenumodel.cpp index 97990b4..070381f 100644 --- a/libqmenumodel/src/qdbusmenumodel.cpp +++ b/libqmenumodel/src/qdbusmenumodel.cpp @@ -89,7 +89,11 @@ void QDBusMenuModel::stop() /*! \internal */ void QDBusMenuModel::serviceVanish(GDBusConnection *) { - setMenuModel(NULL); + GMenuModel *model = menuModel(); + if (model != NULL) { + setMenuModel(NULL); + g_object_unref(model); + } } /*! \internal */ diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index 8735e6c..a45d647 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -56,7 +56,11 @@ void QMenuModel::setMenuModel(GMenuModel *other) if (m_menuModel == other) { return; } + setMenuModelImpl(other); +} +void QMenuModel::setMenuModelImpl(GMenuModel *other) +{ beginResetModel(); clearModel(); @@ -64,6 +68,9 @@ void QMenuModel::setMenuModel(GMenuModel *other) m_menuModel = other; if (m_menuModel) { + g_object_weak_ref(reinterpret_cast(m_menuModel), + reinterpret_cast(QMenuModel::onGMenuModelDestroyed), + this); // this will trigger the menu load (void) g_menu_model_get_n_items(m_menuModel); m_signalChangedId = g_signal_connect(m_menuModel, @@ -85,9 +92,11 @@ GMenuModel *QMenuModel::menuModel() const void QMenuModel::clearModel() { if (m_menuModel) { + g_object_weak_unref(reinterpret_cast(m_menuModel), + reinterpret_cast(QMenuModel::onGMenuModelDestroyed), + this); g_signal_handler_disconnect(m_menuModel, m_signalChangedId); m_signalChangedId = 0; - g_object_unref(m_menuModel); m_menuModel = NULL; } @@ -223,6 +232,14 @@ QVariant QMenuModel::getExtraProperties(const QModelIndex &index) const return extra; } +/*! \internal */ +void QMenuModel::onGMenuModelDestroyed(gpointer data, + GObject *oldObject) +{ + QMenuModel *self = reinterpret_cast(data); + self->m_menuModel = NULL; + self->setMenuModelImpl(NULL); +} /*! \internal */ void QMenuModel::onItemsChanged(GMenuModel *, diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h index beec7ba..f3b431c 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 { @@ -62,8 +63,10 @@ private: QVariant getExtraProperties(const QModelIndex &index) const; QString parseExtraPropertyName(const QString &name) const; void clearModel(); + void setMenuModelImpl(GMenuModel *model); static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data); + static void onGMenuModelDestroyed(gpointer data, GObject *oldObject); }; #endif diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index c6b2f0e..0aa4b52 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -25,6 +25,19 @@ #include #include +extern "C" { +#include +} + +class TestMenuModel : public QMenuModel +{ +public: + TestMenuModel(GMenuModel *other, QObject *parent=0) + : QMenuModel(other, parent) + { + } +}; + class ModelTest : public QObject { Q_OBJECT @@ -242,6 +255,20 @@ private Q_SLOTS: delete model; } + /* + * Test if the model is clearead after GMenuModel be destroyed + */ + void testDestroyGMenuModel() + { + GMenu *menu = g_menu_new(); + g_menu_append(menu, "test-menu0", NULL); + g_menu_append(menu, "test-menu1", NULL); + TestMenuModel model(reinterpret_cast(menu)); + QCOMPARE(model.rowCount(), 2); + + g_object_unref(menu); + QCOMPARE(model.rowCount(), 0); + } }; QTEST_MAIN(ModelTest) diff --git a/tests/script/menuscript.py b/tests/script/menuscript.py index 60cb33b..d25bb30 100644 --- a/tests/script/menuscript.py +++ b/tests/script/menuscript.py @@ -205,6 +205,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): -- cgit v1.2.3 From aa56c7b79317fb88c12fc0573fc23b6939337fe4 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 23 Nov 2012 14:41:21 -0300 Subject: Take care of object ref internally on QMenumodel, instead of QDBusMenuModel. --- libqmenumodel/src/qdbusmenumodel.cpp | 9 ++++----- libqmenumodel/src/qmenumodel.cpp | 22 +++------------------- libqmenumodel/src/qmenumodel.h | 1 - tests/client/modeltest.cpp | 15 --------------- 4 files changed, 7 insertions(+), 40 deletions(-) (limited to 'tests/client/modeltest.cpp') diff --git a/libqmenumodel/src/qdbusmenumodel.cpp b/libqmenumodel/src/qdbusmenumodel.cpp index d3369dd..abf259f 100644 --- a/libqmenumodel/src/qdbusmenumodel.cpp +++ b/libqmenumodel/src/qdbusmenumodel.cpp @@ -89,11 +89,7 @@ void QDBusMenuModel::stop() /*! \internal */ void QDBusMenuModel::serviceVanish(GDBusConnection *) { - GMenuModel *model = menuModel(); - if (model != NULL) { - setMenuModel(NULL); - g_object_unref(model); - } + setMenuModel(NULL); } /*! \internal */ @@ -105,6 +101,9 @@ void QDBusMenuModel::serviceAppear(GDBusConnection *connection) setMenuModel(model); if (model == NULL) { stop(); + } else { + //setModel take care of the ref + g_object_unref(model); } } diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index 3ae2e3e..ec5570f 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -56,11 +56,7 @@ void QMenuModel::setMenuModel(GMenuModel *other) if (m_menuModel == other) { return; } - setMenuModelImpl(other); -} -void QMenuModel::setMenuModelImpl(GMenuModel *other) -{ beginResetModel(); clearModel(); @@ -68,9 +64,7 @@ void QMenuModel::setMenuModelImpl(GMenuModel *other) m_menuModel = other; if (m_menuModel) { - g_object_weak_ref(G_OBJECT(m_menuModel), - reinterpret_cast(QMenuModel::onGMenuModelDestroyed), - this); + 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, @@ -92,11 +86,9 @@ GMenuModel *QMenuModel::menuModel() const void QMenuModel::clearModel() { if (m_menuModel) { - g_object_weak_unref(G_OBJECT(m_menuModel), - reinterpret_cast(QMenuModel::onGMenuModelDestroyed), - this); g_signal_handler_disconnect(m_menuModel, m_signalChangedId); m_signalChangedId = 0; + g_object_unref(m_menuModel); m_menuModel = NULL; } @@ -194,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(this)); return QVariant::fromValue(other); } @@ -232,14 +224,6 @@ QVariant QMenuModel::getExtraProperties(const QModelIndex &index) const return extra; } -/*! \internal */ -void QMenuModel::onGMenuModelDestroyed(gpointer data, - GObject *oldObject) -{ - QMenuModel *self = reinterpret_cast(data); - self->m_menuModel = NULL; - self->setMenuModelImpl(NULL); -} /*! \internal */ void QMenuModel::onItemsChanged(GMenuModel *, diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h index f3b431c..b3ef460 100644 --- a/libqmenumodel/src/qmenumodel.h +++ b/libqmenumodel/src/qmenumodel.h @@ -66,7 +66,6 @@ private: void setMenuModelImpl(GMenuModel *model); static void onItemsChanged(GMenuModel *model, gint position, gint removed, gint added, gpointer data); - static void onGMenuModelDestroyed(gpointer data, GObject *oldObject); }; #endif diff --git a/tests/client/modeltest.cpp b/tests/client/modeltest.cpp index bc5d95e..8be92a6 100644 --- a/tests/client/modeltest.cpp +++ b/tests/client/modeltest.cpp @@ -260,21 +260,6 @@ private Q_SLOTS: delete model; } - - /* - * Test if the model is clearead after GMenuModel be destroyed - */ - void testDestroyGMenuModel() - { - GMenu *menu = g_menu_new(); - g_menu_append(menu, "test-menu0", NULL); - g_menu_append(menu, "test-menu1", NULL); - TestMenuModel model(reinterpret_cast(menu)); - QCOMPARE(model.rowCount(), 2); - - g_object_unref(menu); - QCOMPARE(model.rowCount(), 0); - } }; QTEST_MAIN(ModelTest) -- cgit v1.2.3