aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libempathy-gtk/empathy-chat-view.c49
-rw-r--r--libempathy-gtk/empathy-chat-view.h3
-rw-r--r--libempathy-gtk/empathy-chat.c43
-rw-r--r--libempathy-gtk/empathy-smiley-manager.c84
-rw-r--r--libempathy-gtk/empathy-smiley-manager.h7
-rw-r--r--src/empathy-chat-window.c31
6 files changed, 129 insertions, 88 deletions
diff --git a/libempathy-gtk/empathy-chat-view.c b/libempathy-gtk/empathy-chat-view.c
index f38ab1750..25c1721a4 100644
--- a/libempathy-gtk/empathy-chat-view.c
+++ b/libempathy-gtk/empathy-chat-view.c
@@ -259,52 +259,3 @@ empathy_chat_view_get_last_contact (EmpathyChatView *view)
return NULL;
}
-GtkWidget *
-empathy_chat_view_get_smiley_menu (GCallback callback,
- gpointer user_data)
-{
- EmpathySmileyManager *smiley_manager;
- GSList *smileys, *l;
- GtkWidget *menu;
- gint x = 0;
- gint y = 0;
-
- g_return_val_if_fail (callback != NULL, NULL);
-
- menu = gtk_menu_new ();
-
- smiley_manager = empathy_smiley_manager_new ();
- smileys = empathy_smiley_manager_get_all (smiley_manager);
- for (l = smileys; l; l = l->next) {
- EmpathySmiley *smiley;
- GtkWidget *item;
- GtkWidget *image;
-
- smiley = l->data;
- image = gtk_image_new_from_pixbuf (smiley->pixbuf);
-
- item = gtk_image_menu_item_new_with_label ("");
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
-
- gtk_menu_attach (GTK_MENU (menu), item,
- x, x + 1, y, y + 1);
-
- gtk_widget_set_tooltip_text (item, smiley->str);
-
- g_object_set_data (G_OBJECT (item), "smiley_text", smiley->str);
- g_signal_connect (item, "activate", callback, user_data);
-
- if (x > 3) {
- y++;
- x = 0;
- } else {
- x++;
- }
- }
- g_object_unref (smiley_manager);
-
- gtk_widget_show_all (menu);
-
- return menu;
-}
-
diff --git a/libempathy-gtk/empathy-chat-view.h b/libempathy-gtk/empathy-chat-view.h
index 1c4bd32cb..bf5140001 100644
--- a/libempathy-gtk/empathy-chat-view.h
+++ b/libempathy-gtk/empathy-chat-view.h
@@ -111,9 +111,6 @@ void empathy_chat_view_set_last_timestamp (EmpathyChatView *view,
time_t timestamp);
EmpathyContact * empathy_chat_view_get_last_contact (EmpathyChatView *view);
-GtkWidget * empathy_chat_view_get_smiley_menu (GCallback callback,
- gpointer user_data);
-
G_END_DECLS
#endif /* __EMPATHY_CHAT_VIEW_H__ */
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index ec6a46664..e305f58ab 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -49,6 +49,7 @@
#include "empathy-contact-list-view.h"
#include "empathy-contact-menu.h"
#include "empathy-chat-simple-view.h"
+#include "empathy-smiley-manager.h"
#include "empathy-ui-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
@@ -868,19 +869,18 @@ chat_input_realize_cb (GtkWidget *widget,
}
static void
-chat_insert_smiley_activate_cb (GtkWidget *menuitem,
- EmpathyChat *chat)
+chat_insert_smiley_activate_cb (EmpathySmileyManager *manager,
+ EmpathySmiley *smiley,
+ gpointer user_data)
{
+ EmpathyChat *chat = EMPATHY_CHAT (user_data);
GtkTextBuffer *buffer;
GtkTextIter iter;
- const gchar *smiley;
-
- smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
gtk_text_buffer_get_end_iter (buffer, &iter);
- gtk_text_buffer_insert (buffer, &iter, smiley, -1);
+ gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
gtk_text_buffer_get_end_iter (buffer, &iter);
gtk_text_buffer_insert (buffer, &iter, " ", -1);
@@ -942,17 +942,18 @@ chat_input_populate_popup_cb (GtkTextView *view,
GtkMenu *menu,
EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
- GtkTextBuffer *buffer;
- GtkTextTagTable *table;
- GtkTextTag *tag;
- gint x, y;
- GtkTextIter iter, start, end;
- GtkWidget *item;
- gchar *str = NULL;
- EmpathyChatSpell *chat_spell;
- GtkWidget *smiley_menu;
- GtkWidget *image;
+ EmpathyChatPriv *priv;
+ GtkTextBuffer *buffer;
+ GtkTextTagTable *table;
+ GtkTextTag *tag;
+ gint x, y;
+ GtkTextIter iter, start, end;
+ GtkWidget *item;
+ gchar *str = NULL;
+ EmpathyChatSpell *chat_spell;
+ EmpathySmileyManager *smiley_manager;
+ GtkWidget *smiley_menu;
+ GtkWidget *image;
priv = GET_PRIV (chat);
buffer = gtk_text_view_get_buffer (view);
@@ -969,10 +970,12 @@ chat_input_populate_popup_cb (GtkTextView *view,
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
- smiley_menu = empathy_chat_view_get_smiley_menu (
- G_CALLBACK (chat_insert_smiley_activate_cb),
- chat);
+ smiley_manager = empathy_smiley_manager_new ();
+ smiley_menu = empathy_smiley_menu_new (smiley_manager,
+ chat_insert_smiley_activate_cb,
+ chat);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
+ g_object_unref (smiley_manager);
/* Add the Send menu item. */
gtk_text_buffer_get_bounds (buffer, &start, &end);
diff --git a/libempathy-gtk/empathy-smiley-manager.c b/libempathy-gtk/empathy-smiley-manager.c
index c9322c8eb..4137db63d 100644
--- a/libempathy-gtk/empathy-smiley-manager.c
+++ b/libempathy-gtk/empathy-smiley-manager.c
@@ -347,3 +347,87 @@ empathy_smiley_manager_get_all (EmpathySmileyManager *manager)
return priv->smileys;
}
+typedef struct {
+ EmpathySmileyManager *manager;
+ EmpathySmiley *smiley;
+ EmpathySmileyMenuFunc func;
+ gpointer user_data;
+} ActivateData;
+
+static void
+smiley_menu_data_free (gpointer user_data,
+ GClosure *closure)
+{
+ ActivateData *data = (ActivateData*) user_data;
+
+ g_object_unref (data->manager);
+ g_slice_free (ActivateData, data);
+}
+
+static void
+smiley_menu_activate_cb (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ ActivateData *data = (ActivateData*) user_data;
+
+ data->func (data->manager, data->smiley, data->user_data);
+}
+
+GtkWidget *
+empathy_smiley_menu_new (EmpathySmileyManager *manager,
+ EmpathySmileyMenuFunc func,
+ gpointer user_data)
+{
+ EmpathySmileyManagerPriv *priv = GET_PRIV (manager);
+ GSList *l;
+ GtkWidget *menu;
+ gint x = 0;
+ gint y = 0;
+
+ g_return_val_if_fail (EMPATHY_IS_SMILEY_MANAGER (manager), NULL);
+ g_return_val_if_fail (func != NULL, NULL);
+
+ menu = gtk_menu_new ();
+
+ for (l = priv->smileys; l; l = l->next) {
+ EmpathySmiley *smiley;
+ GtkWidget *item;
+ GtkWidget *image;
+ ActivateData *data;
+
+ smiley = l->data;
+ image = gtk_image_new_from_pixbuf (smiley->pixbuf);
+
+ item = gtk_image_menu_item_new_with_label ("");
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+
+ gtk_menu_attach (GTK_MENU (menu), item,
+ x, x + 1, y, y + 1);
+
+ gtk_widget_set_tooltip_text (item, smiley->str);
+
+ data = g_slice_new (ActivateData);
+ data->manager = g_object_ref (manager);
+ data->smiley = smiley;
+ data->func = func;
+ data->user_data = user_data;
+
+ g_signal_connect_data (item, "activate",
+ G_CALLBACK (smiley_menu_activate_cb),
+ data,
+ smiley_menu_data_free,
+ 0);
+
+ if (x > 3) {
+ y++;
+ x = 0;
+ } else {
+ x++;
+ }
+ }
+
+ gtk_widget_show_all (menu);
+
+ return menu;
+}
+
diff --git a/libempathy-gtk/empathy-smiley-manager.h b/libempathy-gtk/empathy-smiley-manager.h
index 394215ed6..c73675742 100644
--- a/libempathy-gtk/empathy-smiley-manager.h
+++ b/libempathy-gtk/empathy-smiley-manager.h
@@ -52,6 +52,10 @@ typedef struct {
gchar *str;
} EmpathySmiley;
+typedef void (*EmpathySmileyMenuFunc) (EmpathySmileyManager *manager,
+ EmpathySmiley *smiley,
+ gpointer user_data);
+
GType empathy_smiley_manager_get_type (void) G_GNUC_CONST;
EmpathySmileyManager *empathy_smiley_manager_new (void);
void empathy_smiley_manager_load (EmpathySmileyManager *manager);
@@ -66,6 +70,9 @@ void empathy_smiley_manager_add_from_pixbuf (EmpathySmileyManag
GSList * empathy_smiley_manager_get_all (EmpathySmileyManager *manager);
GSList * empathy_smiley_manager_parse (EmpathySmileyManager *manager,
const gchar *text);
+GtkWidget * empathy_smiley_menu_new (EmpathySmileyManager *manager,
+ EmpathySmileyMenuFunc func,
+ gpointer user_data);
void empathy_smiley_free (EmpathySmiley *smiley);
G_END_DECLS
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index ae63b894e..c5e933908 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -49,6 +49,7 @@
#include <libempathy-gtk/empathy-contact-dialogs.h>
#include <libempathy-gtk/empathy-log-window.h>
#include <libempathy-gtk/empathy-geometry.h>
+#include <libempathy-gtk/empathy-smiley-manager.h>
#include <libempathy-gtk/empathy-ui-utils.h>
#include "empathy-chat-window.h"
@@ -465,25 +466,20 @@ chat_window_chat_notify_cb (EmpathyChat *chat)
}
static void
-chat_window_insert_smiley_activate_cb (GtkWidget *menuitem,
- EmpathyChatWindow *window)
+chat_window_insert_smiley_activate_cb (EmpathySmileyManager *manager,
+ EmpathySmiley *smiley,
+ gpointer window)
{
- EmpathyChatWindowPriv *priv;
+ EmpathyChatWindowPriv *priv = GET_PRIV (window);
EmpathyChat *chat;
- GtkTextBuffer *buffer;
- GtkTextIter iter;
- const gchar *smiley;
-
- priv = GET_PRIV (window);
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
chat = priv->current_chat;
- smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
-
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
gtk_text_buffer_get_end_iter (buffer, &iter);
- gtk_text_buffer_insert (buffer, &iter,
- smiley, -1);
+ gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
}
static void
@@ -1183,6 +1179,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
gint i;
GtkWidget *chat_vbox;
gchar *filename;
+ EmpathySmileyManager *smiley_manager;
EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);
@@ -1257,10 +1254,12 @@ empathy_chat_window_init (EmpathyChatWindow *window)
g_object_unref (accel_group);
/* Set up smiley menu */
- menu = empathy_chat_view_get_smiley_menu (
- G_CALLBACK (chat_window_insert_smiley_activate_cb),
- window);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_insert_smiley), menu);
+ smiley_manager = empathy_smiley_manager_new ();
+ menu = empathy_smiley_menu_new (smiley_manager,
+ chat_window_insert_smiley_activate_cb,
+ window);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_insert_smiley),
+ menu);
/* Set up signals we can't do with glade since we may need to
* block/unblock them at some later stage.