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, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * Author: Ryan Lortie <desrt@desrt.ca>
22 #include "gmenumodel.h"
27 * @short_description: An abstract class representing the contents of a menu
28 * @see_also: #GActionGroup
30 * #GMenuModel represents the contents of a menu -- an ordered list of
31 * menu items. The items are associated with actions, which can be
32 * activated through them. Items can be grouped in sections, and may
33 * have submenus associated with them. Both items and sections usually
34 * have some representation data, such as labels or icons. The type of
35 * the associated action (ie whether it is stateful, and what kind of
36 * state it has) can influence the representation of the item.
38 * The conceptual model of menus in #GMenuModel is hierarchical:
39 * sections and submenus are again represented by #GMenuModels.
40 * Menus themselves do not define their own roles. Rather, the role
41 * of a particular #GMenuModel is defined by the item that references
42 * it (or, in the case of the 'root' menu, is defined by the context
43 * in which it is used).
45 * As an example, consider the visible portions of the menu in
46 * <xref linkend="menu-example"/>.
48 * <figure id="menu-example">
49 * <title>An example menu</title>
50 * <graphic fileref="menu-example.png" format="PNG"></graphic>
53 * There are 8 "menus" visible in the screenshot: one menubar, two
54 * submenus and 5 sections:
56 * <listitem>the toplevel menubar (containing 4 items)</listitem>
57 * <listitem>the View submenu (containing 3 sections)</listitem>
58 * <listitem>the first section of the View submenu (containing 2 items)</listitem>
59 * <listitem>the second section of the View submenu (containing 1 item)</listitem>
60 * <listitem>the final section of the View submenu (containing 1 item)</listitem>
61 * <listitem>the Highlight Mode submenu (containing 2 sections)</listitem>
62 * <listitem>the Sources section (containing 2 items)</listitem>
63 * <listitem>the Markup section (containing 2 items)</listitem>
66 * <xref linkend="menu-model"/> illustrates the conceptual connection between
67 * these 8 menus. Each large block in the figure represents a menu and the
68 * smaller blocks within the large block represent items in that menu. Some
69 * items contain references to other menus.
71 * <figure id="menu-model">
72 * <title>A menu model</title>
73 * <graphic fileref="menu-model.png" format="PNG"></graphic>
76 * Notice that the separators visible in <xref linkend="menu-example"/>
77 * appear nowhere in <xref linkend="menu-model"/>. This is because
78 * separators are not explicitly represented in the menu model. Instead,
79 * a separator is inserted between any two non-empty sections of a menu.
80 * Section items can have labels just like any other item. In that case,
81 * a display system may show a section header instead of a separator.
83 * The motivation for this abstract model of application controls is
84 * that modern user interfaces tend to make these controls available
85 * outside the application. Examples include global menus, jumplists,
86 * dash boards, etc. To support such uses, it is necessary to 'export'
87 * information about actions and their representation in menus, which
89 * <link linkend="gio-GActionGroup-exporter">GActionGroup exporter</link>
91 * <link linkend="gio-GMenuModel-exporter">GMenuModel exporter</link>
92 * do for #GActionGroup and #GMenuModel. The client-side counterparts
93 * to make use of the exported information are #GDBusActionGroup and
96 * The API of #GMenuModel is very generic, with iterators for the
97 * attributes and links of an item, see g_menu_model_iterate_item_attributes()
98 * and g_menu_model_iterate_item_links(). The 'standard' attributes and
99 * link types have predefined names: %G_MENU_ATTRIBUTE_LABEL,
100 * %G_MENU_ATTRIBUTE_ACTION, %G_MENU_ATTRIBUTE_TARGET, %G_MENU_LINK_SECTION
101 * and %G_MENU_LINK_SUBMENU.
103 * FIXME: explain how items are associated with actions.
105 * While a wide variety of stateful actions is possible, the following
106 * is the minimum that is expected to be supported by all users of exported
109 * <listitem>an action with no parameter type and no state</listitem>
110 * <listitem>an action with no parameter type and boolean state</listitem>
111 * <listitem>an action with string parameter type and string state</listitem>
114 * <formalpara><title>Stateless</title>
116 * A stateless action typically corresponds to an ordinary menu item.
119 * Selecting such a menu item will activate the action (with no parameter).
123 * <formalpara><title>Boolean State</title>
125 * An action with a boolean state will most typically be used with a "toggle"
126 * or "switch" menu item. The state can be set directly, but activating the
127 * action (with no parameter) results in the state being toggled.
130 * Selecting a toggle menu item will activate the action. The menu item should
131 * be rendered as "checked" when the state is true.
135 * <formalpara><title>String Parameter and State</title>
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.
143 * Radio menu items, in addition to being associated with the action, will
144 * have a target value. Selecting that menu item will result in activation
145 * of the action with the target value as the parameter. The menu item should
146 * be rendered as "selected" when the state of the action is equal to the
147 * target value of the menu item.
155 * #GMenuModel is an opaque structure type. You must access it using the
160 * GMenuAttributeIter:
162 * #GMenuAttributeIter is an opaque structure type. You must access it
163 * using the functions below.
169 * #GMenuLinkIter is an opaque structure type. You must access it using
170 * the functions below.
175 GMenuLinkIter parent_instance;
180 typedef GMenuLinkIterClass GMenuLinkHashIterClass;
182 G_DEFINE_TYPE (GMenuLinkHashIter, g_menu_link_hash_iter, G_TYPE_MENU_LINK_ITER)
185 g_menu_link_hash_iter_get_next (GMenuLinkIter *link_iter,
186 const gchar **out_name,
189 GMenuLinkHashIter *iter = (GMenuLinkHashIter *) link_iter;
190 gpointer keyptr, valueptr;
192 if (!g_hash_table_iter_next (&iter->iter, &keyptr, &valueptr))
196 *value = g_object_ref (valueptr);
202 g_menu_link_hash_iter_finalize (GObject *object)
204 GMenuLinkHashIter *iter = (GMenuLinkHashIter *) object;
206 g_hash_table_unref (iter->table);
208 G_OBJECT_CLASS (g_menu_link_hash_iter_parent_class)
213 g_menu_link_hash_iter_init (GMenuLinkHashIter *iter)
218 g_menu_link_hash_iter_class_init (GMenuLinkHashIterClass *class)
220 GObjectClass *object_class = G_OBJECT_CLASS (class);
222 object_class->finalize = g_menu_link_hash_iter_finalize;
223 class->get_next = g_menu_link_hash_iter_get_next;
229 GMenuAttributeIter parent_instance;
232 } GMenuAttributeHashIter;
234 typedef GMenuAttributeIterClass GMenuAttributeHashIterClass;
236 G_DEFINE_TYPE (GMenuAttributeHashIter, g_menu_attribute_hash_iter, G_TYPE_MENU_ATTRIBUTE_ITER)
239 g_menu_attribute_hash_iter_get_next (GMenuAttributeIter *attr_iter,
243 GMenuAttributeHashIter *iter = (GMenuAttributeHashIter *) attr_iter;
244 gpointer keyptr, valueptr;
246 if (!g_hash_table_iter_next (&iter->iter, &keyptr, &valueptr))
251 *value = g_variant_ref (valueptr);
257 g_menu_attribute_hash_iter_finalize (GObject *object)
259 GMenuAttributeHashIter *iter = (GMenuAttributeHashIter *) object;
261 g_hash_table_unref (iter->table);
263 G_OBJECT_CLASS (g_menu_attribute_hash_iter_parent_class)
268 g_menu_attribute_hash_iter_init (GMenuAttributeHashIter *iter)
273 g_menu_attribute_hash_iter_class_init (GMenuAttributeHashIterClass *class)
275 GObjectClass *object_class = G_OBJECT_CLASS (class);
277 object_class->finalize = g_menu_attribute_hash_iter_finalize;
278 class->get_next = g_menu_attribute_hash_iter_get_next;
281 G_DEFINE_ABSTRACT_TYPE (GMenuModel, g_menu_model, G_TYPE_OBJECT)
284 guint g_menu_model_items_changed_signal;
286 static GMenuAttributeIter *
287 g_menu_model_real_iterate_item_attributes (GMenuModel *model,
290 GHashTable *table = NULL;
291 GMenuAttributeIter *result;
293 G_MENU_MODEL_GET_CLASS (model)->get_item_attributes (model, item_index, &table);
297 GMenuAttributeHashIter *iter = g_object_new (g_menu_attribute_hash_iter_get_type (), NULL);
298 g_hash_table_iter_init (&iter->iter, table);
299 iter->table = g_hash_table_ref (table);
300 result = G_MENU_ATTRIBUTE_ITER (iter);
304 g_critical ("GMenuModel implementation '%s' doesn't override iterate_item_attributes() "
305 "and fails to return sane values from get_item_attributes()",
306 G_OBJECT_TYPE_NAME (model));
311 g_hash_table_unref (table);
317 g_menu_model_real_get_item_attribute_value (GMenuModel *model,
319 const gchar *attribute,
320 const GVariantType *expected_type)
322 GHashTable *table = NULL;
323 GVariant *value = NULL;
325 G_MENU_MODEL_GET_CLASS (model)
326 ->get_item_attributes (model, item_index, &table);
330 value = g_hash_table_lookup (table, attribute);
334 if (expected_type == NULL || g_variant_is_of_type (value, expected_type))
335 value = g_variant_ref (value);
341 g_assert_not_reached ();
344 g_hash_table_unref (table);
349 static GMenuLinkIter *
350 g_menu_model_real_iterate_item_links (GMenuModel *model,
353 GHashTable *table = NULL;
354 GMenuLinkIter *result;
356 G_MENU_MODEL_GET_CLASS (model)
357 ->get_item_links (model, item_index, &table);
361 GMenuLinkHashIter *iter = g_object_new (g_menu_link_hash_iter_get_type (), NULL);
362 g_hash_table_iter_init (&iter->iter, table);
363 iter->table = g_hash_table_ref (table);
364 result = G_MENU_LINK_ITER (iter);
368 g_critical ("GMenuModel implementation '%s' doesn't override iterate_item_links() "
369 "and fails to return sane values from get_item_links()",
370 G_OBJECT_TYPE_NAME (model));
375 g_hash_table_unref (table);
381 g_menu_model_real_get_item_link (GMenuModel *model,
385 GHashTable *table = NULL;
386 GMenuModel *value = NULL;
388 G_MENU_MODEL_GET_CLASS (model)
389 ->get_item_links (model, item_index, &table);
392 value = g_hash_table_lookup (table, link);
394 g_assert_not_reached ();
397 g_object_ref (value);
400 g_hash_table_unref (table);
406 g_menu_model_init (GMenuModel *model)
411 g_menu_model_class_init (GMenuModelClass *class)
413 class->iterate_item_attributes = g_menu_model_real_iterate_item_attributes;
414 class->get_item_attribute_value = g_menu_model_real_get_item_attribute_value;
415 class->iterate_item_links = g_menu_model_real_iterate_item_links;
416 class->get_item_link = g_menu_model_real_get_item_link;
419 * GMenuModel::items-changed:
420 * @model: the #GMenuModel that is changing
421 * @position: the position of the change
422 * @removed: the number of items removed
423 * @added: the number of items added
425 * Emitted when a change has occured to the menu.
427 * The only changes that can occur to a menu is that items are removed
428 * or added. Items may not change (except by being removed and added
429 * back in the same location). This signal is capable of describing
430 * both of those changes (at the same time).
432 * The signal means that starting at the index @position, @removed
433 * items were removed and @added items were added in their place. If
434 * @removed is zero then only items were added. If @added is zero
435 * then only items were removed.
437 * As an example, if the menu contains items a, b, c, d (in that
438 * order) and the signal (2, 1, 3) occurs then the new composition of
439 * the menu will be a, b, _, _, _, d (with each _ representing some
442 * Signal handlers may query the model (particularly the added items)
443 * and expect to see the results of the modification that is being
444 * reported. The signal is emitted after the modification.
446 g_menu_model_items_changed_signal =
447 g_signal_new ("items-changed", G_TYPE_MENU_MODEL,
448 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
449 g_cclosure_marshal_generic, G_TYPE_NONE,
450 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
454 * g_menu_model_is_mutable:
455 * @model: a #GMenuModel
457 * Queries if @model is mutable.
459 * An immutable #GMenuModel will never emit the #GMenuModel::items-changed
460 * signal. Consumers of the model may make optimisations accordingly.
462 * Returns: %TRUE if the model is mutable (ie: "items-changed" may be
466 g_menu_model_is_mutable (GMenuModel *model)
468 return G_MENU_MODEL_GET_CLASS (model)
469 ->is_mutable (model);
473 * g_menu_model_get_n_items:
474 * @model: a #GMenuModel
476 * Query the number of items in @model.
478 * Returns: the number of items
481 g_menu_model_get_n_items (GMenuModel *model)
483 return G_MENU_MODEL_GET_CLASS (model)
484 ->get_n_items (model);
488 * g_menu_model_iterate_item_attributes:
489 * @model: a #GMenuModel
490 * @item_index: the index of the item
492 * Creates a #GMenuAttributeIter to iterate over the attributes of
493 * the item at position @item_index in @model.
495 * You must free the iterator with g_object_unref() when you are done.
497 * Returns: (transfer full): a new #GMenuAttributeIter
500 g_menu_model_iterate_item_attributes (GMenuModel *model,
503 return G_MENU_MODEL_GET_CLASS (model)
504 ->iterate_item_attributes (model, item_index);
508 * g_menu_model_get_item_attribute_value:
509 * @model: a #GMenuModel
510 * @item_index: the index of the item
511 * @attribute: the attribute to query
512 * @expected_type: (allow-none): the expected type of the attribute, or
515 * Queries the item at position @item_index in @model for the attribute
516 * specified by @attribute.
518 * If @expected_type is non-%NULL then it specifies the expected type of
519 * the attribute. If it is %NULL then any type will be accepted.
521 * If the attribute exists and matches @expected_type (or if the
522 * expected type is unspecified) then the value is returned.
524 * If the attribute does not exist, or does not match the expected type
525 * then %NULL is returned.
527 * Returns: (transfer full): the value of the attribute
530 g_menu_model_get_item_attribute_value (GMenuModel *model,
532 const gchar *attribute,
533 const GVariantType *expected_type)
535 return G_MENU_MODEL_GET_CLASS (model)
536 ->get_item_attribute_value (model, item_index, attribute, expected_type);
540 * g_menu_model_get_item_attribute:
541 * @model: a #GMenuModel
542 * @item_index: the index of the item
543 * @attribute: the attribute to query
544 * @format_string: a #GVariant format string
545 * @...: positional parameters, as per @format_string
547 * Queries item at position @item_index in @model for the attribute
548 * specified by @attribute.
550 * If the attribute exists and matches the #GVariantType corresponding
551 * to @format_string then @format_string is used to deconstruct the
552 * value into the positional parameters and %TRUE is returned.
554 * If the attribute does not exist, or it does exist but has the wrong
555 * type, then the positional parameters are ignored and %FALSE is
558 * Returns: %TRUE if the named attribute was found with the expected
562 g_menu_model_get_item_attribute (GMenuModel *model,
564 const gchar *attribute,
565 const gchar *format_string,
568 const GVariantType *expected_type;
572 expected_type = NULL; /* XXX devine the type, ensure no '&' */
574 value = g_menu_model_get_item_attribute_value (model, item_index, attribute, expected_type);
578 va_start (ap, format_string);
579 g_variant_get_va (value, format_string, NULL, &ap);
580 g_variant_unref (value);
587 * g_menu_model_iterate_item_links:
588 * @model: a #GMenuModel
589 * @item_index: the index of the item
591 * Creates a #GMenuLinkIter to iterate over the links of the item at
592 * position @item_index in @model.
594 * You must free the iterator with g_object_unref() when you are done.
596 * Returns: (transfer full): a new #GMenuLinkIter
599 g_menu_model_iterate_item_links (GMenuModel *model,
602 return G_MENU_MODEL_GET_CLASS (model)
603 ->iterate_item_links (model, item_index);
607 * g_menu_model_get_item_link:
608 * @model: a #GMenuModel
609 * @item_index: the index of the item
610 * @link: the link to query
612 * Queries the item at position @item_index in @model for the link
613 * specified by @link.
615 * If the link exists, the linked #GMenuModel is returned. If the link
616 * does not exist, %NULL is returned.
618 * Returns: (transfer full): the linked #GMenuModel, or %NULL
621 g_menu_model_get_item_link (GMenuModel *model,
625 return G_MENU_MODEL_GET_CLASS (model)
626 ->get_item_link (model, item_index, link);
630 * g_menu_model_items_changed:
631 * @model: a #GMenuModel
632 * @position: the position of the change
633 * @removed: the number of items removed
634 * @added: the number of items added
636 * Requests emission of the #GMenuMode::items-changed signal on @model.
638 * This function should never be called except by #GMenuModel
639 * subclasses. Any other calls to this function will very likely lead
640 * to a violation of the interface of the model.
642 * The implementation should update its internal representation of the
643 * menu before emitting the signal. The implementation should further
644 * expect to receive queries about the new state of the menu (and
645 * particularly added menu items) while signal handlers are running.
647 * The implementation must dispatch this call directly from a mainloop
648 * entry and not in response to calls -- particularly those from the
649 * #GMenuModel API. Said another way: the menu must not change while
650 * user code is running without returning to the mainloop.
653 g_menu_model_items_changed (GMenuModel *model,
658 g_signal_emit (model, g_menu_model_items_changed_signal, 0, position, removed, added);
661 G_DEFINE_ABSTRACT_TYPE (GMenuAttributeIter, g_menu_attribute_iter, G_TYPE_OBJECT)
663 struct _GMenuAttributeIterPrivate
671 * g_menu_attribute_iter_get_next:
672 * @iter: a #GMenuAttributeIter
673 * @out_name: (out) (allow-none) (transfer none): the type of the attribute
674 * @value: (out) (allow-none) (transfer full): the attribute value
676 * This function combines g_menu_attribute_iter_next() with
677 * g_menu_attribute_iter_get_name() and g_menu_attribute_iter_get_value().
679 * First the iterator is advanced to the next (possibly first) attribute.
680 * If that fails, then %FALSE is returned and there are no other
683 * If successful, @name and @value are set to the name and value of the
684 * attribute that has just been advanced to. At this point,
685 * g_menu_item_get_name() and g_menu_item_get_value() will return the
688 * The value returned in @name remains valid for as long as the iterator
689 * remains at the current position. The value returned in @value must
690 * be unreffed using g_variant_unref() when it is no longer in use.
692 * Returns: %TRUE on success, or %FALSE if there is no additional
696 g_menu_attribute_iter_get_next (GMenuAttributeIter *iter,
697 const gchar **out_name,
702 if (iter->priv->value)
704 g_variant_unref (iter->priv->value);
705 iter->priv->value = NULL;
708 iter->priv->valid = G_MENU_ATTRIBUTE_ITER_GET_CLASS (iter)
709 ->get_next (iter, &name, &iter->priv->value);
711 if (iter->priv->valid)
713 iter->priv->name = g_quark_from_string (name);
715 *out_name = g_quark_to_string (iter->priv->name);
718 *value = g_variant_ref (iter->priv->value);
721 return iter->priv->valid;
725 * g_menu_attribute_iter_next:
726 * @iter: a #GMenuAttributeIter
728 * Attempts to advance the iterator to the next (possibly first)
731 * %TRUE is returned on success, or %FALSE if there are no more
734 * You must call this function when you first acquire the iterator
735 * to advance it to the first attribute (and determine if the first
736 * attribute exists at all).
738 * Returns: %TRUE on success, or %FALSE when there are no more attributes
741 g_menu_attribute_iter_next (GMenuAttributeIter *iter)
743 return g_menu_attribute_iter_get_next (iter, NULL, NULL);
747 * g_menu_attribute_iter_get_name:
748 * @iter: a #GMenuAttributeIter
750 * Gets the name of the attribute at the current iterator position, as
753 * The iterator is not advanced.
755 * Returns: the name of the attribute
758 g_menu_attribute_iter_get_name (GMenuAttributeIter *iter)
760 g_return_val_if_fail (iter->priv->valid, 0);
762 return g_quark_to_string (iter->priv->name);
766 * g_menu_attribute_iter_get_value:
767 * @iter: a #GMenuAttributeIter
769 * Gets the value of the attribute at the current iterator position.
771 * The iterator is not advanced.
773 * Returns: (transfer full): the value of the current attribute
776 g_menu_attribute_iter_get_value (GMenuAttributeIter *iter)
778 g_return_val_if_fail (iter->priv->valid, NULL);
780 return g_variant_ref (iter->priv->value);
784 g_menu_attribute_iter_finalize (GObject *object)
786 GMenuAttributeIter *iter = G_MENU_ATTRIBUTE_ITER (object);
788 if (iter->priv->value)
789 g_variant_unref (iter->priv->value);
791 G_OBJECT_CLASS (g_menu_attribute_iter_parent_class)
796 g_menu_attribute_iter_init (GMenuAttributeIter *iter)
798 iter->priv = G_TYPE_INSTANCE_GET_PRIVATE (iter, G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterPrivate);
802 g_menu_attribute_iter_class_init (GMenuAttributeIterClass *class)
804 GObjectClass *object_class = G_OBJECT_CLASS (class);
806 object_class->finalize = g_menu_attribute_iter_finalize;
808 g_type_class_add_private (class, sizeof (GMenuAttributeIterPrivate));
811 G_DEFINE_ABSTRACT_TYPE (GMenuLinkIter, g_menu_link_iter, G_TYPE_OBJECT)
813 struct _GMenuLinkIterPrivate
821 * g_menu_link_iter_get_next:
822 * @iter: a #GMenuLinkIter
823 * @out_name: (out) (allow-none) (transfer none): the name of the link
824 * @value: (out) (allow-none) (transfer full): the linked #GMenuModel
826 * This function combines g_menu_link_iter_next() with
827 * g_menu_link_iter_get_name() and g_menu_link_iter_get_value().
829 * First the iterator is advanced to the next (possibly first) link. If
830 * that fails, then %FALSE is returned and there are no other effects.
832 * If successful, @out_name and @value are set to the name and #GMenuModel
833 * of the link that has just been advanced to. At this point,
834 * g_menu_item_get_name() and g_menu_item_get_value() will return the
837 * The value returned in @out_name remains valid for as long as the iterator
838 * remains at the current position. The value returned in @value must
839 * be unreffed using g_object_unref() when it is no longer in use.
841 * Returns: %TRUE on success, or %FALSE if there is no additional link
844 g_menu_link_iter_get_next (GMenuLinkIter *iter,
845 const gchar **out_name,
850 if (iter->priv->value)
852 g_object_unref (iter->priv->value);
853 iter->priv->value = NULL;
856 iter->priv->valid = G_MENU_LINK_ITER_GET_CLASS (iter)
857 ->get_next (iter, &name, &iter->priv->value);
859 if (iter->priv->valid)
861 g_assert (name != NULL);
863 iter->priv->name = g_quark_from_string (name);
865 *out_name = g_quark_to_string (iter->priv->name);
868 *value = g_object_ref (iter->priv->value);
871 return iter->priv->valid;
875 * g_menu_link_iter_next:
876 * @iter: a #GMenuLinkIter
878 * Attempts to advance the iterator to the next (possibly first)
881 * %TRUE is returned on success, or %FALSE if there are no more links.
883 * You must call this function when you first acquire the iterator to
884 * advance it to the first link (and determine if the first link exists
887 * Returns: %TRUE on success, or %FALSE when there are no more links
890 g_menu_link_iter_next (GMenuLinkIter *iter)
892 return g_menu_link_iter_get_next (iter, NULL, NULL);
896 * g_menu_link_iter_get_name:
897 * @iter: a #GMenuLinkIter
899 * Gets the name of the link at the current iterator position.
901 * The iterator is not advanced.
903 * Returns: the type of the link
906 g_menu_link_iter_get_name (GMenuLinkIter *iter)
908 g_return_val_if_fail (iter->priv->valid, 0);
910 return g_quark_to_string (iter->priv->name);
914 * g_menu_link_iter_get_value:
915 * @iter: a #GMenuLinkIter
917 * Gets the linked #GMenuModel at the current iterator position.
919 * The iterator is not advanced.
921 * Returns: (transfer full): the #GMenuModel that is linked to
924 g_menu_link_iter_get_value (GMenuLinkIter *iter)
926 g_return_val_if_fail (iter->priv->valid, NULL);
928 return g_object_ref (iter->priv->value);
932 g_menu_link_iter_finalize (GObject *object)
934 GMenuLinkIter *iter = G_MENU_LINK_ITER (object);
936 if (iter->priv->value)
937 g_object_unref (iter->priv->value);
939 G_OBJECT_CLASS (g_menu_link_iter_parent_class)
944 g_menu_link_iter_init (GMenuLinkIter *iter)
946 iter->priv = G_TYPE_INSTANCE_GET_PRIVATE (iter, G_TYPE_MENU_LINK_ITER, GMenuLinkIterPrivate);
950 g_menu_link_iter_class_init (GMenuLinkIterClass *class)
952 GObjectClass *object_class = G_OBJECT_CLASS (class);
954 object_class->finalize = g_menu_link_iter_finalize;
956 g_type_class_add_private (class, sizeof (GMenuLinkIterPrivate));