2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
/**********************************************************************************
22
This file is a part of the cairo-dock project,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
**********************************************************************************/
29
#include <librsvg/rsvg.h>
30
#include <librsvg/rsvg-cairo.h>
31
#include "cairo-dock.h"
33
#include "applet-notifications.h"
34
#include "applet-trashes-manager.h"
35
#include "applet-draw.h"
38
static int _cd_dustbin_compare_dustbins (const CdDustbin *pDustbin, const gchar *cDustbinPath)
40
if (pDustbin->cPath == NULL)
42
if (cDustbinPath == NULL)
44
return (strcmp (pDustbin->cPath, cDustbinPath));
46
CdDustbin *cd_dustbin_find_dustbin_from_uri (const gchar *cDustbinPath)
48
GList *pElement = g_list_find_custom (myData.pDustbinsList, cDustbinPath, (GCompareFunc) _cd_dustbin_compare_dustbins);
50
return pElement->data;
56
void cd_dustbin_on_file_event (CairoDockFMEventType iEventType, const gchar *cURI, CdDustbin *pDustbin)
58
g_return_if_fail (pDustbin != NULL);
59
cd_message ("%s (%d,%d)", __func__, myData.iNbFiles, myData.iSize);
60
gchar *cQuickInfo = NULL;
63
case CAIRO_DOCK_FILE_DELETED :
64
cd_message ("1 dechet de moins");
66
g_atomic_int_add (&pDustbin->iNbTrashes, -1);
68
if (g_atomic_int_dec_and_test (&myData.iNbTrashes)) // devient nul.
70
cd_message ("la poubelle se vide");
71
cd_dustbin_remove_all_messages ();
72
g_atomic_int_set (&myData.iNbFiles, 0); // inutile de calculer dans ce cas.
73
g_atomic_int_set (&myData.iSize, 0); // inutile de calculer dans ce cas.
74
pDustbin->iNbFiles = 0;
76
cd_dustbin_draw_quick_info (FALSE); // on redessine juste en-dessous.
77
CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pEmptyBinSurface);
79
else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_TRASHES)
81
cd_dustbin_draw_quick_info (TRUE);
83
else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES || myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
85
cd_dustbin_add_message (NULL, pDustbin);
89
case CAIRO_DOCK_FILE_CREATED :
90
cd_message ("1 dechet de plus");
92
g_atomic_int_add (&pDustbin->iNbTrashes, 1);
94
if (g_atomic_int_exchange_and_add (&myData.iNbTrashes, 1) == 0) // il etait nul avant l'incrementation.
96
cd_message ("la poubelle se remplit");
97
CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pFullBinSurface);
99
if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_TRASHES)
101
cd_dustbin_draw_quick_info (TRUE);
103
else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES || myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
105
cd_dustbin_add_message (g_strdup(cURI), pDustbin);
112
cd_message (" -> myData.iNbTrashes = %d", myData.iNbTrashes);
116
gboolean cd_dustbin_check_trashes (Icon *icon)
118
//g_print ("%s ()\n", __func__);
121
int i = 0, iNewState = 0;
122
const gchar *cFirstFileInBin;
123
GError *erreur = NULL;
126
for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
128
pDustbin = pElement->data;
129
iNewState += cd_dustbin_count_trashes (pDustbin->cPath);
131
//g_print (" myData.iNbTrashes : %d -> %d\n", myData.iNbTrashes, iNewState);
132
if ((myData.iNbTrashes == -1) || (myData.iNbTrashes == 0 && iNewState != 0) || (myData.iNbTrashes != 0 && iNewState == 0))
134
myData.iNbTrashes = iNewState;
137
cd_message (" -> on a vide la corbeille");
138
g_return_val_if_fail (myData.pEmptyBinSurface != NULL, TRUE);
139
CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pEmptyBinSurface);
143
cd_message (" -> on a rempli la corbeille");
144
g_return_val_if_fail (myData.pFullBinSurface != NULL, TRUE);
145
CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pFullBinSurface);
153
void cd_dustbin_draw_quick_info (gboolean bRedraw)
155
if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NONE)
157
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF (NULL);
160
cd_message ("%s (%d)", __func__, myData.iNbTrashes);
161
if (cd_dustbin_is_calculating ())
163
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%s...", (myDesklet != NULL ? D_("calculating") : ""));
165
else if (myData.iNbTrashes == 0)
167
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
171
if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_TRASHES)
173
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%d%s", myData.iNbTrashes, (myDesklet != NULL ? D_(" trashe(s)") : ""));
175
else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES)
177
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%d%s", myData.iNbFiles, (myDesklet != NULL ? D_(" file(s)") : ""));
179
else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
181
CD_APPLET_SET_SIZE_AS_QUICK_INFO (myData.iSize);
187
CD_APPLET_REDRAW_MY_ICON;
192
void cd_dustbin_signal_full_dustbin (void)
194
cd_message ("%s (%d,%d)", __func__, myConfig.iSizeLimit, myConfig.iGlobalSizeLimit);
195
gboolean bOneDustbinFull = FALSE;
198
for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
200
pDustbin = pElement->data;
201
if (myConfig.iSizeLimit != 0 && pDustbin->iSize > myConfig.iSizeLimit)
203
cairo_dock_show_temporary_dialog_with_icon ("%s is full !", myIcon, myContainer, CD_DUSTBIN_DIALOG_DURATION, NULL, pDustbin->cPath);
204
bOneDustbinFull = TRUE;
207
if (! bOneDustbinFull && myConfig.iGlobalSizeLimit != 0 && myData.iSize > myConfig.iGlobalSizeLimit)
209
cairo_dock_show_temporary_dialog_with_icon ("I'm full !", myIcon, myContainer, CD_DUSTBIN_DIALOG_DURATION, NULL);