Blame SOURCES/0048-gui-conver-report-gtk-to-GtkApplication.patch

28bab8
From 88ff2fcdf75ee9a44605847dc7e718cb7b5dedb2 Mon Sep 17 00:00:00 2001
28bab8
From: Jakub Filak <jfilak@redhat.com>
28bab8
Date: Wed, 30 Jul 2014 09:33:54 +0200
28bab8
Subject: [LIBREPORT PATCH 48/93] gui: conver report-gtk to GtkApplication
28bab8
28bab8
- improves compatibility with GNOME
28bab8
- allows us to move "Preferences" to the application menu
28bab8
28bab8
Related to rhbz#1069917
28bab8
28bab8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
28bab8
---
28bab8
 src/gui-wizard-gtk/main.c       | 60 ++++++++++++++++++++++++++++++++++++-----
28bab8
 src/gui-wizard-gtk/wizard.c     | 26 ++++--------------
28bab8
 src/gui-wizard-gtk/wizard.glade | 39 ---------------------------
28bab8
 src/gui-wizard-gtk/wizard.h     |  2 +-
28bab8
 4 files changed, 60 insertions(+), 67 deletions(-)
28bab8
28bab8
diff --git a/src/gui-wizard-gtk/main.c b/src/gui-wizard-gtk/main.c
28bab8
index 0bfa45c..697b91f 100644
28bab8
--- a/src/gui-wizard-gtk/main.c
28bab8
+++ b/src/gui-wizard-gtk/main.c
28bab8
@@ -72,6 +72,55 @@ void problem_data_reload_from_dump_dir(void)
28bab8
     g_cd = new_cd;
28bab8
 }
28bab8
 
28bab8
+static void
28bab8
+preferences_activated(GSimpleAction *action,
28bab8
+                           GVariant *parameter,
28bab8
+                           gpointer data)
28bab8
+{
28bab8
+    GtkApplication *app = GTK_APPLICATION(data);
28bab8
+    show_config_list_dialog(GTK_WINDOW(gtk_application_get_active_window(app)));
28bab8
+}
28bab8
+
28bab8
+static void
28bab8
+quit_activated(GSimpleAction *action,
28bab8
+                           GVariant *parameter,
28bab8
+                           gpointer data)
28bab8
+{
28bab8
+    g_application_quit(G_APPLICATION(data));
28bab8
+}
28bab8
+
28bab8
+static GActionEntry app_entries[] =
28bab8
+{
28bab8
+    { "preferences", preferences_activated, NULL, NULL, NULL },
28bab8
+    { "quit", quit_activated, NULL, NULL, NULL }
28bab8
+};
28bab8
+
28bab8
+static void
28bab8
+startup_wizard(GApplication *app,
28bab8
+                gpointer user_data)
28bab8
+{
28bab8
+    g_action_map_add_action_entries(G_ACTION_MAP (app),
28bab8
+            app_entries, G_N_ELEMENTS (app_entries),
28bab8
+            app);
28bab8
+
28bab8
+    GMenu *app_menu = g_menu_new();
28bab8
+    g_menu_append(app_menu, _("Preferences"), "app.preferences");
28bab8
+
28bab8
+    GMenu *service_app_menu_sec = g_menu_new();
28bab8
+    g_menu_append(service_app_menu_sec, _("Quit"), "app.quit");
28bab8
+    g_menu_append_section(app_menu, /*no title*/NULL, G_MENU_MODEL(service_app_menu_sec));
28bab8
+
28bab8
+    gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL(app_menu));
28bab8
+}
28bab8
+
28bab8
+static void
28bab8
+activate_wizard(GApplication *app,
28bab8
+                gpointer user_data)
28bab8
+{
28bab8
+    create_assistant(GTK_APPLICATION(app), (bool)user_data);
28bab8
+    update_gui_state_from_problem_data(UPDATE_SELECTED_EVENT);
28bab8
+}
28bab8
+
28bab8
 int main(int argc, char **argv)
28bab8
 {
28bab8
     bool expert_mode = false;
28bab8
@@ -166,14 +215,13 @@ int main(int argc, char **argv)
28bab8
 
28bab8
     problem_data_reload_from_dump_dir();
28bab8
 
28bab8
-    create_assistant(expert_mode);
28bab8
-
28bab8
     g_custom_logger = &show_error_as_msgbox;
28bab8
-
28bab8
-    update_gui_state_from_problem_data(UPDATE_SELECTED_EVENT);
28bab8
-
28bab8
+    GtkApplication *app = gtk_application_new("org.freedesktop.libreport.report", G_APPLICATION_FLAGS_NONE);
28bab8
+    g_signal_connect(app, "activate", G_CALLBACK(activate_wizard), (gpointer)expert_mode);
28bab8
+    g_signal_connect(app, "startup",  G_CALLBACK(startup_wizard),  NULL);
28bab8
     /* Enter main loop */
28bab8
-    gtk_main();
28bab8
+    g_application_run(G_APPLICATION(app), argc, argv);
28bab8
+    g_object_unref(app);
28bab8
 
28bab8
     if (opts & OPT_d)
28bab8
         delete_dump_dir_possibly_using_abrtd(g_dump_dir_name);
28bab8
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
28bab8
index 1fbe290..7cdd88b 100644
28bab8
--- a/src/gui-wizard-gtk/wizard.c
28bab8
+++ b/src/gui-wizard-gtk/wizard.c
28bab8
@@ -2128,12 +2128,6 @@ static void on_log_changed(GtkTextBuffer *buffer, gpointer user_data)
28bab8
     gtk_widget_show(GTK_WIDGET(g_exp_report_log));
28bab8
 }
28bab8
 
28bab8
-
28bab8
-static void on_show_event_list_cb(GtkWidget *button, gpointer user_data)
28bab8
-{
28bab8
-    show_config_list_dialog(GTK_WINDOW(g_wnd_assistant));
28bab8
-}
28bab8
-
28bab8
 #if 0
28bab8
 static void log_ready_state(void)
28bab8
 {
28bab8
@@ -3192,16 +3186,6 @@ static void add_pages(void)
28bab8
     gtk_widget_override_font(GTK_WIDGET(g_tv_event_log), g_monospace_font);
28bab8
     fix_all_wrapped_labels(GTK_WIDGET(g_assistant));
28bab8
 
28bab8
-    /* Configure btn on select analyzers page */
28bab8
-    GtkWidget *img_config_btn = gtk_image_new_from_icon_name("preferences-system", GTK_ICON_SIZE_BUTTON);
28bab8
-    GtkWidget *config_btn = GTK_WIDGET(gtk_builder_get_object(g_builder, "button_cfg1"));
28bab8
-    if (config_btn)
28bab8
-    {
28bab8
-        g_signal_connect(G_OBJECT(config_btn), "clicked", G_CALLBACK(on_show_event_list_cb), NULL);
28bab8
-        gtk_button_set_image(GTK_BUTTON(config_btn), img_config_btn);
28bab8
-        gtk_button_set_image_position(GTK_BUTTON(config_btn), GTK_POS_RIGHT);
28bab8
-    }
28bab8
-
28bab8
     g_signal_connect(g_cb_no_comment, "toggled", G_CALLBACK(on_no_comment_toggled), NULL);
28bab8
 
28bab8
     g_signal_connect(g_rb_forbidden_words, "toggled", G_CALLBACK(on_forbidden_words_toggled), NULL);
28bab8
@@ -3297,7 +3281,7 @@ static void assistant_quit_cb(void *obj, void *data)
28bab8
         g_loaded_texts = NULL;
28bab8
     }
28bab8
 
28bab8
-    gtk_main_quit();
28bab8
+    gtk_widget_destroy(GTK_WIDGET(data));
28bab8
 }
28bab8
 
28bab8
 static void on_btn_startcast(GtkWidget *btn, gpointer user_data)
28bab8
@@ -3353,7 +3337,7 @@ static bool is_screencast_available()
28bab8
     return status == 0;
28bab8
 }
28bab8
 
28bab8
-void create_assistant(bool expert_mode)
28bab8
+void create_assistant(GtkApplication *app, bool expert_mode)
28bab8
 {
28bab8
     g_loaded_texts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
28bab8
 
28bab8
@@ -3429,7 +3413,7 @@ void create_assistant(bool expert_mode)
28bab8
     gtk_widget_hide(g_btn_onfail);
28bab8
     gtk_widget_show(g_btn_next);
28bab8
 
28bab8
-    g_wnd_assistant = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
28bab8
+    g_wnd_assistant = GTK_WINDOW(gtk_application_window_new(app));
28bab8
     gtk_container_add(GTK_CONTAINER(g_wnd_assistant), GTK_WIDGET(g_box_assistant));
28bab8
 
28bab8
     gtk_window_set_default_size(g_wnd_assistant, DEFAULT_WIDTH, DEFAULT_HEIGHT);
28bab8
@@ -3444,12 +3428,12 @@ void create_assistant(bool expert_mode)
28bab8
 
28bab8
     create_details_treeview();
28bab8
 
28bab8
-    g_signal_connect(g_btn_close, "clicked", G_CALLBACK(assistant_quit_cb), NULL);
28bab8
+    g_signal_connect(g_btn_close, "clicked", G_CALLBACK(assistant_quit_cb), g_wnd_assistant);
28bab8
     g_signal_connect(g_btn_stop, "clicked", G_CALLBACK(on_btn_cancel_event), NULL);
28bab8
     g_signal_connect(g_btn_onfail, "clicked", G_CALLBACK(on_btn_failed_cb), NULL);
28bab8
     g_signal_connect(g_btn_next, "clicked", G_CALLBACK(on_next_btn_cb), NULL);
28bab8
 
28bab8
-    g_signal_connect(g_wnd_assistant, "destroy", G_CALLBACK(assistant_quit_cb), NULL);
28bab8
+    g_signal_connect(g_wnd_assistant, "destroy", G_CALLBACK(assistant_quit_cb), g_wnd_assistant);
28bab8
     g_signal_connect(g_assistant, "switch-page", G_CALLBACK(on_page_prepare), NULL);
28bab8
 
28bab8
     g_signal_connect(g_tb_approve_bt, "toggled", G_CALLBACK(on_bt_approve_toggle), NULL);
28bab8
diff --git a/src/gui-wizard-gtk/wizard.glade b/src/gui-wizard-gtk/wizard.glade
28bab8
index 9a179f4..9296bca 100644
28bab8
--- a/src/gui-wizard-gtk/wizard.glade
28bab8
+++ b/src/gui-wizard-gtk/wizard.glade
28bab8
@@ -430,45 +430,6 @@
28bab8
             <property name="position">1</property>
28bab8
           </packing>
28bab8
         </child>
28bab8
-        <child>
28bab8
-          <object class="GtkHBox" id="hbox2">
28bab8
-            <property name="visible">True</property>
28bab8
-            <property name="can_focus">False</property>
28bab8
-            <child>
28bab8
-              <object class="GtkButton" id="button_cfg1">
28bab8
-                <property name="label">_Preferences</property>
28bab8
-                <property name="visible">True</property>
28bab8
-                <property name="can_focus">True</property>
28bab8
-                <property name="receives_default">True</property>
28bab8
-                <property name="use_underline">True</property>
28bab8
-              </object>
28bab8
-              <packing>
28bab8
-                <property name="expand">False</property>
28bab8
-                <property name="fill">False</property>
28bab8
-                <property name="position">0</property>
28bab8
-              </packing>
28bab8
-            </child>
28bab8
-            <child>
28bab8
-              <object class="GtkAlignment" id="alignment3">
28bab8
-                <property name="visible">True</property>
28bab8
-                <property name="can_focus">False</property>
28bab8
-                <child>
28bab8
-                  <placeholder/>
28bab8
-                </child>
28bab8
-              </object>
28bab8
-              <packing>
28bab8
-                <property name="expand">True</property>
28bab8
-                <property name="fill">True</property>
28bab8
-                <property name="position">1</property>
28bab8
-              </packing>
28bab8
-            </child>
28bab8
-          </object>
28bab8
-          <packing>
28bab8
-            <property name="expand">False</property>
28bab8
-            <property name="fill">False</property>
28bab8
-            <property name="position">2</property>
28bab8
-          </packing>
28bab8
-        </child>
28bab8
       </object>
28bab8
     </child>
28bab8
   </object>
28bab8
diff --git a/src/gui-wizard-gtk/wizard.h b/src/gui-wizard-gtk/wizard.h
28bab8
index a6d8b5d..4c891dc 100644
28bab8
--- a/src/gui-wizard-gtk/wizard.h
28bab8
+++ b/src/gui-wizard-gtk/wizard.h
28bab8
@@ -21,7 +21,7 @@
28bab8
 
28bab8
 #include "internal_libreport_gtk.h"
28bab8
 
28bab8
-void create_assistant(bool expert_mode);
28bab8
+void create_assistant(GtkApplication *app, bool expert_mode);
28bab8
 
28bab8
 enum
28bab8
 {
28bab8
-- 
28bab8
1.8.3.1
28bab8