[nautilus/wip/antoniof/new_open_with: 16/31] properties-window: directly printable user name




commit 84f894cbcdf8ab987f4d764f827a2892c9a692ae
Author: Peter Eisenmann <p3732 getgoogleoff me>
Date:   Mon Nov 22 03:56:52 2021 +0100

    properties-window: directly printable user name
    
    Use a dash with spaces to separate user names and display names, rather
    than line breaks and splitting and recombining the string.
    
    For now the user name is still extracted for each entry, with the
    adaption to GListModel this will only be done when needed.
    
    Part of #1326

 src/nautilus-file.c              |  8 ++++----
 src/nautilus-properties-window.c | 26 +++++++++++++-------------
 2 files changed, 17 insertions(+), 17 deletions(-)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index b5e7291e5..e03d78f90 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -6393,8 +6393,8 @@ nautilus_file_set_owner (NautilusFile                  *file,
  *
  * Get a list of user names. For users with a different associated
  * "real name", the real name follows the standard user name, separated
- * by a carriage return. The caller is responsible for freeing this list
- * and its contents.
+ * by a dash surrounded by spaces. The caller is responsible for freeing
+ * this list and its contents.
  */
 GList *
 nautilus_get_user_names (void)
@@ -6410,9 +6410,9 @@ nautilus_get_user_names (void)
     while ((user = getpwent ()) != NULL)
     {
         real_name = get_real_name (user->pw_name, user->pw_gecos);
-        if (real_name != NULL)
+        if (real_name != NULL && !g_str_equal (real_name, ""))
         {
-            name = g_strconcat (user->pw_name, "\n", real_name, NULL);
+            name = g_strconcat (user->pw_name, " – ", real_name, NULL);
         }
         else
         {
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 3414e6a19..6616db6ab 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -1829,7 +1829,6 @@ synch_user_menu (GtkComboBox  *combo_box,
     GtkTreeModel *model;
     GtkListStore *store;
     GtkTreeIter iter;
-    char *user_name;
     g_autofree char *owner_name = NULL;
     g_autofree char *nice_owner_name = NULL;
     int user_index;
@@ -1863,27 +1862,28 @@ synch_user_menu (GtkComboBox  *combo_box,
 
         for (node = users, user_index = 0; node != NULL; node = node->next, ++user_index)
         {
-            g_auto (GStrv) name_array = NULL;
-            g_autofree char *combo_text = NULL;
+            char *combo_text = (char *) node->data;
+            char *separator_pos = g_strstr_len (combo_text, -1, " – ");
+            char *user_name = combo_text;
 
-            user_name = (char *) node->data;
-
-            name_array = g_strsplit (user_name, "\n", 2);
-            if (name_array[1] != NULL && *name_array[1] != 0)
-            {
-                combo_text = g_strdup_printf ("%s - %s", name_array[0], name_array[1]);
-            }
-            else
+            if (separator_pos != NULL)
             {
-                combo_text = g_strdup (name_array[0]);
+                /* Has display name, extract user name */
+                guint user_name_length = separator_pos - combo_text;
+                user_name = g_strndup (combo_text, user_name_length);
             }
 
             gtk_list_store_append (store, &iter);
             gtk_list_store_set (store, &iter,
                                 0, combo_text,
                                 1, user_name,
-                                2, name_array[0],
+                                2, user_name,
                                 -1);
+            if (separator_pos != NULL)
+            {
+                // only free if copied
+                g_free (user_name);
+            }
         }
 
         g_object_set_data (G_OBJECT (combo_box), "user-hash", GUINT_TO_POINTER (current_user_hash));


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