2
* Copyright (c) 2010 Intel, Inc.
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.
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
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
18
* Author: Thomas Wood <thos@gnome.org>
21
#include "cc-shell-item-view.h"
22
#include "cc-shell-model.h"
23
#include "cc-shell-marshal.h"
25
G_DEFINE_TYPE (CcShellItemView, cc_shell_item_view, GTK_TYPE_ICON_VIEW)
27
#define SHELL_ITEM_VIEW_PRIVATE(o) \
28
(G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_SHELL_ITEM_VIEW, CcShellItemViewPrivate))
30
struct _CcShellItemViewPrivate
32
gboolean ignore_release;
38
DESKTOP_ITEM_ACTIVATED,
43
static guint signals[LAST_SIGNAL] = {0,};
46
cc_shell_item_view_get_property (GObject *object,
54
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
59
cc_shell_item_view_set_property (GObject *object,
67
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
72
cc_shell_item_view_dispose (GObject *object)
74
G_OBJECT_CLASS (cc_shell_item_view_parent_class)->dispose (object);
78
cc_shell_item_view_finalize (GObject *object)
80
G_OBJECT_CLASS (cc_shell_item_view_parent_class)->finalize (object);
84
iconview_button_press_event_cb (GtkWidget *widget,
85
GdkEventButton *event,
86
CcShellItemView *cc_view)
88
/* be sure to ignore double and triple clicks */
89
cc_view->priv->ignore_release = (event->type != GDK_BUTTON_PRESS);
95
iconview_button_release_event_cb (GtkWidget *widget,
96
GdkEventButton *event,
97
CcShellItemView *cc_view)
99
CcShellItemViewPrivate *priv = cc_view->priv;
101
if (event->button == 1 && !priv->ignore_release)
106
gtk_icon_view_get_selected_items (GTK_ICON_VIEW (cc_view));
111
gtk_icon_view_item_activated (GTK_ICON_VIEW (cc_view),
112
(GtkTreePath*) selection->data);
114
g_list_free (selection);
121
iconview_item_activated_cb (GtkIconView *icon_view,
123
CcShellItemView *cc_view)
127
gchar *name, *desktop_file, *id;
129
model = gtk_icon_view_get_model (icon_view);
131
gtk_icon_view_unselect_all (icon_view);
133
/* get the iter and ensure it is valid */
134
if (!gtk_tree_model_get_iter (model, &iter, path))
137
gtk_tree_model_get (model, &iter,
139
COL_DESKTOP_FILE, &desktop_file,
143
g_signal_emit (cc_view, signals[DESKTOP_ITEM_ACTIVATED], 0,
144
name, id, desktop_file);
146
g_free (desktop_file);
152
cc_shell_item_view_update_cells (CcShellItemView *view)
156
cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (view));
157
for (l = cells ; l != NULL; l = l->next)
159
GtkCellRenderer *cell = l->data;
161
if (GTK_IS_CELL_RENDERER_TEXT (cell)) {
162
g_object_set (G_OBJECT (cell),
163
"wrap-mode", PANGO_WRAP_WORD,
165
/* We only have one text cell */
172
cc_shell_item_view_class_init (CcShellItemViewClass *klass)
174
GObjectClass *object_class = G_OBJECT_CLASS (klass);
176
g_type_class_add_private (klass, sizeof (CcShellItemViewPrivate));
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;
183
signals[DESKTOP_ITEM_ACTIVATED] = g_signal_new ("desktop-item-activated",
184
CC_TYPE_SHELL_ITEM_VIEW,
189
cc_shell_marshal_VOID__STRING_STRING_STRING,
198
cc_shell_item_view_init (CcShellItemView *self)
200
self->priv = SHELL_ITEM_VIEW_PRIVATE (self);
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);
211
cc_shell_item_view_new (void)
213
return g_object_new (CC_TYPE_SHELL_ITEM_VIEW, NULL);