~charlesk/gnome-control-center/make-new-panel

« back to all changes in this revision

Viewing changes to shell/cc-shell-category-view.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
 * Copyright (c) 2010 Intel, Inc.
 
3
 *
 
4
 * The Control Center is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by the
 
6
 * Free Software Foundation; either version 2 of the License, or (at your
 
7
 * option) any later version.
 
8
 *
 
9
 * The Control Center is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
11
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
12
 * for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with the Control Center; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 *
 
18
 * Author: Thomas Wood <thos@gnome.org>
 
19
 */
 
20
 
 
21
#include "cc-shell-category-view.h"
 
22
#include "cc-shell-item-view.h"
 
23
#include "cc-shell.h"
 
24
#include "cc-shell-model.h"
 
25
 
 
26
G_DEFINE_TYPE (CcShellCategoryView, cc_shell_category_view, GTK_TYPE_FRAME)
 
27
 
 
28
#define SHELL_CATEGORY_VIEW_PRIVATE(o) \
 
29
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_SHELL_CATEGORY_VIEW, CcShellCategoryViewPrivate))
 
30
 
 
31
enum
 
32
{
 
33
  PROP_NAME = 1,
 
34
  PROP_MODEL
 
35
};
 
36
 
 
37
struct _CcShellCategoryViewPrivate
 
38
{
 
39
  gchar *name;
 
40
  GtkTreeModel *model;
 
41
  GtkWidget *iconview;
 
42
};
 
43
 
 
44
static void
 
45
cc_shell_category_view_get_property (GObject    *object,
 
46
                                     guint       property_id,
 
47
                                     GValue     *value,
 
48
                                     GParamSpec *pspec)
 
49
{
 
50
  CcShellCategoryViewPrivate *priv = CC_SHELL_CATEGORY_VIEW (object)->priv;
 
51
 
 
52
  switch (property_id)
 
53
    {
 
54
    case PROP_NAME:
 
55
      g_value_set_string (value, priv->name);
 
56
      break;
 
57
 
 
58
    case PROP_MODEL:
 
59
      g_value_set_object (value, priv->model);
 
60
      break;
 
61
 
 
62
    default:
 
63
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
64
    }
 
65
}
 
66
 
 
67
static void
 
68
cc_shell_category_view_set_property (GObject      *object,
 
69
                                     guint         property_id,
 
70
                                     const GValue *value,
 
71
                                     GParamSpec   *pspec)
 
72
{
 
73
  CcShellCategoryViewPrivate *priv = CC_SHELL_CATEGORY_VIEW (object)->priv;
 
74
 
 
75
  switch (property_id)
 
76
    {
 
77
    case PROP_NAME:
 
78
      priv->name = g_value_dup_string (value);
 
79
      break;
 
80
 
 
81
    case PROP_MODEL:
 
82
      priv->model = g_value_dup_object (value);
 
83
      break;
 
84
    default:
 
85
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
86
    }
 
87
}
 
88
 
 
89
static void
 
90
cc_shell_category_view_dispose (GObject *object)
 
91
{
 
92
  CcShellCategoryViewPrivate *priv = CC_SHELL_CATEGORY_VIEW (object)->priv;
 
93
 
 
94
  if (priv->model)
 
95
    {
 
96
      g_object_unref (priv->model);
 
97
      priv->model = NULL;
 
98
    }
 
99
 
 
100
  G_OBJECT_CLASS (cc_shell_category_view_parent_class)->dispose (object);
 
101
}
 
102
 
 
103
static void
 
104
cc_shell_category_view_finalize (GObject *object)
 
105
{
 
106
  CcShellCategoryViewPrivate *priv = CC_SHELL_CATEGORY_VIEW (object)->priv;
 
107
 
 
108
  if (priv->name)
 
109
    {
 
110
      g_free (priv->name);
 
111
      priv->name = NULL;
 
112
    }
 
113
 
 
114
  G_OBJECT_CLASS (cc_shell_category_view_parent_class)->finalize (object);
 
115
}
 
116
 
 
117
static void
 
118
label_style_set_cb (GtkWidget *widget,
 
119
                    GtkStyle  *old_style,
 
120
                    gpointer   user_data)
 
121
{
 
122
  GtkStyle *style;
 
123
 
 
124
  /* "base" colours are used for the background inside CcShellCategoryView,
 
125
   * so set the labels to use the "text" colors */
 
126
 
 
127
  g_signal_handlers_block_by_func (widget, label_style_set_cb, NULL);
 
128
 
 
129
  style = gtk_widget_get_style (widget);
 
130
 
 
131
  gtk_widget_modify_fg (widget, GTK_STATE_NORMAL,
 
132
                        &style->text[GTK_STATE_NORMAL]);
 
133
 
 
134
  g_signal_handlers_unblock_by_func (widget, label_style_set_cb, NULL);
 
135
}
 
136
 
 
137
 
 
138
 
 
139
static void
 
140
cc_shell_category_view_constructed (GObject *object)
 
141
{
 
142
  CcShellCategoryViewPrivate *priv = CC_SHELL_CATEGORY_VIEW (object)->priv;
 
143
  GtkWidget *iconview, *vbox;
 
144
  GtkWidget *alignment;
 
145
 
 
146
  iconview = cc_shell_item_view_new ();
 
147
  gtk_icon_view_set_model (GTK_ICON_VIEW (iconview), priv->model);
 
148
 
 
149
  vbox = gtk_vbox_new (FALSE, 0);
 
150
 
 
151
  gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (iconview), COL_PIXBUF);
 
152
  gtk_icon_view_set_text_column (GTK_ICON_VIEW (iconview), COL_NAME);
 
153
  gtk_icon_view_set_item_width (GTK_ICON_VIEW (iconview), 100);
 
154
  cc_shell_item_view_update_cells (CC_SHELL_ITEM_VIEW (iconview));
 
155
 
 
156
  /* create the header if required */
 
157
  if (priv->name)
 
158
    {
 
159
      GtkWidget *label;
 
160
      PangoAttrList *attrs;
 
161
 
 
162
      label = gtk_label_new (priv->name);
 
163
      attrs = pango_attr_list_new ();
 
164
      pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
 
165
      gtk_label_set_attributes (GTK_LABEL (label), attrs);
 
166
      pango_attr_list_unref (attrs);
 
167
      gtk_frame_set_label_widget (GTK_FRAME (object), label);
 
168
 
 
169
      g_signal_connect (label, "style-set", G_CALLBACK (label_style_set_cb),
 
170
                        NULL);
 
171
    }
 
172
 
 
173
  /* add the iconview to the vbox */
 
174
  gtk_box_pack_start (GTK_BOX (vbox), iconview, FALSE, TRUE, 0);
 
175
 
 
176
  /* add the main vbox to the view */
 
177
  alignment = gtk_alignment_new (0, 0, 1, 1);
 
178
  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
 
179
  gtk_container_add (GTK_CONTAINER (alignment), vbox);
 
180
  gtk_container_add (GTK_CONTAINER (object), alignment);
 
181
  gtk_widget_show_all (alignment);
 
182
 
 
183
  priv->iconview = iconview;
 
184
}
 
185
 
 
186
static gboolean
 
187
cc_shell_category_view_draw (GtkWidget *widget,
 
188
                             cairo_t   *cr)
 
189
{
 
190
  GtkStyle *style;
 
191
  GtkStateType state;
 
192
  GtkAllocation allocation;
 
193
 
 
194
  style = gtk_widget_get_style (widget);
 
195
  state = gtk_widget_get_state (widget);
 
196
  gtk_widget_get_allocation (widget, &allocation);
 
197
 
 
198
 
 
199
  cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
 
200
  gdk_cairo_set_source_color (cr, &style->base[state]);
 
201
 
 
202
  cairo_fill (cr);
 
203
 
 
204
  GTK_WIDGET_CLASS (cc_shell_category_view_parent_class)->draw (widget, cr);
 
205
 
 
206
  return FALSE;
 
207
}
 
208
 
 
209
static void
 
210
cc_shell_category_view_class_init (CcShellCategoryViewClass *klass)
 
211
{
 
212
  GParamSpec *pspec;
 
213
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
214
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
215
 
 
216
  g_type_class_add_private (klass, sizeof (CcShellCategoryViewPrivate));
 
217
 
 
218
  object_class->get_property = cc_shell_category_view_get_property;
 
219
  object_class->set_property = cc_shell_category_view_set_property;
 
220
  object_class->dispose = cc_shell_category_view_dispose;
 
221
  object_class->finalize = cc_shell_category_view_finalize;
 
222
  object_class->constructed = cc_shell_category_view_constructed;
 
223
 
 
224
  widget_class->draw = cc_shell_category_view_draw;
 
225
 
 
226
  pspec = g_param_spec_string ("name",
 
227
                               "Name",
 
228
                               "Name of the category",
 
229
                               NULL,
 
230
                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
 
231
                               | G_PARAM_STATIC_STRINGS);
 
232
  g_object_class_install_property (object_class, PROP_NAME, pspec);
 
233
 
 
234
  pspec = g_param_spec_object ("model",
 
235
                               "Model",
 
236
                               "Model of the category",
 
237
                               GTK_TYPE_TREE_MODEL,
 
238
                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
 
239
                               | G_PARAM_STATIC_STRINGS);
 
240
  g_object_class_install_property (object_class, PROP_MODEL, pspec);
 
241
 
 
242
}
 
243
 
 
244
static void
 
245
cc_shell_category_view_init (CcShellCategoryView *self)
 
246
{
 
247
  self->priv = SHELL_CATEGORY_VIEW_PRIVATE (self);
 
248
 
 
249
  gtk_frame_set_shadow_type (GTK_FRAME (self), GTK_SHADOW_NONE);
 
250
}
 
251
 
 
252
GtkWidget *
 
253
cc_shell_category_view_new (const gchar  *name,
 
254
                            GtkTreeModel *model)
 
255
{
 
256
  return g_object_new (CC_TYPE_SHELL_CATEGORY_VIEW,
 
257
                       "name", name,
 
258
                       "model", model, NULL);
 
259
}
 
260
 
 
261
CcShellItemView*
 
262
cc_shell_category_view_get_item_view (CcShellCategoryView *self)
 
263
{
 
264
  return (CcShellItemView*) self->priv->iconview;
 
265
}