]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
examples: Utilize GSettings in hello-c-gnome3 example
authorDaiki Ueno <ueno@gnu.org>
Wed, 16 Apr 2014 08:50:17 +0000 (17:50 +0900)
committerDaiki Ueno <ueno@gnu.org>
Wed, 16 Apr 2014 09:10:43 +0000 (18:10 +0900)
gettext-tools/examples/Makefile.am
gettext-tools/examples/hello-c-gnome3/Makefile.am
gettext-tools/examples/hello-c-gnome3/configure.ac
gettext-tools/examples/hello-c-gnome3/hello.c
gettext-tools/examples/hello-c-gnome3/hello.gresource.xml [deleted file]
gettext-tools/examples/hello-c-gnome3/m4/Makefile.am
gettext-tools/examples/hello-c-gnome3/po/POTFILES.in
gettext-tools/examples/po/Makefile.am

index 4f9f340a6a7da4afc786a126119907bc03fb8c83..5014318cb3ae2103713f2903334277bea8b8006d 100644 (file)
@@ -56,7 +56,8 @@ EXAMPLESFILES = \
   hello-c-gnome3/autoclean.sh \
   hello-c-gnome3/hello.c \
   hello-c-gnome3/hello.desktop.in.in \
-  hello-c-gnome3/hello.gresource.xml \
+  hello-c-gnome3/org.gnu.gettext.examples.hello.gschema.xml \
+  hello-c-gnome3/org.gnu.gettext.examples.hello.gresource.xml \
   hello-c-gnome3/hello.ui \
   hello-c-gnome3/Makefile.am \
   hello-c-gnome3/configure.ac \
index 0dc68b80b1c11fb901c612d950904823f56cf80f..512608a29c5b72b62332ac2f7b21e032cecbb9cb 100644 (file)
@@ -25,12 +25,16 @@ AM_CPPFLAGS = $(GTK_CFLAGS)
 # Link time dependencies.
 LDADD = $(GTK_LIBS) @LIBINTL@
 
-# Compile assets into a C source and link it with the application.
-BUILT_SOURCES = resources.c
+BUILT_SOURCES = gschemas.compiled resources.c
+
+# Compile GSettings schema.
+gschemas.compiled: org.gnu.gettext.examples.hello.gschema.xml
+       $(AM_V_GEN) $(GLIB_COMPILE_SCHEMAS) .
 
-resources.c: hello.gresource.xml hello.ui
-       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $(srcdir)/hello.gresource.xml \
-               --target=$@ --sourcedir=$(srcdir) --generate-source
+# Compile assets into a C source and link it with the application.
+resources.c: org.gnu.gettext.examples.hello.gresource.xml hello.ui
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ \
+               --sourcedir=$(srcdir) --generate-source
 
 # Merge translations into a Desktop Entry file.
 desktopdir = $(datadir)/applications
@@ -47,5 +51,6 @@ hello.desktop: hello.desktop.in
 CLEANFILES = $(BUILT_SOURCES) hello.desktop.in $(desktop_DATA)
 
 # Additional files to be distributed.
-EXTRA_DIST = autogen.sh autoclean.sh \
-       hello.ui hello.desktop.in.in hello.gresource.xml
+EXTRA_DIST = autogen.sh autoclean.sh hello.ui hello.desktop.in.in \
+       org.gnu.gettext.examples.hello.gschema.xml \
+       org.gnu.gettext.examples.hello.gresource.xml
index e51d4d82c970ca6f3f3f963255cd312bf3896416..ddacfb0bf3d46d27f7faa2f95d2522be7a55a414 100644 (file)
@@ -29,6 +29,11 @@ AS_IF([test -z "$GLIB_COMPILE_RESOURCES"], [
   AC_MSG_ERROR([can't find glib-compile-resources])
 ])
 
+AC_PATH_PROG(GLIB_COMPILE_SCHEMAS, [glib-compile-schemas])
+AS_IF([test -z "$GLIB_COMPILE_SCHEMAS"], [
+  AC_MSG_ERROR([can't find glib-compile-schemas])
+])
+
 AC_PATH_PROG([PKG_CONFIG], [pkg-config])
 AS_IF([test -z "$PKG_CONFIG"], [
   AC_MSG_ERROR([can't find pkg-config])
index d079e8d75a3192be7668db09dfb24e49fc1862ab..a642ac622c31d2e9b7c92024efd89b511082815c 100644 (file)
 # include <unistd.h>
 #endif
 
+#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"
+
 static void
 quit_callback (GtkWidget *widget, void *data)
 {
@@ -20,6 +24,7 @@ quit_callback (GtkWidget *widget, void *data)
 }
 
 /* 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),                           \
@@ -45,6 +50,7 @@ struct _HelloApplicationWindow
   GtkApplicationWindow parent;
   GtkWidget *label2;
   GtkWidget *button;
+  GSettings *settings;
 };
 
 struct _HelloApplicationWindowClass
@@ -65,13 +71,29 @@ hello_application_window_init (HelloApplicationWindow *window)
                            getpid ());
   gtk_label_set_label (GTK_LABEL (window->label2), label);
   g_free (label);
+
+  window->settings = g_settings_new (GSETTINGS_SCHEMA);
+  g_settings_bind (window->settings, "label-sensitive",
+                   window->label2, "sensitive",
+                   G_SETTINGS_BIND_DEFAULT);
+}
+
+static void
+hello_application_window_dispose (GObject *object)
+{
+  HelloApplicationWindow *window = HELLO_APPLICATION_WINDOW (object);
+  g_clear_object (&window->settings);
 }
 
 static void
 hello_application_window_class_init (HelloApplicationWindowClass *klass)
 {
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->dispose = hello_application_window_dispose;
+
   gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
-                                               "/org/gnu/gettext/examples/hello/hello.ui");
+                                               UI_PATH);
   gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass),
                                         HelloApplicationWindow, label2);
   gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass),
@@ -126,18 +148,29 @@ static HelloApplication *
 hello_application_new (void)
 {
   return g_object_new (HELLO_TYPE_APPLICATION,
-                       "application-id", "org.gnu.gettext-examples.hello",
+                       "application-id", APPLICATION_ID,
                        NULL);
 }
 
 int
 main (int argc, char *argv[])
 {
+  GApplication *application;
+  int status;
+
+  /* Load the GSettings schema from the current directory.  */
+  g_setenv ("GSETTINGS_SCHEMA_DIR", ".", FALSE);
+
   /* Initializations.  */
   textdomain ("hello-c-gnome3");
   bindtextdomain ("hello-c-gnome3", LOCALEDIR);
 
+  /* Create application.  */
+  application = G_APPLICATION (hello_application_new ());
+
   /* Start the application.  */
-  return g_application_run (G_APPLICATION (hello_application_new ()),
-                            argc, argv);
+  status = g_application_run (application, argc, argv);
+  g_object_unref (application);
+
+  return status;
 }
diff --git a/gettext-tools/examples/hello-c-gnome3/hello.gresource.xml b/gettext-tools/examples/hello-c-gnome3/hello.gresource.xml
deleted file mode 100644 (file)
index 4d2c278..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<gresources>
-  <gresource prefix="/org/gnu/gettext/examples/hello">
-    <file preprocess="xml-stripblanks">hello.ui</file>
-  </gresource>
-</gresources>
index dc63c0f257e3606ebc085ae2d9f7d8ba0fd9bf9f..000cd06f0863b7a089db5578a61421cc5b2ad0de 100644 (file)
@@ -2,5 +2,4 @@ EXTRA_DIST = \
   codeset.m4 gettext.m4 glibc2.m4 glibc21.m4 iconv.m4 intdiv0.m4 \
   inttypes_h.m4 inttypes-pri.m4 lcmessage.m4 lib-ld.m4 lib-link.m4 \
   lib-prefix.m4 lock.m4 nls.m4 po.m4 progtest.m4 stdint_h.m4 \
-  uintmax_t.m4 visibility.m4 \
-  gnome.m4 gnome-gnorba-check.m4 gnome-orbit-check.m4
+  uintmax_t.m4 visibility.m4
index ce9a16e1bb4a47756f5c6695822ee1a383f2dc5e..83808dfb30ee466c7da1308a75759f1b14082bbe 100644 (file)
@@ -5,3 +5,5 @@
 hello.c
 hello.desktop.in.in
 hello.ui
+org.gnu.gettext.examples.hello.gschema.xml
+
index 50abd132e7676b6b5d783533ce7239e827edc939..59f811ce15e3ad86b3dfbf75327f3499be48bdda 100644 (file)
@@ -24,7 +24,7 @@ POTFILES = \
   hello-c-gnome/hello.c \
   hello-c-gnome3/hello.c \
   hello-c-gnome3/hello.desktop.in.in \
-  hello-c-gnome3/hello.gresource.xml \
+  hello-c-gnome3/org.gnu.gettext.examples.hello.gschema.xml \
   hello-c-gnome3/hello.ui \
   hello-c++/hello.cc \
   hello-c++-qt/hello.cc \