Mercurial > pidgin
changeset 2153:0befa2d2e540
[gaim-migrate @ 2163]
moving mail notifications to the core. this makes things much easier on the protocols. next steps: make buddy right-click menu stuff generated by the core (based on information provided by the protocols, similar to the away menu stuff); make entry-widget protocol-specific user options generated by the core based on what the protocols tell it (in a similar way).
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 22 Aug 2001 21:11:58 +0000 |
parents | f631cfc8e824 |
children | cff133e0ec0c |
files | src/gaim.h src/multi.c src/multi.h src/protocols/msn/msn.c src/protocols/yahoo/yay.c src/prpl.c src/prpl.h |
diffstat | 7 files changed, 136 insertions(+), 154 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gaim.h Wed Aug 22 17:25:33 2001 +0000 +++ b/src/gaim.h Wed Aug 22 21:11:58 2001 +0000 @@ -142,6 +142,9 @@ GtkWidget *passprmt; GtkWidget *passentry; + /* stuff for mail check prompt */ + GtkWidget *checkmail; + /* when you get kicked offline, only show one dialog */ GtkWidget *kick_dlg; }; @@ -561,6 +564,7 @@ #define OPT_USR_AUTO 0x00000001 /*#define OPT_USR_KEEPALV 0x00000002 this shouldn't be optional */ #define OPT_USR_REM_PASS 0x00000004 +#define OPT_USR_MAIL_CHECK 0x00000008 #define DEFAULT_INFO "Visit the GAIM website at <A HREF=\"http://gaim.sourceforge.net/\">http://gaim.sourceforge.net/</A>."
--- a/src/multi.c Wed Aug 22 17:25:33 2001 +0000 +++ b/src/multi.c Wed Aug 22 21:11:58 2001 +0000 @@ -292,6 +292,13 @@ gtk_widget_show(u->pwdbox); gtk_widget_show(u->rempass); } + if (!(p->options & OPT_PROTO_MAIL_CHECK) && + (q->options & OPT_PROTO_MAIL_CHECK)) { + gtk_widget_show(u->checkmail); + } else if ((p->options & OPT_PROTO_MAIL_CHECK) && + !(q->options & OPT_PROTO_MAIL_CHECK)) { + gtk_widget_hide(u->checkmail); + } u->tmp_protocol = proto; generate_prpl_options(u, u->main); } else if (!u && (tmpusr.tmp_protocol != proto)) { @@ -308,6 +315,13 @@ gtk_widget_show(tmpusr.pwdbox); gtk_widget_show(tmpusr.rempass); } + if (!(p->options & OPT_PROTO_MAIL_CHECK) && + (q->options & OPT_PROTO_MAIL_CHECK)) { + gtk_widget_show(tmpusr.checkmail); + } else if ((p->options & OPT_PROTO_MAIL_CHECK) && + !(q->options & OPT_PROTO_MAIL_CHECK)) { + gtk_widget_hide(tmpusr.checkmail); + } tmpusr.tmp_protocol = tmpusr.protocol = proto; generate_prpl_options(NULL, newmain); } @@ -369,6 +383,7 @@ GtkWidget *name; GtkWidget *pass; GtkWidget *rempass; + GtkWidget *checkmail; vbox = gtk_vbox_new(FALSE, 5); gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); @@ -405,6 +420,7 @@ rempass = acct_button(_("Remember Password"), u, OPT_USR_REM_PASS, vbox); acct_button(_("Auto-Login"), u, OPT_USR_AUTO, vbox); /*acct_button(_("Send KeepAlive packet (6 bytes/second)"), u, OPT_USR_KEEPALV, vbox);*/ + checkmail = acct_button(_("New Mail Notifications"), u, OPT_USR_MAIL_CHECK, vbox); gtk_widget_show_all(vbox); @@ -413,6 +429,7 @@ u->pwdbox = pwdbox; u->pass = pass; u->rempass = rempass; + u->checkmail = checkmail; gtk_entry_set_text(GTK_ENTRY(name), u->username); gtk_entry_set_text(GTK_ENTRY(pass), u->password); gtk_entry_set_editable(GTK_ENTRY(name), FALSE); @@ -421,6 +438,7 @@ tmpusr.pwdbox = pwdbox; tmpusr.pass = pass; tmpusr.rempass = rempass; + tmpusr.checkmail = checkmail; } } @@ -521,12 +539,16 @@ gtk_widget_hide(u->pwdbox); gtk_widget_hide(u->rempass); } + if (!(p->options & OPT_PROTO_MAIL_CHECK)) + gtk_widget_hide(u->checkmail); } else { p = find_prpl(tmpusr.tmp_protocol); if (p->options & OPT_PROTO_NO_PASSWORD) { gtk_widget_hide(tmpusr.pwdbox); gtk_widget_hide(tmpusr.rempass); } + if (!(p->options & OPT_PROTO_MAIL_CHECK)) + gtk_widget_hide(tmpusr.checkmail); } }
--- a/src/multi.h Wed Aug 22 17:25:33 2001 +0000 +++ b/src/multi.h Wed Aug 22 21:11:58 2001 +0000 @@ -73,6 +73,10 @@ int evil; gboolean wants_to_die; /* defaults to FALSE */ + + /* email notification (MSN and Yahoo) */ + GtkWidget *email_win; + GtkWidget *email_label; }; /* now that we have our struct, we're going to need lots of them. Maybe even a list of them. */
--- a/src/protocols/msn/msn.c Wed Aug 22 17:25:33 2001 +0000 +++ b/src/protocols/msn/msn.c Wed Aug 22 21:11:58 2001 +0000 @@ -245,32 +245,25 @@ static void handle_hotmail(struct gaim_connection *gc, char *data) { - char *mailct, *mailp, *from = NULL, *subj = NULL, notice[MSN_BUF_LEN]; - - if (gc->user->proto_opt[USEROPT_HOTMAIL][0] != '1') return; - mailct = strstr(data, "Content-Type: "); - mailp = strstr(mailct, ";"); - if (mailct && mailp && (mailp > mailct) && - !strncmp(mailct, "Content-Type: text/x-msmsgsemailnotification", mailp - mailct - 1)) { - from = strstr(mailp, "From: "); - subj = strstr(mailp, "Subject: "); + if (strstr(data, "Content-Type: text/x-msmsgsinitialemailnotification;")) { + char *x = strstr(data, "Inbox-Unread:"); + if (!x) return; + x += strlen("Inbox-Unread: "); + connection_has_mail(gc, atoi(x), NULL, NULL); + } else if (strstr(data, "Content-Type: text/x-msmsgsemailnotification;")) { + char *from = strstr(data, "From:"); + char *subject = strstr(data, "Subject:"); + char *x; + if (!from || !subject) { + connection_has_mail(gc, 1, NULL, NULL); + return; + } + from += strlen("From: "); + x = strstr(from, "\r\n"); *x = 0; + subject += strlen("Subject: "); + x = strstr(subject, "\r\n"); *x = 0; + connection_has_mail(gc, -1, from, subject); } - - if (!from || !subj) - return; - - from += strlen("From: "); - mailp = strstr(from, "\r\n"); - if (!mailp) return; - *mailp = 0; - - subj += strlen("Subject: "); - mailp = strstr(from, "\r\n"); - if (!mailp) return; - *mailp = 0; - - g_snprintf(notice, sizeof(notice), "Mail from %s, re: %s", from, subj); - do_error_dialog(notice, "New MSN Mail"); } static struct msn_switchboard *msn_find_switch(struct gaim_connection *gc, char *id) @@ -1340,55 +1333,6 @@ gtk_widget_show(button); } -struct mod_usr_opt { - struct aim_user *user; - int opt; -}; - -static void mod_opt(GtkWidget *b, struct mod_usr_opt *m) -{ - if (m->user) { - if (m->user->proto_opt[m->opt][0] == '1') - m->user->proto_opt[m->opt][0] = '\0'; - else - strcpy(m->user->proto_opt[m->opt],"1"); - } -} - -static void free_muo(GtkWidget *b, struct mod_usr_opt *m) -{ - g_free(m); -} - -static GtkWidget *msn_protoopt_button(const char *text, struct aim_user *u, int option, GtkWidget *box) -{ - GtkWidget *button; - struct mod_usr_opt *muo = g_new0(struct mod_usr_opt, 1); - button = gtk_check_button_new_with_label(text); - if (u) - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (u->proto_opt[option][0] == '1')); - gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0); - muo->user = u; - muo->opt = option; - gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(mod_opt), muo); - gtk_signal_connect(GTK_OBJECT(button), "destroy", GTK_SIGNAL_FUNC(free_muo), muo); - gtk_widget_show(button); - - return button; -} - -static void msn_user_opts(GtkWidget* book, struct aim_user *user) -{ - GtkWidget *vbox; - - vbox = gtk_vbox_new(FALSE, 5); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); - gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("MSN Options")); - gtk_widget_show(vbox); - - msn_protoopt_button("Notify me of new HotMail",user,USEROPT_HOTMAIL,vbox); -} - static void msn_add_buddy(struct gaim_connection *gc, char *who) { struct msn_data *md = gc->proto_data; @@ -1430,10 +1374,10 @@ void msn_init(struct prpl *ret) { ret->protocol = PROTO_MSN; + ret->options = OPT_PROTO_MAIL_CHECK; ret->name = msn_name; ret->list_icon = msn_list_icon; ret->buddy_menu = msn_buddy_menu; - ret->user_opts = msn_user_opts; ret->login = msn_login; ret->close = msn_close; ret->send_im = msn_send_im;
--- a/src/protocols/yahoo/yay.c Wed Aug 22 17:25:33 2001 +0000 +++ b/src/protocols/yahoo/yay.c Wed Aug 22 21:11:58 2001 +0000 @@ -197,17 +197,8 @@ return 1; } -static void des_win(GtkWidget *w, struct yahoo_data *yd) { - gtk_widget_destroy(yd->email_win); - if (yd->email_win == w) - yd->email_win = NULL; - yd->email_label = NULL; -} - static int yahoo_newmail(struct yahoo_session *sess, ...) { struct gaim_connection *gc = sess->user_data; - struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; - char buf[2048]; va_list ap; int count; @@ -216,39 +207,7 @@ count = va_arg(ap, int); va_end(ap); - if (gc->user->proto_opt[USEROPT_MAIL][0] != '1') - return 1; - - if (count) { - g_snprintf(buf, sizeof buf, "%s has %d new message%s on Yahoo Mail.", - gc->username, count, count == 1 ? "" : "s"); - if (!yd->email_win) { - GtkWidget *close; - - yd->email_win = gtk_dialog_new(); - gtk_window_set_policy(GTK_WINDOW(yd->email_win), 0, 0, 1); - gtk_container_set_border_width(GTK_CONTAINER(yd->email_win), 5); - gtk_window_set_title(GTK_WINDOW(yd->email_win), "New Mail"); - gtk_signal_connect(GTK_OBJECT(yd->email_win), "destroy", - GTK_SIGNAL_FUNC(des_win), yd); - gtk_widget_realize(yd->email_win); - aol_icon(yd->email_win->window); - - yd->email_label = gtk_label_new(buf); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(yd->email_win)->vbox), - yd->email_label, 0, 0, 5); - gtk_widget_show(yd->email_label); - - close = picture_button(yd->email_win, _("Close"), cancel_xpm); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(yd->email_win)->action_area), - close, 0, 0, 5); - gtk_signal_connect(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(des_win), yd); - - gtk_widget_show(yd->email_win); - } - gtk_label_set_text(GTK_LABEL(yd->email_label), buf); - } else if (yd->email_win) - gtk_widget_destroy(yd->email_win); + connection_has_mail(gc, count, NULL, NULL); return 1; } @@ -698,39 +657,6 @@ return m; } -struct mod_usr_opt { - struct aim_user *user; - int opt; -}; - -static void mod_opt(GtkWidget *b, struct mod_usr_opt *m) -{ - if (m->user->proto_opt[m->opt][0] == '1') - m->user->proto_opt[m->opt][0] = '\0'; - else - strcpy(m->user->proto_opt[m->opt],"1"); -} - -static void free_muo(GtkWidget *b, struct mod_usr_opt *m) -{ - g_free(m); -} - -static GtkWidget *yahoo_protoopt_button(const char *text, struct aim_user *u, int option, GtkWidget *box) -{ - GtkWidget *button; - struct mod_usr_opt *muo = g_new0(struct mod_usr_opt, 1); - button = gtk_check_button_new_with_label(text); - gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (u->proto_opt[option][0] == '1')); - gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0); - muo->user = u; - muo->opt = option; - gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(mod_opt), muo); - gtk_signal_connect(GTK_OBJECT(button), "destroy", GTK_SIGNAL_FUNC(free_muo), muo); - gtk_widget_show(button); - return button; -} - static void yahoo_print_option(GtkEntry *entry, struct aim_user *user) { int entrynum; @@ -767,7 +693,6 @@ gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("Yahoo Options")); gtk_widget_show(vbox); - yahoo_protoopt_button("Notify me of new Yahoo! Mail", user, USEROPT_MAIL, vbox); hbox = gtk_hbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_widget_show(hbox); @@ -908,6 +833,7 @@ void yahoo_init(struct prpl *ret) { /* the NULL's aren't required but they're nice to have */ ret->protocol = PROTO_YAHOO; + ret->options = OPT_PROTO_MAIL_CHECK; ret->name = yahoo_name; ret->list_icon = yahoo_list_icon; ret->away_states = yahoo_away_states;
--- a/src/prpl.c Wed Aug 22 17:25:33 2001 +0000 +++ b/src/prpl.c Wed Aug 22 21:11:58 2001 +0000 @@ -474,6 +474,83 @@ } } +static void des_email_win(GtkWidget *w, struct gaim_connection *yd) { + gtk_widget_destroy(yd->email_win); + if (yd->email_win == w) + yd->email_win = NULL; + yd->email_label = NULL; +} + +void connection_has_mail(struct gaim_connection *gc, int count, const char *from, const char *subject) +{ + char buf[2048]; + + if (!(gc->user->options & OPT_USR_MAIL_CHECK)) + return; + + if (count < 0 && from && subject) { + g_snprintf(buf, sizeof buf, "%s has mail from %s: %s", + gc->username, from, subject); + if (!gc->email_win) { + GtkWidget *close; + + gc->email_win = gtk_dialog_new(); + gtk_window_set_policy(GTK_WINDOW(gc->email_win), 0, 0, 1); + gtk_container_set_border_width(GTK_CONTAINER(gc->email_win), 5); + gtk_window_set_title(GTK_WINDOW(gc->email_win), "New Mail"); + gtk_signal_connect(GTK_OBJECT(gc->email_win), "destroy", + GTK_SIGNAL_FUNC(des_email_win), gc); + gtk_widget_realize(gc->email_win); + aol_icon(gc->email_win->window); + + gc->email_label = gtk_label_new(buf); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gc->email_win)->vbox), + gc->email_label, 0, 0, 5); + gtk_widget_show(gc->email_label); + + close = picture_button(gc->email_win, _("Close"), cancel_xpm); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gc->email_win)->action_area), + close, 0, 0, 5); + gtk_signal_connect(GTK_OBJECT(close), "clicked", + GTK_SIGNAL_FUNC(des_email_win), gc); + + gtk_widget_show(gc->email_win); + } + gtk_label_set_text(GTK_LABEL(gc->email_label), buf); + } else if (count) { + g_snprintf(buf, sizeof buf, "%s has %d new message%s.", + gc->username, count, count == 1 ? "" : "s"); + if (!gc->email_win) { + GtkWidget *close; + + gc->email_win = gtk_dialog_new(); + gtk_window_set_policy(GTK_WINDOW(gc->email_win), 0, 0, 1); + gtk_container_set_border_width(GTK_CONTAINER(gc->email_win), 5); + gtk_window_set_title(GTK_WINDOW(gc->email_win), "New Mail"); + gtk_signal_connect(GTK_OBJECT(gc->email_win), "destroy", + GTK_SIGNAL_FUNC(des_email_win), gc); + gtk_widget_realize(gc->email_win); + aol_icon(gc->email_win->window); + + gc->email_label = gtk_label_new(buf); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gc->email_win)->vbox), + gc->email_label, 0, 0, 5); + gtk_widget_show(gc->email_label); + + close = picture_button(gc->email_win, _("Close"), cancel_xpm); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(gc->email_win)->action_area), + close, 0, 0, 5); + gtk_signal_connect(GTK_OBJECT(close), "clicked", + GTK_SIGNAL_FUNC(des_email_win), gc); + + gtk_widget_show(gc->email_win); + } + gtk_label_set_text(GTK_LABEL(gc->email_label), buf); + } else if (gc->email_win) + gtk_widget_destroy(gc->email_win); +} + +/* struct ft_req { struct gaim_connection *gc; gboolean send; @@ -500,7 +577,7 @@ static void do_exist_dialog(const char *name, unsigned long size, struct ft_req *fr) { - /* + \* GtkWidget *window; GtkWidget *vbox; GtkWidget *label; @@ -513,7 +590,7 @@ (size <= fr->size) ? ", resume the download," : ""); window = gtk_window_new(GTK_WINDOW_DIALOG); - */ + *\ } static void ftgotfile(gpointer w, struct ft_req *fr) @@ -538,7 +615,7 @@ static void ftrrok(gpointer w, struct ft_req *ft) { - /* ft is going to be free'd as soon as we leave this function, so we'll copy it */ + \* ft is going to be free'd as soon as we leave this function, so we'll copy it *\ struct ft_req *fr = g_memdup(ft, sizeof(struct ft_req)); char buf[256]; @@ -592,3 +669,4 @@ do_ask_dialog(buf, fr, ftrrok, ftrrno); } +*/
--- a/src/prpl.h Wed Aug 22 17:25:33 2001 +0000 +++ b/src/prpl.h Wed Aug 22 21:11:58 2001 +0000 @@ -54,6 +54,8 @@ #define OPT_PROTO_CHAT_TOPIC 0x00000008 /* IRC and Zephyr don't require passwords, so there's no need for a password prompt */ #define OPT_PROTO_NO_PASSWORD 0x00000010 +/* MSN and Yahoo notify you when you have new mail */ +#define OPT_PROTO_MAIL_CHECK 0x00000020 #define GAIM_AWAY_CUSTOM "Custom" @@ -150,6 +152,8 @@ void do_ask_dialog(const char *, void *, void *, void *); void do_prompt_dialog(const char *, void *, void *, void *); +void connection_has_mail(struct gaim_connection *, int, const char *, const char *); + /* UI for file transfer */ #define FT_EXIST_DNE 0 #define FT_EXIST_OVERWRITE 1