aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel
diff options
context:
space:
mode:
Diffstat (limited to 'libqmenumodel')
-rw-r--r--libqmenumodel/src/qdbusmenumodel.cpp9
-rw-r--r--libqmenumodel/src/qmenumodel.cpp22
-rw-r--r--libqmenumodel/src/qmenumodel.h1
3 files changed, 7 insertions, 25 deletions
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<GWeakNotify>(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<GWeakNotify>(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<QMenuModel*>(this));
return QVariant::fromValue<QObject*>(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<QMenuModel*>(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