/soc/2013/ankitkv/gobjectification: 0d5d42e2c0d6: Merged default...

Ankit Vani a at nevitus.org
Fri Sep 13 09:44:38 EDT 2013


Changeset: 0d5d42e2c0d696e5cd9f90ee476534ee86f03278
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-13 19:13 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/0d5d42e2c0d6

Description:

Merged default branch

diffstat:

 pidgin/gtkrequest.c |  69 +++++++++++++++++++++++++++++++++++++++-------------
 pidgin/gtkutils.c   |  19 +++++++++-----
 2 files changed, 63 insertions(+), 25 deletions(-)

diffs (198 lines):

diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -124,6 +124,9 @@ generic_response_start(PidginRequestData
 
 	/* Tell the user we're doing something. */
 	pidgin_set_cursor(GTK_WIDGET(data->dialog), GDK_WATCH);
+
+	g_object_set_data(G_OBJECT(data->dialog),
+		"pidgin-window-is-closing", GINT_TO_POINTER(TRUE));
 }
 
 static void
@@ -434,6 +437,19 @@ pidgin_request_dialog_icon(PurpleRequest
 }
 
 static void
+pidgin_request_help_clicked(GtkButton *button, gpointer _unused)
+{
+	PurpleRequestHelpCb cb;
+	gpointer data;
+
+	cb = g_object_get_data(G_OBJECT(button), "pidgin-help-cb");
+	data = g_object_get_data(G_OBJECT(button), "pidgin-help-data");
+
+	g_return_if_fail(cb != NULL);
+	cb(data);
+}
+
+static void
 pidgin_request_add_help(GtkDialog *dialog, PurpleRequestCommonParameters *cpar)
 {
 	GtkWidget *button;
@@ -446,8 +462,12 @@ pidgin_request_add_help(GtkDialog *dialo
 
 	button = gtk_dialog_add_button(dialog, GTK_STOCK_HELP,
 		GTK_RESPONSE_HELP);
-	g_signal_connect(G_OBJECT(button), "clicked", (GCallback)help_cb,
-		help_data);
+
+	g_object_set_data(G_OBJECT(button), "pidgin-help-cb", help_cb);
+	g_object_set_data(G_OBJECT(button), "pidgin-help-data", help_data);
+
+	g_signal_connect(G_OBJECT(button), "clicked",
+		G_CALLBACK(pidgin_request_help_clicked), NULL);
 }
 
 static void *
@@ -1061,9 +1081,10 @@ create_choice_field(PurpleRequestField *
 	GList *l;
 	gpointer *values = g_new(gpointer, num_labels);
 	gpointer default_value;
+	gboolean default_found = FALSE;
 	int i;
 
-	default_value = purple_request_field_choice_get_default_value(field);
+	default_value = purple_request_field_choice_get_value(field);
 	if (num_labels > 5 || purple_request_cpar_is_compact(cpar))
 	{
 		int default_index = 0;
@@ -1082,8 +1103,10 @@ create_choice_field(PurpleRequestField *
 			l = g_list_next(l);
 
 			gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(widget), text);
-			if (value == default_value)
+			if (value == default_value) {
 				default_index = i;
+				default_found = TRUE;
+			}
 			values[i++] = value;
 		}
 
@@ -1128,8 +1151,10 @@ create_choice_field(PurpleRequestField *
 			if (first_radio == NULL)
 				first_radio = radio;
 
-			if (value == default_value)
+			if (value == default_value) {
 				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE);
+				default_found = TRUE;
+			}
 			values[i++] = value;
 
 			gtk_box_pack_start(GTK_BOX(box), radio, TRUE, TRUE, 0);
@@ -1140,6 +1165,9 @@ create_choice_field(PurpleRequestField *
 		}
 	}
 
+	if (!default_found && i > 0)
+		purple_request_field_choice_set_value(field, values[0]);
+
 	g_object_set_data_full(G_OBJECT(widget), "values", values, g_free);
 
 	return widget;
@@ -1890,26 +1918,34 @@ pidgin_request_folder(const char *title,
 	return (void *)data;
 }
 
-#ifdef _WIN32
-
-/* Not needed (yet) for non-win32, but should work everywhere. */
+/* if request callback issues another request, it should be attached to the
+ * primary request parent */
 static void
-pidgin_window_detach_children(GtkWindow* parent)
+pidgin_window_detach_children(GtkWindow* win)
 {
 	GList *it;
+	GtkWindow *par;
 
-	g_return_if_fail(parent != NULL);
+	g_return_if_fail(win != NULL);
 
+	par = gtk_window_get_transient_for(win);
 	it = gtk_window_list_toplevels();
 	for (it = g_list_first(it); it != NULL; it = g_list_next(it)) {
-		GtkWindow *win = GTK_WINDOW(it->data);
-		if (gtk_window_get_transient_for(win) == parent)
-			gtk_window_set_transient_for(win, NULL);
+		GtkWindow *child = GTK_WINDOW(it->data);
+		if (gtk_window_get_transient_for(child) != win)
+			continue;
+		if (gtk_window_get_destroy_with_parent(child)) {
+#ifdef _WIN32
+			/* XXX test/verify it: Win32 gtk ignores
+			 * gtk_window_set_destroy_with_parent(..., FALSE). */
+			gtk_window_set_transient_for(child, NULL);
+#endif
+			continue;
+		}
+		gtk_window_set_transient_for(child, par);
 	}
 }
 
-#endif
-
 static void
 pidgin_close_request(PurpleRequestType type, void *ui_handle)
 {
@@ -1917,10 +1953,7 @@ pidgin_close_request(PurpleRequestType t
 
 	g_free(data->cbs);
 
-#ifdef _WIN32
-	/* Win32 gtk ignores gtk_window_set_destroy_with_parent(..., FALSE). */
 	pidgin_window_detach_children(GTK_WINDOW(data->dialog));
-#endif
 
 	gtk_widget_destroy(data->dialog);
 
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -2935,7 +2935,7 @@ gboolean pidgin_auto_parent_window(GtkWi
 #else
 	/* This finds the currently active window and makes that the parent window. */
 	GList *windows = NULL;
-	GtkWidget *parent = NULL;
+	GtkWindow *parent = NULL;
 	GdkEvent *event = gtk_get_current_event();
 	GdkWindow *menu = NULL;
 
@@ -2955,24 +2955,29 @@ gboolean pidgin_auto_parent_window(GtkWi
 
 	windows = gtk_window_list_toplevels();
 	while (windows) {
-		GtkWidget *window = windows->data;
+		GtkWindow *window = GTK_WINDOW(windows->data);
 		windows = g_list_delete_link(windows, windows);
 
-		if (window == widget ||
-				!gtk_widget_get_visible(window)) {
+		if (GTK_WIDGET(window) == widget ||
+				!gtk_widget_get_visible(GTK_WIDGET(window))) {
 			continue;
 		}
 
-		if (gtk_window_has_toplevel_focus(GTK_WINDOW(window)) ||
-				(menu && menu == gtk_widget_get_window(window))) {
+		if (gtk_window_has_toplevel_focus(window) ||
+				(menu && menu == gtk_widget_get_window(GTK_WIDGET(window)))) {
 			parent = window;
 			break;
 		}
 	}
 	if (windows)
 		g_list_free(windows);
+	if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(parent),
+		"pidgin-window-is-closing")))
+	{
+		parent = gtk_window_get_transient_for(parent);
+	}
 	if (parent) {
-		gtk_window_set_transient_for(GTK_WINDOW(widget), GTK_WINDOW(parent));
+		gtk_window_set_transient_for(GTK_WINDOW(widget), parent);
 		return TRUE;
 	}
 	return FALSE;



More information about the Commits mailing list