diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2005-07-12 03:55:23 +0000 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2005-07-12 03:55:23 +0000 |
commit | e598a2372179812389a702b78d5f8537eb6827d9 (patch) | |
tree | fad90d39ca5781d5ffdf4e9131050fe79d3e5383 /ui | |
parent | 6b44784148735f594ac862abcd38c50c5d556df0 (diff) | |
download | librcc-e598a2372179812389a702b78d5f8537eb6827d9.tar.gz librcc-e598a2372179812389a702b78d5f8537eb6827d9.tar.bz2 librcc-e598a2372179812389a702b78d5f8537eb6827d9.tar.xz librcc-e598a2372179812389a702b78d5f8537eb6827d9.zip |
Language and Option Names
Diffstat (limited to 'ui')
-rw-r--r-- | ui/Makefile.am | 5 | ||||
-rw-r--r-- | ui/gtk.c | 64 | ||||
-rw-r--r-- | ui/internal.h | 29 | ||||
-rw-r--r-- | ui/librccui.c | 301 | ||||
-rw-r--r-- | ui/librccui.h | 28 | ||||
-rw-r--r-- | ui/rccmenu.c | 89 | ||||
-rw-r--r-- | ui/rccmenu.h | 55 | ||||
-rw-r--r-- | ui/rccnames.c | 107 | ||||
-rw-r--r-- | ui/rccnames.h | 6 |
9 files changed, 595 insertions, 89 deletions
diff --git a/ui/Makefile.am b/ui/Makefile.am index 121d2c4..69395fb 100644 --- a/ui/Makefile.am +++ b/ui/Makefile.am @@ -1,12 +1,13 @@ if HAVE_GTK lib_LTLIBRARIES = librccgtk.la librccgtk_la_SOURCES = librccui.c \ + rccmenu.c rccmenu.h \ rccnames.c rccnames.h \ internal.h \ gtk.c -librccgtk_la_LIBADD = @GTK_LIBS@ ../src/librcc.la +librccgtk_la_LIBADD = @GTK_LIBS@ @XML_LIBS@ ../src/librcc.la librccgtk_la_LDFLAGS = -version-info @LIBRCC_VERSION_INFO@ endif -INCLUDES = -I../src @GTK_INCLUDES@ +INCLUDES = -I../src @GTK_INCLUDES@ @XML_INCLUDES@ include_HEADERS = librccui.h @@ -1,5 +1,8 @@ #include <stdio.h> #include <gtk/gtk.h> + +#include <librcc.h> + #include "internal.h" #include "rccnames.h" @@ -71,7 +74,10 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { rcc_charset_id charset_id; rcc_engine_id engine_id; - + + rcc_option_name *option_name; + rcc_option_value_names optnames; + GtkWidget *list, *item, *menu; if (!ctx) return -1; @@ -81,9 +87,10 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { switch (ctx->type) { case RCC_UI_MENU_LANGUAGE: - list = gtk_menu_new(); - languages=rccGetLanguageList(rccctx); + if (!languages) return -1; + + list = gtk_menu_new(); 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); @@ -104,11 +111,12 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { gtk_option_menu_set_history(GTK_OPTION_MENU(menu), language_id); break; case RCC_UI_MENU_CHARSET: - list = gtk_menu_new(); language_id = (rcc_language_id)rccUiMenuGet(uictx->language); charsets = rccGetCharsetList(rccctx, language_id); + if (!charsets) return -1; + list = gtk_menu_new(); for (i=0;charsets[i];i++) { item = gtk_menu_item_new_with_label(charsets[i]); gtk_widget_show(item); @@ -125,15 +133,17 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); config = rccGetConfig(rccctx, language_id); - charset_id = rccConfigGetSelectedCharset(config, (rcc_class_id)ctx->id); + charset_id = rccConfigGetSelectedCharset(config, rccUiMenuGetClassId(ctx)); if (charset_id == (rcc_charset_id)-1) 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); + if (!engines) return -1; + + list = gtk_menu_new(); for (i=0;engines[i];i++) { item = gtk_menu_item_new_with_label(engines[i]->title); gtk_widget_show(item); @@ -154,12 +164,44 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { gtk_option_menu_set_history(GTK_OPTION_MENU(menu), engine_id); break; case RCC_UI_MENU_OPTION: - if (!ctx->widget) { - 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)); - ctx->widget = item; + switch (rccUiMenuGetRangeType(ctx)) { + case RCC_OPTION_RANGE_TYPE_BOOLEAN: + if (!ctx->widget) { + item = gtk_check_button_new_with_label(rccUiGetOptionName(uictx, rccUiMenuGetOption(ctx))); + ctx->widget = item; + } + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item), rccGetOption(rccctx, rccUiMenuGetOption(ctx))); + break; + case RCC_OPTION_RANGE_TYPE_MENU: + if (!ctx->widget) { + option_name = rccUiGetOptionRccName(uictx, rccUiMenuGetOption(ctx)); + if (!option_name) return -1; + optnames = option_name->value_names; + if (!optnames) return -1; + + list = gtk_menu_new(); + for (i=0;optnames[i];i++) { + item = gtk_menu_item_new_with_label(optnames[i]); + gtk_widget_show(item); + gtk_menu_append(GTK_MENU(list), item); + } + + 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), rccGetOption(rccctx, rccUiMenuGetOption(ctx))); + break; + default: + return -1; } break; + default: + return -1; } return 0; @@ -170,7 +212,7 @@ rcc_ui_box rccUiBoxCreate(rcc_ui_menu_context ctx, const char *title) { GtkWidget *hbox, *label; hbox = gtk_hbox_new(FALSE, BOX_SPACING); gtk_container_border_width(GTK_CONTAINER(hbox), BOX_BORDER); - if (ctx->type != RCC_UI_MENU_OPTION) { + if ((ctx->type != RCC_UI_MENU_OPTION)||(rccUiMenuGetRangeType(ctx) != RCC_OPTION_RANGE_TYPE_BOOLEAN)) { label = gtk_label_new(title); gtk_widget_set_usize(label, TITLE_WIDTH, TITLE_HEIGHT); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); diff --git a/ui/internal.h b/ui/internal.h index 8448fb5..64ee978 100644 --- a/ui/internal.h +++ b/ui/internal.h @@ -1,34 +1,13 @@ #ifndef _RCC_UI_INTERNAL_H #define _RCC_UI_INTERNAL_H -#include "../src/librcc.h" -#include "librccui.h" +#define RCC_UI_MAX_STRING_CHARS 1024 -typedef unsigned int rcc_ui_id; - -typedef void *rcc_ui_menu_internal; +#include <librcc.h> -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; +#include "rccmenu.h" -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; +typedef unsigned int rcc_ui_id; typedef void *rcc_ui_frame_internal; diff --git a/ui/librccui.c b/ui/librccui.c index 3b8bcdc..9f4dc49 100644 --- a/ui/librccui.c +++ b/ui/librccui.c @@ -1,31 +1,272 @@ #include <stdio.h> -#include "../src/rccconfig.h" +#include <string.h> +#include <stdarg.h> +#include <locale.h> + +#include "../config.h" + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> + +#include <librcc.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; +#define XPATH_LANGUAGE "//Languages/Language[@name]" +#define XPATH_OPTION "//Options/Option[@name]" +#define XPATH_VALUE "//Options/Option[@name=\"%s\"]/Value[@name]" +#define XPATH_LANGUAGE_REQUEST_LOCALE "//Languages/Language[@name=\"%s\"]/FullName[@locale=\"%s\"]" +#define XPATH_LANGUAGE_REQUEST "//Languages/Language[@name=\"%s\"]/FullName" +#define XPATH_OPTION_REQUEST_LOCALE "//Options/Option[@name=\"%s\"]/FullName[@locale=\"%s\"]" +#define XPATH_OPTION_REQUEST "//Options/Option[@name=\"%s\"]/FullName" +#define XPATH_VALUE_REQUEST_LOCALE "//Options/Option[@name=\"%s\"]/Value[@name=\"%s\"]/FullName[@locale=\"%s\"]" +#define XPATH_VALUE_REQUEST "//Options/Option[@name=\"%s\"]/Value[@name=\"%s\"]/FullName" + +static const char *rccUiXmlGetText(xmlNodePtr node) { + if ((node)&&(node->children)&&(node->children->type == XML_TEXT_NODE)&&(node->children->content)) return node->children->content; +} + +static xmlNodePtr rccUiNodeFind(xmlXPathContextPtr xpathctx, const char *request, ...) { + xmlXPathObjectPtr obj; + xmlNodeSetPtr node_set; + xmlNodePtr res = NULL; + + unsigned int i, args = 0; + unsigned int size = 128; + va_list ap; + char *req; - ctx = (rcc_ui_menu_context)malloc(sizeof(rcc_ui_menu_context_s)); - if (!ctx) return ctx; + if (!xpathctx) return NULL; + + for (req = strstr(request, "%s"); req; req = strstr(req + 1, "%s")) args++; - ctx->uictx = uictx; - ctx->type = type; - ctx->id = id; + if (args) { + va_start(ap, request); + for (i=0;i<args;i++) { + req = va_arg(ap, char*); + size += strlen(req); + } + va_end(ap); + + req = (char*)malloc(size*sizeof(char)); + if (!req) return NULL; + + va_start(ap, request); + vsprintf(req,request,ap); + va_end(ap); + } else req = (char*)request; + + obj = xmlXPathEvalExpression(req, xpathctx); + if (obj) { + node_set = obj->nodesetval; + if ((node_set)&&(node_set->nodeNr > 0)) { + res = node_set->nodeTab[0]; + } + xmlXPathFreeObject(obj); + } + + if (args) free(req); + + return res; +} + +int rccUiInit() { + int err; + unsigned long i, j, k, nnodes; + + xmlDocPtr xmlctx; + xmlXPathContextPtr xpathctx = NULL; + xmlXPathObjectPtr obj; + xmlNodeSetPtr node_set; + + xmlNodePtr node, cnode; + xmlAttrPtr attr; + + rcc_language_name *lang_name; + const char *lang, *fullname; + const char *locale; + char *lpos; + char *search[4]; + + rcc_option option; + const char *opt, *val; + rcc_option_name *option_name; + const char *value_name; + + unsigned int npos; + + size_t newsize; + char tmpbuf[RCC_UI_MAX_STRING_CHARS+1]; + char ctype_charset[32]; + rcc_iconv icnv; + + err = rccInit(); + if (err) return err; - ctx->widget = rccUiMenuCreateWidget(ctx); - ctx->box = NULL; + if (rccLocaleGetCharset(ctype_charset, NULL, 32)) icnv = NULL; + else { + if ((!strcasecmp(ctype_charset, "UTF-8"))||(!strcasecmp(ctype_charset, "UTF8"))) icnv = NULL; + else icnv = rccIConvOpen(ctype_charset, "UTF-8"); + } - return ctx; + locale = setlocale(LC_CTYPE, NULL); + if (locale) { + search[0] = strdup(locale); + if (!search[0]) goto clean; + lpos = strrchr(search[0], '@'); + if (lpos) *lpos = 0; + + lpos = strrchr(search[0], '.'); + if (lpos) { + search[1] = strdup(search[0]); + if (!search[1]) goto clean; + *strchr(search[1], '.') = 0; + + lpos = strrchr(search[1], '_'); + if (lpos) { + search[2] = strdup(search[1]); + if (!search[2]) goto clean; + *strchr(search[2],'_') = 0; + search[3] = NULL; + } else search[2] = NULL; + } else search[1] = NULL; + } else search[0] = NULL; + + for (npos = 0; rcc_default_language_names[npos].sn; npos++); + + xmlctx = (xmlDocPtr)rccGetConfiguration(); + if (xmlctx) xpathctx = xmlXPathNewContext(xmlctx); + else xpathctx = NULL; + if (xpathctx) { + obj = xmlXPathEvalExpression(XPATH_LANGUAGE, xpathctx); + if (obj) { + node_set = obj->nodesetval; + if (node_set) nnodes = node_set->nodeNr; + else nnodes = 0; + } else nnodes = 0; + + for (i=0;i<nnodes;i++) { + node = node_set->nodeTab[i]; + attr = xmlHasProp(node, "name"); + lang = attr->children->content; + + if ((!lang)||(!lang[0])) continue; + + for (j=0, node = NULL;((search[j])&&(!node));j++) + node = rccUiNodeFind(xpathctx, XPATH_LANGUAGE_REQUEST_LOCALE, lang, search[j]); + if (!node) { + node = rccUiNodeFind(xpathctx, XPATH_LANGUAGE_REQUEST, lang); + if (!node) continue; + } + + fullname = rccUiXmlGetText(node); + if (!fullname) continue; + + if (icnv) { + newsize = rccIConvRecode(icnv, tmpbuf, RCC_UI_MAX_STRING_CHARS, fullname, 0); + if (newsize != (size_t)-1) { + cnode = xmlNewChild(node->parent, NULL, "Recoded", tmpbuf); + fullname = rccUiXmlGetText(cnode); + if (!fullname) fullname = rccUiXmlGetText(node); + } + } + + lang_name = rccUiGetLanguageRccName(NULL, lang); + if (lang_name) lang_name->name = fullname; + else if (npos<RCC_MAX_LANGUAGES) { + rcc_default_language_names[npos].sn = lang; + rcc_default_language_names[npos].name = fullname; + rcc_default_language_names[++npos].sn = NULL; + rcc_default_language_names[npos].name = NULL; + } + } + + if (obj) xmlXPathFreeObject(obj); + + obj = xmlXPathEvalExpression(XPATH_OPTION, xpathctx); + if (obj) { + node_set = obj->nodesetval; + if (node_set) nnodes = node_set->nodeNr; + else nnodes = 0; + } else nnodes = 0; + + for (i=0;i<nnodes;i++) { + node = node_set->nodeTab[i]; + attr = xmlHasProp(node, "name"); + opt = attr->children->content; + + if ((!opt)||(!opt[0])) continue; + option = rccGetOptionByName(opt); + if (option == (rcc_option)-1) continue; + option_name = rccUiGetOptionRccName(NULL, option); + if (!option_name) continue; + + for (j=0, node = NULL;((search[j])&&(!node));j++) + node = rccUiNodeFind(xpathctx, XPATH_OPTION_REQUEST_LOCALE, opt, search[j]); + if (!node) { + node = rccUiNodeFind(xpathctx, XPATH_OPTION_REQUEST, opt); + } + + if (node) { + fullname = rccUiXmlGetText(node); + if (fullname) { + if (icnv) { + newsize = rccIConvRecode(icnv, tmpbuf, RCC_UI_MAX_STRING_CHARS, fullname, 0); + if (newsize != (size_t)-1) { + cnode = xmlNewChild(node->parent, NULL, "Recoded", tmpbuf); + fullname = rccUiXmlGetText(cnode); + if (!fullname) fullname = rccUiXmlGetText(node); + } + } + option_name->name = fullname; + } + } + + if (!option_name->value_names) continue; + + for (k=0;option_name->value_names[k];k++) { + value_name = rccGetOptionValueName(option, (rcc_option_value)k); + if (!value_name) continue; + + for (j=0, node = NULL;((search[j])&&(!node));j++) + node = rccUiNodeFind(xpathctx, XPATH_VALUE_REQUEST_LOCALE, opt, value_name, search[j]); + if (!node) { + node = rccUiNodeFind(xpathctx, XPATH_VALUE_REQUEST, opt, value_name); + } + + if (node) { + fullname = rccUiXmlGetText(node); + if (fullname) { + if (icnv) { + newsize = rccIConvRecode(icnv, tmpbuf, RCC_UI_MAX_STRING_CHARS, fullname, 0); + if (newsize != (size_t)-1) { + cnode = xmlNewChild(node->parent, NULL, "Recoded", tmpbuf); + fullname = rccUiXmlGetText(cnode); + if (!fullname) fullname = rccUiXmlGetText(node); + } + } + option_name->value_names[k] = fullname; + } + } + } + } + if (obj) xmlXPathFreeObject(obj); + + xmlXPathFreeContext(xpathctx); + } + +clean: + for (j=0;search[j];j++) free(search[j]); + if (icnv) rccIConvClose(icnv); + + return 0; } -static void rccUiMenuFreeContext(rcc_ui_menu_context ctx) { - if (!ctx) return; - rccUiMenuFreeWidget(ctx); - free(ctx); +void rccUiFree() { } static rcc_ui_frame_context rccUiFrameCreateContext(rcc_ui_frame_type type, rcc_ui_context uictx) { @@ -57,6 +298,8 @@ rcc_ui_context rccUiCreateContext(rcc_context rccctx) { rcc_ui_context ctx; rcc_ui_menu_context *charsets; rcc_ui_menu_context *options; + rcc_option_type otype; + rcc_option_range *orange; if (!rccctx) return NULL; @@ -85,15 +328,17 @@ rcc_ui_context rccUiCreateContext(rcc_context rccctx) { ctx->internal = rccUiCreateInternal(ctx); - ctx->language = rccUiMenuCreateContext(RCC_UI_MENU_LANGUAGE, 0, ctx); - ctx->engine = rccUiMenuCreateContext(RCC_UI_MENU_ENGINE, 0, ctx); + ctx->language = rccUiMenuCreateContext(RCC_UI_MENU_LANGUAGE, ctx); + ctx->engine = rccUiMenuCreateContext(RCC_UI_MENU_ENGINE, ctx); for (i=0; classes[i]; i++) { - charsets[i] = rccUiMenuCreateContext(RCC_UI_MENU_CHARSET, i, ctx); + charsets[i] = rccUiCharsetMenuCreateContext(RCC_UI_MENU_CHARSET, (rcc_charset_id)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); + otype = rccOptionGetType(rccctx, (rcc_option)i); + orange = rccOptionGetRange(rccctx, (rcc_option)i); + options[i] = rccUiOptionMenuCreateContext(RCC_UI_MENU_OPTION, (rcc_option)i, otype, orange, ctx); if (!options[i]) err = 1; } @@ -145,17 +390,15 @@ void rccUiFreeContext(rcc_ui_context 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; + + ctx->language_names = 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; + ctx->option_names = names; return 0; } @@ -383,7 +626,7 @@ rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, const char *title) { rcc_ui_frame frame; rcc_ui_box engine; rcc_ui_box opt; - const char *optname; + rcc_option_name *optname; if (!ctx) return NULL; @@ -398,10 +641,12 @@ rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, const char *title) { rccUiFrameAdd(framectx, engine); for (i=0; i<RCC_MAX_OPTIONS; i++) { - optname = rccUiGetOptionName(ctx, i); + if (rccUiMenuGetType(ctx->options[i]) == RCC_OPTION_TYPE_INVISIBLE) continue; + + optname = rccUiGetOptionRccName(ctx, i); if (!optname) continue; - opt = rccUiGetOptionBox(ctx, (rcc_option)i, optname); + opt = rccUiGetOptionBox(ctx, (rcc_option)i, optname->name); rccUiFrameAdd(framectx, opt); } diff --git a/ui/librccui.h b/ui/librccui.h index 6b114da..5a8d034 100644 --- a/ui/librccui.h +++ b/ui/librccui.h @@ -14,10 +14,11 @@ typedef void *rcc_ui_page; typedef struct rcc_ui_context_t *rcc_ui_context; +int rccUiInit(); +void rccUiFree(); + 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); @@ -39,6 +40,29 @@ 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); +/******************************************************************************* +************************************ Names ************************************* +*******************************************************************************/ + +struct rcc_language_name_t { + const char *sn; + const char *name; +}; +typedef struct rcc_language_name_t rcc_language_name; + +typedef const char *rcc_option_value_name; +typedef rcc_option_value_name *rcc_option_value_names; + +struct rcc_option_name_t { + rcc_option option; + const char *name; + rcc_option_value_names value_names; +}; +typedef struct rcc_option_name_t rcc_option_name; + +int rccUiSetLanguageNames(rcc_ui_context ctx, rcc_language_name *names); +int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names); + #ifdef __cplusplus } #endif diff --git a/ui/rccmenu.c b/ui/rccmenu.c new file mode 100644 index 0000000..da04cbd --- /dev/null +++ b/ui/rccmenu.c @@ -0,0 +1,89 @@ +#include <stdio.h> +#include <string.h> + +#include "internal.h" +#include "rccmenu.h" + +rcc_ui_menu_context rccUiMenuCreateContext(rcc_ui_menu_type type, 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->widget = rccUiMenuCreateWidget(ctx); + ctx->box = NULL; + + return ctx; +} + +rcc_ui_menu_context rccUiCharsetMenuCreateContext(rcc_ui_menu_type type, rcc_charset_id id, rcc_ui_context uictx) { + rcc_ui_charset_menu_context ctx; + + if ((!uictx)||(type>=RCC_UI_MENU_MAX)) return NULL; + + ctx = (rcc_ui_charset_menu_context)malloc(sizeof(rcc_ui_charset_menu_context_s)); + if (!ctx) return NULL; + + ctx->ui_menu.uictx = uictx; + ctx->ui_menu.type = type; + ctx->id = id; + + ctx->ui_menu.widget = rccUiMenuCreateWidget((rcc_ui_menu_context)ctx); + ctx->ui_menu.box = NULL; + + return (rcc_ui_menu_context)ctx; +} + +rcc_ui_menu_context rccUiOptionMenuCreateContext(rcc_ui_menu_type type, rcc_option id, rcc_option_type otype, rcc_option_range *range, rcc_ui_context uictx) { + rcc_ui_option_menu_context ctx; + + if ((!uictx)||(type>=RCC_UI_MENU_MAX)) return NULL; + + ctx = (rcc_ui_option_menu_context)malloc(sizeof(rcc_ui_option_menu_context_s)); + if (!ctx) return NULL; + + ctx->ui_menu.uictx = uictx; + ctx->ui_menu.type = type; + ctx->id = id; + ctx->type = otype; + ctx->range = range; + + ctx->ui_menu.widget = rccUiMenuCreateWidget((rcc_ui_menu_context)ctx); + ctx->ui_menu.box = NULL; + + return (rcc_ui_menu_context)ctx; +} + + +void rccUiMenuFreeContext(rcc_ui_menu_context ctx) { + if (!ctx) return; + rccUiMenuFreeWidget(ctx); + free(ctx); +} + + +rcc_class_id rccUiMenuGetClassId(rcc_ui_menu_context ctx) { + if (ctx->type != RCC_UI_MENU_CHARSET) return (rcc_class_id)-1; + return ((rcc_ui_charset_menu_context)ctx)->id; +} + +rcc_option rccUiMenuGetOption(rcc_ui_menu_context ctx) { + if (ctx->type != RCC_UI_MENU_OPTION) return (rcc_option)-1; + return ((rcc_ui_option_menu_context)ctx)->id; +} + + +rcc_option_type rccUiMenuGetType(rcc_ui_menu_context ctx) { + if (ctx->type != RCC_UI_MENU_OPTION) return (rcc_option_type)-1; + return ((rcc_ui_option_menu_context)ctx)->type; +} + +rcc_option_range_type rccUiMenuGetRangeType(rcc_ui_menu_context ctx) { + if (ctx->type != RCC_UI_MENU_OPTION) return (rcc_option_type)-1; + return ((rcc_ui_option_menu_context)ctx)->range->type; +} + diff --git a/ui/rccmenu.h b/ui/rccmenu.h new file mode 100644 index 0000000..5ad14ff --- /dev/null +++ b/ui/rccmenu.h @@ -0,0 +1,55 @@ +#ifndef _RCC_UI_MENU_H +#define _RCC_UI_MENU_H + +#include "librccui.h" + +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_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_charset_menu_context_t { + rcc_ui_menu_context_s ui_menu; + rcc_class_id id; +}; +typedef struct rcc_ui_charset_menu_context_t rcc_ui_charset_menu_context_s; +typedef struct rcc_ui_charset_menu_context_t *rcc_ui_charset_menu_context; + +struct rcc_ui_option_menu_context_t { + rcc_ui_menu_context_s ui_menu; + rcc_option id; + rcc_option_type type; + rcc_option_range *range; +}; +typedef struct rcc_ui_option_menu_context_t rcc_ui_option_menu_context_s; +typedef struct rcc_ui_option_menu_context_t *rcc_ui_option_menu_context; + +rcc_ui_menu_context rccUiMenuCreateContext(rcc_ui_menu_type type, rcc_ui_context uictx); +rcc_ui_menu_context rccUiCharsetMenuCreateContext(rcc_ui_menu_type type, rcc_charset_id id, rcc_ui_context uictx); +rcc_ui_menu_context rccUiOptionMenuCreateContext(rcc_ui_menu_type type, rcc_option id, rcc_option_type otype, rcc_option_range *range, rcc_ui_context uictx); +void rccUiMenuFreeContext(rcc_ui_menu_context ctx); + +rcc_class_id rccUiMenuGetClassId(rcc_ui_menu_context ctx); +rcc_option rccUiMenuGetOption(rcc_ui_menu_context ctx); +rcc_option_type rccUiMenuGetType(rcc_ui_menu_context ctx); +rcc_option_range_type rccUiMenuGetRangeType(rcc_ui_menu_context ctx); + +#endif /* _RCC_UI_MENU_H */ diff --git a/ui/rccnames.c b/ui/rccnames.c index f5bf4d8..9ebaba4 100644 --- a/ui/rccnames.c +++ b/ui/rccnames.c @@ -1,44 +1,111 @@ #include <stdio.h> +#include <librcc.h> + #include "internal.h" -const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang) { +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_value_name rcc_default_option_boolean_names[] = { "Off", "On", NULL }; +rcc_option_value_name rcc_default_option_learning_names[] = { "Off", "On", "Relearn", "Learn", NULL }; +rcc_option_value_name rcc_default_option_clo_names[] = { "All Languages", "Configured / AutoEngine", "Configured Only", NULL }; + +rcc_option_name rcc_default_option_names[RCC_MAX_OPTIONS+1] = { + { RCC_LEARNING_MODE, "Recodings Cache", rcc_default_option_learning_names }, + { RCC_AUTODETECT_FS_NAMES, "Autodetect File Names", rcc_default_option_boolean_names }, + { RCC_AUTODETECT_FS_TITLES, "Autodetect FS Titles", rcc_default_option_boolean_names }, + { RCC_CONFIGURED_LANGUAGES_ONLY, "Enabled Languages", rcc_default_option_clo_names }, + { RCC_MAX_OPTIONS } +}; + + +rcc_language_name *rccUiGetLanguageRccName(rcc_ui_context ctx, const char *lang) { const char *res; - unsigned int i; + unsigned int i,j; rcc_language_name *names; - if ((!ctx)||(!lang)) return NULL; + if (!lang) return NULL; - names = ctx->language_names; + for (j=0;j<2;j++) { + if (j) names = rcc_default_language_names; + else names = ctx?ctx->language_names:NULL; - if (names) { - for (i=0;names[i].sn;i++) - if (!strcmp(lang, names[i].sn)) return names[i].name; + if (names) { + for (i=0;names[i].sn;i++) + if (!strcmp(lang, names[i].sn)) return names+i; + } } + + return NULL; +} - - res = rccGetLanguageFullName(lang); - if (res) return res; +const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang) { + const char *res; + unsigned int i,j; + rcc_language_name *names; + + names = rccUiGetLanguageRccName(ctx, lang); + if ((names)&&(names->name)) return names->name; return lang; } +rcc_option_name *rccUiGetOptionRccName(rcc_ui_context ctx, rcc_option option) { + unsigned int i,j; + rcc_option_name *names; + + if ((option<0)||(option>=RCC_MAX_OPTIONS)) return NULL; + + for (j=0;j<2;j++) { + if (j) names = rcc_default_option_names; + else names = ctx?ctx->option_names:NULL; + + if (names) { + for (i=0;names[i].option!=RCC_MAX_OPTIONS;i++) + if (names[i].option == option) return names+i; + } + } + + return NULL; +} + const char *rccUiGetOptionName(rcc_ui_context ctx, rcc_option option) { - const char *res; unsigned int i; - rcc_option_name *names; + rcc_option_name *name; - if ((!ctx)||(option<0)||(option>RCC_MAX_OPTIONS)) return NULL; + name = rccUiGetOptionRccName(ctx, option); + if (name) return name->name; - names = ctx->option_names; + return NULL; +} - if (names) { - for (i=0;((i<RCC_MAX_OPTIONS)&&(names[i].option!=RCC_MAX_OPTIONS));i++) - if (names[i].option == option) return names[i].name; +const char *rccUiGetOptionValueName(rcc_ui_context ctx, rcc_option option, rcc_option_value value) { + unsigned int i; + rcc_option_name *name; + + name = rccUiGetOptionRccName(ctx, option); + if (name) { + for (i=0;name->value_names[i];i++) + if (i == value) return name->value_names[i]; } - - res = rccGetOptionFullName(option); - if (res) return res; return NULL; } diff --git a/ui/rccnames.h b/ui/rccnames.h index cb23960..f73bd19 100644 --- a/ui/rccnames.h +++ b/ui/rccnames.h @@ -1,9 +1,13 @@ #ifndef _RCC_UI_NAMES_C #define _RCC_UI_NAMES_H +extern rcc_language_name rcc_default_language_names[]; +extern rcc_option_name rcc_default_option_names[]; +rcc_language_name *rccUiGetLanguageRccName(rcc_ui_context ctx, const char *lang); const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang); +rcc_option_name *rccUiGetOptionRccName(rcc_ui_context ctx, rcc_option option); const char *rccUiGetOptionName(rcc_ui_context ctx, rcc_option option); - +const char *rccUiGetOptionValueName(rcc_ui_context ctx, rcc_option option, rcc_option_value value); #endif /* _RCC_UI_NAMES_H */ |