comparison plugins/notify.c @ 6485:70d5122bc3ff

[gaim-migrate @ 6999] Removed the old event system and replaced it with a much better signal system. There will most likely be some bugs in this, but it seems to be working for now. Plugins can now generate their own signals, and other plugins can find those plugins and connect to them. This could give plugins a form of IPC. It's also useful for other things. It's rather flexible, except for the damn marshalling, but there's no way around that that I or the glib people can see. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 18 Aug 2003 01:03:43 +0000
parents 059649ed25ed
children 7230e5920911
comparison
equal deleted inserted replaced
6484:5ced8e111473 6485:70d5122bc3ff
34 * -Added option to notify on click as it's own option 34 * -Added option to notify on click as it's own option
35 * rather then as what happens when on focus isn't clicked 35 * rather then as what happens when on focus isn't clicked
36 * -Added apply button to change the denotification methods for 36 * -Added apply button to change the denotification methods for
37 * open conversation windows 37 * open conversation windows
38 * -Fixed apply to conversations, count now keeps count across applies 38 * -Fixed apply to conversations, count now keeps count across applies
39 * -Fixed(?) memory leak, and in the process fixed some stupidities 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 40 * -Hit enter when done editing the title string entry box to save it
41 * 41 *
42 * Thanks to Carles Pina i Estany <carles@pinux.info> 42 * Thanks to Carles Pina i Estany <carles@pinux.info>
43 * for count of new messages option 43 * for count of new messages option
44 * 44 *
45 * From Brian, 20 July 2003: 45 * From Brian, 20 July 2003:
46 * -Use new xml prefs 46 * -Use new xml prefs
47 * -Better handling of notification states tracking 47 * -Better handling of notification states tracking
48 * -Better pref change handling 48 * -Better pref change handling
49 * -Fixed a possible memleak and possible crash (rare) 49 * -Fixed a possible memleak and possible crash (rare)
55 55
56 #include "conversation.h" 56 #include "conversation.h"
57 #include "debug.h" 57 #include "debug.h"
58 #include "notify.h" 58 #include "notify.h"
59 #include "prefs.h" 59 #include "prefs.h"
60 #include "signals.h"
60 61
61 #include "gtkconv.h" 62 #include "gtkconv.h"
62 #include "gtkplugin.h" 63 #include "gtkplugin.h"
63 #include "gtkutils.h" 64 #include "gtkutils.h"
64
65 65
66 #include "gtkplugin.h" 66 #include "gtkplugin.h"
67 67
68 #include <string.h> 68 #include <string.h>
69 #include <ctype.h> 69 #include <ctype.h>
149 ((gaim_conversation_get_type(c) == GAIM_CONV_CHAT) && !(notify_opts & OPT_TYPE_CHAT))) 149 ((gaim_conversation_get_type(c) == GAIM_CONV_CHAT) && !(notify_opts & OPT_TYPE_CHAT)))
150 return 0; 150 return 0;
151 151
152 XGetInputFocus(GDK_WINDOW_XDISPLAY(gtkwin->window->window), &focus_return, &revert_to_return); 152 XGetInputFocus(GDK_WINDOW_XDISPLAY(gtkwin->window->window), &focus_return, &revert_to_return);
153 153
154 if ((notify_opts & OPT_NOTIFY_IN_FOCUS) || 154 if ((notify_opts & OPT_NOTIFY_IN_FOCUS) ||
155 (focus_return != GDK_WINDOW_XWINDOW(gtkwin->window->window))) { 155 (focus_return != GDK_WINDOW_XWINDOW(gtkwin->window->window))) {
156 if (notify_opts & OPT_METHOD_STRING) 156 if (notify_opts & OPT_METHOD_STRING)
157 string_add(gtkwin->window); 157 string_add(gtkwin->window);
158 if (notify_opts & OPT_METHOD_COUNT) 158 if (notify_opts & OPT_METHOD_COUNT)
159 count_add(gtkwin->window); 159 count_add(gtkwin->window);
197 g_object_set_data(G_OBJECT(widget), GDATASTRCNT, GINT_TO_POINTER((guint)0)); 197 g_object_set_data(G_OBJECT(widget), GDATASTRCNT, GINT_TO_POINTER((guint)0));
198 198
199 return 0; 199 return 0;
200 } 200 }
201 201
202 static void chat_recv_im(GaimConnection *gc, int id, char **who, char **text) { 202 static gboolean
203 GaimConversation *c = gaim_find_chat(gc, id); 203 chat_recv_im(GaimAccount *account, GaimConversation *conv, char **who,
204 204 char **text)
205 if (c) 205 {
206 notify(c); 206 if (conv)
207 return; 207 notify(conv);
208 } 208
209 209 return FALSE;
210 static void chat_sent_im(GaimConnection *gc, int id, char **text) { 210 }
211 GaimConversation *c = gaim_find_chat(gc, id); 211
212 212 static void chat_sent_im(GaimConversation *c, char **text) {
213 if (c) 213 if (c)
214 unnotify(c); 214 unnotify(c);
215 return; 215 }
216 } 216
217 217 static gboolean
218 static int im_recv_im(GaimConnection *gc, char **who, char **what, void *m) { 218 im_recv_im(GaimAccount *account, GaimConversation *conv, char **who,
219 GaimConversation *c = gaim_find_conversation(*who); 219 char **what, int *flags, void *m)
220 220 {
221 if (c) 221 if (conv)
222 notify(c); 222 notify(conv);
223 return 0; 223
224 } 224 return FALSE;
225 225 }
226 static int im_sent_im(GaimConnection *gc, char *who, char **what, void *m) { 226
227 GaimConversation *c = gaim_find_conversation(who); 227 static void im_sent_im(GaimConversation *conv, char **what, void *m) {
228 228 if (conv)
229 if (c) 229 unnotify(conv);
230 unnotify(c);
231 return 0;
232 } 230 }
233 231
234 static int attach_signals(GaimConversation *c) { 232 static int attach_signals(GaimConversation *c) {
235 GaimGtkConversation *gtkconv; 233 GaimGtkConversation *gtkconv;
236 GaimGtkWindow *gtkwin; 234 GaimGtkWindow *gtkwin;
256 } 254 }
257 255
258 static void detach_signals(GaimConversation *c) { 256 static void detach_signals(GaimConversation *c) {
259 GaimGtkConversation *gtkconv; 257 GaimGtkConversation *gtkconv;
260 GaimGtkWindow *gtkwin; 258 GaimGtkWindow *gtkwin;
261 259
262 gtkconv = GAIM_GTK_CONVERSATION(c); 260 gtkconv = GAIM_GTK_CONVERSATION(c);
263 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); 261 gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
264 262
265 if (notify_opts & OPT_NOTIFY_FOCUS) { 263 if (notify_opts & OPT_NOTIFY_FOCUS) {
266 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), unnotify_cb, NULL); 264 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkwin->window), unnotify_cb, NULL);
267 } 265 }
268 266
269 if (notify_opts & OPT_NOTIFY_CLICK) { 267 if (notify_opts & OPT_NOTIFY_CLICK) {
275 if (notify_opts & OPT_NOTIFY_TYPE) { 273 if (notify_opts & OPT_NOTIFY_TYPE) {
276 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry), unnotify_cb, gtkwin->window); 274 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry), unnotify_cb, gtkwin->window);
277 } 275 }
278 } 276 }
279 277
280 static void new_conv(char *who) { 278 static void new_conv(GaimConversation *c)
281 GaimConversation *c = gaim_find_conversation(who); 279 {
282 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); 280 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
283 281
284 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTR, GINT_TO_POINTER((guint)0)); 282 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)); 283 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTRCNT, GINT_TO_POINTER((guint)0));
286 284
287 if (c && (notify_opts & OPT_TYPE_IM)) 285 if (c && (notify_opts & OPT_TYPE_IM))
288 attach_signals(c); 286 attach_signals(c);
289 } 287 }
290 288
291 static void chat_join(GaimConnection *gc, int id, char *room) { 289 static void chat_join(GaimConversation *c) {
292 GaimConversation *c = gaim_find_chat(gc, id);
293 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); 290 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
294 291
295 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTR, GINT_TO_POINTER((guint)0)); 292 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)); 293 g_object_set_data(G_OBJECT(gtkwin->window), GDATASTRCNT, GINT_TO_POINTER((guint)0));
297 294
356 len1 = p-curtitle+2; 353 len1 = p-curtitle+2;
357 memcpy(newtitle, curtitle, len1); 354 memcpy(newtitle, curtitle, len1);
358 strncpy(newtitle+len1, curtitle+len1+strlen(title_string), sizeof(newtitle)-len1); 355 strncpy(newtitle+len1, curtitle+len1+strlen(title_string), sizeof(newtitle)-len1);
359 } else if (opts & OPT_METHOD_QUOTE) { 356 } else if (opts & OPT_METHOD_QUOTE) {
360 g_snprintf(newtitle, sizeof(newtitle), "\"%s", curtitle+strlen(title_string)+1); 357 g_snprintf(newtitle, sizeof(newtitle), "\"%s", curtitle+strlen(title_string)+1);
361 } else 358 } else
362 strncpy(newtitle, curtitle+strlen(title_string), sizeof(newtitle)); 359 strncpy(newtitle, curtitle+strlen(title_string), sizeof(newtitle));
363 } 360 }
364 361
365 gtk_window_set_title(win, newtitle); 362 gtk_window_set_title(win, newtitle);
366 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "removed string from window title (title now %s)\n", newtitle); 363 gaim_debug(GAIM_DEBUG_INFO, "notify.c", "removed string from window title (title now %s)\n", newtitle);
367 } 364 }
368 365
369 static void count_add(GtkWidget *widget) { 366 static void count_add(GtkWidget *widget) {
532 static void save_notify_prefs() { 529 static void save_notify_prefs() {
533 gaim_prefs_set_bool("/plugins/gtk/X11/notify/type_im", notify_opts & OPT_TYPE_IM); 530 gaim_prefs_set_bool("/plugins/gtk/X11/notify/type_im", notify_opts & OPT_TYPE_IM);
534 gaim_prefs_set_bool("/plugins/gtk/X11/notify/type_chat", notify_opts & OPT_TYPE_CHAT); 531 gaim_prefs_set_bool("/plugins/gtk/X11/notify/type_chat", notify_opts & OPT_TYPE_CHAT);
535 gaim_prefs_set_bool("/plugins/gtk/X11/notify/type_focused", notify_opts & OPT_NOTIFY_IN_FOCUS); 532 gaim_prefs_set_bool("/plugins/gtk/X11/notify/type_focused", notify_opts & OPT_NOTIFY_IN_FOCUS);
536 gaim_prefs_set_bool("/plugins/gtk/X11/notify/notify_focus", notify_opts & OPT_NOTIFY_FOCUS); 533 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); 534 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); 535 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); 536 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); 537 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); 538 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); 539 gaim_prefs_set_bool("/plugins/gtk/X11/notify/method_count", notify_opts & OPT_METHOD_COUNT);
544 gaim_prefs_set_string("/plugins/gtk/X11/notify/title_string", title_string); 541 gaim_prefs_set_string("/plugins/gtk/X11/notify/title_string", title_string);
545 } 542 }
546 543
547 static void load_notify_prefs() { 544 static void load_notify_prefs() {
548 notify_opts = 0; 545 notify_opts = 0;
549 546
550 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_im") ? OPT_TYPE_IM : 0); 547 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_im") ? OPT_TYPE_IM : 0);
551 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_chat") ? OPT_TYPE_CHAT : 0); 548 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_chat") ? OPT_TYPE_CHAT : 0);
552 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_focused") ? OPT_NOTIFY_IN_FOCUS : 0); 549 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_focused") ? OPT_NOTIFY_IN_FOCUS : 0);
553 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/notify_focus") ? OPT_NOTIFY_FOCUS : 0); 550 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); 551 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); 552 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); 553 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); 554 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); 555 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); 556 notify_opts |= (gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_count") ? OPT_METHOD_COUNT : 0);
623 if (opt_chng==OPT_TYPE_IM || opt_chng==OPT_TYPE_CHAT) { 620 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)) || 621 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))) { 622 (gaim_conversation_get_type(c)==GAIM_CONV_CHAT && (notify_opts & OPT_TYPE_CHAT))) {
626 Window focus_return; 623 Window focus_return;
627 int revert_to_return; 624 int revert_to_return;
628 625
629 XGetInputFocus(GDK_WINDOW_XDISPLAY(gtkwin->window->window), 626 XGetInputFocus(GDK_WINDOW_XDISPLAY(gtkwin->window->window),
630 &focus_return, &revert_to_return); 627 &focus_return, &revert_to_return);
631 if ((notify_opts & OPT_NOTIFY_IN_FOCUS) || 628 if ((notify_opts & OPT_NOTIFY_IN_FOCUS) ||
632 focus_return != GDK_WINDOW_XWINDOW(gtkwin->window->window)) { 629 focus_return != GDK_WINDOW_XWINDOW(gtkwin->window->window)) {
633 if (notify_opts & OPT_METHOD_STRING) 630 if (notify_opts & OPT_METHOD_STRING)
776 773
777 static gboolean 774 static gboolean
778 plugin_load(GaimPlugin *plugin) 775 plugin_load(GaimPlugin *plugin)
779 { 776 {
780 GList *cnv = gaim_get_conversations(); 777 GList *cnv = gaim_get_conversations();
778 void *conv_handle = gaim_conversations_get_handle();
781 779
782 my_plugin = plugin; 780 my_plugin = plugin;
783 781
784 load_notify_prefs(); 782 load_notify_prefs();
785 783
786 gaim_signal_connect(plugin, event_im_recv, im_recv_im, NULL); 784 gaim_signal_connect(conv_handle, "received-im-msg",
787 gaim_signal_connect(plugin, event_chat_recv, chat_recv_im, NULL); 785 plugin, GAIM_CALLBACK(im_recv_im), NULL);
788 gaim_signal_connect(plugin, event_im_send, im_sent_im, NULL); 786 gaim_signal_connect(conv_handle, "received-chat-msg",
789 gaim_signal_connect(plugin, event_chat_send, chat_sent_im, NULL); 787 plugin, GAIM_CALLBACK(chat_recv_im), NULL);
790 gaim_signal_connect(plugin, event_new_conversation, new_conv, NULL); 788 gaim_signal_connect(conv_handle, "sent-im-msg",
791 gaim_signal_connect(plugin, event_chat_join, chat_join, NULL); 789 plugin, GAIM_CALLBACK(im_sent_im), NULL);
790 gaim_signal_connect(conv_handle, "sent-chat-msg",
791 plugin, GAIM_CALLBACK(chat_sent_im), NULL);
792 gaim_signal_connect(conv_handle, "conversation-created",
793 plugin, GAIM_CALLBACK(new_conv), NULL);
794 gaim_signal_connect(conv_handle, "chat-joined",
795 plugin, GAIM_CALLBACK(chat_join), NULL);
792 796
793 while (cnv) { 797 while (cnv) {
794 GaimConversation *c = (GaimConversation *)cnv->data; 798 GaimConversation *c = (GaimConversation *)cnv->data;
795 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c)); 799 GaimGtkWindow *gtkwin = GAIM_GTK_WINDOW(gaim_conversation_get_window(c));
796 800
848 N_("Provides a variety of ways of notifying you of unread messages."), 852 N_("Provides a variety of ways of notifying you of unread messages."),
849 /** description */ 853 /** description */
850 N_("Provides a variety of ways of notifying you of unread messages."), 854 N_("Provides a variety of ways of notifying you of unread messages."),
851 "Etan Reisner <deryni@eden.rutgers.edu>\n\t\t\tBrian Tarricone <bjt23@cornell.edu", 855 "Etan Reisner <deryni@eden.rutgers.edu>\n\t\t\tBrian Tarricone <bjt23@cornell.edu",
852 /**< author */ 856 /**< author */
853 GAIM_WEBSITE, /**< homepage */ 857 GAIM_WEBSITE, /**< homepage */
854 858
855 plugin_load, /**< load */ 859 plugin_load, /**< load */
856 plugin_unload, /**< unload */ 860 plugin_unload, /**< unload */
857 NULL, /**< destroy */ 861 NULL, /**< destroy */
858 862