Debian Codegraph @

xfce-integration/src/applet-thunar-vfs.c

raw
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 #ifdef HAVE_THUNAR
21
22 #include <string.h>
23 #include <thunar-vfs/thunar-vfs.h>
24
25 #include "applet-thunar-vfs.h"
26
27 static GHashTable *s_fm_MonitorHandleTable = NULL;
28
29 static void _vfs_backend_volume_added_callback (ThunarVfsVolumeManager *manager, gpointer volumes, gpointer *data);
30 static void _vfs_backend_volume_removed_callback (ThunarVfsVolumeManager *manager, gpointer volumes, gpointer *data);
31 ///static void _vfs_backend_volume_modified_callback (ThunarVfsVolumeManager *manager, ThunarVfsVolume *pVolume, gpointer *data);
32 static ThunarVfsVolume *thunar_find_volume_from_path (ThunarVfsPath *pThunarPath);
33
34 static void _vfs_backend_free_monitor_data (gpointer *data)
35 {
36 if (data != NULL)
37 {
38 ThunarVfsMonitor *pMonitor = thunar_vfs_monitor_get_default();
39 ThunarVfsMonitorHandle *pHandle = data[2];
40 thunar_vfs_monitor_remove(pMonitor, pHandle); // le ThunarVFSMonitorHandle est-il libere lors du thunar_vfs_monitor_remove () ?
41 g_free (data);
42 }
43 }
44
45 gboolean init_vfs_backend (void)
46 {
47 cd_message ("Initialisation du backend xfce-environnement");
48
49 if (s_fm_MonitorHandleTable != NULL)
50 g_hash_table_destroy (s_fm_MonitorHandleTable);
51
52 s_fm_MonitorHandleTable = g_hash_table_new_full (g_str_hash,
53 g_str_equal,
54 g_free,
55 (GDestroyNotify) _vfs_backend_free_monitor_data);
56
57 thunar_vfs_init();
58
59 return TRUE;
60 }
61
62 void stop_vfs_backend (void)
63 {
64 cd_message ("Arret du backend xfce-environnement");
65
66 if (s_fm_MonitorHandleTable != NULL)
67 {
68 g_hash_table_destroy (s_fm_MonitorHandleTable);
69 s_fm_MonitorHandleTable = NULL;
70 }
71
72 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
73 g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_added_callback, NULL);
74 g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_removed_callback, NULL);
75 ///g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_modified_callback, NULL);
76
77 thunar_vfs_shutdown();
78 }
79
80
81
82 static gboolean file_manager_get_file_info_from_desktop_link (const gchar *cBaseURI, gchar **cName, gchar **cURI, gchar **cIconName, gboolean *bIsDirectory, int *iVolumeID)
83 {
84 cd_message ("%s (%s)", __func__, cBaseURI);
85 GError *erreur = NULL;
86
87 gchar *cFileData = NULL;
88 int iFileSize = 0;
89
90 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cBaseURI, &erreur);
91 if (erreur != NULL)
92 {
93 cd_warning ("Attention : couldn't read %s (%s)", cBaseURI, erreur->message);
94 g_error_free (erreur);
95 return FALSE;
96 }
97 gchar *cFilePath = thunar_vfs_path_dup_string(pThunarPath);
98 thunar_vfs_path_unref(pThunarPath);
99 if (cFilePath == NULL)
100 {
101 cd_warning ("Attention : Couldn't retrieve path of %s", cBaseURI);
102 return FALSE;
103 }
104
105 GKeyFile *pKeyFile = g_key_file_new ();
106 g_key_file_load_from_file (pKeyFile,
107 cFilePath,
108 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
109 &erreur);
110 g_free (cFilePath);
111 if (erreur != NULL)
112 {
113 cd_warning ("Attention : %s", erreur->message);
114 g_error_free (erreur);
115 return FALSE;
116 }
117
118 gchar *cType = g_key_file_get_value (pKeyFile, "Desktop Entry", "Type", NULL);
119 //g_print (" cType : %s\n", cType);
120 if (strncmp (cType, "Link", 4) != 0 && strncmp (cType, "FSDevice", 8) != 0)
121 {
122 g_free(cType);
123 g_key_file_free (pKeyFile);
124 return FALSE;
125 }
126 g_free(cType);
127
128 *cName = g_key_file_get_string (pKeyFile, "Desktop Entry", "Name", NULL);
129
130 *cURI = g_key_file_get_string (pKeyFile, "Desktop Entry", "URL", NULL);
131
132 *cIconName = g_key_file_get_string (pKeyFile, "Desktop Entry", "Icon", NULL);
133
134 *iVolumeID = g_key_file_get_integer (pKeyFile, "Desktop Entry", "X-Gnome-Drive", NULL);
135
136 *bIsDirectory = TRUE;
137
138 g_key_file_free (pKeyFile);
139 return TRUE;
140 }
141
142 void vfs_backend_get_file_info (const gchar *cBaseURI, gchar **cName, gchar **cURI, gchar **cIconName, gboolean *bIsDirectory, int *iVolumeID, double *fOrder, CairoDockFMSortType iSortType)
143 {
144 GError *erreur = NULL;
145 g_return_if_fail (cBaseURI != NULL);
146 cd_message ("%s (%s)", __func__, cBaseURI);
147
148 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cBaseURI, &erreur);
149 if (erreur != NULL)
150 {
151 cd_warning ("couldn't read %s (%s)", cBaseURI, erreur->message);
152 g_error_free (erreur);
153 return;
154 }
155
156 // distinguer les mounts points du reste
157 ThunarVfsVolume *pThunarVolume = thunar_find_volume_from_path (pThunarPath);
158 if (pThunarVolume != NULL)
159 cd_debug (" correspond a un volume");
160
161 ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
162 thunar_vfs_path_unref(pThunarPath);
163 if (erreur != NULL)
164 {
165 /* Si on a trouve un volume, le chemin peut ne pas exister et donc cette erreur peut etre acceptable */
166 if (pThunarVolume == NULL)
167 {
168 cd_warning ("couldn't get info about %s : %s", cBaseURI, erreur->message);
169 g_error_free (erreur);
170 return;
171 }
172 g_error_free (erreur);
173 erreur = NULL;
174 }
175
176 *fOrder = 0;
177 if( pThunarVfsInfo )
178 {
179 if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
180 *fOrder = (double)pThunarVfsInfo->mtime;
181 else if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
182 *fOrder = (double)pThunarVfsInfo->size;
183 else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
184 *fOrder = (double)pThunarVfsInfo->type;
185 }
186
187 *cURI = g_strdup (cBaseURI);
188
189 if( pThunarVolume )
190 {
191 *cName = g_strdup(thunar_vfs_volume_get_name( pThunarVolume ));
192 *iVolumeID = 1;
193 *bIsDirectory = FALSE;
194 *cIconName = g_strdup(thunar_vfs_volume_lookup_icon_name(pThunarVolume, gtk_icon_theme_get_default()));
195 }
196 else if( pThunarVfsInfo )
197 {
198 *cName = g_strdup (pThunarVfsInfo->display_name);
199 *iVolumeID = 0;
200 *bIsDirectory = ((pThunarVfsInfo->type & THUNAR_VFS_FILE_TYPE_DIRECTORY) != 0);
201 *cIconName = pThunarVfsInfo->custom_icon?g_strdup(pThunarVfsInfo->custom_icon):NULL;
202
203 ThunarVfsMimeInfo*pThunarMimeInfo = pThunarVfsInfo->mime_info;
204 if( pThunarMimeInfo )
205 {
206 const gchar *cMimeType = thunar_vfs_mime_info_get_name (pThunarMimeInfo);
207 cd_debug (" cMimeType : %s", cMimeType);
208 if ( *cIconName == NULL && cMimeType && strcmp (cMimeType, "application/x-desktop") == 0)
209 {
210 thunar_vfs_info_unref(pThunarVfsInfo);
211 thunar_vfs_mime_info_unref( pThunarMimeInfo );
212 file_manager_get_file_info_from_desktop_link (cBaseURI, cName, cURI, cIconName, bIsDirectory, iVolumeID);
213 *fOrder = 0;
214 return ;
215 }
216
217 /*On verra un peu plus tard pour les vignettes des images, hein*/
218 if(*cIconName == NULL && (strncmp (cMimeType, "image", 5) == 0))
219 {
220 gchar *cHostname = NULL;
221 gchar *cFilePath = g_filename_from_uri (cBaseURI, &cHostname, &erreur);
222 if (erreur != NULL)
223 {
224 g_error_free (erreur);
225 }
226 else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux.
227 {
228 *cIconName = thunar_vfs_path_dup_string(pThunarPath);
229 cairo_dock_remove_html_spaces (*cIconName);
230 }
231 g_free (cHostname);
232 }
233
234 if (*cIconName == NULL)
235 {
236 *cIconName = g_strdup (thunar_vfs_mime_info_lookup_icon_name(pThunarMimeInfo, gtk_icon_theme_get_default()));
237 }
238 }
239 }
240
241 if( pThunarVfsInfo )
242 {
243 thunar_vfs_info_unref(pThunarVfsInfo);
244 }
245 }
246
247
248 struct ThunarFolder_t {
249 GList *file_list;
250 ThunarVfsJob *job;
251 gboolean isJobFinished;
252 };
253
254 typedef struct ThunarFolder_t ThunarFolder;
255
256 static gboolean thunar_folder_infos_ready (ThunarVfsJob *job,
257 GList *infos,
258 ThunarFolder *folder)
259 {
260 /* merge the list with the existing list of new files */
261 folder->file_list = g_list_concat (folder->file_list, infos);
262
263 /* TRUE to indicate that we took over ownership of the infos list */
264 return TRUE;
265 }
266
267 static void thunar_folder_finished (ThunarVfsJob *job, ThunarFolder *folder)
268 {
269 /* we did it, the folder is loaded */
270 g_signal_handlers_disconnect_matched (folder->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, folder);
271 g_object_unref (G_OBJECT (folder->job));
272 folder->job = NULL;
273 folder->isJobFinished = TRUE;
274 }
275
276 /*
277 * Attention: si l'URI demandee est CAIRO_DOCK_FM_VFS_ROOT, alors il faut retourner la liste des volumes !
278 * En effet dans ThunarVFS "root://" correspond simplement à "/"
279 */
280 GList *vfs_backend_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsType, gboolean bListHiddenFiles, int iNbMaxFiles, gchar **cFullURI)
281 {
282 GError *erreur = NULL;
283 g_return_val_if_fail (cBaseURI != NULL, NULL);
284 cd_message ("%s (%s)", __func__, cBaseURI);
285
286 GList *pIconList = NULL;
287
288 const gchar *cURI = NULL;
289 if (strcmp (cBaseURI, CAIRO_DOCK_FM_VFS_ROOT) == 0)
290 {
291 cURI = CAIRO_DOCK_FM_VFS_ROOT;
292
293 if( cFullURI )
294 {
295 *cFullURI = g_strdup(cURI);
296 }
297
298 /* listons joyeusement les volumes */
299 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
300 const GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
301 int lVolumeFakeID = 1;
302 int iNbFiles = 0;
303
304 for( ; pListVolumes != NULL && iNbFiles < iNbMaxFiles; pListVolumes = pListVolumes->next, lVolumeFakeID++ )
305 {
306 ThunarVfsVolume *pThunarVfsVolume = (ThunarVfsVolume *)pListVolumes->data;
307
308 /* Skip the volumes that are not there or that are not removable */
309 if (!thunar_vfs_volume_is_present (pThunarVfsVolume) || !thunar_vfs_volume_is_removable (pThunarVfsVolume))
310 continue;
311
312 ThunarVfsPath *pThunarVfsPath = thunar_vfs_volume_get_mount_point(pThunarVfsVolume);
313 Icon *icon = cairo_dock_create_dummy_launcher (NULL, NULL, NULL, NULL, 0);
314
315 /* il nous faut: URI, type, nom, icone */
316
317 icon->cBaseURI = thunar_vfs_path_dup_uri(pThunarVfsPath);
318 cd_debug ("mount point : %s", icon->cBaseURI);
319
320 icon->cCommand = thunar_vfs_path_dup_uri(pThunarVfsPath);
321 icon->iVolumeID = lVolumeFakeID;
322
323 cd_message (" -> icon->cBaseURI : %s", icon->cBaseURI);
324
325 icon->iGroup = iNewIconsType;
326
327 icon->cName = g_strdup(thunar_vfs_volume_get_name( pThunarVfsVolume ));
328 cd_debug (" -> icon->cName : %s", icon->cName);
329
330 icon->cFileName = g_strdup(thunar_vfs_volume_lookup_icon_name(pThunarVfsVolume, gtk_icon_theme_get_default()));
331 cd_debug (" -> icon->cFileName : %s", icon->cFileName);
332
333 erreur = NULL;
334 ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarVfsPath, &erreur);
335 if (erreur != NULL)
336 {
337 icon->fOrder = 0;
338 cd_warning ("Attention : %s", erreur->message);
339 g_error_free (erreur);
340 }
341 else
342 {
343 if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
344 icon->fOrder = pThunarVfsInfo->size;
345 else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
346 icon->fOrder = pThunarVfsInfo->mtime;
347 else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
348 icon->fOrder = pThunarVfsInfo->type;
349
350 thunar_vfs_info_unref(pThunarVfsInfo);
351 }
352
353 pIconList = g_list_prepend (pIconList, icon);
354 iNbFiles ++;
355 }
356
357 return pIconList;
358 }
359 else if (strcmp (cBaseURI, CAIRO_DOCK_FM_NETWORK) == 0)
360 {
361 cd_message (" -> Good try, but no, there's no network management in Thunar VFS !");
362
363 if( cFullURI )
364 *cFullURI = g_strdup(CAIRO_DOCK_FM_NETWORK);
365
366 return pIconList;
367 }
368 else
369 cURI = cBaseURI;
370
371 if( cFullURI )
372 *cFullURI = g_strdup(cURI);
373 g_return_val_if_fail (cURI != NULL, NULL);
374
375 cd_message (" -> cURI : %s", cURI);
376
377 ThunarFolder *folder = g_new( ThunarFolder, 1 );
378 folder->isJobFinished = FALSE;
379 folder->file_list = NULL;
380
381 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
382 if (erreur != NULL)
383 {
384 cd_warning ("couldn't read %s (%s)", cURI, erreur->message);
385 g_error_free (erreur);
386 return NULL;
387 }
388 folder->job = thunar_vfs_listdir(pThunarPath, NULL);
389 thunar_vfs_path_unref(pThunarPath);
390
391 g_signal_connect (folder->job, "error", G_CALLBACK (thunar_folder_finished), folder);
392 g_signal_connect (folder->job, "finished", G_CALLBACK (thunar_folder_finished), folder);
393 g_signal_connect (folder->job, "infos-ready", G_CALLBACK (thunar_folder_infos_ready), folder);
394
395 while ( !folder->isJobFinished )
396 {
397 if (gtk_events_pending())
398 {
399 gtk_main_iteration(); // Handle unprocessed GTK events
400 }
401 else
402 {
403 g_thread_yield(); // Yield processing time
404 }
405 }
406
407 /* Ô joie, on a une liste de ThunarVfsInfos ! */
408 GList *lp = NULL;
409 for (lp = folder->file_list; lp != NULL; lp = lp->next)
410 {
411 /* get the info... */
412 ThunarVfsInfo *pThunarVfsInfo = (ThunarVfsInfo *)(lp->data);
413
414 Icon *icon;
415
416 if(pThunarVfsInfo != NULL &&
417 strcmp (thunar_vfs_path_get_name(pThunarVfsInfo->path), ".") != 0 &&
418 strcmp (thunar_vfs_path_get_name(pThunarVfsInfo->path), "..") != 0)
419 {
420 icon = cairo_dock_create_dummy_launcher (NULL, NULL, NULL, NULL, 0);
421 icon->cBaseURI = thunar_vfs_path_dup_uri(pThunarVfsInfo->path);
422 cd_message (" item in directory : %s", icon->cBaseURI);
423 icon->iGroup = iNewIconsType;
424 if ( strcmp (thunar_vfs_mime_info_get_name(pThunarVfsInfo->mime_info), "application/x-desktop") == 0)
425 {
426 gboolean bIsDirectory = FALSE;
427 file_manager_get_file_info_from_desktop_link (icon->cBaseURI, &icon->cName, &icon->cCommand, &icon->cFileName, &bIsDirectory, &icon->iVolumeID);
428 cd_message (" bIsDirectory : %d; iVolumeID : %d", bIsDirectory, icon->iVolumeID);
429 }
430 else
431 {
432 icon->cCommand = g_strdup(icon->cBaseURI);
433 icon->cName = g_strdup (thunar_vfs_path_get_name(pThunarVfsInfo->path));
434 icon->cFileName = NULL;
435 if (strncmp (thunar_vfs_mime_info_get_name(pThunarVfsInfo->mime_info), "image", 5) == 0) // && strncmp (cFileURI, "file://", 7) == 0
436 {
437 gchar *cHostname = NULL;
438 GError *erreur = NULL;
439 gchar *cFilePath = g_filename_from_uri (icon->cBaseURI, &cHostname, &erreur);
440 if (erreur != NULL)
441 {
442 g_error_free (erreur);
443 erreur = NULL;
444 }
445 else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux.
446 {
447 icon->cFileName = g_strdup (cFilePath);
448 cairo_dock_remove_html_spaces (icon->cFileName);
449 }
450 g_free (cHostname);
451 }
452 if (icon->cFileName == NULL)
453 {
454 icon->cFileName = g_strdup(thunar_vfs_mime_info_lookup_icon_name(pThunarVfsInfo->mime_info, gtk_icon_theme_get_default()));
455 }
456 }
457
458 if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
459 icon->fOrder = pThunarVfsInfo->size;
460 else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
461 icon->fOrder = pThunarVfsInfo->mtime;
462 else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
463 icon->fOrder = pThunarVfsInfo->type;
464
465 pIconList = g_list_prepend (pIconList, icon);
466 }
467
468 /* ...release the info at the list position... */
469 thunar_vfs_info_unref (lp->data);
470 }
471
472 if (iSortType == CAIRO_DOCK_FM_SORT_BY_NAME)
473 pIconList = cairo_dock_sort_icons_by_name (pIconList);
474 else
475 pIconList = cairo_dock_sort_icons_by_order (pIconList);
476
477 return pIconList;
478 }
479
480 ThunarVfsVolume *thunar_find_volume_from_path (ThunarVfsPath *pThunarPath)
481 {
482 GError *erreur = NULL;
483 gchar *ltmp_path = NULL;
484
485 ThunarVfsVolume *pThunarVolume = NULL;
486
487 /* premiere methode: on scanne les volumes. c'est peut-etre un volume non monte... */
488 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
489 GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
490 for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
491 {
492 pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
493 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
494 ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
495 if( ltmp_path )
496 {
497 cd_debug (" - %s", ltmp_path);
498 g_free(ltmp_path);
499 }
500
501 /* Skip the volumes that are not there or that are not removable */
502 if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
503 {
504 pThunarVolume = NULL;
505 cd_debug (" saute");
506 continue;
507 }
508
509
510 if( thunar_vfs_path_equal(pThunarPath, pMountPointVfsPath) ) // || thunar_vfs_path_is_ancestor( pThunarPath, pMountPointVfsPath )
511 {
512 cd_debug (" trouve !");
513 break;
514 }
515 pThunarVolume = NULL;
516 }
517
518 /* if( pThunarVolume == NULL )
519 {
520 // deuxieme methode: avec le vfs_info.
521 ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
522 if (erreur != NULL)
523 {
524 cd_warning ("Attention : %s", erreur->message);
525 g_error_free (erreur);
526 }
527 else
528 {
529 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
530 pThunarVolume = thunar_vfs_volume_manager_get_volume_by_info(pThunarVolumeManager, pThunarVfsInfo);
531 g_object_unref(pThunarVolumeManager);
532 thunar_vfs_info_unref(pThunarVfsInfo);
533 cd_debug ("2eme methode -> volume : %x", pThunarVolume);
534
535 // Skip the volumes that are not there or that are not removable
536 if (pThunarVolume == NULL || !thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
537 {
538 pThunarVolume = NULL;
539 }
540 }
541 }*/
542
543 return pThunarVolume;
544 }
545
546 /* Fait */
547 void vfs_backend_launch_uri (const gchar *cURI)
548 {
549 GError *erreur = NULL;
550 g_return_if_fail (cURI != NULL);
551 cd_message ("%s (%s)", __func__, cURI);
552
553 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
554 if (erreur != NULL)
555 {
556 cd_warning ("Attention : couldn't read %s (%s)", cURI, erreur->message);
557 g_error_free (erreur);
558 return;
559 }
560
561 ThunarVfsPath *pThunarRealPath = NULL;
562
563 /* hop, trouvons le volume correspondant */
564 ThunarVfsVolume *pThunarVolume = thunar_find_volume_from_path(pThunarPath);
565 if (pThunarVolume != NULL)
566 {
567 thunar_vfs_path_unref(pThunarPath);
568 pThunarPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
569 }
570
571 ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
572 if (erreur != NULL)
573 {
574 cd_warning ("Attention : %s", erreur->message);
575 g_error_free (erreur);
576 return;
577 }
578
579 /* if this is a directory, open Thunar in that directory */
580 /*if( pThunarVfsInfo->flags & THUNAR_VFS_FILE_FLAGS_EXECUTABLE )
581 {
582 thunar_vfs_info_execute(pThunarVfsInfo,NULL,NULL, NULL,&erreur);
583 if (erreur != NULL)
584 {
585 cd_warning ("Attention : %s", erreur->message);
586 g_error_free (erreur);
587 }
588 }
589 else*/ /// mis en commentaire le 17/09/2009, car il semble que thunar_vfs_info_execute ouvre Thunar sans chercher si c'est lui le file-manager par defaut.
590 {
591 ThunarVfsMimeDatabase *pMimeDB = thunar_vfs_mime_database_get_default();
592 if( pMimeDB )
593 {
594 ThunarVfsMimeApplication *pMimeApplication = thunar_vfs_mime_database_get_default_application(pMimeDB, pThunarVfsInfo->mime_info);
595 if( pMimeApplication )
596 {
597 GList *path_list = g_list_prepend (NULL, pThunarPath);
598 cd_message ("Launching %s ...", thunar_vfs_mime_handler_get_command(pMimeApplication) );
599 thunar_vfs_mime_handler_exec(pMimeApplication,gdk_screen_get_default (),path_list,&erreur);
600 g_list_free(path_list);
601 g_object_unref( pMimeApplication );
602 if (erreur != NULL)
603 {
604 cd_warning ("Attention : %s", erreur->message);
605 g_error_free (erreur);
606 }
607 }
608 g_object_unref( pMimeDB );
609 }
610 }
611
612 thunar_vfs_info_unref(pThunarVfsInfo);
613 }
614
615 /* Fait */
616 gchar *vfs_backend_is_mounted (const gchar *cURI, gboolean *bIsMounted)
617 {
618 GError *erreur = NULL;
619 cd_message ("%s (%s)", __func__, cURI);
620
621 ThunarVfsVolume *pThunarVolume = NULL;
622
623 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
624 if (erreur != NULL)
625 {
626 cd_warning ("ERROR : %s", erreur->message);
627 g_error_free (erreur);
628 return NULL;
629 }
630
631 /* hop, trouvons le volume correspondant */
632 pThunarVolume = thunar_find_volume_from_path(pThunarPath);
633 thunar_vfs_path_unref(pThunarPath);
634
635 if (pThunarVolume == NULL)
636 {
637 cd_warning ("Attention : no volume associated to %s, we'll assume that it is not mounted", cURI);
638 *bIsMounted = FALSE;
639 return NULL;
640 }
641
642 *bIsMounted = thunar_vfs_volume_is_mounted(pThunarVolume);
643 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
644 gchar *cMountPointID = pMountPointVfsPath?thunar_vfs_path_dup_uri(pMountPointVfsPath):NULL;
645
646 cd_message (" bIsMounted <- %d", *bIsMounted);
647
648 return cMountPointID;
649 }
650
651
652 static void _vfs_backend_mount_callback(ThunarVfsVolume *volume, gpointer *data)
653 {
654 cd_message ("%s (%x)", __func__, data);
655
656 /// Debug.
657 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
658 GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
659 for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
660 {
661 ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
662 /* Skip the volumes that are not there or that are not removable */
663 if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
664 {
665 pThunarVolume = NULL;
666 continue;
667 }
668 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
669 gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
670 cd_debug (" + %s", ltmp_path);
671 }
672
673 CairoDockFMMountCallback pCallback = data[0];
674 pCallback (GPOINTER_TO_INT (data[1]), TRUE, data[2], data[3], data[4]);
675 }
676 /*static void _vfs_backend_change_callback(ThunarVfsVolume *volume, gpointer *data)
677 {
678 cd_message ("%s (%x)", __func__, data);
679 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
680 GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
681 for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
682 {
683 ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
684
685 // Skip the volumes that are not there or that are not removable
686 if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
687 {
688 pThunarVolume = NULL;
689 continue;
690 }
691
692 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
693 gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
694 cd_debug (" + %s", ltmp_path);
695 }
696 CairoDockFMMountCallback pCallback = data[0];
697
698 pCallback (GPOINTER_TO_INT (data[1]), TRUE, data[2], data[3], data[4]);
699 }*/
700
701 void vfs_backend_mount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, GldiContainer *pContainer)
702 {
703 GError *erreur = NULL;
704 g_return_if_fail (cURI != NULL);
705 cd_message ("%s (%s)", __func__, cURI);
706
707 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
708 if (erreur != NULL)
709 {
710 cd_warning ("Attention : couldn't read %s (%s)", cURI, erreur->message);
711 g_error_free (erreur);
712 return;
713 }
714 /* hop, trouvons le volume correspondant */
715 ThunarVfsVolume *pThunarVolume = thunar_find_volume_from_path(pThunarPath);
716 thunar_vfs_path_unref(pThunarPath);
717
718 if (pThunarVolume == NULL)
719 {
720 cd_warning ("Attention : no volume associated to %s", cURI);
721 return;
722 }
723
724 gpointer *data2 = g_new (gpointer, 5);
725 data2[0] = pCallback;
726 data2[1] = GINT_TO_POINTER (TRUE);
727 data2[2] = thunar_vfs_volume_get_name(pThunarVolume);
728 data2[3] = icon;
729 data2[4] = pContainer;
730 g_signal_connect(pThunarVolume, "mounted", G_CALLBACK (_vfs_backend_mount_callback), data2);
731
732 if( !thunar_vfs_volume_mount(pThunarVolume, NULL, &erreur) )
733 {
734 cd_warning ("Attention, %s couldn't be mounted : %s",cURI, erreur->message);
735 g_error_free (erreur);
736 }
737 g_signal_handlers_disconnect_matched (pThunarVolume, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data2);
738 g_free (data2);
739 }
740
741 void vfs_backend_unmount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, GldiContainer *pContainer)
742 {
743 GError *erreur = NULL;
744 g_return_if_fail (cURI != NULL);
745 cd_message ("%s (%s)", __func__, cURI);
746
747 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
748 if (erreur != NULL)
749 {
750 cd_message ("Attention : couldn't read %s (%s)", cURI, erreur->message);
751 g_error_free (erreur);
752 return;
753 }
754 /* hop, trouvons le volume correspondant */
755 ThunarVfsVolume *pThunarVolume = thunar_find_volume_from_path(pThunarPath);
756 thunar_vfs_path_unref(pThunarPath);
757
758 if (pThunarVolume == NULL)
759 {
760 cd_warning ("Attention : no volume associated to %s", cURI);
761 return ;
762 }
763
764 gpointer *data2 = g_new (gpointer, 5);
765 data2[0] = pCallback;
766 data2[1] = GINT_TO_POINTER (FALSE);
767 data2[2] = thunar_vfs_volume_get_name(pThunarVolume);
768 data2[3] = icon;
769 data2[4] = pContainer;
770 g_signal_connect(pThunarVolume, "unmounted", G_CALLBACK (_vfs_backend_mount_callback), data2);
771
772 if( !thunar_vfs_volume_unmount(pThunarVolume, NULL, &erreur) )
773 {
774 cd_message ("Attention, %s couldn't be unmounted : %s\n",cURI, erreur->message);
775 g_error_free (erreur);
776 }
777 cd_debug ("demontage fini");
778 g_signal_handlers_disconnect_matched (pThunarVolume, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data2);
779 g_free (data2);
780 }
781
782 static void _vfs_backend_volume_added_callback (ThunarVfsVolumeManager *manager,
783 gpointer volumes,
784 gpointer *data)
785 {
786 CairoDockFMMonitorCallback pCallback = data[0];
787 gpointer user_data = data[1];
788 cd_message ("");
789
790 /* call the callback for each volume */
791 GList *pListVolumes = volumes;
792 for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
793 {
794 ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
795
796 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
797 gchar *info_uri = thunar_vfs_path_dup_uri(pMountPointVfsPath);
798
799 pCallback (CAIRO_DOCK_FILE_CREATED, info_uri, user_data);
800 g_free(info_uri);
801 }
802 }
803
804 static void _vfs_backend_volume_removed_callback (ThunarVfsVolumeManager *manager,
805 gpointer volumes,
806 gpointer *data)
807 {
808 CairoDockFMMonitorCallback pCallback = data[0];
809 gpointer user_data = data[1];
810 cd_message ("");
811
812 /* call the callback for each volume */
813 GList *pListVolumes = volumes;
814 for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
815 {
816 ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
817
818 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
819 gchar *info_uri = thunar_vfs_path_dup_uri(pMountPointVfsPath);
820
821 pCallback (CAIRO_DOCK_FILE_DELETED, info_uri, user_data);
822 g_free(info_uri);
823 }
824 }
825
826 /*void _vfs_backend_volume_modified_callback (ThunarVfsVolumeManager *manager, ThunarVfsVolume *pVolume, gpointer *data)
827 {
828 CairoDockFMMonitorCallback pCallback = data[0];
829 gpointer user_data = data[1];
830 cd_message ("");
831 /// On a le volume tel qu'il est apres le montage/demontage. Du coup, son URI est la nouvelle. Or la modification se fait sur l'ancienne ...
832
833 gboolean bMounted = thunar_vfs_volume_is_mounted(pVolume);
834 if (bMounted) // on vient de le monter. avant c'etait /dev/sdb1, maintenant c'est /media/disk
835 {
836 const gchar* cName = thunar_vfs_volume_get_name (pVolume);
837 cd_debug ("volume to remove : %s", cName);
838 pCallback (CAIRO_DOCK_FILE_DELETED, cName, user_data);
839
840 const ThunarVfsPath *pMountPoint = thunar_vfs_volume_get_mount_point (pVolume);
841 gchar *cUri = thunar_vfs_path_dup_uri (pMountPoint);
842 cd_debug ("new mount point : %s", cUri);
843 pCallback (CAIRO_DOCK_FILE_CREATED, cUri, user_data);
844 g_free (cUri);
845 }
846 else // on vient de le demonter, avant c'etait /media/disk, mais maintenant aussi !
847 {
848 const ThunarVfsPath *pMountPoint = thunar_vfs_volume_get_mount_point (pVolume);
849 gchar *cUri = thunar_vfs_path_dup_uri (pMountPoint);
850 cd_debug ("mount point : %s", cUri);
851
852 /// Debug.
853 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
854 GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
855 for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
856 {
857 ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
858
859 // Skip the volumes that are not there or that are not removable.
860 if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
861 {
862 pThunarVolume = NULL;
863 continue;
864 }
865
866 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
867 gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
868 cd_debug (" + %s", ltmp_path);
869 }
870
871 pCallback (CAIRO_DOCK_FILE_MODIFIED, cUri, user_data);
872 g_free (cUri);
873 }
874 }*/
875
876
877 static void _vfs_backend_thunar_monitor_callback(ThunarVfsMonitor *monitor,
878 ThunarVfsMonitorHandle *handle,
879 ThunarVfsMonitorEvent event,
880 ThunarVfsPath *handle_path,
881 ThunarVfsPath *event_path,
882 gpointer *data)
883 {
884 CairoDockFMMonitorCallback pCallback = data[0];
885 gpointer user_data = data[1];
886 cd_message ("%s (%d , data : %x)", __func__, event, user_data);
887
888 CairoDockFMEventType iEventType;
889 switch (event)
890 {
891 case THUNAR_VFS_MONITOR_EVENT_CHANGED :
892 iEventType = CAIRO_DOCK_FILE_MODIFIED;
893 break;
894
895 case THUNAR_VFS_MONITOR_EVENT_DELETED :
896 iEventType = CAIRO_DOCK_FILE_DELETED;
897 break;
898
899 case THUNAR_VFS_MONITOR_EVENT_CREATED :
900 iEventType = CAIRO_DOCK_FILE_CREATED;
901 break;
902
903 default :
904 return ;
905 }
906 gchar *info_uri = thunar_vfs_path_dup_uri(event_path);
907 pCallback (iEventType, info_uri, user_data);
908 g_free(info_uri);
909 }
910 static void _vfs_backend_volume_changed_callback (ThunarVfsVolume *pThunarVolume, gpointer *data)
911 {
912 CairoDockFMMonitorCallback pCallback = data[0];
913 gpointer user_data = data[1];
914 gchar *cUri = data[2];
915 cd_debug ("%x - %x - %x", data[0], data[1], data[2]);
916 g_return_if_fail (cUri != NULL);
917 cd_message (" >>> %s (%s)", __func__, cUri);
918
919 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
920 gchar *cNewUri = thunar_vfs_path_dup_uri(pMountPointVfsPath);
921 if (strcmp (cNewUri, cUri) != 0)
922 {
923 cd_message (" ce volume devient : %s", cNewUri);
924
925 pCallback (CAIRO_DOCK_FILE_DELETED, cUri, user_data);
926
927 pCallback (CAIRO_DOCK_FILE_CREATED, cNewUri, user_data);
928 g_free (cUri);
929 data[2] = cNewUri;
930 }
931 else
932 g_free (cNewUri);
933 }
934
935
936 void vfs_backend_add_monitor (const gchar *cURI, gboolean bDirectory, CairoDockFMMonitorCallback pCallback, gpointer user_data)
937 {
938 GError *erreur = NULL;
939 g_return_if_fail (cURI != NULL);
940 cd_message ("%s (%s)", __func__, cURI);
941
942 // faire un gros cas particulier pour CAIRO_DOCK_FM_VFS_ROOT, qui est retourné lors du listing dudit répertoire
943 if( strcmp( cURI, CAIRO_DOCK_FM_VFS_ROOT ) == 0 )
944 {
945 // se brancher sur les signaux "volumes-added" et "volumes-removed" du volume manager
946 gpointer *data = g_new0 (gpointer, 2);
947 data[0] = pCallback;
948 data[1] = user_data;
949
950 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
951 // on nettoie d'abord, au cas ou
952 g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_added_callback, NULL);
953 g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_removed_callback, NULL);
954 ///g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_modified_callback, NULL);
955 ///g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_modified_callback, NULL);
956 // puis on se branche
957 g_signal_connect(pThunarVolumeManager, "volumes-added", G_CALLBACK (_vfs_backend_volume_added_callback), data);
958 g_signal_connect(pThunarVolumeManager, "volumes-removed", G_CALLBACK (_vfs_backend_volume_removed_callback), data);
959 ///g_signal_connect(pThunarVolumeManager, "volume-mounted", G_CALLBACK (_vfs_backend_volume_modified_callback), data);
960 ///g_signal_connect(pThunarVolumeManager, "volume-unmounted", G_CALLBACK (_vfs_backend_volume_modified_callback), data);
961
962 //\____________ Pour avoir les changements de point de montage, on se connecte au signal "changed" de chaque volume. En effet, le signal "unmounted" est emis juste apres le demontage, le changement de point de montage ne s'est pas encore fait !
963 GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
964 for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
965 {
966 ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
967
968 /* Skip the volumes that are not there or that are not removable */
969 if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
970 {
971 pThunarVolume = NULL;
972 continue;
973 }
974
975 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
976 gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
977 cd_debug (" signal ajoute sur %s", ltmp_path);
978 gpointer *data2 = g_new0 (gpointer, 3);
979 data2[0] = pCallback;
980 data2[1] = user_data;
981 data2[2] = ltmp_path;
982 g_signal_connect(pThunarVolume, "changed", G_CALLBACK (_vfs_backend_volume_changed_callback), data2);
983 cd_debug ("%x - %x - %x", data2[0], data2[1], data2[2]);
984 }
985 return;
986 }
987
988 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
989 if (erreur != NULL)
990 {
991 cd_warning ("Attention : %s", erreur->message);
992 g_error_free (erreur);
993 return;
994 }
995
996 ThunarVfsMonitor *pThunarMonitor = thunar_vfs_monitor_get_default();
997 ThunarVfsMonitorHandle *pHandle = NULL;
998 gpointer *data = g_new0 (gpointer, 3);
999 data[0] = pCallback;
1000 data[1] = user_data;
1001
1002 if( bDirectory )
1003 {
1004 pHandle = thunar_vfs_monitor_add_directory(pThunarMonitor, pThunarPath,
1005 (ThunarVfsMonitorCallback) _vfs_backend_thunar_monitor_callback,
1006 data);
1007 }
1008 else
1009 {
1010 pHandle = thunar_vfs_monitor_add_file(pThunarMonitor, pThunarPath,
1011 (ThunarVfsMonitorCallback) _vfs_backend_thunar_monitor_callback,
1012 data);
1013 }
1014 g_object_unref(pThunarMonitor);
1015 thunar_vfs_path_unref(pThunarPath);
1016
1017 if (pHandle == NULL)
1018 {
1019 cd_warning ("Attention : couldn't add monitor function to %s\n I will not be able to receive events about this file", cURI);
1020 g_free (data);
1021 }
1022 else
1023 {
1024 cd_message (">>> moniteur ajoute sur %s (%x)", cURI, user_data);
1025 data[2] = pHandle;
1026 g_hash_table_insert (s_fm_MonitorHandleTable, g_strdup (cURI), data);
1027 }
1028 }
1029
1030 void vfs_backend_remove_monitor (const gchar *cURI)
1031 {
1032 cd_message ("%s (%s)", __func__, cURI);
1033 if (cURI != NULL)
1034 {
1035 gpointer *data = g_hash_table_lookup(s_fm_MonitorHandleTable,cURI);
1036 if( data )
1037 {
1038 ThunarVfsMonitorHandle *pHandle = data[2];
1039 if( pHandle )
1040 {
1041 ThunarVfsMonitor *pThunarMonitor = thunar_vfs_monitor_get_default();
1042 thunar_vfs_monitor_remove(pThunarMonitor, pHandle);
1043 g_object_unref(pThunarMonitor);
1044 }
1045 }
1046
1047 cd_message (">>> moniteur supprime sur %s", cURI);
1048 g_hash_table_remove (s_fm_MonitorHandleTable, cURI);
1049
1050 if( strcmp( cURI, CAIRO_DOCK_FM_VFS_ROOT ) == 0 )
1051 {
1052 ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
1053 GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
1054 for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
1055 {
1056 ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
1057
1058 /* Skip the volumes that are not there or that are not removable */
1059 if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
1060 {
1061 pThunarVolume = NULL;
1062 continue;
1063 }
1064
1065 g_signal_handlers_disconnect_matched (pThunarVolume, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_changed_callback, NULL);
1066
1067 /// Debug.
1068 ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
1069 gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
1070 cd_debug (" signal retire sur %s", ltmp_path);
1071 g_free (ltmp_path);
1072 }
1073 }
1074 }
1075 }
1076
1077
1078 gboolean vfs_backend_delete_file (const gchar *cURI)
1079 {
1080 GError *erreur = NULL;
1081 cd_message ("%s (%s)", __func__, cURI);
1082
1083 /*ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
1084 if (erreur != NULL)
1085 {
1086 cd_warning ("Attention : %s", erreur->message);
1087 g_error_free (erreur);
1088 return FALSE;
1089 }
1090
1091 ThunarVfsJob *pJob = thunar_vfs_unlink_file(pThunarPath, &erreur);
1092 g_object_unref(pJob);
1093 thunar_vfs_path_unref(pThunarPath);*/
1094 gchar *cTrashPath = vfs_backend_get_trash_path (NULL, NULL);
1095 g_return_val_if_fail (cTrashPath != NULL, FALSE);
1096 vfs_backend_move_file (cURI, cTrashPath);
1097 g_free (cTrashPath);
1098
1099 return TRUE;
1100 }
1101
1102 gboolean vfs_backend_rename_file (const gchar *cOldURI, const gchar *cNewName)
1103 {
1104 GError *erreur = NULL;
1105 g_return_val_if_fail (cOldURI != NULL, FALSE);
1106 cd_message ("%s (%s)", __func__, cOldURI);
1107
1108 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cOldURI, &erreur);
1109 if (erreur != NULL)
1110 {
1111 cd_warning ("Attention : %s", erreur->message);
1112 g_error_free (erreur);
1113 return FALSE;
1114 }
1115 ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
1116 thunar_vfs_path_unref(pThunarPath);
1117 if (erreur != NULL)
1118 {
1119 cd_warning ("Attention : %s", erreur->message);
1120 g_error_free (erreur);
1121 return FALSE;
1122 }
1123
1124 thunar_vfs_info_rename(pThunarVfsInfo, cNewName, &erreur );
1125 thunar_vfs_info_unref(pThunarVfsInfo);
1126 if (erreur != NULL)
1127 {
1128 cd_warning ("Attention : %s", erreur->message);
1129 g_error_free (erreur);
1130 return FALSE;
1131 }
1132
1133 return TRUE;
1134 }
1135
1136 gboolean vfs_backend_move_file (const gchar *cURI, const gchar *cDirectoryURI)
1137 {
1138 /*
1139 @see thunar_vfs_move_file
1140 */
1141 GError *erreur = NULL;
1142 g_return_val_if_fail (cURI != NULL, FALSE);
1143 cd_message ("%s (%s, %s)", __func__, cURI, cDirectoryURI);
1144
1145 ThunarVfsPath *pThunarPathFrom = thunar_vfs_path_new(cURI, &erreur);
1146 if (erreur != NULL)
1147 {
1148 cd_warning ("Attention : %s", erreur->message);
1149 g_error_free (erreur);
1150 return FALSE;
1151 }
1152
1153 gchar *cDestURI = g_strdup_printf("%s/%s", cDirectoryURI, thunar_vfs_path_get_name(pThunarPathFrom));
1154 ThunarVfsPath *pThunarPathTo = thunar_vfs_path_new(cDestURI, &erreur);
1155 g_free(cDestURI);
1156 if (erreur != NULL)
1157 {
1158 thunar_vfs_path_unref(pThunarPathFrom);
1159 cd_warning ("Attention : %s", erreur->message);
1160 g_error_free (erreur);
1161 return FALSE;
1162 }
1163
1164 ThunarVfsJob *pJob = thunar_vfs_move_file(pThunarPathFrom, pThunarPathTo, &erreur);
1165
1166 thunar_vfs_path_unref(pThunarPathFrom);
1167 thunar_vfs_path_unref(pThunarPathTo);
1168
1169 if (erreur != NULL)
1170 {
1171 cd_warning ("Attention : %s", erreur->message);
1172 g_error_free (erreur);
1173 return FALSE;
1174 }
1175
1176 g_object_unref(pJob);
1177 return TRUE;
1178 }
1179
1180 void vfs_backend_get_file_properties (const gchar *cURI, guint64 *iSize, time_t *iLastModificationTime, gchar **cMimeType, int *iUID, int *iGID, int *iPermissionsMask)
1181 {
1182 GError *erreur = NULL;
1183 g_return_if_fail (cURI != NULL);
1184 cd_message ("%s (%s)", __func__, cURI);
1185
1186 ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
1187 if (erreur != NULL)
1188 {
1189 cd_warning ("Attention : %s", erreur->message);
1190 g_error_free (erreur);
1191 return;
1192 }
1193 ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
1194 thunar_vfs_path_unref(pThunarPath);
1195 if (erreur != NULL)
1196 {
1197 cd_warning ("Attention : %s", erreur->message);
1198 g_error_free (erreur);
1199 return;
1200 }
1201
1202 *iSize = pThunarVfsInfo->size;
1203 *iLastModificationTime = pThunarVfsInfo->mtime;
1204 *cMimeType = g_strdup (thunar_vfs_mime_info_get_name(pThunarVfsInfo->mime_info));
1205 *iUID = pThunarVfsInfo->uid;
1206 *iGID = pThunarVfsInfo->gid;
1207 *iPermissionsMask = pThunarVfsInfo->mode;
1208
1209 thunar_vfs_info_unref(pThunarVfsInfo);
1210 }
1211
1212
1213 gchar *vfs_backend_get_trash_path (const gchar *cNearURI, gchar **cFileInfoPath)
1214 {
1215 GError *erreur = NULL;
1216 cd_message ("%s (%s)", __func__, cNearURI);
1217
1218 ThunarVfsPath *pThunarPath = thunar_vfs_path_new("trash:/", &erreur);
1219 if (erreur != NULL)
1220 {
1221 cd_warning ("Attention : %s", erreur->message);
1222 g_error_free (erreur);
1223 return NULL;
1224 }
1225 thunar_vfs_path_unref(pThunarPath);
1226
1227 /*
1228 * If we haven't returned NULL yet, it means that there exist a valid trash.
1229 * We know that Thunar follows the XDG recommendations.
1230 * So the trash is in ~/.local/share/Trash
1231 */
1232
1233 gchar *trashPath = NULL;
1234 char *home = getenv("HOME");
1235 if( home )
1236 {
1237 trashPath = g_strdup_printf("%s/%s", home, ".local/share/Trash/files");
1238 if (cFileInfoPath != NULL)
1239 *cFileInfoPath = g_strdup_printf ("%s/.local/share/Trash/info", home);
1240 }
1241
1242 return trashPath;
1243 }
1244
1245 gchar *vfs_backend_get_desktop_path (void)
1246 {
1247 GError *erreur = NULL;
1248 cd_message ("");
1249
1250 ThunarVfsPath *pThunarDesktopPath = thunar_vfs_path_new("desktop:/", &erreur);
1251 if (erreur != NULL)
1252 {
1253 cd_warning ("Attention : %s", erreur->message);
1254 g_error_free (erreur);
1255 return NULL;
1256 }
1257 thunar_vfs_path_unref(pThunarDesktopPath);
1258
1259 /*
1260 * If we haven't returned NULL yet, it means that there exist a valid desktop.
1261 * We know that Thunar follows the XDG recommendations.
1262 * So the trash is in ~/Desktop
1263 */
1264
1265 gchar *desktopPath = NULL;
1266 char *home = getenv("HOME");
1267 if( home )
1268 {
1269 desktopPath = g_strdup_printf("%s/%s", home, "Desktop");
1270 }
1271
1272 return desktopPath;
1273 }
1274
1275 #endif