/pidgin/main: be28ca093028: Add close notification for Request A...

Tomasz Wasilczyk twasilczyk at pidgin.im
Thu Oct 24 06:35:47 EDT 2013


Changeset: be28ca093028018c683b880c061f8f48fbc6e5a6
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-10-24 12:35 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/be28ca093028

Description:

Add close notification for Request API dialogs

diffstat:

 libpurple/request.c |  76 +++++++++++++++++++++++++++++++++++++++++++---------
 libpurple/request.h |  11 +++++++
 2 files changed, 73 insertions(+), 14 deletions(-)

diffs (141 lines):

diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -36,10 +36,16 @@ static GList *handles = NULL;
 
 typedef struct
 {
+	GDestroyNotify cb;
+	gpointer data;
+} PurpleRequestCloseNotified;
+
+typedef struct
+{
 	PurpleRequestType type;
 	void *handle;
 	void *ui_handle;
-
+	GSList *notify_on_close;
 } PurpleRequestInfo;
 
 struct _PurpleRequestField
@@ -447,6 +453,23 @@ purple_request_cpar_get_parent_from(Purp
 	return cpar->parent_from;
 }
 
+static PurpleRequestInfo *
+purple_request_info_from_ui_handle(void *ui_handle)
+{
+	GList *it;
+
+	g_return_val_if_fail(ui_handle != NULL, NULL);
+
+	for (it = handles; it != NULL; it = g_list_next(it)) {
+		PurpleRequestInfo *info = it->data;
+
+		if (info->ui_handle == ui_handle)
+			return info;
+	}
+
+	return NULL;
+}
+
 PurpleRequestFields *
 purple_request_fields_new(void)
 {
@@ -2312,29 +2335,47 @@ purple_request_certificate(void *handle,
 gboolean
 purple_request_is_valid_ui_handle(void *ui_handle, PurpleRequestType *type)
 {
-	GList *it;
+	PurpleRequestInfo *info;
 
 	if (ui_handle == NULL)
 		return FALSE;
 
-	for (it = handles; it != NULL; it = g_list_next(it)) {
-		PurpleRequestInfo *info = it->data;
-
-		if (info->ui_handle != ui_handle)
-			continue;
-
-		if (type != NULL)
-			*type = info->type;
-		return TRUE;
-	}
-
-	return FALSE;
+	info = purple_request_info_from_ui_handle(ui_handle);
+
+	if (info == NULL)
+		return FALSE;
+
+	if (type != NULL)
+		*type = info->type;
+
+	return TRUE;
+}
+
+void
+purple_request_add_close_notify(void *ui_handle, GDestroyNotify notify,
+	gpointer notify_data)
+{
+	PurpleRequestInfo *info;
+	PurpleRequestCloseNotified *notified;
+
+	g_return_if_fail(ui_handle != NULL);
+	g_return_if_fail(notify != NULL);
+
+	info = purple_request_info_from_ui_handle(ui_handle);
+	g_return_if_fail(info != NULL);
+
+	notified = g_new0(PurpleRequestCloseNotified, 1);
+	notified->cb = notify;
+	notified->data = notify_data;
+
+	info->notify_on_close = g_slist_append(info->notify_on_close, notified);
 }
 
 static void
 purple_request_close_info(PurpleRequestInfo *info)
 {
 	PurpleRequestUiOps *ops;
+	GSList *it;
 
 	ops = purple_request_get_ui_ops();
 
@@ -2344,6 +2385,13 @@ purple_request_close_info(PurpleRequestI
 	if (ops != NULL && ops->close_request != NULL)
 		ops->close_request(info->type, info->ui_handle);
 
+	for (it = info->notify_on_close; it; it = g_slist_next(it)) {
+		PurpleRequestCloseNotified *notify = it->data;
+
+		notify->cb(notify->data);
+	}
+
+	g_slist_free_full(info->notify_on_close, g_free);
 	g_free(info);
 }
 
diff --git a/libpurple/request.h b/libpurple/request.h
--- a/libpurple/request.h
+++ b/libpurple/request.h
@@ -1878,6 +1878,17 @@ gboolean
 purple_request_is_valid_ui_handle(void *ui_handle, PurpleRequestType *type);
 
 /**
+ * Adds a function called when notification dialog is closed.
+ *
+ * @param ui_handle   The UI handle.
+ * @param notify      The function to be called.
+ * @param notify_data The data to be passed to the callback function.
+ */
+void
+purple_request_add_close_notify(void *ui_handle, GDestroyNotify notify,
+	gpointer notify_data);
+
+/**
  * Closes a request.
  *
  * @param type     The request type.



More information about the Commits mailing list