diff options
author | Xavier Claessens <xclaesse@src.gnome.org> | 2008-12-16 17:24:11 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2008-12-16 17:24:11 +0800 |
commit | 4782781b30c2884f07a7451da03eca3244c62b6f (patch) | |
tree | a13371defb894b023bf9d2bdfdffd60c345abf7c /libempathy-gtk | |
parent | 92e2f7b40ef560f2bc35c5da887c0c3967b24ba5 (diff) | |
download | gsoc2013-empathy-4782781b30c2884f07a7451da03eca3244c62b6f.tar gsoc2013-empathy-4782781b30c2884f07a7451da03eca3244c62b6f.tar.gz gsoc2013-empathy-4782781b30c2884f07a7451da03eca3244c62b6f.tar.bz2 gsoc2013-empathy-4782781b30c2884f07a7451da03eca3244c62b6f.tar.lz gsoc2013-empathy-4782781b30c2884f07a7451da03eca3244c62b6f.tar.xz gsoc2013-empathy-4782781b30c2884f07a7451da03eca3244c62b6f.tar.zst gsoc2013-empathy-4782781b30c2884f07a7451da03eca3244c62b6f.zip |
Move the smiley menu code from EmpathyChatView to EmpathyChatManager.
svn path=/trunk/; revision=1986
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-chat-view.c | 49 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat-view.h | 3 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 43 | ||||
-rw-r--r-- | libempathy-gtk/empathy-smiley-manager.c | 84 | ||||
-rw-r--r-- | libempathy-gtk/empathy-smiley-manager.h | 7 |
5 files changed, 114 insertions, 72 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 |