[librest] demo: add about dialog



commit 51b5ed4003c8d074e6edbbd946524d30e1b84ad5
Author: Günther Wagner <info gunibert de>
Date:   Tue Feb 1 21:59:54 2022 +0100

    demo: add about dialog

 examples/demo/demo-main.c    | 42 +++++++++++++++++++++++++++++++++++++++++-
 examples/demo/demo-window.ui | 14 ++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
---
diff --git a/examples/demo/demo-main.c b/examples/demo/demo-main.c
index b31d7dc..8f12404 100644
--- a/examples/demo/demo-main.c
+++ b/examples/demo/demo-main.c
@@ -19,6 +19,7 @@
  */
 
 #include <gtk/gtk.h>
+#include <glib/gi18n.h>
 #include <adwaita.h>
 #include <gtksourceview/gtksource.h>
 #include "demo-window.h"
@@ -37,6 +38,38 @@ on_activate (GApplication *app, gpointer user_data)
   gtk_window_present (active_window);
 }
 
+static void
+show_about (GSimpleAction *action,
+            GVariant      *state,
+            gpointer       user_data)
+{
+  const char *authors[] = {
+    "Günther Wagner",
+    NULL
+  };
+
+  const char *artists[] = {
+    "Günther Wagner",
+    NULL
+  };
+
+  GtkApplication *app = GTK_APPLICATION (user_data);
+  GtkWindow *window = gtk_application_get_active_window (app);
+
+  gtk_show_about_dialog (window,
+                         "program-name", _("Librest Demo"),
+                         "title", _("About Librest Demo"),
+                         /* "logo-icon-name", "org.gnome.RestDemo", */
+                         "copyright", "Copyright © 2022 Günther Wagner",
+                         "comments", _("Tour of the features in Librest"),
+                         "website", "https://gitlab.gnome.org/GNOME/librest";,
+                         "license-type", GTK_LICENSE_LGPL_2_1,
+                         "authors", authors,
+                         "artists", artists,
+                         "translator-credits", _("translator-credits"),
+                         NULL);
+}
+
 gint
 main (gint   argc,
       gchar *argv[])
@@ -47,7 +80,14 @@ main (gint   argc,
   g_set_prgname ("librest-demo");
   g_set_application_name ("librest-demo");
 
-  GtkApplication *app = gtk_application_new ("org.gnome.RestDemo", G_APPLICATION_FLAGS_NONE);
+  static GActionEntry app_entries[] = {
+    { "about", show_about, NULL, NULL, NULL },
+  };
+
+  AdwApplication *app = adw_application_new ("org.gnome.RestDemo", G_APPLICATION_FLAGS_NONE);
+  g_action_map_add_action_entries (G_ACTION_MAP (app),
+                                   app_entries, G_N_ELEMENTS (app_entries),
+                                   app);
   g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
 
   return g_application_run (G_APPLICATION (app), argc, argv);
diff --git a/examples/demo/demo-window.ui b/examples/demo/demo-window.ui
index 1216714..6134770 100644
--- a/examples/demo/demo-window.ui
+++ b/examples/demo/demo-window.ui
@@ -1,6 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk" version="4.0"/>
+  <menu id="primary_menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_About Librest Demo</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+    </section>
+  </menu>
   <template class="DemoWindow" parent="AdwApplicationWindow">
     <property name="title">Librest Demo</property>
     <property name="default-width">900</property>
@@ -13,6 +21,12 @@
         <property name="orientation">vertical</property>
         <child>
           <object class="GtkHeaderBar" id="headerbar">
+            <child type="end">
+              <object class="GtkMenuButton">
+                <property name="menu-model">primary_menu</property>
+                <property name="icon-name">open-menu-symbolic</property>
+              </object>
+            </child>
           </object>
         </child>
         <child>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]