/dev/tomkiewicz/new-smileys: 030ce6840163: Smileys: toolbar butt...

Tomasz Wasilczyk twasilczyk at pidgin.im
Thu Apr 3 18:47:50 EDT 2014


Changeset: 030ce6840163a6bd4e6649264b68b0f9285f8f79
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-04 00:47 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/030ce6840163

Description:

Smileys: toolbar button sensitivity

diffstat:

 libpurple/smiley-list.c    |  10 ++++++
 libpurple/smiley-list.h    |   3 ++
 pidgin/gtksmiley-theme.c   |  13 +++-----
 pidgin/gtkwebviewtoolbar.c |  67 +++++++++++++++++++++++++++++++++------------
 4 files changed, 67 insertions(+), 26 deletions(-)

diffs (181 lines):

diff --git a/libpurple/smiley-list.c b/libpurple/smiley-list.c
--- a/libpurple/smiley-list.c
+++ b/libpurple/smiley-list.c
@@ -186,6 +186,16 @@ purple_smiley_list_remove(PurpleSmileyLi
 	g_object_unref(smiley);
 }
 
+gboolean
+purple_smiley_list_is_empty(PurpleSmileyList *list)
+{
+	PurpleSmileyListPrivate *priv = PURPLE_SMILEY_LIST_GET_PRIVATE(list);
+
+	g_return_val_if_fail(priv != NULL, TRUE);
+
+	return (priv->smileys == NULL);
+}
+
 PurpleSmiley *
 purple_smiley_list_get_by_shortcut(PurpleSmileyList *list,
 	const gchar *shortcut)
diff --git a/libpurple/smiley-list.h b/libpurple/smiley-list.h
--- a/libpurple/smiley-list.h
+++ b/libpurple/smiley-list.h
@@ -78,6 +78,9 @@ purple_smiley_list_add(PurpleSmileyList 
 void
 purple_smiley_list_remove(PurpleSmileyList *list, PurpleSmiley *smiley);
 
+gboolean
+purple_smiley_list_is_empty(PurpleSmileyList *list);
+
 PurpleSmiley *
 purple_smiley_list_get_by_shortcut(PurpleSmileyList *list,
 	const gchar *shortcut);
diff --git a/pidgin/gtksmiley-theme.c b/pidgin/gtksmiley-theme.c
--- a/pidgin/gtksmiley-theme.c
+++ b/pidgin/gtksmiley-theme.c
@@ -422,19 +422,16 @@ pidgin_smiley_theme_for_conv(PurpleConve
 {
 	PurpleAccount *acc;
 	PurpleSmileyTheme *theme;
-	const gchar *proto_name;
-
-	g_return_val_if_fail(conv != NULL, NULL);
+	const gchar *proto_name = NULL;
 
 	theme = purple_smiley_theme_get_current();
 	if (theme == NULL)
 		return NULL;
 
-	acc = purple_conversation_get_account(conv);
-	g_return_val_if_fail(acc != NULL, NULL);
-
-	proto_name = purple_account_get_protocol_name(acc);
-	g_return_val_if_fail(proto_name != NULL, NULL);
+	if (conv)
+		acc = purple_conversation_get_account(conv);
+	if (acc)
+		proto_name = purple_account_get_protocol_name(acc);
 
 	return purple_smiley_theme_get_smileys(theme, (gpointer)proto_name);
 }
diff --git a/pidgin/gtkwebviewtoolbar.c b/pidgin/gtkwebviewtoolbar.c
--- a/pidgin/gtkwebviewtoolbar.c
+++ b/pidgin/gtkwebviewtoolbar.c
@@ -93,6 +93,8 @@ typedef struct _PidginWebViewToolbarPriv
 	GtkWidget *link_dialog;
 	GtkWidget *smiley_dialog;
 	GtkWidget *image_dialog;
+
+	gboolean allow_smileys;
 } PidginWebViewToolbarPriv;
 
 /******************************************************************************
@@ -820,9 +822,10 @@ add_smiley_list(PidginWebViewToolbar *to
 static void
 insert_smiley_cb(GtkAction *smiley, PidginWebViewToolbar *toolbar)
 {
-	PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	PidginWebViewToolbarPriv *priv =
+		PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
 	PurpleSmileyList *smileys_from_theme, *smileys_from_custom = NULL;
-	GList *theme_smileys, *custom_smileys = NULL;
+	GList *theme_smileys = NULL, *custom_smileys = NULL;
 	PidginWebViewButtons webview_format;
 
 	GtkWidget *dialog, *vbox;
@@ -841,7 +844,10 @@ insert_smiley_cb(GtkAction *smiley, Pidg
 		PIDGIN_WEBVIEW(toolbar->webview));
 
 	smileys_from_theme = pidgin_smiley_theme_for_conv(priv->active_conv);
-	theme_smileys = purple_smiley_list_get_unique(smileys_from_theme);
+	if (smileys_from_theme) {
+		theme_smileys = purple_smiley_list_get_unique(
+			smileys_from_theme);
+	}
 	/* TODO: remove hidden */
 
 	supports_custom = (webview_format & PIDGIN_WEBVIEW_CUSTOM_SMILEY);
@@ -960,6 +966,40 @@ insert_smiley_cb(GtkAction *smiley, Pidg
 }
 
 static void
+update_smiley_button(PidginWebViewToolbar *toolbar)
+{
+	PidginWebViewToolbarPriv *priv =
+		PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
+	PurpleSmileyList *sl;
+	gboolean any_smileys;
+	PidginWebViewButtons webview_format = 0;
+
+	g_return_if_fail(priv != NULL);
+
+	if (toolbar->webview) {
+		webview_format = pidgin_webview_get_format_functions(
+			PIDGIN_WEBVIEW(toolbar->webview));
+	}
+
+	if (!priv->allow_smileys) {
+		gtk_action_set_sensitive(priv->smiley, FALSE);
+		return;
+	}
+
+	sl = pidgin_smiley_theme_for_conv(priv->active_conv);
+	/* it's possible, that all theme smileys are hidden,
+	 * but we won't handle it */
+	any_smileys = (sl ? !purple_smiley_list_is_empty(sl) : FALSE);
+
+	if (!any_smileys && (webview_format & PIDGIN_WEBVIEW_CUSTOM_SMILEY)) {
+		sl = purple_smiley_custom_get_list();
+		any_smileys = (sl ? !purple_smiley_list_is_empty(sl) : FALSE);
+	}
+
+	gtk_action_set_sensitive(priv->smiley, any_smileys);
+}
+
+static void
 send_attention_cb(GtkAction *attention, PidginWebViewToolbar *toolbar)
 {
 	PidginWebViewToolbarPriv *priv = PIDGIN_WEBVIEWTOOLBAR_GET_PRIVATE(toolbar);
@@ -1002,11 +1042,9 @@ update_buttons_cb(PidginWebView *webview
 
 	gtk_action_set_sensitive(priv->image, buttons & PIDGIN_WEBVIEW_IMAGE);
 	gtk_action_set_sensitive(priv->link, buttons & PIDGIN_WEBVIEW_LINK);
-#if 0
-	/* TODO */
-	gtk_action_set_sensitive(priv->smiley, (buttons & PIDGIN_WEBVIEW_SMILEY) &&
-		pidgin_themes_get_proto_smileys(priv->sml));
-#endif
+
+	priv->allow_smileys = !!(buttons & PIDGIN_WEBVIEW_SMILEY);
+	update_smiley_button(toolbar);
 }
 
 /* we call this when we want to _set_active the toggle button, it'll
@@ -1545,11 +1583,8 @@ pidgin_webviewtoolbar_init(PidginWebView
 	/* set attention button to be greyed out until we get a conversation */
 	gtk_action_set_sensitive(priv->attention, FALSE);
 
-#if 0
-	/* TODO */
-	gtk_action_set_sensitive(priv->smiley,
-			pidgin_themes_get_proto_smileys(NULL) != NULL);
-#endif
+	priv->allow_smileys = TRUE;
+	update_smiley_button(toolbar);
 
 	purple_prefs_connect_callback(toolbar,
 	                              PIDGIN_PREFS_ROOT "/conversations/toolbar/wide",
@@ -1642,11 +1677,7 @@ pidgin_webviewtoolbar_switch_active_conv
 		conv && prpl && PURPLE_IS_IM_CONVERSATION(conv) &&
 		PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->send_attention != NULL);
 
-#if 0
-	/* TODO */
-	gtk_action_set_sensitive(priv->smiley,
-		pidgin_themes_get_proto_smileys(priv->sml) != NULL);
-#endif
+	update_smiley_button(toolbar);
 }
 
 void



More information about the Commits mailing list