]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
hello-c-gnome3: Add a simpler "hello world" program.
authorBruno Haible <bruno@clisp.org>
Wed, 18 Dec 2024 10:14:29 +0000 (11:14 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 18 Dec 2024 17:57:52 +0000 (18:57 +0100)
* gettext-tools/examples/hello-c-gnome3/README: New file.
* gettext-tools/examples/hello-c-gnome3/hello2.c: New file, based on
gettext-tools/examples/hello-c-gnome3/hello.c.
* gettext-tools/examples/hello-c-gnome3/hello2.desktop.in.in: New file, based on
gettext-tools/examples/hello-c-gnome3/hello.desktop.in.in.
* gettext-tools/examples/hello-c-gnome3/hello2.gresource.xml: New file, based on
gettext-tools/examples/hello-c-gnome3/hello.gresource.xml.
* gettext-tools/examples/hello-c-gnome3/hello2.ui: Renamed from
gettext-tools/examples/hello-c-gnome3/hello.ui.
* gettext-tools/examples/hello-c-gnome3/hello2.gschema.xml: New file, based on
gettext-tools/examples/hello-c-gnome3/hello.gschema.xml.
* gettext-tools/examples/hello-c-gnome3/hello.c: Greatly simplified.
* gettext-tools/examples/hello-c-gnome3/hello.ui: Use an <object> element
instead of a <template> element.
* gettext-tools/examples/hello-c-gnome3/hello.gschema.xml: Remove file.
* gettext-tools/examples/hello-c-gnome3/Makefile.am (bin_PROGRAMS): Add hello2.
(hello-resources.c): Renamed from resources.c.
(hello2_SOURCES): New variable.
(hello2-resources.c): New target.
(desktop_DATA): Add hello2.desktop.
(hello2.desktop.in, hello2.desktop): New targets.
(BUILT_SOURCES, CLEANFILES, MAINTAINERCLEANFILES): Update.
(EXTRA_DIST): Remove hello.gschema.xml. Add hello2.desktop.in.in,
hello2.desktop.in, hello2.gresource.xml, hello2.ui, hello2.gschema.xml.
* gettext-tools/examples/hello-c-gnome3/po/POTFILES.in: Update.
* gettext-tools/examples/hello-c-gnome3/autoclean.sh: Update.
* gettext-tools/examples/Makefile.am (EXAMPLESFILES): Update.
* gettext-tools/examples/po/Makefile.am (POTFILES): Update.

13 files changed:
gettext-tools/examples/Makefile.am
gettext-tools/examples/hello-c-gnome3/Makefile.am
gettext-tools/examples/hello-c-gnome3/README [new file with mode: 0644]
gettext-tools/examples/hello-c-gnome3/autoclean.sh
gettext-tools/examples/hello-c-gnome3/hello.c
gettext-tools/examples/hello-c-gnome3/hello.ui
gettext-tools/examples/hello-c-gnome3/hello2.c [new file with mode: 0644]
gettext-tools/examples/hello-c-gnome3/hello2.desktop.in.in [new file with mode: 0644]
gettext-tools/examples/hello-c-gnome3/hello2.gresource.xml [new file with mode: 0644]
gettext-tools/examples/hello-c-gnome3/hello2.gschema.xml [moved from gettext-tools/examples/hello-c-gnome3/hello.gschema.xml with 88% similarity]
gettext-tools/examples/hello-c-gnome3/hello2.ui [new file with mode: 0644]
gettext-tools/examples/hello-c-gnome3/po/POTFILES.in
gettext-tools/examples/po/Makefile.am

index dc75f7ffce0414046bbb53f6ef485d599b350ce7..d6e4af0b4ed0935143bd1a709a154daa541ec6e7 100644 (file)
@@ -54,13 +54,18 @@ EXAMPLESFILES = \
   hello-c-gnome2/po/POTFILES.in \
   \
   hello-c-gnome3/INSTALL \
+  hello-c-gnome3/README \
   hello-c-gnome3/autogen.sh \
   hello-c-gnome3/autoclean.sh \
   hello-c-gnome3/hello.c \
   hello-c-gnome3/hello.desktop.in.in \
-  hello-c-gnome3/hello.gschema.xml \
   hello-c-gnome3/hello.gresource.xml \
   hello-c-gnome3/hello.ui \
+  hello-c-gnome3/hello2.c \
+  hello-c-gnome3/hello2.desktop.in.in \
+  hello-c-gnome3/hello2.gresource.xml \
+  hello-c-gnome3/hello2.ui \
+  hello-c-gnome3/hello2.gschema.xml \
   hello-c-gnome3/Makefile.am \
   hello-c-gnome3/configure.ac \
   hello-c-gnome3/m4/Makefile.am \
index 9473dec113ff8761ed3eee489e2dcfe5b1d0d63d..6158d99914bebd519813691095ba166a24e966d7 100644 (file)
@@ -11,10 +11,12 @@ ACLOCAL_AMFLAGS = -I m4
 SUBDIRS = m4 po
 
 # The list of programs that are built.
-bin_PROGRAMS = hello
+bin_PROGRAMS = hello hello2
 
 # The source files of the 'hello' program.
-hello_SOURCES = hello.c resources.c
+hello_SOURCES = hello.c hello-resources.c
+# The source files of the 'hello2' program.
+hello2_SOURCES = hello2.c hello2-resources.c
 
 # Define a C macro LOCALEDIR indicating where catalogs will be installed
 # and a C macro PKGDATADIR indicating a package-specific location.
@@ -30,11 +32,14 @@ AM_CPPFLAGS = $(GTK_CFLAGS)
 LDADD = $(GTK_LIBS) @LIBINTL@
 
 # Compile GSettings schema.
-gschemas.compiled: hello.gschema.xml
+gschemas.compiled: hello2.gschema.xml
        $(AM_V_GEN) $(GLIB_COMPILE_SCHEMAS) --targetdir=. $(srcdir)
 
 # Compile assets into a C source and link it with the application.
-resources.c: hello.gresource.xml hello.ui
+hello-resources.c: hello.gresource.xml hello.ui
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ \
+               --sourcedir=$(srcdir) --generate-source
+hello2-resources.c: hello2.gresource.xml hello2.ui
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ \
                --sourcedir=$(srcdir) --generate-source
 
@@ -43,7 +48,7 @@ resources.c: hello.gresource.xml hello.ui
 pkgdata_DATA = gschemas.compiled
 
 desktopdir = $(datadir)/applications
-desktop_DATA = hello.desktop
+desktop_DATA = hello.desktop hello2.desktop
 
 # Merge translations back into a Desktop Entry file.
 
@@ -52,18 +57,24 @@ desktop_DATA = hello.desktop
 # the 'msgfmt' command will be required at compile-time.
 hello.desktop.in: hello.desktop.in.in
        $(AM_V_GEN) $(MSGFMT) --desktop --template $< -d $(top_srcdir)/po -o $@
+hello2.desktop.in: hello2.desktop.in.in
+       $(AM_V_GEN) $(MSGFMT) --desktop --template $< -d $(top_srcdir)/po -o $@
 
 # Substitute variables in a Desktop Entry file.
 hello.desktop: hello.desktop.in
        $(AM_V_GEN) sed -e 's|@bindir[@]|$(bindir)|g' $< > $@
+hello2.desktop: hello2.desktop.in
+       $(AM_V_GEN) sed -e 's|@bindir[@]|$(bindir)|g' $< > $@
 
-BUILT_SOURCES        = gschemas.compiled resources.c hello.desktop
-CLEANFILES           = gschemas.compiled             hello.desktop
+BUILT_SOURCES        = gschemas.compiled hello-resources.c hello2-resources.c hello.desktop hello2.desktop
+CLEANFILES           = gschemas.compiled                                      hello.desktop hello2.desktop
 DISTCLEANFILES       =
-MAINTAINERCLEANFILES =                   resources.c hello.desktop.in
+MAINTAINERCLEANFILES =                   hello-resources.c hello2-resources.c hello.desktop.in hello2.desktop.in
 
 # Additional files to be distributed.
-EXTRA_DIST = autogen.sh autoclean.sh hello.ui \
+EXTRA_DIST = autogen.sh autoclean.sh \
        hello.desktop.in.in hello.desktop.in \
-       hello.gschema.xml \
-       hello.gresource.xml
+       hello.gresource.xml hello.ui \
+       hello2.desktop.in.in hello2.desktop.in \
+       hello2.gresource.xml hello2.ui \
+       hello2.gschema.xml
diff --git a/gettext-tools/examples/hello-c-gnome3/README b/gettext-tools/examples/hello-c-gnome3/README
new file mode 100644 (file)
index 0000000..5badbd8
--- /dev/null
@@ -0,0 +1,4 @@
+This example contains two programs:
+  - hello, a simple "hello world" program,
+  - hello2, a more elaborate program that demonstrates advanced Gtk 3 features:
+    derived GObject classes, widget templates, GSettings.
index d7552cf54de713b7ec895d7ffdbe2c61df569bfc..769c4a6cf5035b6aaf8ef907008ee728ce082279 100755 (executable)
@@ -8,7 +8,7 @@ test ! -f Makefile || make distclean
 rm -rf autom4te.cache
 
 # Files generated by "make" and distributed (see MAINTAINERCLEANFILES).
-rm -f resources.c hello.desktop.in
+rm -f hello-resources.c hello2-resources.c hello.desktop.in hello2.desktop.in
 
 # Brought in by autopoint.
 rm -f ABOUT-NLS
index c39192f67ddcb28e64b275acd14496aef27028cc..8b4eea44549be33dd9090afed71300713e5df527 100644 (file)
@@ -8,6 +8,9 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 
+/* Get exit() declaration.  */
+#include <stdlib.h>
+
 /* Get getpid() declaration.  */
 #if defined _WIN32 && !defined __CYGWIN__
 /* native Windows API */
 
 #define UI_PATH "/org/gnu/gettext/examples/hello/hello.ui"
 #define APPLICATION_ID "org.gnu.gettext.examples.hello"
-#define GSETTINGS_SCHEMA "org.gnu.gettext.examples.hello"
-
-/* Forward declaration of GObject types.  */
-
-#define HELLO_TYPE_APPLICATION_WINDOW (hello_application_window_get_type ())
-#define HELLO_APPLICATION_WINDOW(obj)                           \
-  (G_TYPE_CHECK_INSTANCE_CAST ((obj),                           \
-                               HELLO_TYPE_APPLICATION_WINDOW,   \
-                               HelloApplicationWindow))
-
-typedef struct _HelloApplicationWindow HelloApplicationWindow;
-typedef struct _HelloApplicationWindowClass HelloApplicationWindowClass;
-
-#define HELLO_TYPE_APPLICATION (hello_application_get_type ())
-#define HELLO_APPLICATION(obj)                          \
-  (G_TYPE_CHECK_INSTANCE_CAST ((obj),                   \
-                               HELLO_TYPE_APPLICATION,  \
-                               HelloApplication))
-
-typedef struct _HelloApplication HelloApplication;
-typedef struct _HelloApplicationClass HelloApplicationClass;
 
-/* Custom application window implementation.  */
-
-struct _HelloApplicationWindow
+/* An ad-hoc struct for managing the main window.
+   (Not connected to the GObject type system.)  */
+struct HelloWindow
 {
-  GtkApplicationWindow parent;
-  GtkWidget *label;
-  GtkWidget *button;
-  GSettings *settings;
+  GtkWindow *window;
+  GtkLabel *label;
+  GtkButton *button;
   gsize label_id;
   gchar *labels[3];
 };
 
-struct _HelloApplicationWindowClass
+static void
+update_content (struct HelloWindow *hello_window)
 {
-  GtkApplicationWindowClass parent_class;
-};
-
-G_DEFINE_TYPE (HelloApplicationWindow, hello_application_window,
-               GTK_TYPE_APPLICATION_WINDOW);
+  gtk_label_set_label (hello_window->label,
+                       hello_window->labels[hello_window->label_id]);
+  hello_window->label_id =
+    (hello_window->label_id + 1) % G_N_ELEMENTS (hello_window->labels);
+}
 
 static void
-update_content (HelloApplicationWindow *window)
+clicked_callback (GtkWidget *widget, struct HelloWindow *hello_window)
 {
-  gtk_label_set_label (GTK_LABEL (window->label),
-                       window->labels[window->label_id]);
-  window->label_id = (window->label_id + 1) % G_N_ELEMENTS (window->labels);
+  update_content (hello_window);
 }
 
 static void
-hello_application_window_init (HelloApplicationWindow *window)
+activate (GApplication *application, void *data)
 {
-  gtk_widget_init_template (GTK_WIDGET (window));
+  GtkBuilder *builder;
+  GError *error = NULL;
+
+  /* Instantiate the UI.  */
+  builder = gtk_builder_new ();
+  if (gtk_builder_add_from_resource (builder, UI_PATH, &error) == 0)
+    {
+      g_printerr ("Error instantiating UI: %s\n", error->message);
+      g_clear_error (&error);
+      exit (1);
+    }
+
+  struct HelloWindow *hello_window = g_malloc (sizeof (struct HelloWindow));
+  hello_window->window = GTK_WINDOW (gtk_builder_get_object (builder, "main_window"));
+  hello_window->label = GTK_LABEL (gtk_builder_get_object (builder, "label"));
+  hello_window->button = GTK_BUTTON (gtk_builder_get_object (builder, "button"));
 
-  window->settings = g_settings_new (GSETTINGS_SCHEMA);
   /* Allow Pango markup in the label.  */
-  g_settings_bind (window->settings, "use-markup",
-                   window->label, "use-markup",
-                   G_SETTINGS_BIND_DEFAULT);
+  gtk_label_set_use_markup (hello_window->label, TRUE);
 
   /* Prepare various presentations of the label.  */
-  window->label_id = 0;
+  hello_window->label_id = 0;
   gchar *line1 = g_strdup_printf ("<big>%s</big>", _("Hello world!"));
   gchar *line2 =
     g_strdup_printf (_("This program is running as process number %s."),
                      g_strdup_printf ("<b>%d</b>", getpid ()));
-  window->labels[0] = g_strdup_printf ("%s\n%s", line1, line2);
-  window->labels[1] =
+  hello_window->labels[0] = g_strdup_printf ("%s\n%s", line1, line2);
+  hello_window->labels[1] =
     g_strdup_printf ("<big><u>%s</u></big>", _("This is another text"));
-  window->labels[2] =
+  hello_window->labels[2] =
     g_strdup_printf ("<big><i>%s</i></big>", _("This is yet another text"));
 
-  update_content (window);
-}
+  update_content (hello_window);
 
-static void
-hello_application_window_class_init (HelloApplicationWindowClass *klass)
-{
-  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
-  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
-                                               UI_PATH);
-  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass),
-                                        HelloApplicationWindow, label);
-  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass),
-                                        HelloApplicationWindow, button);
-}
+  /* Make sure that the application runs for as long as this window is
+     still open.  */
+  gtk_application_add_window (GTK_APPLICATION (application),
+                              GTK_WINDOW (hello_window->window));
 
-static HelloApplicationWindow *
-hello_application_window_new (HelloApplication *application)
-{
-  return g_object_new (HELLO_TYPE_APPLICATION_WINDOW,
-                       "application", application,
-                       NULL);
-}
-
-/* Custom application implementation.  */
-
-struct _HelloApplication
-{
-  GtkApplication parent;
-};
-
-struct _HelloApplicationClass
-{
-  GtkApplicationClass parent_class;
-};
-
-G_DEFINE_TYPE (HelloApplication, hello_application, GTK_TYPE_APPLICATION);
-
-static void
-hello_application_init (HelloApplication *application)
-{
-}
-
-static void
-clicked_callback (GtkWidget *widget, void *data)
-{
-  update_content (HELLO_APPLICATION_WINDOW (data));
-}
-
-static void
-hello_application_activate (GApplication *application)
-{
-  HelloApplicationWindow *window;
-
-  window = hello_application_window_new (HELLO_APPLICATION (application));
-  g_signal_connect (window->button, "clicked",
-                    G_CALLBACK (clicked_callback), window);
-  gtk_window_present (GTK_WINDOW (window));
-}
-
-static void
-hello_application_class_init (HelloApplicationClass *klass)
-{
-  G_APPLICATION_CLASS (klass)->activate = hello_application_activate;
-}
-
-static HelloApplication *
-hello_application_new (void)
-{
-  return g_object_new (HELLO_TYPE_APPLICATION,
-                       "application-id", APPLICATION_ID,
-                       NULL);
+  g_signal_connect (hello_window->button, "clicked",
+                    G_CALLBACK (clicked_callback), hello_window);
+  gtk_window_present (GTK_WINDOW (hello_window->window));
 }
 
 int
@@ -173,19 +103,15 @@ main (int argc, char *argv[])
   GApplication *application;
   int status;
 
-  /* Load the compiled GSettings schema
-     - from PKGDATADIR (so that it works after "make install"),
-     - from the current directory (so that it works in the build directory,
-       before "make install").  */
-  g_setenv ("GSETTINGS_SCHEMA_DIR", PKGDATADIR G_SEARCHPATH_SEPARATOR_S ".",
-            FALSE);
-
   /* Initializations.  */
   textdomain ("hello-c-gnome3");
   bindtextdomain ("hello-c-gnome3", LOCALEDIR);
 
   /* Create application.  */
-  application = G_APPLICATION (hello_application_new ());
+  application =
+    G_APPLICATION (gtk_application_new (APPLICATION_ID,
+                                        G_APPLICATION_DEFAULT_FLAGS));
+  g_signal_connect (application, "activate", G_CALLBACK (activate), NULL);
 
   /* Start the application.  */
   status = g_application_run (application, argc, argv);
index b2d13b0f0647e58e3ed48abd7457b385c8ef7930..e142400c04d2f89797cf76aa86d5e14f88807b68 100644 (file)
@@ -2,7 +2,7 @@
 <!-- This file is in the public domain. -->
 <interface>
   <!-- interface-requires gtk+ 3.10 -->
-  <template class="HelloApplicationWindow" parent="GtkApplicationWindow">
+  <object class="GtkApplicationWindow" id="main_window">
     <property name="title" translatable="yes">Example Application</property>
     <property name="default-width">600</property>
     <property name="default-height">400</property>
@@ -42,5 +42,5 @@
         </child>
       </object>
     </child>
-  </template>
+  </object>
 </interface>
diff --git a/gettext-tools/examples/hello-c-gnome3/hello2.c b/gettext-tools/examples/hello-c-gnome3/hello2.c
new file mode 100644 (file)
index 0000000..e89dfd8
--- /dev/null
@@ -0,0 +1,195 @@
+/* Example for use of GNU gettext.
+   This file is in the public domain.
+
+   Source code of the C program.  */
+
+
+/* Get GTK declarations.  */
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+/* Get getpid() declaration.  */
+#if defined _WIN32 && !defined __CYGWIN__
+/* native Windows API */
+# include <process.h>
+# define getpid _getpid
+#else
+/* POSIX API */
+# include <unistd.h>
+#endif
+
+#define UI_PATH "/org/gnu/gettext/examples/hello/hello2.ui"
+#define APPLICATION_ID "org.gnu.gettext.examples.hello2"
+#define GSETTINGS_SCHEMA "org.gnu.gettext.examples.hello2"
+
+/* Forward declaration of GObject types.  */
+
+#define HELLO_TYPE_APPLICATION_WINDOW (hello_application_window_get_type ())
+#define HELLO_APPLICATION_WINDOW(obj)                           \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj),                           \
+                               HELLO_TYPE_APPLICATION_WINDOW,   \
+                               HelloApplicationWindow))
+
+typedef struct _HelloApplicationWindow HelloApplicationWindow;
+typedef struct _HelloApplicationWindowClass HelloApplicationWindowClass;
+
+#define HELLO_TYPE_APPLICATION (hello_application_get_type ())
+#define HELLO_APPLICATION(obj)                          \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj),                   \
+                               HELLO_TYPE_APPLICATION,  \
+                               HelloApplication))
+
+typedef struct _HelloApplication HelloApplication;
+typedef struct _HelloApplicationClass HelloApplicationClass;
+
+/* Custom application window implementation.  */
+
+struct _HelloApplicationWindow
+{
+  GtkApplicationWindow parent;
+  GtkWidget *label;
+  GtkWidget *button;
+  GSettings *settings;
+  gsize label_id;
+  gchar *labels[3];
+};
+
+struct _HelloApplicationWindowClass
+{
+  GtkApplicationWindowClass parent_class;
+};
+
+G_DEFINE_TYPE (HelloApplicationWindow, hello_application_window,
+               GTK_TYPE_APPLICATION_WINDOW);
+
+static void
+update_content (HelloApplicationWindow *window)
+{
+  gtk_label_set_label (GTK_LABEL (window->label),
+                       window->labels[window->label_id]);
+  window->label_id = (window->label_id + 1) % G_N_ELEMENTS (window->labels);
+}
+
+static void
+hello_application_window_init (HelloApplicationWindow *window)
+{
+  gtk_widget_init_template (GTK_WIDGET (window));
+
+  window->settings = g_settings_new (GSETTINGS_SCHEMA);
+  /* Allow Pango markup in the label.  */
+  g_settings_bind (window->settings, "use-markup",
+                   window->label, "use-markup",
+                   G_SETTINGS_BIND_DEFAULT);
+
+  /* Prepare various presentations of the label.  */
+  window->label_id = 0;
+  gchar *line1 = g_strdup_printf ("<big>%s</big>", _("Hello world!"));
+  gchar *line2 =
+    g_strdup_printf (_("This program is running as process number %s."),
+                     g_strdup_printf ("<b>%d</b>", getpid ()));
+  window->labels[0] = g_strdup_printf ("%s\n%s", line1, line2);
+  window->labels[1] =
+    g_strdup_printf ("<big><u>%s</u></big>", _("This is another text"));
+  window->labels[2] =
+    g_strdup_printf ("<big><i>%s</i></big>", _("This is yet another text"));
+
+  update_content (window);
+}
+
+static void
+hello_application_window_class_init (HelloApplicationWindowClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
+                                               UI_PATH);
+  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass),
+                                        HelloApplicationWindow, label);
+  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass),
+                                        HelloApplicationWindow, button);
+}
+
+static HelloApplicationWindow *
+hello_application_window_new (HelloApplication *application)
+{
+  return g_object_new (HELLO_TYPE_APPLICATION_WINDOW,
+                       "application", application,
+                       NULL);
+}
+
+/* Custom application implementation.  */
+
+struct _HelloApplication
+{
+  GtkApplication parent;
+};
+
+struct _HelloApplicationClass
+{
+  GtkApplicationClass parent_class;
+};
+
+G_DEFINE_TYPE (HelloApplication, hello_application, GTK_TYPE_APPLICATION);
+
+static void
+hello_application_init (HelloApplication *application)
+{
+}
+
+static void
+clicked_callback (GtkWidget *widget, void *data)
+{
+  update_content (HELLO_APPLICATION_WINDOW (data));
+}
+
+static void
+hello_application_activate (GApplication *application)
+{
+  HelloApplicationWindow *window;
+
+  window = hello_application_window_new (HELLO_APPLICATION (application));
+  g_signal_connect (window->button, "clicked",
+                    G_CALLBACK (clicked_callback), window);
+  gtk_window_present (GTK_WINDOW (window));
+}
+
+static void
+hello_application_class_init (HelloApplicationClass *klass)
+{
+  G_APPLICATION_CLASS (klass)->activate = hello_application_activate;
+}
+
+static HelloApplication *
+hello_application_new (void)
+{
+  return g_object_new (HELLO_TYPE_APPLICATION,
+                       "application-id", APPLICATION_ID,
+                       NULL);
+}
+
+int
+main (int argc, char *argv[])
+{
+  GApplication *application;
+  int status;
+
+  /* Load the compiled GSettings schema
+     - from PKGDATADIR (so that it works after "make install"),
+     - from the current directory (so that it works in the build directory,
+       before "make install").  */
+  g_setenv ("GSETTINGS_SCHEMA_DIR", PKGDATADIR G_SEARCHPATH_SEPARATOR_S ".",
+            FALSE);
+
+  /* Initializations.  */
+  textdomain ("hello-c-gnome3");
+  bindtextdomain ("hello-c-gnome3", LOCALEDIR);
+
+  /* Create application.  */
+  application = G_APPLICATION (hello_application_new ());
+
+  /* Start the application.  */
+  status = g_application_run (application, argc, argv);
+  g_object_unref (application);
+
+  return status;
+}
diff --git a/gettext-tools/examples/hello-c-gnome3/hello2.desktop.in.in b/gettext-tools/examples/hello-c-gnome3/hello2.desktop.in.in
new file mode 100644 (file)
index 0000000..5ab5be5
--- /dev/null
@@ -0,0 +1,6 @@
+[Desktop Entry]
+Type=Application
+Name=Hello
+Comment=Hello, world!
+StartupNotify=true
+Exec=@bindir@/hello2
diff --git a/gettext-tools/examples/hello-c-gnome3/hello2.gresource.xml b/gettext-tools/examples/hello-c-gnome3/hello2.gresource.xml
new file mode 100644 (file)
index 0000000..4a65f40
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This file is in the public domain. -->
+<gresources>
+  <gresource prefix="/org/gnu/gettext/examples/hello">
+    <file preprocess="xml-stripblanks">hello2.ui</file>
+  </gresource>
+</gresources>
similarity index 88%
rename from gettext-tools/examples/hello-c-gnome3/hello.gschema.xml
rename to gettext-tools/examples/hello-c-gnome3/hello2.gschema.xml
index 18d7c85070d0bffd9b64f9d80845e6e5051a1260..63e1c6a13ad4473f1b1edfad788431a2f1560f82 100644 (file)
@@ -2,7 +2,7 @@
 <!-- This file is in the public domain. -->
 <schemalist>
   <schema path="/org/gnu/gettext/examples/hello/"
-          id="org.gnu.gettext.examples.hello">
+          id="org.gnu.gettext.examples.hello2">
     <key name="use-markup" type="b">
       <default>true</default>
       <summary>Use XML markup</summary>
diff --git a/gettext-tools/examples/hello-c-gnome3/hello2.ui b/gettext-tools/examples/hello-c-gnome3/hello2.ui
new file mode 100644 (file)
index 0000000..b2d13b0
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This file is in the public domain. -->
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="HelloApplicationWindow" parent="GtkApplicationWindow">
+    <property name="title" translatable="yes">Example Application</property>
+    <property name="default-width">600</property>
+    <property name="default-height">400</property>
+    <child>
+      <object class="GtkBox" id="panel">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkAlignment" id="alignment">
+            <property name="visible">True</property>
+            <property name="xalign">0.5</property>
+            <property name="yalign">0.5</property>
+            <property name="xscale">0</property>
+            <property name="yscale">0</property>
+            <property name="vexpand">True</property>
+            <child>
+              <object class="GtkLabel" id="label">
+                <property name="visible">True</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkHButtonBox" id="buttonbar">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkButton" id="button">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Update text</property>
+                <property name="use_stock">False</property>
+              </object>
+              <packing>
+                <property name="pack-type">end</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
index 6b9fd92cca289ddbcdef4911efcf4516627883d1..9f16cea4364ca4ea042565522fa30b9a57514ccd 100644 (file)
@@ -5,4 +5,7 @@
 hello.c
 hello.desktop.in.in
 hello.ui
-hello.gschema.xml
+hello2.c
+hello2.desktop.in.in
+hello2.ui
+hello2.gschema.xml
index e724e267b0fae2afb08f762f58dd6457fadc5f0e..12ddbc1017fa65d82c6fbdedf977311d1623e7a1 100644 (file)
@@ -24,8 +24,11 @@ POTFILES = \
   hello-c-gnome2/hello.c \
   hello-c-gnome3/hello.c \
   hello-c-gnome3/hello.desktop.in.in \
-  hello-c-gnome3/hello.gschema.xml \
   hello-c-gnome3/hello.ui \
+  hello-c-gnome3/hello2.c \
+  hello-c-gnome3/hello2.desktop.in.in \
+  hello-c-gnome3/hello2.ui \
+  hello-c-gnome3/hello2.gschema.xml \
   hello-c++/hello.cc \
   hello-c++20/hello.cc \
   hello-c++-qt/hello.cc \