From c0931b8a091e10fa6f89625c84f6da453e8fc4d0 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Wed, 10 Dec 2014 07:02:00 +0100
Subject: [LIBREPORT PATCH 120/120] gui: support Enter & 2Click in Preferences
list
Related to rhbz#1067123
Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
src/gtk-helpers/config_dialog.c | 81 ++++++++++++++++++++++++--------
src/gtk-helpers/event_config_dialog.c | 51 ++------------------
src/gtk-helpers/internal_libreport_gtk.h | 1 +
3 files changed, 66 insertions(+), 67 deletions(-)
diff --git a/src/gtk-helpers/config_dialog.c b/src/gtk-helpers/config_dialog.c
index c80dc56..b5835de 100644
--- a/src/gtk-helpers/config_dialog.c
+++ b/src/gtk-helpers/config_dialog.c
@@ -18,6 +18,7 @@
*/
#include <gtk/gtk.h>
+#include <gdk/gdk.h>
#include "internal_libreport_gtk.h"
enum
@@ -83,6 +84,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);
@@ -184,6 +207,40 @@ static gboolean config_filter_func(GtkTreeModel *model,
return visible;
}
+static void open_config_for_selected_row(GtkTreeView *tv)
+{
+ 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);
+
+ cdialog_run(cdialog, name);
+}
+
+static gboolean on_key_press_event_cb(GtkWidget *btn, GdkEvent *event, gpointer user_data)
+{
+ GdkEventKey *ek = (GdkEventKey *)event;
+
+ if (ek->keyval == GDK_KEY_Return)
+ {
+ GtkTreeView *tv = (GtkTreeView *)user_data;
+ open_config_for_selected_row(tv);
+ }
+
+ return FALSE;
+}
+
+static gboolean on_button_press_event_cb(GtkWidget *btn, GdkEvent *event, gpointer user_data)
+{
+ GdkEventButton *eb = (GdkEventButton *)event;
+
+ if (eb->type == GDK_2BUTTON_PRESS)
+ {
+ GtkTreeView *tv = (GtkTreeView *)user_data;
+ open_config_for_selected_row(tv);
+ }
+
+ return FALSE;
+}
+
GtkWidget *create_config_tab_content(const char *column_label,
GtkListStore *store)
{
@@ -194,6 +251,9 @@ GtkWidget *create_config_tab_content(const char *column_label,
GTK_POLICY_AUTOMATIC);
/* workflow list treeview */
GtkWidget *tv = gtk_tree_view_new();
+ g_signal_connect(tv, "key-press-event", G_CALLBACK(on_key_press_event_cb), tv);
+ g_signal_connect(tv, "button-press-event", G_CALLBACK(on_button_press_event_cb), tv);
+
/* column with workflow name and description */
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
@@ -243,27 +303,8 @@ static void on_configure_cb(GtkWidget *btn, gpointer user_data)
GtkWidget *vbox = gtk_notebook_get_nth_page(nb, current_page_n);
GList *children = gtk_container_get_children(GTK_CONTAINER(vbox));
GtkScrolledWindow *sw = (GtkScrolledWindow *)children->data;
- GtkTreeView *tv = (GtkTreeView *)gtk_bin_get_child(GTK_BIN(sw));
- 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));
+ open_config_for_selected_row((GtkTreeView *)gtk_bin_get_child(GTK_BIN(sw)));
}
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 659f563..402f6f2 100644
--- a/src/gtk-helpers/event_config_dialog.c
+++ b/src/gtk-helpers/event_config_dialog.c
@@ -337,7 +337,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));
@@ -367,53 +367,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;
+ config_dialog_t *dialog = create_event_config_dialog(event_name, parent);
+ const int result = cdialog_run(dialog, event_name);
+ free(dialog);
- 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);
-
- 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