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/>.
21
#include "cairo-dock-struct.h"
22
#include "cairo-dock-keyfile-utilities.h"
23
#include "cairo-dock-module-manager.h"
24
#include "cairo-dock-module-factory.h"
25
#include "cairo-dock-gui-factory.h"
26
#include "cairo-dock-log.h"
27
#include "cairo-dock-X-manager.h"
28
#include "cairo-dock-widget-config-group.h"
30
#define CAIRO_DOCK_ICON_MARGIN 6
31
extern gchar *g_cConfFile;
34
static void _config_group_widget_apply (CDWidget *pCdWidget)
36
ConfigGroupWidget *pConfigGroupWidget = CONFIG_GROUP_WIDGET (pCdWidget);
38
// update the conf file.
39
GKeyFile *pKeyFile = cairo_dock_open_key_file (g_cConfFile);
40
g_return_if_fail (pKeyFile != NULL);
42
cairo_dock_update_keyfile_from_widget_list (pKeyFile, pCdWidget->pWidgetList);
43
cairo_dock_write_keys_to_file (pKeyFile, g_cConfFile);
44
g_key_file_free (pKeyFile);
46
// reload the associated managers.
47
const gchar *cManagerName, *cModuleName;
48
CairoDockModule *pModule;
49
CairoDockModuleInstance *pExtraInstance;
50
GldiManager *pManager;
51
GSList *pExtraWidgetList;
52
GKeyFile* pExtraKeyFile;
54
GSList *w = pConfigGroupWidget->pExtraWidgets;
55
for (m = pConfigGroupWidget->pManagers; m != NULL; m = m->next)
57
cManagerName = m->data;
58
pManager = gldi_get_manager (cManagerName);
59
g_return_if_fail (pManager != NULL);
60
gldi_reload_manager (pManager, g_cConfFile);
62
// reload the extensions too
63
for (e = pManager->pExternalModules; e != NULL && w != NULL; e = e->next)
66
cModuleName = e->data;
67
pModule = cairo_dock_find_module_from_name (cModuleName);
71
pExtraInstance = pModule->pInstancesList->data;
72
if (pExtraInstance == NULL)
75
// update its conf file
76
pExtraKeyFile = cairo_dock_open_key_file (pExtraInstance->cConfFilePath);
77
if (pExtraKeyFile == NULL)
80
pExtraWidgetList = w->data;
83
cairo_dock_update_keyfile_from_widget_list (pExtraKeyFile, pExtraWidgetList);
84
if (pModule->pInterface->save_custom_widget != NULL)
85
pModule->pInterface->save_custom_widget (pExtraInstance, pKeyFile, pExtraWidgetList);
86
cairo_dock_write_keys_to_file (pExtraKeyFile, pExtraInstance->cConfFilePath);
87
g_key_file_free (pExtraKeyFile);
90
cairo_dock_reload_module_instance (pExtraInstance, TRUE);
95
static void _config_group_widget_reset (CDWidget *pCdWidget)
97
ConfigGroupWidget *pConfigGroupWidget = CONFIG_GROUP_WIDGET (pCdWidget);
98
g_free (pConfigGroupWidget->cGroupName);
99
g_slist_foreach (pConfigGroupWidget->pExtraWidgets, (GFunc)cairo_dock_free_generated_widget_list, NULL);
100
g_slist_free (pConfigGroupWidget->pExtraWidgets);
101
memset (pCdWidget+1, 0, sizeof (ConfigGroupWidget) - sizeof (CDWidget)); // reset all our parameters.
104
ConfigGroupWidget *cairo_dock_config_group_widget_new (const gchar *cGroupName, GList *pManagers, const gchar *cTitle, const gchar *cIcon)
106
ConfigGroupWidget *pConfigGroupWidget = g_new0 (ConfigGroupWidget, 1);
107
pConfigGroupWidget->widget.iType = WIDGET_CONFIG_GROUP;
108
pConfigGroupWidget->widget.apply = _config_group_widget_apply;
109
pConfigGroupWidget->widget.reset = _config_group_widget_reset;
110
pConfigGroupWidget->cGroupName = g_strdup (cGroupName);
111
pConfigGroupWidget->pManagers = pManagers;
113
// build its widget based on its config file.
114
GKeyFile* pKeyFile = cairo_dock_open_key_file (g_cConfFile);
115
g_return_val_if_fail (pKeyFile != NULL, NULL);
117
GSList *pWidgetList = NULL;
118
GPtrArray *pDataGarbage = g_ptr_array_new ();
119
GtkWidget *pWidget = cairo_dock_build_group_widget (pKeyFile,
121
NULL, // gettext domain
125
g_strdup (CAIRO_DOCK_SHARE_DATA_DIR"/"CAIRO_DOCK_CONF_FILE));
126
pConfigGroupWidget->widget.pWidgetList = pWidgetList;
127
pConfigGroupWidget->widget.pDataGarbage = pDataGarbage;
129
// build the widgets of the extensions
130
GtkWidget *pNoteBook = NULL;
131
GKeyFile* pExtraKeyFile;
132
CairoDockModule *pModule;
133
CairoDockModuleInstance *pExtraInstance;
134
GSList *pExtraWidgetList;
135
gchar *cOriginalConfFilePath;
136
GldiManager *pManager;
137
const gchar *cManagerName, *cModuleName;
139
for (m = pManagers; m != NULL; m = m->next)
141
cManagerName = m->data;
142
pManager = gldi_get_manager (cManagerName);
146
for (e = pManager->pExternalModules; e != NULL; e = e->next)
148
cModuleName = e->data;
149
pModule = cairo_dock_find_module_from_name (cModuleName);
153
pExtraInstance = pModule->pInstancesList->data;
154
if (pExtraInstance == NULL)
157
pExtraKeyFile = cairo_dock_open_key_file (pExtraInstance->cConfFilePath);
158
if (pExtraKeyFile == NULL)
161
pExtraWidgetList = NULL;
162
cOriginalConfFilePath = g_strdup_printf ("%s/%s", pModule->pVisitCard->cShareDataDir, pModule->pVisitCard->cConfFileName);
163
pNoteBook = cairo_dock_build_key_file_widget (pExtraKeyFile,
164
pModule->pVisitCard->cGettextDomain,
167
pDataGarbage, // the garbage array can be mutualized with 'pConfigGroupWidget'
168
cOriginalConfFilePath); /// TODO : fournir pNoteBook a la fonction pour fusionner les differents modules extra...
170
pConfigGroupWidget->pExtraWidgets = g_slist_append (pConfigGroupWidget->pExtraWidgets, pExtraWidgetList); // append, so that we can parse the list in the same order again.
172
if (pModule->pInterface->load_custom_widget != NULL)
173
pModule->pInterface->load_custom_widget (pExtraInstance, pExtraKeyFile, pExtraWidgetList);
175
///g_free (cOriginalConfFilePath);
176
g_key_file_free (pExtraKeyFile);
180
// on rajoute la page du module interne en 1er dans le notebook.
181
if (pNoteBook != NULL)
183
GtkWidget *pLabel = gtk_label_new (cTitle);
184
GtkWidget *pLabelContainer = NULL;
185
GtkWidget *pAlign = NULL;
186
if (cIcon != NULL && *cIcon != '\0')
188
pLabelContainer = _gtk_hbox_new (CAIRO_DOCK_ICON_MARGIN);
189
pAlign = gtk_alignment_new (0., 0.5, 0., 0.);
190
gtk_container_add (GTK_CONTAINER (pAlign), pLabelContainer);
192
GtkWidget *pImage = _gtk_image_new_from_file (cIcon, GTK_ICON_SIZE_BUTTON);
193
gtk_container_add (GTK_CONTAINER (pLabelContainer),
195
gtk_container_add (GTK_CONTAINER (pLabelContainer), pLabel);
196
gtk_widget_show_all (pLabelContainer);
199
GtkWidget *pScrolledWindow = gtk_scrolled_window_new (NULL, NULL); // add scrollbars on the widget before putting it into the notebook.
200
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (pScrolledWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
201
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (pScrolledWindow), pWidget);
203
gtk_notebook_prepend_page (GTK_NOTEBOOK (pNoteBook), pScrolledWindow, (pAlign != NULL ? pAlign : pLabel));
207
pConfigGroupWidget->widget.pWidget = pWidget;
209
g_key_file_free (pKeyFile);
210
return pConfigGroupWidget;