diff options
author | Daiki Ueno <ueno@gnu.org> | 2014-04-16 17:50:17 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2014-04-16 18:10:43 +0900 |
commit | 0628149f2ea9fd01bf72b2f95a5f486d904270e8 (patch) | |
tree | c64177325b9d9318e117954fd2aeedc4e32e07b3 /gettext-tools/examples | |
parent | 43be67d5278994ef7819232cc8414e213e3db71f (diff) | |
download | external_gettext-0628149f2ea9fd01bf72b2f95a5f486d904270e8.zip external_gettext-0628149f2ea9fd01bf72b2f95a5f486d904270e8.tar.gz external_gettext-0628149f2ea9fd01bf72b2f95a5f486d904270e8.tar.bz2 |
examples: Utilize GSettings in hello-c-gnome3 example
Diffstat (limited to 'gettext-tools/examples')
-rw-r--r-- | gettext-tools/examples/Makefile.am | 3 | ||||
-rw-r--r-- | gettext-tools/examples/hello-c-gnome3/Makefile.am | 19 | ||||
-rw-r--r-- | gettext-tools/examples/hello-c-gnome3/configure.ac | 5 | ||||
-rw-r--r-- | gettext-tools/examples/hello-c-gnome3/hello.c | 41 | ||||
-rw-r--r-- | gettext-tools/examples/hello-c-gnome3/hello.gresource.xml | 6 | ||||
-rw-r--r-- | gettext-tools/examples/hello-c-gnome3/m4/Makefile.am | 3 | ||||
-rw-r--r-- | gettext-tools/examples/hello-c-gnome3/po/POTFILES.in | 2 | ||||
-rw-r--r-- | gettext-tools/examples/po/Makefile.am | 2 |
8 files changed, 60 insertions, 21 deletions
diff --git a/gettext-tools/examples/Makefile.am b/gettext-tools/examples/Makefile.am index 4f9f340..5014318 100644 --- a/gettext-tools/examples/Makefile.am +++ b/gettext-tools/examples/Makefile.am @@ -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 \ diff --git a/gettext-tools/examples/hello-c-gnome3/Makefile.am b/gettext-tools/examples/hello-c-gnome3/Makefile.am index 0dc68b8..512608a 100644 --- a/gettext-tools/examples/hello-c-gnome3/Makefile.am +++ b/gettext-tools/examples/hello-c-gnome3/Makefile.am @@ -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 diff --git a/gettext-tools/examples/hello-c-gnome3/configure.ac b/gettext-tools/examples/hello-c-gnome3/configure.ac index e51d4d8..ddacfb0 100644 --- a/gettext-tools/examples/hello-c-gnome3/configure.ac +++ b/gettext-tools/examples/hello-c-gnome3/configure.ac @@ -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]) diff --git a/gettext-tools/examples/hello-c-gnome3/hello.c b/gettext-tools/examples/hello-c-gnome3/hello.c index d079e8d..a642ac6 100644 --- a/gettext-tools/examples/hello-c-gnome3/hello.c +++ b/gettext-tools/examples/hello-c-gnome3/hello.c @@ -13,6 +13,10 @@ # 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 index 4d2c278..0000000 --- a/gettext-tools/examples/hello-c-gnome3/hello.gresource.xml +++ /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> diff --git a/gettext-tools/examples/hello-c-gnome3/m4/Makefile.am b/gettext-tools/examples/hello-c-gnome3/m4/Makefile.am index dc63c0f..000cd06 100644 --- a/gettext-tools/examples/hello-c-gnome3/m4/Makefile.am +++ b/gettext-tools/examples/hello-c-gnome3/m4/Makefile.am @@ -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 diff --git a/gettext-tools/examples/hello-c-gnome3/po/POTFILES.in b/gettext-tools/examples/hello-c-gnome3/po/POTFILES.in index ce9a16e..83808df 100644 --- a/gettext-tools/examples/hello-c-gnome3/po/POTFILES.in +++ b/gettext-tools/examples/hello-c-gnome3/po/POTFILES.in @@ -5,3 +5,5 @@ hello.c hello.desktop.in.in hello.ui +org.gnu.gettext.examples.hello.gschema.xml + diff --git a/gettext-tools/examples/po/Makefile.am b/gettext-tools/examples/po/Makefile.am index 50abd13..59f811c 100644 --- a/gettext-tools/examples/po/Makefile.am +++ b/gettext-tools/examples/po/Makefile.am @@ -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 \ |