From 5d33dd54e1e0169b5df846957fb122e64997c8b1 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Mon, 19 Nov 2012 16:06:21 +0100 Subject: =?UTF-8?q?Reimplement=20roleNames()=20instead=20of=20using=20setR?= =?UTF-8?q?oleNames(=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Qt5, setRoleNames(…) is marked deprecated. --- libqmenumodel/src/qmenumodel.cpp | 23 ++++++++++++++--------- libqmenumodel/src/qmenumodel.h | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index f0c2274..c59522d 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -41,15 +41,6 @@ QMenuModel::QMenuModel(GMenuModel *other, QObject *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); } @@ -101,6 +92,20 @@ void QMenuModel::clearModel() } } +/*! \internal */ +QHash QMenuModel::roleNames() const +{ + static QHash roles; + if (roles.isEmpty()) { + roles[Action] = "action"; + roles[Label] = "label"; + roles[LinkSection] = "linkSection"; + roles[LinkSubMenu] = "linkSubMenu"; + roles[Extra] = "extra"; + } + return roles; +} + /*! \internal */ QVariant QMenuModel::data(const QModelIndex &index, int role) const { diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h index 22c30df..beec7ba 100644 --- a/libqmenumodel/src/qmenumodel.h +++ b/libqmenumodel/src/qmenumodel.h @@ -43,6 +43,7 @@ public: ~QMenuModel(); /* QAbstractItemModel */ + QHash roleNames() const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QModelIndex parent (const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; -- cgit v1.2.3 From af61347893098e0fe2e736606c07337adb6ae18f Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 21 Nov 2012 10:54:29 -0300 Subject: Fixed memory leak after the service disapear. --- libqmenumodel/src/qmenumodel.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index c59522d..b90cbf2 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -72,6 +72,11 @@ void QMenuModel::setMenuModel(GMenuModel *other) this); } + QList list = findChildren(); + Q_FOREACH(QMenuModel *model, list) { + delete model; + } + endResetModel(); } -- cgit v1.2.3 From f221fee6746e87e737de6f7a42334d9c8f8355a3 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 22 Nov 2012 08:05:13 -0300 Subject: Moved model children clear to clearModel function. --- libqmenumodel/src/qmenumodel.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index b90cbf2..1e8238b 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -72,11 +72,6 @@ void QMenuModel::setMenuModel(GMenuModel *other) this); } - QList list = findChildren(); - Q_FOREACH(QMenuModel *model, list) { - delete model; - } - endResetModel(); } @@ -95,6 +90,11 @@ void QMenuModel::clearModel() g_object_unref(m_menuModel); m_menuModel = NULL; } + + QList list = findChildren(); + Q_FOREACH(QMenuModel *model, list) { + delete model; + } } /*! \internal */ -- cgit v1.2.3 From a8dec7920dfd655b6afb0ab7adfec4d1bd565db9 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 22 Nov 2012 08:57:18 -0300 Subject: Avoid find children recursive during the model cleanup. --- libqmenumodel/src/qmenumodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index 1e8238b..8735e6c 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -91,7 +91,7 @@ void QMenuModel::clearModel() m_menuModel = NULL; } - QList list = findChildren(); + QList list = findChildren(QString(), Qt::FindDirectChildrenOnly); Q_FOREACH(QMenuModel *model, list) { delete model; } -- cgit v1.2.3 From a745160b7a3460f25fa52f9902e306e071949346 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 22 Nov 2012 16:13:02 -0300 Subject: Removed QAction dependecy from QStateAction. Exported activate function on QStateAction. --- libqmenumodel/src/CMakeLists.txt | 2 +- libqmenumodel/src/qdbusactiongroup.cpp | 4 ++-- libqmenumodel/src/qstateaction.cpp | 33 ++++++++++++++++++--------------- libqmenumodel/src/qstateaction.h | 14 +++++++++----- 4 files changed, 30 insertions(+), 23 deletions(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/CMakeLists.txt b/libqmenumodel/src/CMakeLists.txt index 8edb3e1..fe7d433 100644 --- a/libqmenumodel/src/CMakeLists.txt +++ b/libqmenumodel/src/CMakeLists.txt @@ -31,7 +31,7 @@ target_link_libraries(${SHAREDLIBNAME} ${GIO_LDFLAGS} ) -qt5_use_modules(${SHAREDLIBNAME} Core Widgets) +qt5_use_modules(${SHAREDLIBNAME} Core) install(TARGETS ${SHAREDLIBNAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/libqmenumodel/src/qdbusactiongroup.cpp b/libqmenumodel/src/qdbusactiongroup.cpp index 756bb76..824b5f0 100644 --- a/libqmenumodel/src/qdbusactiongroup.cpp +++ b/libqmenumodel/src/qdbusactiongroup.cpp @@ -104,7 +104,7 @@ bool QDBusActionGroup::hasAction(const QString &name) QStateAction *QDBusActionGroup::actionImpl(const QString &name) { Q_FOREACH(QStateAction *act, this->findChildren()) { - if (act->text() == name) { + if (act->name() == name) { return act; } } @@ -194,7 +194,7 @@ void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag) void QDBusActionGroup::clear() { Q_FOREACH(QStateAction *act, this->findChildren()) { - Q_EMIT actionVanish(act->text()); + Q_EMIT actionVanish(act->name()); } if (m_actionGroup != NULL) { diff --git a/libqmenumodel/src/qstateaction.cpp b/libqmenumodel/src/qstateaction.cpp index dd4e541..18c3c81 100644 --- a/libqmenumodel/src/qstateaction.cpp +++ b/libqmenumodel/src/qstateaction.cpp @@ -47,11 +47,10 @@ /*! \internal */ QStateAction::QStateAction(QDBusActionGroup *group, const QString &name) - : QAction(name, group), - m_group(group) + : QObject(group), + m_group(group), + m_name(name) { - 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)), @@ -89,9 +88,19 @@ bool QStateAction::isValid() const return m_valid; } -void QStateAction::updateState(const QVariant &state) +QString QStateAction::name() const +{ + return m_name; +} + +void QStateAction::updateState(const QVariant ¶meter) { - m_group->updateActionState(text(), state); + m_group->updateActionState(m_name, parameter); +} + +void QStateAction::activate(const QVariant ¶meter) +{ + m_group->activateAction(m_name, parameter); } /*! \internal */ @@ -112,16 +121,10 @@ void QStateAction::setState(const QVariant &state) } } -/*! \internal */ -void QStateAction::onTriggered() -{ - m_group->activateAction(text(), QVariant()); -} - /*! \internal */ void QStateAction::onActionAppear(const QString &name) { - if (text() == name) { + if (m_name == name) { setState(m_group->actionState(name)); setValid(true); } @@ -130,7 +133,7 @@ void QStateAction::onActionAppear(const QString &name) /*! \internal */ void QStateAction::onActionVanish(const QString &name) { - if (text() == name) { + if (m_name == name) { setState(QVariant()); setValid(false); } @@ -139,7 +142,7 @@ void QStateAction::onActionVanish(const QString &name) /*! \internal */ void QStateAction::onActionStateChanged(const QString &name, const QVariant &state) { - if (text() == name) { + if (m_name == name) { setState(state); } } diff --git a/libqmenumodel/src/qstateaction.h b/libqmenumodel/src/qstateaction.h index 85f207a..0fc68c2 100644 --- a/libqmenumodel/src/qstateaction.h +++ b/libqmenumodel/src/qstateaction.h @@ -20,21 +20,23 @@ #ifndef QDBUSACTION_H #define QDBUSACTION_H -#include +#include #include class QDBusActionGroup; -class QStateAction : public QAction +class QStateAction : public QObject { Q_OBJECT - Q_PROPERTY(QVariant state READ state WRITE setState NOTIFY stateChanged) + Q_PROPERTY(QString name READ name) + Q_PROPERTY(QVariant state READ state 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_INVOKABLE void activate(const QVariant ¶meter = QVariant()); + Q_INVOKABLE void updateState(const QVariant ¶meter); Q_SIGNALS: void stateChanged(QVariant state); @@ -44,16 +46,18 @@ 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; + QString m_name; QStateAction(QDBusActionGroup *group, const QString &name); + void setValid(bool valid); void setState(const QVariant &state); + QString name() const; friend class QDBusActionGroup; }; -- cgit v1.2.3 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. --- libqmenumodel/src/converter.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index 75733ce..5f5b4d2 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -51,8 +51,21 @@ QVariant Converter::toQVariant(GVariant *value) } result.setValue(qmap); + } else if (g_variant_type_is_tuple(type)) { + gsize size = g_variant_n_children(value); + QVariantList vlist; + + for(gsize i=0; i < size; i++) { + GVariant *v = g_variant_get_child_value(value, i); + if (v) { + vlist << toQVariant(v); + } + g_variant_unref(v); + } + + result.setValue(vlist); } else { - qWarning() << "Unsupported GVariant value"; + qWarning() << "Unsupported GVariant value" << (char*) type; } /* TODO: implement convertions to others types @@ -64,7 +77,6 @@ QVariant Converter::toQVariant(GVariant *value) * 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 @@ -72,7 +84,6 @@ QVariant Converter::toQVariant(GVariant *value) * G_VARIANT_TYPE_BYTESTRING * G_VARIANT_TYPE_OBJECT_PATH_ARRAY * G_VARIANT_TYPE_BYTESTRING_ARRAY - * G_VARIANT_TYPE_VARDICT */ return result; @@ -137,6 +148,17 @@ GVariant* Converter::toGVariant(const QVariant &value) g_variant_builder_unref(b); break; } + case QVariant::List: + { + QVariantList lst = value.toList(); + GVariant **vars = g_new(GVariant*, lst.size()); + for(int i=0; i < lst.size(); i++) { + vars[i] = toGVariant(lst[i]); + } + result = g_variant_new_tuple(vars, lst.size()); + g_free(vars); + break; + } default: result = ::toGVariant(value.typeName(), value); } -- cgit v1.2.3 From 193ddd3e44624a624cff1ecbe6c7a7e7a27decae Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 22 Nov 2012 17:48:25 -0300 Subject: Only unref variant if its is valid. --- libqmenumodel/src/converter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index 5f5b4d2..39379c7 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -59,8 +59,8 @@ QVariant Converter::toQVariant(GVariant *value) GVariant *v = g_variant_get_child_value(value, i); if (v) { vlist << toQVariant(v); + g_variant_unref(v); } - g_variant_unref(v); } result.setValue(vlist); -- cgit v1.2.3 From 41f6ce552a513644a90793a8bba15ef5761821cc Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 22 Nov 2012 17:58:56 -0300 Subject: Added docs on new functions. --- libqmenumodel/src/qstateaction.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/qstateaction.cpp b/libqmenumodel/src/qstateaction.cpp index 18c3c81..1861aea 100644 --- a/libqmenumodel/src/qstateaction.cpp +++ b/libqmenumodel/src/qstateaction.cpp @@ -88,21 +88,30 @@ bool QStateAction::isValid() const return m_valid; } -QString QStateAction::name() const -{ - return m_name; -} - +/*! + Request for the state of action to be changed to \a paramenter. + This call merely requests a change. The action may refuse to change its state or may change its state to something other than \a paramenter. +*/ void QStateAction::updateState(const QVariant ¶meter) { m_group->updateActionState(m_name, parameter); } +/*! + Activates the action passing \a parameter. + \a parameter must be the correct type of parameter for the action +*/ void QStateAction::activate(const QVariant ¶meter) { m_group->activateAction(m_name, parameter); } +/*! \internal */ +QString QStateAction::name() const +{ + return m_name; +} + /*! \internal */ void QStateAction::setValid(bool valid) { -- cgit v1.2.3 From 2b54bfb285ab5b2571808bfc9233da4847b27017 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 23 Nov 2012 08:50:51 -0300 Subject: Fixed code style. --- libqmenumodel/src/converter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index 39379c7..6c2411c 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -55,7 +55,7 @@ QVariant Converter::toQVariant(GVariant *value) gsize size = g_variant_n_children(value); QVariantList vlist; - for(gsize i=0; i < size; i++) { + for (gsize i=0; i < size; i++) { GVariant *v = g_variant_get_child_value(value, i); if (v) { vlist << toQVariant(v); @@ -152,7 +152,7 @@ GVariant* Converter::toGVariant(const QVariant &value) { QVariantList lst = value.toList(); GVariant **vars = g_new(GVariant*, lst.size()); - for(int i=0; i < lst.size(); i++) { + for (int i=0; i < lst.size(); i++) { vars[i] = toGVariant(lst[i]); } result = g_variant_new_tuple(vars, lst.size()); -- 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 +++ 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'libqmenumodel/src') 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 -- cgit v1.2.3 From af103ebfb8945c903accb42944516d234fe5744c Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 23 Nov 2012 14:25:39 -0300 Subject: Replaced 'reinterpret_cast' for gobject cast when possible. --- libqmenumodel/src/qdbusmenumodel.cpp | 6 +++--- libqmenumodel/src/qmenumodel.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/qdbusmenumodel.cpp b/libqmenumodel/src/qdbusmenumodel.cpp index 070381f..d3369dd 100644 --- a/libqmenumodel/src/qdbusmenumodel.cpp +++ b/libqmenumodel/src/qdbusmenumodel.cpp @@ -99,9 +99,9 @@ void QDBusMenuModel::serviceVanish(GDBusConnection *) /*! \internal */ void QDBusMenuModel::serviceAppear(GDBusConnection *connection) { - GMenuModel *model = reinterpret_cast(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(); diff --git a/libqmenumodel/src/qmenumodel.cpp b/libqmenumodel/src/qmenumodel.cpp index a45d647..3ae2e3e 100644 --- a/libqmenumodel/src/qmenumodel.cpp +++ b/libqmenumodel/src/qmenumodel.cpp @@ -68,7 +68,7 @@ void QMenuModel::setMenuModelImpl(GMenuModel *other) m_menuModel = other; if (m_menuModel) { - g_object_weak_ref(reinterpret_cast(m_menuModel), + g_object_weak_ref(G_OBJECT(m_menuModel), reinterpret_cast(QMenuModel::onGMenuModelDestroyed), this); // this will trigger the menu load @@ -92,7 +92,7 @@ GMenuModel *QMenuModel::menuModel() const void QMenuModel::clearModel() { if (m_menuModel) { - g_object_weak_unref(reinterpret_cast(m_menuModel), + g_object_weak_unref(G_OBJECT(m_menuModel), reinterpret_cast(QMenuModel::onGMenuModelDestroyed), this); g_signal_handler_disconnect(m_menuModel, m_signalChangedId); -- 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 - 3 files changed, 7 insertions(+), 25 deletions(-) (limited to 'libqmenumodel/src') 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 -- cgit v1.2.3 From bdc349d16b6e88c64e6ad16513f33d71bf1a643d Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 23 Nov 2012 14:56:22 -0300 Subject: Removed missing function declaration. --- libqmenumodel/src/qdbusmenumodel.cpp | 8 ++------ libqmenumodel/src/qmenumodel.h | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'libqmenumodel/src') diff --git a/libqmenumodel/src/qdbusmenumodel.cpp b/libqmenumodel/src/qdbusmenumodel.cpp index abf259f..b404d0b 100644 --- a/libqmenumodel/src/qdbusmenumodel.cpp +++ b/libqmenumodel/src/qdbusmenumodel.cpp @@ -99,12 +99,8 @@ void QDBusMenuModel::serviceAppear(GDBusConnection *connection) busName().toUtf8().data(), objectPath().toUtf8().data())); setMenuModel(model); - if (model == NULL) { - stop(); - } else { - //setModel take care of the ref - g_object_unref(model); - } + //setModel take care of the ref + g_object_unref(model); } /*! \internal */ diff --git a/libqmenumodel/src/qmenumodel.h b/libqmenumodel/src/qmenumodel.h index b3ef460..1ab1e7a 100644 --- a/libqmenumodel/src/qmenumodel.h +++ b/libqmenumodel/src/qmenumodel.h @@ -63,7 +63,6 @@ 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); }; -- cgit v1.2.3