2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
22
#define __USE_XOPEN_EXTENDED
27
#include <glib/gstdio.h>
28
#include <glib/gi18n.h>
31
#include "cairo-dock-keyfile-utilities.h"
32
#include "cairo-dock-file-manager.h" // cairo_dock_copy_file
33
#include "cairo-dock-packages.h"
34
#include "cairo-dock-log.h"
35
#include "cairo-dock-gui-manager.h"
36
#include "cairo-dock-gui-factory.h"
37
#include "cairo-dock-log.h"
38
#include "cairo-dock-config.h" // cairo_dock_load_current_theme
39
#include "cairo-dock-themes-manager.h"
40
#include "cairo-dock-gui-commons.h"
41
#include "cairo-dock-gui-themes.h"
43
#define CAIRO_DOCK_THEME_PANEL_WIDTH 1000
44
#define CAIRO_DOCK_THEME_PANEL_HEIGHT 550
46
extern gchar *g_cThemesDirPath;
48
static GtkWidget *s_pThemeManager = NULL;
49
static CairoDockTask *s_pImportTask = NULL;
52
static gchar *cairo_dock_build_temporary_themes_conf_file (void)
54
//\___________________ On cree un fichier de conf temporaire.
55
const gchar *cTmpDir = g_get_tmp_dir ();
56
gchar *cTmpConfFile = g_strdup_printf ("%s/cairo-dock-init.XXXXXX", cTmpDir);
57
int fds = mkstemp (cTmpConfFile);
60
cd_warning ("can't create a temporary file in %s", cTmpDir);
61
g_free (cTmpConfFile);
65
//\___________________ On copie le fichier de conf par defaut dedans.
66
cairo_dock_copy_file (CAIRO_DOCK_SHARE_DATA_DIR"/themes.conf", cTmpConfFile);
67
/*gchar *cCommand = g_strdup_printf ("cp \"%s\" \"%s\"", CAIRO_DOCK_SHARE_DATA_DIR"/themes.conf", cTmpConfFile);
68
int r = system (cCommand);
76
static void _cairo_dock_fill_model_with_themes (const gchar *cThemeName, CairoDockPackage *pTheme, GtkListStore *pModele)
79
memset (&iter, 0, sizeof (GtkTreeIter));
80
gtk_list_store_append (GTK_LIST_STORE (pModele), &iter);
82
gtk_list_store_set (GTK_LIST_STORE (pModele), &iter,
83
CAIRO_DOCK_MODEL_NAME, pTheme->cDisplayedName,
84
CAIRO_DOCK_MODEL_RESULT, cThemeName, -1);
86
static void _cairo_dock_activate_one_element (GtkCellRendererToggle * cell_renderer, gchar * path, GtkTreeModel * model)
89
if (! gtk_tree_model_get_iter_from_string (model, &iter, path))
92
gtk_tree_model_get (model, &iter, CAIRO_DOCK_MODEL_ACTIVE, &bState, -1);
94
gtk_list_store_set (GTK_LIST_STORE (model), &iter, CAIRO_DOCK_MODEL_ACTIVE, !bState, -1);
96
static void _make_widgets (GtkWidget *pThemeManager, GKeyFile *pKeyFile)
98
cairo_dock_make_tree_view_for_delete_themes (pThemeManager);
102
static void _load_theme (gboolean bSuccess, GtkWidget *pWaitingDialog)
104
if (s_pThemeManager == NULL) // si l'utilisateur a ferme la fenetre entre-temps, on considere qu'il a abandonne.
108
cairo_dock_load_current_theme ();
110
cairo_dock_set_status_message (s_pThemeManager, "");
111
cairo_dock_reload_generic_gui (s_pThemeManager);
114
cairo_dock_set_status_message (s_pThemeManager, _("Could not import the theme."));
115
gtk_widget_destroy (pWaitingDialog);
118
static void on_theme_destroy (gchar *cInitConfFile)
121
g_remove (cInitConfFile);
122
g_free (cInitConfFile);
123
s_pThemeManager = NULL;
126
static gboolean on_theme_apply (gchar *cInitConfFile)
128
cd_debug ("%s (%s)", __func__, cInitConfFile);
129
GError *erreur = NULL;
130
int r; // resultat de system().
132
//\___________________ On recupere l'onglet courant.
133
GtkWidget * pMainVBox = gtk_bin_get_child (GTK_BIN (s_pThemeManager));
134
GList *children = gtk_container_get_children (GTK_CONTAINER (pMainVBox));
135
g_return_val_if_fail (children != NULL, FALSE);
136
GtkWidget *pGroupWidget = children->data;
137
g_list_free (children);
138
int iNumPage = gtk_notebook_get_current_page (GTK_NOTEBOOK (pGroupWidget));
140
//\_______________ On recupere l'onglet courant.
141
GKeyFile* pKeyFile = cairo_dock_open_key_file (cInitConfFile);
142
g_return_val_if_fail (pKeyFile != NULL, FALSE);
144
//\_______________ On effectue les actions correspondantes.
145
gboolean bReloadWindow = FALSE;
148
case 0: // load a theme
149
cairo_dock_set_status_message (s_pThemeManager, _("Importing theme ..."));
150
cairo_dock_load_theme (pKeyFile, (GFunc) _load_theme, s_pThemeManager); // bReloadWindow reste a FALSE, on ne rechargera la fenetre que lorsque le theme aura ete importe.
153
case 1: // save current theme
154
bReloadWindow = cairo_dock_save_current_theme (pKeyFile);
156
cairo_dock_set_status_message (s_pThemeManager, _("Theme has been saved"));
159
case 2: // delete some themes
160
bReloadWindow = cairo_dock_delete_user_themes (pKeyFile);
162
cairo_dock_set_status_message (s_pThemeManager, _("Themes have been deleted"));
165
g_key_file_free (pKeyFile);
167
return !bReloadWindow;
170
void cairo_dock_manage_themes (void)
172
if (s_pThemeManager != NULL)
174
gtk_window_present (GTK_WINDOW (s_pThemeManager));
178
gchar *cInitConfFile = cairo_dock_build_temporary_themes_conf_file (); // sera supprime a la destruction de la fenetre.
180
//\___________________ On laisse l'utilisateur l'editer.
181
const gchar *cPresentedGroup = (cairo_dock_current_theme_need_save () ? "Save" : NULL);
182
const gchar *cTitle = _("Manage Themes");
184
s_pThemeManager = cairo_dock_build_generic_gui_full (cInitConfFile,
186
CAIRO_DOCK_THEME_PANEL_WIDTH, CAIRO_DOCK_THEME_PANEL_HEIGHT,
187
(CairoDockApplyConfigFunc) on_theme_apply,
189
(GFreeFunc) on_theme_destroy,