2 * Copyright © 2011 Canonical Ltd.
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * licence, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 * Author: Ryan Lortie <desrt@desrt.ca>
22 #include "gmenumodel.h"
27 * @short_description: An abstract class representing the contents of a menu
29 * @see_also: #GActionGroup
31 * #GMenuModel represents the contents of a menu -- an ordered list of
32 * menu items. The items are associated with actions, which can be
33 * activated through them. Items can be grouped in sections, and may
34 * have submenus associated with them. Both items and sections usually
35 * have some representation data, such as labels or icons. The type of
36 * the associated action (ie whether it is stateful, and what kind of
37 * state it has) can influence the representation of the item.
39 * The conceptual model of menus in #GMenuModel is hierarchical:
40 * sections and submenus are again represented by #GMenuModels.
41 * Menus themselves do not define their own roles. Rather, the role
42 * of a particular #GMenuModel is defined by the item that references
43 * it (or, in the case of the 'root' menu, is defined by the context
44 * in which it is used).
46 * As an example, consider the visible portions of the menu in
47 * <xref linkend="menu-example"/>.
49 * ## An example menu # {#menu-example}
51 * ![](menu-example.png)
53 * There are 8 "menus" visible in the screenshot: one menubar, two
54 * submenus and 5 sections:
56 * - the toplevel menubar (containing 4 items)
57 * - the View submenu (containing 3 sections)
58 * - the first section of the View submenu (containing 2 items)
59 * - the second section of the View submenu (containing 1 item)
60 * - the final section of the View submenu (containing 1 item)
61 * - the Highlight Mode submenu (containing 2 sections)
62 * - the Sources section (containing 2 items)
63 * - the Markup section (containing 2 items)
65 * <xref linkend="menu-model"/> illustrates the conceptual connection between
66 * these 8 menus. Each large block in the figure represents a menu and the
67 * smaller blocks within the large block represent items in that menu. Some
68 * items contain references to other menus.
70 * ## A menu example # {#menu-model}
74 * Notice that the separators visible in <xref linkend="menu-example"/>
75 * appear nowhere in <xref linkend="menu-model"/>. This is because
76 * separators are not explicitly represented in the menu model. Instead,
77 * a separator is inserted between any two non-empty sections of a menu.
78 * Section items can have labels just like any other item. In that case,
79 * a display system may show a section header instead of a separator.
81 * The motivation for this abstract model of application controls is
82 * that modern user interfaces tend to make these controls available
83 * outside the application. Examples include global menus, jumplists,
84 * dash boards, etc. To support such uses, it is necessary to 'export'
85 * information about actions and their representation in menus, which
87 * <link linkend="gio-GActionGroup-exporter">GActionGroup exporter</link>
89 * <link linkend="gio-GMenuModel-exporter">GMenuModel exporter</link>
90 * do for #GActionGroup and #GMenuModel. The client-side counterparts
91 * to make use of the exported information are #GDBusActionGroup and
94 * The API of #GMenuModel is very generic, with iterators for the
95 * attributes and links of an item, see g_menu_model_iterate_item_attributes()
96 * and g_menu_model_iterate_item_links(). The 'standard' attributes and
97 * link types have predefined names: %G_MENU_ATTRIBUTE_LABEL,
98 * %G_MENU_ATTRIBUTE_ACTION, %G_MENU_ATTRIBUTE_TARGET, %G_MENU_LINK_SECTION
99 * and %G_MENU_LINK_SUBMENU.
101 * Items in a #GMenuModel represent active controls if they refer to
102 * an action that can get activated when the user interacts with the
103 * menu item. The reference to the action is encoded by the string id
104 * in the %G_MENU_ATTRIBUTE_ACTION attribute. An action id uniquely
105 * identifies an action in an action group. Which action group(s) provide
106 * actions depends on the context in which the menu model is used.
107 * E.g. when the model is exported as the application menu of a
108 * #GtkApplication, actions can be application-wide or window-specific
109 * (and thus come from two different action groups). By convention, the
110 * application-wide actions have names that start with "app.", while the
111 * names of window-specific actions start with "win.".
113 * While a wide variety of stateful actions is possible, the following
114 * is the minimum that is expected to be supported by all users of exported
116 * - an action with no parameter type and no state
117 * - an action with no parameter type and boolean state
118 * - an action with string parameter type and string state
122 * A stateless action typically corresponds to an ordinary menu item.
124 * Selecting such a menu item will activate the action (with no parameter).
128 * An action with a boolean state will most typically be used with a "toggle"
129 * or "switch" menu item. The state can be set directly, but activating the
130 * action (with no parameter) results in the state being toggled.
132 * Selecting a toggle menu item will activate the action. The menu item should
133 * be rendered as "checked" when the state is true.
135 * ## String Parameter and State
137 * Actions with string parameters and state will most typically be used to
138 * represent an enumerated choice over the items available for a group of
139 * radio menu items. Activating the action with a string parameter is
140 * equivalent to setting that parameter as the state.
142 * Radio menu items, in addition to being associated with the action, will
143 * have a target value. Selecting that menu item will result in activation
144 * of the action with the target value as the parameter. The menu item should
145 * be rendered as "selected" when the state of the action is equal to the
146 * target value of the menu item.
152 * #GMenuModel is an opaque structure type. You must access it using the
159 * GMenuAttributeIter:
161 * #GMenuAttributeIter is an opaque structure type. You must access it
162 * using the functions below.
170 * #GMenuLinkIter is an opaque structure type. You must access it using
171 * the functions below.
178 GMenuLinkIter parent_instance;
183 typedef GMenuLinkIterClass GMenuLinkHashIterClass;
185 static GType g_menu_link_hash_iter_get_type (void);
187 G_DEFINE_TYPE (GMenuLinkHashIter, g_menu_link_hash_iter, G_TYPE_MENU_LINK_ITER)
190 g_menu_link_hash_iter_get_next (GMenuLinkIter *link_iter,
191 const gchar **out_name,
194 GMenuLinkHashIter *iter = (GMenuLinkHashIter *) link_iter;
195 gpointer keyptr, valueptr;
197 if (!g_hash_table_iter_next (&iter->iter, &keyptr, &valueptr))
201 *value = g_object_ref (valueptr);
207 g_menu_link_hash_iter_finalize (GObject *object)
209 GMenuLinkHashIter *iter = (GMenuLinkHashIter *) object;
211 g_hash_table_unref (iter->table);
213 G_OBJECT_CLASS (g_menu_link_hash_iter_parent_class)
218 g_menu_link_hash_iter_init (GMenuLinkHashIter *iter)
223 g_menu_link_hash_iter_class_init (GMenuLinkHashIterClass *class)
225 GObjectClass *object_class = G_OBJECT_CLASS (class);
227 object_class->finalize = g_menu_link_hash_iter_finalize;
228 class->get_next = g_menu_link_hash_iter_get_next;
234 GMenuAttributeIter parent_instance;
237 } GMenuAttributeHashIter;
239 typedef GMenuAttributeIterClass GMenuAttributeHashIterClass;
241 static GType g_menu_attribute_hash_iter_get_type (void);
243 G_DEFINE_TYPE (GMenuAttributeHashIter, g_menu_attribute_hash_iter, G_TYPE_MENU_ATTRIBUTE_ITER)
246 g_menu_attribute_hash_iter_get_next (GMenuAttributeIter *attr_iter,
250 GMenuAttributeHashIter *iter = (GMenuAttributeHashIter *) attr_iter;
251 gpointer keyptr, valueptr;
253 if (!g_hash_table_iter_next (&iter->iter, &keyptr, &valueptr))
258 *value = g_variant_ref (valueptr);
264 g_menu_attribute_hash_iter_finalize (GObject *object)
266 GMenuAttributeHashIter *iter = (GMenuAttributeHashIter *) object;
268 g_hash_table_unref (iter->table);
270 G_OBJECT_CLASS (g_menu_attribute_hash_iter_parent_class)
275 g_menu_attribute_hash_iter_init (GMenuAttributeHashIter *iter)
280 g_menu_attribute_hash_iter_class_init (GMenuAttributeHashIterClass *class)
282 GObjectClass *object_class = G_OBJECT_CLASS (class);
284 object_class->finalize = g_menu_attribute_hash_iter_finalize;
285 class->get_next = g_menu_attribute_hash_iter_get_next;
288 G_DEFINE_ABSTRACT_TYPE (GMenuModel, g_menu_model, G_TYPE_OBJECT)
291 static guint g_menu_model_items_changed_signal;
293 static GMenuAttributeIter *
294 g_menu_model_real_iterate_item_attributes (GMenuModel *model,
297 GHashTable *table = NULL;
298 GMenuAttributeIter *result;
300 G_MENU_MODEL_GET_CLASS (model)->get_item_attributes (model, item_index, &table);
304 GMenuAttributeHashIter *iter = g_object_new (g_menu_attribute_hash_iter_get_type (), NULL);
305 g_hash_table_iter_init (&iter->iter, table);
306 iter->table = g_hash_table_ref (table);
307 result = G_MENU_ATTRIBUTE_ITER (iter);
311 g_critical ("GMenuModel implementation '%s' doesn't override iterate_item_attributes() "
312 "and fails to return sane values from get_item_attributes()",
313 G_OBJECT_TYPE_NAME (model));
318 g_hash_table_unref (table);
324 g_menu_model_real_get_item_attribute_value (GMenuModel *model,
326 const gchar *attribute,
327 const GVariantType *expected_type)
329 GHashTable *table = NULL;
330 GVariant *value = NULL;
332 G_MENU_MODEL_GET_CLASS (model)
333 ->get_item_attributes (model, item_index, &table);
337 value = g_hash_table_lookup (table, attribute);
341 if (expected_type == NULL || g_variant_is_of_type (value, expected_type))
342 value = g_variant_ref (value);
348 g_assert_not_reached ();
351 g_hash_table_unref (table);
356 static GMenuLinkIter *
357 g_menu_model_real_iterate_item_links (GMenuModel *model,
360 GHashTable *table = NULL;
361 GMenuLinkIter *result;
363 G_MENU_MODEL_GET_CLASS (model)
364 ->get_item_links (model, item_index, &table);
368 GMenuLinkHashIter *iter = g_object_new (g_menu_link_hash_iter_get_type (), NULL);
369 g_hash_table_iter_init (&iter->iter, table);
370 iter->table = g_hash_table_ref (table);
371 result = G_MENU_LINK_ITER (iter);
375 g_critical ("GMenuModel implementation '%s' doesn't override iterate_item_links() "
376 "and fails to return sane values from get_item_links()",
377 G_OBJECT_TYPE_NAME (model));
382 g_hash_table_unref (table);
388 g_menu_model_real_get_item_link (GMenuModel *model,
392 GHashTable *table = NULL;
393 GMenuModel *value = NULL;
395 G_MENU_MODEL_GET_CLASS (model)
396 ->get_item_links (model, item_index, &table);
399 value = g_hash_table_lookup (table, link);
401 g_assert_not_reached ();
404 g_object_ref (value);
407 g_hash_table_unref (table);
413 g_menu_model_init (GMenuModel *model)
418 g_menu_model_class_init (GMenuModelClass *class)
420 class->iterate_item_attributes = g_menu_model_real_iterate_item_attributes;
421 class->get_item_attribute_value = g_menu_model_real_get_item_attribute_value;
422 class->iterate_item_links = g_menu_model_real_iterate_item_links;
423 class->get_item_link = g_menu_model_real_get_item_link;
426 * GMenuModel::items-changed:
427 * @model: the #GMenuModel that is changing
428 * @position: the position of the change
429 * @removed: the number of items removed
430 * @added: the number of items added
432 * Emitted when a change has occured to the menu.
434 * The only changes that can occur to a menu is that items are removed
435 * or added. Items may not change (except by being removed and added
436 * back in the same location). This signal is capable of describing
437 * both of those changes (at the same time).
439 * The signal means that starting at the index @position, @removed
440 * items were removed and @added items were added in their place. If
441 * @removed is zero then only items were added. If @added is zero
442 * then only items were removed.
444 * As an example, if the menu contains items a, b, c, d (in that
445 * order) and the signal (2, 1, 3) occurs then the new composition of
446 * the menu will be a, b, _, _, _, d (with each _ representing some
449 * Signal handlers may query the model (particularly the added items)
450 * and expect to see the results of the modification that is being
451 * reported. The signal is emitted after the modification.
453 g_menu_model_items_changed_signal =
454 g_signal_new ("items-changed", G_TYPE_MENU_MODEL,
455 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
456 g_cclosure_marshal_generic, G_TYPE_NONE,
457 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
461 * g_menu_model_is_mutable:
462 * @model: a #GMenuModel
464 * Queries if @model is mutable.
466 * An immutable #GMenuModel will never emit the #GMenuModel::items-changed
467 * signal. Consumers of the model may make optimisations accordingly.
469 * Returns: %TRUE if the model is mutable (ie: "items-changed" may be
475 g_menu_model_is_mutable (GMenuModel *model)
477 return G_MENU_MODEL_GET_CLASS (model)
478 ->is_mutable (model);
482 * g_menu_model_get_n_items:
483 * @model: a #GMenuModel
485 * Query the number of items in @model.
487 * Returns: the number of items
492 g_menu_model_get_n_items (GMenuModel *model)
494 return G_MENU_MODEL_GET_CLASS (model)
495 ->get_n_items (model);
499 * g_menu_model_iterate_item_attributes:
500 * @model: a #GMenuModel
501 * @item_index: the index of the item
503 * Creates a #GMenuAttributeIter to iterate over the attributes of
504 * the item at position @item_index in @model.
506 * You must free the iterator with g_object_unref() when you are done.
508 * Returns: (transfer full): a new #GMenuAttributeIter
513 g_menu_model_iterate_item_attributes (GMenuModel *model,
516 return G_MENU_MODEL_GET_CLASS (model)
517 ->iterate_item_attributes (model, item_index);
521 * g_menu_model_get_item_attribute_value:
522 * @model: a #GMenuModel
523 * @item_index: the index of the item
524 * @attribute: the attribute to query
525 * @expected_type: (allow-none): the expected type of the attribute, or
528 * Queries the item at position @item_index in @model for the attribute
529 * specified by @attribute.
531 * If @expected_type is non-%NULL then it specifies the expected type of
532 * the attribute. If it is %NULL then any type will be accepted.
534 * If the attribute exists and matches @expected_type (or if the
535 * expected type is unspecified) then the value is returned.
537 * If the attribute does not exist, or does not match the expected type
538 * then %NULL is returned.
540 * Returns: (transfer full): the value of the attribute
545 g_menu_model_get_item_attribute_value (GMenuModel *model,
547 const gchar *attribute,
548 const GVariantType *expected_type)
550 return G_MENU_MODEL_GET_CLASS (model)
551 ->get_item_attribute_value (model, item_index, attribute, expected_type);
555 * g_menu_model_get_item_attribute:
556 * @model: a #GMenuModel
557 * @item_index: the index of the item
558 * @attribute: the attribute to query
559 * @format_string: a #GVariant format string
560 * @...: positional parameters, as per @format_string
562 * Queries item at position @item_index in @model for the attribute
563 * specified by @attribute.
565 * If the attribute exists and matches the #GVariantType corresponding
566 * to @format_string then @format_string is used to deconstruct the
567 * value into the positional parameters and %TRUE is returned.
569 * If the attribute does not exist, or it does exist but has the wrong
570 * type, then the positional parameters are ignored and %FALSE is
573 * This function is a mix of g_menu_model_get_item_attribute_value() and
574 * g_variant_get(), followed by a g_variant_unref(). As such,
575 * @format_string must make a complete copy of the data (since the
576 * #GVariant may go away after the call to g_variant_unref()). In
577 * particular, no '&' characters are allowed in @format_string.
579 * Returns: %TRUE if the named attribute was found with the expected
585 g_menu_model_get_item_attribute (GMenuModel *model,
587 const gchar *attribute,
588 const gchar *format_string,
594 value = g_menu_model_get_item_attribute_value (model, item_index, attribute, NULL);
599 if (!g_variant_check_format_string (value, format_string, TRUE))
601 g_variant_unref (value);
605 va_start (ap, format_string);
606 g_variant_get_va (value, format_string, NULL, &ap);
607 g_variant_unref (value);
614 * g_menu_model_iterate_item_links:
615 * @model: a #GMenuModel
616 * @item_index: the index of the item
618 * Creates a #GMenuLinkIter to iterate over the links of the item at
619 * position @item_index in @model.
621 * You must free the iterator with g_object_unref() when you are done.
623 * Returns: (transfer full): a new #GMenuLinkIter
628 g_menu_model_iterate_item_links (GMenuModel *model,
631 return G_MENU_MODEL_GET_CLASS (model)
632 ->iterate_item_links (model, item_index);
636 * g_menu_model_get_item_link:
637 * @model: a #GMenuModel
638 * @item_index: the index of the item
639 * @link: the link to query
641 * Queries the item at position @item_index in @model for the link
642 * specified by @link.
644 * If the link exists, the linked #GMenuModel is returned. If the link
645 * does not exist, %NULL is returned.
647 * Returns: (transfer full): the linked #GMenuModel, or %NULL
652 g_menu_model_get_item_link (GMenuModel *model,
656 return G_MENU_MODEL_GET_CLASS (model)
657 ->get_item_link (model, item_index, link);
661 * g_menu_model_items_changed:
662 * @model: a #GMenuModel
663 * @position: the position of the change
664 * @removed: the number of items removed
665 * @added: the number of items added
667 * Requests emission of the #GMenuModel::items-changed signal on @model.
669 * This function should never be called except by #GMenuModel
670 * subclasses. Any other calls to this function will very likely lead
671 * to a violation of the interface of the model.
673 * The implementation should update its internal representation of the
674 * menu before emitting the signal. The implementation should further
675 * expect to receive queries about the new state of the menu (and
676 * particularly added menu items) while signal handlers are running.
678 * The implementation must dispatch this call directly from a mainloop
679 * entry and not in response to calls -- particularly those from the
680 * #GMenuModel API. Said another way: the menu must not change while
681 * user code is running without returning to the mainloop.
686 g_menu_model_items_changed (GMenuModel *model,
691 g_signal_emit (model, g_menu_model_items_changed_signal, 0, position, removed, added);
694 struct _GMenuAttributeIterPrivate
701 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GMenuAttributeIter, g_menu_attribute_iter, G_TYPE_OBJECT)
704 * g_menu_attribute_iter_get_next:
705 * @iter: a #GMenuAttributeIter
706 * @out_name: (out) (allow-none) (transfer none): the type of the attribute
707 * @value: (out) (allow-none) (transfer full): the attribute value
709 * This function combines g_menu_attribute_iter_next() with
710 * g_menu_attribute_iter_get_name() and g_menu_attribute_iter_get_value().
712 * First the iterator is advanced to the next (possibly first) attribute.
713 * If that fails, then %FALSE is returned and there are no other
716 * If successful, @name and @value are set to the name and value of the
717 * attribute that has just been advanced to. At this point,
718 * g_menu_attribute_iter_get_name() and g_menu_attribute_iter_get_value() will
719 * return the same values again.
721 * The value returned in @name remains valid for as long as the iterator
722 * remains at the current position. The value returned in @value must
723 * be unreffed using g_variant_unref() when it is no longer in use.
725 * Returns: %TRUE on success, or %FALSE if there is no additional
731 g_menu_attribute_iter_get_next (GMenuAttributeIter *iter,
732 const gchar **out_name,
737 if (iter->priv->value)
739 g_variant_unref (iter->priv->value);
740 iter->priv->value = NULL;
743 iter->priv->valid = G_MENU_ATTRIBUTE_ITER_GET_CLASS (iter)
744 ->get_next (iter, &name, &iter->priv->value);
746 if (iter->priv->valid)
748 iter->priv->name = g_quark_from_string (name);
750 *out_name = g_quark_to_string (iter->priv->name);
753 *value = g_variant_ref (iter->priv->value);
756 return iter->priv->valid;
760 * g_menu_attribute_iter_next:
761 * @iter: a #GMenuAttributeIter
763 * Attempts to advance the iterator to the next (possibly first)
766 * %TRUE is returned on success, or %FALSE if there are no more
769 * You must call this function when you first acquire the iterator
770 * to advance it to the first attribute (and determine if the first
771 * attribute exists at all).
773 * Returns: %TRUE on success, or %FALSE when there are no more attributes
778 g_menu_attribute_iter_next (GMenuAttributeIter *iter)
780 return g_menu_attribute_iter_get_next (iter, NULL, NULL);
784 * g_menu_attribute_iter_get_name:
785 * @iter: a #GMenuAttributeIter
787 * Gets the name of the attribute at the current iterator position, as
790 * The iterator is not advanced.
792 * Returns: the name of the attribute
797 g_menu_attribute_iter_get_name (GMenuAttributeIter *iter)
799 g_return_val_if_fail (iter->priv->valid, 0);
801 return g_quark_to_string (iter->priv->name);
805 * g_menu_attribute_iter_get_value:
806 * @iter: a #GMenuAttributeIter
808 * Gets the value of the attribute at the current iterator position.
810 * The iterator is not advanced.
812 * Returns: (transfer full): the value of the current attribute
817 g_menu_attribute_iter_get_value (GMenuAttributeIter *iter)
819 g_return_val_if_fail (iter->priv->valid, NULL);
821 return g_variant_ref (iter->priv->value);
825 g_menu_attribute_iter_finalize (GObject *object)
827 GMenuAttributeIter *iter = G_MENU_ATTRIBUTE_ITER (object);
829 if (iter->priv->value)
830 g_variant_unref (iter->priv->value);
832 G_OBJECT_CLASS (g_menu_attribute_iter_parent_class)
837 g_menu_attribute_iter_init (GMenuAttributeIter *iter)
839 iter->priv = g_menu_attribute_iter_get_instance_private (iter);
843 g_menu_attribute_iter_class_init (GMenuAttributeIterClass *class)
845 GObjectClass *object_class = G_OBJECT_CLASS (class);
847 object_class->finalize = g_menu_attribute_iter_finalize;
850 struct _GMenuLinkIterPrivate
857 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GMenuLinkIter, g_menu_link_iter, G_TYPE_OBJECT)
860 * g_menu_link_iter_get_next:
861 * @iter: a #GMenuLinkIter
862 * @out_link: (out) (allow-none) (transfer none): the name of the link
863 * @value: (out) (allow-none) (transfer full): the linked #GMenuModel
865 * This function combines g_menu_link_iter_next() with
866 * g_menu_link_iter_get_name() and g_menu_link_iter_get_value().
868 * First the iterator is advanced to the next (possibly first) link.
869 * If that fails, then %FALSE is returned and there are no other effects.
871 * If successful, @out_link and @value are set to the name and #GMenuModel
872 * of the link that has just been advanced to. At this point,
873 * g_menu_link_iter_get_name() and g_menu_link_iter_get_value() will return the
876 * The value returned in @out_link remains valid for as long as the iterator
877 * remains at the current position. The value returned in @value must
878 * be unreffed using g_object_unref() when it is no longer in use.
880 * Returns: %TRUE on success, or %FALSE if there is no additional link
885 g_menu_link_iter_get_next (GMenuLinkIter *iter,
886 const gchar **out_link,
891 if (iter->priv->value)
893 g_object_unref (iter->priv->value);
894 iter->priv->value = NULL;
897 iter->priv->valid = G_MENU_LINK_ITER_GET_CLASS (iter)
898 ->get_next (iter, &name, &iter->priv->value);
900 if (iter->priv->valid)
902 g_assert (name != NULL);
904 iter->priv->name = g_quark_from_string (name);
906 *out_link = g_quark_to_string (iter->priv->name);
909 *value = g_object_ref (iter->priv->value);
912 return iter->priv->valid;
916 * g_menu_link_iter_next:
917 * @iter: a #GMenuLinkIter
919 * Attempts to advance the iterator to the next (possibly first)
922 * %TRUE is returned on success, or %FALSE if there are no more links.
924 * You must call this function when you first acquire the iterator to
925 * advance it to the first link (and determine if the first link exists
928 * Returns: %TRUE on success, or %FALSE when there are no more links
933 g_menu_link_iter_next (GMenuLinkIter *iter)
935 return g_menu_link_iter_get_next (iter, NULL, NULL);
939 * g_menu_link_iter_get_name:
940 * @iter: a #GMenuLinkIter
942 * Gets the name of the link at the current iterator position.
944 * The iterator is not advanced.
946 * Returns: the type of the link
951 g_menu_link_iter_get_name (GMenuLinkIter *iter)
953 g_return_val_if_fail (iter->priv->valid, 0);
955 return g_quark_to_string (iter->priv->name);
959 * g_menu_link_iter_get_value:
960 * @iter: a #GMenuLinkIter
962 * Gets the linked #GMenuModel at the current iterator position.
964 * The iterator is not advanced.
966 * Returns: (transfer full): the #GMenuModel that is linked to
971 g_menu_link_iter_get_value (GMenuLinkIter *iter)
973 g_return_val_if_fail (iter->priv->valid, NULL);
975 return g_object_ref (iter->priv->value);
979 g_menu_link_iter_finalize (GObject *object)
981 GMenuLinkIter *iter = G_MENU_LINK_ITER (object);
983 if (iter->priv->value)
984 g_object_unref (iter->priv->value);
986 G_OBJECT_CLASS (g_menu_link_iter_parent_class)
991 g_menu_link_iter_init (GMenuLinkIter *iter)
993 iter->priv = g_menu_link_iter_get_instance_private (iter);
997 g_menu_link_iter_class_init (GMenuLinkIterClass *class)
999 GObjectClass *object_class = G_OBJECT_CLASS (class);
1001 object_class->finalize = g_menu_link_iter_finalize;