You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

240 lines
8.7 KiB

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