[Xfce4-commits] <thunar:master> Remove keys if field is empty in properties page.

Nick Schermer noreply at xfce.org
Fri Sep 28 18:26:01 CEST 2012


Updating branch refs/heads/master
         to 7cb0de9b35f1bb0bbc5dc3104a25bcd79cb8b374 (commit)
       from cb4119a20abb4c1eb70ef595c953d3ed557cca40 (commit)

commit 7cb0de9b35f1bb0bbc5dc3104a25bcd79cb8b374
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Sep 28 18:22:52 2012 +0200

    Remove keys if field is empty in properties page.
    
    Some apps don't support for example an empty Path= so
    remove the key from the file if the value is nul.

 plugins/thunar-apr/thunar-apr-desktop-page.c |   63 +++++++++++++++----------
 1 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/plugins/thunar-apr/thunar-apr-desktop-page.c b/plugins/thunar-apr/thunar-apr-desktop-page.c
index 116f751..b525b90 100644
--- a/plugins/thunar-apr/thunar-apr-desktop-page.c
+++ b/plugins/thunar-apr/thunar-apr-desktop-page.c
@@ -602,6 +602,27 @@ thunar_apr_desktop_page_save (ThunarAprDesktopPage *desktop_page,
 
 
 static void
+thunar_apr_desktop_page_set_string (GKeyFile    *key_file,
+                                    const gchar *key,
+                                    const gchar *value)
+{
+  if (value != NULL && *value != '\0')
+    {
+      g_key_file_set_string (key_file,
+                             G_KEY_FILE_DESKTOP_GROUP,
+                             key, value);
+    }
+  else
+    {
+      g_key_file_remove_key  (key_file,
+                              G_KEY_FILE_DESKTOP_GROUP,
+                              key, NULL);
+    }
+}
+
+
+
+static void
 thunar_apr_desktop_page_save_widget (ThunarAprDesktopPage *desktop_page,
                                      GtkWidget            *widget,
                                      GKeyFile             *key_file)
@@ -621,7 +642,7 @@ thunar_apr_desktop_page_save_widget (ThunarAprDesktopPage *desktop_page,
           key = g_strdup_printf (G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME "[%s]", *locale);
           if (g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, key, NULL))
             {
-              g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, key, desktop_page->description_text);
+              thunar_apr_desktop_page_set_string (key_file, key, desktop_page->description_text);
               g_free (key);
               break;
             }
@@ -631,10 +652,9 @@ thunar_apr_desktop_page_save_widget (ThunarAprDesktopPage *desktop_page,
       /* fallback to unlocalized description */
       if (G_UNLIKELY (*locale == NULL))
         {
-          g_key_file_set_string (key_file,
-                                 G_KEY_FILE_DESKTOP_GROUP,
-                                 G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME,
-                                 desktop_page->description_text);
+          thunar_apr_desktop_page_set_string (key_file,
+                                              G_KEY_FILE_DESKTOP_KEY_GENERIC_NAME,
+                                              desktop_page->description_text);
         }
     }
   else if (widget == desktop_page->command_entry)
@@ -644,10 +664,9 @@ thunar_apr_desktop_page_save_widget (ThunarAprDesktopPage *desktop_page,
       desktop_page->command_text = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1);
 
       /* save the unlocalized command */
-      g_key_file_set_string (key_file,
-                             G_KEY_FILE_DESKTOP_GROUP,
-                             G_KEY_FILE_DESKTOP_KEY_EXEC,
-                             desktop_page->command_text);
+      thunar_apr_desktop_page_set_string (key_file,
+                                          G_KEY_FILE_DESKTOP_KEY_EXEC,
+                                          desktop_page->command_text);
     }
   else if (widget == desktop_page->path_entry)
     {
@@ -656,10 +675,9 @@ thunar_apr_desktop_page_save_widget (ThunarAprDesktopPage *desktop_page,
       desktop_page->path_text = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1);
 
       /* save the unlocalized command */
-      g_key_file_set_string (key_file,
-                             G_KEY_FILE_DESKTOP_GROUP,
-                             G_KEY_FILE_DESKTOP_KEY_PATH,
-                             desktop_page->path_text);
+      thunar_apr_desktop_page_set_string (key_file,
+                                          G_KEY_FILE_DESKTOP_KEY_PATH,
+                                          desktop_page->path_text);
     }
   else if (widget == desktop_page->url_entry)
     {
@@ -668,10 +686,9 @@ thunar_apr_desktop_page_save_widget (ThunarAprDesktopPage *desktop_page,
       desktop_page->url_text = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1);
 
       /* save the unlocalized url */
-      g_key_file_set_string (key_file,
-                             G_KEY_FILE_DESKTOP_GROUP,
-                             G_KEY_FILE_DESKTOP_KEY_URL,
-                             desktop_page->url_text);
+      thunar_apr_desktop_page_set_string (key_file,
+                                          G_KEY_FILE_DESKTOP_KEY_URL,
+                                          desktop_page->url_text);
     }
   else if (widget == desktop_page->comment_entry)
     {
@@ -685,10 +702,7 @@ thunar_apr_desktop_page_save_widget (ThunarAprDesktopPage *desktop_page,
           key = g_strdup_printf (G_KEY_FILE_DESKTOP_KEY_COMMENT "[%s]", *locale);
           if (g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, key, NULL))
             {
-              g_key_file_set_string (key_file,
-                                     G_KEY_FILE_DESKTOP_GROUP,
-                                     key,
-                                     desktop_page->comment_text);
+              thunar_apr_desktop_page_set_string (key_file, key, desktop_page->comment_text);
               g_free (key);
               break;
             }
@@ -697,10 +711,9 @@ thunar_apr_desktop_page_save_widget (ThunarAprDesktopPage *desktop_page,
 
       /* fallback to unlocalized comment */
       if (G_UNLIKELY (*locale == NULL))
-        g_key_file_set_string (key_file,
-                              G_KEY_FILE_DESKTOP_GROUP,
-                              G_KEY_FILE_DESKTOP_KEY_COMMENT,
-                              desktop_page->comment_text);
+        thunar_apr_desktop_page_set_string (key_file,
+                                            G_KEY_FILE_DESKTOP_KEY_COMMENT,
+                                            desktop_page->comment_text);
     }
   else if (widget == desktop_page->snotify_button)
     {


More information about the Xfce4-commits mailing list