# HG changeset patch # User Luke Schierer # Date 1034775727 0 # Node ID 03ba413ca20b764a32c24f393ee13a3934586d8c # Parent 03e58c0789173c0e23de319306879adffec7924b [gaim-migrate @ 3843] notification in chats (deryni) committer: Tailor Script diff -r 03e58c078917 -r 03ba413ca20b plugins/notify.c --- a/plugins/notify.c Wed Oct 16 06:30:45 2002 +0000 +++ b/plugins/notify.c Wed Oct 16 13:42:07 2002 +0000 @@ -8,13 +8,11 @@ * for count of new messages option */ -/* if my flash messages patch gets merged in can use cnv->local - * to notify on new messages also - */ +#ifndef GAIM_PLUGINS +#define GAIM_PLUGINS +#endif -#define GAIM_PLUGINS #include "gaim.h" - #include #include #include @@ -24,10 +22,15 @@ #include #include +guint type = 1; +#define TYPE_IM 0x00000001 +#define TYPE_CHAT 0x00000002 + guint choice = 1; #define NOTIFY_FOCUS 0x00000001 #define NOTIFY_TYPE 0x00000002 #define NOTIFY_IN_FOCUS 0x00000004 +#define NOTIFY_CLICK 0x00000008 guint method = 1; #define METHOD_STRING 0x00000001 @@ -40,7 +43,6 @@ * other way of removing the signal callbacks to work and not crash gaim */ GtkWidget *really_evil_hack; -/* GHashTable *hash = NULL; */ GtkWidget *Entry; gchar *title_string = "(*) "; @@ -54,28 +56,26 @@ void urgent_remove(struct conversation *c); int counter (char *buf, int *length); -int received_im(struct gaim_connection *gc, char **who, char **what, void *m) { - char buf[256]; - struct conversation *cnv = find_conversation(*who); - GtkWindow *win; - char *me = g_strdup(normalize(gc->username)); - int revert_to_return; - Window focus_return; - int c, length; +struct conversation *find_chat(struct gaim_connection *gc, int id) { + GList *cnv = chats; + struct conversation *c; + + while (cnv) { + c = (struct conversation *) cnv->data; + + if (c && (c->gc == gc) && c->is_chat && (c->id == id)) + return c; - if (!strcmp(me, normalize(*who))) { - g_free(me); - return 0; + cnv = cnv->next; } - g_free(me); + return NULL; +} - if (cnv == NULL) - { - if (away_options & OPT_AWAY_QUEUE) - return 0; - - cnv = new_conversation(*who); - } +int notify(struct conversation *cnv) { + char buf[256]; + GtkWindow *win; + Window focus_return; + int revert_to_return, c, length; win = (GtkWindow *)cnv->window; @@ -111,20 +111,16 @@ /* do it the gdk way for windows compatibility(?) if I can figure it out */ /* Sean says this is a bad thing, and I should try using gtk_property_get first */ /* I'll want to pay attention to note on dev.gnome.org though */ -/* gdk_property_change(win->window, WM_HINTS, WM_HINTS, 32, GDK_PROP_MODE_REPLACE, XUrgencyHint, 1); */ + /* gdk_property_change(win->window, WM_HINTS, WM_HINTS, 32, GDK_PROP_MODE_REPLACE, XUrgencyHint, 1); */ XWMHints *hints = XGetWMHints(GDK_WINDOW_XDISPLAY(cnv->window->window), GDK_WINDOW_XWINDOW(cnv->window->window)); hints->flags |= XUrgencyHint; XSetWMHints(GDK_WINDOW_XDISPLAY(cnv->window->window), GDK_WINDOW_XWINDOW(cnv->window->window), hints); } } - return 0; } -int sent_im(struct gaim_connection *gc, char *who, char **what, void *m) { - /* char buf[256]; */ - struct conversation *c = find_conversation(who); - +int unnotify(struct conversation *c) { if (method & METHOD_QUOTE) quote_remove(c->window); if (method & METHOD_COUNT) @@ -136,16 +132,45 @@ return 0; } -int new_conv(char *who) { +void chat_recv_im(struct gaim_connection *gc, int id, char **who, char **text) { + struct conversation *c = find_chat(gc, id); + + if (c && (type & TYPE_CHAT)) + notify(c); + return; +} + +void chat_sent_im(struct gaim_connection *gc, int id, char **text) { + struct conversation *c = find_chat(gc, id); + + if (c && (type & TYPE_CHAT)) + unnotify(c); + return; +} + +int im_recv_im(struct gaim_connection *gc, char **who, char **what, void *m) { + struct conversation *c = find_conversation(*who); + + if (c && (type & TYPE_IM)) + notify(c); + return 0; +} + +int im_sent_im(struct gaim_connection *gc, char *who, char **what, void *m) { struct conversation *c = find_conversation(who); -/* g_hash_table_insert(hash, who, GINT_TO_POINTER(choice)); */ + if (c && (type & TYPE_IM)) + unnotify(c); + return 0; +} +int attach_signals(struct conversation *c) { if (choice & NOTIFY_FOCUS) { gtk_signal_connect_while_alive(GTK_OBJECT(c->window), "focus-in-event", GTK_SIGNAL_FUNC(un_star), NULL, GTK_OBJECT(really_evil_hack)); gtk_object_set_user_data(GTK_OBJECT(c->window), c); } - else { + + if (choice & NOTIFY_CLICK) { gtk_signal_connect_while_alive(GTK_OBJECT(c->window), "button_press_event", GTK_SIGNAL_FUNC(un_star), NULL, GTK_OBJECT(really_evil_hack)); gtk_object_set_user_data(GTK_OBJECT(c->window), c); gtk_signal_connect_while_alive(GTK_OBJECT(c->text), "button_press_event", GTK_SIGNAL_FUNC(un_star_window), NULL, GTK_OBJECT(really_evil_hack)); @@ -161,6 +186,22 @@ return 0; } +void new_conv(char *who) { + struct conversation *c = find_conversation(who); + + if (c && (type & TYPE_IM)) + attach_signals(c); + return; +} + +void chat_join(struct gaim_connection *gc, int id, char *room) { + struct conversation *c = find_chat(gc, id); + + if (type & TYPE_CHAT) + attach_signals(c); + return; +} + void un_star(GtkWidget *widget, gpointer data) { struct conversation *c = gtk_object_get_user_data(GTK_OBJECT(widget)); @@ -188,9 +229,6 @@ int i = 1; *length = 0; -/* if (buf[0] != '[') */ -/* return (0); */ - while (isdigit(buf[i]) && idata; -/* if (options = GPOINTER_TO_INT(g_hash_table_lookup(hash, cnv->name))) { */ - un_star(cnv->window, NULL); -/* if (options & REMOVE_FOCUS) */ -/* gtk_signal_disconnect_by_func(GTK_OBJECT(cnv->window), GTK_SIGNAL_FUNC(un_star), NULL); */ -/* else { */ -/* gtk_signal_disconnect_by_func(GTK_OBJECT(cnv->window), GTK_SIGNAL_FUNC(un_star), NULL); */ -/* gtk_signal_disconnect_by_func(GTK_OBJECT(cnv->text), GTK_SIGNAL_FUNC(un_star_window), NULL); */ -/* gtk_signal_disconnect_by_func(GTK_OBJECT(cnv->entry), GTK_SIGNAL_FUNC(un_star_window), NULL); */ -/* } */ -/* if (options & REMOVE_TYPE) */ -/* gtk_signal_disconnect_by_func(GTK_OBJECT(cnv->entry), GTK_SIGNAL_FUNC(un_star_window), NULL); */ -/* } */ - c = c->next; + + un_star(cnv->window, NULL); + + c = c->next; } } @@ -385,49 +425,66 @@ ret = gtk_vbox_new(FALSE, 18); gtk_container_set_border_width (GTK_CONTAINER (ret), 12); + vbox = make_frame(ret, _("Notify For")); + toggle = gtk_check_button_new_with_mnemonic(_("_IM windows")); + gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), type & TYPE_IM); + gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(7)); + + toggle = gtk_check_button_new_with_mnemonic(_("_Chat windows")); + gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), type & TYPE_CHAT); + gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(8)); + + /*--------------*/ vbox = make_frame(ret, _("Notification Methods")); hbox = gtk_hbox_new(FALSE, 18); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); toggle = gtk_check_button_new_with_mnemonic(_("Prepend _string into window title:")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), method & METHOD_STRING); - gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(2)); + gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(3)); gtk_box_pack_start(GTK_BOX(hbox), toggle, FALSE, FALSE, 0); Entry = gtk_entry_new_with_max_length(7); gtk_widget_set_sensitive(GTK_WIDGET(Entry), method & METHOD_STRING); gtk_box_pack_start(GTK_BOX(hbox), Entry, FALSE, FALSE, 0); gtk_entry_set_text(GTK_ENTRY(Entry), title_string); - toggle = gtk_check_button_new_with_mnemonic(_("_Quote window title.")); + toggle = gtk_check_button_new_with_mnemonic(_("_Quote window title")); gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), method & METHOD_QUOTE); - gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(3)); + gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(4)); toggle = gtk_check_button_new_with_mnemonic(_("Set Window Manager \"_URGENT\" Hint")); gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), method & METHOD_URGENT); - gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(4)); + gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(5)); - toggle = gtk_check_button_new_with_mnemonic(_("Insert _count of new messages into window title")); + toggle = gtk_check_button_new_with_mnemonic(_("Insert c_ount of new messages into window title")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), method & METHOD_COUNT); gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); + gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(7)); + + toggle = gtk_check_button_new_with_mnemonic(_("_Notify even if conversation is in focus")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_IN_FOCUS); + gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(6)); - toggle = gtk_check_button_new_with_mnemonic(_("_Notify even if conversation is in focus.")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_IN_FOCUS); - gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); - gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(5)); - /*--------------*/ vbox = make_frame(ret, _("Notification Removal")); - toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window gains _focus.")); + toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window gains _focus")); gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_FOCUS); gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(0)); + toggle = gtk_check_button_new_with_mnemonic(_("Remove when conversation window _receives click")); + gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_CLICK); + gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(1)); + toggle = gtk_check_button_new_with_mnemonic(_("Remove when _typing in conversation window")); gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), choice & NOTIFY_TYPE); - gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(1)); + gtk_signal_connect(GTK_OBJECT(toggle), "toggled", GTK_SIGNAL_FUNC(options), GINT_TO_POINTER(2)); gtk_widget_show_all(ret); return ret; diff -r 03e58c078917 -r 03ba413ca20b src/server.c --- a/src/server.c Wed Oct 16 06:30:45 2002 +0000 +++ b/src/server.c Wed Oct 16 13:42:07 2002 +0000 @@ -969,8 +969,6 @@ { struct conversation *b; - plugin_event(event_chat_join, gc, id, name); - b = (struct conversation *)g_new0(struct conversation, 1); gc->buddy_chats = g_slist_append(gc->buddy_chats, b); chats = g_list_append(chats, b); @@ -1007,6 +1005,8 @@ show_new_buddy_chat(b); + plugin_event(event_chat_join, gc, id, name); + return b; }