Mercurial > pidgin
annotate finch/libgnt/gntutils.c @ 21278:ebb46dea479a
Buttons were leaking all this time!
It's a good thing there ain't too many of them in finch!
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 31 Oct 2007 18:13:53 +0000 |
parents | 44b4e8bd759b |
children | e2e57d3c0578 |
rev | line source |
---|---|
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19380
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
16125
diff
changeset
|
22 |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
23 #include "gntbutton.h" |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
24 #include "gntcheckbox.h" |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
25 #include "gntcombobox.h" |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
26 #include "gntentry.h" |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
27 #include "gntlabel.h" |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
28 #include "gntline.h" |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
29 #include "gnttextview.h" |
15979
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
30 #include "gnttree.h" |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
31 #include "gntutils.h" |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
32 #include "gntwindow.h" |
15817 | 33 |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
34 #include "config.h" |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
35 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
36 #include <stdarg.h> |
15817 | 37 #include <stdlib.h> |
38 #include <string.h> | |
39 | |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
40 #ifndef NO_LIBXML |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
41 #include <libxml/parser.h> |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
42 #include <libxml/tree.h> |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
43 #endif |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
44 |
15817 | 45 #include "config.h" |
46 | |
47 void gnt_util_get_text_bound(const char *text, int *width, int *height) | |
48 { | |
49 const char *s = text, *last; | |
50 int count = 1, max = 0; | |
51 int len; | |
52 | |
53 /* XXX: ew ... everyone look away */ | |
54 last = s; | |
55 if (s) | |
56 { | |
57 while (*s) | |
58 { | |
59 if (*s == '\n' || *s == '\r') | |
60 { | |
61 count++; | |
62 len = gnt_util_onscreen_width(last, s); | |
63 if (max < len) | |
64 max = len; | |
65 last = s + 1; | |
66 } | |
67 s = g_utf8_next_char(s); | |
68 } | |
69 | |
70 len = gnt_util_onscreen_width(last, s); | |
71 if (max < len) | |
72 max = len; | |
73 } | |
74 | |
75 if (height) | |
76 *height = count; | |
77 if (width) | |
78 *width = max + (count > 1); | |
79 } | |
80 | |
81 int gnt_util_onscreen_width(const char *start, const char *end) | |
82 { | |
83 int width = 0; | |
84 | |
85 if (end == NULL) | |
86 end = start + strlen(start); | |
87 | |
88 while (start < end) { | |
89 width += g_unichar_iswide(g_utf8_get_char(start)) ? 2 : 1; | |
90 start = g_utf8_next_char(start); | |
91 } | |
92 return width; | |
93 } | |
94 | |
95 const char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w) | |
96 { | |
97 int size; | |
98 int width = 0; | |
99 const char *str = string; | |
100 | |
101 if (len <= 0) { | |
102 len = gnt_util_onscreen_width(string, NULL); | |
103 } | |
104 | |
105 while (width < len && *str) { | |
106 size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1; | |
107 if (width + size > len) | |
108 break; | |
109 str = g_utf8_next_char(str); | |
110 width += size; | |
111 } | |
112 if (w) | |
113 *w = width; | |
114 return str; | |
115 } | |
116 | |
117 char *gnt_util_onscreen_fit_string(const char *string, int maxw) | |
118 { | |
119 const char *start, *end; | |
120 GString *str; | |
121 | |
122 if (maxw <= 0) | |
123 maxw = getmaxx(stdscr) - 4; | |
124 | |
125 start = string; | |
126 str = g_string_new(NULL); | |
127 | |
128 while (*start) { | |
129 if ((end = strchr(start, '\n')) != NULL || | |
130 (end = strchr(start, '\r')) != NULL) { | |
131 if (gnt_util_onscreen_width(start, end) > maxw) | |
132 end = NULL; | |
133 } | |
134 if (end == NULL) | |
135 end = gnt_util_onscreen_width_to_pointer(start, maxw, NULL); | |
136 str = g_string_append_len(str, start, end - start); | |
137 if (*end) { | |
138 str = g_string_append_c(str, '\n'); | |
139 if (*end == '\n' || *end == '\r') | |
140 end++; | |
141 } | |
142 start = end; | |
143 } | |
144 return g_string_free(str, FALSE); | |
145 } | |
146 | |
147 struct duplicate_fns | |
148 { | |
149 GDupFunc key_dup; | |
150 GDupFunc value_dup; | |
151 GHashTable *table; | |
152 }; | |
153 | |
154 static void | |
155 duplicate_values(gpointer key, gpointer value, gpointer data) | |
156 { | |
157 struct duplicate_fns *fns = data; | |
158 g_hash_table_insert(fns->table, fns->key_dup ? fns->key_dup(key) : key, | |
159 fns->value_dup ? fns->value_dup(value) : value); | |
160 } | |
161 | |
162 GHashTable *g_hash_table_duplicate(GHashTable *src, GHashFunc hash, | |
163 GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d, | |
164 GDupFunc key_dup, GDupFunc value_dup) | |
165 { | |
166 GHashTable *dest = g_hash_table_new_full(hash, equal, key_d, value_d); | |
167 struct duplicate_fns fns = {key_dup, value_dup, dest}; | |
168 g_hash_table_foreach(src, duplicate_values, &fns); | |
169 return dest; | |
170 } | |
171 | |
172 gboolean gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint, | |
173 GValue *return_accu, | |
174 const GValue *handler_return, | |
175 gpointer dummy) | |
176 { | |
177 gboolean continue_emission; | |
178 gboolean signal_handled; | |
179 | |
180 signal_handled = g_value_get_boolean (handler_return); | |
181 g_value_set_boolean (return_accu, signal_handled); | |
182 continue_emission = !signal_handled; | |
183 | |
184 return continue_emission; | |
185 } | |
186 | |
15979
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
187 typedef struct { |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
188 GHashTable *hash; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
189 GntTree *tree; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
190 } BindingView; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
191 |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
192 static void |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
193 add_binding(gpointer key, gpointer value, gpointer data) |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
194 { |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
195 BindingView *bv = data; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
196 GntBindableActionParam *act = value; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
197 const char *name = g_hash_table_lookup(bv->hash, act->action); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
198 if (name && *name) { |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
199 const char *k = gnt_key_lookup(key); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
200 if (!k) |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
201 k = key; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
202 gnt_tree_add_row_after(bv->tree, (gpointer)k, |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
203 gnt_tree_create_row(bv->tree, k, name), NULL, NULL); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
204 } |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
205 } |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
206 |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
207 static void |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
208 add_action(gpointer key, gpointer value, gpointer data) |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
209 { |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
210 BindingView *bv = data; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
211 g_hash_table_insert(bv->hash, value, key); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
212 } |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
213 |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
214 GntWidget *gnt_widget_bindings_view(GntWidget *widget) |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
215 { |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
216 GntBindable *bind = GNT_BINDABLE(widget); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
217 GntWidget *tree = gnt_tree_new_with_columns(2); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
218 GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bind)); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
219 GHashTable *hash = g_hash_table_new(g_direct_hash, g_direct_equal); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
220 BindingView bv = {hash, GNT_TREE(tree)}; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
221 |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
222 gnt_tree_set_compare_func(bv.tree, (GCompareFunc)g_utf8_collate); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
223 g_hash_table_foreach(klass->actions, add_action, &bv); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
224 g_hash_table_foreach(klass->bindings, add_binding, &bv); |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
225 if (GNT_TREE(tree)->list == NULL) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
226 gnt_widget_destroy(tree); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
227 tree = NULL; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
228 } else |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
229 gnt_tree_adjust_columns(bv.tree); |
15979
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
230 g_hash_table_destroy(hash); |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
231 |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
232 return tree; |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
233 } |
2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
234 |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
235 #ifndef NO_LIBXML |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
236 static GntWidget * |
18583
cf7297803a73
Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
237 gnt_widget_from_xmlnode(xmlNode *node, GntWidget **data[], int max) |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
238 { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
239 GntWidget *widget = NULL; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
240 char *name; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
241 char *id, *prop, *content; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
242 int val; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
243 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
244 if (node == NULL || node->name == NULL || node->type != XML_ELEMENT_NODE) |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
245 return NULL; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
246 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
247 name = (char*)node->name; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
248 content = (char*)xmlNodeGetContent(node); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
249 if (strcmp(name + 1, "window") == 0 || strcmp(name + 1, "box") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
250 xmlNode *ch; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
251 char *title; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
252 gboolean vert = (*name == 'v'); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
253 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
254 if (name[1] == 'w') |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
255 widget = gnt_window_box_new(FALSE, vert); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
256 else |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
257 widget = gnt_box_new(FALSE, vert); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
258 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
259 title = (char*)xmlGetProp(node, (xmlChar*)"title"); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
260 if (title) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
261 gnt_box_set_title(GNT_BOX(widget), title); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
262 xmlFree(title); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
263 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
264 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
265 prop = (char*)xmlGetProp(node, (xmlChar*)"fill"); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
266 if (prop) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
267 if (sscanf(prop, "%d", &val) == 1) |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
268 gnt_box_set_fill(GNT_BOX(widget), !!val); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
269 xmlFree(prop); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
270 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
271 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
272 prop = (char*)xmlGetProp(node, (xmlChar*)"align"); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
273 if (prop) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
274 if (sscanf(prop, "%d", &val) == 1) |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
275 gnt_box_set_alignment(GNT_BOX(widget), val); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
276 xmlFree(prop); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
277 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
278 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
279 prop = (char*)xmlGetProp(node, (xmlChar*)"pad"); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
280 if (prop) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
281 if (sscanf(prop, "%d", &val) == 1) |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
282 gnt_box_set_pad(GNT_BOX(widget), val); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
283 xmlFree(prop); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
284 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
285 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
286 for (ch = node->children; ch; ch=ch->next) |
18583
cf7297803a73
Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
287 gnt_box_add_widget(GNT_BOX(widget), gnt_widget_from_xmlnode(ch, data, max)); |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
288 } else if (strcmp(name, "button") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
289 widget = gnt_button_new(content); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
290 } else if (strcmp(name, "label") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
291 widget = gnt_label_new(content); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
292 } else if (strcmp(name, "entry") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
293 widget = gnt_entry_new(content); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
294 } else if (strcmp(name, "combobox") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
295 widget = gnt_combo_box_new(); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
296 } else if (strcmp(name, "checkbox") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
297 widget = gnt_check_box_new(content); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
298 } else if (strcmp(name, "tree") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
299 widget = gnt_tree_new(); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
300 } else if (strcmp(name, "textview") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
301 widget = gnt_text_view_new(); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
302 } else if (strcmp(name + 1, "line") == 0) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
303 widget = gnt_line_new(*name == 'v'); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
304 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
305 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
306 xmlFree(content); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
307 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
308 if (widget == NULL) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
309 g_printerr("Invalid widget name %s\n", name); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
310 return NULL; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
311 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
312 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
313 id = (char*)xmlGetProp(node, (xmlChar*)"id"); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
314 if (id) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
315 int i; |
18583
cf7297803a73
Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
316 if (sscanf(id, "%d", &i) == 1 && i >= 0 && i < max) { |
cf7297803a73
Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
317 *data[i] = widget; |
cf7297803a73
Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
318 xmlFree(id); |
cf7297803a73
Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
319 } |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
320 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
321 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
322 prop = (char*)xmlGetProp(node, (xmlChar*)"border"); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
323 if (prop) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
324 int val; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
325 if (sscanf(prop, "%d", &val) == 1) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
326 if (val) |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
327 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
328 else |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
329 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
330 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
331 xmlFree(prop); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
332 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
333 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
334 prop = (char*)xmlGetProp(node, (xmlChar*)"shadow"); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
335 if (prop) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
336 int val; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
337 if (sscanf(prop, "%d", &val) == 1) { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
338 if (val) |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
339 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
340 else |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
341 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
342 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
343 xmlFree(prop); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
344 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
345 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
346 return widget; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
347 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
348 #endif |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
349 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
350 void gnt_util_parse_widgets(const char *string, int num, ...) |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
351 { |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
352 #ifndef NO_LIBXML |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
353 xmlParserCtxtPtr ctxt; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
354 xmlDocPtr doc; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
355 xmlNodePtr node; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
356 va_list list; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
357 GntWidget ***data; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
358 int id; |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
359 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
360 ctxt = xmlNewParserCtxt(); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
361 doc = xmlCtxtReadDoc(ctxt, (xmlChar*)string, NULL, NULL, XML_PARSE_NOBLANKS); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
362 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
363 data = g_new0(GntWidget **, num); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
364 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
365 va_start(list, num); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
366 for (id = 0; id < num; id++) |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
367 data[id] = va_arg(list, gpointer); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
368 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
369 node = xmlDocGetRootElement(doc); |
18583
cf7297803a73
Guard against possible weird crashes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18511
diff
changeset
|
370 gnt_widget_from_xmlnode(node, data, num); |
16125
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
371 |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
372 xmlFreeDoc(doc); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
373 xmlCleanupParser(); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
374 va_end(list); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
375 g_free(data); |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
376 #endif |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
377 } |
5f204f55af09
Add a utility function to create widgets from an XML description.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15979
diff
changeset
|
378 |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
379 #ifndef NO_LIBXML |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
380 static void |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
381 util_parse_html_to_tv(xmlNode *node, GntTextView *tv, GntTextFormatFlags flag) |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
382 { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
383 const char *name; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
384 char *content; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
385 xmlNode *ch; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
386 gboolean processed = FALSE; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
387 char *url = NULL; |
19380
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
388 gboolean insert_nl_s = FALSE, insert_nl_e = FALSE; |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
389 |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
390 if (node == NULL || node->name == NULL || node->type != XML_ELEMENT_NODE) |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
391 return; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
392 |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
393 name = (char*)node->name; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
394 if (g_ascii_strcasecmp(name, "b") == 0 || |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
395 g_ascii_strcasecmp(name, "strong") == 0 || |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
396 g_ascii_strcasecmp(name, "i") == 0 || |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
397 g_ascii_strcasecmp(name, "blockquote") == 0) { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
398 flag |= GNT_TEXT_FLAG_BOLD; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
399 } else if (g_ascii_strcasecmp(name, "u") == 0) { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
400 flag |= GNT_TEXT_FLAG_UNDERLINE; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
401 } else if (g_ascii_strcasecmp(name, "br") == 0) { |
19380
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
402 insert_nl_e = TRUE; |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
403 } else if (g_ascii_strcasecmp(name, "a") == 0) { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
404 flag |= GNT_TEXT_FLAG_UNDERLINE; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
405 url = (char *)xmlGetProp(node, (xmlChar*)"href"); |
19380
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
406 } else if (g_ascii_strcasecmp(name, "h1") == 0 || |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
407 g_ascii_strcasecmp(name, "h2") == 0 || |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
408 g_ascii_strcasecmp(name, "h3") == 0 || |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
409 g_ascii_strcasecmp(name, "h4") == 0 || |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
410 g_ascii_strcasecmp(name, "h5") == 0 || |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
411 g_ascii_strcasecmp(name, "h6") == 0) { |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
412 insert_nl_s = TRUE; |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
413 insert_nl_e = TRUE; |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
414 } else if (g_ascii_strcasecmp(name, "title") == 0) { |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
415 insert_nl_s = TRUE; |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
416 insert_nl_e = TRUE; |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
417 flag |= GNT_TEXT_FLAG_BOLD | GNT_TEXT_FLAG_UNDERLINE; |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
418 } else { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
419 /* XXX: Process other possible tags */ |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
420 } |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
421 |
19380
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
422 if (insert_nl_s) |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
423 gnt_text_view_append_text_with_flags(tv, "\n", flag); |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
424 |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
425 for (ch = node->children; ch; ch = ch->next) { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
426 if (ch->type == XML_ELEMENT_NODE) { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
427 processed = TRUE; |
19380
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
428 util_parse_html_to_tv(ch, tv, flag); |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
429 } |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
430 } |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
431 |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
432 if (!processed) { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
433 content = (char*)xmlNodeGetContent(node); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
434 gnt_text_view_append_text_with_flags(tv, content, flag); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
435 xmlFree(content); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
436 } |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
437 |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
438 if (url) { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
439 char *href = g_strdup_printf(" (%s)", url); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
440 gnt_text_view_append_text_with_flags(tv, href, flag); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
441 g_free(href); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
442 xmlFree(url); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
443 } |
19380
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
444 |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
445 if (insert_nl_e) |
e28db9ae02b3
Add support for a few more XHTML tags.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19334
diff
changeset
|
446 gnt_text_view_append_text_with_flags(tv, "\n", flag); |
19334
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
447 } |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
448 #endif |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
449 |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
450 gboolean gnt_util_parse_xhtml_to_textview(const char *string, GntTextView *tv) |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
451 { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
452 #ifdef NO_LIBXML |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
453 return FALSE; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
454 #else |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
455 xmlParserCtxtPtr ctxt; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
456 xmlDocPtr doc; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
457 xmlNodePtr node; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
458 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
459 gboolean ret = FALSE; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
460 |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
461 ctxt = xmlNewParserCtxt(); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
462 doc = xmlCtxtReadDoc(ctxt, (xmlChar*)string, NULL, NULL, XML_PARSE_NOBLANKS | XML_PARSE_RECOVER); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
463 if (doc) { |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
464 node = xmlDocGetRootElement(doc); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
465 util_parse_html_to_tv(node, tv, flag); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
466 xmlFreeDoc(doc); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
467 ret = TRUE; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
468 } |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
469 xmlCleanupParser(); |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
470 return ret; |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
471 #endif |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
472 } |
fda2d2d99850
Add support to parse and add XHTML in a textview. This we can use for logs,
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18873
diff
changeset
|
473 |
18511
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
474 /* Setup trigger widget */ |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
475 typedef struct { |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
476 char *text; |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
477 GntWidget *button; |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
478 } TriggerButton; |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
479 |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
480 static void |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
481 free_trigger_button(TriggerButton *b) |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
482 { |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
483 g_free(b->text); |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
484 g_free(b); |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
485 } |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
486 |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
487 static gboolean |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
488 key_pressed(GntWidget *widget, const char *text, TriggerButton *trig) |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
489 { |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
490 if (text && trig->text && |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
491 strcmp(text, trig->text) == 0) { |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
492 gnt_widget_activate(trig->button); |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
493 return TRUE; |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
494 } |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
495 return FALSE; |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
496 } |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
497 |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
498 void gnt_util_set_trigger_widget(GntWidget *wid, const char *text, GntWidget *button) |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
499 { |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
500 TriggerButton *tb = g_new0(TriggerButton, 1); |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
501 tb->text = g_strdup(text); |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
502 tb->button = button; |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
503 g_signal_connect(G_OBJECT(wid), "key_pressed", G_CALLBACK(key_pressed), tb); |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
504 g_signal_connect_swapped(G_OBJECT(button), "destroy", G_CALLBACK(free_trigger_button), tb); |
7ee0e0597a26
Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17928
diff
changeset
|
505 } |