]> git.0d.be Git - empathy.git/commitdiff
Add path in EmpathySmiley
authorXavier Claessens <xclaesse@gmail.com>
Thu, 17 Jul 2008 08:28:50 +0000 (10:28 +0200)
committerXavier Claessens <xclaesse@gmail.com>
Thu, 11 Jun 2009 16:06:29 +0000 (18:06 +0200)
libempathy-gtk/empathy-smiley-manager.c
libempathy-gtk/empathy-smiley-manager.h
libempathy-gtk/empathy-theme-adium.c
libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h

index a729a2929c67ab0af78d50e82b932399c610e02f..21384c75b5d78c9c2451ac1ab30417de84e12f7b 100644 (file)
@@ -37,9 +37,10 @@ typedef struct {
 } EmpathySmileyManagerPriv;
 
 struct _SmileyManagerTree {
-       gunichar   c;
-       GdkPixbuf *pixbuf;
-       GSList    *childrens;
+       gunichar     c;
+       GdkPixbuf   *pixbuf;
+       const gchar *path;
+       GSList      *childrens;
 };
 
 G_DEFINE_TYPE (EmpathySmileyManager, empathy_smiley_manager, G_TYPE_OBJECT);
@@ -55,6 +56,7 @@ smiley_manager_tree_new (gunichar c)
        tree->c = c;
        tree->pixbuf = NULL;
        tree->childrens = NULL;
+       tree->path = NULL;
 
        return tree;
 }
@@ -81,7 +83,7 @@ smiley_manager_tree_free (SmileyManagerTree *tree)
 
 /* Note: This function takes the ownership of str */
 static EmpathySmiley *
-smiley_new (GdkPixbuf *pixbuf, gchar *str)
+smiley_new (GdkPixbuf *pixbuf, gchar *str, const gchar *path)
 {
        EmpathySmiley *smiley;
 
@@ -90,6 +92,7 @@ smiley_new (GdkPixbuf *pixbuf, gchar *str)
                smiley->pixbuf = g_object_ref (pixbuf);
        }
        smiley->str = str;
+       smiley->path = path;
 
        return smiley;
 }
@@ -112,8 +115,16 @@ static void
 smiley_manager_finalize (GObject *object)
 {
        EmpathySmileyManagerPriv *priv = GET_PRIV (object);
+       GSList                   *l;
 
        smiley_manager_tree_free (priv->tree);
+       for (l = priv->smileys; l; l = l->next) {
+               EmpathySmiley *smiley = l->data;
+
+               /* The smiley got the ownership of the path */
+               g_free ((gchar*) smiley->path);
+               empathy_smiley_free (smiley);
+       }
        g_slist_foreach (priv->smileys, (GFunc) empathy_smiley_free, NULL);
        g_slist_free (priv->smileys);
 }
@@ -201,8 +212,9 @@ smiley_manager_tree_find_or_insert_child (SmileyManagerTree *tree, gunichar c)
 
 static void
 smiley_manager_tree_insert (SmileyManagerTree *tree,
-                           GdkPixbuf         *smiley,
-                           const gchar       *str)
+                           GdkPixbuf         *pixbuf,
+                           const gchar       *str,
+                           const gchar       *path)
 {
        SmileyManagerTree *child;
 
@@ -210,28 +222,32 @@ smiley_manager_tree_insert (SmileyManagerTree *tree,
 
        str = g_utf8_next_char (str);
        if (*str) {
-               smiley_manager_tree_insert (child, smiley, str);
+               smiley_manager_tree_insert (child, pixbuf, str, path);
                return;
        }
 
-       child->pixbuf = g_object_ref (smiley);
+       child->pixbuf = g_object_ref (pixbuf);
+       child->path = path;
 }
 
 static void
 smiley_manager_add_valist (EmpathySmileyManager *manager,
-                          GdkPixbuf            *smiley,
+                          GdkPixbuf            *pixbuf,
+                          gchar                *path,
                           const gchar          *first_str,
                           va_list               var_args)
 {
        EmpathySmileyManagerPriv *priv = GET_PRIV (manager);
        const gchar              *str;
+       EmpathySmiley            *smiley;
 
        for (str = first_str; str; str = va_arg (var_args, gchar*)) {
-               smiley_manager_tree_insert (priv->tree, smiley, str);
+               smiley_manager_tree_insert (priv->tree, pixbuf, str, path);
        }
 
-       priv->smileys = g_slist_prepend (priv->smileys,
-               smiley_new (smiley, g_strdup (first_str)));
+       /* We give the ownership of path to the smiley */
+       smiley = smiley_new (pixbuf, g_strdup (first_str), path);
+       priv->smileys = g_slist_prepend (priv->smileys, smiley);
 }
 
 void
@@ -240,39 +256,25 @@ empathy_smiley_manager_add (EmpathySmileyManager *manager,
                            const gchar          *first_str,
                            ...)
 {
-       GdkPixbuf *smiley;
+       GdkPixbuf *pixbuf;
        va_list    var_args;
 
        g_return_if_fail (EMPATHY_IS_SMILEY_MANAGER (manager));
        g_return_if_fail (!EMP_STR_EMPTY (icon_name));
        g_return_if_fail (!EMP_STR_EMPTY (first_str));
 
-       smiley = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
-       if (smiley) {
+       pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+       if (pixbuf) {
+               gchar *path;
+
                va_start (var_args, first_str);
-               smiley_manager_add_valist (manager, smiley, first_str, var_args);
+               path = empathy_filename_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+               smiley_manager_add_valist (manager, pixbuf, path, first_str, var_args);
                va_end (var_args);
-               g_object_unref (smiley);
+               g_object_unref (pixbuf);
        }
 }
 
-void
-empathy_smiley_manager_add_from_pixbuf (EmpathySmileyManager *manager,
-                                       GdkPixbuf            *smiley,
-                                       const gchar          *first_str,
-                                       ...)
-{
-       va_list var_args;
-
-       g_return_if_fail (EMPATHY_IS_SMILEY_MANAGER (manager));
-       g_return_if_fail (GDK_IS_PIXBUF (smiley));
-       g_return_if_fail (!EMP_STR_EMPTY (first_str));
-
-       va_start (var_args, first_str);
-       smiley_manager_add_valist (manager, smiley, first_str, var_args);
-       va_end (var_args);
-}
-
 void
 empathy_smiley_manager_load (EmpathySmileyManager *manager)
 {
@@ -320,7 +322,9 @@ empathy_smiley_manager_parse (EmpathySmileyManager *manager,
                if (cur_tree == priv->tree) {
                        if (child) {
                                if (t > cur_str) {
-                                       smiley = smiley_new (NULL, g_strndup (cur_str, t - cur_str));
+                                       smiley = smiley_new (NULL,
+                                                            g_strndup (cur_str, t - cur_str),
+                                                            NULL);
                                        smileys = g_slist_prepend (smileys, smiley);
                                }
                                cur_str = t;
@@ -335,7 +339,9 @@ empathy_smiley_manager_parse (EmpathySmileyManager *manager,
                        continue;
                }
 
-               smiley = smiley_new (cur_tree->pixbuf, g_strndup (cur_str, t - cur_str));
+               smiley = smiley_new (cur_tree->pixbuf,
+                                    g_strndup (cur_str, t - cur_str),
+                                    cur_tree->path);
                smileys = g_slist_prepend (smileys, smiley);
                if (cur_tree->pixbuf) {
                        cur_str = t;
@@ -350,7 +356,9 @@ empathy_smiley_manager_parse (EmpathySmileyManager *manager,
                }
        }
 
-       smiley = smiley_new (cur_tree->pixbuf, g_strndup (cur_str, t - cur_str));
+       smiley = smiley_new (cur_tree->pixbuf,
+                            g_strndup (cur_str, t - cur_str),
+                            cur_tree->path);
        smileys = g_slist_prepend (smileys, smiley);
 
        return g_slist_reverse (smileys);
index 5eaf4b283966da177514397703372af337d6226d..dc7428c3bbb22290ffa19c2931215e59f2882283 100644 (file)
@@ -48,8 +48,9 @@ struct _EmpathySmileyManagerClass {
 };
 
 typedef struct {
-       GdkPixbuf *pixbuf;
-       gchar     *str;
+       GdkPixbuf   *pixbuf;
+       gchar       *str;
+       const gchar *path;
 } EmpathySmiley;
 
 typedef void (*EmpathySmileyMenuFunc) (EmpathySmileyManager *manager,
@@ -63,10 +64,6 @@ void                  empathy_smiley_manager_add             (EmpathySmileyManag
                                                              const gchar          *icon_name,
                                                              const gchar          *first_str,
                                                              ...);
-void                  empathy_smiley_manager_add_from_pixbuf (EmpathySmileyManager *manager,
-                                                             GdkPixbuf            *smiley,
-                                                             const gchar          *first_str,
-                                                             ...);
 GSList *              empathy_smiley_manager_get_all         (EmpathySmileyManager *manager);
 GSList *              empathy_smiley_manager_parse           (EmpathySmileyManager *manager,
                                                              const gchar          *text);
index ab773b21c2037dc9d17de7718de4aa4ed0a4b995..5277810cf2fa3bcd92bdf76e481884718c1a4fdf 100644 (file)
@@ -26,6 +26,7 @@
 #include <libempathy/empathy-utils.h>
 
 #include "empathy-theme-adium.h"
+#include "empathy-ui-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
 #include <libempathy/empathy-debug.h>
@@ -163,33 +164,6 @@ theme_adium_escape_body (const gchar *body)
        return ret;
 }
 
-static const gchar *
-theme_adium_get_default_avatar_filename (EmpathyThemeAdium *theme)
-{
-       EmpathyThemeAdiumPriv *priv = GET_PRIV (theme);
-       GtkIconTheme          *icon_theme;
-       GtkIconInfo           *icon_info;
-       gint                   w, h;
-       gint                   size = 48;
-
-       /* Lazy initialization */
-       if (priv->default_avatar_filename) {
-               return priv->default_avatar_filename;
-       }
-
-       icon_theme = gtk_icon_theme_get_default ();
-
-       if (gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &w, &h)) {
-               size = (w + h) / 2;
-       }
-
-       icon_info = gtk_icon_theme_lookup_icon (icon_theme, "stock_person", size, 0);
-       priv->default_avatar_filename = g_strdup (gtk_icon_info_get_filename (icon_info));
-       gtk_icon_info_free (icon_info);
-
-       return priv->default_avatar_filename;
-}
-
 static void
 theme_adium_scroll_down (EmpathyChatView *view)
 {
@@ -233,7 +207,12 @@ theme_adium_append_message (EmpathyChatView *view,
                avatar_filename = avatar->filename;
        }
        if (!avatar_filename) {
-               avatar_filename = theme_adium_get_default_avatar_filename (theme);
+               if (!priv->default_avatar_filename) {
+                       priv->default_avatar_filename =
+                               empathy_filename_from_icon_name ("stock_person",
+                                                                GTK_ICON_SIZE_DIALOG);
+               }
+               avatar_filename = priv->default_avatar_filename;
        }
 
        /* Get the right html/func to add the message */
index f30c58aade0b8275c8be7deabe369c40d4bcb400..cf423de41db0c75c8c12c959bb152c423c3064b5 100644 (file)
@@ -558,6 +558,29 @@ empathy_pixbuf_from_icon_name (const gchar *icon_name,
        return empathy_pixbuf_from_icon_name_sized (icon_name, size);
 }
 
+gchar *
+empathy_filename_from_icon_name (const gchar *icon_name,
+                                GtkIconSize  icon_size)
+{
+       GtkIconTheme *icon_theme;
+       GtkIconInfo  *icon_info;
+       gint          w, h;
+       gint          size = 48;
+       gchar        *ret;
+
+       icon_theme = gtk_icon_theme_get_default ();
+
+       if (gtk_icon_size_lookup (icon_size, &w, &h)) {
+               size = (w + h) / 2;
+       }
+
+       icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size, 0);
+       ret = g_strdup (gtk_icon_info_get_filename (icon_info));
+       gtk_icon_info_free (icon_info);
+
+       return ret;
+}
+
 /* Stolen from GtkSourceView, hence the weird intendation. Please keep it like
  * that to make it easier to apply changes from the original code.
  */
index 4d58fedcf7d3f52ba7bafbf2b716d1b87a264b49..60d48f3c45ac5681586c073ed72cbec51e5db5ca 100644 (file)
@@ -90,12 +90,15 @@ GdkPixbuf *   empathy_pixbuf_from_avatar_scaled         (EmpathyAvatar    *avata
 GdkPixbuf *   empathy_pixbuf_avatar_from_contact_scaled (EmpathyContact   *contact,
                                                         gint              width,
                                                         gint              height);
-GdkPixbuf * empathy_pixbuf_scale_down_if_necessary      (GdkPixbuf        *pixbuf,
+GdkPixbuf *   empathy_pixbuf_scale_down_if_necessary    (GdkPixbuf        *pixbuf,
                                                         gint              max_size);
-GdkPixbuf * empathy_pixbuf_from_icon_name               (const gchar      *icon_name,
+GdkPixbuf *   empathy_pixbuf_from_icon_name             (const gchar      *icon_name,
                                                         GtkIconSize       icon_size);
-GdkPixbuf * empathy_pixbuf_from_icon_name_sized         (const gchar      *icon_name,
+GdkPixbuf *   empathy_pixbuf_from_icon_name_sized       (const gchar      *icon_name,
                                                         gint              size);
+gchar *       empathy_filename_from_icon_name           (const gchar      *icon_name,
+                                                        GtkIconSize       icon_size);
+
 /* Text view */
 gboolean    empathy_text_iter_forward_search            (const GtkTextIter*iter,
                                                         const gchar      *str,