API enhancement for 2.8.0

Andrew Victor avictor.za at gmail.com
Wed Mar 23 17:33:44 EDT 2011


hi,

Is it possible we could add the following for 2.8.0:
    void purple_request_field_set_tooltip(PurpleRequestField *field,
const char *tooltip);
    const char *purple_request_field_get_tooltip(const
PurpleRequestField *field);

It will provide a mechanism for prpl's to provide some
context-sensitive help on Request UI forms.

Appended is a proof-of-concept patch...
(If Pidgin 2.8.0's minimum GTK+ version is still 2.10.0, the gtk calls
need to be within GTK_CHECK_VERSION() checks)


--- libpurple/request.c	cc2b05b46a40779cd9faa24fbffc8b9bfa2442ff
+++ libpurple/request.c	1528d4b41b74a6c50ef5d8ca746b6b4d1f3bd80e
@@ -365,6 +365,7 @@ purple_request_field_destroy(PurpleReque
 	g_free(field->id);
 	g_free(field->label);
 	g_free(field->type_hint);
+	g_free(field->tooltip);

 	if (field->type == PURPLE_REQUEST_FIELD_STRING)
 	{
@@ -428,6 +429,16 @@ void
 }

 void
+purple_request_field_set_tooltip(PurpleRequestField *field,
+								 const char *tooltip)
+{
+	g_return_if_fail(field != NULL);
+
+	g_free(field->tooltip);
+	field->tooltip = g_strdup(tooltip);
+}
+
+void
 purple_request_field_set_required(PurpleRequestField *field, gboolean required)
 {
 	g_return_if_fail(field != NULL);
@@ -502,6 +513,14 @@ purple_request_field_get_type_hint(const
 	return field->type_hint;
 }

+const char *
+purple_request_field_get_tooltip(const PurpleRequestField *field)
+{
+	g_return_val_if_fail(field != NULL, NULL);
+
+	return field->tooltip;
+}
+
 gboolean
 purple_request_field_is_required(const PurpleRequestField *field)
 {
============================================================
--- libpurple/request.h	f3460d06e7653696508046113ed3205809fb4add
+++ libpurple/request.h	105dff1d6175f3637652a91a0aaf8475fb91e709
@@ -108,6 +108,7 @@ struct _PurpleRequestField
 	char *id;
 	char *label;
 	char *type_hint;
+	char *tooltip;

 	gboolean visible;
 	gboolean required;
@@ -517,6 +518,18 @@ void purple_request_field_set_type_hint(
 									  const char *type_hint);

 /**
+ * Sets the tooltip for the field.
+ *
+ * This is optionally used by the UIs to provide a tooltip for
+ * the field.
+ *
+ * @param field     The field.
+ * @param tooltip   The tooltip text.
+ */
+void purple_request_field_set_tooltip(PurpleRequestField *field,
+									const char *tooltip);
+
+/**
  * Sets whether or not a field is required.
  *
  * @param field    The field.
@@ -582,6 +595,15 @@ const char *purple_request_field_get_typ
 const char *purple_request_field_get_type_hint(const
PurpleRequestField *field);

 /**
+ * Returns the field's tooltip.
+ *
+ * @param field The field.
+ *
+ * @return The field's tooltip.
+ */
+const char *purple_request_field_get_tooltip(const PurpleRequestField *field);
+
+/**
  * Returns whether or not a field is required.
  *
  * @param field The field.
============================================================
--- pidgin/gtkrequest.c	c13851355e046995c5e133960c40c9e4c2fe48cd
+++ pidgin/gtkrequest.c	a44a112c10f72a30800fb2790247d508a485bb39
@@ -833,6 +833,7 @@ create_string_field(PurpleRequestField *
 static GtkWidget *
 create_string_field(PurpleRequestField *field)
 {
+	const char *tooltip = purple_request_field_get_tooltip(field);
 	const char *value;
 	GtkWidget *widget;

@@ -862,6 +863,9 @@ create_string_field(PurpleRequestField *
 			gtk_text_buffer_set_text(buffer, value, -1);
 		}

+		if (tooltip != NULL)
+			gtk_widget_set_tooltip_text(textview, tooltip);
+
 		gtk_text_view_set_editable(GTK_TEXT_VIEW(textview),
 			purple_request_field_string_is_editable(field));

@@ -886,6 +890,9 @@ create_string_field(PurpleRequestField *
 		if (value != NULL)
 			gtk_entry_set_text(GTK_ENTRY(widget), value);

+		if (tooltip != NULL)
+			gtk_widget_set_tooltip_text(widget, tooltip);
+
 		if (purple_request_field_string_is_masked(field))
 		{
 			gtk_entry_set_visibility(GTK_ENTRY(widget), FALSE);
@@ -908,6 +915,7 @@ create_int_field(PurpleRequestField *fie
 static GtkWidget *
 create_int_field(PurpleRequestField *field)
 {
+	const char *tooltip = purple_request_field_get_tooltip(field);
 	int value;
 	GtkWidget *widget;

@@ -926,6 +934,9 @@ create_int_field(PurpleRequestField *fie
 		gtk_entry_set_text(GTK_ENTRY(widget), buf);
 	}

+	if (tooltip != NULL)
+		gtk_widget_set_tooltip_text(widget, tooltip);
+
 	g_signal_connect(G_OBJECT(widget), "focus-out-event",
 					 G_CALLBACK(field_int_focus_out_cb), field);

@@ -935,11 +946,15 @@ create_bool_field(PurpleRequestField *fi
 static GtkWidget *
 create_bool_field(PurpleRequestField *field)
 {
+	const char *tooltip = purple_request_field_get_tooltip(field);
 	GtkWidget *widget;

 	widget = gtk_check_button_new_with_label(
 		purple_request_field_get_label(field));

+	if (tooltip != NULL)
+		gtk_widget_set_tooltip_text(widget, tooltip);
+
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
 		purple_request_field_bool_get_default_value(field));

@@ -952,6 +967,7 @@ create_choice_field(PurpleRequestField *
 static GtkWidget *
 create_choice_field(PurpleRequestField *field)
 {
+	const char *tooltip = purple_request_field_get_tooltip(field);
 	GtkWidget *widget;
 	GList *labels = purple_request_field_choice_get_labels(field);
 	int num_labels = g_list_length(labels);
@@ -970,6 +986,9 @@ create_choice_field(PurpleRequestField *
 		gtk_combo_box_set_active(GTK_COMBO_BOX(widget),
 						purple_request_field_choice_get_default_value(field));

+		if (tooltip != NULL)
+			gtk_widget_set_tooltip_text(widget, tooltip);
+
 		g_signal_connect(G_OBJECT(widget), "changed",
 						 G_CALLBACK(field_choice_menu_cb), field);
 	}
@@ -987,6 +1006,9 @@ create_choice_field(PurpleRequestField *

 		widget = box;

+		if (tooltip != NULL)
+			gtk_widget_set_tooltip_text(widget, tooltip);
+
 		for (l = labels, i = 0; l != NULL; l = l->next, i++)
 		{
 			const char *text = l->data;
@@ -1014,6 +1036,7 @@ create_image_field(PurpleRequestField *f
 static GtkWidget *
 create_image_field(PurpleRequestField *field)
 {
+	const char *tooltip = purple_request_field_get_tooltip(field);
 	GtkWidget *widget;
 	GdkPixbuf *buf, *scale;
 	GdkPixbufLoader *loader;
@@ -1034,12 +1057,16 @@ create_image_field(PurpleRequestField *f
 	g_object_unref(G_OBJECT(loader));
 	g_object_unref(G_OBJECT(scale));

+	if (tooltip != NULL)
+		gtk_widget_set_tooltip_text(widget, tooltip);
+
 	return widget;
 }

 static GtkWidget *
 create_account_field(PurpleRequestField *field)
 {
+	const char *tooltip = purple_request_field_get_tooltip(field);
 	GtkWidget *widget;

 	widget = pidgin_account_option_menu_new(
@@ -1049,6 +1076,9 @@ create_account_field(PurpleRequestField
 		purple_request_field_account_get_filter(field),
 		field);

+	if (tooltip != NULL)
+		gtk_widget_set_tooltip_text(widget, tooltip);
+
 	return widget;
 }




More information about the Devel mailing list