Mercurial > audlegacy
diff src/audacious/strings.c @ 4089:9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
- input plugins can use these functions as aud_uri_to_display_basename() / aud_uri_to_display_dirname() on associating FIELD_FILE_NAME / FIELD_FILE_PATH.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Mon, 17 Dec 2007 21:56:17 +0900 |
parents | 040243a50bd3 |
children | 5f92bee6cd5b |
line wrap: on
line diff
--- a/src/audacious/strings.c Sun Dec 16 18:54:45 2007 +0100 +++ b/src/audacious/strings.c Mon Dec 17 21:56:17 2007 +0900 @@ -194,6 +194,7 @@ return out_str; } +/* convert name of absolute path in local file system encoding into utf8 string */ gchar * filename_to_utf8(const gchar * filename) { @@ -209,6 +210,40 @@ return str_to_utf8_fallback(filename); } +/* derives basename from uri. basename is in utf8 */ +gchar * +uri_to_display_basename(const gchar * uri) +{ + gchar *realfn, *utf8fn, *basename; + + g_return_val_if_fail(uri, NULL); + + realfn = g_filename_from_uri(uri, NULL, NULL); + utf8fn = g_filename_display_name(realfn ? realfn : uri); // guaranteed to be non-NULL + basename = g_path_get_basename(utf8fn); + + g_free(realfn); g_free(utf8fn); + + return basename; +} + +/* derives dirname from uri. dirname is in utf8 */ +gchar * +uri_to_display_dirname(const gchar * uri) +{ + gchar *realfn, *utf8fn, *dirname; + + g_return_val_if_fail(uri, NULL); + + realfn = g_filename_from_uri(uri, NULL, NULL); + utf8fn = g_filename_display_name(realfn ? realfn : uri); // guaranteed to be non-NULL + dirname = g_path_get_dirname(utf8fn); + + g_free(realfn); g_free(utf8fn); + + return dirname; +} + gchar * str_to_utf8(const gchar * str) {