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