]> git.0d.be Git - empathy.git/commitdiff
pixbuf-utils: copy the generic pixbuf-related utily functions from Empathy
authorMarco Barisione <marco.barisione@collabora.co.uk>
Tue, 30 Jul 2013 15:08:34 +0000 (16:08 +0100)
committerMarco Barisione <marco.barisione@collabora.co.uk>
Tue, 20 Aug 2013 10:03:06 +0000 (11:03 +0100)
This commit also changes the licence of the moved code from GPL to LGPL.
See GOSSIP-RELICENSING.txt for details.

https://bugzilla.gnome.org/show_bug.cgi?id=699492

18 files changed:
libempathy-gtk/empathy-account-chooser.c
libempathy-gtk/empathy-avatar-image.c
libempathy-gtk/empathy-individual-store-channel.c
libempathy-gtk/empathy-individual-view.c
libempathy-gtk/empathy-local-xmpp-assistant-widget.c
libempathy-gtk/empathy-notify-manager.c
libempathy-gtk/empathy-protocol-chooser.c
libempathy-gtk/empathy-roster-contact.c
libempathy-gtk/empathy-smiley-manager.c
libempathy-gtk/empathy-theme-adium.c
libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h
src/empathy-accounts-dialog.c
src/empathy-call-window.c
tp-account-widgets/Makefile.am
tp-account-widgets/tpaw-avatar-chooser.c
tp-account-widgets/tpaw-pixbuf-utils.c [new file with mode: 0644]
tp-account-widgets/tpaw-pixbuf-utils.h [new file with mode: 0644]

index e6f4367c9eda828ccc8a37eecfd1fb50de3ef6ae..69fc54fe22f95bcbb9ba68c07f6f9e0d608d26ea 100644 (file)
@@ -25,8 +25,7 @@
 #include "empathy-account-chooser.h"
 
 #include <glib/gi18n-lib.h>
-
-#include "empathy-ui-utils.h"
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 #include "empathy-debug.h"
@@ -840,7 +839,7 @@ account_chooser_filter_ready_cb (gboolean is_enabled,
   store = GTK_LIST_STORE (gtk_combo_box_get_model (combobox));
 
   icon_name = tp_account_get_icon_name (account);
-  pixbuf = empathy_pixbuf_from_icon_name (icon_name,
+  pixbuf = tpaw_pixbuf_from_icon_name (icon_name,
     GTK_ICON_SIZE_BUTTON);
 
   gtk_list_store_set (store, iter,
index f61c1b236892eec98018fe8a38dbc8a022a07638..78a3e5ff313c326f863333879af3804464b752ac 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <glib/gi18n-lib.h>
 #include <gdk/gdkx.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 
 #include "empathy-ui-utils.h"
 #include "empathy-utils.h"
@@ -211,7 +212,7 @@ avatar_image_button_press_event (GtkWidget *widget, GdkEventButton *event)
                return TRUE;
        }
 
-       pixbuf = empathy_pixbuf_scale_down_if_necessary (priv->pixbuf, MAX_LARGE);
+       pixbuf = tpaw_pixbuf_scale_down_if_necessary (priv->pixbuf, MAX_LARGE);
        popup_width = gdk_pixbuf_get_width (pixbuf);
        popup_height = gdk_pixbuf_get_height (pixbuf);
 
@@ -302,7 +303,7 @@ empathy_avatar_image_set (EmpathyAvatarImage *avatar_image,
        }
 
        if (avatar) {
-               priv->pixbuf = empathy_pixbuf_from_data ((gchar *) avatar->data,
+               priv->pixbuf = tpaw_pixbuf_from_data ((gchar *) avatar->data,
                                avatar->len);
        }
 
@@ -311,7 +312,7 @@ empathy_avatar_image_set (EmpathyAvatarImage *avatar_image,
                return;
        }
 
-       scaled_pixbuf = empathy_pixbuf_scale_down_if_necessary (priv->pixbuf, MAX_SMALL);
+       scaled_pixbuf = tpaw_pixbuf_scale_down_if_necessary (priv->pixbuf, MAX_SMALL);
        gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), scaled_pixbuf);
 
        if (scaled_pixbuf != priv->pixbuf) {
index a1a1161f976d6ee66544ced3b411bba0529968a1..eb0f3f5930b809585f68915decce16d59e0dac2b 100644 (file)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "empathy-individual-store-channel.h"
 
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
+
 #include "empathy-utils.h"
 #include "empathy-ui-utils.h"
 #include "empathy-images.h"
@@ -159,7 +161,7 @@ individual_store_channel_contact_chat_state_changed (TpTextChannel *channel,
   if (state == TP_CHANNEL_CHAT_STATE_COMPOSING)
     {
       gchar *icon_filename =
-          empathy_filename_from_icon_name (EMPATHY_IMAGE_TYPING,
+          tpaw_filename_from_icon_name (EMPATHY_IMAGE_TYPING,
             GTK_ICON_SIZE_MENU);
 
       pixbuf = gdk_pixbuf_new_from_file (icon_filename, NULL);
index 22e65a0ec53e90b6e431131d325154c310703691..b901848e16df3196857a22bd2b30f78ce191f637 100644 (file)
@@ -28,6 +28,7 @@
 #include "empathy-individual-view.h"
 
 #include <glib/gi18n-lib.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #include "empathy-cell-renderer-activatable.h"
@@ -1161,12 +1162,12 @@ individual_view_group_icon_cell_data_func (GtkTreeViewColumn *tree_column,
 
   if (!tp_strdiff (name, EMPATHY_INDIVIDUAL_STORE_FAVORITE))
     {
-      pixbuf = empathy_pixbuf_from_icon_name ("emblem-favorite",
+      pixbuf = tpaw_pixbuf_from_icon_name ("emblem-favorite",
           GTK_ICON_SIZE_MENU);
     }
   else if (!tp_strdiff (name, EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY))
     {
-      pixbuf = empathy_pixbuf_from_icon_name ("im-local-xmpp",
+      pixbuf = tpaw_pixbuf_from_icon_name ("im-local-xmpp",
           GTK_ICON_SIZE_MENU);
     }
 
index 971ad5e9628d716b69b0005d53924a13271f15a2..d5f044ebaa5cd36a64577828e334628d59b37c59 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <glib/gi18n-lib.h>
 #include <tp-account-widgets/tpaw-account-widget.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #include "empathy-ui-utils.h"
@@ -87,7 +88,7 @@ empathy_local_xmpp_assistant_widget_constructed (GObject *object)
   gtk_grid_attach (GTK_GRID (self), w, 0, 0, 1, 1);
   gtk_widget_show (w);
 
-  pix = empathy_pixbuf_from_icon_name_sized ("im-local-xmpp", 48);
+  pix = tpaw_pixbuf_from_icon_name_sized ("im-local-xmpp", 48);
   if (pix != NULL)
     {
       w = gtk_image_new_from_pixbuf (pix);
index 033557e8148cea4b8eacc5eb06bed998091bde8e..8ca97950e9e8fa11331de7258086eecf05a2a0c6 100644 (file)
@@ -21,6 +21,7 @@
 #include "empathy-notify-manager.h"
 
 #include <libnotify/notify.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 
 #include "empathy-gsettings.h"
 #include "empathy-ui-utils.h"
@@ -174,7 +175,7 @@ empathy_notify_manager_get_pixbuf_for_notification (EmpathyNotifyManager *self,
     pixbuf = empathy_pixbuf_avatar_from_contact_scaled (contact, 48, 48);
 
   if (pixbuf == NULL)
-    pixbuf = empathy_pixbuf_from_icon_name_sized (icon_name, 48);
+    pixbuf = tpaw_pixbuf_from_icon_name_sized (icon_name, 48);
 
   return pixbuf;
 }
index f2414ad10831c75bb5ae65448e489a7f761b502a..3966809f7ec65678a5c715e96af8c7f431744c47 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <glib/gi18n-lib.h>
 #include <tp-account-widgets/tpaw-connection-managers.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #include "empathy-ui-utils.h"
@@ -231,7 +232,7 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser,
           g_strdup (proto_name), g_strdup (cm_name));
 
       icon_name = tpaw_protocol_icon_name (proto_name);
-      pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+      pixbuf = tpaw_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
 
       display_name = tpaw_protocol_name_to_display_name (proto_name);
 
@@ -249,7 +250,7 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser,
           !tp_strdiff (cm_name, "gabble"))
         {
           display_name = tpaw_service_name_to_display_name ("google-talk");
-          pixbuf = empathy_pixbuf_from_icon_name ("im-google-talk",
+          pixbuf = tpaw_pixbuf_from_icon_name ("im-google-talk",
                   GTK_ICON_SIZE_BUTTON);
 
           gtk_list_store_insert_with_values (priv->store,
@@ -264,7 +265,7 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser,
           g_clear_object (&pixbuf);
 
           display_name = tpaw_service_name_to_display_name ("facebook");
-          pixbuf = empathy_pixbuf_from_icon_name ("im-facebook",
+          pixbuf = tpaw_pixbuf_from_icon_name ("im-facebook",
                   GTK_ICON_SIZE_BUTTON);
 
           gtk_list_store_insert_with_values (priv->store,
index 22b360075671217efaeb4b6b9c2d4cbb392503c7..328b5124036f24884e6ffcc6e0fb4319fa1e3c7b 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <glib/gi18n-lib.h>
 #include <tp-account-widgets/tpaw-images.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 
 #include "empathy-ui-utils.h"
 #include "empathy-utils.h"
@@ -124,7 +125,7 @@ avatar_loaded_cb (GObject *source,
 
   if (pixbuf == NULL)
     {
-      pixbuf = empathy_pixbuf_from_icon_name_sized (
+      pixbuf = tpaw_pixbuf_from_icon_name_sized (
           TPAW_IMAGE_AVATAR_DEFAULT, AVATAR_SIZE);
     }
 
index fcbe560242e7b23ec5059e13827d89da8fc982f8..44ea817becd583c2122794504e597b3b41d11166 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include "empathy-smiley-manager.h"
 
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #include "empathy-ui-utils.h"
@@ -247,12 +248,12 @@ empathy_smiley_manager_add (EmpathySmileyManager *manager,
        g_return_if_fail (!TPAW_STR_EMPTY (icon_name));
        g_return_if_fail (!TPAW_STR_EMPTY (first_str));
 
-       pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+       pixbuf = tpaw_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
        if (pixbuf) {
                gchar *path;
 
                va_start (var_args, first_str);
-               path = empathy_filename_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+               path = tpaw_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 (pixbuf);
index 5fd61d3395085c2d1e3d8420b70e2635ecb1b7d1..0cf74e396b164d7255b77302f32c23c7d920ee37 100644 (file)
@@ -25,6 +25,7 @@
 #include <glib/gi18n-lib.h>
 #include <tp-account-widgets/tpaw-images.h>
 #include <tp-account-widgets/tpaw-time.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #include "empathy-gsettings.h"
@@ -954,7 +955,7 @@ theme_adium_add_message (EmpathyThemeAdium *self,
         {
           if (!self->priv->data->default_avatar_filename)
             self->priv->data->default_avatar_filename =
-              empathy_filename_from_icon_name (TPAW_IMAGE_AVATAR_DEFAULT,
+              tpaw_filename_from_icon_name (TPAW_IMAGE_AVATAR_DEFAULT,
                        GTK_ICON_SIZE_DIALOG);
 
           avatar_filename = self->priv->data->default_avatar_filename;
index 174eceac403d8a6e592eadb61e9eaeecbec2ff02..5e01d9fcc97f7a9bd0d7a42677d541055662bcd1 100644 (file)
@@ -37,6 +37,7 @@
 #include <glib/gi18n-lib.h>
 #include <gio/gdesktopappinfo.h>
 #include <tp-account-widgets/tpaw-live-search.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #include "empathy-ft-factory.h"
@@ -155,69 +156,6 @@ empathy_protocol_name_for_contact (EmpathyContact *contact)
   return tp_account_get_icon_name (account);
 }
 
-GdkPixbuf *
-empathy_pixbuf_from_data (gchar *data,
-    gsize data_size)
-{
-  return empathy_pixbuf_from_data_and_mime (data, data_size, NULL);
-}
-
-GdkPixbuf *
-empathy_pixbuf_from_data_and_mime (gchar *data,
-           gsize data_size,
-           gchar **mime_type)
-{
-  GdkPixbufLoader *loader;
-  GdkPixbufFormat *format;
-  GdkPixbuf *pixbuf = NULL;
-  gchar **mime_types;
-  GError *error = NULL;
-
-  if (!data)
-    return NULL;
-
-  loader = gdk_pixbuf_loader_new ();
-  if (!gdk_pixbuf_loader_write (loader, (guchar *) data, data_size, &error))
-    {
-      DEBUG ("Failed to write to pixbuf loader: %s",
-        error ? error->message : "No error given");
-      goto out;
-    }
-
-  if (!gdk_pixbuf_loader_close (loader, &error))
-    {
-      DEBUG ("Failed to close pixbuf loader: %s",
-        error ? error->message : "No error given");
-      goto out;
-    }
-
-  pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
-  if (pixbuf)
-    {
-      g_object_ref (pixbuf);
-
-      if (mime_type != NULL)
-        {
-          format = gdk_pixbuf_loader_get_format (loader);
-          mime_types = gdk_pixbuf_format_get_mime_types (format);
-
-          *mime_type = g_strdup (*mime_types);
-          if (mime_types[1] != NULL)
-            DEBUG ("Loader supports more than one mime "
-              "type! Picking the first one, %s",
-              *mime_type);
-
-          g_strfreev (mime_types);
-        }
-    }
-
-out:
-  g_clear_error (&error);
-  g_object_unref (loader);
-
-  return pixbuf;
-}
-
 struct SizeData
 {
   gint width;
@@ -654,7 +592,7 @@ empathy_pixbuf_contact_status_icon_with_icon_name (EmpathyContact *contact,
   numerator = 3;
   denominator = 4;
 
-  icon_filename = empathy_filename_from_icon_name (icon_name,
+  icon_filename = tpaw_filename_from_icon_name (icon_name,
       GTK_ICON_SIZE_MENU);
 
   if (icon_filename == NULL)
@@ -711,7 +649,7 @@ empathy_pixbuf_protocol_from_contact_scaled (EmpathyContact *contact,
   g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
   account = empathy_contact_get_account (contact);
-  filename = empathy_filename_from_icon_name (
+  filename = tpaw_filename_from_icon_name (
       tp_account_get_icon_name (account), GTK_ICON_SIZE_MENU);
 
   if (filename != NULL)
@@ -723,94 +661,6 @@ empathy_pixbuf_protocol_from_contact_scaled (EmpathyContact *contact,
   return pixbuf;
 }
 
-GdkPixbuf *
-empathy_pixbuf_scale_down_if_necessary (GdkPixbuf *pixbuf,
-    gint max_size)
-{
-  gint width, height;
-  gdouble factor;
-
-  width = gdk_pixbuf_get_width (pixbuf);
-  height = gdk_pixbuf_get_height (pixbuf);
-
-  if (width > 0 && (width > max_size || height > max_size))
-    {
-      factor = (gdouble) max_size / MAX (width, height);
-
-      width = width * factor;
-      height = height * factor;
-
-      return gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_HYPER);
-    }
-
-  return g_object_ref (pixbuf);
-}
-
-GdkPixbuf *
-empathy_pixbuf_from_icon_name_sized (const gchar *icon_name,
-    gint size)
-{
-  GtkIconTheme *theme;
-  GdkPixbuf *pixbuf;
-  GError *error = NULL;
-
-  if (!icon_name)
-    return NULL;
-
-  theme = gtk_icon_theme_get_default ();
-
-  pixbuf = gtk_icon_theme_load_icon (theme, icon_name, size, 0, &error);
-
-  if (error)
-    {
-      DEBUG ("Error loading icon: %s", error->message);
-      g_clear_error (&error);
-    }
-
-  return pixbuf;
-}
-
-GdkPixbuf *
-empathy_pixbuf_from_icon_name (const gchar *icon_name,
-    GtkIconSize  icon_size)
-{
-  gint w, h;
-  gint size = 48;
-
-  if (!icon_name)
-    return NULL;
-
-  if (gtk_icon_size_lookup (icon_size, &w, &h))
-    size = (w + h) / 2;
-
-  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);
-  if (icon_info == NULL)
-    return NULL;
-
-  ret = g_strdup (gtk_icon_info_get_filename (icon_info));
-  gtk_icon_info_free (icon_info);
-
-  return ret;
-}
-
 void
 empathy_url_show (GtkWidget *parent,
       const char *url)
index 3478e860545623591b1b5683d6a906f5b50e02e4..22c0899cb28be85cc525b76ef84dc62a1692c209 100644 (file)
@@ -60,11 +60,6 @@ const gchar * empathy_icon_name_for_presence (
 const gchar * empathy_icon_name_for_contact (EmpathyContact *contact);
 const gchar * empathy_icon_name_for_individual (FolksIndividual *individual);
 const gchar * empathy_protocol_name_for_contact (EmpathyContact *contact);
-GdkPixbuf * empathy_pixbuf_from_data (gchar *data,
-    gsize data_size);
-GdkPixbuf * empathy_pixbuf_from_data_and_mime (gchar *data,
-    gsize data_size,
-    gchar **mime_type);
 void empathy_pixbuf_avatar_from_individual_scaled_async (
     FolksIndividual *individual,
     gint width,
@@ -85,14 +80,6 @@ GdkPixbuf * empathy_pixbuf_contact_status_icon_with_icon_name (
     EmpathyContact *contact,
     const gchar *icon_name,
     gboolean show_protocol);
-GdkPixbuf * empathy_pixbuf_scale_down_if_necessary (GdkPixbuf *pixbuf,
-    gint max_size);
-GdkPixbuf * empathy_pixbuf_from_icon_name (const gchar *icon_name,
-    GtkIconSize icon_size);
-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);
 
 void empathy_move_to_window_desktop (GtkWindow *window,
     guint32 timestamp);
index ca5d57f5cbd9f9a6d1ca36131fe0b56f19925058..aa1f9ab31551dfd34db0056049ff0bf1b1bc4da5 100644 (file)
@@ -31,6 +31,7 @@
 #include <tp-account-widgets/tpaw-account-widget.h>
 #include <tp-account-widgets/tpaw-builder.h>
 #include <tp-account-widgets/tpaw-user-info.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #include "empathy-accounts-common.h"
@@ -1023,7 +1024,7 @@ ensure_icon (EmpathyAccountsDialog *self,
   pixbuf = g_hash_table_lookup (priv->icons_cache, icon_name);
   if (pixbuf == NULL)
     {
-      pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+      pixbuf = tpaw_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
 
       if (pixbuf == NULL)
         return NULL;
index 6c215b53b843fcc235803d31a0d437e0f459879b..39c70c17b9e4b4dd773457009107e1176348199a 100644 (file)
@@ -28,6 +28,7 @@
 #include <tp-account-widgets/tpaw-builder.h>
 #include <tp-account-widgets/tpaw-camera-monitor.h>
 #include <tp-account-widgets/tpaw-images.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #include "empathy-about-dialog.h"
@@ -1893,7 +1894,7 @@ init_contact_avatar_with_size (EmpathyContact *contact,
 
   if (pixbuf_avatar == NULL)
     {
-      pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
+      pixbuf_avatar = tpaw_pixbuf_from_icon_name_sized (
           TPAW_IMAGE_AVATAR_DEFAULT, size);
     }
 
index fa79032f6710d6e2a3c2244fdc816561e4d613e1..968e626171743427357a8e92da32ff8ed4513ae9 100644 (file)
@@ -42,6 +42,7 @@ libtp_account_widgets_sources =               \
        tpaw-irc-network.c                      \
        tpaw-irc-server.c                       \
        tpaw-live-search.c                      \
+       tpaw-pixbuf-utils.c                     \
        tpaw-string-parser.c                    \
        tpaw-time.c                             \
        tpaw-user-info.c                        \
@@ -70,6 +71,7 @@ libtp_account_widgets_headers =                       \
        tpaw-irc-network.h                      \
        tpaw-irc-server.h                       \
        tpaw-live-search.h                      \
+       tpaw-pixbuf-utils.h                     \
        tpaw-string-parser.h                    \
        tpaw-time.h                             \
        tpaw-user-info.h                        \
index 6a5b83b427a07e570e5ae3306a85522c23fc255f..77d4a0b72b8576f440234991c6d172052f564b8e 100644 (file)
@@ -27,6 +27,7 @@
 #include <tp-account-widgets/tpaw-camera-monitor.h>
 #include <tp-account-widgets/tpaw-gsettings.h>
 #include <tp-account-widgets/tpaw-images.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
 #include <tp-account-widgets/tpaw-utils.h>
 
 #ifdef HAVE_CHEESE
@@ -145,7 +146,7 @@ get_avatar_cb (GObject *source,
       goto out;
     }
 
-  pixbuf = empathy_pixbuf_from_data_and_mime ((gchar *) avatar->data,
+  pixbuf = tpaw_pixbuf_from_data_and_mime ((gchar *) avatar->data,
       avatar->len, &mime_type);
   if (pixbuf == NULL)
     {
@@ -725,7 +726,7 @@ avatar_chooser_set_image (TpawAvatarChooser *self,
 
   self->priv->changed = TRUE;
 
-  pixbuf_view = empathy_pixbuf_scale_down_if_necessary (pixbuf,
+  pixbuf_view = tpaw_pixbuf_scale_down_if_necessary (pixbuf,
       AVATAR_SIZE_VIEW);
   image = gtk_image_new_from_pixbuf (pixbuf_view);
 
@@ -751,7 +752,7 @@ avatar_chooser_set_image_from_data (TpawAvatarChooser *self,
       return;
     }
 
-  pixbuf = empathy_pixbuf_from_data_and_mime (data, size, &mime_type);
+  pixbuf = tpaw_pixbuf_from_data_and_mime (data, size, &mime_type);
   if (pixbuf == NULL)
     {
       g_free (data);
@@ -844,7 +845,7 @@ avatar_chooser_update_preview_cb (GtkFileChooser *file_chooser,
 
       if (pixbuf != NULL)
         {
-          scaled_pixbuf = empathy_pixbuf_scale_down_if_necessary (pixbuf,
+          scaled_pixbuf = tpaw_pixbuf_scale_down_if_necessary (pixbuf,
               AVATAR_SIZE_SAVE);
 
           gtk_image_set_from_pixbuf (GTK_IMAGE (image), scaled_pixbuf);
diff --git a/tp-account-widgets/tpaw-pixbuf-utils.c b/tp-account-widgets/tpaw-pixbuf-utils.c
new file mode 100644 (file)
index 0000000..1b226e9
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2002-2007 Imendio AB
+ * Copyright (C) 2007-2013 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors: Mikael Hallendal <micke@imendio.com>
+ *          Richard Hult <richard@imendio.com>
+ *          Martyn Russell <martyn@imendio.com>
+ *          Xavier Claessens <xclaesse@gmail.com>
+ *          Travis Reitter <travis.reitter@collabora.co.uk>
+ */
+
+#include "config.h"
+#include "tpaw-pixbuf-utils.h"
+
+#include <gdk/gdkx.h>
+
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include "empathy-debug.h"
+
+GdkPixbuf *
+tpaw_pixbuf_from_data (gchar *data,
+    gsize data_size)
+{
+  return tpaw_pixbuf_from_data_and_mime (data, data_size, NULL);
+}
+
+GdkPixbuf *
+tpaw_pixbuf_from_data_and_mime (gchar *data,
+           gsize data_size,
+           gchar **mime_type)
+{
+  GdkPixbufLoader *loader;
+  GdkPixbufFormat *format;
+  GdkPixbuf *pixbuf = NULL;
+  gchar **mime_types;
+  GError *error = NULL;
+
+  if (!data)
+    return NULL;
+
+  loader = gdk_pixbuf_loader_new ();
+  if (!gdk_pixbuf_loader_write (loader, (guchar *) data, data_size, &error))
+    {
+      DEBUG ("Failed to write to pixbuf loader: %s",
+        error ? error->message : "No error given");
+      goto out;
+    }
+
+  if (!gdk_pixbuf_loader_close (loader, &error))
+    {
+      DEBUG ("Failed to close pixbuf loader: %s",
+        error ? error->message : "No error given");
+      goto out;
+    }
+
+  pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+  if (pixbuf)
+    {
+      g_object_ref (pixbuf);
+
+      if (mime_type != NULL)
+        {
+          format = gdk_pixbuf_loader_get_format (loader);
+          mime_types = gdk_pixbuf_format_get_mime_types (format);
+
+          *mime_type = g_strdup (*mime_types);
+          if (mime_types[1] != NULL)
+            DEBUG ("Loader supports more than one mime "
+              "type! Picking the first one, %s",
+              *mime_type);
+
+          g_strfreev (mime_types);
+        }
+    }
+
+out:
+  g_clear_error (&error);
+  g_object_unref (loader);
+
+  return pixbuf;
+}
+
+GdkPixbuf *
+tpaw_pixbuf_scale_down_if_necessary (GdkPixbuf *pixbuf,
+    gint max_size)
+{
+  gint width, height;
+  gdouble factor;
+
+  width = gdk_pixbuf_get_width (pixbuf);
+  height = gdk_pixbuf_get_height (pixbuf);
+
+  if (width > 0 && (width > max_size || height > max_size))
+    {
+      factor = (gdouble) max_size / MAX (width, height);
+
+      width = width * factor;
+      height = height * factor;
+
+      return gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_HYPER);
+    }
+
+  return g_object_ref (pixbuf);
+}
+
+GdkPixbuf *
+tpaw_pixbuf_from_icon_name_sized (const gchar *icon_name,
+    gint size)
+{
+  GtkIconTheme *theme;
+  GdkPixbuf *pixbuf;
+  GError *error = NULL;
+
+  if (!icon_name)
+    return NULL;
+
+  theme = gtk_icon_theme_get_default ();
+
+  pixbuf = gtk_icon_theme_load_icon (theme, icon_name, size, 0, &error);
+
+  if (error)
+    {
+      DEBUG ("Error loading icon: %s", error->message);
+      g_clear_error (&error);
+    }
+
+  return pixbuf;
+}
+
+GdkPixbuf *
+tpaw_pixbuf_from_icon_name (const gchar *icon_name,
+    GtkIconSize  icon_size)
+{
+  gint w, h;
+  gint size = 48;
+
+  if (!icon_name)
+    return NULL;
+
+  if (gtk_icon_size_lookup (icon_size, &w, &h))
+    size = (w + h) / 2;
+
+  return tpaw_pixbuf_from_icon_name_sized (icon_name, size);
+}
+
+gchar *
+tpaw_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);
+  if (icon_info == NULL)
+    return NULL;
+
+  ret = g_strdup (gtk_icon_info_get_filename (icon_info));
+  gtk_icon_info_free (icon_info);
+
+  return ret;
+}
diff --git a/tp-account-widgets/tpaw-pixbuf-utils.h b/tp-account-widgets/tpaw-pixbuf-utils.h
new file mode 100644 (file)
index 0000000..0521f71
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2002-2007 Imendio AB
+ * Copyright (C) 2007-2013 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Authors: Mikael Hallendal <micke@imendio.com>
+ *          Richard Hult <richard@imendio.com>
+ *          Martyn Russell <martyn@imendio.com>
+ *          Xavier Claessens <xclaesse@gmail.com>
+ *          Travis Reitter <travis.reitter@collabora.co.uk>
+ */
+
+#ifndef __TPAW_UI_UTILS_H__
+#define __TPAW_UI_UTILS_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+GdkPixbuf * tpaw_pixbuf_from_data (gchar *data,
+    gsize data_size);
+GdkPixbuf * tpaw_pixbuf_from_data_and_mime (gchar *data,
+    gsize data_size,
+    gchar **mime_type);
+GdkPixbuf * tpaw_pixbuf_scale_down_if_necessary (GdkPixbuf *pixbuf,
+    gint max_size);
+GdkPixbuf * tpaw_pixbuf_from_icon_name (const gchar *icon_name,
+    GtkIconSize icon_size);
+GdkPixbuf * tpaw_pixbuf_from_icon_name_sized (const gchar *icon_name,
+    gint size);
+gchar * tpaw_filename_from_icon_name (const gchar *icon_name,
+    GtkIconSize icon_size);
+
+G_END_DECLS
+
+#endif /*  __TPAW_UI_UTILS_H__ */