104 lines
4.3 KiB
Diff
104 lines
4.3 KiB
Diff
|
From 58b2f3df81c46f8596a0a81bd2f8071948ec9238 Mon Sep 17 00:00:00 2001
|
||
|
From: Jakub Filak <jfilak@redhat.com>
|
||
|
Date: Wed, 8 Aug 2012 16:59:33 +0200
|
||
|
Subject: [PATCH 06/10] trac#660: report-gtk: introduce generic ask_yes_no()
|
||
|
function for options
|
||
|
|
||
|
* the generic ask_yes_no() function shows a standard 'yes/no' dialog
|
||
|
with a checkbox
|
||
|
* if user checks the checkbox the ask_yes_no() function immediately
|
||
|
returns 'yes' in the future calls
|
||
|
|
||
|
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
||
|
---
|
||
|
src/gui-wizard-gtk/wizard.c | 52 ++++++++++++++++++++++++++++-----------------
|
||
|
1 file changed, 33 insertions(+), 19 deletions(-)
|
||
|
|
||
|
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
|
||
|
index ce7b742..861d922 100644
|
||
|
--- a/src/gui-wizard-gtk/wizard.c
|
||
|
+++ b/src/gui-wizard-gtk/wizard.c
|
||
|
@@ -310,46 +310,60 @@ static void update_window_title(void)
|
||
|
free(title);
|
||
|
}
|
||
|
|
||
|
-static void on_toggle_ask_steal_cb(GtkToggleButton *tb, gpointer user_data)
|
||
|
+static void on_toggle_ask_yes_no_save_result_cb(GtkToggleButton *tb, gpointer user_data)
|
||
|
{
|
||
|
- set_user_setting("ask_steal_dir", gtk_toggle_button_get_active(tb) ? "no" : "yes");
|
||
|
+ set_user_setting(user_data, gtk_toggle_button_get_active(tb) ? "no" : "yes");
|
||
|
}
|
||
|
|
||
|
-static bool ask_continue_before_steal(const char *base_dir, const char *dump_dir)
|
||
|
+/*
|
||
|
+ * Function shows a dialog with 'Yes/No' buttons and a check box allowing to
|
||
|
+ * remeber the answer. The answer is stored in configuration file under
|
||
|
+ * 'option_name' key.
|
||
|
+ */
|
||
|
+static bool ask_yes_no_save_result(const char *message, const char *option_name)
|
||
|
{
|
||
|
- const char *ask_steal_dir = get_user_setting("ask_steal_dir");
|
||
|
+ const char *ask_result = get_user_setting(option_name);
|
||
|
|
||
|
- if (ask_steal_dir && string_to_bool(ask_steal_dir) == false)
|
||
|
+ if (ask_result && string_to_bool(ask_result) == false)
|
||
|
return true;
|
||
|
|
||
|
GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(g_wnd_assistant),
|
||
|
- GTK_DIALOG_DESTROY_WITH_PARENT,
|
||
|
- GTK_MESSAGE_QUESTION,
|
||
|
- GTK_BUTTONS_OK_CANCEL,
|
||
|
- _("Need writable directory, but '%s' is not writable."
|
||
|
- " Move it to '%s' and operate on the moved data?"),
|
||
|
- dump_dir, base_dir
|
||
|
- );
|
||
|
+ GTK_DIALOG_DESTROY_WITH_PARENT,
|
||
|
+ GTK_MESSAGE_QUESTION,
|
||
|
+ GTK_BUTTONS_YES_NO,
|
||
|
+ "%s", message);
|
||
|
|
||
|
gint response = GTK_RESPONSE_CANCEL;
|
||
|
- g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(save_dialog_response), &response);
|
||
|
+ g_signal_connect(G_OBJECT(dialog), "response",
|
||
|
+ G_CALLBACK(save_dialog_response), &response);
|
||
|
|
||
|
- GtkWidget *ask_steal_cb = gtk_check_button_new_with_label(_("Don't ask me again"));
|
||
|
+ GtkWidget *ask_yes_no_cb = gtk_check_button_new_with_label(_("Don't ask me again"));
|
||
|
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
|
||
|
- ask_steal_cb, TRUE, TRUE, 0);
|
||
|
- g_signal_connect(ask_steal_cb, "toggled", G_CALLBACK(on_toggle_ask_steal_cb), NULL);
|
||
|
+ ask_yes_no_cb, TRUE, TRUE, 0);
|
||
|
+ g_signal_connect(ask_yes_no_cb, "toggled",
|
||
|
+ G_CALLBACK(on_toggle_ask_yes_no_save_result_cb), (gpointer)option_name);
|
||
|
|
||
|
/* check it by default if it's shown for the first time */
|
||
|
- if (!ask_steal_dir)
|
||
|
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ask_steal_cb), TRUE);
|
||
|
+ if (!ask_result)
|
||
|
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ask_yes_no_cb), TRUE);
|
||
|
|
||
|
- gtk_widget_show(ask_steal_cb);
|
||
|
+ gtk_widget_show(ask_yes_no_cb);
|
||
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
||
|
gtk_widget_destroy(dialog);
|
||
|
|
||
|
return response == GTK_RESPONSE_OK;
|
||
|
}
|
||
|
|
||
|
+static bool ask_continue_before_steal(const char *base_dir, const char *dump_dir)
|
||
|
+{
|
||
|
+ char *msg = xasprintf(_("Need writable directory, but '%s' is not writable."
|
||
|
+ " Move it to '%s' and operate on the moved data?"),
|
||
|
+ dump_dir, base_dir);
|
||
|
+ const bool response = ask_yes_no_save_result(msg, "ask_steal_dir");
|
||
|
+ free(msg);
|
||
|
+ return response;
|
||
|
+}
|
||
|
+
|
||
|
struct dump_dir *wizard_open_directory_for_writing(const char *dump_dir_name)
|
||
|
{
|
||
|
struct dump_dir *dd = open_directory_for_writing(dump_dir_name,
|
||
|
--
|
||
|
1.7.11.2
|
||
|
|