Mercurial > pidgin
changeset 12712:8ae981f2c9cb
[gaim-migrate @ 15056]
SF Patch #1395207 from Sadrul
"Gaim currently doesn't allow to have
formatted/multiline string as a preference for
core-plugins. It'd be great if core plugins could have
formatted strings for preference (ie. have
imhtml+toolbar for the preference in the
Plugin-preference dialog) without actually having to
worry about gtk-codes."
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 04 Jan 2006 04:14:02 +0000 |
parents | 145f76e74a9f |
children | d7043c3c793d |
files | plugins/ChangeLog.API src/gtkpluginpref.c src/pluginpref.c src/pluginpref.h src/prefs.h |
diffstat | 5 files changed, 108 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/ChangeLog.API Wed Jan 04 03:01:32 2006 +0000 +++ b/plugins/ChangeLog.API Wed Jan 04 04:14:02 2006 +0000 @@ -211,6 +211,10 @@ * GaimConversationUiOps->present(GaimConversation *) * GaimPlugin.unloadable * gaim_plugin_is_unloadable() + * GAIM_PLUGIN_PREF_STRING_FORMAT + * gaim_plugin_pref_get_format_type() + * gaim_plugin_pref_set_format_type() + * GaimStringFormatType Signals - Changed: (See the Doxygen docs for details on all signals.) * Signal propagation now stops after a handler returns a non-NULL value.
--- a/src/gtkpluginpref.c Wed Jan 04 03:01:32 2006 +0000 +++ b/src/gtkpluginpref.c Wed Jan 04 04:14:02 2006 +0000 @@ -31,6 +31,7 @@ #include "pluginpref.h" #include "prefs.h" +#include "gtkimhtml.h" #include "gtkpluginpref.h" #include "gtkprefs.h" #include "gtkutils.h" @@ -44,13 +45,34 @@ return FALSE; } + +static void +imhtml_cb(GtkTextBuffer *buffer, gpointer data) +{ + char *pref; + char *text; + GtkIMHtml *imhtml = data; + + pref = g_object_get_data(G_OBJECT(imhtml), "pref-key"); + g_return_if_fail(pref); + + text = gtk_imhtml_get_markup(imhtml); + + if (!text) + text = ""; + gaim_prefs_set_string(pref, text); + g_free(text); +} + static void make_string_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) { GtkWidget *hbox, *gtk_label, *entry; gchar *pref_name, *pref_label; + GaimStringFormatType format; pref_name = gaim_plugin_pref_get_name(pref); pref_label = gaim_plugin_pref_get_label(pref); + format = gaim_plugin_pref_get_format_type(pref); switch(gaim_plugin_pref_get_type(pref)) { case GAIM_PLUGIN_PREF_CHOICE: @@ -77,21 +99,41 @@ if(sg) gtk_size_group_add_widget(sg, gtk_label); - entry = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(entry), gaim_prefs_get_string(pref_name)); - gtk_entry_set_max_length(GTK_ENTRY(entry), + if (format == GAIM_STRING_FORMAT_TYPE_NONE) + { + entry = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(entry), gaim_prefs_get_string(pref_name)); + gtk_entry_set_max_length(GTK_ENTRY(entry), gaim_plugin_pref_get_max_length(pref)); - if (gaim_plugin_pref_get_masked(pref)) + if (gaim_plugin_pref_get_masked(pref)) + { + gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); + gtk_entry_set_invisible_char(GTK_ENTRY(entry), GAIM_INVISIBLE_CHAR); + } + g_signal_connect(G_OBJECT(entry), "changed", + G_CALLBACK(entry_cb), + (gpointer)pref_name); + gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), entry); + gtk_widget_show(entry); + gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); + } + else { - gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); - gtk_entry_set_invisible_char(GTK_ENTRY(entry), GAIM_INVISIBLE_CHAR); + GtkWidget *imhtml, *toolbar, *frame; + + frame = gaim_gtk_create_imhtml(TRUE, &imhtml, &toolbar); + if (!(format & GAIM_STRING_FORMAT_TYPE_HTML)) + gtk_widget_destroy(toolbar); + + gtk_imhtml_append_text(GTK_IMHTML(imhtml), gaim_prefs_get_string(pref_name), + (format & GAIM_STRING_FORMAT_TYPE_MULTILINE) ? 0 : GTK_IMHTML_NO_NEWLINE); + gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), imhtml); + gtk_widget_show_all(frame); + g_object_set_data(G_OBJECT(imhtml), "pref-key", pref_name); + g_signal_connect(G_OBJECT(gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml))), + "changed", G_CALLBACK(imhtml_cb), imhtml); + gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0); } - g_signal_connect(G_OBJECT(entry), "changed", - G_CALLBACK(entry_cb), - (gpointer)pref_name); - gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), entry); - gtk_widget_show(entry); - gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); break; }
--- a/src/pluginpref.c Wed Jan 04 03:01:32 2006 +0000 +++ b/src/pluginpref.c Wed Jan 04 04:14:02 2006 +0000 @@ -45,6 +45,7 @@ GList *choices; unsigned int max_length; gboolean masked; + GaimStringFormatType format; }; GaimPluginPrefFrame * @@ -293,3 +294,24 @@ return pref->masked; } + +void +gaim_plugin_pref_set_format_type(GaimPluginPref *pref, GaimStringFormatType format) +{ + g_return_if_fail(pref); + g_return_if_fail(pref->type == GAIM_PLUGIN_PREF_STRING_FORMAT); + + pref->format = format; +} + +GaimStringFormatType +gaim_plugin_pref_get_format_type(GaimPluginPref *pref) +{ + g_return_val_if_fail(pref, 0); + + if (pref->type != GAIM_PLUGIN_PREF_STRING_FORMAT) + return GAIM_STRING_FORMAT_TYPE_NONE; + + return pref->format; +} +
--- a/src/pluginpref.h Wed Jan 04 03:01:32 2006 +0000 +++ b/src/pluginpref.h Wed Jan 04 04:14:02 2006 +0000 @@ -33,6 +33,7 @@ GAIM_PLUGIN_PREF_NONE, GAIM_PLUGIN_PREF_CHOICE, GAIM_PLUGIN_PREF_INFO, /**< no-value label */ + GAIM_PLUGIN_PREF_STRING_FORMAT } GaimPluginPrefType; #include <glib.h> @@ -231,6 +232,23 @@ */ gboolean gaim_plugin_pref_get_masked(GaimPluginPref *pref); +/** + * Sets the format type for a formattable-string plugin pref. You need to set the + * pref type to GAIM_PLUGIN_PREF_STRING_FORMAT first before setting the format. + * + * @param pref The plugin pref + * @param format The format of the string + */ +void gaim_plugin_pref_set_format_type(GaimPluginPref *pref, GaimStringFormatType format); + +/** + * Gets the format type of the formattable-string plugin pref. + * + * @param pref The plugin pref + * @return The format of the pref + */ +GaimStringFormatType gaim_plugin_pref_get_format_type(GaimPluginPref *pref); + /*@}*/ #ifdef __cplusplus
--- a/src/prefs.h Wed Jan 04 03:01:32 2006 +0000 +++ b/src/prefs.h Wed Jan 04 04:14:02 2006 +0000 @@ -29,6 +29,16 @@ #include <glib.h> /** + * String format for preferences. + */ +typedef enum +{ + GAIM_STRING_FORMAT_TYPE_NONE = 0, + GAIM_STRING_FORMAT_TYPE_MULTILINE = 1 << 0, + GAIM_STRING_FORMAT_TYPE_HTML = 1 << 1 +} GaimStringFormatType; + +/** * Pref data types. */ typedef enum _GaimPrefType