| 126 } PidginNotifyType; |
126 } PidginNotifyType; |
| 127 |
127 |
| 128 static PidginNotifyDialog *mail_dialog = NULL; |
128 static PidginNotifyDialog *mail_dialog = NULL; |
| 129 static PidginNotifyDialog *pounce_dialog = NULL; |
129 static PidginNotifyDialog *pounce_dialog = NULL; |
| 130 |
130 |
| 131 static PidginNotifyDialog *pidgin_get_notification_dialog(PidginNotifyType type); |
131 static PidginNotifyDialog *pidgin_create_notification_dialog(PidginNotifyType type); |
| 132 static void *pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed, |
132 static void *pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed, |
| 133 const char **subjects, |
133 const char **subjects, |
| 134 const char **froms, const char **tos, |
134 const char **froms, const char **tos, |
| 135 const char **urls); |
135 const char **urls); |
| 136 |
136 |
| 304 g_free(mail_dialog); |
304 g_free(mail_dialog); |
| 305 mail_dialog = NULL; |
305 mail_dialog = NULL; |
| 306 } |
306 } |
| 307 |
307 |
| 308 static void |
308 static void |
| 309 email_response_cb(GtkDialog *dlg, gint id, PidginNotifyDialog *dialog) |
309 email_response_cb(GtkDialog *unused, gint id, PidginNotifyDialog *unused2) |
| 310 { |
310 { |
| 311 PidginNotifyMailData *data = NULL; |
311 PidginNotifyMailData *data = NULL; |
| |
312 GtkTreeModel *model = GTK_TREE_MODEL(mail_dialog->treemodel); |
| 312 GtkTreeIter iter; |
313 GtkTreeIter iter; |
| 313 |
314 |
| 314 if (id == GTK_RESPONSE_YES) |
315 if (id == GTK_RESPONSE_YES) |
| 315 { |
316 { |
| 316 /* A single row activated. Remove that row. */ |
317 /* A single row activated. Remove that row. */ |
| 317 GtkTreeSelection *selection; |
318 GtkTreeSelection *selection; |
| 318 |
319 |
| 319 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); |
320 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mail_dialog->treeview)); |
| 320 |
321 |
| 321 if (gtk_tree_selection_get_selected(selection, NULL, &iter)) |
322 if (gtk_tree_selection_get_selected(selection, NULL, &iter)) |
| 322 { |
323 { |
| 323 gtk_tree_model_get(GTK_TREE_MODEL(dialog->treemodel), &iter, |
324 gtk_tree_model_get(model, &iter, PIDGIN_MAIL_DATA, &data, -1); |
| 324 PIDGIN_MAIL_DATA, &data, -1); |
|
| 325 purple_notify_uri(NULL, data->url); |
325 purple_notify_uri(NULL, data->url); |
| 326 |
326 |
| 327 gtk_tree_store_remove(dialog->treemodel, &iter); |
327 gtk_tree_store_remove(mail_dialog->treemodel, &iter); |
| 328 if (data->purple_has_handle) |
328 if (data->purple_has_handle) |
| 329 purple_notify_close(PURPLE_NOTIFY_EMAILS, data); |
329 purple_notify_close(PURPLE_NOTIFY_EMAILS, data); |
| 330 else |
330 else |
| 331 pidgin_close_notify(PURPLE_NOTIFY_EMAILS, data); |
331 pidgin_close_notify(PURPLE_NOTIFY_EMAILS, data); |
| 332 |
332 |
| 333 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mail_dialog->treemodel), &iter)) |
333 if (gtk_tree_model_get_iter_first(model, &iter)) |
| 334 return; |
334 return; |
| 335 } |
335 } |
| 336 else |
336 else |
| 337 return; |
337 return; |
| 338 } |
338 } |
| 339 else |
339 else |
| 340 { |
340 { |
| 341 /* Remove all the rows */ |
341 /* Remove all the rows */ |
| 342 while (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mail_dialog->treemodel), &iter)) |
342 while (gtk_tree_model_get_iter_first(model, &iter)) |
| 343 { |
343 { |
| 344 gtk_tree_model_get(GTK_TREE_MODEL(dialog->treemodel), &iter, |
344 gtk_tree_model_get(model, &iter, PIDGIN_MAIL_DATA, &data, -1); |
| 345 PIDGIN_MAIL_DATA, &data, -1); |
|
| 346 |
345 |
| 347 if (id == GTK_RESPONSE_ACCEPT) |
346 if (id == GTK_RESPONSE_ACCEPT) |
| 348 purple_notify_uri(NULL, data->url); |
347 purple_notify_uri(NULL, data->url); |
| 349 |
348 |
| 350 gtk_tree_store_remove(dialog->treemodel, &iter); |
349 gtk_tree_store_remove(mail_dialog->treemodel, &iter); |
| 351 if (data->purple_has_handle) |
350 if (data->purple_has_handle) |
| 352 purple_notify_close(PURPLE_NOTIFY_EMAILS, data); |
351 purple_notify_close(PURPLE_NOTIFY_EMAILS, data); |
| 353 else |
352 else |
| 354 pidgin_close_notify(PURPLE_NOTIFY_EMAILS, data); |
353 pidgin_close_notify(PURPLE_NOTIFY_EMAILS, data); |
| 355 } |
354 } |
| 356 } |
355 } |
| 357 |
356 |
| 358 reset_mail_dialog(NULL); |
357 reset_mail_dialog(NULL); |
| 359 } |
358 } |
| 360 |
359 |
| 361 static void email_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { |
360 static void |
| 362 email_response_cb(GTK_DIALOG(mail_dialog->dialog), GTK_RESPONSE_YES, mail_dialog); |
361 email_row_activated_cb(GtkTreeView *tv, GtkTreePath *path, |
| |
362 GtkTreeViewColumn *col, gpointer data) |
| |
363 { |
| |
364 email_response_cb(NULL, GTK_RESPONSE_YES, NULL); |
| 363 } |
365 } |
| 364 |
366 |
| 365 static gboolean |
367 static gboolean |
| 366 formatted_close_cb(GtkWidget *win, GdkEvent *event, void *user_data) |
368 formatted_close_cb(GtkWidget *win, GdkEvent *event, void *user_data) |
| 367 { |
369 { |
| 609 static void * |
611 static void * |
| 610 pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed, |
612 pidgin_notify_emails(PurpleConnection *gc, size_t count, gboolean detailed, |
| 611 const char **subjects, const char **froms, |
613 const char **subjects, const char **froms, |
| 612 const char **tos, const char **urls) |
614 const char **tos, const char **urls) |
| 613 { |
615 { |
| 614 PidginNotifyDialog *notification_dialog; |
|
| 615 GtkWidget *dialog; |
|
| 616 char *notification; |
616 char *notification; |
| 617 PurpleAccount *account; |
617 PurpleAccount *account; |
| 618 PidginNotifyMailData *data = NULL, *data2; |
618 PidginNotifyMailData *data = NULL, *data2; |
| 619 gboolean new_data = FALSE; |
619 gboolean new_data = FALSE; |
| 620 |
620 |
| 621 /* Don't bother updating if there aren't new emails and we don't have any displayed currently */ |
621 /* Don't bother updating if there aren't new emails and we don't have any displayed currently */ |
| 622 if (count == 0 && mail_dialog == NULL) |
622 if (count == 0 && mail_dialog == NULL) |
| 623 return NULL; |
623 return NULL; |
| 624 |
624 |
| 625 account = purple_connection_get_account(gc); |
625 account = purple_connection_get_account(gc); |
| 626 /* This creates the mail dialog (mail_dialog) if necessary */ |
626 if (mail_dialog == NULL) |
| 627 notification_dialog = pidgin_get_notification_dialog(PIDGIN_NOTIFY_MAIL); |
627 mail_dialog = pidgin_create_notification_dialog(PIDGIN_NOTIFY_MAIL); |
| 628 dialog = notification_dialog->dialog; |
|
| 629 |
628 |
| 630 mail_dialog->total_count += count; |
629 mail_dialog->total_count += count; |
| 631 if (detailed) { |
630 if (detailed) { |
| 632 for ( ; count; --count) { |
631 for ( ; count; --count) { |
| 633 char *to_text = NULL; |
632 char *to_text = NULL; |
| 702 return NULL; |
701 return NULL; |
| 703 } |
702 } |
| 704 } |
703 } |
| 705 } |
704 } |
| 706 |
705 |
| 707 if (!GTK_WIDGET_VISIBLE(dialog)) { |
706 if (!GTK_WIDGET_VISIBLE(mail_dialog->dialog)) { |
| 708 GdkPixbuf *pixbuf = gtk_widget_render_icon(dialog, PIDGIN_STOCK_DIALOG_MAIL, |
707 GdkPixbuf *pixbuf = gtk_widget_render_icon(mail_dialog->dialog, PIDGIN_STOCK_DIALOG_MAIL, |
| 709 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL), NULL); |
708 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_EXTRA_SMALL), NULL); |
| 710 char *label_text = g_strdup_printf(ngettext("<b>%d new email.</b>", |
709 char *label_text = g_strdup_printf(ngettext("<b>%d new email.</b>", |
| 711 "<b>%d new emails.</b>", |
710 "<b>%d new emails.</b>", |
| 712 mail_dialog->total_count), mail_dialog->total_count); |
711 mail_dialog->total_count), mail_dialog->total_count); |
| 713 mail_dialog->in_use = TRUE; /* So that _set_headline doesn't accidentally |
712 mail_dialog->in_use = TRUE; /* So that _set_headline doesn't accidentally |
| 714 remove the notifications when replacing an |
713 remove the notifications when replacing an |
| 715 old notification. */ |
714 old notification. */ |
| 716 pidgin_blist_set_headline(label_text, |
715 pidgin_blist_set_headline(label_text, |
| 717 pixbuf, G_CALLBACK(gtk_widget_show_all), dialog, |
716 pixbuf, G_CALLBACK(gtk_widget_show_all), mail_dialog->dialog, |
| 718 (GDestroyNotify)reset_mail_dialog); |
717 (GDestroyNotify)reset_mail_dialog); |
| 719 mail_dialog->in_use = FALSE; |
718 mail_dialog->in_use = FALSE; |
| 720 g_free(label_text); |
719 g_free(label_text); |
| 721 if (pixbuf) |
720 if (pixbuf) |
| 722 g_object_unref(pixbuf); |
721 g_object_unref(pixbuf); |
| 723 } else if (!GTK_WIDGET_HAS_FOCUS(dialog)) |
722 } else if (!GTK_WIDGET_HAS_FOCUS(mail_dialog->dialog)) |
| 724 pidgin_set_urgent(GTK_WINDOW(dialog), TRUE); |
723 pidgin_set_urgent(GTK_WINDOW(mail_dialog->dialog), TRUE); |
| 725 |
724 |
| 726 return data; |
725 return data; |
| 727 } |
726 } |
| 728 |
727 |
| 729 static gboolean |
728 static gboolean |
| 1347 |
1346 |
| 1348 void |
1347 void |
| 1349 pidgin_notify_pounce_add(PurpleAccount *account, PurplePounce *pounce, |
1348 pidgin_notify_pounce_add(PurpleAccount *account, PurplePounce *pounce, |
| 1350 const char *alias, const char *event, const char *message, const char *date) |
1349 const char *alias, const char *event, const char *message, const char *date) |
| 1351 { |
1350 { |
| 1352 PidginNotifyDialog *notification_dialog; |
|
| 1353 GtkWidget *dialog; |
|
| 1354 GdkPixbuf *icon; |
1351 GdkPixbuf *icon; |
| 1355 GtkTreeIter iter; |
1352 GtkTreeIter iter; |
| 1356 PidginNotifyPounceData *pounce_data; |
1353 PidginNotifyPounceData *pounce_data; |
| 1357 |
1354 |
| 1358 notification_dialog = pidgin_get_notification_dialog(PIDGIN_NOTIFY_POUNCE); |
1355 if (pounce_dialog == NULL) |
| 1359 dialog = notification_dialog->dialog; |
1356 pounce_dialog = pidgin_create_notification_dialog(PIDGIN_NOTIFY_POUNCE); |
| 1360 |
1357 |
| 1361 icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL); |
1358 icon = pidgin_create_prpl_icon(account, PIDGIN_PRPL_ICON_SMALL); |
| 1362 |
1359 |
| 1363 pounce_data = g_new(PidginNotifyPounceData, 1); |
1360 pounce_data = g_new(PidginNotifyPounceData, 1); |
| 1364 |
1361 |
| 1399 PidginNotifyDialog *spec_dialog = NULL; |
1396 PidginNotifyDialog *spec_dialog = NULL; |
| 1400 |
1397 |
| 1401 g_return_val_if_fail(type < PIDGIN_NOTIFY_TYPES, NULL); |
1398 g_return_val_if_fail(type < PIDGIN_NOTIFY_TYPES, NULL); |
| 1402 |
1399 |
| 1403 if (type == PIDGIN_NOTIFY_MAIL) { |
1400 if (type == PIDGIN_NOTIFY_MAIL) { |
| 1404 if (mail_dialog != NULL) |
1401 g_return_val_if_fail(mail_dialog == NULL, mail_dialog); |
| 1405 return mail_dialog; |
|
| 1406 |
1402 |
| 1407 model = gtk_tree_store_new(COLUMNS_PIDGIN_MAIL, |
1403 model = gtk_tree_store_new(COLUMNS_PIDGIN_MAIL, |
| 1408 GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER); |
1404 GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER); |
| 1409 |
1405 |
| 1410 } else if (type == PIDGIN_NOTIFY_POUNCE) { |
1406 } else if (type == PIDGIN_NOTIFY_POUNCE) { |
| 1411 |
1407 g_return_val_if_fail(pounce_dialog == NULL, pounce_dialog); |
| 1412 if (pounce_dialog != NULL) |
1408 |
| 1413 return pounce_dialog; |
1409 model = gtk_tree_store_new(COLUMNS_PIDGIN_POUNCE, |
| 1414 |
|
| 1415 model = gtk_tree_store_new(PIDGIN_POUNCE_COLUMNS, |
|
| 1416 GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, |
1410 GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, |
| 1417 G_TYPE_STRING, G_TYPE_POINTER); |
1411 G_TYPE_STRING, G_TYPE_POINTER); |
| 1418 } |
1412 } |
| 1419 |
1413 |
| 1420 dialog = gtk_dialog_new_with_buttons(NULL, NULL, 0, |
1414 dialog = gtk_dialog_new_with_buttons(NULL, NULL, 0, |
| 1549 |
1543 |
| 1550 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
1544 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
| 1551 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
1545 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); |
| 1552 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
1546 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); |
| 1553 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 2); |
1547 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 2); |
| 1554 |
|
| 1555 if (type == PIDGIN_NOTIFY_MAIL) |
|
| 1556 mail_dialog = spec_dialog; |
|
| 1557 else if (type == PIDGIN_NOTIFY_POUNCE) { |
|
| 1558 pounce_dialog = spec_dialog; |
|
| 1559 } |
|
| 1560 |
1548 |
| 1561 return spec_dialog; |
1549 return spec_dialog; |
| 1562 } |
1550 } |
| 1563 |
1551 |
| 1564 static void |
1552 static void |