diff options
author | Marco Barisione <marco.barisione@collabora.co.uk> | 2013-07-30 23:08:34 +0800 |
---|---|---|
committer | Marco Barisione <marco.barisione@collabora.co.uk> | 2013-08-20 18:03:06 +0800 |
commit | a56fa2a95e93ad68ca08f336178b26baf3b3f29d (patch) | |
tree | 547ac5a682a4fc8c4f8281d1f1bb4e7a39ff8daa /libempathy-gtk | |
parent | 3abe4df5f32c37e968d0556c755b8387d9f1f771 (diff) | |
download | gsoc2013-empathy-a56fa2a95e93ad68ca08f336178b26baf3b3f29d.tar gsoc2013-empathy-a56fa2a95e93ad68ca08f336178b26baf3b3f29d.tar.gz gsoc2013-empathy-a56fa2a95e93ad68ca08f336178b26baf3b3f29d.tar.bz2 gsoc2013-empathy-a56fa2a95e93ad68ca08f336178b26baf3b3f29d.tar.lz gsoc2013-empathy-a56fa2a95e93ad68ca08f336178b26baf3b3f29d.tar.xz gsoc2013-empathy-a56fa2a95e93ad68ca08f336178b26baf3b3f29d.tar.zst gsoc2013-empathy-a56fa2a95e93ad68ca08f336178b26baf3b3f29d.zip |
pixbuf-utils: copy the generic pixbuf-related utily functions from Empathy
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
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-account-chooser.c | 5 | ||||
-rw-r--r-- | libempathy-gtk/empathy-avatar-image.c | 7 | ||||
-rw-r--r-- | libempathy-gtk/empathy-individual-store-channel.c | 4 | ||||
-rw-r--r-- | libempathy-gtk/empathy-individual-view.c | 5 | ||||
-rw-r--r-- | libempathy-gtk/empathy-local-xmpp-assistant-widget.c | 3 | ||||
-rw-r--r-- | libempathy-gtk/empathy-notify-manager.c | 3 | ||||
-rw-r--r-- | libempathy-gtk/empathy-protocol-chooser.c | 7 | ||||
-rw-r--r-- | libempathy-gtk/empathy-roster-contact.c | 3 | ||||
-rw-r--r-- | libempathy-gtk/empathy-smiley-manager.c | 5 | ||||
-rw-r--r-- | libempathy-gtk/empathy-theme-adium.c | 3 | ||||
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.c | 156 | ||||
-rw-r--r-- | libempathy-gtk/empathy-ui-utils.h | 13 |
12 files changed, 30 insertions, 184 deletions
diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c index e6f4367c9..69fc54fe2 100644 --- a/libempathy-gtk/empathy-account-chooser.c +++ b/libempathy-gtk/empathy-account-chooser.c @@ -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, diff --git a/libempathy-gtk/empathy-avatar-image.c b/libempathy-gtk/empathy-avatar-image.c index f61c1b236..78a3e5ff3 100644 --- a/libempathy-gtk/empathy-avatar-image.c +++ b/libempathy-gtk/empathy-avatar-image.c @@ -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) { diff --git a/libempathy-gtk/empathy-individual-store-channel.c b/libempathy-gtk/empathy-individual-store-channel.c index a1a1161f9..eb0f3f593 100644 --- a/libempathy-gtk/empathy-individual-store-channel.c +++ b/libempathy-gtk/empathy-individual-store-channel.c @@ -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); diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c index 22e65a0ec..b901848e1 100644 --- a/libempathy-gtk/empathy-individual-view.c +++ b/libempathy-gtk/empathy-individual-view.c @@ -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); } diff --git a/libempathy-gtk/empathy-local-xmpp-assistant-widget.c b/libempathy-gtk/empathy-local-xmpp-assistant-widget.c index 971ad5e96..d5f044eba 100644 --- a/libempathy-gtk/empathy-local-xmpp-assistant-widget.c +++ b/libempathy-gtk/empathy-local-xmpp-assistant-widget.c @@ -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); diff --git a/libempathy-gtk/empathy-notify-manager.c b/libempathy-gtk/empathy-notify-manager.c index 033557e81..8ca97950e 100644 --- a/libempathy-gtk/empathy-notify-manager.c +++ b/libempathy-gtk/empathy-notify-manager.c @@ -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; } diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index f2414ad10..3966809f7 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -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, diff --git a/libempathy-gtk/empathy-roster-contact.c b/libempathy-gtk/empathy-roster-contact.c index 22b360075..328b51240 100644 --- a/libempathy-gtk/empathy-roster-contact.c +++ b/libempathy-gtk/empathy-roster-contact.c @@ -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); } diff --git a/libempathy-gtk/empathy-smiley-manager.c b/libempathy-gtk/empathy-smiley-manager.c index fcbe56024..44ea817be 100644 --- a/libempathy-gtk/empathy-smiley-manager.c +++ b/libempathy-gtk/empathy-smiley-manager.c @@ -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); diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c index 5fd61d339..0cf74e396 100644 --- a/libempathy-gtk/empathy-theme-adium.c +++ b/libempathy-gtk/empathy-theme-adium.c @@ -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; diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index 174eceac4..5e01d9fcc 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -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) diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 3478e8605..22c0899cb 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -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); |