aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-11-23 02:43:00 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-11-23 02:50:55 +0100
commit9ac9fe914f2f9535154bd5785b9ea401365e14d6 (patch)
treea6a65dbaf401c7e365f056ea755b98b8526ab8b9
parent1619b4656c1e7810e06ff12af087bc04d2e47a5c (diff)
downloadsensei-raw-ctl-9ac9fe914f2f9535154bd5785b9ea401365e14d6.tar.gz
sensei-raw-ctl-9ac9fe914f2f9535154bd5785b9ea401365e14d6.tar.xz
sensei-raw-ctl-9ac9fe914f2f9535154bd5785b9ea401365e14d6.zip
Allow retrying on errors
The GUI code stinks and it's not really worth my time.
-rw-r--r--sensei-raw-ctl-gui.c69
1 files changed, 44 insertions, 25 deletions
diff --git a/sensei-raw-ctl-gui.c b/sensei-raw-ctl-gui.c
index 146e051..6c4ee99 100644
--- a/sensei-raw-ctl-gui.c
+++ b/sensei-raw-ctl-gui.c
@@ -64,17 +64,22 @@ enum
// ----- User interface -------------------------------------------------------
-static void
-fatal (GtkWidget *parent, const gchar *message)
+static gboolean
+user_wants_to_retry_critical_op (GtkWidget *parent, const gchar *message)
{
GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Fatal error"));
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_NONE, _("Error"));
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ _("_Retry"), TRUE, _("_Close"), FALSE, NULL);
gtk_message_dialog_format_secondary_text
(GTK_MESSAGE_DIALOG (dialog), "%s", message);
- gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gboolean success = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
- gtk_main_quit ();
+ if (!success)
+ gtk_main_quit ();
+ return success;
}
static void
@@ -88,29 +93,37 @@ set_page (GtkBuilder *builder, gint page)
static gboolean
spawn_ctl (gchar **argv, gchar **out, GtkBuilder *builder)
{
- GError *error = NULL;
- gint status;
- gchar *err;
-
GtkWidget *win = GTK_WIDGET (gtk_builder_get_object (builder, "win"));
- if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
- out, &err, &status, &error))
+ gboolean trying = TRUE;
+ while (trying)
{
- fatal (win, error->message);
- g_error_free (error);
- return FALSE;
- }
+ GError *error = NULL;
+ gchar *err = NULL;
+ gint status;
+
+ if (!g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
+ out, &err, &status, &error))
+ {
+ trying = user_wants_to_retry_critical_op (win, error->message);
+ g_error_free (error);
+ continue;
+ }
- if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
- return TRUE;
+ if (WIFEXITED (status) && WEXITSTATUS (status) == 0)
+ {
+ g_free (err);
+ return TRUE;
+ }
- if (strstr (err, "no suitable device"))
- set_page (builder, PAGE_NO_DEVICE);
- else
- fatal (win, err);
+ trying = FALSE;
+ if (strstr (err, "no suitable device"))
+ set_page (builder, PAGE_NO_DEVICE);
+ else
+ trying = user_wants_to_retry_critical_op (win, err);
- g_clear_pointer (out, g_free);
- g_free (err);
+ g_clear_pointer (out, g_free);
+ g_free (err);
+ }
return FALSE;
}
@@ -199,8 +212,14 @@ out:
g_free (out);
if (line != OUT_COUNT)
- fatal (GTK_WIDGET (gtk_builder_get_object (builder, "win")),
- _("Internal error"));
+ {
+ GtkWidget *dialog = gtk_message_dialog_new (
+ GTK_WINDOW (gtk_builder_get_object (builder, "win")),
+ GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE, _("Internal error: backend mismatch"));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
}
static void