~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to dustbin/src/applet-trashes-manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 3
 
10
* of the License, or (at your option) any later version.
 
11
*
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
/**********************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock project,
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
**********************************************************************************/
 
28
#include <stdlib.h>
 
29
#include <string.h>
 
30
#include <sys/types.h>
 
31
#include <sys/stat.h>
 
32
#include <unistd.h>
 
33
#include <glib/gstdio.h>
 
34
 
 
35
#include "cairo-dock.h"
 
36
 
 
37
#include "applet-draw.h"
 
38
#include "applet-struct.h"
 
39
#include "applet-trashes-manager.h"
 
40
 
 
41
extern int lstat (const char *path, struct stat *buf);
 
42
 
 
43
static GStaticRWLock s_mTasksMutex = G_STATIC_RW_LOCK_INIT;
 
44
static GList *s_pTasksList = NULL;
 
45
static int s_iThreadIsRunning = 0;
 
46
static int s_iSidTimerRedraw = 0;
 
47
static int s_iSidDelayMeasure = 0;
 
48
 
 
49
gpointer cd_dustbin_threaded_calculation (gpointer data)
 
50
{
 
51
        int iNbFiles, iSize;
 
52
        do
 
53
        {
 
54
                //\________________________ On quitte si plus de message.
 
55
                g_static_rw_lock_writer_lock (&s_mTasksMutex);
 
56
                if (s_pTasksList == NULL)  // aucun message dans la file d'attente, on quitte.
 
57
                {
 
58
                        cd_message ("*** plus de message, on quitte le thread.");
 
59
                        g_atomic_int_set (&s_iThreadIsRunning, 0);
 
60
                        g_static_rw_lock_writer_unlock (&s_mTasksMutex);
 
61
                        break;
 
62
                }
 
63
                
 
64
                //\________________________ On recupere le message de tete.
 
65
                GList *pFirstElement = s_pTasksList;
 
66
                CdDustbinMessage *pMessage = pFirstElement->data;
 
67
                CdDustbin *pDustbin = pMessage->pDustbin;
 
68
                gchar *cURI = pMessage->cURI;
 
69
                cd_message ("*** recuperation du message : %s", cURI);
 
70
                
 
71
                //\________________________ On l'enleve de la liste.
 
72
                s_pTasksList = g_list_remove (s_pTasksList, pMessage);
 
73
                g_free (pMessage);
 
74
                
 
75
                g_static_rw_lock_writer_unlock (&s_mTasksMutex);
 
76
                
 
77
                //\________________________ On traite le message.
 
78
                if (pDustbin == NULL)  // recalcul complet.
 
79
                {
 
80
                        cd_dustbin_task_all_dustbins (&myData.iNbFiles, &myData.iSize);
 
81
                }
 
82
                else if (cURI == NULL)
 
83
                {
 
84
                        g_atomic_int_add (&myData.iNbFiles, - pDustbin->iNbFiles);
 
85
                        g_atomic_int_add (&myData.iSize, - pDustbin->iSize);
 
86
                        cd_dustbin_task_directory (pDustbin->cPath, myConfig.iQuickInfoType, pDustbin, &pDustbin->iNbFiles, &pDustbin->iSize);
 
87
                        g_atomic_int_add (&myData.iNbFiles, pDustbin->iNbFiles);
 
88
                        g_atomic_int_add (&myData.iSize, pDustbin->iSize);
 
89
                }
 
90
                else  // calcul d'un fichier supplementaire.
 
91
                {
 
92
                        cd_dustbin_task_one_file (cURI, myConfig.iQuickInfoType, pDustbin, &iNbFiles, &iSize);
 
93
                        pDustbin->iNbFiles += iNbFiles;
 
94
                        pDustbin->iSize += iSize;
 
95
                        g_atomic_int_add (&myData.iNbFiles, iNbFiles);
 
96
                        g_atomic_int_add (&myData.iSize, iSize);
 
97
                }
 
98
                g_free (cURI);
 
99
        }
 
100
        while (1);
 
101
        
 
102
        cd_message ("*** fin du thread -> %dfichiers , %db", myData.iNbFiles, myData.iSize);
 
103
        
 
104
        return NULL;
 
105
}
 
106
 
 
107
 
 
108
void cd_dustbin_free_message (CdDustbinMessage *pMessage)
 
109
{
 
110
        if (pMessage == NULL)
 
111
                return;
 
112
        g_free (pMessage->cURI);
 
113
        g_free (pMessage);
 
114
}
 
115
 
 
116
void cd_dustbin_remove_all_messages (void)
 
117
{
 
118
        g_list_foreach (s_pTasksList, (GFunc) cd_dustbin_free_message, NULL);
 
119
        g_list_free (s_pTasksList);
 
120
        s_pTasksList = NULL;
 
121
}
 
122
 
 
123
void cd_dustbin_remove_messages (CdDustbin *pDustbin)
 
124
{
 
125
        CdDustbinMessage *pMessage;
 
126
        GList *pElement = s_pTasksList, *pNextElement;
 
127
        while (pElement != NULL)
 
128
        {
 
129
                pMessage = pElement->data;
 
130
                pNextElement = pElement->next;
 
131
 
 
132
                if (pMessage->pDustbin == pDustbin)  // on l'enleve de la liste et on l'efface.
 
133
                {
 
134
                        s_pTasksList = g_list_remove (s_pTasksList, pMessage);
 
135
                        cd_dustbin_free_message (pMessage);
 
136
                }
 
137
                pElement = pNextElement;
 
138
        }
 
139
}
 
140
 
 
141
 
 
142
gboolean cd_dustbin_is_calculating (void)
 
143
{
 
144
        int iThreadIsRunning = g_atomic_int_get (&s_iThreadIsRunning);
 
145
        return (iThreadIsRunning != 0 || s_iSidDelayMeasure != 0);
 
146
}
 
147
 
 
148
static gboolean _cd_dustbin_check_for_redraw (gpointer data)
 
149
{
 
150
        int iThreadIsRunning = g_atomic_int_get (&s_iThreadIsRunning);
 
151
        cd_message ("%s (%d)", __func__, iThreadIsRunning);
 
152
        if (! iThreadIsRunning)
 
153
        {
 
154
                s_iSidTimerRedraw = 0;
 
155
                cd_message ("  redessin (%d,%d)\n", myData.iNbFiles, myData.iSize);
 
156
                if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES || myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
 
157
                        cd_dustbin_draw_quick_info (TRUE);
 
158
                cd_dustbin_signal_full_dustbin ();
 
159
                return FALSE;
 
160
        }
 
161
        return TRUE;
 
162
}
 
163
static void _cd_dustbin_launch_task (void)
 
164
{
 
165
        cd_message ("");
 
166
        if (g_atomic_int_compare_and_exchange (&s_iThreadIsRunning, 0, 1))  // il etait egal a 0, on lui met 1 et on lance le thread.
 
167
        {
 
168
                cd_message (" ==> lancement du thread de calcul\n");
 
169
                if (s_iSidTimerRedraw == 0)
 
170
                        s_iSidTimerRedraw = g_timeout_add (150, (GSourceFunc) _cd_dustbin_check_for_redraw, (gpointer) NULL);
 
171
                
 
172
                GError *erreur = NULL;
 
173
                GThread* pThread = g_thread_create ((GThreadFunc) cd_dustbin_threaded_calculation,
 
174
                        NULL,
 
175
                        FALSE,
 
176
                        &erreur);
 
177
                if (erreur != NULL)
 
178
                {
 
179
                        cd_message ("Attention : %s\n", erreur->message);
 
180
                        g_error_free (erreur);
 
181
                }
 
182
        }
 
183
}
 
184
static gboolean _cd_dustbin_launch_task_delayed (gpointer *data)
 
185
{
 
186
        _cd_dustbin_launch_task ();
 
187
        s_iSidDelayMeasure = 0;
 
188
        return FALSE;
 
189
}
 
190
void cd_dustbin_add_message (gchar *cURI, CdDustbin *pDustbin)
 
191
{
 
192
        cd_message ("%s (%s)", __func__, cURI);
 
193
        g_static_rw_lock_writer_lock (&s_mTasksMutex);
 
194
        
 
195
        CdDustbinMessage *pNewMessage = g_new (CdDustbinMessage, 1);
 
196
        pNewMessage->cURI = cURI;
 
197
        pNewMessage->pDustbin = pDustbin;
 
198
        
 
199
        if (pDustbin == NULL)
 
200
        {
 
201
                cd_dustbin_remove_all_messages ();
 
202
                s_pTasksList = g_list_prepend (s_pTasksList, pNewMessage);
 
203
                g_atomic_int_set (&myData.iNbFiles, -1);  // en cours.
 
204
                g_atomic_int_set (&myData.iSize, -1);  // en cours.
 
205
        }
 
206
        else if (cURI == NULL)
 
207
        {
 
208
                cd_dustbin_remove_messages (pDustbin);
 
209
                s_pTasksList = g_list_prepend (s_pTasksList, pNewMessage);
 
210
        }
 
211
        else
 
212
        {
 
213
                s_pTasksList = g_list_append (s_pTasksList, pNewMessage);
 
214
        }
 
215
        g_static_rw_lock_writer_unlock (&s_mTasksMutex);
 
216
        
 
217
        if (! g_atomic_int_get (&s_iThreadIsRunning))
 
218
        {
 
219
                if (s_iSidDelayMeasure != 0)
 
220
                {
 
221
                        cd_message ("  lancement calcul retarde");
 
222
                        g_source_remove (s_iSidDelayMeasure);
 
223
                        s_iSidDelayMeasure = 0;
 
224
                }
 
225
                s_iSidDelayMeasure = g_timeout_add (400, (GSourceFunc) _cd_dustbin_launch_task_delayed, NULL);  // on retarde le calcul, car il y'a probablement d'autres fichiers qui vont arriver.
 
226
        }
 
227
        if (pDustbin == NULL)
 
228
                cd_dustbin_draw_quick_info (TRUE);
 
229
}
 
230
 
 
231
 
 
232
 
 
233
int cd_dustbin_count_trashes (gchar *cDirectory)
 
234
{
 
235
        //g_print ("%s (%s)\n", __func__, cDirectory);
 
236
        GError *erreur = NULL;
 
237
        GDir *dir = g_dir_open (cDirectory, 0, &erreur);
 
238
        if (erreur != NULL)
 
239
        {
 
240
                cd_warning ("Attention : %s", erreur->message);
 
241
                g_error_free (erreur);
 
242
                return 0;
 
243
        }
 
244
        
 
245
        int iNbTrashes = 0;
 
246
        while (g_dir_read_name (dir) != NULL)
 
247
        {
 
248
                iNbTrashes ++;
 
249
        }
 
250
        
 
251
        g_dir_close (dir);
 
252
        return iNbTrashes;
 
253
}
 
254
 
 
255
void cd_dustbin_task_directory (gchar *cDirectory, CdDustbinInfotype iInfoType, CdDustbin *pDustbin, int *iNbFiles, int *iSize)
 
256
{
 
257
        cd_debug ("%s (%s)", __func__, cDirectory);
 
258
        g_atomic_int_set (iNbFiles, 0);
 
259
        g_atomic_int_set (iSize, 0);
 
260
 
 
261
        GError *erreur = NULL;
 
262
        GDir *dir = g_dir_open (cDirectory, 0, &erreur);
 
263
        if (erreur != NULL)
 
264
        {
 
265
                cd_warning ("Attention : %s", erreur->message);
 
266
                g_error_free (erreur);
 
267
                return ;
 
268
        }
 
269
        
 
270
        int iNbFilesSubDir, iSizeSubDir;
 
271
        struct stat buf;
 
272
        const gchar *cFileName;
 
273
        CdDustbinMessage *pMessage;
 
274
        GString *sFilePath = g_string_new ("");
 
275
        while ((cFileName = g_dir_read_name (dir)) != NULL)
 
276
        {
 
277
                g_static_rw_lock_reader_lock (&s_mTasksMutex);
 
278
                if (s_pTasksList != NULL)
 
279
                {
 
280
                        pMessage = s_pTasksList->data;
 
281
                        if (pMessage->pDustbin == NULL || pMessage->pDustbin == pDustbin)  // une demande de recalcul complet a ete faite sur cette poubelle, on interromp le calcul.
 
282
                        {
 
283
                                g_static_rw_lock_reader_unlock (&s_mTasksMutex);
 
284
                                break ;
 
285
                        }
 
286
                }
 
287
                g_static_rw_lock_reader_unlock (&s_mTasksMutex);
 
288
                
 
289
                g_string_printf (sFilePath, "%s/%s", cDirectory, cFileName);
 
290
                if (lstat (sFilePath->str, &buf) != -1)
 
291
                {
 
292
                        if (S_ISDIR (buf.st_mode))
 
293
                        {
 
294
                                cd_debug ("  %s est un repertoire", sFilePath->str);
 
295
                                iNbFilesSubDir = 0;
 
296
                                iSizeSubDir = 0;
 
297
                                cd_dustbin_task_directory (sFilePath->str, iInfoType, pDustbin, &iNbFilesSubDir, &iSizeSubDir);
 
298
                                g_atomic_int_add (iNbFiles, iNbFilesSubDir);
 
299
                                g_atomic_int_add (iSize, iSizeSubDir);
 
300
                                cd_debug ("  + %d fichiers dans ce sous-repertoire", iNbFilesSubDir );
 
301
                        }
 
302
                        else
 
303
                        {
 
304
                                g_atomic_int_add (iNbFiles, 1);
 
305
                                g_atomic_int_add (iSize, buf.st_size);
 
306
                        }
 
307
                }
 
308
        }
 
309
        
 
310
        g_string_free (sFilePath, TRUE);
 
311
        g_dir_close (dir);
 
312
}
 
313
 
 
314
void cd_dustbin_task_one_file (gchar *cURI, CdDustbinInfotype iInfoType, CdDustbin *pDustbin, int *iNbFiles, int *iSize)
 
315
{
 
316
        cd_debug ("%s (%s)", __func__, cURI);
 
317
        
 
318
        GError *erreur = NULL;
 
319
        gchar *cFilePath = g_filename_from_uri (cURI, NULL, &erreur);
 
320
        if (erreur != NULL)
 
321
        {
 
322
                cd_warning ("Attention : %s", erreur->message);
 
323
                g_error_free (erreur);
 
324
                g_atomic_int_set (iNbFiles, 0);
 
325
                g_atomic_int_set (iSize, 0);
 
326
                return ;
 
327
        }
 
328
        
 
329
        struct stat buf;
 
330
        if (lstat (cFilePath, &buf) != -1)
 
331
        {
 
332
                if (S_ISDIR (buf.st_mode))
 
333
                {
 
334
                        cd_dustbin_task_directory (cFilePath, iInfoType, pDustbin, iNbFiles, iSize);
 
335
                }
 
336
                else
 
337
                {
 
338
                        g_atomic_int_set (iNbFiles, 1);
 
339
                        g_atomic_int_set (iSize, buf.st_size);
 
340
                }
 
341
        }
 
342
        else
 
343
        {
 
344
                g_atomic_int_set (iNbFiles, 0);
 
345
                g_atomic_int_set (iSize, 0);
 
346
        }
 
347
        g_free (cFilePath);
 
348
}
 
349
 
 
350
void cd_dustbin_task_all_dustbins (int *iNbFiles, int *iSize)
 
351
{
 
352
        cd_message ("");
 
353
        g_atomic_int_set (iNbFiles, 0);
 
354
        g_atomic_int_set (iSize, 0);
 
355
        
 
356
        int iNbFilesHere, iSizeHere;
 
357
        CdDustbin *pDustbin;
 
358
        GList *pElement;
 
359
        for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
 
360
        {
 
361
                pDustbin = pElement->data;
 
362
                
 
363
                cd_dustbin_task_directory (pDustbin->cPath, myConfig.iQuickInfoType, pDustbin, &pDustbin->iNbFiles, &pDustbin->iSize);
 
364
                
 
365
                g_atomic_int_add (iNbFiles, pDustbin->iNbFiles);
 
366
                g_atomic_int_add (iSize, pDustbin->iSize);
 
367
        }
 
368
}
 
369
 
 
370
static void _cd_dustbin_empty_dir (const gchar *cDirectory)
 
371
{
 
372
        g_return_if_fail (cDirectory != NULL && *cDirectory != '\0' && strcmp (cDirectory, g_getenv ("HOME")) != 0);
 
373
        gchar *cCommand = g_strdup_printf ("find '%s' -maxdepth 1 -mindepth 1 -exec rm -rf '{}' \\;", cDirectory);  // un rm -rf * n'efface pas les fichiers caches.
 
374
        cd_message (cCommand);
 
375
        g_print ("***\n***%s\n***\n", cCommand);
 
376
        ///int r = system (cCommand);
 
377
        cairo_dock_launch_command (cCommand);  // est-ce que ca ne va pas saturer le file-monitor ?
 
378
        g_free (cCommand);
 
379
}
 
380
 
 
381
void cd_dustbin_delete_trash (GtkMenuItem *menu_item, gchar *cDirectory)
 
382
{
 
383
        gchar *cQuestion;
 
384
        if (cDirectory != NULL)
 
385
                cQuestion = g_strdup_printf (D_("You're about to delete all files in %s. Sure ?"), cDirectory);
 
386
        else if (myData.pDustbinsList != NULL)
 
387
                cQuestion = g_strdup_printf (D_("You're about to delete all files in all dustbins. Sure ?"));
 
388
        else
 
389
                return;
 
390
        int answer = cairo_dock_ask_question_and_wait (cQuestion, myIcon, myContainer);
 
391
        g_free (cQuestion);
 
392
        if (answer == GTK_RESPONSE_YES)
 
393
        {
 
394
                GString *sCommand = g_string_new ("");
 
395
                if (cDirectory != NULL)
 
396
                {
 
397
                        g_string_printf (sCommand, "rm -rf '%s'/* '%s'/.*", cDirectory, cDirectory);
 
398
                        _cd_dustbin_empty_dir (cDirectory);
 
399
                }
 
400
                else
 
401
                {
 
402
                        CdDustbin *pDustbin;
 
403
                        GList *pElement;
 
404
                        for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
 
405
                        {
 
406
                                pDustbin = pElement->data;
 
407
                                ///g_string_append_printf (sCommand, "\"%s\"/* \"%s\"/.* ", pDustbin->cPath, pDustbin->cPath);
 
408
                                _cd_dustbin_empty_dir (pDustbin->cPath);
 
409
                        }
 
410
                }
 
411
                ///cd_message (">>> %s", sCommand->str);
 
412
                ///system (sCommand->str);  // g_spawn_command_line_async() ne marche pas pour celle-la.
 
413
                
 
414
                gchar *cFileInfoPath= NULL;
 
415
                gchar *cDefaultTrash = cairo_dock_fm_get_trash_path (g_getenv ("HOME"), &cFileInfoPath);
 
416
                if (cDefaultTrash != NULL && cFileInfoPath != NULL)  // il faut aussi effacer les infos.
 
417
                {
 
418
                        if (cDirectory == NULL || strcmp (cDirectory, cDefaultTrash) == 0)
 
419
                        {
 
420
                                ///g_string_printf (sCommand, "rm -rf \"%s\"/*info \"%s\"/.*info", cFileInfoPath, cFileInfoPath);
 
421
                                _cd_dustbin_empty_dir (cFileInfoPath);
 
422
                                ///cd_message (">>> %s", sCommand->str);
 
423
                                ///system (sCommand->str);
 
424
                        }
 
425
                }
 
426
                g_free (cDefaultTrash);
 
427
                g_free (cFileInfoPath);
 
428
                ///g_string_free (sCommand, TRUE);
 
429
        }
 
430
}
 
431
 
 
432
void cd_dustbin_show_trash (GtkMenuItem *menu_item, gchar *cDirectory)
 
433
{
 
434
        if (myConfig.cDefaultBrowser != NULL)
 
435
        {
 
436
                GString *sCommand = g_string_new (myConfig.cDefaultBrowser);
 
437
                if (cDirectory != NULL)
 
438
                {
 
439
                        g_string_append_printf (sCommand, " %s", cDirectory);
 
440
                }
 
441
                else if (myData.pDustbinsList != NULL)
 
442
                {
 
443
                        CdDustbin *pDustbin;
 
444
                        GList *pElement;
 
445
                        for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
 
446
                        {
 
447
                                pDustbin = pElement->data;
 
448
                                g_string_append_printf (sCommand, " %s", pDustbin->cPath);
 
449
                        }
 
450
                }
 
451
                else
 
452
                        return ;
 
453
                cd_message ("dustbin : %s", sCommand->str);
 
454
                GError *erreur = NULL;
 
455
                g_spawn_command_line_async (sCommand->str, &erreur);
 
456
                if (erreur != NULL)
 
457
                {
 
458
                        cd_warning ("Dustbin : when trying to execute '%s' : %s", sCommand->str, erreur->message);
 
459
                        g_error_free (erreur);
 
460
                        cairo_dock_show_temporary_dialog (D_("A problem occured\nIf '%s' is not your usual file browser,\nyou can change it in the conf panel of this module"), myIcon, myContainer, 5000, myConfig.cDefaultBrowser);
 
461
                }
 
462
                g_string_free (sCommand, TRUE);
 
463
        }
 
464
        else
 
465
        {
 
466
                cairo_dock_fm_launch_uri (cDirectory != NULL ? cDirectory : "trash:/");
 
467
        }
 
468
}
 
469
 
 
470
void cd_dustbin_sum_all_tasks (int *iNbFiles, int *iSize)
 
471
{
 
472
        int iTotalMeasure = 0;
 
473
        CdDustbin *pDustbin;
 
474
        GList *pElement;
 
475
        for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
 
476
        {
 
477
                pDustbin = pElement->data;
 
478
                g_atomic_int_add (iNbFiles, pDustbin->iNbFiles);
 
479
                g_atomic_int_add (iSize, pDustbin->iSize);
 
480
        }
 
481
}
 
482
 
 
483
 
 
484
 
 
485
gboolean cd_dustbin_is_monitored (gchar *cDustbinPath)
 
486
{
 
487
        g_return_val_if_fail (cDustbinPath != NULL, FALSE);
 
488
        CdDustbin *pDustbin;
 
489
        GList *pElement;
 
490
        for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
 
491
        {
 
492
                pDustbin = pElement->data;
 
493
                if (pDustbin->cPath != NULL && strcmp (pDustbin->cPath, cDustbinPath) == 0)
 
494
                        return TRUE;
 
495
        }
 
496
        return FALSE;
 
497
}
 
498
 
 
499
gboolean cd_dustbin_add_one_dustbin (gchar *cDustbinPath, int iAuthorizedWeight)
 
500
{
 
501
        g_return_val_if_fail (cDustbinPath != NULL, FALSE);
 
502
        cd_message ("%s (%s)", __func__, cDustbinPath);
 
503
        
 
504
        CdDustbin *pDustbin = g_new0 (CdDustbin, 1);
 
505
        pDustbin->cPath = cDustbinPath;
 
506
        pDustbin->iAuthorizedWeight = iAuthorizedWeight;
 
507
        myData.pDustbinsList = g_list_prepend (myData.pDustbinsList, pDustbin);
 
508
        
 
509
        if (cairo_dock_fm_add_monitor_full (cDustbinPath, TRUE, NULL, (CairoDockFMMonitorCallback) cd_dustbin_on_file_event, pDustbin))
 
510
        {
 
511
                pDustbin->iNbTrashes = cd_dustbin_count_trashes (cDustbinPath);
 
512
                g_atomic_int_add (&myData.iNbTrashes, pDustbin->iNbTrashes);
 
513
                cd_message ("  myConfig.iNbTrashes <- %d", myData.iNbTrashes);
 
514
                return TRUE;
 
515
        }
 
516
        else
 
517
                return FALSE;
 
518
}
 
519
 
 
520
void cd_dustbin_free_dustbin (CdDustbin *pDustbin)
 
521
{
 
522
        g_free (pDustbin->cPath);
 
523
        g_free (pDustbin);
 
524
}
 
525
 
 
526
void cd_dustbin_remove_all_dustbins (void)
 
527
{
 
528
        g_static_rw_lock_writer_lock (&s_mTasksMutex);
 
529
        cd_dustbin_remove_all_messages ();
 
530
        g_static_rw_lock_writer_unlock (&s_mTasksMutex);  // un g_thread_join() serait peut-etre necessaire.
 
531
        
 
532
        CdDustbin *pDustbin;
 
533
        GList *pElement;
 
534
        for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
 
535
        {
 
536
                pDustbin = pElement->data;
 
537
                cairo_dock_fm_remove_monitor_full (pDustbin->cPath, FALSE, NULL);
 
538
                cd_dustbin_free_dustbin (pDustbin);
 
539
        }
 
540
        g_list_free (myData.pDustbinsList);
 
541
        myData.pDustbinsList = NULL;
 
542
        myData.iNbTrashes = 0;
 
543
}