- Change language_pack name to input_method_config, Language pack is going to

be somthing else
- Fix Some memory problems in e_intl
- Add methods for reading and writing the configuration from an Eet
- Add a program used for creating and editing the input method config


SVN revision: 17690
This commit is contained in:
stffrdhrn 2005-10-19 23:34:17 +00:00 committed by stffrdhrn
parent bc72254585
commit c74d477ef7
4 changed files with 338 additions and 38 deletions

View File

@ -13,7 +13,8 @@ bin_PROGRAMS = \
enlightenment \
enlightenment_remote \
enlightenment_eapp \
enlightenment_eapp_cache_gen
enlightenment_eapp_cache_gen \
enlightenment_imc
ENLIGHTENMENTHEADERS = \
e.h \
@ -202,6 +203,12 @@ $(enlightenment_src)
enlightenment_eapp_cache_gen_LDFLAGS = @e_libs@ @dlopen_libs@
enlightenment_imc_SOURCES = \
e.h \
e_imc_main.c \
$(enlightenment_src)
enlightenment_imc_LDFLAGS = @e_libs@ @dlopen_libs@
installed_headersdir = $(prefix)/include/enlightenment
installed_headers_DATA = $(ENLIGHTENMENTHEADERS)

217
src/bin/e_imc_main.c Normal file
View File

@ -0,0 +1,217 @@
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#include "e.h"
#include <errno.h>
extern int errno;
static void _e_help(void);
/* externally accessible functions */
int
main(int argc, char **argv)
{
int i = 0;
int valid_args = 0;
int write_ops = 0;
Eet_File *ef = NULL;
E_Input_Method_Config *write_imc = NULL;
E_Input_Method_Config *read_imc = NULL;
int del_name = 0;
int del_exe = 0;
char *file = NULL;
char *set_name = NULL;
char *set_exe = NULL;
char *set_gtk_im_module = NULL;
char *set_qt_im_module = NULL;
char *set_xmodifiers = NULL;
int list = 0;
/* handle some command-line parameters */
for (i = 1; i < argc; i++)
{
if ((!strcmp(argv[i], "-set-name")) && (i < (argc - 1)))
{
i++;
set_name = argv[i];
valid_args++;
write_ops++;
}
else if ((!strcmp(argv[i], "-set-exe")) && (i < (argc - 1)))
{
i++;
set_exe = argv[i];
valid_args++;
write_ops++;
}
else if ((!strcmp(argv[i], "-set-gtk-im-module")) && (i < (argc - 1)))
{
i++;
set_gtk_im_module = argv[i];
valid_args++;
write_ops++;
}
else if ((!strcmp(argv[i], "-set-qt-im-module")) && (i < (argc - 1)))
{
i++;
set_qt_im_module = argv[i];
valid_args++;
write_ops++;
}
else if ((!strcmp(argv[i], "-set-xmodifiers")) && (i < (argc - 1)))
{
i++;
set_xmodifiers = argv[i];
valid_args++;
write_ops++;
}
else if ((!strcmp(argv[i], "-del-all")))
{
del_name = 1;
del_exe = 1;
valid_args++;
write_ops++;
}
else if ((!strcmp(argv[i], "-del-name")))
{
del_name = 1;
valid_args++;
write_ops++;
}
else if ((!strcmp(argv[i], "-del-exe")))
{
del_exe = 1;
valid_args++;
write_ops++;
}
else if ((!strcmp(argv[i], "-h")) ||
(!strcmp(argv[i], "-help")) ||
(!strcmp(argv[i], "--h")) ||
(!strcmp(argv[i], "--help")))
{
_e_help();
exit(0);
}
else if ((!strcmp(argv[i], "-list")))
{
list = 1;
valid_args++;
}
else
file = argv[i];
}
if (!file)
{
printf("ERROR: no file specified!\n");
_e_help();
exit(0);
}
if (valid_args == 0) {
printf("ERROR: no valid arguments!\n");
_e_help();
exit(0);
}
eet_init();
e_intl_init();
if (write_ops != 0 && ecore_file_exists(file))
{
ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
}
else if (write_ops != 0)
{
ef = eet_open(file, EET_FILE_MODE_WRITE);
}
else
{
ef = eet_open(file, EET_FILE_MODE_READ);
}
if (!ef)
{
printf("ERROR: cannot open file %s for READ/WRITE (%d:%s)\n", file, errno, strerror(errno));
return -1;
}
/* If File Exists, Try to read imc */
read_imc = e_intl_input_method_config_read (ef);
/* else create new imc */
if (write_ops != 0)
{
int write_ok;
write_imc = malloc(sizeof(E_Input_Method_Config));
write_imc->version = E_INTL_INPUT_METHOD_CONFIG_VERSION;
if (read_imc == NULL)
{
write_imc->e_im_name = NULL;
write_imc->gtk_im_module = NULL;
write_imc->qt_im_module = NULL;
write_imc->xmodifiers = NULL;
write_imc->e_im_exec = NULL;
}
else
{
write_imc->e_im_name = read_imc->e_im_name;
write_imc->gtk_im_module = read_imc->gtk_im_module;
write_imc->qt_im_module = read_imc->qt_im_module;
write_imc->xmodifiers = read_imc->xmodifiers;
write_imc->e_im_exec = read_imc->e_im_exec;
}
if (set_name != NULL)
write_imc->e_im_name = set_name;
if (set_gtk_im_module != NULL)
write_imc->gtk_im_module = set_gtk_im_module;
if (set_qt_im_module != NULL)
write_imc->qt_im_module = set_qt_im_module;
if (set_xmodifiers != NULL)
write_imc->xmodifiers = set_xmodifiers;
if (set_exe != NULL)
write_imc->e_im_exec = set_exe;
/* write imc to file */
write_ok = e_intl_input_method_config_write (ef, write_imc);
}
if (list)
{
printf("Config File List:\n");
printf("Config Version:\t%d\n", read_imc->version);
printf("Config Name:\t%s\n", read_imc->e_im_name);
printf("Command Line:\t%s\n", read_imc->e_im_exec);
printf("gtk_im_module:\t%s\n", read_imc->gtk_im_module);
printf("qt_im_module:\t%s\n", read_imc->qt_im_module);
printf("xmodifiers:\t%s\n", read_imc->xmodifiers);
}
e_intl_input_method_config_free(read_imc);
E_FREE(write_imc);
eet_close(ef);
e_intl_shutdown();
eet_shutdown();
/* just return 0 to keep the compiler quiet */
return 0;
}
static void
_e_help(void)
{
printf("OPTIONS:\n"
" -set-name NAME Set the application name\n"
" -set-exe EXE Set the application execute line\n"
" -set-gtk-im-module Set the gtk_im_module env var\n"
" -set-qt-im-module Set the qt_im_module env var\n"
" -set-xmodifiers Set the xmodifiers env var\n"
" -del-name Delete the application name\n"
" -del-exe Delete the application execute line\n"
" -list List Contents of Input Method Config file\n"
);
}

View File

@ -17,12 +17,14 @@ static char *_e_intl_orig_lang = NULL;
static char *_e_intl_language = NULL;
static Evas_List *_e_intl_languages = NULL;
static char *_e_intl_orig_gtk_im_module_file = NULL;
static char *_e_intl_orig_xmodifiers = NULL;
static char *_e_intl_orig_qt_im_module = NULL;
static char *_e_intl_orig_gtk_im_module = NULL;
static char *_e_intl_input_method = NULL;
static Evas_List *_e_intl_input_methods = NULL;
static Ecore_Exe *_e_intl_input_method_exec = NULL;
static Eet_Data_Descriptor *_e_intl_input_method_config_edd = NULL;
#define ADD_LANG(lang) _e_intl_languages = evas_list_append(_e_intl_languages, lang)
#define ADD_IM(method) _e_intl_input_methods = evas_list_append(_e_intl_input_methods, method)
@ -31,7 +33,7 @@ int
e_intl_init(void)
{
char *s;
E_Language_Pack *elp;
E_Input_Method_Config *imc;
if (_e_intl_languages) return 1;
@ -76,6 +78,15 @@ e_intl_init(void)
ADD_LANG("sv_SV.UTF-8");
ADD_LANG("nb_NO.UTF-8");
_e_intl_input_method_config_edd = E_CONFIG_DD_NEW("input_method_config", E_Input_Method_Config);
E_CONFIG_VAL(_e_intl_input_method_config_edd, E_Input_Method_Config, version, INT);
E_CONFIG_VAL(_e_intl_input_method_config_edd, E_Input_Method_Config, e_im_name, STR);
E_CONFIG_VAL(_e_intl_input_method_config_edd, E_Input_Method_Config, gtk_im_module, STR);
E_CONFIG_VAL(_e_intl_input_method_config_edd, E_Input_Method_Config, qt_im_module, STR);
E_CONFIG_VAL(_e_intl_input_method_config_edd, E_Input_Method_Config, xmodifiers, STR);
E_CONFIG_VAL(_e_intl_input_method_config_edd, E_Input_Method_Config, e_im_exec, STR);
if ((s = getenv("LC_MESSAGES"))) _e_intl_orig_lc_messages = strdup(s);
if ((s = getenv("LANGUAGE"))) _e_intl_orig_language = strdup(s);
if ((s = getenv("LC_ALL"))) _e_intl_orig_lc_all = strdup(s);
@ -84,33 +95,30 @@ e_intl_init(void)
if ((s = getenv("GTK_IM_MODULE"))) _e_intl_orig_gtk_im_module = strdup(s);
if ((s = getenv("QT_IM_MODULE"))) _e_intl_orig_qt_im_module = strdup(s);
if ((s = getenv("XMODIFIERS"))) _e_intl_orig_xmodifiers = strdup(s);
if ((s = getenv("GTK_IM_MODULE_FILE"))) _e_intl_orig_gtk_im_module_file = strdup(s);
/* Exception: NULL == use LANG. this will get setup in e_config */
e_intl_language_set(NULL);
elp = malloc(sizeof(E_Language_Pack));
elp->version = 1;
elp->e_im_name = strdup("scim");
elp->gtk_im_module = strdup("scim");
elp->qt_im_module = strdup("scim");
elp->xmodifiers = strdup("@im=SCIM");
elp->e_im_exec = strdup("scim");
elp->gtk_im_module_file = NULL;
imc = malloc(sizeof(E_Input_Method_Config));
imc->version = E_INTL_INPUT_METHOD_CONFIG_VERSION;
imc->e_im_name = strdup("scim");
imc->gtk_im_module = strdup("scim");
imc->qt_im_module = strdup("scim");
imc->xmodifiers = strdup("@im=SCIM");
imc->e_im_exec = strdup("scim");
ADD_IM(elp);
ADD_IM(imc);
elp = malloc(sizeof(E_Language_Pack));
elp->version = 1;
elp->e_im_name = strdup("uim");
elp->gtk_im_module = strdup("uim");
elp->qt_im_module = strdup("uim");
elp->xmodifiers = strdup("@im=uim");
elp->gtk_im_module_file = NULL;
elp->e_im_exec = strdup("uim-xim");
imc = malloc(sizeof(E_Input_Method_Config));
imc->version = E_INTL_INPUT_METHOD_CONFIG_VERSION;
imc->e_im_name = strdup("uim");
imc->gtk_im_module = strdup("uim");
imc->qt_im_module = strdup("uim");
imc->xmodifiers = strdup("@im=uim");
imc->e_im_exec = strdup("uim-xim");
ADD_IM(elp);
ADD_IM(imc);
return 1;
}
@ -123,7 +131,22 @@ e_intl_shutdown(void)
E_FREE(_e_intl_orig_language);
E_FREE(_e_intl_orig_lc_all);
E_FREE(_e_intl_orig_lang);
E_FREE(_e_intl_orig_gtk_im_module);
E_FREE(_e_intl_orig_qt_im_module);
E_FREE(_e_intl_orig_xmodifiers);
evas_list_free(_e_intl_languages);
while (_e_intl_input_methods)
{
E_Input_Method_Config *imc;
imc = _e_intl_input_methods->data;
_e_intl_input_methods = evas_list_remove_list(_e_intl_input_methods, _e_intl_input_methods);
e_intl_input_method_config_free(imc);
}
E_CONFIG_DD_FREE(_e_intl_input_method_config_edd);
return 1;
}
@ -212,7 +235,7 @@ e_intl_language_list(void)
void
e_intl_input_method_set(const char *method)
{
E_Language_Pack *elp;
E_Input_Method_Config *imc;
Evas_List *next;
if (_e_intl_input_method) free(_e_intl_input_method);
@ -222,7 +245,6 @@ e_intl_input_method_set(const char *method)
e_util_env_set("GTK_IM_MODULE", _e_intl_orig_gtk_im_module);
e_util_env_set("QT_IM_MODULE", _e_intl_orig_qt_im_module);
e_util_env_set("XMODIFIERS", _e_intl_orig_xmodifiers);
e_util_env_set("GTk_IM_MODULE_FILE", _e_intl_orig_gtk_im_module_file);
}
if (method)
@ -230,17 +252,16 @@ e_intl_input_method_set(const char *method)
_e_intl_input_method = strdup(method);
for (next = _e_intl_input_methods; next; next = next->next)
{
elp = next->data;
if (!strcmp(elp->e_im_name, _e_intl_input_method))
imc = next->data;
if (!strcmp(imc->e_im_name, _e_intl_input_method))
{
e_util_env_set("GTK_IM_MODULE", elp->gtk_im_module);
e_util_env_set("QT_IM_MODULE", elp->qt_im_module);
e_util_env_set("XMODIFIERS", elp->xmodifiers);
e_util_env_set("GTk_IM_MODULE_FILE", elp->gtk_im_module_file);
if (elp->e_im_exec != NULL)
e_util_env_set("GTK_IM_MODULE", imc->gtk_im_module);
e_util_env_set("QT_IM_MODULE", imc->qt_im_module);
e_util_env_set("XMODIFIERS", imc->xmodifiers);
if (imc->e_im_exec != NULL)
{
/* FIXME: first check ok exec availability */
ecore_exe_run(elp->e_im_exec, NULL);
_e_intl_input_method_exec = ecore_exe_run(imc->e_im_exec, NULL);
}
break;
}
@ -263,16 +284,57 @@ e_intl_input_method_list(void)
{
Evas_List *im_list;
Evas_List *next;
E_Language_Pack *elp;
E_Input_Method_Config *imc;
im_list = NULL;
for (next = _e_intl_input_methods; next; next = next->next)
{
elp = next->data;
im_list = evas_list_append(im_list, strdup(elp->e_im_name));
imc = next->data;
im_list = evas_list_append(im_list, strdup(imc->e_im_name));
}
return im_list;
}
/* Get the input method configuration from the file */
E_Input_Method_Config *
e_intl_input_method_config_read (Eet_File * imc_file)
{
E_Input_Method_Config *imc;
imc = NULL;
if (imc_file)
{
imc = (E_Input_Method_Config *) eet_data_read(imc_file, _e_intl_input_method_config_edd, "imc");
}
return imc;
}
/* Write the input method configuration to the file */
int
e_intl_input_method_config_write (Eet_File * imc_file, E_Input_Method_Config * imc)
{
int ok = 0;
if (imc_file)
{
ok = eet_data_write(imc_file, _e_intl_input_method_config_edd, "imc", imc, 0);
}
return ok;
}
void
e_intl_input_method_config_free (E_Input_Method_Config *imc)
{
if (imc != NULL)
{
E_FREE(imc->e_im_name);
E_FREE(imc->gtk_im_module);
E_FREE(imc->qt_im_module);
E_FREE(imc->xmodifiers);
E_FREE(imc->e_im_exec);
E_FREE(imc);
}
}

View File

@ -9,20 +9,32 @@
#define _(str) gettext(str)
#define d_(str, dom) dgettext(PACKAGE dom, str)
typedef struct _E_Input_Method_Config E_Input_Method_Config;
typedef struct _E_Language_Pack E_Language_Pack;
#else
#ifndef E_INTL_H
#define E_INTL_H
#define E_INTL_LANGUAGE_PACK_VERSION 1
#define E_INTL_INPUT_METHOD_CONFIG_VERSION 1
struct _E_Language_Pack
{
int version;
char *e_lp_name;
char *lang;
char *input_method;
char *font_fallbacks;
};
struct _E_Input_Method_Config
{
int version;
char *e_im_name;
char *gtk_im_module;
char *qt_im_module;
char *xmodifiers;
char *gtk_im_module_file;
char *e_im_exec;
};
@ -36,6 +48,8 @@ EAPI const Evas_List *e_intl_language_list(void);
EAPI void e_intl_input_method_set(const char *method);
EAPI const char *e_intl_input_method_get(void);
EAPI Evas_List *e_intl_input_method_list(void);
EAPI E_Input_Method_Config *e_intl_input_method_config_read (Eet_File *imc_file);
EAPI int e_intl_input_method_config_write (Eet_File *imc_file, E_Input_Method_Config *imc);
EAPI void e_intl_input_method_config_free (E_Input_Method_Config *imc);
#endif
#endif