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 * <figure id="menu-example">
50 * <title>An example menu</title>
51 * <graphic fileref="menu-example.png" format="PNG"></graphic>
54 * There are 8 "menus" visible in the screenshot: one menubar, two
55 * submenus and 5 sections:
57 * <listitem>the toplevel menubar (containing 4 items)</listitem>
58 * <listitem>the View submenu (containing 3 sections)</listitem>
59 * <listitem>the first section of the View submenu (containing 2 items)</listitem>
60 * <listitem>the second section of the View submenu (containing 1 item)</listitem>
61 * <listitem>the final section of the View submenu (containing 1 item)</listitem>
62 * <listitem>the Highlight Mode submenu (containing 2 sections)</listitem>
63 * <listitem>the Sources section (containing 2 items)</listitem>
64 * <listitem>the Markup section (containing 2 items)</listitem>
67 * <xref linkend="menu-model"/> illustrates the conceptual connection between
68 * these 8 menus. Each large block in the figure represents a menu and the
69 * smaller blocks within the large block represent items in that menu. Some
70 * items contain references to other menus.
72 * <figure id="menu-model">
73 * <title>A menu model</title>
74 * <graphic fileref="menu-model.png" format="PNG"></graphic>
77 * Notice that the separators visible in <xref linkend="menu-example"/>
78 * appear nowhere in <xref linkend="menu-model"/>. This is because
79 * separators are not explicitly represented in the menu model. Instead,
80 * a separator is inserted between any two non-empty sections of a menu.
81 * Section items can have labels just like any other item. In that case,
82 * a display system may show a section header instead of a separator.
84 * The motivation for this abstract model of application controls is
85 * that modern user interfaces tend to make these controls available
86 * outside the application. Examples include global menus, jumplists,
87 * dash boards, etc. To support such uses, it is necessary to 'export'
88 * information about actions and their representation in menus, which
90 * <link linkend="gio-GActionGroup-exporter">GActionGroup exporter</link>
92 * <link linkend="gio-GMenuModel-exporter">GMenuModel exporter</link>
93 * do for #GActionGroup and #GMenuModel. The client-side counterparts
94 * to make use of the exported information are #GDBusActionGroup and
97 * The API of #GMenuModel is very generic, with iterators for the
98 * attributes and links of an item, see g_menu_model_iterate_item_attributes()
99 * and g_menu_model_iterate_item_links(). The 'standard' attributes and
100 * link types have predefined names: %G_MENU_ATTRIBUTE_LABEL,
101 * %G_MENU_ATTRIBUTE_ACTION, %G_MENU_ATTRIBUTE_TARGET, %G_MENU_LINK_SECTION
102 * and %G_MENU_LINK_SUBMENU.
104 * Items in a #GMenuModel represent active controls if they refer to
105 * an action that can get activated when the user interacts with the
106 * menu item. The reference to the action is encoded by the string id
107 * in the %G_MENU_ATTRIBUTE_ACTION attribute. An action id uniquely
108 * identifies an action in an action group. Which action group(s) provide
109 * actions depends on the context in which the menu model is used.
110 * E.g. when the model is exported as the application menu of a
111 * #GtkApplication, actions can be application-wide or window-specific
112 * (and thus come from two different action groups). By convention, the
113 * application-wide actions have names that start with "app.", while the
114 * names of window-specific actions start with "win.".
116 * While a wide variety of stateful actions is possible, the following
117 * is the minimum that is expected to be supported by all users of exported
120 * <listitem>an action with no parameter type and no state</listitem>
121 * <listitem>an action with no parameter type and boolean state</listitem>
122 * <listitem>an action with string parameter type and string state</listitem>
125 * <formalpara><title>Stateless</title>
127 * A stateless action typically corresponds to an ordinary menu item.
130 * Selecting such a menu item will activate the action (with no parameter).
134 * <formalpara><title>Boolean State</title>
136 * An action with a boolean state will most typically be used with a "toggle"
137 * or "switch" menu item. The state can be set directly, but activating the
138 * action (with no parameter) results in the state being toggled.
141 * Selecting a toggle menu item will activate the action. The menu item should
142 * be rendered as "checked" when the state is true.
146 * <formalpara><title>String Parameter and State</title>
148 * Actions with string parameters and state will most typically be used to
149 * represent an enumerated choice over the items available for a group of
150 * radio menu items. Activating the action with a string parameter is
151 * equivalent to setting that parameter as the state.
154 * Radio menu items, in addition to being associated with the action, will
155 * have a target value. Selecting that menu item will result in activation
156 * of the action with the target value as the parameter. The menu item should
157 * be rendered as "selected" when the state of the action is equal to the
158 * target value of the menu item.
166 * #GMenuModel is an opaque structure type. You must access it using the
173 * GMenuAttributeIter:
175 * #GMenuAttributeIter is an opaque structure type. You must access it
176 * using the functions below.
184 * #GMenuLinkIter is an opaque structure type. You must access it using
185 * the functions below.
192 GMenuLinkIter parent_instance;
197 typedef GMenuLinkIterClass GMenuLinkHashIterClass;
199 static GType g_menu_link_hash_iter_get_type (void);
201 G_DEFINE_TYPE (GMenuLinkHashIter, g_menu_link_hash_iter, G_TYPE_MENU_LINK_ITER)
204 g_menu_link_hash_iter_get_next (GMenuLinkIter *link_iter,
205 const gchar **out_name,
208 GMenuLinkHashIter *iter = (GMenuLinkHashIter *) link_iter;
209 gpointer keyptr, valueptr;
211 if (!g_hash_table_iter_next (&iter->iter, &keyptr, &valueptr))
215 *value = g_object_ref (valueptr);
221 g_menu_link_hash_iter_finalize (GObject *object)
223 GMenuLinkHashIter *iter = (GMenuLinkHashIter *) object;
225 g_hash_table_unref (iter->table);
227 G_OBJECT_CLASS (g_menu_link_hash_iter_parent_class)
232 g_menu_link_hash_iter_init (GMenuLinkHashIter *iter)
237 g_menu_link_hash_iter_class_init (GMenuLinkHashIterClass *class)
239 GObjectClass *object_class = G_OBJECT_CLASS (class);
241 object_class->finalize = g_menu_link_hash_iter_finalize;
242 class->get_next = g_menu_link_hash_iter_get_next;
248 GMenuAttributeIter parent_instance;
251 } GMenuAttributeHashIter;
253 typedef GMenuAttributeIterClass GMenuAttributeHashIterClass;
255 static GType g_menu_attribute_hash_iter_get_type (void);
257 G_DEFINE_TYPE (GMenuAttributeHashIter, g_menu_attribute_hash_iter, G_TYPE_MENU_ATTRIBUTE_ITER)
260 g_menu_attribute_hash_iter_get_next (GMenuAttributeIter *attr_iter,
264 GMenuAttributeHashIter *iter = (GMenuAttributeHashIter *) attr_iter;
265 gpointer keyptr, valueptr;
267 if (!g_hash_table_iter_next (&iter->iter, &keyptr, &valueptr))
272 *value = g_variant_ref (valueptr);
278 g_menu_attribute_hash_iter_finalize (GObject *object)
280 GMenuAttributeHashIter *iter = (GMenuAttributeHashIter *) object;
282 g_hash_table_unref (iter->table);
284 G_OBJECT_CLASS (g_menu_attribute_hash_iter_parent_class)
289 g_menu_attribute_hash_iter_init (GMenuAttributeHashIter *iter)
294 g_menu_attribute_hash_iter_class_init (GMenuAttributeHashIterClass *class)
296 GObjectClass *object_class = G_OBJECT_CLASS (class);
298 object_class->finalize = g_menu_attribute_hash_iter_finalize;
299 class->get_next = g_menu_attribute_hash_iter_get_next;
302 G_DEFINE_ABSTRACT_TYPE (GMenuModel, g_menu_model, G_TYPE_OBJECT)
305 static guint g_menu_model_items_changed_signal;
307 static GMenuAttributeIter *
308 g_menu_model_real_iterate_item_attributes (GMenuModel *model,
311 GHashTable *table = NULL;
312 GMenuAttributeIter *result;
314 G_MENU_MODEL_GET_CLASS (model)->get_item_attributes (model, item_index, &table);
318 GMenuAttributeHashIter *iter = g_object_new (g_menu_attribute_hash_iter_get_type (), NULL);
319 g_hash_table_iter_init (&iter->iter, table);
320 iter->table = g_hash_table_ref (table);
321 result = G_MENU_ATTRIBUTE_ITER (iter);
325 g_critical ("GMenuModel implementation '%s' doesn't override iterate_item_attributes() "
326 "and fails to return sane values from get_item_attributes()",
327 G_OBJECT_TYPE_NAME (model));
332 g_hash_table_unref (table);
338 g_menu_model_real_get_item_attribute_value (GMenuModel *model,
340 const gchar *attribute,
341 const GVariantType *expected_type)
343 GHashTable *table = NULL;
344 GVariant *value = NULL;
346 G_MENU_MODEL_GET_CLASS (model)
347 ->get_item_attributes (model, item_index, &table);
351 value = g_hash_table_lookup (table, attribute);
355 if (expected_type == NULL || g_variant_is_of_type (value, expected_type))
356 value = g_variant_ref (value);
362 g_assert_not_reached ();
365 g_hash_table_unref (table);
370 static GMenuLinkIter *
371 g_menu_model_real_iterate_item_links (GMenuModel *model,
374 GHashTable *table = NULL;
375 GMenuLinkIter *result;
377 G_MENU_MODEL_GET_CLASS (model)
378 ->get_item_links (model, item_index, &table);
382 GMenuLinkHashIter *iter = g_object_new (g_menu_link_hash_iter_get_type (), NULL);
383 g_hash_table_iter_init (&iter->iter, table);
384 iter->table = g_hash_table_ref (table);
385 result = G_MENU_LINK_ITER (iter);
389 g_critical ("GMenuModel implementation '%s' doesn't override iterate_item_links() "
390 "and fails to return sane values from get_item_links()",
391 G_OBJECT_TYPE_NAME (model));
396 g_hash_table_unref (table);
402 g_menu_model_real_get_item_link (GMenuModel *model,
406 GHashTable *table = NULL;
407 GMenuModel *value = NULL;
409 G_MENU_MODEL_GET_CLASS (model)
410 ->get_item_links (model, item_index, &table);
413 value = g_hash_table_lookup (table, link);
415 g_assert_not_reached ();
418 g_object_ref (value);
421 g_hash_table_unref (table);
427 g_menu_model_init (GMenuModel *model)
432 g_menu_model_class_init (GMenuModelClass *class)
434 class->iterate_item_attributes = g_menu_model_real_iterate_item_attributes;
435 class->get_item_attribute_value = g_menu_model_real_get_item_attribute_value;
436 class->iterate_item_links = g_menu_model_real_iterate_item_links;
437 class->get_item_link = g_menu_model_real_get_item_link;
440 * GMenuModel::items-changed:
441 * @model: the #GMenuModel that is changing
442 * @position: the position of the change
443 * @removed: the number of items removed
444 * @added: the number of items added
446 * Emitted when a change has occured to the menu.
448 * The only changes that can occur to a menu is that items are removed
449 * or added. Items may not change (except by being removed and added
450 * back in the same location). This signal is capable of describing
451 * both of those changes (at the same time).
453 * The signal means that starting at the index @position, @removed
454 * items were removed and @added items were added in their place. If
455 * @removed is zero then only items were added. If @added is zero
456 * then only items were removed.
458 * As an example, if the menu contains items a, b, c, d (in that
459 * order) and the signal (2, 1, 3) occurs then the new composition of
460 * the menu will be a, b, _, _, _, d (with each _ representing some
463 * Signal handlers may query the model (particularly the added items)
464 * and expect to see the results of the modification that is being
465 * reported. The signal is emitted after the modification.
467 g_menu_model_items_changed_signal =
468 g_signal_new ("items-changed", G_TYPE_MENU_MODEL,
469 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
470 g_cclosure_marshal_generic, G_TYPE_NONE,
471 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
475 * g_menu_model_is_mutable:
476 * @model: a #GMenuModel
478 * Queries if @model is mutable.
480 * An immutable #GMenuModel will never emit the #GMenuModel::items-changed
481 * signal. Consumers of the model may make optimisations accordingly.
483 * Returns: %TRUE if the model is mutable (ie: "items-changed" may be
489 g_menu_model_is_mutable (GMenuModel *model)
491 return G_MENU_MODEL_GET_CLASS (model)
492 ->is_mutable (model);
496 * g_menu_model_get_n_items:
497 * @model: a #GMenuModel
499 * Query the number of items in @model.
501 * Returns: the number of items
506 g_menu_model_get_n_items (GMenuModel *model)
508 return G_MENU_MODEL_GET_CLASS (model)
509 ->get_n_items (model);
513 * g_menu_model_iterate_item_attributes:
514 * @model: a #GMenuModel
515 * @item_index: the index of the item
517 * Creates a #GMenuAttributeIter to iterate over the attributes of
518 * the item at position @item_index in @model.
520 * You must free the iterator with g_object_unref() when you are done.
522 * Returns: (transfer full): a new #GMenuAttributeIter
527 g_menu_model_iterate_item_attributes (GMenuModel *model,
530 return G_MENU_MODEL_GET_CLASS (model)
531 ->iterate_item_attributes (model, item_index);
535 * g_menu_model_get_item_attribute_value:
536 * @model: a #GMenuModel
537 * @item_index: the index of the item
538 * @attribute: the attribute to query
539 * @expected_type: (allow-none): the expected type of the attribute, or
542 * Queries the item at position @item_index in @model for the attribute
543 * specified by @attribute.
545 * If @expected_type is non-%NULL then it specifies the expected type of
546 * the attribute. If it is %NULL then any type will be accepted.
548 * If the attribute exists and matches @expected_type (or if the
549 * expected type is unspecified) then the value is returned.
551 * If the attribute does not exist, or does not match the expected type
552 * then %NULL is returned.
554 * Returns: (transfer full): the value of the attribute
559 g_menu_model_get_item_attribute_value (GMenuModel *model,
561 const gchar *attribute,
562 const GVariantType *expected_type)
564 return G_MENU_MODEL_GET_CLASS (model)
565 ->get_item_attribute_value (model, item_index, attribute, expected_type);
569 * g_menu_model_get_item_attribute:
570 * @model: a #GMenuModel
571 * @item_index: the index of the item
572 * @attribute: the attribute to query
573 * @format_string: a #GVariant format string
574 * @...: positional parameters, as per @format_string
576 * Queries item at position @item_index in @model for the attribute
577 * specified by @attribute.
579 * If the attribute exists and matches the #GVariantType corresponding
580 * to @format_string then @format_string is used to deconstruct the
581 * value into the positional parameters and %TRUE is returned.
583 * If the attribute does not exist, or it does exist but has the wrong
584 * type, then the positional parameters are ignored and %FALSE is
587 * This function is a mix of g_menu_model_get_item_attribute_value() and
588 * g_variant_get(), followed by a g_variant_unref(). As such,
589 * @format_string must make a complete copy of the data (since the
590 * #GVariant may go away after the call to g_variant_unref()). In
591 * particular, no '&' characters are allowed in @format_string.
593 * Returns: %TRUE if the named attribute was found with the expected
599 g_menu_model_get_item_attribute (GMenuModel *model,
601 const gchar *attribute,
602 const gchar *format_string,
608 value = g_menu_model_get_item_attribute_value (model, item_index, attribute, NULL);
613 if (!g_variant_check_format_string (value, format_string, TRUE))
615 g_variant_unref (value);
619 va_start (ap, format_string);
620 g_variant_get_va (value, format_string, NULL, &ap);
621 g_variant_unref (value);
628 * g_menu_model_iterate_item_links:
629 * @model: a #GMenuModel
630 * @item_index: the index of the item
632 * Creates a #GMenuLinkIter to iterate over the links of the item at
633 * position @item_index in @model.
635 * You must free the iterator with g_object_unref() when you are done.
637 * Returns: (transfer full): a new #GMenuLinkIter
642 g_menu_model_iterate_item_links (GMenuModel *model,
645 return G_MENU_MODEL_GET_CLASS (model)
646 ->iterate_item_links (model, item_index);
650 * g_menu_model_get_item_link:
651 * @model: a #GMenuModel
652 * @item_index: the index of the item
653 * @link: the link to query
655 * Queries the item at position @item_index in @model for the link
656 * specified by @link.
658 * If the link exists, the linked #GMenuModel is returned. If the link
659 * does not exist, %NULL is returned.
661 * Returns: (transfer full): the linked #GMenuModel, or %NULL
666 g_menu_model_get_item_link (GMenuModel *model,
670 return G_MENU_MODEL_GET_CLASS (model)
671 ->get_item_link (model, item_index, link);
675 * g_menu_model_items_changed:
676 * @model: a #GMenuModel
677 * @position: the position of the change
678 * @removed: the number of items removed
679 * @added: the number of items added
681 * Requests emission of the #GMenuModel::items-changed signal on @model.
683 * This function should never be called except by #GMenuModel
684 * subclasses. Any other calls to this function will very likely lead
685 * to a violation of the interface of the model.
687 * The implementation should update its internal representation of the
688 * menu before emitting the signal. The implementation should further
689 * expect to receive queries about the new state of the menu (and
690 * particularly added menu items) while signal handlers are running.
692 * The implementation must dispatch this call directly from a mainloop
693 * entry and not in response to calls -- particularly those from the
694 * #GMenuModel API. Said another way: the menu must not change while
695 * user code is running without returning to the mainloop.
700 g_menu_model_items_changed (GMenuModel *model,
705 g_signal_emit (model, g_menu_model_items_changed_signal, 0, position, removed, added);
708 struct _GMenuAttributeIterPrivate
715 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GMenuAttributeIter, g_menu_attribute_iter, G_TYPE_OBJECT)
718 * g_menu_attribute_iter_get_next:
719 * @iter: a #GMenuAttributeIter
720 * @out_name: (out) (allow-none) (transfer none): the type of the attribute
721 * @value: (out) (allow-none) (transfer full): the attribute value
723 * This function combines g_menu_attribute_iter_next() with
724 * g_menu_attribute_iter_get_name() and g_menu_attribute_iter_get_value().
726 * First the iterator is advanced to the next (possibly first) attribute.
727 * If that fails, then %FALSE is returned and there are no other
730 * If successful, @name and @value are set to the name and value of the
731 * attribute that has just been advanced to. At this point,
732 * g_menu_attribute_iter_get_name() and g_menu_attribute_iter_get_value() will
733 * return the same values again.
735 * The value returned in @name remains valid for as long as the iterator
736 * remains at the current position. The value returned in @value must
737 * be unreffed using g_variant_unref() when it is no longer in use.
739 * Returns: %TRUE on success, or %FALSE if there is no additional
745 g_menu_attribute_iter_get_next (GMenuAttributeIter *iter,
746 const gchar **out_name,
751 if (iter->priv->value)
753 g_variant_unref (iter->priv->value);
754 iter->priv->value = NULL;
757 iter->priv->valid = G_MENU_ATTRIBUTE_ITER_GET_CLASS (iter)
758 ->get_next (iter, &name, &iter->priv->value);
760 if (iter->priv->valid)
762 iter->priv->name = g_quark_from_string (name);
764 *out_name = g_quark_to_string (iter->priv->name);
767 *value = g_variant_ref (iter->priv->value);
770 return iter->priv->valid;
774 * g_menu_attribute_iter_next:
775 * @iter: a #GMenuAttributeIter
777 * Attempts to advance the iterator to the next (possibly first)
780 * %TRUE is returned on success, or %FALSE if there are no more
783 * You must call this function when you first acquire the iterator
784 * to advance it to the first attribute (and determine if the first
785 * attribute exists at all).
787 * Returns: %TRUE on success, or %FALSE when there are no more attributes
792 g_menu_attribute_iter_next (GMenuAttributeIter *iter)
794 return g_menu_attribute_iter_get_next (iter, NULL, NULL);
798 * g_menu_attribute_iter_get_name:
799 * @iter: a #GMenuAttributeIter
801 * Gets the name of the attribute at the current iterator position, as
804 * The iterator is not advanced.
806 * Returns: the name of the attribute
811 g_menu_attribute_iter_get_name (GMenuAttributeIter *iter)
813 g_return_val_if_fail (iter->priv->valid, 0);
815 return g_quark_to_string (iter->priv->name);
819 * g_menu_attribute_iter_get_value:
820 * @iter: a #GMenuAttributeIter
822 * Gets the value of the attribute at the current iterator position.
824 * The iterator is not advanced.
826 * Returns: (transfer full): the value of the current attribute
831 g_menu_attribute_iter_get_value (GMenuAttributeIter *iter)
833 g_return_val_if_fail (iter->priv->valid, NULL);
835 return g_variant_ref (iter->priv->value);
839 g_menu_attribute_iter_finalize (GObject *object)
841 GMenuAttributeIter *iter = G_MENU_ATTRIBUTE_ITER (object);
843 if (iter->priv->value)
844 g_variant_unref (iter->priv->value);
846 G_OBJECT_CLASS (g_menu_attribute_iter_parent_class)
851 g_menu_attribute_iter_init (GMenuAttributeIter *iter)
853 iter->priv = g_menu_attribute_iter_get_instance_private (iter);
857 g_menu_attribute_iter_class_init (GMenuAttributeIterClass *class)
859 GObjectClass *object_class = G_OBJECT_CLASS (class);
861 object_class->finalize = g_menu_attribute_iter_finalize;
864 struct _GMenuLinkIterPrivate
871 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GMenuLinkIter, g_menu_link_iter, G_TYPE_OBJECT)
874 * g_menu_link_iter_get_next:
875 * @iter: a #GMenuLinkIter
876 * @out_link: (out) (allow-none) (transfer none): the name of the link
877 * @value: (out) (allow-none) (transfer full): the linked #GMenuModel
879 * This function combines g_menu_link_iter_next() with
880 * g_menu_link_iter_get_name() and g_menu_link_iter_get_value().
882 * First the iterator is advanced to the next (possibly first) link.
883 * If that fails, then %FALSE is returned and there are no other effects.
885 * If successful, @out_link and @value are set to the name and #GMenuModel
886 * of the link that has just been advanced to. At this point,
887 * g_menu_link_iter_get_name() and g_menu_link_iter_get_value() will return the
890 * The value returned in @out_link remains valid for as long as the iterator
891 * remains at the current position. The value returned in @value must
892 * be unreffed using g_object_unref() when it is no longer in use.
894 * Returns: %TRUE on success, or %FALSE if there is no additional link
899 g_menu_link_iter_get_next (GMenuLinkIter *iter,
900 const gchar **out_link,
905 if (iter->priv->value)
907 g_object_unref (iter->priv->value);
908 iter->priv->value = NULL;
911 iter->priv->valid = G_MENU_LINK_ITER_GET_CLASS (iter)
912 ->get_next (iter, &name, &iter->priv->value);
914 if (iter->priv->valid)
916 g_assert (name != NULL);
918 iter->priv->name = g_quark_from_string (name);
920 *out_link = g_quark_to_string (iter->priv->name);
923 *value = g_object_ref (iter->priv->value);
926 return iter->priv->valid;
930 * g_menu_link_iter_next:
931 * @iter: a #GMenuLinkIter
933 * Attempts to advance the iterator to the next (possibly first)
936 * %TRUE is returned on success, or %FALSE if there are no more links.
938 * You must call this function when you first acquire the iterator to
939 * advance it to the first link (and determine if the first link exists
942 * Returns: %TRUE on success, or %FALSE when there are no more links
947 g_menu_link_iter_next (GMenuLinkIter *iter)
949 return g_menu_link_iter_get_next (iter, NULL, NULL);
953 * g_menu_link_iter_get_name:
954 * @iter: a #GMenuLinkIter
956 * Gets the name of the link at the current iterator position.
958 * The iterator is not advanced.
960 * Returns: the type of the link
965 g_menu_link_iter_get_name (GMenuLinkIter *iter)
967 g_return_val_if_fail (iter->priv->valid, 0);
969 return g_quark_to_string (iter->priv->name);
973 * g_menu_link_iter_get_value:
974 * @iter: a #GMenuLinkIter
976 * Gets the linked #GMenuModel at the current iterator position.
978 * The iterator is not advanced.
980 * Returns: (transfer full): the #GMenuModel that is linked to
985 g_menu_link_iter_get_value (GMenuLinkIter *iter)
987 g_return_val_if_fail (iter->priv->valid, NULL);
989 return g_object_ref (iter->priv->value);
993 g_menu_link_iter_finalize (GObject *object)
995 GMenuLinkIter *iter = G_MENU_LINK_ITER (object);
997 if (iter->priv->value)
998 g_object_unref (iter->priv->value);
1000 G_OBJECT_CLASS (g_menu_link_iter_parent_class)
1001 ->finalize (object);
1005 g_menu_link_iter_init (GMenuLinkIter *iter)
1007 iter->priv = g_menu_link_iter_get_instance_private (iter);
1011 g_menu_link_iter_class_init (GMenuLinkIterClass *class)
1013 GObjectClass *object_class = G_OBJECT_CLASS (class);
1015 object_class->finalize = g_menu_link_iter_finalize;