/dev/tomkiewicz/new-smileys: 4423f463a782: Smileys in PidginWebv...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Tue Apr 1 09:20:53 EDT 2014
Changeset: 4423f463a782104e5581402e05977da1554c3ae4
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-01 15:20 +0200
Branch: default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/4423f463a782
Description:
Smileys in PidginWebviewToolbar
diffstat:
libpurple/smiley-list.c | 21 +++
libpurple/smiley-list.h | 3 +
libpurple/smiley-parser.c | 12 +-
pidgin/gtkconv.c | 4 +
pidgin/gtksmiley-theme.c | 23 ++++
pidgin/gtksmiley-theme.h | 3 +
pidgin/gtkutils.c | 1 -
pidgin/gtkwebview.c | 17 ++-
pidgin/gtkwebview.h | 4 +
pidgin/gtkwebviewtoolbar.c | 255 ++++++++++++++------------------------------
pidgin/gtkwebviewtoolbar.h | 10 -
11 files changed, 161 insertions(+), 192 deletions(-)
diffs (truncated from 650 to 300 lines):
diff --git a/libpurple/smiley-list.c b/libpurple/smiley-list.c
--- a/libpurple/smiley-list.c
+++ b/libpurple/smiley-list.c
@@ -33,6 +33,7 @@ typedef struct {
GList *smileys;
GList *smileys_end;
PurpleTrie *trie;
+ GHashTable *unique_map;
} PurpleSmileyListPrivate;
enum
@@ -91,6 +92,7 @@ gboolean
purple_smiley_list_add(PurpleSmileyList *list, PurpleSmiley *smiley)
{
PurpleSmileyListPrivate *priv = PURPLE_SMILEY_LIST_GET_PRIVATE(list);
+ const gchar *smiley_path;
gboolean succ;
g_return_val_if_fail(priv != NULL, FALSE);
@@ -113,6 +115,12 @@ purple_smiley_list_add(PurpleSmileyList
g_object_set_data(G_OBJECT(smiley), "purple-smiley-list-elem",
priv->smileys_end);
+ smiley_path = purple_smiley_get_path(smiley);
+ if (g_hash_table_lookup(priv->unique_map, smiley_path) == NULL) {
+ g_hash_table_insert(priv->unique_map,
+ g_strdup(smiley_path), smiley);
+ }
+
return TRUE;
}
@@ -151,6 +159,16 @@ purple_smiley_list_get_trie(PurpleSmiley
return priv->trie;
}
+GList *
+purple_smiley_list_get_unique(PurpleSmileyList *list)
+{
+ PurpleSmileyListPrivate *priv = PURPLE_SMILEY_LIST_GET_PRIVATE(list);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return g_hash_table_get_values(priv->unique_map);
+}
+
/*******************************************************************************
* Object stuff
@@ -163,6 +181,8 @@ purple_smiley_list_init(GTypeInstance *i
PurpleSmileyListPrivate *priv = PURPLE_SMILEY_LIST_GET_PRIVATE(sl);
priv->trie = purple_trie_new();
+ priv->unique_map = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, NULL);
PURPLE_DBUS_REGISTER_POINTER(sl, PurpleSmileyList);
}
@@ -175,6 +195,7 @@ purple_smiley_list_finalize(GObject *obj
GList *it;
g_object_unref(priv->trie);
+ g_hash_table_destroy(priv->unique_map);
for (it = priv->smileys; it; it = g_list_next(it)) {
PurpleSmiley *smiley = it->data;
diff --git a/libpurple/smiley-list.h b/libpurple/smiley-list.h
--- a/libpurple/smiley-list.h
+++ b/libpurple/smiley-list.h
@@ -81,6 +81,9 @@ purple_smiley_list_remove(PurpleSmileyLi
PurpleTrie *
purple_smiley_list_get_trie(PurpleSmileyList *list);
+GList *
+purple_smiley_list_get_unique(PurpleSmileyList *list_);
+
G_END_DECLS
#endif /* _PURPLE_SMILEY_H_ */
diff --git a/libpurple/smiley-parser.c b/libpurple/smiley-parser.c
--- a/libpurple/smiley-parser.c
+++ b/libpurple/smiley-parser.c
@@ -41,22 +41,16 @@ purple_smiley_parse(const gchar *message
PurpleSmileyList *theme_smileys;
PurpleTrie *theme_trie;
- if (message == NULL || message[0] == '\0') {
- purple_debug_info("tomo", "no msg");
+ if (message == NULL || message[0] == '\0')
return g_strdup(message);
- }
theme = purple_smiley_theme_get_current();
- if (theme == NULL) {
- purple_debug_info("tomo", "no theme");
+ if (theme == NULL)
return g_strdup(message);
- }
theme_smileys = purple_smiley_theme_get_smileys(theme, ui_data);
- if (theme_smileys == NULL) {
- purple_debug_info("tomo", "no smileys");
+ if (theme_smileys == NULL)
return g_strdup(message);
- }
theme_trie = purple_smiley_list_get_trie(theme_smileys);
g_return_val_if_fail(theme_trie != NULL, g_strdup(message));
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -2368,6 +2368,8 @@ pidgin_conv_switch_active_conversation(P
purple_conversation_close_logs(old_conv);
gtkconv->active_conv = conv;
+ pidgin_webview_switch_active_conversation(
+ PIDGIN_WEBVIEW(gtkconv->entry), conv);
purple_conversation_set_logging(conv,
gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(gtkconv->win->menu->logging)));
@@ -6086,6 +6088,8 @@ private_gtkconv_new(PurpleConversation *
pidgin_webview_show_toolbar(PIDGIN_WEBVIEW(gtkconv->entry));
else
pidgin_webview_hide_toolbar(PIDGIN_WEBVIEW(gtkconv->entry));
+ pidgin_webview_switch_active_conversation(
+ PIDGIN_WEBVIEW(gtkconv->entry), conv);
if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/im/show_buddy_icons"))
gtk_widget_show(gtkconv->infopane_hbox);
diff --git a/pidgin/gtksmiley-theme.c b/pidgin/gtksmiley-theme.c
--- a/pidgin/gtksmiley-theme.c
+++ b/pidgin/gtksmiley-theme.c
@@ -247,6 +247,7 @@ pidgin_smiley_theme_index_parse(const gc
g_strdup(token));
}
g_strfreev(split);
+ smiley->shortcuts = g_list_reverse(smiley->shortcuts);
}
fclose(file);
@@ -416,6 +417,28 @@ pidgin_smiley_theme_get_author(PidginSmi
return priv->author;
}
+PurpleSmileyList *
+pidgin_smiley_theme_for_conv(PurpleConversation *conv)
+{
+ PurpleAccount *acc;
+ PurpleSmileyTheme *theme;
+ const gchar *proto_name;
+
+ g_return_val_if_fail(conv != NULL, 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);
+
+ return purple_smiley_theme_get_smileys(theme, (gpointer)proto_name);
+}
+
static void
pidgin_smiley_theme_activate_impl(PurpleSmileyTheme *theme)
{
diff --git a/pidgin/gtksmiley-theme.h b/pidgin/gtksmiley-theme.h
--- a/pidgin/gtksmiley-theme.h
+++ b/pidgin/gtksmiley-theme.h
@@ -81,6 +81,9 @@ pidgin_smiley_theme_get_icon(PidginSmile
const gchar *
pidgin_smiley_theme_get_author(PidginSmileyTheme *theme);
+PurpleSmileyList *
+pidgin_smiley_theme_for_conv(PurpleConversation *conv);
+
void
pidgin_smiley_theme_init(void);
diff --git a/pidgin/gtkutils.c b/pidgin/gtkutils.c
--- a/pidgin/gtkutils.c
+++ b/pidgin/gtkutils.c
@@ -309,7 +309,6 @@ pidgin_create_webview(gboolean editable,
if (editable) {
pidgin_webviewtoolbar_attach(PIDGIN_WEBVIEWTOOLBAR(toolbar), webview);
- pidgin_webviewtoolbar_associate_smileys(PIDGIN_WEBVIEWTOOLBAR(toolbar), "default");
pidgin_webview_set_toolbar(PIDGIN_WEBVIEW(webview), toolbar);
}
pidgin_setup_webview(webview);
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -660,6 +660,8 @@ pidgin_webview_insert_smiley(PidginWebVi
unescaped = purple_unescape_html(smiley);
webview_smiley = pidgin_webview_smiley_find(webview, sml, unescaped);
+#if 0
+ /* TODO */
if (priv->format_functions & PIDGIN_WEBVIEW_SMILEY) {
char *tmp;
/* TODO Better smiley insertion... */
@@ -667,7 +669,9 @@ pidgin_webview_insert_smiley(PidginWebVi
webview_smiley, smiley);
pidgin_webview_append_html(webview, tmp);
g_free(tmp);
- } else {
+ } else
+#endif
+ {
pidgin_webview_append_html(webview, smiley);
}
@@ -2442,3 +2446,14 @@ pidgin_webview_activate_toolbar(PidginWe
pidgin_webviewtoolbar_activate(priv->toolbar, action);
}
+void
+pidgin_webview_switch_active_conversation(PidginWebView *webview,
+ PurpleConversation *conv)
+{
+ PidginWebViewPriv *priv = PIDGIN_WEBVIEW_GET_PRIVATE(webview);
+
+ g_return_if_fail(priv != NULL);
+ g_return_if_fail(priv->toolbar != NULL);
+
+ pidgin_webviewtoolbar_switch_active_conversation(priv->toolbar, conv);
+}
diff --git a/pidgin/gtkwebview.h b/pidgin/gtkwebview.h
--- a/pidgin/gtkwebview.h
+++ b/pidgin/gtkwebview.h
@@ -735,6 +735,10 @@ void pidgin_webview_hide_toolbar(PidginW
*/
void pidgin_webview_activate_toolbar(PidginWebView *webview, PidginWebViewAction action);
+void
+pidgin_webview_switch_active_conversation(PidginWebView *webview,
+ PurpleConversation *conv);
+
/* Do not use. */
void
pidgin_webview_set_toolbar(PidginWebView *webview, GtkWidget *toolbar);
diff --git a/pidgin/gtkwebviewtoolbar.c b/pidgin/gtkwebviewtoolbar.c
--- a/pidgin/gtkwebviewtoolbar.c
+++ b/pidgin/gtkwebviewtoolbar.c
@@ -27,12 +27,14 @@
#include "prefs.h"
#include "request.h"
#include "pidginstock.h"
+#include "smiley-list.h"
#include "util.h"
#include "debug.h"
#include "gtkdialogs.h"
#include "gtkwebviewtoolbar.h"
#include "gtksmiley.h"
+#include "gtksmiley-theme.h"
#include "gtkutils.h"
#include <gdk/gdkkeysyms.h>
@@ -90,8 +92,6 @@ typedef struct _PidginWebViewToolbarPriv
GtkWidget *link_dialog;
GtkWidget *smiley_dialog;
GtkWidget *image_dialog;
-
- char *sml;
} PidginWebViewToolbarPriv;
/******************************************************************************
@@ -713,38 +713,50 @@ insert_smiley_text(GtkWidget *widget, Pi
close_smiley_dialog(toolbar);
}
-/* smiley buttons list */
-struct smiley_button_list {
- int width, height;
- GtkWidget *button;
- const PidginWebViewSmiley *smiley;
- struct smiley_button_list *next;
-};
+static gboolean
+smiley_dialog_input_cb(GtkWidget *dialog, GdkEvent *event,
+ PidginWebViewToolbar *toolbar)
+{
+ if ((event->type == GDK_KEY_PRESS && event->key.keyval == GDK_KEY_Escape) ||
+ (event->type == GDK_BUTTON_PRESS && event->button.button == 1))
+ {
+ close_smiley_dialog(toolbar);
+ return TRUE;
+ }
-static struct smiley_button_list *
-sort_smileys(struct smiley_button_list *ls, PidginWebViewToolbar *toolbar,
- int *width, const PidginWebViewSmiley *smiley)
+ return FALSE;
+}
+
More information about the Commits
mailing list