~larsu/indicator-messages/set-status-return-value

« back to all changes in this revision

Viewing changes to src/gmenuutils.c

  • Committer: Tarmac
  • Author(s): Lars Uebernickel
  • Date: 2013-09-09 14:32:02 UTC
  • mfrom: (375.2.6 use-gicon-serialize)
  • Revision ID: tarmac-20130909143202-iip1qcm9w2mcqq6w
Use g_icon_serialize() instead of g_icon_to_string().

Approved by Charles Kerr, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2012 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU General Public License version 3, as published
6
 
 * by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
 
 * PURPOSE.  See the GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License along
14
 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authors:
17
 
 *     Lars Uebernickel <lars.uebernickel@canonical.com>
18
 
 */
19
 
 
20
 
#include "gmenuutils.h"
21
 
#include "dbus-data.h"
22
 
 
23
 
/* g_menu_find_section:
24
 
 * @menu: a #GMenu
25
 
 * @section: the section to be found in @menu
26
 
 *
27
 
 * @Returns the index of the first menu item that is linked to #section, or -1
28
 
 * if there's no such item.
29
 
 */
30
 
int
31
 
g_menu_find_section (GMenu      *menu,
32
 
                     GMenuModel *section)
33
 
{
34
 
  GMenuModel *model = G_MENU_MODEL (menu);
35
 
  int n_items;
36
 
  int i;
37
 
 
38
 
  g_return_val_if_fail (G_IS_MENU_MODEL (section), -1);
39
 
 
40
 
  n_items = g_menu_model_get_n_items (model);
41
 
  for (i = 0; i < n_items; i++)
42
 
    {
43
 
      GMenuModel *link;
44
 
      gboolean found;
45
 
 
46
 
      link = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);
47
 
      found = section == link;
48
 
 
49
 
      g_object_unref (link);
50
 
 
51
 
      if (found)
52
 
        return i;
53
 
    }
54
 
 
55
 
  return -1;
56
 
}
57
 
 
58
 
 
59
 
void
60
 
g_menu_append_with_icon (GMenu *menu,
61
 
                         const gchar *label,
62
 
                         GIcon *icon,
63
 
                         const gchar *detailed_action)
64
 
{
65
 
  gchar *iconstr;
66
 
 
67
 
  iconstr = g_icon_to_string (icon);
68
 
  g_menu_append_with_icon_name (menu, label, iconstr, detailed_action);
69
 
 
70
 
  g_free (iconstr);
71
 
}
72
 
 
73
 
void
74
 
g_menu_append_with_icon_name (GMenu *menu,
75
 
                              const gchar *label,
76
 
                              const gchar *icon_name,
77
 
                              const gchar *detailed_action)
78
 
{
79
 
  GMenuItem *item;
80
 
 
81
 
  item = g_menu_item_new (label, detailed_action);
82
 
  g_menu_item_set_attribute (item, "icon", "s", icon_name);
83
 
 
84
 
  g_menu_append_item (menu, item);
85
 
 
86
 
  g_object_unref (item);
87
 
}