Mercurial > pidgin.yaz
annotate plugins/notify.c @ 5079:6e02fa68d5e1
[gaim-migrate @ 5432]
/me hands sean and luke an 80-column terminal
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 08 Apr 2003 03:02:32 +0000 |
parents | 00b6af528964 |
children | fefad67de2c7 |
rev | line source |
---|---|
3392 | 1 /* Rewritten by Etan Reisner <deryni@eden.rutgers.edu> |
3374 | 2 * |
3 * Added config dialog | |
4 * Added control over notification method | |
5 * Added control over when to release notification | |
4035 | 6 * |
7 * Added option to get notification for chats also | |
8 * Cleaned up code | |
9 * Added option to notify on click as it's own option | |
10 * rather then as what happens when on focus isn't clicked | |
11 * Added apply button to change the denotification methods for | |
12 * open conversation windows | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
13 * Fixed apply to conversations, count now keeps count across applies |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
14 * Fixed(?) memory leak, and in the process fixed some stupidities |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
15 * Hit enter when done editing the title string entry box to save it |
3392 | 16 * |
17 * Thanks to Carles Pina i Estany <carles@pinux.info> | |
18 * for count of new messages option | |
19 */ | |
20 | |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
21 #include "config.h" |
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
22 |
3710 | 23 #ifndef GAIM_PLUGINS |
24 #define GAIM_PLUGINS | |
25 #endif | |
3374 | 26 |
191 | 27 #include "gaim.h" |
3428 | 28 #include <string.h> |
29 #include <ctype.h> | |
30 #include <stdlib.h> | |
191 | 31 #include <gtk/gtk.h> |
3385 | 32 #include <X11/Xlib.h> |
3374 | 33 #include <X11/Xutil.h> |
3392 | 34 #include <X11/Xatom.h> |
3374 | 35 #include <gdk/gdkx.h> |
36 | |
3710 | 37 guint type = 1; |
5021 | 38 #define TYPE_IM 0x00000001 |
39 #define TYPE_CHAT 0x00000002 | |
3710 | 40 |
3392 | 41 guint choice = 1; |
42 #define NOTIFY_FOCUS 0x00000001 | |
43 #define NOTIFY_TYPE 0x00000002 | |
5021 | 44 #define NOTIFY_IN_FOCUS 0x00000004 |
45 #define NOTIFY_CLICK 0x00000008 | |
3374 | 46 |
3392 | 47 guint method = 1; |
48 #define METHOD_STRING 0x00000001 | |
49 #define METHOD_QUOTE 0x00000002 | |
50 #define METHOD_URGENT 0x00000004 | |
51 #define METHOD_COUNT 0x00000008 | |
191 | 52 |
53 void *handle; | |
3565 | 54 GtkWidget *Entry; |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
55 gchar *title_string; |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
56 int Number = 0; |
191 | 57 |
3374 | 58 /* predefine some functions, less warnings */ |
59 void options(GtkWidget *widget, gpointer data); | |
4047 | 60 /* this returns an int so that typing events don't get stopped here */ |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
61 int un_star(GtkWidget *widget, gpointer data); |
3428 | 62 int counter (char *buf, int *length); |
4035 | 63 /*string functions */ |
64 void string_add(GtkWidget *widget); | |
65 gboolean string_remove(GtkWidget *widget); | |
66 /* count functions */ | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
67 void count_add(GtkWidget *widget, int number); |
4035 | 68 gboolean count_remove(GtkWidget *widget); |
69 /* quote functions */ | |
70 void quote_add(GtkWidget *widget); | |
71 gboolean quote_remove(GtkWidget *widget); | |
72 /* urgent functions */ | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
73 void urgent_add(struct gaim_conversation *c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
74 gboolean urgent_remove(struct gaim_conversation *c); |
3710 | 75 |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
76 int notify(struct gaim_conversation *cnv) { |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
77 struct gaim_gtk_window *gtkwin; |
3710 | 78 Window focus_return; |
4035 | 79 int revert_to_return; |
191 | 80 |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
81 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(cnv)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
82 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
83 XGetInputFocus(GDK_WINDOW_XDISPLAY(gtkwin->window->window), &focus_return, &revert_to_return); |
3374 | 84 |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
85 if ((choice & NOTIFY_IN_FOCUS) || |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
86 focus_return != GDK_WINDOW_XWINDOW(gtkwin->window->window)) { |
4035 | 87 if (method & METHOD_STRING) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
88 string_add(gtkwin->window); |
4035 | 89 if (method & METHOD_COUNT) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
90 count_add(gtkwin->window, 0); |
4035 | 91 if (method & METHOD_QUOTE) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
92 quote_add(gtkwin->window); |
4035 | 93 if (method & METHOD_URGENT) |
94 urgent_add(cnv); | |
3374 | 95 } |
96 return 0; | |
97 } | |
98 | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
99 guint unnotify(struct gaim_conversation *c, gboolean clean) { |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
100 struct gaim_gtk_window *gtkwin; |
4035 | 101 guint option = 0; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
102 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
103 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5021 | 104 |
4043 | 105 /* The top level ifs check whether we are either cleaning all methods, |
106 * or whether we have that method is currently selected. | |
107 * If we do then they are cleaned | |
108 * | |
109 * The second level ifs check if we removed something, | |
110 * and if that method is currently selected. | |
111 * If we did and it is then set option so that it can be re-added */ | |
4035 | 112 if (clean || (method & METHOD_QUOTE)) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
113 if (quote_remove(gtkwin->window) && (method & METHOD_QUOTE)) |
4035 | 114 option ^= METHOD_QUOTE; |
5021 | 115 |
4035 | 116 if (clean || (method & METHOD_COUNT)) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
117 if (count_remove(gtkwin->window) && (method & METHOD_COUNT)) |
4035 | 118 option ^= METHOD_COUNT; |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
119 |
4035 | 120 if (clean || (method & METHOD_STRING)) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
121 if (string_remove(gtkwin->window) && (method & METHOD_STRING)) |
4035 | 122 option ^= METHOD_STRING; |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
123 |
4035 | 124 if (clean || (method & METHOD_URGENT)) |
4043 | 125 if (urgent_remove(c) && (method & METHOD_URGENT)) |
4035 | 126 option ^= METHOD_URGENT; |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
127 |
4035 | 128 return option; |
3374 | 129 } |
130 | |
3710 | 131 void chat_recv_im(struct gaim_connection *gc, int id, char **who, char **text) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
132 struct gaim_conversation *c = gaim_find_chat(gc, id); |
3710 | 133 |
134 if (c && (type & TYPE_CHAT)) | |
135 notify(c); | |
136 return; | |
137 } | |
138 | |
139 void chat_sent_im(struct gaim_connection *gc, int id, char **text) { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
140 struct gaim_conversation *c = gaim_find_chat(gc, id); |
3710 | 141 |
142 if (c && (type & TYPE_CHAT)) | |
4035 | 143 unnotify(c, FALSE); |
3710 | 144 return; |
145 } | |
146 | |
147 int im_recv_im(struct gaim_connection *gc, char **who, char **what, void *m) { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
148 struct gaim_conversation *c = gaim_find_conversation(*who); |
3710 | 149 |
150 if (c && (type & TYPE_IM)) | |
151 notify(c); | |
152 return 0; | |
153 } | |
154 | |
155 int im_sent_im(struct gaim_connection *gc, char *who, char **what, void *m) { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
156 struct gaim_conversation *c = gaim_find_conversation(who); |
3374 | 157 |
3710 | 158 if (c && (type & TYPE_IM)) |
4035 | 159 unnotify(c, FALSE); |
3710 | 160 return 0; |
161 } | |
3392 | 162 |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
163 int attach_signals(struct gaim_conversation *c) { |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
164 struct gaim_gtk_conversation *gtkconv; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
165 struct gaim_gtk_window *gtkwin; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
166 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
167 gtkconv = GAIM_GTK_CONVERSATION(c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
168 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
169 |
3392 | 170 if (choice & NOTIFY_FOCUS) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
171 g_signal_connect(G_OBJECT(gtkwin->window), "focus-in-event", G_CALLBACK(un_star), NULL); |
3374 | 172 } |
3710 | 173 |
174 if (choice & NOTIFY_CLICK) { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
175 g_signal_connect(G_OBJECT(gtkwin->window), "button_press_event", G_CALLBACK(un_star), NULL); |
4035 | 176 |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
177 g_signal_connect_swapped(G_OBJECT(gtkconv->imhtml), "button_press_event", G_CALLBACK(un_star), G_OBJECT(gtkwin->window)); |
4035 | 178 |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
179 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "button_press_event", G_CALLBACK(un_star), G_OBJECT(gtkwin->window)); |
3374 | 180 } |
181 | |
3392 | 182 if (choice & NOTIFY_TYPE) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
183 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key-press-event", G_CALLBACK(un_star), G_OBJECT(gtkwin->window)); |
191 | 184 } |
4035 | 185 |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
186 g_object_set_data(G_OBJECT(gtkwin->window), "user_data", c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
187 g_object_set_data(G_OBJECT(gtkwin->window), "notify_data", GUINT_TO_POINTER(choice)); |
3428 | 188 return 0; |
191 | 189 } |
190 | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
191 void detach_signals(struct gaim_conversation *c) { |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
192 struct gaim_gtk_conversation *gtkconv; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
193 struct gaim_gtk_window *gtkwin; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
194 guint options; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
195 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
196 gtkconv = GAIM_GTK_CONVERSATION(c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
197 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
198 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
199 options = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(gtkwin->window), "notify_data")); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
200 |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
201 if (options & NOTIFY_FOCUS) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
202 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), un_star, NULL); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
203 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
204 if (options & NOTIFY_CLICK) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
205 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), un_star, NULL); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
206 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->imhtml), un_star, gtkwin->window); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
207 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry), un_star, gtkwin->window); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
208 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
209 |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
210 if (options & NOTIFY_TYPE) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
211 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry), un_star, gtkwin->window); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
212 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
213 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
214 |
3710 | 215 void new_conv(char *who) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
216 struct gaim_conversation *c = gaim_find_conversation(who); |
3710 | 217 |
4035 | 218 if (c && (type & TYPE_IM)) |
3710 | 219 attach_signals(c); |
220 } | |
221 | |
222 void chat_join(struct gaim_connection *gc, int id, char *room) { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
223 struct gaim_conversation *c = gaim_find_chat(gc, id); |
3710 | 224 |
4043 | 225 if (c && (type & TYPE_CHAT)) |
3710 | 226 attach_signals(c); |
227 } | |
228 | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
229 int un_star(GtkWidget *widget, gpointer data) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
230 struct gaim_conversation *c = g_object_get_data(G_OBJECT(widget), "user_data"); |
3374 | 231 |
232 if (method & METHOD_QUOTE) | |
233 quote_remove(widget); | |
3392 | 234 if (method & METHOD_COUNT) |
235 count_remove(widget); | |
3374 | 236 if (method & METHOD_STRING) |
237 string_remove(widget); | |
4043 | 238 if (c && method & METHOD_URGENT) |
3374 | 239 urgent_remove(c); |
4047 | 240 return 0; |
3374 | 241 } |
242 | |
5021 | 243 /* This function returns the number in [ ]'s or 0 |
244 and sets *length to the number of digits in that number */ | |
3392 | 245 int counter (char *buf, int *length) { |
246 char temp[256]; | |
5021 | 247 int i = 0; |
248 int j = 0; | |
3392 | 249 *length = 0; |
250 | |
5021 | 251 /* Don't assume buf[0]=='[' */ |
252 while( buf[i++] != '[' && i<sizeof(buf)); | |
253 | |
3392 | 254 while (isdigit(buf[i]) && i<sizeof(buf)) { |
5021 | 255 temp[j++] = buf[i++]; |
3392 | 256 (*length)++; |
257 } | |
5021 | 258 temp[j] = '\0'; |
4035 | 259 |
3392 | 260 if (buf[i] != ']') { |
261 *length = 0; | |
262 return (0); | |
263 } | |
264 | |
265 return (atoi(temp)); | |
266 } | |
267 | |
4035 | 268 void string_add(GtkWidget *widget) { |
269 char buf[256]; | |
270 GtkWindow *win = GTK_WINDOW(widget); | |
271 | |
272 strncpy(buf, win->title, sizeof(buf)); | |
273 if (!strstr(buf, title_string)) { | |
274 g_snprintf(buf, sizeof(buf), "%s%s", title_string, win->title); | |
275 gtk_window_set_title(win, buf); | |
276 } | |
277 } | |
278 | |
279 gboolean string_remove(GtkWidget *widget) { | |
191 | 280 char buf[256]; |
3374 | 281 GtkWindow *win = GTK_WINDOW(widget); |
282 | |
3392 | 283 strncpy(buf, win->title, sizeof(buf)); |
3374 | 284 if (strstr(buf, title_string)) { |
285 g_snprintf(buf, sizeof(buf), "%s", &win->title[strlen(title_string)]); | |
286 gtk_window_set_title(win, buf); | |
4035 | 287 return TRUE; |
3374 | 288 } |
4035 | 289 return FALSE; |
3374 | 290 } |
291 | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
292 void count_add(GtkWidget *widget, int number) { |
4035 | 293 char buf[256]; |
294 int c, length; | |
295 GtkWindow *win = GTK_WINDOW(widget); | |
296 | |
297 strncpy(buf, win->title, sizeof(buf)); | |
298 c = counter(buf, &length); | |
5021 | 299 |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
300 if (number) { |
5021 | 301 /* This might cause problems in the future. |
302 I'm pretty sure if count_add is called after quote_add | |
303 and number!=0, then this will have problems dealing with | |
304 the quotation marks. */ | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
305 g_snprintf(buf, sizeof(buf), "[%d] %s", number, win->title); |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
306 } else if (!c) { |
4035 | 307 g_snprintf(buf, sizeof(buf), "[1] %s", win->title); |
5021 | 308 } else if (buf[0] == '[' || buf[1] == '[' ) { |
309 /* This has to be so complicated in order to account for METHOD_QUOTE */ | |
310 g_snprintf(buf, sizeof(buf), "[%d] %s", c+1, &win->title[ ((method & METHOD_QUOTE) ? 4 : 3)+length ]); | |
311 if( buf[ strlen(buf)-1 ] == '"' ) | |
312 buf[ strlen(buf)-1 ] = '\0'; | |
4035 | 313 } |
314 gtk_window_set_title(win, buf); | |
315 } | |
316 | |
317 gboolean count_remove(GtkWidget *widget) { | |
3392 | 318 char buf[256]; |
319 GtkWindow *win = GTK_WINDOW(widget); | |
320 int length; | |
321 | |
322 strncpy(buf, win->title, sizeof(buf)); | |
4793 | 323 if (buf[0] == '[') { |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
324 Number = counter(buf, &length); |
3392 | 325 g_snprintf(buf, sizeof(buf), "%s", &win->title[3+length]); |
326 gtk_window_set_title(win, buf); | |
4035 | 327 return TRUE; |
3392 | 328 } |
4035 | 329 return FALSE; |
3392 | 330 } |
331 | |
4035 | 332 void quote_add(GtkWidget *widget) { |
333 char buf[256]; | |
334 GtkWindow *win = GTK_WINDOW(widget); | |
335 | |
336 strncpy(buf, win->title, sizeof(buf)); | |
4793 | 337 if (buf[0] != '\"') { |
4035 | 338 g_snprintf(buf, sizeof(buf), "\"%s\"", win->title); |
339 gtk_window_set_title(win, buf); | |
340 } | |
341 } | |
342 | |
343 gboolean quote_remove(GtkWidget *widget) { | |
3374 | 344 char buf[256]; |
345 GtkWindow *win = GTK_WINDOW(widget); | |
191 | 346 |
3392 | 347 strncpy(buf, win->title, sizeof(buf)); |
4793 | 348 if (buf[0] == '\"') { |
3374 | 349 g_snprintf(buf, strlen(buf) - 1, "%s", &win->title[1]); |
191 | 350 gtk_window_set_title(win, buf); |
4035 | 351 return TRUE; |
191 | 352 } |
4035 | 353 return FALSE; |
3374 | 354 } |
355 | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
356 void urgent_add(struct gaim_conversation *c) { |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
357 struct gaim_gtk_window *gtkwin; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
358 XWMHints *hints; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
359 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
360 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
361 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
362 hints = XGetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window)); |
4035 | 363 hints->flags |= XUrgencyHint; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
364 XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints); |
4218 | 365 XFree(hints); |
4035 | 366 } |
367 | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
368 gboolean urgent_remove(struct gaim_conversation *c) { |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
369 struct gaim_gtk_conversation *gtkconv; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
370 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
371 gtkconv = GAIM_GTK_CONVERSATION(c); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
372 |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
373 if ((gaim_conversation_get_type(c) == GAIM_CONV_CHAT && |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
374 (chat_options & OPT_CHAT_ONE_WINDOW)) || |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
375 (gaim_conversation_get_type(c) != GAIM_CONV_CHAT && |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
376 (im_options & OPT_IM_ONE_WINDOW))) { |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
377 if (gaim_conversation_get_type(c) == GAIM_CONV_CHAT) { |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
378 struct gaim_conversation *c = (struct gaim_conversation *)gaim_get_chats()->data; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
379 struct gaim_gtk_window *gtkwin; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
380 GdkWindow *win; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
381 XWMHints *hints; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
382 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
383 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
384 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
385 win = gtkwin->window->window; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
386 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
387 hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win), GDK_WINDOW_XWINDOW(win)); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
388 if (hints->flags & XUrgencyHint) { |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
389 hints->flags &= ~XUrgencyHint; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
390 XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints); |
4218 | 391 XFree(hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
392 return TRUE; |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
393 } |
4218 | 394 XFree(hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
395 return FALSE; |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
396 } else { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
397 struct gaim_conversation *c; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
398 struct gaim_gtk_window *gtkwin; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
399 GdkWindow *win; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
400 XWMHints *hints; |
3374 | 401 |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
402 c = (struct gaim_conversation *)gaim_get_ims()->data; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
403 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
404 win = gtkwin->window->window; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
405 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
406 hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win), GDK_WINDOW_XWINDOW(win)); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
407 if (hints->flags & XUrgencyHint) { |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
408 hints->flags &= ~XUrgencyHint; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
409 XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints); |
4218 | 410 XFree(hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
411 return TRUE; |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
412 } |
4218 | 413 XFree(hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
414 return FALSE; |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
415 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
416 } else { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
417 struct gaim_gtk_window *gtkwin; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
418 XWMHints *hints; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
419 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
420 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
421 hints = XGetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
422 |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
423 if (hints->flags & XUrgencyHint) { |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
424 hints->flags &= ~XUrgencyHint; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
425 XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints); |
4218 | 426 XFree(hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
427 return TRUE; |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
428 } |
4218 | 429 XFree(hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
430 return FALSE; |
4035 | 431 } |
3374 | 432 } |
433 | |
434 void save_notify_prefs() { | |
3392 | 435 gchar buf[1000]; |
3374 | 436 FILE *fp; |
437 | |
438 snprintf(buf, 1000, "%s/.gaim/.notify", getenv("HOME")); | |
439 if (!(fp = fopen(buf, "w"))) { | |
3561 | 440 do_error_dialog(_("Unable to write to config file"), _("Notify plugin"), GAIM_ERROR); |
3374 | 441 return; |
442 } | |
443 | |
3710 | 444 fprintf(fp, "%d=TYPE\n", type); |
3392 | 445 fprintf(fp, "%d=CHOICE\n", choice); |
446 fprintf(fp, "%d=METHOD\n", method); | |
447 fprintf(fp, "%s=STRING\n", title_string); | |
3374 | 448 fclose(fp); |
449 } | |
450 | |
451 void load_notify_prefs() { | |
452 gchar buf[1000]; | |
453 gchar **parsed; | |
454 FILE *fp; | |
455 | |
456 g_snprintf(buf, sizeof(buf), "%s/.gaim/.notify", getenv("HOME")); | |
457 if (!(fp = fopen(buf, "r"))) | |
458 return; | |
459 | |
460 while (fgets(buf, 1000, fp) != NULL) { | |
461 parsed = g_strsplit(g_strchomp(buf), "=", 2); | |
462 if (parsed[0] && parsed[1]) { | |
3710 | 463 if (!strcmp(parsed[1], "TYPE")) |
464 type = atoi(parsed[0]); | |
3392 | 465 if (!strcmp(parsed[1], "CHOICE")) |
466 choice = atoi(parsed[0]); | |
467 if (!strcmp(parsed[1], "METHOD")) | |
468 method = atoi(parsed[0]); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
469 if (!strcmp(parsed[1], "STRING")) { |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
470 if (title_string != NULL) |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
471 g_free(title_string); |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
472 title_string = g_strdup(parsed[0]); |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
473 } |
3374 | 474 } |
3392 | 475 g_strfreev(parsed); |
3374 | 476 } |
477 fclose(fp); | |
478 return; | |
479 } | |
480 | |
481 void options(GtkWidget *widget, gpointer data) { | |
4035 | 482 gint option = GPOINTER_TO_INT(data); |
3374 | 483 |
484 if (option == 0) | |
3392 | 485 choice ^= NOTIFY_FOCUS; |
3374 | 486 else if (option == 1) |
3710 | 487 choice ^= NOTIFY_CLICK; |
488 else if (option == 2) | |
3392 | 489 choice ^= NOTIFY_TYPE; |
3710 | 490 else if (option == 3) { |
3374 | 491 method ^= METHOD_STRING; |
492 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) | |
493 gtk_widget_set_sensitive(Entry, TRUE); | |
494 else | |
495 gtk_widget_set_sensitive(Entry, FALSE); | |
496 } | |
3710 | 497 else if (option == 4) |
3374 | 498 method ^= METHOD_QUOTE; |
3710 | 499 else if (option == 5) |
3374 | 500 method ^= METHOD_URGENT; |
3710 | 501 else if (option == 6) |
3392 | 502 choice ^= NOTIFY_IN_FOCUS; |
3710 | 503 else if (option == 7) |
3392 | 504 method ^= METHOD_COUNT; |
3710 | 505 else if (option == 8) |
506 type ^= TYPE_IM; | |
507 else if (option == 9) | |
508 type ^= TYPE_CHAT; | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
509 else if (option == 10) { |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
510 /* I made an option for this as at least a way to have it save correctly |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
511 * I'd much rather there were better ways, and I don't want to save this |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
512 * no matter which pref is changed, that's too much of a hack */ |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
513 if (title_string != NULL) { |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
514 g_free(title_string); |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
515 title_string = g_strdup(gtk_entry_get_text(GTK_ENTRY(Entry))); |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
516 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
517 } |
3710 | 518 |
519 save_notify_prefs(); | |
3374 | 520 } |
521 | |
4035 | 522 void apply_options(GtkWidget *widget, gpointer data) { |
4376
2c985a9e994c
[gaim-migrate @ 4642]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
523 GList *cnv = gaim_get_conversations(); |
4035 | 524 |
525 while (cnv) { | |
526 guint notification; | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
527 struct gaim_conversation *c = (struct gaim_conversation *) cnv->data; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
528 struct gaim_gtk_conversation *gtkconv; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
529 struct gaim_gtk_window *gtkwin; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
530 guint options = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(c->window), "notify_data")); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
531 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
532 gtkconv = GAIM_GTK_CONVERSATION(c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
533 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
534 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
535 if (options & NOTIFY_FOCUS) |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
536 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), un_star, NULL); |
4035 | 537 |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
538 /* remove old notification signals */ |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
539 detach_signals(c); |
4035 | 540 |
541 /* clean off all notification markings */ | |
542 notification = unnotify(c, TRUE); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
543 |
4035 | 544 /* re-add appropriate notification methods cleaned above */ |
4043 | 545 if (notification & METHOD_STRING) /* re-add string */ |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
546 string_add(gtkwin->window); |
4035 | 547 if (notification & METHOD_QUOTE) /* re-add quote */ |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
548 quote_add(gtkwin->window); |
4035 | 549 if (notification & METHOD_COUNT) /* re-add count */ |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
550 count_add(gtkwin->window, Number); |
4035 | 551 if (notification & METHOD_URGENT) /* re-add urgent */ |
552 urgent_add(c); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
553 |
4035 | 554 /* attach new unnotification signals */ |
555 attach_signals(c); | |
556 | |
557 cnv = cnv->next; | |
558 } | |
559 } | |
560 | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1000
diff
changeset
|
561 char *gaim_plugin_init(GModule *hndl) { |
191 | 562 handle = hndl; |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
563 title_string = g_strdup("(*) "); |
191 | 564 |
3374 | 565 load_notify_prefs(); |
566 | |
3710 | 567 gaim_signal_connect(handle, event_im_recv, im_recv_im, NULL); |
568 gaim_signal_connect(handle, event_chat_recv, chat_recv_im, NULL); | |
569 gaim_signal_connect(handle, event_im_send, im_sent_im, NULL); | |
570 gaim_signal_connect(handle, event_chat_send, chat_sent_im, NULL); | |
3374 | 571 gaim_signal_connect(handle, event_new_conversation, new_conv, NULL); |
3710 | 572 gaim_signal_connect(handle, event_chat_join, chat_join, NULL); |
1052
25f121faa75e
[gaim-migrate @ 1062]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
573 return NULL; |
191 | 574 } |
575 | |
3392 | 576 void gaim_plugin_remove() { |
4476
62c1e5e656d0
[gaim-migrate @ 4751]
Christian Hammond <chipx86@chipx86.com>
parents:
4376
diff
changeset
|
577 GList *c = gaim_get_conversations(); |
3392 | 578 |
579 while (c) { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
580 struct gaim_conversation *cnv = (struct gaim_conversation *)c->data; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
581 struct gaim_gtk_window *gtkwin; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
582 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
583 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(cnv)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
584 |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
585 detach_signals(cnv); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
586 un_star(gtkwin->window, NULL); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
587 |
3710 | 588 c = c->next; |
3392 | 589 } |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
590 |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
591 /* this might be a hack I'm not sure, I don't think so but... */ |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
592 g_free(title_string); |
3392 | 593 } |
594 | |
3551 | 595 struct gaim_plugin_description desc; |
596 struct gaim_plugin_description *gaim_plugin_desc() { | |
597 desc.api_version = PLUGIN_API_VERSION; | |
4585 | 598 desc.name = g_strdup(_("Message Notification")); |
3551 | 599 desc.version = g_strdup(VERSION); |
4585 | 600 desc.description = g_strdup(_("Provides a variety of ways of notifying you of unread messages.")); |
3551 | 601 desc.authors = g_strdup("Etan Reisner <deryni@eden.rutgers.edu>"); |
602 desc.url = g_strdup(WEBSITE); | |
603 return &desc; | |
604 } | |
605 | |
191 | 606 char *name() { |
4585 | 607 return _("Message Notification"); |
191 | 608 } |
609 | |
610 char *description() { | |
4585 | 611 return _("Provides a variety of ways of notifying you of unread messages."); |
191 | 612 } |
3374 | 613 |
3565 | 614 GtkWidget *gaim_plugin_config_gtk() { |
615 GtkWidget *ret; | |
616 GtkWidget *vbox, *hbox; | |
4035 | 617 GtkWidget *toggle, *button; |
3565 | 618 ret = gtk_vbox_new(FALSE, 18); |
619 gtk_container_set_border_width (GTK_CONTAINER (ret), 12); | |
3392 | 620 |
3710 | 621 vbox = make_frame(ret, _("Notify For")); |
622 toggle = gtk_check_button_new_with_mnemonic(_("_IM windows")); | |
623 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
624 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), type & TYPE_IM); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
625 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(8)); |
3710 | 626 |
627 toggle = gtk_check_button_new_with_mnemonic(_("_Chat windows")); | |
628 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
629 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), type & TYPE_CHAT); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
630 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(9)); |
3710 | 631 |
632 /*--------------*/ | |
3565 | 633 vbox = make_frame(ret, _("Notification Methods")); |
634 hbox = gtk_hbox_new(FALSE, 18); | |
635 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
636 toggle = gtk_check_button_new_with_mnemonic(_("Prepend _string into window title (hit enter to save):")); |
3565 | 637 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), method & METHOD_STRING); |
4035 | 638 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(3)); |
3565 | 639 gtk_box_pack_start(GTK_BOX(hbox), toggle, FALSE, FALSE, 0); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
640 Entry = gtk_entry_new(); |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
641 gtk_entry_set_max_length(GTK_ENTRY(Entry), 10); |
3565 | 642 gtk_widget_set_sensitive(GTK_WIDGET(Entry), method & METHOD_STRING); |
643 gtk_box_pack_start(GTK_BOX(hbox), Entry, FALSE, FALSE, 0); | |
3392 | 644 gtk_entry_set_text(GTK_ENTRY(Entry), title_string); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
645 g_signal_connect(G_OBJECT(Entry), "activate", G_CALLBACK(options), GINT_TO_POINTER(10)); |
3374 | 646 |
3710 | 647 toggle = gtk_check_button_new_with_mnemonic(_("_Quote window title")); |
3565 | 648 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
649 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), method & METHOD_QUOTE); | |
4035 | 650 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(4)); |
3374 | 651 |
3565 | 652 toggle = gtk_check_button_new_with_mnemonic(_("Set Window Manager \"_URGENT\" Hint")); |
653 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
654 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), method & METHOD_URGENT); | |
4035 | 655 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(5)); |
656 | |
3710 | 657 toggle = gtk_check_button_new_with_mnemonic(_("Insert c_ount of new messages into window title")); |
3565 | 658 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), method & METHOD_COUNT); |
659 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
4035 | 660 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(7)); |
3710 | 661 |
662 toggle = gtk_check_button_new_with_mnemonic(_("_Notify even if conversation is in focus")); | |
663 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_IN_FOCUS); | |
664 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
4035 | 665 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(6)); |
3392 | 666 |
3565 | 667 /*--------------*/ |
668 vbox = make_frame(ret, _("Notification Removal")); | |
3710 | 669 toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window gains _focus")); |
3565 | 670 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
671 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_FOCUS); | |
4035 | 672 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(0)); |
3374 | 673 |
3710 | 674 toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window _receives click")); |
675 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
676 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_CLICK); | |
4035 | 677 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(1)); |
3710 | 678 |
3565 | 679 toggle = gtk_check_button_new_with_mnemonic(_("Remove when _typing in conversation window")); |
680 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
681 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_TYPE); | |
4035 | 682 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options), GINT_TO_POINTER(2)); |
683 | |
684 button = gtk_button_new_with_mnemonic(_("Appl_y")); | |
685 gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 5); | |
686 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(apply_options), NULL); | |
3565 | 687 |
688 gtk_widget_show_all(ret); | |
689 return ret; | |
3374 | 690 } |