/pidgin/main: 3579cb14f8f2: Request API: compact layout feature

Tomasz Wasilczyk twasilczyk at pidgin.im
Thu Sep 12 09:33:25 EDT 2013


Changeset: 3579cb14f8f28472dafd7b70271e2285d4487579
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2013-09-12 15:33 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/3579cb14f8f2

Description:

Request API: compact layout feature

diffstat:

 libpurple/request.c |  17 +++++++++++++++++
 libpurple/request.h |  26 ++++++++++++++++++++++++++
 pidgin/gtkrequest.c |  35 ++++++++++++++++++++++++++---------
 3 files changed, 69 insertions(+), 9 deletions(-)

diffs (175 lines):

diff --git a/libpurple/request.c b/libpurple/request.c
--- a/libpurple/request.c
+++ b/libpurple/request.c
@@ -166,6 +166,7 @@ struct _PurpleRequestCommonParameters
 	gconstpointer icon_data;
 	gsize icon_size;
 	gboolean html;
+	gboolean compact;
 };
 
 PurpleRequestCommonParameters *
@@ -331,6 +332,22 @@ purple_request_cpar_is_html(PurpleReques
 	return cpar->html;
 }
 
+void
+purple_request_cpar_set_compact(PurpleRequestCommonParameters *cpar,
+	gboolean compact)
+{
+	cpar->compact = compact;
+}
+
+gboolean
+purple_request_cpar_is_compact(PurpleRequestCommonParameters *cpar)
+{
+	if (cpar == NULL)
+		return FALSE;
+
+	return cpar->compact;
+}
+
 PurpleRequestFields *
 purple_request_fields_new(void)
 {
diff --git a/libpurple/request.h b/libpurple/request.h
--- a/libpurple/request.h
+++ b/libpurple/request.h
@@ -336,6 +336,26 @@ purple_request_cpar_set_html(PurpleReque
 gboolean
 purple_request_cpar_is_html(PurpleRequestCommonParameters *cpar);
 
+/**
+ * Sets dialog display mode to compact or default.
+ *
+ * @param cpar    The parameters set.
+ * @param compact TRUE for compact, FALSE otherwise.
+ */
+void
+purple_request_cpar_set_compact(PurpleRequestCommonParameters *cpar,
+	gboolean compact);
+
+/**
+ * Gets dialog display mode.
+ *
+ * @param cpar The parameters set (may be @c NULL).
+ *
+ * @return TRUE for compact, FALSE for default.
+ */
+gboolean
+purple_request_cpar_is_compact(PurpleRequestCommonParameters *cpar);
+
 /*@}*/
 
 /**************************************************************************/
@@ -1133,6 +1153,12 @@ purple_request_field_choice_get_value(co
 GList *
 purple_request_field_choice_get_elements(const PurpleRequestField *field);
 
+/**
+ * Sets the destructor for field values.
+ *
+ * @param field   The field.
+ * @param destroy The destroy function.
+ */
 void
 purple_request_field_choice_set_data_destructor(PurpleRequestField *field,
 	GDestroyNotify destroy);
diff --git a/pidgin/gtkrequest.c b/pidgin/gtkrequest.c
--- a/pidgin/gtkrequest.c
+++ b/pidgin/gtkrequest.c
@@ -1019,7 +1019,8 @@ create_bool_field(PurpleRequestField *fi
 }
 
 static GtkWidget *
-create_choice_field(PurpleRequestField *field)
+create_choice_field(PurpleRequestField *field,
+	PurpleRequestCommonParameters *cpar)
 {
 	GtkWidget *widget;
 	GList *elements = purple_request_field_choice_get_elements(field);
@@ -1027,11 +1028,12 @@ create_choice_field(PurpleRequestField *
 	GList *l;
 	gpointer *values = g_new(gpointer, num_labels);
 	gpointer default_value;
-	int i, default_index = -1;
+	int i;
 
 	default_value = purple_request_field_choice_get_default_value(field);
-	if (num_labels > 5)
+	if (num_labels > 5 || purple_request_cpar_is_compact(cpar))
 	{
+		int default_index = 0;
 		widget = gtk_combo_box_text_new();
 
 		i = 0;
@@ -1335,6 +1337,7 @@ pidgin_request_fields(const char *title,
 	char *label_text;
 	char *primary_esc, *secondary_esc;
 	int total_fields = 0;
+	const gboolean compact = purple_request_cpar_is_compact(cpar);
 
 	data            = g_new0(PidginRequestData, 1);
 	data->type      = PURPLE_REQUEST_FIELDS;
@@ -1501,7 +1504,8 @@ pidgin_request_fields(const char *title,
 					rows++;
 
 				rows += 2;
-			}
+			} else if (compact && type != PURPLE_REQUEST_FIELD_BOOLEAN)
+				rows++;
 
 			col_num++;
 
@@ -1509,7 +1513,10 @@ pidgin_request_fields(const char *title,
 				col_num = 0;
 		}
 
-		table = gtk_table_new(rows, 2 * cols, FALSE);
+		if (compact)
+			table = gtk_table_new(rows, cols, FALSE);
+		else
+			table = gtk_table_new(rows, 2 * cols, FALSE);
 		gtk_table_set_row_spacings(GTK_TABLE(table), PIDGIN_HIG_BOX_SPACE);
 		gtk_table_set_col_spacings(GTK_TABLE(table), PIDGIN_HIG_BOX_SPACE);
 
@@ -1544,8 +1551,11 @@ pidgin_request_fields(const char *title,
 				{
 					char *text = NULL;
 
-					if (field_label[strlen(field_label) - 1] != ':')
+					if (field_label[strlen(field_label) - 1] != ':' &&
+						field_label[strlen(field_label) - 1] != '?')
+					{
 						text = g_strdup_printf("%s:", field_label);
+					}
 
 					label = gtk_label_new(NULL);
 					gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), text ? text : field_label);
@@ -1590,7 +1600,7 @@ pidgin_request_fields(const char *title,
 					else if (type == PURPLE_REQUEST_FIELD_BOOLEAN)
 						widget = create_bool_field(field);
 					else if (type == PURPLE_REQUEST_FIELD_CHOICE)
-						widget = create_choice_field(field);
+						widget = create_choice_field(field, cpar);
 					else if (type == PURPLE_REQUEST_FIELD_LIST)
 						widget = create_list_field(field);
 					else if (type == PURPLE_REQUEST_FIELD_IMAGE)
@@ -1634,8 +1644,15 @@ pidgin_request_fields(const char *title,
 									 GTK_FILL | GTK_EXPAND,
 									 5, 0);
 				}
-				else
-				{
+				else if (compact) {
+					row_num++;
+					gtk_table_attach(GTK_TABLE(table), widget,
+									 0, 2 * cols,
+									 row_num, row_num + 1,
+									 GTK_FILL | GTK_EXPAND,
+									 GTK_FILL | GTK_EXPAND,
+									 5, 0);
+				} else {
 					gtk_table_attach(GTK_TABLE(table), widget,
 							 		 1, 2 * cols,
 									 row_num, row_num + 1,



More information about the Commits mailing list