aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src/qmenumodel.cpp
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-11-23 12:03:07 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-11-23 12:03:07 -0300
commit6078bd7ddc6819d2650435313bb824442bbe033d (patch)
tree510e14d5585b7fa2777a1a51b9616be07e25de30 /libqmenumodel/src/qmenumodel.cpp
parent04391e9723278f8bb0a0985abd50aa9c3455980d (diff)
downloadqmenumodel-6078bd7ddc6819d2650435313bb824442bbe033d.tar.gz
qmenumodel-6078bd7ddc6819d2650435313bb824442bbe033d.tar.bz2
qmenumodel-6078bd7ddc6819d2650435313bb824442bbe033d.zip
Fixed QMenumodel behaviour when the GMenuModel is destroyed.
Diffstat (limited to 'libqmenumodel/src/qmenumodel.cpp')
-rw-r--r--libqmenumodel/src/qmenumodel.cpp19
1 files changed, 18 insertions, 1 deletions
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<GObject*>(m_menuModel),
+ reinterpret_cast<GWeakNotify>(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<GObject*>(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;
}
@@ -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<QMenuModel*>(data);
+ self->m_menuModel = NULL;
+ self->setMenuModelImpl(NULL);
+}
/*! \internal */
void QMenuModel::onItemsChanged(GMenuModel *,