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

« back to all changes in this revision

Viewing changes to lib/widgets/gd-main-view-generic.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 "gd-main-view.h"
 
23
#include "gd-main-view-generic.h"
 
24
 
 
25
typedef GdMainViewGenericIface GdMainViewGenericInterface;
 
26
G_DEFINE_INTERFACE (GdMainViewGeneric, gd_main_view_generic, GTK_TYPE_WIDGET)
 
27
 
 
28
enum {
 
29
  DELETE_ITEM_CLICKED,
 
30
  LAST_SIGNAL
 
31
};
 
32
 
 
33
static guint signals[LAST_SIGNAL] = { 0 };
 
34
 
 
35
static void
 
36
gd_main_view_generic_default_init (GdMainViewGenericInterface *iface)
 
37
{
 
38
  signals[DELETE_ITEM_CLICKED] =
 
39
    g_signal_new ("delete-item-clicked",
 
40
                  GD_TYPE_MAIN_VIEW_GENERIC,
 
41
                  G_SIGNAL_RUN_LAST,
 
42
                  0,
 
43
                  NULL, NULL, NULL,
 
44
                  G_TYPE_NONE, 1,
 
45
                  G_TYPE_STRING);
 
46
}
 
47
 
 
48
/**
 
49
 * gd_main_view_generic_set_model:
 
50
 * @self:
 
51
 * @model: (allow-none):
 
52
 *
 
53
 */
 
54
void
 
55
gd_main_view_generic_set_model (GdMainViewGeneric *self,
 
56
                                GtkTreeModel *model)
 
57
{
 
58
  GdMainViewGenericInterface *iface;
 
59
 
 
60
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
61
 
 
62
  (* iface->set_model) (self, model);
 
63
}
 
64
 
 
65
GtkTreePath *
 
66
gd_main_view_generic_get_path_at_pos (GdMainViewGeneric *self,
 
67
                                      gint x,
 
68
                                      gint y)
 
69
{
 
70
  GdMainViewGenericInterface *iface;
 
71
 
 
72
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
73
 
 
74
  return (* iface->get_path_at_pos) (self, x, y);
 
75
}
 
76
 
 
77
void
 
78
gd_main_view_generic_set_selection_mode (GdMainViewGeneric *self,
 
79
                                         gboolean selection_mode)
 
80
{
 
81
  GdMainViewGenericInterface *iface;
 
82
 
 
83
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
84
 
 
85
  (* iface->set_selection_mode) (self, selection_mode);
 
86
}
 
87
 
 
88
void
 
89
gd_main_view_generic_scroll_to_path (GdMainViewGeneric *self,
 
90
                                     GtkTreePath *path)
 
91
{
 
92
  GdMainViewGenericInterface *iface;
 
93
 
 
94
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
95
 
 
96
  (* iface->scroll_to_path) (self, path);
 
97
}
 
98
 
 
99
static gboolean
 
100
build_selection_uris_foreach (GtkTreeModel *model,
 
101
                              GtkTreePath *path,
 
102
                              GtkTreeIter *iter,
 
103
                              gpointer user_data)
 
104
{
 
105
  GPtrArray *ptr_array = user_data;
 
106
  gchar *uri;
 
107
  gboolean is_selected;
 
108
 
 
109
  gtk_tree_model_get (model, iter,
 
110
                      GD_MAIN_COLUMN_URI, &uri,
 
111
                      GD_MAIN_COLUMN_SELECTED, &is_selected,
 
112
                      -1);
 
113
 
 
114
  if (is_selected)
 
115
    g_ptr_array_add (ptr_array, uri);
 
116
  else
 
117
    g_free (uri);
 
118
 
 
119
  return FALSE;
 
120
}
 
121
 
 
122
static gchar **
 
123
model_get_selection_uris (GtkTreeModel *model)
 
124
{
 
125
  GPtrArray *ptr_array = g_ptr_array_new ();
 
126
 
 
127
  gtk_tree_model_foreach (model,
 
128
                          build_selection_uris_foreach,
 
129
                          ptr_array);
 
130
  
 
131
  g_ptr_array_add (ptr_array, NULL);
 
132
  return (gchar **) g_ptr_array_free (ptr_array, FALSE);
 
133
}
 
134
 
 
135
void
 
136
_gd_main_view_generic_dnd_common (GtkTreeModel *model,
 
137
                                  gboolean selection_mode,
 
138
                                  GtkTreePath *path,
 
139
                                  GtkSelectionData *data)
 
140
{
 
141
  gchar **uris;
 
142
 
 
143
  if (selection_mode)
 
144
    {
 
145
      uris = model_get_selection_uris (model);
 
146
    }
 
147
  else
 
148
    {
 
149
      GtkTreeIter iter;
 
150
      gboolean res;
 
151
      gchar *uri = NULL;
 
152
 
 
153
      if (path != NULL)
 
154
        {
 
155
          res = gtk_tree_model_get_iter (model, &iter, path);
 
156
          if (res)
 
157
            gtk_tree_model_get (model, &iter,
 
158
                                GD_MAIN_COLUMN_URI, &uri,
 
159
                                -1);
 
160
        }
 
161
 
 
162
      uris = g_new0 (gchar *, 2);
 
163
      uris[0] = uri;
 
164
      uris[1] = NULL;
 
165
    }
 
166
 
 
167
  gtk_selection_data_set_uris (data, uris);
 
168
  g_strfreev (uris);
 
169
}
 
170
 
 
171
void
 
172
_gd_main_view_generic_item_delete_clicked (GdMainViewGeneric *self,
 
173
                                           const gchar *path)
 
174
{
 
175
  g_signal_emit (self, signals[DELETE_ITEM_CLICKED], 0, path);
 
176
}