~cairo-dock-team/ubuntu/precise/cairo-dock/988102

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2009-06-20 23:46:54 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090620234654-hlg7pqvys6temuqq
Tags: 2.0.5-0ubuntu1
* New Upstream Version. (LP: #390053)
* debian/rules: 
 - Drop autoreconf call, it's fixed upstream.
 - Call dh_desktop for all desktop files.
* debian/control:
 - Add libgtkglext1-dev as depends for cairo-dock-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#include <unistd.h>
11
11
#define __USE_XOPEN_EXTENDED
12
12
#include <stdlib.h>
 
13
#include <sys/stat.h>
13
14
#include <glib/gstdio.h>
14
15
#include <glib/gi18n.h>
15
16
 
48
49
extern int g_iWmHint;
49
50
extern gboolean g_bForceOpenGL;
50
51
 
 
52
static GtkWidget *s_pThemeManager = NULL;
 
53
 
51
54
void cairo_dock_free_theme (CairoDockTheme *pTheme)
52
55
{
53
56
        if (pTheme == NULL)
139
142
 
140
143
gchar *cairo_dock_download_file (const gchar *cServerAdress, const gchar *cDistantFilePath, const gchar *cDistantFileName, gint iShowActivity, const gchar *cExtractTo, GError **erreur)
141
144
{
 
145
        cairo_dock_set_status_message_printf (s_pThemeManager, _("Downloading file %s ..."), cDistantFileName);
142
146
        gchar *cTmpFilePath = g_strdup ("/tmp/cairo-dock-net-file.XXXXXX");
143
147
        int fds = mkstemp (cTmpFilePath);
144
148
        if (fds == -1)
159
163
        }
160
164
        gchar *cCommand = g_strdup_printf ("%s wget \"%s/%s/%s\" -O \"%s\" -t %d -T %d%s", (iShowActivity == 2 ? "xterm -e '" : ""), cServerAdress, cDistantFilePath, cDistantFileName, cTmpFilePath, CAIRO_DOCK_DL_NB_RETRY, CAIRO_DOCK_DL_TIMEOUT, (iShowActivity == 2 ? "'" : ""));
161
165
        g_print ("%s\n", cCommand);
 
166
        
162
167
        int r = system (cCommand);
163
 
        close(fds);
164
168
        if (r != 0)
165
169
        {
166
170
                g_set_error (erreur, 1, 1, "an error occured while executing '%s'", cCommand);
168
172
                g_free (cTmpFilePath);
169
173
                cTmpFilePath = NULL;
170
174
        }
 
175
        
 
176
        gboolean bOk = (cTmpFilePath != NULL);
 
177
        if (cTmpFilePath != NULL)
 
178
        {
 
179
                struct stat buf;
 
180
                stat (cTmpFilePath, &buf);
 
181
                bOk = (buf.st_size > 0);
 
182
        }
 
183
        if (! bOk)
 
184
        {
 
185
                g_set_error (erreur, 1, 1, "couldn't get distant file %s", cDistantFileName);
 
186
                cairo_dock_set_status_message_printf (s_pThemeManager, _("couldn't get distant file %s"), cDistantFileName);
 
187
                g_remove (cTmpFilePath);
 
188
                g_free (cTmpFilePath);
 
189
                cTmpFilePath = NULL;
 
190
        }
 
191
        else
 
192
        {
 
193
                cairo_dock_set_status_message (s_pThemeManager, "");
 
194
        }
 
195
        close(fds);
171
196
        g_free (cCommand);
172
197
        
173
198
        if (cTmpFilePath != NULL && cExtractTo != NULL)
226
251
        cd_message ("listing net themes on %s/%s ...", cServerAdress, cDirectory);
227
252
        
228
253
        GError *tmp_erreur = NULL;
229
 
        gchar *cContent = cairo_dock_get_distant_file_content (cServerAdress, cDirectory, cListFileName, 1, &tmp_erreur);
 
254
        gchar *cContent = cairo_dock_get_distant_file_content (cServerAdress, cDirectory, cListFileName, 0, &tmp_erreur);
230
255
        if (tmp_erreur != NULL)
231
256
        {
232
257
                cd_warning ("couldn't retrieve themes on %s (check that your connection is alive, or retry later)", cServerAdress);
383
408
 
384
409
 
385
410
 
386
 
static void on_theme_destroy (gpointer *user_data)
 
411
static void on_theme_destroy (gchar *cInitConfFile)
387
412
{
388
413
        g_print ("%s ()\n", __func__);
389
 
        g_remove (user_data[0]);
390
 
        g_free (user_data[0]);
391
 
        cairo_dock_dialog_unreference (user_data[2]);
392
 
        g_free (user_data);
393
 
}
394
 
static gboolean on_theme_apply (gpointer *user_data)
395
 
{
396
 
        gchar *cInitConfFile = user_data[0];
397
 
        GtkWidget *pWidget = user_data[2];
 
414
        g_remove (cInitConfFile);
 
415
        g_free (cInitConfFile);
 
416
        s_pThemeManager = NULL;
 
417
}
 
418
 
 
419
static gboolean _find_module_from_user_data_dir (gchar *cModuleName, CairoDockModule *pModule, const gchar *cUserDataDirName)
 
420
{
 
421
        if (pModule->pVisitCard->cUserDataDir && strcmp (cUserDataDirName, pModule->pVisitCard->cUserDataDir) == 0)
 
422
                return TRUE;
 
423
        return FALSE;
 
424
}
 
425
static gboolean on_theme_apply (gchar *cInitConfFile)
 
426
{
398
427
        g_print ("%s (%s)\n", __func__, cInitConfFile);
399
428
        GError *erreur = NULL;
400
429
        int r;  // resultat de system().
652
681
                }
653
682
                g_free (cUserThemesDir);
654
683
                
655
 
                g_return_val_if_fail (cNewThemePath != NULL, TRUE);
 
684
                g_return_val_if_fail (cNewThemePath != NULL && g_file_test (cNewThemePath, G_FILE_TEST_EXISTS), TRUE);
656
685
                g_print ("cNewThemePath : %s\n", cNewThemePath);
657
686
                
658
687
                //\___________________ On charge les parametres de comportement.
737
766
                }
738
767
                else
739
768
                {
740
 
                        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/icones et les .conf du dock et des plug-ins.
 
769
                        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.
741
770
                        cd_message (sCommand->str);
742
771
                        r = system (sCommand->str);
743
772
                        
744
773
                        gchar *cNewPlugInsDir = g_strdup_printf ("%s/%s", cNewThemePath, "plug-ins");
745
774
                        GDir *dir = g_dir_open (cNewPlugInsDir, 0, NULL);  // NULL si ce theme n'a pas de repertoire 'plug-ins'.
746
 
                        const gchar* cModuleName;
747
 
                        gchar *cConfFilePath, *cNewConfFilePath, *cUserDataDirPath;
 
775
                        const gchar* cModuleDirName;
 
776
                        gchar *cConfFilePath, *cNewConfFilePath, *cUserDataDirPath, *cConfFileName;
748
777
                        do
749
778
                        {
750
 
                                cModuleName = g_dir_read_name (dir);
751
 
                                if (cModuleName == NULL)
 
779
                                cModuleDirName = g_dir_read_name (dir);
 
780
                                if (cModuleDirName == NULL)
752
781
                                        break ;
753
782
                                
754
 
                                CairoDockModule *pModule =  cairo_dock_find_module_from_name (cModuleName);
 
783
                                /*CairoDockModule *pModule =  cairo_dock_find_module_from_name (cModuleName);
755
784
                                if (pModule == NULL || pModule->pVisitCard == NULL)
756
 
                                        continue;
 
785
                                        continue;*/
757
786
 
758
 
                                cd_debug ("  installing %s's config\n", cModuleName);
759
 
                                cUserDataDirPath = g_strdup_printf ("%s/plug-ins/%s", g_cCurrentThemePath, pModule->pVisitCard->cUserDataDir);
 
787
                                cd_debug ("  installing %s's config\n", cModuleDirName);
 
788
                                cUserDataDirPath = g_strdup_printf ("%s/plug-ins/%s", g_cCurrentThemePath, cModuleDirName);
760
789
                                if (! g_file_test (cUserDataDirPath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
761
790
                                {
762
791
                                        cd_debug ("    directory %s doesn't exist, it will be created.", cUserDataDirPath);
763
792
                                        
764
 
                                        gchar *command = g_strdup_printf ("mkdir -p %s", cUserDataDirPath);
 
793
                                        gchar *command = g_strdup_printf ("mkdir -p '%s'", cUserDataDirPath);
765
794
                                        r = system (command);
766
795
                                        g_free (command);
767
796
                                }
768
 
                                cConfFilePath = g_strdup_printf ("%s/%s", cUserDataDirPath, pModule->pVisitCard->cConfFileName);
769
 
                                cNewConfFilePath = g_strdup_printf ("%s/%s/%s", cNewPlugInsDir, pModule->pVisitCard->cUserDataDir, pModule->pVisitCard->cConfFileName);
 
797
                                
 
798
                                cConfFileName = g_strdup_printf ("%s.conf", cModuleDirName);
 
799
                                cNewConfFilePath = g_strdup_printf ("%s/%s/%s", cNewPlugInsDir, cModuleDirName, cConfFileName);
 
800
                                if (! g_file_test (cNewConfFilePath, G_FILE_TEST_EXISTS))
 
801
                                {
 
802
                                        g_free (cConfFileName);
 
803
                                        g_free (cNewConfFilePath);
 
804
                                        CairoDockModule *pModule = cairo_dock_foreach_module ((GHRFunc) _find_module_from_user_data_dir, cModuleDirName);
 
805
                                        if (pModule == NULL)  // du coup, dans ce cas-la, on ne charge pas des plug-ins non utilises par l'utilisateur.
 
806
                                        {
 
807
                                                cd_warning ("couldn't find the module owning '%s', this file will be ignored.");
 
808
                                                continue;
 
809
                                        }
 
810
                                        cConfFileName = g_strdup (pModule->pVisitCard->cConfFileName);
 
811
                                        cNewConfFilePath = g_strdup_printf ("%s/%s/%s", cNewPlugInsDir, cModuleDirName, cConfFileName);
 
812
                                }
 
813
                                cConfFilePath = g_strdup_printf ("%s/%s", cUserDataDirPath, cConfFileName);
770
814
                                
771
815
                                if (! g_file_test (cConfFilePath, G_FILE_TEST_EXISTS))
772
816
                                {
782
826
                                g_free (cNewConfFilePath);
783
827
                                g_free (cConfFilePath);
784
828
                                g_free (cUserDataDirPath);
 
829
                                g_free (cConfFileName);
785
830
                        }
786
831
                        while (1);
787
832
                        g_dir_close (dir);
798
843
        
799
844
        return TRUE;
800
845
}
801
 
gboolean cairo_dock_manage_themes (GtkWidget *pWidget, CairoDockStartMode iMode)
 
846
void cairo_dock_manage_themes (void)
802
847
{
 
848
        if (s_pThemeManager != NULL)
 
849
        {
 
850
                gtk_window_present (GTK_WINDOW (s_pThemeManager));
 
851
                return ;
 
852
        }
 
853
        
803
854
        gchar *cInitConfFile = cairo_dock_build_temporary_themes_conf_file ();  // sera supprime a la destruction de la fenetre.
804
855
        
805
856
        //\___________________ On laisse l'utilisateur l'editer.
806
857
        gchar *cPresentedGroup = (cairo_dock_theme_need_save () ? "Save" : NULL);
807
 
        const gchar *cTitle = (iMode == CAIRO_DOCK_START_SAFE ? _("< Safe Mode >") : _("Manage Themes"));
808
 
        
809
 
        CairoDialog *pDialog = NULL;
810
 
        if (iMode == CAIRO_DOCK_START_SAFE)
811
 
        {
812
 
                pDialog = cairo_dock_show_general_message (_("You are running Cairo-Dock in safe mode.\nWhy ? Probably because a plug-in has messed into your dock,\n or maybe your theme has got corrupted.\nSo, no plug-in will be available, and you can now save your current theme if you want\n before you start using the dock.\nTry with your current theme, if it works, it means a plug-in is wrong.\nOtherwise, try with another theme.\nSave a config that is working, and restart the dock in normal mode.\nThen, activate plug-ins one by one to guess which one is wrong."), 0.);
813
 
                g_print ("safe mode ...\n");
814
 
                while (gtk_events_pending ())
815
 
                        gtk_main_iteration ();
816
 
        }
817
 
        
818
 
        gpointer *data = g_new0 (gpointer, 3);
819
 
        data[0] = cInitConfFile;
820
 
        data[1] = NULL;
821
 
        data[2] = pDialog;
822
 
        if (iMode == CAIRO_DOCK_START_NOMINAL)
823
 
        {
824
 
                gboolean bChoiceOK = cairo_dock_build_normal_gui (cInitConfFile, NULL, cTitle, CAIRO_DOCK_THEME_PANEL_WIDTH, CAIRO_DOCK_THEME_PANEL_HEIGHT, (CairoDockApplyConfigFunc) on_theme_apply, data, (GFreeFunc) on_theme_destroy);
825
 
        }
826
 
        else  // maintenance ou sans echec.
827
 
        {
828
 
                gboolean bChoiceOK = cairo_dock_build_normal_gui (cInitConfFile, NULL, cTitle, CAIRO_DOCK_THEME_PANEL_WIDTH, CAIRO_DOCK_THEME_PANEL_HEIGHT, NULL, NULL, NULL);  // bloquant.
829
 
                on_theme_apply (data);
830
 
                on_theme_destroy (data);
831
 
        }
832
 
        
833
 
        return FALSE;
 
858
        const gchar *cTitle = _("Manage Themes");
 
859
        
 
860
        cairo_dock_build_normal_gui (cInitConfFile,
 
861
                NULL, cTitle,
 
862
                CAIRO_DOCK_THEME_PANEL_WIDTH, CAIRO_DOCK_THEME_PANEL_HEIGHT,
 
863
                (CairoDockApplyConfigFunc) on_theme_apply,
 
864
                cInitConfFile,
 
865
                (GFreeFunc) on_theme_destroy,
 
866
                &s_pThemeManager);
834
867
}
835
868
 
836
869
gchar *cairo_dock_get_theme_path (const gchar *cThemeName, const gchar *cShareThemesDir, const gchar *cUserThemesDir, const gchar *cDistantThemesDir)
861
894
        {
862
895
                gchar *cDistantFileName = g_strdup_printf ("%s/%s.tar.gz", cThemeName, cThemeName);
863
896
                GError *erreur = NULL;
864
 
                cThemePath = cairo_dock_download_file (g_cThemeServerAdress != NULL ? g_cThemeServerAdress : CAIRO_DOCK_THEME_SERVER, cDistantThemesDir, cDistantFileName, 2, cUserThemesDir, &erreur);
 
897
                cThemePath = cairo_dock_download_file (g_cThemeServerAdress != NULL ? g_cThemeServerAdress : CAIRO_DOCK_THEME_SERVER, cDistantThemesDir, cDistantFileName, 0, cUserThemesDir, &erreur);
865
898
                g_free (cDistantFileName);
866
899
                if (erreur != NULL)
867
900
                {
868
901
                        cd_warning ("couldn't retrieve distant theme %s : %s" , cThemeName, erreur->message);
 
902
                        cairo_dock_set_status_message_printf (s_pThemeManager, _("couldn't retrieve distant theme %s"), cThemeName);  // le message sera repris par une bulle de dialogue, mais on le met la aussi quand meme.
869
903
                        g_error_free (erreur);
870
904
                }
871
905
        }