comparison pidgin/plugins/notify.c @ 15500:d75099d2567e

gaim_gtk to pidgin. I hope
author Sean Egan <seanegan@gmail.com>
date Sat, 03 Feb 2007 07:23:11 +0000
parents bb3bf2f88406
children 762b6547adf9
comparison
equal deleted inserted replaced
15499:45ecefd0ce3a 15500:d75099d2567e
110 static GdkAtom _GaimUnseenCount = GDK_NONE; 110 static GdkAtom _GaimUnseenCount = GDK_NONE;
111 #endif 111 #endif
112 112
113 /* notification set/unset */ 113 /* notification set/unset */
114 static int notify(GaimConversation *conv, gboolean increment); 114 static int notify(GaimConversation *conv, gboolean increment);
115 static void notify_win(GaimGtkWindow *gaimwin); 115 static void notify_win(PidginWindow *gaimwin);
116 static void unnotify(GaimConversation *conv, gboolean reset); 116 static void unnotify(GaimConversation *conv, gboolean reset);
117 static int unnotify_cb(GtkWidget *widget, gpointer data, 117 static int unnotify_cb(GtkWidget *widget, gpointer data,
118 GaimConversation *conv); 118 GaimConversation *conv);
119 119
120 /* gtk widget callbacks for prefs panel */ 120 /* gtk widget callbacks for prefs panel */
125 gpointer data); 125 gpointer data);
126 static void apply_method(void); 126 static void apply_method(void);
127 static void apply_notify(void); 127 static void apply_notify(void);
128 128
129 /* string function */ 129 /* string function */
130 static void handle_string(GaimGtkWindow *gaimwin); 130 static void handle_string(PidginWindow *gaimwin);
131 131
132 /* count_title function */ 132 /* count_title function */
133 static void handle_count_title(GaimGtkWindow *gaimwin); 133 static void handle_count_title(PidginWindow *gaimwin);
134 134
135 /* count_xprop function */ 135 /* count_xprop function */
136 static void handle_count_xprop(GaimGtkWindow *gaimwin); 136 static void handle_count_xprop(PidginWindow *gaimwin);
137 137
138 /* urgent function */ 138 /* urgent function */
139 static void handle_urgent(GaimGtkWindow *gaimwin, gboolean set); 139 static void handle_urgent(PidginWindow *gaimwin, gboolean set);
140 140
141 /* raise function */ 141 /* raise function */
142 static void handle_raise(GaimGtkWindow *gaimwin); 142 static void handle_raise(PidginWindow *gaimwin);
143 143
144 /****************************************/ 144 /****************************************/
145 /* Begin doing stuff below this line... */ 145 /* Begin doing stuff below this line... */
146 /****************************************/ 146 /****************************************/
147 static guint 147 static guint
148 count_messages(GaimGtkWindow *gaimwin) 148 count_messages(PidginWindow *gaimwin)
149 { 149 {
150 guint count = 0; 150 guint count = 0;
151 GList *convs = NULL, *l; 151 GList *convs = NULL, *l;
152 152
153 for (convs = gaimwin->gtkconvs; convs != NULL; convs = convs->next) { 153 for (convs = gaimwin->gtkconvs; convs != NULL; convs = convs->next) {
154 GaimGtkConversation *conv = convs->data; 154 PidginConversation *conv = convs->data;
155 for (l = conv->convs; l != NULL; l = l->next) { 155 for (l = conv->convs; l != NULL; l = l->next) {
156 count += GPOINTER_TO_INT(gaim_conversation_get_data(l->data, "notify-message-count")); 156 count += GPOINTER_TO_INT(gaim_conversation_get_data(l->data, "notify-message-count"));
157 } 157 }
158 } 158 }
159 159
163 static int 163 static int
164 notify(GaimConversation *conv, gboolean increment) 164 notify(GaimConversation *conv, gboolean increment)
165 { 165 {
166 gint count; 166 gint count;
167 gboolean has_focus; 167 gboolean has_focus;
168 GaimGtkWindow *gaimwin = NULL; 168 PidginWindow *gaimwin = NULL;
169 169
170 if (conv == NULL) 170 if (conv == NULL)
171 return 0; 171 return 0;
172 172
173 /* We want to remove the notifications, but not reset the counter */ 173 /* We want to remove the notifications, but not reset the counter */
174 unnotify(conv, FALSE); 174 unnotify(conv, FALSE);
175 175
176 gaimwin = GAIM_GTK_CONVERSATION(conv)->win; 176 gaimwin = PIDGIN_CONVERSATION(conv)->win;
177 177
178 /* If we aren't doing notifications for this type of conversation, return */ 178 /* If we aren't doing notifications for this type of conversation, return */
179 if (((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) && 179 if (((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) &&
180 !gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_im")) || 180 !gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_im")) ||
181 ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) && 181 ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT) &&
198 198
199 return 0; 199 return 0;
200 } 200 }
201 201
202 static void 202 static void
203 notify_win(GaimGtkWindow *gaimwin) 203 notify_win(PidginWindow *gaimwin)
204 { 204 {
205 if (count_messages(gaimwin) <= 0) 205 if (count_messages(gaimwin) <= 0)
206 return; 206 return;
207 207
208 if (gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_count")) 208 if (gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_count"))
219 219
220 static void 220 static void
221 unnotify(GaimConversation *conv, gboolean reset) 221 unnotify(GaimConversation *conv, gboolean reset)
222 { 222 {
223 GaimConversation *active_conv = NULL; 223 GaimConversation *active_conv = NULL;
224 GaimGtkWindow *gaimwin = NULL; 224 PidginWindow *gaimwin = NULL;
225 225
226 g_return_if_fail(conv != NULL); 226 g_return_if_fail(conv != NULL);
227 227
228 gaimwin = GAIM_GTK_CONVERSATION(conv)->win; 228 gaimwin = PIDGIN_CONVERSATION(conv)->win;
229 active_conv = gaim_gtk_conv_window_get_active_conversation(gaimwin); 229 active_conv = pidgin_conv_window_get_active_conversation(gaimwin);
230 230
231 /* reset the conversation window title */ 231 /* reset the conversation window title */
232 gaim_conversation_autoset_title(active_conv); 232 gaim_conversation_autoset_title(active_conv);
233 233
234 if (reset) { 234 if (reset) {
293 } 293 }
294 294
295 static int 295 static int
296 attach_signals(GaimConversation *conv) 296 attach_signals(GaimConversation *conv)
297 { 297 {
298 GaimGtkConversation *gtkconv = NULL; 298 PidginConversation *gtkconv = NULL;
299 GaimGtkWindow *gtkwin = NULL; 299 PidginWindow *gtkwin = NULL;
300 GSList *imhtml_ids = NULL, *entry_ids = NULL; 300 GSList *imhtml_ids = NULL, *entry_ids = NULL;
301 guint id; 301 guint id;
302 302
303 gtkconv = GAIM_GTK_CONVERSATION(conv); 303 gtkconv = PIDGIN_CONVERSATION(conv);
304 if (!gtkconv) { 304 if (!gtkconv) {
305 gaim_debug_misc("notify", "Failed to find gtkconv\n"); 305 gaim_debug_misc("notify", "Failed to find gtkconv\n");
306 return 0; 306 return 0;
307 } 307 }
308 308
348 } 348 }
349 349
350 static void 350 static void
351 detach_signals(GaimConversation *conv) 351 detach_signals(GaimConversation *conv)
352 { 352 {
353 GaimGtkConversation *gtkconv = NULL; 353 PidginConversation *gtkconv = NULL;
354 GaimGtkWindow *gtkwin = NULL; 354 PidginWindow *gtkwin = NULL;
355 GSList *ids = NULL, *l; 355 GSList *ids = NULL, *l;
356 356
357 gtkconv = GAIM_GTK_CONVERSATION(conv); 357 gtkconv = PIDGIN_CONVERSATION(conv);
358 if (!gtkconv) 358 if (!gtkconv)
359 return; 359 return;
360 gtkwin = gtkconv->win; 360 gtkwin = gtkconv->win;
361 361
362 ids = gaim_conversation_get_data(conv, "notify-imhtml-signals"); 362 ids = gaim_conversation_get_data(conv, "notify-imhtml-signals");
388 388
389 static void 389 static void
390 conv_switched(GaimConversation *conv) 390 conv_switched(GaimConversation *conv)
391 { 391 {
392 #if 0 392 #if 0
393 GaimGtkWindow *gaimwin = gaim_conversation_get_window(new_conv); 393 PidginWindow *gaimwin = gaim_conversation_get_window(new_conv);
394 #endif 394 #endif
395 395
396 /* 396 /*
397 * If the conversation was switched, then make sure we re-notify 397 * If the conversation was switched, then make sure we re-notify
398 * because Gaim will have overwritten our custom window title. 398 * because Gaim will have overwritten our custom window title.
414 } 414 }
415 415
416 static void 416 static void
417 deleting_conv(GaimConversation *conv) 417 deleting_conv(GaimConversation *conv)
418 { 418 {
419 GaimGtkWindow *gaimwin = NULL; 419 PidginWindow *gaimwin = NULL;
420 420
421 detach_signals(conv); 421 detach_signals(conv);
422 422
423 gaimwin = GAIM_GTK_CONVERSATION(conv)->win; 423 gaimwin = PIDGIN_CONVERSATION(conv)->win;
424 424
425 handle_urgent(gaimwin, FALSE); 425 handle_urgent(gaimwin, FALSE);
426 gaim_conversation_set_data(conv, "notify-message-count", GINT_TO_POINTER(0)); 426 gaim_conversation_set_data(conv, "notify-message-count", GINT_TO_POINTER(0));
427 427
428 return; 428 return;
435 } 435 }
436 436
437 #if 0 437 #if 0
438 static void 438 static void
439 conversation_dragging(GaimConversation *active_conv, 439 conversation_dragging(GaimConversation *active_conv,
440 GaimGtkWindow *old_gaimwin, 440 PidginWindow *old_gaimwin,
441 GaimGtkWindow *new_gaimwin) 441 PidginWindow *new_gaimwin)
442 { 442 {
443 if (old_gaimwin != new_gaimwin) { 443 if (old_gaimwin != new_gaimwin) {
444 if (old_gaimwin == NULL) { 444 if (old_gaimwin == NULL) {
445 /* 445 /*
446 gaim_conversation_autoset_title(active_conv); 446 gaim_conversation_autoset_title(active_conv);
482 } 482 }
483 } 483 }
484 #endif 484 #endif
485 485
486 static void 486 static void
487 handle_string(GaimGtkWindow *gaimwin) 487 handle_string(PidginWindow *gaimwin)
488 { 488 {
489 GtkWindow *window = NULL; 489 GtkWindow *window = NULL;
490 gchar newtitle[256]; 490 gchar newtitle[256];
491 491
492 g_return_if_fail(gaimwin != NULL); 492 g_return_if_fail(gaimwin != NULL);
499 gtk_window_get_title(window)); 499 gtk_window_get_title(window));
500 gtk_window_set_title(window, newtitle); 500 gtk_window_set_title(window, newtitle);
501 } 501 }
502 502
503 static void 503 static void
504 handle_count_title(GaimGtkWindow *gaimwin) 504 handle_count_title(PidginWindow *gaimwin)
505 { 505 {
506 GtkWindow *window; 506 GtkWindow *window;
507 char newtitle[256]; 507 char newtitle[256];
508 508
509 g_return_if_fail(gaimwin != NULL); 509 g_return_if_fail(gaimwin != NULL);
515 count_messages(gaimwin), gtk_window_get_title(window)); 515 count_messages(gaimwin), gtk_window_get_title(window));
516 gtk_window_set_title(window, newtitle); 516 gtk_window_set_title(window, newtitle);
517 } 517 }
518 518
519 static void 519 static void
520 handle_count_xprop(GaimGtkWindow *gaimwin) 520 handle_count_xprop(PidginWindow *gaimwin)
521 { 521 {
522 #ifndef _WIN32 522 #ifndef _WIN32
523 guint count; 523 guint count;
524 GtkWidget *window; 524 GtkWidget *window;
525 GdkWindow *gdkwin; 525 GdkWindow *gdkwin;
542 GDK_PROP_MODE_REPLACE, (guchar *) &count, 1); 542 GDK_PROP_MODE_REPLACE, (guchar *) &count, 1);
543 #endif 543 #endif
544 } 544 }
545 545
546 static void 546 static void
547 handle_urgent(GaimGtkWindow *win, gboolean set) 547 handle_urgent(PidginWindow *win, gboolean set)
548 { 548 {
549 #ifndef _WIN32 549 #ifndef _WIN32
550 gaim_gtk_set_urgent(GTK_WINDOW(win->window), set); 550 pidgin_set_urgent(GTK_WINDOW(win->window), set);
551 #endif 551 #endif
552 } 552 }
553 553
554 static void 554 static void
555 handle_raise(GaimGtkWindow *gaimwin) 555 handle_raise(PidginWindow *gaimwin)
556 { 556 {
557 gaim_gtk_conv_window_raise(gaimwin); 557 pidgin_conv_window_raise(gaimwin);
558 } 558 }
559 559
560 static void 560 static void
561 type_toggle_cb(GtkWidget *widget, gpointer data) 561 type_toggle_cb(GtkWidget *widget, gpointer data)
562 { 562 {
623 623
624 static void 624 static void
625 apply_method() 625 apply_method()
626 { 626 {
627 GList *convs; 627 GList *convs;
628 GaimGtkWindow *gaimwin = NULL; 628 PidginWindow *gaimwin = NULL;
629 629
630 for (convs = gaim_get_conversations(); convs != NULL; 630 for (convs = gaim_get_conversations(); convs != NULL;
631 convs = convs->next) { 631 convs = convs->next) {
632 GaimConversation *conv = (GaimConversation *)convs->data; 632 GaimConversation *conv = (GaimConversation *)convs->data;
633 633
634 /* remove notifications */ 634 /* remove notifications */
635 unnotify(conv, FALSE); 635 unnotify(conv, FALSE);
636 636
637 gaimwin = GAIM_GTK_CONVERSATION(conv)->win; 637 gaimwin = PIDGIN_CONVERSATION(conv)->win;
638 if (GPOINTER_TO_INT(gaim_conversation_get_data(conv, "notify-message-count")) != 0) 638 if (GPOINTER_TO_INT(gaim_conversation_get_data(conv, "notify-message-count")) != 0)
639 /* reattach appropriate notifications */ 639 /* reattach appropriate notifications */
640 notify(conv, FALSE); 640 notify(conv, FALSE);
641 } 641 }
642 } 642 }
667 667
668 ret = gtk_vbox_new(FALSE, 18); 668 ret = gtk_vbox_new(FALSE, 18);
669 gtk_container_set_border_width(GTK_CONTAINER (ret), 12); 669 gtk_container_set_border_width(GTK_CONTAINER (ret), 12);
670 670
671 /*---------- "Notify For" ----------*/ 671 /*---------- "Notify For" ----------*/
672 frame = gaim_gtk_make_frame(ret, _("Notify For")); 672 frame = pidgin_make_frame(ret, _("Notify For"));
673 vbox = gtk_vbox_new(FALSE, 5); 673 vbox = gtk_vbox_new(FALSE, 5);
674 gtk_container_add(GTK_CONTAINER(frame), vbox); 674 gtk_container_add(GTK_CONTAINER(frame), vbox);
675 675
676 toggle = gtk_check_button_new_with_mnemonic(_("_IM windows")); 676 toggle = gtk_check_button_new_with_mnemonic(_("_IM windows"));
677 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); 677 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0);
694 gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_chat_nick")); 694 gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_chat_nick"));
695 g_signal_connect(G_OBJECT(toggle), "toggled", 695 g_signal_connect(G_OBJECT(toggle), "toggled",
696 G_CALLBACK(type_toggle_cb), "type_chat_nick"); 696 G_CALLBACK(type_toggle_cb), "type_chat_nick");
697 gtk_widget_set_sensitive(toggle, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ref))); 697 gtk_widget_set_sensitive(toggle, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ref)));
698 g_signal_connect(G_OBJECT(ref), "toggled", 698 g_signal_connect(G_OBJECT(ref), "toggled",
699 G_CALLBACK(gaim_gtk_toggle_sensitive), toggle); 699 G_CALLBACK(pidgin_toggle_sensitive), toggle);
700 700
701 toggle = gtk_check_button_new_with_mnemonic(_("_Focused windows")); 701 toggle = gtk_check_button_new_with_mnemonic(_("_Focused windows"));
702 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); 702 gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0);
703 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), 703 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle),
704 gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_focused")); 704 gaim_prefs_get_bool("/plugins/gtk/X11/notify/type_focused"));
705 g_signal_connect(G_OBJECT(toggle), "toggled", 705 g_signal_connect(G_OBJECT(toggle), "toggled",
706 G_CALLBACK(type_toggle_cb), "type_focused"); 706 G_CALLBACK(type_toggle_cb), "type_focused");
707 707
708 /*---------- "Notification Methods" ----------*/ 708 /*---------- "Notification Methods" ----------*/
709 frame = gaim_gtk_make_frame(ret, _("Notification Methods")); 709 frame = pidgin_make_frame(ret, _("Notification Methods"));
710 vbox = gtk_vbox_new(FALSE, 5); 710 vbox = gtk_vbox_new(FALSE, 5);
711 gtk_container_add(GTK_CONTAINER(frame), vbox); 711 gtk_container_add(GTK_CONTAINER(frame), vbox);
712 712
713 /* String method button */ 713 /* String method button */
714 hbox = gtk_hbox_new(FALSE, 18); 714 hbox = gtk_hbox_new(FALSE, 18);
764 gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_raise")); 764 gaim_prefs_get_bool("/plugins/gtk/X11/notify/method_raise"));
765 g_signal_connect(G_OBJECT(toggle), "toggled", 765 g_signal_connect(G_OBJECT(toggle), "toggled",
766 G_CALLBACK(method_toggle_cb), "method_raise"); 766 G_CALLBACK(method_toggle_cb), "method_raise");
767 767
768 /*---------- "Notification Removals" ----------*/ 768 /*---------- "Notification Removals" ----------*/
769 frame = gaim_gtk_make_frame(ret, _("Notification Removal")); 769 frame = pidgin_make_frame(ret, _("Notification Removal"));
770 vbox = gtk_vbox_new(FALSE, 5); 770 vbox = gtk_vbox_new(FALSE, 5);
771 gtk_container_add(GTK_CONTAINER(frame), vbox); 771 gtk_container_add(GTK_CONTAINER(frame), vbox);
772 772
773 /* Remove on focus button */ 773 /* Remove on focus button */
774 toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window _gains focus")); 774 toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window _gains focus"));
818 static gboolean 818 static gboolean
819 plugin_load(GaimPlugin *plugin) 819 plugin_load(GaimPlugin *plugin)
820 { 820 {
821 GList *convs = gaim_get_conversations(); 821 GList *convs = gaim_get_conversations();
822 void *conv_handle = gaim_conversations_get_handle(); 822 void *conv_handle = gaim_conversations_get_handle();
823 void *gtk_conv_handle = gaim_gtk_conversations_get_handle(); 823 void *gtk_conv_handle = pidgin_conversations_get_handle();
824 824
825 my_plugin = plugin; 825 my_plugin = plugin;
826 826
827 gaim_signal_connect(gtk_conv_handle, "displayed-im-msg", plugin, 827 gaim_signal_connect(gtk_conv_handle, "displayed-im-msg", plugin,
828 GAIM_CALLBACK(message_displayed_cb), NULL); 828 GAIM_CALLBACK(message_displayed_cb), NULL);
872 } 872 }
873 873
874 return TRUE; 874 return TRUE;
875 } 875 }
876 876
877 static GaimGtkPluginUiInfo ui_info = 877 static PidginPluginUiInfo ui_info =
878 { 878 {
879 get_config_frame, 879 get_config_frame,
880 0 /* page_num (Reserved) */ 880 0 /* page_num (Reserved) */
881 }; 881 };
882 882
884 { 884 {
885 GAIM_PLUGIN_MAGIC, 885 GAIM_PLUGIN_MAGIC,
886 GAIM_MAJOR_VERSION, 886 GAIM_MAJOR_VERSION,
887 GAIM_MINOR_VERSION, 887 GAIM_MINOR_VERSION,
888 GAIM_PLUGIN_STANDARD, /**< type */ 888 GAIM_PLUGIN_STANDARD, /**< type */
889 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ 889 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */
890 0, /**< flags */ 890 0, /**< flags */
891 NULL, /**< dependencies */ 891 NULL, /**< dependencies */
892 GAIM_PRIORITY_DEFAULT, /**< priority */ 892 GAIM_PRIORITY_DEFAULT, /**< priority */
893 893
894 NOTIFY_PLUGIN_ID, /**< id */ 894 NOTIFY_PLUGIN_ID, /**< id */