aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-smiley-manager.c82
-rw-r--r--libempathy-gtk/empathy-smiley-manager.h9
-rw-r--r--libempathy-gtk/empathy-theme-adium.c35
-rw-r--r--libempathy-gtk/empathy-ui-utils.c23
-rw-r--r--libempathy-gtk/empathy-ui-utils.h9
5 files changed, 84 insertions, 74 deletions
diff --git a/libempathy-gtk/empathy-smiley-manager.c b/libempathy-gtk/empathy-smiley-manager.c
index a729a2929..21384c75b 100644
--- a/libempathy-gtk/empathy-smiley-manager.c
+++ b/libempathy-gtk/empathy-smiley-manager.c
@@ -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,40 +256,26 @@ 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)
{
g_return_if_fail (EMPATHY_IS_SMILEY_MANAGER (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);
diff --git a/libempathy-gtk/empathy-smiley-manager.h b/libempathy-gtk/empathy-smiley-manager.h
index 5eaf4b283..dc7428c3b 100644
--- a/libempathy-gtk/empathy-smiley-manager.h
+++ b/libempathy-gtk/empathy-smiley-manager.h
@@ -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);
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index ab773b21c..5277810cf 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -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 */
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index f30c58aad..cf423de41 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -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.
*/
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index 4d58fedcf..60d48f3c4 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -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,