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