From 1c48e7e5fef4c027a34f9312ff17b2ab1f6d4640 Mon Sep 17 00:00:00 2001 From: Akira TAGOH <akira@tagoh.org> Date: Thu, 22 Nov 2012 15:22:59 +0900 Subject: [PATCH] Added another backend module for MATE 1.5 support --- backends/Makefile.am | 2 +- backends/mate-gsettings/Makefile.am | 47 +++++++++++ backends/mate-gsettings/mate-gsettings-module.c | 108 ++++++++++++++++++++++++ configure.ac | 5 +- tests/run.sh | 2 +- 5 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 backends/mate-gsettings/Makefile.am create mode 100644 backends/mate-gsettings/mate-gsettings-module.c diff --git a/backends/Makefile.am b/backends/Makefile.am index e60905c..125dbee 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -5,7 +5,7 @@ if ENABLE_GCONF SUBDIRS += gconf endif if ENABLE_GSETTINGS -SUBDIRS += gsettings +SUBDIRS += gsettings mate-gsettings endif if ENABLE_LXDE SUBDIRS += lxde diff --git a/backends/mate-gsettings/Makefile.am b/backends/mate-gsettings/Makefile.am new file mode 100644 index 0000000..7c9a96e --- /dev/null +++ b/backends/mate-gsettings/Makefile.am @@ -0,0 +1,47 @@ +## +# Global definitions +NULL = +INCLUDES = \ + -DIMSETTINGS_LOCALEDIR="\"$(datadir)/locale\"" \ + -I$(top_srcdir)/imsettings \ + $(GSETTINGS_CFLAGS) \ + $(NULL) +LIBS = \ + @LDFLAGS@ \ + $(top_builddir)/imsettings/libimsettings.la \ + $(GSETTINGS_LIBS) \ + $(NULL) +EXTRA_DIST = \ + $(NULL) + + +## +# Local definitions + +## +# Local Rules + +## +# Target platform +imsettingsdir = $(IMSETTINGS_MODULEDIR) +imsettings_LTLIBRARIES = \ + libimsettings-mate-gsettings.la \ + $(NULL) +# +libimsettings_mate_gsettings_la_SOURCES = \ + mate-gsettings-module.c \ + $(NULL) +libimsettings_mate_gsettings_la_CFLAGS = \ + -DG_LOG_DOMAIN="\"IMSettings-MATE-GSettings backend\"" \ + $(CFLAGS) \ + $(NULL) +libimsettings_mate_gsettings_la_LDFLAGS = \ + -avoid-version \ + -module \ + $(LDFLAGS) \ + $(NULL) +libimsettings_mate_gsettings_la_LIBADD = \ + $(LDADDS) \ + $(NULL) + +-include $(top_srcdir)/git.mk diff --git a/backends/mate-gsettings/mate-gsettings-module.c b/backends/mate-gsettings/mate-gsettings-module.c new file mode 100644 index 0000000..354b003 --- /dev/null +++ b/backends/mate-gsettings/mate-gsettings-module.c @@ -0,0 +1,108 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * mate-gsettings-module.c + * Copyright (C) 2011-2012 Red Hat, Inc. All rights reserved. + * + * Authors: + * Akira TAGOH <tagoh@redhat.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gio/gio.h> +#include <glib/gi18n-lib.h> +#include "imsettings-info.h" +#include "imsettings-utils.h" + +#define IMMODULE_SCHEMA "org.mate.interface" +#define IMMODULE_KEY "gtk-im-module" + +gboolean _check_schema (void); +void module_switch_im(IMSettingsInfo *info); +gchar *module_dump_im (void); + +/*< private >*/ +gboolean +_check_schema(void) +{ + const gchar * const *schemas = g_settings_list_schemas(); + gint i; + + for (i = 0; schemas[i] != NULL; i++) { + if (g_strcmp0(schemas[i], IMMODULE_SCHEMA) == 0) + return TRUE; + } + g_warning("Settings schema '%s' is not installed.", + IMMODULE_SCHEMA); + + return FALSE; +} + +/*< public >*/ +void +module_switch_im(IMSettingsInfo *info) +{ + GSettings *settings = NULL; + const gchar *gtkimm = imsettings_info_get_gtkimm(info); + gchar *val = NULL; + + if (!gtkimm || gtkimm[0] == 0) { + g_warning("Invalid gtk immodule in: %s", + imsettings_info_get_filename(info)); + goto finalize; + } + if (!_check_schema()) + goto finalize; +#ifdef ENABLE_FALLBACK_IM + val = g_strdup_printf("%s:xim", gtkimm); +#else + val = g_strdup(gtkimm); +#endif + settings = g_settings_new(IMMODULE_SCHEMA); + if (!g_settings_set_string(settings, + IMMODULE_KEY, + val)) { + g_warning("Unable to set %s to %s", IMMODULE_KEY, IMMODULE_SCHEMA); + goto finalize; + } + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, + "Setting up %s as gtk+ immodule", + val); + finalize: + g_free(val); + if (settings) + g_object_unref(settings); +} + +gchar * +module_dump_im(void) +{ + GSettings *settings; + gchar *retval = NULL; + + if (_check_schema()) { + settings = g_settings_new(IMMODULE_SCHEMA); + retval = g_settings_get_string(settings, + IMMODULE_KEY); + if (settings) + g_object_unref(settings); + } + + return retval; +} diff --git a/configure.ac b/configure.ac index cf3c900..75a05dc 100644 --- a/configure.ac +++ b/configure.ac @@ -112,7 +112,7 @@ PKG_CHECK_MODULES(GSETTINGS, gio-2.0 >= $GIO_REQUIRED, PKG_CHECK_MODULES(LXDE, glib-2.0, [use_lxde="yes"], [use_lxde="no"]) -# for mate backend +# for mate backend (mateconf based) PKG_CHECK_MODULES(MATE, mateconf-2.0, [use_mate="yes"], [use_mate="no"]) @@ -320,6 +320,7 @@ AC_CONFIG_FILES([ backends/gconf/Makefile backends/gsettings/Makefile backends/lxde/Makefile + backends/mate-gsettings/Makefile backends/mateconf/Makefile backends/qt/Makefile backends/xfce/Makefile @@ -358,7 +359,7 @@ if test "x$use_gconf" = "xyes"; then echo " CFLAGS: $GSETTINGS_CFLAGS" echo " LDFLAGS: $GSETTINGS_LIBS" fi -echo " MATE support: $use_mate" +echo " MATE (< 1.5) support: $use_mate" if test "x$use_mate" = "xyes"; then echo " CFLAGS: $MATE_CFLAGS" echo " LDFLAGS: $MATE_LIBS" -- 1.7.11.7