~ubuntu-branches/ubuntu/wily/epiphany-browser/wily

« back to all changes in this revision

Viewing changes to lib/widgets/gd-main-icon-view.c

  • Committer: Package Import Robot
  • Author(s): Gustavo Noronha Silva, Jeremy Bicha, Emilio Pozuelo Monfort, Gustavo Noronha Silva
  • Date: 2012-12-10 11:40:01 UTC
  • mfrom: (1.8.8) (105.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20121210114001-42jjyg3qw3eyz00a
Tags: 3.6.1-1
[ Jeremy Bicha ]
* New upstream unstable release
* debian/control.in:
  - Bump minimum intltool to 0.50
* debian/epiphany-browser-data.install:
  - The developers no longer provide help files to install since they were
    too outdated
* Dropped upstream patches:
  - 01_email-as-user-for-password-remembering.patch
  - 13_toolbar_size_fixes.patch
* debian/watch: Watch for unstable releases.

[ Emilio Pozuelo Monfort ]
* New upstream release.
  + debian/patches/14_pkglibdir.patch:
    - Removed, applied upstream.
  + debian/control.in:
    - Update (build-)dependencies.

[ Gustavo Noronha Silva ]
* debian/control.in:
- Build-Depend on gnome-common >= 3.6, needed for the code
  coverage feature

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2011 Red Hat, Inc.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by 
 
6
 * the Free Software Foundation; either version 2 of the License, or (at your
 
7
 * option) any later version.
 
8
 *
 
9
 * This program 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 Lesser General Public 
 
12
 * License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public License 
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 *
 
18
 * Author: Cosimo Cecchi <cosimoc@redhat.com>
 
19
 *
 
20
 */
 
21
 
 
22
#include "ephy-overview-store.h"
 
23
#include "ephy-removable-pixbuf-renderer.h"
 
24
#include "gd-main-icon-view.h"
 
25
#include "gd-main-view.h"
 
26
#include "gd-main-view-generic.h"
 
27
#include "gd-toggle-pixbuf-renderer.h"
 
28
#include "gd-two-lines-renderer.h"
 
29
 
 
30
#include <math.h>
 
31
#include <glib/gi18n.h>
 
32
 
 
33
#define VIEW_ITEM_WIDTH 140
 
34
#define VIEW_ITEM_WRAP_WIDTH 128
 
35
#define VIEW_COLUMN_SPACING 20
 
36
#define VIEW_MARGIN 16
 
37
 
 
38
struct _GdMainIconViewPrivate {
 
39
  GtkCellRenderer *pixbuf_cell;
 
40
  gboolean selection_mode;
 
41
};
 
42
 
 
43
static void gd_main_view_generic_iface_init (GdMainViewGenericIface *iface);
 
44
G_DEFINE_TYPE_WITH_CODE (GdMainIconView, gd_main_icon_view, GTK_TYPE_ICON_VIEW,
 
45
                         G_IMPLEMENT_INTERFACE (GD_TYPE_MAIN_VIEW_GENERIC,
 
46
                                                gd_main_view_generic_iface_init))
 
47
 
 
48
static GtkTreePath*
 
49
get_source_row (GdkDragContext *context)
 
50
{
 
51
  GtkTreeRowReference *ref;
 
52
 
 
53
  ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
 
54
 
 
55
  if (ref)
 
56
    return gtk_tree_row_reference_get_path (ref);
 
57
  else
 
58
    return NULL;
 
59
}
 
60
 
 
61
static void
 
62
gd_main_icon_view_drag_data_get (GtkWidget *widget,
 
63
                                 GdkDragContext *drag_context,
 
64
                                 GtkSelectionData *data,
 
65
                                 guint info,
 
66
                                 guint time)
 
67
{
 
68
  GdMainIconView *self = GD_MAIN_ICON_VIEW (widget);
 
69
  GtkTreeModel *model = gtk_icon_view_get_model (GTK_ICON_VIEW (self));
 
70
 
 
71
  if (info != 0)
 
72
    return;
 
73
 
 
74
  _gd_main_view_generic_dnd_common (model, self->priv->selection_mode,
 
75
                                    get_source_row (drag_context), data);
 
76
 
 
77
  GTK_WIDGET_CLASS (gd_main_icon_view_parent_class)->drag_data_get (widget, drag_context,
 
78
                                                                    data, info, time);
 
79
}
 
80
 
 
81
static void
 
82
on_cell_delete_clicked (EphyRemovablePixbufRenderer *cell,
 
83
                        const gchar *path,
 
84
                        GdMainIconView *self)
 
85
{
 
86
  _gd_main_view_generic_item_delete_clicked (GD_MAIN_VIEW_GENERIC (self), path);
 
87
}
 
88
 
 
89
static void
 
90
gd_main_icon_view_constructed (GObject *obj)
 
91
{
 
92
  GdMainIconView *self = GD_MAIN_ICON_VIEW (obj);
 
93
  GtkCellRenderer *cell;
 
94
  const GtkTargetEntry targets[] = {
 
95
    { "text/uri-list", GTK_TARGET_OTHER_APP, 0 }
 
96
  };
 
97
 
 
98
  G_OBJECT_CLASS (gd_main_icon_view_parent_class)->constructed (obj);
 
99
 
 
100
  gtk_widget_set_hexpand (GTK_WIDGET (self), TRUE);
 
101
  gtk_widget_set_vexpand (GTK_WIDGET (self), TRUE);
 
102
  gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (self), GTK_SELECTION_NONE);
 
103
 
 
104
  g_object_set (self,
 
105
                "column-spacing", VIEW_COLUMN_SPACING,
 
106
                "margin", VIEW_MARGIN,
 
107
                NULL);
 
108
 
 
109
  self->priv->pixbuf_cell = cell = ephy_removable_pixbuf_renderer_new ();
 
110
  g_object_set (cell,
 
111
                "xalign", 0.5,
 
112
                "yalign", 0.5,
 
113
                NULL);
 
114
  g_signal_connect (cell, "delete-clicked",
 
115
                    G_CALLBACK (on_cell_delete_clicked),
 
116
                    obj);
 
117
 
 
118
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE);
 
119
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
 
120
                                 "active", GD_MAIN_COLUMN_SELECTED);
 
121
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
 
122
                                 "pixbuf", GD_MAIN_COLUMN_ICON);
 
123
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
 
124
                                 "render-policy", EPHY_OVERVIEW_STORE_CLOSE_BUTTON_RENDER_POLICY);
 
125
 
 
126
  cell = gd_two_lines_renderer_new ();
 
127
  g_object_set (cell,
 
128
                "alignment", PANGO_ALIGN_CENTER,
 
129
                "wrap-mode", PANGO_WRAP_WORD_CHAR,
 
130
                "wrap-width", VIEW_ITEM_WRAP_WIDTH,
 
131
                "text-lines", 3,
 
132
                NULL);
 
133
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE);
 
134
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
 
135
                                 "text", GD_MAIN_COLUMN_TITLE);
 
136
  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
 
137
                                 "line-two", GD_MAIN_COLUMN_AUTHOR);
 
138
 
 
139
  gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (self),
 
140
                                          GDK_BUTTON1_MASK,
 
141
                                          targets, 1,
 
142
                                          GDK_ACTION_COPY);
 
143
}
 
144
 
 
145
static void
 
146
gd_main_icon_view_class_init (GdMainIconViewClass *klass)
 
147
{
 
148
  GObjectClass *oclass = G_OBJECT_CLASS (klass);
 
149
  GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
 
150
 
 
151
  oclass->constructed = gd_main_icon_view_constructed;
 
152
  wclass->drag_data_get = gd_main_icon_view_drag_data_get;
 
153
 
 
154
  gtk_widget_class_install_style_property (wclass,
 
155
                                           g_param_spec_int ("check-icon-size",
 
156
                                                             "Check icon size",
 
157
                                                             "Check icon size",
 
158
                                                             -1, G_MAXINT, 40,
 
159
                                                             G_PARAM_READWRITE));
 
160
 
 
161
  g_type_class_add_private (klass, sizeof (GdMainIconViewPrivate));
 
162
}
 
163
 
 
164
static void
 
165
gd_main_icon_view_init (GdMainIconView *self)
 
166
{
 
167
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_MAIN_ICON_VIEW, GdMainIconViewPrivate);
 
168
}
 
169
 
 
170
static GtkTreePath *
 
171
gd_main_icon_view_get_path_at_pos (GdMainViewGeneric *mv,
 
172
                                   gint x,
 
173
                                   gint y)
 
174
{
 
175
  return gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (mv), x, y);
 
176
}
 
177
 
 
178
static void
 
179
gd_main_icon_view_set_selection_mode (GdMainViewGeneric *mv,
 
180
                                      gboolean selection_mode)
 
181
{
 
182
  GdMainIconView *self = GD_MAIN_ICON_VIEW (mv);
 
183
 
 
184
  self->priv->selection_mode = selection_mode;
 
185
 
 
186
  g_object_set (self->priv->pixbuf_cell,
 
187
                "toggle-visible", selection_mode,
 
188
                NULL);
 
189
  gtk_widget_queue_draw (GTK_WIDGET (self));
 
190
}
 
191
 
 
192
static void
 
193
gd_main_icon_view_scroll_to_path (GdMainViewGeneric *mv,
 
194
                                  GtkTreePath *path)
 
195
{
 
196
  gtk_icon_view_scroll_to_path (GTK_ICON_VIEW (mv), path, TRUE, 0.5, 0.5);
 
197
}
 
198
 
 
199
static void
 
200
gd_main_icon_view_set_model (GdMainViewGeneric *mv,
 
201
                             GtkTreeModel *model)
 
202
{
 
203
  gtk_icon_view_set_model (GTK_ICON_VIEW (mv), model);
 
204
}
 
205
 
 
206
static void
 
207
gd_main_view_generic_iface_init (GdMainViewGenericIface *iface)
 
208
{
 
209
  iface->set_model = gd_main_icon_view_set_model;
 
210
  iface->get_path_at_pos = gd_main_icon_view_get_path_at_pos;
 
211
  iface->scroll_to_path = gd_main_icon_view_scroll_to_path;
 
212
  iface->set_selection_mode = gd_main_icon_view_set_selection_mode;
 
213
}
 
214
 
 
215
GtkWidget *
 
216
gd_main_icon_view_new (void)
 
217
{
 
218
  return g_object_new (GD_TYPE_MAIN_ICON_VIEW, NULL);
 
219
}