diff options
-rw-r--r-- | libqmenumodel/src/unitymenumodel.cpp | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp index 71358c4..cceed9e 100644 --- a/libqmenumodel/src/unitymenumodel.cpp +++ b/libqmenumodel/src/unitymenumodel.cpp @@ -395,9 +395,18 @@ static QString iconUri(GIcon *icon) QVariant UnityMenuModel::data(const QModelIndex &index, int role) const { + GSequenceIter *it; GtkMenuTrackerItem *item; - item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index.row())); + it = g_sequence_get_iter_at_pos (priv->items, index.row()); + if (!it || g_sequence_iter_is_end (it)) { + return QVariant(); + } + + item = (GtkMenuTrackerItem *) g_sequence_get (it); + if (!item) { + return QVariant(); + } switch (role) { case LabelRole: @@ -497,12 +506,14 @@ QObject * UnityMenuModel::submenu(int position, QQmlComponent* actionStateParser UnityMenuModel *model; it = g_sequence_get_iter_at_pos (priv->items, position); - if (g_sequence_iter_is_end (it)) + if (!it || g_sequence_iter_is_end (it)) { return NULL; + } item = (GtkMenuTrackerItem *) g_sequence_get (it); - if (!gtk_menu_tracker_item_get_has_submenu (item)) + if (!item || !gtk_menu_tracker_item_get_has_submenu (item)) { return NULL; + } model = (UnityMenuModel *) g_object_get_qdata (G_OBJECT (item), unity_submenu_model_quark ()); if (model == NULL) { @@ -603,10 +614,19 @@ static QString qtify_name(const char *name) bool UnityMenuModel::loadExtendedAttributes(int position, const QVariantMap &schema) { + GSequenceIter *it; GtkMenuTrackerItem *item; QVariantMap *extendedAttrs; - item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, position)); + it = g_sequence_get_iter_at_pos (priv->items, position); + if (!it || g_sequence_iter_is_end (it)) { + return false; + } + + item = (GtkMenuTrackerItem *) g_sequence_get (it); + if (!item) { + return false; + } extendedAttrs = new QVariantMap; @@ -647,9 +667,18 @@ QVariant UnityMenuModel::get(int row, const QByteArray &role) void UnityMenuModel::activate(int index, const QVariant& parameter) { + GSequenceIter *it; GtkMenuTrackerItem *item; - item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index)); + it = g_sequence_get_iter_at_pos (priv->items, index); + if (!it || g_sequence_iter_is_end (it)) { + return; + } + + item = (GtkMenuTrackerItem *) g_sequence_get (it); + if (!item) { + return; + } if (parameter.isValid()) { gchar *action; @@ -665,12 +694,20 @@ void UnityMenuModel::activate(int index, const QVariant& parameter) void UnityMenuModel::changeState(int index, const QVariant& parameter) { + GSequenceIter *it; GtkMenuTrackerItem* item; GVariant* data; GVariant* current_state; - item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index)); - if (!item) return; + it = g_sequence_get_iter_at_pos (priv->items, index); + if (!it || g_sequence_iter_is_end (it)) { + return; + } + + item = (GtkMenuTrackerItem *) g_sequence_get (it); + if (!item) { + return; + } current_state = gtk_menu_tracker_item_get_action_state (item); if (current_state) { @@ -794,11 +831,15 @@ char * UnityMenuModelPrivate::fullActionName(UnityMenuAction *action) name = bytes.constData(); iter = g_sequence_get_iter_at_pos (this->items, action->index()); - if (!g_sequence_iter_is_end (iter)) { + if (iter && !g_sequence_iter_is_end (iter)) { GtkMenuTrackerItem *item; const gchar *action_namespace; item = (GtkMenuTrackerItem *) g_sequence_get (iter); + if (!item) { + return g_strdup (name); + } + action_namespace = gtk_menu_tracker_item_get_action_namespace (item); if (action_namespace != NULL) return g_strjoin (".", action_namespace, name, NULL); |