1 /*
2 * Copyright (C) 2007 Ignacio Casal Quinteiro <nacho.resa@gmail.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #include "glossary-panel.h"
23
24 #include <glib.h>
25 #include <glib-object.h>
26 #include <gtk/gtk.h>
27
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
30 #include <libxml/xmlmemory.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
34
35 #define GTR_GLOSSARY_PANEL_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ( \
36 (object), \
37 GTR_TYPE_GLOSSARY_PANEL, \
38 GtrGlossaryPanelPrivate))
39
40 G_DEFINE_TYPE (GtrGlossaryPanel, gtr_glossary_panel, GTK_TYPE_BOX)
41 #define XML_FILE_NAME "glossary.xml"
42 /*
43 * TreeItem structure
44 */
45 typedef struct _TreeItem TreeItem;
46 struct _TreeItem
47 {
48 gchar *word;
49 gchar *description;
50 GList *children;
51 };
52
53 enum
54 {
55 WORD_COLUMN,
56 DESCRIPTION_COLUMN,
57 N_COLUMNS
58 };
59
60 struct _GtrGlossaryPanelPrivate
61 {
62 GtkWidget *tree;
63 GtkWidget *search_entry;
64 GtkWidget *add_button;
65 xmlDocPtr *doc;
66 GList *elements;
67 };
68
69 typedef struct person
70 {
71 xmlChar *name;
72 xmlChar *email;
73 xmlChar *company;
74 xmlChar *organisation;
75 xmlChar *smail;
76 xmlChar *webPage;
77 xmlChar *phone;
78 } person, *personPtr;
79
80 /*
81 * And the code needed to parse it
82 */
parsePerson(xmlDocPtr doc,xmlNsPtr ns,xmlNodePtr cur)83 static personPtr parsePerson (xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur)
84 {
85 personPtr ret = NULL;
86
87 /*
88 * allocate the struct
89 */
90 ret = (personPtr) g_malloc (sizeof (person));
91 if (ret == NULL)
92 {
93 fprintf (stderr, "out of memory\n");
94 return (NULL);
95 }
96 memset (ret, 0, sizeof (person));
97
98 /* We don't care what the top level element name is */
99 /* COMPAT xmlChildrenNode is a macro unifying libxml1 and libxml2 names */
100 cur = cur->xmlChildrenNode;
101 while (cur != NULL)
102 {
103 if ((!xmlStrcmp (cur->name, (const xmlChar *) "Person")) &&
104 (cur->ns == ns))
105 ret->name = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
106 if ((!xmlStrcmp (cur->name, (const xmlChar *) "Email")) &&
107 (cur->ns == ns))
108 ret->email = xmlNodeListGetString (doc, cur->xmlChildrenNode, 1);
109 cur = cur->next;
110 }
111
112 return (ret);
113 }
114
115 static void
process_node(xmlNode * root_node)116 process_node (xmlNode * root_node)
117 {
118 GtrGlossaryPanelPrivate *priv;
119
120 xmlNodePtr cur_node;
121
122 cur_node = cur_node->xmlChildrenNode;
123
124 }
125
126 static gboolean
gtr_glossary_panel_load_items(GtrGlossaryPanel * panel)127 gtr_glossary_panel_load_items (GtrGlossaryPanel * panel)
128 {
129 GtrGlossaryPanelPrivate *priv = panel->priv;
130
131 return FALSE;
132 }
133
134 static void
gtr_glossary_panel_init(GtrGlossaryPanel * panel)135 gtr_glossary_panel_init (GtrGlossaryPanel * panel)
136 {
137 GtrGlossaryPanelPrivate *priv = panel->priv;
138
139 priv->tree = gtk_tree_view_new ();
140
141 panel->priv = GTR_GLOSSARY_PANEL_GET_PRIVATE (panel);
142
143 gtk_orientable_set_orientation (GTK_ORIENTABLE (panel),
144 GTK_ORIENTATION_VERTICAL);
145
146
147 }
148
149 static void
gtr_glossary_panel_finalize(GObject * object)150 gtr_glossary_panel_finalize (GObject * object)
151 {
152 G_OBJECT_CLASS (gtr_glossary_panel_parent_class)->finalize (object);
153 }
154
155 static void
gtr_glossary_panel_class_init(GtrGlossaryPanelClass * klass)156 gtr_glossary_panel_class_init (GtrGlossaryPanelClass * klass)
157 {
158 GObjectClass *object_class = G_OBJECT_CLASS (klass);
159
160 g_type_class_add_private (klass, sizeof (GtrGlossaryPanelPrivate));
161
162 object_class->finalize = gtr_glossary_panel_finalize;
163 }
164
165 GtkWidget *
gtr_glossary_panel_new(void)166 gtr_glossary_panel_new (void)
167 {
168 return GTK_WIDGET (g_object_new (GTR_TYPE_GLOSSARY_PANEL, NULL));
169 }
170