diff options
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]; |