GMenu: add g_menu_item_set_icon() convenience
[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_ACTION_NAMESPACE:
47  *
48  * The menu item attribute that holds the namespace for all action names in
49  * menus that are linked from this item.
50  *
51  * Since: 2.36
52  **/
53 #define G_MENU_ATTRIBUTE_ACTION_NAMESPACE "action-namespace"
54
55 /**
56  * G_MENU_ATTRIBUTE_TARGET:
57  *
58  * The menu item attribute which holds the target with which the item's action
59  * will be activated.
60  *
61  * See also g_menu_item_set_action_and_target()
62  *
63  * Since: 2.32
64  **/
65 #define G_MENU_ATTRIBUTE_TARGET "target"
66
67 /**
68  * G_MENU_ATTRIBUTE_LABEL:
69  *
70  * The menu item attribute which holds the label of the item.
71  *
72  * Since: 2.32
73  **/
74 #define G_MENU_ATTRIBUTE_LABEL "label"
75
76 /**
77  * G_MENU_ATTRIBUTE_ICON:
78  *
79  * The menu item attribute which holds the icon of the item.
80  *
81  * The icon is stored in the format returned by g_icon_serialize().
82  *
83  * This attribute is intended only to represent 'noun' icons such as
84  * favicons for a webpage, or application icons.  It should not be used
85  * for 'verbs' (ie: stock icons).
86  *
87  * Since: 2.38
88  **/
89 #define G_MENU_ATTRIBUTE_ICON "icon"
90
91 /**
92  * G_MENU_LINK_SUBMENU:
93  *
94  * The name of the link that associates a menu item with a submenu.
95  *
96  * See also g_menu_item_set_link().
97  *
98  * Since: 2.32
99  **/
100 #define G_MENU_LINK_SUBMENU "submenu"
101
102 /**
103  * G_MENU_LINK_SECTION:
104  *
105  * The name of the link that associates a menu item with a section.  The linked
106  * menu will usually be shown in place of the menu item, using the item's label
107  * as a header.
108  *
109  * See also g_menu_item_set_link().
110  *
111  * Since: 2.32
112  **/
113 #define G_MENU_LINK_SECTION "section"
114
115 #define G_TYPE_MENU_MODEL                                   (g_menu_model_get_type ())
116 #define G_MENU_MODEL(inst)                                  (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
117                                                              G_TYPE_MENU_MODEL, GMenuModel))
118 #define G_MENU_MODEL_CLASS(class)                           (G_TYPE_CHECK_CLASS_CAST ((class),                       \
119                                                              G_TYPE_MENU_MODEL, GMenuModelClass))
120 #define G_IS_MENU_MODEL(inst)                               (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
121                                                              G_TYPE_MENU_MODEL))
122 #define G_IS_MENU_MODEL_CLASS(class)                        (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
123                                                              G_TYPE_MENU_MODEL))
124 #define G_MENU_MODEL_GET_CLASS(inst)                        (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
125                                                              G_TYPE_MENU_MODEL, GMenuModelClass))
126
127 typedef struct _GMenuModelPrivate                           GMenuModelPrivate;
128 typedef struct _GMenuModelClass                             GMenuModelClass;
129
130 typedef struct _GMenuAttributeIterPrivate                   GMenuAttributeIterPrivate;
131 typedef struct _GMenuAttributeIterClass                     GMenuAttributeIterClass;
132 typedef struct _GMenuAttributeIter                          GMenuAttributeIter;
133
134 typedef struct _GMenuLinkIterPrivate                        GMenuLinkIterPrivate;
135 typedef struct _GMenuLinkIterClass                          GMenuLinkIterClass;
136 typedef struct _GMenuLinkIter                               GMenuLinkIter;
137
138 struct _GMenuModel
139 {
140   GObject            parent_instance;
141   GMenuModelPrivate *priv;
142 };
143
144 struct _GMenuModelClass
145 {
146   GObjectClass parent_class;
147
148   gboolean              (*is_mutable)                       (GMenuModel          *model);
149   gint                  (*get_n_items)                      (GMenuModel          *model);
150   void                  (*get_item_attributes)              (GMenuModel          *model,
151                                                              gint                 item_index,
152                                                              GHashTable         **attributes);
153   GMenuAttributeIter *  (*iterate_item_attributes)          (GMenuModel          *model,
154                                                              gint                 item_index);
155   GVariant *            (*get_item_attribute_value)         (GMenuModel          *model,
156                                                              gint                 item_index,
157                                                              const gchar         *attribute,
158                                                              const GVariantType  *expected_type);
159   void                  (*get_item_links)                   (GMenuModel          *model,
160                                                              gint                 item_index,
161                                                              GHashTable         **links);
162   GMenuLinkIter *       (*iterate_item_links)               (GMenuModel          *model,
163                                                              gint                 item_index);
164   GMenuModel *          (*get_item_link)                    (GMenuModel          *model,
165                                                              gint                 item_index,
166                                                              const gchar         *link);
167 };
168
169 GLIB_AVAILABLE_IN_2_32
170 GType                   g_menu_model_get_type                           (void) G_GNUC_CONST;
171
172 GLIB_AVAILABLE_IN_2_32
173 gboolean                g_menu_model_is_mutable                         (GMenuModel         *model);
174 GLIB_AVAILABLE_IN_2_32
175 gint                    g_menu_model_get_n_items                        (GMenuModel         *model);
176
177 GLIB_AVAILABLE_IN_2_32
178 GMenuAttributeIter *    g_menu_model_iterate_item_attributes            (GMenuModel         *model,
179                                                                          gint                item_index);
180 GLIB_AVAILABLE_IN_2_32
181 GVariant *              g_menu_model_get_item_attribute_value           (GMenuModel         *model,
182                                                                          gint                item_index,
183                                                                          const gchar        *attribute,
184                                                                          const GVariantType *expected_type);
185 GLIB_AVAILABLE_IN_2_32
186 gboolean                g_menu_model_get_item_attribute                 (GMenuModel         *model,
187                                                                          gint                item_index,
188                                                                          const gchar        *attribute,
189                                                                          const gchar        *format_string,
190                                                                          ...);
191 GLIB_AVAILABLE_IN_2_32
192 GMenuLinkIter *         g_menu_model_iterate_item_links                 (GMenuModel         *model,
193                                                                          gint                item_index);
194 GLIB_AVAILABLE_IN_2_32
195 GMenuModel *            g_menu_model_get_item_link                      (GMenuModel         *model,
196                                                                          gint                item_index,
197                                                                          const gchar        *link);
198
199 GLIB_AVAILABLE_IN_2_32
200 void                    g_menu_model_items_changed                      (GMenuModel         *model,
201                                                                          gint                position,
202                                                                          gint                removed,
203                                                                          gint                added);
204
205
206 #define G_TYPE_MENU_ATTRIBUTE_ITER                          (g_menu_attribute_iter_get_type ())
207 #define G_MENU_ATTRIBUTE_ITER(inst)                         (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
208                                                              G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIter))
209 #define G_MENU_ATTRIBUTE_ITER_CLASS(class)                  (G_TYPE_CHECK_CLASS_CAST ((class),                       \
210                                                              G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterClass))
211 #define G_IS_MENU_ATTRIBUTE_ITER(inst)                      (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
212                                                              G_TYPE_MENU_ATTRIBUTE_ITER))
213 #define G_IS_MENU_ATTRIBUTE_ITER_CLASS(class)               (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
214                                                              G_TYPE_MENU_ATTRIBUTE_ITER))
215 #define G_MENU_ATTRIBUTE_ITER_GET_CLASS(inst)               (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
216                                                              G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterClass))
217
218 struct _GMenuAttributeIter
219 {
220   GObject parent_instance;
221   GMenuAttributeIterPrivate *priv;
222 };
223
224 struct _GMenuAttributeIterClass
225 {
226   GObjectClass parent_class;
227
228   gboolean      (*get_next) (GMenuAttributeIter  *iter,
229                              const gchar        **out_name,
230                              GVariant           **value);
231 };
232
233 GLIB_AVAILABLE_IN_2_32
234 GType                   g_menu_attribute_iter_get_type                  (void) G_GNUC_CONST;
235
236 GLIB_AVAILABLE_IN_2_32
237 gboolean                g_menu_attribute_iter_get_next                  (GMenuAttributeIter  *iter,
238                                                                          const gchar        **out_name,
239                                                                          GVariant           **value);
240 GLIB_AVAILABLE_IN_2_32
241 gboolean                g_menu_attribute_iter_next                      (GMenuAttributeIter  *iter);
242 GLIB_AVAILABLE_IN_2_32
243 const gchar *           g_menu_attribute_iter_get_name                  (GMenuAttributeIter  *iter);
244 GLIB_AVAILABLE_IN_2_32
245 GVariant *              g_menu_attribute_iter_get_value                 (GMenuAttributeIter  *iter);
246
247
248 #define G_TYPE_MENU_LINK_ITER                               (g_menu_link_iter_get_type ())
249 #define G_MENU_LINK_ITER(inst)                              (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
250                                                              G_TYPE_MENU_LINK_ITER, GMenuLinkIter))
251 #define G_MENU_LINK_ITER_CLASS(class)                       (G_TYPE_CHECK_CLASS_CAST ((class),                       \
252                                                              G_TYPE_MENU_LINK_ITER, GMenuLinkIterClass))
253 #define G_IS_MENU_LINK_ITER(inst)                           (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
254                                                              G_TYPE_MENU_LINK_ITER))
255 #define G_IS_MENU_LINK_ITER_CLASS(class)                    (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
256                                                              G_TYPE_MENU_LINK_ITER))
257 #define G_MENU_LINK_ITER_GET_CLASS(inst)                    (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
258                                                              G_TYPE_MENU_LINK_ITER, GMenuLinkIterClass))
259
260 struct _GMenuLinkIter
261 {
262   GObject parent_instance;
263   GMenuLinkIterPrivate *priv;
264 };
265
266 struct _GMenuLinkIterClass
267 {
268   GObjectClass parent_class;
269
270   gboolean      (*get_next) (GMenuLinkIter  *iter,
271                              const gchar   **out_link,
272                              GMenuModel    **value);
273 };
274
275 GLIB_AVAILABLE_IN_2_32
276 GType                   g_menu_link_iter_get_type                       (void) G_GNUC_CONST;
277
278 GLIB_AVAILABLE_IN_2_32
279 gboolean                g_menu_link_iter_get_next                       (GMenuLinkIter  *iter,
280                                                                          const gchar   **out_link,
281                                                                          GMenuModel    **value);
282 GLIB_AVAILABLE_IN_2_32
283 gboolean                g_menu_link_iter_next                           (GMenuLinkIter  *iter);
284 GLIB_AVAILABLE_IN_2_32
285 const gchar *           g_menu_link_iter_get_name                       (GMenuLinkIter  *iter);
286 GLIB_AVAILABLE_IN_2_32
287 GMenuModel *            g_menu_link_iter_get_value                      (GMenuLinkIter  *iter);
288
289 G_END_DECLS
290
291 #endif /* __G_MENU_MODEL_H__ */