~ubuntu-branches/ubuntu/utopic/cairo-dock-plug-ins/utopic-201408192140

« back to all changes in this revision

Viewing changes to .pc/bzr3045-3046_GVFS_support_x-nautilus-desktop_and_fixed_typos_and_memory_leaks.patch/gvfs-integration/cairo-dock-gio-vfs.c

  • Committer: Matthieu Baerts
  • Date: 2014-04-06 23:04:40 UTC
  • mfrom: (1.1.37)
  • Revision ID: matttbe@gmail.com-20140406230440-ho7ktfc4a7vndigu
Tags: 3.3.99.beta1.2.really.3.3.2-0ubuntu1
* Revert back to the 3.3.2 version: (LP: #1302246)
  Unfortunately, due to the lack of time, we have to revert back to the
  latest stable version. Sorry for that but feel free to help us ;-)
* debian/patches: cherry-pick patches from upstream BZR repo, all 'bug-fix'
  and changes that were already in the 3.3.99.beta1 version except all
  changes linked to the new style, the menu and the configuration.
  - bzr3008_GMenu_new_apps_in_the_list.patch: GMenu: New Apps: if there are
    new apps when the 'new apps' dialogue is opened, add these new apps in
    the list
  - bzr3010_GMenu_option_hide_new_apps_dialogue.patch: GMenu: Config: Added
    the possibility to not display notification to quickly launch new apps
  - bzr3021_Terminal_launch_default_terminal_middle_click.patch: Terminal:
    middle click: launch the default terminal
  - bzr3031-3032_GMenu_remove_empty_submenus.patch: GMenu: do not add empty
    submenus when creating them and remove empty submenus
  - bzr3035_DND2Share_History_was_empty.patch: DnD2Share: history menu was
    empty
  - bzr3036-3040_Shortcuts_removed_disk_usage_on_bookmarks_and_support_
    x-nautilus_URI.patch: Shortcuts: correctly removed an old bookmark ;
    added support for x-nautilus-(...) URI ; avoid duplicated code +
    bookmarks doesn't have a disk usage ; translated a few sentences from
    French to English
  - bzr3043_Fixed_typo_with_some_sentences.patch: Fixed typo with some
    sentences which were not correctly translated
  - bzr3045-3046_GVFS_support_x-nautilus-desktop_and_fixed_typos_and_memory_
    leaks.patch: gvfs: fixed typo and tiny memory leak ; GTK3: 'x-nautilus-
    desktop' is just an URI where the root is the path to the desktop
  - bzr3047-3048_Status-Notifier_Added_support_of_middle_click_and_scroll:
    Status-Notifier: IAS (ubuntu): added the support of the middle click ;
    Scroll signals were not catched
  - bzr3051_Logout_Added_support_of_Cinnamon.patch: logout: added support of
    Cinnamon
  - bzr3057_GMenu_new_apps_show_dialog_after_installation.patch: GMenu: new
    apps: show the dialog only after the end of the installation
  - bzr3065_Impulse_do_not_redraw_icon_when_not_needed.patch: Impulse: stop
    animations: do not redraw the icon if it's not needed (e.g. when
    disabling the applet)
  - bzr3067_AlsaMixer_support_cinnamon_settings.patch: AlsaMixer: added the
    support of cinnamon-settings
  - bzr3068_Clock_fixed_a_crash_when_configuring_when_not_enabled.patch:
    Clock: fixed a crash when configuring the applet if it's not activated
  - bzr3069_Indicator_Generic_no_need_to_hide_the_icon_before_removing_it:
    Indicator Generic: stop: no need to hide the icon before removing it
* debian/control: bumped Core versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 3
 
10
* of the License, or (at your option) any later version.
 
11
*
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
// If Gio is not detected, do not try to compile this file.
 
21
// Note: Gio is present from GLib >= 2.16
 
22
#include "cairo-dock-gio-vfs.h"
 
23
 
 
24
#ifdef HAVE_LIBGIO
 
25
#include <string.h>
 
26
#include <stdlib.h>
 
27
 
 
28
#include <glib.h>
 
29
#include <gio/gio.h>
 
30
#define G_VFS_DBUS_DAEMON_NAME "org.gtk.vfs.Daemon"
 
31
 
 
32
#include <cairo-dock.h>
 
33
 
 
34
static void _cairo_dock_gio_vfs_empty_dir (const gchar *cBaseURI);
 
35
 
 
36
static GHashTable *s_hMonitorHandleTable = NULL;
 
37
 
 
38
static void _gio_vfs_free_monitor_data (gpointer *data)
 
39
{
 
40
        if (data != NULL)
 
41
        {
 
42
                GFileMonitor *pHandle = data[2];
 
43
                g_file_monitor_cancel (pHandle);
 
44
                g_object_unref (pHandle);
 
45
                g_free (data);
 
46
        }
 
47
}
 
48
 
 
49
gboolean cairo_dock_gio_vfs_init (void)
 
50
{
 
51
        // first, check that the session has gvfs on DBus
 
52
        if( !cairo_dock_dbus_is_enabled() ||
 
53
            !cairo_dock_dbus_detect_application (G_VFS_DBUS_DAEMON_NAME) )
 
54
        {
 
55
                cd_warning("VFS Deamon NOT found on DBus !");
 
56
          return FALSE;
 
57
        }
 
58
        cd_message("VFS Deamon found on DBus.");
 
59
        
 
60
        
 
61
        if (s_hMonitorHandleTable != NULL)
 
62
                g_hash_table_destroy (s_hMonitorHandleTable);
 
63
        
 
64
        s_hMonitorHandleTable = g_hash_table_new_full (g_str_hash,
 
65
                g_str_equal,
 
66
                g_free,
 
67
                (GDestroyNotify) _gio_vfs_free_monitor_data);
 
68
        
 
69
        GVfs *vfs = g_vfs_get_default ();
 
70
        return (vfs != NULL && g_vfs_is_active (vfs));  // utile ?
 
71
}
 
72
 
 
73
/* no longer used...
 
74
static void cairo_dock_gio_vfs_stop (void)
 
75
{
 
76
        if (s_hMonitorHandleTable != NULL)
 
77
        {
 
78
                g_hash_table_destroy (s_hMonitorHandleTable);
 
79
                s_hMonitorHandleTable = NULL;
 
80
        }
 
81
}
 
82
*/
 
83
 
 
84
static gchar *_cd_get_icon_path (GIcon *pIcon, const gchar *cTargetURI)  // cTargetURI est l'URI que represente l'icone, pour les cas ou l'icone est contenue dans le repertoire lui-meme (CD ou DVD de jeux notamment)
 
85
{
 
86
        //g_print ("%s ()\n", __func__);
 
87
        gchar *cIconPath = NULL;
 
88
        if (G_IS_THEMED_ICON (pIcon))
 
89
        {
 
90
                const gchar * const *cFileNames = g_themed_icon_get_names (G_THEMED_ICON (pIcon));
 
91
                //cd_message ("icones possibles : %s", g_strjoinv (":", (gchar **) cFileNames));
 
92
                int i;
 
93
                for (i = 0; cFileNames[i] != NULL && cIconPath == NULL; i ++)
 
94
                {
 
95
                        //g_print (" une icone possible est : %s\n", cFileNames[i]);
 
96
                        
 
97
                        gchar *path = cairo_dock_search_icon_s_path (cFileNames[i], CAIRO_DOCK_DEFAULT_ICON_SIZE);
 
98
                        if (path)
 
99
                        {
 
100
                                g_free (path);
 
101
                                cIconPath = g_strdup (cFileNames[i]);
 
102
                        }
 
103
                        
 
104
                        //g_print ("  chemin trouve : %s\n", cIconPath);
 
105
                }
 
106
        }
 
107
        else if (G_IS_FILE_ICON (pIcon))
 
108
        {
 
109
                GFile *pFile = g_file_icon_get_file (G_FILE_ICON (pIcon));
 
110
                cIconPath = g_file_get_basename (pFile);
 
111
                //g_print (" file_icon => %s\n", cIconPath);
 
112
                
 
113
                if (cTargetURI && cIconPath && g_str_has_suffix (cIconPath, ".ico"))  // cas des montages de CD ou d'iso
 
114
                {
 
115
                        gchar *tmp = cIconPath;
 
116
                        cIconPath = g_strdup_printf ("%s/%s", cTargetURI, tmp);
 
117
                        g_free (tmp);
 
118
                        if (strncmp (cIconPath, "file://", 7) == 0)
 
119
                        {
 
120
                                tmp = cIconPath;
 
121
                                cIconPath = g_filename_from_uri (tmp, NULL, NULL);
 
122
                                g_free (tmp);
 
123
                        }
 
124
                }
 
125
        }
 
126
        return cIconPath;
 
127
}
 
128
 
 
129
 
 
130
static void _cd_find_mount_from_volume_name (const gchar *cVolumeName, GMount **pFoundMount, gchar **cURI, gchar **cIconName)
 
131
{
 
132
        g_return_if_fail (cVolumeName != NULL);
 
133
        cd_message ("%s (%s)", __func__, cVolumeName);
 
134
        GFile *pFile = g_file_new_for_uri ("computer://");
 
135
        GError *erreur = NULL;
 
136
        const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE","
 
137
                G_FILE_ATTRIBUTE_STANDARD_NAME","
 
138
                ///G_FILE_ATTRIBUTE_STANDARD_ICON","
 
139
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI;
 
140
        GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile,
 
141
                cAttributes,
 
142
                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
143
                NULL,
 
144
                &erreur);
 
145
        if (erreur != NULL)
 
146
        {
 
147
                cd_warning ("gvfs-integration : %s", erreur->message);
 
148
                g_error_free (erreur);
 
149
                g_object_unref (pFile);
 
150
                return ;
 
151
        }
 
152
        
 
153
        GFileInfo *pFileInfo;
 
154
        do
 
155
        {
 
156
                pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur);
 
157
                if (erreur != NULL)
 
158
                {
 
159
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
160
                        g_error_free (erreur);
 
161
                        erreur = NULL;
 
162
                }
 
163
                else
 
164
                {
 
165
                        if (pFileInfo == NULL)
 
166
                                break ;
 
167
                        GFileType iFileType = g_file_info_get_file_type (pFileInfo);
 
168
                        if (iFileType == G_FILE_TYPE_MOUNTABLE)
 
169
                        {
 
170
                                const gchar *cFileName = g_file_info_get_name (pFileInfo);
 
171
                                cd_debug ("  test of  %s...", cFileName);
 
172
                                const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
 
173
                                
 
174
                                GMount *pMount = NULL;
 
175
                                if (cTargetURI != NULL)
 
176
                                {
 
177
                                        GFile *file = g_file_new_for_uri (cTargetURI);
 
178
                                        pMount = g_file_find_enclosing_mount (file, NULL, NULL);
 
179
                                        g_object_unref (file);
 
180
                                }
 
181
                                if (pMount != NULL)
 
182
                                {
 
183
                                        gchar *cName = g_mount_get_name (pMount);
 
184
                                        cd_message ("    mount : %s", cName);
 
185
                                        if (cName != NULL && strcmp (cName, cVolumeName) == 0)
 
186
                                        {
 
187
                                                cd_debug ("Found");
 
188
                                                *pFoundMount = pMount;
 
189
                                                *cURI = g_strconcat ("computer:///", cFileName, NULL);
 
190
                                                GIcon *pSystemIcon = g_mount_get_icon (pMount);
 
191
                                                *cIconName = _cd_get_icon_path (pSystemIcon, NULL);
 
192
                                                g_object_unref (pSystemIcon);
 
193
                                                g_free (cName);
 
194
                                                break ;
 
195
                                        }
 
196
                                        g_free (cName);
 
197
                                }
 
198
                        }
 
199
                        g_object_unref (pFileInfo);
 
200
                }
 
201
        } while (TRUE);
 
202
        g_object_unref (pFileEnum);
 
203
        g_object_unref (pFile);
 
204
}
 
205
 
 
206
static GDrive *_cd_find_drive_from_name (const gchar *cName)
 
207
{
 
208
        g_return_val_if_fail (cName != NULL, NULL);
 
209
        cd_message ("%s (%s)", __func__, cName);
 
210
        GVolumeMonitor *pVolumeMonitor = g_volume_monitor_get ();
 
211
        GDrive *pFoundDrive = NULL;
 
212
        
 
213
        gchar *str = strrchr (cName, '-');
 
214
        if (str)
 
215
                *str = '\0';
 
216
        
 
217
        //\___________________ On chope les disques connectes (lecteur de CD/disquette/etc) et on liste leurs volumes.
 
218
        GList *pDrivesList = g_volume_monitor_get_connected_drives (pVolumeMonitor);
 
219
        GList *dl;
 
220
        GDrive *pDrive;
 
221
        gchar *cDriveName;
 
222
        for (dl = pDrivesList; dl != NULL; dl = dl->next)
 
223
        {
 
224
                pDrive = dl->data;
 
225
                if (pFoundDrive == NULL)
 
226
                {
 
227
                        cDriveName = g_drive_get_name  (pDrive);
 
228
                        cd_message ("  drive '%s'", cDriveName);
 
229
                        if (cDriveName != NULL && strcmp (cDriveName, cName) == 0)
 
230
                                pFoundDrive = pDrive;
 
231
                        else
 
232
                                g_object_unref (pDrive);
 
233
                        g_free (cDriveName);
 
234
                }
 
235
                else
 
236
                        g_object_unref (pDrive);
 
237
        }
 
238
        g_list_free (pDrivesList);
 
239
        if (str)
 
240
                *str = '-';
 
241
        return pFoundDrive;
 
242
}
 
243
static gchar *_cd_find_volume_name_from_drive_name (const gchar *cName)
 
244
{
 
245
        g_return_val_if_fail (cName != NULL, NULL);
 
246
        cd_message ("%s (%s)", __func__, cName);
 
247
        GDrive *pDrive = _cd_find_drive_from_name (cName);
 
248
        g_return_val_if_fail (pDrive != NULL, NULL);
 
249
        
 
250
        gchar *cVolumeName = NULL;
 
251
        GList *pAssociatedVolumes = g_drive_get_volumes (pDrive);
 
252
        g_object_unref (pDrive);
 
253
        if (pAssociatedVolumes == NULL)
 
254
                return NULL;
 
255
        
 
256
        int iNumVolume;
 
257
        gchar *str = strrchr (cName, '-');
 
258
        if (str)
 
259
        {
 
260
                iNumVolume = atoi (str+1);
 
261
        }
 
262
        else
 
263
                iNumVolume = 0;
 
264
        
 
265
        GVolume *pVolume = g_list_nth_data (pAssociatedVolumes, iNumVolume);
 
266
        if (pVolume != NULL)
 
267
        {
 
268
                cVolumeName = g_volume_get_name (pVolume);
 
269
        }
 
270
        cd_debug ("%dth volume -> cVolumeName : %s", iNumVolume, cVolumeName);
 
271
        
 
272
        /* cd_debug ("List of unavailable volumes on this disc:");
 
273
        GList *av;
 
274
        gchar *cLog;
 
275
        for (av = pAssociatedVolumes; av != NULL; av = av->next)
 
276
        {
 
277
                pVolume = av->data;
 
278
                cLog = g_volume_get_name (pVolume);
 
279
                cd_debug ("  - %s", cLog);
 
280
                g_free (cLog);
 
281
        }*/
 
282
        
 
283
        g_list_foreach (pAssociatedVolumes, (GFunc)g_object_unref, NULL);
 
284
        g_list_free (pAssociatedVolumes);
 
285
        
 
286
        return cVolumeName;
 
287
}
 
288
static gboolean _cd_find_can_eject_from_drive_name (const gchar *cName)
 
289
{
 
290
        cd_debug ("%s (%s)", __func__, cName);
 
291
        GDrive *pDrive = _cd_find_drive_from_name (cName);
 
292
        g_return_val_if_fail (pDrive != NULL, FALSE);
 
293
        
 
294
        gboolean bCanEject = g_drive_can_eject (pDrive);
 
295
        g_object_unref (pDrive);
 
296
        return bCanEject;
 
297
}
 
298
 
 
299
static void cairo_dock_gio_vfs_get_file_info (const gchar *cBaseURI, gchar **cName, gchar **cURI, gchar **cIconName, gboolean *bIsDirectory, int *iVolumeID, double *fOrder, CairoDockFMSortType iSortType)
 
300
{
 
301
        *cName = NULL;
 
302
        *cURI = NULL;
 
303
        *cIconName = NULL;
 
304
        g_return_if_fail (cBaseURI != NULL);
 
305
        GError *erreur = NULL;
 
306
        cd_message ("%s (%s)", __func__, cBaseURI);
 
307
        
 
308
        // make it a valid URI.
 
309
        gchar *cValidUri;
 
310
        if (strncmp (cBaseURI, "x-nautilus-desktop://", 21) == 0)  // shortcut on the desktop (nautilus)
 
311
        {
 
312
                gchar *cNautilusFile = g_strdup (cBaseURI+14);
 
313
                memcpy (cNautilusFile, "file", 4);
 
314
                if (g_str_has_suffix (cBaseURI, ".volume"))
 
315
                {
 
316
                        cNautilusFile[strlen(cNautilusFile)-7] = '\0';
 
317
                }
 
318
                else if (g_str_has_suffix (cBaseURI, ".drive"))
 
319
                {
 
320
                        cNautilusFile[strlen(cNautilusFile)-6] = '\0';
 
321
                }
 
322
                cValidUri = g_filename_from_uri (cNautilusFile, NULL, &erreur);
 
323
                if (erreur != NULL)
 
324
                {
 
325
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
326
                        g_error_free (erreur);
 
327
                        return ;
 
328
                }
 
329
                gchar *cVolumeName = cValidUri + 1;  // we drop the '/'.
 
330
                cd_message ("cVolumeName : %s", cVolumeName);
 
331
                
 
332
                GMount *pMount = NULL;
 
333
                gchar *uri=NULL, *iconname=NULL;
 
334
                _cd_find_mount_from_volume_name (cVolumeName, &pMount, &uri, &iconname);
 
335
                g_return_if_fail (pMount != NULL);
 
336
                
 
337
                if (cURI)
 
338
                        *cURI = uri;
 
339
                else
 
340
                        g_free (uri);
 
341
                if (cIconName)
 
342
                        *cIconName = iconname;
 
343
                else
 
344
                        g_free (iconname);
 
345
                if (cName)
 
346
                        *cName = g_strdup (cVolumeName);
 
347
                if (bIsDirectory)
 
348
                        *bIsDirectory = TRUE;
 
349
                if (iVolumeID)
 
350
                        *iVolumeID = 1;
 
351
                if (fOrder)
 
352
                        *fOrder = 0;
 
353
                
 
354
                g_object_unref (pMount);
 
355
                g_free (cValidUri);
 
356
                g_free (cNautilusFile);
 
357
                return;
 
358
        }
 
359
        else  // normal file
 
360
        {
 
361
                if (*cBaseURI == '/')
 
362
                        cValidUri = g_filename_to_uri (cBaseURI, NULL, NULL);
 
363
                else
 
364
                        cValidUri = g_strdup (cBaseURI);
 
365
                // strange case when unmounting a FTP bookmark when it's not available: crash with DBus
 
366
                if (*cBaseURI == ':' || *cValidUri == ':')
 
367
                {
 
368
                        cd_warning ("invalid URI (%s ; %s), skip it", cBaseURI, cValidUri);
 
369
                        g_free (cValidUri);
 
370
                        return;
 
371
                }
 
372
        }
 
373
        
 
374
        // get its attributes.
 
375
        GFile *pFile = g_file_new_for_uri (cValidUri);
 
376
        g_return_if_fail (pFile);
 
377
        const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_TYPE","
 
378
                G_FILE_ATTRIBUTE_STANDARD_SIZE","
 
379
                G_FILE_ATTRIBUTE_TIME_MODIFIED","
 
380
                G_FILE_ATTRIBUTE_TIME_ACCESS","
 
381
                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
 
382
                G_FILE_ATTRIBUTE_STANDARD_NAME","
 
383
                G_FILE_ATTRIBUTE_STANDARD_ICON","
 
384
                G_FILE_ATTRIBUTE_THUMBNAIL_PATH","
 
385
                #if (GLIB_MAJOR_VERSION > 2) || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 20)
 
386
                ///G_FILE_ATTRIBUTE_PREVIEW_ICON","
 
387
                #endif
 
388
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI;
 
389
        GFileInfo *pFileInfo = g_file_query_info (pFile,
 
390
                cQuery,
 
391
                G_FILE_QUERY_INFO_NONE,  /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
 
392
                NULL,
 
393
                &erreur);
 
394
        if (erreur != NULL)  // peut arriver si l'emplacement n'est pas monte.
 
395
        {
 
396
                cd_debug ("gvfs-integration : %s", erreur->message);  // inutile d'en faire un warning.
 
397
                g_error_free (erreur);
 
398
                g_free (cValidUri);
 
399
                g_object_unref (pFile);
 
400
                return ;
 
401
        }
 
402
        
 
403
        const gchar *cFileName = g_file_info_get_name (pFileInfo);
 
404
        const gchar *cMimeType = g_file_info_get_content_type (pFileInfo);
 
405
        GFileType iFileType = g_file_info_get_file_type (pFileInfo);
 
406
        const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
 
407
        
 
408
        // find the order of the file
 
409
        if (fOrder)
 
410
        {
 
411
                if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
 
412
                {
 
413
                        GTimeVal t;
 
414
                        g_file_info_get_modification_time (pFileInfo, &t);
 
415
                        *fOrder = t.tv_sec;
 
416
                }
 
417
                else if (iSortType == CAIRO_DOCK_FM_SORT_BY_ACCESS)
 
418
                        *fOrder =  g_file_info_get_attribute_uint64 (pFileInfo, G_FILE_ATTRIBUTE_TIME_ACCESS);
 
419
                else if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
 
420
                        *fOrder = g_file_info_get_size (pFileInfo);
 
421
                else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
 
422
                        *fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0);
 
423
                else
 
424
                        *fOrder = 0;
 
425
        }
 
426
        
 
427
        if (bIsDirectory)
 
428
                *bIsDirectory = (iFileType == G_FILE_TYPE_DIRECTORY);
 
429
        
 
430
        
 
431
        // find a readable name if it's a mount point.
 
432
        if (iFileType == G_FILE_TYPE_MOUNTABLE)
 
433
        {
 
434
                if (iVolumeID)
 
435
                        *iVolumeID = 1;
 
436
                
 
437
                if (cName)
 
438
                {
 
439
                        *cName = NULL;
 
440
                        
 
441
                        cd_message ("  cTargetURI:%s", cTargetURI);
 
442
                        GMount *pMount = NULL;
 
443
                        if (cTargetURI != NULL)
 
444
                        {
 
445
                                GFile *file = g_file_new_for_uri (cTargetURI);
 
446
                                pMount = g_file_find_enclosing_mount (file, NULL, NULL);
 
447
                                g_object_unref (file);
 
448
                        }
 
449
                        if (pMount != NULL)
 
450
                        {
 
451
                                *cName = g_mount_get_name (pMount);
 
452
                                cd_message ("un GMount existe (%s)",* cName);
 
453
                                g_object_unref (pMount);
 
454
                        }
 
455
                        else
 
456
                        {
 
457
                                gchar *cMountName = g_strdup (cFileName);
 
458
                                gchar *str = strrchr (cMountName, '.');  // on vire l'extension ".volume" ou ".drive".
 
459
                                if (str != NULL)
 
460
                                {
 
461
                                        *str = '\0';
 
462
                                        if (strcmp (str+1, "link") == 0)  // pour les liens, on prend le nom du lien.
 
463
                                        {
 
464
                                                if (strcmp (cMountName, "root") == 0)  // on remplace 'root' par un nom plus parlant, sinon on prendra le nom du lien.
 
465
                                                {
 
466
                                                        *cName = g_strdup (D_("File System"));
 
467
                                                }
 
468
                                        }
 
469
                                        else if (strcmp (str+1, "drive") == 0)  // on cherche un nom plus parlant si possible.
 
470
                                        {
 
471
                                                gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cMountName);
 
472
                                                if (cVolumeName != NULL)
 
473
                                                {
 
474
                                                        *cName = cVolumeName;
 
475
                                                }
 
476
                                        }
 
477
                                }
 
478
                                if (*cName == NULL)
 
479
                                        *cName = cMountName;
 
480
                                else
 
481
                                        g_free (cMountName);
 
482
                        }
 
483
                        if (*cName ==  NULL)
 
484
                                *cName = g_strdup (cFileName);
 
485
                }
 
486
        }
 
487
        else  // for an normal file, just re-use the filename
 
488
        {
 
489
                if (iVolumeID)
 
490
                        *iVolumeID = 0;
 
491
                if (cName)
 
492
                        *cName = g_strdup (cFileName);
 
493
        }
 
494
        
 
495
        // find the target URI if it's a mount point
 
496
        if (cURI)
 
497
        {
 
498
                if (cTargetURI)
 
499
                {
 
500
                        *cURI = g_strdup (cTargetURI);
 
501
                        g_free (cValidUri);
 
502
                        cValidUri = NULL;
 
503
                }
 
504
                else
 
505
                        *cURI = cValidUri;
 
506
        }
 
507
        
 
508
        // find an icon.
 
509
        if (cIconName)
 
510
        {
 
511
                *cIconName = NULL;
 
512
                // first use an available thumbnail.
 
513
                *cIconName = g_strdup (g_file_info_get_attribute_byte_string (pFileInfo, G_FILE_ATTRIBUTE_THUMBNAIL_PATH));
 
514
                #if (GLIB_MAJOR_VERSION > 2) || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 20)
 
515
                /**if (*cIconName == NULL)
 
516
                {
 
517
                        GIcon *pPreviewIcon = (GIcon *)g_file_info_get_attribute_object (pFileInfo, G_FILE_ATTRIBUTE_PREVIEW_ICON);
 
518
                        if (pPreviewIcon != NULL)
 
519
                        {
 
520
                                *cIconName = _cd_get_icon_path (pPreviewIcon, NULL);
 
521
                                //g_print ("got preview icon '%s'\n", *cIconName);
 
522
                        }
 
523
                }*/
 
524
                #endif
 
525
                // if no thumbnail available and the file is an image, use it directly.
 
526
                if (*cIconName == NULL && cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0)
 
527
                {
 
528
                        gchar *cHostname = NULL;
 
529
                        GError *erreur = NULL;
 
530
                        gchar *cFilePath = g_filename_from_uri (cBaseURI, &cHostname, &erreur);
 
531
                        if (erreur != NULL)
 
532
                        {
 
533
                                g_error_free (erreur);
 
534
                        }
 
535
                        else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0)  // on ne recupere la vignette que sur les fichiers locaux.
 
536
                        {
 
537
                                *cIconName = g_strdup (cFilePath);
 
538
                                cairo_dock_remove_html_spaces (*cIconName);
 
539
                        }
 
540
                        g_free (cHostname);
 
541
                }
 
542
                // else, get the icon for the mime-types.
 
543
                if (*cIconName == NULL)
 
544
                {
 
545
                        GIcon *pSystemIcon = g_file_info_get_icon (pFileInfo);
 
546
                        if (pSystemIcon != NULL)
 
547
                        {
 
548
                                *cIconName = _cd_get_icon_path (pSystemIcon, cTargetURI ? cTargetURI : *cURI);
 
549
                        }
 
550
                }
 
551
                cd_message ("cIconName : %s", *cIconName);
 
552
        }
 
553
        
 
554
        g_object_unref (pFileInfo);
 
555
        g_object_unref (pFile);
 
556
}
 
557
 
 
558
/* no longer used...
 
559
static Icon *_cd_get_icon_for_volume (GVolume *pVolume, GMount *pMount)
 
560
{
 
561
        GIcon *pIcon;
 
562
        GFile *pRootDir;
 
563
        gchar *cName, *cCommand, *cFileName;
 
564
        if (pVolume != NULL)
 
565
                pMount = g_volume_get_mount (pVolume);
 
566
        else if (pMount == NULL)
 
567
                return NULL;
 
568
        
 
569
        if (pMount != NULL)  // ce volume est monte.
 
570
        {
 
571
                cName = g_mount_get_name (pMount);
 
572
                
 
573
                pRootDir = g_mount_get_root (pMount);
 
574
                cCommand = g_file_get_uri (pRootDir);
 
575
                
 
576
                pIcon = g_mount_get_icon (pMount);
 
577
                cFileName = _cd_get_icon_path (pIcon, NULL);
 
578
                
 
579
                g_object_unref (pRootDir);
 
580
                g_object_unref (pIcon);
 
581
                g_object_unref (pMount);
 
582
        }
 
583
        else  // ce volume est demonte, on le montre quand meme (l'automount peut etre off).
 
584
        {
 
585
                cName = g_volume_get_name (pVolume);
 
586
                
 
587
                pIcon = g_volume_get_icon (pVolume);
 
588
                cFileName = _cd_get_icon_path (pIcon, NULL);
 
589
                
 
590
                cCommand = g_strdup (cName);
 
591
                
 
592
                g_object_unref (pIcon);
 
593
        }
 
594
        
 
595
        Icon *pNewIcon = cairo_dock_create_dummy_launcher (cName,
 
596
                cFileName,
 
597
                cCommand,
 
598
                NULL,
 
599
                0);
 
600
        pNewIcon->iVolumeID = 1;
 
601
        pNewIcon->cBaseURI = g_strdup (pNewIcon->cCommand);
 
602
        cd_message (" => %s", pNewIcon->cCommand);
 
603
        return pNewIcon;
 
604
}
 
605
*/
 
606
/* no longer used...
 
607
static GList *cairo_dock_gio_vfs_list_volumes (void)
 
608
{
 
609
        GVolumeMonitor *pVolumeMonitor = g_volume_monitor_get ();
 
610
        GList *pIconsList = NULL;
 
611
        Icon *pNewIcon;
 
612
        
 
613
        //\___________________ On chope les disques connectes (lecteur de CD/disquette/etc) et on liste leurs volumes.
 
614
        GList *pDrivesList = g_volume_monitor_get_connected_drives (pVolumeMonitor);
 
615
        GList *pAssociatedVolumes;
 
616
        GList *dl, *av;
 
617
        GDrive *pDrive;
 
618
        GVolume *pVolume;
 
619
        gchar *cLog;
 
620
        for (dl = pDrivesList; dl != NULL; dl = dl->next)
 
621
        {
 
622
                pDrive = dl->data;
 
623
                
 
624
                pAssociatedVolumes = g_drive_get_volumes (pDrive);
 
625
                if (pAssociatedVolumes != NULL)
 
626
                {
 
627
                        for (av = pAssociatedVolumes; av != NULL; av = av->next)
 
628
                        {
 
629
                                pVolume = av->data;
 
630
                                pNewIcon = _cd_get_icon_for_volume (pVolume, NULL);
 
631
                                if (pNewIcon != NULL)
 
632
                                        pIconsList = g_list_prepend (pIconsList, pNewIcon);
 
633
                                g_object_unref (pVolume);
 
634
                        }
 
635
                        g_list_free (pAssociatedVolumes);
 
636
                }
 
637
                else  // le disque n'a aucun volume montable
 
638
                {
 
639
                        cd_message ("  le disque n'a aucun volume montable");
 
640
                        *if (g_drive_is_media_removable (pDrive) && ! g_drive_is_media_check_automatic (pDrive))
 
641
                        {
 
642
                                g_drive_get_icon (pDrive);
 
643
                                g_drive_get_name (pDrive);
 
644
                        }*
 
645
                }
 
646
                //g_object_unref (pDrive);
 
647
        }
 
648
        g_list_free (pDrivesList);
 
649
 
 
650
        gchar *cLog;
 
651
 
 
652
        //\___________________ On chope les volumes qui ne sont pas associes a un disque.
 
653
        GList *pVolumesList = g_volume_monitor_get_volumes (pVolumeMonitor);
 
654
        GList *v;
 
655
        for (v = pVolumesList; v != NULL; v = v->next)
 
656
        {
 
657
                pVolume = v->data;
 
658
                cLog = g_volume_get_name (pVolume);
 
659
                cd_message ("volume '%s'", cLog);
 
660
                pDrive = g_volume_get_drive (pVolume);
 
661
                if (pDrive != NULL)  // on l'a deja liste dans la 1ere boucle.
 
662
                {
 
663
                        g_free (cLog);
 
664
                        cLog = g_drive_get_name (pDrive);
 
665
                        cd_message ("  drive '%s' est deja liste", cLog);
 
666
                        g_object_unref (pDrive);
 
667
                }
 
668
                else
 
669
                {
 
670
                        cd_message (" + volume '%s'", cLog);
 
671
                        if (pNewIcon != NULL)
 
672
                                pNewIcon = _cd_get_icon_for_volume (pVolume, NULL);
 
673
                        pIconsList = g_list_prepend (pIconsList, pNewIcon);
 
674
                }
 
675
                g_free (cLog);
 
676
                g_object_unref (pVolume);
 
677
        }
 
678
        g_list_free (pVolumesList);
 
679
 
 
680
        //\___________________ On chope les points de montage qui n'ont pas de volumes. (montage de mtab, ftp, etc)
 
681
        GList *pMountsList = g_volume_monitor_get_mounts (pVolumeMonitor);
 
682
        GMount *pMount;
 
683
        GList *m;
 
684
        for (m = pMountsList; m != NULL; m = m->next)
 
685
        {
 
686
                pMount = m->data;
 
687
                cLog = g_mount_get_name (pMount);
 
688
                cd_message ("mount '%s'", cLog);
 
689
                g_free (cLog);
 
690
                pVolume = g_mount_get_volume (pMount);
 
691
                if (pVolume != NULL)  // on l'a deja liste precedemment.
 
692
                {
 
693
                        cLog = g_volume_get_name (pVolume);
 
694
                        cd_message ("volume '%s' est deja liste", cLog);
 
695
                        g_free (cLog);
 
696
                        g_object_unref (pVolume);
 
697
                }
 
698
                else
 
699
                {
 
700
                        cd_message ("volume 'NULL'");
 
701
                        if (pNewIcon != NULL)
 
702
                                pNewIcon = _cd_get_icon_for_volume (NULL, pMount);
 
703
                        pIconsList = g_list_prepend (pIconsList, pNewIcon);
 
704
                }
 
705
                g_object_unref (pMount);
 
706
        }
 
707
        g_list_free (pMountsList);
 
708
        
 
709
        return pIconsList;
 
710
}*/
 
711
 
 
712
static GList *cairo_dock_gio_vfs_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsGroup, gboolean bListHiddenFiles, int iNbMaxFiles, gchar **cValidUri)
 
713
{
 
714
        g_return_val_if_fail (cBaseURI != NULL, NULL);
 
715
        cd_message ("%s (%s)", __func__, cBaseURI);
 
716
        
 
717
        gchar *cURI;
 
718
        if (strcmp (cBaseURI, CAIRO_DOCK_FM_VFS_ROOT) == 0)
 
719
                cURI = g_strdup ("computer://");
 
720
        else if (strcmp (cBaseURI, CAIRO_DOCK_FM_NETWORK) == 0)
 
721
                cURI = g_strdup ("network://");
 
722
        else
 
723
                cURI = (*cBaseURI == '/' ? g_strconcat ("file://", cBaseURI, NULL) : g_strdup (cBaseURI));
 
724
        *cValidUri = cURI;
 
725
        
 
726
        GFile *pFile = g_file_new_for_uri (cURI);
 
727
        GError *erreur = NULL;
 
728
        const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE","
 
729
                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
 
730
                G_FILE_ATTRIBUTE_STANDARD_NAME","
 
731
                G_FILE_ATTRIBUTE_STANDARD_ICON","
 
732
                G_FILE_ATTRIBUTE_THUMBNAIL_PATH","
 
733
                G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN","
 
734
                #if (GLIB_MAJOR_VERSION > 2) || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 20)
 
735
                ///G_FILE_ATTRIBUTE_PREVIEW_ICON","
 
736
                #endif
 
737
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI;
 
738
        GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile,
 
739
                cAttributes,
 
740
                G_FILE_QUERY_INFO_NONE,  /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
 
741
                NULL,
 
742
                &erreur);
 
743
        if (erreur != NULL)
 
744
        {
 
745
                cd_warning ("gvfs-integration : %s", erreur->message);
 
746
                g_error_free (erreur);
 
747
                g_object_unref (pFile);
 
748
                return NULL;
 
749
        }
 
750
        
 
751
        int iOrder = 0;
 
752
        int iNbFiles = 0;
 
753
        GList *pIconList = NULL;
 
754
        Icon *icon;
 
755
        GFileInfo *pFileInfo;
 
756
        do
 
757
        {
 
758
                pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur);
 
759
                if (erreur != NULL)
 
760
                {
 
761
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
762
                        g_error_free (erreur);
 
763
                        erreur = NULL;
 
764
                        continue;
 
765
                }
 
766
                if (pFileInfo == NULL)
 
767
                        break ;
 
768
                
 
769
                gboolean bIsHidden = g_file_info_get_is_hidden (pFileInfo);
 
770
                if (bListHiddenFiles || ! bIsHidden)
 
771
                {
 
772
                        GFileType iFileType = g_file_info_get_file_type (pFileInfo);
 
773
                        GIcon *pFileIcon = g_file_info_get_icon (pFileInfo);
 
774
                        if (pFileIcon == NULL)
 
775
                        {
 
776
                                cd_message ("No ICON");
 
777
                                continue;
 
778
                        }
 
779
                        const gchar *cFileName = g_file_info_get_name (pFileInfo);
 
780
                        const gchar *cMimeType = g_file_info_get_content_type (pFileInfo);
 
781
                        gchar *cName = NULL;
 
782
                        
 
783
                        icon = cairo_dock_create_dummy_launcher (NULL, NULL, NULL, NULL, 0);
 
784
                        icon->iGroup = iNewIconsGroup;
 
785
                        icon->cBaseURI = g_strconcat (*cValidUri, "/", cFileName, NULL);
 
786
                        //g_print        ("+ %s (mime:%s)n", icon->cBaseURI, cMimeType);
 
787
                        
 
788
                        if (iFileType == G_FILE_TYPE_MOUNTABLE)
 
789
                        {
 
790
                                const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
 
791
                                cd_message ("It's a mount point: %s (%s)", cTargetURI, cFileName);
 
792
                                
 
793
                                GMount *pMount = NULL;
 
794
                                if (cTargetURI != NULL)
 
795
                                {
 
796
                                        icon->cCommand = g_strdup (cTargetURI);
 
797
                                        GFile *file = g_file_new_for_uri (cTargetURI);
 
798
                                        pMount = g_file_find_enclosing_mount (file, NULL, NULL);
 
799
                                        g_object_unref (file);
 
800
                                }
 
801
                                if (pMount != NULL)
 
802
                                {
 
803
                                        cName = g_mount_get_name (pMount);
 
804
                                        cd_message ("GMount exists (%s)", cName);
 
805
                                        g_object_unref (pMount);
 
806
                                        
 
807
                                        /* GVolume *volume = g_mount_get_volume (pMount);
 
808
                                        if (volume)
 
809
                                                cd_message ("  volume associe : %s", g_volume_get_name (volume));
 
810
                                        GDrive *drive = g_mount_get_drive (pMount);
 
811
                                        if (drive)
 
812
                                                cd_message ("  disque associe : %s", g_drive_get_name (drive));*/
 
813
                                        
 
814
                                        ///pFileIcon = g_mount_get_icon (pMount);
 
815
                                }
 
816
                                else
 
817
                                {
 
818
                                        cName = g_strdup (cFileName);
 
819
                                        gchar *str = strrchr (cName, '.');  // we remove the extension ".volume" or ".drive".
 
820
                                        if (str != NULL)
 
821
                                        {
 
822
                                                *str = '\0';
 
823
                                                if (strcmp (str+1, "link") == 0)
 
824
                                                {
 
825
                                                        if (strcmp (cName, "root") == 0)
 
826
                                                        {
 
827
                                                                g_free (cName);
 
828
                                                                cName = g_strdup (D_("File System"));
 
829
                                                        }
 
830
                                                }
 
831
                                                else if (strcmp (str+1, "drive") == 0)  // on cherche un nom plus parlant si possible.
 
832
                                                {
 
833
                                                        gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cName);
 
834
                                                        if (cVolumeName != NULL)
 
835
                                                        {
 
836
                                                                g_free (cName);
 
837
                                                                cName = cVolumeName;
 
838
                                                                //g_free (cVolumeName);
 
839
                                                                //continue;  /// apparemment il n'est plus necessaire d'afficher les .drives qui ont 1 (ou plusieurs ?) volumes, car ces derniers sont dans la liste, donc ca fait redondant.
 
840
                                                                /**if (strcmp (cVolumeName, "discard") == 0)
 
841
                                                                        continue;
 
842
                                                                g_free (cName);
 
843
                                                                cName = cVolumeName;*/
 
844
                                                        }
 
845
                                                }
 
846
                                        }
 
847
                                }
 
848
                                icon->iVolumeID = 1;
 
849
                                cd_message ("The name of this volume is: %s", cName);
 
850
                        }
 
851
                        else
 
852
                        {
 
853
                                if (iFileType == G_FILE_TYPE_DIRECTORY)
 
854
                                        icon->iVolumeID = -1;
 
855
                                cName = g_strdup (cFileName);
 
856
                        }
 
857
                        
 
858
                        if (icon->cCommand == NULL)
 
859
                                icon->cCommand = g_strdup (icon->cBaseURI);
 
860
                        icon->cName = cName;
 
861
                        icon->cFileName = g_strdup (g_file_info_get_attribute_byte_string (pFileInfo, G_FILE_ATTRIBUTE_THUMBNAIL_PATH));
 
862
                        #if (GLIB_MAJOR_VERSION > 2) || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 20)
 
863
                        /**if (icon->cFileName == NULL)
 
864
                        {
 
865
                                GIcon *pPreviewIcon = (GIcon *)g_file_info_get_attribute_object (pFileInfo, G_FILE_ATTRIBUTE_PREVIEW_ICON);
 
866
                                if (pPreviewIcon != NULL)
 
867
                                {
 
868
                                        icon->cFileName = _cd_get_icon_path (pPreviewIcon, NULL);
 
869
                                        // g_print ("got preview icon '%s'\n", icon->cFileName);
 
870
                                }
 
871
                        }*/
 
872
                        #endif
 
873
                        if (cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0)
 
874
                        {
 
875
                                gchar *cHostname = NULL;
 
876
                                gchar *cFilePath = g_filename_from_uri (icon->cBaseURI, &cHostname, &erreur);
 
877
                                if (erreur != NULL)
 
878
                                {
 
879
                                        g_error_free (erreur);
 
880
                                        erreur = NULL;
 
881
                                }
 
882
                                else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0)  // on ne recupere la vignette que sur les fichiers locaux.
 
883
                                {
 
884
                                        icon->cFileName = g_strdup (cFilePath);
 
885
                                        cairo_dock_remove_html_spaces (icon->cFileName);
 
886
                                }
 
887
 
 
888
                                g_free (cHostname);
 
889
                                g_free (cFilePath);
 
890
                        }
 
891
                        if (icon->cFileName == NULL)
 
892
                        {
 
893
                                icon->cFileName = _cd_get_icon_path (pFileIcon, icon->cCommand);
 
894
                                //g_print ("icon->cFileName : %s\n", icon->cFileName);
 
895
                        }
 
896
                        
 
897
                        if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
 
898
                                icon->fOrder = g_file_info_get_size (pFileInfo);
 
899
                        else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
 
900
                        {
 
901
                                GTimeVal t;
 
902
                                g_file_info_get_modification_time (pFileInfo, &t);
 
903
                                icon->fOrder = t.tv_sec;
 
904
                        }
 
905
                        else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
 
906
                                icon->fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0);
 
907
                        if (icon->fOrder == 0)  // un peu moyen mais mieux que rien non ?
 
908
                                icon->fOrder = iOrder;
 
909
                        /*pIconList = g_list_insert_sorted (pIconList,
 
910
                                icon,
 
911
                                (GCompareFunc) cairo_dock_compare_icons_order);*/
 
912
                        pIconList = g_list_prepend (pIconList, icon);
 
913
                        cd_debug (" + %s (%s)", icon->cName, icon->cFileName);
 
914
                        iOrder ++;
 
915
                        iNbFiles ++;
 
916
                }
 
917
                g_object_unref (pFileInfo);
 
918
        } while (iNbFiles < iNbMaxFiles);
 
919
        
 
920
        g_object_unref (pFileEnum);
 
921
        g_object_unref (pFile);
 
922
        
 
923
        if (iSortType == CAIRO_DOCK_FM_SORT_BY_NAME)
 
924
                pIconList = cairo_dock_sort_icons_by_name (pIconList);
 
925
        else
 
926
                pIconList = cairo_dock_sort_icons_by_order (pIconList);
 
927
        
 
928
        return pIconList;
 
929
}
 
930
 
 
931
static gsize cairo_dock_gio_vfs_measure_directory (const gchar *cBaseURI, gint iCountType, gboolean bRecursive, gint *pCancel)
 
932
{
 
933
        g_return_val_if_fail (cBaseURI != NULL, 0);
 
934
        //cd_debug ("%s (%s)", __func__, cBaseURI);
 
935
        
 
936
        gchar *cURI = (*cBaseURI == '/' ? g_strconcat ("file://", cBaseURI, NULL) : (gchar*)cBaseURI);  // on le libere a la fin si necessaire.
 
937
        
 
938
        GFile *pFile = g_file_new_for_uri (cURI);
 
939
        GError *erreur = NULL;
 
940
        const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE","
 
941
                G_FILE_ATTRIBUTE_STANDARD_SIZE","
 
942
                G_FILE_ATTRIBUTE_STANDARD_NAME","
 
943
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI;
 
944
        GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile,
 
945
                cAttributes,
 
946
                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
947
                NULL,
 
948
                &erreur);
 
949
        if (erreur != NULL)
 
950
        {
 
951
                cd_warning ("gvfs-integration: %s (%s)", erreur->message, cURI);
 
952
                g_error_free (erreur);
 
953
                g_object_unref (pFile);
 
954
                if (cURI != cBaseURI)
 
955
                        g_free (cURI);
 
956
                g_atomic_int_set (pCancel, TRUE);
 
957
                return 0;
 
958
        }
 
959
        
 
960
        gsize iMeasure = 0;
 
961
        GFileInfo *pFileInfo;
 
962
        GString *sFilePath = g_string_new ("");
 
963
        do
 
964
        {
 
965
                pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur);
 
966
                if (erreur != NULL)
 
967
                {
 
968
                        cd_warning ("gvfs-integration : %s (%s [%s]: %s)", erreur->message,
 
969
                                g_file_info_get_name (pFileInfo),
 
970
                                g_file_info_get_display_name (pFileInfo),
 
971
                                g_file_info_get_content_type (pFileInfo));
 
972
                        g_error_free (erreur);
 
973
                        erreur = NULL;
 
974
                        continue;
 
975
                }
 
976
                if (pFileInfo == NULL)
 
977
                        break ;
 
978
                
 
979
                const gchar *cFileName = g_file_info_get_name (pFileInfo);
 
980
                
 
981
                g_string_printf (sFilePath, "%s/%s", cURI, cFileName);
 
982
                //GFile *file = g_file_new_for_uri (sFilePath->str);
 
983
                //const gchar *cTargetURI = g_file_get_uri (file);
 
984
                //g_print ("+ %s [%s]\n", cFileName, cTargetURI);
 
985
                GFileType iFileType = g_file_info_get_file_type (pFileInfo);
 
986
                
 
987
                if (iFileType == G_FILE_TYPE_DIRECTORY && bRecursive)
 
988
                {
 
989
                        g_string_printf (sFilePath, "%s/%s", cURI, cFileName);
 
990
                        iMeasure += MAX (1, cairo_dock_gio_vfs_measure_directory (sFilePath->str, iCountType, bRecursive, pCancel));  // un repertoire vide comptera pour 1.
 
991
                }
 
992
                else
 
993
                {
 
994
                        if (iCountType == 1)  // measure size.
 
995
                        {
 
996
                                iMeasure += g_file_info_get_size (pFileInfo);
 
997
                        }
 
998
                        else  // measure nb files.
 
999
                        {
 
1000
                                iMeasure ++;
 
1001
                        }
 
1002
                }
 
1003
                g_object_unref (pFileInfo);
 
1004
        } while (! g_atomic_int_get (pCancel));
 
1005
        if (*pCancel)
 
1006
                cd_debug ("measure cancelled");
 
1007
        
 
1008
        g_object_unref (pFileEnum);
 
1009
        g_object_unref (pFile);
 
1010
        g_string_free (sFilePath, TRUE);
 
1011
        if (cURI != cBaseURI)
 
1012
                g_free (cURI);
 
1013
        
 
1014
        return iMeasure;
 
1015
}
 
1016
 
 
1017
 
 
1018
static gchar *_cd_find_target_uri (const gchar *cBaseURI)
 
1019
{
 
1020
        GError *erreur = NULL;
 
1021
        GFile *pFile = g_file_new_for_uri (cBaseURI);
 
1022
        GFileInfo *pFileInfo = g_file_query_info (pFile,
 
1023
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI,
 
1024
                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
1025
                NULL,
 
1026
                &erreur);
 
1027
        g_object_unref (pFile);
 
1028
        if (erreur != NULL)
 
1029
        {
 
1030
                cd_debug ("%s (%s) : %s", __func__, cBaseURI, erreur->message);  // peut arriver avec un .mount, donc pas de warning.
 
1031
                g_error_free (erreur);
 
1032
                return NULL;
 
1033
        }
 
1034
        gchar *cTargetURI = g_strdup (g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI));
 
1035
        g_object_unref (pFileInfo);
 
1036
        return cTargetURI;
 
1037
}
 
1038
 
 
1039
static void cairo_dock_gio_vfs_launch_uri (const gchar *cURI)
 
1040
{
 
1041
        g_return_if_fail (cURI != NULL);
 
1042
        
 
1043
        // in case it's a mount point, take the URI that can actually be launched. 
 
1044
        GError *erreur = NULL;
 
1045
        gchar *cValidUri = (*cURI == '/' ? g_strconcat ("file://", cURI, NULL) : g_strdup (cURI));
 
1046
        cd_message ("%s (%s)", __func__, cValidUri);
 
1047
        
 
1048
        gchar *cTargetURI = _cd_find_target_uri (cValidUri);
 
1049
        cURI= (cTargetURI ? cTargetURI : cValidUri);
 
1050
        
 
1051
        // now, try to launch it with the default program know by gvfs.
 
1052
        gboolean bSuccess = g_app_info_launch_default_for_uri (cURI,
 
1053
                NULL,
 
1054
                &erreur);
 
1055
        if (erreur != NULL || ! bSuccess)  // error can happen (for instance, opening 'trash:/' on XFCE with a previous installation of nautilus) => try with another method.
 
1056
        {
 
1057
                cd_debug ("gvfs-integration : couldn't launch '%s' [%s]", cURI, erreur->message);
 
1058
                g_error_free (erreur);
 
1059
                erreur = NULL;
 
1060
                
 
1061
                // get the mime-type.
 
1062
                GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
 
1063
                const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE;
 
1064
                GFileInfo *pFileInfo = g_file_query_info (pFile,
 
1065
                        cQuery,
 
1066
                        G_FILE_QUERY_INFO_NONE,
 
1067
                        NULL,
 
1068
                        &erreur);
 
1069
                if (erreur != NULL)  // if no mime-type (can happen with not mounted volumes), abort.
 
1070
                {
 
1071
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
1072
                        g_error_free (erreur);
 
1073
                }
 
1074
                else
 
1075
                {
 
1076
                        // get all the apps that can launch it.
 
1077
                        const gchar *cMimeType = g_file_info_get_content_type (pFileInfo);
 
1078
                        GList *pAppsList = g_app_info_get_all_for_type (cMimeType);
 
1079
                        GAppInfo *pAppInfo;
 
1080
                        const char *cExec;
 
1081
                        GList *a;
 
1082
                        for (a = pAppsList; a != NULL; a = a->next)
 
1083
                        {
 
1084
                                pAppInfo = a->data;
 
1085
                                cExec = g_app_info_get_executable (pAppInfo);
 
1086
                                if (cExec)  // use the first available. it is supposed to be the most suitable, but the default method doesn't seem to use it.
 
1087
                                {
 
1088
                                        gchar *cPath = g_filename_from_uri (cURI, NULL, NULL);
 
1089
                                        cairo_dock_launch_command_printf ("%s \"%s\"", NULL, cExec, cPath?cPath:cURI);  // in case the program doesn't handle URI (geeqie, etc).
 
1090
                                        g_free (cPath);
 
1091
                                        break;
 
1092
                                }
 
1093
                        }
 
1094
                        g_list_free (pAppsList);
 
1095
                }
 
1096
                g_object_unref (pFile);
 
1097
        }
 
1098
        g_free (cValidUri);
 
1099
        g_free (cTargetURI);
 
1100
}
 
1101
 
 
1102
static GMount *_cd_find_mount_from_uri (const gchar *cURI, gchar **cTargetURI)
 
1103
{
 
1104
        cd_message ("%s (%s)", __func__, cURI);
 
1105
        gchar *_cTargetURI = _cd_find_target_uri (cURI);
 
1106
        
 
1107
        GMount *pMount = NULL;
 
1108
        if (_cTargetURI != NULL)
 
1109
        {
 
1110
                cd_debug ("  pointe sur %s", _cTargetURI);
 
1111
                GFile *file = g_file_new_for_uri (_cTargetURI);
 
1112
                pMount = g_file_find_enclosing_mount (file, NULL, NULL);
 
1113
                g_object_unref (file);
 
1114
        }
 
1115
        if (cTargetURI != NULL)
 
1116
                *cTargetURI = _cTargetURI;
 
1117
        else
 
1118
                g_free (_cTargetURI);
 
1119
        return pMount;
 
1120
}
 
1121
 
 
1122
static gchar *cairo_dock_gio_vfs_is_mounted (const gchar *cURI, gboolean *bIsMounted)
 
1123
{
 
1124
        cd_message ("%s (%s)", __func__, cURI);
 
1125
        gchar *cTargetURI = NULL;
 
1126
        
 
1127
        GFile *pFile = g_file_new_for_uri (cURI);
 
1128
        GFileType iType = g_file_query_file_type (pFile, G_FILE_QUERY_INFO_NONE, NULL);
 
1129
        g_object_unref (pFile);
 
1130
        cd_debug ("iType: %d\n", iType);
 
1131
        
 
1132
        if (iType == G_FILE_TYPE_MOUNTABLE)  // look for the mount point it targets
 
1133
        {
 
1134
                GMount *pMount = _cd_find_mount_from_uri (cURI, &cTargetURI);
 
1135
                cd_debug (" cTargetURI : %s", cTargetURI);
 
1136
                if (pMount != NULL)
 
1137
                {
 
1138
                        *bIsMounted = TRUE;
 
1139
                        g_object_unref (pMount);
 
1140
                }
 
1141
                else
 
1142
                {
 
1143
                        if (cTargetURI != NULL && strcmp (cTargetURI, "file:///") == 0)  // cas particulier ?
 
1144
                                *bIsMounted = TRUE;
 
1145
                        else
 
1146
                                *bIsMounted = FALSE;
 
1147
                }
 
1148
        }
 
1149
        else if (iType == G_FILE_TYPE_UNKNOWN)  // probably a remote share folder or whatever that is not yet mounted
 
1150
        {
 
1151
                *bIsMounted = FALSE;
 
1152
        }
 
1153
        else  // any other types (directory, regular file, etc) that is on (or point to) a monted volume.
 
1154
        {
 
1155
                *bIsMounted = TRUE;
 
1156
        }
 
1157
        return cTargetURI;
 
1158
}
 
1159
 
 
1160
static gchar * _cd_find_drive_name_from_URI (const gchar *cURI)
 
1161
{
 
1162
        g_return_val_if_fail (cURI != NULL, NULL);
 
1163
        if (strncmp (cURI, "computer:///", 12) == 0)
 
1164
        {
 
1165
                gchar *cDriveName = g_strdup (cURI+12);
 
1166
                gchar *str = strrchr (cDriveName, '.');
 
1167
                if (str != NULL)
 
1168
                {
 
1169
                        if (strcmp (str+1, "drive") == 0)
 
1170
                        {
 
1171
                                *str = '\0';
 
1172
                                while (1)
 
1173
                                {
 
1174
                                        str = strchr (cDriveName, '\\');
 
1175
                                        if (str == NULL)
 
1176
                                                break;
 
1177
                                        *str = '/';
 
1178
                                }
 
1179
                                return cDriveName;
 
1180
                        }
 
1181
                }
 
1182
                g_free (cDriveName);
 
1183
        }
 
1184
        return NULL;
 
1185
}
 
1186
static gboolean cairo_dock_gio_vfs_can_eject (const gchar *cURI)
 
1187
{
 
1188
        cd_message ("%s (%s)", __func__, cURI);
 
1189
        gchar *cDriveName = _cd_find_drive_name_from_URI (cURI);
 
1190
        if (cDriveName == NULL)
 
1191
                return FALSE;
 
1192
        
 
1193
        gboolean bCanEject = _cd_find_can_eject_from_drive_name (cDriveName);
 
1194
        //g_free (cDriveName);
 
1195
        return bCanEject;
 
1196
}
 
1197
static gboolean cairo_dock_gio_vfs_eject_drive (const gchar *cURI)
 
1198
{
 
1199
        cd_message ("%s (%s)", __func__, cURI);
 
1200
        gchar *cDriveName = _cd_find_drive_name_from_URI (cURI);
 
1201
        GDrive *pDrive = _cd_find_drive_from_name (cDriveName);
 
1202
        if (pDrive != NULL)
 
1203
        {
 
1204
                #if GLIB_CHECK_VERSION (2, 22, 0)
 
1205
                g_drive_eject_with_operation (pDrive,
 
1206
                        G_MOUNT_UNMOUNT_NONE,
 
1207
                        NULL,
 
1208
                        NULL,
 
1209
                        NULL,
 
1210
                        NULL);
 
1211
                #else
 
1212
                g_drive_eject (pDrive,
 
1213
                        G_MOUNT_UNMOUNT_NONE,
 
1214
                        NULL,
 
1215
                        NULL,
 
1216
                        NULL);
 
1217
                #endif
 
1218
        }
 
1219
        g_object_unref (pDrive);
 
1220
        g_free (cDriveName);
 
1221
        return TRUE;
 
1222
}
 
1223
 
 
1224
 
 
1225
static void _gio_vfs_mount_callback (gpointer pObject, GAsyncResult *res, gpointer *data)
 
1226
//static void _gio_vfs_mount_callback (gboolean succeeded, char *error, char *detailed_error, gpointer *data)
 
1227
{
 
1228
        cd_message ("%s (%d)", __func__, GPOINTER_TO_INT (data[1]));
 
1229
        
 
1230
        CairoDockFMMountCallback pCallback = data[0];
 
1231
        
 
1232
        GError *erreur = NULL;
 
1233
        gboolean bSuccess;
 
1234
        if (GPOINTER_TO_INT (data[1]) == 1)
 
1235
        {
 
1236
                if (data[5])
 
1237
                        bSuccess = (g_file_mount_mountable_finish (G_FILE (pObject), res, &erreur) != NULL);
 
1238
                else
 
1239
                        bSuccess = g_file_mount_enclosing_volume_finish (G_FILE (pObject), res, &erreur);
 
1240
        }
 
1241
        else if (GPOINTER_TO_INT (data[1]) == 0)
 
1242
                #if GLIB_CHECK_VERSION (2, 22, 0)
 
1243
                bSuccess = g_mount_unmount_with_operation_finish (G_MOUNT (pObject), res, &erreur);
 
1244
                #else
 
1245
                bSuccess = g_mount_unmount_finish (G_MOUNT (pObject), res, &erreur);
 
1246
                #endif
 
1247
        else
 
1248
                #if GLIB_CHECK_VERSION (2, 22, 0)
 
1249
                bSuccess = g_mount_eject_with_operation_finish (G_MOUNT (pObject), res, &erreur);
 
1250
                #else
 
1251
                bSuccess = g_mount_eject_finish (G_MOUNT (pObject), res, &erreur);
 
1252
                #endif
 
1253
        if (erreur != NULL)
 
1254
        {
 
1255
                cd_warning ("gvfs-integration : %s", erreur->message);
 
1256
                g_error_free (erreur);
 
1257
        }
 
1258
        
 
1259
        cd_message ("(un)mounted -> %d", bSuccess);
 
1260
        if (pCallback != NULL)
 
1261
                pCallback (GPOINTER_TO_INT (data[1]) == 1, bSuccess, data[2], data[3], data[4]);
 
1262
        g_free (data[2]);
 
1263
        g_free (data[3]);
 
1264
        g_free (data);
 
1265
}
 
1266
 
 
1267
static void cairo_dock_gio_vfs_mount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, gpointer user_data)
 
1268
{
 
1269
        g_return_if_fail (cURI != NULL);
 
1270
        cd_message ("%s (%s)", __func__, cURI);
 
1271
        
 
1272
        gchar *cTargetURI = _cd_find_target_uri (cURI);
 
1273
        GFile *pFile = g_file_new_for_uri (cURI);
 
1274
        
 
1275
        gpointer *data = g_new (gpointer, 6);  // libere dans la callback.
 
1276
        data[0] = pCallback;
 
1277
        data[1] = GINT_TO_POINTER (1);  // mount
 
1278
        data[2] = (cTargetURI ? g_path_get_basename (cTargetURI) : g_strdup (cURI));
 
1279
        data[3] = g_strdup (cURI);
 
1280
        data[4] = user_data;
 
1281
        
 
1282
        GMountOperation *mount_op = gtk_mount_operation_new (GTK_WINDOW (g_pPrimaryContainer->pWidget));
 
1283
        g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
 
1284
        
 
1285
        GFileType iType = g_file_query_file_type (pFile, G_FILE_QUERY_INFO_NONE, NULL);
 
1286
        cd_debug ("iType: %d\n", iType);
 
1287
        if (iType == G_FILE_TYPE_MOUNTABLE)
 
1288
        {
 
1289
                data[5] = GINT_TO_POINTER (1);
 
1290
                g_file_mount_mountable  (pFile,
 
1291
                        G_MOUNT_MOUNT_NONE,
 
1292
                        mount_op,
 
1293
                        NULL,
 
1294
                        (GAsyncReadyCallback) _gio_vfs_mount_callback,
 
1295
                        data);
 
1296
        }
 
1297
        else  // smb share folders typically have an unknown type; we have to use the other mount function for these types of mount points.
 
1298
        {
 
1299
                data[5] = GINT_TO_POINTER (0);
 
1300
                g_file_mount_enclosing_volume (pFile,
 
1301
                        G_MOUNT_MOUNT_NONE,
 
1302
                        mount_op,
 
1303
                        NULL,
 
1304
                        (GAsyncReadyCallback) _gio_vfs_mount_callback,
 
1305
                        data);
 
1306
        }
 
1307
        // unref mount_op here - g_file_mount_enclosing_volume() does ref for itself
 
1308
        g_object_unref (mount_op);
 
1309
        g_object_unref (pFile);
 
1310
        g_free (cTargetURI);
 
1311
}
 
1312
 
 
1313
static void cairo_dock_gio_vfs_unmount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, gpointer user_data)
 
1314
{
 
1315
        g_return_if_fail (cURI != NULL);
 
1316
        cd_message ("%s (%s)", __func__, cURI);
 
1317
        
 
1318
        gchar *cTargetURI = NULL;
 
1319
        GMount *pMount = _cd_find_mount_from_uri (cURI, &cTargetURI);
 
1320
        if (pMount == NULL || ! G_IS_MOUNT (pMount))
 
1321
        {
 
1322
                return ;
 
1323
        }
 
1324
        
 
1325
        if ( ! g_mount_can_unmount (pMount))
 
1326
                return ;
 
1327
        
 
1328
        gboolean bCanEject = g_mount_can_eject (pMount);
 
1329
        gboolean bCanUnmount = g_mount_can_unmount (pMount);
 
1330
        cd_message ("eject:%d / unmount:%d", bCanEject, bCanUnmount);
 
1331
        if (! bCanEject && ! bCanUnmount)
 
1332
        {
 
1333
                cd_warning ("can't unmount this volume (%s)", cURI);
 
1334
                return ;
 
1335
        }
 
1336
        
 
1337
        gpointer *data = g_new (gpointer, 5);
 
1338
        data[0] = pCallback;
 
1339
        data[1] = GINT_TO_POINTER (bCanEject ? 2 : 0);
 
1340
        data[2] = g_mount_get_name (pMount);
 
1341
        data[3] = g_strdup (cURI);
 
1342
        data[4] = user_data;
 
1343
        if (bCanEject)
 
1344
                #if GLIB_CHECK_VERSION (2, 22, 0)
 
1345
                g_mount_eject_with_operation (pMount,
 
1346
                        G_MOUNT_UNMOUNT_NONE,
 
1347
                        NULL,
 
1348
                        NULL,
 
1349
                        (GAsyncReadyCallback) _gio_vfs_mount_callback,
 
1350
                        data);
 
1351
                #else
 
1352
                g_mount_eject (pMount,
 
1353
                        G_MOUNT_UNMOUNT_NONE,
 
1354
                        NULL,
 
1355
                        (GAsyncReadyCallback) _gio_vfs_mount_callback,
 
1356
                        data);
 
1357
                #endif
 
1358
        else
 
1359
                #if GLIB_CHECK_VERSION (2, 22, 0)
 
1360
                g_mount_unmount_with_operation (pMount,
 
1361
                        G_MOUNT_UNMOUNT_NONE,
 
1362
                        NULL,
 
1363
                        NULL,
 
1364
                        (GAsyncReadyCallback) _gio_vfs_mount_callback,
 
1365
                        data);
 
1366
                #else
 
1367
                g_mount_unmount (pMount,
 
1368
                        G_MOUNT_UNMOUNT_NONE,
 
1369
                        NULL,
 
1370
                        (GAsyncReadyCallback) _gio_vfs_mount_callback,
 
1371
                        data);
 
1372
                #endif
 
1373
}
 
1374
 
 
1375
 
 
1376
static void _on_monitor_changed (GFileMonitor *monitor,
 
1377
        GFile *file,
 
1378
        GFile *other_file,
 
1379
        GFileMonitorEvent event_type,
 
1380
        gpointer  *data)
 
1381
{
 
1382
        CairoDockFMMonitorCallback pCallback = data[0];
 
1383
        gpointer user_data = data[1];
 
1384
        cd_message ("%s (%d , data : %x)", __func__, event_type, user_data);
 
1385
        
 
1386
        CairoDockFMEventType iEventType;
 
1387
        switch (event_type)
 
1388
        {
 
1389
                ///case G_FILE_MONITOR_EVENT_CHANGED :  // ignorer celui-ci devrait permettre d'eviter la moitie des signaux inutiles que gvfs emet.
 
1390
                case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT :
 
1391
                //case G_FILE_MONITOR_EVENT_UNMOUNTED : // pertinent ?...
 
1392
                        iEventType = CAIRO_DOCK_FILE_MODIFIED;
 
1393
                        cd_message ("modification d'un fichier");
 
1394
                break;
 
1395
                
 
1396
                case G_FILE_MONITOR_EVENT_DELETED :
 
1397
                        iEventType = CAIRO_DOCK_FILE_DELETED;
 
1398
                        cd_message ("effacement d'un fichier");
 
1399
                break;
 
1400
                
 
1401
                case G_FILE_MONITOR_EVENT_CREATED :
 
1402
                        iEventType = CAIRO_DOCK_FILE_CREATED;
 
1403
                        cd_message ("creation d'un fichier");
 
1404
                break;
 
1405
                
 
1406
                default :
 
1407
                return ;
 
1408
        }
 
1409
        gchar *cURI = g_file_get_uri (file);
 
1410
        cd_message (" c'est le fichier %s", cURI);
 
1411
        gchar *cPath = NULL;
 
1412
        if (strncmp (cURI, "computer://", 11) == 0)
 
1413
        {
 
1414
                if (event_type == G_FILE_MONITOR_EVENT_CHANGED)
 
1415
                {
 
1416
                        g_free (cURI);
 
1417
                        return ;
 
1418
                }
 
1419
                memcpy (cURI+4, "file", 4);
 
1420
                cPath = g_filename_from_uri (cURI+4, NULL, NULL);
 
1421
                cd_debug(" (path:%s)", cPath);
 
1422
                g_free (cURI);
 
1423
                cURI = g_strdup_printf ("computer://%s", cPath);
 
1424
                cd_message ("son URI complete est : %s", cURI);
 
1425
        }
 
1426
        
 
1427
        pCallback (iEventType, cURI, user_data);
 
1428
        g_free (cURI);
 
1429
}
 
1430
 
 
1431
 
 
1432
static void cairo_dock_gio_vfs_add_monitor (const gchar *cURI, gboolean bDirectory, CairoDockFMMonitorCallback pCallback, gpointer user_data)
 
1433
{
 
1434
        g_return_if_fail (cURI != NULL);
 
1435
        GError *erreur = NULL;
 
1436
        GFileMonitor *pMonitor;
 
1437
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
 
1438
        if (bDirectory)
 
1439
                pMonitor = g_file_monitor_directory (pFile,
 
1440
                        G_FILE_MONITOR_WATCH_MOUNTS,
 
1441
                        NULL,
 
1442
                        &erreur);
 
1443
        else
 
1444
                pMonitor = g_file_monitor_file (pFile,
 
1445
                        G_FILE_MONITOR_WATCH_MOUNTS,
 
1446
                        NULL,
 
1447
                        &erreur);
 
1448
        g_object_unref (pFile);
 
1449
        if (erreur != NULL)
 
1450
        {
 
1451
                cd_warning ("gvfs-integration : couldn't add monitor on '%s' (%d) [%s]", cURI, bDirectory, erreur->message);
 
1452
                g_error_free (erreur);
 
1453
                return ;
 
1454
        }
 
1455
        
 
1456
        gpointer *data = g_new0 (gpointer, 3);
 
1457
        data[0] = pCallback;
 
1458
        data[1] = user_data;
 
1459
        data[2] = pMonitor;
 
1460
        g_signal_connect (G_OBJECT (pMonitor), "changed", G_CALLBACK (_on_monitor_changed), data);
 
1461
        
 
1462
        g_hash_table_insert (s_hMonitorHandleTable, g_strdup (cURI), data);
 
1463
        cd_message (">>> moniteur ajoute sur %s (%x)", cURI, user_data);
 
1464
}
 
1465
 
 
1466
static void cairo_dock_gio_vfs_remove_monitor (const gchar *cURI)
 
1467
{
 
1468
        if (cURI != NULL)
 
1469
        {
 
1470
                cd_message (">>> moniteur supprime sur %s", cURI);
 
1471
                g_hash_table_remove (s_hMonitorHandleTable, cURI);
 
1472
        }
 
1473
}
 
1474
 
 
1475
 
 
1476
 
 
1477
static gboolean cairo_dock_gio_vfs_delete_file (const gchar *cURI, gboolean bNoTrash)
 
1478
{
 
1479
        g_return_val_if_fail (cURI != NULL, FALSE);
 
1480
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
 
1481
        
 
1482
        GError *erreur = NULL;
 
1483
        gboolean bSuccess;
 
1484
        if (bNoTrash)
 
1485
        {
 
1486
                const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_TYPE;
 
1487
                GFileInfo *pFileInfo = g_file_query_info (pFile,
 
1488
                        cQuery,
 
1489
                        G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
1490
                        NULL,
 
1491
                        &erreur);
 
1492
                if (erreur != NULL)
 
1493
                {
 
1494
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
1495
                        g_error_free (erreur);
 
1496
                        g_object_unref (pFile);
 
1497
                        return FALSE;
 
1498
                }
 
1499
                
 
1500
                GFileType iFileType = g_file_info_get_file_type (pFileInfo);
 
1501
                if (iFileType == G_FILE_TYPE_DIRECTORY)
 
1502
                {
 
1503
                        _cairo_dock_gio_vfs_empty_dir (cURI);
 
1504
                }
 
1505
                
 
1506
                bSuccess = g_file_delete (pFile, NULL, &erreur);
 
1507
                if (erreur != NULL)
 
1508
                {
 
1509
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
1510
                        g_error_free (erreur);
 
1511
                }
 
1512
        }
 
1513
        else
 
1514
        {
 
1515
                bSuccess = g_file_trash (pFile, NULL, &erreur);
 
1516
                if (erreur != NULL)
 
1517
                {
 
1518
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
1519
                        g_error_free (erreur);
 
1520
                }
 
1521
        }
 
1522
        g_object_unref (pFile);
 
1523
        return bSuccess;
 
1524
}
 
1525
 
 
1526
static gboolean cairo_dock_gio_vfs_rename_file (const gchar *cOldURI, const gchar *cNewName)
 
1527
{
 
1528
        g_return_val_if_fail (cOldURI != NULL, FALSE);
 
1529
        GFile *pOldFile = (*cOldURI == '/' ? g_file_new_for_path (cOldURI) : g_file_new_for_uri (cOldURI));
 
1530
        GError *erreur = NULL;
 
1531
        GFile *pNewFile = g_file_set_display_name (pOldFile, cNewName, NULL, &erreur);
 
1532
        if (erreur != NULL)
 
1533
        {
 
1534
                cd_warning ("gvfs-integration : %s", erreur->message);
 
1535
                g_error_free (erreur);
 
1536
        }
 
1537
        gboolean bSuccess = (pNewFile != NULL);
 
1538
        if (pNewFile != NULL)
 
1539
                g_object_unref (pNewFile);
 
1540
        g_object_unref (pOldFile);
 
1541
        return bSuccess;
 
1542
}
 
1543
 
 
1544
static gboolean cairo_dock_gio_vfs_move_file (const gchar *cURI, const gchar *cDirectoryURI)
 
1545
{
 
1546
        g_return_val_if_fail (cURI != NULL, FALSE);
 
1547
        cd_message (" %s -> %s", cURI, cDirectoryURI);
 
1548
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
 
1549
        
 
1550
        gchar *cFileName = g_file_get_basename (pFile);
 
1551
        gchar *cNewFileURI = g_strconcat (cDirectoryURI, "/", cFileName, NULL);  // un peu moyen mais bon...
 
1552
        GFile *pDestinationFile = (*cNewFileURI == '/' ? g_file_new_for_path (cNewFileURI) : g_file_new_for_uri (cNewFileURI));
 
1553
        g_free (cNewFileURI);
 
1554
        g_free (cFileName);
 
1555
        
 
1556
        GError *erreur = NULL;
 
1557
        gboolean bSuccess = g_file_move (pFile,
 
1558
                pDestinationFile,
 
1559
                G_FILE_COPY_NOFOLLOW_SYMLINKS,
 
1560
                NULL,
 
1561
                NULL,  // GFileProgressCallback
 
1562
                NULL,  // data
 
1563
                &erreur);
 
1564
        if (erreur != NULL)
 
1565
        {
 
1566
                cd_warning ("gvfs-integration : %s", erreur->message);
 
1567
                g_error_free (erreur);
 
1568
        }
 
1569
        g_object_unref (pFile);
 
1570
        g_object_unref (pDestinationFile);
 
1571
        return bSuccess;
 
1572
}
 
1573
 
 
1574
static gboolean cairo_dock_gio_vfs_create_file (const gchar *cURI, gboolean bDirectory)
 
1575
{
 
1576
        g_return_val_if_fail (cURI != NULL, FALSE);
 
1577
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
 
1578
        
 
1579
        GError *erreur = NULL;
 
1580
        gboolean bSuccess = TRUE;
 
1581
        #if (GLIB_MAJOR_VERSION > 2) || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 18)
 
1582
        if (bDirectory)
 
1583
                g_file_make_directory_with_parents (pFile, NULL, &erreur);
 
1584
        else
 
1585
        #endif
 
1586
                g_file_create (pFile, G_FILE_CREATE_PRIVATE, NULL, &erreur);
 
1587
        if (erreur != NULL)
 
1588
        {
 
1589
                cd_warning ("gvfs-integration : %s", erreur->message);
 
1590
                g_error_free (erreur);
 
1591
                bSuccess = FALSE;
 
1592
        }
 
1593
        g_object_unref (pFile);
 
1594
        
 
1595
        return bSuccess;
 
1596
}
 
1597
 
 
1598
static void cairo_dock_gio_vfs_get_file_properties (const gchar *cURI, guint64 *iSize, time_t *iLastModificationTime, gchar **cMimeType, int *iUID, int *iGID, int *iPermissionsMask)
 
1599
{
 
1600
        g_return_if_fail (cURI != NULL);
 
1601
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
 
1602
        GError *erreur = NULL;
 
1603
        const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_SIZE","
 
1604
                G_FILE_ATTRIBUTE_TIME_MODIFIED","
 
1605
                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
 
1606
                G_FILE_ATTRIBUTE_UNIX_UID","
 
1607
                G_FILE_ATTRIBUTE_UNIX_GID","
 
1608
                G_FILE_ATTRIBUTE_ACCESS_CAN_READ","
 
1609
                G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE","
 
1610
                G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE;
 
1611
        GFileInfo *pFileInfo = g_file_query_info (pFile,
 
1612
                cQuery,
 
1613
                G_FILE_QUERY_INFO_NONE,  /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
 
1614
                NULL,
 
1615
                &erreur);
 
1616
        if (erreur != NULL)
 
1617
        {
 
1618
                cd_warning ("gvfs-integration : couldn't get file properties for '%s' [%s]", cURI, erreur->message);
 
1619
                g_error_free (erreur);
 
1620
        }
 
1621
        
 
1622
        *iSize = g_file_info_get_attribute_uint64 (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE);
 
1623
        *iLastModificationTime = (time_t) g_file_info_get_attribute_uint64 (pFileInfo, G_FILE_ATTRIBUTE_TIME_MODIFIED);
 
1624
        *cMimeType = g_file_info_get_attribute_as_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
 
1625
        *iUID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_UNIX_UID);
 
1626
        *iGID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_UNIX_GID);
 
1627
        gboolean r = g_file_info_get_attribute_boolean (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
 
1628
        gboolean w = g_file_info_get_attribute_boolean (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
 
1629
        gboolean x = g_file_info_get_attribute_boolean (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
 
1630
        *iPermissionsMask = r * 8 * 8 + w * 8 + x;
 
1631
        
 
1632
        g_object_unref (pFileInfo);
 
1633
        g_object_unref (pFile);
 
1634
}
 
1635
 
 
1636
 
 
1637
static gchar *cairo_dock_gio_vfs_get_trash_path (const gchar *cNearURI, gchar **cFileInfoPath)
 
1638
{
 
1639
        if (cNearURI == NULL)
 
1640
                return g_strdup ("trash://");
 
1641
        gchar *cPath = NULL;
 
1642
        /*GFile *pFile = g_file_new_for_uri ("trash://");
 
1643
        gchar *cPath = g_file_get_path (pFile);
 
1644
        g_object_unref (pFile);*/
 
1645
        const gchar *xdgPath = g_getenv ("XDG_DATA_HOME");
 
1646
        if (xdgPath != NULL)
 
1647
        {
 
1648
                cPath = g_strdup_printf ("%s/Trash/files", xdgPath);
 
1649
                if (cFileInfoPath != NULL)
 
1650
                        *cFileInfoPath = g_strdup_printf ("%s/Trash/info", xdgPath);
 
1651
        }
 
1652
        else
 
1653
        {
 
1654
                cPath = g_strdup_printf ("%s/.local/share/Trash/files", g_getenv ("HOME"));
 
1655
                if (cFileInfoPath != NULL)
 
1656
                        *cFileInfoPath = g_strdup_printf ("%s/.local/share/Trash/info", g_getenv ("HOME"));
 
1657
        }
 
1658
        return cPath;
 
1659
}
 
1660
 
 
1661
static gchar *cairo_dock_gio_vfs_get_desktop_path (void)
 
1662
{
 
1663
        GFile *pFile = g_file_new_for_uri ("desktop://");
 
1664
        gchar *cPath = g_file_get_path (pFile);
 
1665
        g_object_unref (pFile);
 
1666
        return cPath;
 
1667
}
 
1668
 
 
1669
static void _cairo_dock_gio_vfs_empty_dir (const gchar *cBaseURI)
 
1670
{
 
1671
        if (cBaseURI == NULL)
 
1672
                return ;
 
1673
        
 
1674
        GFile *pFile = (*cBaseURI == '/' ? g_file_new_for_path (cBaseURI) : g_file_new_for_uri (cBaseURI));
 
1675
        GError *erreur = NULL;
 
1676
        const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE","
 
1677
                G_FILE_ATTRIBUTE_STANDARD_NAME;
 
1678
        GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile,
 
1679
                cAttributes,
 
1680
                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
1681
                NULL,
 
1682
                &erreur);
 
1683
        if (erreur != NULL)
 
1684
        {
 
1685
                cd_warning ("gvfs-integration : %s", erreur->message);
 
1686
                g_object_unref (pFile);
 
1687
                g_error_free (erreur);
 
1688
                return ;
 
1689
        }
 
1690
        
 
1691
        GString *sFileUri = g_string_new ("");
 
1692
        GFileInfo *pFileInfo;
 
1693
        GFile *file;
 
1694
        do
 
1695
        {
 
1696
                pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur);
 
1697
                if (erreur != NULL)
 
1698
                {
 
1699
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
1700
                        g_error_free (erreur);
 
1701
                        erreur = NULL;
 
1702
                        continue;
 
1703
                }
 
1704
                if (pFileInfo == NULL)
 
1705
                        break ;
 
1706
                
 
1707
                GFileType iFileType = g_file_info_get_file_type (pFileInfo);
 
1708
                const gchar *cFileName = g_file_info_get_name (pFileInfo);
 
1709
                
 
1710
                g_string_printf (sFileUri, "%s/%s", cBaseURI, cFileName);
 
1711
                if (iFileType == G_FILE_TYPE_DIRECTORY)
 
1712
                {
 
1713
                        _cairo_dock_gio_vfs_empty_dir (sFileUri->str);
 
1714
                }
 
1715
                
 
1716
                file = (*cBaseURI == '/' ? g_file_new_for_path (sFileUri->str) : g_file_new_for_uri (sFileUri->str));
 
1717
                g_file_delete (file, NULL, &erreur);
 
1718
                if (erreur != NULL)
 
1719
                {
 
1720
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
1721
                        g_error_free (erreur);
 
1722
                        erreur = NULL;
 
1723
                }
 
1724
                g_object_unref (file);
 
1725
                
 
1726
                g_object_unref (pFileInfo);
 
1727
        } while (1);
 
1728
        
 
1729
        g_string_free (sFileUri, TRUE);
 
1730
        g_object_unref (pFileEnum);
 
1731
        g_object_unref (pFile);
 
1732
}
 
1733
 
 
1734
static inline int _convert_base16 (char c)
 
1735
{
 
1736
        int x;
 
1737
        if (c >= '0' && c <= '9')
 
1738
                x = c - '0';
 
1739
        else
 
1740
                x = 10 + (c - 'A');
 
1741
        return x;
 
1742
}
 
1743
static void cairo_dock_gio_vfs_empty_trash (void)
 
1744
{
 
1745
        GFile *pFile = g_file_new_for_uri ("trash://");
 
1746
        GError *erreur = NULL;
 
1747
        const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TARGET_URI","
 
1748
                G_FILE_ATTRIBUTE_STANDARD_NAME","
 
1749
                G_FILE_ATTRIBUTE_STANDARD_TYPE;
 
1750
        GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile,
 
1751
                cAttributes,
 
1752
                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
1753
                NULL,
 
1754
                &erreur);
 
1755
        if (erreur != NULL)
 
1756
        {
 
1757
                cd_warning ("gvfs-integration : %s", erreur->message);
 
1758
                g_object_unref (pFile);
 
1759
                g_error_free (erreur);
 
1760
                return ;
 
1761
        }
 
1762
        
 
1763
        GString *sFileUri = g_string_new ("");
 
1764
        GFileInfo *pFileInfo;;
 
1765
        do
 
1766
        {
 
1767
                pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur);
 
1768
                if (erreur != NULL)
 
1769
                {
 
1770
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
1771
                        g_error_free (erreur);
 
1772
                        erreur = NULL;
 
1773
                        continue;
 
1774
                }
 
1775
                if (pFileInfo == NULL)
 
1776
                        break ;
 
1777
                
 
1778
                const gchar *cFileName = g_file_info_get_name (pFileInfo);
 
1779
                //g_print (" - %s\n", cFileName);
 
1780
                
 
1781
                // il y'a 2 cas : un fichier dans la poubelle du home, et un fichier dans une poubelle d'un autre volume.
 
1782
                if (cFileName && *cFileName == '\\')  // nom de la forme "\media\Fabounet2\.Trash-1000\files\t%C3%A8st%201" et URI "trash:///%5Cmedia%5CFabounet2%5C.Trash-1000%5Cfiles%5Ct%25C3%25A8st%25201", mais cette URI ne marche pas des qu'il y'a des caracteres non ASCII-7 dans le nom (bug dans gio/gvfs ?). Donc on feinte, en construisant le chemin du fichier (et de son double dans 'info').
 
1783
                {
 
1784
                        g_string_printf (sFileUri, "file://%s", cFileName);
 
1785
                        g_strdelimit (sFileUri->str, "\\", '/');
 
1786
                        //g_print ("   - %s\n", sFileUri->str);
 
1787
                        
 
1788
                        GFileType iFileType = g_file_info_get_file_type (pFileInfo);
 
1789
                        if (iFileType == G_FILE_TYPE_DIRECTORY)  // can't delete a non-empty folder located on a different volume than home.
 
1790
                        {
 
1791
                                _cairo_dock_gio_vfs_empty_dir (sFileUri->str);
 
1792
                        }
 
1793
                        GFile *file = g_file_new_for_uri (sFileUri->str);
 
1794
                        g_file_delete (file, NULL, &erreur);
 
1795
                        g_object_unref (file);
 
1796
                        
 
1797
                        gchar *str = g_strrstr (sFileUri->str, "/files/");
 
1798
                        if (str)
 
1799
                        {
 
1800
                                *str = '\0';
 
1801
                                gchar *cInfo = g_strdup_printf ("%s/info/%s.trashinfo", sFileUri->str, str+7);
 
1802
                                //g_print ("   - %s\n", cInfo);
 
1803
                                file = g_file_new_for_uri (cInfo);
 
1804
                                g_free (cInfo);
 
1805
                                g_file_delete (file, NULL, NULL);
 
1806
                                g_object_unref (file);
 
1807
                        }
 
1808
                }
 
1809
                else  // poubelle principale : nom de la forme "tȿst 1" et URI "trash:///t%C3%A8st%201"
 
1810
                {
 
1811
                        if (strchr (cFileName, '%'))  // if there is a % inside the name, it disturb gio, so let's remove it.
 
1812
                        {
 
1813
                                gchar *cTmpPath = g_strdup_printf ("/%s", cFileName);
 
1814
                                gchar *cEscapedFileName = g_filename_to_uri (cTmpPath, NULL, NULL);
 
1815
                                g_free (cTmpPath);
 
1816
                                g_string_printf (sFileUri, "trash://%s", cEscapedFileName+7);  // replace file:// with trash://
 
1817
                                g_free (cEscapedFileName);
 
1818
                        }
 
1819
                        else  // else it can handle the URI as usual.
 
1820
                                g_string_printf (sFileUri, "trash:///%s", cFileName);
 
1821
                        GFile *file = g_file_new_for_uri (sFileUri->str);
 
1822
                        /*gchar *cValidURI = g_file_get_uri (file);
 
1823
                        //g_print ("   - %s\n", cValidURI);
 
1824
                        g_object_unref (file);
 
1825
                        
 
1826
                        file = g_file_new_for_uri (cValidURI);
 
1827
                        g_free (cValidURI);*/
 
1828
                        g_file_delete (file, NULL, &erreur);
 
1829
                        g_object_unref (file);
 
1830
                }
 
1831
                if (erreur != NULL)
 
1832
                {
 
1833
                        cd_warning ("gvfs-integration : %s", erreur->message);
 
1834
                        g_error_free (erreur);
 
1835
                        erreur = NULL;
 
1836
                }
 
1837
                
 
1838
                g_object_unref (pFileInfo);
 
1839
        } while (1);
 
1840
        
 
1841
        g_string_free (sFileUri, TRUE);
 
1842
        g_object_unref (pFileEnum);
 
1843
        g_object_unref (pFile);
 
1844
}
 
1845
 
 
1846
static GList *cairo_dock_gio_vfs_list_apps_for_file (const gchar *cBaseURI)
 
1847
{
 
1848
        gchar *cValidUri;
 
1849
        if (*cBaseURI == '/')
 
1850
                cValidUri = g_filename_to_uri (cBaseURI, NULL, NULL);
 
1851
        else
 
1852
                cValidUri = g_strdup (cBaseURI);
 
1853
        GFile *pFile = g_file_new_for_uri (cValidUri);
 
1854
        
 
1855
        GError *erreur = NULL;
 
1856
        const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE;
 
1857
        GFileInfo *pFileInfo = g_file_query_info (pFile,
 
1858
                cQuery,
 
1859
                G_FILE_QUERY_INFO_NONE,
 
1860
                NULL,
 
1861
                &erreur);
 
1862
        
 
1863
        if (erreur != NULL)  // peut arriver si l'emplacement n'est pas monte, mais on signale tout de meme la raison avec un warning.
 
1864
        {
 
1865
                cd_warning ("gvfs-integration : %s", erreur->message);
 
1866
                g_error_free (erreur);
 
1867
                g_free (cValidUri);
 
1868
                g_object_unref (pFile);
 
1869
                return NULL;
 
1870
        }
 
1871
        
 
1872
        const gchar *cMimeType = g_file_info_get_content_type (pFileInfo);
 
1873
        
 
1874
        GList *pAppsList = g_app_info_get_all_for_type (cMimeType);
 
1875
        GList *a;
 
1876
        GList *pList = NULL;
 
1877
        gchar **pData;
 
1878
        GAppInfo *pAppInfo;
 
1879
        GIcon *pIcon;
 
1880
        for (a = pAppsList; a != NULL; a = a->next)
 
1881
        {
 
1882
                pAppInfo = a->data;
 
1883
                pIcon = g_app_info_get_icon (pAppInfo);
 
1884
                
 
1885
                pData = g_new0 (gchar*, 4);
 
1886
                #if (GLIB_MAJOR_VERSION > 2) || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 24)
 
1887
                        pData[0] = g_strdup (g_app_info_get_display_name (pAppInfo));
 
1888
                #else
 
1889
                        pData[0] = g_strdup (g_app_info_get_name (pAppInfo));
 
1890
                #endif
 
1891
                pData[1] = g_strdup (g_app_info_get_executable (pAppInfo));
 
1892
                if (pIcon)
 
1893
                #if (GLIB_MAJOR_VERSION > 2) || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 20)
 
1894
                        pData[2] = g_icon_to_string (pIcon);
 
1895
                #else
 
1896
                        pData[2] = _cd_get_icon_path (pIcon, NULL);
 
1897
                #endif
 
1898
                pList = g_list_prepend (pList, pData);
 
1899
        }
 
1900
        pList = g_list_reverse (pList);
 
1901
        
 
1902
        g_free (cValidUri);
 
1903
        g_object_unref (pFile);
 
1904
        g_list_free (pAppsList);
 
1905
        g_object_unref (pFileInfo);
 
1906
        return pList;
 
1907
}
 
1908
 
 
1909
gboolean cairo_dock_gio_vfs_fill_backend(CairoDockDesktopEnvBackend *pVFSBackend)
 
1910
{
 
1911
        if(pVFSBackend)
 
1912
        {
 
1913
                pVFSBackend->get_file_info = cairo_dock_gio_vfs_get_file_info;
 
1914
                pVFSBackend->get_file_properties = cairo_dock_gio_vfs_get_file_properties;
 
1915
                pVFSBackend->list_directory = cairo_dock_gio_vfs_list_directory;
 
1916
                pVFSBackend->measure_directory = cairo_dock_gio_vfs_measure_directory;
 
1917
                pVFSBackend->launch_uri = cairo_dock_gio_vfs_launch_uri;
 
1918
                pVFSBackend->is_mounted = cairo_dock_gio_vfs_is_mounted;
 
1919
                pVFSBackend->can_eject = cairo_dock_gio_vfs_can_eject;
 
1920
                pVFSBackend->eject = cairo_dock_gio_vfs_eject_drive;
 
1921
                pVFSBackend->mount = cairo_dock_gio_vfs_mount;
 
1922
                pVFSBackend->unmount = cairo_dock_gio_vfs_unmount;
 
1923
                pVFSBackend->add_monitor = cairo_dock_gio_vfs_add_monitor;
 
1924
                pVFSBackend->remove_monitor = cairo_dock_gio_vfs_remove_monitor;
 
1925
                pVFSBackend->delete_file = cairo_dock_gio_vfs_delete_file;
 
1926
                pVFSBackend->rename = cairo_dock_gio_vfs_rename_file;
 
1927
                pVFSBackend->move = cairo_dock_gio_vfs_move_file;
 
1928
                pVFSBackend->create = cairo_dock_gio_vfs_create_file;
 
1929
                pVFSBackend->get_trash_path = cairo_dock_gio_vfs_get_trash_path;
 
1930
                pVFSBackend->empty_trash = cairo_dock_gio_vfs_empty_trash;
 
1931
                pVFSBackend->get_desktop_path = cairo_dock_gio_vfs_get_desktop_path;
 
1932
                pVFSBackend->list_apps_for_file = cairo_dock_gio_vfs_list_apps_for_file;
 
1933
        }
 
1934
 
 
1935
        return TRUE;
 
1936
}
 
1937
 
 
1938
#else
 
1939
 
 
1940
gboolean cairo_dock_gio_vfs_init (void)
 
1941
{
 
1942
        return FALSE;
 
1943
}
 
1944
 
 
1945
gboolean cairo_dock_gio_vfs_fill_backend(CairoDockDesktopEnvBackend *pVFSBackend)
 
1946
{
 
1947
        return FALSE;
 
1948
}
 
1949
 
 
1950
#endif