From 076a036070b15a14e130675b9a81a563e77d0138 Mon Sep 17 00:00:00 2001 From: Bruce Cowan <bruce@bcowan.eu> Date: Sun, 31 Dec 2017 14:21:14 +0000 Subject: [PATCH] Bring back about screen Menu doesn't work, have to use <Primary>+a --- data/interface.ui | 40 +--------------------- data/menu.ui | 19 +++++++++++ data/rugby.gresource.xml | 1 + src/rugby-app-window.c | 7 ---- src/rugby-application.c | 71 +++++++++++++++++++++++++++++++++++++--- 5 files changed, 88 insertions(+), 50 deletions(-) create mode 100644 data/menu.ui diff --git a/data/interface.ui b/data/interface.ui index 1198f84..a0cd5de 100644 --- a/data/interface.ui +++ b/data/interface.ui @@ -1,45 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- Generated with glade 3.20.2 --> <interface> - <requires lib="gtk+" version="3.10"/> - <object class="GtkAboutDialog" id="about"> - <property name="can_focus">False</property> - <property name="type_hint">dialog</property> - <property name="program_name">Rugby</property> - <property name="copyright" translatable="yes">Copyright © 2012-2017 Bruce Cowan</property> - <property name="logo_icon_name">image-missing</property> - <property name="license_type">lgpl-3-0</property> - <child internal-child="vbox"> - <object class="GtkBox"> - <property name="can_focus">False</property> - <property name="orientation">vertical</property> - <property name="spacing">2</property> - <child internal-child="action_area"> - <object class="GtkButtonBox"> - <property name="can_focus">False</property> - <property name="layout_style">end</property> - <child> - <placeholder/> - </child> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <placeholder/> - </child> - </object> - </child> - <child> - <placeholder/> - </child> - </object> + <requires lib="gtk+" version="3.16"/> <object class="GtkAdjustment" id="adjustment1"> <property name="upper">200</property> <property name="step_increment">1</property> diff --git a/data/menu.ui b/data/menu.ui new file mode 100644 index 0000000..63db880 --- /dev/null +++ b/data/menu.ui @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<interface> + <menu id="appmenu"> + <section> + <item> + <attribute name="label" translatable="yes">_About</attribute> + <attribute name="action">app.about</attribute> + <attribute name="accel"><Primary>a</attribute> + </item> + </section> + <section> + <item> + <attribute name="label" translatable="yes">_Quit</attribute> + <attribute name="action">app.quit</attribute> + <attribute name="accel"><Primary>q</attribute> + </item> + </section> + </menu> +</interface> diff --git a/data/rugby.gresource.xml b/data/rugby.gresource.xml index 1c7c2f8..a32d207 100644 --- a/data/rugby.gresource.xml +++ b/data/rugby.gresource.xml @@ -2,6 +2,7 @@ <gresources> <gresource prefix="/uk/me/bcowan/rugby"> <file preprocess="xml-stripblanks">interface.ui</file> + <file preprocess="xml-stripblanks">menu.ui</file> <file compressed="true">rugby.css</file> </gresource> </gresources> diff --git a/src/rugby-app-window.c b/src/rugby-app-window.c index 18f4e30..457cc2c 100644 --- a/src/rugby-app-window.c +++ b/src/rugby-app-window.c @@ -112,13 +112,6 @@ rugby_app_window_init (RugbyAppWindow *self) gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (self->filter), filter_visible_func, self, NULL); gtk_tree_view_set_model (GTK_TREE_VIEW (self->treeview), self->filter); - - GtkCssProvider *provider = gtk_css_provider_new (); - gtk_css_provider_load_from_resource (provider, "/uk/me/bcowan/rugby/rugby.css"); - - gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), - GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } static void diff --git a/src/rugby-application.c b/src/rugby-application.c index 58a7411..96c8b4e 100644 --- a/src/rugby-application.c +++ b/src/rugby-application.c @@ -11,22 +11,85 @@ struct _RugbyApplication G_DEFINE_TYPE (RugbyApplication, rugby_application, GTK_TYPE_APPLICATION); static void -rugby_application_init (RugbyApplication *app) +rugby_application_activate (GApplication *app) { + RugbyAppWindow *win = rugby_app_window_new (RUGBY_APPLICATION (app)); + gtk_window_present (GTK_WINDOW (win)); } static void -rugby_application_activate (GApplication *app) +about_activated (GSimpleAction *simple, + GVariant *parameter, + gpointer user_data) { - RugbyAppWindow *win = rugby_app_window_new (RUGBY_APPLICATION (app)); - gtk_window_present (GTK_WINDOW (win)); + GtkApplication *app = GTK_APPLICATION (user_data); + GtkWindow *window = gtk_application_get_active_window (app); + + static const gchar *authors[] = { "Bruce Cowan", NULL }; + g_autoptr (GDateTime) date = g_date_time_new_now_local (); + gint year = g_date_time_get_year (date); + g_autofree gchar *copyright = g_strdup_printf ("Copyright © 2012–%d Bruce Cowan", + year); + + gtk_show_about_dialog (window, + "logo-icon-name", "face-wink", + "program-name", "Rugby", + "copyright", copyright, + "license-type", GTK_LICENSE_LGPL_3_0, + "authors", authors, + "comments", "Rugby scores possiblities program", + NULL); + +} + +static void +quit_activated (GSimpleAction *simple, + GVariant *parameter, + gpointer user_data) +{ + g_application_quit (G_APPLICATION (user_data)); +} + +static const GActionEntry app_entries[] = +{ + { "about", about_activated, NULL, NULL, NULL }, + { "quit", quit_activated, NULL, NULL, NULL } +}; + +static void +rugby_application_startup (GApplication *app) +{ + G_APPLICATION_CLASS (rugby_application_parent_class)->startup (app); + + g_action_map_add_action_entries (G_ACTION_MAP (app), + app_entries, G_N_ELEMENTS (app_entries), + app); + + g_autoptr (GtkBuilder) builder = gtk_builder_new_from_resource ("/uk/me/bcowan/rugby/menu.ui"); + GMenuModel *app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu")); + gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu); + + // CSS styling + g_autoptr (GtkCssProvider) provider = gtk_css_provider_new (); + gtk_css_provider_load_from_resource (provider, "/uk/me/bcowan/rugby/rugby.css"); + + gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } static void rugby_application_class_init (RugbyApplicationClass *klass) { GApplicationClass *app_class = G_APPLICATION_CLASS (klass); + app_class->activate = rugby_application_activate; + app_class->startup = rugby_application_startup; +} + +static void +rugby_application_init (RugbyApplication *self) +{ } RugbyApplication * -- GitLab