[Xfce4-commits] [xfce/exo] 01/02: Clear bad entries in mimeapps.list

noreply at xfce.org noreply at xfce.org
Sat May 25 20:01:17 CEST 2019


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/exo.

commit 48e12f1d5f31e576f7017c50785032ef6d22cfd1
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Sat May 25 14:00:05 2019 -0400

    Clear bad entries in mimeapps.list
---
 exo-helper/exo-helper.c | 102 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 84 insertions(+), 18 deletions(-)

diff --git a/exo-helper/exo-helper.c b/exo-helper/exo-helper.c
index 8f7536d..cc89d42 100644
--- a/exo-helper/exo-helper.c
+++ b/exo-helper/exo-helper.c
@@ -51,6 +51,7 @@
 static void       exo_helper_finalize   (GObject        *object);
 static ExoHelper *exo_helper_new        (const gchar    *id,
                                          XfceRc         *rc);
+static void       clear_bad_entries     (XfceRc         *rc);
 
 
 
@@ -682,6 +683,23 @@ exo_helper_database_get_default (ExoHelperDatabase *database,
 
 
 
+static XfceRc*
+mimeapps_open (gboolean readonly)
+{
+  XfceRc *rc;
+
+  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "mimeapps.list", readonly);
+  if (G_UNLIKELY (rc == NULL))
+    {
+      /* deprecated location (glib < 2.41) */
+      rc = xfce_rc_config_open (XFCE_RESOURCE_DATA, "applications/mimeapps.list", readonly);
+    }
+
+  return rc;
+}
+
+
+
 /**
  * exo_helper_database_set_default:
  * @database : an #ExoHelperDatabase.
@@ -753,16 +771,11 @@ exo_helper_database_set_default (ExoHelperDatabase *database,
     }
 
   /* open the mimeapp.list file to set the default handler of the mime type */
-  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "mimeapps.list", FALSE);
+  rc = mimeapps_open (FALSE);
   if (G_UNLIKELY (rc == NULL))
     {
-      /* deprecated location (glib < 2.41) */
-      rc = xfce_rc_config_open (XFCE_RESOURCE_DATA, "applications/mimeapps.list", FALSE);
-      if (G_UNLIKELY (rc == NULL))
-        {
-          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_IO, _("Failed to open %s for writing"), "mimeapps.list");
-          return FALSE;
-        }
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_IO, _("Failed to open %s for writing"), "mimeapps.list");
+      return FALSE;
     }
 
   /* open the exo desktop file to read the mimetypes the file supports */
@@ -791,6 +804,8 @@ exo_helper_database_set_default (ExoHelperDatabase *database,
       xfce_rc_close (desktop_file);
     }
 
+  clear_bad_entries (rc);
+
   xfce_rc_close (rc);
 
   return TRUE;
@@ -867,16 +882,11 @@ exo_helper_database_clear_default (ExoHelperDatabase *database,
     }
 
   /* open the mimeapp.list file to set the default handler of the mime type */
-  rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "mimeapps.list", FALSE);
+  rc = mimeapps_open (FALSE);
   if (G_UNLIKELY (rc == NULL))
     {
-      /* deprecated location (glib < 2.41) */
-      rc = xfce_rc_config_open (XFCE_RESOURCE_DATA, "applications/mimeapps.list", FALSE);
-      if (G_UNLIKELY (rc == NULL))
-        {
-          g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_IO, _("Failed to open %s for writing"), "mimeapps.list");
-          return FALSE;
-        }
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_IO, _("Failed to open %s for writing"), "mimeapps.list");
+      return FALSE;
     }
 
   /* open the exo desktop file to read the mimetypes the file supports */
@@ -901,6 +911,8 @@ exo_helper_database_clear_default (ExoHelperDatabase *database,
       xfce_rc_close (desktop_file);
     }
 
+  clear_bad_entries (rc);
+
   xfce_rc_close (rc);
 
   return TRUE;
@@ -908,6 +920,62 @@ exo_helper_database_clear_default (ExoHelperDatabase *database,
 
 
 
+static void
+clear_bad_entry (XfceRc *rc,
+                 gchar  *key,
+                 gchar  *filename)
+{
+  gchar **values;
+
+  if (xfce_rc_has_entry (rc, key))
+    {
+      values = xfce_rc_read_list_entry (rc, key, ";");
+      if (values != NULL)
+        {
+          GSList *list = NULL, *item = NULL;
+          gint i;
+
+          for (i = 0; values[i] != NULL; i++)
+            {
+              if (!exo_str_is_empty(values[i]) && g_strcmp0(values[i], filename) != 0)
+                {
+                  list = g_slist_append (list, g_strdup(values[i]));
+                }
+            }
+          g_strfreev(values);
+
+          if (list == NULL)
+            {
+              xfce_rc_delete_entry (rc, key, FALSE);
+            }
+          else
+            {
+              gchar   *value;
+              GString *string = g_string_new (NULL);
+              for (item = list; item != NULL; item = g_slist_next (item))
+                {
+                  g_string_append_printf (string, "%s;", (gchar *)item->data);
+                }
+              value = g_string_free (string, FALSE);
+              xfce_rc_write_entry (rc, key, value);
+              g_slist_free_full (list, g_free);
+              g_free (value);
+            }
+        }
+    }
+}
+
+
+
+static void
+clear_bad_entries (XfceRc *rc)
+{
+  xfce_rc_set_group (rc, "Added Associations");
+  clear_bad_entry (rc, "x-scheme-handler/file", "exo-file-manager.desktop"); // Xfce #7257
+}
+
+
+
 static gint
 helper_compare (gconstpointer a,
                 gconstpointer b)
@@ -1116,8 +1184,6 @@ exo_helper_database_set_custom (ExoHelperDatabase *database,
 gboolean exo_helper_database_get_dismissed (ExoHelperDatabase *database,
                                             ExoHelperCategory  category)
 {
-  const gchar *value;
-  ExoHelper   *helper = NULL;
   XfceRc      *rc;
   gchar       *key;
   gboolean     dismissed = FALSE;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list