~ubuntu-branches/ubuntu/utopic/qmenumodel/utopic-proposed

« back to all changes in this revision

Viewing changes to libqmenumodel/src/unitymenumodel.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Charles Kerr, Nick Dedekind
  • Date: 2014-07-04 07:38:11 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20140704073811-vhvywosl4t7464pr
Tags: 0.2.7+14.10.20140704-0ubuntu1
[ Charles Kerr ]
* Fix a dangling UnityMenuAction pointer by ensuring it's registered
  with only one menu at a time. (LP: #1282282)

[ Nick Dedekind ]
* Unset the UnityMenuActions::model when destroying UnityMenuModel
  (LP: #1334203)

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    QHash<QByteArray, int> roles;
80
80
    ActionStateParser* actionStateParser;
81
81
    QHash<UnityMenuAction*, GtkSimpleActionObserver*> registeredActions;
 
82
    bool destructorGuard;
82
83
 
83
84
    static void nameAppeared(GDBusConnection *connection, const gchar *name, const gchar *owner, gpointer user_data);
84
85
    static void nameVanished(GDBusConnection *connection, const gchar *name, gpointer user_data);
113
114
    this->connection = NULL;
114
115
    this->nameWatchId = 0;
115
116
    this->actionStateParser = new ActionStateParser(model);
 
117
    this->destructorGuard = false;
116
118
 
117
119
    this->muxer = gtk_action_muxer_new ();
118
120
 
126
128
    this->connection = NULL;
127
129
    this->nameWatchId = 0;
128
130
    this->actionStateParser = new ActionStateParser(model);
 
131
    this->destructorGuard = false;
129
132
 
130
133
    this->muxer = GTK_ACTION_MUXER( g_object_ref(other.muxer));
131
134
 
134
137
 
135
138
UnityMenuModelPrivate::~UnityMenuModelPrivate()
136
139
{
 
140
    this->destructorGuard = true;
137
141
    this->clearItems(false);
138
142
 
139
143
    g_sequence_free(this->items);
144
148
    QHash<UnityMenuAction*, GtkSimpleActionObserver*>::const_iterator it = this->registeredActions.constBegin();
145
149
    for (; it != this->registeredActions.constEnd(); ++it) {
146
150
        g_object_unref(it.value());
 
151
        it.key()->setModel(NULL);
147
152
    }
148
153
    this->registeredActions.clear();
149
154
 
787
792
 
788
793
void UnityMenuModel::registerAction(UnityMenuAction* action)
789
794
{
 
795
    if (priv->destructorGuard)
 
796
        return;
 
797
 
790
798
    if (!priv->registeredActions.contains(action)) {
791
799
        GtkSimpleActionObserver* observer_item;
792
800
        observer_item = gtk_simple_action_observer_new(GTK_ACTION_OBSERVABLE (priv->muxer),
808
816
 
809
817
void UnityMenuModel::unregisterAction(UnityMenuAction* action)
810
818
{
 
819
    if (priv->destructorGuard)
 
820
        return;
 
821
 
811
822
    if (priv->registeredActions.contains(action)) {
812
823
        GtkSimpleActionObserver* observer_item;
813
824
        observer_item = priv->registeredActions[action];