gmenumodel: document G_MENU_{ATTRIBUTE,LINK}_*
[platform/upstream/glib.git] / gio / gmenumodel.h
1 /*
2  * Copyright © 2011 Canonical Ltd.
3  *
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.
8  *
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.
13  *
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,
17  * USA.
18  *
19  * Author: Ryan Lortie <desrt@desrt.ca>
20  */
21
22 #ifndef __G_MENU_MODEL_H__
23 #define __G_MENU_MODEL_H__
24
25 #include <glib-object.h>
26
27 #include <gio/giotypes.h>
28
29 G_BEGIN_DECLS
30
31 /**
32  * G_MENU_ATTRIBUTE_ACTION:
33  *
34  * The menu item attribute which holds the action name of the item.  Action
35  * names are namespaced with an identifier for the action group in which the
36  * action resides. For example, "win." for window-specific actions and "app."
37  * for application-wide actions.
38  *
39  * See also g_menu_model_get_item_attribute() and g_menu_item_set_attribute().
40  *
41  * Since: 2.32
42  **/
43 #define G_MENU_ATTRIBUTE_ACTION "action"
44
45 /**
46  * G_MENU_ATTRIBUTE_TARGET:
47  *
48  * The menu item attribute which holds the target with which the item's action
49  * will be activated.
50  *
51  * See also g_menu_item_set_action_and_target()
52  *
53  * Since: 2.32
54  **/
55 #define G_MENU_ATTRIBUTE_TARGET "target"
56
57 /**
58  * G_MENU_ATTRIBUTE_LABEL:
59  *
60  * The menu item attribute which holds the label of the item.
61  *
62  * Since: 2.32
63  **/
64 #define G_MENU_ATTRIBUTE_LABEL "label"
65
66 /**
67  * G_MENU_LINK_SUBMENU:
68  *
69  * The name of the link that associates a menu item with a submenu.
70  *
71  * See also g_menu_item_set_link().
72  *
73  * Since: 2.32
74  **/
75 #define G_MENU_LINK_SUBMENU "submenu"
76
77 /**
78  * G_MENU_LINK_SUBMENU:
79  *
80  * The name of the link that associates a menu item with a section.  The linked
81  * menu will usually be shown in place of the menu item, using the item's label
82  * as a header.
83  *
84  * See also g_menu_item_set_link().
85  *
86  * Since: 2.32
87  **/
88 #define G_MENU_LINK_SECTION "section"
89
90 #define G_TYPE_MENU_MODEL                                   (g_menu_model_get_type ())
91 #define G_MENU_MODEL(inst)                                  (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
92                                                              G_TYPE_MENU_MODEL, GMenuModel))
93 #define G_MENU_MODEL_CLASS(class)                           (G_TYPE_CHECK_CLASS_CAST ((class),                       \
94                                                              G_TYPE_MENU_MODEL, GMenuModelClass))
95 #define G_IS_MENU_MODEL(inst)                               (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
96                                                              G_TYPE_MENU_MODEL))
97 #define G_IS_MENU_MODEL_CLASS(class)                        (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
98                                                              G_TYPE_MENU_MODEL))
99 #define G_MENU_MODEL_GET_CLASS(inst)                        (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
100                                                              G_TYPE_MENU_MODEL, GMenuModelClass))
101
102 typedef struct _GMenuModelPrivate                           GMenuModelPrivate;
103 typedef struct _GMenuModelClass                             GMenuModelClass;
104
105 typedef struct _GMenuAttributeIterPrivate                   GMenuAttributeIterPrivate;
106 typedef struct _GMenuAttributeIterClass                     GMenuAttributeIterClass;
107 typedef struct _GMenuAttributeIter                          GMenuAttributeIter;
108
109 typedef struct _GMenuLinkIterPrivate                        GMenuLinkIterPrivate;
110 typedef struct _GMenuLinkIterClass                          GMenuLinkIterClass;
111 typedef struct _GMenuLinkIter                               GMenuLinkIter;
112
113 struct _GMenuModel
114 {
115   GObject            parent_instance;
116   GMenuModelPrivate *priv;
117 };
118
119 struct _GMenuModelClass
120 {
121   GObjectClass parent_class;
122
123   gboolean              (*is_mutable)                       (GMenuModel          *model);
124   gint                  (*get_n_items)                      (GMenuModel          *model);
125   void                  (*get_item_attributes)              (GMenuModel          *model,
126                                                              gint                 item_index,
127                                                              GHashTable         **attributes);
128   GMenuAttributeIter *  (*iterate_item_attributes)          (GMenuModel          *model,
129                                                              gint                 item_index);
130   GVariant *            (*get_item_attribute_value)         (GMenuModel          *model,
131                                                              gint                 item_index,
132                                                              const gchar         *attribute,
133                                                              const GVariantType  *expected_type);
134   void                  (*get_item_links)                   (GMenuModel          *model,
135                                                              gint                 item_index,
136                                                              GHashTable         **links);
137   GMenuLinkIter *       (*iterate_item_links)               (GMenuModel          *model,
138                                                              gint                 item_index);
139   GMenuModel *          (*get_item_link)                    (GMenuModel          *model,
140                                                              gint                 item_index,
141                                                              const gchar         *link);
142 };
143
144 GLIB_AVAILABLE_IN_2_32
145 GType                   g_menu_model_get_type                           (void) G_GNUC_CONST;
146
147 GLIB_AVAILABLE_IN_2_32
148 gboolean                g_menu_model_is_mutable                         (GMenuModel         *model);
149 GLIB_AVAILABLE_IN_2_32
150 gint                    g_menu_model_get_n_items                        (GMenuModel         *model);
151
152 GLIB_AVAILABLE_IN_2_32
153 GMenuAttributeIter *    g_menu_model_iterate_item_attributes            (GMenuModel         *model,
154                                                                          gint                item_index);
155 GLIB_AVAILABLE_IN_2_32
156 GVariant *              g_menu_model_get_item_attribute_value           (GMenuModel         *model,
157                                                                          gint                item_index,
158                                                                          const gchar        *attribute,
159                                                                          const GVariantType *expected_type);
160 GLIB_AVAILABLE_IN_2_32
161 gboolean                g_menu_model_get_item_attribute                 (GMenuModel         *model,
162                                                                          gint                item_index,
163                                                                          const gchar        *attribute,
164                                                                          const gchar        *format_string,
165                                                                          ...);
166 GLIB_AVAILABLE_IN_2_32
167 GMenuLinkIter *         g_menu_model_iterate_item_links                 (GMenuModel         *model,
168                                                                          gint                item_index);
169 GLIB_AVAILABLE_IN_2_32
170 GMenuModel *            g_menu_model_get_item_link                      (GMenuModel         *model,
171                                                                          gint                item_index,
172                                                                          const gchar        *link);
173
174 GLIB_AVAILABLE_IN_2_32
175 void                    g_menu_model_items_changed                      (GMenuModel         *model,
176                                                                          gint                position,
177                                                                          gint                removed,
178                                                                          gint                added);
179
180
181 #define G_TYPE_MENU_ATTRIBUTE_ITER                          (g_menu_attribute_iter_get_type ())
182 #define G_MENU_ATTRIBUTE_ITER(inst)                         (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
183                                                              G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIter))
184 #define G_MENU_ATTRIBUTE_ITER_CLASS(class)                  (G_TYPE_CHECK_CLASS_CAST ((class),                       \
185                                                              G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterClass))
186 #define G_IS_MENU_ATTRIBUTE_ITER(inst)                      (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
187                                                              G_TYPE_MENU_ATTRIBUTE_ITER))
188 #define G_IS_MENU_ATTRIBUTE_ITER_CLASS(class)               (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
189                                                              G_TYPE_MENU_ATTRIBUTE_ITER))
190 #define G_MENU_ATTRIBUTE_ITER_GET_CLASS(inst)               (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
191                                                              G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterClass))
192
193 struct _GMenuAttributeIter
194 {
195   GObject parent_instance;
196   GMenuAttributeIterPrivate *priv;
197 };
198
199 struct _GMenuAttributeIterClass
200 {
201   GObjectClass parent_class;
202
203   gboolean      (*get_next) (GMenuAttributeIter  *iter,
204                              const gchar        **out_type,
205                              GVariant           **value);
206 };
207
208 GLIB_AVAILABLE_IN_2_32
209 GType                   g_menu_attribute_iter_get_type                  (void) G_GNUC_CONST;
210
211 GLIB_AVAILABLE_IN_2_32
212 gboolean                g_menu_attribute_iter_get_next                  (GMenuAttributeIter  *iter,
213                                                                          const gchar        **out_name,
214                                                                          GVariant           **value);
215 GLIB_AVAILABLE_IN_2_32
216 gboolean                g_menu_attribute_iter_next                      (GMenuAttributeIter  *iter);
217 GLIB_AVAILABLE_IN_2_32
218 const gchar *           g_menu_attribute_iter_get_name                  (GMenuAttributeIter  *iter);
219 GLIB_AVAILABLE_IN_2_32
220 GVariant *              g_menu_attribute_iter_get_value                 (GMenuAttributeIter  *iter);
221
222
223 #define G_TYPE_MENU_LINK_ITER                               (g_menu_link_iter_get_type ())
224 #define G_MENU_LINK_ITER(inst)                              (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
225                                                              G_TYPE_MENU_LINK_ITER, GMenuLinkIter))
226 #define G_MENU_LINK_ITER_CLASS(class)                       (G_TYPE_CHECK_CLASS_CAST ((class),                       \
227                                                              G_TYPE_MENU_LINK_ITER, GMenuLinkIterClass))
228 #define G_IS_MENU_LINK_ITER(inst)                           (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
229                                                              G_TYPE_MENU_LINK_ITER))
230 #define G_IS_MENU_LINK_ITER_CLASS(class)                    (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
231                                                              G_TYPE_MENU_LINK_ITER))
232 #define G_MENU_LINK_ITER_GET_CLASS(inst)                    (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
233                                                              G_TYPE_MENU_LINK_ITER, GMenuLinkIterClass))
234
235 struct _GMenuLinkIter
236 {
237   GObject parent_instance;
238   GMenuLinkIterPrivate *priv;
239 };
240
241 struct _GMenuLinkIterClass
242 {
243   GObjectClass parent_class;
244
245   gboolean      (*get_next) (GMenuLinkIter  *iter,
246                              const gchar   **out_name,
247                              GMenuModel    **value);
248 };
249
250 GLIB_AVAILABLE_IN_2_32
251 GType                   g_menu_link_iter_get_type                       (void) G_GNUC_CONST;
252
253 GLIB_AVAILABLE_IN_2_32
254 gboolean                g_menu_link_iter_get_next                       (GMenuLinkIter  *iter,
255                                                                          const gchar   **out_link,
256                                                                          GMenuModel    **value);
257 GLIB_AVAILABLE_IN_2_32
258 gboolean                g_menu_link_iter_next                           (GMenuLinkIter  *iter);
259 GLIB_AVAILABLE_IN_2_32
260 const gchar *           g_menu_link_iter_get_name                       (GMenuLinkIter  *iter);
261 GLIB_AVAILABLE_IN_2_32
262 GMenuModel *            g_menu_link_iter_get_value                      (GMenuLinkIter  *iter);
263
264 G_END_DECLS
265
266 #endif /* __G_MENU_MODEL_H__ */