Blame SOURCES/0120-gui-support-Enter-2Click-in-Preferences-list.patch

4b6aa8
From c0931b8a091e10fa6f89625c84f6da453e8fc4d0 Mon Sep 17 00:00:00 2001
4b6aa8
From: Jakub Filak <jfilak@redhat.com>
4b6aa8
Date: Wed, 10 Dec 2014 07:02:00 +0100
4b6aa8
Subject: [LIBREPORT PATCH 120/120] gui: support Enter & 2Click in Preferences
4b6aa8
 list
4b6aa8
4b6aa8
Related to rhbz#1067123
4b6aa8
4b6aa8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
4b6aa8
---
4b6aa8
 src/gtk-helpers/config_dialog.c          | 81 ++++++++++++++++++++++++--------
4b6aa8
 src/gtk-helpers/event_config_dialog.c    | 51 ++------------------
4b6aa8
 src/gtk-helpers/internal_libreport_gtk.h |  1 +
4b6aa8
 3 files changed, 66 insertions(+), 67 deletions(-)
4b6aa8
4b6aa8
diff --git a/src/gtk-helpers/config_dialog.c b/src/gtk-helpers/config_dialog.c
4b6aa8
index c80dc56..b5835de 100644
4b6aa8
--- a/src/gtk-helpers/config_dialog.c
4b6aa8
+++ b/src/gtk-helpers/config_dialog.c
4b6aa8
@@ -18,6 +18,7 @@
4b6aa8
 */
4b6aa8
 
4b6aa8
 #include <gtk/gtk.h>
4b6aa8
+#include <gdk/gdk.h>
4b6aa8
 #include "internal_libreport_gtk.h"
4b6aa8
 
4b6aa8
 enum
4b6aa8
@@ -83,6 +84,28 @@ gpointer cdialog_get_data(config_dialog_t *cdialog)
4b6aa8
     return cdialog->data;
4b6aa8
 }
4b6aa8
 
4b6aa8
+int cdialog_run(config_dialog_t *cdialog, const char *name)
4b6aa8
+{
4b6aa8
+    if (cdialog == NULL || cdialog->dialog == NULL)
4b6aa8
+    {
4b6aa8
+        log("There is no configurable option for: '%s'", name);
4b6aa8
+        return GTK_RESPONSE_REJECT;
4b6aa8
+    }
4b6aa8
+
4b6aa8
+    const int result = gtk_dialog_run(GTK_DIALOG(cdialog->dialog));
4b6aa8
+    if (result == GTK_RESPONSE_APPLY)
4b6aa8
+    {
4b6aa8
+        if (cdialog->save_data)
4b6aa8
+            cdialog->save_data(cdialog->data, name);
4b6aa8
+    }
4b6aa8
+    else if (result == GTK_RESPONSE_CANCEL)
4b6aa8
+        log_notice("Cancelling on user request");
4b6aa8
+
4b6aa8
+    gtk_widget_hide(GTK_WIDGET(cdialog->dialog));
4b6aa8
+
4b6aa8
+    return result;
4b6aa8
+}
4b6aa8
+
4b6aa8
 static const void *get_column_value_from_row(GtkTreeView *treeview, int column, int type)
4b6aa8
 {
4b6aa8
     GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
4b6aa8
@@ -184,6 +207,40 @@ static gboolean config_filter_func(GtkTreeModel *model,
4b6aa8
   return visible;
4b6aa8
 }
4b6aa8
 
4b6aa8
+static void open_config_for_selected_row(GtkTreeView *tv)
4b6aa8
+{
4b6aa8
+    config_dialog_t *cdialog = (config_dialog_t *)get_column_value_from_row(tv, CONFIG_DIALOG, TYPE_POINTER);
4b6aa8
+    const char *name = (const char *)get_column_value_from_row(tv, COLUMN_NAME, TYPE_STR);
4b6aa8
+
4b6aa8
+    cdialog_run(cdialog, name);
4b6aa8
+}
4b6aa8
+
4b6aa8
+static gboolean on_key_press_event_cb(GtkWidget *btn, GdkEvent *event, gpointer user_data)
4b6aa8
+{
4b6aa8
+    GdkEventKey *ek = (GdkEventKey *)event;
4b6aa8
+
4b6aa8
+    if (ek->keyval == GDK_KEY_Return)
4b6aa8
+    {
4b6aa8
+        GtkTreeView *tv = (GtkTreeView *)user_data;
4b6aa8
+        open_config_for_selected_row(tv);
4b6aa8
+    }
4b6aa8
+
4b6aa8
+    return FALSE;
4b6aa8
+}
4b6aa8
+
4b6aa8
+static gboolean on_button_press_event_cb(GtkWidget *btn, GdkEvent *event, gpointer user_data)
4b6aa8
+{
4b6aa8
+    GdkEventButton *eb = (GdkEventButton *)event;
4b6aa8
+
4b6aa8
+    if (eb->type == GDK_2BUTTON_PRESS)
4b6aa8
+    {
4b6aa8
+        GtkTreeView *tv = (GtkTreeView *)user_data;
4b6aa8
+        open_config_for_selected_row(tv);
4b6aa8
+    }
4b6aa8
+
4b6aa8
+    return FALSE;
4b6aa8
+}
4b6aa8
+
4b6aa8
 GtkWidget *create_config_tab_content(const char *column_label,
4b6aa8
                                       GtkListStore *store)
4b6aa8
 {
4b6aa8
@@ -194,6 +251,9 @@ GtkWidget *create_config_tab_content(const char *column_label,
4b6aa8
                                     GTK_POLICY_AUTOMATIC);
4b6aa8
     /* workflow list treeview */
4b6aa8
     GtkWidget *tv = gtk_tree_view_new();
4b6aa8
+    g_signal_connect(tv, "key-press-event", G_CALLBACK(on_key_press_event_cb), tv);
4b6aa8
+    g_signal_connect(tv, "button-press-event", G_CALLBACK(on_button_press_event_cb), tv);
4b6aa8
+
4b6aa8
     /* column with workflow name and description */
4b6aa8
     GtkCellRenderer *renderer;
4b6aa8
     GtkTreeViewColumn *column;
4b6aa8
@@ -243,27 +303,8 @@ static void on_configure_cb(GtkWidget *btn, gpointer user_data)
4b6aa8
     GtkWidget *vbox = gtk_notebook_get_nth_page(nb, current_page_n);
4b6aa8
     GList *children = gtk_container_get_children(GTK_CONTAINER(vbox));
4b6aa8
     GtkScrolledWindow *sw = (GtkScrolledWindow *)children->data;
4b6aa8
-    GtkTreeView *tv = (GtkTreeView *)gtk_bin_get_child(GTK_BIN(sw));
4b6aa8
-    config_dialog_t *cdialog = (config_dialog_t *)get_column_value_from_row(tv, CONFIG_DIALOG, TYPE_POINTER);
4b6aa8
-    const char *name = (const char *)get_column_value_from_row(tv, COLUMN_NAME, TYPE_STR);
4b6aa8
-
4b6aa8
 
4b6aa8
-    if (cdialog == NULL || cdialog->dialog == NULL)
4b6aa8
-    {
4b6aa8
-        log("There is no configurable option for: '%s'", name);
4b6aa8
-        return;
4b6aa8
-    }
4b6aa8
-
4b6aa8
-    int result = gtk_dialog_run(GTK_DIALOG(cdialog->dialog));
4b6aa8
-    if (result == GTK_RESPONSE_APPLY)
4b6aa8
-    {
4b6aa8
-        if (cdialog->save_data)
4b6aa8
-            cdialog->save_data(cdialog->data, name);
4b6aa8
-    }
4b6aa8
-    else if (result == GTK_RESPONSE_CANCEL)
4b6aa8
-        log_notice("Cancelling on user request");
4b6aa8
-
4b6aa8
-    gtk_widget_hide(GTK_WIDGET(cdialog->dialog));
4b6aa8
+    open_config_for_selected_row((GtkTreeView *)gtk_bin_get_child(GTK_BIN(sw)));
4b6aa8
 }
4b6aa8
 
4b6aa8
 static void on_close_cb(GtkWidget *btn, gpointer config_list_w)
4b6aa8
diff --git a/src/gtk-helpers/event_config_dialog.c b/src/gtk-helpers/event_config_dialog.c
4b6aa8
index 659f563..402f6f2 100644
4b6aa8
--- a/src/gtk-helpers/event_config_dialog.c
4b6aa8
+++ b/src/gtk-helpers/event_config_dialog.c
4b6aa8
@@ -337,7 +337,7 @@ config_dialog_t *create_event_config_dialog(const char *event_name, GtkWindow *p
4b6aa8
     if (parent_window != NULL)
4b6aa8
     {
4b6aa8
         gtk_window_set_icon_name(GTK_WINDOW(dialog),
4b6aa8
-        gtk_window_get_icon_name(parent_window));
4b6aa8
+                                 gtk_window_get_icon_name(parent_window));
4b6aa8
     }
4b6aa8
 
4b6aa8
     GtkWidget *content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
4b6aa8
@@ -367,53 +367,10 @@ int show_event_config_dialog(const char *event_name, GtkWindow *parent)
4b6aa8
 {
4b6aa8
     INITIALIZE_LIBREPORT();
4b6aa8
 
4b6aa8
-    event_config_t *event = get_event_config(event_name);
4b6aa8
-
4b6aa8
-    GtkWindow *parent_window = parent ? parent : g_event_list_window;
4b6aa8
+    config_dialog_t *dialog = create_event_config_dialog(event_name, parent);
4b6aa8
+    const int result = cdialog_run(dialog, event_name);
4b6aa8
+    free(dialog);
4b6aa8
 
4b6aa8
-    GtkWidget *dialog = gtk_dialog_new_with_buttons(
4b6aa8
-                        /*title:*/ec_get_screen_name(event) ? ec_get_screen_name(event) : event_name,
4b6aa8
-                        parent_window,
4b6aa8
-                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
4b6aa8
-                        _("_Cancel"),
4b6aa8
-                        GTK_RESPONSE_CANCEL,
4b6aa8
-                        _("_OK"),
4b6aa8
-                        GTK_RESPONSE_APPLY,
4b6aa8
-                        NULL);
4b6aa8
-
4b6aa8
-    /* Allow resize?
4b6aa8
-     * W/o resize, e.g. upload configuration hint looks awfully
4b6aa8
-     * line wrapped.
4b6aa8
-     * With resize, there are some somewhat not nice effects:
4b6aa8
-     * for one, opening an expander will enlarge window,
4b6aa8
-     * but won't contract it back when expander is closed.
4b6aa8
-     */
4b6aa8
-    gtk_window_set_resizable(GTK_WINDOW(dialog), true);
4b6aa8
-    gtk_window_set_default_size(GTK_WINDOW(dialog), 450, -1);
4b6aa8
-
4b6aa8
-    if (parent_window != NULL)
4b6aa8
-    {
4b6aa8
-        gtk_window_set_icon_name(GTK_WINDOW(dialog),
4b6aa8
-                gtk_window_get_icon_name(parent_window));
4b6aa8
-    }
4b6aa8
-
4b6aa8
-    GtkWidget *content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
4b6aa8
-    content = cdialog_get_widget(create_event_config_dialog_content(event, content));
4b6aa8
-
4b6aa8
-    gtk_widget_show_all(content);
4b6aa8
-
4b6aa8
-    int result = gtk_dialog_run(GTK_DIALOG(dialog));
4b6aa8
-    if (result == GTK_RESPONSE_APPLY)
4b6aa8
-    {
4b6aa8
-        dehydrate_config_dialog(g_option_list);
4b6aa8
-        const char *const store_passwords_s = get_user_setting("store_passwords");
4b6aa8
-        save_event_config_data_to_user_storage(event_name,
4b6aa8
-                                               get_event_config(event_name),
4b6aa8
-                                               !(store_passwords_s && !strcmp(store_passwords_s, "no")));
4b6aa8
-    }
4b6aa8
-    //else if (result == GTK_RESPONSE_CANCEL)
4b6aa8
-    //    log("log");
4b6aa8
-    gtk_widget_destroy(dialog);
4b6aa8
     return result;
4b6aa8
 }
4b6aa8
 
4b6aa8
diff --git a/src/gtk-helpers/internal_libreport_gtk.h b/src/gtk-helpers/internal_libreport_gtk.h
4b6aa8
index dc1ef31..f8f1c13 100644
4b6aa8
--- a/src/gtk-helpers/internal_libreport_gtk.h
4b6aa8
+++ b/src/gtk-helpers/internal_libreport_gtk.h
4b6aa8
@@ -80,6 +80,7 @@ void load_workflow_config_data_from_user_storage(GHashTable *workflows);
4b6aa8
 void cdialog_set_widget(config_dialog_t *cdialog, GtkWidget *widget);
4b6aa8
 GtkWidget *cdialog_get_widget(config_dialog_t *cdialog);
4b6aa8
 gpointer cdialog_get_data(config_dialog_t *cdialog);
4b6aa8
+int cdialog_run(config_dialog_t *cdialog, const char *name);
4b6aa8
 
4b6aa8
 void dehydrate_config_dialog(GList *option_widgets);
4b6aa8
 
4b6aa8
-- 
4b6aa8
1.8.3.1
4b6aa8