~noskcaj/ubuntu/trusty/thunar/lp-1277149

« back to all changes in this revision

Viewing changes to .pc/02_guard-for-no-supported-vfs-schemas.patch/thunar/thunar-gio-extensions.c

  • Committer: Package Import Robot
  • Author(s): Lionel Le Folgoc
  • Date: 2012-12-03 13:13:58 UTC
  • mfrom: (1.3.4)
  • Revision ID: package-import@ubuntu.com-20121203131358-zk6tkel37d732wh6
Tags: 1.6.0-0ubuntu1
* Upload to raring.
* Remaining Ubuntu change:
  - debian/control: recommend udisks2 for mounting devices. lp: #1014632
* Drop obsolete Ubuntu changes:
  - debian/patches/02_guard-for-no-supported-vfs-schemas.patch,
    debian/patches/xubuntu_fix-duplicate-volumes.patch: included upstream.
* Bugs fixed:
  - "Thunar: sendto_printer broken" lp: #1061846
  - "segfault when a specific html file is selected" lp: #751739
  - "can't book mark remote shares" lp: #778268
  - "Thunar crashed with SIGSEGV in thunarx_menu_provider_get_file_actions()
    thinking a directory was a file" lp: #852410
  - "Left or right-clicking on 3MB or bigger svg file is unresponsive"
    lp: #893330
  - "Thunar crashed with SIGSEGV in fast_validate()" lp: #913041
  - "Thunar crashed with SIGSEGV in thunar_file_get_display_name()"
    lp: #931101
  - "Thunar crashed with SIGSEGV in sort_by_mime_type()" lp: #931842
  - "Thunar crashed with SIGSEGV in thunar_util_parse_parent()" lp: #969222
  - "thunar crashed with SIGSEGV in thunar_standard_view_cancel_thumbnailing()"
    lp: #1059397
  - "Does not unmount USB drive when you try first time" lp: #1059997
  - "regression: thunar no longer shows all unmounted, but mountable, volumes
    in sidepane" lp: #1068947
  - "Thunar shows folder sizes wrong" lp: #59235
  - "Right-click "Open With" list not refreshing" lp: #107392
  - "no thunar contextmenu with GTK setting "gtk-menu-popup-delay = 0""
    lp: #127372
  - "rename folder, still active but answers not on 'Enter'" lp: #479975
  - "Thunar hangs on first launch of each session" lp: #775117
  - "emblems disappear on rename" lp: #877755
  - "Remote Deleted file in Thunar remains visible until resfresh" lp: #999824
  - "Incorrect alphabetical sort order in thunar with non-latin (eg. cyrillic)
    file names" lp: #684317
  - "Thunar does not display current folder name" lp: #875193
  - "Thunar crashed with SIGSEGV in g_file_equal()" lp: #900306
  - "Hard to see, if volume is mounted or not" lp: #838917

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* vi:set et ai sw=2 sts=2 ts=2: */
2
 
/*-
3
 
 * Copyright (c) 2009-2010 Jannis Pohlmann <jannis@xfce.org>
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or 
6
 
 * modify it under the terms of the GNU General Public License as
7
 
 * published by the Free Software Foundation; either version 2 of 
8
 
 * the License, or (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public 
16
 
 * License along with this program; if not, write to the Free 
17
 
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
 * Boston, MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
#ifdef HAVE_CONFIG_H
22
 
#include <config.h>
23
 
#endif
24
 
 
25
 
#include <gio/gio.h>
26
 
#ifdef HAVE_GIO_UNIX
27
 
#include <gio/gunixmounts.h>
28
 
#endif
29
 
 
30
 
#include <exo/exo.h>
31
 
#include <libxfce4util/libxfce4util.h>
32
 
 
33
 
#include <thunar/thunar-file.h>
34
 
#include <thunar/thunar-gio-extensions.h>
35
 
#include <thunar/thunar-private.h>
36
 
#include <thunar/thunar-util.h>
37
 
 
38
 
 
39
 
 
40
 
GFile *
41
 
thunar_g_file_new_for_home (void)
42
 
{
43
 
  return g_file_new_for_path (xfce_get_homedir ());
44
 
}
45
 
 
46
 
 
47
 
 
48
 
GFile *
49
 
thunar_g_file_new_for_root (void)
50
 
{
51
 
  return g_file_new_for_uri ("file:///");
52
 
}
53
 
 
54
 
 
55
 
 
56
 
GFile *
57
 
thunar_g_file_new_for_trash (void)
58
 
{
59
 
  return g_file_new_for_uri ("trash:///");
60
 
}
61
 
 
62
 
 
63
 
 
64
 
GFile *
65
 
thunar_g_file_new_for_desktop (void)
66
 
{
67
 
  return g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP));
68
 
}
69
 
 
70
 
 
71
 
 
72
 
GFile *
73
 
thunar_g_file_new_for_user_special_dir (GUserDirectory dir)
74
 
{
75
 
  const gchar *path;
76
 
 
77
 
  _thunar_return_val_if_fail (dir < G_USER_N_DIRECTORIES, NULL);
78
 
 
79
 
  path = g_get_user_special_dir (dir);
80
 
  if (path == NULL)
81
 
    path = xfce_get_homedir ();
82
 
 
83
 
  return g_file_new_for_path (path);
84
 
}
85
 
 
86
 
 
87
 
 
88
 
gboolean
89
 
thunar_g_file_is_root (GFile *file)
90
 
{
91
 
  GFile   *parent;
92
 
  gboolean is_root = TRUE;
93
 
 
94
 
  parent = g_file_get_parent (file);
95
 
  if (G_UNLIKELY (parent != NULL))
96
 
    {
97
 
      is_root = FALSE;
98
 
      g_object_unref (parent);
99
 
    }
100
 
 
101
 
  return is_root;
102
 
}
103
 
 
104
 
 
105
 
 
106
 
gboolean 
107
 
thunar_g_file_is_trashed (GFile *file)
108
 
{
109
 
  _thunar_return_val_if_fail (G_IS_FILE (file), FALSE);
110
 
  return g_file_has_uri_scheme (file, "trash");
111
 
}
112
 
 
113
 
 
114
 
 
115
 
gboolean
116
 
thunar_g_file_is_home (GFile *file)
117
 
{
118
 
  GFile   *home;
119
 
  gboolean is_home = FALSE;
120
 
 
121
 
  _thunar_return_val_if_fail (G_IS_FILE (file), FALSE);
122
 
 
123
 
  home = thunar_g_file_new_for_home ();
124
 
  is_home = g_file_equal (home, file);
125
 
  g_object_unref (home);
126
 
 
127
 
  return is_home;
128
 
}
129
 
 
130
 
 
131
 
 
132
 
gboolean
133
 
thunar_g_file_is_desktop (GFile *file)
134
 
{
135
 
  GFile   *desktop;
136
 
  gboolean is_desktop;
137
 
 
138
 
  _thunar_return_val_if_fail (G_IS_FILE (file), FALSE);
139
 
 
140
 
  desktop = thunar_g_file_new_for_desktop ();
141
 
  is_desktop = g_file_equal (desktop, file);
142
 
  g_object_unref (desktop);
143
 
 
144
 
  return is_desktop;
145
 
}
146
 
 
147
 
 
148
 
 
149
 
GKeyFile *
150
 
thunar_g_file_query_key_file (GFile              *file,
151
 
                              GCancellable       *cancellable,
152
 
                              GError            **error)
153
 
{
154
 
  GKeyFile *key_file;
155
 
  gchar    *contents = NULL;
156
 
  gsize     length;
157
 
 
158
 
  _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
159
 
  _thunar_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
160
 
  _thunar_return_val_if_fail (error == NULL || *error == NULL, NULL);
161
 
 
162
 
  /* try to load the entire file into memory */
163
 
  if (!g_file_load_contents (file, cancellable, &contents, &length, NULL, error))
164
 
    return NULL;
165
 
 
166
 
  /* allocate a new key file */
167
 
  key_file = g_key_file_new ();
168
 
 
169
 
  /* try to parse the key file from the contents of the file */
170
 
  if (G_LIKELY (length == 0
171
 
      || g_key_file_load_from_data (key_file, contents, length,
172
 
                                    G_KEY_FILE_KEEP_COMMENTS
173
 
                                    | G_KEY_FILE_KEEP_TRANSLATIONS,
174
 
                                    error)))
175
 
    {
176
 
      g_free (contents);
177
 
      return key_file;
178
 
    }
179
 
  else
180
 
    {
181
 
      g_free (contents);
182
 
      g_key_file_free (key_file);
183
 
      return NULL;
184
 
    }
185
 
}
186
 
 
187
 
 
188
 
 
189
 
gboolean
190
 
thunar_g_file_write_key_file (GFile        *file,
191
 
                              GKeyFile     *key_file,
192
 
                              GCancellable *cancellable,
193
 
                              GError      **error)
194
 
{
195
 
  gchar *contents;
196
 
  gsize  length;
197
 
 
198
 
  _thunar_return_val_if_fail (G_IS_FILE (file), FALSE);
199
 
  _thunar_return_val_if_fail (key_file != NULL, FALSE);
200
 
  _thunar_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
201
 
  _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
202
 
 
203
 
  /* write the key file into the contents buffer */
204
 
  contents = g_key_file_to_data (key_file, &length, NULL);
205
 
 
206
 
  /* try to replace the file contents with the key file data */
207
 
  if (!g_file_replace_contents (file, contents, length, NULL, FALSE, 
208
 
                                G_FILE_CREATE_REPLACE_DESTINATION,
209
 
                                NULL, cancellable, error))
210
 
    {
211
 
      g_free (contents);
212
 
      return FALSE;
213
 
    }
214
 
  else
215
 
    {
216
 
      g_free (contents);
217
 
      return TRUE;
218
 
    }
219
 
}
220
 
 
221
 
 
222
 
 
223
 
gchar *
224
 
thunar_g_file_get_location (GFile *file)
225
 
{
226
 
  gchar *location;
227
 
 
228
 
  _thunar_return_val_if_fail (G_IS_FILE (file), NULL);
229
 
  
230
 
  location = g_file_get_path (file);
231
 
  if (location == NULL)
232
 
    location = g_file_get_uri (file);
233
 
 
234
 
  return location;
235
 
}
236
 
 
237
 
 
238
 
 
239
 
gboolean
240
 
thunar_g_vfs_is_uri_scheme_supported (const gchar *scheme)
241
 
{
242
 
  const gchar * const *supported_schemes;
243
 
  gboolean             supported = FALSE;
244
 
  guint                n;
245
 
  GVfs                *gvfs;
246
 
 
247
 
  _thunar_return_val_if_fail (scheme != NULL && *scheme != '\0', FALSE);
248
 
 
249
 
  gvfs = g_vfs_get_default ();
250
 
  supported_schemes = g_vfs_get_supported_uri_schemes (gvfs);
251
 
 
252
 
  for (n = 0; !supported && supported_schemes[n] != NULL; ++n) 
253
 
    if (g_strcmp0 (supported_schemes[n], scheme) == 0)
254
 
      supported = TRUE;
255
 
 
256
 
  return supported;
257
 
}
258
 
 
259
 
 
260
 
 
261
 
GType
262
 
thunar_g_file_list_get_type (void)
263
 
{
264
 
  static GType type = G_TYPE_INVALID;
265
 
 
266
 
  if (G_UNLIKELY (type == G_TYPE_INVALID))
267
 
    {
268
 
      type = g_boxed_type_register_static (I_("ThunarGFileList"),
269
 
                                           (GBoxedCopyFunc) thunar_g_file_list_copy,
270
 
                                           (GBoxedFreeFunc) thunar_g_file_list_free);
271
 
    }
272
 
 
273
 
  return type;
274
 
}
275
 
 
276
 
 
277
 
 
278
 
/**
279
 
 * thunar_g_file_list_new_from_string:
280
 
 * @string : a string representation of an URI list.
281
 
 *
282
 
 * Splits an URI list conforming to the text/uri-list
283
 
 * mime type defined in RFC 2483 into individual URIs,
284
 
 * discarding any comments and whitespace. The resulting
285
 
 * list will hold one #GFile for each URI.
286
 
 *
287
 
 * If @string contains no URIs, this function
288
 
 * will return %NULL.
289
 
 *
290
 
 * Return value: the list of #GFile<!---->s or %NULL.
291
 
 **/
292
 
GList *
293
 
thunar_g_file_list_new_from_string (const gchar *string)
294
 
{
295
 
  GList  *list = NULL;
296
 
  gchar **uris;
297
 
  gsize   n;
298
 
 
299
 
  uris = g_uri_list_extract_uris (string);
300
 
 
301
 
  for (n = 0; uris != NULL && uris[n] != NULL; ++n)
302
 
    list = g_list_append (list, g_file_new_for_uri (uris[n]));
303
 
 
304
 
  g_strfreev (uris);
305
 
 
306
 
  return list;
307
 
}
308
 
 
309
 
 
310
 
 
311
 
/**
312
 
 * thunar_g_file_list_to_string:
313
 
 * @list : a list of #GFile<!---->s.
314
 
 *
315
 
 * Free the returned value using g_free() when you
316
 
 * are done with it.
317
 
 *
318
 
 * Return value: the string representation of @list conforming to the
319
 
 *               text/uri-list mime type defined in RFC 2483.
320
 
 **/
321
 
gchar *
322
 
thunar_g_file_list_to_string (GList *list)
323
 
{
324
 
  GString *string;
325
 
  gchar   *uri;
326
 
  GList   *lp;
327
 
 
328
 
  /* allocate initial string */
329
 
  string = g_string_new (NULL);
330
 
 
331
 
  for (lp = list; lp != NULL; lp = lp->next)
332
 
    {
333
 
      uri = g_file_get_uri (lp->data);
334
 
      string = g_string_append (string, uri);
335
 
      g_free (uri);
336
 
 
337
 
      string = g_string_append (string, "\r\n");
338
 
    }
339
 
 
340
 
  return g_string_free (string, FALSE);
341
 
}
342
 
 
343
 
 
344
 
 
345
 
GList *
346
 
thunar_g_file_list_append (GList *list,
347
 
                           GFile *file)
348
 
{
349
 
  return g_list_append (list, g_object_ref (file));
350
 
}
351
 
 
352
 
 
353
 
 
354
 
GList *
355
 
thunar_g_file_list_prepend (GList *list,
356
 
                            GFile *file)
357
 
{
358
 
  return g_list_prepend (list, g_object_ref (file));
359
 
}
360
 
 
361
 
 
362
 
 
363
 
/**
364
 
 * thunar_g_file_list_copy:
365
 
 * @list : a list of #GFile<!---->s.
366
 
 *
367
 
 * Takes a deep copy of @list and returns the
368
 
 * result. The caller is responsible to free the
369
 
 * returned list using thunar_g_file_list_free().
370
 
 *
371
 
 * Return value: a deep copy of @list.
372
 
 **/
373
 
GList*
374
 
thunar_g_file_list_copy (GList *list)
375
 
{
376
 
  GList *copy = NULL;
377
 
  GList *lp;
378
 
 
379
 
  for (lp = g_list_last (list); lp != NULL; lp = lp->prev)
380
 
    copy = g_list_prepend (copy, g_object_ref (lp->data));
381
 
 
382
 
  return copy;
383
 
}
384
 
 
385
 
 
386
 
 
387
 
/**
388
 
 * thunar_g_file_list_free:
389
 
 * @list : a list of #GFile<!---->s.
390
 
 *
391
 
 * Frees the #GFile<!---->s in @list and
392
 
 * the @list itself.
393
 
 **/
394
 
void
395
 
thunar_g_file_list_free (GList *list)
396
 
{
397
 
  GList *lp;
398
 
  for (lp = list; lp != NULL; lp = lp->next)
399
 
    g_object_unref (lp->data);
400
 
  g_list_free (list);
401
 
}
402
 
 
403
 
 
404
 
 
405
 
#ifdef HAVE_GIO_UNIX
406
 
static gboolean
407
 
thunar_g_mount_is_internal (GMount *mount)
408
 
{
409
 
  const gchar *point_mount_path;
410
 
  gboolean     is_internal = FALSE;
411
 
  GFile       *root;
412
 
  GList       *lp;
413
 
  GList       *mount_points;
414
 
  gchar       *mount_path;
415
 
 
416
 
  _thunar_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
417
 
 
418
 
  /* determine the mount path */
419
 
  root = g_mount_get_root (mount);
420
 
  mount_path = g_file_get_path (root);
421
 
  g_object_unref (root);
422
 
 
423
 
  /* assume non-internal if we cannot determine the path */
424
 
  if (mount_path == NULL)
425
 
    return FALSE;
426
 
 
427
 
  if (g_unix_is_mount_path_system_internal (mount_path))
428
 
    {
429
 
      /* mark as internal */
430
 
      is_internal = TRUE;
431
 
    }
432
 
  else
433
 
    {
434
 
      /* get a list of all mount points */
435
 
      mount_points = g_unix_mount_points_get (NULL);
436
 
 
437
 
      /* search for the mount point associated with the mount entry */
438
 
      for (lp = mount_points; !is_internal && lp != NULL; lp = lp->next)
439
 
        {
440
 
          point_mount_path = g_unix_mount_point_get_mount_path (lp->data);
441
 
 
442
 
          /* check if this is the mount point we are looking for */
443
 
          if (g_strcmp0 (mount_path, point_mount_path) == 0)
444
 
            {
445
 
              /* mark as internal if the user cannot mount this device */
446
 
              if (!g_unix_mount_point_is_user_mountable (lp->data))
447
 
                is_internal = TRUE;
448
 
            }
449
 
              
450
 
          /* free the mount point, we no longer need it */
451
 
          g_unix_mount_point_free (lp->data);
452
 
        }
453
 
 
454
 
      /* free the mount point list */
455
 
      g_list_free (mount_points);
456
 
    }
457
 
 
458
 
  g_free (mount_path);
459
 
 
460
 
  return is_internal;
461
 
}
462
 
#endif
463
 
 
464
 
 
465
 
 
466
 
gboolean
467
 
thunar_g_volume_is_removable (GVolume *volume)
468
 
{
469
 
  gboolean         can_eject = FALSE;
470
 
  gboolean         can_mount = FALSE;
471
 
  gboolean         can_unmount = FALSE;
472
 
  gboolean         is_removable = FALSE;
473
 
  gboolean         is_internal = FALSE;
474
 
  GDrive          *drive;
475
 
  GMount          *mount;
476
 
 
477
 
  _thunar_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
478
 
  
479
 
  /* check if the volume can be ejected */
480
 
  can_eject = g_volume_can_eject (volume);
481
 
 
482
 
  /* determine the drive for the volume */
483
 
  drive = g_volume_get_drive (volume);
484
 
  if (drive != NULL)
485
 
    {
486
 
      /*check if the drive media can be removed */
487
 
      is_removable = g_drive_is_media_removable (drive);
488
 
 
489
 
      /* release the drive */
490
 
      g_object_unref (drive);
491
 
    }
492
 
 
493
 
  /* determine the mount for the volume (if it is mounted at all) */
494
 
  mount = g_volume_get_mount (volume);
495
 
  if (mount != NULL)
496
 
    {
497
 
#ifdef HAVE_GIO_UNIX
498
 
      is_internal = thunar_g_mount_is_internal (mount);
499
 
#endif
500
 
 
501
 
      /* check if the volume can be unmounted */
502
 
      can_unmount = g_mount_can_unmount (mount);
503
 
 
504
 
      /* release the mount */
505
 
      g_object_unref (mount);
506
 
    }
507
 
 
508
 
  /* determine whether the device can be mounted */
509
 
  can_mount = g_volume_can_mount (volume);
510
 
 
511
 
  return (!is_internal) && (can_eject || can_unmount || is_removable || can_mount);
512
 
}
513
 
 
514
 
 
515
 
 
516
 
gboolean
517
 
thunar_g_volume_is_mounted (GVolume *volume)
518
 
{
519
 
  gboolean is_mounted = FALSE;
520
 
  GMount  *mount;
521
 
 
522
 
  _thunar_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
523
 
 
524
 
  /* determine the mount for this volume (if it is mounted at all) */
525
 
  mount = g_volume_get_mount (volume);
526
 
  if (mount != NULL)
527
 
    {
528
 
      is_mounted = TRUE;
529
 
      g_object_unref (mount);
530
 
    }
531
 
 
532
 
  return is_mounted;
533
 
}
534
 
 
535
 
 
536
 
 
537
 
gboolean 
538
 
thunar_g_volume_is_present (GVolume *volume)
539
 
{
540
 
  gboolean has_media = FALSE;
541
 
  gboolean is_shadowed = FALSE;
542
 
  GDrive  *drive;
543
 
  GMount  *mount;
544
 
 
545
 
  _thunar_return_val_if_fail (G_IS_VOLUME (volume), FALSE);
546
 
 
547
 
  drive = g_volume_get_drive (volume);
548
 
  if (drive != NULL)
549
 
    {
550
 
      has_media = g_drive_has_media (drive);
551
 
      g_object_unref (drive);
552
 
    }
553
 
 
554
 
  mount = g_volume_get_mount (volume);
555
 
  if (mount != NULL)
556
 
    {
557
 
      is_shadowed = g_mount_is_shadowed (mount);
558
 
      g_object_unref (mount);
559
 
    }
560
 
 
561
 
  return has_media && !is_shadowed;
562
 
}
563
 
 
564
 
 
565
 
 
566
 
gboolean
567
 
thunar_g_app_info_launch (GAppInfo          *info,
568
 
                          GFile             *working_directory,
569
 
                          GList             *path_list,
570
 
                          GAppLaunchContext *context,
571
 
                          GError           **error)
572
 
{
573
 
  gboolean result = FALSE;
574
 
  gchar   *new_path = NULL;
575
 
  gchar   *old_path = NULL;
576
 
 
577
 
  _thunar_return_val_if_fail (G_IS_APP_INFO (info), FALSE);
578
 
  _thunar_return_val_if_fail (working_directory == NULL || G_IS_FILE (working_directory), FALSE);
579
 
  _thunar_return_val_if_fail (path_list != NULL, FALSE);
580
 
  _thunar_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), FALSE);
581
 
  _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
582
 
 
583
 
  /* check if we want to set the working directory of the spawned app */
584
 
  if (working_directory != NULL)
585
 
    {
586
 
      /* determine the working directory path */
587
 
      new_path = g_file_get_path (working_directory);
588
 
      if (new_path != NULL)
589
 
        {
590
 
          /* switch to the desired working directory, remember that of Thunar itself */
591
 
          old_path = thunar_util_change_working_directory (new_path);
592
 
 
593
 
          /* forget about the new working directory path */
594
 
          g_free (new_path);
595
 
        }
596
 
    }
597
 
 
598
 
  /* launch the paths with the specified app info */
599
 
  result = g_app_info_launch (info, path_list, context, error);
600
 
 
601
 
  /* check if we need to reset the working directory to the one Thunar was
602
 
   * opened from */
603
 
  if (old_path != NULL)
604
 
    {
605
 
      /* switch to Thunar's original working directory */
606
 
      new_path = thunar_util_change_working_directory (old_path);
607
 
 
608
 
      /* clean up */
609
 
      g_free (new_path);
610
 
      g_free (old_path);
611
 
    }
612
 
 
613
 
  return result;
614
 
}
615