comparison src/prpl.c @ 5538:f7dc3f656f03

[gaim-migrate @ 5938] No more connection_has_mail()! committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 27 May 2003 08:09:10 +0000
parents cce2d7868c78
children 9eb5b13fd412
comparison
equal deleted inserted replaced
5537:3becf79500d2 5538:f7dc3f656f03
201 act = g_list_next(act); 201 act = g_list_next(act);
202 } 202 }
203 c = g_slist_next(c); 203 c = g_slist_next(c);
204 } 204 }
205 } 205 }
206 }
207
208 struct mail_notify {
209 struct gaim_connection *gc;
210 GtkWidget *email_win;
211 GtkWidget *email_label;
212 char *url;
213 };
214 GSList *mailnots = NULL;
215
216 static struct mail_notify *find_mail_notify(struct gaim_connection *gc)
217 {
218 GSList *m = mailnots;
219 while (m) {
220 if (((struct mail_notify *)m->data)->gc == gc)
221 return m->data;
222 m = m->next;
223 }
224 return NULL;
225 }
226
227 static void des_email_win(GtkWidget *w, struct mail_notify *mn)
228 {
229 if (w != mn->email_win) {
230 gtk_widget_destroy(mn->email_win);
231 return;
232 }
233
234 gaim_debug(GAIM_DEBUG_INFO, "prpl", "Removing mail notification.\n");
235
236 mailnots = g_slist_remove(mailnots, mn);
237 if (mn->url)
238 g_free(mn->url);
239 g_free(mn);
240 }
241
242 void connection_has_mail(struct gaim_connection *gc, int count, const char *from, const char *subject, const char *url)
243 {
244 GtkWidget *hbox;
245 GtkWidget *vbox;
246 GtkWidget *urlbut;
247 GtkWidget *close;
248
249 struct mail_notify *mn;
250 char buf[2048];
251
252 if (!(gc->account->options & OPT_ACCT_MAIL_CHECK))
253 return;
254
255 if (!(mn = find_mail_notify(gc))) {
256 mn = g_new0(struct mail_notify, 1);
257 mn->gc = gc;
258 mailnots = g_slist_append(mailnots, mn);
259 }
260
261 if (count < 0) {
262 if (from && subject)
263 g_snprintf(buf, sizeof buf, _("%s has mail from %s: %s"), gc->username, from, *subject ? subject : _("No Subject"));
264 else
265 g_snprintf(buf, sizeof buf, _("%s has new mail."), gc->username);
266 } else if (count > 0) {
267 g_snprintf(buf, sizeof buf,
268 ngettext("%s has %d new message.","%s has %d new messages.",count), gc->username, count);
269 } else if (mn->email_win) {
270 gtk_widget_destroy(mn->email_win);
271 return;
272 } else
273 return;
274
275 if (mn->email_win) {
276 gtk_label_set_text(GTK_LABEL(mn->email_label), buf);
277 return;
278 }
279
280
281 GAIM_DIALOG(mn->email_win);
282 gtk_window_set_role(GTK_WINDOW(mn->email_win), "mail");
283 gtk_window_set_resizable(GTK_WINDOW(mn->email_win), TRUE);
284 gtk_window_set_title(GTK_WINDOW(mn->email_win), _("Gaim - New Mail"));
285 g_signal_connect(G_OBJECT(mn->email_win), "destroy",
286 G_CALLBACK(des_email_win), mn);
287 gtk_widget_realize(mn->email_win);
288
289 vbox = gtk_vbox_new(FALSE, 5);
290 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
291 gtk_container_add(GTK_CONTAINER(mn->email_win), vbox);
292
293 mn->email_label = gtk_label_new(buf);
294 gtk_label_set_text(GTK_LABEL(mn->email_label), buf);
295 gtk_label_set_line_wrap(GTK_LABEL(mn->email_label), TRUE);
296 gtk_box_pack_start(GTK_BOX(vbox), mn->email_label, FALSE, TRUE, 5);
297
298 hbox = gtk_hbox_new(FALSE, 5);
299 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
300
301 if (url) {
302 mn->url = g_strdup(url);
303 urlbut = gaim_pixbuf_button_from_stock(_("Open Mail"), GTK_STOCK_JUMP_TO, GAIM_BUTTON_HORIZONTAL);
304 gtk_box_pack_end(GTK_BOX(hbox), urlbut, 0, 0, 5);
305 g_signal_connect(G_OBJECT(urlbut), "clicked",
306 G_CALLBACK(open_url), mn->url);
307 g_signal_connect(G_OBJECT(urlbut), "clicked",
308 G_CALLBACK(des_email_win), mn);
309 }
310
311 close = gaim_pixbuf_button_from_stock(_("Close"), GTK_STOCK_CLOSE, GAIM_BUTTON_HORIZONTAL);
312 gtk_window_set_focus(GTK_WINDOW(mn->email_win), close);
313 gtk_box_pack_end(GTK_BOX(hbox), close, 0, 0, 5);
314 g_signal_connect(G_OBJECT(close), "clicked",
315 G_CALLBACK(des_email_win), mn);
316
317 gtk_widget_show_all(mn->email_win);
318 } 206 }
319 207
320 struct icon_data { 208 struct icon_data {
321 struct gaim_connection *gc; 209 struct gaim_connection *gc;
322 char *who; 210 char *who;