2 * @file notify.h Notification API
4 * @see @ref notify-signals
9 * Purple is the legal property of its developers, whose names are too numerous
10 * to list here. Please refer to the COPYRIGHT file distributed with this
11 * source distribution.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #ifndef _PURPLE_NOTIFY_H_
28 #define _PURPLE_NOTIFY_H_
31 #include <glib-object.h>
34 typedef struct _PurpleNotifyUserInfoEntry PurpleNotifyUserInfoEntry
;
35 typedef struct _PurpleNotifyUserInfo PurpleNotifyUserInfo
;
37 #include "connection.h"
40 * Notification close callbacks.
42 typedef void (*PurpleNotifyCloseCallback
) (gpointer user_data
);
50 PURPLE_NOTIFY_MESSAGE
= 0, /**< Message notification. */
51 PURPLE_NOTIFY_EMAIL
, /**< Single email notification. */
52 PURPLE_NOTIFY_EMAILS
, /**< Multiple email notification. */
53 PURPLE_NOTIFY_FORMATTED
, /**< Formatted text. */
54 PURPLE_NOTIFY_SEARCHRESULTS
, /**< Buddy search results. */
55 PURPLE_NOTIFY_USERINFO
, /**< Formatted userinfo text. */
56 PURPLE_NOTIFY_URI
/**< URI notification or display. */
62 * Notification message types.
66 PURPLE_NOTIFY_MSG_ERROR
= 0, /**< Error notification. */
67 PURPLE_NOTIFY_MSG_WARNING
, /**< Warning notification. */
68 PURPLE_NOTIFY_MSG_INFO
/**< Information notification. */
70 } PurpleNotifyMsgType
;
74 * The types of buttons
78 PURPLE_NOTIFY_BUTTON_LABELED
= 0, /**< special use, see _button_add_labeled */
79 PURPLE_NOTIFY_BUTTON_CONTINUE
= 1,
80 PURPLE_NOTIFY_BUTTON_ADD
,
81 PURPLE_NOTIFY_BUTTON_INFO
,
82 PURPLE_NOTIFY_BUTTON_IM
,
83 PURPLE_NOTIFY_BUTTON_JOIN
,
84 PURPLE_NOTIFY_BUTTON_INVITE
85 } PurpleNotifySearchButtonType
;
89 * Search results object.
93 GList
*columns
; /**< List of the search column objects. */
94 GList
*rows
; /**< List of rows in the result. */
95 GList
*buttons
; /**< List of buttons to display. */
97 } PurpleNotifySearchResults
;
100 * Types of PurpleNotifyUserInfoEntry objects
104 PURPLE_NOTIFY_USER_INFO_ENTRY_PAIR
= 0,
105 PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK
,
106 PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER
107 } PurpleNotifyUserInfoEntryType
;
110 * Single column of a search result.
114 char *title
; /**< Title of the column. */
116 } PurpleNotifySearchColumn
;
120 * Callback for a button in a search result.
122 * @param c the PurpleConnection passed to purple_notify_searchresults
123 * @param row the contents of the selected row
124 * @param user_data User defined data.
126 typedef void (*PurpleNotifySearchResultsCallback
)(PurpleConnection
*c
, GList
*row
,
131 * Definition of a button.
135 PurpleNotifySearchButtonType type
;
136 PurpleNotifySearchResultsCallback callback
; /**< Function to be called when clicked. */
137 char *label
; /**< only for PURPLE_NOTIFY_BUTTON_LABELED */
138 } PurpleNotifySearchButton
;
142 * Notification UI operations.
146 void *(*notify_message
)(PurpleNotifyMsgType type
, const char *title
,
147 const char *primary
, const char *secondary
);
149 void *(*notify_email
)(PurpleConnection
*gc
,
150 const char *subject
, const char *from
,
151 const char *to
, const char *url
);
153 void *(*notify_emails
)(PurpleConnection
*gc
,
154 size_t count
, gboolean detailed
,
155 const char **subjects
, const char **froms
,
156 const char **tos
, const char **urls
);
158 void *(*notify_formatted
)(const char *title
, const char *primary
,
159 const char *secondary
, const char *text
);
161 void *(*notify_searchresults
)(PurpleConnection
*gc
, const char *title
,
162 const char *primary
, const char *secondary
,
163 PurpleNotifySearchResults
*results
, gpointer user_data
);
165 void (*notify_searchresults_new_rows
)(PurpleConnection
*gc
,
166 PurpleNotifySearchResults
*results
,
169 void *(*notify_userinfo
)(PurpleConnection
*gc
, const char *who
,
170 PurpleNotifyUserInfo
*user_info
);
172 void *(*notify_uri
)(const char *uri
);
174 void (*close_notify
)(PurpleNotifyType type
, void *ui_handle
);
176 void (*_purple_reserved1
)(void);
177 void (*_purple_reserved2
)(void);
178 void (*_purple_reserved3
)(void);
179 void (*_purple_reserved4
)(void);
188 /**************************************************************************/
189 /** Search results notification API */
190 /**************************************************************************/
194 * Displays results from a buddy search. This can be, for example,
195 * a window with a list of all found buddies, where you are given the
196 * option of adding buddies to your buddy list.
198 * @param gc The PurpleConnection handle associated with the information.
199 * @param title The title of the message. If this is NULL, the title
200 * will be "Search Results."
201 * @param primary The main point of the message.
202 * @param secondary The secondary information.
203 * @param results The PurpleNotifySearchResults instance.
204 * @param cb The callback to call when the user closes
206 * @param user_data The data to pass to the close callback and any other
207 * callback associated with a button.
209 * @return A UI-specific handle.
211 void *purple_notify_searchresults(PurpleConnection
*gc
, const char *title
,
212 const char *primary
, const char *secondary
,
213 PurpleNotifySearchResults
*results
, PurpleNotifyCloseCallback cb
,
217 * Frees a PurpleNotifySearchResults object.
219 * @param results The PurpleNotifySearchResults to free.
221 void purple_notify_searchresults_free(PurpleNotifySearchResults
*results
);
224 * Replace old rows with the new. Reuse an existing window.
226 * @param gc The PurpleConnection structure.
227 * @param results The PurpleNotifySearchResults structure.
228 * @param data Data returned by the purple_notify_searchresults().
230 void purple_notify_searchresults_new_rows(PurpleConnection
*gc
,
231 PurpleNotifySearchResults
*results
,
236 * Adds a stock button that will be displayed in the search results dialog.
238 * @param results The search results object.
239 * @param type Type of the button. (TODO: Only one button of a given type
241 * @param cb Function that will be called on the click event.
243 void purple_notify_searchresults_button_add(PurpleNotifySearchResults
*results
,
244 PurpleNotifySearchButtonType type
,
245 PurpleNotifySearchResultsCallback cb
);
249 * Adds a plain labelled button that will be displayed in the search results
252 * @param results The search results object
253 * @param label The label to display
254 * @param cb Function that will be called on the click event
256 void purple_notify_searchresults_button_add_labeled(PurpleNotifySearchResults
*results
,
258 PurpleNotifySearchResultsCallback cb
);
262 * Returns a newly created search results object.
264 * @return The new search results object.
266 PurpleNotifySearchResults
*purple_notify_searchresults_new(void);
269 * Returns a newly created search result column object.
271 * @param title Title of the column. NOTE: Title will get g_strdup()ed.
273 * @return The new search column object.
275 PurpleNotifySearchColumn
*purple_notify_searchresults_column_new(const char *title
);
278 * Adds a new column to the search result object.
280 * @param results The result object to which the column will be added.
281 * @param column The column that will be added to the result object.
283 void purple_notify_searchresults_column_add(PurpleNotifySearchResults
*results
,
284 PurpleNotifySearchColumn
*column
);
287 * Adds a new row of the results to the search results object.
289 * @param results The search results object.
290 * @param row The row of the results.
292 void purple_notify_searchresults_row_add(PurpleNotifySearchResults
*results
,
295 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_NOTIFY_C_)
297 * Returns a number of the rows in the search results object.
299 * @deprecated This function will be removed in Pidgin 3.0.0 unless
300 * there is sufficient demand to keep it. Using this
301 * function encourages looping through the results
302 * inefficiently. Instead of using this function you
303 * should iterate through the results using a loop
305 * for (l = results->rows; l != NULL; l = l->next)
306 * If you really need to get the number of rows you
307 * can use g_list_length(results->rows).
309 * @param results The search results object.
311 * @return Number of the result rows.
313 guint
purple_notify_searchresults_get_rows_count(PurpleNotifySearchResults
*results
);
316 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_NOTIFY_C_)
318 * Returns a number of the columns in the search results object.
320 * @deprecated This function will be removed in Pidgin 3.0.0 unless
321 * there is sufficient demand to keep it. Using this
322 * function encourages looping through the columns
323 * inefficiently. Instead of using this function you
324 * should iterate through the columns using a loop
326 * for (l = results->columns; l != NULL; l = l->next)
327 * If you really need to get the number of columns you
328 * can use g_list_length(results->columns).
330 * @param results The search results object.
332 * @return Number of the columns.
334 guint
purple_notify_searchresults_get_columns_count(PurpleNotifySearchResults
*results
);
337 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_NOTIFY_C_)
339 * Returns a row of the results from the search results object.
341 * @deprecated This function will be removed in Pidgin 3.0.0 unless
342 * there is sufficient demand to keep it. Using this
343 * function encourages looping through the results
344 * inefficiently. Instead of using this function you
345 * should iterate through the results using a loop
347 * for (l = results->rows; l != NULL; l = l->next)
348 * If you really need to get the data for a particular
349 * row you can use g_list_nth_data(results->rows, row_id).
351 * @param results The search results object.
352 * @param row_id Index of the row to be returned.
354 * @return Row of the results.
356 GList
*purple_notify_searchresults_row_get(PurpleNotifySearchResults
*results
,
357 unsigned int row_id
);
360 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_NOTIFY_C_)
362 * Returns a title of the search results object's column.
364 * @deprecated This function will be removed in Pidgin 3.0.0 unless
365 * there is sufficient demand to keep it. Using this
366 * function encourages looping through the columns
367 * inefficiently. Instead of using this function you
368 * should iterate through the name of a particular
370 * g_list_nth_data(results->columns, row_id).
372 * @param results The search results object.
373 * @param column_id Index of the column.
375 * @return Title of the column.
377 char *purple_notify_searchresults_column_get_title(PurpleNotifySearchResults
*results
,
378 unsigned int column_id
);
383 /**************************************************************************/
384 /** @name Notification API */
385 /**************************************************************************/
389 * Displays a notification message to the user.
391 * @param handle The plugin or connection handle.
392 * @param type The notification type.
393 * @param title The title of the message.
394 * @param primary The main point of the message.
395 * @param secondary The secondary information.
396 * @param cb The callback to call when the user closes
398 * @param user_data The data to pass to the callback.
400 * @return A UI-specific handle.
402 void *purple_notify_message(void *handle
, PurpleNotifyMsgType type
,
403 const char *title
, const char *primary
,
404 const char *secondary
, PurpleNotifyCloseCallback cb
,
408 * Displays a single email notification to the user.
410 * @param handle The plugin or connection handle.
411 * @param subject The subject of the email.
412 * @param from The from address.
413 * @param to The destination address.
414 * @param url The URL where the message can be read.
415 * @param cb The callback to call when the user closes
417 * @param user_data The data to pass to the callback.
419 * @return A UI-specific handle.
421 void *purple_notify_email(void *handle
, const char *subject
,
422 const char *from
, const char *to
,
423 const char *url
, PurpleNotifyCloseCallback cb
,
427 * Displays a notification for multiple emails to the user.
429 * @param handle The plugin or connection handle.
430 * @param count The number of emails. '0' can be used to signify that
431 * the user has no unread emails and the UI should remove
432 * the mail notification.
433 * @param detailed @c TRUE if there is information for each email in the
435 * @param subjects The array of subjects.
436 * @param froms The array of from addresses.
437 * @param tos The array of destination addresses.
438 * @param urls The URLs where the messages can be read.
439 * @param cb The callback to call when the user closes
441 * @param user_data The data to pass to the callback.
443 * @return A UI-specific handle.
445 void *purple_notify_emails(void *handle
, size_t count
, gboolean detailed
,
446 const char **subjects
, const char **froms
,
447 const char **tos
, const char **urls
,
448 PurpleNotifyCloseCallback cb
, gpointer user_data
);
451 * Displays a notification with formatted text.
453 * The text is essentially a stripped-down format of HTML, the same that
456 * @param handle The plugin or connection handle.
457 * @param title The title of the message.
458 * @param primary The main point of the message.
459 * @param secondary The secondary information.
460 * @param text The formatted text.
461 * @param cb The callback to call when the user closes
463 * @param user_data The data to pass to the callback.
465 * @return A UI-specific handle.
467 void *purple_notify_formatted(void *handle
, const char *title
,
468 const char *primary
, const char *secondary
,
469 const char *text
, PurpleNotifyCloseCallback cb
, gpointer user_data
);
472 * Displays user information with formatted text, passing information giving
473 * the connection and username from which the user information came.
475 * The text is essentially a stripped-down format of HTML, the same that
478 * @param gc The PurpleConnection handle associated with the information.
479 * @param who The username associated with the information.
480 * @param user_info The PurpleNotifyUserInfo which contains the information
481 * @param cb The callback to call when the user closes the notification.
482 * @param user_data The data to pass to the callback.
484 * @return A UI-specific handle.
486 void *purple_notify_userinfo(PurpleConnection
*gc
, const char *who
,
487 PurpleNotifyUserInfo
*user_info
, PurpleNotifyCloseCallback cb
,
491 * Create a new PurpleNotifyUserInfo which is suitable for passing to
492 * purple_notify_userinfo()
494 * @return A new PurpleNotifyUserInfo, which the caller must destroy when done
496 PurpleNotifyUserInfo
*purple_notify_user_info_new(void);
499 * Destroy a PurpleNotifyUserInfo
501 * @param user_info The PurpleNotifyUserInfo
503 void purple_notify_user_info_destroy(PurpleNotifyUserInfo
*user_info
);
506 * Retrieve the array of PurpleNotifyUserInfoEntry objects from a
507 * PurpleNotifyUserInfo
509 * This GList may be manipulated directly with normal GList functions such
510 * as g_list_insert(). Only PurpleNotifyUserInfoEntry are allowed in the
511 * list. If a PurpleNotifyUserInfoEntry item is added to the list, it
512 * should not be g_free()'d by the caller; PurpleNotifyUserInfo will g_free
515 * To remove a PurpleNotifyUserInfoEntry, use
516 * purple_notify_user_info_remove_entry(). Do not use the GList directly.
518 * @param user_info The PurpleNotifyUserInfo
520 * @constreturn A GList of PurpleNotifyUserInfoEntry objects
522 GList
*purple_notify_user_info_get_entries(PurpleNotifyUserInfo
*user_info
);
525 * Create a textual representation of a PurpleNotifyUserInfo, separating
526 * entries with newline
528 * @param user_info The PurpleNotifyUserInfo
529 * @param newline The separation character
531 char *purple_notify_user_info_get_text_with_newline(PurpleNotifyUserInfo
*user_info
, const char *newline
);
534 * Add a label/value pair to a PurpleNotifyUserInfo object.
535 * PurpleNotifyUserInfo keeps track of the order in which pairs are added.
537 * @param user_info The PurpleNotifyUserInfo
538 * @param label A label, which for example might be displayed by a
539 * UI with a colon after it ("Status:"). Do not include
540 * a colon. If NULL, value will be displayed without a
542 * @param value The value, which might be displayed by a UI after
543 * the label. If NULL, label will still be displayed;
544 * the UI should then treat label as independent and not
545 * include a colon if it would otherwise.
547 void purple_notify_user_info_add_pair(PurpleNotifyUserInfo
*user_info
, const char *label
, const char *value
);
550 * Prepend a label/value pair to a PurpleNotifyUserInfo object
552 * @param user_info The PurpleNotifyUserInfo
553 * @param label A label, which for example might be displayed by a
554 * UI with a colon after it ("Status:"). Do not include
555 * a colon. If NULL, value will be displayed without a
557 * @param value The value, which might be displayed by a UI after
558 * the label. If NULL, label will still be displayed;
559 * the UI should then treat label as independent and not
560 * include a colon if it would otherwise.
562 void purple_notify_user_info_prepend_pair(PurpleNotifyUserInfo
*user_info
, const char *label
, const char *value
);
564 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_NOTIFY_C_)
566 * Remove a PurpleNotifyUserInfoEntry from a PurpleNotifyUserInfo object
567 * without freeing the entry.
569 * @param user_info The PurpleNotifyUserInfo
570 * @param user_info_entry The PurpleNotifyUserInfoEntry
572 * @deprecated Nothing is using this function and it should be removed
573 * in 3.0.0. Or, if we decide we want to keep it in 3.0.0
574 * then we should make purple_notify_user_info_entry_destroy
575 * public so that entries can be free'd after they're removed.
577 void purple_notify_user_info_remove_entry(PurpleNotifyUserInfo
*user_info
, PurpleNotifyUserInfoEntry
*user_info_entry
);
581 * Create a new PurpleNotifyUserInfoEntry
583 * If added to a PurpleNotifyUserInfo object, this should not be free()'d,
584 * as PurpleNotifyUserInfo will do so when destroyed.
585 * purple_notify_user_info_add_pair() and
586 * purple_notify_user_info_prepend_pair() are convenience methods for
587 * creating entries and adding them to a PurpleNotifyUserInfo.
589 * @param label A label, which for example might be displayed by a UI
590 * with a colon after it ("Status:"). Do not include a
591 * colon. If NULL, value will be displayed without a label.
592 * @param value The value, which might be displayed by a UI after the
593 * label. If NULL, label will still be displayed; the UI
594 * should then treat label as independent and not include a
595 * colon if it would otherwise.
597 * @result A new PurpleNotifyUserInfoEntry
599 PurpleNotifyUserInfoEntry
*purple_notify_user_info_entry_new(const char *label
, const char *value
);
602 * Add a section break. A UI might display this as a horizontal line.
604 * @param user_info The PurpleNotifyUserInfo
606 void purple_notify_user_info_add_section_break(PurpleNotifyUserInfo
*user_info
);
609 * Prepend a section break. A UI might display this as a horizontal line.
611 * @param user_info The PurpleNotifyUserInfo
614 void purple_notify_user_info_prepend_section_break(PurpleNotifyUserInfo
*user_info
);
617 * Add a section header. A UI might display this in a different font
620 * @param user_info The PurpleNotifyUserInfo
621 * @param label The name of the section
623 void purple_notify_user_info_add_section_header(PurpleNotifyUserInfo
*user_info
, const char *label
);
626 * Prepend a section header. A UI might display this in a different font
629 * @param user_info The PurpleNotifyUserInfo
630 * @param label The name of the section
633 void purple_notify_user_info_prepend_section_header(PurpleNotifyUserInfo
*user_info
, const char *label
);
636 * Remove the last item which was added to a PurpleNotifyUserInfo. This
637 * could be used to remove a section header which is not needed.
639 void purple_notify_user_info_remove_last_item(PurpleNotifyUserInfo
*user_info
);
642 * Get the label for a PurpleNotifyUserInfoEntry
644 * @param user_info_entry The PurpleNotifyUserInfoEntry
648 const gchar
*purple_notify_user_info_entry_get_label(PurpleNotifyUserInfoEntry
*user_info_entry
);
651 * Set the label for a PurpleNotifyUserInfoEntry
653 * @param user_info_entry The PurpleNotifyUserInfoEntry
654 * @param label The label
656 void purple_notify_user_info_entry_set_label(PurpleNotifyUserInfoEntry
*user_info_entry
, const char *label
);
659 * Get the value for a PurpleNotifyUserInfoEntry
661 * @param user_info_entry The PurpleNotifyUserInfoEntry
665 const gchar
*purple_notify_user_info_entry_get_value(PurpleNotifyUserInfoEntry
*user_info_entry
);
668 * Set the value for a PurpleNotifyUserInfoEntry
670 * @param user_info_entry The PurpleNotifyUserInfoEntry
671 * @param value The value
673 void purple_notify_user_info_entry_set_value(PurpleNotifyUserInfoEntry
*user_info_entry
, const char *value
);
677 * Get the type of a PurpleNotifyUserInfoEntry
679 * @param user_info_entry The PurpleNotifyUserInfoEntry
681 * @return The PurpleNotifyUserInfoEntryType
683 PurpleNotifyUserInfoEntryType
purple_notify_user_info_entry_get_type(PurpleNotifyUserInfoEntry
*user_info_entry
);
686 * Set the type of a PurpleNotifyUserInfoEntry
688 * @param user_info_entry The PurpleNotifyUserInfoEntry
689 * @param type The PurpleNotifyUserInfoEntryType
691 void purple_notify_user_info_entry_set_type(PurpleNotifyUserInfoEntry
*user_info_entry
,
692 PurpleNotifyUserInfoEntryType type
);
695 * Opens a URI or somehow presents it to the user.
697 * @param handle The plugin or connection handle.
698 * @param uri The URI to display or go to.
700 * @return A UI-specific handle, if any. This may only be presented if
701 * the UI code displays a dialog instead of a webpage, or something
704 void *purple_notify_uri(void *handle
, const char *uri
);
707 * Closes a notification.
709 * This should be used only by the UI operation functions and part of the
712 * @param type The notification type.
713 * @param ui_handle The notification UI handle.
715 void purple_notify_close(PurpleNotifyType type
, void *ui_handle
);
718 * Closes all notifications registered with the specified handle.
720 * @param handle The handle.
722 void purple_notify_close_with_handle(void *handle
);
725 * A wrapper for purple_notify_message that displays an information message.
727 #define purple_notify_info(handle, title, primary, secondary) \
728 purple_notify_message((handle), PURPLE_NOTIFY_MSG_INFO, (title), \
729 (primary), (secondary), NULL, NULL)
732 * A wrapper for purple_notify_message that displays a warning message.
734 #define purple_notify_warning(handle, title, primary, secondary) \
735 purple_notify_message((handle), PURPLE_NOTIFY_MSG_WARNING, (title), \
736 (primary), (secondary), NULL, NULL)
739 * A wrapper for purple_notify_message that displays an error message.
741 #define purple_notify_error(handle, title, primary, secondary) \
742 purple_notify_message((handle), PURPLE_NOTIFY_MSG_ERROR, (title), \
743 (primary), (secondary), NULL, NULL)
747 /**************************************************************************/
748 /** @name UI Registration Functions */
749 /**************************************************************************/
753 * Sets the UI operations structure to be used when displaying a
756 * @param ops The UI operations structure.
758 void purple_notify_set_ui_ops(PurpleNotifyUiOps
*ops
);
761 * Returns the UI operations structure to be used when displaying a
764 * @return The UI operations structure.
766 PurpleNotifyUiOps
*purple_notify_get_ui_ops(void);
770 /**************************************************************************/
771 /** @name Notify Subsystem */
772 /**************************************************************************/
776 * Returns the notify subsystem handle.
778 * @return The notify subsystem handle.
780 void *purple_notify_get_handle(void);
783 * Initializes the notify subsystem.
785 void purple_notify_init(void);
788 * Uninitializes the notify subsystem.
790 void purple_notify_uninit(void);
799 #endif /* _PURPLE_NOTIFY_H_ */