aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libqmenumodel/src/unitymenuaction.cpp10
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp11
-rw-r--r--tests/client/CMakeLists.txt1
3 files changed, 15 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];
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)