changeset 31846:a88631af0f5e

Add API: purple_request_field_set_tooltip & purple_request_field_get_tooltip This allows protocol prpl's to provide some context-sensitive help text for Requiest UI fields.
author andrew.victor@mxit.com
date Tue, 03 May 2011 21:22:51 +0000
parents 63fb41aa3dbe
children ea4bb5fe1fdc
files ChangeLog.API libpurple/request.c libpurple/request.h pidgin/gtkrequest.c
diffstat 4 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Tue May 03 20:55:39 2011 +0000
+++ b/ChangeLog.API	Tue May 03 21:22:51 2011 +0000
@@ -5,6 +5,8 @@
 		Added:
 		* purple_notify_searchresult_column_set_visible
 		* purple_notify_searchresult_column_is_visible
+		* purple_request_field_set_tooltip
+		* purple_request_field_get_tooltip
 
 		Removed:
 		* purple_core_migrate
--- a/libpurple/request.c	Tue May 03 20:55:39 2011 +0000
+++ b/libpurple/request.c	Tue May 03 21:22:51 2011 +0000
@@ -365,6 +365,7 @@
 	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,15 @@
 }
 
 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 +512,14 @@
 	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)
 {
--- a/libpurple/request.h	Tue May 03 20:55:39 2011 +0000
+++ b/libpurple/request.h	Tue May 03 21:22:51 2011 +0000
@@ -180,6 +180,7 @@
 	} u;
 
 	void *ui_data;
+	char *tooltip;
 
 };
 #endif
@@ -517,6 +518,18 @@
 									  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_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.
--- a/pidgin/gtkrequest.c	Tue May 03 20:55:39 2011 +0000
+++ b/pidgin/gtkrequest.c	Tue May 03 21:22:51 2011 +0000
@@ -862,6 +862,10 @@
 			gtk_text_buffer_set_text(buffer, value, -1);
 		}
 
+#if GTK_CHECK_VERSION(2,12,0)
+		gtk_widget_set_tooltip_text(textview, purple_request_field_get_tooltip(field));
+#endif
+
 		gtk_text_view_set_editable(GTK_TEXT_VIEW(textview),
 			purple_request_field_string_is_editable(field));
 
@@ -886,6 +890,10 @@
 		if (value != NULL)
 			gtk_entry_set_text(GTK_ENTRY(widget), value);
 
+#if GTK_CHECK_VERSION(2,12,0)
+		gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
+#endif
+
 		if (purple_request_field_string_is_masked(field))
 		{
 			gtk_entry_set_visibility(GTK_ENTRY(widget), FALSE);
@@ -926,6 +934,10 @@
 		gtk_entry_set_text(GTK_ENTRY(widget), buf);
 	}
 
+#if GTK_CHECK_VERSION(2,12,0)
+	gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
+#endif
+
 	g_signal_connect(G_OBJECT(widget), "focus-out-event",
 					 G_CALLBACK(field_int_focus_out_cb), field);
 
@@ -940,6 +952,10 @@
 	widget = gtk_check_button_new_with_label(
 		purple_request_field_get_label(field));
 
+#if GTK_CHECK_VERSION(2,12,0)
+	gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
+#endif
+
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
 		purple_request_field_bool_get_default_value(field));
 
@@ -970,6 +986,10 @@
 		gtk_combo_box_set_active(GTK_COMBO_BOX(widget),
 						purple_request_field_choice_get_default_value(field));
 
+#if GTK_CHECK_VERSION(2,12,0)
+		gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
+#endif
+
 		g_signal_connect(G_OBJECT(widget), "changed",
 						 G_CALLBACK(field_choice_menu_cb), field);
 	}
@@ -987,6 +1007,10 @@
 
 		widget = box;
 
+#if GTK_CHECK_VERSION(2,12,0)
+		gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
+#endif
+
 		for (l = labels, i = 0; l != NULL; l = l->next, i++)
 		{
 			const char *text = l->data;
@@ -1034,6 +1058,10 @@
 	g_object_unref(G_OBJECT(loader));
 	g_object_unref(G_OBJECT(scale));
 
+#if GTK_CHECK_VERSION(2,12,0)
+	gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
+#endif
+
 	return widget;
 }
 
@@ -1049,6 +1077,10 @@
 		purple_request_field_account_get_filter(field),
 		field);
 
+#if GTK_CHECK_VERSION(2,12,0)
+	gtk_widget_set_tooltip_text(widget, purple_request_field_get_tooltip(field));
+#endif
+
 	return widget;
 }