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

« back to all changes in this revision

Viewing changes to dustbin/src/applet-init.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:
20
20
#include "stdlib.h"
21
21
#include "string.h"
22
22
 
23
 
#include "applet-draw.h"
24
23
#include "applet-config.h"
25
24
#include "applet-notifications.h"
26
25
#include "applet-trashes-manager.h"
29
28
 
30
29
 
31
30
CD_APPLET_DEFINITION (N_("dustbin"),
32
 
        1, 6, 2,
33
 
        CAIRO_DOCK_CATEGORY_DESKTOP,
 
31
        2, 2, 0,
 
32
        CAIRO_DOCK_CATEGORY_APPLET_FILES,
34
33
        N_("This applet manages the dustbin\n"
35
34
        "You can threw files and unmount disks by drag andn droping them on the icon.\n"
36
35
        "The applet can warn you if you use too much space\n"
37
36
        "Middle-click to display usefull info about the dustbin."),
38
37
        "Fabounet (Fabrice Rey)")
39
38
 
40
 
 
41
 
static void _load_theme (GError **erreur)
 
39
static void _get_theme (void)
42
40
{
43
 
        //\_______________ On charge en priorite les images utilisateur.
44
41
        if (myConfig.cEmptyUserImage != NULL)
45
42
        {
46
 
                gchar *cUserImagePath = cairo_dock_generate_file_path (myConfig.cEmptyUserImage);
47
 
                myData.pEmptyBinSurface = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cUserImagePath);
48
 
                g_free (cUserImagePath);
 
43
                gchar *cPath = cairo_dock_search_icon_s_path (myConfig.cEmptyUserImage);
 
44
                if (! g_file_test (cPath, G_FILE_TEST_EXISTS))
 
45
                {
 
46
                        g_free (myConfig.cEmptyUserImage);
 
47
                        myConfig.cEmptyUserImage = NULL;
 
48
                }
 
49
                g_free (cPath);
49
50
        }
50
51
        if (myConfig.cFullUserImage != NULL)
51
52
        {
52
 
                gchar *cUserImagePath = cairo_dock_generate_file_path (myConfig.cFullUserImage);
53
 
                myData.pFullBinSurface = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cUserImagePath);
54
 
                g_free (cUserImagePath);
55
 
        }
56
 
        
57
 
        //\_______________ On charge le theme si necessaire.
58
 
        if (myConfig.cThemePath != NULL && (myData.pEmptyBinSurface == NULL || myData.pFullBinSurface == NULL))
59
 
        {
60
 
                GError *tmp_erreur = NULL;
61
 
                GDir *dir = g_dir_open (myConfig.cThemePath, 0, &tmp_erreur);
62
 
                if (tmp_erreur != NULL)
63
 
                {
64
 
                        g_propagate_error (erreur, tmp_erreur);
65
 
                        return ;
66
 
                }
67
 
                
68
 
                const gchar *cElementName;
69
 
                gchar *cElementPath;
70
 
                while ((cElementName = g_dir_read_name (dir)) != NULL)
71
 
                {
72
 
                        cElementPath = g_strdup_printf ("%s/%s", myConfig.cThemePath, cElementName);
73
 
                        cd_message ("  %s\n", cElementPath);
74
 
                        if (strncmp (cElementName, "trashcan_full", 13) == 0 && myConfig.cFullUserImage == NULL)
75
 
                        {
76
 
                                myData.cDialogIconPath = cElementPath;
77
 
                                myData.pFullBinSurface = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cElementPath);
78
 
                        }
79
 
                        else
80
 
                        {
81
 
                                if (strncmp (cElementName, "trashcan_empty", 14) == 0 && myData.pEmptyBinSurface == NULL)
82
 
                                        myData.pEmptyBinSurface = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cElementPath);
83
 
                                g_free (cElementPath);
84
 
                        }
85
 
                }
86
 
                g_dir_close (dir);
87
 
        }
88
 
        if (myData.pFullBinSurface == NULL || myData.pFullBinSurface == NULL)
89
 
        {
90
 
                cd_warning ("dustbin : couldn't find images, check the existence of te files in %s", myConfig.cThemePath);
91
 
        }
92
 
}
93
 
 
94
 
static void _cd_dusbin_start (CairoDockModuleInstance *myApplet)
95
 
{
96
 
        //\_______________ On commence a surveiller les repertoires.
97
 
        gboolean bMonitoringOK = FALSE;
98
 
        gchar *cDustbinPath = cairo_dock_fm_get_trash_path (g_getenv ("HOME"), NULL);
99
 
        if (cDustbinPath != NULL)
100
 
                bMonitoringOK = cd_dustbin_add_one_dustbin (cDustbinPath, 0);  // cDustbinPath ne nous appartient plus.
101
 
        
102
 
        if (myConfig.cAdditionnalDirectoriesList != NULL)
103
 
        {
104
 
                int i = 0;
105
 
                while (myConfig.cAdditionnalDirectoriesList[i] != NULL)
106
 
                {
107
 
                        if (*myConfig.cAdditionnalDirectoriesList[i] == '\0' || *myConfig.cAdditionnalDirectoriesList[i] == ' ')
108
 
                        {
109
 
                                cd_warning ("dustbin : this directory (%s) is not valid, be careful with it !", myConfig.cAdditionnalDirectoriesList[i]);
110
 
                                i ++;
111
 
                                continue ;
112
 
                        }
113
 
                        if (*myConfig.cAdditionnalDirectoriesList[i] == '~')
114
 
                                bMonitoringOK |= cd_dustbin_add_one_dustbin (g_strdup_printf ("%s%s", getenv ("HOME"), myConfig.cAdditionnalDirectoriesList[i]+1), 0);
115
 
                        else
116
 
                                bMonitoringOK |= cd_dustbin_add_one_dustbin (g_strdup (myConfig.cAdditionnalDirectoriesList[i]), 0);
117
 
                        i ++;
118
 
                }
119
 
                cd_message ("  %d dossier(s) poubelle", i);
120
 
        }
121
 
        cd_message ("  %d dechet(s) actuellement (%d)", myData.iNbTrashes, bMonitoringOK);
122
 
        
123
 
        //\_______________ On met l'icone qui va bien.
124
 
        if (myData.iNbTrashes <= 0)
125
 
        {
126
 
                CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pEmptyBinSurface);
127
 
        }
128
 
        else
129
 
        {
130
 
                CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pFullBinSurface);
131
 
        }
132
 
        
133
 
        //\_______________ On lance le comptage de nos poubelles.
134
 
        if (bMonitoringOK)
135
 
        {
136
 
                if (myConfig.iQuickInfoType == CD_DUSTBIN_INFO_NB_FILES || myConfig.iQuickInfoType == CD_DUSTBIN_INFO_WEIGHT)
137
 
                {
138
 
                        cd_dustbin_add_message (NULL, NULL);
139
 
                }
140
 
                else
141
 
                {
142
 
                        cd_dustbin_draw_quick_info (FALSE);
143
 
                }
144
 
        }
145
 
        else  // methode par defaut.
146
 
        {
147
 
                gchar *cDustbinPath = cairo_dock_fm_get_trash_path (g_getenv ("HOME"), NULL);
148
 
                if (cDustbinPath != NULL)
149
 
                {
150
 
                        if (myConfig.cAdditionnalDirectoriesList != NULL)
151
 
                                g_strfreev (myConfig.cAdditionnalDirectoriesList);
152
 
                        myConfig.cAdditionnalDirectoriesList = g_new0 (gchar *, 2);
153
 
                        myConfig.cAdditionnalDirectoriesList[0] = cDustbinPath;
154
 
                }
155
 
                if (myConfig.cAdditionnalDirectoriesList != NULL)
156
 
                {
157
 
                        cd_message ("***mode degrade");
158
 
                        cd_dustbin_check_trashes (myIcon);
159
 
                        myData.iSidCheckTrashes = g_timeout_add_seconds ((int) (myConfig.fCheckInterval), (GSourceFunc) cd_dustbin_check_trashes, (gpointer) myIcon);
 
53
                gchar *cPath = cairo_dock_search_icon_s_path (myConfig.cFullUserImage);
 
54
                if (! g_file_test (cPath, G_FILE_TEST_EXISTS))
 
55
                {
 
56
                        g_free (myConfig.cFullUserImage);
 
57
                        myConfig.cFullUserImage = NULL;
 
58
                }
 
59
                g_free (cPath);
 
60
        }
 
61
        if (myConfig.cThemePath != NULL)
 
62
        {
 
63
                if (myConfig.cEmptyUserImage == NULL)
 
64
                {
 
65
                        myConfig.cEmptyUserImage = g_strdup_printf ("%s/%s", myConfig.cThemePath, "trashcan_empty.svg");
 
66
                        if (! g_file_test (myConfig.cEmptyUserImage, G_FILE_TEST_EXISTS))
 
67
                        {
 
68
                                g_free (myConfig.cEmptyUserImage);
 
69
                                myConfig.cEmptyUserImage = g_strdup_printf ("%s/%s", myConfig.cThemePath, "trashcan_empty.png");
 
70
                                if (! g_file_test (myConfig.cEmptyUserImage, G_FILE_TEST_EXISTS))
 
71
                                {
 
72
                                        g_free (myConfig.cEmptyUserImage);
 
73
                                        myConfig.cEmptyUserImage = NULL;
 
74
                                        cd_warning ("dustbin : couldn't find an image for empty dustbin, check the existence of the files in %s", myConfig.cThemePath);
 
75
                                }
 
76
                        }
 
77
                }
 
78
                if (myConfig.cFullUserImage == NULL)
 
79
                {
 
80
                        myConfig.cFullUserImage = g_strdup_printf ("%s/%s", myConfig.cThemePath, "trashcan_full.svg");
 
81
                        if (! g_file_test (myConfig.cFullUserImage, G_FILE_TEST_EXISTS))
 
82
                        {
 
83
                                g_free (myConfig.cFullUserImage);
 
84
                                myConfig.cFullUserImage = g_strdup_printf ("%s/%s", myConfig.cThemePath, "trashcan_full.png");
 
85
                                if (! g_file_test (myConfig.cFullUserImage, G_FILE_TEST_EXISTS))
 
86
                                {
 
87
                                        g_free (myConfig.cFullUserImage);
 
88
                                        myConfig.cFullUserImage = NULL;
 
89
                                        cd_warning ("dustbin : couldn't find an image for full dustbin, check the existence of the files in %s", myConfig.cThemePath);
 
90
                                }
 
91
                        }
160
92
                }
161
93
        }
162
94
}
163
95
 
164
96
CD_APPLET_INIT_BEGIN
165
 
        //\_______________ On charge le theme choisi.
166
97
        if (myDesklet)
167
98
        {
168
99
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
169
100
        }
170
101
        
171
 
        GError *erreur = NULL;
172
 
        _load_theme (&erreur);
173
 
        if (erreur != NULL)
174
 
        {
175
 
                cd_warning ("dustbin : %s", erreur->message);
176
 
                g_error_free (erreur);
177
 
                return;
178
 
        }
 
102
        //\_______________ On recupere les images du theme choisi.
 
103
        _get_theme ();
179
104
        
180
105
        //\_______________ On enregistre nos notifications.
181
106
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
183
108
        CD_APPLET_REGISTER_FOR_DROP_DATA_EVENT;
184
109
        CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
185
110
        
186
 
        //\_______________ On demarre la surveillance de nos poubelles.
187
 
        _cd_dusbin_start (myApplet);
 
111
        //\_______________ On demarre la surveillance de la poubelle.
 
112
        cd_dustbin_start (myApplet);
 
113
        CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cEmptyUserImage);
 
114
        
188
115
CD_APPLET_INIT_END
189
116
 
190
117
 
196
123
        CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
197
124
        
198
125
        //\_______________ On stoppe la surveillance.
199
 
        cd_dustbin_remove_all_dustbins ();
 
126
        cd_dustbin_stop (myApplet);
200
127
        
201
 
        if (myData.iSidCheckTrashes != 0)
202
 
        {
203
 
                g_source_remove (myData.iSidCheckTrashes);
204
 
                myData.iSidCheckTrashes = 0;
205
 
        }
206
128
CD_APPLET_STOP_END
207
129
 
208
130
 
209
131
CD_APPLET_RELOAD_BEGIN
210
 
        //\_______________ On recharge notre theme.
211
 
        if (myDesklet)
212
 
        {
213
 
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
214
 
        }
215
 
        
216
 
        if (myData.pEmptyBinSurface != NULL)
217
 
        {
218
 
                cairo_surface_destroy (myData.pEmptyBinSurface);
219
 
                myData.pEmptyBinSurface = NULL;
220
 
        }
221
 
        if (myData.pFullBinSurface != NULL)
222
 
        {
223
 
                cairo_surface_destroy (myData.pFullBinSurface);
224
 
                myData.pFullBinSurface = NULL;
225
 
        }
226
 
        GError *erreur = NULL;
227
 
        _load_theme (&erreur);
228
 
        if (erreur != NULL)
229
 
        {
230
 
                cd_warning ("dustbin : %s", erreur->message);
231
 
                g_error_free (erreur);
232
 
                return TRUE;
233
 
        }
234
 
        
235
132
        //\_______________ On recharge les donnees qui ont pu changer.
236
133
        if (CD_APPLET_MY_CONFIG_CHANGED)
237
134
        {
 
135
                if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED)  // we are now in a desklet, set a renderer.
 
136
                {
 
137
                        CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
138
                }
 
139
                
238
140
                //\_______________ On stoppe la surveillance.
239
 
                cd_dustbin_remove_all_dustbins ();
240
 
                
241
 
                if (myData.iSidCheckTrashes != 0)
242
 
                {
243
 
                        g_source_remove (myData.iSidCheckTrashes);
244
 
                        myData.iSidCheckTrashes = 0;
245
 
                }
 
141
                cd_dustbin_stop (myApplet);
246
142
                
247
143
                //\_______________ On la redemarre.
248
 
                _cd_dusbin_start (myApplet);
249
 
        }
250
 
        else  // on redessine
251
 
        {
252
 
                if (myData.iSidCheckTrashes != 0)
253
 
                        myData.iNbTrashes = -1;
254
 
                else
255
 
                {
256
 
                        cd_dustbin_draw_quick_info (FALSE);
257
 
                        if (myData.iNbTrashes == 0)
258
 
                        {
259
 
                                CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pEmptyBinSurface);
260
 
                        }
261
 
                        else
262
 
                        {
263
 
                                CD_APPLET_SET_SURFACE_ON_MY_ICON (myData.pFullBinSurface);
264
 
                        }
265
 
                }
 
144
                _get_theme ();
 
145
                cd_dustbin_start (myApplet);
 
146
                
 
147
                CD_APPLET_SET_IMAGE_ON_MY_ICON (myData.bDisplayFullIcon ? myConfig.cFullUserImage: myConfig.cEmptyUserImage);
266
148
        }
267
149
CD_APPLET_RELOAD_END