[Xfce4-commits] [xfce/exo] 01/02: Add new exo_helper_database_clear_default, discard preferred application if dialog is canceled (Bug #8802)
noreply at xfce.org
noreply at xfce.org
Fri Jun 16 04:26:00 CEST 2017
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 1c64787b0c25f18b924de6a98423e76a3a9ac772
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Thu Jun 15 22:24:36 2017 -0400
Add new exo_helper_database_clear_default, discard preferred application if dialog is canceled (Bug #8802)
---
exo-helper/exo-helper.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++
exo-helper/exo-helper.h | 3 ++
exo-helper/main.c | 2 +
3 files changed, 110 insertions(+)
diff --git a/exo-helper/exo-helper.c b/exo-helper/exo-helper.c
index 14c941d..ad3561a 100644
--- a/exo-helper/exo-helper.c
+++ b/exo-helper/exo-helper.c
@@ -774,6 +774,111 @@ exo_helper_database_set_default (ExoHelperDatabase *database,
+/**
+ * exo_helper_database_clear_default:
+ * @database : an #ExoHelperDatabase.
+ * @category : an #ExoHelperCategory.
+ * @error : return location for errors or %NULL.
+ *
+ * Clears the default #ExoHelper for @category in @database.
+ * Returns %TRUE on success, %FALSE if @error is set.
+ *
+ * Return value: %TRUE on success, %FALSE if @error is set.
+ *
+ * Since: 0.11.3
+ **/
+gboolean
+exo_helper_database_clear_default (ExoHelperDatabase *database,
+ ExoHelperCategory category,
+ GError **error)
+{
+ XfceRc *rc, *desktop_file;
+ gchar *key;
+ const gchar *filename;
+ gchar **mimetypes;
+ guint i;
+ gchar *path;
+
+ g_return_val_if_fail (category < EXO_HELPER_N_CATEGORIES, FALSE);
+ g_return_val_if_fail (EXO_IS_HELPER_DATABASE (database), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ /* open the helpers.rc for writing */
+ rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/helpers.rc", FALSE);
+ if (G_UNLIKELY (rc == NULL))
+ {
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_IO, _("Failed to open %s for writing"), "helpers.rc");
+ return FALSE;
+ }
+
+ /* save the new setting */
+ key = exo_helper_category_to_string (category);
+ xfce_rc_delete_entry (rc, key, FALSE);
+ xfce_rc_close (rc);
+ g_free (key);
+
+ /* get the desktop filename */
+ switch (category)
+ {
+ case EXO_HELPER_WEBBROWSER:
+ filename = "exo-web-browser.desktop";
+ break;
+
+ case EXO_HELPER_MAILREADER:
+ filename = "exo-mail-reader.desktop";
+ break;
+
+ case EXO_HELPER_FILEMANAGER:
+ filename = "exo-file-manager.desktop";
+ break;
+
+ default:
+ /* no mimetype support for terminals */
+ return TRUE;
+ }
+
+ /* 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);
+ 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;
+ }
+ }
+
+ /* open the exo desktop file to read the mimetypes the file supports */
+ path = g_build_filename ("applications", filename, NULL);
+ desktop_file = xfce_rc_config_open (XFCE_RESOURCE_DATA, path, TRUE);
+ g_free (path);
+
+ if (G_UNLIKELY (desktop_file != NULL))
+ {
+ xfce_rc_set_group (desktop_file, "Desktop Entry");
+ mimetypes = xfce_rc_read_list_entry (desktop_file, "X-XFCE-MimeType", ";");
+ if (mimetypes != NULL)
+ {
+ xfce_rc_set_group (rc, "Added Associations");
+
+ for (i = 0; mimetypes[i] != NULL; i++)
+ if (!exo_str_is_empty (mimetypes[i]))
+ xfce_rc_delete_entry (rc, mimetypes[i], FALSE);
+ g_strfreev (mimetypes);
+ }
+
+ xfce_rc_close (desktop_file);
+ }
+
+ xfce_rc_close (rc);
+
+ return TRUE;
+}
+
+
+
static gint
helper_compare (gconstpointer a,
gconstpointer b)
diff --git a/exo-helper/exo-helper.h b/exo-helper/exo-helper.h
index ba32728..b4e0bc6 100644
--- a/exo-helper/exo-helper.h
+++ b/exo-helper/exo-helper.h
@@ -72,6 +72,9 @@ gboolean exo_helper_database_set_default (ExoHelperDatabase *data
ExoHelperCategory category,
ExoHelper *helper,
GError **error);
+gboolean exo_helper_database_clear_default (ExoHelperDatabase *database,
+ ExoHelperCategory category,
+ GError **error);
GList *exo_helper_database_get_all (ExoHelperDatabase *database,
ExoHelperCategory category);
ExoHelper *exo_helper_database_get_custom (ExoHelperDatabase *database,
diff --git a/exo-helper/main.c b/exo-helper/main.c
index 94a4605..8f69b68 100644
--- a/exo-helper/main.c
+++ b/exo-helper/main.c
@@ -186,6 +186,8 @@ main (int argc, char **argv)
gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
helper = exo_helper_database_get_default (database, category);
+ else
+ exo_helper_database_clear_default (database, category, NULL);
gtk_widget_destroy (dialog);
/* iterate the mainloop until the dialog is fully destroyed */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list