* @file notify.c Notification API * Gaim is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * 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 static GaimNotifyUiOps *notify_ui_ops = NULL; static GList *handles = NULL; GaimNotifyCloseCallback cb; gaim_notify_message(void *handle, GaimNotifyMsgType type, const char *title, const char *primary, const char *secondary, GaimNotifyCloseCallback cb, gpointer user_data) g_return_val_if_fail(primary != NULL, NULL); ops = gaim_notify_get_ui_ops(); if (ops != NULL && ops->notify_message != NULL) { info = g_new0(GaimNotifyInfo, 1); info->type = GAIM_NOTIFY_MESSAGE; info->ui_handle = ops->notify_message(type, title, primary, info->cb_user_data = user_data; handles = g_list_append(handles, info); gaim_notify_email(void *handle, const char *subject, const char *from, const char *to, const char *url, GaimNotifyCloseCallback cb, ops = gaim_notify_get_ui_ops(); if (ops != NULL && ops->notify_email != NULL) { info = g_new0(GaimNotifyInfo, 1); info->type = GAIM_NOTIFY_EMAIL; info->ui_handle = ops->notify_email(handle, subject, from, to, url); info->cb_user_data = user_data; handles = g_list_append(handles, info); gaim_notify_emails(void *handle, size_t count, gboolean detailed, const char **subjects, const char **froms, const char **tos, const char **urls, GaimNotifyCloseCallback cb, gpointer user_data) g_return_val_if_fail(count != 0, NULL); return gaim_notify_email(handle, (subjects == NULL ? NULL : *subjects), (froms == NULL ? NULL : *froms), (tos == NULL ? NULL : *tos), (urls == NULL ? NULL : *urls), ops = gaim_notify_get_ui_ops(); if (ops != NULL && ops->notify_emails != NULL) { info = g_new0(GaimNotifyInfo, 1); info->type = GAIM_NOTIFY_EMAILS; info->ui_handle = ops->notify_emails(handle, count, detailed, subjects, info->cb_user_data = user_data; handles = g_list_append(handles, info); gaim_notify_formatted(void *handle, const char *title, const char *primary, const char *secondary, const char *text, GaimNotifyCloseCallback cb, gpointer user_data) g_return_val_if_fail(primary != NULL, NULL); ops = gaim_notify_get_ui_ops(); if (ops != NULL && ops->notify_formatted != NULL) { info = g_new0(GaimNotifyInfo, 1); info->type = GAIM_NOTIFY_FORMATTED; info->ui_handle = ops->notify_formatted(title, primary, secondary, text); info->cb_user_data = user_data; handles = g_list_append(handles, info); gaim_notify_searchresults(GaimConnection *gc, const char *title, const char *primary, const char *secondary, GaimNotifySearchResults *results, GaimNotifyCloseCallback cb, gpointer user_data) ops = gaim_notify_get_ui_ops(); if (ops != NULL && ops->notify_searchresults != NULL) { info = g_new0(GaimNotifyInfo, 1); info->type = GAIM_NOTIFY_SEARCHRESULTS; info->ui_handle = ops->notify_searchresults(gc, title, primary, info->cb_user_data = user_data; handles = g_list_append(handles, info); gaim_notify_searchresults_free(GaimNotifySearchResults *results) g_return_if_fail(results != NULL); for (l = results->buttons; l; l = g_list_delete_link(l, l)) { GaimNotifySearchButton *button = l->data; for (l = results->rows; l; l = g_list_delete_link(l, l)) { for (; row; row = g_list_delete_link(row, row)) { for (l = results->columns; l; l = g_list_delete_link(l, l)) { GaimNotifySearchColumn *column = l->data; gaim_notify_searchresults_new_rows(GaimConnection *gc, GaimNotifySearchResults *results, void *data, gpointer user_data) ops = gaim_notify_get_ui_ops(); if (ops != NULL && ops->notify_searchresults != NULL) { ops->notify_searchresults_new_rows(gc, results, data, user_data); gaim_notify_searchresults_button_add(GaimNotifySearchResults *results, GaimNotifySearchButtonType type, GaimNotifySearchResultsCallback cb) GaimNotifySearchButton *button; g_return_if_fail(results != NULL); g_return_if_fail(cb != NULL); button = g_new0(GaimNotifySearchButton, 1); results->buttons = g_list_append(results->buttons, button); gaim_notify_searchresults_button_add_labeled(GaimNotifySearchResults *results, GaimNotifySearchResultsCallback cb) { GaimNotifySearchButton *button; g_return_if_fail(results != NULL); g_return_if_fail(cb != NULL); g_return_if_fail(label != NULL); g_return_if_fail(*label != '\0'); button = g_new0(GaimNotifySearchButton, 1); button->type = GAIM_NOTIFY_BUTTON_LABELED; button->label = g_strdup(label); results->buttons = g_list_append(results->buttons, button); GaimNotifySearchResults * gaim_notify_searchresults_new() GaimNotifySearchResults *rs = g_new0(GaimNotifySearchResults, 1); gaim_notify_searchresults_column_add(GaimNotifySearchResults *results, GaimNotifySearchColumn *column) g_return_if_fail(results != NULL); g_return_if_fail(column != NULL); results->columns = g_list_append(results->columns, column); void gaim_notify_searchresults_row_add(GaimNotifySearchResults *results, g_return_if_fail(results != NULL); g_return_if_fail(row != NULL); results->rows = g_list_append(results->rows, row); gaim_notify_searchresults_column_new(const char *title) GaimNotifySearchColumn *sc; g_return_val_if_fail(title != NULL, NULL); sc = g_new0(GaimNotifySearchColumn, 1); sc->title = g_strdup(title); gaim_notify_searchresults_get_columns_count(GaimNotifySearchResults *results) g_return_val_if_fail(results != NULL, 0); return g_list_length(results->columns); gaim_notify_searchresults_get_rows_count(GaimNotifySearchResults *results) g_return_val_if_fail(results != NULL, 0); return g_list_length(results->rows); gaim_notify_searchresults_column_get_title(GaimNotifySearchResults *results, g_return_val_if_fail(results != NULL, NULL); return ((GaimNotifySearchColumn *)g_list_nth_data(results->columns, column_id))->title; gaim_notify_searchresults_row_get(GaimNotifySearchResults *results, g_return_val_if_fail(results != NULL, NULL); return g_list_nth_data(results->rows, row_id); gaim_notify_userinfo(GaimConnection *gc, const char *who, const char *text, GaimNotifyCloseCallback cb, gpointer user_data) g_return_val_if_fail(who != NULL, NULL); ops = gaim_notify_get_ui_ops(); if (ops != NULL && ops->notify_userinfo != NULL) { char *infotext = g_strdup(text); info = g_new0(GaimNotifyInfo, 1); info->type = GAIM_NOTIFY_USERINFO; gaim_signal_emit(gaim_notify_get_handle(), "displaying-userinfo", gaim_connection_get_account(gc), who, &infotext); info->ui_handle = ops->notify_userinfo(gc, who, infotext); info->cb_user_data = user_data; handles = g_list_append(handles, info); gaim_notify_uri(void *handle, const char *uri) g_return_val_if_fail(uri != NULL, NULL); ops = gaim_notify_get_ui_ops(); if (ops != NULL && ops->notify_uri != NULL) { info = g_new0(GaimNotifyInfo, 1); info->type = GAIM_NOTIFY_URI; info->ui_handle = ops->notify_uri(uri); handles = g_list_append(handles, info); gaim_notify_close(GaimNotifyType type, void *ui_handle) g_return_if_fail(ui_handle != NULL); ops = gaim_notify_get_ui_ops(); for (l = handles; l != NULL; l = l->next) { GaimNotifyInfo *info = l->data; if (info->ui_handle == ui_handle) { handles = g_list_remove(handles, info); if (ops != NULL && ops->close_notify != NULL) ops->close_notify(info->type, ui_handle); info->cb(info->cb_user_data); gaim_notify_close_with_handle(void *handle) g_return_if_fail(handle != NULL); ops = gaim_notify_get_ui_ops(); for (l = handles; l != NULL; l = l_next) { GaimNotifyInfo *info = l->data; if (info->handle == handle) { handles = g_list_remove(handles, info); if (ops != NULL && ops->close_notify != NULL) ops->close_notify(info->type, info->ui_handle); info->cb(info->cb_user_data); gaim_notify_set_ui_ops(GaimNotifyUiOps *ops) gaim_notify_get_ui_ops(void) gaim_notify_get_handle(void) gpointer handle = gaim_notify_get_handle(); gaim_signal_register(handle, "displaying-userinfo", gaim_marshal_VOID__POINTER_POINTER_POINTER, NULL, 3, gaim_value_new(GAIM_TYPE_SUBTYPE, gaim_value_new(GAIM_TYPE_STRING), gaim_value_new_outgoing(GAIM_TYPE_STRING)); gaim_signals_unregister_by_instance(gaim_notify_get_handle());