~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to libslab/themed-icon.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of libslab.
3
 
 *
4
 
 * Copyright (c) 2006 Novell, Inc.
5
 
 *
6
 
 * Libslab is free software; you can redistribute it and/or modify it under the
7
 
 * terms of the GNU Lesser General Public License as published by the Free
8
 
 * Software Foundation; either version 2 of the License, or (at your option)
9
 
 * any later version.
10
 
 *
11
 
 * Libslab is distributed in the hope that it will be useful, but WITHOUT ANY
12
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
14
 
 * more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public License
17
 
 * along with libslab; if not, write to the Free Software Foundation, Inc., 51
18
 
 * Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "themed-icon.h"
22
 
 
23
 
#include "gnome-utils.h"
24
 
 
25
 
static void themed_icon_class_init (ThemedIconClass *);
26
 
static void themed_icon_init (ThemedIcon *);
27
 
static void themed_icon_finalize (GObject *);
28
 
static void themed_icon_get_property (GObject *, guint, GValue *, GParamSpec *);
29
 
static void themed_icon_set_property (GObject *, guint, const GValue *, GParamSpec *);
30
 
 
31
 
static void themed_icon_show (GtkWidget *);
32
 
static void themed_icon_style_set (GtkWidget *, GtkStyle *);
33
 
 
34
 
enum
35
 
{
36
 
        PROP_0,
37
 
        PROP_ICON_ID,
38
 
        PROP_ICON_SIZE
39
 
};
40
 
 
41
 
typedef struct
42
 
{
43
 
        gboolean icon_loaded;
44
 
} ThemedIconPrivate;
45
 
 
46
 
#define THEMED_ICON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), THEMED_ICON_TYPE, ThemedIconPrivate))
47
 
 
48
 
G_DEFINE_TYPE (ThemedIcon, themed_icon, GTK_TYPE_IMAGE)
49
 
 
50
 
static void themed_icon_class_init (ThemedIconClass * themed_icon_class)
51
 
{
52
 
        GObjectClass *g_obj_class = G_OBJECT_CLASS (themed_icon_class);
53
 
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (themed_icon_class);
54
 
 
55
 
        g_obj_class->get_property = themed_icon_get_property;
56
 
        g_obj_class->set_property = themed_icon_set_property;
57
 
        g_obj_class->finalize = themed_icon_finalize;
58
 
 
59
 
        widget_class->show = themed_icon_show;
60
 
        widget_class->style_set = themed_icon_style_set;
61
 
 
62
 
        g_type_class_add_private (themed_icon_class, sizeof (ThemedIconPrivate));
63
 
 
64
 
        g_object_class_install_property (g_obj_class, PROP_ICON_ID, g_param_spec_string ("icon-id",
65
 
                        "icon-id", "the identifier of the icon", NULL,
66
 
                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
67
 
 
68
 
        g_object_class_install_property (g_obj_class, PROP_ICON_SIZE,
69
 
                g_param_spec_enum ("icon-size", "icon-size", "the size of the icon",
70
 
                        GTK_TYPE_ICON_SIZE, GTK_ICON_SIZE_BUTTON,
71
 
                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
72
 
}
73
 
 
74
 
static void
75
 
themed_icon_init (ThemedIcon * icon)
76
 
{
77
 
        ThemedIconPrivate *priv = THEMED_ICON_GET_PRIVATE (icon);
78
 
 
79
 
        priv->icon_loaded = FALSE;
80
 
}
81
 
 
82
 
GtkWidget *
83
 
themed_icon_new (const gchar * id, GtkIconSize size)
84
 
{
85
 
        GtkWidget *icon = GTK_WIDGET (g_object_new (
86
 
                THEMED_ICON_TYPE, "icon-id", id, "icon-size", size, NULL));
87
 
 
88
 
        return icon;
89
 
}
90
 
 
91
 
static void
92
 
themed_icon_finalize (GObject * object)
93
 
{
94
 
        ThemedIcon *icon = THEMED_ICON (object);
95
 
        if (icon->id)
96
 
                g_free (icon->id);
97
 
        (*G_OBJECT_CLASS (themed_icon_parent_class)->finalize) (object);
98
 
}
99
 
 
100
 
static void
101
 
themed_icon_get_property (GObject * g_obj, guint prop_id, GValue * value, GParamSpec * param_spec)
102
 
{
103
 
        ThemedIcon *icon = THEMED_ICON (g_obj);
104
 
 
105
 
        switch (prop_id)
106
 
        {
107
 
        case PROP_ICON_ID:
108
 
                g_value_set_string (value, icon->id);
109
 
                break;
110
 
 
111
 
        case PROP_ICON_SIZE:
112
 
                g_value_set_enum (value, icon->size);
113
 
                break;
114
 
 
115
 
        default:
116
 
                break;
117
 
        }
118
 
}
119
 
 
120
 
static void
121
 
themed_icon_set_property (GObject * g_obj, guint prop_id, const GValue * value,
122
 
        GParamSpec * param_spec)
123
 
{
124
 
        ThemedIcon *icon = THEMED_ICON (g_obj);
125
 
 
126
 
        switch (prop_id)
127
 
        {
128
 
        case PROP_ICON_ID:
129
 
                icon->id = g_strdup (g_value_get_string (value));
130
 
 
131
 
/*                      gtk_image_load_by_id (GTK_IMAGE (icon), icon->size, icon->id); */
132
 
 
133
 
                break;
134
 
 
135
 
        case PROP_ICON_SIZE:
136
 
                icon->size = g_value_get_enum (value);
137
 
 
138
 
/*                      gtk_image_load_by_id (GTK_IMAGE (icon), icon->size, icon->id); */
139
 
 
140
 
                break;
141
 
 
142
 
        default:
143
 
                break;
144
 
        }
145
 
}
146
 
 
147
 
static void
148
 
themed_icon_show (GtkWidget * widget)
149
 
{
150
 
        ThemedIcon *icon = THEMED_ICON (widget);
151
 
        ThemedIconPrivate *priv = THEMED_ICON_GET_PRIVATE (icon);
152
 
 
153
 
        if (!priv->icon_loaded)
154
 
                priv->icon_loaded = load_image_by_id (GTK_IMAGE (icon), icon->size, icon->id);
155
 
 
156
 
        (*GTK_WIDGET_CLASS (themed_icon_parent_class)->show) (widget);
157
 
}
158
 
 
159
 
static void
160
 
themed_icon_style_set (GtkWidget * widget, GtkStyle * prev_style)
161
 
{
162
 
        ThemedIcon *icon = THEMED_ICON (widget);
163
 
 
164
 
        load_image_by_id (GTK_IMAGE (icon), icon->size, icon->id);
165
 
}