Mercurial > pidgin
changeset 5437:0031a613a87d
[gaim-migrate @ 5819]
These are important.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 18 May 2003 19:59:43 +0000 |
parents | ad445074d239 |
children | 6e7ba9efd1f4 |
files | src/gtknotify.c src/gtknotify.h src/notify.c src/notify.h |
diffstat | 4 files changed, 543 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtknotify.c Sun May 18 19:59:43 2003 +0000 @@ -0,0 +1,130 @@ +/** + * @file gtknotify.c GTK+ Notification API + * @ingroup gtkui + * + * gaim + * + * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "gtknotify.h" +#include "stock.h" +#include <gtk/gtk.h> + +static void * +gaim_gtk_notify_message(GaimNotifyMsgType type, const char *title, + const char *primary, const char *secondary, + GCallback cb, void *user_data) +{ + GtkWidget *dialog; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *img = NULL; + char label_text[2048]; + const char *icon_name = NULL; + + switch (type) { + case GAIM_NOTIFY_MSG_ERROR: + icon_name = GAIM_STOCK_DIALOG_ERROR; + break; + + case GAIM_NOTIFY_MSG_WARNING: + icon_name = GAIM_STOCK_DIALOG_WARNING; + break; + + case GAIM_NOTIFY_MSG_INFO: + icon_name = GAIM_STOCK_DIALOG_INFO; + break; + + default: + icon_name = NULL; + break; + } + + if (icon_name != NULL) { + img = gtk_image_new_from_stock(icon_name, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(img), 0, 0); + } + + dialog = gtk_dialog_new_with_buttons("", NULL, 0, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + g_signal_connect(G_OBJECT(dialog), "response", + G_CALLBACK(gtk_widget_destroy), NULL); + + gtk_container_set_border_width(GTK_CONTAINER(dialog), 6); + gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); + gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 12); + gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 6); + + hbox = gtk_hbox_new(FALSE, 12); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox); + + if (img != NULL) + gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); + + g_snprintf(label_text, sizeof(label_text), + "<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", + primary, (secondary ? secondary : "")); + + label = gtk_label_new(NULL); + + gtk_label_set_markup(GTK_LABEL(label), label_text); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + + gtk_widget_show_all(dialog); + + return dialog; +} + +static void * +gaim_gtk_notify_email(const char *subject, const char *from, + const char *to, const char *url, + GCallback cb, void *user_data) +{ + return NULL; +} + +static void * +gaim_gtk_notify_emails(size_t count, const char **subjects, + const char **froms, const char **tos, + const char **urls, GCallback cb, void *user_data) +{ + return NULL; +} + +static void +gaim_gtk_close_notify(GaimNotifyType type, void *ptr) +{ + gtk_widget_destroy(GTK_WIDGET(ptr)); +} + +static GaimNotifyUiOps ops = +{ + gaim_gtk_notify_message, + gaim_gtk_notify_email, + gaim_gtk_notify_emails, + gaim_gtk_close_notify +}; + +GaimNotifyUiOps * +gaim_get_gtk_notify_ui_ops(void) +{ + return &ops; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtknotify.h Sun May 18 19:59:43 2003 +0000 @@ -0,0 +1,35 @@ +/** + * @file gtknotify.h GTK+ Notification API + * @ingroup gtkui + * + * gaim + * + * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _GAIM_GTK_NOTIFY_H_ +#define _GAIM_GTK_NOTIFY_H_ + +#include "notify.h" + +/** + * Returns the UI operations structure for GTK+ notification functions. + * + * @return The GTK+ UI notify operations structure. + */ +GaimNotifyUiOps *gaim_get_gtk_notify_ui_ops(void); + +#endif /* _GAIM_GTK_NOTIFY_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/notify.c Sun May 18 19:59:43 2003 +0000 @@ -0,0 +1,181 @@ +/** + * @file notify.c Notification API + * @ingroup core + * + * gaim + * + * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "notify.h" + +static GaimNotifyUiOps *notify_ui_ops = NULL; +static GList *handles = NULL; + +typedef struct +{ + GaimNotifyType type; + void *handle; + void *ptr; + +} GaimNotifyInfo; + +void * +gaim_notify_message(void *handle, GaimNotifyType type, + const char *title, const char *primary, + const char *secondary, GCallback cb, void *user_data) +{ + GaimNotifyUiOps *ops; + + g_return_val_if_fail(primary != NULL, NULL); + + ops = gaim_get_notify_ui_ops(); + + if (ops != NULL && ops->notify_message != NULL) { + GaimNotifyInfo *info; + + info = g_new0(GaimNotifyInfo, 1); + info->type = GAIM_NOTIFY_MESSAGE; + info->handle = handle; + info->ptr = ops->notify_message(type, title, primary, secondary, + cb, user_data); + + handles = g_list_append(handles, info); + + return info->ptr; + } + + return NULL; +} + +void * +gaim_notify_email(void *handle, const char *subject, const char *from, + const char *to, const char *url, GCallback cb, + void *user_data) +{ + GaimNotifyUiOps *ops; + + ops = gaim_get_notify_ui_ops(); + + if (ops != NULL && ops->notify_email != NULL) { + GaimNotifyInfo *info; + + info = g_new0(GaimNotifyInfo, 1); + info->type = GAIM_NOTIFY_EMAIL; + info->handle = handle; + info->ptr = ops->notify_email(subject, from, to, url, cb, + user_data); + + handles = g_list_append(handles, info); + + return info->ptr; + } + + return NULL; +} + +void * +gaim_notify_emails(void *handle, size_t count, const char **subjects, + const char **froms, const char **tos, const char **urls, + GCallback cb, void *user_data) +{ + GaimNotifyUiOps *ops; + + g_return_val_if_fail(count != 0, NULL); + + ops = gaim_get_notify_ui_ops(); + + if (ops != NULL && ops->notify_emails != NULL) { + GaimNotifyInfo *info; + + info = g_new0(GaimNotifyInfo, 1); + info->type = GAIM_NOTIFY_EMAILS; + info->handle = handle; + info->ptr = ops->notify_emails(count, subjects, froms, tos, urls, + cb, user_data); + + handles = g_list_append(handles, info); + + return info->ptr; + } + + return NULL; +} + +void +gaim_notify_close(GaimNotifyType type, void *ptr) +{ + GList *l; + GaimNotifyUiOps *ops; + + g_return_if_fail(ptr != NULL); + + ops = gaim_get_notify_ui_ops(); + + for (l = handles; l != NULL; l = l->next) { + GaimNotifyInfo *info = l->data; + + if (info->ptr == ptr) { + handles = g_list_remove(handles, info); + + if (ops != NULL && ops->close_notify != NULL) + ops->close_notify(info->type, ptr); + + g_free(info); + + break; + } + } +} + +void +gaim_notify_close_with_handle(void *handle) +{ + GList *l, *l_next; + GaimNotifyUiOps *ops; + + g_return_if_fail(handle != NULL); + + ops = gaim_get_notify_ui_ops(); + + for (l = handles; l != NULL; l = l_next) { + GaimNotifyInfo *info = l->data; + + l_next = l->next; + + if (info->handle == handle) { + handles = g_list_remove(handles, info); + + if (ops != NULL && ops->close_notify != NULL) + ops->close_notify(info->type, info->ptr); + + g_free(info); + } + } +} + +void +gaim_set_notify_ui_ops(GaimNotifyUiOps *ops) +{ + notify_ui_ops = ops; +} + +GaimNotifyUiOps * +gaim_get_notify_ui_ops(void) +{ + return notify_ui_ops; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/notify.h Sun May 18 19:59:43 2003 +0000 @@ -0,0 +1,197 @@ +/** + * @file notify.h Notification API + * @ingroup core + * + * gaim + * + * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _GAIM_NOTIFY_H_ +#define _GAIM_NOTIFY_H_ + +#include <stdlib.h> +#include <glib-object.h> +#include <glib.h> + +/** + * Notification types. + */ +typedef enum +{ + GAIM_NOTIFY_MESSAGE = 0, /**< Message notification. */ + GAIM_NOTIFY_EMAIL, /**< Single e-mail notification. */ + GAIM_NOTIFY_EMAILS /**< Multiple e-mail notification. */ + +} GaimNotifyType; + +/** + * Notification message types. + */ +typedef enum +{ + GAIM_NOTIFY_MSG_ERROR = 0, /**< Error notification. */ + GAIM_NOTIFY_MSG_WARNING, /**< Warning notification. */ + GAIM_NOTIFY_MSG_INFO /**< Information notification. */ + +} GaimNotifyMsgType; + +/** + * Notification UI operations. + */ +typedef struct +{ + void *(*notify_message)(GaimNotifyMsgType type, const char *title, + const char *primary, const char *secondary, + GCallback cb, void *user_data); + void *(*notify_email)(const char *subject, const char *from, + const char *to, const char *url, + GCallback cb, void *user_data); + void *(*notify_emails)(size_t count, const char **subjects, + const char **froms, const char **tos, + const char **urls, GCallback cb, + void *user_data); + + void (*close_notify)(GaimNotifyType type, void *uihandle); + +} GaimNotifyUiOps; + +/**************************************************************************/ +/** @name Notification API */ +/**************************************************************************/ +/*@{*/ + +/** + * Displays a notification message to the user. + * + * @param handle The plugin or connection handle. + * @param type The notification type. + * @param title The title of the message. + * @param primary The main point of the message. + * @param secondary The secondary information. + * @param cb The callback to call when the user closes + * the notification. + * @param user_data The data to pass to the callback. + * + * @return A UI-specific handle. + */ +void *gaim_notify_message(void *handle, GaimNotifyType type, + const char *title, const char *primary, + const char *secondary, GCallback cb, + void *user_data); + +/** + * Displays a single e-mail notification to the user. + * + * @param handle The plugin or connection handle. + * @param subject The subject of the e-mail. + * @param from The from address. + * @param to The destination address. + * @param url The URL where the message can be read. + * @param cb The callback to call when the user closes + * the notification. + * @param user_data The data to pass to the callback. + * + * @return A UI-specific handle. + */ +void *gaim_notify_email(void *handle, const char *subject, + const char *from, const char *to, + const char *url, GCallback cb, + void *user_data); + +/** + * Displays a notification for multiple e-mails to the user. + * + * @param handle The plugin or connection handle. + * @param count The number of e-mails. + * @param subjects The array of subjects. + * @param froms The array of from addresses. + * @param tos The array of destination addresses. + * @param url The URLs where the messages can be read. + * @param cb The callback to call when the user closes + * the notification. + * @param user_data The data to pass to the callback. + * + * @return A UI-specific handle. + */ +void *gaim_notify_emails(void *handle, size_t count, + const char **subjects, const char **froms, + const char **tos, const char **urls, + GCallback cb, void *user_data); + +/** + * Closes a notification. + * + * This should be used only by the UI operation functions and part of the + * core. + * + * @param type The notification type. + * @param uihandle The notification UI handle. + */ +void gaim_notify_close(GaimNotifyType type, void *uihandle); + +/** + * Closes all notifications registered with the specified handle. + * + * @param handle The handle. + */ +void gaim_notify_close_with_handle(void *handle); + +/** + * A wrapper for gaim_notify_message that displays an information message. + */ +#define gaim_notify_info(handle, title, primary, secondary) \ + gaim_notify_message((handle), GAIM_NOTIFY_MSG_INFO, (title), \ + (primary), (secondary), NULL, NULL) + +/** + * A wrapper for gaim_notify_message that displays a warning message. + */ +#define gaim_notify_warning(handle, title, primary, secondary) \ + gaim_notify_message((handle), GAIM_NOTIFY_MSG_WARNING, (title), \ + (primary), (secondary), NULL, NULL) + +/** + * A wrapper for gaim_notify_message that displays an error message. + */ +#define gaim_notify_error(handle, title, primary, secondary) \ + gaim_notify_message((handle), GAIM_NOTIFY_MSG_ERROR, (title), \ + (primary), (secondary), NULL, NULL) + +/*@}*/ + +/**************************************************************************/ +/** @name UI Operations API */ +/**************************************************************************/ +/*@{*/ + +/** + * Sets the UI operations structure to be used when displaying a + * notification. + * + * @param ops The UI operations structure. + */ +void gaim_set_notify_ui_ops(GaimNotifyUiOps *ops); + +/** + * Returns the UI operations structure to be used when displaying a + * notification. + * + * @param ops The UI operations structure. + */ +GaimNotifyUiOps *gaim_get_notify_ui_ops(void); + +#endif /* _GAIM_NOTIFY_H_ */