~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to capplets/default-applications/gnome-da-xml.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Authors: Luca Cavalli <loopback@slackit.org>
3
 
 *
4
 
 *  Copyright 2005-2006 Luca Cavalli
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of version 2 of the GNU General Public License
8
 
 *  as published by the Free Software Foundation
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
18
 
 *
19
 
 */
20
 
 
21
 
#include <string.h>
22
 
#include <glib.h>
23
 
#include <glib/gi18n.h>
24
 
#include <libxml/parser.h>
25
 
 
26
 
#include "gnome-da-capplet.h"
27
 
#include "gnome-da-xml.h"
28
 
#include "gnome-da-item.h"
29
 
 
30
 
 
31
 
static gboolean
32
 
gnome_da_xml_get_bool (const xmlNode *parent, const gchar *val_name)
33
 
{
34
 
    xmlNode *element;
35
 
    gboolean ret_val = FALSE;
36
 
    xmlChar *xml_val_name;
37
 
    gint len;
38
 
 
39
 
    g_return_val_if_fail (parent != NULL, FALSE);
40
 
    g_return_val_if_fail (parent->children != NULL, ret_val);
41
 
    g_return_val_if_fail (val_name != NULL, FALSE);
42
 
 
43
 
    xml_val_name = xmlCharStrdup (val_name);
44
 
    len = xmlStrlen (xml_val_name);
45
 
 
46
 
    for (element = parent->children; element != NULL; element = element->next) {
47
 
        if (!xmlStrncmp (element->name, xml_val_name, len)) {
48
 
            xmlChar *cont = xmlNodeGetContent (element);
49
 
 
50
 
            if (!xmlStrcasecmp (cont, "true") || !xmlStrcasecmp (cont, "1"))
51
 
                ret_val = TRUE;
52
 
            else
53
 
                ret_val = FALSE;
54
 
 
55
 
            xmlFree (cont);
56
 
        }
57
 
    }
58
 
 
59
 
    xmlFree (xml_val_name);
60
 
    return ret_val;
61
 
}
62
 
 
63
 
static gchar*
64
 
gnome_da_xml_get_string (const xmlNode *parent, const gchar *val_name)
65
 
{
66
 
    const gchar * const *sys_langs;
67
 
    xmlChar *node_lang;
68
 
    xmlNode *element;
69
 
    gchar *ret_val = NULL;
70
 
    xmlChar *xml_val_name;
71
 
    gint len;
72
 
    gint i;
73
 
 
74
 
    g_return_val_if_fail (parent != NULL, ret_val);
75
 
    g_return_val_if_fail (parent->children != NULL, ret_val);
76
 
    g_return_val_if_fail (val_name != NULL, ret_val);
77
 
 
78
 
#if GLIB_CHECK_VERSION (2, 6, 0)
79
 
    sys_langs = g_get_language_names ();
80
 
#endif
81
 
 
82
 
    xml_val_name = xmlCharStrdup (val_name);
83
 
    len = xmlStrlen (xml_val_name);
84
 
 
85
 
    for (element = parent->children; element != NULL; element = element->next) {
86
 
        if (!xmlStrncmp (element->name, xml_val_name, len)) {
87
 
            node_lang = xmlNodeGetLang (element);
88
 
 
89
 
            if (node_lang == NULL) {
90
 
                ret_val = (gchar *) xmlNodeGetContent (element);
91
 
            }
92
 
            else {
93
 
                for (i = 0; sys_langs[i] != NULL; i++) {
94
 
                    if (!strcmp (sys_langs[i], node_lang)) {
95
 
                        ret_val = (gchar *) xmlNodeGetContent (element);
96
 
                        /* since sys_langs is sorted from most desirable to
97
 
                         * least desirable, exit at first match
98
 
                         */
99
 
                        break;
100
 
                    }
101
 
                }
102
 
            }
103
 
            xmlFree (node_lang);
104
 
        }
105
 
    }
106
 
 
107
 
    xmlFree (xml_val_name);
108
 
    return ret_val;
109
 
}
110
 
 
111
 
static gboolean
112
 
is_executable_valid (gchar *executable)
113
 
{
114
 
    gchar *path;
115
 
 
116
 
    path = g_find_program_in_path (executable);
117
 
 
118
 
    if (path) {
119
 
        g_free (path);
120
 
        return TRUE;
121
 
    }
122
 
 
123
 
    return FALSE;
124
 
}
125
 
 
126
 
static void
127
 
gnome_da_xml_load_xml (GnomeDACapplet *capplet, const gchar * filename)
128
 
{
129
 
    xmlDoc *xml_doc;
130
 
    xmlNode *root, *section, *element;
131
 
    gchar *executable;
132
 
    GnomeDAWebItem *web_item;
133
 
    GnomeDASimpleItem *mail_item;
134
 
    GnomeDASimpleItem *media_item;
135
 
    GnomeDATermItem *term_item;
136
 
    GnomeDAVisualItem *visual_item;
137
 
    GnomeDAMobilityItem *mobility_item;
138
 
 
139
 
    xml_doc = xmlParseFile (filename);
140
 
 
141
 
    if (!xml_doc)
142
 
        return;
143
 
 
144
 
    root = xmlDocGetRootElement (xml_doc);
145
 
 
146
 
    for (section = root->children; section != NULL; section = section->next) {
147
 
        if (!xmlStrncmp (section->name, "web-browsers", 12)) {
148
 
            for (element = section->children; element != NULL; element = element->next) {
149
 
                if (!xmlStrncmp (element->name, "web-browser", 11)) {
150
 
                    executable = gnome_da_xml_get_string (element, "executable");
151
 
                    if (is_executable_valid (executable)) {
152
 
                        web_item = gnome_da_web_item_new ();
153
 
 
154
 
                        web_item->generic.name = gnome_da_xml_get_string (element, "name");
155
 
                        web_item->generic.executable = executable;
156
 
                        web_item->generic.command = gnome_da_xml_get_string (element, "command");
157
 
                        web_item->generic.icon_name = gnome_da_xml_get_string (element, "icon-name");
158
 
 
159
 
                        web_item->run_in_terminal = gnome_da_xml_get_bool (element, "run-in-terminal");
160
 
                        web_item->netscape_remote = gnome_da_xml_get_bool (element, "netscape-remote");
161
 
                        if (web_item->netscape_remote) {
162
 
                            web_item->tab_command = gnome_da_xml_get_string (element, "tab-command");
163
 
                            web_item->win_command = gnome_da_xml_get_string (element, "win-command");
164
 
                        }
165
 
 
166
 
                        capplet->web_browsers = g_list_append (capplet->web_browsers, web_item);
167
 
                    }
168
 
                    else
169
 
                        g_free (executable);
170
 
                }
171
 
            }
172
 
        }
173
 
        else if (!xmlStrncmp (section->name, "mail-readers", 12)) {
174
 
            for (element = section->children; element != NULL; element = element->next) {
175
 
                if (!xmlStrncmp (element->name, "mail-reader", 11)) {
176
 
                    executable = gnome_da_xml_get_string (element, "executable");
177
 
                    if (is_executable_valid (executable)) {
178
 
                        mail_item = gnome_da_simple_item_new ();
179
 
 
180
 
                        mail_item->generic.name = gnome_da_xml_get_string (element, "name");
181
 
                        mail_item->generic.executable = executable;
182
 
                        mail_item->generic.command = gnome_da_xml_get_string (element, "command");
183
 
                        mail_item->generic.icon_name = gnome_da_xml_get_string (element, "icon-name");
184
 
 
185
 
                        mail_item->run_in_terminal = gnome_da_xml_get_bool (element, "run-in-terminal");
186
 
 
187
 
                        capplet->mail_readers = g_list_append (capplet->mail_readers, mail_item);
188
 
                    }
189
 
                    else
190
 
                        g_free (executable);
191
 
                }
192
 
            }
193
 
        }
194
 
        else if (!xmlStrncmp (section->name, "terminals", 9)) {
195
 
            for (element = section->children; element != NULL; element = element->next) {
196
 
                if (!xmlStrncmp (element->name, "terminal", 8)) {
197
 
                    executable = gnome_da_xml_get_string (element, "executable");
198
 
                    if (is_executable_valid (executable)) {
199
 
                        term_item = gnome_da_term_item_new ();
200
 
 
201
 
                        term_item->generic.name = gnome_da_xml_get_string (element, "name");
202
 
                        term_item->generic.executable = executable;
203
 
                        term_item->generic.command = gnome_da_xml_get_string (element, "command");
204
 
                        term_item->generic.icon_name = gnome_da_xml_get_string (element, "icon-name");
205
 
 
206
 
                        term_item->exec_flag = gnome_da_xml_get_string (element, "exec-flag");
207
 
 
208
 
                        capplet->terminals = g_list_append (capplet->terminals, term_item);
209
 
                    }
210
 
                    else
211
 
                        g_free (executable);
212
 
                }
213
 
            }
214
 
        }
215
 
        else if (!xmlStrncmp (section->name, "media-players", 13)) {
216
 
            for (element = section->children; element != NULL; element = element->next) {
217
 
                if (!xmlStrncmp (element->name, "media-player", 12)) {
218
 
                    executable = gnome_da_xml_get_string (element, "executable");
219
 
                    if (is_executable_valid (executable)) {
220
 
                        media_item = gnome_da_simple_item_new ();
221
 
 
222
 
                        media_item->generic.name = gnome_da_xml_get_string (element, "name");
223
 
                        media_item->generic.executable = executable;
224
 
                        media_item->generic.command = gnome_da_xml_get_string (element, "command");
225
 
                        media_item->generic.icon_name = gnome_da_xml_get_string (element, "icon-name");
226
 
 
227
 
                        media_item->run_in_terminal = gnome_da_xml_get_bool (element, "run-in-terminal");
228
 
 
229
 
                        capplet->media_players = g_list_append (capplet->media_players, media_item);
230
 
                    }
231
 
                    else
232
 
                        g_free (executable);
233
 
                }
234
 
            }
235
 
        }
236
 
        else if (!xmlStrncmp (section->name, "a11y-visual", 11)) {
237
 
            for (element = section->children; element != NULL; element = element->next) {
238
 
                if (!xmlStrncmp (element->name, "visual", 6)) {
239
 
                    executable = gnome_da_xml_get_string (element,"executable");
240
 
                    if (is_executable_valid (executable)) {
241
 
                        visual_item = gnome_da_visual_item_new ();
242
 
 
243
 
                        visual_item->generic.name = gnome_da_xml_get_string (element, "name");
244
 
                        visual_item->generic.executable = executable;
245
 
                        visual_item->generic.command = gnome_da_xml_get_string (element, "command");
246
 
                        visual_item->generic.icon_name = gnome_da_xml_get_string (element, "icon-name");
247
 
 
248
 
                        visual_item->run_at_startup = gnome_da_xml_get_bool (element, "run-at-startup");
249
 
 
250
 
                        capplet->visual_ats = g_list_append (capplet->visual_ats, visual_item);
251
 
                    }
252
 
                    else
253
 
                        g_free (executable);
254
 
                }
255
 
            }
256
 
        }
257
 
        else if (!xmlStrncmp (section->name, "a11y-mobility", 13)) {
258
 
            for (element = section->children; element != NULL; element = element->next) {
259
 
                if (!xmlStrncmp (element->name, "mobility", 8)) {
260
 
                    executable = gnome_da_xml_get_string (element,"executable");
261
 
                    if (is_executable_valid (executable)) {
262
 
                        mobility_item = gnome_da_mobility_item_new ();
263
 
 
264
 
                        mobility_item->generic.name = gnome_da_xml_get_string (element, "name");
265
 
                        mobility_item->generic.executable = executable;
266
 
                        mobility_item->generic.command = gnome_da_xml_get_string (element, "command");
267
 
                        mobility_item->generic.icon_name = gnome_da_xml_get_string (element, "icon-name");
268
 
 
269
 
                        mobility_item->run_at_startup = gnome_da_xml_get_bool (element, "run-at-startup");
270
 
 
271
 
                        capplet->mobility_ats = g_list_append (capplet->mobility_ats, mobility_item);
272
 
                    }
273
 
                    else
274
 
                        g_free (executable);
275
 
                }
276
 
            }
277
 
        }
278
 
    }
279
 
 
280
 
    xmlFreeDoc (xml_doc);
281
 
}
282
 
 
283
 
void
284
 
gnome_da_xml_load_list (GnomeDACapplet *capplet)
285
 
{
286
 
    GDir *app_dir = g_dir_open (GNOMECC_APPS_DIR, 0, NULL);
287
 
 
288
 
    if (app_dir != NULL) {
289
 
        const gchar *extra_file;
290
 
        gchar *filename;
291
 
 
292
 
        while ((extra_file = g_dir_read_name (app_dir)) != NULL) {
293
 
            filename = g_build_filename (GNOMECC_APPS_DIR, extra_file, NULL);
294
 
 
295
 
            if (g_str_has_suffix (filename, ".xml"))
296
 
                gnome_da_xml_load_xml (capplet, filename);
297
 
 
298
 
            g_free (filename);
299
 
        }
300
 
        g_dir_close (app_dir);
301
 
    }
302
 
}
303
 
 
304
 
void
305
 
gnome_da_xml_free (GnomeDACapplet *capplet)
306
 
{
307
 
    g_list_foreach (capplet->web_browsers, (GFunc) gnome_da_web_item_free, NULL);
308
 
    g_list_foreach (capplet->mail_readers, (GFunc) gnome_da_simple_item_free, NULL);
309
 
    g_list_foreach (capplet->terminals, (GFunc) gnome_da_term_item_free, NULL);
310
 
    g_list_foreach (capplet->media_players, (GFunc) gnome_da_simple_item_free, NULL);
311
 
    g_list_foreach (capplet->visual_ats, (GFunc) gnome_da_visual_item_free, NULL);
312
 
    g_list_foreach (capplet->mobility_ats, (GFunc) gnome_da_mobility_item_free, NULL);
313
 
 
314
 
    g_list_free (capplet->web_browsers);
315
 
    g_list_free (capplet->mail_readers);
316
 
    g_list_free (capplet->terminals);
317
 
    g_list_free (capplet->media_players);
318
 
    g_list_free (capplet->visual_ats);
319
 
    g_list_free (capplet->mobility_ats);
320
 
 
321
 
    g_object_unref (capplet->builder);
322
 
    g_free (capplet);
323
 
}