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

« back to all changes in this revision

Viewing changes to shell/cc-shell-item-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-item-view.h"
 
22
#include "cc-shell-model.h"
 
23
#include "cc-shell-marshal.h"
 
24
 
 
25
G_DEFINE_TYPE (CcShellItemView, cc_shell_item_view, GTK_TYPE_ICON_VIEW)
 
26
 
 
27
#define SHELL_ITEM_VIEW_PRIVATE(o) \
 
28
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_SHELL_ITEM_VIEW, CcShellItemViewPrivate))
 
29
 
 
30
struct _CcShellItemViewPrivate
 
31
{
 
32
  gboolean ignore_release;
 
33
};
 
34
 
 
35
 
 
36
enum
 
37
{
 
38
  DESKTOP_ITEM_ACTIVATED,
 
39
 
 
40
  LAST_SIGNAL
 
41
};
 
42
 
 
43
static guint signals[LAST_SIGNAL] = {0,};
 
44
 
 
45
static void
 
46
cc_shell_item_view_get_property (GObject    *object,
 
47
                                 guint       property_id,
 
48
                                 GValue     *value,
 
49
                                 GParamSpec *pspec)
 
50
{
 
51
  switch (property_id)
 
52
    {
 
53
    default:
 
54
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
55
    }
 
56
}
 
57
 
 
58
static void
 
59
cc_shell_item_view_set_property (GObject      *object,
 
60
                                 guint         property_id,
 
61
                                 const GValue *value,
 
62
                                 GParamSpec   *pspec)
 
63
{
 
64
  switch (property_id)
 
65
    {
 
66
    default:
 
67
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
68
    }
 
69
}
 
70
 
 
71
static void
 
72
cc_shell_item_view_dispose (GObject *object)
 
73
{
 
74
  G_OBJECT_CLASS (cc_shell_item_view_parent_class)->dispose (object);
 
75
}
 
76
 
 
77
static void
 
78
cc_shell_item_view_finalize (GObject *object)
 
79
{
 
80
  G_OBJECT_CLASS (cc_shell_item_view_parent_class)->finalize (object);
 
81
}
 
82
 
 
83
static gboolean
 
84
iconview_button_press_event_cb (GtkWidget       *widget,
 
85
                                GdkEventButton  *event,
 
86
                                CcShellItemView *cc_view)
 
87
{
 
88
  /* be sure to ignore double and triple clicks */
 
89
  cc_view->priv->ignore_release = (event->type != GDK_BUTTON_PRESS);
 
90
 
 
91
  return FALSE;
 
92
}
 
93
 
 
94
static gboolean
 
95
iconview_button_release_event_cb (GtkWidget       *widget,
 
96
                                  GdkEventButton  *event,
 
97
                                  CcShellItemView *cc_view)
 
98
{
 
99
  CcShellItemViewPrivate *priv = cc_view->priv;
 
100
 
 
101
  if (event->button == 1 && !priv->ignore_release)
 
102
    {
 
103
      GList *selection;
 
104
 
 
105
      selection =
 
106
        gtk_icon_view_get_selected_items (GTK_ICON_VIEW (cc_view));
 
107
 
 
108
      if (!selection)
 
109
        return TRUE;
 
110
 
 
111
      gtk_icon_view_item_activated (GTK_ICON_VIEW (cc_view),
 
112
                                    (GtkTreePath*) selection->data);
 
113
 
 
114
      g_list_free (selection);
 
115
    }
 
116
 
 
117
  return TRUE;
 
118
}
 
119
 
 
120
static void
 
121
iconview_item_activated_cb (GtkIconView     *icon_view,
 
122
                            GtkTreePath     *path,
 
123
                            CcShellItemView *cc_view)
 
124
{
 
125
  GtkTreeModel *model;
 
126
  GtkTreeIter iter;
 
127
  gchar *name, *desktop_file, *id;
 
128
 
 
129
  model = gtk_icon_view_get_model (icon_view);
 
130
 
 
131
  gtk_icon_view_unselect_all (icon_view);
 
132
 
 
133
  /* get the iter and ensure it is valid */
 
134
  if (!gtk_tree_model_get_iter (model, &iter, path))
 
135
    return;
 
136
 
 
137
  gtk_tree_model_get (model, &iter,
 
138
                      COL_NAME, &name,
 
139
                      COL_DESKTOP_FILE, &desktop_file,
 
140
                      COL_ID, &id,
 
141
                      -1);
 
142
 
 
143
  g_signal_emit (cc_view, signals[DESKTOP_ITEM_ACTIVATED], 0,
 
144
                 name, id, desktop_file);
 
145
 
 
146
  g_free (desktop_file);
 
147
  g_free (name);
 
148
  g_free (id);
 
149
}
 
150
 
 
151
void
 
152
cc_shell_item_view_update_cells (CcShellItemView *view)
 
153
{
 
154
        GList *cells, *l;
 
155
 
 
156
        cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (view));
 
157
        for (l = cells ; l != NULL; l = l->next)
 
158
        {
 
159
                GtkCellRenderer *cell = l->data;
 
160
 
 
161
                if (GTK_IS_CELL_RENDERER_TEXT (cell)) {
 
162
                        g_object_set (G_OBJECT (cell),
 
163
                                      "wrap-mode", PANGO_WRAP_WORD,
 
164
                                      NULL);
 
165
                        /* We only have one text cell */
 
166
                        break;
 
167
                }
 
168
        }
 
169
}
 
170
 
 
171
static void
 
172
cc_shell_item_view_class_init (CcShellItemViewClass *klass)
 
173
{
 
174
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
175
 
 
176
  g_type_class_add_private (klass, sizeof (CcShellItemViewPrivate));
 
177
 
 
178
  object_class->get_property = cc_shell_item_view_get_property;
 
179
  object_class->set_property = cc_shell_item_view_set_property;
 
180
  object_class->dispose = cc_shell_item_view_dispose;
 
181
  object_class->finalize = cc_shell_item_view_finalize;
 
182
 
 
183
  signals[DESKTOP_ITEM_ACTIVATED] = g_signal_new ("desktop-item-activated",
 
184
                                                  CC_TYPE_SHELL_ITEM_VIEW,
 
185
                                                  G_SIGNAL_RUN_FIRST,
 
186
                                                  0,
 
187
                                                  NULL,
 
188
                                                  NULL,
 
189
                                                  cc_shell_marshal_VOID__STRING_STRING_STRING,
 
190
                                                  G_TYPE_NONE,
 
191
                                                  3,
 
192
                                                  G_TYPE_STRING,
 
193
                                                  G_TYPE_STRING,
 
194
                                                  G_TYPE_STRING);
 
195
}
 
196
 
 
197
static void
 
198
cc_shell_item_view_init (CcShellItemView *self)
 
199
{
 
200
  self->priv = SHELL_ITEM_VIEW_PRIVATE (self);
 
201
 
 
202
  g_signal_connect (self, "item-activated",
 
203
                    G_CALLBACK (iconview_item_activated_cb), self);
 
204
  g_signal_connect (self, "button-press-event",
 
205
                    G_CALLBACK (iconview_button_press_event_cb), self);
 
206
  g_signal_connect (self, "button-release-event",
 
207
                    G_CALLBACK (iconview_button_release_event_cb), self);
 
208
}
 
209
 
 
210
GtkWidget *
 
211
cc_shell_item_view_new (void)
 
212
{
 
213
  return g_object_new (CC_TYPE_SHELL_ITEM_VIEW, NULL);
 
214
}