Blob Blame History Raw
2009-09-15  Akira TAGOH  <tagoh@redhat.com>

	* data/xinputinfo.sh.in: output the value if the configuration is
	the script or not.

	* tests/main.c (init): set IMSETTINGS_HELPER_PATH to xinputinfo.sh
	working without the real installation.

	* tests/rhbz_523349.c: new testcase.

	* imsettings/imsettings-info.c (imsettings_info_notify_properties):
	Add a reference of the environment variable to get the unit testing
	working.
	(_IMSETTINGS_DEFUNC_PROPERTY): update the variables before looking
	if the configuration is based on the script. (rhbz#523349)
	(imsettings_info_is_script): new.

Index: imsettings/imsettings-info.c
===================================================================
--- imsettings/imsettings-info.c	(リビジョン 342)
+++ imsettings/imsettings-info.c	(リビジョン 343)
@@ -74,6 +74,7 @@
 	gboolean  is_system_default;
 	gboolean  is_user_default;
 	gboolean  is_xim;
+	gboolean  is_script;
 } IMSettingsInfoPrivate;
 
 enum {
@@ -94,6 +95,7 @@
 	PROP_SHORT_DESC,
 	PROP_LONG_DESC,
 	PROP_ICON,
+	PROP_IS_SCRIPT,
 	PROP_IS_SYSTEM_DEFAULT,
 	PROP_IS_USER_DEFAULT,
 	PROP_IS_XIM,
@@ -181,6 +183,7 @@
 		"SHORT_DESC=",
 		"LONG_DESC=",
 		"ICON=",
+		"IMSETTINGS_IS_SCRIPT=",
 		NULL
 	};
 	static const gchar *properties[] = {
@@ -197,6 +200,7 @@
 		"short_desc",
 		"long_desc",
 		"icon",
+		"is_script",
 		NULL
 	};
 	gint i;
@@ -204,7 +208,7 @@
 	guint prop;
 	struct stat st;
 	IMSettingsInfoPrivate *priv = IMSETTINGS_INFO_GET_PRIVATE (object);
-	gchar *lang;
+	gchar *lang, *path;
 
 	cmd = g_string_new(NULL);
 	str = g_string_new(NULL);
@@ -212,7 +216,13 @@
 		lang = g_strdup_printf("LANG=%s ", priv->language);
 	else
 		lang = g_strdup("");
-	xinputinfo = g_build_filename(XINPUTINFO_PATH, "xinputinfo.sh", NULL);
+	if (g_getenv("IMSETTINGS_HELPER_PATH") != NULL) {
+		path = g_strdup(g_getenv("IMSETTINGS_HELPER_PATH"));
+	} else {
+		path = g_strdup(XINPUTINFO_PATH);
+	}
+	xinputinfo = g_build_filename(path, "xinputinfo.sh", NULL);
+	g_free(path);
 	g_string_append_printf(cmd, "%s. %s %s", lang, xinputinfo, filename);
 
 	g_free(xinputinfo);
@@ -268,6 +278,14 @@
 								 properties[prop - (PROP_GTK_IMM - PROP_0)], str->str,
 								 NULL);
 						    break;
+					    case PROP_IS_SCRIPT:
+						    g_object_set(object,
+								 "is_script",
+								 (g_ascii_strcasecmp(str->str, "true") == 0 ||
+								  g_ascii_strcasecmp(str->str, "yes") == 0 ||
+								  g_ascii_strcasecmp(str->str, "1") == 0),
+								 NULL);
+						    break;
 					    case PROP_IGNORE_FLAG:
 						    g_object_set(object,
 								 "ignore",
@@ -412,6 +430,9 @@
 			    }
 		    } G_STMT_END;
 		    break;
+	    case PROP_IS_SCRIPT:
+		    _set_bool_prop(is_script);
+		    break;
 	    case PROP_IS_SYSTEM_DEFAULT:
 		    _set_bool_prop(is_system_default);
 		    break;
@@ -489,6 +510,9 @@
 	    case PROP_ICON:
 		    _get_str_prop(icon_file);
 		    break;
+	    case PROP_IS_SCRIPT:
+		    _get_bool_prop(is_script);
+		    break;
 	    case PROP_IS_SYSTEM_DEFAULT:
 		    _get_bool_prop(is_system_default);
 		    break;
@@ -735,6 +759,12 @@
 							    _("Icon filename to be used on GUI"),
 							    ICONDIR G_DIR_SEPARATOR_S "imsettings-unknown.png",
 							    G_PARAM_READWRITE));
+	g_object_class_install_property(object_class, PROP_IS_SCRIPT,
+					g_param_spec_boolean("is_script",
+							     "Script",
+							     "Whether or not the configuration is written in the shell script",
+							     FALSE,
+							     G_PARAM_READWRITE));
 	g_object_class_install_property(object_class, PROP_IS_SYSTEM_DEFAULT,
 					g_param_spec_boolean("is_system_default",
 							     _("System Default"),
@@ -807,6 +837,11 @@
 		g_return_val_if_fail (IMSETTINGS_IS_INFO (info), (_v_)); \
 									\
 		priv = IMSETTINGS_INFO_GET_PRIVATE (info);		\
+		if (imsettings_info_is_script(info)) {			\
+			/* reload the configuration before referencing. */ \
+			g_object_set(info, "filename",			\
+				     priv->filename, NULL);		\
+		}							\
 									\
 		return priv->_m_;					\
 	}
@@ -863,6 +898,18 @@
 }
 
 gboolean
+imsettings_info_is_script(IMSettingsInfo *info)
+{
+	IMSettingsInfoPrivate *priv;
+
+	g_return_val_if_fail (IMSETTINGS_IS_INFO (info), FALSE);
+
+	priv = IMSETTINGS_INFO_GET_PRIVATE (info);
+
+	return priv->is_script;
+}
+
+gboolean
 imsettings_info_is_system_default(IMSettingsInfo *info)
 {
 	IMSettingsInfoPrivate *priv;
Index: imsettings/imsettings-info.h
===================================================================
--- imsettings/imsettings-info.h	(リビジョン 342)
+++ imsettings/imsettings-info.h	(リビジョン 343)
@@ -66,6 +66,7 @@
 const gchar    *imsettings_info_get_long_desc         (IMSettingsInfo       *info);
 const gchar    *imsettings_info_get_icon_file         (IMSettingsInfo       *info);
 const gchar    *imsettings_info_get_supported_language(IMSettingsInfo       *info);
+gboolean        imsettings_info_is_script             (IMSettingsInfo       *info);
 gboolean        imsettings_info_is_visible            (IMSettingsInfo       *info);
 gboolean        imsettings_info_is_system_default     (IMSettingsInfo       *info);
 gboolean        imsettings_info_is_user_default       (IMSettingsInfo       *info);
Index: data/xinputinfo.sh.in
===================================================================
--- data/xinputinfo.sh.in	(リビジョン 342)
+++ data/xinputinfo.sh.in	(リビジョン 343)
@@ -20,6 +20,14 @@
 # Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
+function is_script() {
+    if [ "x$(sed -re '/^[ 	]?*[a-zA-Z0-9_]+=.*/{d};/[ 	]?*#.*/{d}' $1)" = "x" ]; then
+	return 1
+    else
+	return 0
+    fi
+}
+
 USER_XINPUTRC="$HOME/.xinputrc"
 SYS_XINPUTRC="@XINPUTRC_PATH@/xinputrc"
 
@@ -42,13 +50,16 @@
 
 if [ $# -gt 0 ]; then
     source $1
+    IMSETTINGS_FILENAME=$1
 else
     [ -z "$IMSETTINGS_DISABLE_USER_XINPUTRC" ] && IMSETTINGS_DISABLE_USER_XINPUTRC=no
 
     if [ -r "$USER_XINPUTRC" -a "x$IMSETTINGS_DISABLE_USER_XINPUTRC" = "xno" ]; then
 	source "$USER_XINPUTRC"
+	IMSETTINGS_FILENAME=$USER_XINPUTRC
     elif [ -r "$SYS_XINPUTRC" ]; then
 	source "$SYS_XINPUTRC"
+	IMSETTINGS_FILENAME=$SYS_XINPUTRC
     fi
 fi
 
@@ -58,6 +69,12 @@
 # For backward compatibility
 [ -z "$IMSETTINGS_IGNORE_ME" ] && IMSETTINGS_IGNORE_ME=$IM_CHOOSER_IGNORE_ME
 
+if is_script $IMSETTINGS_FILENAME; then
+    IMSETTINGS_IS_SCRIPT=1
+else
+    IMSETTINGS_IS_SCRIPT=0
+fi
+
 cat <<EOF
 AUXILIARY_PROGRAM=$AUXILIARY_PROGRAM
 AUXILIARY_ARGS="`echo $AUXILIARY_ARGS | sed -e "s/\\\\([\\"']\\\\)/\\\\\\\\\\\\1/g"`"
@@ -72,4 +89,5 @@
 XIM=$XIM
 XIM_PROGRAM=$XIM_PROGRAM
 XIM_ARGS="`echo $XIM_ARGS | sed -e "s/\\\\([\\"']\\\\)/\\\\\\\\\\\\1/g"`"
+IMSETTINGS_IS_SCRIPT=$IMSETTINGS_IS_SCRIPT
 EOF