aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Dedekind <nicholas.dedekind@gmail.com>2014-07-04 07:38:02 +0000
committerCI bot <ps-jenkins@lists.canonical.com>2014-07-04 07:38:02 +0000
commit2ec6160a767750525f567ed3c1cc49c6bbe84e05 (patch)
tree33ce61334463ae2fdae55e4325cdde93f3ef526a
parentd83588e3e3ba9a3410e4e122f6a06f61d68c7a09 (diff)
parent4f4fde02f90abeb1d20a842b2a7578a84fe75f51 (diff)
downloadqmenumodel-2ec6160a767750525f567ed3c1cc49c6bbe84e05.tar.gz
qmenumodel-2ec6160a767750525f567ed3c1cc49c6bbe84e05.tar.bz2
qmenumodel-2ec6160a767750525f567ed3c1cc49c6bbe84e05.zip
Unset the UnityMenuActions::model when destroying UnityMenuModel Fixes: 1334203
-rw-r--r--libqmenumodel/src/unitymenuaction.cpp6
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp11
-rw-r--r--tests/client/CMakeLists.txt1
-rw-r--r--tests/client/unitymenuactiontest.cpp62
4 files changed, 76 insertions, 4 deletions
diff --git a/libqmenumodel/src/unitymenuaction.cpp b/libqmenumodel/src/unitymenuaction.cpp
index 6f564d1..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
@@ -105,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];
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt
index cb16fc0..ed2f1aa 100644
--- a/tests/client/CMakeLists.txt
+++ b/tests/client/CMakeLists.txt
@@ -60,6 +60,7 @@ declare_test(qmltest)
declare_test(convertertest)
declare_test(modelsignalstest)
declare_test(treetest)
+declare_test(unitymenuactiontest)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qmlfiles.h.in
${CMAKE_CURRENT_BINARY_DIR}/qmlfiles.h)
diff --git a/tests/client/unitymenuactiontest.cpp b/tests/client/unitymenuactiontest.cpp
new file mode 100644
index 0000000..d33ab2e
--- /dev/null
+++ b/tests/client/unitymenuactiontest.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2014 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Nick Dedekind <nick.dedekind@canonical.com>
+ */
+
+#include "unitymenumodel.h"
+#include "unitymenuaction.h"
+
+#include <QObject>
+#include <QtTest>
+
+class UnityMenuActionTest : public QObject
+{
+ Q_OBJECT
+private:
+
+private Q_SLOTS:
+
+ /*
+ * Test if the propety busType handle correct integer values
+ */
+ void testDestroyAfterModel()
+ {
+ UnityMenuModel* model = new UnityMenuModel;
+ UnityMenuAction* action = new UnityMenuAction;
+ action->setModel(model);
+
+ delete model;
+ delete action;
+ }
+
+ /*
+ * Test if the propety busType handle correct integer values
+ */
+ void testDestroyBeforeModel()
+ {
+ UnityMenuModel* model = new UnityMenuModel;
+ UnityMenuAction* action = new UnityMenuAction;
+ action->setModel(model);
+
+ delete action;
+ delete model;
+ }
+};
+
+QTEST_MAIN(UnityMenuActionTest)
+
+#include "unitymenuactiontest.moc"