~ubuntu-branches/ubuntu/oneiric/cairo-dock/oneiric-201110111206

« back to all changes in this revision

Viewing changes to src/cairo-dock-themes-manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne, Matthieu Baerts (matttbe), Julien Lavergne
  • Date: 2009-10-04 16:33:52 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20091004163352-ttbbjfmpb8uzl8j4
Tags: 2.0.9-0ubuntu1
[ Matthieu Baerts (matttbe) ]
* New Upstream Version. (LP: #435587)
* Added apport hook in debian/apport
 - Add debian/apport
 - debian/cairo-dock-core.install: Added debian/apport/cairo-dock.py
* Use .desktop provided by upstream
 - Removed debian/*.desktop
 - debian/cairo-dock-core.install: install upstream desktop files. 

[ Julien Lavergne ]
* Adjust debian/changelog with Daniel Holbach suggestions.
* debian/patches/01_rename_cairo-dock-package-theme.patch: drop, 
  merged upstream.
* debian/patches/01-desktop-file-category.patch:
 - Remove Encoding field and set category to Utility.
* debian/patches/02-merge-changelog.patch:
 - Merge ChangeLog and ChangeLog-2.0.9.
* debian/apport: Remove commands with grep, python doesn't like it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
* Themes manager for Cairo-Dock
 
2
* This file is a part of the Cairo-Dock project
3
3
*
4
 
* Copyright : (C) 2009 by Fabrice Rey
5
 
* E-mail    : fabounet@users.berlios.de
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
6
6
*
7
7
* This program is free software; you can redistribute it and/or
8
8
* modify it under the terms of the GNU General Public License
13
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
15
* GNU General Public License for more details.
16
 
*   http://www.gnu.org/licenses/licenses.html#GPL
 
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/>.
17
18
*/
18
19
 
19
20
#include <string.h>
37
38
#include "cairo-dock-themes-manager.h"
38
39
 
39
40
#define CAIRO_DOCK_MODIFIED_THEME_FILE ".cairo-dock-need-save"
40
 
#define CAIRO_DOCK_THEME_PANEL_WIDTH 750
41
 
#define CAIRO_DOCK_THEME_PANEL_HEIGHT 400
 
41
#define CAIRO_DOCK_THEME_PANEL_WIDTH 1000
 
42
#define CAIRO_DOCK_THEME_PANEL_HEIGHT 530
42
43
#define CAIRO_DOCK_THEME_SERVER "http://themes.cairo-dock.org"
43
44
#define CAIRO_DOCK_BACKUP_THEME_SERVER "http://fabounet03.free.fr"
44
 
#define CAIRO_DOCK_PREFIX_NET_THEME "(Net)   "
45
 
#define CAIRO_DOCK_PREFIX_USER_THEME "(User)  "
46
 
#define CAIRO_DOCK_PREFIX_LOCAL_THEME "(Local) "
47
45
#define CAIRO_DOCK_DEFAULT_THEME_LIST_NAME "liste.txt"
48
46
#define CAIRO_DOCK_DL_NB_RETRY 2
49
47
#define CAIRO_DOCK_DL_TIMEOUT 5
54
52
extern gchar *g_cCurrentLaunchersPath;
55
53
extern gchar *g_cMainDockDefaultRendererName;
56
54
extern gchar *g_cThemeServerAdress;
 
55
extern int g_iMajorVersion, g_iMinorVersion, g_iMicroVersion;
57
56
 
58
57
extern CairoDock *g_pMainDock;
59
58
extern gboolean g_bForceOpenGL;
71
70
        g_free (pTheme);
72
71
}
73
72
 
74
 
GHashTable *cairo_dock_list_local_themes (const gchar *cThemesDir, GHashTable *hProvidedTable, GError **erreur)
75
 
{
76
 
        cd_message ("%s (%s)", __func__, cThemesDir);
 
73
static inline int _get_theme_rating (const gchar *cThemesDir, const gchar *cThemeName)
 
74
{
 
75
        gchar *cRatingFile = g_strdup_printf ("%s/.rating/%s", cThemesDir, cThemeName);
 
76
        int iRating = 0;
 
77
        gsize length = 0;
 
78
        gchar *cContent = NULL;
 
79
        g_file_get_contents (cRatingFile,
 
80
                &cContent,
 
81
                &length,
 
82
                NULL);
 
83
        if (cContent)
 
84
        {
 
85
                iRating = atoi (cContent);
 
86
                g_free (cContent);
 
87
        }
 
88
        g_free (cRatingFile);
 
89
        return iRating; 
 
90
}
 
91
 
 
92
GHashTable *cairo_dock_list_local_themes (const gchar *cThemesDir, GHashTable *hProvidedTable, gboolean bUpdateThemeValidity, GError **erreur)
 
93
{
 
94
        g_print ("%s (%s)\n", __func__, cThemesDir);
77
95
        GError *tmp_erreur = NULL;
78
96
        GDir *dir = g_dir_open (cThemesDir, 0, &tmp_erreur);
79
97
        if (tmp_erreur != NULL)
83
101
        }
84
102
 
85
103
        GHashTable *pThemeTable = (hProvidedTable != NULL ? hProvidedTable : g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) cairo_dock_free_theme));
86
 
 
 
104
        
 
105
        int iType;
 
106
        const gchar *cPrefix;
 
107
        if (strncmp (cThemesDir, "/usr", 4) == 0)
 
108
        {
 
109
                iType = CAIRO_DOCK_LOCAL_THEME;
 
110
                cPrefix = CAIRO_DOCK_PREFIX_LOCAL_THEME;
 
111
        }
 
112
        else
 
113
        {
 
114
                iType = CAIRO_DOCK_USER_THEME;
 
115
                cPrefix = CAIRO_DOCK_PREFIX_USER_THEME;
 
116
        }
 
117
        
 
118
        GString *sRatingFile = g_string_new (cThemesDir);
87
119
        gchar *cThemePath;
88
120
        const gchar* cThemeName;
89
 
        int iType = (strncmp (cThemesDir, "/usr", 4) == 0 ? 0 : 1);
90
 
        const gchar *cPrefix = (iType == 0 ? CAIRO_DOCK_PREFIX_LOCAL_THEME : CAIRO_DOCK_PREFIX_USER_THEME);
 
121
        int iVersion;
 
122
        gboolean bOutdated;
91
123
        CairoDockTheme *pTheme;
92
124
        do
93
125
        {
95
127
                if (cThemeName == NULL)
96
128
                        break ;
97
129
                
 
130
                if (*cThemeName == '.')
 
131
                        continue;
 
132
                
 
133
                // on ecarte les non repertoires.
98
134
                cThemePath = g_strdup_printf ("%s/%s", cThemesDir, cThemeName);
99
 
                if (g_file_test (cThemePath, G_FILE_TEST_IS_DIR))
100
 
                {
101
 
                        pTheme = g_new0 (CairoDockTheme, 1);
102
 
                        pTheme->cThemePath = cThemePath;
103
 
                        pTheme->cDisplayedName = g_strdup_printf ("%s%s", (cPrefix != NULL ? cPrefix : ""), cThemeName);
104
 
                        pTheme->iType = iType;
105
 
                        
106
 
                        g_hash_table_insert (pThemeTable, g_strdup (cThemeName), pTheme);  // donc ecrase un theme installe ayant le meme nom.
107
 
                }
 
135
                if (! g_file_test (cThemePath, G_FILE_TEST_IS_DIR))
 
136
                {
 
137
                        g_free (cThemePath);
 
138
                        continue;
 
139
                }
 
140
                
 
141
                // on recupere la version du theme.
 
142
                //g_print (" referencement du theme local %s...\n", cThemeName);
 
143
                bOutdated = FALSE;
 
144
                iVersion = 0;
 
145
                gchar *cVersionFile = g_strdup_printf ("%s/version", cThemePath);
 
146
                if (g_file_test (cVersionFile, G_FILE_TEST_EXISTS))
 
147
                {
 
148
                        gsize length = 0;
 
149
                        gchar *cContent = NULL;
 
150
                        g_file_get_contents (cVersionFile,
 
151
                                &cContent,
 
152
                                &length,
 
153
                                NULL);
 
154
                        if (cContent)
 
155
                        {
 
156
                                iVersion = atoi (cContent);
 
157
                                bOutdated = (iVersion == 0);
 
158
                                g_free (cContent);
 
159
                        }
 
160
                }
 
161
                
 
162
                // on regarde si on n'ecrase pas un theme de meme nom de version superieure.
 
163
                CairoDockTheme *pSameTheme = g_hash_table_lookup (pThemeTable, cThemeName);
 
164
                if (pSameTheme != NULL)
 
165
                {
 
166
                        //g_print (" le meme theme existe deja en version %d (<> %d)\n", pSameTheme->iVersion, iVersion);
 
167
                        if (pSameTheme->iVersion > iVersion)  // on saute ce theme, et on le marque comme obsolete.
 
168
                        {
 
169
                                g_file_set_contents (cVersionFile,
 
170
                                        "0",
 
171
                                        -1,
 
172
                                        NULL);
 
173
                                g_free (cThemePath);
 
174
                                g_free (cVersionFile);
 
175
                                // par contre on affiche la note que l'utilisateur avait precedemment etablie.
 
176
                                int iRating = _get_theme_rating (cThemesDir, cThemeName);
 
177
                                if (iRating > 0)
 
178
                                        pSameTheme->iRating = iRating;
 
179
                                continue;
 
180
                        }
 
181
                }
 
182
                
 
183
                if (bOutdated && bUpdateThemeValidity)  // theme precedement marque obsolete, mais aucun theme ne l'ecrase => on le rehabilite.
 
184
                {
 
185
                        g_print (" le theme n'est plus obsolete\n");
 
186
                        iVersion = 1;
 
187
                        g_file_set_contents (cVersionFile,
 
188
                                "1",
 
189
                                -1,
 
190
                                NULL);
 
191
                }
 
192
                
 
193
                g_free (cVersionFile);
 
194
                
 
195
                // on insere le theme dans la table.
 
196
                pTheme = g_new0 (CairoDockTheme, 1);
 
197
                pTheme->cThemePath = cThemePath;
 
198
                pTheme->cDisplayedName = g_strdup_printf ("%s%s", (cPrefix != NULL ? cPrefix : ""), cThemeName);
 
199
                pTheme->iType = iType;
 
200
                pTheme->iVersion = iVersion;
 
201
                pTheme->iRating = _get_theme_rating (cThemesDir, cThemeName);
 
202
                if (pSameTheme != NULL)
 
203
                        pTheme->iSobriety = pSameTheme->iSobriety;
 
204
                g_hash_table_insert (pThemeTable, g_strdup (cThemeName), pTheme);  // donc ecrase un theme installe ayant le meme nom.
108
205
        }
109
206
        while (1);
110
207
        g_dir_close (dir);
122
219
                }
123
220
        }
124
221
        gchar *cResultPath;
125
 
        gchar *cCommand = g_strdup_printf ("tar xfz \"%s\" -C \"%s\"", cArchivePath, cExtractTo);
 
222
        gchar *cCommand = g_strdup_printf ("tar xf%c \"%s\" -C \"%s\"", (g_str_has_suffix (cArchivePath, "bz2") ? 'j' : 'z'), cArchivePath, cExtractTo);
 
223
        g_print ("tar : %s\n", cCommand);
126
224
        int r = system (cCommand);
127
225
        if (r != 0)
128
226
        {
142
240
                
143
241
                if (g_str_has_suffix (cLocalFileName, ".tar.gz"))
144
242
                        cLocalFileName[strlen(cLocalFileName)-7] = '\0';
 
243
                else if (g_str_has_suffix (cLocalFileName, ".tar.bz2"))
 
244
                        cLocalFileName[strlen(cLocalFileName)-8] = '\0';
 
245
                else if (g_str_has_suffix (cLocalFileName, ".tgz"))
 
246
                        cLocalFileName[strlen(cLocalFileName)-4] = '\0';
145
247
                
146
248
                cResultPath = g_strdup_printf ("%s/%s", cExtractTo, cLocalFileName);
147
249
                g_free (cLocalFileName);
177
279
        int r = system (cCommand);
178
280
        if (r != 0)
179
281
        {
180
 
                g_set_error (erreur, 1, 1, "an error occured while executing '%s'", cCommand);
 
282
                cd_warning ("an error occured while executing '%s'", cCommand);
181
283
                g_remove (cTmpFilePath);
182
284
                g_free (cTmpFilePath);
183
285
                cTmpFilePath = NULL;
268
370
                g_propagate_error (erreur, tmp_erreur);
269
371
                return hProvidedTable;
270
372
        }
271
 
        if (cContent == NULL || (g_bEasterEggs && strncmp (cContent, "#CD", 3) != 0))
 
373
        if (cContent == NULL || strncmp (cContent, "#!CD", 4) != 0)  // avec une connexion wifi etablie sur un operateur auquel on ne s'est pas logue, il peut nous renvoyer des messages au lieu de juste rien. On filtre ca par un entete dedie.
272
374
        {
273
375
                cd_warning ("empty themes list on %s (check that your connection is alive, or retry later)", cServerAdress);
274
376
                g_set_error (erreur, 1, 1, "empty themes list on %s", cServerAdress);
281
383
        gchar **cNetThemesList = g_strsplit (cContent, "\n", -1);
282
384
        g_free (cContent);
283
385
        
 
386
        gchar *cHeader = cNetThemesList[0];
 
387
        if (cHeader[4] != '\n')
 
388
        {
 
389
                int iMajorVersion=0, iMinorVersion=0, iMicroVersion=0;
 
390
                cairo_dock_get_version_from_string (cHeader+4, &iMajorVersion, &iMinorVersion, &iMicroVersion);
 
391
                g_print ("%d/%d/%d\n", iMajorVersion, iMinorVersion, iMicroVersion);
 
392
                if (iMajorVersion > g_iMajorVersion ||
 
393
                        (iMajorVersion == g_iMajorVersion &&
 
394
                                (iMinorVersion > g_iMinorVersion ||
 
395
                                        (iMinorVersion == g_iMinorVersion && iMicroVersion > g_iMicroVersion))))
 
396
                {
 
397
                        g_print ("A new version is available !\n>>>\n%s\n<<<\n", cHeader+4);
 
398
                }
 
399
        }
 
400
        
284
401
        int i;
285
402
        gboolean bFirstComment = FALSE;
286
 
        gchar *cThemeName;
 
403
        gchar *cThemeName, *str, *str2;
287
404
        CairoDockTheme *pTheme = NULL;
288
 
        for (i = 0; cNetThemesList[i] != NULL; i ++)
 
405
        for (i = 1; cNetThemesList[i] != NULL; i ++)
289
406
        {
290
407
                cThemeName = cNetThemesList[i];
291
 
                if (*cThemeName == '#' || *cThemeName == '\0')
 
408
                if (*cThemeName == '\0')
 
409
                        continue;
 
410
                if (*cThemeName == '#')
292
411
                {
293
 
                        if (*cThemeName == '#' && bFirstComment && pTheme != NULL)
 
412
                        if (bFirstComment && pTheme != NULL)  // 1er commentaire apres un theme.
294
413
                        {
295
 
                                cd_debug ("+ commentaire : %s", cThemeName+1);
296
 
                                pTheme->fSize = g_ascii_strtod (cThemeName+1, NULL);
297
 
                                pTheme->cAuthor = g_strdup (strchr (cThemeName, ' '));
 
414
                                str = cThemeName+1;  // on saute les #
 
415
                                while (*str == '#')
 
416
                                        str ++;
 
417
                                if (*str == '\0')
 
418
                                        continue;
 
419
                                cd_debug ("+ commentaire : %s", str);
 
420
                                
 
421
                                char **pValues = g_strsplit (str, ";", -1);
 
422
                                if (!pValues)
 
423
                                        continue;
 
424
                                gchar *cValue;
 
425
                                int i;
 
426
                                for (i = 0; pValues[i] != NULL; i ++)
 
427
                                {
 
428
                                        cValue = pValues[i];
 
429
                                        switch (i)
 
430
                                        {
 
431
                                                case 0:
 
432
                                                        pTheme->fSize = g_ascii_strtod (cValue, NULL);
 
433
                                                break ;
 
434
                                                case 1:
 
435
                                                        pTheme->cAuthor = g_strdup (cValue);
 
436
                                                break ;
 
437
                                                case 2:
 
438
                                                        pTheme->iRating = atoi (cValue);
 
439
                                                break ;
 
440
                                                case 3:
 
441
                                                        pTheme->iSobriety = atoi (cValue);
 
442
                                                break ;
 
443
                                                case 4:
 
444
                                                        pTheme->iVersion = atoi (cValue);
 
445
                                                break ;
 
446
                                        }
 
447
                                }
 
448
                                g_strfreev (pValues);
 
449
                                
298
450
                                gchar *cDisplayedName = g_strdup_printf ("%s by %s [%.2f MB]", pTheme->cDisplayedName, (pTheme->cAuthor ? pTheme->cAuthor : "---"), pTheme->fSize);
299
451
                                g_free (pTheme->cDisplayedName);
300
452
                                pTheme->cDisplayedName = cDisplayedName;
301
453
                        }
302
 
                        g_free (cThemeName);
303
454
                        bFirstComment = FALSE;
304
455
                }
305
456
                else
309
460
                        pTheme->iType = CAIRO_DOCK_DISTANT_THEME;
310
461
                        pTheme->cThemePath = g_strdup_printf ("%s/%s/%s", cServerAdress, cDirectory, cThemeName);
311
462
                        pTheme->cDisplayedName = g_strconcat (CAIRO_DOCK_PREFIX_NET_THEME, cThemeName, NULL);
312
 
                        g_hash_table_insert (pThemeTable, cThemeName, pTheme);
 
463
                        g_hash_table_insert (pThemeTable, g_strdup (cThemeName), pTheme);
313
464
                        bFirstComment = TRUE;
314
465
                }
315
466
        }
316
467
        
317
 
        g_free (cNetThemesList);  // car les noms sont passes dans la hashtable.
 
468
        g_strfreev (cNetThemesList);
318
469
        return pThemeTable;
319
470
}
320
471
 
330
481
        if (erreur != NULL)
331
482
        {
332
483
                cd_warning ("while loading distant themes in '%s/%s' : %s", g_cThemeServerAdress != NULL ? g_cThemeServerAdress : CAIRO_DOCK_THEME_SERVER, cDistantThemesDir, erreur->message);
 
484
                g_print ("s_pThemeManager:%x\n", s_pThemeManager);
333
485
                cairo_dock_set_status_message_printf (s_pThemeManager, _("couldn't get the list of themes for %s (no connection ?)"), cDistantThemesDir);
334
486
                g_error_free (erreur);
335
487
                erreur = NULL;
337
489
        
338
490
        //\______________ On recupere les themes pre-installes (qui ecrasent donc les precedents).
339
491
        if (cShareThemesDir != NULL)
340
 
                pThemeTable = cairo_dock_list_local_themes (cShareThemesDir, pThemeTable, &erreur);
 
492
                pThemeTable = cairo_dock_list_local_themes (cShareThemesDir, pThemeTable, cDistantThemesDir != NULL, &erreur);
341
493
        if (erreur != NULL)
342
494
        {
343
495
                cd_warning ("while loading pre-installed themes in '%s' : %s", cShareThemesDir, erreur->message);
347
499
        
348
500
        //\______________ On recupere les themes utilisateurs (qui ecrasent donc tout le monde).
349
501
        if (cUserThemesDir != NULL)
350
 
                pThemeTable = cairo_dock_list_local_themes (cUserThemesDir, pThemeTable, NULL);
 
502
                pThemeTable = cairo_dock_list_local_themes (cUserThemesDir, pThemeTable, cDistantThemesDir != NULL, NULL);
351
503
        
352
504
        return pThemeTable;
353
505
}
542
694
                if (g_key_file_get_boolean (pKeyFile, "Save", "package", NULL))
543
695
                {
544
696
                        cd_message ("building theme package ...");
545
 
                        if (g_file_test (CAIRO_DOCK_SHARE_DATA_DIR"/../../bin/cairo-dock-package-theme.sh", G_FILE_TEST_EXISTS))
 
697
                        if (g_file_test (CAIRO_DOCK_SHARE_DATA_DIR"/../../bin/cairo-dock-package-theme", G_FILE_TEST_EXISTS))
546
698
                        {
547
 
                                gchar *cCommand = g_strdup_printf ("$TERM -e '%s \"%s\"'", "cairo-dock-package-theme.sh", cNewThemeName);
 
699
                                gchar *cCommand = g_strdup_printf ("$TERM -e '%s \"%s\"'", "cairo-dock-package-theme", cNewThemeName);
548
700
                                r = system (cCommand);
549
701
                                g_free (cCommand);
550
702
                        }
663
815
                g_print ("cNewThemeName : '%s'\n", cNewThemeName);
664
816
                gchar *cUserThemesDir = g_strdup_printf ("%s/%s", g_cCairoDockDataDir, CAIRO_DOCK_THEMES_DIR);
665
817
                gchar *cNewThemePath = NULL;
666
 
                if (g_str_has_suffix (cNewThemeName, ".tar.gz"))  // c'est un paquet.
 
818
                if (g_str_has_suffix (cNewThemeName, ".tar.gz") || g_str_has_suffix (cNewThemeName, ".tar.bz2") || g_str_has_suffix (cNewThemeName, ".tgz"))  // c'est un paquet.
667
819
                {
668
820
                        g_print ("c'est un paquet\n");
669
821
                        if (*cNewThemeName == '/' || strncmp (cNewThemeName, "file://", 7) == 0)  // paquet en local.
670
822
                        {
671
823
                                g_print (" paquet local\n");
672
824
                                //cairo_dock_remove_html_spaces (cNewThemeName);
673
 
                                cNewThemePath = cairo_dock_uncompress_file (*cNewThemeName == '/' ? cNewThemeName : cNewThemeName+7, cUserThemesDir, NULL);
 
825
                                gchar *cFilePath = (*cNewThemeName == '/' ? g_strdup (cNewThemeName) : g_filename_from_uri (cNewThemeName, NULL, NULL));
 
826
                                cNewThemePath = cairo_dock_uncompress_file (cFilePath, cUserThemesDir, NULL);
 
827
                                g_free (cFilePath);
674
828
                        }
675
829
                        else  // paquet distant.
676
830
                        {
735
889
                }
736
890
                //\___________________ On charge les icones.
737
891
                gchar *cNewLocalIconsPath = g_strdup_printf ("%s/%s", cNewThemePath, CAIRO_DOCK_LOCAL_ICONS_DIR);
738
 
                if (! g_file_test (cNewLocalIconsPath, G_FILE_TEST_IS_DIR))  // c'est un ancien theme, mettons-le vite a jour !
739
 
                {
740
 
                        g_string_printf (sCommand, "sed -i \"s/~\\/.cairo-dock/~\\/.config\\/%s/g\" '%s/%s/%s'", CAIRO_DOCK_DATA_DIR, g_cCairoDockDataDir, CAIRO_DOCK_CURRENT_THEME_NAME, CAIRO_DOCK_CONF_FILE);
741
 
                        cd_message ("%s", sCommand->str);
742
 
                        r = system (sCommand->str);
743
 
                        
744
 
                        g_string_printf (sCommand, "sed -i \"/default icon directory/ { s/~\\/.config\\/%s\\/%s\\/icons/%s/g }\" '%s/%s'", CAIRO_DOCK_DATA_DIR, CAIRO_DOCK_CURRENT_THEME_NAME, CAIRO_DOCK_LOCAL_THEME_KEYWORD, g_cCurrentThemePath, CAIRO_DOCK_CONF_FILE);
745
 
                        cd_message ("%s", sCommand->str);
746
 
                        r = system (sCommand->str);
747
 
                        
748
 
                        g_string_printf (sCommand, "sed -i \"s/_ThemeDirectory_/%s/g\" '%s/%s'", CAIRO_DOCK_LOCAL_THEME_KEYWORD, g_cCurrentThemePath, CAIRO_DOCK_CONF_FILE);
749
 
                        cd_message ("%s", sCommand->str);
750
 
                        r = system (sCommand->str);
751
 
                        
 
892
                if (! g_file_test (cNewLocalIconsPath, G_FILE_TEST_IS_DIR))  // c'est un ancien theme, on deplace les icones vers le repertoire 'icons'.
 
893
                {                       
752
894
                        g_string_printf (sCommand, "find '%s/%s' -mindepth 1 ! -name '*.desktop' -exec /bin/cp '{}' '%s/%s' \\;", cNewThemePath, CAIRO_DOCK_LAUNCHERS_DIR, g_cCurrentThemePath, CAIRO_DOCK_LOCAL_ICONS_DIR);
753
895
                }
754
896
                else
773
915
                }
774
916
                
775
917
                //\___________________ On charge les lanceurs si necessaire, en effacant ceux existants.
 
918
                if (! g_file_test (g_cCurrentLaunchersPath, G_FILE_TEST_EXISTS))
 
919
                {
 
920
                        gchar *command = g_strdup_printf ("mkdir -p '%s'", g_cCurrentLaunchersPath);
 
921
                        r = system (command);
 
922
                        g_free (command);
 
923
                }
776
924
                if (g_pMainDock == NULL || g_key_file_get_boolean (pKeyFile, "Themes", "use theme launchers", NULL))
777
925
                {
778
926
                        g_string_printf (sCommand, "rm -f '%s'/*.desktop", g_cCurrentLaunchersPath);
797
945
                }
798
946
                else
799
947
                {
800
 
                        g_string_printf (sCommand, "find '%s' -mindepth 1 ! -name '*.conf' ! -path '%s/%s*' ! -type d -exec cp -p {} '%s' \\;", cNewThemePath, cNewThemePath, CAIRO_DOCK_LAUNCHERS_DIR, g_cCurrentThemePath);  // copie tous les fichiers du nouveau theme sauf les lanceurs et les .conf du dock et des plug-ins.
 
948
                        // on copie tous les fichiers du nouveau theme sauf les lanceurs et les .conf (dock et plug-ins).
 
949
                        g_string_printf (sCommand, "find '%s' -mindepth 1 ! -name '*.conf' ! -path '%s/%s*' ! -type d -exec cp -p {} '%s' \\;", cNewThemePath, cNewThemePath, CAIRO_DOCK_LAUNCHERS_DIR, g_cCurrentThemePath);
801
950
                        cd_message (sCommand->str);
802
951
                        r = system (sCommand->str);
803
952
                        
804
 
                        gchar *cNewPlugInsDir = g_strdup_printf ("%s/%s", cNewThemePath, "plug-ins");
 
953
                        // on parcours les .conf des plug-ins, on les met a jour, et on fusionne avec le theme courant.
 
954
                        gchar *cNewPlugInsDir = g_strdup_printf ("%s/%s", cNewThemePath, "plug-ins");  // repertoire des plug-ins du nouveau theme.
805
955
                        GDir *dir = g_dir_open (cNewPlugInsDir, 0, NULL);  // NULL si ce theme n'a pas de repertoire 'plug-ins'.
806
956
                        const gchar* cModuleDirName;
807
957
                        gchar *cConfFilePath, *cNewConfFilePath, *cUserDataDirPath, *cConfFileName;
808
958
                        do
809
959
                        {
810
 
                                cModuleDirName = g_dir_read_name (dir);
 
960
                                cModuleDirName = g_dir_read_name (dir);  // nom du repertoire du theme (pas forcement egal au nom du theme)
811
961
                                if (cModuleDirName == NULL)
812
962
                                        break ;
813
963
                                
814
 
                                /*CairoDockModule *pModule =  cairo_dock_find_module_from_name (cModuleName);
815
 
                                if (pModule == NULL || pModule->pVisitCard == NULL)
816
 
                                        continue;*/
817
 
 
 
964
                                // on cree le repertoire du plug-in dans le theme courant.
818
965
                                cd_debug ("  installing %s's config\n", cModuleDirName);
819
 
                                cUserDataDirPath = g_strdup_printf ("%s/plug-ins/%s", g_cCurrentThemePath, cModuleDirName);
 
966
                                cUserDataDirPath = g_strdup_printf ("%s/plug-ins/%s", g_cCurrentThemePath, cModuleDirName);  // repertoire du plug-in dans le theme courant.
820
967
                                if (! g_file_test (cUserDataDirPath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
821
968
                                {
822
969
                                        cd_debug ("    directory %s doesn't exist, it will be created.", cUserDataDirPath);
826
973
                                        g_free (command);
827
974
                                }
828
975
                                
 
976
                                // on recupere le nom et le chemin du .conf du plug-in dans le nouveau theme.
829
977
                                cConfFileName = g_strdup_printf ("%s.conf", cModuleDirName);
830
978
                                cNewConfFilePath = g_strdup_printf ("%s/%s/%s", cNewPlugInsDir, cModuleDirName, cConfFileName);
831
979
                                if (! g_file_test (cNewConfFilePath, G_FILE_TEST_EXISTS))
832
980
                                {
833
981
                                        g_free (cConfFileName);
834
982
                                        g_free (cNewConfFilePath);
835
 
                                        CairoDockModule *pModule = cairo_dock_foreach_module ((GHRFunc) _find_module_from_user_data_dir, cModuleDirName);
 
983
                                        CairoDockModule *pModule = cairo_dock_foreach_module ((GHRFunc) _find_module_from_user_data_dir, (gpointer) cModuleDirName);
836
984
                                        if (pModule == NULL)  // du coup, dans ce cas-la, on ne charge pas des plug-ins non utilises par l'utilisateur.
837
985
                                        {
838
986
                                                cd_warning ("couldn't find the module owning '%s', this file will be ignored.");
841
989
                                        cConfFileName = g_strdup (pModule->pVisitCard->cConfFileName);
842
990
                                        cNewConfFilePath = g_strdup_printf ("%s/%s/%s", cNewPlugInsDir, cModuleDirName, cConfFileName);
843
991
                                }
844
 
                                cConfFilePath = g_strdup_printf ("%s/%s", cUserDataDirPath, cConfFileName);
 
992
                                cConfFilePath = g_strdup_printf ("%s/%s", cUserDataDirPath, cConfFileName);  // chemin du .conf dans le theme courant.
845
993
                                
 
994
                                // on met a jour le .conf du nouveau theme.
 
995
                                /*GError *erreur = NULL;
 
996
                                GKeyFile *pKeyFile = cairo_dock_open_key_file (cInstanceConfFilePath);
 
997
                                if (pKeyFile == NULL)
 
998
                                        return NULL;
 
999
 
 
1000
                                gboolean bNeedsUpgrade = cairo_dock_conf_file_needs_update (pKeyFile, pModule->pVisitCard->cModuleVersion);
 
1001
                                if (bNeedsUpgrade)
 
1002
                                {
 
1003
                                        cairo_dock_flush_conf_file (pKeyFile, cInstanceConfFilePath, pModule->pVisitCard->cShareDataDir, pModule->pVisitCard->cConfFileName);
 
1004
                                        g_key_file_free (pKeyFile);
 
1005
                                        pKeyFile = cairo_dock_open_key_file (cInstanceConfFilePath);
 
1006
                                        if (pKeyFile == NULL)
 
1007
                                                return NULL;
 
1008
                                }*/
 
1009
                                // on fusionne les 2 .conf.
846
1010
                                if (! g_file_test (cConfFilePath, G_FILE_TEST_EXISTS))
847
1011
                                {
848
1012
                                        cd_debug ("    no conf file %s, we will take the theme's one", cConfFilePath);
887
1051
        gchar *cInitConfFile = cairo_dock_build_temporary_themes_conf_file ();  // sera supprime a la destruction de la fenetre.
888
1052
        
889
1053
        //\___________________ On laisse l'utilisateur l'editer.
890
 
        gchar *cPresentedGroup = (cairo_dock_theme_need_save () ? "Save" : NULL);
 
1054
        const gchar *cPresentedGroup = (cairo_dock_theme_need_save () ? "Save" : NULL);
891
1055
        const gchar *cTitle = _("Manage Themes");
892
1056
        
893
1057
        cairo_dock_build_normal_gui (cInitConfFile,
909
1073
        if (cUserThemesDir != NULL)
910
1074
        {
911
1075
                cThemePath = g_strdup_printf ("%s/%s", cUserThemesDir, cThemeName);
 
1076
                
912
1077
                if (g_file_test (cThemePath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
 
1078
                {
 
1079
                        gboolean bOutdated = FALSE;
 
1080
                        gchar *cVersionFile = g_strdup_printf ("%s/version", cThemePath);
 
1081
                        if (g_file_test (cVersionFile, G_FILE_TEST_EXISTS))
 
1082
                        {
 
1083
                                gsize length = 0;
 
1084
                                gchar *cContent = NULL;
 
1085
                                g_file_get_contents (cVersionFile,
 
1086
                                        &cContent,
 
1087
                                        &length,
 
1088
                                        NULL);
 
1089
                                if (cContent)
 
1090
                                {
 
1091
                                        int iVersion = atoi (cContent);
 
1092
                                        bOutdated = (iVersion == 0);
 
1093
                                        g_free (cContent);
 
1094
                                }
 
1095
                        }
 
1096
                        if (! bOutdated)
913
1097
                        return cThemePath;
 
1098
                }
 
1099
                
914
1100
                g_free (cThemePath);
915
1101
                cThemePath = NULL;
916
1102
        }
 
1103
        
917
1104
        if (cShareThemesDir != NULL)
918
1105
        {
919
1106
                cThemePath = g_strdup_printf ("%s/%s", cShareThemesDir, cThemeName);