From 2845fb905cccd6655c294247722648d3bce97a27 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 08 Jan 2005 23:33:58 +0000 Subject: Update 2005-01-09 Marco Pesenti Gritti * cut-n-paste/recent-files/egg-recent-item.c: * cut-n-paste/recent-files/egg-recent-item.h: * cut-n-paste/recent-files/egg-recent-model.c: * cut-n-paste/recent-files/egg-recent-util.c: * cut-n-paste/recent-files/egg-recent-view-gtk.c: * cut-n-paste/recent-files/egg-recent-view.c: Update --- (limited to 'cut-n-paste') diff --git a/cut-n-paste/recent-files/egg-recent-item.c b/cut-n-paste/recent-files/egg-recent-item.c index 9be7970..c533205 100644 --- a/cut-n-paste/recent-files/egg-recent-item.c +++ b/cut-n-paste/recent-files/egg-recent-item.c @@ -1,5 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/** +/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the @@ -39,6 +39,7 @@ egg_recent_item_new (void) item->private_data = FALSE; item->uri = NULL; item->mime_type = NULL; + item->mime_type_is_explicit = FALSE; item->refcount = 1; @@ -97,11 +98,6 @@ egg_recent_item_new_from_uri (const gchar *uri) return NULL; } - item->mime_type = gnome_vfs_get_mime_type (item->uri); - - if (!item->mime_type) - item->mime_type = g_strdup (GNOME_VFS_MIME_TYPE_UNKNOWN); - return item; } @@ -182,6 +178,21 @@ egg_recent_item_new_valist (const gchar *uri, va_list args) } */ +static void +egg_recent_item_update_mime_type (EggRecentItem *item) +{ + if (!item->mime_type_is_explicit) { + g_free (item->mime_type); + item->mime_type = NULL; + + if (item->uri) + item->mime_type = gnome_vfs_get_mime_type (item->uri); + + if (!item->mime_type) + item->mime_type = g_strdup (GNOME_VFS_MIME_TYPE_UNKNOWN); + } +} + gboolean egg_recent_item_set_uri (EggRecentItem *item, const gchar *uri) { @@ -208,6 +219,8 @@ egg_recent_item_set_uri (EggRecentItem *item, const gchar *uri) g_free (utf8_uri); } + egg_recent_item_update_mime_type (item); + return TRUE; } @@ -334,7 +347,16 @@ egg_recent_item_get_short_name (const EggRecentItem *item) void egg_recent_item_set_mime_type (EggRecentItem *item, const gchar *mime) { - item->mime_type = g_strdup (mime); + g_free (item->mime_type); + item->mime_type = NULL; + + if (mime && mime[0]) { + item->mime_type_is_explicit = TRUE; + item->mime_type = g_strdup (mime); + } else { + item->mime_type_is_explicit = FALSE; + egg_recent_item_update_mime_type (item); + } } gchar * diff --git a/cut-n-paste/recent-files/egg-recent-item.h b/cut-n-paste/recent-files/egg-recent-item.h index 5b3b405..93091ae 100644 --- a/cut-n-paste/recent-files/egg-recent-item.h +++ b/cut-n-paste/recent-files/egg-recent-item.h @@ -27,6 +27,8 @@ struct _EggRecentItem { GList *groups; int refcount; + + guint mime_type_is_explicit : 1; }; GType egg_recent_item_get_type (void) G_GNUC_CONST; diff --git a/cut-n-paste/recent-files/egg-recent-model.c b/cut-n-paste/recent-files/egg-recent-model.c index f36053b..201aec0 100644 --- a/cut-n-paste/recent-files/egg-recent-model.c +++ b/cut-n-paste/recent-files/egg-recent-model.c @@ -1,5 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/** +/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the @@ -677,12 +677,17 @@ static void egg_recent_model_monitor (EggRecentModel *model, gboolean should_monitor) { if (should_monitor && model->priv->monitor == NULL) { + char *uri; + + uri = gnome_vfs_get_uri_from_local_path (model->priv->path); gnome_vfs_monitor_add (&model->priv->monitor, - model->priv->path, - GNOME_VFS_MONITOR_FILE, - egg_recent_model_monitor_cb, - model); + uri, + GNOME_VFS_MONITOR_FILE, + egg_recent_model_monitor_cb, + model); + + g_free (uri); /* if the above fails, don't worry about it. * local notifications will still happen @@ -1286,6 +1291,7 @@ egg_recent_model_add_full (EggRecentModel * model, EggRecentItem *item) ret = TRUE; } else { g_warning ("Failed to lock: %s", strerror (errno)); + fclose (file); return FALSE; } diff --git a/cut-n-paste/recent-files/egg-recent-util.c b/cut-n-paste/recent-files/egg-recent-util.c index cb30e05..6780cd1 100644 --- a/cut-n-paste/recent-files/egg-recent-util.c +++ b/cut-n-paste/recent-files/egg-recent-util.c @@ -55,50 +55,31 @@ 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 +94,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 +105,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); diff --git a/cut-n-paste/recent-files/egg-recent-view-gtk.c b/cut-n-paste/recent-files/egg-recent-view-gtk.c index 34805b2..9872736 100644 --- a/cut-n-paste/recent-files/egg-recent-view-gtk.c +++ b/cut-n-paste/recent-files/egg-recent-view-gtk.c @@ -1,5 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/** +/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the @@ -190,7 +190,7 @@ egg_recent_view_gtk_new_separator (EggRecentViewGtk *view) retval = gtk_separator_menu_item_new (); - /** + /* * this is a tag so we can distinguish our menu items * from others that may be in the menu. */ @@ -285,7 +285,7 @@ egg_recent_view_gtk_new_menu_item (EggRecentViewGtk *view, g_free (mime_type); g_free (text); - /** + /* * this is a tag so we can distinguish our menu items * from others that may be in the menu. */ @@ -773,7 +773,6 @@ egg_recent_view_gtk_new (GtkWidget *menu, GtkWidget *start_menu_item) /** * egg_recent_view_gtk_get_type: - * @: * * This returns a GType representing a EggRecentViewGtk object. * diff --git a/cut-n-paste/recent-files/egg-recent-view.c b/cut-n-paste/recent-files/egg-recent-view.c index 0aa38b9..7794561 100644 --- a/cut-n-paste/recent-files/egg-recent-view.c +++ b/cut-n-paste/recent-files/egg-recent-view.c @@ -1,5 +1,5 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/** +/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the -- cgit v0.9.1