[Xfce4-commits] [xfce/exo] 01/01: Enable dismissing 'Failed to open default' errors, reenabled after switching defaults
noreply at xfce.org
noreply at xfce.org
Sat May 25 15:24:27 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 19ef743040f6501524b33d2b6d07c868f53cb220
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Sat May 25 09:24:18 2019 -0400
Enable dismissing 'Failed to open default' errors, reenabled after switching defaults
---
exo-helper/exo-helper.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++
exo-helper/exo-helper.h | 5 +++
exo-helper/main.c | 76 ++++++++++++++++++++++++++++++++++++++------
3 files changed, 155 insertions(+), 10 deletions(-)
diff --git a/exo-helper/exo-helper.c b/exo-helper/exo-helper.c
index 9659041..13eef5d 100644
--- a/exo-helper/exo-helper.c
+++ b/exo-helper/exo-helper.c
@@ -723,6 +723,11 @@ exo_helper_database_set_default (ExoHelperDatabase *database,
/* save the new setting */
key = exo_helper_category_to_string (category);
xfce_rc_write_entry (rc, key, exo_helper_get_id (helper));
+ g_free (key);
+
+ /* clear the dismissed preference */
+ key = g_strconcat (exo_helper_category_to_string (category), "Dismissed", NULL);
+ xfce_rc_delete_entry (rc, key, FALSE);
xfce_rc_close (rc);
g_free (key);
@@ -828,6 +833,11 @@ exo_helper_database_clear_default (ExoHelperDatabase *database,
/* save the new setting */
key = exo_helper_category_to_string (category);
xfce_rc_delete_entry (rc, key, FALSE);
+ g_free (key);
+
+ /* clear the dismissed preference */
+ key = g_strconcat (exo_helper_category_to_string (category), "Dismissed", NULL);
+ xfce_rc_delete_entry (rc, key, FALSE);
xfce_rc_close (rc);
g_free (key);
@@ -1087,3 +1097,77 @@ exo_helper_database_set_custom (ExoHelperDatabase *database,
g_free (category_string);
g_free (file);
}
+
+/**
+ * exo_helper_database_get_dismissed:
+ * @database : an #ExoHelperDatabase.
+ * @category : an #ExoHelperCategory.
+ *
+ * Returns %TRUE if errors should no longer be displayed
+ * on the default #ExoHelper for the @category in @database.
+ *
+ * Return value: %TRUE if dismissed, %FALSE otherwise.
+ **/
+gboolean exo_helper_database_get_dismissed (ExoHelperDatabase *database,
+ ExoHelperCategory category)
+{
+ const gchar *value;
+ ExoHelper *helper = NULL;
+ XfceRc *rc;
+ gchar *key;
+ gboolean dismissed = FALSE;
+
+ g_return_val_if_fail (EXO_IS_HELPER_DATABASE (database), FALSE);
+ g_return_val_if_fail (category < EXO_HELPER_N_CATEGORIES, FALSE);
+
+ rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/helpers.rc", TRUE);
+ if (G_LIKELY (rc != NULL))
+ {
+ key = g_strconcat (exo_helper_category_to_string (category), "Dismissed", NULL);
+ dismissed = xfce_rc_read_bool_entry (rc, key, FALSE);
+ xfce_rc_close (rc);
+ g_free (key);
+ }
+
+ return dismissed;
+}
+
+/**
+ * exo_helper_database_set_dismissed:
+ * @database : an #ExoHelperDatabase.
+ * @category : an #ExoHelperCategory.
+ * @dismissed : TRUE if the errr should no longer be displayed.
+ * @error : return location for errors or %NULL.
+ *
+ * Dismisses future errors related to the selected helper category.
+ * This setting is cleared any time a new default is configured.
+ * Returns %TRUE on success, %FALSE if @error is set.
+ *
+ * Return value: %TRUE on success, %FALSE if @error is set.
+ **/
+gboolean
+exo_helper_database_set_dismissed (ExoHelperDatabase *database,
+ ExoHelperCategory category,
+ gboolean dismissed)
+{
+ XfceRc *rc;
+ gchar *key;
+
+ g_return_val_if_fail (category < EXO_HELPER_N_CATEGORIES, FALSE);
+ g_return_val_if_fail (EXO_IS_HELPER_DATABASE (database), FALSE);
+
+ /* open the helpers.rc for writing */
+ rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/helpers.rc", FALSE);
+ if (G_UNLIKELY (rc == NULL))
+ {
+ return FALSE;
+ }
+
+ /* save the new setting */
+ key = g_strconcat (exo_helper_category_to_string (category), "Dismissed", NULL);
+ xfce_rc_write_bool_entry (rc, key, dismissed);
+ xfce_rc_close (rc);
+ g_free (key);
+
+ return TRUE;
+}
diff --git a/exo-helper/exo-helper.h b/exo-helper/exo-helper.h
index b4e0bc6..fa74432 100644
--- a/exo-helper/exo-helper.h
+++ b/exo-helper/exo-helper.h
@@ -82,6 +82,11 @@ ExoHelper *exo_helper_database_get_custom (ExoHelperDatabase *data
void exo_helper_database_set_custom (ExoHelperDatabase *database,
ExoHelperCategory category,
const gchar *command);
+gboolean exo_helper_database_get_dismissed (ExoHelperDatabase *database,
+ ExoHelperCategory category);
+gboolean exo_helper_database_set_dismissed (ExoHelperDatabase *database,
+ ExoHelperCategory category,
+ gboolean dismissed);
G_END_DECLS
diff --git a/exo-helper/main.c b/exo-helper/main.c
index 13831c3..69b0d28 100644
--- a/exo-helper/main.c
+++ b/exo-helper/main.c
@@ -47,6 +47,55 @@ static const gchar *CATEGORY_EXEC_ERRORS[] =
+static void
+error_dialog_dismiss_toggled (GtkToggleButton *button,
+ gboolean *return_value)
+{
+ *return_value = gtk_toggle_button_get_active (button);
+}
+
+
+
+static GtkWidget *
+get_helper_error_dialog (ExoHelperCategory category,
+ GError *error,
+ gboolean *return_value)
+{
+ GtkWidget *dialog;
+ GtkWidget *message_area;
+ GtkWidget *check_button;
+ GList *children;
+
+ dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "%s.", _(CATEGORY_EXEC_ERRORS[category]));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
+
+ /* Clear excess padding */
+ children = gtk_container_get_children (GTK_CONTAINER (dialog));
+ gtk_box_set_spacing (GTK_BOX (g_list_nth_data (children, 0)), 0);
+ g_list_free (children);
+
+ message_area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
+
+ /* Align labels left */
+ children = gtk_container_get_children (GTK_CONTAINER (message_area));
+ gtk_widget_set_halign (GTK_WIDGET (g_list_nth_data (children, 0)), GTK_ALIGN_START);
+ gtk_widget_set_halign (GTK_WIDGET (g_list_nth_data (children, 1)), GTK_ALIGN_START);
+ g_list_free (children);
+
+ /* Enable permanently dismissing this error. */
+ check_button = gtk_check_button_new_with_mnemonic (_("Do _not show this message again"));
+ gtk_box_pack_end (GTK_BOX (message_area), check_button, FALSE, FALSE, 0);
+ gtk_widget_set_margin_top (check_button, 12);
+ gtk_widget_show (check_button);
+
+ g_signal_connect (G_OBJECT (check_button), "toggled", G_CALLBACK (error_dialog_dismiss_toggled), return_value);
+
+ return dialog;
+}
+
+
+
int
main (int argc, char **argv)
{
@@ -198,27 +247,34 @@ main (int argc, char **argv)
gtk_main_iteration ();
}
- /* release our reference on the database */
- g_object_unref (G_OBJECT (database));
-
/* check if we have a valid helper now */
if (G_LIKELY (helper != NULL))
{
/* try to execute the helper with the given parameter */
if (!exo_helper_execute (helper, NULL, (argc > 1) ? argv[1] : NULL, &error))
{
- dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
- "%s.", _(CATEGORY_EXEC_ERRORS[category]));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
- if (startup_id != NULL)
- gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
+ if (!exo_helper_database_get_dismissed (database, category))
+ {
+ gboolean dismissed = FALSE;
+ dialog = get_helper_error_dialog (category, error, &dismissed);
+ if (startup_id != NULL)
+ gtk_window_set_startup_id (GTK_WINDOW (dialog), startup_id);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ if (dismissed)
+ {
+ exo_helper_database_set_dismissed (database, category, dismissed);
+ }
+ }
g_error_free (error);
result = EXIT_FAILURE;
}
g_object_unref (G_OBJECT (helper));
}
+
+ /* release our reference on the database */
+ g_object_unref(G_OBJECT(database));
}
else if (opt_version == TRUE)
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list