gmenumodel.h 14 KB
Newer Older
Matthias Clasen's avatar
Matthias Clasen committed
1 2 3
/*
 * Copyright © 2011 Canonical Ltd.
 *
4 5 6 7
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
Matthias Clasen's avatar
Matthias Clasen committed
8 9 10 11 12 13 14
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * 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/>.
Matthias Clasen's avatar
Matthias Clasen committed
16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * Author: Ryan Lortie <desrt@desrt.ca>
 */

#ifndef __G_MENU_MODEL_H__
#define __G_MENU_MODEL_H__

#include <glib-object.h>

#include <gio/giotypes.h>

G_BEGIN_DECLS

29 30 31 32 33 34 35 36 37 38 39 40
/**
 * G_MENU_ATTRIBUTE_ACTION:
 *
 * The menu item attribute which holds the action name of the item.  Action
 * names are namespaced with an identifier for the action group in which the
 * action resides. For example, "win." for window-specific actions and "app."
 * for application-wide actions.
 *
 * See also g_menu_model_get_item_attribute() and g_menu_item_set_attribute().
 *
 * Since: 2.32
 **/
Matthias Clasen's avatar
Matthias Clasen committed
41
#define G_MENU_ATTRIBUTE_ACTION "action"
42

43 44 45 46 47 48 49 50 51 52
/**
 * G_MENU_ATTRIBUTE_ACTION_NAMESPACE:
 *
 * The menu item attribute that holds the namespace for all action names in
 * menus that are linked from this item.
 *
 * Since: 2.36
 **/
#define G_MENU_ATTRIBUTE_ACTION_NAMESPACE "action-namespace"

53 54 55 56 57 58 59 60 61 62
/**
 * G_MENU_ATTRIBUTE_TARGET:
 *
 * The menu item attribute which holds the target with which the item's action
 * will be activated.
 *
 * See also g_menu_item_set_action_and_target()
 *
 * Since: 2.32
 **/
Matthias Clasen's avatar
Matthias Clasen committed
63
#define G_MENU_ATTRIBUTE_TARGET "target"
64 65 66 67 68 69 70 71

/**
 * G_MENU_ATTRIBUTE_LABEL:
 *
 * The menu item attribute which holds the label of the item.
 *
 * Since: 2.32
 **/
Matthias Clasen's avatar
Matthias Clasen committed
72 73
#define G_MENU_ATTRIBUTE_LABEL "label"

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
/**
 * G_MENU_ATTRIBUTE_ICON:
 *
 * The menu item attribute which holds the icon of the item.
 *
 * The icon is stored in the format returned by g_icon_serialize().
 *
 * This attribute is intended only to represent 'noun' icons such as
 * favicons for a webpage, or application icons.  It should not be used
 * for 'verbs' (ie: stock icons).
 *
 * Since: 2.38
 **/
#define G_MENU_ATTRIBUTE_ICON "icon"

89 90 91 92 93 94 95 96 97
/**
 * G_MENU_LINK_SUBMENU:
 *
 * The name of the link that associates a menu item with a submenu.
 *
 * See also g_menu_item_set_link().
 *
 * Since: 2.32
 **/
Matthias Clasen's avatar
Matthias Clasen committed
98
#define G_MENU_LINK_SUBMENU "submenu"
99 100

/**
101
 * G_MENU_LINK_SECTION:
102 103 104 105 106 107 108 109 110
 *
 * The name of the link that associates a menu item with a section.  The linked
 * menu will usually be shown in place of the menu item, using the item's label
 * as a header.
 *
 * See also g_menu_item_set_link().
 *
 * Since: 2.32
 **/
Matthias Clasen's avatar
Matthias Clasen committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
#define G_MENU_LINK_SECTION "section"

#define G_TYPE_MENU_MODEL                                   (g_menu_model_get_type ())
#define G_MENU_MODEL(inst)                                  (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
                                                             G_TYPE_MENU_MODEL, GMenuModel))
#define G_MENU_MODEL_CLASS(class)                           (G_TYPE_CHECK_CLASS_CAST ((class),                       \
                                                             G_TYPE_MENU_MODEL, GMenuModelClass))
#define G_IS_MENU_MODEL(inst)                               (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
                                                             G_TYPE_MENU_MODEL))
#define G_IS_MENU_MODEL_CLASS(class)                        (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
                                                             G_TYPE_MENU_MODEL))
#define G_MENU_MODEL_GET_CLASS(inst)                        (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
                                                             G_TYPE_MENU_MODEL, GMenuModelClass))

typedef struct _GMenuModelPrivate                           GMenuModelPrivate;
typedef struct _GMenuModelClass                             GMenuModelClass;

typedef struct _GMenuAttributeIterPrivate                   GMenuAttributeIterPrivate;
typedef struct _GMenuAttributeIterClass                     GMenuAttributeIterClass;
typedef struct _GMenuAttributeIter                          GMenuAttributeIter;

typedef struct _GMenuLinkIterPrivate                        GMenuLinkIterPrivate;
typedef struct _GMenuLinkIterClass                          GMenuLinkIterClass;
typedef struct _GMenuLinkIter                               GMenuLinkIter;

struct _GMenuModel
{
  GObject            parent_instance;
  GMenuModelPrivate *priv;
};

142 143 144 145 146 147 148 149 150 151 152 153
/**
 * GMenuModelClass::get_item_attributes:
 * @model: the #GMenuModel to query
 * @item_index: The #GMenuItem to query
 * @attributes: (out) (element-type utf8 GLib.Variant): Attributes on the item
 *
 * Gets all the attributes associated with the item in the menu model.
 */
/**
 * GMenuModelClass::get_item_links:
 * @model: the #GMenuModel to query
 * @item_index: The #GMenuItem to query
154
 * @links: (out) (element-type utf8 Gio.MenuModel): Links from the item
155 156 157
 *
 * Gets all the links associated with the item in the menu model.
 */
Matthias Clasen's avatar
Matthias Clasen committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
struct _GMenuModelClass
{
  GObjectClass parent_class;

  gboolean              (*is_mutable)                       (GMenuModel          *model);
  gint                  (*get_n_items)                      (GMenuModel          *model);
  void                  (*get_item_attributes)              (GMenuModel          *model,
                                                             gint                 item_index,
                                                             GHashTable         **attributes);
  GMenuAttributeIter *  (*iterate_item_attributes)          (GMenuModel          *model,
                                                             gint                 item_index);
  GVariant *            (*get_item_attribute_value)         (GMenuModel          *model,
                                                             gint                 item_index,
                                                             const gchar         *attribute,
                                                             const GVariantType  *expected_type);
  void                  (*get_item_links)                   (GMenuModel          *model,
                                                             gint                 item_index,
                                                             GHashTable         **links);
  GMenuLinkIter *       (*iterate_item_links)               (GMenuModel          *model,
                                                             gint                 item_index);
  GMenuModel *          (*get_item_link)                    (GMenuModel          *model,
                                                             gint                 item_index,
                                                             const gchar         *link);
};

183
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
184 185
GType                   g_menu_model_get_type                           (void) G_GNUC_CONST;

186
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
187
gboolean                g_menu_model_is_mutable                         (GMenuModel         *model);
188
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
189 190
gint                    g_menu_model_get_n_items                        (GMenuModel         *model);

191
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
192 193
GMenuAttributeIter *    g_menu_model_iterate_item_attributes            (GMenuModel         *model,
                                                                         gint                item_index);
194
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
195 196 197 198
GVariant *              g_menu_model_get_item_attribute_value           (GMenuModel         *model,
                                                                         gint                item_index,
                                                                         const gchar        *attribute,
                                                                         const GVariantType *expected_type);
199
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
200 201 202 203 204
gboolean                g_menu_model_get_item_attribute                 (GMenuModel         *model,
                                                                         gint                item_index,
                                                                         const gchar        *attribute,
                                                                         const gchar        *format_string,
                                                                         ...);
205
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
206 207
GMenuLinkIter *         g_menu_model_iterate_item_links                 (GMenuModel         *model,
                                                                         gint                item_index);
208
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
209 210 211 212
GMenuModel *            g_menu_model_get_item_link                      (GMenuModel         *model,
                                                                         gint                item_index,
                                                                         const gchar        *link);

213
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
void                    g_menu_model_items_changed                      (GMenuModel         *model,
                                                                         gint                position,
                                                                         gint                removed,
                                                                         gint                added);


#define G_TYPE_MENU_ATTRIBUTE_ITER                          (g_menu_attribute_iter_get_type ())
#define G_MENU_ATTRIBUTE_ITER(inst)                         (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
                                                             G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIter))
#define G_MENU_ATTRIBUTE_ITER_CLASS(class)                  (G_TYPE_CHECK_CLASS_CAST ((class),                       \
                                                             G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterClass))
#define G_IS_MENU_ATTRIBUTE_ITER(inst)                      (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
                                                             G_TYPE_MENU_ATTRIBUTE_ITER))
#define G_IS_MENU_ATTRIBUTE_ITER_CLASS(class)               (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
                                                             G_TYPE_MENU_ATTRIBUTE_ITER))
#define G_MENU_ATTRIBUTE_ITER_GET_CLASS(inst)               (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
                                                             G_TYPE_MENU_ATTRIBUTE_ITER, GMenuAttributeIterClass))

struct _GMenuAttributeIter
{
  GObject parent_instance;
  GMenuAttributeIterPrivate *priv;
};

struct _GMenuAttributeIterClass
{
  GObjectClass parent_class;

  gboolean      (*get_next) (GMenuAttributeIter  *iter,
Jasper St. Pierre's avatar
Jasper St. Pierre committed
243
                             const gchar        **out_name,
Matthias Clasen's avatar
Matthias Clasen committed
244 245 246
                             GVariant           **value);
};

247
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
248 249
GType                   g_menu_attribute_iter_get_type                  (void) G_GNUC_CONST;

250
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
251 252 253
gboolean                g_menu_attribute_iter_get_next                  (GMenuAttributeIter  *iter,
                                                                         const gchar        **out_name,
                                                                         GVariant           **value);
254
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
255
gboolean                g_menu_attribute_iter_next                      (GMenuAttributeIter  *iter);
256
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
257
const gchar *           g_menu_attribute_iter_get_name                  (GMenuAttributeIter  *iter);
258
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
GVariant *              g_menu_attribute_iter_get_value                 (GMenuAttributeIter  *iter);


#define G_TYPE_MENU_LINK_ITER                               (g_menu_link_iter_get_type ())
#define G_MENU_LINK_ITER(inst)                              (G_TYPE_CHECK_INSTANCE_CAST ((inst),                     \
                                                             G_TYPE_MENU_LINK_ITER, GMenuLinkIter))
#define G_MENU_LINK_ITER_CLASS(class)                       (G_TYPE_CHECK_CLASS_CAST ((class),                       \
                                                             G_TYPE_MENU_LINK_ITER, GMenuLinkIterClass))
#define G_IS_MENU_LINK_ITER(inst)                           (G_TYPE_CHECK_INSTANCE_TYPE ((inst),                     \
                                                             G_TYPE_MENU_LINK_ITER))
#define G_IS_MENU_LINK_ITER_CLASS(class)                    (G_TYPE_CHECK_CLASS_TYPE ((class),                       \
                                                             G_TYPE_MENU_LINK_ITER))
#define G_MENU_LINK_ITER_GET_CLASS(inst)                    (G_TYPE_INSTANCE_GET_CLASS ((inst),                      \
                                                             G_TYPE_MENU_LINK_ITER, GMenuLinkIterClass))

struct _GMenuLinkIter
{
  GObject parent_instance;
  GMenuLinkIterPrivate *priv;
};

struct _GMenuLinkIterClass
{
  GObjectClass parent_class;

  gboolean      (*get_next) (GMenuLinkIter  *iter,
Jasper St. Pierre's avatar
Jasper St. Pierre committed
285
                             const gchar   **out_link,
Matthias Clasen's avatar
Matthias Clasen committed
286 287 288
                             GMenuModel    **value);
};

289
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
290 291
GType                   g_menu_link_iter_get_type                       (void) G_GNUC_CONST;

292
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
293 294 295
gboolean                g_menu_link_iter_get_next                       (GMenuLinkIter  *iter,
                                                                         const gchar   **out_link,
                                                                         GMenuModel    **value);
296
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
297
gboolean                g_menu_link_iter_next                           (GMenuLinkIter  *iter);
298
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
299
const gchar *           g_menu_link_iter_get_name                       (GMenuLinkIter  *iter);
300
GLIB_AVAILABLE_IN_2_32
Matthias Clasen's avatar
Matthias Clasen committed
301 302 303 304 305
GMenuModel *            g_menu_link_iter_get_value                      (GMenuLinkIter  *iter);

G_END_DECLS

#endif /* __G_MENU_MODEL_H__ */