]> www.fi.muni.cz Git - evince.git/blobdiff - cut-n-paste/recent-files/egg-recent-item.c
Release 0.3.2
[evince.git] / cut-n-paste / recent-files / egg-recent-item.c
index 9be7970ec8b744ed3a0f5702a04adfaacd02bba8..bf7fee6c636d153d55d45d64b76bd6ed3c639356 100644 (file)
@@ -1,5 +1,5 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /* -*- 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
  * 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->private_data = FALSE;
        item->uri = NULL;
        item->mime_type = NULL;
+       item->mime_type_is_explicit = FALSE;
 
        item->refcount = 1;
 
 
        item->refcount = 1;
 
@@ -97,11 +98,6 @@ egg_recent_item_new_from_uri (const gchar *uri)
                return NULL;
        }
        
                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;
 }
 
        return item;
 }
 
@@ -132,6 +128,7 @@ egg_recent_item_copy (const EggRecentItem *item)
        newitem->uri = g_strdup (item->uri);
        if (item->mime_type)
                newitem->mime_type = g_strdup (item->mime_type);
        newitem->uri = g_strdup (item->uri);
        if (item->mime_type)
                newitem->mime_type = g_strdup (item->mime_type);
+       newitem->mime_type_is_explicit = item->mime_type_is_explicit
        newitem->timestamp = item->timestamp;
        newitem->private_data = item->private_data;
        newitem->groups = egg_recent_item_copy_groups (item->groups);
        newitem->timestamp = item->timestamp;
        newitem->private_data = item->private_data;
        newitem->groups = egg_recent_item_copy_groups (item->groups);
@@ -182,6 +179,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)
 {
 gboolean
 egg_recent_item_set_uri (EggRecentItem *item, const gchar *uri)
 {
@@ -248,7 +260,7 @@ make_valid_utf8 (const char *name)
 
        string = NULL;
        remainder = name;
 
        string = NULL;
        remainder = name;
-       remaining_bytes = strlen (name);
+       remaining_bytes = name ? strlen (name) : 0;
 
        while (remaining_bytes != 0) {
                if (g_utf8_validate (remainder, remaining_bytes, &invalid))
 
        while (remaining_bytes != 0) {
                if (g_utf8_validate (remainder, remaining_bytes, &invalid))
@@ -304,6 +316,11 @@ egg_recent_item_get_short_name (const EggRecentItem *item)
                return NULL;
 
        short_name = gnome_vfs_uri_extract_short_name (uri);
                return NULL;
 
        short_name = gnome_vfs_uri_extract_short_name (uri);
+       if (short_name == NULL) {
+               gnome_vfs_uri_unref (uri);
+               return NULL;
+       }
+
        valid = FALSE;
 
        if (strcmp (gnome_vfs_uri_get_scheme (uri), "file") == 0) {
        valid = FALSE;
 
        if (strcmp (gnome_vfs_uri_get_scheme (uri), "file") == 0) {
@@ -334,12 +351,22 @@ egg_recent_item_get_short_name (const EggRecentItem *item)
 void 
 egg_recent_item_set_mime_type (EggRecentItem *item, const gchar *mime)
 {
 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;
+       }
 }
 
 gchar * 
 }
 
 gchar * 
-egg_recent_item_get_mime_type (const EggRecentItem *item)
+egg_recent_item_get_mime_type (EggRecentItem *item)
 {
 {
+       egg_recent_item_update_mime_type (item);
+
        return g_strdup (item->mime_type);
 }
 
        return g_strdup (item->mime_type);
 }