X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=cut-n-paste%2Frecent-files%2Fegg-recent-item.c;h=ce4b64e834878c2ba02e1feab43fab1b2a8c9481;hb=07ae50430dd7dda3d9304f3836d2a58f011b9d4d;hp=c533205187159067484ad59f64f559280e88e24f;hpb=2845fb905cccd6655c294247722648d3bce97a27;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 c5332051..ce4b64e8 100644 --- a/cut-n-paste/recent-files/egg-recent-item.c +++ b/cut-n-paste/recent-files/egg-recent-item.c @@ -101,83 +101,6 @@ egg_recent_item_new_from_uri (const gchar *uri) 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) -{ - 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); - - egg_recent_item_set_private (item, priv); - break; - default: - break; - } - - arg = va_arg (args, EggRecentArg); - } - - return item; -} -*/ - static void egg_recent_item_update_mime_type (EggRecentItem *item) { @@ -219,8 +142,6 @@ egg_recent_item_set_uri (EggRecentItem *item, const gchar *uri) g_free (utf8_uri); } - egg_recent_item_update_mime_type (item); - return TRUE; } @@ -261,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)) @@ -289,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 @@ -304,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); @@ -316,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); @@ -355,13 +318,14 @@ egg_recent_item_set_mime_type (EggRecentItem *item, const gchar *mime) item->mime_type = g_strdup (mime); } else { item->mime_type_is_explicit = FALSE; - egg_recent_item_update_mime_type (item); } } 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); }