- related to trac#916
Signed-off-by: Jakub Filak jfilak@redhat.com --- src/gtk-helpers/ask_dialogs.c | 67 +++++++++++++++++++++++++------- src/gtk-helpers/internal_libreport_gtk.h | 18 +++++++++ 2 files changed, 70 insertions(+), 15 deletions(-)
diff --git a/src/gtk-helpers/ask_dialogs.c b/src/gtk-helpers/ask_dialogs.c index 7994e1b..43f8f6b 100644 --- a/src/gtk-helpers/ask_dialogs.c +++ b/src/gtk-helpers/ask_dialogs.c @@ -33,18 +33,28 @@ static void on_toggle_ask_yes_no_yesforever_cb(GtkToggleButton *tb, gpointer use gtk_widget_set_sensitive(GTK_WIDGET(user_data), !gtk_toggle_button_get_active(tb)); }
-/* - * Function shows a dialog with 'Yes/No' buttons and a check box allowing to - * remember the answer. The "Don't ask me again" response is stored in - * configuration file under 'key'. - */ -int run_ask_yes_no_yesforever_dialog(const char *key, const char *message, GtkWindow *parent) +/* Reserve 7 bits for configuration of dialog version */ +typedef enum { + ASK_YES_NO_SAVE_RESULT = 0x001, + ASK_YES_NO_YESFOREVER = 0x100, +} ask_yes_no_dialog_flags; + +static int run_ask_yes_no_save_generic_result_dialog(ask_yes_no_dialog_flags flags, + const char *key, + const char *message, + GtkWindow *parent) { const char *ask_result = get_user_setting(key);
- if (ask_result && string_to_bool(ask_result) == false) - /* Do you want to be asked? -> No, I don't. Do whatever you want */ - return true; + if (ask_result) + { + const bool ret = string_to_bool(ask_result); + if (flags & ASK_YES_NO_YESFOREVER && ret == false) + /* Do you want to be asked? -> No, I don't. Do whatever you want */ + return true; + + return ret; + }
GtkWidget *dialog = gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT, @@ -62,20 +72,47 @@ int run_ask_yes_no_yesforever_dialog(const char *key, const char *message, GtkWi 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_yes_no_cb, TRUE, TRUE, 0); - g_signal_connect(ask_yes_no_cb, "toggled", - G_CALLBACK(on_toggle_ask_yes_no_yesforever_cb), (gpointer)no_button);
- /* Don't check the box by default. If the box is checked the 'No' button is disabled and - * we don't want to force users to click on 'Yes' button. */ + if (flags & ASK_YES_NO_YESFOREVER) + { + /* Don't check the box by default. If the box is checked the 'No' + * button is disabled and we don't want to force users to click on + * 'Yes' button. */ + g_signal_connect(ask_yes_no_cb, "toggled", + G_CALLBACK(on_toggle_ask_yes_no_yesforever_cb), (gpointer)no_button); + }
gtk_widget_show(ask_yes_no_cb); gtk_dialog_run(GTK_DIALOG(dialog));
- /* the box is checked -> Don't ask me again and my response is always 'Yes' */ - set_user_setting(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ask_yes_no_cb)) ? "no" : "yes"); + if (flags & ASK_YES_NO_YESFOREVER) + /* the box is checked -> Don't ask me again and my response is always 'Yes' */ + set_user_setting(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ask_yes_no_cb)) ? "no" : "yes"); + else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ask_yes_no_cb))) + /* the box is checked -> remember my current answer */ + set_user_setting(key, response == GTK_RESPONSE_YES ? "yes" : "no");
gtk_widget_destroy(dialog);
return response == GTK_RESPONSE_YES; }
+/* + * Function shows a dialog with 'Yes/No' buttons and a check box allowing to + * remember the answer. The "Don't ask me again" response is stored in + * configuration file under 'key'. + */ +int run_ask_yes_no_yesforever_dialog(const char *key, const char *message, GtkWindow *parent) +{ + return run_ask_yes_no_save_generic_result_dialog(ASK_YES_NO_YESFOREVER, key, message, parent); +} + +/* + * Function runs a dialog with 'Yes/No' buttons and a check box allowing to + * remember the answer. The answer is stored in configuration file under + * 'key'. + */ +int run_ask_yes_no_save_result_dialog(const char *key, const char *message, GtkWindow *parent) +{ + return run_ask_yes_no_save_generic_result_dialog(ASK_YES_NO_SAVE_RESULT, key, message, parent); +} diff --git a/src/gtk-helpers/internal_libreport_gtk.h b/src/gtk-helpers/internal_libreport_gtk.h index cecad6f..ea94837 100644 --- a/src/gtk-helpers/internal_libreport_gtk.h +++ b/src/gtk-helpers/internal_libreport_gtk.h @@ -115,6 +115,24 @@ GList *find_url_tokens(const char *line); #define run_ask_yes_no_yesforever_dialog libreport_run_ask_yes_no_yesforever_dialog int run_ask_yes_no_yesforever_dialog(const char *key, const char *message, GtkWindow *parent);
+/* + * Runs a dialog with 'Yes'/'No' buttons and 'Don't ask me again' check box and + * waits until the dialog is closed. This variant of dialog allows user to + * click both of buttons if the check box is checked and stores a string which + * corresponds to an answer. + * + * Uses libreport's user settings. Don't forget to call load_user_settings() + * before the first call of this funcion and call save_user_settings() after + * the last call of this function. + * + * @param key Key under which the response is stored. Not NULL + * @param message Displayed message. Not NULL + * @param parent Transient parent or NULL + * @returns Non 0 if the answer is "Yes"; otherwise 0 + */ +#define run_ask_yes_no_save_result_dialog libreport_run_ask_yes_no_save_result_dialog +int run_ask_yes_no_save_result_dialog(const char *key, const char *message, GtkWindow *parent); + #ifdef __cplusplus } #endif