~walkerlee/totem/pre-interview

« back to all changes in this revision

Viewing changes to libgd/libgd/gd-main-view-generic.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-05-26 00:07:51 UTC
  • mfrom: (1.6.1) (24.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130526000751-kv8ap3x1di4qq8j2
Tags: 3.8.2-0ubuntu1
* Sync with Debian. Remaining changes: 
* debian/control.in:
  - Drop build-depends on libepc-ui-dev and libgrilo-0.2-dev (in universe)
  - Drop libxtst-dev build-depends so that the (redundant) fake key presses
    for inhibiting the screensaver are disabled (LP: #1007438)
  - Build-depend on libzeitgeist-dev
  - Suggest rather than recommend gstreamer components in universe
  - Add totem-plugins-extra
  - Add XB-Npp-Description and XB-Npp-Filename header to the 
    totem-mozilla package to improve ubufox/ubuntu plugin db integration 
  - Refer to Firefox in totem-mozilla description instead of Iceweasel
  - Don't have totem-mozilla recommend any particular browser
  - Drop obsolete python library dependencies since iplayer is no longer
    included
* debian/totem-common.install, debian/source_totem.py:
  - Install Ubuntu apport debugging hook
* debian/totem-plugins-extra.install:
  - Universe plugins split out of totem-plugins (currently only gromit)
* debian/totem-plugins.install:    
  - Skip the plugins split to -extra and add the zeitgeist plugin
* debian/rules:
  - Build with --fail-missing, to ensure we install everything. 
    + Ignore libtotem.{,l}a since we delibrately don't install these.
  - Re-enable hardening, make sure both PIE and BINDNOW are used
    by setting hardening=+all. (LP: #1039604)
* debian/patches/91_quicklist_entries.patch:
  - Add static quicklist
* debian/patches/92_gst-plugins-good.patch:
  - Build without unnecessary gstreamer1.0-bad dependency
* debian/patches/93_grilo_optional.patch:
  - Allow building without grilo while grilo MIR is still pending
* debian/patches/correct_desktop_mimetypes.patch:
  - Don't list the mimetypes after the unity lists
* debian/patches/revert_shell_menu.patch: 
  - revert the use of a shell menu until indicator-appmenu can handle
    the mixed shell/traditional menus itself
* New upstream release

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-generic.h"
 
23
 
 
24
enum {
 
25
  VIEW_SELECTION_CHANGED,
 
26
  NUM_SIGNALS
 
27
};
 
28
 
 
29
static guint signals[NUM_SIGNALS] = { 0, };
 
30
 
 
31
typedef GdMainViewGenericIface GdMainViewGenericInterface;
 
32
G_DEFINE_INTERFACE (GdMainViewGeneric, gd_main_view_generic, GTK_TYPE_WIDGET)
 
33
 
 
34
static void
 
35
gd_main_view_generic_default_init (GdMainViewGenericInterface *iface)
 
36
{
 
37
  signals[VIEW_SELECTION_CHANGED] =
 
38
    g_signal_new ("view-selection-changed",
 
39
                  GD_TYPE_MAIN_VIEW_GENERIC,
 
40
                  G_SIGNAL_RUN_LAST,
 
41
                  0, NULL, NULL, NULL,
 
42
                  G_TYPE_NONE, 0);
 
43
}
 
44
 
 
45
/**
 
46
 * gd_main_view_generic_set_model:
 
47
 * @self:
 
48
 * @model: (allow-none):
 
49
 *
 
50
 */
 
51
void
 
52
gd_main_view_generic_set_model (GdMainViewGeneric *self,
 
53
                                GtkTreeModel *model)
 
54
{
 
55
  GdMainViewGenericInterface *iface;
 
56
 
 
57
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
58
 
 
59
  (* iface->set_model) (self, model);
 
60
}
 
61
 
 
62
GtkTreePath *
 
63
gd_main_view_generic_get_path_at_pos (GdMainViewGeneric *self,
 
64
                                      gint x,
 
65
                                      gint y)
 
66
{
 
67
  GdMainViewGenericInterface *iface;
 
68
 
 
69
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
70
 
 
71
  return (* iface->get_path_at_pos) (self, x, y);
 
72
}
 
73
 
 
74
void
 
75
gd_main_view_generic_set_selection_mode (GdMainViewGeneric *self,
 
76
                                         gboolean selection_mode)
 
77
{
 
78
  GdMainViewGenericInterface *iface;
 
79
 
 
80
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
81
 
 
82
  (* iface->set_selection_mode) (self, selection_mode);
 
83
}
 
84
 
 
85
 
 
86
typedef struct {
 
87
  GtkTreePath *rubberband_start;
 
88
  GtkTreePath *rubberband_end;
 
89
} RubberbandInfo;
 
90
 
 
91
static void
 
92
rubber_band_info_destroy (RubberbandInfo *info)
 
93
{
 
94
  g_clear_pointer (&info->rubberband_start,
 
95
                   gtk_tree_path_free);
 
96
  g_clear_pointer (&info->rubberband_end,
 
97
                   gtk_tree_path_free);
 
98
  g_slice_free (RubberbandInfo, info);
 
99
}
 
100
 
 
101
static RubberbandInfo*
 
102
get_rubber_band_info (GdMainViewGeneric *self)
 
103
{
 
104
  RubberbandInfo *info;
 
105
 
 
106
  info = g_object_get_data (G_OBJECT (self), "gd-main-view-generic-rubber-band");
 
107
  if (info == NULL)
 
108
    {
 
109
      info = g_slice_new0 (RubberbandInfo);
 
110
      g_object_set_data_full (G_OBJECT (self), "gd-main-view-generic-rubber-band",
 
111
                              info, (GDestroyNotify)rubber_band_info_destroy);
 
112
    }
 
113
 
 
114
  return info;
 
115
}
 
116
 
 
117
void
 
118
gd_main_view_generic_set_rubberband_range (GdMainViewGeneric *self,
 
119
                                           GtkTreePath *start,
 
120
                                           GtkTreePath *end)
 
121
{
 
122
  RubberbandInfo *info;
 
123
 
 
124
  info = get_rubber_band_info (self);
 
125
 
 
126
  if (start == NULL || end == NULL)
 
127
    {
 
128
      g_clear_pointer (&info->rubberband_start,
 
129
                       gtk_tree_path_free);
 
130
      g_clear_pointer (&info->rubberband_end,
 
131
                       gtk_tree_path_free);
 
132
    }
 
133
  else
 
134
    {
 
135
      if (gtk_tree_path_compare (start, end) < 0)
 
136
        {
 
137
          info->rubberband_start = gtk_tree_path_copy (start);
 
138
          info->rubberband_end = gtk_tree_path_copy (end);
 
139
        }
 
140
      else
 
141
        {
 
142
          info->rubberband_start = gtk_tree_path_copy (end);
 
143
          info->rubberband_end = gtk_tree_path_copy (start);
 
144
        }
 
145
    }
 
146
 
 
147
  gtk_widget_queue_draw (GTK_WIDGET (self));
 
148
}
 
149
 
 
150
void
 
151
_gd_main_view_generic_get_rubberband_range (GdMainViewGeneric *self,
 
152
                                            GtkTreePath **start,
 
153
                                            GtkTreePath **end)
 
154
{
 
155
  RubberbandInfo *info;
 
156
 
 
157
  info = get_rubber_band_info (self);
 
158
 
 
159
  *start = info->rubberband_start;
 
160
  *end = info->rubberband_end;
 
161
}
 
162
 
 
163
void
 
164
gd_main_view_generic_scroll_to_path (GdMainViewGeneric *self,
 
165
                                     GtkTreePath *path)
 
166
{
 
167
  GdMainViewGenericInterface *iface;
 
168
 
 
169
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
170
 
 
171
  (* iface->scroll_to_path) (self, path);
 
172
}
 
173
 
 
174
/**
 
175
 * gd_main_view_generic_get_model:
 
176
 *
 
177
 * Returns: (transfer none): The associated model
 
178
 */
 
179
GtkTreeModel *
 
180
gd_main_view_generic_get_model (GdMainViewGeneric *self)
 
181
{
 
182
  GdMainViewGenericInterface *iface;
 
183
 
 
184
  iface = GD_MAIN_VIEW_GENERIC_GET_IFACE (self);
 
185
 
 
186
  return (* iface->get_model) (self);
 
187
}
 
188
 
 
189
static gboolean
 
190
build_selection_uris_foreach (GtkTreeModel *model,
 
191
                              GtkTreePath *path,
 
192
                              GtkTreeIter *iter,
 
193
                              gpointer user_data)
 
194
{
 
195
  GPtrArray *ptr_array = user_data;
 
196
  gchar *uri;
 
197
  gboolean is_selected;
 
198
 
 
199
  gtk_tree_model_get (model, iter,
 
200
                      GD_MAIN_COLUMN_URI, &uri,
 
201
                      GD_MAIN_COLUMN_SELECTED, &is_selected,
 
202
                      -1);
 
203
 
 
204
  if (is_selected)
 
205
    g_ptr_array_add (ptr_array, uri);
 
206
  else
 
207
    g_free (uri);
 
208
 
 
209
  return FALSE;
 
210
}
 
211
 
 
212
static gchar **
 
213
model_get_selection_uris (GtkTreeModel *model)
 
214
{
 
215
  GPtrArray *ptr_array = g_ptr_array_new ();
 
216
 
 
217
  gtk_tree_model_foreach (model,
 
218
                          build_selection_uris_foreach,
 
219
                          ptr_array);
 
220
  
 
221
  g_ptr_array_add (ptr_array, NULL);
 
222
  return (gchar **) g_ptr_array_free (ptr_array, FALSE);
 
223
}
 
224
 
 
225
static gboolean
 
226
set_selection_foreach (GtkTreeModel *model,
 
227
                       GtkTreePath *path,
 
228
                       GtkTreeIter *iter,
 
229
                       gpointer user_data)
 
230
{
 
231
  gboolean selection = GPOINTER_TO_INT (user_data);
 
232
 
 
233
  gtk_list_store_set (GTK_LIST_STORE (model), iter,
 
234
                      GD_MAIN_COLUMN_SELECTED, selection,
 
235
                      -1);
 
236
 
 
237
  return FALSE;
 
238
}
 
239
 
 
240
static void
 
241
set_all_selection (GdMainViewGeneric *self,
 
242
                   GtkTreeModel *model,
 
243
                   gboolean selection)
 
244
{
 
245
  GtkTreeModel *actual_model;
 
246
 
 
247
  if (!model)
 
248
    return;
 
249
 
 
250
  if (GTK_IS_TREE_MODEL_FILTER (model))
 
251
    actual_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
 
252
  else
 
253
    actual_model = model;
 
254
 
 
255
  gtk_tree_model_foreach (actual_model,
 
256
                          set_selection_foreach,
 
257
                          GINT_TO_POINTER (selection));
 
258
  g_signal_emit (self, signals[VIEW_SELECTION_CHANGED], 0);
 
259
}
 
260
 
 
261
void
 
262
gd_main_view_generic_select_all (GdMainViewGeneric *self)
 
263
{
 
264
  GtkTreeModel *model = gd_main_view_generic_get_model (self);
 
265
 
 
266
  set_all_selection (self, model, TRUE);
 
267
}
 
268
 
 
269
void
 
270
gd_main_view_generic_unselect_all (GdMainViewGeneric *self)
 
271
{
 
272
  GtkTreeModel *model = gd_main_view_generic_get_model (self);
 
273
 
 
274
  set_all_selection (self, model, FALSE);
 
275
}
 
276
 
 
277
void
 
278
_gd_main_view_generic_dnd_common (GtkTreeModel *model,
 
279
                                  gboolean selection_mode,
 
280
                                  GtkTreePath *path,
 
281
                                  GtkSelectionData *data)
 
282
{
 
283
  gchar **uris;
 
284
 
 
285
  if (selection_mode)
 
286
    {
 
287
      uris = model_get_selection_uris (model);
 
288
    }
 
289
  else
 
290
    {
 
291
      GtkTreeIter iter;
 
292
      gboolean res;
 
293
      gchar *uri = NULL;
 
294
 
 
295
      if (path != NULL)
 
296
        {
 
297
          res = gtk_tree_model_get_iter (model, &iter, path);
 
298
          if (res)
 
299
            gtk_tree_model_get (model, &iter,
 
300
                                GD_MAIN_COLUMN_URI, &uri,
 
301
                                -1);
 
302
        }
 
303
 
 
304
      uris = g_new0 (gchar *, 2);
 
305
      uris[0] = uri;
 
306
      uris[1] = NULL;
 
307
    }
 
308
 
 
309
  gtk_selection_data_set_uris (data, uris);
 
310
  g_strfreev (uris);
 
311
}