root/trunk/third/nautilus/components/services/summary/lib/eazel-summary-shared.c @ 15547

Revision 15547, 8.7 KB (checked in by ghudson, 9 years ago)

This commit was generated by cvs2svn to compensate for changes in r15546,
which included commits to RCS files with non-trunk default branches.

Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3/*
4 * Copyright (C) 2000 Eazel, Inc
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 * Author: J Shane Culpepper <pepper@eazel.com>
22 */
23
24#include <config.h>
25
26#include "eazel-summary-shared.h"
27
28#include <libtrilobite/libtrilobite.h>
29#include <gnome.h>
30#include <glib.h>
31#include <gnome-xml/tree.h>
32#include <gnome-xml/parser.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <unistd.h>
36
37static GList * build_services_glist_from_xml (xmlNodePtr node);
38static GList * build_eazel_news_glist_from_xml (xmlNodePtr node);
39static GList * build_update_news_glist_from_xml (xmlNodePtr node);
40static SummaryData * summary_data_new (void);
41static ServicesData * services_data_new (void);
42static EazelNewsData * eazel_news_data_new (void);
43static UpdateNewsData * update_news_data_new (void);
44static ServicesData * parse_a_service (xmlNodePtr node);
45static EazelNewsData * parse_a_eazel_news_item (xmlNodePtr node);
46static UpdateNewsData * parse_a_update_news_item (xmlNodePtr node);
47
48
49static SummaryData *
50summary_data_new ()
51{
52        SummaryData     *return_value;
53        return_value = g_new0 (SummaryData, 1);
54
55        return_value->services_list = NULL;
56        return_value->eazel_news_list = NULL;
57        return_value->update_news_list = NULL;
58
59        return return_value;
60
61} /* end summary_data_new */
62
63static ServicesData *
64services_data_new ()
65{
66        ServicesData    *return_value;
67        return_value = g_new0 (ServicesData, 1);
68
69        return_value->name = NULL;
70        return_value->icon = NULL;
71        return_value->button_label = NULL;
72        return_value->description_header = NULL;
73        return_value->description = NULL;
74        return_value->enabled = TRUE;
75
76        return return_value;
77
78} /* end services_data_new */
79
80static EazelNewsData *
81eazel_news_data_new ()
82{
83        EazelNewsData   *return_value;
84        return_value = g_new0 (EazelNewsData, 1);
85
86        return_value->name = NULL;
87        return_value->icon = NULL;
88        return_value->date = NULL;
89        return_value->message = NULL;
90
91        return return_value;
92
93} /* end eazel_news_data_new */
94
95static UpdateNewsData *
96update_news_data_new ()
97{
98        UpdateNewsData  *return_value;
99        return_value = g_new0 (UpdateNewsData, 1);
100
101        return_value->name = NULL;
102        return_value->version = NULL;
103        return_value->priority = NULL;
104        return_value->description = NULL;
105        return_value->icon = NULL;
106        return_value->button_label = NULL;
107        return_value->uri = NULL;
108        return_value->softcat_uri = NULL;
109
110        return return_value;
111
112} /* end update_news_data_new */
113
114static ServicesData *
115parse_a_service (xmlNodePtr node)
116{
117        ServicesData    *return_value;
118        char            *tempbuf;
119
120        return_value = services_data_new ();
121
122        return_value->name = g_strdup (trilobite_xml_get_string (node, "NAME"));
123        return_value->icon = g_strdup (trilobite_xml_get_string (node, "ICON"));
124        return_value->button_label = g_strdup (trilobite_xml_get_string (node, "BUTTON_LABEL"));
125        return_value->uri = g_strdup (trilobite_xml_get_string (node, "URI"));
126        return_value->description_header = g_strdup (trilobite_xml_get_string (node, "DESCRIPTION_HEADER"));
127        return_value->description = g_strdup (trilobite_xml_get_string (node, "DESCRIPTION"));
128        tempbuf = g_strdup (trilobite_xml_get_string (node, "ENABLED"));
129        if (tempbuf[0] == 'T' || tempbuf[0] == 't') {
130                return_value->enabled = TRUE;
131        }
132        else if (tempbuf[0] == 'F' || tempbuf[0] == 'f') {
133                return_value->enabled = FALSE;
134        }
135        else {
136                g_warning (_("Could not find a valid boolean value for grey_out!"));
137                return_value->enabled = FALSE;
138        }
139
140        return return_value;
141
142} /* end parse_a_service */
143
144static EazelNewsData *
145parse_a_eazel_news_item (xmlNodePtr node)
146{
147        EazelNewsData *return_value;
148        return_value = eazel_news_data_new ();
149
150        return_value->name = g_strdup (trilobite_xml_get_string (node, "NAME"));
151        return_value->icon = g_strdup (trilobite_xml_get_string (node, "ICON"));
152        return_value->date = g_strdup (trilobite_xml_get_string (node, "DATE"));
153        return_value->message = g_strdup (trilobite_xml_get_string (node, "MESSAGE"));
154
155        return return_value;
156
157} /* end parse_a_eazel_news_item */
158
159static UpdateNewsData *
160parse_a_update_news_item (xmlNodePtr node)
161{
162        UpdateNewsData *return_value;
163        return_value = update_news_data_new ();
164
165        return_value->name = g_strdup (trilobite_xml_get_string (node, "NAME"));
166        return_value->version = g_strdup (trilobite_xml_get_string (node, "VERSION"));
167        return_value->priority = g_strdup (trilobite_xml_get_string (node, "PRIORITY"));
168        return_value->description = g_strdup (trilobite_xml_get_string (node, "DESCRIPTION"));
169        return_value->icon = g_strdup (trilobite_xml_get_string (node, "ICON"));
170        return_value->button_label = g_strdup (trilobite_xml_get_string (node, "BUTTON_LABEL"));
171        return_value->uri = g_strdup (trilobite_xml_get_string (node, "URI"));
172        return_value->softcat_uri = g_strdup (trilobite_xml_get_string (node, "SOFTCAT_URI"));
173
174        return return_value;
175
176} /* end parse_a_update_news_item */
177
178static GList *
179build_services_glist_from_xml (xmlNodePtr node)
180{
181        GList           *return_value;
182        xmlNodePtr      service;
183
184        return_value = NULL;
185        service = node->xmlChildrenNode;
186        if (service == NULL) {
187                g_warning (_("There is no service data !\n"));
188                return NULL;
189        }
190
191        while (service) {
192                ServicesData    *sdata;
193
194                sdata = parse_a_service (service);
195                return_value = g_list_append (return_value, sdata);
196                service = service->next;
197        }
198
199        return return_value;
200
201} /* end build_services_glist_from_xml */
202
203static GList *
204build_eazel_news_glist_from_xml (xmlNodePtr node)
205{
206        GList           *return_value;
207        xmlNodePtr      news_item;
208
209        return_value = NULL;
210        news_item = node->xmlChildrenNode;
211        if (news_item == NULL) {
212                g_warning (_("There is no eazel news data !\n"));
213                return NULL;
214        }
215
216        while (news_item) {
217                EazelNewsData   *ndata;
218
219                ndata = parse_a_eazel_news_item (news_item);
220                return_value = g_list_append (return_value, ndata);
221                news_item = news_item->next;
222        }
223
224        return return_value;
225
226} /* end build_eazel_news_glist_from_xml */
227
228static GList *
229build_update_news_glist_from_xml (xmlNodePtr node)
230{
231        GList           *return_value;
232        xmlNodePtr      news_item;
233
234        return_value = NULL;
235        news_item = node->xmlChildrenNode;
236        if (news_item == NULL) {
237                g_warning (_("There is no eazel news data !\n"));
238                return NULL;
239        }
240
241        while (news_item) {
242                UpdateNewsData  *ndata;
243
244                ndata = parse_a_update_news_item (news_item);
245                return_value = g_list_append (return_value, ndata);
246                news_item = news_item->next;
247        }
248
249        return return_value;
250
251} /* end build_update_news_glist_from_xml */
252
253
254SummaryData *
255parse_summary_xml_file (const char *url)
256{
257
258        SummaryData     *return_value;
259        char            *body;
260        int             length;
261        xmlDocPtr       doc;
262        xmlNodePtr      base;
263        xmlNodePtr      child;
264
265        /* fetch remote config file into memory */
266        if (! trilobite_fetch_uri (url, &body, &length)) {
267                g_assert (_("Could not fetch summary configuration !"));
268                return NULL;
269        }
270
271        /* <rant> libxml will have a temper tantrum if there is whitespace before the
272        *          * first tag.  so we must babysit it.
273        *                   */
274        while ((length > 0) && (*body <= ' ')) {
275                body++, length--;
276        }
277
278        doc = xmlParseMemory (body, length);
279         if (doc == NULL) {
280                 g_warning ("Invalid data in summary configuration: %s", body);
281                 return NULL;
282        }
283
284        return_value = summary_data_new ();
285
286        base = doc->root;
287
288        if (base == NULL) {
289                xmlFreeDoc (doc);
290                g_warning (_("The summary configuration contains no data!\n"));
291                return NULL;
292        }
293
294        if (g_strcasecmp (base->name, "SUMMARY_DATA")) {
295                g_print (_("Cannot find the SUMMARY_DATA xmlnode!\n"));
296                xmlFreeDoc (doc);
297                g_warning (_("Bailing from the SUMMARY_DATA parse!\n"));
298                return NULL;
299        }
300
301        child = doc->root->xmlChildrenNode;
302
303        if (child == NULL) {
304                g_print (_("Could not find any summary configuration data!\n"));
305                xmlFreeDoc (doc);
306                g_warning (_("Bailing from summary configuration parse!\n"));
307                return NULL;
308        }
309
310        while (child) {
311                if (g_strcasecmp (child->name, "SERVICES") == 0) {
312                        return_value->services_list = build_services_glist_from_xml (child);
313                }
314                if (g_strcasecmp (child->name, "EAZEL_NEWS") == 0) {
315                        return_value->eazel_news_list = build_eazel_news_glist_from_xml (child);
316                }
317                if (g_strcasecmp (child->name, "UPDATE_NEWS") == 0) {
318                        return_value->update_news_list = build_update_news_glist_from_xml (child);
319                }
320                child = child->next;
321        }
322
323        return return_value;
324
325} /* parse_summary_xml_file */
326
Note: See TracBrowser for help on using the browser.