void save_data_from_event_config_dialog(GList *widgets, event_config_t *ec) { dehydrate_config_dialog(widgets); const char *const store_passwords_s = get_user_setting("store_passwords"); save_event_config_data_to_user_storage(ec_get_name(ec), ec, !(store_passwords_s && !strcmp(store_passwords_s, "no"))); }
int ask_yes_no_yesforever(const char *key, const char *question) { INITIALIZE_LIBREPORT(); const char *yes = _("y"); const char *no = _("N"); const char *forever = _("f"); { /* Use response from REPORT_CLIENT_RESPONSE environment variable. * * The forever response is not allowed in this case. * There is no serious reason for that, it is just decision. * (It doesn't make much sense to allow the forever answer here.) */ const char *env_response = getenv("REPORT_CLIENT_RESPONSE"); if (env_response) return strncasecmp(yes, env_response, strlen(yes)) == 0; } { /* Load an value for the key from user setting. * NO means 'Don't ask me again, I said yes forever'. */ const char *option = get_user_setting(key); if (option && string_to_bool(option) == false) return 1; } if (is_slave_mode()) printf(REPORT_PREFIX_ASK_YES_NO_YESFOREVER "%s %s\n", key, question); else printf("%s [%s/%s/%s] ", question, yes, no, forever); fflush(stdout); if (!is_slave_mode() && is_noninteractive_mode()) { putchar('\n'); fflush(stdout); return 0; } char response[16]; if (NULL == fgets(response, sizeof(response), stdin)) return 0; if ((is_slave_mode() && response[0] == 'f') || strncasecmp(forever, response, strlen(forever)) == 0) { /* NO means 'Don't ask me again, I said yes forever'. */ set_user_setting(key, "no"); return 1; } else set_user_setting(key, "yes"); return ((is_slave_mode() && response[0] == 'y') || strncasecmp(yes, response, strlen(yes)) == 0); }
int show_event_config_dialog(const char *event_name, GtkWindow *parent) { event_config_t *event = get_event_config(event_name); GtkWindow *parent_window = parent ? parent : g_event_list_window; GtkWidget *dialog = gtk_dialog_new_with_buttons( /*title:*/ec_get_screen_name(event) ? ec_get_screen_name(event) : event_name, parent_window, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_APPLY, NULL); /* Allow resize? * W/o resize, e.g. upload configuration hint looks awfully * line wrapped. * With resize, there are some somewhat not nice effects: * for one, opening an expander will enlarge window, * but won't contract it back when expander is closed. */ gtk_window_set_resizable(GTK_WINDOW(dialog), true); gtk_window_set_default_size(GTK_WINDOW(dialog), 450, -1); if (parent_window != NULL) { gtk_window_set_icon_name(GTK_WINDOW(dialog), gtk_window_get_icon_name(parent_window)); } GtkWidget *content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); content = cdialog_get_widget(create_event_config_dialog_content(event, content)); gtk_widget_show_all(content); int result = gtk_dialog_run(GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_APPLY) { dehydrate_config_dialog(g_option_list); const char *const store_passwords_s = get_user_setting("store_passwords"); save_event_config_data_to_user_storage(event_name, get_event_config(event_name), !(store_passwords_s && !strcmp(store_passwords_s, "no"))); } //else if (result == GTK_RESPONSE_CANCEL) // log("log"); gtk_widget_destroy(dialog); return result; }
config_dialog_t *create_event_config_dialog_content(event_config_t *event, GtkWidget *content) { if (content == NULL) content = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); //event_config_t *event = get_event_config(event_name); GtkWidget *option_table = gtk_grid_new(); gtk_grid_set_row_homogeneous(GTK_GRID(option_table), FALSE); gtk_grid_set_column_homogeneous(GTK_GRID(option_table), FALSE); gtk_grid_set_row_spacing(GTK_GRID(option_table), 2); g_object_set_data(G_OBJECT(option_table), "n-rows", (gpointer)-1); gtk_widget_set_hexpand(option_table, TRUE); gtk_widget_set_vexpand(option_table, TRUE); gtk_widget_set_halign(option_table, GTK_ALIGN_FILL); gtk_widget_set_valign(option_table, GTK_ALIGN_FILL); /* table to hold advanced options * hidden in expander which is visible only if there's at least * one advanced option */ GtkWidget *adv_option_table = gtk_grid_new(); gtk_grid_set_row_homogeneous(GTK_GRID(adv_option_table), FALSE); gtk_grid_set_column_homogeneous(GTK_GRID(adv_option_table), FALSE); gtk_grid_set_row_spacing(GTK_GRID(adv_option_table), 2); g_object_set_data(G_OBJECT(adv_option_table), "n-rows", (gpointer)-1); GtkWidget *adv_expander = gtk_expander_new(_("Advanced")); gtk_container_add(GTK_CONTAINER(adv_expander), adv_option_table); g_object_set_data(G_OBJECT(option_table), "advanced-options", adv_option_table); has_password_option = false; /* it's already stored in config_dialog_t from the previous call * we need to set it to null so we create a new list for the actual * event_config * note: say *NO* to the global variables! */ g_option_list = NULL; /* this fills the g_option_list, so we can use it for new_config_dialog */ g_list_foreach(event->options, &add_option_to_table, option_table); /* if there is at least one password option, add checkbox to disable storing passwords */ if (has_password_option) { unsigned last_row = add_one_row_to_grid(GTK_GRID(option_table)); GtkWidget *pass_store_cb = gtk_check_button_new_with_label(_("Don't store passwords")); gtk_grid_attach(GTK_GRID(option_table), pass_store_cb, /*left,top:*/ 0, last_row, /*width,height:*/ 1, 1); const char *store_passwords = get_user_setting("store_passwords"); if (store_passwords && !strcmp(store_passwords, "no")) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pass_store_cb), 1); g_signal_connect(pass_store_cb, "toggled", G_CALLBACK(on_show_pass_store_cb), NULL); } gtk_box_pack_start(GTK_BOX(content), option_table, false, false, 20); /* add the adv_option_table to the dialog only if there is some adv option */ if (g_list_length(gtk_container_get_children(GTK_CONTAINER(adv_option_table))) > 0) gtk_box_pack_start(GTK_BOX(content), adv_expander, false, false, 0); /* add warning if secrets service is not available showing the nagging dialog * is considered "too heavy UI" be designers */ if (!is_event_config_user_storage_available()) { GtkWidget *keyring_warn_lbl = gtk_label_new( _("Secret Service is not available, your settings won't be saved!")); static const GdkColor red = { .red = 0xffff }; gtk_widget_modify_fg(keyring_warn_lbl, GTK_STATE_NORMAL, &red); gtk_box_pack_start(GTK_BOX(content), keyring_warn_lbl, false, false, 0); } gtk_widget_show_all(content); //make it all visible //g_option_list is filled on config_dialog_t *cdialog = new_config_dialog(NULL, g_option_list, (config_save_fun_t)save_data_from_event_dialog_name ); return cdialog; }
static int run_ask_yes_no_save_generic_result_dialog(ask_yes_no_dialog_flags flags, const char *key, const char *message, GtkWindow *parent) { INITIALIZE_LIBREPORT(); const char *ask_result = get_user_setting(key); if (ask_result) { const bool ret = string_to_bool(ask_result); if (!(flags & ASK_YES_NO__YESFOREVER)) return ret; /* ASK_YES_NO__YESFOREVER */ if (ret == false) /* Do you want to be asked? -> No, I don't. Do whatever you want */ return true; /* CONTINUE becuase saved value is "yes" and it means 'Ask me!' */ } GtkWidget *dialog = gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", message); /* let's try to use the text as markup * this allows us to use hyperlinks to man pages */ gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), message); /* Follow GTK3's yes-no-buttons order: * [No] [Yes] */ GtkWidget *no_button = gtk_dialog_add_button(GTK_DIALOG(dialog), _("_No"), GTK_RESPONSE_NO); gtk_dialog_add_button(GTK_DIALOG(dialog), _("_Yes"), GTK_RESPONSE_YES); gint response = GTK_RESPONSE_NO; g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(save_dialog_response), &response); 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); 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); } /* Esc -> No, Enter -> Yes */ gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES); gtk_widget_show(ask_yes_no_cb); gtk_dialog_run(GTK_DIALOG(dialog)); 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 (flags & ASK_YES_NO__SAVE_RESULT) { 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"); } else /* should not happen */ error_msg("BUG:%s:%d %s() unknown type (0x%x) of ask_yes_no dialog", __FILE__, __LINE__, __func__, flags); gtk_widget_destroy(dialog); return response == GTK_RESPONSE_YES; }
static const char *get_autoreport_event_name(void) { load_user_settings("abrt-applet"); const char *configured = get_user_setting("AutoreportingEvent"); return configured ? configured : g_settings_autoreporting_event; }