diff options
author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2014-06-30 18:42:42 +0100 |
---|---|---|
committer | Nick Dedekind <nicholas.dedekind@gmail.com> | 2014-06-30 18:42:42 +0100 |
commit | 6d8d26d0dc8b7c48dc494b25c4c8ee721125378b (patch) | |
tree | 1dcec2694b80554bd88a36ba99c635800c7e7f25 /libqmenumodel | |
parent | c7955b4f04e5a9a2530ad340b1801a81e37ea72c (diff) | |
download | qmenumodel-6d8d26d0dc8b7c48dc494b25c4c8ee721125378b.tar.gz qmenumodel-6d8d26d0dc8b7c48dc494b25c4c8ee721125378b.tar.bz2 qmenumodel-6d8d26d0dc8b7c48dc494b25c4c8ee721125378b.zip |
unset actions model in destructor
Diffstat (limited to 'libqmenumodel')
-rw-r--r-- | libqmenumodel/src/unitymenuaction.cpp | 10 | ||||
-rw-r--r-- | libqmenumodel/src/unitymenumodel.cpp | 11 |
2 files changed, 14 insertions, 7 deletions
diff --git a/libqmenumodel/src/unitymenuaction.cpp b/libqmenumodel/src/unitymenuaction.cpp index 46edf16..5de3cf8 100644 --- a/libqmenumodel/src/unitymenuaction.cpp +++ b/libqmenumodel/src/unitymenuaction.cpp @@ -33,9 +33,7 @@ UnityMenuAction::UnityMenuAction(QObject* parent) UnityMenuAction::~UnityMenuAction() { - if (m_model) { - m_model->unregisterAction(this); - } + unregisterAction(); } QString UnityMenuAction::name() const @@ -59,9 +57,7 @@ UnityMenuModel* UnityMenuAction::model() const void UnityMenuAction::setModel(UnityMenuModel* model) { if (m_model != model) { - if (!model) { - unregisterAction(); - } + unregisterAction(); m_model = model; registerAction(); Q_EMIT modelChanged(model); @@ -107,7 +103,7 @@ void UnityMenuAction::setValid(bool valid) } } -int UnityMenuAction::index() const +int UnityMenuAction::index() const { return m_index; } diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp index 8db990b..a6ae140 100644 --- a/libqmenumodel/src/unitymenumodel.cpp +++ b/libqmenumodel/src/unitymenumodel.cpp @@ -79,6 +79,7 @@ public: QHash<QByteArray, int> roles; ActionStateParser* actionStateParser; QHash<UnityMenuAction*, GtkSimpleActionObserver*> registeredActions; + bool destructorGuard; static void nameAppeared(GDBusConnection *connection, const gchar *name, const gchar *owner, gpointer user_data); static void nameVanished(GDBusConnection *connection, const gchar *name, gpointer user_data); @@ -113,6 +114,7 @@ UnityMenuModelPrivate::UnityMenuModelPrivate(UnityMenuModel *model) this->connection = NULL; this->nameWatchId = 0; this->actionStateParser = new ActionStateParser(model); + this->destructorGuard = false; this->muxer = gtk_action_muxer_new (); @@ -126,6 +128,7 @@ UnityMenuModelPrivate::UnityMenuModelPrivate(const UnityMenuModelPrivate& other, this->connection = NULL; this->nameWatchId = 0; this->actionStateParser = new ActionStateParser(model); + this->destructorGuard = false; this->muxer = GTK_ACTION_MUXER( g_object_ref(other.muxer)); @@ -134,6 +137,7 @@ UnityMenuModelPrivate::UnityMenuModelPrivate(const UnityMenuModelPrivate& other, UnityMenuModelPrivate::~UnityMenuModelPrivate() { + this->destructorGuard = true; this->clearItems(false); g_sequence_free(this->items); @@ -144,6 +148,7 @@ UnityMenuModelPrivate::~UnityMenuModelPrivate() QHash<UnityMenuAction*, GtkSimpleActionObserver*>::const_iterator it = this->registeredActions.constBegin(); for (; it != this->registeredActions.constEnd(); ++it) { g_object_unref(it.value()); + it.key()->setModel(NULL); } this->registeredActions.clear(); @@ -787,6 +792,9 @@ bool UnityMenuModel::event(QEvent* e) void UnityMenuModel::registerAction(UnityMenuAction* action) { + if (priv->destructorGuard) + return; + if (!priv->registeredActions.contains(action)) { GtkSimpleActionObserver* observer_item; observer_item = gtk_simple_action_observer_new(GTK_ACTION_OBSERVABLE (priv->muxer), @@ -808,6 +816,9 @@ void UnityMenuModel::registerAction(UnityMenuAction* action) void UnityMenuModel::unregisterAction(UnityMenuAction* action) { + if (priv->destructorGuard) + return; + if (priv->registeredActions.contains(action)) { GtkSimpleActionObserver* observer_item; observer_item = priv->registeredActions[action]; |