~ubuntu-branches/ubuntu/trusty/unity-control-center/trusty

« back to all changes in this revision

Viewing changes to shell/cc-shell-category-view.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-01-08 16:29:18 UTC
  • Revision ID: package-import@ubuntu.com-20140108162918-g29dd08tr913y2qh
Tags: upstream-14.04.0
ImportĀ upstreamĀ versionĀ 14.04.0

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
cc_shell_category_view_constructed (GObject *object)
 
119
{
 
120
  CcShellCategoryViewPrivate *priv = CC_SHELL_CATEGORY_VIEW (object)->priv;
 
121
  GtkWidget *iconview, *vbox;
 
122
  GtkCellRenderer *renderer;
 
123
 
 
124
  iconview = cc_shell_item_view_new ();
 
125
  gtk_icon_view_set_model (GTK_ICON_VIEW (iconview), priv->model);
 
126
 
 
127
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
128
 
 
129
  renderer = gtk_cell_renderer_pixbuf_new ();
 
130
  g_object_set (renderer,
 
131
                "follow-state", TRUE,
 
132
                NULL);
 
133
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (iconview),
 
134
                              renderer, FALSE);
 
135
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (iconview), renderer,
 
136
                                 "pixbuf", COL_PIXBUF);
 
137
 
 
138
  gtk_icon_view_set_text_column (GTK_ICON_VIEW (iconview), COL_NAME);
 
139
  gtk_icon_view_set_item_width (GTK_ICON_VIEW (iconview), 100);
 
140
  cc_shell_item_view_update_cells (CC_SHELL_ITEM_VIEW (iconview));
 
141
  gtk_icon_view_set_columns (GTK_ICON_VIEW (iconview), 7);
 
142
 
 
143
  /* create the header if required */
 
144
  if (priv->name)
 
145
    {
 
146
      GtkWidget *label;
 
147
      PangoAttrList *attrs;
 
148
 
 
149
      label = gtk_label_new (priv->name);
 
150
      attrs = pango_attr_list_new ();
 
151
      pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
 
152
      gtk_label_set_attributes (GTK_LABEL (label), attrs);
 
153
      pango_attr_list_unref (attrs);
 
154
      gtk_frame_set_label_widget (GTK_FRAME (object), label);
 
155
      gtk_widget_show (label);
 
156
    }
 
157
 
 
158
  /* add the iconview to the vbox */
 
159
  gtk_box_pack_start (GTK_BOX (vbox), iconview, FALSE, TRUE, 0);
 
160
 
 
161
  /* add the main vbox to the view */
 
162
  gtk_container_add (GTK_CONTAINER (object), vbox);
 
163
  gtk_widget_show_all (vbox);
 
164
 
 
165
  priv->iconview = iconview;
 
166
}
 
167
 
 
168
static void
 
169
cc_shell_category_view_class_init (CcShellCategoryViewClass *klass)
 
170
{
 
171
  GParamSpec *pspec;
 
172
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
173
 
 
174
  g_type_class_add_private (klass, sizeof (CcShellCategoryViewPrivate));
 
175
 
 
176
  object_class->get_property = cc_shell_category_view_get_property;
 
177
  object_class->set_property = cc_shell_category_view_set_property;
 
178
  object_class->dispose = cc_shell_category_view_dispose;
 
179
  object_class->finalize = cc_shell_category_view_finalize;
 
180
  object_class->constructed = cc_shell_category_view_constructed;
 
181
 
 
182
  pspec = g_param_spec_string ("name",
 
183
                               "Name",
 
184
                               "Name of the category",
 
185
                               NULL,
 
186
                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
 
187
                               | G_PARAM_STATIC_STRINGS);
 
188
  g_object_class_install_property (object_class, PROP_NAME, pspec);
 
189
 
 
190
  pspec = g_param_spec_object ("model",
 
191
                               "Model",
 
192
                               "Model of the category",
 
193
                               GTK_TYPE_TREE_MODEL,
 
194
                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
 
195
                               | G_PARAM_STATIC_STRINGS);
 
196
  g_object_class_install_property (object_class, PROP_MODEL, pspec);
 
197
 
 
198
}
 
199
 
 
200
static void
 
201
cc_shell_category_view_init (CcShellCategoryView *self)
 
202
{
 
203
  self->priv = SHELL_CATEGORY_VIEW_PRIVATE (self);
 
204
 
 
205
  gtk_frame_set_shadow_type (GTK_FRAME (self), GTK_SHADOW_NONE);
 
206
}
 
207
 
 
208
GtkWidget *
 
209
cc_shell_category_view_new (const gchar  *name,
 
210
                            GtkTreeModel *model)
 
211
{
 
212
  return g_object_new (CC_TYPE_SHELL_CATEGORY_VIEW,
 
213
                       "name", name,
 
214
                       "model", model, NULL);
 
215
}
 
216
 
 
217
CcShellItemView*
 
218
cc_shell_category_view_get_item_view (CcShellCategoryView *self)
 
219
{
 
220
  return (CcShellItemView*) self->priv->iconview;
 
221
}