~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to dustbin/src/applet-draw.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 <string.h>
 
29
#include <librsvg/rsvg.h>
 
30
#include <librsvg/rsvg-cairo.h>
 
31
#include "cairo-dock.h"
 
32
 
 
33
#include "applet-notifications.h"
 
34
#include "applet-trashes-manager.h"
 
35
#include "applet-draw.h"
 
36
 
 
37
 
 
38
static int _cd_dustbin_compare_dustbins (const CdDustbin *pDustbin, const gchar *cDustbinPath)
 
39
{
 
40
        if (pDustbin->cPath == NULL)
 
41
                return -1;
 
42
        if (cDustbinPath == NULL)
 
43
                return 1;
 
44
        return (strcmp (pDustbin->cPath, cDustbinPath));
 
45
}
 
46
CdDustbin *cd_dustbin_find_dustbin_from_uri (const gchar *cDustbinPath)
 
47
{
 
48
        GList *pElement = g_list_find_custom (myData.pDustbinsList, cDustbinPath, (GCompareFunc) _cd_dustbin_compare_dustbins);
 
49
        if (pElement != NULL)
 
50
                return pElement->data;
 
51
        else
 
52
                return NULL;
 
53
}
 
54
 
 
55
 
 
56
void cd_dustbin_on_file_event (CairoDockFMEventType iEventType, const gchar *cURI, CdDustbin *pDustbin)
 
57
{
 
58
        g_return_if_fail (pDustbin != NULL);
 
59
        cd_message ("%s (%d,%d)", __func__, myData.iNbFiles, myData.iSize);
 
60
        gchar *cQuickInfo = NULL;
 
61
        switch (iEventType)
 
62
        {
 
63
                case CAIRO_DOCK_FILE_DELETED :
 
64
                        cd_message ("1 dechet de moins");
 
65
                        
 
66
                        g_atomic_int_add (&pDustbin->iNbTrashes, -1);
 
67
                        
 
68
                        if (g_atomic_int_dec_and_test (&myData.iNbTrashes))  // devient nul.
 
69
                        {
 
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;
 
75
                                pDustbin->iSize = 0;
 
76
                                cd_dustbin_draw_quick_info (FALSE);  // on redessine juste en-dessous.
 
77
                                CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pEmptyBinSurface);
 
78
                        }
 
79
                        else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_TRASHES)
 
80
                        {
 
81
                                cd_dustbin_draw_quick_info (TRUE);
 
82
                        }
 
83
                        else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES || myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
 
84
                        {
 
85
                                cd_dustbin_add_message (NULL, pDustbin);
 
86
                        }
 
87
                break ;
 
88
                
 
89
                case CAIRO_DOCK_FILE_CREATED :
 
90
                        cd_message ("1 dechet de plus");
 
91
                        
 
92
                        g_atomic_int_add (&pDustbin->iNbTrashes, 1);
 
93
                        
 
94
                        if (g_atomic_int_exchange_and_add (&myData.iNbTrashes, 1) == 0)  // il etait nul avant l'incrementation.
 
95
                        {
 
96
                                cd_message ("la poubelle se remplit");
 
97
                                CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pFullBinSurface);
 
98
                        }
 
99
                        if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_TRASHES)
 
100
                        {
 
101
                                cd_dustbin_draw_quick_info (TRUE);
 
102
                        }
 
103
                        else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES || myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
 
104
                        {
 
105
                                cd_dustbin_add_message (g_strdup(cURI), pDustbin);
 
106
                        }
 
107
                break ;
 
108
                
 
109
                default :
 
110
                        break;
 
111
        }
 
112
        cd_message (" -> myData.iNbTrashes = %d", myData.iNbTrashes);
 
113
}
 
114
 
 
115
 
 
116
gboolean cd_dustbin_check_trashes (Icon *icon)
 
117
{
 
118
        //g_print ("%s ()\n", __func__);
 
119
        
 
120
        GDir *dir;
 
121
        int i = 0, iNewState = 0;
 
122
        const gchar *cFirstFileInBin;
 
123
        GError *erreur = NULL;
 
124
        CdDustbin *pDustbin;
 
125
        GList *pElement;
 
126
        for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
 
127
        {
 
128
                pDustbin = pElement->data;
 
129
                iNewState += cd_dustbin_count_trashes (pDustbin->cPath);
 
130
        }
 
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))
 
133
        {
 
134
                myData.iNbTrashes = iNewState;
 
135
                if (iNewState == 0)
 
136
                {
 
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);
 
140
                }
 
141
                else
 
142
                {
 
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);
 
146
                }
 
147
        }
 
148
        
 
149
        return TRUE;
 
150
}
 
151
 
 
152
 
 
153
void cd_dustbin_draw_quick_info (gboolean bRedraw)
 
154
{
 
155
        if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NONE)
 
156
        {
 
157
                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF (NULL);
 
158
                return ;
 
159
        }
 
160
        cd_message ("%s (%d)", __func__, myData.iNbTrashes);
 
161
        if (cd_dustbin_is_calculating ())
 
162
        {
 
163
                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%s...", (myDesklet != NULL ? D_("calculating") : ""));
 
164
        }
 
165
        else if (myData.iNbTrashes == 0)
 
166
        {
 
167
                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
 
168
        }
 
169
        else
 
170
        {
 
171
                if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_TRASHES)
 
172
                {
 
173
                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%d%s", myData.iNbTrashes, (myDesklet != NULL ? D_(" trashe(s)") : ""));
 
174
                }
 
175
                else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES)
 
176
                {
 
177
                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%d%s", myData.iNbFiles, (myDesklet != NULL ? D_(" file(s)") : ""));
 
178
                }
 
179
                else if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
 
180
                {
 
181
                        CD_APPLET_SET_SIZE_AS_QUICK_INFO (myData.iSize);
 
182
                }
 
183
        }
 
184
        
 
185
        if (bRedraw)
 
186
        {
 
187
                CD_APPLET_REDRAW_MY_ICON;
 
188
        }
 
189
}
 
190
 
 
191
 
 
192
void cd_dustbin_signal_full_dustbin (void)
 
193
{
 
194
        cd_message ("%s (%d,%d)", __func__, myConfig.iSizeLimit, myConfig.iGlobalSizeLimit);
 
195
        gboolean bOneDustbinFull = FALSE;
 
196
        CdDustbin *pDustbin;
 
197
        GList *pElement;
 
198
        for (pElement = myData.pDustbinsList; pElement != NULL; pElement = pElement->next)
 
199
        {
 
200
                pDustbin = pElement->data;
 
201
                if (myConfig.iSizeLimit != 0 && pDustbin->iSize > myConfig.iSizeLimit)
 
202
                {
 
203
                        cairo_dock_show_temporary_dialog_with_icon ("%s is full !", myIcon, myContainer, CD_DUSTBIN_DIALOG_DURATION, NULL, pDustbin->cPath);
 
204
                        bOneDustbinFull = TRUE;
 
205
                }
 
206
        }
 
207
        if (! bOneDustbinFull && myConfig.iGlobalSizeLimit != 0 && myData.iSize > myConfig.iGlobalSizeLimit)
 
208
        {
 
209
                cairo_dock_show_temporary_dialog_with_icon ("I'm full !", myIcon, myContainer, CD_DUSTBIN_DIALOG_DURATION, NULL);
 
210
        }
 
211
}