diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | configure.in | 9 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/curconfig.c | 95 | ||||
-rw-r--r-- | src/curconfig.h | 5 | ||||
-rw-r--r-- | src/internal.h | 4 | ||||
-rw-r--r-- | src/librcc.c | 79 | ||||
-rw-r--r-- | src/librcc.h | 93 | ||||
-rw-r--r-- | src/lngconfig.c | 46 | ||||
-rw-r--r-- | src/opt.c | 21 | ||||
-rw-r--r-- | src/opt.h | 5 | ||||
-rw-r--r-- | src/rccconfig.c | 58 | ||||
-rw-r--r-- | src/rccconfig.h | 3 | ||||
-rw-r--r-- | src/rccenca.c | 2 | ||||
-rw-r--r-- | src/rcclist.c | 59 | ||||
-rw-r--r-- | src/rcclist.h | 5 | ||||
-rw-r--r-- | src/xml.c | 4 | ||||
-rw-r--r-- | ui/Makefile.am | 12 | ||||
-rw-r--r-- | ui/gtk.c | 203 | ||||
-rw-r--r-- | ui/internal.h | 71 | ||||
-rw-r--r-- | ui/librccui.c | 387 | ||||
-rw-r--r-- | ui/librccui.h | 46 | ||||
-rw-r--r-- | ui/rccnames.c | 31 | ||||
-rw-r--r-- | ui/rccnames.h | 9 |
25 files changed, 1133 insertions, 124 deletions
diff --git a/Makefile.am b/Makefile.am index 1f097f7..618d546 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,3 @@ -SUBDIRS = src +SUBDIRS = src ui -EXTRA_DIST = example librcd.spec
\ No newline at end of file +EXTRA_DIST = librcd.spec
\ No newline at end of file @@ -6,3 +6,6 @@ Library for autoconversion of charsets to/from UTF-8. engine = auto engine selected - which is selected current - resolves default values + +# ToDo +# XML files with additional languages
\ No newline at end of file diff --git a/configure.in b/configure.in index bb8966a..4cf04d4 100644 --- a/configure.in +++ b/configure.in @@ -43,6 +43,13 @@ XML_INCLUDES="\`xml-config --cflags\`" AC_SUBST(XML_LIBS) AC_SUBST(XML_INCLUDES) +AC_PATH_PROG(GTK_CONFIG, gtk-config, no) +AM_CONDITIONAL(HAVE_GTK, [ test $GTK_CONFIG != no ]) +GTK_LIBS="\`gtk-config --libs\`" +GTK_INCLUDES="\`gtk-config --cflags\`" +AC_SUBST(GTK_LIBS) +AC_SUBST(GTK_INCLUDES) + AC_CHECK_HEADER(librcd.h, [AC_CHECK_LIB(rcd, rcdGetRussianCharset, [ RCD_LIBS="-lrcd" RCD_INCLUDES="" @@ -75,4 +82,4 @@ AC_C_CONST dnl Checks for library functions. AC_CHECK_FUNCS(strcasecmp strncasecmp strdup) -AC_OUTPUT(src/Makefile examples/Makefile librcc.spec) +AC_OUTPUT(src/Makefile ui/Makefile examples/Makefile librcc.spec) diff --git a/src/Makefile.am b/src/Makefile.am index 01a7da1..72cf0ec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,8 +2,11 @@ lib_LTLIBRARIES = librcc.la librcc_la_SOURCES = librcc.c \ rcclocale.c rcclocale.h \ lng.c lng.h \ + opt.c opt.h \ lngconfig.c lngconfig.h \ + curconfig.c curconfig.h \ rccconfig.c rccconfig.h \ + rcclist.c rcclist.h \ plugin.c plugin.h \ rccenca.c rccenca.h \ engine.c engine.h \ diff --git a/src/curconfig.c b/src/curconfig.c new file mode 100644 index 0000000..4a26a33 --- /dev/null +++ b/src/curconfig.c @@ -0,0 +1,95 @@ +#include <stdio.h> +#include "internal.h" + +const char *rccGetEngineName(rcc_context ctx, rcc_engine_id engine_id) { + if (!ctx) return NULL; + return rccConfigGetEngineName(ctx->current_config, engine_id); +} + +const char *rccGetCharsetName(rcc_context ctx, rcc_charset_id charset_id) { + if (!ctx) return NULL; + return rccConfigGetCharsetName(ctx->current_config, charset_id); +} + +const char *rccGetAutoCharsetName(rcc_context ctx, rcc_charset_id charset_id) { + if (!ctx) return NULL; + return rccConfigGetAutoCharsetName(ctx->current_config, charset_id); +} + +rcc_engine_id rccGetEngineByName(rcc_context ctx, const char *name) { + if (!ctx) return (rcc_engine_id)-1; + return rccConfigGetEngineByName(ctx->current_config, name); +} + +rcc_charset_id rccGetCharsetByName(rcc_context ctx, const char *name) { + if (!ctx) return (rcc_charset_id)-1; + return rccConfigGetCharsetByName(ctx->current_config, name); +} + +rcc_charset_id rccGetAutoCharsetByName(rcc_context ctx, const char *name) { + if (!ctx) return (rcc_charset_id)-1; + return rccConfigGetAutoCharsetByName(ctx->current_config, name); +} + +rcc_engine_id rccGetSelectedEngine(rcc_context ctx) { + if (!ctx) return (rcc_engine_id)-1; + return rccConfigGetSelectedEngine(ctx->current_config); +} + +const char *rccGetSelectedEngineName(rcc_context ctx) { + if (!ctx) return NULL; + return rccConfigGetSelectedEngineName(ctx->current_config); +} + +rcc_engine_id rccGetCurrentEngine(rcc_context ctx) { + if (!ctx) return (rcc_engine_id)-1; + return rccConfigGetCurrentEngine(ctx->current_config); +} + +const char *rccGetCurrentEngineName(rcc_context ctx) { + if (!ctx) return NULL; + return rccConfigGetCurrentEngineName(ctx->current_config); +} + +rcc_charset_id rccGetSelectedCharset(rcc_context ctx, rcc_class_id class_id) { + return rccConfigGetSelectedCharset(ctx->current_config, class_id); +} + +const char *rccGetSelectedCharsetName(rcc_context ctx, rcc_class_id class_id) { + if (!ctx) return NULL; + return rccConfigGetSelectedCharsetName(ctx->current_config, class_id); +} + +rcc_charset_id rccGetCurrentCharset(rcc_context ctx, rcc_class_id class_id) { + return rccConfigGetCurrentCharset(ctx->current_config, class_id); +} + +const char *rccGetCurrentCharsetName(rcc_context ctx, rcc_class_id class_id) { + if (!ctx) return NULL; + return rccConfigGetCurrentCharsetName(ctx->current_config, class_id); +} + +int rccSetEngine(rcc_context ctx, rcc_engine_id engine_id) { + if (!ctx) return -1; + return rccConfigSetEngine(ctx->current_config, engine_id); +} + +int rccSetCharset(rcc_context ctx, rcc_class_id class_id, rcc_charset_id charset_id) { + if (!ctx) return -1; + return rccConfigSetCharset(ctx->current_config, class_id, charset_id); +} + +int rccSetEngineByName(rcc_context ctx, const char *name) { + if (!ctx) return -1; + return rccConfigSetEngineByName(ctx->current_config, name); +} + +int rccSetCharsetByName(rcc_context ctx, rcc_class_id class_id, const char *name) { + if (!ctx) return -1; + return rccConfigSetCharsetByName(ctx->current_config, class_id, name); +} + +rcc_charset_id rccGetLocaleCharset(rcc_context ctx, const char *locale_variable) { + if (!ctx) return (rcc_charset_id)-1; + return rccConfigGetLocaleCharset(ctx->current_config, locale_variable); +} diff --git a/src/curconfig.h b/src/curconfig.h new file mode 100644 index 0000000..f1ffaff --- /dev/null +++ b/src/curconfig.h @@ -0,0 +1,5 @@ +#ifndef _RCC_CUR_CONFIG_H +#define _RCC_CUR_CONFIG_H + + +#endif /* _RCC_CUR_CONFIG_H */ diff --git a/src/internal.h b/src/internal.h index 7d40547..c943384 100644 --- a/src/internal.h +++ b/src/internal.h @@ -11,6 +11,8 @@ struct rcc_context_t { char locale_variable[RCC_MAX_VARIABLE_CHARS+1]; rcc_language_alias_list aliases; + + rcc_option_value options[RCC_MAX_OPTIONS]; unsigned int max_languages; unsigned int n_languages; @@ -33,6 +35,8 @@ struct rcc_context_t { unsigned char configure; rcc_language_config current_config; rcc_language_id current_language; + + unsigned int configuration_lock; }; typedef struct rcc_context_t rcc_context_s; diff --git a/src/librcc.c b/src/librcc.c index 56c357b..684e76a 100644 --- a/src/librcc.c +++ b/src/librcc.c @@ -6,9 +6,11 @@ #include "internal.h" #include "rccconfig.h" #include "rccenca.h" +#include "rcclist.h" int rccInit() { + /*DS: Load addition languages from config! */ return rccEncaInit(); } @@ -16,7 +18,7 @@ void rccFree() { rccEncaFree(); } -rcc_context rccInitContext(rcc_init_flags flags, unsigned int max_languages, unsigned int max_classes, const char *locale) { +rcc_context rccCreateContext(rcc_init_flags flags, unsigned int max_languages, unsigned int max_classes, const char *locale) { int err; unsigned int i; @@ -109,7 +111,11 @@ rcc_context rccInitContext(rcc_init_flags flags, unsigned int max_languages, uns rccRegisterLanguage(ctx, rcc_default_languages); ctx->current_config = NULL; } - + + for (i=0;i<RCC_MAX_OPTIONS;i++) + ctx->options[i] = 0; + + ctx->configuration_lock = 0; ctx->configure = 1; return ctx; @@ -163,8 +169,24 @@ void rccFreeContext(rcc_context ctx) { } } +int rccLockConfiguration(rcc_context ctx, unsigned int lock_code) { + if (!ctx) return -1; + if (ctx->configuration_lock) return -3; + ctx->configuration_lock = lock_code; + return 0; +} + +int rccUnlockConfiguration(rcc_context ctx, unsigned int lock_code) { + if (!ctx) return -1; + if (ctx->configuration_lock != lock_code) return -3; + ctx->configuration_lock = 0; + return 0; +} + rcc_language_id rccRegisterLanguage(rcc_context ctx, rcc_language *language) { if ((!ctx)||(!language)) return -1; + if (ctx->configuration_lock) return -3; + if (ctx->n_languages == ctx->max_languages) return -2; ctx->languages[ctx->n_languages++] = language; ctx->languages[ctx->n_languages] = NULL; @@ -213,7 +235,9 @@ rcc_alias_id rccRegisterLanguageAlias(rcc_context ctx, rcc_language_alias *alias rcc_class_id rccRegisterClass(rcc_context ctx, rcc_class *cl) { if ((!ctx)||(!cl)) return -1; + if (ctx->configuration_lock) return -3; if (ctx->n_classes == ctx->max_classes) return -2; + ctx->configure = 1; ctx->classes[ctx->n_languages++] = cl; ctx->classes[ctx->n_languages] = NULL; @@ -227,57 +251,6 @@ rcc_class_type rccGetClassType(rcc_context ctx, rcc_class_id class_id) { return ctx->classes[class_id]->class_type; } -static rcc_language_ptr *rccGetLanguageList(rcc_context ctx) { - if (!ctx) return NULL; - return ctx->languages; -} - -static rcc_charset *rccGetCharsetList(rcc_context ctx, rcc_language_id language_id) { - if ((!ctx)||(language_id<0)||(language_id>=ctx->n_languages)) return NULL; - return ctx->languages[language_id]->charsets; -} - -static rcc_engine_ptr *rccGetEngineList(rcc_context ctx, rcc_language_id language_id) { - if ((!ctx)||(language_id<0)||(language_id>=ctx->n_languages)) return NULL; - return ctx->languages[language_id]->engines; -} - -static rcc_charset *rccGetCurrentCharsetList(rcc_context ctx) { - rcc_language_id language_id; - - if (!ctx) return NULL; - - language_id = rccGetCurrentLanguage(ctx); - if (language_id<0) return NULL; - - return rccGetCharsetList(ctx, language_id); -} - -static rcc_engine_ptr *rccGetCurrentEngineList(rcc_context ctx) { - rcc_language_id language_id; - - if (!ctx) return NULL; - - language_id = rccGetCurrentLanguage(ctx); - if (language_id<0) return NULL; - - return rccGetEngineList(ctx, language_id); -} - -static rcc_charset *rccGetCurrentAutoCharsetList(rcc_context ctx) { - rcc_language_id language_id; - rcc_engine_id engine_id; - - if (!ctx) return NULL; - - language_id = rccGetCurrentLanguage(ctx); - engine_id = rccGetCurrentEngine(ctx); - if ((language_id<0)||(engine_id<0)) return NULL; - - - return ctx->languages[language_id]->engines[engine_id]->charsets; -} - int rccConfigure(rcc_context ctx) { unsigned int i; diff --git a/src/librcc.h b/src/librcc.h index 0ca55a4..2e06911 100644 --- a/src/librcc.h +++ b/src/librcc.h @@ -1,5 +1,5 @@ -#ifndef LIBRCC_H -#define LIBRCC_H +#ifndef _LIBRCC_H +#define _LIBRCC_H /******************************************************************************* ***************************** Global Defines *********************************** @@ -44,9 +44,12 @@ void rccFree(); *******************************************************************************/ typedef unsigned int rcc_init_flags; #define RCC_DEFAULT_CONFIGURATION 1 -rcc_context rccInitContext(rcc_init_flags flags, unsigned int max_languages, unsigned int max_classes, const char *locale); +rcc_context rccCreateContext(rcc_init_flags flags, unsigned int max_languages, unsigned int max_classes, const char *locale); void rccFreeContext(rcc_context ctx); +int rccLockConfiguration(rcc_context ctx, unsigned int lock_code); +int rccUnlockConfiguration(rcc_context ctx, unsigned int lock_code); + /******************************************************************************* ******************* Altering Language Configuaration *************************** *******************************************************************************/ @@ -73,7 +76,6 @@ typedef rcc_engine_ptr rcc_engine_list[RCC_MAX_ENGINES+1]; /* Language */ struct rcc_language_t { const char *sn; - const char *name; rcc_charset_list charsets; rcc_engine_list engines; }; @@ -90,6 +92,12 @@ typedef struct rcc_language_alias_t rcc_language_alias; typedef rcc_language_alias *rcc_language_alias_ptr; typedef rcc_language_alias_ptr rcc_language_alias_list[RCC_MAX_ALIASES+1]; +struct rcc_language_name_t { + const char *sn; + const char *name; +}; +typedef struct rcc_language_name_t rcc_language_name; + rcc_language_id rccRegisterLanguage(rcc_context ctx, rcc_language *language); rcc_charset_id rccLanguageRegisterCharset(rcc_language *language, rcc_charset charset); rcc_engine_id rccLanguageRegisterEngine(rcc_language *language, rcc_engine *engine); @@ -101,6 +109,7 @@ rcc_alias_id rccRegisterLanguageAlias(rcc_context ctx, rcc_language_alias *alias typedef enum rcc_class_type_t { RCC_CLASS_INVALID = 0, RCC_CLASS_STANDARD, + RCC_CLASS_KNOWN, RCC_CLASS_FS } rcc_class_type; typedef const struct rcc_class_t rcc_class; @@ -109,6 +118,7 @@ struct rcc_class_t { const char *name; const char *defvalue; /* locale variable name or parrent name */ const rcc_class_type class_type; + const char *fullname; }; typedef rcc_class *rcc_class_ptr; typedef rcc_class_ptr rcc_class_list[RCC_MAX_CLASSES+1]; @@ -124,10 +134,15 @@ typedef enum rcc_option_t { RCC_LEARNING_MODE = 0, RCC_AUTODETECT_FS_TITLES, RCC_AUTODETECT_FS_NAMES, - RCC_USE_HEADERS, RCC_MAX_OPTIONS } rcc_option; +struct rcc_option_name_t { + rcc_option option; + const char *name; +}; +typedef struct rcc_option_name_t rcc_option_name; + /* lng.c */ const char *rccGetLanguageName(rcc_context ctx, rcc_language_id language_id); rcc_language_id rccGetLanguageByName(rcc_context ctx, const char *name); @@ -141,6 +156,10 @@ const char *rccGetCurrentLanguageName(rcc_context ctx); int rccSetLanguage(rcc_context ctx, rcc_language_id language_id); int rccSetLanguageByName(rcc_context ctx, const char *name); +/* opt.c */ +rcc_option_value rccGetOption(rcc_context ctx, rcc_option option); +int rccSetOption(rcc_context ctx, rcc_option option, rcc_option_value value); + /* lngconfig.c */ int rccConfigInit(rcc_language_config config, rcc_context ctx); int rccConfigFree(rcc_language_config config); @@ -164,41 +183,51 @@ rcc_charset_id rccConfigGetSelectedCharset(rcc_language_config config, rcc_class const char *rccConfigGetSelectedCharsetName(rcc_language_config config, rcc_class_id class_id); rcc_charset_id rccConfigGetCurrentCharset(rcc_language_config config, rcc_class_id class_id); const char *rccConfigGetCurrentCharsetName(rcc_language_config config, rcc_class_id class_id); -rcc_option_value rccConfigGetOption(rcc_language_config config, rcc_option option); int rccConfigSetEngine(rcc_language_config config, rcc_engine_id engine_id); int rccConfigSetCharset(rcc_language_config config, rcc_class_id class_id, rcc_charset_id charset_id); int rccConfigSetEngineByName(rcc_language_config config, const char *name); int rccConfigSetCharsetByName(rcc_language_config config, rcc_class_id class_id, const char *name); -int rccConfigSetOption(rcc_language_config config, rcc_option option, rcc_option_value value); rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char *locale_variable); /* curconfig.c */ -#define rccGetEngineName(ctx, engine_id) rccConfigGetEngineName(ctx->current_config, engine_id) -#define rccGetCharsetName(ctx, charset_id) rccConfigGetCharsetName(ctx->current_config, charset_id) -#define rccGetAutoCharsetName(ctx, charset_id) rccConfigGetAutoCharsetName(ctx->current_config, charset_id) -#define rccGetEngineByName(ctx, name) rccConfigGetEngineByName(ctx->current_config, name) -#define rccGetCharsetByName(ctx, name) rccConfigGetCharsetByName(ctx->current_config, name) -#define rccGetAutoCharsetByName(ctx, name) rccConfigGetAutoCharsetByName(ctx->current_config, name) - -#define rccGetSelectedEngine(ctx) rccConfigGetSelectedEngine(ctx->current_config) -#define rccGetSelectedEngineName(ctx) rccConfigGetSelectedEngineName(ctx->current_config) -#define rccGetCurrentEngine(ctx) rccConfigGetCurrentEngine(ctx->current_config) -#define rccGetCurrentEngineName(ctx) rccConfigGetCurrentEngineName(ctx->current_config) -#define rccGetSelectedCharset(ctx,class_id) rccConfigGetSelectedCharset(ctx->current_config, class_id) -#define rccGetSelectedCharsetName(ctx,class_id) rccConfigGetSelectedCharsetName(ctx->current_config, class_id) -#define rccGetCurrentCharset(ctx,class_id) rccConfigGetCurrentCharset(ctx->current_config, class_id) -#define rccGetCurrentCharsetName(ctx,class_id) rccConfigGetCurrentCharsetName(ctx->current_config, class_id) -#define rccGetOption(ctx, option) rccConfigGetOption(ctx->current_config, option) - -#define rccSetEngine(ctx, engine_id) rccConfigSetEngine(ctx->current_config, engine_id) -#define rccSetCharset(ctx, class_id, charset_id) rccConfigSetCharset(ctx->current_config, class_id, charset_id) -#define rccSetOption(ctx,option,value) rccConfigSetOption(ctx->current_config, option, value) -#define rccSetEngineByName(ctx, name) rccConfigSetEngineByName(ctx->current_config, name) -#define rccSetCharsetByName(ctx, class_id, name) rccConfigSetCharsetByName(ctx->current_config, class_id, name) - -#define rccGetLocaleCharset(ctx, locale_variable) rccConfigGetLocaleCharset(ctx->current_config, locale_variable) +const char *rccGetEngineName(rcc_context ctx, rcc_engine_id engine_id); +const char *rccGetCharsetName(rcc_context ctx, rcc_charset_id charset_id); +const char *rccGetAutoCharsetName(rcc_context ctx, rcc_charset_id charset_id); + +rcc_engine_id rccGetEngineByName(rcc_context ctx, const char *name); +rcc_charset_id rccGetCharsetByName(rcc_context ctx, const char *name); +rcc_charset_id rccGetAutoCharsetByName(rcc_context ctx, const char *name); + +rcc_engine_id rccGetSelectedEngine(rcc_context ctx); +const char *rccGetSelectedEngineName(rcc_context ctx); +rcc_engine_id rccGetCurrentEngine(rcc_context ctx); +const char *rccGetCurrentEngineName(rcc_context ctx); +rcc_charset_id rccGetSelectedCharset(rcc_context ctx, rcc_class_id class_id); +const char *rccGetSelectedCharsetName(rcc_context ctx, rcc_class_id class_id); +rcc_charset_id rccGetCurrentCharset(rcc_context ctx, rcc_class_id class_id); +const char *rccGetCurrentCharsetName(rcc_context ctx, rcc_class_id class_id); + +int rccSetEngine(rcc_context ctx, rcc_engine_id engine_id); +int rccSetCharset(rcc_context ctx, rcc_class_id class_id, rcc_charset_id charset_id); +int rccSetEngineByName(rcc_context ctx, const char *name); +int rccSetCharsetByName(rcc_context ctx, rcc_class_id class_id, const char *name); + +rcc_charset_id rccGetLocaleCharset(rcc_context ctx, const char *locale_variable); + +/******************************************************************************* +************************ Language Configuaration ******************************* +*******************************************************************************/ +/* rcclist.c */ +rcc_language_ptr *rccGetLanguageList(rcc_context ctx); +rcc_charset *rccGetCharsetList(rcc_context ctx, rcc_language_id language_id); +rcc_engine_ptr *rccGetEngineList(rcc_context ctx, rcc_language_id language_id); +rcc_charset *rccGetCurrentCharsetList(rcc_context ctx); +rcc_engine_ptr *rccGetCurrentEngineList(rcc_context ctx); +rcc_charset *rccGetCurrentAutoCharsetList(rcc_context ctx); +rcc_class_ptr *rccGetClassList(rcc_context ctx); + /******************************************************************************* ************************ RCC_STRING Manipulations ****************************** @@ -238,4 +267,4 @@ int rccLoad(rcc_context ctx); } #endif -#endif /* LIBRCC_H */ +#endif /* _LIBRCC_H */ diff --git a/src/lngconfig.c b/src/lngconfig.c index b7c40c4..5de0fae 100644 --- a/src/lngconfig.c +++ b/src/lngconfig.c @@ -116,8 +116,6 @@ int rccConfigInit(rcc_language_config config, rcc_context ctx) { config->language = NULL; config->charset = charsets; config->engine = -1; - for (i=0;i<RCC_MAX_OPTIONS;i++) - config->options[i] = 0; return 0; } @@ -161,7 +159,6 @@ rcc_language_config rccGetCurrentConfig(rcc_context ctx) { return rccGetConfig(ctx, language_id); } - rcc_engine_id rccConfigGetSelectedEngine(rcc_language_config config) { if (!config) return -1; @@ -270,11 +267,6 @@ const char *rccConfigGetCurrentCharsetName(rcc_language_config config, rcc_class return rccConfigGetCharsetName(config, charset_id); } -rcc_option_value rccConfigGetOption(rcc_language_config config, rcc_option option) { - if ((!config)||(option<0)||(option>=RCC_MAX_OPTIONS)) return -1; - - return config->options[option]; -} int rccConfigSetEngine(rcc_language_config config, rcc_engine_id engine_id) { unsigned int i; @@ -325,16 +317,6 @@ int rccConfigSetCharsetByName(rcc_language_config config, rcc_class_id class_id, return rccConfigSetCharset(config, class_id, charset_id); } -int rccConfigSetOption(rcc_language_config config, rcc_option option, rcc_option_value value) { - if ((!config)||(option>=RCC_MAX_OPTIONS)) return -1; - if (config->options[option] != value) { - if (config->ctx->current_config == config) config->ctx->configure = 1; - config->options[option]=value; - } - - return 0; -} - rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char *locale_variable) { int err; rcc_charset *charsets; @@ -359,3 +341,31 @@ rcc_charset_id rccConfigGetLocaleCharset(rcc_language_config config, const char return rccConfigGetCharsetByName(config, stmp); } + +/* +int rccConfigInit(rcc_language_config config, rcc_context ctx) { + for (i=0;i<RCC_MAX_OPTIONS;i++) + config->options[i] = 0; +} + +rcc_option_value rccConfigGetOption(rcc_language_config config, rcc_option option) { + if ((!config)||(option<0)||(option>=RCC_MAX_OPTIONS)) return -1; + + return config->options[option]; +} + +int rccConfigSetOption(rcc_language_config config, rcc_option option, rcc_option_value value) { + if ((!config)||(option>=RCC_MAX_OPTIONS)) return -1; + if (config->options[option] != value) { + if (config->ctx->current_config == config) config->ctx->configure = 1; + config->options[option]=value; + } + + return 0; +} + +rcc_option_value rccConfigGetOption(rcc_language_config config, rcc_option option); +int rccConfigSetOption(rcc_language_config config, rcc_option option, rcc_option_value value); +#define rccGetOption(ctx, option) rccConfigGetOption(ctx->current_config, option) +#define rccSetOption(ctx,option,value) rccConfigSetOption(ctx->current_config, option, value) +*/ diff --git a/src/opt.c b/src/opt.c new file mode 100644 index 0000000..ec4684f --- /dev/null +++ b/src/opt.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +#include "internal.h" +#include "opt.h" + +rcc_option_value rccConfigGetOption(rcc_context ctx, rcc_option option) { + if ((!ctx)||(option<0)||(option>=RCC_MAX_OPTIONS)) return -1; + + return ctx->options[option]; +} + +int rccConfigSetOption(rcc_context ctx, rcc_option option, rcc_option_value value) { + if ((!ctx)||(option>=RCC_MAX_OPTIONS)) return -1; + + if (ctx->options[option] != value) { + ctx->configure = 1; + ctx->options[option]=value; + } + + return 0; +} diff --git a/src/opt.h b/src/opt.h new file mode 100644 index 0000000..566cf1e --- /dev/null +++ b/src/opt.h @@ -0,0 +1,5 @@ +#ifndef _RCC_OPT_H +#define _RCC_OPT_H + + +#endif /* _RCC_OPT_H */ diff --git a/src/rccconfig.c b/src/rccconfig.c index 7caabea..c77b27a 100644 --- a/src/rccconfig.c +++ b/src/rccconfig.c @@ -25,72 +25,98 @@ rcc_engine rcc_russian_engine = { }; rcc_language rcc_default_languages[] = { -{"default", "Autodetect", {"Default", NULL}, { +{"default", {"Default", NULL}, { &rcc_default_engine, NULL }}, -{"off", "Dissable", {"Default", NULL}, { +{"off", {"Default", NULL}, { &rcc_default_engine, NULL }}, -{"ru","Russian", {"Default","KOI8-R","CP1251","UTF-8","IBM866","MACCYRILLIC","ISO8859-5", NULL}, { +{"ru", {"Default","KOI8-R","CP1251","UTF-8","IBM866","MACCYRILLIC","ISO8859-5", NULL}, { &rcc_russian_engine, &rcc_default_engine, NULL }}, -{"uk","Ukrainian", {"Default","KOI8-U","CP1251","UTF-8","IBM855","MACCYRILLIC","ISO8859-5","CP1125", NULL}, { +{"uk", {"Default","KOI8-U","CP1251","UTF-8","IBM855","MACCYRILLIC","ISO8859-5","CP1125", NULL}, { &rcc_russian_engine, &rcc_default_engine, NULL }}, -{"be","Belarussian",{"Default", "UTF-8", "CP1251", "IBM866", "ISO-8859-5", "KOI8-UNI", "maccyr" "IBM855", NULL},{ +{"be", {"Default", "UTF-8", "CP1251", "IBM866", "ISO-8859-5", "KOI8-UNI", "maccyr" "IBM855", NULL},{ &rcc_default_engine, NULL }}, -{"bg","Bulgarian",{"Default", "UTF-8", "CP1251", "ISO-8859-5", "IBM855", "maccyr", "ECMA-113", NULL},{ +{"bg", {"Default", "UTF-8", "CP1251", "ISO-8859-5", "IBM855", "maccyr", "ECMA-113", NULL},{ &rcc_default_engine, NULL }}, -{"cz","Czech",{"Default", "UTF-8", "ISO-8859-2", "CP1250", "IBM852", "KEYBCS2", "macce", "KOI-8_CS_2", "CORK", NULL},{ +{"cz", {"Default", "UTF-8", "ISO-8859-2", "CP1250", "IBM852", "KEYBCS2", "macce", "KOI-8_CS_2", "CORK", NULL},{ &rcc_default_engine, NULL }}, -{"es","Estonian",{"Default", "UTF-8", "ISO-8859-4", "CP1257", "IBM775", "ISO-8859-13", "macce", "baltic", NULL},{ +{"es", {"Default", "UTF-8", "ISO-8859-4", "CP1257", "IBM775", "ISO-8859-13", "macce", "baltic", NULL},{ &rcc_default_engine, NULL }}, -{"hr","Croatian",{"Default", "UTF-8", "CP1250", "ISO-8859-2", "IBM852", "macce", "CORK", NULL},{ +{"hr", {"Default", "UTF-8", "CP1250", "ISO-8859-2", "IBM852", "macce", "CORK", NULL},{ &rcc_default_engine, NULL }}, -{"hu","Hungarian",{"Default", "UTF-8", "ISO-8859-2", "CP1250", "IBM852", "macce", "CORK", NULL},{ +{"hu", {"Default", "UTF-8", "ISO-8859-2", "CP1250", "IBM852", "macce", "CORK", NULL},{ &rcc_default_engine, NULL }}, -{"lt","Lithuanian",{"Default", "UTF-8", "CP1257", "ISO-8859-4", "IBM775", "ISO-8859-13", "macce", "baltic", NULL},{ +{"lt", {"Default", "UTF-8", "CP1257", "ISO-8859-4", "IBM775", "ISO-8859-13", "macce", "baltic", NULL},{ &rcc_default_engine, NULL }}, -{"lv","Latvian",{"Default", "UTF-8", "CP1257", "ISO-8859-4", "IBM775", "ISO-8859-13", "macce", "baltic", NULL},{ +{"lv", {"Default", "UTF-8", "CP1257", "ISO-8859-4", "IBM775", "ISO-8859-13", "macce", "baltic", NULL},{ &rcc_default_engine, NULL }}, -{"pl","Polish",{"Default", "UTF-8", "ISO-8859-2", "CP1250", "IBM852", "macce", "ISO-8859-13", "ISO-8859-16", "baltic", "CORK", NULL},{ +{"pl", {"Default", "UTF-8", "ISO-8859-2", "CP1250", "IBM852", "macce", "ISO-8859-13", "ISO-8859-16", "baltic", "CORK", NULL},{ &rcc_default_engine, NULL }}, -{"sk","Slovak",{"Default", "UTF-8", "CP1250", "ISO-8859-2", "IBM852", "KEYBCS2", "macce", "KOI-8_CS_2", "CORK", NULL},{ +{"sk", {"Default", "UTF-8", "CP1250", "ISO-8859-2", "IBM852", "KEYBCS2", "macce", "KOI-8_CS_2", "CORK", NULL},{ &rcc_default_engine, NULL }}, -{"sl","Slovenian",{"Default", "UTF-8", "ISO-8859-2", "CP1250", "IBM852", "macce", "CORK", NULL},{ +{"sl", {"Default", "UTF-8", "ISO-8859-2", "CP1250", "IBM852", "macce", "CORK", NULL},{ &rcc_default_engine, NULL }}, -{"zh","Chinese",{"Default", "UTF-8", "GB2312", "GBK", "GB18030", "BIG5", NULL},{ +{"zh", {"Default", "UTF-8", "GB2312", "GBK", "GB18030", "BIG5", NULL},{ &rcc_default_engine, NULL }}, {NULL} }; +rcc_language_name rcc_default_language_names[RCC_MAX_LANGUAGES+1] = { +{"default", "Autodetect"}, +{"off", "Dissable"}, +{"ru","Russian"}, +{"uk","Ukrainian"}, +{"be","Belarussian"}, +{"bg","Bulgarian"}, +{"cz","Czech"}, +{"es","Estonian"}, +{"hr","Croatian"}, +{"hu","Hungarian"}, +{"lt","Lithuanian"}, +{"lv","Latvian"}, +{"pl","Polish"}, +{"sk","Slovak"}, +{"sl","Slovenian"}, +{"zh","Chinese"}, +{NULL, NULL} +}; + +rcc_option_name rcc_default_option_names[] = { + { RCC_LEARNING_MODE, "Learning Mode" }, + { RCC_AUTODETECT_FS_TITLES, "Autodetect FS Encoding" }, + { RCC_AUTODETECT_FS_NAMES, "Autodetect File Names" }, + { RCC_MAX_OPTIONS, NULL} +}; diff --git a/src/rccconfig.h b/src/rccconfig.h index ac74dbe..8ca4810 100644 --- a/src/rccconfig.h +++ b/src/rccconfig.h @@ -14,4 +14,7 @@ extern rcc_engine rcc_russian_engine; extern rcc_language rcc_default_languages[]; +extern rcc_language_name rcc_default_language_names[]; +extern rcc_option_name rcc_default_option_names[]; + #endif /* _RCC_CONFIG_H */ diff --git a/src/rccenca.c b/src/rccenca.c index d01e3d8..20e1eb4 100644 --- a/src/rccenca.c +++ b/src/rccenca.c @@ -49,7 +49,7 @@ void rccEncaFreeContext(rcc_engine_context ctx) { #endif /* RCC_ENCA_SUPPORT */ } -rcc_charset_id rccEnca(rcc_engine_context ctx, char *buf, int len) { +rcc_charset_id rccEnca(rcc_engine_context ctx, const char *buf, int len) { #ifdef RCC_ENCA_SUPPORT rcc_engine_internal internal; const char *charset; diff --git a/src/rcclist.c b/src/rcclist.c new file mode 100644 index 0000000..dc26d7e --- /dev/null +++ b/src/rcclist.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include "internal.h" + +rcc_language_ptr *rccGetLanguageList(rcc_context ctx) { + if (!ctx) return NULL; + return ctx->languages; +} + +rcc_charset *rccGetCharsetList(rcc_context ctx, rcc_language_id language_id) { + if ((!ctx)||(language_id<0)||(language_id>=ctx->n_languages)) return NULL; + return ctx->languages[language_id]->charsets; +} + +rcc_engine_ptr *rccGetEngineList(rcc_context ctx, rcc_language_id language_id) { + if ((!ctx)||(language_id<0)||(language_id>=ctx->n_languages)) return NULL; + return ctx->languages[language_id]->engines; +} + +rcc_charset *rccGetCurrentCharsetList(rcc_context ctx) { + rcc_language_id language_id; + + if (!ctx) return NULL; + + language_id = rccGetCurrentLanguage(ctx); + if (language_id<0) return NULL; + + return rccGetCharsetList(ctx, language_id); +} + +rcc_engine_ptr *rccGetCurrentEngineList(rcc_context ctx) { + rcc_language_id language_id; + + if (!ctx) return NULL; + + language_id = rccGetCurrentLanguage(ctx); + if (language_id<0) return NULL; + + return rccGetEngineList(ctx, language_id); +} + +rcc_charset *rccGetCurrentAutoCharsetList(rcc_context ctx) { + rcc_language_id language_id; + rcc_engine_id engine_id; + + if (!ctx) return NULL; + + language_id = rccGetCurrentLanguage(ctx); + engine_id = rccGetCurrentEngine(ctx); + if ((language_id<0)||(engine_id<0)) return NULL; + + + return ctx->languages[language_id]->engines[engine_id]->charsets; +} + +rcc_class_ptr *rccGetClassList(rcc_context ctx) { + if (!ctx) return NULL; + + return ctx->classes; +} diff --git a/src/rcclist.h b/src/rcclist.h new file mode 100644 index 0000000..000e09c --- /dev/null +++ b/src/rcclist.h @@ -0,0 +1,5 @@ +#ifndef _RCC_LIST_H +#define _RCC_LIST_H + + +#endif /* _RCC_LIST_H */ @@ -2,11 +2,13 @@ #include "internal.h" /* pass programm name */ + +/* Load and Then Save */ +/* flock */ int rccSave(rcc_context ctx) { return 0; } -/* Load and Then Save */ int rccLoad(rcc_context ctx) { return 0; } diff --git a/ui/Makefile.am b/ui/Makefile.am new file mode 100644 index 0000000..121d2c4 --- /dev/null +++ b/ui/Makefile.am @@ -0,0 +1,12 @@ +if HAVE_GTK +lib_LTLIBRARIES = librccgtk.la +librccgtk_la_SOURCES = librccui.c \ + rccnames.c rccnames.h \ + internal.h \ + gtk.c +librccgtk_la_LIBADD = @GTK_LIBS@ ../src/librcc.la +librccgtk_la_LDFLAGS = -version-info @LIBRCC_VERSION_INFO@ +endif + +INCLUDES = -I../src @GTK_INCLUDES@ +include_HEADERS = librccui.h diff --git a/ui/gtk.c b/ui/gtk.c new file mode 100644 index 0000000..d299a8e --- /dev/null +++ b/ui/gtk.c @@ -0,0 +1,203 @@ +#include <stdio.h> +#include <gtk/gtk.h> +#include "internal.h" +#include "rccnames.h" + +rcc_ui_internal rccUiCreateInternal(rcc_ui_context ctx) { + return NULL; +} + +void rccUiFreeInternal(rcc_ui_context ctx) { +} + +rcc_ui_widget rccUiMenuCreateWidget(rcc_ui_menu_context ctx) { + return NULL; +} + +void rccUiMenuDestroyWidget(rcc_ui_menu_context ctx) { +} + +rcc_ui_id rccUiMenuGet(rcc_ui_menu_context ctx) { + GtkWidget *menu; + + if (!ctx) return (rcc_ui_id)-1; + + if (ctx->type == RCC_UI_MENU_OPTION) + return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ctx->widget)); + + menu = gtk_option_menu_get_menu(ctx->widget); + return g_list_index(GTK_MENU_SHELL(menu)->children, gtk_menu_get_active(GTK_MENU(menu))); +} + +int rccUiMenuSet(rcc_ui_menu_context ctx, rcc_ui_id id) { + if (!ctx) return -1; + + switch (ctx->type) { + case RCC_UI_MENU_OPTION: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ctx->widget),id); + break; + default: + gtk_option_menu_set_history(ctx->widget, id); + } + + return 0; +} + + +static int rccGtkMenuLanguageCB(GtkWidget * w, gpointer item) { + rccUiRestoreLanguage(((rcc_ui_menu_context)item)->uictx); +} + +int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { + unsigned int i; + + rcc_context rccctx; + rcc_ui_context uictx; + + rcc_language_config config; + rcc_language_ptr *languages; + rcc_language_id language_id; + + rcc_charset *charsets; + rcc_engine_ptr *engines; + + rcc_charset_id charset_id; + rcc_engine_id engine_id; + + GtkWidget *list, *item, *menu; + + if (!ctx) return -1; + + uictx = ctx->uictx; + rccctx = uictx->rccctx; + + switch (ctx->type) { + case RCC_UI_MENU_LANGUAGE: + list = gtk_menu_new(); + + languages=rccGetLanguageList(rccctx); + for (i=0; languages[i]; i++) { + item = gtk_menu_item_new_with_label(rccUiGetLanguageName(uictx, languages[i]->sn)); + gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(rccGtkMenuLanguageCB), ctx); + gtk_menu_append(GTK_MENU(list), item); + gtk_widget_show(item); + } + + language_id = rccGetSelectedLanguage(rccctx); + if (language_id < 0) language_id = 0; + + if (ctx->widget) menu = ctx->widget; + else { + menu = gtk_option_menu_new(); + ctx->widget = menu; + } + gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu)); + gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); + gtk_option_menu_set_history(GTK_OPTION_MENU(menu), language_id); + + return 0; + break; + case RCC_UI_MENU_CHARSET: + + list = gtk_menu_new(); + + language_id = (rcc_language_id)rccUiMenuGet(uictx->language); + charsets = rccGetCharsetList(rccctx, language_id); + + for (i=0;charsets[i];i++) { + list = gtk_menu_item_new_with_label(charsets[i]); + gtk_widget_show(item); + gtk_menu_append(GTK_MENU(list), item); + } + + if (ctx->widget) menu = ctx->widget; + else { + menu = gtk_option_menu_new(); + ctx->widget = menu; + } + + gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu)); + gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); + + config = rccGetConfig(rccctx, language_id); + charset_id = rccConfigGetSelectedCharset(config, (rcc_class_id)ctx->id); + if (charset_id < 0) charset_id = 0; + gtk_option_menu_set_history(GTK_OPTION_MENU(menu), charset_id); + break; + case RCC_UI_MENU_ENGINE: + list = gtk_menu_new(); + + language_id = (rcc_language_id)rccUiMenuGet(uictx->language); + engines = rccGetEngineList(rccctx, language_id); + for (i=0;engines[i];i++) { + list = gtk_menu_item_new_with_label(engines[i]->title); + gtk_widget_show(item); + gtk_menu_append(GTK_MENU(list), item); + } + + if (ctx->widget) menu = ctx->widget; + else { + menu = gtk_option_menu_new(); + ctx->widget = menu; + } + + gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu)); + gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); + + config = rccGetConfig(rccctx, language_id); + engine_id = rccConfigGetSelectedEngine(config); + if (engine_id < 0) engine_id = 0; + gtk_option_menu_set_history(GTK_OPTION_MENU(menu), engine_id); + + break; + case RCC_UI_MENU_OPTION: + item = gtk_check_button_new_with_label(rccUiGetOptionName(uictx, (rcc_option)ctx->id)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item), rccGetOption(rccctx, (rcc_option)ctx->id)); + break; + } + + return 0; +} + + +rcc_ui_box rccUiBoxCreate(rcc_ui_menu_context ctx, const char *title) { + GtkWidget *hbox, *label; + hbox = gtk_hbox_new(FALSE, 10); + gtk_container_border_width(GTK_CONTAINER(hbox), 5); + if (ctx->type != RCC_UI_MENU_OPTION) { + label = gtk_label_new(title); + gtk_widget_set_usize(label, 120, 17); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + } + gtk_box_pack_start(GTK_BOX(hbox), (GtkWidget*)ctx->widget, TRUE, TRUE, 0); + return (rcc_ui_box)hbox; +} + +rcc_ui_frame rccUiFrameCreate(rcc_ui_context ctx, const char *title) { + GtkWidget *frame, *box; + frame = gtk_frame_new(title?title:""); + gtk_container_border_width(GTK_CONTAINER(frame), 5); + + box = gtk_vbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(frame), box); + + return (rcc_ui_frame)frame; +} + +int rccUiFrameAdd(rcc_ui_frame frame, rcc_ui_box box) { + GtkWidget *vbox; + + vbox = gtk_container_get_toplevels()->data; + gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(box), FALSE, FALSE, 0); + return 0; +} + +rcc_ui_page rccUiPageCreate(rcc_ui_context ctx, const char *title) { + return (rcc_ui_page)gtk_vbox_new(FALSE, 0); +} + +int rccUiPageAdd(rcc_ui_page page, rcc_ui_frame frame) { + if ((!page)||(!frame)) return -1; + gtk_box_pack_start(GTK_BOX(page), GTK_WIDGET(frame), FALSE, FALSE, 0); + return 0; +} diff --git a/ui/internal.h b/ui/internal.h new file mode 100644 index 0000000..afc0a08 --- /dev/null +++ b/ui/internal.h @@ -0,0 +1,71 @@ +#ifndef _RCC_UI_INTERNAL_H +#define _RCC_UI_INTERNAL_H + +#include "../src/librcc.h" +#include "librccui.h" + +typedef unsigned int rcc_ui_id; +typedef void *rcc_ui_internal; +typedef void *rcc_ui_menu_internal; + +enum rcc_ui_menu_type_t { + RCC_UI_MENU_LANGUAGE = 0, + RCC_UI_MENU_CHARSET, + RCC_UI_MENU_ENGINE, + RCC_UI_MENU_OPTION, + RCC_UI_MENU_MAX +}; +typedef enum rcc_ui_menu_type_t rcc_ui_menu_type; + +struct rcc_ui_menu_context_t { + rcc_ui_widget widget; + rcc_ui_box box; + + rcc_ui_context uictx; + rcc_ui_menu_type type; + rcc_ui_id id; + + rcc_ui_menu_internal internal; +}; +typedef struct rcc_ui_menu_context_t rcc_ui_menu_context_s; +typedef struct rcc_ui_menu_context_t *rcc_ui_menu_context; + +struct rcc_ui_context_t { + rcc_context rccctx; + + rcc_ui_menu_context language; + rcc_ui_menu_context engine; + rcc_ui_menu_context *charsets; + rcc_ui_menu_context *options; + + rcc_ui_internal internal; + + rcc_language_name *language_names; + rcc_option_name *option_names; + + rcc_ui_frame language_frame; + rcc_ui_frame charset_frame; + rcc_ui_frame engine_frame; + + rcc_ui_page page; +}; +typedef struct rcc_ui_context_t rcc_ui_contexts_s; + + +rcc_ui_internal rccUiCreateInternal(rcc_ui_context ctx); +void rccUiFreeInternal(rcc_ui_context ctx); + +rcc_ui_widget rccUiMenuCreateWidget(rcc_ui_menu_context ctx); +void rccUiMenuDestroyWidget(rcc_ui_menu_context ctx); +int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx); + +rcc_ui_id rccUiMenuGet(rcc_ui_menu_context ctx); +int rccUiMenuSet(rcc_ui_menu_context ctx, rcc_ui_id id); + +rcc_ui_box rccUiBoxCreate(rcc_ui_menu_context ctx, const char *title); +rcc_ui_frame rccUiFrameCreate(rcc_ui_context ctx, const char *title); +int rccUiFrameAdd(rcc_ui_frame frame, rcc_ui_box box); +rcc_ui_page rccUiPageCreate(rcc_ui_context ctx, const char *title); +int rccUiPageAdd(rcc_ui_page page, rcc_ui_frame frame); + +#endif /* _RCC_UI_INTERNAL_H */ diff --git a/ui/librccui.c b/ui/librccui.c new file mode 100644 index 0000000..0700b8b --- /dev/null +++ b/ui/librccui.c @@ -0,0 +1,387 @@ +#include <stdio.h> +#include "../src/rccconfig.h" +#include "internal.h" +#include "rccnames.h" + +#define RCC_UI_LOCK_CODE 0x1111 + +static rcc_ui_menu_context rccUiMenuCreateContext(rcc_ui_menu_type type, rcc_ui_id id, rcc_ui_context uictx) { + rcc_ui_menu_context ctx; + if ((!uictx)||(type>RCC_UI_MENU_MAX)) return NULL; + + ctx = (rcc_ui_menu_context)malloc(sizeof(rcc_ui_menu_context_s)); + if (!ctx) return ctx; + + ctx->uictx = uictx; + ctx->type = type; + ctx->id = id; + + ctx->widget = rccUiMenuCreateWidget(ctx); + ctx->box = NULL; + + return ctx; +} + +static void rccUiMenuFreeContext(rcc_ui_menu_context ctx) { + if (!ctx) return; + rccUiMenuFreeWidget(ctx); + free(ctx); +} + +rcc_ui_context rccUiCreateContext(rcc_context rccctx) { + int err = 0; + unsigned int i; + + rcc_class_ptr *classes; + rcc_ui_context ctx; + rcc_ui_menu_context *charsets; + rcc_ui_menu_context *options; + + if (!rccctx) return NULL; + + err = rccLockConfiguration(rccctx, RCC_UI_LOCK_CODE); + if (err) return NULL; + + classes = rccGetClassList(rccctx); + for (i=0; classes[i]; i++); + + ctx = (rcc_ui_context)malloc(sizeof(struct rcc_ui_context_t)); + charsets = (rcc_ui_menu_context*)malloc((i+1)*sizeof(rcc_ui_menu_context)); + options = (rcc_ui_menu_context*)malloc((RCC_MAX_OPTIONS)*sizeof(rcc_ui_menu_context)); + if ((!ctx)||(!charsets)) { + if (ctx) free(ctx); + if (charsets) free(charsets); + rccUnlockConfiguration(rccctx, RCC_UI_LOCK_CODE); + return NULL; + } + + ctx->language_frame = NULL; + ctx->charset_frame = NULL; + ctx->engine_frame = NULL; + ctx->page = NULL; + + ctx->charsets = charsets; + ctx->rccctx = rccctx; + + ctx->language_names = rcc_default_language_names; + ctx->option_names = rcc_default_option_names; + + ctx->internal = rccUiCreateInternal(ctx); + + ctx->language = rccUiMenuCreateContext(RCC_UI_MENU_LANGUAGE, 0, ctx); + ctx->engine = rccUiMenuCreateContext(RCC_UI_MENU_ENGINE, 0, ctx); + for (i=0; classes[i]; i++) { + charsets[i] = rccUiMenuCreateContext(RCC_UI_MENU_CHARSET, i, ctx); + if (!charsets[i]) err = 1; + } + charsets[i] = NULL; + for (i=0; i<RCC_MAX_OPTIONS; i++) { + options[i] = rccUiMenuCreateContext(RCC_UI_MENU_OPTION, i, ctx); + if (!options[i]) err = 1; + } + + if ((err)||(!ctx->language)||(!ctx->engine)) { + rccUiFreeContext(ctx); + return NULL; + } + + return ctx; +} + +void rccUiFreeContext(rcc_ui_context ctx) { + unsigned int i; + rcc_class_ptr *classes; + + if (!ctx) return; + + rccUiFreeInternal(ctx); + + if (ctx->charsets) { + classes = rccGetClassList(ctx->rccctx); + for (i=0; classes[i]; i++) + if (ctx->charsets[i]) rccUiMenuFreeContext(ctx->charsets[i]); + free(ctx->charsets); + } + if (ctx->options) { + for (i=0;i<RCC_MAX_OPTIONS;i++) { + if (ctx->options[i]) rccUiMenuFreeContext(ctx->options[i]); + } + free(ctx->options); + } + if (ctx->engine) rccUiMenuFreeContext(ctx->engine); + if (ctx->language) rccUiMenuFreeContext(ctx->language); + + rccUnlockConfiguration(ctx->rccctx, RCC_UI_LOCK_CODE); + + free(ctx); +} + +int rccUiSetLanguageNames(rcc_ui_context ctx, rcc_language_name *names) { + if (!ctx) return -1; + + if (names) ctx->language_names = names; + else ctx->language_names = rcc_default_language_names; + return 0; +} + +int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names) { + if (!ctx) return -1; + + if (names) ctx->option_names = names; + else ctx->option_names = rcc_default_option_names; + return 0; +} + + +int rccUiRestoreLanguage(rcc_ui_context ctx) { + unsigned int i; + rcc_class_ptr *classes; + rcc_context rccctx; + + if (!ctx) return -1; + + rccctx = ctx->rccctx; + + rccUiMenuSet(ctx->engine, (rcc_ui_id)rccGetSelectedEngine(rccctx)); + + for (i=0;i<RCC_MAX_OPTIONS;i++) + rccUiMenuSet(ctx->options[i], rccGetOption(rccctx, (rcc_option)i)); + + classes = rccGetClassList(rccctx); + for (i=0;classes[i];i++) + rccUiMenuSet(ctx->charsets[i], rccGetSelectedCharset(rccctx, (rcc_class_id)i)); + + return 0; +} + +int rccUiRestore(rcc_ui_context ctx) { + rcc_language_id language_id; + + if (!ctx) return -1; + + language_id = rccGetSelectedLanguage(ctx->rccctx); + rccUiMenuSet(ctx->language, (rcc_ui_id)language_id); + return 0; +} + +int rccUiUpdate(rcc_ui_context ctx) { + unsigned int i; + rcc_class_ptr *classes; + rcc_context rccctx; + + if (!ctx) return -1; + + rccctx = ctx->rccctx; + + rccSetLanguage(rccctx, (rcc_language_id)rccUiMenuGet(ctx->language)); + + for (i=0;i<RCC_MAX_OPTIONS;i++) + rccSetOption(rccctx, (rcc_option)i, (rcc_option_value)rccUiMenuGet(ctx->options[i])); + + rccSetEngine(rccctx, (rcc_language_id)rccUiMenuGet(ctx->engine)); + + classes = rccGetClassList(rccctx); + for (i=0;classes[i];i++) + rccSetCharset(rccctx, (rcc_class_id)i, rccUiMenuGet(ctx->charsets[i])); + + return 0; +} + + + +rcc_ui_widget rccUiGetLanguageMenu(rcc_ui_context ctx) { + if (!ctx) return NULL; + + if (rccUiMenuConfigureWidget(ctx->language)) return NULL; + return ctx->language->widget; +} + +rcc_ui_widget rccUiGetCharsetMenu(rcc_ui_context ctx, rcc_class_id id) { + rcc_charset *charsets; + unsigned int i; + + if ((!ctx)||(id<0)) return NULL; + + charsets = rccGetCurrentCharsetList(ctx->rccctx); + for (i=0;charsets[i];i++); + if (id>=i) return NULL; + + if (rccUiMenuConfigureWidget(ctx->charsets[i])) return NULL; + return ctx->charsets[i]->widget; +} + + +rcc_ui_widget rccUiGetEngineMenu(rcc_ui_context ctx) { + if (!ctx) return NULL; + + if (rccUiMenuConfigureWidget(ctx->engine)) return NULL; + return ctx->engine->widget; +} + + +rcc_ui_widget rccUiGetOptionMenu(rcc_ui_context ctx, rcc_option option) { + if ((!ctx)||(option<0)||(option>RCC_MAX_OPTIONS)) return NULL; + + if (rccUiMenuConfigureWidget(ctx->options[option])) return NULL; + return ctx->options[option]->widget; +} + + +rcc_ui_box rccUiGetLanguageBox(rcc_ui_context ctx, const char *title) { + rcc_ui_widget language; + + if (!ctx) return NULL; + if (ctx->language->box) return ctx->language->box; + + language = rccUiGetLanguageMenu(ctx); + if (!language) return NULL; + + ctx->language->box = rccUiBoxCreate(ctx->language, title); + return ctx->language->box; +} + +rcc_ui_box rccUiGetCharsetBox(rcc_ui_context ctx, rcc_class_id id, const char *title) { + unsigned int i; + rcc_class_ptr *classes; + rcc_ui_widget charset; + + if (!ctx) return NULL; + + classes = rccGetClassList(ctx->rccctx); + for (i=0; classes[i]; i++); + if (id>=i) return NULL; + + if (ctx->charsets[id]->box) return ctx->charsets[id]->box; + + + charset = rccUiGetCharsetMenu(ctx, id); + if (!charset) return NULL; + + ctx->charsets[id]->box = rccUiBoxCreate(ctx->charsets[id], title); + return ctx->charsets[id]->box; +} + +rcc_ui_box rccUiGetEngineBox(rcc_ui_context ctx, const char *title) { + rcc_ui_widget engine; + + if (!ctx) return NULL; + if (ctx->engine->box) return ctx->engine->box; + + engine = rccUiGetEngineMenu(ctx); + if (!engine) return NULL; + + ctx->engine->box = rccUiBoxCreate(ctx->engine, title); + return ctx->engine->box; +} + +rcc_ui_box rccUiGetOptionBox(rcc_ui_context ctx, rcc_option option, const char *title) { + rcc_ui_widget opt; + + if ((!ctx)||(option<0)||(option>=RCC_MAX_OPTIONS)) return NULL; + if (ctx->options[option]->box) return ctx->options[option]->box; + + opt = rccUiGetOptionMenu(ctx, option); + if (!opt) return NULL; + + ctx->options[option]->box = rccUiBoxCreate(ctx->options[option], title); + return ctx->options[option]->box; + +} + +rcc_ui_frame rccUiGetLanguageFrame(rcc_ui_context ctx, const char *title) { + rcc_ui_frame frame; + rcc_ui_box language; + + if (!ctx) return NULL; + + if (ctx->language_frame) return ctx->language_frame; + + frame = rccUiFrameCreate(ctx, title); + if (!frame) return NULL; + + language = rccUiGetLanguageBox(ctx, title); + if (!language) return NULL; + + rccUiFrameAdd(frame, language); + + ctx->language_frame = frame; + + return frame; +} + +rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, const char *title) { + unsigned int i; + rcc_class_ptr *classes; + rcc_ui_frame frame; + rcc_ui_box charset; + + if (!ctx) return NULL; + + if (ctx->charset_frame) return ctx->charset_frame; + + frame = rccUiFrameCreate(ctx, title); + if (!frame) return NULL; + + classes = rccGetClassList(ctx->rccctx); + for (i=0; classes[i]; i++) { + charset = rccUiGetCharsetBox(ctx, (rcc_class_id)i, classes[i]->fullname); + rccUiFrameAdd(frame, charset); + } + + ctx->charset_frame = frame; + + return frame; +} + + +rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, const char *title) { + unsigned int i; + rcc_ui_frame frame; + rcc_ui_box engine; + rcc_ui_box opt; + + if (!ctx) return NULL; + + if (ctx->engine_frame) return ctx->engine_frame; + + frame = rccUiFrameCreate(ctx, title); + if (!frame) return NULL; + + engine = rccUiGetEngineBox(ctx, title); + rccUiFrameAdd(frame, engine); + + for (i=0; i<RCC_MAX_OPTIONS; i++) { + opt = rccUiGetOptionBox(ctx, (rcc_option)i, rccUiGetOptionName(ctx, i)); + rccUiFrameAdd(frame, opt); + } + + ctx->engine_frame = frame; + + return frame; +} + + +rcc_ui_page rccUiGetPage(rcc_ui_context ctx, const char *title, const char *language_title, const char *charset_title, const char *engine_title) { + rcc_ui_page page; + rcc_ui_frame frame; + + if (!ctx) return NULL; + + if (ctx->page) return ctx->page; + + page = rccUiPageCreate(ctx, title); + if (!page) return NULL; + + frame = rccUiGetLanguageFrame(ctx, language_title); + rccUiPageAdd(page, frame); + + frame = rccUiGetCharsetsFrame(ctx, charset_title); + rccUiPageAdd(page, frame); + + frame = rccUiGetEngineFrame(ctx, engine_title); + rccUiPageAdd(page, frame); + + ctx->page = page; + + return page; +} diff --git a/ui/librccui.h b/ui/librccui.h new file mode 100644 index 0000000..6b114da --- /dev/null +++ b/ui/librccui.h @@ -0,0 +1,46 @@ +#ifndef _LIBRCC_UI_H +#define _LIBRCC_UI_H + +#include <librcc.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *rcc_ui_widget; +typedef void *rcc_ui_box; +typedef void *rcc_ui_frame; +typedef void *rcc_ui_page; + +typedef struct rcc_ui_context_t *rcc_ui_context; + +rcc_ui_context rccUiCreateContext(rcc_context rccctx); +void rccUiFreeContext(rcc_ui_context ctx); +int rccUiSetLanguageNames(rcc_ui_context ctx, rcc_language_name *names); +int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names); + +int rccUiRestoreLanguage(rcc_ui_context ctx); +int rccUiRestore(rcc_ui_context ctx); +int rccUiUpdate(rcc_ui_context ctx); + +rcc_ui_widget rccUiGetLanguageMenu(rcc_ui_context ctx); +rcc_ui_widget rccUiGetCharsetMenu(rcc_ui_context ctx, rcc_class_id id); +rcc_ui_widget rccUiGetEngineMenu(rcc_ui_context ctx); +rcc_ui_widget rccUiGetOptionMenu(rcc_ui_context ctx, rcc_option option); + +rcc_ui_box rccUiGetLanguageBox(rcc_ui_context ctx, const char *title); +rcc_ui_box rccUiGetCharsetBox(rcc_ui_context ctx, rcc_class_id id, const char *title); +rcc_ui_box rccUiGetEngineBox(rcc_ui_context ctx, const char *title); +rcc_ui_box rccUiGetOptionBox(rcc_ui_context ctx, rcc_option option, const char *title); + +rcc_ui_frame rccUiGetLanguageFrame(rcc_ui_context ctx, const char *title); +rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, const char *title); +rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, const char *title); + +rcc_ui_page rccUiGetPage(rcc_ui_context ctx, const char *title, const char *language_title, const char *charset_title, const char *engine_title); + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBRCC_UI_H */ diff --git a/ui/rccnames.c b/ui/rccnames.c new file mode 100644 index 0000000..e4f4b48 --- /dev/null +++ b/ui/rccnames.c @@ -0,0 +1,31 @@ +#include <stdio.h> + +#include "internal.h" + +const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang) { + unsigned int i; + rcc_language_name *names; + + if ((!ctx)||(!lang)) return NULL; + + names = ctx->language_names; + + for (i=0;names[i].sn;i++) + if (!strcmp(lang, names[i].sn)) return names[i].name; + + return lang; +} + +const char *rccUiGetOptionName(rcc_ui_context ctx, rcc_option option) { + unsigned int i; + rcc_option_name *names; + + if (!ctx) return NULL; + + names = ctx->option_names; + + for (i=0;i<RCC_MAX_OPTIONS;i++) + if (names[i].option == option) return names[i].name; + + return NULL; +} diff --git a/ui/rccnames.h b/ui/rccnames.h new file mode 100644 index 0000000..cb23960 --- /dev/null +++ b/ui/rccnames.h @@ -0,0 +1,9 @@ +#ifndef _RCC_UI_NAMES_C +#define _RCC_UI_NAMES_H + + +const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang); +const char *rccUiGetOptionName(rcc_ui_context ctx, rcc_option option); + + +#endif /* _RCC_UI_NAMES_H */ |