2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Christophe Chapuis (for any bug report, please mail me to chris.chapuis@gmail.com)
26
Inspiration was taken from the "gnome-integration" plug-in...
28
******************************************************************************/
31
#include <thunar-vfs/thunar-vfs.h>
33
#include "applet-thunar-vfs.h"
35
static GHashTable *s_fm_MonitorHandleTable = NULL;
37
static void _vfs_backend_volume_added_callback (ThunarVfsVolumeManager *manager, gpointer volumes, gpointer *data);
38
static void _vfs_backend_volume_removed_callback (ThunarVfsVolumeManager *manager, gpointer volumes, gpointer *data);
39
///static void _vfs_backend_volume_modified_callback (ThunarVfsVolumeManager *manager, ThunarVfsVolume *pVolume, gpointer *data);
40
static ThunarVfsVolume *thunar_find_volume_from_path (ThunarVfsPath *pThunarPath);
42
static void _vfs_backend_free_monitor_data (gpointer *data)
46
ThunarVfsMonitor *pMonitor = thunar_vfs_monitor_get_default();
47
ThunarVfsMonitorHandle *pHandle = data[2];
48
thunar_vfs_monitor_remove(pMonitor, pHandle); // le ThunarVFSMonitorHandle est-il libere lors du thunar_vfs_monitor_remove () ?
53
gboolean init_vfs_backend (void)
55
cd_message ("Initialisation du backend xfce-environnement");
57
if (s_fm_MonitorHandleTable != NULL)
58
g_hash_table_destroy (s_fm_MonitorHandleTable);
60
s_fm_MonitorHandleTable = g_hash_table_new_full (g_str_hash,
63
(GDestroyNotify) _vfs_backend_free_monitor_data);
70
void stop_vfs_backend (void)
72
cd_message ("Arret du backend xfce-environnement");
74
if (s_fm_MonitorHandleTable != NULL)
76
g_hash_table_destroy (s_fm_MonitorHandleTable);
77
s_fm_MonitorHandleTable = NULL;
80
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
81
g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_added_callback, NULL);
82
g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_removed_callback, NULL);
83
///g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_modified_callback, NULL);
85
thunar_vfs_shutdown();
90
static gboolean file_manager_get_file_info_from_desktop_link (const gchar *cBaseURI, gchar **cName, gchar **cURI, gchar **cIconName, gboolean *bIsDirectory, int *iVolumeID)
92
cd_message ("%s (%s)", __func__, cBaseURI);
93
GError *erreur = NULL;
95
gchar *cFileData = NULL;
98
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cBaseURI, &erreur);
101
cd_warning ("Attention : couldn't read %s (%s)", cBaseURI, erreur->message);
102
g_error_free (erreur);
105
gchar *cFilePath = thunar_vfs_path_dup_string(pThunarPath);
106
thunar_vfs_path_unref(pThunarPath);
107
if (cFilePath == NULL)
109
cd_warning ("Attention : Couldn't retrieve path of %s", cBaseURI);
113
GKeyFile *pKeyFile = g_key_file_new ();
114
g_key_file_load_from_file (pKeyFile,
116
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
121
cd_warning ("Attention : %s", erreur->message);
122
g_error_free (erreur);
126
gchar *cType = g_key_file_get_value (pKeyFile, "Desktop Entry", "Type", NULL);
127
//g_print (" cType : %s\n", cType);
128
if (strncmp (cType, "Link", 4) != 0 && strncmp (cType, "FSDevice", 8) != 0)
131
g_key_file_free (pKeyFile);
136
*cName = g_key_file_get_string (pKeyFile, "Desktop Entry", "Name", NULL);
138
*cURI = g_key_file_get_string (pKeyFile, "Desktop Entry", "URL", NULL);
140
*cIconName = g_key_file_get_string (pKeyFile, "Desktop Entry", "Icon", NULL);
142
*iVolumeID = g_key_file_get_integer (pKeyFile, "Desktop Entry", "X-Gnome-Drive", NULL);
144
*bIsDirectory = TRUE;
146
g_key_file_free (pKeyFile);
150
void vfs_backend_get_file_info (const gchar *cBaseURI, gchar **cName, gchar **cURI, gchar **cIconName, gboolean *bIsDirectory, int *iVolumeID, double *fOrder, CairoDockFMSortType iSortType)
152
GError *erreur = NULL;
153
g_return_if_fail (cBaseURI != NULL);
154
cd_message ("%s (%s)", __func__, cBaseURI);
156
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cBaseURI, &erreur);
159
cd_warning ("Attention : couldn't read %s (%s)", cBaseURI, erreur->message);
160
g_error_free (erreur);
164
// distinguer les mounts points du reste
165
ThunarVfsVolume *pThunarVolume = thunar_find_volume_from_path (pThunarPath);
166
if (pThunarVolume != NULL)
167
cd_message (" correspond a un volume");
169
ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
170
thunar_vfs_path_unref(pThunarPath);
173
/* Si on a trouve un volume, le chemin peut ne pas exister et donc cette erreur peut etre acceptable */
174
if (pThunarVolume == NULL)
176
cd_warning ("Attention : %s", erreur->message);
177
g_error_free (erreur);
178
thunar_vfs_info_unref(pThunarVfsInfo);
181
g_error_free (erreur);
188
if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
189
*fOrder = (double)pThunarVfsInfo->mtime;
190
else if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
191
*fOrder = (double)pThunarVfsInfo->size;
192
else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
193
*fOrder = (double)pThunarVfsInfo->type;
196
*cURI = g_strdup (cBaseURI);
200
*cName = g_strdup(thunar_vfs_volume_get_name( pThunarVolume ));
202
*bIsDirectory = FALSE;
203
*cIconName = g_strdup(thunar_vfs_volume_lookup_icon_name(pThunarVolume, gtk_icon_theme_get_default()));
205
else if( pThunarVfsInfo )
207
*cName = g_strdup (pThunarVfsInfo->display_name);
209
*bIsDirectory = ((pThunarVfsInfo->type & THUNAR_VFS_FILE_TYPE_DIRECTORY) != 0);
210
*cIconName = pThunarVfsInfo->custom_icon?g_strdup(pThunarVfsInfo->custom_icon):NULL;
212
ThunarVfsMimeInfo*pThunarMimeInfo = pThunarVfsInfo->mime_info;
213
if( pThunarMimeInfo )
215
const gchar *cMimeType = thunar_vfs_mime_info_get_name (pThunarMimeInfo);
216
cd_message (" cMimeType : %s", cMimeType);
217
if ( *cIconName == NULL && cMimeType && strcmp (cMimeType, "application/x-desktop") == 0)
219
thunar_vfs_info_unref(pThunarVfsInfo);
220
thunar_vfs_mime_info_unref( pThunarMimeInfo );
221
file_manager_get_file_info_from_desktop_link (cBaseURI, cName, cURI, cIconName, bIsDirectory, iVolumeID);
226
/*On verra un peu plus tard pour les vignettes des images, hein*/
227
if(*cIconName == NULL && (strncmp (cMimeType, "image", 5) == 0))
229
gchar *cHostname = NULL;
230
gchar *cFilePath = g_filename_from_uri (cBaseURI, &cHostname, &erreur);
233
g_error_free (erreur);
235
else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux.
237
*cIconName = thunar_vfs_path_dup_string(pThunarPath);
238
cairo_dock_remove_html_spaces (*cIconName);
243
if (*cIconName == NULL)
245
*cIconName = g_strdup (thunar_vfs_mime_info_lookup_icon_name(pThunarMimeInfo, gtk_icon_theme_get_default()));
252
thunar_vfs_info_unref(pThunarVfsInfo);
257
struct ThunarFolder_t {
260
gboolean isJobFinished;
263
typedef struct ThunarFolder_t ThunarFolder;
265
static gboolean thunar_folder_infos_ready (ThunarVfsJob *job,
267
ThunarFolder *folder)
269
/* merge the list with the existing list of new files */
270
folder->file_list = g_list_concat (folder->file_list, infos);
272
/* TRUE to indicate that we took over ownership of the infos list */
276
static void thunar_folder_finished (ThunarVfsJob *job, ThunarFolder *folder)
278
/* we did it, the folder is loaded */
279
g_signal_handlers_disconnect_matched (folder->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, folder);
280
g_object_unref (G_OBJECT (folder->job));
282
folder->isJobFinished = TRUE;
286
* Attention: si l'URI demandee est CAIRO_DOCK_FM_VFS_ROOT, alors il faut retourner la liste des volumes !
287
* En effet dans ThunarVFS "root://" correspond simplement Ć "/"
289
GList *vfs_backend_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsType, gboolean bListHiddenFiles, gchar **cFullURI)
291
GError *erreur = NULL;
292
g_return_val_if_fail (cBaseURI != NULL, NULL);
293
cd_message ("%s (%s)", __func__, cBaseURI);
295
GList *pIconList = NULL;
297
const gchar *cURI = NULL;
298
if (strcmp (cBaseURI, CAIRO_DOCK_FM_VFS_ROOT) == 0)
300
cURI = CAIRO_DOCK_FM_VFS_ROOT;
304
*cFullURI = g_strdup(cURI);
307
/* listons joyeusement les volumes */
308
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
309
const GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
310
int lVolumeFakeID = 1;
312
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next, lVolumeFakeID++ )
314
ThunarVfsVolume *pThunarVfsVolume = (ThunarVfsVolume *)pListVolumes->data;
316
/* Skip the volumes that are not there or that are not removable */
317
if (!thunar_vfs_volume_is_present (pThunarVfsVolume) || !thunar_vfs_volume_is_removable (pThunarVfsVolume))
320
ThunarVfsPath *pThunarVfsPath = thunar_vfs_volume_get_mount_point(pThunarVfsVolume);
321
Icon *icon = g_new0 (Icon, 1);
323
/* il nous faut: URI, type, nom, icone */
325
icon->cBaseURI = thunar_vfs_path_dup_uri(pThunarVfsPath);
326
cd_debug ("mount point : %s", icon->cBaseURI);
328
icon->acCommand = thunar_vfs_path_dup_uri(pThunarVfsPath);
329
icon->iVolumeID = lVolumeFakeID;
331
cd_message (" -> icon->cBaseURI : %s", icon->cBaseURI);
333
icon->iType = iNewIconsType;
335
icon->acName = g_strdup(thunar_vfs_volume_get_name( pThunarVfsVolume ));
336
cd_debug (" -> icon->acName : %s", icon->acName);
338
icon->acFileName = g_strdup(thunar_vfs_volume_lookup_icon_name(pThunarVfsVolume, gtk_icon_theme_get_default()));
339
cd_debug (" -> icon->acFileName : %s", icon->acFileName);
342
ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarVfsPath, &erreur);
346
cd_warning ("Attention : %s", erreur->message);
347
g_error_free (erreur);
351
if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
352
icon->fOrder = pThunarVfsInfo->size;
353
else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
354
icon->fOrder = pThunarVfsInfo->mtime;
355
else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
356
icon->fOrder = pThunarVfsInfo->type;
358
thunar_vfs_info_unref(pThunarVfsInfo);
361
pIconList = g_list_prepend (pIconList, icon);
366
else if (strcmp (cBaseURI, CAIRO_DOCK_FM_NETWORK) == 0)
368
cd_message (" -> Good try, but no, there's no network management in Thunar VFS !");
371
*cFullURI = g_strdup(CAIRO_DOCK_FM_NETWORK);
379
*cFullURI = g_strdup(cURI);
380
g_return_val_if_fail (cURI != NULL, NULL);
382
cd_message (" -> cURI : %s", cURI);
384
ThunarFolder *folder = g_new( ThunarFolder, 1 );
385
folder->isJobFinished = FALSE;
386
folder->file_list = NULL;
388
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
391
cd_warning ("couldn't read %s (%s)", cURI, erreur->message);
392
g_error_free (erreur);
395
folder->job = thunar_vfs_listdir(pThunarPath, NULL);
396
thunar_vfs_path_unref(pThunarPath);
398
g_signal_connect (folder->job, "error", G_CALLBACK (thunar_folder_finished), folder);
399
g_signal_connect (folder->job, "finished", G_CALLBACK (thunar_folder_finished), folder);
400
g_signal_connect (folder->job, "infos-ready", G_CALLBACK (thunar_folder_infos_ready), folder);
402
while ( !folder->isJobFinished )
404
if (gtk_events_pending())
406
gtk_main_iteration(); // Handle unprocessed GTK events
410
g_thread_yield(); // Yield processing time
414
/* Ć joie, on a une liste de ThunarVfsInfos ! */
416
for (lp = folder->file_list; lp != NULL; lp = lp->next)
418
/* get the info... */
419
ThunarVfsInfo *pThunarVfsInfo = (ThunarVfsInfo *)(lp->data);
423
if(pThunarVfsInfo != NULL &&
424
strcmp (thunar_vfs_path_get_name(pThunarVfsInfo->path), ".") != 0 &&
425
strcmp (thunar_vfs_path_get_name(pThunarVfsInfo->path), "..") != 0)
427
icon = g_new0 (Icon, 1);
428
icon->cBaseURI = thunar_vfs_path_dup_uri(pThunarVfsInfo->path);
429
cd_message (" item in directory : %s", icon->cBaseURI);
430
icon->iType = iNewIconsType;
431
if ( strcmp (thunar_vfs_mime_info_get_name(pThunarVfsInfo->mime_info), "application/x-desktop") == 0)
433
gboolean bIsDirectory = FALSE;
434
file_manager_get_file_info_from_desktop_link (icon->cBaseURI, &icon->acName, &icon->acCommand, &icon->acFileName, &bIsDirectory, &icon->iVolumeID);
435
cd_message (" bIsDirectory : %d; iVolumeID : %d", bIsDirectory, icon->iVolumeID);
439
icon->acCommand = g_strdup(icon->cBaseURI);
440
icon->acName = g_strdup (thunar_vfs_path_get_name(pThunarVfsInfo->path));
441
icon->acFileName = NULL;
442
if (strncmp (thunar_vfs_mime_info_get_name(pThunarVfsInfo->mime_info), "image", 5) == 0) // && strncmp (cFileURI, "file://", 7) == 0
444
gchar *cHostname = NULL;
445
GError *erreur = NULL;
446
gchar *cFilePath = g_filename_from_uri (icon->cBaseURI, &cHostname, &erreur);
449
g_error_free (erreur);
452
else if (cHostname == NULL || strcmp (cHostname, "localhost") == 0) // on ne recupere la vignette que sur les fichiers locaux.
454
icon->acFileName = g_strdup (cFilePath);
455
cairo_dock_remove_html_spaces (icon->acFileName);
459
if (icon->acFileName == NULL)
461
icon->acFileName = g_strdup(thunar_vfs_mime_info_lookup_icon_name(pThunarVfsInfo->mime_info, gtk_icon_theme_get_default()));
465
if (iSortType == CAIRO_DOCK_FM_SORT_BY_SIZE)
466
icon->fOrder = pThunarVfsInfo->size;
467
else if (iSortType == CAIRO_DOCK_FM_SORT_BY_DATE)
468
icon->fOrder = pThunarVfsInfo->mtime;
469
else if (iSortType == CAIRO_DOCK_FM_SORT_BY_TYPE)
470
icon->fOrder = pThunarVfsInfo->type;
472
pIconList = g_list_prepend (pIconList, icon);
475
/* ...release the info at the list position... */
476
thunar_vfs_info_unref (lp->data);
479
if (iSortType == CAIRO_DOCK_FM_SORT_BY_NAME)
480
pIconList = cairo_dock_sort_icons_by_name (pIconList);
482
pIconList = cairo_dock_sort_icons_by_order (pIconList);
487
ThunarVfsVolume *thunar_find_volume_from_path (ThunarVfsPath *pThunarPath)
489
GError *erreur = NULL;
490
gchar *ltmp_path = NULL;
492
ThunarVfsVolume *pThunarVolume = NULL;
494
/* premiere methode: on scanne les volumes. c'est peut-etre un volume non monte... */
495
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
496
GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
497
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
499
pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
500
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
501
ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
504
cd_debug (" - %s", ltmp_path);
508
/* Skip the volumes that are not there or that are not removable */
509
if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
511
pThunarVolume = NULL;
517
if( thunar_vfs_path_equal(pThunarPath, pMountPointVfsPath) ) // || thunar_vfs_path_is_ancestor( pThunarPath, pMountPointVfsPath )
519
cd_debug (" trouve !");
522
pThunarVolume = NULL;
525
/* if( pThunarVolume == NULL )
527
// deuxieme methode: avec le vfs_info.
528
ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
531
cd_warning ("Attention : %s", erreur->message);
532
g_error_free (erreur);
536
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
537
pThunarVolume = thunar_vfs_volume_manager_get_volume_by_info(pThunarVolumeManager, pThunarVfsInfo);
538
g_object_unref(pThunarVolumeManager);
539
thunar_vfs_info_unref(pThunarVfsInfo);
540
g_print ("2eme methode -> volume : %x\n", pThunarVolume);
542
// Skip the volumes that are not there or that are not removable
543
if (pThunarVolume == NULL || !thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
545
pThunarVolume = NULL;
550
return pThunarVolume;
554
void vfs_backend_launch_uri (const gchar *cURI)
556
GError *erreur = NULL;
557
g_return_if_fail (cURI != NULL);
558
cd_message ("%s (%s)", __func__, cURI);
560
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
563
cd_warning ("Attention : couldn't read %s (%s)", cURI, erreur->message);
564
g_error_free (erreur);
568
ThunarVfsPath *pThunarRealPath = NULL;
570
/* hop, trouvons le volume correspondant */
571
ThunarVfsVolume *pThunarVolume = thunar_find_volume_from_path(pThunarPath);
572
if (pThunarVolume != NULL)
574
thunar_vfs_path_unref(pThunarPath);
575
pThunarPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
578
ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
581
cd_warning ("Attention : %s", erreur->message);
582
g_error_free (erreur);
586
/* if this is a directory, open Thunar in that directory */
587
if( pThunarVfsInfo->flags & THUNAR_VFS_FILE_FLAGS_EXECUTABLE )
589
thunar_vfs_info_execute(pThunarVfsInfo,NULL,NULL, NULL,&erreur);
592
cd_warning ("Attention : %s", erreur->message);
593
g_error_free (erreur);
598
ThunarVfsMimeDatabase *pMimeDB = thunar_vfs_mime_database_get_default();
601
ThunarVfsMimeApplication *pMimeApplication = thunar_vfs_mime_database_get_default_application(pMimeDB, pThunarVfsInfo->mime_info);
602
if( pMimeApplication )
604
GList *path_list = g_list_prepend (NULL, pThunarPath);
605
cd_message ("Launching %s ...", thunar_vfs_mime_handler_get_command(pMimeApplication) );
606
thunar_vfs_mime_handler_exec(pMimeApplication,gdk_screen_get_default (),path_list,&erreur);
607
g_list_free(path_list);
608
g_object_unref( pMimeApplication );
611
cd_warning ("Attention : %s", erreur->message);
612
g_error_free (erreur);
615
g_object_unref( pMimeDB );
619
thunar_vfs_info_unref(pThunarVfsInfo);
623
gchar *vfs_backend_is_mounted (const gchar *cURI, gboolean *bIsMounted)
625
GError *erreur = NULL;
626
cd_message ("%s (%s)", __func__, cURI);
628
ThunarVfsVolume *pThunarVolume = NULL;
630
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
633
cd_warning ("ERROR : %s", erreur->message);
634
g_error_free (erreur);
638
/* hop, trouvons le volume correspondant */
639
pThunarVolume = thunar_find_volume_from_path(pThunarPath);
640
thunar_vfs_path_unref(pThunarPath);
642
if (pThunarVolume == NULL)
644
cd_warning ("Attention : no volume associated to %s, we'll assume that it is not mounted", cURI);
649
*bIsMounted = thunar_vfs_volume_is_mounted(pThunarVolume);
650
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
651
gchar *cMountPointID = pMountPointVfsPath?thunar_vfs_path_dup_uri(pMountPointVfsPath):NULL;
653
cd_message (" bIsMounted <- %d", *bIsMounted);
655
return cMountPointID;
659
static void _vfs_backend_mount_callback(ThunarVfsVolume *volume, gpointer *data)
661
cd_message ("%s (%x)", __func__, data);
664
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
665
GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
666
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
668
ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
669
/* Skip the volumes that are not there or that are not removable */
670
if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
672
pThunarVolume = NULL;
675
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
676
gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
677
cd_debug (" + %s", ltmp_path);
680
CairoDockFMMountCallback pCallback = data[0];
681
pCallback (GPOINTER_TO_INT (data[1]), TRUE, data[2], data[3], data[4]);
683
/*static void _vfs_backend_change_callback(ThunarVfsVolume *volume, gpointer *data)
685
cd_message ("%s (%x)", __func__, data);
686
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
687
GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
688
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
690
ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
692
// Skip the volumes that are not there or that are not removable
693
if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
695
pThunarVolume = NULL;
699
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
700
gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
701
cd_debug (" + %s", ltmp_path);
703
CairoDockFMMountCallback pCallback = data[0];
705
pCallback (GPOINTER_TO_INT (data[1]), TRUE, data[2], data[3], data[4]);
708
void vfs_backend_mount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, CairoContainer *pContainer)
710
GError *erreur = NULL;
711
g_return_if_fail (cURI != NULL);
712
cd_message ("%s (%s)", __func__, cURI);
714
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
717
cd_warning ("Attention : couldn't read %s (%s)", cURI, erreur->message);
718
g_error_free (erreur);
721
/* hop, trouvons le volume correspondant */
722
ThunarVfsVolume *pThunarVolume = thunar_find_volume_from_path(pThunarPath);
723
thunar_vfs_path_unref(pThunarPath);
725
if (pThunarVolume == NULL)
727
cd_warning ("Attention : no volume associated to %s", cURI);
731
gpointer *data2 = g_new (gpointer, 5);
732
data2[0] = pCallback;
733
data2[1] = GINT_TO_POINTER (TRUE);
734
data2[2] = thunar_vfs_volume_get_name(pThunarVolume);
736
data2[4] = pContainer;
737
g_signal_connect(pThunarVolume, "mounted", G_CALLBACK (_vfs_backend_mount_callback), data2);
739
if( !thunar_vfs_volume_mount(pThunarVolume, NULL, &erreur) )
741
cd_warning ("Attention, %s couldn't be mounted : %s",cURI, erreur->message);
742
g_error_free (erreur);
744
g_signal_handlers_disconnect_matched (pThunarVolume, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data2);
748
void vfs_backend_unmount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, CairoContainer *pContainer)
750
GError *erreur = NULL;
751
g_return_if_fail (cURI != NULL);
752
cd_message ("%s (%s)", __func__, cURI);
754
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
757
cd_message ("Attention : couldn't read %s (%s)", cURI, erreur->message);
758
g_error_free (erreur);
761
/* hop, trouvons le volume correspondant */
762
ThunarVfsVolume *pThunarVolume = thunar_find_volume_from_path(pThunarPath);
763
thunar_vfs_path_unref(pThunarPath);
765
if (pThunarVolume == NULL)
767
cd_warning ("Attention : no volume associated to %s", cURI);
771
gpointer *data2 = g_new (gpointer, 5);
772
data2[0] = pCallback;
773
data2[1] = GINT_TO_POINTER (FALSE);
774
data2[2] = thunar_vfs_volume_get_name(pThunarVolume);
776
data2[4] = pContainer;
777
g_signal_connect(pThunarVolume, "unmounted", G_CALLBACK (_vfs_backend_mount_callback), data2);
779
if( !thunar_vfs_volume_unmount(pThunarVolume, NULL, &erreur) )
781
cd_message ("Attention, %s couldn't be unmounted : %s\n",cURI, erreur->message);
782
g_error_free (erreur);
784
cd_debug ("demontage fini");
785
g_signal_handlers_disconnect_matched (pThunarVolume, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, data2);
789
static void _vfs_backend_volume_added_callback (ThunarVfsVolumeManager *manager,
793
CairoDockFMMonitorCallback pCallback = data[0];
794
gpointer user_data = data[1];
797
/* call the callback for each volume */
798
GList *pListVolumes = volumes;
799
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
801
ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
803
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
804
gchar *info_uri = thunar_vfs_path_dup_uri(pMountPointVfsPath);
806
pCallback (CAIRO_DOCK_FILE_CREATED, info_uri, user_data);
811
static void _vfs_backend_volume_removed_callback (ThunarVfsVolumeManager *manager,
815
CairoDockFMMonitorCallback pCallback = data[0];
816
gpointer user_data = data[1];
819
/* call the callback for each volume */
820
GList *pListVolumes = volumes;
821
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
823
ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
825
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
826
gchar *info_uri = thunar_vfs_path_dup_uri(pMountPointVfsPath);
828
pCallback (CAIRO_DOCK_FILE_DELETED, info_uri, user_data);
833
/*void _vfs_backend_volume_modified_callback (ThunarVfsVolumeManager *manager, ThunarVfsVolume *pVolume, gpointer *data)
835
CairoDockFMMonitorCallback pCallback = data[0];
836
gpointer user_data = data[1];
838
/// 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 ...
840
gboolean bMounted = thunar_vfs_volume_is_mounted(pVolume);
841
if (bMounted) // on vient de le monter. avant c'etait /dev/sdb1, maintenant c'est /media/disk
843
const gchar* cName = thunar_vfs_volume_get_name (pVolume);
844
cd_debug ("volume to remove : %s", cName);
845
pCallback (CAIRO_DOCK_FILE_DELETED, cName, user_data);
847
const ThunarVfsPath *pMountPoint = thunar_vfs_volume_get_mount_point (pVolume);
848
gchar *cUri = thunar_vfs_path_dup_uri (pMountPoint);
849
cd_debug ("new mount point : %s", cUri);
850
pCallback (CAIRO_DOCK_FILE_CREATED, cUri, user_data);
853
else // on vient de le demonter, avant c'etait /media/disk, mais maintenant aussi !
855
const ThunarVfsPath *pMountPoint = thunar_vfs_volume_get_mount_point (pVolume);
856
gchar *cUri = thunar_vfs_path_dup_uri (pMountPoint);
857
cd_debug ("mount point : %s", cUri);
860
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
861
GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
862
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
864
ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
866
// Skip the volumes that are not there or that are not removable.
867
if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
869
pThunarVolume = NULL;
873
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
874
gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
875
cd_debug (" + %s", ltmp_path);
878
pCallback (CAIRO_DOCK_FILE_MODIFIED, cUri, user_data);
884
static void _vfs_backend_thunar_monitor_callback(ThunarVfsMonitor *monitor,
885
ThunarVfsMonitorHandle *handle,
886
ThunarVfsMonitorEvent event,
887
ThunarVfsPath *handle_path,
888
ThunarVfsPath *event_path,
891
CairoDockFMMonitorCallback pCallback = data[0];
892
gpointer user_data = data[1];
893
cd_message ("%s (%d , data : %x)", __func__, event, user_data);
895
CairoDockFMEventType iEventType;
898
case THUNAR_VFS_MONITOR_EVENT_CHANGED :
899
iEventType = CAIRO_DOCK_FILE_MODIFIED;
902
case THUNAR_VFS_MONITOR_EVENT_DELETED :
903
iEventType = CAIRO_DOCK_FILE_DELETED;
906
case THUNAR_VFS_MONITOR_EVENT_CREATED :
907
iEventType = CAIRO_DOCK_FILE_CREATED;
913
gchar *info_uri = thunar_vfs_path_dup_uri(event_path);
914
pCallback (iEventType, info_uri, user_data);
917
static void _vfs_backend_volume_changed_callback (ThunarVfsVolume *pThunarVolume, gpointer *data)
919
CairoDockFMMonitorCallback pCallback = data[0];
920
gpointer user_data = data[1];
921
gchar *cUri = data[2];
922
cd_debug ("%x - %x - %x", data[0], data[1], data[2]);
923
g_return_if_fail (cUri != NULL);
924
cd_message (" >>> %s (%s)", __func__, cUri);
926
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
927
gchar *cNewUri = thunar_vfs_path_dup_uri(pMountPointVfsPath);
928
if (strcmp (cNewUri, cUri) != 0)
930
cd_message (" ce volume devient : %s", cNewUri);
932
pCallback (CAIRO_DOCK_FILE_DELETED, cUri, user_data);
934
pCallback (CAIRO_DOCK_FILE_CREATED, cNewUri, user_data);
943
void vfs_backend_add_monitor (const gchar *cURI, gboolean bDirectory, CairoDockFMMonitorCallback pCallback, gpointer user_data)
945
GError *erreur = NULL;
946
g_return_if_fail (cURI != NULL);
947
cd_message ("%s (%s)", __func__, cURI);
949
// faire un gros cas particulier pour CAIRO_DOCK_FM_VFS_ROOT, qui est retournƩ lors du listing dudit rƩpertoire
950
if( strcmp( cURI, CAIRO_DOCK_FM_VFS_ROOT ) == 0 )
952
// se brancher sur les signaux "volumes-added" et "volumes-removed" du volume manager
953
gpointer *data = g_new0 (gpointer, 2);
957
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
958
// on nettoie d'abord, au cas ou
959
g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_added_callback, NULL);
960
g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_removed_callback, NULL);
961
///g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_modified_callback, NULL);
962
///g_signal_handlers_disconnect_matched (pThunarVolumeManager, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_modified_callback, NULL);
963
// puis on se branche
964
g_signal_connect(pThunarVolumeManager, "volumes-added", G_CALLBACK (_vfs_backend_volume_added_callback), data);
965
g_signal_connect(pThunarVolumeManager, "volumes-removed", G_CALLBACK (_vfs_backend_volume_removed_callback), data);
966
///g_signal_connect(pThunarVolumeManager, "volume-mounted", G_CALLBACK (_vfs_backend_volume_modified_callback), data);
967
///g_signal_connect(pThunarVolumeManager, "volume-unmounted", G_CALLBACK (_vfs_backend_volume_modified_callback), data);
969
//\____________ 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 !
970
GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
971
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
973
ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
975
/* Skip the volumes that are not there or that are not removable */
976
if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
978
pThunarVolume = NULL;
982
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
983
gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
984
cd_debug (" signal ajoute sur %s", ltmp_path);
985
gpointer *data2 = g_new0 (gpointer, 3);
986
data2[0] = pCallback;
987
data2[1] = user_data;
988
data2[2] = ltmp_path;
989
g_signal_connect(pThunarVolume, "changed", G_CALLBACK (_vfs_backend_volume_changed_callback), data2);
990
cd_debug ("%x - %x - %x", data2[0], data2[1], data2[2]);
995
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
998
cd_warning ("Attention : %s", erreur->message);
999
g_error_free (erreur);
1003
ThunarVfsMonitor *pThunarMonitor = thunar_vfs_monitor_get_default();
1004
ThunarVfsMonitorHandle *pHandle = NULL;
1005
gpointer *data = g_new0 (gpointer, 3);
1006
data[0] = pCallback;
1007
data[1] = user_data;
1011
pHandle = thunar_vfs_monitor_add_directory(pThunarMonitor, pThunarPath,
1012
(ThunarVfsMonitorCallback) _vfs_backend_thunar_monitor_callback,
1017
pHandle = thunar_vfs_monitor_add_file(pThunarMonitor, pThunarPath,
1018
(ThunarVfsMonitorCallback) _vfs_backend_thunar_monitor_callback,
1021
g_object_unref(pThunarMonitor);
1022
thunar_vfs_path_unref(pThunarPath);
1024
if (pHandle == NULL)
1026
cd_warning ("Attention : couldn't add monitor function to %s\n I will not be able to receive events about this file", cURI);
1031
cd_message (">>> moniteur ajoute sur %s (%x)", cURI, user_data);
1033
g_hash_table_insert (s_fm_MonitorHandleTable, g_strdup (cURI), data);
1037
void vfs_backend_remove_monitor (const gchar *cURI)
1039
cd_message ("%s (%s)", __func__, cURI);
1042
gpointer *data = g_hash_table_lookup(s_fm_MonitorHandleTable,cURI);
1045
ThunarVfsMonitorHandle *pHandle = data[2];
1048
ThunarVfsMonitor *pThunarMonitor = thunar_vfs_monitor_get_default();
1049
thunar_vfs_monitor_remove(pThunarMonitor, pHandle);
1050
g_object_unref(pThunarMonitor);
1054
cd_message (">>> moniteur supprime sur %s", cURI);
1055
g_hash_table_remove (s_fm_MonitorHandleTable, cURI);
1057
if( strcmp( cURI, CAIRO_DOCK_FM_VFS_ROOT ) == 0 )
1059
ThunarVfsVolumeManager *pThunarVolumeManager = thunar_vfs_volume_manager_get_default();
1060
GList *pListVolumes = thunar_vfs_volume_manager_get_volumes(pThunarVolumeManager);
1061
for( ; pListVolumes != NULL; pListVolumes = pListVolumes->next )
1063
ThunarVfsVolume *pThunarVolume = (ThunarVfsVolume *)pListVolumes->data;
1065
/* Skip the volumes that are not there or that are not removable */
1066
if (!thunar_vfs_volume_is_present (pThunarVolume) || !thunar_vfs_volume_is_removable (pThunarVolume))
1068
pThunarVolume = NULL;
1072
g_signal_handlers_disconnect_matched (pThunarVolume, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, _vfs_backend_volume_changed_callback, NULL);
1075
ThunarVfsPath *pMountPointVfsPath = thunar_vfs_volume_get_mount_point(pThunarVolume);
1076
gchar *ltmp_path = thunar_vfs_path_dup_uri(pMountPointVfsPath);
1077
cd_debug (" signal retire sur %s", ltmp_path);
1085
gboolean vfs_backend_delete_file (const gchar *cURI)
1087
GError *erreur = NULL;
1088
cd_message ("%s (%s)", __func__, cURI);
1090
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
1093
cd_warning ("Attention : %s", erreur->message);
1094
g_error_free (erreur);
1098
ThunarVfsJob *pJob = thunar_vfs_unlink_file(pThunarPath, &erreur);
1099
g_object_unref(pJob);
1101
thunar_vfs_path_unref(pThunarPath);
1106
gboolean vfs_backend_rename_file (const gchar *cOldURI, const gchar *cNewName)
1108
GError *erreur = NULL;
1109
g_return_val_if_fail (cOldURI != NULL, FALSE);
1110
cd_message ("%s (%s)", __func__, cOldURI);
1112
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cOldURI, &erreur);
1115
cd_warning ("Attention : %s", erreur->message);
1116
g_error_free (erreur);
1119
ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
1120
thunar_vfs_path_unref(pThunarPath);
1123
cd_warning ("Attention : %s", erreur->message);
1124
g_error_free (erreur);
1128
thunar_vfs_info_rename(pThunarVfsInfo, cNewName, &erreur );
1129
thunar_vfs_info_unref(pThunarVfsInfo);
1132
cd_warning ("Attention : %s", erreur->message);
1133
g_error_free (erreur);
1140
gboolean vfs_backend_move_file (const gchar *cURI, const gchar *cDirectoryURI)
1143
@see thunar_vfs_move_file
1145
GError *erreur = NULL;
1146
g_return_val_if_fail (cURI != NULL, FALSE);
1147
cd_message ("%s (%s, %s)", __func__, cURI, cDirectoryURI);
1149
ThunarVfsPath *pThunarPathFrom = thunar_vfs_path_new(cURI, &erreur);
1152
cd_warning ("Attention : %s", erreur->message);
1153
g_error_free (erreur);
1157
gchar *cDestURI = g_strdup_printf("%s/%s", cDirectoryURI, thunar_vfs_path_get_name(pThunarPathFrom));
1158
ThunarVfsPath *pThunarPathTo = thunar_vfs_path_new(cDestURI, &erreur);
1162
thunar_vfs_path_unref(pThunarPathFrom);
1163
cd_warning ("Attention : %s", erreur->message);
1164
g_error_free (erreur);
1168
ThunarVfsJob *pJob = thunar_vfs_move_file(pThunarPathFrom, pThunarPathTo, &erreur);
1170
thunar_vfs_path_unref(pThunarPathFrom);
1171
thunar_vfs_path_unref(pThunarPathTo);
1175
cd_warning ("Attention : %s", erreur->message);
1176
g_error_free (erreur);
1180
g_object_unref(pJob);
1184
void vfs_backend_get_file_properties (const gchar *cURI, guint64 *iSize, time_t *iLastModificationTime, gchar **cMimeType, int *iUID, int *iGID, int *iPermissionsMask)
1186
GError *erreur = NULL;
1187
g_return_if_fail (cURI != NULL);
1188
cd_message ("%s (%s)", __func__, cURI);
1190
ThunarVfsPath *pThunarPath = thunar_vfs_path_new(cURI, &erreur);
1193
cd_warning ("Attention : %s", erreur->message);
1194
g_error_free (erreur);
1197
ThunarVfsInfo *pThunarVfsInfo = thunar_vfs_info_new_for_path(pThunarPath, &erreur);
1198
thunar_vfs_path_unref(pThunarPath);
1201
cd_warning ("Attention : %s", erreur->message);
1202
g_error_free (erreur);
1206
*iSize = pThunarVfsInfo->size;
1207
*iLastModificationTime = pThunarVfsInfo->mtime;
1208
*cMimeType = g_strdup (thunar_vfs_mime_info_get_name(pThunarVfsInfo->mime_info));
1209
*iUID = pThunarVfsInfo->uid;
1210
*iGID = pThunarVfsInfo->gid;
1211
*iPermissionsMask = pThunarVfsInfo->mode;
1213
thunar_vfs_info_unref(pThunarVfsInfo);
1217
gchar *vfs_backend_get_trash_path (const gchar *cNearURI, gchar **cFileInfoPath)
1219
GError *erreur = NULL;
1220
cd_message ("%s (%s)", __func__, cNearURI);
1222
ThunarVfsPath *pThunarPath = thunar_vfs_path_new("trash:/", &erreur);
1225
cd_warning ("Attention : %s", erreur->message);
1226
g_error_free (erreur);
1229
thunar_vfs_path_unref(pThunarPath);
1232
* If we haven't returned NULL yet, it means that there exist a valid trash.
1233
* We know that Thunar follows the XDG recommendations.
1234
* So the trash is in ~/.local/share/Trash
1237
gchar *trashPath = NULL;
1238
char *home = getenv("HOME");
1241
trashPath = g_strdup_printf("%s/%s", home, ".local/share/Trash/files");
1242
if (cFileInfoPath != NULL)
1243
*cFileInfoPath = g_strdup_printf ("%s/.local/share/Trash/info", home);
1249
gchar *vfs_backend_get_desktop_path (void)
1251
GError *erreur = NULL;
1254
ThunarVfsPath *pThunarDesktopPath = thunar_vfs_path_new("desktop:/", &erreur);
1257
cd_warning ("Attention : %s", erreur->message);
1258
g_error_free (erreur);
1261
thunar_vfs_path_unref(pThunarDesktopPath);
1264
* If we haven't returned NULL yet, it means that there exist a valid desktop.
1265
* We know that Thunar follows the XDG recommendations.
1266
* So the trash is in ~/Desktop
1269
gchar *desktopPath = NULL;
1270
char *home = getenv("HOME");
1273
desktopPath = g_strdup_printf("%s/%s", home, "Desktop");