Mercurial > pidgin
annotate plugins/notify.c @ 6365:72bbe310ac77
[gaim-migrate @ 6870]
delete buddies when we delete an account (thanks Vann) and clean up
some compiler warnings in the irc code (thanks Paco-Paco)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Mon, 04 Aug 2003 17:44:19 +0000 |
parents | dd2be7cd66df |
children | 8f94cce8faa5 |
rev | line source |
---|---|
6302 | 1 /* |
2 * Gaim buddy notification plugin. | |
3 * | |
4 * Copyright (C) 2000-2001, Eric Warmenhoven (original code) | |
5 * Copyright (C) 2002, Etan Reisner <deryni@eden.rutgers.edu> (rewritten code) | |
6 * Copyright (C) 2003, Christian Hammond (update for changed API) | |
6322 | 7 * Copyright (C) 2003, Brian Tarricone <bjt23@cornell.edu> (mostly rewritten) |
6302 | 8 * Copyright (C) 2003, Mark Doliner (minor cleanup) |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
3374 | 19 * |
6302 | 20 * You should have received a copy of the GNU General Public License |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 * | |
24 */ | |
25 | |
26 /* | |
27 * From Etan, 2002: | |
28 * -Added config dialog | |
29 * -Added control over notification method | |
30 * -Added control over when to release notification | |
31 * | |
32 * -Added option to get notification for chats also | |
33 * -Cleaned up code | |
34 * -Added option to notify on click as it's own option | |
35 * rather then as what happens when on focus isn't clicked | |
36 * -Added apply button to change the denotification methods for | |
37 * open conversation windows | |
38 * -Fixed apply to conversations, count now keeps count across applies | |
39 * -Fixed(?) memory leak, and in the process fixed some stupidities | |
40 * -Hit enter when done editing the title string entry box to save it | |
3392 | 41 * |
42 * Thanks to Carles Pina i Estany <carles@pinux.info> | |
43 * for count of new messages option | |
6302 | 44 * |
45 * From Brian, 20 July 2003: | |
46 * -Use new xml prefs | |
47 * -Better handling of notification states tracking | |
48 * -Better pref change handling | |
49 * -Fixed a possible memleak and possible crash (rare) | |
50 * -Use gtk_window_get_title() rather than gtkwin->title | |
51 * -Other random fixes and cleanups | |
3392 | 52 */ |
53 | |
6302 | 54 #include "internal.h" |
55 | |
56 #include "conversation.h" | |
57 #include "debug.h" | |
58 #include "notify.h" | |
59 #include "prefs.h" | |
4202
59751fe608c5
[gaim-migrate @ 4438]
Christian Hammond <chipx86@chipx86.com>
parents:
4165
diff
changeset
|
60 |
6302 | 61 #include "gtkconv.h" |
62 #include "gtkplugin.h" | |
63 #include "gtkutils.h" | |
64 | |
65 | |
66 #include "gtkplugin.h" | |
67 | |
3428 | 68 #include <string.h> |
69 #include <ctype.h> | |
70 #include <stdlib.h> | |
191 | 71 #include <gtk/gtk.h> |
3385 | 72 #include <X11/Xlib.h> |
3374 | 73 #include <X11/Xutil.h> |
3392 | 74 #include <X11/Xatom.h> |
3374 | 75 #include <gdk/gdkx.h> |
6302 | 76 #include <glib.h> |
3374 | 77 |
6302 | 78 #define NOTIFY_PLUGIN_ID "gtk-x11-notify" |
3710 | 79 |
6302 | 80 #define OPT_TYPE_IM ((guint)0x00000001) |
81 #define OPT_TYPE_CHAT ((guint)0x00000002) | |
82 #define OPT_NOTIFY_FOCUS ((guint)0x00000004) | |
83 #define OPT_NOTIFY_TYPE ((guint)0x00000008) | |
84 #define OPT_NOTIFY_IN_FOCUS ((guint)0x00000010) | |
85 #define OPT_NOTIFY_CLICK ((guint)0x00000020) | |
86 #define OPT_METHOD_STRING ((guint)0x00000040) | |
87 #define OPT_METHOD_QUOTE ((guint)0x00000080) | |
88 #define OPT_METHOD_URGENT ((guint)0x00000100) | |
89 #define OPT_METHOD_COUNT ((guint)0x00000200) | |
90 #define OPT_METHOD_STRING_CHNG ((guint)0x00000400) | |
91 #define STATE_IS_NOTIFIED ((guint)0x80000000) | |
3374 | 92 |
6302 | 93 #define TITLE_STR_BUFSIZE 256 |
94 | |
95 #define GDATASTR "notify-plugin-opts" | |
96 #define GDATASTRCNT "notify-plugin-count" | |
191 | 97 |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
98 static GaimPlugin *my_plugin = NULL; |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
99 |
6302 | 100 static guint notify_opts = 0; |
101 static gchar title_string[TITLE_STR_BUFSIZE+1]; | |
102 | |
103 /* notification set/unset */ | |
104 static int notify(GaimConversation *c); | |
105 static void unnotify(GaimConversation *c); | |
106 static int unnotify_cb(GtkWidget *widget, gpointer data); | |
107 | |
108 /* gtk widget callbacks for prefs panel */ | |
109 static void options_toggle_cb(GtkWidget *widget, gpointer data); | |
110 static gboolean options_settitle_cb(GtkWidget *w, GdkEventFocus *evt, GtkWidget *entry); | |
111 static void options_toggle_title_cb(GtkWidget *w, GtkWidget *entry); | |
112 static void apply_options(int opt_chng); | |
113 | |
114 /* string functions */ | |
115 static void string_add(GtkWidget *widget); | |
116 static void string_remove(GtkWidget *widget); | |
191 | 117 |
4035 | 118 /* count functions */ |
6302 | 119 static void count_add(GtkWidget *widget); |
120 static void count_remove(GtkWidget *widget); | |
121 | |
4035 | 122 /* quote functions */ |
6302 | 123 static void quote_add(GtkWidget *widget); |
124 static void quote_remove(GtkWidget *widget); | |
125 | |
4035 | 126 /* urgent functions */ |
6302 | 127 static void urgent_add(GaimConversation *c); |
128 static void urgent_remove(GaimConversation *c); | |
3710 | 129 |
6302 | 130 /****************************************/ |
131 /* Begin doing stuff below this line... */ | |
132 /****************************************/ | |
133 | |
134 static int notify(GaimConversation *c) { | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
135 GaimGtkWindow *gtkwin; |
3710 | 136 Window focus_return; |
4035 | 137 int revert_to_return; |
6302 | 138 guint opts; |
139 gint count; | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
140 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
141 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5021 | 142 |
6302 | 143 /* increment message counter */ |
144 count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtkwin->window), GDATASTRCNT)); | |
145 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTRCNT, GINT_TO_POINTER(count+1)); | |
146 | |
147 /* if we aren't doing notifications for this type of convo, bail */ | |
148 if (((gaim_conversation_get_type(c) == GAIM_CONV_IM) && !(notify_opts & OPT_TYPE_IM)) || | |
149 ((gaim_conversation_get_type(c) == GAIM_CONV_CHAT) && !(notify_opts & OPT_TYPE_CHAT))) | |
150 return 0; | |
151 | |
152 XGetInputFocus(GDK_WINDOW_XDISPLAY(gtkwin->window->window), &focus_return, &revert_to_return); | |
5021 | 153 |
6302 | 154 if ((notify_opts & OPT_NOTIFY_IN_FOCUS) || |
155 (focus_return != GDK_WINDOW_XWINDOW(gtkwin->window->window))) { | |
156 if (notify_opts & OPT_METHOD_STRING) | |
157 string_add(gtkwin->window); | |
158 if (notify_opts & OPT_METHOD_COUNT) | |
159 count_add(gtkwin->window); | |
160 if (notify_opts & OPT_METHOD_QUOTE) | |
161 quote_add(gtkwin->window); | |
162 if (notify_opts & OPT_METHOD_URGENT) | |
163 urgent_add(c); | |
164 } | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
165 |
6302 | 166 opts = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtkwin->window), GDATASTR)); |
167 opts |= STATE_IS_NOTIFIED; | |
168 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTR, GINT_TO_POINTER(opts)); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
169 |
6302 | 170 return 0; |
3374 | 171 } |
172 | |
6302 | 173 static void unnotify(GaimConversation *c) { |
174 GaimGtkWindow *gtkwin; | |
175 | |
176 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); | |
177 | |
178 urgent_remove(c); | |
179 quote_remove(GTK_WIDGET(gtkwin->window)); | |
180 count_remove(GTK_WIDGET(gtkwin->window)); | |
181 string_remove(GTK_WIDGET(gtkwin->window)); | |
182 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTR, GINT_TO_POINTER((guint)0)); | |
183 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTRCNT, GINT_TO_POINTER((guint)0)); | |
184 } | |
185 | |
186 static int unnotify_cb(GtkWidget *widget, gpointer data) { | |
187 GaimConversation *c = g_object_get_data(G_OBJECT(widget), "user_data"); | |
188 | |
189 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "in unnotify_cb()\n"); | |
190 | |
191 if (c) | |
192 urgent_remove(c); | |
193 quote_remove(widget); | |
194 count_remove(widget); | |
195 string_remove(widget); | |
196 g_object_set_data(G_OBJECT(widget), GDATASTR, GINT_TO_POINTER((guint)0)); | |
197 g_object_set_data(G_OBJECT(widget), GDATASTRCNT, GINT_TO_POINTER((guint)0)); | |
198 | |
199 return 0; | |
200 } | |
201 | |
202 static void chat_recv_im(GaimConnection *gc, int id, char **who, char **text) { | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
203 GaimConversation *c = gaim_find_chat(gc, id); |
3710 | 204 |
6302 | 205 if (c) |
3710 | 206 notify(c); |
207 return; | |
208 } | |
209 | |
6302 | 210 static void chat_sent_im(GaimConnection *gc, int id, char **text) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
211 GaimConversation *c = gaim_find_chat(gc, id); |
3710 | 212 |
6302 | 213 if (c) |
214 unnotify(c); | |
3710 | 215 return; |
216 } | |
217 | |
6302 | 218 static int im_recv_im(GaimConnection *gc, char **who, char **what, void *m) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
219 GaimConversation *c = gaim_find_conversation(*who); |
3710 | 220 |
6302 | 221 if (c) |
3710 | 222 notify(c); |
223 return 0; | |
224 } | |
225 | |
6302 | 226 static int im_sent_im(GaimConnection *gc, char *who, char **what, void *m) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
227 GaimConversation *c = gaim_find_conversation(who); |
3374 | 228 |
6302 | 229 if (c) |
230 unnotify(c); | |
3710 | 231 return 0; |
232 } | |
3392 | 233 |
6302 | 234 static int attach_signals(GaimConversation *c) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
235 GaimGtkConversation *gtkconv; |
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
236 GaimGtkWindow *gtkwin; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
237 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
238 gtkconv = GAIM_GTK_CONVERSATION(c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
239 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
240 |
6302 | 241 if (notify_opts & OPT_NOTIFY_FOCUS) { |
242 g_signal_connect(G_OBJECT(gtkwin->window), "focus-in-event", G_CALLBACK(unnotify_cb), NULL); | |
3374 | 243 } |
3710 | 244 |
6302 | 245 if (notify_opts & OPT_NOTIFY_CLICK) { |
246 g_signal_connect(G_OBJECT(gtkwin->window), "button_press_event", G_CALLBACK(unnotify_cb), NULL); | |
247 g_signal_connect_swapped(G_OBJECT(gtkconv->imhtml), "button_press_event", G_CALLBACK(unnotify_cb), G_OBJECT(gtkwin->window)); | |
248 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "button_press_event", G_CALLBACK(unnotify_cb), G_OBJECT(gtkwin->window)); | |
3374 | 249 } |
250 | |
6302 | 251 if (notify_opts & OPT_NOTIFY_TYPE) { |
252 g_signal_connect_swapped(G_OBJECT(gtkconv->entry), "key-press-event", G_CALLBACK(unnotify_cb), G_OBJECT(gtkwin->window)); | |
191 | 253 } |
4035 | 254 |
3428 | 255 return 0; |
191 | 256 } |
257 | |
6302 | 258 static void detach_signals(GaimConversation *c) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
259 GaimGtkConversation *gtkconv; |
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
260 GaimGtkWindow *gtkwin; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
261 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
262 gtkconv = GAIM_GTK_CONVERSATION(c); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
263 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
264 |
6302 | 265 if (notify_opts & OPT_NOTIFY_FOCUS) { |
266 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), unnotify_cb, NULL); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
267 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
268 |
6302 | 269 if (notify_opts & OPT_NOTIFY_CLICK) { |
270 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), unnotify_cb, NULL); | |
271 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->imhtml), unnotify_cb, gtkwin->window); | |
272 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry), unnotify_cb, gtkwin->window); | |
273 } | |
274 | |
275 if (notify_opts & OPT_NOTIFY_TYPE) { | |
276 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry), unnotify_cb, gtkwin->window); | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
277 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
278 } |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
279 |
6302 | 280 static void new_conv(char *who) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
281 GaimConversation *c = gaim_find_conversation(who); |
6302 | 282 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
3710 | 283 |
6302 | 284 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTR, GINT_TO_POINTER((guint)0)); |
285 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTRCNT, GINT_TO_POINTER((guint)0)); | |
286 | |
287 if (c && (notify_opts & OPT_TYPE_IM)) | |
3710 | 288 attach_signals(c); |
289 } | |
290 | |
6302 | 291 static void chat_join(GaimConnection *gc, int id, char *room) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
292 GaimConversation *c = gaim_find_chat(gc, id); |
6302 | 293 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
3710 | 294 |
6302 | 295 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTR, GINT_TO_POINTER((guint)0)); |
296 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTRCNT, GINT_TO_POINTER((guint)0)); | |
297 | |
298 if (c && (notify_opts & OPT_TYPE_CHAT)) | |
3710 | 299 attach_signals(c); |
300 } | |
301 | |
6302 | 302 static void string_add(GtkWidget *widget) { |
303 GtkWindow *win = GTK_WINDOW(widget); | |
304 gchar newtitle[256]; | |
305 const gchar *curtitle = gtk_window_get_title(win); | |
306 guint opts = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), GDATASTR)); | |
307 | |
308 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "string_add(): opts=0x%04x\n", opts); | |
309 | |
310 if (opts & OPT_METHOD_STRING) | |
311 return; | |
3374 | 312 |
6302 | 313 if (!strstr(curtitle, title_string)) { |
314 if (opts & OPT_METHOD_COUNT) { | |
315 char *p = strchr(curtitle, ']'); | |
316 int len1; | |
317 if (!p) | |
318 return; | |
319 len1 = p-curtitle+2; | |
320 memcpy(newtitle, curtitle, len1); | |
321 strncpy(newtitle+len1, title_string, sizeof(newtitle)-len1); | |
322 strncpy(newtitle+len1+strlen(title_string), curtitle+len1, | |
323 sizeof(newtitle)-len1-strlen(title_string)); | |
324 } else if (opts & OPT_METHOD_QUOTE) { | |
325 g_snprintf(newtitle, sizeof(newtitle), "\"%s%s", title_string, curtitle+1); | |
326 } else { | |
327 g_snprintf(newtitle, sizeof(newtitle), "%s%s", title_string, curtitle); | |
328 } | |
329 gtk_window_set_title(win, newtitle); | |
330 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "added string to window title\n"); | |
331 } | |
332 | |
333 opts |= OPT_METHOD_STRING; | |
334 g_object_set_data(G_OBJECT(widget), GDATASTR, GINT_TO_POINTER(opts)); | |
3374 | 335 } |
336 | |
6302 | 337 static void string_remove(GtkWidget *widget) { |
338 GtkWindow *win = GTK_WINDOW(widget); | |
339 gchar newtitle[256]; | |
340 const gchar *curtitle; | |
341 guint opts = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), GDATASTR)); | |
3392 | 342 |
6302 | 343 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "string_remove(): opts=0x%04x\n", opts); |
4035 | 344 |
6302 | 345 if (!(opts & OPT_METHOD_STRING)) |
346 return; | |
347 | |
348 curtitle = gtk_window_get_title(win); | |
3392 | 349 |
6302 | 350 if (strstr(curtitle, title_string)) { |
351 if (opts & OPT_METHOD_COUNT) { | |
352 char *p = strchr(curtitle, ']'); | |
353 int len1; | |
354 if (!p) | |
355 return; | |
356 len1 = p-curtitle+2; | |
357 memcpy(newtitle, curtitle, len1); | |
358 strncpy(newtitle+len1, curtitle+len1+strlen(title_string), sizeof(newtitle)-len1); | |
359 } else if (opts & OPT_METHOD_QUOTE) { | |
360 g_snprintf(newtitle, sizeof(newtitle), "\"%s", curtitle+strlen(title_string)+1); | |
361 } else | |
362 strncpy(newtitle, curtitle+strlen(title_string), sizeof(newtitle)); | |
363 } | |
364 | |
365 gtk_window_set_title(win, newtitle); | |
366 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "removed string from window title (title now %s)\n", newtitle); | |
3374 | 367 } |
368 | |
6302 | 369 static void count_add(GtkWidget *widget) { |
4035 | 370 GtkWindow *win = GTK_WINDOW(widget); |
6302 | 371 char newtitle[256]; |
372 const gchar *curtitle; | |
373 guint opts = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), GDATASTR)); | |
374 gint curcount = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), GDATASTRCNT)); | |
4035 | 375 |
6302 | 376 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "count_add(): opts=0x%04x\n", opts); |
377 | |
378 if (curcount>0 && (opts & OPT_METHOD_COUNT)) | |
379 count_remove(widget); | |
5021 | 380 |
6302 | 381 curtitle = gtk_window_get_title(win); |
382 if (opts & OPT_METHOD_QUOTE) | |
383 g_snprintf(newtitle, sizeof(newtitle), "\"[%d] %s", curcount, curtitle+1); | |
384 else | |
385 g_snprintf(newtitle, sizeof(newtitle), "[%d] %s", curcount, curtitle); | |
386 gtk_window_set_title(win, newtitle); | |
387 | |
388 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "added count of %d to window\n", curcount); | |
389 | |
390 opts |= OPT_METHOD_COUNT; | |
391 g_object_set_data(G_OBJECT(widget), GDATASTR, GINT_TO_POINTER(opts)); | |
4035 | 392 } |
393 | |
6302 | 394 static void count_remove(GtkWidget *widget) { |
3392 | 395 GtkWindow *win = GTK_WINDOW(widget); |
6302 | 396 char newtitle[256], *p; |
397 const gchar *curtitle; | |
398 guint opts = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), GDATASTR)); | |
399 | |
400 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "count_remove(): opts=0x%04x\n", opts); | |
401 | |
402 if (!(opts & OPT_METHOD_COUNT)) | |
403 return; | |
404 | |
405 curtitle = gtk_window_get_title(win); | |
3392 | 406 |
6302 | 407 p = strchr(curtitle, ']'); |
408 | |
409 if (p) { | |
410 if (opts & OPT_METHOD_QUOTE) | |
411 g_snprintf(newtitle, sizeof(newtitle), "\"%s", p+2); | |
412 else | |
413 g_snprintf(newtitle, sizeof(newtitle), p+2); | |
414 gtk_window_set_title(win, newtitle); | |
415 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "removed count from title (title now %s)\n", newtitle); | |
3392 | 416 } |
6302 | 417 |
418 opts &= ~OPT_METHOD_COUNT; | |
419 g_object_set_data(G_OBJECT(widget), GDATASTR, GINT_TO_POINTER(opts)); | |
3392 | 420 } |
421 | |
6302 | 422 static void quote_add(GtkWidget *widget) { |
4035 | 423 GtkWindow *win = GTK_WINDOW(widget); |
6302 | 424 char newtitle[256]; |
425 const gchar *curtitle = gtk_window_get_title(win); | |
426 guint opts = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), GDATASTR)); | |
427 | |
428 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "quote_add(): opts=0x%04x\n", opts); | |
4035 | 429 |
6302 | 430 if (opts & OPT_METHOD_QUOTE) |
431 return; | |
432 | |
433 if (*curtitle != '\"') { | |
434 g_snprintf(newtitle, sizeof(newtitle), "\"%s\"", curtitle); | |
435 gtk_window_set_title(win, newtitle); | |
436 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "quoted title\n"); | |
4035 | 437 } |
6302 | 438 |
439 opts |= OPT_METHOD_QUOTE; | |
440 g_object_set_data(G_OBJECT(widget), GDATASTR, GINT_TO_POINTER(opts)); | |
4035 | 441 } |
442 | |
6302 | 443 static void quote_remove(GtkWidget *widget) { |
3374 | 444 GtkWindow *win = GTK_WINDOW(widget); |
6302 | 445 char newtitle[512]; |
446 const gchar *curtitle = gtk_window_get_title(win); | |
447 guint opts = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), GDATASTR)); | |
448 | |
449 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "quote_remove(): opts=0x%04x\n", opts); | |
191 | 450 |
6302 | 451 if (!(opts & OPT_METHOD_QUOTE)) |
452 return; | |
453 | |
454 if (*curtitle == '\"' && strlen(curtitle)-2<sizeof(newtitle)) { | |
455 memcpy(newtitle, curtitle+1, strlen(curtitle)-2); | |
456 newtitle[strlen(curtitle)-2] = 0; | |
457 gtk_window_set_title(win, newtitle); | |
458 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "removed quotes from title (title now %s)\n", newtitle); | |
459 } | |
460 | |
461 opts &= ~OPT_METHOD_QUOTE; | |
462 g_object_set_data(G_OBJECT(widget), GDATASTR, GINT_TO_POINTER(opts)); | |
3374 | 463 } |
464 | |
6302 | 465 static void urgent_add(GaimConversation *c) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
466 GaimGtkWindow *gtkwin; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
467 XWMHints *hints; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
468 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
469 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
470 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
471 hints = XGetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window)); |
4035 | 472 hints->flags |= XUrgencyHint; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
473 XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints); |
4218 | 474 XFree(hints); |
4035 | 475 } |
476 | |
6302 | 477 static void urgent_remove(GaimConversation *c) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
478 GaimGtkConversation *gtkconv; |
6302 | 479 const char *convo_placement = gaim_prefs_get_string("/core/conversations/placement"); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
480 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
481 gtkconv = GAIM_GTK_CONVERSATION(c); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
482 |
6302 | 483 if (!strcmp(convo_placement, "new")) { |
484 GaimGtkWindow *gtkwin; | |
485 XWMHints *hints; | |
486 | |
487 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); | |
488 hints = XGetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window)); | |
489 | |
490 if (hints->flags & XUrgencyHint) { | |
491 hints->flags &= ~XUrgencyHint; | |
492 XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints); | |
493 } | |
494 XFree(hints); | |
495 } else { | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
496 if (gaim_conversation_get_type(c) == GAIM_CONV_CHAT) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
497 GaimConversation *c = (GaimConversation *)gaim_get_chats()->data; |
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
498 GaimGtkWindow *gtkwin; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
499 GdkWindow *win; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
500 XWMHints *hints; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
501 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
502 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
503 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
504 win = gtkwin->window->window; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
505 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
506 hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win), GDK_WINDOW_XWINDOW(win)); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
507 if (hints->flags & XUrgencyHint) { |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
508 hints->flags &= ~XUrgencyHint; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
509 XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
510 } |
4218 | 511 XFree(hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
512 } else { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
513 GaimConversation *c; |
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
514 GaimGtkWindow *gtkwin; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
515 GdkWindow *win; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
516 XWMHints *hints; |
3374 | 517 |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5530
diff
changeset
|
518 c = (GaimConversation *)gaim_get_ims()->data; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
519 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
520 win = gtkwin->window->window; |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
521 |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
522 hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win), GDK_WINDOW_XWINDOW(win)); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
523 if (hints->flags & XUrgencyHint) { |
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
524 hints->flags &= ~XUrgencyHint; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
525 XSetWMHints(GDK_WINDOW_XDISPLAY(gtkwin->window->window), GDK_WINDOW_XWINDOW(gtkwin->window->window), hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
526 } |
4218 | 527 XFree(hints); |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
528 } |
4035 | 529 } |
3374 | 530 } |
531 | |
6302 | 532 static void save_notify_prefs() { |
533 gaim_prefs_set_bool("/plugins/gtk/X11/notify/notify_im", notify_opts & OPT_TYPE_IM); | |
534 gaim_prefs_set_bool("/plugins/gtk/X11/notify/notify_chat", notify_opts & OPT_TYPE_CHAT); | |
535 gaim_prefs_set_bool("/plugins/gtk/X11/notify/notify_in_focus", notify_opts & OPT_NOTIFY_IN_FOCUS); | |
536 gaim_prefs_set_bool("/plugins/gtk/X11/notify/notify_focus", notify_opts & OPT_NOTIFY_FOCUS); | |
537 gaim_prefs_set_bool("/plugins/gtk/X11/notify/notify_click", notify_opts & OPT_NOTIFY_CLICK); | |
538 gaim_prefs_set_bool("/plugins/gtk/X11/notify/notify_type", notify_opts & OPT_NOTIFY_TYPE); | |
539 gaim_prefs_set_bool("/plugins/gtk/X11/notify/method_string", notify_opts & OPT_METHOD_STRING); | |
540 gaim_prefs_set_bool("/plugins/gtk/X11/notify/method_quote", notify_opts & OPT_METHOD_QUOTE); | |
541 gaim_prefs_set_bool("/plugins/gtk/X11/notify/method_urgent", notify_opts & OPT_METHOD_URGENT); | |
542 gaim_prefs_set_bool("/plugins/gtk/X11/notify/method_count", notify_opts & OPT_METHOD_COUNT); | |
3374 | 543 |
6302 | 544 gaim_prefs_set_string("/plugins/gtk/X11/notify/title_string", title_string); |
3374 | 545 } |
546 | |
6302 | 547 static void load_notify_prefs() { |
548 notify_opts = 0; | |
549 | |
550 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_im") ? OPT_TYPE_IM : 0); | |
551 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_chat") ? OPT_TYPE_CHAT : 0); | |
552 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_in_focus") ? OPT_NOTIFY_IN_FOCUS : 0); | |
553 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_focus") ? OPT_NOTIFY_FOCUS : 0); | |
554 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_click") ? OPT_NOTIFY_CLICK : 0); | |
555 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_type") ? OPT_NOTIFY_TYPE : 0); | |
556 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_string") ? OPT_METHOD_STRING : 0); | |
557 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_quote") ? OPT_METHOD_QUOTE : 0); | |
558 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_urgent") ? OPT_METHOD_URGENT : 0); | |
559 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_count") ? OPT_METHOD_COUNT : 0); | |
3374 | 560 |
6302 | 561 strncpy(title_string, gaim_prefs_get_string("/plugins/gtk/X11/notify/title_string"), TITLE_STR_BUFSIZE); |
3374 | 562 } |
563 | |
6302 | 564 static void options_toggle_cb(GtkWidget *w, gpointer data) { |
4035 | 565 gint option = GPOINTER_TO_INT(data); |
3374 | 566 |
6302 | 567 notify_opts ^= option; |
568 | |
569 /* save prefs and re-notify the windows */ | |
570 save_notify_prefs(); | |
571 apply_options(option); | |
572 } | |
573 | |
574 static gboolean options_settitle_cb(GtkWidget *w, GdkEventFocus *evt, GtkWidget *entry) { | |
575 GList *cnv = gaim_get_conversations(); | |
576 | |
577 /* first we have to kill all the old strings */ | |
578 while (cnv) { | |
579 GaimConversation *c = (GaimConversation *)cnv->data; | |
580 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); | |
581 string_remove(gtkwin->window); | |
582 cnv = cnv->next; | |
3374 | 583 } |
6302 | 584 |
585 g_snprintf(title_string, sizeof(title_string), gtk_entry_get_text(GTK_ENTRY(entry))); | |
586 | |
587 /* save prefs and re-notify the windows */ | |
588 save_notify_prefs(); | |
589 apply_options(OPT_METHOD_STRING_CHNG); | |
590 | |
591 return FALSE; | |
592 } | |
593 | |
594 static void options_toggle_title_cb(GtkWidget *w, GtkWidget *entry) { | |
595 notify_opts ^= OPT_METHOD_STRING; | |
596 | |
597 if (notify_opts & OPT_METHOD_STRING) | |
598 gtk_widget_set_sensitive(entry, TRUE); | |
599 else | |
600 gtk_widget_set_sensitive(entry, FALSE); | |
3710 | 601 |
602 save_notify_prefs(); | |
6302 | 603 apply_options(OPT_METHOD_STRING); |
3374 | 604 } |
605 | |
6302 | 606 static void apply_options(int opt_chng) { |
4376
2c985a9e994c
[gaim-migrate @ 4642]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
607 GList *cnv = gaim_get_conversations(); |
4035 | 608 |
6302 | 609 /* option-setting handlers should have cleared out all window notifications */ |
610 | |
4035 | 611 while (cnv) { |
6302 | 612 GaimConversation *c = (GaimConversation *)cnv->data; |
613 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); | |
614 guint opts = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtkwin->window), GDATASTR)); | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4218
diff
changeset
|
615 |
6302 | 616 /* kill signals */ |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
617 detach_signals(c); |
4035 | 618 |
6302 | 619 /* |
620 * do a full notify if the option that changed was an OPT_TYPE_* | |
621 * either notify if it was enabled, or unnotify if it was disabled | |
622 */ | |
623 if (opt_chng==OPT_TYPE_IM || opt_chng==OPT_TYPE_CHAT) { | |
624 if ((gaim_conversation_get_type(c)==GAIM_CONV_IM && (notify_opts & OPT_TYPE_IM)) || | |
625 (gaim_conversation_get_type(c)==GAIM_CONV_CHAT && (notify_opts & OPT_TYPE_CHAT))) { | |
626 Window focus_return; | |
627 int revert_to_return; | |
628 | |
629 XGetInputFocus(GDK_WINDOW_XDISPLAY(gtkwin->window->window), | |
630 &focus_return, &revert_to_return); | |
631 if ((notify_opts & OPT_NOTIFY_IN_FOCUS) || | |
632 focus_return != GDK_WINDOW_XWINDOW(gtkwin->window->window)) { | |
633 if (notify_opts & OPT_METHOD_STRING) | |
634 string_add(gtkwin->window); | |
635 if (notify_opts & OPT_METHOD_COUNT) | |
636 count_add(gtkwin->window); | |
637 if (notify_opts & OPT_METHOD_QUOTE) | |
638 quote_add(gtkwin->window); | |
639 if (notify_opts & OPT_METHOD_URGENT) | |
640 urgent_add(c); | |
641 } | |
642 } else { | |
643 //don't simply call unnotify(), because that will kill the msg counter | |
644 urgent_remove(c); | |
645 quote_remove(gtkwin->window); | |
646 count_remove(gtkwin->window); | |
647 string_remove(gtkwin->window); | |
648 } | |
649 } else if (opts & STATE_IS_NOTIFIED) { | |
650 //add/remove the status that was changed | |
651 switch(opt_chng) { | |
652 case OPT_METHOD_COUNT: | |
653 if (notify_opts & OPT_METHOD_COUNT) | |
654 count_add(gtkwin->window); | |
655 else | |
656 count_remove(gtkwin->window); | |
657 break; | |
658 case OPT_METHOD_QUOTE: | |
659 if (notify_opts & OPT_METHOD_QUOTE) | |
660 quote_add(gtkwin->window); | |
661 else | |
662 quote_remove(gtkwin->window); | |
663 break; | |
664 case OPT_METHOD_STRING: | |
665 if (notify_opts & OPT_METHOD_STRING) | |
666 string_add(gtkwin->window); | |
667 else | |
668 string_remove(gtkwin->window); | |
669 break; | |
670 case OPT_METHOD_URGENT: | |
671 if (notify_opts & OPT_METHOD_URGENT) | |
672 urgent_add(c); | |
673 else | |
674 urgent_remove(c); | |
675 break; | |
676 case OPT_METHOD_STRING_CHNG: | |
677 string_add(gtkwin->window); | |
678 break; | |
679 } | |
680 } | |
4203
ec6d0c5e5c23
[gaim-migrate @ 4439]
Christian Hammond <chipx86@chipx86.com>
parents:
4202
diff
changeset
|
681 |
4035 | 682 /* attach new unnotification signals */ |
6302 | 683 attach_signals(c); |
4035 | 684 |
6302 | 685 cnv = cnv->next; |
4035 | 686 } |
687 } | |
688 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
689 static GtkWidget * |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
690 get_config_frame(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
691 { |
3565 | 692 GtkWidget *ret; |
6302 | 693 GtkWidget *frame; |
3565 | 694 GtkWidget *vbox, *hbox; |
6302 | 695 GtkWidget *toggle, *entry; |
696 | |
3565 | 697 ret = gtk_vbox_new(FALSE, 18); |
6302 | 698 gtk_container_set_border_width(GTK_CONTAINER (ret), 12); |
3392 | 699 |
6302 | 700 /*---------- "Notify For" ----------*/ |
701 frame = gaim_gtk_make_frame(ret, _("Notify For")); | |
702 vbox = gtk_vbox_new(FALSE, 5); | |
703 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
704 | |
3710 | 705 toggle = gtk_check_button_new_with_mnemonic(_("_IM windows")); |
706 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
6302 | 707 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_TYPE_IM); |
708 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_TYPE_IM)); | |
3710 | 709 |
710 toggle = gtk_check_button_new_with_mnemonic(_("_Chat windows")); | |
711 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
6302 | 712 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_TYPE_CHAT); |
713 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_TYPE_CHAT)); | |
3710 | 714 |
6302 | 715 /*---------- "Notification Methods" ----------*/ |
716 frame = gaim_gtk_make_frame(ret, _("Notification Methods")); | |
717 vbox = gtk_vbox_new(FALSE, 5); | |
718 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
719 | |
3565 | 720 hbox = gtk_hbox_new(FALSE, 18); |
721 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
6302 | 722 toggle = gtk_check_button_new_with_mnemonic(_("Prepend _string into window title:")); |
723 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_METHOD_STRING); | |
3565 | 724 gtk_box_pack_start(GTK_BOX(hbox), toggle, FALSE, FALSE, 0); |
6302 | 725 entry = gtk_entry_new(); |
726 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
727 gtk_entry_set_max_length(GTK_ENTRY(entry), 10); | |
728 gtk_widget_set_sensitive(GTK_WIDGET(entry), notify_opts & OPT_METHOD_STRING); | |
729 gtk_entry_set_text(GTK_ENTRY(entry), title_string); | |
730 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_title_cb), entry); | |
731 g_signal_connect(G_OBJECT(entry), "focus-out-event", G_CALLBACK(options_settitle_cb), entry); | |
3374 | 732 |
6302 | 733 toggle = gtk_check_button_new_with_mnemonic(_("_Quote window title")); |
734 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
735 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_METHOD_QUOTE); | |
736 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_METHOD_QUOTE)); | |
3374 | 737 |
6302 | 738 toggle = gtk_check_button_new_with_mnemonic(_("Set Window Manager \"_URGENT\" Hint")); |
739 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
740 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_METHOD_URGENT); | |
741 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_METHOD_URGENT)); | |
4035 | 742 |
6302 | 743 toggle = gtk_check_button_new_with_mnemonic(_("Insert c_ount of new messages into window title")); |
744 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_METHOD_COUNT); | |
745 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
746 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_METHOD_COUNT)); | |
3710 | 747 |
6302 | 748 toggle = gtk_check_button_new_with_mnemonic(_("_Notify even if conversation is in focus")); |
749 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_NOTIFY_IN_FOCUS); | |
750 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
751 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_NOTIFY_IN_FOCUS)); | |
3392 | 752 |
6302 | 753 /*---------- "Notification Methods" ----------*/ |
754 frame = gaim_gtk_make_frame(ret, _("Notification Removal")); | |
755 vbox = gtk_vbox_new(FALSE, 5); | |
756 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
3374 | 757 |
6302 | 758 toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window gains _focus")); |
759 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
760 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_NOTIFY_FOCUS); | |
761 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_NOTIFY_FOCUS)); | |
3710 | 762 |
6302 | 763 toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window _receives click")); |
764 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
765 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_NOTIFY_CLICK); | |
766 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_NOTIFY_CLICK)); | |
4035 | 767 |
6302 | 768 toggle = gtk_check_button_new_with_mnemonic(_("Remove when _typing in conversation window")); |
769 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
770 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), notify_opts & OPT_NOTIFY_TYPE); | |
771 g_signal_connect(G_OBJECT(toggle), "toggled", G_CALLBACK(options_toggle_cb), GINT_TO_POINTER(OPT_NOTIFY_TYPE)); | |
3565 | 772 |
6302 | 773 gtk_widget_show_all(ret); |
774 return ret; | |
3374 | 775 } |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
776 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
777 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
778 plugin_load(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
779 { |
6302 | 780 GList *cnv = gaim_get_conversations(); |
781 | |
782 my_plugin = plugin; | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
783 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
784 load_notify_prefs(); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
785 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
786 gaim_signal_connect(plugin, event_im_recv, im_recv_im, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
787 gaim_signal_connect(plugin, event_chat_recv, chat_recv_im, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
788 gaim_signal_connect(plugin, event_im_send, im_sent_im, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
789 gaim_signal_connect(plugin, event_chat_send, chat_sent_im, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
790 gaim_signal_connect(plugin, event_new_conversation, new_conv, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
791 gaim_signal_connect(plugin, event_chat_join, chat_join, NULL); |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
792 |
6302 | 793 while (cnv) { |
794 GaimConversation *c = (GaimConversation *)cnv->data; | |
795 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); | |
796 | |
797 /* attach signals */ | |
798 attach_signals(c); | |
799 /* zero out data */ | |
800 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTR, GINT_TO_POINTER((guint)0)); | |
801 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTRCNT, GINT_TO_POINTER((guint)0)); | |
802 | |
803 cnv = cnv->next; | |
804 } | |
805 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
806 return TRUE; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
807 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
808 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
809 static gboolean |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
810 plugin_unload(GaimPlugin *plugin) |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
811 { |
6302 | 812 GList *cnv = gaim_get_conversations(); |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
813 |
6302 | 814 while (cnv) { |
815 GaimConversation *c = (GaimConversation *)cnv->data; | |
816 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
817 |
6302 | 818 /* kill signals */ |
819 detach_signals(c); | |
820 /* zero out data */ | |
821 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTR, GINT_TO_POINTER((guint)0)); | |
822 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTRCNT, GINT_TO_POINTER((guint)0)); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
823 |
6302 | 824 cnv = cnv->next; |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
825 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
826 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
827 return TRUE; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
828 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
829 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
830 static GaimGtkPluginUiInfo ui_info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
831 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
832 get_config_frame |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
833 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
834 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
835 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
836 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
837 2, /**< api_version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
838 GAIM_PLUGIN_STANDARD, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
839 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
840 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
841 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
842 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
843 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
844 NOTIFY_PLUGIN_ID, /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
845 N_("Message Notification"), /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
846 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
847 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
848 N_("Provides a variety of ways of notifying you of unread messages."), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
849 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
850 N_("Provides a variety of ways of notifying you of unread messages."), |
6302 | 851 "Etan Reisner <deryni@eden.rutgers.edu>\n\t\t\tBrian Tarricone <bjt23@cornell.edu", |
852 /**< author */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
853 WEBSITE, /**< homepage */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
854 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
855 plugin_load, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
856 plugin_unload, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
857 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
858 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
859 &ui_info, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
860 NULL /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
861 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
862 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
863 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
864 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
865 { |
6302 | 866 gaim_prefs_add_none("/plugins/gtk"); |
867 gaim_prefs_add_none("/plugins/gtk/X11"); | |
868 gaim_prefs_add_none("/plugins/gtk/X11/notify"); | |
869 | |
870 gaim_prefs_add_bool("/plugins/gtk/X11/notify/notify_im", TRUE); | |
871 gaim_prefs_add_bool("/plugins/gtk/X11/notify/notify_chat", FALSE); | |
872 gaim_prefs_add_bool("/plugins/gtk/X11/notify/method_string", FALSE); | |
873 gaim_prefs_add_string("/plugins/gtk/X11/notify/title_string", "(*)"); | |
874 gaim_prefs_add_bool("/plugins/gtk/X11/notify/method_quote", FALSE); | |
875 gaim_prefs_add_bool("/plugins/gtk/X11/notify/method_urgent", FALSE); | |
876 gaim_prefs_add_bool("/plugins/gtk/X11/notify/method_count", FALSE); | |
877 gaim_prefs_add_bool("/plugins/gtk/X11/notify/notify_in_focus", FALSE); | |
878 gaim_prefs_add_bool("/plugins/gtk/X11/notify/notify_focus", FALSE); | |
879 gaim_prefs_add_bool("/plugins/gtk/X11/notify/notify_click", FALSE); | |
880 gaim_prefs_add_bool("/plugins/gtk/X11/notify/notify_type", TRUE); | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
881 } |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5021
diff
changeset
|
882 |
6063 | 883 GAIM_INIT_PLUGIN(notify, init_plugin, info) |