Mercurial > pidgin
annotate plugins/spellchk.c @ 4207:bda7855fa32f
[gaim-migrate @ 4443]
So, I figured, "Hey, it's 7am on a Sunday. Why don't I take the legend out
of OSCAR Info windows."
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 05 Jan 2003 12:09:34 +0000 |
parents | 59751fe608c5 |
children | 922b66840a51 |
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 |
30 struct replace_words { | |
31 char *bad; | |
32 char *good; | |
33 }; | |
34 | |
35 GList *words = NULL; | |
36 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
37 static int num_words(char *); |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
38 static int get_word(char *, int); |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
39 static char *have_word(char *, int); |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
40 static void substitute(char **, int, int, char *); |
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 GList *w; | |
46 char *tmp; | |
47 | |
48 if (message == NULL || *message == NULL) | |
49 return; | |
50 | |
51 l = num_words(*message); | |
52 for (i = 0; i < l; i++) { | |
53 word = get_word(*message, i); | |
54 w = words; | |
55 while (w) { | |
56 struct replace_words *r; | |
57 r = (struct replace_words *)(w->data); | |
58 tmp = have_word(*message, word); | |
138
e8ea1e2fdf0c
[gaim-migrate @ 148]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
123
diff
changeset
|
59 if (!strcmp(tmp, r->bad)) { |
103 | 60 substitute(message, word, strlen(r->bad), |
61 r->good); | |
112
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
62 l += num_words(r->good) - num_words(r->bad); |
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
63 i += num_words(r->good) - num_words(r->bad); |
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
64 } |
103 | 65 free(tmp); |
66 w = w->next; | |
67 } | |
68 } | |
69 } | |
70 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
71 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
|
72 int pos = *position, spos = pos; |
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 if (pos == len) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
75 return 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
76 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
77 while (ibuf[pos++] != '\n') { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
78 if (pos == len) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
79 return 0; |
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 pos--; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
82 ibuf[pos] = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
83 *buf = &ibuf[spos]; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
84 pos++; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
85 *position = pos; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
86 return 1; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
87 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
88 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
89 static void load_conf() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
90 char *defaultconf = "BAD r\nGOOD are\n\n" |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
91 "BAD u\nGOOD you\n\n" |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
92 "BAD teh\nGOOD the\n\n"; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
93 char *buf, *ibuf; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
94 char name[82]; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
95 char cmd[256]; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
96 int fh, pnt = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
97 struct stat st; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
98 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
99 if (words != NULL) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
100 g_list_free(words); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
101 words = NULL; |
103 | 102 |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
103 buf = malloc(1000); |
3728 | 104 snprintf(buf, 1000, "%s/.gaim/dict", gaim_home_dir()); |
123
f7a5f376f54e
[gaim-migrate @ 133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
113
diff
changeset
|
105 fh = open(buf, O_RDONLY, 0600); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
106 if (fh == -1) { |
123
f7a5f376f54e
[gaim-migrate @ 133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
113
diff
changeset
|
107 fh = open(buf, O_TRUNC | O_WRONLY | O_CREAT, 0600); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
108 if (fh != -1) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
109 write(fh, defaultconf, strlen(defaultconf)); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
110 close(fh); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
111 free(buf); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
112 load_conf(); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
113 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
114 return; |
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 free(buf); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
117 if (fstat(fh, &st) != 0) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
118 return; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
119 ibuf = malloc(st.st_size); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
120 read(fh, ibuf, st.st_size); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
121 close(fh); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
122 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
123 cmd[0] = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
124 name[0] = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
125 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
126 while(buf_get_line(ibuf, &buf, &pnt, st.st_size)) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
127 if (*buf != '#') { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
128 if (!strncasecmp(buf, "BAD ", 4)) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
129 strncpy(name, buf + 4, 81); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
130 if (!strncasecmp(buf, "GOOD ", 5)) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
131 strncpy(cmd, buf + 5, 255); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
132 if (*name) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
133 struct replace_words *r; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
134 r = malloc(sizeof *r); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
135 r->bad = strdup(name); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
136 r->good = strdup(cmd); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
137 words = g_list_append(words, r); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
138 cmd[0] = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
139 name[0] = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
140 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
141 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
142 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
143 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
144 free(ibuf); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
145 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
146 |
103 | 147 |
148 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
149 static int num_words(char *m) { |
103 | 150 int count = 0; |
151 int pos; | |
152 int state = 0; | |
153 | |
154 for (pos = 0; pos < strlen(m); pos++) { | |
155 switch (state) { | |
156 case 0: /* expecting word */ | |
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1862
diff
changeset
|
157 if (!isspace(m[pos]) && !ispunct(m[pos])) { |
103 | 158 count++; |
159 state = 1; | |
160 } else if (m[pos] == '<') | |
161 state = 2; | |
162 break; | |
163 case 1: /* inside word */ | |
112
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
164 if (m[pos] == '<') |
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
165 state = 2; |
1873
08ac51210d09
[gaim-migrate @ 1883]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1862
diff
changeset
|
166 else if (isspace(m[pos]) || ispunct(m[pos])) |
103 | 167 state = 0; |
168 break; | |
169 case 2: /* inside HTML tag */ | |
170 if (m[pos] == '>') | |
171 state = 0; | |
172 break; | |
173 } | |
174 } | |
175 return count; | |
176 } | |
177 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
178 static int get_word(char *m, int word) { |
103 | 179 int count = 0; |
180 int pos = 0; | |
181 int state = 0; | |
182 | |
183 for (pos = 0; pos < strlen(m) && count <= word; pos++) { | |
184 switch (state) { | |
185 case 0: | |
1862
fd60aa357882
[gaim-migrate @ 1872]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1740
diff
changeset
|
186 if (!isspace(m[pos]) && !ispunct(m[pos])) { |
103 | 187 count++; |
188 state = 1; | |
189 } else if (m[pos] == '<') | |
190 state = 2; | |
191 break; | |
192 case 1: | |
112
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
193 if (m[pos] == '<') |
a57fd3390ee4
[gaim-migrate @ 122]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
111
diff
changeset
|
194 state = 2; |
1862
fd60aa357882
[gaim-migrate @ 1872]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1740
diff
changeset
|
195 else if (isspace(m[pos]) || ispunct(m[pos])) |
103 | 196 state = 0; |
197 break; | |
198 case 2: | |
199 if (m[pos] == '>') | |
200 state = 0; | |
201 break; | |
202 } | |
203 } | |
204 return pos - 1; | |
205 } | |
206 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
207 static char *have_word(char *m, int pos) { |
3733 | 208 char *tmp = strpbrk(&m[pos], "' \t\f\r\n\"><.?!-,/"); |
103 | 209 int len = (int)(tmp - &m[pos]); |
210 | |
211 if (tmp == NULL) { | |
212 tmp = strdup(&m[pos]); | |
213 return tmp; | |
214 } | |
215 | |
216 tmp = malloc(len + 1); | |
217 tmp[0] = 0; | |
218 strncat(tmp, &m[pos], len); | |
219 | |
220 return tmp; | |
221 } | |
222 | |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
223 static void substitute(char **mes, int pos, int m, char *text) { |
257
a93e273ca1d6
[gaim-migrate @ 267]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
224 char *new = g_malloc(strlen(*mes) + strlen(text) + 1); |
103 | 225 char *tmp; |
226 new[0] = 0; | |
227 | |
228 strncat(new, *mes, pos); | |
229 strcat(new, text); | |
230 | |
231 strcat(new, &(*mes)[pos + m]); | |
232 tmp = *mes; | |
233 *mes = new; | |
257
a93e273ca1d6
[gaim-migrate @ 267]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
208
diff
changeset
|
234 g_free(tmp); |
103 | 235 } |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
236 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
237 static GtkWidget *configwin = NULL; |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
238 static GtkWidget *list; |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
239 static GtkWidget *bad_entry; |
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
240 static GtkWidget *good_entry; |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
241 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
242 static void row_unselect() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
243 gtk_entry_set_text(GTK_ENTRY(bad_entry), ""); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
244 gtk_entry_set_text(GTK_ENTRY(good_entry), ""); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
245 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
246 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
247 static void row_select() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
248 char *badwrd, *goodwrd; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
249 int row; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
250 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
251 if (GTK_CLIST(list)->selection) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
252 row = (int) GTK_CLIST (list)->selection->data; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
253 else |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
254 row = -1; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
255 if (row != -1) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
256 gtk_clist_get_text(GTK_CLIST(list), row, 0, &badwrd); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
257 gtk_clist_get_text(GTK_CLIST(list), row, 1, &goodwrd); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
258 gtk_entry_set_text(GTK_ENTRY(bad_entry), badwrd); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
259 gtk_entry_set_text(GTK_ENTRY(good_entry), goodwrd); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
260 } else { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
261 row_unselect(); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
262 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
263 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
264 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
265 static void list_add_new() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
266 int i; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
267 gchar *item[2] = {"*NEW*", "EDIT ME"}; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
268 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
269 i = gtk_clist_append(GTK_CLIST(list), item); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
270 gtk_clist_select_row(GTK_CLIST(list), i, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
271 gtk_clist_moveto(GTK_CLIST(list), i, 0, 0.5, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
272 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
273 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
274 static void list_delete() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
275 int row; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
276 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
277 if (GTK_CLIST(list)->selection) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
278 row = (int) GTK_CLIST (list)->selection->data; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
279 else |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
280 row = -1; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
281 if (row != -1) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
282 gtk_clist_unselect_all(GTK_CLIST(list)); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
283 gtk_clist_remove(GTK_CLIST(list), row); |
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 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
286 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
287 static void close_config() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
288 if (configwin) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
289 gtk_widget_destroy(configwin); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
290 configwin = NULL; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
291 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
292 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
293 static void save_list() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
294 int fh, i = 0; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
295 char buf[512]; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
296 char *a, *b; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
297 |
3728 | 298 snprintf(buf, sizeof buf, "%s/.gaim/dict", gaim_home_dir()); |
123
f7a5f376f54e
[gaim-migrate @ 133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
113
diff
changeset
|
299 fh = open(buf, O_TRUNC | O_WRONLY | O_CREAT, 0600); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
300 if (fh != 1) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
301 while (gtk_clist_get_text(GTK_CLIST(list), i, 0, &a)) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
302 gtk_clist_get_text(GTK_CLIST(list), i, 1, &b); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
303 snprintf(buf, sizeof buf, "BAD %s\nGOOD %s\n\n", a, b); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
304 write(fh, buf, strlen(buf)); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
305 i++; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
306 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
307 close (fh); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
308 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
309 close_config(); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
310 load_conf(); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
311 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
312 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
313 static void bad_changed() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
314 int row; |
1940
8de58cd2892f
[gaim-migrate @ 1950]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1873
diff
changeset
|
315 const char *m; |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
316 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
317 if (GTK_CLIST(list)->selection) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
318 row = (int) GTK_CLIST (list)->selection->data; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
319 else |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
320 row = -1; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
321 if (row != -1) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
322 m = gtk_entry_get_text(GTK_ENTRY(bad_entry)); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
323 gtk_clist_set_text(GTK_CLIST(list), row, 0, m); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
324 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
325 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
326 |
1081
efcacae6acdb
[gaim-migrate @ 1091]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
327 static void good_changed() { |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
328 int row; |
1940
8de58cd2892f
[gaim-migrate @ 1950]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1873
diff
changeset
|
329 const char *m; |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
330 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
331 if (GTK_CLIST(list)->selection) |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
332 row = (int) GTK_CLIST (list)->selection->data; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
333 else |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
334 row = -1; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
335 if (row != -1) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
336 m = gtk_entry_get_text(GTK_ENTRY(good_entry)); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
337 gtk_clist_set_text(GTK_CLIST(list), row, 1, m); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
338 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
339 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
340 |
3630 | 341 /* |
342 * EXPORTED FUNCTIONS | |
343 */ | |
344 | |
345 G_MODULE_EXPORT char *gaim_plugin_init(GModule *handle) { | |
346 load_conf(); | |
347 | |
348 gaim_signal_connect(handle, event_im_send, substitute_words, NULL); | |
349 gaim_signal_connect(handle, event_chat_send, substitute_words, NULL); | |
350 return NULL; | |
351 } | |
352 | |
353 G_MODULE_EXPORT void gaim_plugin_remove() { | |
354 } | |
355 | |
356 struct gaim_plugin_description desc; | |
357 G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() { | |
358 desc.api_version = PLUGIN_API_VERSION; | |
359 desc.name = g_strdup("Text replacement"); | |
360 desc.version = g_strdup(VERSION); | |
361 desc.description = g_strdup("Replaces text in outgoing messages according to user-defined rules."); | |
362 desc.authors = g_strdup("Eric Warmehoven <eric@warmenhoven.org>"); | |
363 desc.url = g_strdup(WEBSITE); | |
364 return &desc; | |
365 } | |
366 | |
367 G_MODULE_EXPORT char *name() { | |
368 return "IM Spell Check"; | |
369 } | |
370 | |
371 G_MODULE_EXPORT char *description() { | |
372 return "Watches outgoing IM text and corrects common spelling errors."; | |
373 } | |
374 | |
375 G_MODULE_EXPORT GtkWidget *gaim_plugin_config_gtk() { | |
3565 | 376 GtkWidget *ret, *vbox, *win; |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
377 GtkWidget *hbox; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
378 GtkWidget *button; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
379 GList *w = words; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
380 struct replace_words *r; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
381 char *pair[2] = {"Replace", "With"}; |
3565 | 382 |
383 ret = gtk_vbox_new(FALSE, 18); | |
384 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
385 |
3565 | 386 vbox = make_frame(ret, _("Text Replacements")); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
387 gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
388 gtk_container_add(GTK_CONTAINER(configwin), vbox); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
389 gtk_widget_show (vbox); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
390 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
391 win = gtk_scrolled_window_new(0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
392 gtk_container_add(GTK_CONTAINER(vbox), win); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
393 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (win), |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
394 GTK_POLICY_AUTOMATIC, |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
395 GTK_POLICY_ALWAYS); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
396 gtk_widget_show(win); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
397 list = gtk_clist_new_with_titles(2, pair); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
398 gtk_clist_set_column_width(GTK_CLIST(list), 0, 90); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
399 gtk_clist_set_selection_mode(GTK_CLIST(list), GTK_SELECTION_BROWSE); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
400 gtk_clist_column_titles_passive(GTK_CLIST(list)); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
401 gtk_container_add(GTK_CONTAINER(win), list); |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
402 g_signal_connect(GTK_OBJECT(list), "select_row", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
403 G_CALLBACK(row_select), NULL); |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
404 g_signal_connect(GTK_OBJECT(list), "unselect_row", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
405 G_CALLBACK(row_unselect), NULL); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
406 gtk_widget_show(list); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
407 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
408 hbox = gtk_hbox_new(FALSE, 2); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
409 gtk_box_pack_end(GTK_BOX(vbox), hbox, 0, 0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
410 gtk_widget_show(hbox); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
411 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
412 button = gtk_button_new_with_label("Add New"); |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
413 g_signal_connect(GTK_OBJECT(button), "clicked", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
414 G_CALLBACK(list_add_new), NULL); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
415 gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
416 gtk_widget_set_usize(button, 100, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
417 gtk_widget_show(button); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
418 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
419 button = gtk_button_new_with_label("Delete"); |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
420 g_signal_connect(GTK_OBJECT(button), "clicked", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
421 G_CALLBACK(list_delete), NULL); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
422 gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
423 gtk_widget_set_usize(button, 100, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
424 gtk_widget_show(button); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
425 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
426 button = gtk_button_new_with_label("Cancel"); |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
427 g_signal_connect(GTK_OBJECT(button), "clicked", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
428 G_CALLBACK(close_config), NULL); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
429 gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
430 gtk_widget_set_usize(button, 100, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
431 gtk_widget_show(button); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
432 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
433 button = gtk_button_new_with_label("Save"); |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
434 g_signal_connect(GTK_OBJECT(button), "clicked", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
435 G_CALLBACK(save_list), NULL); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
436 gtk_box_pack_start(GTK_BOX(hbox), button, 0, 0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
437 gtk_widget_set_usize(button, 100, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
438 gtk_widget_show(button); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
439 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
440 hbox = gtk_hbox_new(FALSE, 2); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
441 gtk_box_pack_end(GTK_BOX(vbox), hbox, 0, 0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
442 gtk_widget_show(hbox); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
443 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
444 bad_entry = gtk_entry_new_with_max_length(40); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
445 gtk_widget_set_usize(bad_entry, 96, 0); |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
446 g_signal_connect(GTK_OBJECT(bad_entry), "changed", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
447 G_CALLBACK(bad_changed), NULL); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
448 gtk_box_pack_start(GTK_BOX(hbox), bad_entry, 0, 0, 0); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
449 gtk_widget_show(bad_entry); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
450 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
451 good_entry = gtk_entry_new_with_max_length(255); |
4165
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
452 g_signal_connect(GTK_OBJECT(good_entry), "changed", |
07a3d1fae88f
[gaim-migrate @ 4394]
Christian Hammond <chipx86@chipx86.com>
parents:
3733
diff
changeset
|
453 G_CALLBACK(good_changed), NULL); |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
454 gtk_container_add(GTK_CONTAINER(hbox), good_entry); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
455 gtk_widget_show(good_entry); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
456 |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
457 while (w) { |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
458 r = (struct replace_words *)(w->data); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
459 pair[0] = r->bad; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
460 pair[1] = r->good; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
461 gtk_clist_append(GTK_CLIST(list), pair); |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
462 w = w->next; |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
463 } |
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
464 |
3565 | 465 gtk_widget_show_all(ret); |
466 return ret; | |
111
d927bb34e2c6
[gaim-migrate @ 121]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
467 } |