From: Daiki Ueno Date: Wed, 16 Apr 2014 08:50:17 +0000 (+0900) Subject: examples: Utilize GSettings in hello-c-gnome3 example X-Git-Tag: v0.19~108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0628149f2ea9fd01bf72b2f95a5f486d904270e8;p=thirdparty%2Fgettext.git examples: Utilize GSettings in hello-c-gnome3 example --- diff --git a/gettext-tools/examples/Makefile.am b/gettext-tools/examples/Makefile.am index 4f9f340a6..5014318cb 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 0dc68b80b..512608a29 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 e51d4d82c..ddacfb0bf 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 d079e8d75..a642ac622 100644 --- a/gettext-tools/examples/hello-c-gnome3/hello.c +++ b/gettext-tools/examples/hello-c-gnome3/hello.c @@ -13,6 +13,10 @@ # include #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 4d2c27810..000000000 --- a/gettext-tools/examples/hello-c-gnome3/hello.gresource.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - hello.ui - - diff --git a/gettext-tools/examples/hello-c-gnome3/m4/Makefile.am b/gettext-tools/examples/hello-c-gnome3/m4/Makefile.am index dc63c0f25..000cd06f0 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 ce9a16e1b..83808dfb3 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 50abd132e..59f811ce1 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 \