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/>.
23
#include <libxml/tree.h>
24
#include <libxml/parser.h>
26
#include <cairo-dock.h>
27
#include "applet-struct.h"
28
#include "applet-xml.h"
29
#include "applet-draw.h"
34
void cd_doncky_free_item (TextZone *pTextZone)
36
if (pTextZone == NULL)
39
//g_free (pTextZone->cFont); // Pourquoi çà plante ??
40
g_free (pTextZone->cText);
41
g_free (pTextZone->cCommand);
46
void cd_doncky_free_item_list (CairoDockModuleInstance *myApplet)
48
if (myData.pTextZoneList == NULL)
54
for (t = myData.pTextZoneList; t != NULL; t = t->next)
57
cd_doncky_free_item (pTextZone);
59
g_list_free (myData.pTextZoneList);
60
myData.pTextZoneList = NULL;
63
gboolean cd_doncky_readxml (CairoDockModuleInstance *myApplet)
65
// On va lire le contenu de myConfig.cXmlFilePath
66
cd_debug ("Doncky-debug : ----------------------> myConfig.cXmlFilePath = \"%s\"",myConfig.cXmlFilePath);
69
g_return_val_if_fail (myConfig.cXmlFilePath != NULL, FALSE);
72
xmlNodePtr pXmlMainNode;
75
pXmlFile = cairo_dock_open_xml_file (myConfig.cXmlFilePath, "code", &pXmlMainNode, NULL);
77
g_return_val_if_fail (pXmlFile != NULL && pXmlMainNode != NULL, FALSE);
81
xmlChar *cAttribute, *cNodeContent, *cTextNodeContent;
82
TextZone *pTextZone = NULL;
87
for (pXmlNode = pXmlMainNode->children, i = 0; pXmlNode != NULL; pXmlNode = pXmlNode->next, i ++)
90
if (xmlStrcmp (pXmlNode->name, (const xmlChar *) "zone") == 0)
92
pTextZone = g_new0 (TextZone, 1);
93
myData.pTextZoneList = g_list_append (myData.pTextZoneList, pTextZone);
95
pTextZone->cCommand = NULL;
96
pTextZone->bRefresh = FALSE;
97
pTextZone->bEndOfLine = FALSE;
98
pTextZone->bBar = FALSE;
101
xmlNodePtr pXmlSubNode;
102
for (pXmlSubNode = pXmlNode->children; pXmlSubNode != NULL; pXmlSubNode = pXmlSubNode->next)
104
cNodeContent = xmlNodeGetContent (pXmlSubNode);
106
// On gère le refresh à part pour lui imposer à 0 si rien n'est renseigné
107
if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "refresh") == 0)
109
pTextZone->iRefresh = g_strtod (cNodeContent, NULL);
110
pTextZone->bRefresh = TRUE;
111
pTextZone->iTimer = pTextZone->iRefresh - 2 ; // On triche sur le timer à la lecture du xml pour avoir un refresh
115
if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "cmd") == 0 || xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "echo") == 0 || xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "internal") == 0)
117
pTextZone->bRefresh = TRUE;
118
pTextZone->iRefresh = 0;
122
// On gère l'alignement à part pour lui imposer à 'left' si rien n'est renseigné (ou si mal renseigné)
123
if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "align") == 0)
125
pTextZone->cAlign = xmlNodeGetContent (pXmlSubNode);
126
if (strcmp (pTextZone->cAlign, "left") == 0)
127
pTextZone->cAlign = g_strdup_printf("left");
128
else if (strcmp (pTextZone->cAlign, "center") == 0)
129
pTextZone->cAlign = g_strdup_printf("center");
130
else if (strcmp (pTextZone->cAlign, "right") == 0)
131
pTextZone->cAlign = g_strdup_printf("right");
133
pTextZone->cAlign = g_strdup_printf("left");
135
else if (pTextZone->cAlign == NULL)
136
pTextZone->cAlign = g_strdup_printf("left");
139
if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "font") == 0)
141
pTextZone->cFont = xmlNodeGetContent (pXmlSubNode);
143
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "red") == 0)
145
pTextZone->fTextColor[0] = g_strtod (cNodeContent, NULL);
147
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "green") == 0)
149
pTextZone->fTextColor[1] = g_strtod (cNodeContent, NULL);
151
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "blue") == 0)
153
pTextZone->fTextColor[2] = g_strtod (cNodeContent, NULL);
155
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "alpha") == 0)
157
pTextZone->fTextColor[3] = g_strtod (cNodeContent, NULL);
159
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "txt") == 0)
161
pTextZone->cText = xmlNodeGetContent (pXmlSubNode);
163
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "echo") == 0)
165
// On insère sh -c 'echo " AVANT la commande et "' APRES
167
cXmlCommand = xmlNodeGetContent (pXmlSubNode);
169
GString *sTemp = g_string_new ("");
170
g_string_printf (sTemp, "sh -c 'echo \"%s\"'", cXmlCommand);
171
pTextZone->cCommand = g_strdup_printf("%s",sTemp->str) ;
173
g_string_free (sTemp, TRUE);
174
g_free (cXmlCommand);
176
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "cmd") == 0)
178
pTextZone->cCommand = xmlNodeGetContent (pXmlSubNode);
180
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "br") == 0)
182
pTextZone->bEndOfLine = TRUE;
183
pTextZone->bNextNewLine = TRUE;
185
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "nbr") == 0)
187
pTextZone->bEndOfLine = TRUE;
188
pTextZone->bNextNewLine = FALSE;
190
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "internal") == 0)
191
pTextZone->cInternal = xmlNodeGetContent (pXmlSubNode);
195
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "lbar") == 0)
197
gchar *cTempo = xmlNodeGetContent (pXmlSubNode);
199
// On récupère le 1er champ -> = commande interne
200
g_strreverse (cTempo);
201
cTempo = strrchr(cTempo, ';') ;
202
ltrim( cTempo, ";" );
203
g_strreverse (cTempo);
204
pTextZone->cInternal = g_strdup_printf("%s", cTempo);
206
// On récupère le 2ème champ -> = Largeur
207
cTempo = strchr(xmlNodeGetContent (pXmlSubNode), ';') ;
208
ltrim( cTempo, ";" );
209
g_strreverse (cTempo);
210
cTempo = strchr(cTempo, ';') ;
211
ltrim( cTempo, ";" );
212
g_strreverse (cTempo);
213
pTextZone->iWidth = atoi(cTempo);
215
// On récupère le 3ème champ -> = Hauteur
216
cTempo = strrchr(xmlNodeGetContent (pXmlSubNode), ';') ;
217
ltrim( cTempo, ";" );
218
pTextZone->iHeight = atoi(cTempo);
220
pTextZone->bLimitedBar = TRUE;
223
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "bar") == 0)
225
gchar *cTempo = xmlNodeGetContent (pXmlSubNode);
227
// On récupère le 1er champ -> = commande interne
228
g_strreverse (cTempo);
229
cTempo = strrchr(cTempo, ';') ;
230
ltrim( cTempo, ";" );
231
g_strreverse (cTempo);
232
pTextZone->cInternal = g_strdup_printf("%s", cTempo);
234
// On récupère le 3ème champ -> = Hauteur
235
cTempo = strrchr(xmlNodeGetContent (pXmlSubNode), ';') ;
236
ltrim( cTempo, ";" );
237
pTextZone->iHeight = atoi(cTempo);
239
pTextZone->bBar = TRUE;
241
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "img") == 0)
243
pTextZone->cImgPath = xmlNodeGetContent (pXmlSubNode);
244
pTextZone->bImgDraw=FALSE;
246
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "imgsize") == 0)
248
pTextZone->iImgSize = g_strtod (cNodeContent, NULL);
250
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "imgsizeW") == 0)
252
pTextZone->iWidth= g_strtod (cNodeContent, NULL);
254
else if (xmlStrcmp (pXmlSubNode->name, (const xmlChar *) "imgsizeH") == 0)
256
pTextZone->iHeight = g_strtod (cNodeContent, NULL);
260
xmlFree (cNodeContent);
264
cairo_dock_close_xml_file (pXmlFile);