]> www.fi.muni.cz Git - evince.git/blobdiff - cut-n-paste/recent-files/egg-recent-util.c
Do not leak the target window
[evince.git] / cut-n-paste / recent-files / egg-recent-util.c
index cb30e053fb1554450576cea155b38afbb9635f9e..bc15a06e76f92a15f2f82ae9937f528b41259d31 100644 (file)
 #include <math.h>
 #include "egg-recent-util.h"
 
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
 #define EGG_RECENT_UTIL_HOSTNAME_SIZE 512
 
 /* ripped out of gedit2 */
@@ -54,51 +58,32 @@ egg_recent_util_escape_underlines (const gchar* text)
 }
 
 #ifndef USE_STABLE_LIBGNOMEUI
-static GdkPixbuf *
-scale_icon (GdkPixbuf *pixbuf,
-           double *scale)
-{
-       guint width, height;
-
-       width = gdk_pixbuf_get_width (pixbuf);
-       height = gdk_pixbuf_get_height (pixbuf);
-
-       width = floor (width * *scale + 0.5);
-       height = floor (height * *scale + 0.5);
-       
-       return gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
-}
-
 static GdkPixbuf *
 load_icon_file (char          *filename,
-               guint          base_size,
                guint          nominal_size)
 {
        GdkPixbuf *pixbuf, *scaled_pixbuf;
-       guint width, height, size;
-       double scale;
+       guint width, height;
 
-       pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
+       pixbuf = gdk_pixbuf_new_from_file_at_size (filename, nominal_size, nominal_size, NULL);
 
        if (pixbuf == NULL) {
                return NULL;
        }
        
-       if (base_size == 0) {
-               width = gdk_pixbuf_get_width (pixbuf); 
-               height = gdk_pixbuf_get_height (pixbuf);
-               size = MAX (width, height);
-               if (size > nominal_size) {
-                       base_size = size;
+       width = gdk_pixbuf_get_width (pixbuf); 
+       height = gdk_pixbuf_get_height (pixbuf);
+       /* if the icon is larger than the nominal size, scale down */
+       if (MAX (width, height) > nominal_size) {
+               if (width > height) {
+                       height = height * nominal_size / width;
+                       width = nominal_size;
                } else {
-                       /* Don't scale up small icons */
-                       base_size = nominal_size;
+                       width = width * nominal_size / height;
+                       height = nominal_size;
                }
-       }
-       
-       if (base_size != nominal_size) {
-               scale = (double)nominal_size/base_size;
-               scaled_pixbuf = scale_icon (pixbuf, &scale);
+               scaled_pixbuf = gdk_pixbuf_scale_simple
+                       (pixbuf, width, height, GDK_INTERP_BILINEAR);
                g_object_unref (pixbuf);
                pixbuf = scaled_pixbuf;
        }
@@ -113,7 +98,6 @@ egg_recent_util_get_icon (GnomeIconTheme *theme, const gchar *uri,
        gchar *icon;
        gchar *filename;
        const GnomeIconData *icon_data;
-       int base_size;
        GdkPixbuf *pixbuf;
        
        icon = gnome_icon_lookup (theme, NULL, uri, NULL, NULL,
@@ -125,14 +109,14 @@ egg_recent_util_get_icon (GnomeIconTheme *theme, const gchar *uri,
        filename = gnome_icon_theme_lookup_icon (theme, icon,
                                                 size,
                                                 &icon_data,
-                                                &base_size);
+                                                NULL);
        g_free (icon);
 
        if (filename == NULL) {
                return NULL;
        }
 
-       pixbuf = load_icon_file (filename, base_size, size);
+       pixbuf = load_icon_file (filename, size);
        g_free (filename);
        
        
@@ -148,7 +132,14 @@ egg_recent_util_get_unique_id (void)
        guint32 rand;
        int pid;
        
+#ifndef G_OS_WIN32
        gethostname (hostname, EGG_RECENT_UTIL_HOSTNAME_SIZE);
+#else
+       {
+               DWORD size = EGG_RECENT_UTIL_HOSTNAME_SIZE;
+               GetComputerName (hostname, &size);
+       }
+#endif
        
        time (&the_time);
        rand = g_random_int ();