/pidgin/main: b7165d4e1d73: Implement purple_*_is_valid_ui_handl...

Tomasz Wasilczyk twasilczyk at pidgin.im
Sat Sep 21 08:47:21 EDT 2013


Changeset: b7165d4e1d738a43f5543739a035a63983b2b8b9
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-09-21 14:47 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/b7165d4e1d73

Description:

Implement purple_*_is_valid_ui_handle, purple_request_cpar_*et_parent_from, pidgin_request_get_dialog_window

diffstat:

 libpurple/dbus-analyze-functions.py |   3 ++
 libpurple/notify.c                  |  22 +++++++++++++++++++
 libpurple/notify.h                  |  12 ++++++++++
 libpurple/request.c                 |  42 +++++++++++++++++++++++++++++++++++++
 libpurple/request.h                 |  33 +++++++++++++++++++++++++++++
 pidgin/gtknotify.c                  |   2 +
 pidgin/gtkrequest.c                 |  11 +++++++++
 pidgin/gtkrequest.h                 |  10 ++++++++
 pidgin/gtkutils.c                   |  19 ++++++++++++++++
 9 files changed, 154 insertions(+), 0 deletions(-)

diffs (272 lines):

diff --git a/libpurple/dbus-analyze-functions.py b/libpurple/dbus-analyze-functions.py
--- a/libpurple/dbus-analyze-functions.py
+++ b/libpurple/dbus-analyze-functions.py
@@ -49,6 +49,9 @@ excluded = [\
     # as pointer to a struct, instead of a pointer to an enum.  This
     # causes a compilation error. Someone should fix this script.
     "purple_log_read",
+
+    # Similiar to the above:
+    "purple_notify_is_valid_ui_handle",
     ]
 
 # This is a list of functions that return a GList* or GSList * whose elements
diff --git a/libpurple/notify.c b/libpurple/notify.c
--- a/libpurple/notify.c
+++ b/libpurple/notify.c
@@ -722,6 +722,28 @@ purple_notify_uri(void *handle, const ch
 	return NULL;
 }
 
+gboolean
+purple_notify_is_valid_ui_handle(void *ui_handle, PurpleNotifyType *type)
+{
+	GList *it;
+
+	if (ui_handle == NULL)
+		return FALSE;
+
+	for (it = handles; it != NULL; it = g_list_next(it)) {
+		PurpleNotifyInfo *info = it->data;
+
+		if (info->ui_handle != ui_handle)
+			continue;
+
+		if (type != NULL)
+			*type = info->type;
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
 void
 purple_notify_close(PurpleNotifyType type, void *ui_handle)
 {
diff --git a/libpurple/notify.h b/libpurple/notify.h
--- a/libpurple/notify.h
+++ b/libpurple/notify.h
@@ -648,6 +648,18 @@ void purple_notify_user_info_entry_set_t
 void *purple_notify_uri(void *handle, const char *uri);
 
 /**
+ * Checks, if passed UI handle is valid.
+ *
+ * @param ui_handle The UI handle.
+ * @param type      The pointer to variable, where request type may be stored
+ *                  (may be @c NULL).
+ *
+ * @return TRUE, if handle is valid, FALSE otherwise.
+ */
+gboolean
+purple_notify_is_valid_ui_handle(void *ui_handle, PurpleNotifyType *type);
+
+/**
  * Closes a notification.
  *
  * This should be used only by the UI operation functions and part of the
diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -175,6 +175,8 @@ struct _PurpleRequestCommonParameters
 	gpointer help_data;
 
 	GSList *extra_actions;
+
+	gpointer parent_from;
 };
 
 PurpleRequestCommonParameters *
@@ -424,6 +426,24 @@ purple_request_cpar_get_extra_actions(Pu
 	return cpar->extra_actions;
 }
 
+void
+purple_request_cpar_set_parent_from(PurpleRequestCommonParameters *cpar,
+	gpointer ui_handle)
+{
+	g_return_if_fail(cpar != NULL);
+
+	cpar->parent_from = ui_handle;
+}
+
+gpointer
+purple_request_cpar_get_parent_from(PurpleRequestCommonParameters *cpar)
+{
+	if (cpar == NULL)
+		return NULL;
+
+	return cpar->parent_from;
+}
+
 PurpleRequestFields *
 purple_request_fields_new(void)
 {
@@ -2286,6 +2306,28 @@ purple_request_certificate(void *handle,
 	                             NULL, user_data);
 }
 
+gboolean
+purple_request_is_valid_ui_handle(void *ui_handle, PurpleRequestType *type)
+{
+	GList *it;
+
+	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;
+}
+
 static void
 purple_request_close_info(PurpleRequestInfo *info)
 {
diff --git a/libpurple/request.h b/libpurple/request.h
--- a/libpurple/request.h
+++ b/libpurple/request.h
@@ -423,6 +423,27 @@ purple_request_cpar_set_extra_actions(Pu
 GSList *
 purple_request_cpar_get_extra_actions(PurpleRequestCommonParameters *cpar);
 
+/**
+ * Sets the same parent window for this dialog, as the parent of specified
+ * Notify API or Request API dialog UI handle.
+ *
+ * @param cpar      The parameters set.
+ * @param ui_handle The UI handle.
+ */
+void
+purple_request_cpar_set_parent_from(PurpleRequestCommonParameters *cpar,
+	gpointer ui_handle);
+
+/**
+ * Gets the parent "donor" for this dialog.
+ *
+ * @param cpar The parameters set (may be @c NULL).
+ *
+ * @return The donors UI handle.
+ */
+gpointer
+purple_request_cpar_get_parent_from(PurpleRequestCommonParameters *cpar);
+
 /*@}*/
 
 /**************************************************************************/
@@ -1845,6 +1866,18 @@ purple_request_fields(void *handle, cons
 	void *user_data);
 
 /**
+ * Checks, if passed UI handle is valid.
+ *
+ * @param ui_handle The UI handle.
+ * @param type      The pointer to variable, where request type may be stored
+ *                  (may be @c NULL).
+ *
+ * @return TRUE, if handle is valid, FALSE otherwise.
+ */
+gboolean
+purple_request_is_valid_ui_handle(void *ui_handle, PurpleRequestType *type);
+
+/**
  * Closes a request.
  *
  * @param type     The request type.
diff --git a/pidgin/gtknotify.c b/pidgin/gtknotify.c
--- a/pidgin/gtknotify.c
+++ b/pidgin/gtknotify.c
@@ -617,6 +617,8 @@ pidgin_notify_message(PurpleNotifyMsgTyp
 	gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
 	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
 
+	g_object_set_data(G_OBJECT(dialog), "pidgin-parent-from",
+		purple_request_cpar_get_parent_from(cpar));
 	pidgin_auto_parent_window(dialog);
 
 	gtk_widget_show_all(dialog);
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -2165,6 +2165,17 @@ pidgin_close_request(PurpleRequestType t
 	g_free(data);
 }
 
+GtkWindow *
+pidgin_request_get_dialog_window(void *ui_handle)
+{
+	PidginRequestData *data = ui_handle;
+
+	g_return_val_if_fail(
+		purple_request_is_valid_ui_handle(data, NULL), NULL);
+
+	return GTK_WINDOW(data->dialog);
+}
+
 static PurpleRequestUiOps ops =
 {
 	PURPLE_REQUEST_FEATURE_HTML,
diff --git a/pidgin/gtkrequest.h b/pidgin/gtkrequest.h
--- a/pidgin/gtkrequest.h
+++ b/pidgin/gtkrequest.h
@@ -37,6 +37,16 @@ G_BEGIN_DECLS
  */
 PurpleRequestUiOps *pidgin_request_get_ui_ops(void);
 
+/**
+ * Gets dialog window for specified libpurple request.
+ *
+ * @param ui_handle The UI handle.
+ *
+ * @return The dialog window.
+ */
+GtkWindow *
+pidgin_request_get_dialog_window(void *ui_handle);
+
 G_END_DECLS
 
 #endif /* _PIDGINREQUEST_H_ */
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -61,6 +61,7 @@
 #include "gtkconv.h"
 #include "gtkdialogs.h"
 #include "pidginstock.h"
+#include "gtkrequest.h"
 #include "gtkthemes.h"
 #include "gtkutils.h"
 #include "gtkwebview.h"
@@ -2931,6 +2932,24 @@ gboolean pidgin_auto_parent_window(GtkWi
 	GtkWindow *parent = NULL;
 	GdkEvent *event = gtk_get_current_event();
 	GdkWindow *menu = NULL;
+	gpointer parent_from;
+	PurpleNotifyType notify_type;
+
+	parent_from = g_object_get_data(G_OBJECT(widget), "pidgin-parent-from");
+	if (purple_request_is_valid_ui_handle(parent_from, NULL)) {
+		
+		gtk_window_set_transient_for(GTK_WINDOW(widget),
+			gtk_window_get_transient_for(
+				pidgin_request_get_dialog_window(parent_from)));
+		return TRUE;
+	}
+	if (purple_notify_is_valid_ui_handle(parent_from, &notify_type) &&
+		notify_type == PURPLE_NOTIFY_MESSAGE)
+	{
+		gtk_window_set_transient_for(GTK_WINDOW(widget),
+			gtk_window_get_transient_for(GTK_WINDOW(parent_from)));
+		return TRUE;
+	}
 
 	if (event == NULL)
 		/* The window was not triggered by a user action. */



More information about the Commits mailing list