[nautilus] Revert "general: always show file names for desktop files"



commit 3fc52e01065e1c2e046f9684ab962dbd9a205a3f
Author: Carlos Soriano <csoriano1618 gmail com>
Date:   Tue Jan 2 17:48:11 2018 +0000

    Revert "general: always show file names for desktop files"
    
    This reverts commit ac0e5578d291073fc034e5a206dcb36a2fd0220f

 src/nautilus-directory-async.c | 23 ++++++++++---
 src/nautilus-file.c            | 73 +++++++++++++++++++++++++++++++++++++++---
 src/nautilus-link.c            | 16 +++++++++
 src/nautilus-link.h            |  3 ++
 4 files changed, 106 insertions(+), 9 deletions(-)
---
diff --git a/src/nautilus-directory-async.c b/src/nautilus-directory-async.c
index 42ee8918c..d642e6fad 100644
--- a/src/nautilus-directory-async.c
+++ b/src/nautilus-directory-async.c
@@ -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
     {
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index 88a367e88..e62b54a5c 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -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;
 }
diff --git a/src/nautilus-link.c b/src/nautilus-link.c
index 8246752e1..d52841843 100644
--- a/src/nautilus-link.c
+++ b/src/nautilus-link.c
@@ -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;
diff --git a/src/nautilus-link.h b/src/nautilus-link.h
index fc73b6e58..be0c691ce 100644
--- a/src/nautilus-link.h
+++ b/src/nautilus-link.h
@@ -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);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]