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

« back to all changes in this revision

Viewing changes to libslab/nameplate-tile.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 libtile.
3
 
 *
4
 
 * Copyright (c) 2006 Novell, Inc.
5
 
 *
6
 
 * Libtile 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
 
 * Libtile 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 "nameplate-tile.h"
22
 
 
23
 
static void nameplate_tile_class_init (NameplateTileClass *);
24
 
static void nameplate_tile_init (NameplateTile *);
25
 
static void nameplate_tile_finalize (GObject *);
26
 
static void nameplate_tile_get_property (GObject *, guint, GValue *, GParamSpec *);
27
 
static void nameplate_tile_set_property (GObject *, guint, const GValue *, GParamSpec *);
28
 
static GObject *nameplate_tile_constructor (GType, guint, GObjectConstructParam *);
29
 
 
30
 
static void nameplate_tile_drag_begin (GtkWidget *, GdkDragContext *);
31
 
 
32
 
static void nameplate_tile_setup (NameplateTile *);
33
 
 
34
 
typedef struct
35
 
{
36
 
        GtkContainer *image_ctnr;
37
 
        GtkContainer *header_ctnr;
38
 
        GtkContainer *subheader_ctnr;
39
 
} NameplateTilePrivate;
40
 
 
41
 
#define NAMEPLATE_TILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAMEPLATE_TILE_TYPE, NameplateTilePrivate))
42
 
 
43
 
enum
44
 
{
45
 
        PROP_0,
46
 
        PROP_NAMEPLATE_IMAGE,
47
 
        PROP_NAMEPLATE_HEADER,
48
 
        PROP_NAMEPLATE_SUBHEADER,
49
 
};
50
 
 
51
 
G_DEFINE_TYPE (NameplateTile, nameplate_tile, TILE_TYPE)
52
 
 
53
 
GtkWidget *nameplate_tile_new (const gchar * uri, GtkWidget * image, GtkWidget * header,
54
 
        GtkWidget * subheader)
55
 
{
56
 
        return GTK_WIDGET (
57
 
                g_object_new (NAMEPLATE_TILE_TYPE,
58
 
                "tile-uri",            uri,
59
 
                "nameplate-image",     image,
60
 
                "nameplate-header",    header,
61
 
                "nameplate-subheader", subheader, 
62
 
                NULL));
63
 
}
64
 
 
65
 
static void
66
 
nameplate_tile_class_init (NameplateTileClass * this_class)
67
 
{
68
 
        GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class);
69
 
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (this_class);
70
 
 
71
 
        g_obj_class->constructor = nameplate_tile_constructor;
72
 
        g_obj_class->get_property = nameplate_tile_get_property;
73
 
        g_obj_class->set_property = nameplate_tile_set_property;
74
 
        g_obj_class->finalize = nameplate_tile_finalize;
75
 
 
76
 
        widget_class->drag_begin = nameplate_tile_drag_begin;
77
 
 
78
 
        g_type_class_add_private (this_class, sizeof (NameplateTilePrivate));
79
 
 
80
 
        g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_IMAGE,
81
 
                g_param_spec_object ("nameplate-image", "nameplate-image", "nameplate image",
82
 
                        GTK_TYPE_WIDGET, G_PARAM_READWRITE));
83
 
 
84
 
        g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_HEADER,
85
 
                g_param_spec_object ("nameplate-header", "nameplate-header", "nameplate header",
86
 
                        GTK_TYPE_WIDGET, G_PARAM_READWRITE));
87
 
 
88
 
        g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_SUBHEADER,
89
 
                g_param_spec_object ("nameplate-subheader", "nameplate-subheader",
90
 
                        "nameplate subheader", GTK_TYPE_WIDGET, G_PARAM_READWRITE));
91
 
}
92
 
 
93
 
static void
94
 
nameplate_tile_init (NameplateTile * this)
95
 
{
96
 
}
97
 
 
98
 
static GObject *
99
 
nameplate_tile_constructor (GType type, guint n_param, GObjectConstructParam * param)
100
 
{
101
 
        GObject *g_obj =
102
 
                (*G_OBJECT_CLASS (nameplate_tile_parent_class)->constructor) (type, n_param, param);
103
 
 
104
 
        nameplate_tile_setup (NAMEPLATE_TILE (g_obj));
105
 
 
106
 
        return g_obj;
107
 
}
108
 
 
109
 
static void
110
 
nameplate_tile_finalize (GObject * g_object)
111
 
{
112
 
        NameplateTile *np_tile;
113
 
        NameplateTilePrivate *priv;
114
 
 
115
 
        np_tile = NAMEPLATE_TILE (g_object);
116
 
        priv = NAMEPLATE_TILE_GET_PRIVATE (np_tile);
117
 
 
118
 
        (*G_OBJECT_CLASS (nameplate_tile_parent_class)->finalize) (g_object);
119
 
}
120
 
 
121
 
static void
122
 
nameplate_tile_get_property (GObject * g_object, guint prop_id, GValue * value,
123
 
        GParamSpec * param_spec)
124
 
{
125
 
        NameplateTile *np_tile = NAMEPLATE_TILE (g_object);
126
 
 
127
 
        switch (prop_id)
128
 
        {
129
 
        case PROP_NAMEPLATE_IMAGE:
130
 
                g_value_set_object (value, np_tile->image);
131
 
                break;
132
 
 
133
 
        case PROP_NAMEPLATE_HEADER:
134
 
                g_value_set_object (value, np_tile->header);
135
 
                break;
136
 
 
137
 
        case PROP_NAMEPLATE_SUBHEADER:
138
 
                g_value_set_object (value, np_tile->subheader);
139
 
                break;
140
 
        default:
141
 
                break;
142
 
        }
143
 
}
144
 
 
145
 
static void
146
 
nameplate_tile_set_property (GObject * g_object, guint prop_id, const GValue * value,
147
 
        GParamSpec * param_spec)
148
 
{
149
 
        NameplateTile *this = NAMEPLATE_TILE (g_object);
150
 
        NameplateTilePrivate *priv = NAMEPLATE_TILE_GET_PRIVATE (this);
151
 
 
152
 
        GObject *widget_obj = NULL;
153
 
 
154
 
        switch (prop_id) {
155
 
                case PROP_NAMEPLATE_IMAGE:
156
 
                case PROP_NAMEPLATE_HEADER:
157
 
                case PROP_NAMEPLATE_SUBHEADER:
158
 
                        widget_obj = g_value_get_object (value);
159
 
                        break;
160
 
                default:
161
 
                        break;
162
 
        }
163
 
 
164
 
        switch (prop_id)
165
 
        {
166
 
        case PROP_NAMEPLATE_IMAGE:
167
 
                if (GTK_IS_WIDGET (widget_obj))
168
 
                {
169
 
                        if (GTK_IS_WIDGET (this->image))
170
 
                                gtk_widget_destroy (this->image);
171
 
 
172
 
                        this->image = GTK_WIDGET (widget_obj);
173
 
 
174
 
                        gtk_container_add (priv->image_ctnr, this->image);
175
 
 
176
 
                        gtk_widget_show_all (this->image);
177
 
                }
178
 
                else if (GTK_IS_WIDGET (this->image))
179
 
                        gtk_widget_destroy (this->image);
180
 
 
181
 
                break;
182
 
 
183
 
        case PROP_NAMEPLATE_HEADER:
184
 
                if (GTK_IS_WIDGET (widget_obj))
185
 
                {
186
 
                        if (GTK_IS_WIDGET (this->header))
187
 
                                gtk_widget_destroy (this->header);
188
 
 
189
 
                        this->header = GTK_WIDGET (widget_obj);
190
 
 
191
 
                        gtk_container_add (priv->header_ctnr, this->header);
192
 
 
193
 
                        gtk_widget_show_all (this->header);
194
 
                }
195
 
                else if (GTK_IS_WIDGET (this->header))
196
 
                        gtk_widget_destroy (this->header);
197
 
 
198
 
                break;
199
 
 
200
 
        case PROP_NAMEPLATE_SUBHEADER:
201
 
                if (GTK_IS_WIDGET (widget_obj))
202
 
                {
203
 
                        if (GTK_IS_WIDGET (this->subheader))
204
 
                                gtk_widget_destroy (this->subheader);
205
 
 
206
 
                        this->subheader = GTK_WIDGET (widget_obj);
207
 
 
208
 
                        gtk_container_add (priv->subheader_ctnr, this->subheader);
209
 
 
210
 
                        gtk_widget_show_all (this->subheader);
211
 
                }
212
 
                else if (GTK_IS_WIDGET (this->subheader))
213
 
                        gtk_widget_destroy (this->subheader);
214
 
 
215
 
                break;
216
 
 
217
 
        default:
218
 
                break;
219
 
        }
220
 
}
221
 
 
222
 
static void
223
 
nameplate_tile_setup (NameplateTile *this)
224
 
{
225
 
        NameplateTilePrivate *priv = NAMEPLATE_TILE_GET_PRIVATE (this);
226
 
 
227
 
        GtkWidget *hbox;
228
 
        GtkWidget *alignment;
229
 
        GtkWidget *vbox;
230
 
 
231
 
        priv->image_ctnr = GTK_CONTAINER (gtk_alignment_new (0.5, 0.5, 1.0, 1.0));
232
 
        priv->header_ctnr = GTK_CONTAINER (gtk_alignment_new (0.0, 0.5, 1.0, 1.0));
233
 
        priv->subheader_ctnr = GTK_CONTAINER (gtk_alignment_new (0.0, 0.5, 1.0, 1.0));
234
 
 
235
 
        hbox = gtk_hbox_new (FALSE, 6);
236
 
        vbox = gtk_vbox_new (FALSE, 0);
237
 
 
238
 
        alignment = gtk_alignment_new (0.0, 0.5, 1.0, 0.0);
239
 
 
240
 
        gtk_container_add (GTK_CONTAINER (this), hbox);
241
 
        gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (priv->image_ctnr), FALSE, FALSE, 0);
242
 
        gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
243
 
 
244
 
        gtk_container_add (GTK_CONTAINER (alignment), vbox);
245
 
        gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->header_ctnr), FALSE, FALSE, 0);
246
 
        gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->subheader_ctnr), FALSE, FALSE, 0);
247
 
 
248
 
        if (GTK_IS_WIDGET (this->image))
249
 
                gtk_container_add (priv->image_ctnr, this->image);
250
 
 
251
 
        if (GTK_IS_WIDGET (this->header))
252
 
                gtk_container_add (priv->header_ctnr, this->header);
253
 
 
254
 
        if (GTK_IS_WIDGET (this->subheader))
255
 
                gtk_container_add (priv->subheader_ctnr, this->subheader);
256
 
 
257
 
        gtk_button_set_focus_on_click (GTK_BUTTON (this), FALSE);
258
 
}
259
 
 
260
 
static void
261
 
nameplate_tile_drag_begin (GtkWidget * widget, GdkDragContext * context)
262
 
{
263
 
        NameplateTile *this = NAMEPLATE_TILE (widget);
264
 
        GtkImage *image;
265
 
 
266
 
        (*GTK_WIDGET_CLASS (nameplate_tile_parent_class)->drag_begin) (widget, context);
267
 
 
268
 
        if (!this->image || !GTK_IS_IMAGE (this->image))
269
 
                return;
270
 
 
271
 
        image = GTK_IMAGE (this->image);
272
 
 
273
 
        switch (image->storage_type)
274
 
        {
275
 
        case GTK_IMAGE_PIXBUF:
276
 
                if (image->data.pixbuf.pixbuf)
277
 
                        gtk_drag_set_icon_pixbuf (context, image->data.pixbuf.pixbuf, 0, 0);
278
 
 
279
 
                break;
280
 
 
281
 
        case GTK_IMAGE_ICON_NAME:
282
 
                if (image->data.name.pixbuf)
283
 
                        gtk_drag_set_icon_pixbuf (context, image->data.name.pixbuf, 0, 0);
284
 
 
285
 
                break;
286
 
 
287
 
        default:
288
 
                break;
289
 
        }
290
 
}