X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=cut-n-paste%2Frecent-files%2Fegg-recent-item.c;h=ce4b64e834878c2ba02e1feab43fab1b2a8c9481;hb=07ae50430dd7dda3d9304f3836d2a58f011b9d4d;hp=9be7970ec8b744ed3a0f5702a04adfaacd02bba8;hpb=69d92c409d333e5dd9cc82537c0834b201487c60;p=evince.git diff --git a/cut-n-paste/recent-files/egg-recent-item.c b/cut-n-paste/recent-files/egg-recent-item.c index 9be7970e..ce4b64e8 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,90 +98,23 @@ 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; } -/* -static GList * -egg_recent_item_copy_groups (const GList *list) -{ - GList *newlist = NULL; - - while (list) { - gchar *group = (gchar *)list->data; - - newlist = g_list_prepend (newlist, g_strdup (group)); - - list = list->next; - } - - return newlist; -} - - -EggRecentItem * -egg_recent_item_copy (const EggRecentItem *item) -{ - EggRecentItem *newitem; - - newitem = egg_recent_item_new (); - newitem->uri = g_strdup (item->uri); - if (item->mime_type) - newitem->mime_type = g_strdup (item->mime_type); - newitem->timestamp = item->timestamp; - newitem->private_data = item->private_data; - newitem->groups = egg_recent_item_copy_groups (item->groups); - - return newitem; -} -*/ - -/* -EggRecentItem * -egg_recent_item_new_valist (const gchar *uri, va_list args) +static void +egg_recent_item_update_mime_type (EggRecentItem *item) { - EggRecentItem *item; - EggRecentArg arg; - gchar *str1; - gchar *str2; - gboolean priv; - - item = egg_recent_item_new (); - - arg = va_arg (args, EggRecentArg); - - while (arg != EGG_RECENT_ARG_NONE) { - switch (arg) { - case EGG_RECENT_ARG_MIME_TYPE: - str1 = va_arg (args, gchar*); - - egg_recent_item_set_mime_type (item, str1); - break; - case EGG_RECENT_ARG_GROUP: - str1 = va_arg (args, gchar*); - - egg_recent_item_add_group (item, str1); - break; - case EGG_RECENT_ARG_PRIVATE: - priv = va_arg (args, gboolean); + if (!item->mime_type_is_explicit) { + g_free (item->mime_type); + item->mime_type = NULL; - egg_recent_item_set_private (item, priv); - break; - default: - break; - } + if (item->uri) + item->mime_type = gnome_vfs_get_mime_type (item->uri); - arg = va_arg (args, EggRecentArg); + if (!item->mime_type) + item->mime_type = g_strdup (GNOME_VFS_MIME_TYPE_UNKNOWN); } - - return item; } -*/ gboolean egg_recent_item_set_uri (EggRecentItem *item, const gchar *uri) @@ -248,7 +182,7 @@ make_valid_utf8 (const char *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)) @@ -276,6 +210,70 @@ make_valid_utf8 (const char *name) return g_string_free (string, FALSE); } +static gchar * +get_uri_shortname_for_display (GnomeVFSURI *uri) +{ + gchar *name; + gboolean validated; + + validated = FALSE; + name = gnome_vfs_uri_extract_short_name (uri); + + if (name == NULL) + { + name = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD); + } + else if (g_ascii_strcasecmp (uri->method_string, "file") == 0) + { + gchar *text_uri; + gchar *local_file; + text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD); + local_file = gnome_vfs_get_local_path_from_uri (text_uri); + + if (local_file != NULL) + { + g_free (name); + name = g_filename_display_basename (local_file); + validated = TRUE; + } + + g_free (local_file); + g_free (text_uri); + } + else if (!gnome_vfs_uri_has_parent (uri)) + { + const gchar *method; + + method = uri->method_string; + + if (name == NULL || + strcmp (name, GNOME_VFS_URI_PATH_STR) == 0) + { + g_free (name); + name = g_strdup (method); + } + else + { + gchar *tmp; + + tmp = name; + name = g_strdup_printf ("%s: %s", method, name); + g_free (tmp); + } + } + + if (!validated && !g_utf8_validate (name, -1, NULL)) + { + gchar *utf8_name; + + utf8_name = make_valid_utf8 (name); + g_free (name); + name = utf8_name; + } + + return name; +} + /** * egg_recent_item_get_short_name: * @item: an #EggRecentItem @@ -291,8 +289,7 @@ gchar * egg_recent_item_get_short_name (const EggRecentItem *item) { GnomeVFSURI *uri; - char *short_name; - gboolean valid; + gchar *short_name; g_return_val_if_fail (item != NULL, NULL); @@ -303,28 +300,7 @@ egg_recent_item_get_short_name (const EggRecentItem *item) if (uri == NULL) return NULL; - short_name = gnome_vfs_uri_extract_short_name (uri); - valid = FALSE; - - if (strcmp (gnome_vfs_uri_get_scheme (uri), "file") == 0) { - char *tmp; - - tmp = g_filename_to_utf8 (short_name, -1, NULL, NULL, NULL); - if (tmp) { - g_free (short_name); - short_name = tmp; - valid = TRUE; - } - } - - if (!valid) { - char *tmp; - - tmp = make_valid_utf8 (short_name); - g_assert (tmp != NULL); - g_free (short_name); - short_name = tmp; - } + short_name = get_uri_shortname_for_display (uri); gnome_vfs_uri_unref (uri); @@ -334,12 +310,22 @@ 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; + } } 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); }