Mercurial > pidgin
annotate plugins/spellchk.c @ 4512:c5bc145addf9
[gaim-migrate @ 4788]
Removed filter_break.. Made unnecessary by parse_line's processing of escaped chars. Fixes win32 pounce sound paths.
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Mon, 03 Feb 2003 16:02:50 +0000 |
parents | dcc6c130c6d9 |
children | 2427d847e39c |
rev | line source |
---|---|
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
1 /* |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
2 * A lot of this code (especially the config code) was taken directly |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
3 * or nearly directly from xchat, version 1.4.2 by Peter Zelezny and others. |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
4 * |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
5 * TODO: |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
6 * ? I think i did everything i want to with it. |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
7 * |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
8 * BUGS: |
112
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
9 * ? I think i fixed them all. |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
10 */ |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
11 #include "config.h" |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
12 |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
13 #ifndef GAIM_PLUGINS |
103 | 14 #define GAIM_PLUGINS |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
15 #endif |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
16 |
103 | 17 #include "gaim.h" |
18 | |
19 #include <string.h> | |
20 #include <ctype.h> | |
21 #include <stdlib.h> | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
22 #include <sys/stat.h> |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
23 #include <sys/types.h> |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
24 #include <unistd.h> |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
25 #include <fcntl.h> |
3630 | 26 #ifdef _WIN32 |
27 #include "win32dep.h" | |
28 #endif | |
103 | 29 |
4348 | 30 enum { |
31 BAD_COLUMN, | |
32 GOOD_COLUMN, | |
33 N_COLUMNS | |
103 | 34 }; |
35 | |
4348 | 36 static int num_words(const char *); |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
37 static int get_word(char *, int); |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
38 static char *have_word(char *, int); |
4348 | 39 static void substitute(char **, int, int, const char *); |
40 static GtkListStore *model; | |
103 | 41 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
42 static void substitute_words(struct gaim_connection *gc, char *who, char **message, void *m) { |
103 | 43 int i, l; |
44 int word; | |
45 char *tmp; | |
46 | |
47 if (message == NULL || *message == NULL) | |
48 return; | |
49 | |
50 l = num_words(*message); | |
51 for (i = 0; i < l; i++) { | |
4348 | 52 GtkTreeIter iter; |
103 | 53 word = get_word(*message, i); |
4348 | 54 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) { |
55 do { | |
56 GValue val0, val1; | |
57 const char *bad, *good; | |
58 memset(&val0, 0, sizeof(val0)); | |
59 memset(&val1, 0, sizeof(val1)); | |
60 gtk_tree_model_get_value(GTK_TREE_MODEL(model), &iter, 0, &val0); | |
61 gtk_tree_model_get_value(GTK_TREE_MODEL(model), &iter, 1, &val1); | |
62 tmp = have_word(*message, word); | |
63 bad = g_value_get_string(&val0); | |
64 good = g_value_get_string(&val1); | |
65 if (!strcmp(tmp, bad)) { | |
66 substitute(message, word, strlen(bad), | |
67 good); | |
68 l += num_words(good) - num_words(bad); | |
69 i += num_words(good) - num_words(bad); | |
70 } | |
71 free(tmp); | |
72 g_value_unset(&val0); | |
73 g_value_unset(&val1); | |
74 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter)); | |
103 | 75 } |
76 } | |
77 } | |
78 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
79 static int buf_get_line(char *ibuf, char **buf, int *position, int len) { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
80 int pos = *position, spos = pos; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
81 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
82 if (pos == len) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
83 return 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
84 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
85 while (ibuf[pos++] != '\n') { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
86 if (pos == len) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
87 return 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
88 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
89 pos--; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
90 ibuf[pos] = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
91 *buf = &ibuf[spos]; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
92 pos++; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
93 *position = pos; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
94 return 1; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
95 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
96 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
97 static void load_conf() { |
4348 | 98 const char * const defaultconf = "BAD r\nGOOD are\n\n" |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
99 "BAD u\nGOOD you\n\n" |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
100 "BAD teh\nGOOD the\n\n"; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
101 char *buf, *ibuf; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
102 char name[82]; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
103 char cmd[256]; |
4348 | 104 int pnt = 0; |
105 gsize size; | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
106 |
4348 | 107 model = gtk_list_store_new((gint)N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING); |
103 | 108 |
4348 | 109 buf = g_build_filename(gaim_home_dir(), ".gaim", "dict", NULL); |
110 g_file_get_contents(buf, &ibuf, &size, NULL); | |
111 free(buf); | |
112 if(!ibuf) { | |
113 ibuf = g_strdup(defaultconf); | |
114 size = strlen(defaultconf); | |
106
e05e6373ea5a
[gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
103
diff
changeset
|
115 } |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
116 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
117 cmd[0] = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
118 name[0] = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
119 |
4348 | 120 while(buf_get_line(ibuf, &buf, &pnt, size)) { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
121 if (*buf != '#') { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
122 if (!strncasecmp(buf, "BAD ", 4)) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
123 strncpy(name, buf + 4, 81); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
124 if (!strncasecmp(buf, "GOOD ", 5)) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
125 strncpy(cmd, buf + 5, 255); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
126 if (*name) { |
4348 | 127 GtkTreeIter iter; |
128 gtk_list_store_append(model, &iter); | |
129 gtk_list_store_set(model, &iter, | |
130 0, g_strdup(name), | |
131 1, g_strdup(cmd), | |
132 -1); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
133 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
134 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
135 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
136 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
137 free(ibuf); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
138 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
139 |
103 | 140 |
141 | |
4348 | 142 static int num_words(const char *m) { |
103 | 143 int count = 0; |
144 int pos; | |
145 int state = 0; | |
146 | |
147 for (pos = 0; pos < strlen(m); pos++) { | |
148 switch (state) { | |
149 case 0: /* expecting word */ | |
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1862
diff
changeset
|
150 if (!isspace(m[pos]) && !ispunct(m[pos])) { |
103 | 151 count++; |
152 state = 1; | |
153 } else if (m[pos] == '<') | |
154 state = 2; | |
155 break; | |
156 case 1: /* inside word */ | |
112
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
157 if (m[pos] == '<') |
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
158 state = 2; |
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1862
diff
changeset
|
159 else if (isspace(m[pos]) || ispunct(m[pos])) |
103 | 160 state = 0; |
161 break; | |
162 case 2: /* inside HTML tag */ | |
163 if (m[pos] == '>') | |
164 state = 0; | |
165 break; | |
166 } | |
167 } | |
168 return count; | |
169 } | |
170 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
171 static int get_word(char *m, int word) { |
103 | 172 int count = 0; |
173 int pos = 0; | |
174 int state = 0; | |
175 | |
176 for (pos = 0; pos < strlen(m) && count <= word; pos++) { | |
177 switch (state) { | |
178 case 0: | |
1862
fd60aa357882
[gaim-migrate @ 1872]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1740
diff
changeset
|
179 if (!isspace(m[pos]) && !ispunct(m[pos])) { |
103 | 180 count++; |
181 state = 1; | |
182 } else if (m[pos] == '<') | |
183 state = 2; | |
184 break; | |
185 case 1: | |
112
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
186 if (m[pos] == '<') |
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
187 state = 2; |
1862
fd60aa357882
[gaim-migrate @ 1872]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1740
diff
changeset
|
188 else if (isspace(m[pos]) || ispunct(m[pos])) |
103 | 189 state = 0; |
190 break; | |
191 case 2: | |
192 if (m[pos] == '>') | |
193 state = 0; | |
194 break; | |
195 } | |
196 } | |
197 return pos - 1; | |
198 } | |
199 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
200 static char *have_word(char *m, int pos) { |
3733 | 201 char *tmp = strpbrk(&m[pos], "' \t\f\r\n\"><.?!-,/"); |
103 | 202 int len = (int)(tmp - &m[pos]); |
203 | |
204 if (tmp == NULL) { | |
205 tmp = strdup(&m[pos]); | |
206 return tmp; | |
207 } | |
208 | |
209 tmp = malloc(len + 1); | |
210 tmp[0] = 0; | |
211 strncat(tmp, &m[pos], len); | |
212 | |
213 return tmp; | |
214 } | |
215 | |
4348 | 216 static void substitute(char **mes, int pos, int m, const char *text) { |
257
a93e273ca1d6
[gaim-migrate @ 267]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
217 char *new = g_malloc(strlen(*mes) + strlen(text) + 1); |
103 | 218 char *tmp; |
219 new[0] = 0; | |
220 | |
221 strncat(new, *mes, pos); | |
222 strcat(new, text); | |
223 | |
224 strcat(new, &(*mes)[pos + m]); | |
225 tmp = *mes; | |
226 *mes = new; | |
257
a93e273ca1d6
[gaim-migrate @ 267]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
227 g_free(tmp); |
103 | 228 } |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
229 |
4348 | 230 static GtkWidget *tree; |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
231 static GtkWidget *bad_entry; |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
232 static GtkWidget *good_entry; |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
233 |
4348 | 234 static void save_list(); |
235 | |
236 static void on_edited(GtkCellRendererText *cellrenderertext, | |
237 gchar *path, | |
238 gchar *arg2, | |
239 gpointer data) | |
240 { | |
241 GtkTreeIter iter; | |
242 GValue val; | |
243 if(arg2[0] == '\0') { | |
244 gdk_beep(); | |
245 return; | |
246 } | |
247 memset(&val, 0, sizeof(val)); | |
248 g_return_if_fail(gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(model), &iter, path)); | |
249 gtk_tree_model_get_value(GTK_TREE_MODEL(model), &iter, GPOINTER_TO_INT(data), &val); | |
250 if(strcmp(arg2, g_value_get_string(&val))) { | |
251 gtk_list_store_set(model, &iter, GPOINTER_TO_INT(data), arg2, -1); | |
252 save_list(); | |
253 printf("Editado! %s, %s\n", path, arg2); | |
254 } | |
255 g_value_unset(&val); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
256 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
257 |
4348 | 258 static void list_add_new() |
259 { | |
260 GtkTreeIter iter; | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
261 |
4348 | 262 gtk_list_store_append(model, &iter); |
263 gtk_list_store_set(model, &iter, | |
264 0, gtk_entry_get_text(GTK_ENTRY(bad_entry)), | |
265 1, gtk_entry_get_text(GTK_ENTRY(good_entry)), | |
266 -1); | |
267 gtk_editable_select_region(GTK_EDITABLE(bad_entry), 0, -1); | |
268 gtk_widget_grab_focus(bad_entry); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
269 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
270 |
4348 | 271 static void add_selected_row_to_list(GtkTreeModel *model, GtkTreePath *path, |
272 GtkTreeIter *iter, gpointer data) | |
273 { | |
274 GSList **list = (GSList **)data; | |
275 *list = g_slist_append(*list, gtk_tree_path_copy(path) ); | |
276 } | |
277 | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
278 |
4348 | 279 static void remove_row(void *data1, gpointer data2) |
280 { | |
281 GtkTreePath *path = (GtkTreePath*)data1; | |
282 GtkTreeIter iter; | |
283 gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path); | |
284 gtk_list_store_remove(model, &iter); | |
285 gtk_tree_path_free(path); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
286 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
287 |
4348 | 288 static void list_delete() |
289 { | |
290 GtkTreeSelection *sel; | |
291 GSList *list = NULL; | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
292 |
4348 | 293 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); |
294 gtk_tree_selection_selected_foreach(sel, add_selected_row_to_list, &list); | |
295 | |
296 g_slist_foreach(list, remove_row, NULL); | |
297 g_slist_free(list); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
298 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
299 |
4348 | 300 static void save_list() |
301 { | |
302 FILE *f; | |
303 char *name; | |
304 GtkTreeIter iter; | |
305 char tempfilename[BUF_LONG]; | |
306 int fd; | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
307 |
4348 | 308 name = g_build_filename(gaim_home_dir(), ".gaim", "dict", NULL); |
309 strcpy(tempfilename, name); | |
310 strcat(tempfilename,".XXXXXX"); | |
311 fd = g_mkstemp(tempfilename); | |
312 if(fd<0) { | |
313 perror(tempfilename); | |
314 g_free(name); | |
315 return; | |
316 } | |
317 if (!(f = fdopen(fd, "w"))) { | |
318 perror("fdopen"); | |
319 close(fd); | |
320 g_free(name); | |
321 return; | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
322 } |
4348 | 323 |
324 fchmod(fd, S_IRUSR | S_IWUSR); | |
4373
dcc6c130c6d9
[gaim-migrate @ 4639]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4363
diff
changeset
|
325 |
4348 | 326 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter)) { |
327 do { | |
328 GValue val0, val1; | |
329 memset(&val0, 0, sizeof(val0)); | |
330 memset(&val1, 0, sizeof(val1)); | |
331 gtk_tree_model_get_value(GTK_TREE_MODEL(model), &iter, 0, &val0); | |
332 gtk_tree_model_get_value(GTK_TREE_MODEL(model), &iter, 1, &val1); | |
333 fprintf(f, "BAD %s\nGOOD %s\n\n", g_value_get_string(&val0), g_value_get_string(&val1)); | |
334 g_value_unset(&val0); | |
335 g_value_unset(&val1); | |
336 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter)); | |
337 } | |
338 if(fclose(f)) { | |
339 debug_printf("Error writing to %s: %m\n", tempfilename); | |
340 unlink(tempfilename); | |
341 g_free(name); | |
342 return; | |
343 } | |
344 rename(tempfilename, name); | |
345 g_free(name); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
346 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
347 |
4348 | 348 static void |
349 check_if_something_is_selected(GtkTreeModel *model, | |
350 GtkTreePath *path, GtkTreeIter *iter, gpointer data) | |
351 { | |
352 *((gboolean*)data) = TRUE; | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
353 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
354 |
4348 | 355 static void on_selection_changed(GtkTreeSelection *sel, |
356 gpointer data) | |
357 { | |
358 gboolean is = FALSE; | |
359 gtk_tree_selection_selected_foreach(sel, check_if_something_is_selected, &is); | |
360 gtk_widget_set_sensitive((GtkWidget*)data, is); | |
361 } | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
362 |
4348 | 363 static gboolean non_empty(const char *s) |
364 { | |
365 while(*s && isspace(*s)) | |
366 s++; | |
367 return *s; | |
368 } | |
369 | |
370 static void on_entry_changed(GtkEditable *editable, gpointer data) | |
371 { | |
372 gtk_widget_set_sensitive((GtkWidget*)data, | |
373 non_empty(gtk_entry_get_text(GTK_ENTRY(bad_entry))) && | |
374 non_empty(gtk_entry_get_text(GTK_ENTRY(good_entry)))); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
375 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
376 |
3630 | 377 /* |
378 * EXPORTED FUNCTIONS | |
379 */ | |
380 | |
381 G_MODULE_EXPORT char *gaim_plugin_init(GModule *handle) { | |
382 load_conf(); | |
383 | |
384 gaim_signal_connect(handle, event_im_send, substitute_words, NULL); | |
385 gaim_signal_connect(handle, event_chat_send, substitute_words, NULL); | |
386 return NULL; | |
387 } | |
388 | |
389 G_MODULE_EXPORT void gaim_plugin_remove() { | |
390 } | |
391 | |
392 struct gaim_plugin_description desc; | |
393 G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() { | |
394 desc.api_version = PLUGIN_API_VERSION; | |
395 desc.name = g_strdup("Text replacement"); | |
396 desc.version = g_strdup(VERSION); | |
397 desc.description = g_strdup("Replaces text in outgoing messages according to user-defined rules."); | |
398 desc.authors = g_strdup("Eric Warmehoven <eric@warmenhoven.org>"); | |
399 desc.url = g_strdup(WEBSITE); | |
400 return &desc; | |
401 } | |
402 | |
403 G_MODULE_EXPORT char *name() { | |
404 return "IM Spell Check"; | |
405 } | |
406 | |
407 G_MODULE_EXPORT char *description() { | |
408 return "Watches outgoing IM text and corrects common spelling errors."; | |
409 } | |
410 | |
4348 | 411 G_MODULE_EXPORT GtkWidget *gaim_plugin_config_gtk() |
412 { | |
3565 | 413 GtkWidget *ret, *vbox, *win; |
4348 | 414 GtkWidget *hbox, *label; |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
415 GtkWidget *button; |
4348 | 416 GtkSizeGroup *sg; |
417 GtkCellRenderer *renderer; | |
418 GtkTreeViewColumn *column; | |
419 | |
420 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
3565 | 421 |
422 ret = gtk_vbox_new(FALSE, 18); | |
423 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
424 |
3565 | 425 vbox = make_frame(ret, _("Text Replacements")); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
426 gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); |
4348 | 427 gtk_widget_set_size_request(vbox, 300, -1); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
428 gtk_widget_show (vbox); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
429 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
430 win = gtk_scrolled_window_new(0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
431 gtk_container_add(GTK_CONTAINER(vbox), win); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
432 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (win), |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
433 GTK_POLICY_AUTOMATIC, |
4348 | 434 GTK_POLICY_AUTOMATIC); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
435 gtk_widget_show(win); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
436 |
4348 | 437 tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); |
438 /* gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree), TRUE); */ | |
439 gtk_widget_set_size_request(tree, 260,200); | |
440 | |
441 renderer = gtk_cell_renderer_text_new (); | |
442 g_object_set (G_OBJECT (renderer), | |
443 "editable", TRUE, | |
444 NULL); | |
445 g_signal_connect(G_OBJECT(renderer), "edited", | |
446 G_CALLBACK(on_edited), GINT_TO_POINTER(0)); | |
447 column = gtk_tree_view_column_new_with_attributes (_("You type"), | |
448 renderer, "text", BAD_COLUMN, NULL); | |
449 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
450 gtk_tree_view_column_set_fixed_width(column, 130); | |
451 /* gtk_tree_view_column_set_resizable(column, TRUE); */ | |
452 gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); | |
453 renderer = gtk_cell_renderer_text_new (); | |
454 g_object_set (G_OBJECT (renderer), | |
455 "editable", TRUE, | |
456 NULL); | |
457 g_signal_connect(G_OBJECT(renderer), "edited", | |
458 G_CALLBACK(on_edited), GINT_TO_POINTER(1)); | |
459 column = gtk_tree_view_column_new_with_attributes (_("You send"), | |
460 renderer, "text", GOOD_COLUMN, NULL); | |
461 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
462 gtk_tree_view_column_set_fixed_width(column, 130); | |
463 /* gtk_tree_view_column_set_resizable(column, TRUE); */ | |
464 gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); | |
465 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)), | |
466 GTK_SELECTION_MULTIPLE); | |
467 gtk_container_add(GTK_CONTAINER(win), tree); | |
468 gtk_widget_show(tree); | |
469 | |
470 hbox = gtk_hbutton_box_new(); | |
471 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
472 gtk_widget_show(hbox); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
473 |
4348 | 474 button = gtk_button_new_from_stock(GTK_STOCK_DELETE); |
475 g_signal_connect(G_OBJECT(button), "clicked", | |
476 G_CALLBACK(list_delete), NULL); | |
477 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
478 gtk_widget_set_sensitive(button, FALSE); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
479 |
4348 | 480 g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree))), |
481 "changed", G_CALLBACK(on_selection_changed), button); | |
482 | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
483 gtk_widget_show(button); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
484 |
4348 | 485 vbox = make_frame(ret, _("Add a new text replacement")); |
486 gtk_widget_set_size_request(vbox, 300, -1); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
487 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
488 hbox = gtk_hbox_new(FALSE, 2); |
4348 | 489 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
490 gtk_widget_show(hbox); | |
491 | |
492 label = gtk_label_new_with_mnemonic(_("You _type:")); | |
493 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
494 | |
495 bad_entry = gtk_entry_new(); | |
496 gtk_entry_set_max_length(GTK_ENTRY(bad_entry), 40); | |
497 gtk_box_pack_start(GTK_BOX(hbox), bad_entry, TRUE, TRUE, 0); | |
498 gtk_size_group_add_widget(sg, bad_entry); | |
499 gtk_label_set_mnemonic_widget(GTK_LABEL(label), bad_entry); | |
500 gtk_widget_show(bad_entry); | |
501 | |
502 hbox = gtk_hbox_new(FALSE, 2); | |
503 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
504 gtk_widget_show(hbox); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
505 |
4348 | 506 label = gtk_label_new_with_mnemonic(_("You _send:")); |
507 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
508 |
4348 | 509 good_entry = gtk_entry_new(); |
510 gtk_entry_set_max_length(GTK_ENTRY(good_entry), 255); | |
511 gtk_box_pack_start(GTK_BOX(hbox), good_entry, TRUE, TRUE, 0); | |
512 gtk_size_group_add_widget(sg, good_entry); | |
513 gtk_label_set_mnemonic_widget(GTK_LABEL(label), good_entry); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
514 gtk_widget_show(good_entry); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
515 |
4348 | 516 hbox = gtk_hbutton_box_new(); |
517 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
518 button = gtk_button_new_from_stock(GTK_STOCK_ADD); | |
519 g_signal_connect(G_OBJECT(button), "clicked", | |
520 G_CALLBACK(list_add_new), NULL); | |
521 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
522 g_signal_connect(G_OBJECT(bad_entry), "changed", G_CALLBACK(on_entry_changed), button); | |
523 g_signal_connect(G_OBJECT(good_entry), "changed", G_CALLBACK(on_entry_changed), button); | |
524 gtk_widget_set_sensitive(button, FALSE); | |
525 gtk_widget_show(button); | |
526 | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
527 |
3565 | 528 gtk_widget_show_all(ret); |
529 return ret; | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
530 } |