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

« back to all changes in this revision

Viewing changes to kde-integration/src/applet-vfs.c

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
*/
19
19
 
 
20
#include <stdlib.h>
20
21
#include <string.h>
 
22
#include <sys/types.h>
 
23
#include <sys/stat.h>
 
24
#include <unistd.h>
21
25
 
22
26
#include <glib.h>
23
27
#include <gio/gio.h>
24
28
 
25
29
#include "applet-vfs.h"
26
30
 
 
31
extern int lstat (const char *path, struct stat *buf);
 
32
 
27
33
static GHashTable *s_hMonitorHandleTable = NULL;
28
34
 
29
35
 
424
430
        
425
431
        if (pMount != NULL)  // ce volume est monte.
426
432
        {
427
 
                pNewIcon = g_new0 (Icon, 1);
428
 
                pNewIcon->cName = g_mount_get_name (pMount);
429
 
                
430
433
                pRootDir = g_mount_get_root (pMount);
431
 
                pNewIcon->cCommand = g_file_get_uri (pRootDir);
432
 
                //g_object_unref (pRootDir);
433
 
                
434
434
                pIcon = g_mount_get_icon (pMount);
435
 
                pNewIcon->cFileName = _cd_get_icon_path (pIcon);
436
 
                //g_object_unref (pIcon);
 
435
                pNewIcon = cairo_dock_create_dummy_launcher (g_mount_get_name (pMount),
 
436
                        _cd_get_icon_path (pIcon),
 
437
                        g_file_get_uri (pRootDir),
 
438
                        NULL,
 
439
                        0);
 
440
                pNewIcon->iTrueType = CAIRO_DOCK_ICON_TYPE_FILE;
437
441
                
438
 
                //g_object_unref (pMount);
 
442
                g_object_unref (pRootDir);
 
443
                g_object_unref (pIcon);
 
444
                g_object_unref (pMount);
439
445
        }
440
446
        else  // ce volume est demonte, on le montre quand meme (l'automount peut etre off).
441
447
        {
442
 
                pNewIcon = g_new0 (Icon, 1);
443
 
                pNewIcon->cName = g_volume_get_name (pVolume);
444
 
                
445
448
                pIcon = g_volume_get_icon (pVolume);
446
 
                pNewIcon->cFileName = _cd_get_icon_path (pIcon);
447
 
                //g_object_unref (pIcon);
448
 
                
449
 
                pNewIcon->cCommand = g_strdup (pNewIcon->cName);
 
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
                pNewIcon->iTrueType = CAIRO_DOCK_ICON_TYPE_FILE;
 
455
                        
 
456
                g_object_unref (pIcon);
450
457
        }
451
458
        pNewIcon->iVolumeID = 1;
452
459
        pNewIcon->cBaseURI = g_strdup (pNewIcon->cCommand);
514
521
                else
515
522
                {
516
523
                        cd_message (" + volume '%s'\n", g_volume_get_name  (pVolume));
517
 
                        if (pNewIcon != NULL)
518
 
                                pNewIcon = _cd_get_icon_for_volume (pVolume, NULL);
 
524
                        pNewIcon = _cd_get_icon_for_volume (pVolume, NULL);
519
525
                        pIconsList = g_list_prepend (pIconsList, pNewIcon);
520
526
                }
521
527
                //g_object_unref (pVolume);
539
545
                else
540
546
                {
541
547
                        cd_message ("+ volume '%s'", g_volume_get_name  (pVolume));
542
 
                        if (pNewIcon != NULL)
543
 
                                pNewIcon = _cd_get_icon_for_volume (NULL, pMount);
 
548
                        pNewIcon = _cd_get_icon_for_volume (NULL, pMount);
544
549
                        pIconsList = g_list_prepend (pIconsList, pNewIcon);
545
550
                }
546
551
                //g_object_unref (pMount);
550
555
        return pIconsList;
551
556
}
552
557
 
553
 
GList *vfs_backend_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsType, gboolean bListHiddenFiles, gchar **cFullURI)
 
558
GList *vfs_backend_list_directory (const gchar *cBaseURI, CairoDockFMSortType iSortType, int iNewIconsType, gboolean bListHiddenFiles, int iNbMaxFiles, gchar **cFullURI)
554
559
{
555
560
        g_return_val_if_fail (cBaseURI != NULL, NULL);
556
561
        cd_message ("%s (%s)", __func__, cBaseURI);
626
631
                        const gchar *cMimeType = g_file_info_get_content_type (pFileInfo);
627
632
                        gchar *cName = NULL;
628
633
                        
629
 
                        icon = g_new0 (Icon, 1);
 
634
                        icon = cairo_dock_create_dummy_launcher (NULL, NULL, NULL, NULL, 0);
 
635
                        icon->iTrueType = CAIRO_DOCK_ICON_TYPE_FILE;
630
636
                        icon->iType = iNewIconsType;
631
637
                        icon->cBaseURI = g_strconcat (*cFullURI, "/", cFileName, NULL);
632
638
                        cd_message ("+ %s (mime:%s)", icon->cBaseURI, cMimeType);
693
699
                                cd_message ("le nom de ce volume est : %s", cName);
694
700
                        }
695
701
                        else
 
702
                        {
 
703
                                if (iFileType == G_FILE_TYPE_DIRECTORY)
 
704
                                        icon->iVolumeID = -1;
696
705
                                cName = g_strdup (cFileName);
 
706
                        }
697
707
                        
698
708
                        if (icon->cCommand == NULL)
699
709
                                icon->cCommand = g_strdup (icon->cBaseURI);
740
750
                        //g_list_prepend (pIconList, icon);
741
751
                        iOrder ++;
742
752
                }
743
 
        } while (TRUE);  // 'g_file_enumerator_close' est appelee lors du dernier 'g_file_enumerator_next_file'.
 
753
        } while (iOrder < iNbMaxFiles);  // 'g_file_enumerator_close' est appelee lors du dernier 'g_file_enumerator_next_file'.
 
754
        if (iOrder == iNbMaxFiles)
 
755
                g_file_enumerator_close (pFileEnum, NULL, NULL);  // g_file_enumerator_close() est appelee lors du dernier 'g_file_enumerator_next_file'.
 
756
        
744
757
        
745
758
        if (bAddHome && pIconList != NULL)
746
759
        {
747
 
                icon = g_new0 (Icon, 1);
 
760
                Icon *pRootIcon = cairo_dock_get_icon_with_name (pIconList, "/");
 
761
                if (pRootIcon == NULL)
 
762
                {
 
763
                        pRootIcon = cairo_dock_get_first_icon (pIconList);
 
764
                        cd_debug ("domage ! (%s:%s)\n", pRootIcon->cCommand, pRootIcon->cName);
 
765
                }
 
766
                icon = cairo_dock_create_dummy_launcher (g_strdup ("home"),
 
767
                        g_strdup (pRootIcon->cFileName),
 
768
                        g_strdup ("/home"),
 
769
                        NULL,
 
770
                        iOrder++);
 
771
                icon->iTrueType = CAIRO_DOCK_ICON_TYPE_FILE;
748
772
                icon->iType = iNewIconsType;
749
773
                icon->cBaseURI = g_strdup_printf ("file://%s", "/home");
750
 
                icon->cCommand = g_strdup ("/home");
751
 
                //icon->cCommand = g_strdup (icon->cBaseURI);
752
774
                icon->iVolumeID = 0;
753
 
                icon->cName = g_strdup ("home");
754
 
                Icon *pRootIcon = cairo_dock_get_icon_with_name (pIconList, "/");
755
 
                if (pRootIcon == NULL)
756
 
                {
757
 
                        pRootIcon = cairo_dock_get_first_icon (pIconList);
758
 
                        g_print ("domage ! (%s:%s)\n", pRootIcon->cCommand, pRootIcon->cName);
759
 
                }
760
 
                icon->cFileName = g_strdup (pRootIcon->cFileName);
761
 
                icon->fOrder = iOrder++;
762
775
                pIconList = g_list_insert_sorted (pIconList,
763
776
                        icon,
764
777
                        (GCompareFunc) cairo_dock_compare_icons_order);
798
811
{
799
812
        g_return_if_fail (cURI != NULL);
800
813
        
801
 
        g_print ("%s (%s)", __func__, cURI);
802
 
        gchar *cCommand = g_strdup_printf ("kfmclient exec \"%s\"", cURI);
 
814
        cd_debug ("%s (%s)", __func__, cURI);
 
815
        gchar *cCommand = g_strdup_printf ("kioclient exec \"%s\"", cURI);
803
816
        cairo_dock_launch_command (cCommand);
804
817
        g_free (cCommand);
805
818
        
902
915
}
903
916
 
904
917
 
 
918
 
905
919
static void _vfs_backend_mount_callback (gpointer pObject, GAsyncResult *res, gpointer *data)
906
 
//static void _vfs_backend_mount_callback (gboolean succeeded, char *error, char *detailed_error, gpointer *data)
 
920
//static void _gio_vfs_mount_callback (gboolean succeeded, char *error, char *detailed_error, gpointer *data)
907
921
{
908
922
        cd_message ("%s (%d)", __func__, GPOINTER_TO_INT (data[1]));
909
923
        
924
938
                g_error_free (erreur);
925
939
        }
926
940
        
927
 
        cd_message ("(un)mount fini -> %d", bSuccess);
928
 
        pCallback (GPOINTER_TO_INT (data[1]) == 1, bSuccess, data[2], data[3], data[4]);
929
 
        //g_free (data[2]);
930
 
        //g_object_unref (pObject);
931
 
        //g_free (data);
 
941
        cd_message ("(un)mounted -> %d", bSuccess);
 
942
        if (pCallback != NULL)
 
943
                pCallback (GPOINTER_TO_INT (data[1]) == 1, bSuccess, data[2], data[3], data[4]);
 
944
        g_free (data[2]);
 
945
        g_free (data[3]);
 
946
        g_free (data);
932
947
}
933
948
 
934
 
void vfs_backend_mount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, CairoContainer *pContainer)
 
949
void vfs_backend_mount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, gpointer user_data)
935
950
{
936
 
        g_return_if_fail (iVolumeID > 0);
 
951
        g_return_if_fail (cURI != NULL);
937
952
        cd_message ("%s (%s)", __func__, cURI);
938
953
        
939
 
        /*gchar *cTargetURI = NULL;
940
 
        GMount *pMount = _cd_find_mount_from_uri (cURI, &cTargetURI);
941
 
        cd_message (" %x / %s\n", pMount, cTargetURI);
942
 
        GVolume *pVolume = g_mount_get_volume (pMount);
943
 
        gpointer *data2 = g_new (gpointer, 5);
944
 
        data2[0] = pCallback;
945
 
        data2[1] = GINT_TO_POINTER (1);
946
 
        data2[2] = g_path_get_basename (cURI);
947
 
        data2[3] = icon;
948
 
        data2[4] = pDock;
949
 
        g_volume_mount (pVolume,
950
 
                G_MOUNT_MOUNT_NONE,
951
 
                NULL,
952
 
                NULL,
953
 
                (GAsyncReadyCallback) _vfs_backend_mount_callback,
954
 
                data2);*/
955
954
        gchar *cTargetURI = _cd_find_target_uri (cURI);
956
955
        GFile *pFile = g_file_new_for_uri (cURI);
957
956
        
958
 
        gpointer *data2 = g_new (gpointer, 5);
959
 
        data2[0] = pCallback;
960
 
        data2[1] = GINT_TO_POINTER (1);
961
 
        data2[2] = g_path_get_basename (cTargetURI);
962
 
        data2[3] = icon;
963
 
        data2[4] = pContainer;
 
957
        gpointer *data = g_new (gpointer, 5);  // libere dans la callback.
 
958
        data[0] = pCallback;
 
959
        data[1] = GINT_TO_POINTER (1);  // mount
 
960
        data[2] = (cTargetURI ? g_path_get_basename (cTargetURI) : g_strdup (cURI));
 
961
        data[3] = g_strdup (cURI);
 
962
        data[4] = user_data;
964
963
        g_file_mount_mountable  (pFile,
965
964
                G_MOUNT_MOUNT_NONE,
966
965
                NULL,
967
966
                NULL,
968
967
                (GAsyncReadyCallback) _vfs_backend_mount_callback,
969
 
                data2);
 
968
                data);
970
969
        g_free (cTargetURI);
971
970
}
972
971
 
973
 
void vfs_backend_unmount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, CairoContainer *pContainer)
 
972
void vfs_backend_unmount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, gpointer user_data)
974
973
{
975
974
        g_return_if_fail (cURI != NULL);
976
975
        cd_message ("%s (%s)", __func__, cURI);
989
988
        gboolean bCanUnmount = g_mount_can_unmount (pMount);
990
989
        cd_message ("eject:%d / unmount:%d\n", bCanEject, bCanUnmount);
991
990
        if (! bCanEject && ! bCanUnmount)
 
991
        {
 
992
                cd_warning ("can't unmount this volume (%s)", cURI);
992
993
                return ;
 
994
        }
993
995
        
994
 
        gpointer *data2 = g_new (gpointer, 5);
995
 
        data2[0] = pCallback;
996
 
        data2[1] = GINT_TO_POINTER (bCanEject ? 2 : 0);
997
 
        data2[2] = g_mount_get_name (pMount);
998
 
        data2[3] = icon;
999
 
        data2[4] = pContainer;
 
996
        gpointer *data = g_new (gpointer, 5);
 
997
        data[0] = pCallback;
 
998
        data[1] = GINT_TO_POINTER (bCanEject ? 2 : 0);
 
999
        data[2] = g_mount_get_name (pMount);
 
1000
        data[3] = g_strdup (cURI);
 
1001
        data[4] = user_data;
1000
1002
        if (bCanEject)
1001
1003
                g_mount_eject (pMount,
1002
1004
                        G_MOUNT_UNMOUNT_NONE,
1003
1005
                        NULL,
1004
1006
                        (GAsyncReadyCallback) _vfs_backend_mount_callback,
1005
 
                        data2);
 
1007
                        data);
1006
1008
        else
1007
1009
                g_mount_unmount (pMount,
1008
1010
                        G_MOUNT_UNMOUNT_NONE ,
1009
1011
                        NULL,
1010
1012
                        (GAsyncReadyCallback) _vfs_backend_mount_callback,
1011
 
                        data2);
 
1013
                        data);
1012
1014
}
1013
1015
 
1014
1016
 
1113
1115
 
1114
1116
 
1115
1117
 
1116
 
gboolean vfs_backend_delete_file (const gchar *cURI)
 
1118
gboolean vfs_backend_delete_file (const gchar *cURI, gboolean bNoTrash)
1117
1119
{
1118
1120
        g_return_val_if_fail (cURI != NULL, FALSE);
1119
 
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
1120
1121
        
1121
 
        GError *erreur = NULL;
1122
 
        gboolean bSuccess = g_file_trash (pFile, NULL, &erreur);
1123
 
        if (erreur != NULL)
1124
 
        {
1125
 
                cd_warning ("gnome-integration : %s", erreur->message);
1126
 
                g_error_free (erreur);
1127
 
        }
1128
 
        g_object_unref (pFile);
1129
 
        return bSuccess;
 
1122
        if (bNoTrash)
 
1123
        {
 
1124
                GError *erreur = NULL;
 
1125
                gchar *cFilePath = g_filename_from_uri (cURI, NULL, &erreur);
 
1126
                if (erreur != NULL)
 
1127
                {
 
1128
                        cd_warning ("%s", erreur->message);
 
1129
                        g_error_free (erreur);
 
1130
                        return FALSE;
 
1131
                }
 
1132
                gchar *cCommand = g_strdup_printf ("rm -rf \"%s\"", cFilePath);
 
1133
                cairo_dock_launch_command (cCommand);
 
1134
                g_free (cCommand);
 
1135
                g_free (cFilePath);
 
1136
        }
 
1137
        else
 
1138
        {
 
1139
                gchar *cCommand = g_strdup_printf ("kioclient move \"%s\" trash:/", cURI);
 
1140
                cairo_dock_launch_command (cCommand);
 
1141
                g_free (cCommand);
 
1142
        }
 
1143
        return TRUE;
1130
1144
}
1131
1145
 
1132
1146
gboolean vfs_backend_rename_file (const gchar *cOldURI, const gchar *cNewName)
1133
1147
{
1134
1148
        g_return_val_if_fail (cOldURI != NULL, FALSE);
1135
 
        GFile *pOldFile = (*cOldURI == '/' ? g_file_new_for_path (cOldURI) : g_file_new_for_uri (cOldURI));
1136
 
        GError *erreur = NULL;
1137
 
        GFile *pNewFile = g_file_set_display_name (pOldFile, cNewName, NULL, &erreur);
1138
 
        if (erreur != NULL)
 
1149
        
 
1150
        gboolean bSuccess = FALSE;
 
1151
        gchar *cPath = g_path_get_dirname (cOldURI);
 
1152
        if (cPath)
1139
1153
        {
1140
 
                cd_warning ("gnome-integration : %s", erreur->message);
1141
 
                g_error_free (erreur);
 
1154
                gchar *cNewURI = g_strdup_printf ("%s/%s", cPath, cNewName);
 
1155
                gchar *cCommand = g_strdup_printf ("kioclient move \"%s\" \"%s\"", cOldURI, cNewURI);
 
1156
                cairo_dock_launch_command (cCommand);
 
1157
                g_free (cCommand);
 
1158
                g_free (cNewURI);
 
1159
                bSuccess = TRUE;
1142
1160
        }
1143
 
        gboolean bSuccess = (pNewFile != NULL);
1144
 
        if (pNewFile != NULL)
1145
 
                g_object_unref (pNewFile);
1146
 
        g_object_unref (pOldFile);
 
1161
        g_free (cPath);
1147
1162
        return bSuccess;
1148
1163
}
1149
1164
 
1151
1166
{
1152
1167
        g_return_val_if_fail (cURI != NULL, FALSE);
1153
1168
        cd_message (" %s -> %s", cURI, cDirectoryURI);
1154
 
        GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI));
1155
1169
        
1156
 
        gchar *cFileName = g_file_get_basename (pFile);
1157
 
        gchar *cNewFileURI = g_strconcat (cDirectoryURI, "/", cFileName, NULL);  // un peu moyen mais bon...
1158
 
        GFile *pDestinationFile = (*cNewFileURI == '/' ? g_file_new_for_path (cNewFileURI) : g_file_new_for_uri (cNewFileURI));
 
1170
        gchar *cFileName = g_path_get_basename (cURI);
 
1171
        gchar *cNewFileURI = g_strconcat (cDirectoryURI, "/", cFileName, NULL);
 
1172
        gchar *cCommand = g_strdup_printf ("kioclient move \"%s\" \"%s\"", cURI, cNewFileURI);
 
1173
        cairo_dock_launch_command (cCommand);
 
1174
        g_free (cCommand);
1159
1175
        g_free (cNewFileURI);
1160
1176
        g_free (cFileName);
1161
 
        
1162
 
        GError *erreur = NULL;
1163
 
        gboolean bSuccess = g_file_move (pFile,
1164
 
                pDestinationFile,
1165
 
                G_FILE_COPY_NOFOLLOW_SYMLINKS,
1166
 
                NULL,
1167
 
                NULL,  // GFileProgressCallback
1168
 
                NULL,  // data
1169
 
                &erreur);
1170
 
        if (erreur != NULL)
1171
 
        {
1172
 
                cd_warning ("gnome-integration : %s", erreur->message);
1173
 
                g_error_free (erreur);
1174
 
        }
1175
 
        g_object_unref (pFile);
1176
 
        g_object_unref (pDestinationFile);
 
1177
        return TRUE;
 
1178
}
 
1179
 
 
1180
gboolean vfs_backend_create_file (const gchar *cURI, gboolean bDirectory)
 
1181
{
 
1182
        g_return_val_if_fail (cURI != NULL, FALSE);
 
1183
        gchar *cPath = g_filename_from_uri (cURI, NULL, NULL);
 
1184
        
 
1185
        gchar *cCommand;
 
1186
        gboolean bSuccess = TRUE;
 
1187
        if (bDirectory)
 
1188
                cCommand = g_strdup_printf ("mkdir -p \"%s\"", cPath);
 
1189
        else
 
1190
                cCommand = g_strdup_printf ("touch \"%s\"", cPath);
 
1191
        cairo_dock_launch_command (cCommand);
 
1192
        
 
1193
        g_free (cCommand);
 
1194
        g_free (cPath);
1177
1195
        return bSuccess;
1178
1196
}
1179
1197
 
1216
1234
}
1217
1235
 
1218
1236
 
 
1237
void vfs_backend_empty_trash (void)
 
1238
{
 
1239
        cairo_dock_launch_command ("ktrash --empty");
 
1240
}
 
1241
 
1219
1242
gchar *vfs_backend_get_trash_path (const gchar *cNearURI, gchar **cFileInfoPath)
1220
1243
{
1221
1244
        gchar *cPath = NULL;
1247
1270
                cPath = g_strdup_printf ("%s/Desktop", g_getenv ("HOME"));
1248
1271
        return cPath;
1249
1272
}
 
1273
 
 
1274
 
 
1275
gsize vfs_backend_measure_directory (const gchar *cBaseURI, gint iCountType, gboolean bRecursive, gint *pCancel)
 
1276
{
 
1277
        g_return_val_if_fail (cBaseURI != NULL, 0);
 
1278
        g_print ("%s (%s)\n", __func__, cBaseURI);
 
1279
        
 
1280
        GError *erreur = NULL;
 
1281
        gchar *cDirectory = (*cBaseURI == '/' ? (gchar*)cBaseURI : g_filename_from_uri (cBaseURI, NULL, &erreur));
 
1282
        if (erreur != NULL)
 
1283
        {
 
1284
                cd_warning ("kde-integration : %s", erreur->message);
 
1285
                g_error_free (erreur);
 
1286
                return 0;
 
1287
        }
 
1288
        
 
1289
        GDir *dir = g_dir_open (cDirectory, 0, &erreur);
 
1290
        if (erreur != NULL)
 
1291
        {
 
1292
                cd_warning ("kde-integration : %s", erreur->message);
 
1293
                g_error_free (erreur);
 
1294
                return 0;
 
1295
        }
 
1296
        
 
1297
        gsize iMeasure = 0;
 
1298
        struct stat buf;
 
1299
        const gchar *cFileName;
 
1300
        GString *sFilePath = g_string_new ("");
 
1301
        while ((cFileName = g_dir_read_name (dir)) != NULL && ! g_atomic_int_get (pCancel))
 
1302
        {
 
1303
                g_string_printf (sFilePath, "%s/%s", cDirectory, cFileName);
 
1304
                
 
1305
                if (lstat (sFilePath->str, &buf) != -1)
 
1306
                {
 
1307
                        if (S_ISDIR (buf.st_mode) && bRecursive)  // repertoire.
 
1308
                        {
 
1309
                                iMeasure += MAX (1, vfs_backend_measure_directory (sFilePath->str, iCountType, bRecursive, pCancel));  // un repertoire vide comptera pour 1.
 
1310
                        }
 
1311
                        else  // fichier simple.
 
1312
                        {
 
1313
                                if (iCountType == 1)  // measure size.
 
1314
                                {
 
1315
                                        iMeasure += buf.st_size;
 
1316
                                }
 
1317
                                else  // measure nb files.
 
1318
                                {
 
1319
                                        iMeasure ++;
 
1320
                                }
 
1321
                        }
 
1322
                }
 
1323
        }
 
1324
        
 
1325
        g_dir_close (dir);
 
1326
        g_string_free (sFilePath, TRUE);
 
1327
        if (cDirectory != cBaseURI)
 
1328
                g_free (cDirectory);
 
1329
        
 
1330
        return iMeasure;
 
1331
}