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 <stdlib.h>
21 #include <string.h>
22 
23 #include "cairo-dock-draw.h"
24 #include "cairo-dock-icon-factory.h"
25 #include "cairo-dock-keyfile-utilities.h"
26 #include "cairo-dock-dock-factory.h"
27 #include "cairo-dock-log.h"
28 #include "cairo-dock-animations.h"
29 #include "cairo-dock-dialog-manager.h"
30 #include "cairo-dock-desklet-manager.h"
31 #include "cairo-dock-dock-manager.h"
32 #include "cairo-dock-container.h"
33 #include "cairo-dock-config.h"
34 #include "cairo-dock-backends-manager.h"
35 
36 // public (manager, config, data)
37 GldiManager myBackendsMgr;
38 CairoBackendsParam myBackendsParam;
39 
40 // dependancies
41 extern gboolean g_bUseOpenGL;
42 
43 // private
44 static GHashTable *s_hRendererTable = NULL;  // table des rendus de dock.
45 static GHashTable *s_hDeskletRendererTable = NULL;  // table des rendus des desklets.
46 static GHashTable *s_hDialogRendererTable = NULL;  // table des rendus des dialogues.
47 static GHashTable *s_hDeskletDecorationsTable = NULL;  // table des decorations des desklets.
48 static GHashTable *s_hAnimationsTable = NULL;  // table des animations disponibles.
49 static GHashTable *s_hDialogDecoratorTable = NULL;  // table des decorateurs de dialogues disponibles.
50 static GHashTable *s_hHidingEffectTable = NULL;  // table des effets de cachage des docks.
51 static GHashTable *s_hIconContainerTable = NULL;  // table des rendus d'icones de container.
52 /*
53 typedef struct _CairoBackendMgr CairoBackendMgr;
54 struct _CairoBackendMgr {
55 	GHashTable *pTable;
56 	gpointer (*get_backend) (CairoBackendMgr *pBackendMgr, const gchar *cName);
57 	gpointer (*select_backend) (CairoBackendMgr *pBackendMgr, const gchar *cName, gpointer data);
58 	void (*register_backend) (CairoBackendMgr *pBackendMgr, const gchar *cName, gpointer pBackend);
59 	void (*remove_backend) (const gchar *cName);
60 	};
61 
62 gpointer _get_backend (CairoBackendMgr *pBackendMgr, const gchar *cName)
63 {
64 	gpointer pBackend = NULL;
65 	if (cName != NULL)
66 		pBackend = g_hash_table_lookup (pBackendMgr->pTable, cName);
67 	return pBackend;
68 }
69 
70 void _register_backend (CairoBackendMgr *pBackendMgr, const gchar *cName, gpointer pBackend)
71 {
72 	g_hash_table_insert (pBackendMgr->pTable, g_strdup (cName), pBackend);
73 }
74 
75 void _remove_backend (CairoBackendMgr *pBackendMgr, const gchar *cName)
76 {
77 	g_hash_table_remove (pBackendMgr->pTable, cName);
78 }*/
79 
80 
cairo_dock_get_renderer(const gchar * cRendererName,gboolean bForMainDock)81 CairoDockRenderer *cairo_dock_get_renderer (const gchar *cRendererName, gboolean bForMainDock)
82 {
83 	//g_print ("%s (%s, %d)\n", __func__, cRendererName, bForMainDock);
84 	CairoDockRenderer *pRenderer = NULL;
85 	if (cRendererName != NULL)
86 		pRenderer = g_hash_table_lookup (s_hRendererTable, cRendererName);
87 
88 	if (pRenderer == NULL)
89 	{
90 		const gchar *cDefaultRendererName = (bForMainDock ? myBackendsParam.cMainDockDefaultRendererName : myBackendsParam.cSubDockDefaultRendererName);
91 		//g_print ("  cDefaultRendererName : %s\n", cDefaultRendererName);
92 		if (cDefaultRendererName != NULL)
93 			pRenderer = g_hash_table_lookup (s_hRendererTable, cDefaultRendererName);
94 	}
95 
96 	if (pRenderer == NULL)
97 		pRenderer = g_hash_table_lookup (s_hRendererTable, CAIRO_DOCK_DEFAULT_RENDERER_NAME);
98 
99 	return pRenderer;
100 }
101 
cairo_dock_register_renderer(const gchar * cRendererName,CairoDockRenderer * pRenderer)102 void cairo_dock_register_renderer (const gchar *cRendererName, CairoDockRenderer *pRenderer)
103 {
104 	cd_message ("%s (%s)", __func__, cRendererName);
105 	g_hash_table_insert (s_hRendererTable, g_strdup (cRendererName), pRenderer);
106 }
107 
cairo_dock_remove_renderer(const gchar * cRendererName)108 void cairo_dock_remove_renderer (const gchar *cRendererName)
109 {
110 	g_hash_table_remove (s_hRendererTable, cRendererName);
111 }
112 
113 
cairo_dock_get_desklet_renderer(const gchar * cRendererName)114 CairoDeskletRenderer *cairo_dock_get_desklet_renderer (const gchar *cRendererName)
115 {
116 	if (cRendererName != NULL)
117 		return g_hash_table_lookup (s_hDeskletRendererTable, cRendererName);
118 	else
119 		return NULL;
120 }
121 
cairo_dock_register_desklet_renderer(const gchar * cRendererName,CairoDeskletRenderer * pRenderer)122 void cairo_dock_register_desklet_renderer (const gchar *cRendererName, CairoDeskletRenderer *pRenderer)
123 {
124 	cd_message ("%s (%s)", __func__, cRendererName);
125 	g_hash_table_insert (s_hDeskletRendererTable, g_strdup (cRendererName), pRenderer);
126 }
127 
cairo_dock_remove_desklet_renderer(const gchar * cRendererName)128 void cairo_dock_remove_desklet_renderer (const gchar *cRendererName)
129 {
130 	g_hash_table_remove (s_hDeskletRendererTable, cRendererName);
131 }
132 
cairo_dock_predefine_desklet_renderer_config(CairoDeskletRenderer * pRenderer,const gchar * cConfigName,CairoDeskletRendererConfigPtr pConfig)133 void cairo_dock_predefine_desklet_renderer_config (CairoDeskletRenderer *pRenderer, const gchar *cConfigName, CairoDeskletRendererConfigPtr pConfig)
134 {
135 	g_return_if_fail (cConfigName != NULL && pConfig != NULL);
136 	CairoDeskletRendererPreDefinedConfig *pPreDefinedConfig = g_new (CairoDeskletRendererPreDefinedConfig, 1);
137 	pPreDefinedConfig->cName = g_strdup (cConfigName);
138 	pPreDefinedConfig->pConfig = pConfig;
139 	pRenderer->pPreDefinedConfigList = g_list_prepend (pRenderer->pPreDefinedConfigList, pPreDefinedConfig);
140 }
141 
cairo_dock_get_desklet_renderer_predefined_config(const gchar * cRendererName,const gchar * cConfigName)142 CairoDeskletRendererConfigPtr cairo_dock_get_desklet_renderer_predefined_config (const gchar *cRendererName, const gchar *cConfigName)
143 {
144 	CairoDeskletRenderer *pRenderer = cairo_dock_get_desklet_renderer (cRendererName);
145 	g_return_val_if_fail (pRenderer != NULL && cConfigName != NULL, NULL);
146 
147 	GList *c;
148 	CairoDeskletRendererPreDefinedConfig *pPreDefinedConfig;
149 	for (c = pRenderer->pPreDefinedConfigList; c != NULL; c = c->next)
150 	{
151 		pPreDefinedConfig = c->data;
152 		if (strcmp (pPreDefinedConfig->cName, cConfigName) == 0)
153 			return pPreDefinedConfig->pConfig;
154 	}
155 	return NULL;
156 }
157 
158 
cairo_dock_get_dialog_renderer(const gchar * cRendererName)159 CairoDialogRenderer *cairo_dock_get_dialog_renderer (const gchar *cRendererName)
160 {
161 	if (cRendererName != NULL)
162 		return g_hash_table_lookup (s_hDialogRendererTable, cRendererName);
163 	else
164 		return NULL;
165 }
166 
cairo_dock_register_dialog_renderer(const gchar * cRendererName,CairoDialogRenderer * pRenderer)167 void cairo_dock_register_dialog_renderer (const gchar *cRendererName, CairoDialogRenderer *pRenderer)
168 {
169 	cd_message ("%s (%s)", __func__, cRendererName);
170 	g_hash_table_insert (s_hDialogRendererTable, g_strdup (cRendererName), pRenderer);
171 }
172 
cairo_dock_remove_dialog_renderer(const gchar * cRendererName)173 void cairo_dock_remove_dialog_renderer (const gchar *cRendererName)
174 {
175 	g_hash_table_remove (s_hDialogRendererTable, cRendererName);
176 }
177 
178 
cairo_dock_get_desklet_decoration(const gchar * cDecorationName)179 CairoDeskletDecoration *cairo_dock_get_desklet_decoration (const gchar *cDecorationName)
180 {
181 	if (cDecorationName != NULL)
182 		return g_hash_table_lookup (s_hDeskletDecorationsTable, cDecorationName);
183 	else if (myDeskletsParam.cDeskletDecorationsName != NULL)
184 		return g_hash_table_lookup (s_hDeskletDecorationsTable, myDeskletsParam.cDeskletDecorationsName);
185 	else
186 		return NULL;
187 }
188 
cairo_dock_register_desklet_decoration(const gchar * cDecorationName,CairoDeskletDecoration * pDecoration)189 void cairo_dock_register_desklet_decoration (const gchar *cDecorationName, CairoDeskletDecoration *pDecoration)
190 {
191 	cd_message ("%s (%s)", __func__, cDecorationName);
192 	g_hash_table_insert (s_hDeskletDecorationsTable, g_strdup (cDecorationName), pDecoration);
193 }
194 
cairo_dock_remove_desklet_decoration(const gchar * cDecorationName)195 void cairo_dock_remove_desklet_decoration (const gchar *cDecorationName)
196 {
197 	g_hash_table_remove (s_hDeskletDecorationsTable, cDecorationName);
198 }
199 
200 
201 // Hiding animations
cairo_dock_get_hiding_effect(const gchar * cHidingEffect)202 CairoDockHidingEffect *cairo_dock_get_hiding_effect (const gchar *cHidingEffect)
203 {
204 	if (cHidingEffect != NULL)
205 		return g_hash_table_lookup (s_hHidingEffectTable, cHidingEffect);
206 	else
207 		return NULL;
208 }
209 
cairo_dock_register_hiding_effect(const gchar * cHidingEffect,CairoDockHidingEffect * pEffect)210 void cairo_dock_register_hiding_effect (const gchar *cHidingEffect, CairoDockHidingEffect *pEffect)
211 {
212 	cd_message ("%s (%s)", __func__, cHidingEffect);
213 	g_hash_table_insert (s_hHidingEffectTable, g_strdup (cHidingEffect), pEffect);
214 }
215 
cairo_dock_remove_hiding_effect(const gchar * cHidingEffect)216 void cairo_dock_remove_hiding_effect (const gchar *cHidingEffect)
217 {
218 	g_hash_table_remove (s_hHidingEffectTable, cHidingEffect);
219 }
220 
221 
222 // Icon-Container renderers
cairo_dock_get_icon_container_renderer(const gchar * cRendererName)223 CairoIconContainerRenderer *cairo_dock_get_icon_container_renderer (const gchar *cRendererName)
224 {
225 	if (cRendererName != NULL)
226 		return g_hash_table_lookup (s_hIconContainerTable, cRendererName);
227 	else
228 		return NULL;
229 }
230 
cairo_dock_register_icon_container_renderer(const gchar * cRendererName,CairoIconContainerRenderer * pRenderer)231 void cairo_dock_register_icon_container_renderer (const gchar *cRendererName, CairoIconContainerRenderer *pRenderer)
232 {
233 	cd_message ("%s (%s)", __func__, cRendererName);
234 	g_hash_table_insert (s_hIconContainerTable, g_strdup (cRendererName), pRenderer);
235 }
236 
cairo_dock_remove_icon_container_renderer(const gchar * cRendererName)237 void cairo_dock_remove_icon_container_renderer (const gchar *cRendererName)
238 {
239 	g_hash_table_remove (s_hIconContainerTable, cRendererName);
240 }
241 
cairo_dock_foreach_icon_container_renderer(GHFunc pCallback,gpointer data)242 void cairo_dock_foreach_icon_container_renderer (GHFunc pCallback, gpointer data)
243 {
244 	g_hash_table_foreach (s_hIconContainerTable, pCallback, data);
245 }
246 
247 
cairo_dock_set_renderer(CairoDock * pDock,const gchar * cRendererName)248 void cairo_dock_set_renderer (CairoDock *pDock, const gchar *cRendererName)
249 {
250 	g_return_if_fail (pDock != NULL);
251 	cd_message ("%s (%x:%s)", __func__, pDock, cRendererName);
252 
253 	if (pDock->pRenderer && pDock->pRenderer->free_data)
254 	{
255 		pDock->pRenderer->free_data (pDock);
256 		pDock->pRendererData = NULL;
257 	}
258 	pDock->pRenderer = cairo_dock_get_renderer (cRendererName, (pDock->iRefCount == 0));
259 
260 	pDock->fMagnitudeMax = 1.;
261 	pDock->container.bUseReflect = pDock->pRenderer->bUseReflect;
262 
263 	int iAnimationDeltaT = pDock->container.iAnimationDeltaT;
264 	pDock->container.iAnimationDeltaT = (g_bUseOpenGL && pDock->pRenderer->render_opengl != NULL ? myContainersParam.iGLAnimationDeltaT : myContainersParam.iCairoAnimationDeltaT);
265 	if (pDock->container.iAnimationDeltaT == 0)
266 		pDock->container.iAnimationDeltaT = 30;  // le main dock est cree avant meme qu'on ait recupere la valeur en conf. Lorsqu'une vue lui sera attribuee, la bonne valeur sera renseignee, en attendant on met un truc non nul.
267 	if (iAnimationDeltaT != pDock->container.iAnimationDeltaT && pDock->container.iSidGLAnimation != 0)
268 	{
269 		g_source_remove (pDock->container.iSidGLAnimation);
270 		pDock->container.iSidGLAnimation = 0;
271 		cairo_dock_launch_animation (CAIRO_CONTAINER (pDock));
272 	}
273 	if (pDock->cRendererName != cRendererName)  // NULL ecrase le nom de l'ancienne vue.
274 	{
275 		g_free (pDock->cRendererName);
276 		pDock->cRendererName = g_strdup (cRendererName);
277 	}
278 }
279 
cairo_dock_set_default_renderer(CairoDock * pDock)280 void cairo_dock_set_default_renderer (CairoDock *pDock)
281 {
282 	g_return_if_fail (pDock != NULL);
283 	cairo_dock_set_renderer (pDock, pDock->cRendererName);  // NULL => laissera le champ cRendererName nul plutot que de mettre le nom de la vue par defaut.
284 }
285 
286 
cairo_dock_set_desklet_renderer(CairoDesklet * pDesklet,CairoDeskletRenderer * pRenderer,CairoDeskletRendererConfigPtr pConfig)287 void cairo_dock_set_desklet_renderer (CairoDesklet *pDesklet, CairoDeskletRenderer *pRenderer, CairoDeskletRendererConfigPtr pConfig)
288 {
289 	g_return_if_fail (pDesklet != NULL);
290 
291 	if (pDesklet->pRenderer != NULL && pDesklet->pRenderer->free_data != NULL)  // meme si pDesklet->pRendererData == NULL.
292 	{
293 		pDesklet->pRenderer->free_data (pDesklet);
294 		pDesklet->pRendererData = NULL;
295 	}
296 
297 	pDesklet->pRenderer = pRenderer;
298 	gtk_widget_set_double_buffered (pDesklet->container.pWidget, ! (g_bUseOpenGL && pRenderer != NULL && pRenderer->render_opengl != NULL));  // some renderers don't have an opengl version yet.
299 	pDesklet->container.iAnimationDeltaT = (g_bUseOpenGL && pRenderer != NULL && pRenderer->render_opengl != NULL ? myContainersParam.iGLAnimationDeltaT : myContainersParam.iCairoAnimationDeltaT);
300 	//g_print ("desklet: %d\n", pDesklet->container.iAnimationDeltaT);
301 
302 	if (pRenderer != NULL)
303 	{
304 		if (pRenderer->configure != NULL)
305 			pDesklet->pRendererData = pRenderer->configure (pDesklet, pConfig);
306 
307 		if (pRenderer->calculate_icons != NULL)
308 			pRenderer->calculate_icons (pDesklet);
309 
310 		Icon* pIcon = pDesklet->pIcon;
311 		if (pIcon)
312 			cairo_dock_load_icon_buffers (pIcon, CAIRO_CONTAINER (pDesklet));  // immediately, because the applet may need it to draw its stuff.
313 
314 		GList* ic;
315 		for (ic = pDesklet->icons; ic != NULL; ic = ic->next)
316 		{
317 			pIcon = ic->data;
318 			pIcon->iRequestedWidth = pIcon->fWidth;
319 			pIcon->iRequestedHeight = pIcon->fHeight;
320 			cairo_dock_trigger_load_icon_buffers (pIcon);
321 		}
322 
323 		if (pRenderer->load_data != NULL)
324 			pRenderer->load_data (pDesklet);
325 	}
326 }
327 
cairo_dock_set_desklet_renderer_by_name(CairoDesklet * pDesklet,const gchar * cRendererName,CairoDeskletRendererConfigPtr pConfig)328 void cairo_dock_set_desklet_renderer_by_name (CairoDesklet *pDesklet, const gchar *cRendererName, CairoDeskletRendererConfigPtr pConfig)
329 {
330 	cd_message ("%s (%s)", __func__, cRendererName);
331 	CairoDeskletRenderer *pRenderer = (cRendererName != NULL ? cairo_dock_get_desklet_renderer (cRendererName) : NULL);
332 
333 	cairo_dock_set_desklet_renderer (pDesklet, pRenderer, pConfig);
334 }
335 
336 
cairo_dock_set_dialog_renderer(CairoDialog * pDialog,CairoDialogRenderer * pRenderer,CairoDialogRendererConfigPtr pConfig)337 void cairo_dock_set_dialog_renderer (CairoDialog *pDialog, CairoDialogRenderer *pRenderer, CairoDialogRendererConfigPtr pConfig)
338 {
339 	g_return_if_fail (pDialog != NULL);
340 
341 	if (pDialog->pRenderer != NULL && pDialog->pRenderer->free_data != NULL)
342 	{
343 		pDialog->pRenderer->free_data (pDialog);
344 		pDialog->pRendererData = NULL;
345 	}
346 
347 	pDialog->pRenderer = pRenderer;
348 
349 	if (pRenderer != NULL)
350 	{
351 		if (pRenderer->configure != NULL)
352 			pDialog->pRendererData = pRenderer->configure (pDialog, pConfig);
353 	}
354 }
355 
cairo_dock_set_dialog_renderer_by_name(CairoDialog * pDialog,const gchar * cRendererName,CairoDialogRendererConfigPtr pConfig)356 void cairo_dock_set_dialog_renderer_by_name (CairoDialog *pDialog, const gchar *cRendererName, CairoDialogRendererConfigPtr pConfig)
357 {
358 	cd_message ("%s (%s)", __func__, cRendererName);
359 	CairoDialogRenderer *pRenderer = (cRendererName != NULL ? cairo_dock_get_dialog_renderer (cRendererName) : NULL);
360 
361 	cairo_dock_set_dialog_renderer (pDialog, pRenderer, pConfig);
362 }
363 
364 
cairo_dock_render_desklet_with_new_data(CairoDesklet * pDesklet,CairoDeskletRendererDataPtr pNewData)365 void cairo_dock_render_desklet_with_new_data (CairoDesklet *pDesklet, CairoDeskletRendererDataPtr pNewData)
366 {
367 	if (pDesklet->pRenderer != NULL && pDesklet->pRenderer->update != NULL)
368 		pDesklet->pRenderer->update (pDesklet, pNewData);
369 
370 	gtk_widget_queue_draw (pDesklet->container.pWidget);
371 }
372 
cairo_dock_render_dialog_with_new_data(CairoDialog * pDialog,CairoDialogRendererDataPtr pNewData)373 void cairo_dock_render_dialog_with_new_data (CairoDialog *pDialog, CairoDialogRendererDataPtr pNewData)
374 {
375 	if (pDialog->pRenderer != NULL && pDialog->pRenderer->update != NULL)
376 		pDialog->pRenderer->update (pDialog, pNewData);
377 
378 	if (pDialog->pInteractiveWidget != NULL)
379 		gldi_dialog_redraw_interactive_widget (pDialog);
380 	else
381 		gtk_widget_queue_draw (pDialog->container.pWidget);
382 }
383 
384 
cairo_dock_get_dialog_decorator(const gchar * cDecoratorName)385 CairoDialogDecorator *cairo_dock_get_dialog_decorator (const gchar *cDecoratorName)
386 {
387 	CairoDialogDecorator *pDecorator = NULL;
388 	if (cDecoratorName != NULL)
389 		pDecorator = g_hash_table_lookup (s_hDialogDecoratorTable, cDecoratorName);
390 	return pDecorator;
391 }
392 
cairo_dock_register_dialog_decorator(const gchar * cDecoratorName,CairoDialogDecorator * pDecorator)393 void cairo_dock_register_dialog_decorator (const gchar *cDecoratorName, CairoDialogDecorator *pDecorator)
394 {
395 	cd_message ("%s (%s)", __func__, cDecoratorName);
396 	g_hash_table_insert (s_hDialogDecoratorTable, g_strdup (cDecoratorName), pDecorator);
397 }
398 
cairo_dock_remove_dialog_decorator(const gchar * cDecoratorName)399 void cairo_dock_remove_dialog_decorator (const gchar *cDecoratorName)
400 {
401 	g_hash_table_remove (s_hDialogDecoratorTable, cDecoratorName);
402 }
403 
cairo_dock_set_dialog_decorator(CairoDialog * pDialog,CairoDialogDecorator * pDecorator)404 void cairo_dock_set_dialog_decorator (CairoDialog *pDialog, CairoDialogDecorator *pDecorator)
405 {
406 	pDialog->pDecorator = pDecorator;
407 }
cairo_dock_set_dialog_decorator_by_name(CairoDialog * pDialog,const gchar * cDecoratorName)408 void cairo_dock_set_dialog_decorator_by_name (CairoDialog *pDialog, const gchar *cDecoratorName)
409 {
410 	cd_message ("%s (%s)", __func__, cDecoratorName);
411 	CairoDialogDecorator *pDecorator = cairo_dock_get_dialog_decorator (cDecoratorName);
412 
413 	cairo_dock_set_dialog_decorator (pDialog, pDecorator);
414 }
415 
416 
cairo_dock_foreach_dock_renderer(GHFunc pFunction,gpointer data)417 void cairo_dock_foreach_dock_renderer (GHFunc pFunction, gpointer data)
418 {
419 	g_hash_table_foreach (s_hRendererTable, pFunction, data);
420 }
421 
cairo_dock_foreach_desklet_decoration(GHFunc pFunction,gpointer data)422 void cairo_dock_foreach_desklet_decoration (GHFunc pFunction, gpointer data)
423 {
424 	g_hash_table_foreach (s_hDeskletDecorationsTable, pFunction, data);
425 }
426 
cairo_dock_foreach_dialog_decorator(GHFunc pFunction,gpointer data)427 void cairo_dock_foreach_dialog_decorator (GHFunc pFunction, gpointer data)
428 {
429 	g_hash_table_foreach (s_hDialogDecoratorTable, pFunction, data);
430 }
431 
432 
433 static int iNbAnimation = 0;
cairo_dock_register_animation(const gchar * cAnimation,const gchar * cDisplayedName,gboolean bIsEffect)434 int cairo_dock_register_animation (const gchar *cAnimation, const gchar *cDisplayedName, gboolean bIsEffect)
435 {
436 	cd_message ("%s (%s)", __func__, cAnimation);
437 	iNbAnimation ++;
438 	CairoDockAnimationRecord *pRecord = g_new (CairoDockAnimationRecord, 1);
439 	pRecord->id = iNbAnimation;
440 	pRecord->cDisplayedName = cDisplayedName;
441 	pRecord->bIsEffect = bIsEffect;
442 	g_hash_table_insert (s_hAnimationsTable, g_strdup (cAnimation), pRecord);
443 	return iNbAnimation;
444 }
445 
cairo_dock_free_animation_record(CairoDockAnimationRecord * pRecord)446 void cairo_dock_free_animation_record (CairoDockAnimationRecord *pRecord)
447 {
448 	g_free (pRecord);
449 }
450 
cairo_dock_get_animation_id(const gchar * cAnimation)451 int cairo_dock_get_animation_id (const gchar *cAnimation)
452 {
453 	g_return_val_if_fail (cAnimation != NULL, 0);
454 	CairoDockAnimationRecord *pRecord = g_hash_table_lookup (s_hAnimationsTable, cAnimation);
455 	return (pRecord ? pRecord->id : 0);
456 }
457 
cairo_dock_get_animation_displayed_name(const gchar * cAnimation)458 const gchar *cairo_dock_get_animation_displayed_name (const gchar *cAnimation)
459 {
460 	g_return_val_if_fail (cAnimation != NULL, NULL);
461 	CairoDockAnimationRecord *pRecord = g_hash_table_lookup (s_hAnimationsTable, cAnimation);
462 	return (pRecord ? pRecord->cDisplayedName : NULL);
463 }
464 
cairo_dock_unregister_animation(const gchar * cAnimation)465 void cairo_dock_unregister_animation (const gchar *cAnimation)
466 {
467 	g_return_if_fail (cAnimation != NULL);
468 	g_hash_table_remove (s_hAnimationsTable, cAnimation);
469 }
470 
cairo_dock_foreach_animation(GHFunc pHFunction,gpointer data)471 void cairo_dock_foreach_animation (GHFunc pHFunction, gpointer data)
472 {
473 	g_hash_table_foreach (s_hAnimationsTable, pHFunction, data);
474 }
475 
476 
477   //////////////////
478  /// GET CONFIG ///
479 //////////////////
480 
get_config(GKeyFile * pKeyFile,CairoBackendsParam * pBackends)481 static gboolean get_config (GKeyFile *pKeyFile, CairoBackendsParam *pBackends)
482 {
483 	gboolean bFlushConfFileNeeded = FALSE;
484 
485 	// views
486 	pBackends->cMainDockDefaultRendererName = cairo_dock_get_string_key_value (pKeyFile, "Views", "main dock view", &bFlushConfFileNeeded, CAIRO_DOCK_DEFAULT_RENDERER_NAME, "Cairo Dock", NULL);
487 	if (pBackends->cMainDockDefaultRendererName == NULL)
488 		pBackends->cMainDockDefaultRendererName = g_strdup (CAIRO_DOCK_DEFAULT_RENDERER_NAME);
489 	cd_message ("cMainDockDefaultRendererName <- %s", pBackends->cMainDockDefaultRendererName);
490 
491 	pBackends->cSubDockDefaultRendererName = cairo_dock_get_string_key_value (pKeyFile, "Views", "sub-dock view", &bFlushConfFileNeeded, CAIRO_DOCK_DEFAULT_RENDERER_NAME, "Sub-Docks", NULL);
492 	if (pBackends->cSubDockDefaultRendererName == NULL)
493 		pBackends->cSubDockDefaultRendererName = g_strdup (CAIRO_DOCK_DEFAULT_RENDERER_NAME);
494 
495 	pBackends->fSubDockSizeRatio = cairo_dock_get_double_key_value (pKeyFile, "Views", "relative icon size", &bFlushConfFileNeeded, 0.8, "Sub-Docks", NULL);
496 
497 	// system
498 	pBackends->iUnfoldingDuration = cairo_dock_get_integer_key_value (pKeyFile, "System", "unfold duration", &bFlushConfFileNeeded, 400, NULL, NULL);
499 
500 	int iNbSteps = cairo_dock_get_integer_key_value (pKeyFile, "System", "grow nb steps", &bFlushConfFileNeeded, 10, NULL, NULL);
501 	iNbSteps = MAX (iNbSteps, 1);
502 	pBackends->iGrowUpInterval = MAX (1, CAIRO_DOCK_NB_MAX_ITERATIONS / iNbSteps);
503 
504 	iNbSteps = cairo_dock_get_integer_key_value (pKeyFile, "System", "shrink nb steps", &bFlushConfFileNeeded, 8, NULL, NULL);
505 	iNbSteps = MAX (iNbSteps, 1);
506 	pBackends->iShrinkDownInterval = MAX (1, CAIRO_DOCK_NB_MAX_ITERATIONS / iNbSteps);
507 
508 	pBackends->iUnhideNbSteps = cairo_dock_get_integer_key_value (pKeyFile, "System", "move up nb steps", &bFlushConfFileNeeded, 10, NULL, NULL);
509 
510 	pBackends->iHideNbSteps = cairo_dock_get_integer_key_value (pKeyFile, "System", "move down nb steps", &bFlushConfFileNeeded, 12, NULL, NULL);
511 
512 	// frequence de rafraichissement.
513 	int iRefreshFrequency = cairo_dock_get_integer_key_value (pKeyFile, "System", "refresh frequency", &bFlushConfFileNeeded, 25, NULL, NULL);
514 	pBackends->fRefreshInterval = 1000. / iRefreshFrequency;
515 	pBackends->bDynamicReflection = cairo_dock_get_boolean_key_value (pKeyFile, "System", "dynamic reflection", &bFlushConfFileNeeded, FALSE, NULL, NULL);
516 
517 	return bFlushConfFileNeeded;
518 }
519 
520 
521   ////////////////////
522  /// RESET CONFIG ///
523 ////////////////////
524 
reset_config(CairoBackendsParam * pBackendsParam)525 static void reset_config (CairoBackendsParam *pBackendsParam)
526 {
527 	// views
528 	g_free (pBackendsParam->cMainDockDefaultRendererName);
529 	g_free (pBackendsParam->cSubDockDefaultRendererName);
530 
531 	// system
532 }
533 
534 
535   ////////////
536  /// LOAD ///
537 ////////////
538 
539 
540   //////////////
541  /// RELOAD ///
542 //////////////
543 
reload(CairoBackendsParam * pPrevBackendsParam,CairoBackendsParam * pBackendsParam)544 static void reload (CairoBackendsParam *pPrevBackendsParam, CairoBackendsParam *pBackendsParam)
545 {
546 	CairoBackendsParam *pPrevViews = pPrevBackendsParam;
547 
548 	// views
549 	if (g_strcmp0 (pPrevViews->cMainDockDefaultRendererName, pBackendsParam->cMainDockDefaultRendererName) != 0)
550 	{
551 		cairo_dock_set_all_views_to_default (1);  // met a jour la taille des docks principaux.
552 		gldi_docks_redraw_all_root ();
553 	}
554 
555 	if (g_strcmp0 (pPrevViews->cSubDockDefaultRendererName, pBackendsParam->cSubDockDefaultRendererName) != 0
556 	|| pPrevViews->fSubDockSizeRatio != pBackendsParam->fSubDockSizeRatio)
557 	{
558 		cairo_dock_set_all_views_to_default (2);  // met a jour la taille des sous-docks.
559 	}
560 }
561 
562 
563   ////////////
564  /// INIT ///
565 ////////////
566 
init(void)567 static void init (void)
568 {
569 	s_hRendererTable = g_hash_table_new_full (g_str_hash,
570 		g_str_equal,
571 		g_free,
572 		g_free);
573 
574 	s_hDeskletRendererTable = g_hash_table_new_full (g_str_hash,
575 		g_str_equal,
576 		g_free,
577 		g_free);
578 
579 	s_hDialogRendererTable = g_hash_table_new_full (g_str_hash,
580 		g_str_equal,
581 		g_free,
582 		g_free);
583 
584 	s_hDeskletDecorationsTable = g_hash_table_new_full (g_str_hash,
585 		g_str_equal,
586 		g_free,
587 		(GFreeFunc) gldi_desklet_decoration_free);
588 
589 	s_hAnimationsTable = g_hash_table_new_full (g_str_hash,
590 		g_str_equal,
591 		g_free,
592 		(GFreeFunc) cairo_dock_free_animation_record);
593 
594 	s_hDialogDecoratorTable = g_hash_table_new_full (g_str_hash,
595 		g_str_equal,
596 		g_free,
597 		g_free);
598 
599 	s_hHidingEffectTable = g_hash_table_new_full (g_str_hash,
600 		g_str_equal,
601 		g_free,
602 		g_free);
603 
604 	s_hIconContainerTable = g_hash_table_new_full (g_str_hash,
605 		g_str_equal,
606 		g_free,
607 		g_free);
608 }
609 
610 
611   ///////////////
612  /// MANAGER ///
613 ///////////////
614 
gldi_register_backends_manager(void)615 void gldi_register_backends_manager (void)
616 {
617 	// Manager
618 	memset (&myBackendsMgr, 0, sizeof (GldiManager));
619 	gldi_object_init (GLDI_OBJECT(&myBackendsMgr), &myManagerObjectMgr, NULL);
620 	myBackendsMgr.cModuleName 	= "Backends";
621 	// interface
622 	myBackendsMgr.init 			= init;
623 	myBackendsMgr.load 			= NULL;
624 	myBackendsMgr.unload 		= NULL;
625 	myBackendsMgr.reload 		= (GldiManagerReloadFunc)reload;
626 	myBackendsMgr.get_config 	= (GldiManagerGetConfigFunc)get_config;
627 	myBackendsMgr.reset_config  = (GldiManagerResetConfigFunc)reset_config;
628 	// Config
629 	myBackendsMgr.pConfig = (GldiManagerConfigPtr)&myBackendsParam;
630 	myBackendsMgr.iSizeOfConfig = sizeof (CairoBackendsParam);
631 	// data
632 	myBackendsMgr.pData = (GldiManagerDataPtr)NULL;
633 	myBackendsMgr.iSizeOfData = 0;
634 }
635