#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"
#include "empathy-images.h"
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;
if (data->preserve_aspect_ratio && (data->width > 0 || data->height > 0))
{
- if (width < data->width && height < data->height)
- {
- width = width;
- height = height;
- }
-
if (data->width < 0)
{
width = width * (double) data->height / (gdouble) height;
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)
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)
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;
-}
-
-/* Takes care of moving the window to the current workspace. */
-void
-empathy_window_present_with_time (GtkWindow *window,
- guint32 timestamp)
-{
- GdkWindow *gdk_window;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- /* Move the window to the current workspace before trying to show it.
- * This is the behaviour people expect when clicking on the statusbar icon. */
- gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
-
- if (gdk_window)
- {
- gint x, y;
- gint w, h;
-
- /* Has no effect if the WM has viewports, like compiz */
- gdk_x11_window_move_to_current_desktop (gdk_window);
-
- /* If window is still off-screen, hide it to force it to
- * reposition on the current workspace. */
- gtk_window_get_position (window, &x, &y);
- gtk_window_get_size (window, &w, &h);
- if (!EMPATHY_RECT_IS_ON_SCREEN (x, y, w, h))
- gtk_widget_hide (GTK_WIDGET (window));
- }
-
- if (timestamp == GDK_CURRENT_TIME)
- gtk_window_present (window);
- else
- gtk_window_present_with_time (window, timestamp);
-}
-
-void
-empathy_window_present (GtkWindow *window)
-{
- empathy_window_present_with_time (window, gtk_get_current_event_time ());
-}
-
-/** empathy_make_absolute_url_len:
- * @url: an url
- * @len: a length
- *
- * Same as #empathy_make_absolute_url but for a limited string length
- */
-gchar *
-empathy_make_absolute_url_len (const gchar *url,
- guint len)
-{
- g_return_val_if_fail (url != NULL, NULL);
-
- if (g_str_has_prefix (url, "help:") ||
- g_str_has_prefix (url, "mailto:") ||
- strstr (url, ":/"))
- return g_strndup (url, len);
-
- if (strstr (url, "@"))
- return g_strdup_printf ("mailto:%.*s", len, url);
-
- return g_strdup_printf ("http://%.*s", len, url);
-}
-
-/** empathy_make_absolute_url:
- * @url: an url
- *
- * The URL opening code can't handle schemeless strings, so we try to be
- * smart and add http if there is no scheme or doesn't look like a mail
- * address. This should work in most cases, and let us click on strings
- * like "www.gnome.org".
- *
- * Returns: a newly allocated url with proper mailto: or http:// prefix, use
- * g_free when your are done with it
- */
-gchar *
-empathy_make_absolute_url (const gchar *url)
-{
- return empathy_make_absolute_url_len (url, strlen (url));
-}
-
void
empathy_url_show (GtkWidget *parent,
const char *url)
g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent));
g_return_if_fail (url != NULL);
- real_url = empathy_make_absolute_url (url);
+ real_url = tpaw_make_absolute_url (url);
gtk_show_uri (parent ? gtk_widget_get_screen (parent) : NULL, real_url,
gtk_get_current_event_time (), &error);