~ubuntu-branches/ubuntu/quantal/cairo-dock-plug-ins/quantal-201208191523

« back to all changes in this revision

Viewing changes to gnome-integration/src/applet-gvfs.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-10 00:05:57 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810000557-pfxoz5w7hbyclcqh
Tags: 2.2.0~0beta4-0ubuntu1
* New Upstream Version (LP: #614625)
* Fixed a few bugs on LP:
 - LP: #483963: Dustbin applet does not display trashes on all volumes
 - LP: #485159: Some apps have problem with Systray
 - LP: #500677: ~/.xsession-errors is too much used by CD
 - LP: #500979: Shortcuts: the order gets messed up
 - LP: #521531: Mail: crashes on Maildir
 - LP: #519915: GTG: create a new applet to control GTG
 - LP: #526138: GMenu doesn't handle desktop file exec strings properly
 - LP: #531317: CMake: Added an error if the prefix of 'cairo-dock-plugins'
                 is not the same 'cairo-dock-core'
 - LP: #531319: CMake: check the version of 'cairo-dock' when building
                 'cairo-dock-plugins'
 - LP: #537115: Click at the position where icon lavel was, the icon
                 and dock still receive the event
 - LP: #537943: Terminal applet shortkey behaviour
 - LP: #538637: Trash applet doesn't create .trashinfo files on XFCE
 - More details on the 'ChangeLog' file
* debian/rules:
 - Autotools has been replaced by CMake
 - cdbs is now used.
* debian/copyright:
 - Updated with the new applets
* debian/control:
 - Autotools has been replaced by CMake
 - Added libcurl4-gnutls-dev, libindicator-dev, libdbusmenu-glib-dev
   libido-0.1-dev, libical-dev, libdbusmenu-gtk-dev as Build-deps
 - Bump Standard-Version to 3.9.1
 - Wget is required for dnd2share applet
 - Added the exact realease for 'cairo-dock-dev' in order to prevent any
    build error if this package is not already available (thx to didrocks)
* debian/cairo-dock-plug-ins*.install:
 - All sonames are now installed into lib32 or lib64 (lib*)

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
 
#include <string.h>
21
 
 
22
 
#include <glib.h>
23
 
#include <gio/gio.h>
24
 
 
25
 
#include "applet-gvfs.h"
26
 
 
27
 
static GHashTable *s_hMonitorHandleTable = NULL;
28
 
 
29
 
 
30
 
static void _vfs_backend_free_monitor_data (gpointer *data)
31
 
{
32
 
        if (data != NULL)
33
 
        {
34
 
                GFileMonitor *pHandle = data[2];
35
 
                g_file_monitor_cancel (pHandle);  // le GFileMonitor est-il libere lors du g_file_monitor_cancel () ?
36
 
                g_free (data);
37
 
        }
38
 
}
39
 
 
40
 
gboolean init_vfs_backend (void)
41
 
{
42
 
        if (s_hMonitorHandleTable != NULL)
43
 
                g_hash_table_destroy (s_hMonitorHandleTable);
44
 
        
45
 
        s_hMonitorHandleTable = g_hash_table_new_full (g_str_hash,
46
 
                g_str_equal,
47
 
                g_free,
48
 
                (GDestroyNotify) _vfs_backend_free_monitor_data);
49
 
        
50
 
        GVfs *vfs = g_vfs_get_default ();
51
 
        return (vfs != NULL && g_vfs_is_active (vfs));  // utile ?
52
 
}
53
 
 
54
 
void stop_vfs_backend (void)
55
 
{
56
 
        if (s_hMonitorHandleTable != NULL)
57
 
        {
58
 
                g_hash_table_destroy (s_hMonitorHandleTable);
59
 
                s_hMonitorHandleTable = NULL;
60
 
        }
61
 
}
62
 
 
63
 
 
64
 
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)
65
 
{
66
 
        //g_print ("%s ()\n", __func__);
67
 
        gchar *cIconPath = NULL;
68
 
        if (G_IS_THEMED_ICON (pIcon))
69
 
        {
70
 
                const gchar * const *cFileNames = g_themed_icon_get_names (G_THEMED_ICON (pIcon));
71
 
                //cd_message ("icones possibles : %s\n", g_strjoinv (":", (gchar **) cFileNames));
72
 
                int i;
73
 
                for (i = 0; cFileNames[i] != NULL && cIconPath == NULL; i ++)
74
 
                {
75
 
                        //g_print (" une icone possible est : %s\n", cFileNames[i]);
76
 
                        cIconPath = cairo_dock_search_icon_s_path (cFileNames[i]);
77
 
                        //g_print ("  chemin trouve : %s\n", cIconPath);
78
 
                }
79
 
        }
80
 
        else if (G_IS_FILE_ICON (pIcon))
81
 
        {
82
 
                GFile *pFile = g_file_icon_get_file (G_FILE_ICON (pIcon));
83
 
                cIconPath = g_file_get_basename (pFile);
84
 
                //g_print (" file_icon => %s\n", cIconPath);
85
 
                
86
 
                if (cTargetURI && cIconPath && g_str_has_suffix (cIconPath, ".ico"))  // cas des montages de CD ou d'iso
87
 
                {
88
 
                        gchar *tmp = cIconPath;
89
 
                        cIconPath = g_strdup_printf ("%s/%s", cTargetURI, tmp);
90
 
                        g_free (tmp);
91
 
                        if (strncmp (cIconPath, "file://", 7) == 0)
92
 
                        {
93
 
                                tmp = cIconPath;
94
 
                                cIconPath = g_filename_from_uri (tmp, NULL, NULL);
95
 
                                g_free (tmp);
96
 
                        }
97
 
                }
98
 
        }
99
 
        return cIconPath;
100
 
}
101
 
 
102
 
 
103
 
static void _cd_find_mount_from_volume_name (const gchar *cVolumeName, GMount **pFoundMount, gchar **cURI, gchar **cIconName)
104
 
{
105
 
        g_return_if_fail (cVolumeName != NULL);
106
 
        cd_message ("%s (%s)", __func__, cVolumeName);
107
 
        GFile *pFile = g_file_new_for_uri ("computer://");
108
 
        GError *erreur = NULL;
109
 
        const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE","
110
 
                G_FILE_ATTRIBUTE_STANDARD_NAME","
111
 
                G_FILE_ATTRIBUTE_STANDARD_ICON","
112
 
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI","
113
 
                G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE;
114
 
        GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile,
115
 
                cAttributes,
116
 
                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
117
 
                NULL,
118
 
                &erreur);
119
 
        //g_object_unref (pFile);
120
 
        if (erreur != NULL)
121
 
        {
122
 
                cd_warning ("gnome_integration : %s", erreur->message);
123
 
                g_error_free (erreur);
124
 
                return ;
125
 
        }
126
 
        
127
 
        GList *pIconList = NULL;
128
 
        Icon *icon;
129
 
        GFileInfo *pFileInfo;
130
 
        do
131
 
        {
132
 
                pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur);
133
 
                if (erreur != NULL)
134
 
                {
135
 
                        cd_warning ("gnome_integration : %s", erreur->message);
136
 
                        g_error_free (erreur);
137
 
                        erreur = NULL;
138
 
                }
139
 
                else
140
 
                {
141
 
                        if (pFileInfo == NULL)
142
 
                                break ;
143
 
                        GFileType iFileType = g_file_info_get_file_type (pFileInfo);
144
 
                        if (iFileType == G_FILE_TYPE_MOUNTABLE)
145
 
                        {
146
 
                                const gchar *cFileName = g_file_info_get_name (pFileInfo);
147
 
                                cd_message ("  test de  %s...", cFileName);
148
 
                                const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
149
 
                                
150
 
                                GMount *pMount = NULL;
151
 
                                if (cTargetURI != NULL)
152
 
                                {
153
 
                                        GFile *file = g_file_new_for_uri (cTargetURI);
154
 
                                        pMount = g_file_find_enclosing_mount (file, NULL, NULL);
155
 
                                        //g_object_unref (file);
156
 
                                }
157
 
                                if (pMount != NULL)
158
 
                                {
159
 
                                        gchar *cName = g_mount_get_name (pMount);
160
 
                                        cd_message ("    mount : %s", cName);
161
 
                                        if (cName != NULL && strcmp (cName, cVolumeName) == 0)
162
 
                                        {
163
 
                                                cd_message ("TROUVE");
164
 
                                                *pFoundMount = pMount;
165
 
                                                *cURI = g_strconcat ("computer:///", cFileName, NULL);
166
 
                                                GIcon *pSystemIcon = g_mount_get_icon (pMount);
167
 
                                                *cIconName = _cd_get_icon_path (pSystemIcon, NULL);
168
 
                                                g_free (cName);
169
 
                                                break ;
170
 
                                        }
171
 
                                        g_free (cName);
172
 
                                }
173
 
                        }
174
 
                }
175
 
        } while (TRUE);
176
 
        //g_object_unref (pFileEnum);
177
 
}
178
 
 
179
 
static GDrive *_cd_find_drive_from_name (const gchar *cName)
180
 
{
181
 
        g_return_val_if_fail (cName != NULL, NULL);
182
 
        cd_message ("%s (%s)", __func__, cName);
183
 
        GVolumeMonitor *pVolumeMonitor = g_volume_monitor_get ();
184
 
        GDrive *pFoundDrive = NULL;
185
 
        
186
 
        //\___________________ On chope les disques connectes (lecteur de CD/disquette/etc) et on liste leurs volumes.
187
 
        GList *pDrivesList = g_volume_monitor_get_connected_drives (pVolumeMonitor);
188
 
        GList *dl;
189
 
        GDrive *pDrive;
190
 
        gchar *cDriveName;
191
 
        for (dl = pDrivesList; dl != NULL; dl = dl->next)
192
 
        {
193
 
                pDrive = dl->data;
194
 
                if (pFoundDrive == NULL)
195
 
                {
196
 
                        cDriveName = g_drive_get_name  (pDrive);
197
 
                        cd_message ("  drive '%s'", cDriveName);
198
 
                        if (cDriveName != NULL && strcmp (cDriveName, cName) == 0)
199
 
                                pFoundDrive = pDrive;
200
 
                        else
201
 
                                g_object_unref (pDrive);
202
 
                        //g_free (cDriveName);
203
 
                }
204
 
                else
205
 
                        g_object_unref (pDrive);
206
 
        }
207
 
        g_list_free (pDrivesList);
208
 
        return pFoundDrive;
209
 
}
210
 
static gchar *_cd_find_volume_name_from_drive_name (const gchar *cName)
211
 
{
212
 
        g_return_val_if_fail (cName != NULL, NULL);
213
 
        cd_message ("%s (%s)", __func__, cName);
214
 
        GDrive *pDrive = _cd_find_drive_from_name (cName);
215
 
        g_return_val_if_fail (pDrive != NULL, NULL);
216
 
        
217
 
        gchar *cVolumeName = NULL;
218
 
        GList *pAssociatedVolumes = g_drive_get_volumes (pDrive);
219
 
        if (pAssociatedVolumes != NULL)
220
 
        {
221
 
                GVolume *pVolume;
222
 
                GList *av;
223
 
                if (pAssociatedVolumes->next != NULL)
224
 
                {
225
 
                        cd_message ("ce disque contient plus d'un volume, on garde le nom du disque plutot que de selectionner le nom d'un volume");
226
 
                        cd_message ("Pour info, la liste des volumes disponibles sur ce disque est :");
227
 
                        for (av = pAssociatedVolumes; av != NULL; av = av->next)
228
 
                        {
229
 
                                pVolume = av->data;
230
 
                                cd_message ("  - %s", g_volume_get_name  (pVolume));
231
 
                                /*if (cVolumeName == NULL)
232
 
                                        cVolumeName = g_volume_get_name  (pVolume);
233
 
                                else
234
 
                                        cd_warning ("gnome-integration : this drive (%s) has more than 1 volume but we only consider the first one (%s), ignoring %s", cName, cVolumeName, g_volume_get_name  (pVolume));*/
235
 
                                g_object_unref (pVolume);
236
 
                        }
237
 
                }
238
 
                else
239
 
                {
240
 
                        return g_strdup ("discard");
241
 
                        pVolume = pAssociatedVolumes->data;
242
 
                        cVolumeName = g_volume_get_name  (pVolume);
243
 
                        g_object_unref (pVolume);
244
 
                        cd_message ("ce disque contient 1 seul volume (%s), on prend son nom", cVolumeName);
245
 
                }
246
 
                g_list_free (pAssociatedVolumes);
247
 
        }
248
 
        //g_object_unref (pDrive);
249
 
        return cVolumeName;
250
 
}
251
 
static gboolean _cd_find_can_eject_from_drive_name (const gchar *cName)
252
 
{
253
 
        cd_debug ("%s (%s)", __func__, cName);
254
 
        GDrive *pDrive = _cd_find_drive_from_name (cName);
255
 
        g_return_val_if_fail (pDrive != NULL, FALSE);
256
 
        
257
 
        gboolean bCanEject = g_drive_can_eject (pDrive);
258
 
        //g_object_unref (pDrive);
259
 
        return bCanEject;
260
 
}
261
 
 
262
 
void vfs_backend_get_file_info (const gchar *cBaseURI, gchar **cName, gchar **cURI, gchar **cIconName, gboolean *bIsDirectory, int *iVolumeID, double *fOrder, CairoDockFMSortType iSortType)
263
 
{
264
 
        g_return_if_fail (cBaseURI != NULL);
265
 
        GError *erreur = NULL;
266
 
        cd_message ("%s (%s)", __func__, cBaseURI);
267
 
        
268
 
        gchar *cFullURI;
269
 
        if (strncmp (cBaseURI, "x-nautilus-desktop://", 21) == 0)
270
 
        {
271
 
                gchar *cNautilusFile = g_strdup (cBaseURI+14);
272
 
                memcpy (cNautilusFile, "file", 4);
273
 
                if (g_str_has_suffix (cBaseURI, ".volume"))
274
 
                {
275
 
                        cNautilusFile[strlen(cNautilusFile)-7] = '\0';
276
 
                }
277
 
                else if (g_str_has_suffix (cBaseURI, ".drive"))
278
 
                {
279
 
                        cNautilusFile[strlen(cNautilusFile)-6] = '\0';
280
 
                }
281
 
                cFullURI = g_filename_from_uri (cNautilusFile, NULL, &erreur);
282
 
                if (erreur != NULL)
283
 
                {
284
 
                        cd_warning ("gnome_integration : %s", erreur->message);
285
 
                        g_error_free (erreur);
286
 
                        return ;
287
 
                }
288
 
                gchar *cVolumeName = cFullURI + 1;  // on saute le '/'.
289
 
                cd_message ("cVolumeName : %s", cVolumeName);
290
 
                
291
 
                GMount *pMount = NULL;
292
 
                _cd_find_mount_from_volume_name (cVolumeName, &pMount, cURI, cIconName);
293
 
                g_return_if_fail (pMount != NULL);
294
 
                
295
 
                *cName = g_strdup (cVolumeName);
296
 
                *bIsDirectory = TRUE;
297
 
                *iVolumeID = 1;
298
 
                *fOrder = 0;
299
 
                //g_object_unref (pMount);
300
 
                
301
 
                g_free (cFullURI);
302
 
                //g_free (cNautilusFile);
303
 
                return;
304
 
        }
305
 
        else
306
 
        {
307
 
                if (*cBaseURI == '/')
308
 
                        cFullURI = g_filename_to_uri (cBaseURI, NULL, NULL);
309
 
                else
310
 
                        cFullURI = g_strdup (cBaseURI);
311
 
                if (*cBaseURI == ':' || *cFullURI == ':')  // cas bizarre au demontage d'un signet ftp quand celui-ci n'est pas accessible plantage dans dbus).
312
 
                {
313
 
                        cd_warning ("invalid URI (%s ; %s), skip it", cBaseURI, cFullURI);
314
 
                        g_free (cFullURI);
315
 
                        *cName = NULL;
316
 
                        *cURI = NULL;
317
 
                        *cIconName = NULL;
318
 
                        return;
319
 
                }
320
 
        }
321
 
        cd_message (" -> cFullURI : %s", cFullURI);
322
 
        
323
 
        GFile *pFile = g_file_new_for_uri (cFullURI);
324
 
        
325
 
        const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_TYPE","
326
 
                G_FILE_ATTRIBUTE_STANDARD_SIZE","
327
 
                G_FILE_ATTRIBUTE_TIME_MODIFIED","
328
 
                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
329
 
                G_FILE_ATTRIBUTE_STANDARD_NAME","
330
 
                G_FILE_ATTRIBUTE_STANDARD_ICON","
331
 
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI","
332
 
                G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE;
333
 
        GFileInfo *pFileInfo = g_file_query_info (pFile,
334
 
                cQuery,
335
 
                G_FILE_QUERY_INFO_NONE,  /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
336
 
                NULL,
337
 
                &erreur);
338
 
        //g_object_unref (pFile);
339
 
        if (erreur != NULL)
340
 
        {
341
 
                cd_warning ("gnome_integration : %s", erreur->message);
342
 
                g_error_free (erreur);
343
 
                return ;
344
 
        }
345
 
        
346
 
        *cURI = cFullURI;
347
 
        const gchar *cFileName = g_file_info_get_name (pFileInfo);
348
 
        const gchar *cMimeType = g_file_info_get_content_type (pFileInfo);
349
 
        GFileType iFileType = g_file_info_get_file_type (pFileInfo);
350
 
        
351
 
        if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
352
 
        {
353
 
                GTimeVal t;
354
 
                g_file_info_get_modification_time (pFileInfo, &t);
355
 
                *fOrder = t.tv_sec;
356
 
        }
357
 
        else if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
358
 
                *fOrder = g_file_info_get_size (pFileInfo);
359
 
        else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
360
 
                *fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0);
361
 
        else
362
 
                *fOrder = 0;
363
 
        
364
 
        *bIsDirectory = (iFileType == G_FILE_TYPE_DIRECTORY);
365
 
        cd_message (" => '%s' (mime:%s ; bIsDirectory:%d)", cFileName, cMimeType, *bIsDirectory);
366
 
        
367
 
        const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
368
 
        if (iFileType == G_FILE_TYPE_MOUNTABLE)
369
 
        {
370
 
                *cName = NULL;
371
 
                *iVolumeID = 1;
372
 
                
373
 
                cd_message ("  cTargetURI:%s", cTargetURI);
374
 
                GMount *pMount = NULL;
375
 
                if (cTargetURI != NULL)
376
 
                {
377
 
                        GFile *file = g_file_new_for_uri (cTargetURI);
378
 
                        pMount = g_file_find_enclosing_mount (file, NULL, NULL);
379
 
                        //g_object_unref (file);
380
 
                }
381
 
                if (pMount != NULL)
382
 
                {
383
 
                        *cName = g_mount_get_name (pMount);
384
 
                        cd_message ("un GMount existe (%s)",* cName);
385
 
                }
386
 
                else
387
 
                {
388
 
                        gchar *cMountName = g_strdup (cFileName);
389
 
                        gchar *str = strrchr (cMountName, '.');  // on vire l'extension ".volume" ou ".drive".
390
 
                        if (str != NULL)
391
 
                        {
392
 
                                *str = '\0';
393
 
                                if (strcmp (str+1, "link") == 0)  // pour les liens, on prend le nom du lien.
394
 
                                {
395
 
                                        if (strcmp (cMountName, "root") == 0)  // on remplace 'root' par un nom plus parlant, sinon on prendra le nom du lien.
396
 
                                        {
397
 
                                                *cName = g_strdup ("/");
398
 
                                        }
399
 
                                }
400
 
                                else if (strcmp (str+1, "drive") == 0)  // on cherche un nom plus parlant si possible.
401
 
                                {
402
 
                                        gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cMountName);
403
 
                                        if (cVolumeName != NULL)
404
 
                                        {
405
 
                                                *cName = cVolumeName;
406
 
                                        }
407
 
                                }
408
 
                        }
409
 
                        if (*cName == NULL)
410
 
                                *cName = cMountName;
411
 
                        //else
412
 
                                //g_free (cMountName);
413
 
                }
414
 
                if (*cName ==  NULL)
415
 
                        *cName = g_strdup (cFileName);
416
 
        }
417
 
        else
418
 
        {
419
 
                *iVolumeID = 0;
420
 
                *cName = g_strdup (cFileName);
421
 
        }
422
 
        
423
 
        *cIconName = NULL;
424
 
        if (cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0)
425
 
        {
426
 
                gchar *cHostname = NULL;
427
 
                GError *erreur = NULL;
428
 
                gchar *cFilePath = g_filename_from_uri (cBaseURI, &cHostname, &erreur);
429
 
                if (erreur != NULL)
430
 
                {
431
 
                        g_error_free (erreur);
432
 
                }
433
 
                else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0)  // on ne recupere la vignette que sur les fichiers locaux.
434
 
                {
435
 
                        *cIconName = g_strdup (cFilePath);
436
 
                        cairo_dock_remove_html_spaces (*cIconName);
437
 
                }
438
 
                //g_free (cHostname);
439
 
        }
440
 
        if (*cIconName == NULL)
441
 
        {
442
 
                GIcon *pSystemIcon = g_file_info_get_icon (pFileInfo);
443
 
                if (pSystemIcon != NULL)
444
 
                {
445
 
                        *cIconName = _cd_get_icon_path (pSystemIcon, cTargetURI ? cTargetURI : *cURI);
446
 
                }
447
 
        }
448
 
        cd_message ("cIconName : %s", *cIconName);
449
 
        
450
 
        //*iVolumeID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE);
451
 
        //cd_message ("ID : %d\n", *iVolumeID);
452
 
        g_object_unref (pFileInfo);
453
 
}
454
 
 
455
 
static Icon *_cd_get_icon_for_volume (GVolume *pVolume, GMount *pMount)
456
 
{
457
 
        Icon *pNewIcon = NULL;
458
 
        GIcon *pIcon;
459
 
        GFile *pRootDir;
460
 
        
461
 
        if (pVolume != NULL)
462
 
                pMount = g_volume_get_mount (pVolume);
463
 
        else if (pMount == NULL)
464
 
                return NULL;
465
 
        
466
 
        if (pMount != NULL)  // ce volume est monte.
467
 
        {
468
 
                pNewIcon = g_new0 (Icon, 1);
469
 
                pNewIcon->cName = g_mount_get_name (pMount);
470
 
                
471
 
                pRootDir = g_mount_get_root (pMount);
472
 
                pNewIcon->cCommand = g_file_get_uri (pRootDir);
473
 
                //g_object_unref (pRootDir);
474
 
                
475
 
                pIcon = g_mount_get_icon (pMount);
476
 
                pNewIcon->cFileName = _cd_get_icon_path (pIcon, NULL);
477
 
                //g_object_unref (pIcon);
478
 
                
479
 
                //g_object_unref (pMount);
480
 
        }
481
 
        else  // ce volume est demonte, on le montre quand meme (l'automount peut etre off).
482
 
        {
483
 
                pNewIcon = g_new0 (Icon, 1);
484
 
                pNewIcon->cName = g_volume_get_name (pVolume);
485
 
                
486
 
                pIcon = g_volume_get_icon (pVolume);
487
 
                pNewIcon->cFileName = _cd_get_icon_path (pIcon, NULL);
488
 
                //g_object_unref (pIcon);
489
 
                
490
 
                pNewIcon->cCommand = g_strdup (pNewIcon->cName);
491
 
        }
492
 
        pNewIcon->iVolumeID = 1;
493
 
        pNewIcon->cBaseURI = g_strdup (pNewIcon->cCommand);
494
 
        cd_message (" => %s", pNewIcon->cCommand);
495
 
        return pNewIcon;
496
 
}
497
 
 
498
 
GList *vfs_backend_list_volumes (void)
499
 
{
500
 
        GVolumeMonitor *pVolumeMonitor = g_volume_monitor_get ();
501
 
        GList *pIconsList = NULL;
502
 
        Icon *pNewIcon;
503
 
        
504
 
        //\___________________ On chope les disques connectes (lecteur de CD/disquette/etc) et on liste leurs volumes.
505
 
        GList *pDrivesList = g_volume_monitor_get_connected_drives (pVolumeMonitor);
506
 
        GList *pAssociatedVolumes;
507
 
        GList *dl, *av;
508
 
        GDrive *pDrive;
509
 
        GVolume *pVolume;
510
 
        for (dl = pDrivesList; dl != NULL; dl = dl->next)
511
 
        {
512
 
                pDrive = dl->data;
513
 
                cd_message ("drive '%s'", g_drive_get_name  (pDrive));
514
 
                
515
 
                pAssociatedVolumes = g_drive_get_volumes (pDrive);
516
 
                if (pAssociatedVolumes != NULL)
517
 
                {
518
 
                        for (av = pAssociatedVolumes; av != NULL; av = av->next)
519
 
                        {
520
 
                                pVolume = av->data;
521
 
                                cd_message (" + volume '%s'", g_volume_get_name  (pVolume));
522
 
                                pNewIcon = _cd_get_icon_for_volume (pVolume, NULL);
523
 
                                if (pNewIcon != NULL)
524
 
                                        pIconsList = g_list_prepend (pIconsList, pNewIcon);
525
 
                                //g_object_unref (pVolume);
526
 
                        }
527
 
                        g_list_free (pAssociatedVolumes);
528
 
                }
529
 
                else  // le disque n'a aucun volume montable
530
 
                {
531
 
                        cd_message ("  le disque n'a aucun volume montable");
532
 
                        /*if (g_drive_is_media_removable (pDrive) && ! g_drive_is_media_check_automatic (pDrive))
533
 
                        {
534
 
                                g_drive_get_icon (pDrive);
535
 
                                g_drive_get_name (pDrive);
536
 
                        }*/
537
 
                }
538
 
                //g_object_unref (pDrive);
539
 
        }
540
 
        g_list_free (pDrivesList);
541
 
 
542
 
        //\___________________ On chope les volumes qui ne sont pas associes a un disque.
543
 
        GList *pVolumesList = g_volume_monitor_get_volumes (pVolumeMonitor);
544
 
        GList *v;
545
 
        for (v = pVolumesList; v != NULL; v = v->next)
546
 
        {
547
 
                pVolume = v->data;
548
 
                cd_message ("volume '%s'", g_volume_get_name  (pVolume));
549
 
                pDrive = g_volume_get_drive (pVolume);
550
 
                if (pDrive != NULL)  // on l'a deja liste dans la 1ere boucle.
551
 
                {
552
 
                        cd_message ("  drive '%s' est deja liste", g_drive_get_name (pDrive));
553
 
                        //g_object_unref (pDrive);
554
 
                }
555
 
                else
556
 
                {
557
 
                        cd_message (" + volume '%s'\n", g_volume_get_name  (pVolume));
558
 
                        if (pNewIcon != NULL)
559
 
                                pNewIcon = _cd_get_icon_for_volume (pVolume, NULL);
560
 
                        pIconsList = g_list_prepend (pIconsList, pNewIcon);
561
 
                }
562
 
                //g_object_unref (pVolume);
563
 
        }
564
 
        g_list_free (pVolumesList);
565
 
 
566
 
        //\___________________ On chope les points de montage qui n'ont pas de volumes. (montage de mtab, ftp, etc)
567
 
        GList *pMountsList = g_volume_monitor_get_mounts (pVolumeMonitor);
568
 
        GMount *pMount;
569
 
        GList *m;
570
 
        for (m = pMountsList; m != NULL; m = m->next)
571
 
        {
572
 
                pMount = m->data;
573
 
                cd_message ("mount '%s'", g_mount_get_name (pMount));
574
 
                pVolume = g_mount_get_volume (pMount);
575
 
                if (pVolume != NULL)  // on l'a deja liste precedemment.
576
 
                {
577
 
                        cd_message ("volume '%s' est deja liste", g_volume_get_name  (pVolume));
578
 
                        //g_object_unref (pVolume);
579
 
                }
580
 
                else
581
 
                {
582
 
                        cd_message ("+ volume '%s'", g_volume_get_name  (pVolume));
583
 
                        if (pNewIcon != NULL)
584
 
                                pNewIcon = _cd_get_icon_for_volume (NULL, pMount);
585
 
                        pIconsList = g_list_prepend (pIconsList, pNewIcon);
586
 
                }
587
 
                //g_object_unref (pMount);
588
 
        }
589
 
        g_list_free (pMountsList);
590
 
        
591
 
        return pIconsList;
592
 
}
593
 
 
594
 
GList *vfs_backend_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsType, gboolean bListHiddenFiles, gchar **cFullURI)
595
 
{
596
 
        g_return_val_if_fail (cBaseURI != NULL, NULL);
597
 
        cd_message ("%s (%s)", __func__, cBaseURI);
598
 
        
599
 
        gchar *cURI;
600
 
        gboolean bAddHome = FALSE;
601
 
        if (strcmp (cBaseURI, CAIRO_DOCK_FM_VFS_ROOT) == 0)
602
 
        {
603
 
                cURI = g_strdup ("computer://");
604
 
                bAddHome = TRUE;
605
 
                ///*cFullURI = cURI;
606
 
                ///return vfs_backend_list_volumes ();
607
 
                //vfs_backend_list_volumes ();
608
 
        }
609
 
        else if (strcmp (cBaseURI, CAIRO_DOCK_FM_NETWORK) == 0)
610
 
                cURI = g_strdup ("network://");
611
 
        else
612
 
                cURI = (*cBaseURI == '/' ? g_strconcat ("file://", cBaseURI, NULL) : g_strdup (cBaseURI));
613
 
        *cFullURI = cURI;
614
 
        
615
 
        GFile *pFile = g_file_new_for_uri (cURI);
616
 
        GError *erreur = NULL;
617
 
        const gchar *cAttributes = G_FILE_ATTRIBUTE_STANDARD_TYPE","
618
 
                G_FILE_ATTRIBUTE_STANDARD_SIZE","
619
 
                G_FILE_ATTRIBUTE_TIME_MODIFIED","
620
 
                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
621
 
                G_FILE_ATTRIBUTE_STANDARD_NAME","
622
 
                G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN","
623
 
                G_FILE_ATTRIBUTE_STANDARD_ICON","
624
 
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI","
625
 
                G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE;
626
 
        GFileEnumerator *pFileEnum = g_file_enumerate_children (pFile,
627
 
                cAttributes,
628
 
                G_FILE_QUERY_INFO_NONE,  /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
629
 
                NULL,
630
 
                &erreur);
631
 
        //g_object_unref (pFile);
632
 
        if (erreur != NULL)
633
 
        {
634
 
                cd_warning ("gnome_integration : %s", erreur->message);
635
 
                g_error_free (erreur);
636
 
                return NULL;
637
 
        }
638
 
        
639
 
        int iOrder = 0;
640
 
        GList *pIconList = NULL;
641
 
        Icon *icon;
642
 
        GFileInfo *pFileInfo;
643
 
        do
644
 
        {
645
 
                pFileInfo = g_file_enumerator_next_file (pFileEnum, NULL, &erreur);
646
 
                if (erreur != NULL)
647
 
                {
648
 
                        cd_warning ("gnome_integration : %s", erreur->message);
649
 
                        g_error_free (erreur);
650
 
                        erreur = NULL;
651
 
                        continue;
652
 
                }
653
 
                if (pFileInfo == NULL)
654
 
                        break ;
655
 
                
656
 
                gboolean bIsHidden = g_file_info_get_is_hidden (pFileInfo);
657
 
                if (bListHiddenFiles || ! bIsHidden)
658
 
                {
659
 
                        GFileType iFileType = g_file_info_get_file_type (pFileInfo);
660
 
                        GIcon *pFileIcon = g_file_info_get_icon (pFileInfo);
661
 
                        if (pFileIcon == NULL)
662
 
                        {
663
 
                                cd_message ("AUCUNE ICONE");
664
 
                                continue;
665
 
                        }
666
 
                        const gchar *cFileName = g_file_info_get_name (pFileInfo);
667
 
                        const gchar *cMimeType = g_file_info_get_content_type (pFileInfo);
668
 
                        gchar *cName = NULL;
669
 
                        
670
 
                        icon = g_new0 (Icon, 1);
671
 
                        icon->iType = iNewIconsType;
672
 
                        icon->cBaseURI = g_strconcat (*cFullURI, "/", cFileName, NULL);
673
 
                        cd_message ("+ %s (mime:%s)", icon->cBaseURI, cMimeType);
674
 
                        
675
 
                        if (iFileType == G_FILE_TYPE_MOUNTABLE)
676
 
                        {
677
 
                                const gchar *cTargetURI = g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
678
 
                                cd_message ("  c'est un point de montage correspondant a %s", cTargetURI);
679
 
                                
680
 
                                GMount *pMount = NULL;
681
 
                                if (cTargetURI != NULL)
682
 
                                {
683
 
                                        icon->cCommand = g_strdup (cTargetURI);
684
 
                                        GFile *file = g_file_new_for_uri (cTargetURI);
685
 
                                        pMount = g_file_find_enclosing_mount (file, NULL, NULL);
686
 
                                        //g_object_unref (file);
687
 
                                }
688
 
                                if (pMount != NULL)
689
 
                                {
690
 
                                        cName = g_mount_get_name (pMount);
691
 
                                        cd_message ("un GMount existe (%s)", cName);
692
 
                                        
693
 
                                        GVolume *volume = g_mount_get_volume (pMount);
694
 
                                        if (volume)
695
 
                                                cd_message ("  volume associe : %s", g_volume_get_name (volume));
696
 
                                        GDrive *drive = g_mount_get_drive (pMount);
697
 
                                        if (drive)
698
 
                                                cd_message ("  disque associe : %s", g_drive_get_name (drive));
699
 
                                        
700
 
                                        ///pFileIcon = g_mount_get_icon (pMount);
701
 
                                }
702
 
                                else
703
 
                                {
704
 
                                        cName = g_strdup (cFileName);
705
 
                                        gchar *str = strrchr (cName, '.');  // on vire l'extension ".volume" ou ".drive".
706
 
                                        if (str != NULL)
707
 
                                        {
708
 
                                                *str = '\0';
709
 
                                                if (strcmp (str+1, "link") == 0)
710
 
                                                {
711
 
                                                        if (strcmp (cName, "root") == 0)
712
 
                                                        {
713
 
                                                                g_free (cName);
714
 
                                                                cName = g_strdup ("/");
715
 
                                                        }
716
 
                                                }
717
 
                                                else if (strcmp (str+1, "drive") == 0)  // on cherche un nom plus parlant si possible.
718
 
                                                {
719
 
                                                        gchar *cVolumeName = _cd_find_volume_name_from_drive_name (cName);
720
 
                                                        if (cVolumeName != NULL)
721
 
                                                        {
722
 
                                                                g_free (cName);
723
 
                                                                g_free (cVolumeName);
724
 
                                                                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.
725
 
                                                                /**if (strcmp (cVolumeName, "discard") == 0)
726
 
                                                                        continue;
727
 
                                                                g_free (cName);
728
 
                                                                cName = cVolumeName;*/
729
 
                                                        }
730
 
                                                }
731
 
                                        }
732
 
                                }
733
 
                                icon->iVolumeID = 1;
734
 
                                cd_message ("le nom de ce volume est : %s", cName);
735
 
                        }
736
 
                        else
737
 
                                cName = g_strdup (cFileName);
738
 
                        
739
 
                        if (icon->cCommand == NULL)
740
 
                                icon->cCommand = g_strdup (icon->cBaseURI);
741
 
                        icon->cName = cName;
742
 
                        icon->cFileName = NULL;
743
 
                        if (cMimeType != NULL && strncmp (cMimeType, "image", 5) == 0)
744
 
                        {
745
 
                                gchar *cHostname = NULL;
746
 
                                gchar *cFilePath = g_filename_from_uri (icon->cBaseURI, &cHostname, &erreur);
747
 
                                if (erreur != NULL)
748
 
                                {
749
 
                                        g_error_free (erreur);
750
 
                                        erreur = NULL;
751
 
                                }
752
 
                                else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0)  // on ne recupere la vignette que sur les fichiers locaux.
753
 
                                {
754
 
                                        icon->cFileName = g_strdup (cFilePath);
755
 
                                        cairo_dock_remove_html_spaces (icon->cFileName);
756
 
                                }
757
 
                                g_free (cHostname);
758
 
                                g_free (cFilePath);
759
 
                        }
760
 
                        if (icon->cFileName == NULL)
761
 
                        {
762
 
                                icon->cFileName = _cd_get_icon_path (pFileIcon, icon->cCommand);
763
 
                                //g_print ("icon->cFileName : %s\n", icon->cFileName);
764
 
                        }
765
 
                        
766
 
                        if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
767
 
                                icon->fOrder = g_file_info_get_size (pFileInfo);
768
 
                        else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
769
 
                        {
770
 
                                GTimeVal t;
771
 
                                g_file_info_get_modification_time (pFileInfo, &t);
772
 
                                icon->fOrder = t.tv_sec;
773
 
                        }
774
 
                        else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
775
 
                                icon->fOrder = (cMimeType != NULL ? *((int *) cMimeType) : 0);
776
 
                        if (icon->fOrder == 0)  // un peu moyen mais mieux que rien non ?
777
 
                                icon->fOrder = iOrder;
778
 
                        pIconList = g_list_insert_sorted (pIconList,
779
 
                                icon,
780
 
                                (GCompareFunc) cairo_dock_compare_icons_order);
781
 
                        cd_debug (" + %s (%s)", icon->cName, icon->cFileName);
782
 
                        iOrder ++;
783
 
                }
784
 
        } while (TRUE);  // 'g_file_enumerator_close' est appelee lors du dernier 'g_file_enumerator_next_file'.
785
 
        
786
 
        if (bAddHome && pIconList != NULL)
787
 
        {
788
 
                icon = g_new0 (Icon, 1);
789
 
                icon->iType = iNewIconsType;
790
 
                icon->cBaseURI = g_strdup_printf ("file://%s", "/home");
791
 
                icon->cCommand = g_strdup ("/home");
792
 
                //icon->cCommand = g_strdup (icon->cBaseURI);
793
 
                icon->iVolumeID = 0;
794
 
                icon->cName = g_strdup ("home");
795
 
                Icon *pRootIcon = cairo_dock_get_icon_with_name (pIconList, "/");
796
 
                if (pRootIcon == NULL)
797
 
                {
798
 
                        pRootIcon = cairo_dock_get_first_icon (pIconList);
799
 
                        g_print ("domage ! (%s:%s)\n", pRootIcon->cCommand, pRootIcon->cName);
800
 
                }
801
 
                icon->cFileName = g_strdup (pRootIcon->cFileName);
802
 
                icon->fOrder = iOrder++;
803
 
                pIconList = g_list_insert_sorted (pIconList,
804
 
                        icon,
805
 
                        (GCompareFunc) cairo_dock_compare_icons_order);
806
 
        }
807
 
        
808
 
        if (iSortType == CAIRO_DOCK_FM_SORT_BY_NAME)
809
 
                pIconList = cairo_dock_sort_icons_by_name (pIconList);
810
 
        else
811
 
                pIconList = cairo_dock_sort_icons_by_order (pIconList);
812
 
        
813
 
        return pIconList;
814
 
}
815
 
 
816
 
 
817
 
 
818
 
static gchar *_cd_find_target_uri (const gchar *cBaseURI)
819
 
{
820
 
        GError *erreur = NULL;
821
 
        GFile *pFile = g_file_new_for_uri (cBaseURI);
822
 
        GFileInfo *pFileInfo = g_file_query_info (pFile,
823
 
                G_FILE_ATTRIBUTE_STANDARD_TARGET_URI,
824
 
                G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
825
 
                NULL,
826
 
                &erreur);
827
 
        g_object_unref (pFile);
828
 
        if (erreur != NULL)
829
 
        {
830
 
                cd_warning ("gnome-integration (%s) : %s", cBaseURI, erreur->message);
831
 
                g_error_free (erreur);
832
 
                return NULL;
833
 
        }
834
 
        gchar *cTargetURI = g_strdup (g_file_info_get_attribute_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI));
835
 
        g_object_unref (pFileInfo);
836
 
        return cTargetURI;
837
 
}
838
 
void vfs_backend_launch_uri (const gchar *cURI)
839
 
{
840
 
        g_return_if_fail (cURI != NULL);
841
 
        GError *erreur = NULL;
842
 
        gchar *cFullURI = (*cURI == '/' ? g_strconcat ("file://", cURI, NULL) : g_strdup (cURI));
843
 
        cd_message ("%s (%s)", __func__, cFullURI);
844
 
        
845
 
        gchar *cTargetURI = _cd_find_target_uri (cFullURI);
846
 
        gboolean bSuccess = g_app_info_launch_default_for_uri (cTargetURI != NULL ? cTargetURI : cFullURI,
847
 
                NULL,
848
 
                &erreur);
849
 
        g_free (cFullURI);
850
 
        g_free (cTargetURI);
851
 
        if (erreur != NULL)
852
 
        {
853
 
                cd_warning ("gnome_integration : couldn't launch '%s' [%s]", cURI, erreur->message);
854
 
                g_error_free (erreur);
855
 
        }
856
 
}
857
 
 
858
 
GMount *_cd_find_mount_from_uri (const gchar *cURI, gchar **cTargetURI)
859
 
{
860
 
        cd_message ("%s (%s)", __func__, cURI);
861
 
        gchar *_cTargetURI = _cd_find_target_uri (cURI);
862
 
        
863
 
        GMount *pMount = NULL;
864
 
        if (_cTargetURI != NULL)
865
 
        {
866
 
                cd_message ("  pointe sur %s", _cTargetURI);
867
 
                GFile *file = g_file_new_for_uri (_cTargetURI);
868
 
                pMount = g_file_find_enclosing_mount (file, NULL, NULL);
869
 
                g_object_unref (file);
870
 
        }
871
 
        if (cTargetURI != NULL)
872
 
                *cTargetURI = _cTargetURI;
873
 
        else
874
 
                g_free (_cTargetURI);
875
 
        return pMount;
876
 
}
877
 
 
878
 
gchar *vfs_backend_is_mounted (const gchar *cURI, gboolean *bIsMounted)
879
 
{
880
 
        cd_message ("%s (%s)", __func__, cURI);
881
 
        gchar *cTargetURI = NULL;
882
 
        GMount *pMount = _cd_find_mount_from_uri (cURI, &cTargetURI);
883
 
        cd_message (" cTargetURI : %s", cTargetURI);
884
 
        if (pMount != NULL)
885
 
                *bIsMounted = TRUE;
886
 
        else
887
 
        {
888
 
                if (cTargetURI != NULL && strcmp (cTargetURI, "file:///") == 0)  // cas particulier ?
889
 
                        *bIsMounted = TRUE;
890
 
                else
891
 
                        *bIsMounted = FALSE;
892
 
        }
893
 
        return cTargetURI;
894
 
}
895
 
 
896
 
static gchar * _cd_find_drive_name_from_URI (const gchar *cURI)
897
 
{
898
 
        g_return_val_if_fail (cURI != NULL, NULL);
899
 
        if (strncmp (cURI, "computer:///", 12) == 0)
900
 
        {
901
 
                gchar *cDriveName = g_strdup (cURI+12);
902
 
                gchar *str = strrchr (cDriveName, '.');
903
 
                if (str != NULL)
904
 
                {
905
 
                        if (strcmp (str+1, "drive") == 0)
906
 
                        {
907
 
                                *str = '\0';
908
 
                                while (1)
909
 
                                {
910
 
                                        str = strchr (cDriveName, '\\');
911
 
                                        if (str == NULL)
912
 
                                                break;
913
 
                                        *str = '/';
914
 
                                }
915
 
                                return cDriveName;
916
 
                        }
917
 
                }
918
 
                g_free (cDriveName);
919
 
        }
920
 
        return NULL;
921
 
}
922
 
gboolean vfs_backend_can_eject (const gchar *cURI)
923
 
{
924
 
        cd_message ("%s (%s)", __func__, cURI);
925
 
        gchar *cDriveName = _cd_find_drive_name_from_URI (cURI);
926
 
        if (cDriveName == NULL)
927
 
                return FALSE;
928
 
        
929
 
        gboolean bCanEject = _cd_find_can_eject_from_drive_name (cDriveName);
930
 
        //g_free (cDriveName);
931
 
        return bCanEject;
932
 
}
933
 
gboolean vfs_backend_eject_drive (const gchar *cURI)
934
 
{
935
 
        cd_message ("%s (%s)", __func__, cURI);
936
 
        gchar *cDriveName = _cd_find_drive_name_from_URI (cURI);
937
 
        GDrive *pDrive = _cd_find_drive_from_name (cDriveName);
938
 
        if (pDrive != NULL)
939
 
        {
940
 
                g_drive_eject (pDrive,
941
 
                        G_MOUNT_UNMOUNT_NONE,
942
 
                        NULL,
943
 
                        NULL,
944
 
                        NULL);
945
 
        }
946
 
        //g_object_unref (pDrive);
947
 
        //g_free (cDriveName);
948
 
        return TRUE;
949
 
}
950
 
 
951
 
 
952
 
static void _vfs_backend_mount_callback (gpointer pObject, GAsyncResult *res, gpointer *data)
953
 
//static void _vfs_backend_mount_callback (gboolean succeeded, char *error, char *detailed_error, gpointer *data)
954
 
{
955
 
        cd_message ("%s (%d)", __func__, GPOINTER_TO_INT (data[1]));
956
 
        
957
 
        CairoDockFMMountCallback pCallback = data[0];
958
 
        
959
 
        GError *erreur = NULL;
960
 
        gboolean bSuccess;
961
 
        if (GPOINTER_TO_INT (data[1]) == 1)
962
 
                bSuccess = (g_file_mount_mountable_finish (G_FILE (pObject), res, &erreur) != NULL);
963
 
                //bSuccess = (g_volume_mount_finish (G_VOLUME (pObject), res, &erreur));
964
 
        else if (GPOINTER_TO_INT (data[1]) == 0)
965
 
                bSuccess = g_mount_unmount_finish (G_MOUNT (pObject), res, &erreur);
966
 
        else
967
 
                bSuccess = g_mount_eject_finish (G_MOUNT (pObject), res, &erreur);
968
 
        if (erreur != NULL)
969
 
        {
970
 
                cd_warning ("gnome-integration : %s", erreur->message);
971
 
                g_error_free (erreur);
972
 
        }
973
 
        
974
 
        cd_message ("(un)mount fini -> %d", bSuccess);
975
 
        pCallback (GPOINTER_TO_INT (data[1]) == 1, bSuccess, data[2], data[3], data[4]);
976
 
        //g_free (data[2]);
977
 
        //g_object_unref (pObject);
978
 
        //g_free (data);
979
 
}
980
 
 
981
 
void vfs_backend_mount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, CairoContainer *pContainer)
982
 
{
983
 
        g_return_if_fail (iVolumeID > 0);
984
 
        cd_message ("%s (%s)", __func__, cURI);
985
 
        
986
 
        /*gchar *cTargetURI = NULL;
987
 
        GMount *pMount = _cd_find_mount_from_uri (cURI, &cTargetURI);
988
 
        cd_message (" %x / %s\n", pMount, cTargetURI);
989
 
        GVolume *pVolume = g_mount_get_volume (pMount);
990
 
        gpointer *data2 = g_new (gpointer, 5);
991
 
        data2[0] = pCallback;
992
 
        data2[1] = GINT_TO_POINTER (1);
993
 
        data2[2] = g_path_get_basename (cURI);
994
 
        data2[3] = icon;
995
 
        data2[4] = pDock;
996
 
        g_volume_mount (pVolume,
997
 
                G_MOUNT_MOUNT_NONE,
998
 
                NULL,
999
 
                NULL,
1000
 
                (GAsyncReadyCallback) _vfs_backend_mount_callback,
1001
 
                data2);*/
1002
 
        gchar *cTargetURI = _cd_find_target_uri (cURI);
1003
 
        GFile *pFile = g_file_new_for_uri (cURI);
1004
 
        
1005
 
        gpointer *data2 = g_new (gpointer, 5);
1006
 
        data2[0] = pCallback;
1007
 
        data2[1] = GINT_TO_POINTER (1);
1008
 
        data2[2] = g_path_get_basename (cTargetURI);
1009
 
        data2[3] = icon;
1010
 
        data2[4] = pContainer;
1011
 
        g_file_mount_mountable  (pFile,
1012
 
                G_MOUNT_MOUNT_NONE,
1013
 
                NULL,
1014
 
                NULL,
1015
 
                (GAsyncReadyCallback) _vfs_backend_mount_callback,
1016
 
                data2);
1017
 
        g_free (cTargetURI);
1018
 
}
1019
 
 
1020
 
void vfs_backend_unmount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, CairoContainer *pContainer)
1021
 
{
1022
 
        g_return_if_fail (cURI != NULL);
1023
 
        cd_message ("%s (%s)", __func__, cURI);
1024
 
        
1025
 
        gchar *cTargetURI = NULL;
1026
 
        GMount *pMount = _cd_find_mount_from_uri (cURI, &cTargetURI);
1027
 
        if (pMount == NULL || ! G_IS_MOUNT (pMount))
1028
 
        {
1029
 
                return ;
1030
 
        }
1031
 
        
1032
 
        if ( ! g_mount_can_unmount (pMount))
1033
 
                return ;
1034
 
        
1035
 
        gboolean bCanEject = g_mount_can_eject (pMount);
1036
 
        gboolean bCanUnmount = g_mount_can_unmount (pMount);
1037
 
        cd_message ("eject:%d / unmount:%d\n", bCanEject, bCanUnmount);
1038
 
        if (! bCanEject && ! bCanUnmount)
1039
 
                return ;
1040
 
        
1041
 
        gpointer *data2 = g_new (gpointer, 5);
1042
 
        data2[0] = pCallback;
1043
 
        data2[1] = GINT_TO_POINTER (bCanEject ? 2 : 0);
1044
 
        data2[2] = g_mount_get_name (pMount);
1045
 
        data2[3] = icon;
1046
 
        data2[4] = pContainer;
1047
 
        if (bCanEject)
1048
 
                g_mount_eject (pMount,
1049
 
                        G_MOUNT_UNMOUNT_NONE,
1050
 
                        NULL,
1051
 
                        (GAsyncReadyCallback) _vfs_backend_mount_callback,
1052
 
                        data2);
1053
 
        else
1054
 
                g_mount_unmount (pMount,
1055
 
                        G_MOUNT_UNMOUNT_NONE ,
1056
 
                        NULL,
1057
 
                        (GAsyncReadyCallback) _vfs_backend_mount_callback,
1058
 
                        data2);
1059
 
}
1060
 
 
1061
 
 
1062
 
static void _on_monitor_changed (GFileMonitor *monitor,
1063
 
        GFile *file,
1064
 
        GFile *other_file,
1065
 
        GFileMonitorEvent event_type,
1066
 
        gpointer  *data)
1067
 
{
1068
 
        CairoDockFMMonitorCallback pCallback = data[0];
1069
 
        gpointer user_data = data[1];
1070
 
        cd_message ("%s (%d , data : %x)", __func__, event_type, user_data);
1071
 
        
1072
 
        CairoDockFMEventType iEventType;
1073
 
        switch (event_type)
1074
 
        {
1075
 
                case G_FILE_MONITOR_EVENT_CHANGED :
1076
 
                case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT :
1077
 
                //case G_FILE_MONITOR_EVENT_UNMOUNTED : // pertinent ?...
1078
 
                        iEventType = CAIRO_DOCK_FILE_MODIFIED;
1079
 
                        cd_message ("modification d'un fichier");
1080
 
                break;
1081
 
                
1082
 
                case G_FILE_MONITOR_EVENT_DELETED :
1083
 
                        iEventType = CAIRO_DOCK_FILE_DELETED;
1084
 
                        cd_message ("effacement d'un fichier");
1085
 
                break;
1086
 
                
1087
 
                case G_FILE_MONITOR_EVENT_CREATED :
1088
 
                        iEventType = CAIRO_DOCK_FILE_CREATED;
1089
 
                        cd_message ("creation d'un fichier");
1090
 
                break;
1091
 
                
1092
 
                default :
1093
 
                return ;
1094
 
        }
1095
 
        gchar *cURI = g_file_get_uri (file);
1096
 
        cd_message (" c'est le fichier %s", cURI);
1097
 
        gchar *cPath = NULL;
1098
 
        if (strncmp (cURI, "computer://", 11) == 0)
1099
 
        {
1100
 
                if (event_type == G_FILE_MONITOR_EVENT_CHANGED)
1101
 
                {
1102
 
                        g_free (cURI);
1103
 
                        return ;
1104
 
                }
1105
 
                memcpy (cURI+4, "file", 4);
1106
 
                cPath = g_filename_from_uri (cURI+4, NULL, NULL);
1107
 
                cd_debug(" (path:%s)", cPath);
1108
 
                g_free (cURI);
1109
 
                cURI = g_strdup_printf ("computer://%s", cPath);
1110
 
                cd_message ("son URI complete est : %s", cURI);
1111
 
        }
1112
 
        
1113
 
        pCallback (iEventType, cURI, user_data);
1114
 
        g_free (cURI);
1115
 
}
1116
 
 
1117
 
 
1118
 
void vfs_backend_add_monitor (const gchar *cURI, gboolean bDirectory, CairoDockFMMonitorCallback pCallback, gpointer user_data)
1119
 
{
1120
 
        g_return_if_fail (cURI != NULL);
1121
 
        GError *erreur = NULL;
1122
 
        GFileMonitor *pMonitor;
1123
 
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
1124
 
        if (bDirectory)
1125
 
                pMonitor = g_file_monitor_directory (pFile,
1126
 
                        G_FILE_MONITOR_WATCH_MOUNTS,
1127
 
                        NULL,
1128
 
                        &erreur);
1129
 
        else
1130
 
                pMonitor = g_file_monitor_file (pFile,
1131
 
                        G_FILE_MONITOR_WATCH_MOUNTS,
1132
 
                        NULL,
1133
 
                        &erreur);
1134
 
        //g_object_unref (pFile);
1135
 
        if (erreur != NULL)
1136
 
        {
1137
 
                cd_warning ("gnome-integration : couldn't add monitor on '%s' (%d) [%s]", cURI, bDirectory, erreur->message);
1138
 
                g_error_free (erreur);
1139
 
                return ;
1140
 
        }
1141
 
        
1142
 
        gpointer *data = g_new0 (gpointer, 3);
1143
 
        data[0] = pCallback;
1144
 
        data[1] = user_data;
1145
 
        data[2] = pMonitor;
1146
 
        g_signal_connect (G_OBJECT (pMonitor), "changed", G_CALLBACK (_on_monitor_changed), data);
1147
 
        
1148
 
        g_hash_table_insert (s_hMonitorHandleTable, g_strdup (cURI), data);
1149
 
        cd_message (">>> moniteur ajoute sur %s (%x)", cURI, user_data);
1150
 
}
1151
 
 
1152
 
void vfs_backend_remove_monitor (const gchar *cURI)
1153
 
{
1154
 
        if (cURI != NULL)
1155
 
        {
1156
 
                cd_message (">>> moniteur supprime sur %s", cURI);
1157
 
                g_hash_table_remove (s_hMonitorHandleTable, cURI);
1158
 
        }
1159
 
}
1160
 
 
1161
 
 
1162
 
 
1163
 
gboolean vfs_backend_delete_file (const gchar *cURI)
1164
 
{
1165
 
        g_return_val_if_fail (cURI != NULL, FALSE);
1166
 
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
1167
 
        
1168
 
        GError *erreur = NULL;
1169
 
        gboolean bSuccess = g_file_trash (pFile, NULL, &erreur);
1170
 
        if (erreur != NULL)
1171
 
        {
1172
 
                cd_warning ("gnome-integration : %s", erreur->message);
1173
 
                g_error_free (erreur);
1174
 
        }
1175
 
        g_object_unref (pFile);
1176
 
        return bSuccess;
1177
 
}
1178
 
 
1179
 
gboolean vfs_backend_rename_file (const gchar *cOldURI, const gchar *cNewName)
1180
 
{
1181
 
        g_return_val_if_fail (cOldURI != NULL, FALSE);
1182
 
        GFile *pOldFile = (*cOldURI == '/' ? g_file_new_for_path (cOldURI) : g_file_new_for_uri (cOldURI));
1183
 
        GError *erreur = NULL;
1184
 
        GFile *pNewFile = g_file_set_display_name (pOldFile, cNewName, NULL, &erreur);
1185
 
        if (erreur != NULL)
1186
 
        {
1187
 
                cd_warning ("gnome-integration : %s", erreur->message);
1188
 
                g_error_free (erreur);
1189
 
        }
1190
 
        gboolean bSuccess = (pNewFile != NULL);
1191
 
        if (pNewFile != NULL)
1192
 
                g_object_unref (pNewFile);
1193
 
        g_object_unref (pOldFile);
1194
 
        return bSuccess;
1195
 
}
1196
 
 
1197
 
gboolean vfs_backend_move_file (const gchar *cURI, const gchar *cDirectoryURI)
1198
 
{
1199
 
        g_return_val_if_fail (cURI != NULL, FALSE);
1200
 
        cd_message (" %s -> %s", cURI, cDirectoryURI);
1201
 
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
1202
 
        
1203
 
        gchar *cFileName = g_file_get_basename (pFile);
1204
 
        gchar *cNewFileURI = g_strconcat (cDirectoryURI, "/", cFileName, NULL);  // un peu moyen mais bon...
1205
 
        GFile *pDestinationFile = (*cNewFileURI == '/' ? g_file_new_for_path (cNewFileURI) : g_file_new_for_uri (cNewFileURI));
1206
 
        g_free (cNewFileURI);
1207
 
        g_free (cFileName);
1208
 
        
1209
 
        GError *erreur = NULL;
1210
 
        gboolean bSuccess = g_file_move (pFile,
1211
 
                pDestinationFile,
1212
 
                G_FILE_COPY_NOFOLLOW_SYMLINKS,
1213
 
                NULL,
1214
 
                NULL,  // GFileProgressCallback
1215
 
                NULL,  // data
1216
 
                &erreur);
1217
 
        if (erreur != NULL)
1218
 
        {
1219
 
                cd_warning ("gnome-integration : %s", erreur->message);
1220
 
                g_error_free (erreur);
1221
 
        }
1222
 
        g_object_unref (pFile);
1223
 
        g_object_unref (pDestinationFile);
1224
 
        return bSuccess;
1225
 
}
1226
 
 
1227
 
void vfs_backend_get_file_properties (const gchar *cURI, guint64 *iSize, time_t *iLastModificationTime, gchar **cMimeType, int *iUID, int *iGID, int *iPermissionsMask)
1228
 
{
1229
 
        g_return_if_fail (cURI != NULL);
1230
 
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
1231
 
        GError *erreur = NULL;
1232
 
        const gchar *cQuery = G_FILE_ATTRIBUTE_STANDARD_SIZE","
1233
 
                G_FILE_ATTRIBUTE_TIME_MODIFIED","
1234
 
                G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
1235
 
                G_FILE_ATTRIBUTE_UNIX_UID","
1236
 
                G_FILE_ATTRIBUTE_UNIX_GID","
1237
 
                G_FILE_ATTRIBUTE_ACCESS_CAN_READ","
1238
 
                G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE","
1239
 
                G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE;
1240
 
        GFileInfo *pFileInfo = g_file_query_info (pFile,
1241
 
                cQuery,
1242
 
                G_FILE_QUERY_INFO_NONE,  /// G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
1243
 
                NULL,
1244
 
                &erreur);
1245
 
        if (erreur != NULL)
1246
 
        {
1247
 
                cd_warning ("gnome-integration : couldn't get file properties for '%s' [%s]", cURI, erreur->message);
1248
 
                g_error_free (erreur);
1249
 
        }
1250
 
        
1251
 
        *iSize = g_file_info_get_attribute_uint64 (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE);
1252
 
        *iLastModificationTime = (time_t) g_file_info_get_attribute_uint64 (pFileInfo, G_FILE_ATTRIBUTE_TIME_MODIFIED);
1253
 
        *cMimeType = g_file_info_get_attribute_as_string (pFileInfo, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1254
 
        *iUID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_UNIX_UID);
1255
 
        *iGID = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_UNIX_GID);
1256
 
        int r = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
1257
 
        int w = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
1258
 
        int x = g_file_info_get_attribute_uint32 (pFileInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
1259
 
        *iPermissionsMask = r * 8 * 8 + w * 8 + x;
1260
 
        
1261
 
        g_object_unref (pFileInfo);
1262
 
        g_object_unref (pFile);
1263
 
}
1264
 
 
1265
 
 
1266
 
gchar *vfs_backend_get_trash_path (const gchar *cNearURI, gchar **cFileInfoPath)
1267
 
{
1268
 
        gchar *cPath = NULL;
1269
 
        /*GFile *pFile = g_file_new_for_uri ("trash://");
1270
 
        gchar *cPath = g_file_get_path (pFile);
1271
 
        g_object_unref (pFile);*/
1272
 
        const gchar *xdgPath = g_getenv ("XDG_DATA_HOME");
1273
 
        if (xdgPath != NULL)
1274
 
        {
1275
 
                cPath = g_strdup_printf ("%s/Trash/files", xdgPath);
1276
 
                if (cFileInfoPath != NULL)
1277
 
                        *cFileInfoPath = g_strdup_printf ("%s/Trash/info", xdgPath);
1278
 
        }
1279
 
        else
1280
 
        {
1281
 
                cPath = g_strdup_printf ("%s/.local/share/Trash/files", g_getenv ("HOME"));
1282
 
                if (cFileInfoPath != NULL)
1283
 
                        *cFileInfoPath = g_strdup_printf ("%s/.local/share/Trash/info", g_getenv ("HOME"));
1284
 
        }
1285
 
        return cPath;
1286
 
}
1287
 
 
1288
 
gchar *vfs_backend_get_desktop_path (void)
1289
 
{
1290
 
        GFile *pFile = g_file_new_for_uri ("desktop://");
1291
 
        gchar *cPath = g_file_get_path (pFile);
1292
 
        g_object_unref (pFile);
1293
 
        return cPath;
1294
 
}