GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit 874f69f2 authored by William Jon McCann's avatar William Jon McCann

Set a better file display name by default

https://bugzilla.gnome.org/show_bug.cgi?id=524116
parent 4047e531
......@@ -38,6 +38,7 @@
#include "nautilus-vfs-directory.h"
#include <eel/eel-glib-extensions.h>
#include <eel/eel-string.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
enum {
......@@ -453,19 +454,31 @@ nautilus_directory_get_existing_corresponding_file (NautilusDirectory *directory
char *
nautilus_directory_get_name_for_self_as_new_file (NautilusDirectory *directory)
{
GFile *file;
char *directory_uri;
char *name, *colon;
char *scheme;
char *name;
char *hostname = NULL;
directory_uri = nautilus_directory_get_uri (directory);
file = g_file_new_for_uri (directory_uri);
scheme = g_file_get_uri_scheme (file);
g_object_unref (file);
colon = strchr (directory_uri, ':');
if (colon == NULL || colon == directory_uri) {
nautilus_uri_parse (directory_uri, &hostname, NULL, NULL);
if (hostname == NULL) {
name = g_strdup (directory_uri);
} else if (scheme == NULL) {
name = g_strdup (hostname);
} else {
name = g_strndup (directory_uri, colon - directory_uri);
/* Translators: this is of the format "hostname (uri-scheme)" */
name = g_strdup_printf (_("%s (%s)"), hostname, scheme);
}
g_free (directory_uri);
g_free (scheme);
g_free (hostname);
return name;
}
......
......@@ -54,6 +54,213 @@ static void update_xdg_dir_cache (void);
static void schedule_user_dirs_changed (void);
static void desktop_dir_changed (void);
/* Allowed characters outside alphanumeric for unreserved. */
#define G_URI_OTHER_UNRESERVED "-._~"
/* This or something equivalent will eventually go into glib/guri.h */
gboolean
nautilus_uri_parse (const char *uri,
char **host,
guint16 *port,
char **userinfo)
{
char *tmp_str;
const char *start, *p;
char c;
g_return_val_if_fail (uri != NULL, FALSE);
if (host)
*host = NULL;
if (port)
*port = 0;
if (userinfo)
*userinfo = NULL;
/* From RFC 3986 Decodes:
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
* hier-part = "//" authority path-abempty
* path-abempty = *( "/" segment )
* authority = [ userinfo "@" ] host [ ":" port ]
*/
/* Check we have a valid scheme */
tmp_str = g_uri_parse_scheme (uri);
if (tmp_str == NULL)
return FALSE;
g_free (tmp_str);
/* Decode hier-part:
* hier-part = "//" authority path-abempty
*/
p = uri;
start = strstr (p, "//");
if (start == NULL)
return FALSE;
start += 2;
if (strchr (start, '@') != NULL)
{
/* Decode userinfo:
* userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
* pct-encoded = "%" HEXDIG HEXDIG
*/
p = start;
while (1)
{
c = *p++;
if (c == '@')
break;
/* pct-encoded */
if (c == '%')
{
if (!(g_ascii_isxdigit (p[0]) ||
g_ascii_isxdigit (p[1])))
return FALSE;
p++;
continue;
}
/* unreserved / sub-delims / : */
if (!(g_ascii_isalnum (c) ||
strchr (G_URI_OTHER_UNRESERVED, c) ||
strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
c == ':'))
return FALSE;
}
if (userinfo)
*userinfo = g_strndup (start, p - start - 1);
start = p;
}
else
{
p = start;
}
/* decode host:
* host = IP-literal / IPv4address / reg-name
* reg-name = *( unreserved / pct-encoded / sub-delims )
*/
/* If IPv6 or IPvFuture */
if (*p == '[')
{
start++;
p++;
while (1)
{
c = *p++;
if (c == ']')
break;
/* unreserved / sub-delims */
if (!(g_ascii_isalnum (c) ||
strchr (G_URI_OTHER_UNRESERVED, c) ||
strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
c == ':' ||
c == '.'))
goto error;
}
}
else
{
while (1)
{
c = *p++;
if (c == ':' ||
c == '/' ||
c == '?' ||
c == '#' ||
c == '\0')
break;
/* pct-encoded */
if (c == '%')
{
if (!(g_ascii_isxdigit (p[0]) ||
g_ascii_isxdigit (p[1])))
goto error;
p++;
continue;
}
/* unreserved / sub-delims */
if (!(g_ascii_isalnum (c) ||
strchr (G_URI_OTHER_UNRESERVED, c) ||
strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c)))
goto error;
}
}
if (host)
*host = g_uri_unescape_segment (start, p - 1, NULL);
if (c == ':')
{
/* Decode pot:
* port = *DIGIT
*/
guint tmp = 0;
while (1)
{
c = *p++;
if (c == '/' ||
c == '?' ||
c == '#' ||
c == '\0')
break;
if (!g_ascii_isdigit (c))
goto error;
tmp = (tmp * 10) + (c - '0');
if (tmp > 65535)
goto error;
}
if (port)
*port = (guint16) tmp;
}
return TRUE;
error:
if (host && *host)
{
g_free (*host);
*host = NULL;
}
if (userinfo && *userinfo)
{
g_free (*userinfo);
*userinfo = NULL;
}
return FALSE;
}
char *
nautilus_compute_title_for_location (GFile *location)
{
......
......@@ -60,6 +60,11 @@ char * nautilus_compute_title_for_location (GFile *file);
gboolean nautilus_is_file_roller_installed (void);
gboolean nautilus_uri_parse (const char *uri,
char **host,
guint16 *port,
char **userinfo);
/* Return an allocated file name that is guranteed to be unique, but
* tries to make the name readable to users.
* This isn't race-free, so don't use for security-related things
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment