~cairo-dock-team/ubuntu/oneiric/cairo-dock/2.3.0-3

« back to all changes in this revision

Viewing changes to src/cairo-dock-config.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2010-08-09 23:26:12 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20100809232612-pocdxliaxjdetm37
Tags: upstream-2.2.0~0beta4
ImportĀ upstreamĀ versionĀ 2.2.0~0beta4

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
 
#include <math.h>
21
 
#include <string.h>
22
 
 
23
 
#include <gtk/gtk.h>
24
 
 
25
 
#include <stdio.h>
26
 
#include <stdlib.h>
27
 
 
28
 
#ifdef HAVE_LIBCRYPT
29
 
/* libC crypt */
30
 
#include <crypt.h>
31
 
 
32
 
static char DES_crypt_key[64] =
33
 
{
34
 
    1,0,0,1,1,1,0,0, 1,0,1,1,1,0,1,1, 1,1,0,1,0,1,0,1, 1,1,0,0,0,0,0,1,
35
 
    0,0,0,1,0,1,1,0, 1,1,1,0,1,1,1,0, 1,1,1,0,0,1,0,0, 1,0,1,0,1,0,1,1
36
 
}; 
37
 
#endif
38
 
 
39
 
#include "cairo-dock-draw.h"
40
 
#include "cairo-dock-draw-opengl.h"
41
 
#include "cairo-dock-load.h"
42
 
#include "cairo-dock-icons.h"
43
 
#include "cairo-dock-applications-manager.h"
44
 
#include "cairo-dock-modules.h"
45
 
#include "cairo-dock-keyfile-utilities.h"
46
 
#include "cairo-dock-gui-factory.h"
47
 
#include "cairo-dock-dock-factory.h"
48
 
#include "cairo-dock-themes-manager.h"
49
 
#include "cairo-dock-renderer-manager.h"
50
 
#include "cairo-dock-menu.h"
51
 
#include "cairo-dock-callbacks.h"
52
 
#include "cairo-dock-dialogs.h"
53
 
#include "cairo-dock-X-utilities.h"
54
 
#include "cairo-dock-log.h"
55
 
#include "cairo-dock-keybinder.h"
56
 
#include "cairo-dock-dock-manager.h"
57
 
#include "cairo-dock-surface-factory.h"
58
 
#include "cairo-dock-class-manager.h"
59
 
#include "cairo-dock-gauge.h"
60
 
#include "cairo-dock-gui-manager.h"
61
 
#include "cairo-dock-desklet.h"
62
 
#include "cairo-dock-internal-position.h"
63
 
#include "cairo-dock-internal-accessibility.h"
64
 
#include "cairo-dock-internal-system.h"
65
 
#include "cairo-dock-internal-taskbar.h"
66
 
#include "cairo-dock-internal-dialogs.h"
67
 
#include "cairo-dock-internal-indicators.h"
68
 
#include "cairo-dock-internal-views.h"
69
 
#include "cairo-dock-internal-labels.h"
70
 
#include "cairo-dock-internal-desklets.h"
71
 
#include "cairo-dock-internal-icons.h"
72
 
#include "cairo-dock-internal-background.h"
73
 
#include "cairo-dock-container.h"
74
 
#include "cairo-dock-dock-facility.h"
75
 
#include "cairo-dock-file-manager.h"
76
 
#include "cairo-dock-animations.h"
77
 
#include "cairo-dock-config.h"
78
 
 
79
 
extern CairoDock *g_pMainDock;
80
 
extern gchar *g_cCurrentThemePath;
81
 
extern gchar *g_cCairoDockDataDir;
82
 
extern gchar *g_cCurrentLaunchersPath;
83
 
extern CairoDockImageBuffer g_pDockBackgroundBuffer;
84
 
extern CairoDockDesktopBackground *g_pFakeTransparencyDesktopBg;
85
 
extern gboolean g_bUseOpenGL;
86
 
extern CairoDockDesktopEnv g_iDesktopEnv;
87
 
 
88
 
static gboolean s_bLoading = FALSE;
89
 
 
90
 
 
91
 
gboolean cairo_dock_get_boolean_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, gboolean bDefaultValue, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName)
92
 
{
93
 
        GError *erreur = NULL;
94
 
        gboolean bValue = g_key_file_get_boolean (pKeyFile, cGroupName, cKeyName, &erreur);
95
 
        if (erreur != NULL)
96
 
        {
97
 
                if (bFlushConfFileNeeded != NULL)
98
 
                        cd_warning (erreur->message);
99
 
                g_error_free (erreur);
100
 
                erreur = NULL;
101
 
 
102
 
                gchar* cGroupNameUpperCase = g_ascii_strup (cGroupName, -1);
103
 
                bValue = g_key_file_get_boolean (pKeyFile, cGroupNameUpperCase, cKeyName, &erreur);
104
 
                g_free (cGroupNameUpperCase);
105
 
                if (erreur != NULL)
106
 
                {
107
 
                        g_error_free (erreur);
108
 
                        erreur = NULL;
109
 
                        bValue = g_key_file_get_boolean (pKeyFile, "Cairo Dock", cKeyName, &erreur);
110
 
                        if (erreur != NULL)
111
 
                        {
112
 
                                g_error_free (erreur);
113
 
                                erreur = NULL;
114
 
                                bValue = g_key_file_get_boolean (pKeyFile, (cDefaultGroupName != NULL ? cDefaultGroupName : cGroupName), (cDefaultKeyName != NULL ? cDefaultKeyName : cKeyName), &erreur);
115
 
                                if (erreur != NULL)
116
 
                                {
117
 
                                        g_error_free (erreur);
118
 
                                        bValue = bDefaultValue;
119
 
                                }
120
 
                                else
121
 
                                        cd_message (" (recuperee)");
122
 
                        }
123
 
                        else
124
 
                                cd_message (" (recuperee)");
125
 
                }
126
 
 
127
 
                g_key_file_set_boolean (pKeyFile, cGroupName, cKeyName, bValue);
128
 
                if (bFlushConfFileNeeded != NULL)
129
 
                        *bFlushConfFileNeeded = TRUE;
130
 
        }
131
 
        return bValue;
132
 
}
133
 
 
134
 
int cairo_dock_get_integer_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, int iDefaultValue, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName)
135
 
{
136
 
        GError *erreur = NULL;
137
 
        int iValue = g_key_file_get_integer (pKeyFile, cGroupName, cKeyName, &erreur);
138
 
        if (erreur != NULL)
139
 
        {
140
 
                if (bFlushConfFileNeeded != NULL)
141
 
                        cd_warning (erreur->message);
142
 
                g_error_free (erreur);
143
 
                erreur = NULL;
144
 
 
145
 
                gchar* cGroupNameUpperCase = g_ascii_strup (cGroupName, -1);
146
 
                iValue = g_key_file_get_integer (pKeyFile, cGroupNameUpperCase, cKeyName, &erreur);
147
 
                if (erreur != NULL)
148
 
                {
149
 
                        g_error_free (erreur);
150
 
                        erreur = NULL;
151
 
                        iValue = g_key_file_get_integer (pKeyFile, "Cairo Dock", cKeyName, &erreur);
152
 
                        if (erreur != NULL)
153
 
                        {
154
 
                                g_error_free (erreur);
155
 
                                erreur = NULL;
156
 
                                iValue = g_key_file_get_integer (pKeyFile, (cDefaultGroupName != NULL ? cDefaultGroupName : cGroupName), (cDefaultKeyName != NULL ? cDefaultKeyName : cKeyName), &erreur);
157
 
                                if (erreur != NULL)
158
 
                                {
159
 
                                        g_error_free (erreur);
160
 
                                        iValue = iDefaultValue;
161
 
                                }
162
 
                                else
163
 
                                        cd_message (" (recuperee)");
164
 
                        }
165
 
                        else
166
 
                                cd_message (" (recuperee)");
167
 
                }
168
 
                g_free (cGroupNameUpperCase);
169
 
 
170
 
                g_key_file_set_integer (pKeyFile, cGroupName, cKeyName, iValue);
171
 
                if (bFlushConfFileNeeded != NULL)
172
 
                        *bFlushConfFileNeeded = TRUE;
173
 
        }
174
 
        return iValue;
175
 
}
176
 
 
177
 
double cairo_dock_get_double_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, double fDefaultValue, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName)
178
 
{
179
 
        GError *erreur = NULL;
180
 
        double fValue = g_key_file_get_double (pKeyFile, cGroupName, cKeyName, &erreur);
181
 
        if (erreur != NULL)
182
 
        {
183
 
                if (bFlushConfFileNeeded != NULL)
184
 
                        cd_warning (erreur->message);
185
 
                g_error_free (erreur);
186
 
                erreur = NULL;
187
 
 
188
 
                gchar* cGroupNameUpperCase = g_ascii_strup (cGroupName, -1);
189
 
                fValue = g_key_file_get_double (pKeyFile, cGroupNameUpperCase, cKeyName, &erreur);
190
 
                if (erreur != NULL)
191
 
                {
192
 
                        g_error_free (erreur);
193
 
                        erreur = NULL;
194
 
                        fValue = g_key_file_get_double (pKeyFile, "Cairo Dock", cKeyName, &erreur);
195
 
                        if (erreur != NULL)
196
 
                        {
197
 
                                g_error_free (erreur);
198
 
                                erreur = NULL;
199
 
                                fValue = g_key_file_get_double (pKeyFile, (cDefaultGroupName != NULL ? cDefaultGroupName : cGroupName), (cDefaultKeyName != NULL ? cDefaultKeyName : cKeyName), &erreur);
200
 
                                if (erreur != NULL)
201
 
                                {
202
 
                                        g_error_free (erreur);
203
 
                                        fValue = fDefaultValue;
204
 
                                }
205
 
                                else
206
 
                                        cd_message (" (recuperee)");
207
 
                        }
208
 
                        else
209
 
                                cd_message (" (recuperee)");
210
 
                }
211
 
                g_free (cGroupNameUpperCase);
212
 
 
213
 
                g_key_file_set_double (pKeyFile, cGroupName, cKeyName, fValue);
214
 
                if (bFlushConfFileNeeded != NULL)
215
 
                        *bFlushConfFileNeeded = TRUE;
216
 
        }
217
 
        return fValue;
218
 
}
219
 
 
220
 
gchar *cairo_dock_get_string_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, const gchar *cDefaultValue, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName)
221
 
{
222
 
        GError *erreur = NULL;
223
 
        gchar *cValue = g_key_file_get_string (pKeyFile, cGroupName, cKeyName, &erreur);
224
 
        if (erreur != NULL)
225
 
        {
226
 
                if (bFlushConfFileNeeded != NULL)
227
 
                        cd_warning (erreur->message);
228
 
                g_error_free (erreur);
229
 
                erreur = NULL;
230
 
 
231
 
                gchar* cGroupNameUpperCase = g_ascii_strup (cGroupName, -1);
232
 
                cValue = g_key_file_get_string (pKeyFile, cGroupNameUpperCase, cKeyName, &erreur);
233
 
                if (erreur != NULL)
234
 
                {
235
 
                        g_error_free (erreur);
236
 
                        erreur = NULL;
237
 
                        cValue = g_key_file_get_string (pKeyFile, "Cairo Dock", cKeyName, &erreur);
238
 
                        if (erreur != NULL)
239
 
                        {
240
 
                                g_error_free (erreur);
241
 
                                erreur = NULL;
242
 
                                cValue = g_key_file_get_string (pKeyFile, (cDefaultGroupName != NULL ? cDefaultGroupName : cGroupName), (cDefaultKeyName != NULL ? cDefaultKeyName : cKeyName), &erreur);
243
 
                                if (erreur != NULL)
244
 
                                {
245
 
                                        g_error_free (erreur);
246
 
                                        cValue = g_strdup (cDefaultValue);
247
 
                                }
248
 
                                else
249
 
                                        cd_message (" (recuperee)");
250
 
                        }
251
 
                        else
252
 
                                cd_message (" (recuperee)");
253
 
                }
254
 
                g_free (cGroupNameUpperCase);
255
 
 
256
 
                g_key_file_set_string (pKeyFile, cGroupName, cKeyName, (cValue != NULL ? cValue : ""));
257
 
                if (bFlushConfFileNeeded != NULL)
258
 
                        *bFlushConfFileNeeded = TRUE;
259
 
        }
260
 
        if (cValue != NULL && *cValue == '\0')
261
 
        {
262
 
                g_free (cValue);
263
 
                cValue = NULL;
264
 
        }
265
 
        return cValue;
266
 
}
267
 
 
268
 
void cairo_dock_get_integer_list_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, int *iValueBuffer, guint iNbElements, int *iDefaultValues, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName)
269
 
{
270
 
        GError *erreur = NULL;
271
 
        gsize length = 0;
272
 
        if (iDefaultValues != NULL)
273
 
                memcpy (iValueBuffer, iDefaultValues, iNbElements * sizeof (int));
274
 
 
275
 
        int *iValuesList = g_key_file_get_integer_list (pKeyFile, cGroupName, cKeyName, &length, &erreur);
276
 
        if (erreur != NULL)
277
 
        {
278
 
                if (bFlushConfFileNeeded != NULL)
279
 
                        cd_warning (erreur->message);
280
 
                g_error_free (erreur);
281
 
                erreur = NULL;
282
 
 
283
 
                gchar* cGroupNameUpperCase = g_ascii_strup (cGroupName, -1);
284
 
                iValuesList = g_key_file_get_integer_list (pKeyFile, cGroupNameUpperCase, cKeyName, &length, &erreur);
285
 
                if (erreur != NULL)
286
 
                {
287
 
                        g_error_free (erreur);
288
 
                        erreur = NULL;
289
 
                        iValuesList = g_key_file_get_integer_list (pKeyFile, "Cairo Dock", cKeyName, &length, &erreur);
290
 
                        if (erreur != NULL)
291
 
                        {
292
 
                                g_error_free (erreur);
293
 
                                erreur = NULL;
294
 
                                iValuesList = g_key_file_get_integer_list (pKeyFile, (cDefaultGroupName != NULL ? cDefaultGroupName : cGroupName), (cDefaultKeyName != NULL ? cDefaultKeyName : cKeyName), &length, &erreur);
295
 
                                if (erreur != NULL)
296
 
                                {
297
 
                                        g_error_free (erreur);
298
 
                                }
299
 
                                else
300
 
                                {
301
 
                                        cd_message (" (recuperee)");
302
 
                                        if (length > 0)
303
 
                                                memcpy (iValueBuffer, iValuesList, MIN (iNbElements, length) * sizeof (int));
304
 
                                }
305
 
                        }
306
 
                        else
307
 
                        {
308
 
                                cd_message (" (recuperee)");
309
 
                                if (length > 0)
310
 
                                        memcpy (iValueBuffer, iValuesList, MIN (iNbElements, length) * sizeof (int));
311
 
                        }
312
 
                }
313
 
                else
314
 
                {
315
 
                        if (length > 0)
316
 
                                memcpy (iValueBuffer, iValuesList, MIN (iNbElements, length) * sizeof (int));
317
 
                }
318
 
                g_free (cGroupNameUpperCase);
319
 
                
320
 
                if (iDefaultValues != NULL)  // on ne modifie les valeurs actuelles que si on a explicitement passe des valeurs par defaut en entree; sinon on considere que l'on va traiter le cas en aval.
321
 
                        g_key_file_set_integer_list (pKeyFile, cGroupName, cKeyName, iValueBuffer, iNbElements);
322
 
                if (bFlushConfFileNeeded != NULL)
323
 
                        *bFlushConfFileNeeded = TRUE;
324
 
        }
325
 
        else
326
 
        {
327
 
                if (length > 0)
328
 
                        memcpy (iValueBuffer, iValuesList, MIN (iNbElements, length) * sizeof (int));
329
 
        }
330
 
        g_free (iValuesList);
331
 
}
332
 
 
333
 
void cairo_dock_get_double_list_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, double *fValueBuffer, guint iNbElements, double *fDefaultValues, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName)
334
 
{
335
 
        GError *erreur = NULL;
336
 
        gsize length = 0;
337
 
        if (fDefaultValues != NULL)
338
 
                memcpy (fValueBuffer, fDefaultValues, iNbElements * sizeof (double));
339
 
 
340
 
        double *fValuesList = g_key_file_get_double_list (pKeyFile, cGroupName, cKeyName, &length, &erreur);
341
 
        if (erreur != NULL)
342
 
        {
343
 
                if (bFlushConfFileNeeded != NULL)
344
 
                        cd_warning (erreur->message);
345
 
                g_error_free (erreur);
346
 
                erreur = NULL;
347
 
 
348
 
                gchar* cGroupNameUpperCase = g_ascii_strup (cGroupName, -1);
349
 
                fValuesList = g_key_file_get_double_list (pKeyFile, cGroupNameUpperCase, cKeyName, &length, &erreur);
350
 
                if (erreur != NULL)
351
 
                {
352
 
                        g_error_free (erreur);
353
 
                        erreur = NULL;
354
 
                        fValuesList = g_key_file_get_double_list (pKeyFile, "Cairo Dock", cKeyName, &length, &erreur);
355
 
                        if (erreur != NULL)
356
 
                        {
357
 
                                g_error_free (erreur);
358
 
                                erreur = NULL;
359
 
                                fValuesList = g_key_file_get_double_list (pKeyFile, (cDefaultGroupName != NULL ? cDefaultGroupName : cGroupName), (cDefaultKeyName != NULL ? cDefaultKeyName : cKeyName), &length, &erreur);
360
 
                                if (erreur != NULL)
361
 
                                {
362
 
                                        g_error_free (erreur);
363
 
                                }
364
 
                                else
365
 
                                {
366
 
                                        cd_message (" (recuperee)");
367
 
                                        if (length > 0)
368
 
                                                memcpy (fValueBuffer, fValuesList, MIN (iNbElements, length) * sizeof (double));
369
 
                                }
370
 
                        }
371
 
                        else
372
 
                        {
373
 
                                cd_message (" (recuperee)");
374
 
                                if (length > 0)
375
 
                                        memcpy (fValueBuffer, fValuesList, MIN (iNbElements, length) * sizeof (double));
376
 
                        }
377
 
                }
378
 
                else
379
 
                {
380
 
                        if (length > 0)
381
 
                                memcpy (fValueBuffer, fValuesList, MIN (iNbElements, length) * sizeof (double));
382
 
                }
383
 
                g_free (cGroupNameUpperCase);
384
 
 
385
 
                g_key_file_set_double_list (pKeyFile, cGroupName, cKeyName, fValueBuffer, iNbElements);
386
 
                if (bFlushConfFileNeeded != NULL)
387
 
                        *bFlushConfFileNeeded = TRUE;
388
 
        }
389
 
        else
390
 
        {
391
 
                if (length > 0)
392
 
                        memcpy (fValueBuffer, fValuesList, MIN (iNbElements, length) * sizeof (double));
393
 
        }
394
 
        g_free (fValuesList);
395
 
}
396
 
 
397
 
gchar **cairo_dock_get_string_list_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, gsize *length, const gchar *cDefaultValues, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName)
398
 
{
399
 
        GError *erreur = NULL;
400
 
        *length = 0;
401
 
        gchar **cValuesList = g_key_file_get_string_list (pKeyFile, cGroupName, cKeyName, length, &erreur);
402
 
        if (erreur != NULL)
403
 
        {
404
 
                if (bFlushConfFileNeeded != NULL)
405
 
                        cd_warning (erreur->message);
406
 
                g_error_free (erreur);
407
 
                erreur = NULL;
408
 
 
409
 
                gchar* cGroupNameUpperCase = g_ascii_strup (cGroupName, -1);
410
 
                cValuesList = g_key_file_get_string_list (pKeyFile, cGroupNameUpperCase, cKeyName, length, &erreur);
411
 
                if (erreur != NULL)
412
 
                {
413
 
                        g_error_free (erreur);
414
 
                        erreur = NULL;
415
 
                        cValuesList = g_key_file_get_string_list (pKeyFile, (cDefaultGroupName != NULL ? cDefaultGroupName : cGroupName), (cDefaultKeyName != NULL ? cDefaultKeyName : cKeyName), length, &erreur);
416
 
                        if (erreur != NULL)
417
 
                        {
418
 
                                g_error_free (erreur);
419
 
                                cValuesList = g_strsplit (cDefaultValues, ";", -1);  // "" -> NULL.
420
 
                                int i = 0;
421
 
                                if (cValuesList != NULL)
422
 
                                {
423
 
                                        while (cValuesList[i] != NULL)
424
 
                                                i ++;
425
 
                                }
426
 
                                *length = i;
427
 
                        }
428
 
                }
429
 
                g_free (cGroupNameUpperCase);
430
 
 
431
 
                if (*length > 0)
432
 
                        g_key_file_set_string_list (pKeyFile, cGroupName, cKeyName, (const gchar **)cValuesList, *length);
433
 
                else
434
 
                        g_key_file_set_string (pKeyFile, cGroupName, cKeyName, "");
435
 
                if (bFlushConfFileNeeded != NULL)
436
 
                        *bFlushConfFileNeeded = TRUE;
437
 
        }
438
 
        if (cValuesList != NULL && (cValuesList[0] == NULL || (*(cValuesList[0]) == '\0' && *length == 1)))
439
 
        {
440
 
                g_strfreev (cValuesList);
441
 
                cValuesList = NULL;
442
 
                *length = 0;
443
 
        }
444
 
        return cValuesList;
445
 
}
446
 
 
447
 
gchar *cairo_dock_get_file_path_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName, const gchar *cDefaultDir, const gchar *cDefaultFileName)
448
 
{
449
 
        gchar *cFileName = cairo_dock_get_string_key_value (pKeyFile, cGroupName, cKeyName, bFlushConfFileNeeded, NULL, cDefaultGroupName, cDefaultKeyName);
450
 
        gchar *cFilePath = NULL;
451
 
        if (cFileName != NULL)
452
 
                cFilePath = cairo_dock_generate_file_path (cFileName);
453
 
        else if (cDefaultFileName != NULL && cDefaultDir != NULL)
454
 
                cFilePath = g_strdup_printf ("%s/%s", cDefaultDir, cDefaultFileName);
455
 
        return cFilePath;
456
 
}
457
 
void cairo_dock_get_size_key_value (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, gint iDefaultSize, const gchar *cDefaultGroupName, const gchar *cDefaultKeyName, int *iWidth, int *iHeight)
458
 
{
459
 
        int iSize[2];
460
 
        int iDefaultValues[2] = {iDefaultSize, iDefaultSize};
461
 
        cairo_dock_get_integer_list_key_value (pKeyFile, cGroupName, cKeyName, bFlushConfFileNeeded, iSize, 2, iDefaultValues, cDefaultGroupName, cDefaultKeyName);
462
 
        *iWidth = iSize[0];
463
 
        *iHeight = iSize[1];
464
 
}
465
 
 
466
 
 
467
 
void cairo_dock_read_conf_file (const gchar *cConfFilePath, CairoDock *pDock)
468
 
{
469
 
        //g_print ("%s (%s)\n", __func__, cConfFilePath);
470
 
        GError *erreur = NULL;
471
 
        gsize length;
472
 
        gboolean bFlushConfFileNeeded = FALSE, bFlushConfFileNeeded2 = FALSE;  // si un champ n'existe pas, on le rajoute au fichier de conf.
473
 
 
474
 
        //\___________________ On ouvre le fichier de conf.
475
 
        GKeyFile *pKeyFile = cairo_dock_open_key_file (cConfFilePath);
476
 
        if (pKeyFile == NULL)
477
 
                return ;
478
 
        
479
 
        s_bLoading = TRUE;
480
 
        
481
 
        //\___________________ On garde une trace de certains parametres.
482
 
        gchar *cRaiseDockShortcutOld = myAccessibility.cRaiseDockShortcut;
483
 
        myAccessibility.cRaiseDockShortcut = NULL;
484
 
        gboolean bPopUpOld = myAccessibility.bPopUp;  // FALSE initialement.
485
 
        gboolean bUseFakeTransparencyOld = mySystem.bUseFakeTransparency;  // FALSE initialement.
486
 
        gboolean bGroupAppliByClassOld = myTaskBar.bGroupAppliByClass;  // FALSE initialement.
487
 
        gboolean bHideVisibleApplisOld = myTaskBar.bHideVisibleApplis;
488
 
        gboolean bAppliOnCurrentDesktopOnlyOld = myTaskBar.bAppliOnCurrentDesktopOnly;
489
 
        gboolean bMixLauncherAppliOld = myTaskBar.bMixLauncherAppli;
490
 
        gboolean bOverWriteXIconsOld = myTaskBar.bOverWriteXIcons;  // TRUE initialement.
491
 
        gint iMinimizedWindowRenderTypeOld = myTaskBar.iMinimizedWindowRenderType;
492
 
        gchar *cDeskletDecorationsNameOld = myDesklets.cDeskletDecorationsName;
493
 
        myDesklets.cDeskletDecorationsName = NULL;
494
 
        int iSeparateIconsOld = myIcons.iSeparateIcons;
495
 
        CairoDockIconType tIconTypeOrderOld[CAIRO_DOCK_NB_TYPES];
496
 
        memcpy (tIconTypeOrderOld, myIcons.tIconTypeOrder, sizeof (tIconTypeOrderOld));
497
 
        
498
 
        //\___________________ On recupere la conf de tous les modules.
499
 
        bFlushConfFileNeeded = cairo_dock_get_global_config (pKeyFile);
500
 
        
501
 
        //\___________________ Post-initialisation : parametres impactant le main dock.
502
 
        pDock->iGapX = myPosition.iGapX;
503
 
        pDock->iGapY = myPosition.iGapY;
504
 
        
505
 
        pDock->fAlign = myPosition.fAlign;
506
 
        pDock->bAutoHide = myAccessibility.bAutoHide;
507
 
        
508
 
        gboolean bGroupOrderChanged;
509
 
        if (tIconTypeOrderOld[CAIRO_DOCK_LAUNCHER] != myIcons.tIconTypeOrder[CAIRO_DOCK_LAUNCHER] ||
510
 
                tIconTypeOrderOld[CAIRO_DOCK_APPLI] != myIcons.tIconTypeOrder[CAIRO_DOCK_APPLI] ||
511
 
                tIconTypeOrderOld[CAIRO_DOCK_APPLET] != myIcons.tIconTypeOrder[CAIRO_DOCK_APPLET])
512
 
                bGroupOrderChanged = TRUE;
513
 
        else
514
 
                bGroupOrderChanged = FALSE;
515
 
        
516
 
        if (myPosition.bUseXinerama)
517
 
        {
518
 
                pDock->iNumScreen = myPosition.iNumScreen;
519
 
                cairo_dock_get_screen_offsets (myPosition.iNumScreen, &pDock->iScreenOffsetX, &pDock->iScreenOffsetY);
520
 
        }
521
 
        else
522
 
        {
523
 
                pDock->iNumScreen = pDock->iScreenOffsetX = pDock->iScreenOffsetY = 0;
524
 
        }
525
 
        
526
 
        switch (myPosition.iScreenBorder)
527
 
        {
528
 
                case CAIRO_DOCK_BOTTOM :
529
 
                default :
530
 
                        pDock->container.bIsHorizontal = CAIRO_DOCK_HORIZONTAL;
531
 
                        pDock->container.bDirectionUp = TRUE;
532
 
                break;
533
 
                case CAIRO_DOCK_TOP :
534
 
                        pDock->container.bIsHorizontal = CAIRO_DOCK_HORIZONTAL;
535
 
                        pDock->container.bDirectionUp = FALSE;
536
 
                break;
537
 
                case CAIRO_DOCK_RIGHT :
538
 
                        pDock->container.bIsHorizontal = CAIRO_DOCK_VERTICAL;
539
 
                        pDock->container.bDirectionUp = TRUE;
540
 
                break;
541
 
                case CAIRO_DOCK_LEFT :
542
 
                        pDock->container.bIsHorizontal = CAIRO_DOCK_VERTICAL;
543
 
                        pDock->container.bDirectionUp = FALSE;
544
 
                break;
545
 
        }
546
 
        
547
 
        //\___________________ On (re)charge tout, car n'importe quel parametre peut avoir change.
548
 
        cairo_t* pCairoContext = cairo_dock_create_drawing_context_generic (CAIRO_CONTAINER (pDock));
549
 
        double fMaxScale = cairo_dock_get_max_scale (pDock);
550
 
        
551
 
        // fausse transparence.
552
 
        if (mySystem.bUseFakeTransparency)
553
 
        {
554
 
                if (g_pFakeTransparencyDesktopBg == NULL)
555
 
                {
556
 
                        g_pFakeTransparencyDesktopBg = cairo_dock_get_desktop_background (g_bUseOpenGL);
557
 
                }
558
 
                else if (g_bUseOpenGL)
559
 
                {
560
 
                        CairoDockDesktopBackground *dummy = cairo_dock_get_desktop_background (g_bUseOpenGL);  // pour recharger la texture.
561
 
                        cairo_dock_destroy_desktop_background (dummy);
562
 
                }
563
 
        }
564
 
        else if (g_pFakeTransparencyDesktopBg != NULL)
565
 
        {
566
 
                cairo_dock_destroy_desktop_background (g_pFakeTransparencyDesktopBg);
567
 
                g_pFakeTransparencyDesktopBg = NULL;
568
 
        }
569
 
        
570
 
        //\___________________ on recharge les buffers d'images.
571
 
        cairo_dock_unload_dialog_buttons ();  // on se contente de remettre a zero ces buffers,
572
 
        cairo_dock_unload_desklet_buttons ();  // qui seront charges lorsque necessaire.
573
 
        
574
 
        cairo_dock_load_icons_background_surface (myIcons.cBackgroundImagePath, fMaxScale);
575
 
 
576
 
        cairo_dock_load_box_surface (fMaxScale);
577
 
 
578
 
        cairo_dock_load_task_indicator (myTaskBar.bShowAppli && (myTaskBar.bMixLauncherAppli || myTaskBar.bDrawIndicatorOnAppli) ? myIndicators.cIndicatorImagePath : NULL, fMaxScale, myIndicators.fIndicatorRatio);
579
 
        
580
 
        cairo_dock_load_active_window_indicator (myIndicators.cActiveIndicatorImagePath, fMaxScale, myIndicators.iActiveCornerRadius, myIndicators.iActiveLineWidth, myIndicators.fActiveColor);
581
 
        
582
 
        cairo_dock_load_class_indicator (myTaskBar.bShowAppli && myTaskBar.bGroupAppliByClass ? myIndicators.cClassIndicatorImagePath : NULL, fMaxScale);
583
 
        
584
 
        cairo_dock_load_visible_zone (pDock, myBackground.cVisibleZoneImageFile, myAccessibility.iVisibleZoneWidth, myAccessibility.iVisibleZoneHeight, myBackground.fVisibleZoneAlpha);
585
 
        
586
 
        cairo_dock_create_icon_pbuffer ();
587
 
        
588
 
        //\___________________ On recharge les lanceurs, les applis, et les applets.
589
 
        if (bGroupAppliByClassOld != myTaskBar.bGroupAppliByClass ||
590
 
                bHideVisibleApplisOld != myTaskBar.bHideVisibleApplis ||
591
 
                bAppliOnCurrentDesktopOnlyOld != myTaskBar.bAppliOnCurrentDesktopOnly ||
592
 
                bMixLauncherAppliOld != myTaskBar.bMixLauncherAppli ||
593
 
                bOverWriteXIconsOld != myTaskBar.bOverWriteXIcons ||
594
 
                iMinimizedWindowRenderTypeOld != myTaskBar.iMinimizedWindowRenderType ||
595
 
                (cairo_dock_application_manager_is_running () && ! myTaskBar.bShowAppli))  // on ne veut plus voir les applis, il faut donc les enlever.
596
 
        {
597
 
                cairo_dock_stop_application_manager ();
598
 
        }
599
 
        
600
 
        if (bGroupOrderChanged || myIcons.iSeparateIcons != iSeparateIconsOld)
601
 
                pDock->icons = g_list_sort (pDock->icons, (GCompareFunc) cairo_dock_compare_icons_order);
602
 
 
603
 
        if ((iSeparateIconsOld && ! myIcons.iSeparateIcons) || bGroupOrderChanged)
604
 
                cairo_dock_remove_automatic_separators (pDock);
605
 
                
606
 
        g_pDockBackgroundBuffer.iWidth = 1e4;  // inutile de mettre a jour les decorations maintenant.
607
 
        g_pDockBackgroundBuffer.iHeight = 1e4;
608
 
        if (pDock->icons == NULL)
609
 
        {
610
 
                pDock->fFlatDockWidth = - myIcons.iIconGap;  // car on ne le connaissait pas encore au moment de la creation du dock.
611
 
                cairo_dock_build_docks_tree_with_desktop_files (pDock, g_cCurrentLaunchersPath);
612
 
        }
613
 
        else
614
 
        {
615
 
                cairo_dock_synchronize_sub_docks_position (pDock, FALSE);
616
 
                cairo_dock_reload_buffers_in_all_docks (FALSE);  // tout sauf les applets, qui seront rechargees en bloc juste apres.
617
 
        }
618
 
        
619
 
        GTimeVal time_val;
620
 
        g_get_current_time (&time_val);  // on pourrait aussi utiliser un compteur statique a la fonction ...
621
 
        double fTime = time_val.tv_sec + time_val.tv_usec * 1e-6;
622
 
        cairo_dock_activate_modules_from_list (mySystem.cActiveModuleList, fTime);
623
 
        cairo_dock_deactivate_old_modules (fTime);
624
 
        
625
 
        if (! cairo_dock_application_manager_is_running () && myTaskBar.bShowAppli)  // maintenant on veut voir les applis !
626
 
        {
627
 
                cairo_dock_start_application_manager (pDock);  // va inserer le separateur si necessaire.
628
 
        }
629
 
 
630
 
        if (myIcons.iSeparateIcons && (! iSeparateIconsOld || bGroupOrderChanged))
631
 
        {
632
 
                cairo_dock_insert_separators_in_dock (pDock);
633
 
        }
634
 
        
635
 
        cairo_dock_draw_subdock_icons ();
636
 
        
637
 
        cairo_dock_set_all_views_to_default (0);  // met a jour la taille de tous les docks, maintenant qu'ils sont tous remplis.
638
 
        cairo_dock_redraw_root_docks (TRUE);  // TRUE <=> sauf le main dock.
639
 
        
640
 
        if (myAccessibility.cRaiseDockShortcut != NULL)
641
 
        {
642
 
                if (cRaiseDockShortcutOld == NULL || strcmp (myAccessibility.cRaiseDockShortcut, cRaiseDockShortcutOld) != 0)
643
 
                {
644
 
                        if (cRaiseDockShortcutOld != NULL)
645
 
                                cd_keybinder_unbind (cRaiseDockShortcutOld, (CDBindkeyHandler) cairo_dock_raise_from_keyboard);
646
 
                        if (! cd_keybinder_bind (myAccessibility.cRaiseDockShortcut, (CDBindkeyHandler) cairo_dock_raise_from_keyboard, NULL))
647
 
                        {
648
 
                                g_free (myAccessibility.cRaiseDockShortcut);
649
 
                                myAccessibility.cRaiseDockShortcut = NULL;
650
 
                        }
651
 
                }
652
 
        }
653
 
        else
654
 
        {
655
 
                if (cRaiseDockShortcutOld != NULL)
656
 
                {
657
 
                        cd_keybinder_unbind (cRaiseDockShortcutOld, (CDBindkeyHandler) cairo_dock_raise_from_keyboard);
658
 
                        cairo_dock_place_root_dock (pDock);
659
 
                        gtk_widget_show (pDock->container.pWidget);
660
 
                }
661
 
        }
662
 
        g_free (cRaiseDockShortcutOld);
663
 
        
664
 
        //\___________________ On gere le changement dans la visibilite.
665
 
        if (pDock->bAutoHide)
666
 
        {
667
 
                pDock->iInputState = CAIRO_DOCK_INPUT_HIDDEN;  // le 'configure' mettra a jour la zone d'input.
668
 
                pDock->fHideOffset = 1.;
669
 
        }
670
 
        else
671
 
        {
672
 
                cairo_dock_start_showing (pDock);
673
 
        }
674
 
        
675
 
        cairo_dock_hide_show_launchers_on_other_desktops (pDock);
676
 
        
677
 
        myAccessibility.bReserveSpace = myAccessibility.bReserveSpace && (myAccessibility.cRaiseDockShortcut == NULL);
678
 
        cairo_dock_reserve_space_for_all_root_docks (myAccessibility.bReserveSpace);
679
 
 
680
 
        cairo_dock_load_background_decorations (pDock);
681
 
 
682
 
        cairo_dock_place_root_dock (pDock);
683
 
        if (mySystem.bUseFakeTransparency && ! bUseFakeTransparencyOld)
684
 
        {
685
 
                gtk_window_set_keep_below (GTK_WINDOW (pDock->container.pWidget), TRUE);  // le main dock ayant ete cree avant, il n'a pas herite de ce parametre.
686
 
        }
687
 
        else if (! mySystem.bUseFakeTransparency && bUseFakeTransparencyOld)
688
 
        {
689
 
                gtk_window_set_keep_below (GTK_WINDOW (pDock->container.pWidget), FALSE);
690
 
        }
691
 
        
692
 
        if (myAccessibility.bPopUp)
693
 
        {
694
 
                cairo_dock_start_polling_screen_edge (pDock);
695
 
                if (! bPopUpOld)
696
 
                {
697
 
                        if (cairo_dock_get_nb_dialog_windows () == 0)
698
 
                                gtk_window_set_keep_below (GTK_WINDOW (pDock->container.pWidget), TRUE);  // le main dock ayant ete cree avant, il n'a pas herite de ce parametre.
699
 
                        else
700
 
                                pDock->bPopped == TRUE;  // pour que le pop-down marche quand on fermera la fenetre.
701
 
                }
702
 
        }
703
 
        else
704
 
        {
705
 
                cairo_dock_stop_polling_screen_edge ();
706
 
                if (bPopUpOld)
707
 
                        cairo_dock_set_docks_on_top_layer (FALSE);
708
 
        }
709
 
        
710
 
        pDock->container.iMouseX = 0;  // on se place hors du dock initialement.
711
 
        pDock->container.iMouseY = 0;
712
 
        cairo_dock_calculate_dock_icons (pDock);
713
 
        gtk_widget_queue_draw (pDock->container.pWidget);  // le 'gdk_window_move_resize' ci-dessous ne provoquera pas le redessin si la taille n'a pas change.
714
 
        
715
 
        //\___________________ On recharge les decorations des desklets.
716
 
        if (cDeskletDecorationsNameOld == NULL && myDesklets.cDeskletDecorationsName != NULL)  // chargement initial, on charge juste ceux qui n'ont pas encore leur deco et qui ont atteint leur taille definitive.
717
 
        {
718
 
                cairo_dock_reload_desklets_decorations (FALSE, pCairoContext);
719
 
        }
720
 
        else if (cDeskletDecorationsNameOld != NULL && (myDesklets.cDeskletDecorationsName == NULL || strcmp (cDeskletDecorationsNameOld, myDesklets.cDeskletDecorationsName) != 0))  // le theme par defaut a change, on recharge les desklets qui utilisent le theme "default".
721
 
        {
722
 
                cairo_dock_reload_desklets_decorations (TRUE, pCairoContext);
723
 
        }
724
 
        else if (myDesklets.cDeskletDecorationsName != NULL && strcmp (myDesklets.cDeskletDecorationsName, "personnal") == 0)  // on a configure le theme personnel, il peut avoir change.
725
 
        {
726
 
                cairo_dock_reload_desklets_decorations (TRUE, pCairoContext);
727
 
        }
728
 
        else  // on charge juste ceux qui n'ont pas encore leur deco et qui ont atteint leur taille definitive.
729
 
        {
730
 
                cairo_dock_reload_desklets_decorations (FALSE, pCairoContext);
731
 
        }
732
 
        g_free (cDeskletDecorationsNameOld);
733
 
        
734
 
        cairo_dock_update_renderer_list_for_gui ();
735
 
        cairo_dock_update_desklet_decorations_list_for_gui ();
736
 
        cairo_dock_update_desklet_decorations_list_for_applet_gui ();
737
 
        cairo_dock_update_animations_list_for_gui ();
738
 
        cairo_dock_update_dialog_decorator_list_for_gui ();
739
 
        
740
 
        //\___________________ On ecrit sur le disque si necessaire.
741
 
        if (! bFlushConfFileNeeded)
742
 
                bFlushConfFileNeeded = cairo_dock_conf_file_needs_update (pKeyFile, CAIRO_DOCK_VERSION);
743
 
        if (bFlushConfFileNeeded)
744
 
        {
745
 
                cairo_dock_flush_conf_file (pKeyFile, cConfFilePath, CAIRO_DOCK_SHARE_DATA_DIR, CAIRO_DOCK_CONF_FILE);
746
 
        }
747
 
        
748
 
        cairo_destroy (pCairoContext);
749
 
        
750
 
        g_key_file_free (pKeyFile);
751
 
 
752
 
        s_bLoading = FALSE;
753
 
        
754
 
        cairo_dock_refresh_launcher_gui ();
755
 
}
756
 
 
757
 
gboolean cairo_dock_is_loading (void)
758
 
{
759
 
        return s_bLoading;
760
 
}
761
 
 
762
 
 
763
 
void cairo_dock_update_conf_file (const gchar *cConfFilePath, GType iFirstDataType, ...)  // type, groupe, cle, valeur, etc. finir par G_TYPE_INVALID.
764
 
{
765
 
        cd_message ("%s (%s)", __func__, cConfFilePath);
766
 
        GKeyFile *pKeyFile = cairo_dock_open_key_file (cConfFilePath);
767
 
        g_return_if_fail (pKeyFile != NULL);
768
 
        
769
 
        va_list args;
770
 
        va_start (args, iFirstDataType);
771
 
        
772
 
        GType iType = iFirstDataType;
773
 
        gboolean bValue;
774
 
        gint iValue;
775
 
        double fValue;
776
 
        gchar *cValue;
777
 
        gchar *cGroupName, *cGroupKey;
778
 
        while (iType != G_TYPE_INVALID)
779
 
        {
780
 
                cGroupName = va_arg (args, gchar *);
781
 
                cGroupKey = va_arg (args, gchar *);
782
 
 
783
 
                switch (iType)
784
 
                {
785
 
                        case G_TYPE_BOOLEAN :
786
 
                                bValue = va_arg (args, gboolean);
787
 
                                g_key_file_set_boolean (pKeyFile, cGroupName, cGroupKey, bValue);
788
 
                        break ;
789
 
                        case G_TYPE_INT :
790
 
                                iValue = va_arg (args, gint);
791
 
                                g_key_file_set_integer (pKeyFile, cGroupName, cGroupKey, iValue);
792
 
                        break ;
793
 
                        case G_TYPE_DOUBLE :
794
 
                                fValue = va_arg (args, gdouble);
795
 
                                g_key_file_set_double (pKeyFile, cGroupName, cGroupKey, fValue);
796
 
                        break ;
797
 
                        case G_TYPE_STRING :
798
 
                                cValue = va_arg (args, gchar *);
799
 
                                g_key_file_set_string (pKeyFile, cGroupName, cGroupKey, cValue);
800
 
                        break ;
801
 
                        default :
802
 
                        break ;
803
 
                }
804
 
 
805
 
                iType = va_arg (args, GType);
806
 
        }
807
 
 
808
 
        cairo_dock_write_keys_to_file (pKeyFile, cConfFilePath);
809
 
        g_key_file_free (pKeyFile);
810
 
 
811
 
        va_end (args);
812
 
}
813
 
 
814
 
 
815
 
void cairo_dock_update_conf_file_with_position (const gchar *cConfFilePath, int x, int y)
816
 
{
817
 
        //g_print ("%s (%s ; %d;%d)\n", __func__, cConfFilePath, x, y);
818
 
        cairo_dock_update_conf_file (cConfFilePath,
819
 
                G_TYPE_INT, "Position", "x gap", x,
820
 
                G_TYPE_INT, "Position", "y gap", y,
821
 
                G_TYPE_INVALID);
822
 
}
823
 
 
824
 
 
825
 
void cairo_dock_get_version_from_string (const gchar *cVersionString, int *iMajorVersion, int *iMinorVersion, int *iMicroVersion)
826
 
{
827
 
        gchar **cVersions = g_strsplit (cVersionString, ".", -1);
828
 
        if (cVersions[0] != NULL)
829
 
        {
830
 
                *iMajorVersion = atoi (cVersions[0]);
831
 
                if (cVersions[1] != NULL)
832
 
                {
833
 
                        *iMinorVersion = atoi (cVersions[1]);
834
 
                        if (cVersions[2] != NULL)
835
 
                                *iMicroVersion = atoi (cVersions[2]);
836
 
                }
837
 
        }
838
 
        g_strfreev (cVersions);
839
 
}
840
 
 
841
 
 
842
 
void cairo_dock_decrypt_string( const guchar *cEncryptedString,  guchar **cDecryptedString )
843
 
{
844
 
        g_return_if_fail (cDecryptedString != NULL);
845
 
        if( !cEncryptedString || *cEncryptedString == '\0' )
846
 
        {
847
 
                *cDecryptedString = g_strdup( "" );
848
 
                return;
849
 
        }
850
 
#ifdef HAVE_LIBCRYPT
851
 
        guchar *input = g_strdup(cEncryptedString);
852
 
        guchar *shifted_input = input;
853
 
        guchar **output = cDecryptedString;
854
 
        
855
 
        guchar *current_output = NULL;
856
 
        
857
 
        *output = g_malloc( (strlen(input)+1)/3+1 );
858
 
        current_output = *output;
859
 
 
860
 
  guchar *last_char_in_input = input + strlen(input);
861
 
//  g_print( "Password (before decrypt): %s\n", input );
862
 
 
863
 
  for( ; shifted_input < last_char_in_input; shifted_input += 16+8, current_output += 8 )
864
 
  {
865
 
    guint block[8];
866
 
    guchar txt[64];
867
 
    gint i = 0, j = 0;
868
 
    guchar current_letter = 0;
869
 
    
870
 
    memset( txt, 0, 64 );
871
 
 
872
 
    shifted_input[16+8-1] = 0; // cut the string
873
 
 
874
 
    sscanf( shifted_input, "%X-%X-%X-%X-%X-%X-%X-%X",
875
 
    &block[0], &block[1], &block[2], &block[3], &block[4], &block[5], &block[6], &block[7] );
876
 
 
877
 
    // process the eight first characters of "input"
878
 
    for( i = 0; i < 8 ; i++ )
879
 
      for ( j = 0; j < 8; j++ )
880
 
        txt[i*8+j] = block[i] >> j & 1;
881
 
    
882
 
    setkey( DES_crypt_key );
883
 
    encrypt( txt, 1 );  // decrypt
884
 
 
885
 
    for ( i = 0; i < 8; i++ )
886
 
    {
887
 
      current_output[i] = 0;
888
 
      for ( j = 0; j < 8; j++ )
889
 
      {
890
 
        current_output[i] |= txt[i*8+j] << j;
891
 
      }
892
 
    }
893
 
  }
894
 
 
895
 
  *current_output = 0;
896
 
 
897
 
//  g_print( "Password (after decrypt): %s\n", *output );
898
 
 
899
 
        g_free( input );
900
 
 
901
 
#else
902
 
        *cDecryptedString = g_strdup( cEncryptedString );
903
 
#endif
904
 
}
905
 
 
906
 
void cairo_dock_encrypt_string( const guchar *cDecryptedString,  guchar **cEncryptedString )
907
 
{
908
 
        g_return_if_fail (cEncryptedString != NULL);
909
 
        if( !cDecryptedString || *cDecryptedString == '\0' )
910
 
        {
911
 
                *cEncryptedString = g_strdup( "" );
912
 
                return;
913
 
        }
914
 
        
915
 
#ifdef HAVE_LIBCRYPT
916
 
        const guchar *input = cDecryptedString;
917
 
        guchar **output = cEncryptedString;
918
 
        guint input_length = 0;
919
 
        
920
 
        guchar *current_output = NULL;
921
 
        // for each block of 8 characters, we need 24 bytes.
922
 
        guint nbBlocks = strlen(input)/8+1;
923
 
        *output = g_malloc( nbBlocks*24+1 );
924
 
        current_output = *output;
925
 
 
926
 
  const guchar *last_char_in_input = input + strlen(input);
927
 
 
928
 
//  g_print( "Password (before encrypt): %s\n", input );
929
 
 
930
 
  for( ; input < last_char_in_input; input += 8, current_output += 16+8 )
931
 
  {
932
 
    guchar txt[64];
933
 
    guint i = 0, j = 0;
934
 
    guchar current_letter = 0;
935
 
    
936
 
    memset( txt, 0, 64 );
937
 
    
938
 
    // process the eight first characters of "input"
939
 
    for( i = 0; i < strlen(input) && i < 8 ; i++ )
940
 
      for ( j = 0; j < 8; j++ )
941
 
        txt[i*8+j] = input[i] >> j & 1;
942
 
    
943
 
    setkey( DES_crypt_key );
944
 
    encrypt( txt, 0 );  // encrypt
945
 
 
946
 
    for ( i = 0; i < 8; i++ )
947
 
    {
948
 
      current_letter = 0;
949
 
      for ( j = 0; j < 8; j++ )
950
 
      {
951
 
        current_letter |= txt[i*8+j] << j;
952
 
      }
953
 
      snprintf( current_output + i*3, 4, "%02X-", current_letter );
954
 
    }
955
 
  }
956
 
 
957
 
  *(current_output-1) = 0;
958
 
 
959
 
//  g_print( "Password (after encrypt): %s\n", *output );
960
 
#else
961
 
        *cEncryptedString = g_strdup( cDecryptedString );
962
 
#endif
963
 
}
964
 
 
965
 
 
966
 
xmlDocPtr cairo_dock_open_xml_file (const gchar *cDataFilePath, const gchar *cRootNodeName, xmlNodePtr *root_node, GError **erreur)
967
 
{
968
 
        if (cairo_dock_get_file_size (cDataFilePath) == 0)
969
 
        {
970
 
                g_set_error (erreur, 1, 1, "file '%s' doesn't exist or is empty", cDataFilePath);
971
 
                *root_node = NULL;
972
 
                return NULL;
973
 
        }
974
 
        xmlInitParser ();
975
 
        
976
 
        xmlDocPtr doc = xmlParseFile (cDataFilePath);
977
 
        if (doc == NULL)
978
 
        {
979
 
                g_set_error (erreur, 1, 1, "file '%s' is incorrect", cDataFilePath);
980
 
                *root_node = NULL;
981
 
                return NULL;
982
 
        }
983
 
        
984
 
        xmlNodePtr noeud = xmlDocGetRootElement (doc);
985
 
        if (noeud == NULL || xmlStrcmp (noeud->name, (const xmlChar *) cRootNodeName) != 0)
986
 
        {
987
 
                g_set_error (erreur, 1, 2, "xml file '%s' is not well formed", cDataFilePath);
988
 
                *root_node = NULL;
989
 
                return doc;
990
 
        }
991
 
        *root_node = noeud;
992
 
        return doc;
993
 
}
994
 
 
995
 
void cairo_dock_close_xml_file (xmlDocPtr doc)
996
 
{
997
 
        //xmlCleanupParser ();
998
 
        if (doc)
999
 
                xmlFreeDoc (doc);
1000
 
}
1001
 
 
1002
 
 
1003
 
 
1004
 
gchar *cairo_dock_get_default_system_font (void)
1005
 
{
1006
 
        static gchar *s_cFontName = NULL;
1007
 
        if (s_cFontName == NULL)
1008
 
        {
1009
 
                if (g_iDesktopEnv == CAIRO_DOCK_GNOME)
1010
 
                        s_cFontName = cairo_dock_launch_command_sync ("gconftool-2 -g /desktop/gnome/interface/font_name");  /// ou document_font_name ?...
1011
 
                else
1012
 
                        s_cFontName = g_strdup ("Sans 10");
1013
 
        }
1014
 
        return g_strdup (s_cFontName);
1015
 
}