159 lines
5.9 KiB
Diff
159 lines
5.9 KiB
Diff
|
From c134783d5c9fc8ba6691408ce9b3015ab368ad16 Mon Sep 17 00:00:00 2001
|
||
|
From: Jakub Filak <jfilak@redhat.com>
|
||
|
Date: Tue, 29 Apr 2014 09:49:23 +0200
|
||
|
Subject: [LIBREPORT PATCH 08/10] refactoring: unify event configuration
|
||
|
dialogs
|
||
|
|
||
|
Related to #259
|
||
|
|
||
|
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
||
|
---
|
||
|
src/gtk-helpers/config_dialog.c | 40 ++++++++++++++-----------
|
||
|
src/gtk-helpers/event_config_dialog.c | 51 +++-----------------------------
|
||
|
src/gtk-helpers/internal_libreport_gtk.h | 1 +
|
||
|
3 files changed, 28 insertions(+), 64 deletions(-)
|
||
|
|
||
|
diff --git a/src/gtk-helpers/config_dialog.c b/src/gtk-helpers/config_dialog.c
|
||
|
index 6cc4be9..6de08e3 100644
|
||
|
--- a/src/gtk-helpers/config_dialog.c
|
||
|
+++ b/src/gtk-helpers/config_dialog.c
|
||
|
@@ -83,6 +83,28 @@ gpointer cdialog_get_data(config_dialog_t *cdialog)
|
||
|
return cdialog->data;
|
||
|
}
|
||
|
|
||
|
+int cdialog_run(config_dialog_t *cdialog, const char *name)
|
||
|
+{
|
||
|
+ if (cdialog == NULL || cdialog->dialog == NULL)
|
||
|
+ {
|
||
|
+ log("There is no configurable option for: '%s'", name);
|
||
|
+ return GTK_RESPONSE_REJECT;
|
||
|
+ }
|
||
|
+
|
||
|
+ const int result = gtk_dialog_run(GTK_DIALOG(cdialog->dialog));
|
||
|
+ if (result == GTK_RESPONSE_APPLY)
|
||
|
+ {
|
||
|
+ if (cdialog->save_data)
|
||
|
+ cdialog->save_data(cdialog->data, name);
|
||
|
+ }
|
||
|
+ else if (result == GTK_RESPONSE_CANCEL)
|
||
|
+ log_notice("Cancelling on user request");
|
||
|
+
|
||
|
+ gtk_widget_hide(GTK_WIDGET(cdialog->dialog));
|
||
|
+
|
||
|
+ return result;
|
||
|
+}
|
||
|
+
|
||
|
static const void *get_column_value_from_row(GtkTreeView *treeview, int column, int type)
|
||
|
{
|
||
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||
|
@@ -246,23 +268,7 @@ static void on_configure_cb(GtkWidget *btn, gpointer user_data)
|
||
|
config_dialog_t *cdialog = (config_dialog_t *)get_column_value_from_row(tv, CONFIG_DIALOG, TYPE_POINTER);
|
||
|
const char *name = (const char *)get_column_value_from_row(tv, COLUMN_NAME, TYPE_STR);
|
||
|
|
||
|
-
|
||
|
- if (cdialog == NULL || cdialog->dialog == NULL)
|
||
|
- {
|
||
|
- log("There is no configurable option for: '%s'", name);
|
||
|
- return;
|
||
|
- }
|
||
|
-
|
||
|
- int result = gtk_dialog_run(GTK_DIALOG(cdialog->dialog));
|
||
|
- if (result == GTK_RESPONSE_APPLY)
|
||
|
- {
|
||
|
- if (cdialog->save_data)
|
||
|
- cdialog->save_data(cdialog->data, name);
|
||
|
- }
|
||
|
- else if (result == GTK_RESPONSE_CANCEL)
|
||
|
- log_notice("Cancelling on user request");
|
||
|
-
|
||
|
- gtk_widget_hide(GTK_WIDGET(cdialog->dialog));
|
||
|
+ cdialog_run(cdialog, name);
|
||
|
}
|
||
|
|
||
|
static void on_close_cb(GtkWidget *btn, gpointer config_list_w)
|
||
|
diff --git a/src/gtk-helpers/event_config_dialog.c b/src/gtk-helpers/event_config_dialog.c
|
||
|
index ff3e38b..655abb6 100644
|
||
|
--- a/src/gtk-helpers/event_config_dialog.c
|
||
|
+++ b/src/gtk-helpers/event_config_dialog.c
|
||
|
@@ -319,7 +319,7 @@ config_dialog_t *create_event_config_dialog(const char *event_name, GtkWindow *p
|
||
|
if (parent_window != NULL)
|
||
|
{
|
||
|
gtk_window_set_icon_name(GTK_WINDOW(dialog),
|
||
|
- gtk_window_get_icon_name(parent_window));
|
||
|
+ gtk_window_get_icon_name(parent_window));
|
||
|
}
|
||
|
|
||
|
GtkWidget *content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||
|
@@ -349,53 +349,10 @@ int show_event_config_dialog(const char *event_name, GtkWindow *parent)
|
||
|
{
|
||
|
INITIALIZE_LIBREPORT();
|
||
|
|
||
|
- 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,
|
||
|
- _("_Cancel"),
|
||
|
- GTK_RESPONSE_CANCEL,
|
||
|
- _("_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);
|
||
|
+ config_dialog_t *dialog = create_event_config_dialog(event_name, parent);
|
||
|
+ const int result = cdialog_run(dialog, event_name);
|
||
|
+ free(dialog);
|
||
|
|
||
|
- 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;
|
||
|
}
|
||
|
|
||
|
diff --git a/src/gtk-helpers/internal_libreport_gtk.h b/src/gtk-helpers/internal_libreport_gtk.h
|
||
|
index dc1ef31..f8f1c13 100644
|
||
|
--- a/src/gtk-helpers/internal_libreport_gtk.h
|
||
|
+++ b/src/gtk-helpers/internal_libreport_gtk.h
|
||
|
@@ -80,6 +80,7 @@ void load_workflow_config_data_from_user_storage(GHashTable *workflows);
|
||
|
void cdialog_set_widget(config_dialog_t *cdialog, GtkWidget *widget);
|
||
|
GtkWidget *cdialog_get_widget(config_dialog_t *cdialog);
|
||
|
gpointer cdialog_get_data(config_dialog_t *cdialog);
|
||
|
+int cdialog_run(config_dialog_t *cdialog, const char *name);
|
||
|
|
||
|
void dehydrate_config_dialog(GList *option_widgets);
|
||
|
|
||
|
--
|
||
|
1.8.3.1
|
||
|
|