Sun, 25 May 2003 13:41:02 +0000
[gaim-migrate @ 5910]
I think this is better
| 5437 | 1 | /** |
| 2 | * @file gtknotify.c GTK+ Notification API | |
| 3 | * @ingroup gtkui | |
| 4 | * | |
| 5 | * gaim | |
| 6 | * | |
| 7 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 8 | * | |
| 9 | * This program is free software; you can redistribute it and/or modify | |
| 10 | * it under the terms of the GNU General Public License as published by | |
| 11 | * the Free Software Foundation; either version 2 of the License, or | |
| 12 | * (at your option) any later version. | |
| 13 | * | |
| 14 | * This program is distributed in the hope that it will be useful, | |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | * GNU General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with this program; if not, write to the Free Software | |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 22 | */ | |
| 23 | #include "gtknotify.h" | |
| 24 | #include "stock.h" | |
| 25 | #include <gtk/gtk.h> | |
| 26 | ||
|
5476
6f863ea68018
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
27 | static void *gaim_gtk_notify_emails(size_t count, const char **subjects, |
|
6f863ea68018
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
28 | const char **froms, const char **tos, |
|
6f863ea68018
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
29 | const char **urls, GCallback cb, |
|
6f863ea68018
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
30 | void *user_data); |
|
6f863ea68018
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
31 | |
| 5437 | 32 | static void * |
| 33 | gaim_gtk_notify_message(GaimNotifyMsgType type, const char *title, | |
| 34 | const char *primary, const char *secondary, | |
| 35 | GCallback cb, void *user_data) | |
| 36 | { | |
| 37 | GtkWidget *dialog; | |
| 38 | GtkWidget *hbox; | |
| 39 | GtkWidget *label; | |
| 40 | GtkWidget *img = NULL; | |
| 41 | char label_text[2048]; | |
| 42 | const char *icon_name = NULL; | |
| 43 | ||
| 44 | switch (type) { | |
| 45 | case GAIM_NOTIFY_MSG_ERROR: | |
| 46 | icon_name = GAIM_STOCK_DIALOG_ERROR; | |
| 47 | break; | |
| 48 | ||
| 49 | case GAIM_NOTIFY_MSG_WARNING: | |
| 50 | icon_name = GAIM_STOCK_DIALOG_WARNING; | |
| 51 | break; | |
| 52 | ||
| 53 | case GAIM_NOTIFY_MSG_INFO: | |
| 54 | icon_name = GAIM_STOCK_DIALOG_INFO; | |
| 55 | break; | |
| 56 | ||
| 57 | default: | |
| 58 | icon_name = NULL; | |
| 59 | break; | |
| 60 | } | |
| 61 | ||
| 62 | if (icon_name != NULL) { | |
| 63 | img = gtk_image_new_from_stock(icon_name, GTK_ICON_SIZE_DIALOG); | |
| 64 | gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
| 65 | } | |
| 66 | ||
| 67 | dialog = gtk_dialog_new_with_buttons("", NULL, 0, | |
| 68 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, | |
| 69 | NULL); | |
| 70 | g_signal_connect(G_OBJECT(dialog), "response", | |
| 71 | G_CALLBACK(gtk_widget_destroy), NULL); | |
| 72 | ||
| 73 | gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); | |
| 74 | gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | |
| 75 | gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | |
| 76 | gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12); | |
| 77 | gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6); | |
| 78 | ||
| 79 | hbox = gtk_hbox_new(FALSE, 12); | |
| 80 | gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); | |
| 81 | ||
| 82 | if (img != NULL) | |
| 83 | gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
| 84 | ||
| 85 | g_snprintf(label_text, sizeof(label_text), | |
| 86 | "<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", | |
| 87 | primary, (secondary ? secondary : "")); | |
| 88 | ||
| 89 | label = gtk_label_new(NULL); | |
| 90 | ||
| 91 | gtk_label_set_markup(GTK_LABEL(label), label_text); | |
| 92 | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 93 | gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
| 94 | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
| 95 | ||
| 96 | gtk_widget_show_all(dialog); | |
| 97 | ||
| 98 | return dialog; | |
| 99 | } | |
| 100 | ||
| 101 | static void * | |
| 102 | gaim_gtk_notify_email(const char *subject, const char *from, | |
| 103 | const char *to, const char *url, | |
| 104 | GCallback cb, void *user_data) | |
| 105 | { | |
|
5476
6f863ea68018
[gaim-migrate @ 5872]
Christian Hammond <chipx86@chipx86.com>
parents:
5437
diff
changeset
|
106 | return gaim_gtk_notify_emails(1, &subject, &from, &to, &url, cb, user_data); |
| 5437 | 107 | } |
| 108 | ||
| 109 | static void * | |
| 110 | gaim_gtk_notify_emails(size_t count, const char **subjects, | |
| 111 | const char **froms, const char **tos, | |
| 112 | const char **urls, GCallback cb, void *user_data) | |
| 113 | { | |
| 114 | return NULL; | |
| 115 | } | |
| 116 | ||
| 117 | static void | |
| 118 | gaim_gtk_close_notify(GaimNotifyType type, void *ptr) | |
| 119 | { | |
| 120 | gtk_widget_destroy(GTK_WIDGET(ptr)); | |
| 121 | } | |
| 122 | ||
| 123 | static GaimNotifyUiOps ops = | |
| 124 | { | |
| 125 | gaim_gtk_notify_message, | |
| 126 | gaim_gtk_notify_email, | |
| 127 | gaim_gtk_notify_emails, | |
| 128 | gaim_gtk_close_notify | |
| 129 | }; | |
| 130 | ||
| 131 | GaimNotifyUiOps * | |
| 132 | gaim_get_gtk_notify_ui_ops(void) | |
| 133 | { | |
| 134 | return &ops; | |
| 135 | } |