annotate finch/libgnt/gntutils.c @ 19334:fda2d2d99850

Add support to parse and add XHTML in a textview. This we can use for logs, in the conversation window etc. places.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 23 Aug 2007 05:55:57 +0000
parents 7066896f6628
children e28db9ae02b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17718
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
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16125
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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: 15818
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"
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
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>
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 #include <stdlib.h>
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 #include <string.h>
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
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
15818
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 #include "config.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 void gnt_util_get_text_bound(const char *text, int *width, int *height)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 const char *s = text, *last;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 int count = 1, max = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 int len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 /* XXX: ew ... everyone look away */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 last = s;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 if (s)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 while (*s)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 if (*s == '\n' || *s == '\r')
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61 count++;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 len = gnt_util_onscreen_width(last, s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 if (max < len)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 max = len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 last = s + 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 s = g_utf8_next_char(s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 len = gnt_util_onscreen_width(last, s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 if (max < len)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 max = len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 if (height)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 *height = count;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 if (width)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 *width = max + (count > 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 int gnt_util_onscreen_width(const char *start, const char *end)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 int width = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 if (end == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 end = start + strlen(start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 while (start < end) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 width += g_unichar_iswide(g_utf8_get_char(start)) ? 2 : 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 start = g_utf8_next_char(start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 return width;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 const char *gnt_util_onscreen_width_to_pointer(const char *string, int len, int *w)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 int size;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 int width = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 const char *str = string;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 if (len <= 0) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 len = gnt_util_onscreen_width(string, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 while (width < len && *str) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 size = g_unichar_iswide(g_utf8_get_char(str)) ? 2 : 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 if (width + size > len)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 break;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 str = g_utf8_next_char(str);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 width += size;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 if (w)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 *w = width;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 return str;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 char *gnt_util_onscreen_fit_string(const char *string, int maxw)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 const char *start, *end;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 GString *str;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 if (maxw <= 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 maxw = getmaxx(stdscr) - 4;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 start = string;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 str = g_string_new(NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 while (*start) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 if ((end = strchr(start, '\n')) != NULL ||
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 (end = strchr(start, '\r')) != NULL) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 if (gnt_util_onscreen_width(start, end) > maxw)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 end = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 if (end == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 end = gnt_util_onscreen_width_to_pointer(start, maxw, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 str = g_string_append_len(str, start, end - start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 if (*end) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 str = g_string_append_c(str, '\n');
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 if (*end == '\n' || *end == '\r')
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 end++;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 start = end;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 return g_string_free(str, FALSE);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147 struct duplicate_fns
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 GDupFunc key_dup;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 GDupFunc value_dup;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 GHashTable *table;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 };
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 duplicate_values(gpointer key, gpointer value, gpointer data)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 struct duplicate_fns *fns = data;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 g_hash_table_insert(fns->table, fns->key_dup ? fns->key_dup(key) : key,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 fns->value_dup ? fns->value_dup(value) : value);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 GHashTable *g_hash_table_duplicate(GHashTable *src, GHashFunc hash,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 GDupFunc key_dup, GDupFunc value_dup)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 GHashTable *dest = g_hash_table_new_full(hash, equal, key_d, value_d);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 struct duplicate_fns fns = {key_dup, value_dup, dest};
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 g_hash_table_foreach(src, duplicate_values, &fns);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 return dest;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 gboolean gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 GValue *return_accu,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 const GValue *handler_return,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 gpointer dummy)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 gboolean continue_emission;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 gboolean signal_handled;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 signal_handled = g_value_get_boolean (handler_return);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 g_value_set_boolean (return_accu, signal_handled);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 continue_emission = !signal_handled;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 return continue_emission;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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: 15818
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;
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
388
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 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
390 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
391
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 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
393 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
394 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
395 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
396 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
397 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
398 } 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
399 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
400 } else if (g_ascii_strcasecmp(name, "br") == 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
401 gnt_text_view_append_text_with_flags(tv, "\n", 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
402 } 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
403 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
404 url = (char *)xmlGetProp(node, (xmlChar*)"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
405 } 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
406 /* 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
407 }
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
408
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
409 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
410 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
411 processed = 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
412 }
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
413 util_parse_html_to_tv(ch, 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
414 }
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
415
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
416 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
417 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
418 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
419 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
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
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
422 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
423 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
424 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
425 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
426 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
427 }
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
428 }
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 #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
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 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
432 {
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 #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
434 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
435 #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
436 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
437 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
438 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
439 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
440 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
441
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 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
443 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
444 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
445 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
446 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
447 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
448 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
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 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
451 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
452 #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
453 }
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
18511
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
455 /* Setup trigger widget */
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
456 typedef struct {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
457 char *text;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
458 GntWidget *button;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
459 } TriggerButton;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
460
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
461 static void
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
462 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: 17718
diff changeset
463 {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
464 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: 17718
diff changeset
465 g_free(b);
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
466 }
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
467
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
468 static gboolean
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
469 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: 17718
diff changeset
470 {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
471 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: 17718
diff changeset
472 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: 17718
diff changeset
473 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: 17718
diff changeset
474 return TRUE;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
475 }
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
476 return FALSE;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
477 }
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
478
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
479 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: 17718
diff changeset
480 {
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
481 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: 17718
diff changeset
482 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: 17718
diff changeset
483 tb->button = button;
7ee0e0597a26 Add utility function to trigger some button when some key is pressed with
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17718
diff changeset
484 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: 17718
diff changeset
485 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: 17718
diff changeset
486 }