Commit 3fc52e01 authored by Carlos Soriano 's avatar Carlos Soriano

Revert "general: always show file names for desktop files"

This reverts commit ac0e5578
parent 6584c178
Pipeline #1781 canceled with stage
......@@ -194,6 +194,7 @@ static void add_all_files_to_work_queue (NautilusDirectory *directory);
static void link_info_done (NautilusDirectory *directory,
NautilusFile *file,
const char *uri,
const char *name,
GIcon *icon,
gboolean is_launcher);
static void move_file_to_low_priority_queue (NautilusDirectory *directory,
......@@ -1810,7 +1811,7 @@ lacks_link_info (NautilusFile *file)
}
else
{
link_info_done (file->details->directory, file, NULL, NULL, FALSE);
link_info_done (file->details->directory, file, NULL, NULL, NULL, FALSE);
return FALSE;
}
}
......@@ -3587,6 +3588,7 @@ static void
link_info_done (NautilusDirectory *directory,
NautilusFile *file,
const char *uri,
const char *name,
GIcon *icon,
gboolean is_launcher)
{
......@@ -3596,6 +3598,15 @@ link_info_done (NautilusDirectory *directory,
is_trusted = is_link_trusted (file, is_launcher);
if (is_trusted)
{
nautilus_file_set_display_name (file, name, name, TRUE);
}
else
{
nautilus_file_set_display_name (file, NULL, NULL, TRUE);
}
file->details->got_link_info = TRUE;
g_clear_object (&file->details->custom_icon);
......@@ -3649,13 +3660,14 @@ link_info_got_data (NautilusDirectory *directory,
goffset bytes_read,
char *file_contents)
{
char *link_uri, *uri;
char *link_uri, *uri, *name;
GIcon *icon;
gboolean is_launcher;
nautilus_directory_ref (directory);
uri = NULL;
name = NULL;
icon = NULL;
is_launcher = FALSE;
......@@ -3664,7 +3676,7 @@ link_info_got_data (NautilusDirectory *directory,
{
link_uri = nautilus_file_get_uri (file);
nautilus_link_get_link_info_given_file_contents (file_contents, bytes_read, link_uri,
&uri, &icon, &is_launcher);
&uri, &name, &icon, &is_launcher);
g_free (link_uri);
}
else
......@@ -3673,11 +3685,12 @@ link_info_got_data (NautilusDirectory *directory,
}
nautilus_file_ref (file);
link_info_done (directory, file, uri, icon, is_launcher);
link_info_done (directory, file, uri, name, icon, is_launcher);
nautilus_file_changed (file);
nautilus_file_unref (file);
g_free (uri);
g_free (name);
if (icon != NULL)
{
......@@ -3766,7 +3779,7 @@ link_info_start (NautilusDirectory *directory,
/* If it's not a link we are done. If it is, we need to read it. */
if (!nautilus_style_link)
{
link_info_done (directory, file, NULL, NULL, FALSE);
link_info_done (directory, file, NULL, NULL, NULL, FALSE);
}
else
{
......
......@@ -2048,10 +2048,19 @@ nautilus_file_can_rename_file (NautilusFile *file,
gpointer callback_data)
{
GError *error;
gboolean is_renameable_desktop_file;
gboolean success;
gboolean name_changed;
gchar *new_file_name;
gchar *uri;
gchar *old_name;
is_renameable_desktop_file =
is_desktop_file (file) && can_rename_desktop_file (file);
/* Return an error for incoming names containing path separators. */
if (strstr (new_name, "/") != NULL)
/* Return an error for incoming names containing path separators.
* But not for .desktop files as '/' are allowed for them */
if (strstr (new_name, "/") != NULL && !is_renameable_desktop_file)
{
error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
_("Slashes are not allowed in filenames"));
......@@ -2076,7 +2085,8 @@ nautilus_file_can_rename_file (NautilusFile *file,
* (1) rename returns an error if new & old are same.
* (2) We don't want to send file-changed signal if nothing changed.
*/
if (name_is (file, new_name))
if (!is_renameable_desktop_file &&
name_is (file, new_name))
{
if (callback != NULL)
{
......@@ -2108,7 +2118,62 @@ nautilus_file_can_rename_file (NautilusFile *file,
return NULL;
}
new_file_name = g_strdup (new_name);
if (is_renameable_desktop_file)
{
/* Don't actually change the name if the new name is the same.
* This helps for the vfolder method where this can happen and
* we want to minimize actual changes
*/
uri = nautilus_file_get_uri (file);
old_name = nautilus_link_local_get_text (uri);
if (old_name != NULL && strcmp (new_name, old_name) == 0)
{
success = TRUE;
name_changed = FALSE;
}
else
{
success = nautilus_link_local_set_text (uri, new_name);
name_changed = TRUE;
}
g_free (old_name);
g_free (uri);
if (!success)
{
error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
_("Probably the content of the file is an invalid desktop file format"));
if (callback != NULL)
{
(*callback)(file, NULL, error, callback_data);
}
g_error_free (error);
return NULL;
}
new_file_name = g_strdup_printf ("%s.desktop", new_name);
new_file_name = g_strdelimit (new_file_name, "/", '-');
if (name_is (file, new_file_name))
{
if (name_changed)
{
nautilus_file_invalidate_attributes (file,
NAUTILUS_FILE_ATTRIBUTE_INFO |
NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
}
if (callback != NULL)
{
(*callback)(file, NULL, NULL, callback_data);
}
g_free (new_file_name);
return NULL;
}
}
else
{
new_file_name = g_strdup (new_name);
}
return new_file_name;
}
......
......@@ -319,6 +319,14 @@ nautilus_link_local_set_key (const char *uri,
return success;
}
gboolean
nautilus_link_local_set_text (const char *uri,
const char *text)
{
return nautilus_link_local_set_key (uri, "Name", text, TRUE);
}
gboolean
nautilus_link_local_set_icon (const char *uri,
const char *icon)
......@@ -392,6 +400,12 @@ nautilus_link_get_link_uri_from_desktop (GKeyFile *key_file,
return retval;
}
static char *
nautilus_link_get_link_name_from_desktop (GKeyFile *key_file)
{
return g_key_file_get_locale_string (key_file, MAIN_GROUP, "Name", NULL, NULL);
}
static GIcon *
nautilus_link_get_link_icon_from_desktop (GKeyFile *key_file)
{
......@@ -511,6 +525,7 @@ nautilus_link_get_link_info_given_file_contents (const char *file_contents,
int link_file_size,
const char *file_uri,
char **uri,
char **name,
GIcon **icon,
gboolean *is_launcher)
{
......@@ -529,6 +544,7 @@ nautilus_link_get_link_info_given_file_contents (const char *file_contents,
}
*uri = nautilus_link_get_link_uri_from_desktop (key_file, file_uri);
*name = nautilus_link_get_link_name_from_desktop (key_file);
*icon = nautilus_link_get_link_icon_from_desktop (key_file);
*is_launcher = FALSE;
......
......@@ -31,6 +31,8 @@ gboolean nautilus_link_local_create (const char
const char *target_uri,
int screen,
gboolean unique_filename);
gboolean nautilus_link_local_set_text (const char *uri,
const char *text);
gboolean nautilus_link_local_set_icon (const char *uri,
const char *icon);
char * nautilus_link_local_get_text (const char *uri);
......@@ -39,6 +41,7 @@ void nautilus_link_get_link_info_given_file_contents (const char
int link_file_size,
const char *file_uri,
char **uri,
char **name,
GIcon **icon,
gboolean *is_launcher);
......
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