Commit 2b177587 authored by Matthias Clasen's avatar Matthias Clasen

Move a function around

_Gtk_file_chooser_label_for_file is not actually
used in gtkfilechooserdefault.c anymore, so move
it to a better place.
parent 8b7940c0
......@@ -896,62 +896,6 @@ set_preview_widget (GtkFileChooserDefault *impl,
update_preview_widget_visibility (impl);
}
/* FIXME: GtkFileSystem needs a function to split a remote path
* into hostname and path components, or maybe just have a
* gtk_file_system_path_get_display_name().
*
* This function is also used in gtkfilechooserbutton.c
*/
gchar *
_gtk_file_chooser_label_for_file (GFile *file)
{
const gchar *path, *start, *end, *p;
gchar *uri, *host, *label;
uri = g_file_get_uri (file);
start = strstr (uri, "://");
if (start)
{
start += 3;
path = strchr (start, '/');
if (path)
end = path;
else
{
end = uri + strlen (uri);
path = "/";
}
/* strip username */
p = strchr (start, '@');
if (p && p < end)
start = p + 1;
p = strchr (start, ':');
if (p && p < end)
end = p;
host = g_strndup (start, end - start);
/* Translators: the first string is a path and the second string
* is a hostname. Nautilus and the panel contain the same string
* to translate.
*/
label = g_strdup_printf (_("%1$s on %2$s"), path, host);
g_free (host);
}
else
{
label = g_strdup (uri);
}
g_free (uri);
return label;
}
/* Callback used when the "New Folder" button is clicked */
static void
new_folder_button_clicked (GtkButton *button,
......
......@@ -33,8 +33,6 @@ typedef struct _GtkFileChooserDefault GtkFileChooserDefault;
GType _gtk_file_chooser_default_get_type (void) G_GNUC_CONST;
GtkWidget *_gtk_file_chooser_default_new (void);
gchar * _gtk_file_chooser_label_for_file (GFile *file);
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_DEFAULT_H__ */
......@@ -449,3 +449,53 @@ _gtk_file_chooser_get_settings_for_widget (GtkWidget *widget)
return settings;
}
gchar *
_gtk_file_chooser_label_for_file (GFile *file)
{
const gchar *path, *start, *end, *p;
gchar *uri, *host, *label;
uri = g_file_get_uri (file);
start = strstr (uri, "://");
if (start)
{
start += 3;
path = strchr (start, '/');
if (path)
end = path;
else
{
end = uri + strlen (uri);
path = "/";
}
/* strip username */
p = strchr (start, '@');
if (p && p < end)
start = p + 1;
p = strchr (start, ':');
if (p && p < end)
end = p;
host = g_strndup (start, end - start);
/* Translators: the first string is a path and the second string
* is a hostname. Nautilus and the panel contain the same string
* to translate.
*/
label = g_strdup_printf (_("%1$s on %2$s"), path, host);
g_free (host);
}
else
{
label = g_strdup (uri);
}
g_free (uri);
return label;
}
......@@ -54,6 +54,8 @@ GList *_gtk_file_chooser_extract_recent_folders (GList *infos);
GSettings *_gtk_file_chooser_get_settings_for_widget (GtkWidget *widget);
gchar * _gtk_file_chooser_label_for_file (GFile *file);
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_UTILS_H__ */
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