summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-14 17:59:15 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-14 17:59:15 +0000
commit3e5322512be81527430059b901747df7692a6855 (patch)
tree1a7ffe1229f4a5077f11cbdd0fabc246305abfbb
parentf15620c372b8813a87d07eee169cf2096c99c173 (diff)
downloadlibrcc-3e5322512be81527430059b901747df7692a6855.tar.gz
librcc-3e5322512be81527430059b901747df7692a6855.tar.bz2
librcc-3e5322512be81527430059b901747df7692a6855.tar.xz
librcc-3e5322512be81527430059b901747df7692a6855.zip
Localisation
-rw-r--r--README6
-rw-r--r--src/rcclocale.c11
-rw-r--r--src/rccstring.c2
-rw-r--r--src/rccxml.c22
-rw-r--r--ui/gtk.c6
-rw-r--r--ui/internal.h5
-rw-r--r--ui/librccui.c211
-rw-r--r--ui/librccui.h93
-rw-r--r--ui/rccnames.c125
-rw-r--r--ui/rccnames.h19
10 files changed, 409 insertions, 91 deletions
diff --git a/README b/README
index ee7c526..64e510c 100644
--- a/README
+++ b/README
@@ -1,11 +1,9 @@
Library for autoconversion of charsets to/from UTF-8.
-# Add rcd & db4 libs
-# Add Gtk1 plugin
class = charset class
engine = auto engine
selected - which is selected
current - resolves default values
-# ToDo
-# XML files with additional languages \ No newline at end of file
+icnv = NULL - conversion isn't required
+icnv->icnv = (iconv_t)-1 - problem
diff --git a/src/rcclocale.c b/src/rcclocale.c
index 838dfd6..9095bca 100644
--- a/src/rcclocale.c
+++ b/src/rcclocale.c
@@ -41,11 +41,14 @@ int rccLocaleGetLanguage(char *result, const char *lv, unsigned int n) {
locale_class = rccLocaleGetClassByName(lv);
if (locale_class >= 0) {
l = setlocale(locale_class, NULL);
- if (!l) return -1;
- else if ((strcmp(l,"C")==0)||(strcmp(l,"POSIX")==0)) return -1;
- } else return -1;
+ } else {
+ if (!strcasecmp(lv, "LANG")) l = getenv("LANG");
+ else if (!strcasecmp(lv, "LANGUAGE")) l = getenv("LANGUAGE");
+ else l = NULL;
+ }
+ if ((!l)||(strcmp(l,"C")==0)||(strcmp(l,"POSIX")==0)) return -1;
- for (i=0;((l[i])&&(l[i]!='.'));i++);
+ for (i=0;((l[i])&&(l[i]!='.')&&(l[i]!=':'));i++);
for (j=0;rcc_default_aliases[j].alias;j++)
if (strncmp(l,rcc_default_aliases[j].alias,i)==0) {
diff --git a/src/rccstring.c b/src/rccstring.c
index f1f7016..d520693 100644
--- a/src/rccstring.c
+++ b/src/rccstring.c
@@ -48,7 +48,7 @@ int rccStringFixID(rcc_string string, rcc_context ctx) {
language_id = rccGetLanguageByName(ctx, lang);
if ((language_id == (rcc_language_id)-1)||(language_id == 0)) return -1;
- config = rccGetLanguageConfig(ctx, language_id);
+ config = rccGetConfig(ctx, language_id);
if (!config) return -1;
header->language_id = language_id;
diff --git a/src/rccxml.c b/src/rccxml.c
index 5e60731..b7cc1d8 100644
--- a/src/rccxml.c
+++ b/src/rccxml.c
@@ -118,17 +118,19 @@ int rccXmlInit(int LoadConfiguration) {
}
}
- rcc_default_languages[pos].sn = lang;
- rcc_default_languages[pos].charsets[0] = rcc_default_charset;
- if (cpos > 1) rcc_default_languages[pos].charsets[cpos] = NULL;
- else {
- rcc_default_languages[pos].charsets[1] = rcc_utf8_charset;
- rcc_default_languages[pos].charsets[2] = NULL;
- }
- rcc_default_languages[pos].engines[0] = &rcc_default_engine;
- rcc_default_languages[pos].engines[epos] = NULL;
+ if ((cpos > 1)||(epos > 1)) {
+ rcc_default_languages[pos].sn = lang;
+ rcc_default_languages[pos].charsets[0] = rcc_default_charset;
+ if (cpos > 1) rcc_default_languages[pos].charsets[cpos] = NULL;
+ else {
+ rcc_default_languages[pos].charsets[1] = rcc_utf8_charset;
+ rcc_default_languages[pos].charsets[2] = NULL;
+ }
+ rcc_default_languages[pos].engines[0] = &rcc_default_engine;
+ rcc_default_languages[pos].engines[epos] = NULL;
- if (pos == lpos) rcc_default_languages[++lpos].sn = NULL;
+ if (pos == lpos) rcc_default_languages[++lpos].sn = NULL;
+ }
}
clear:
diff --git a/ui/gtk.c b/ui/gtk.c
index 06392ed..da909eb 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -6,7 +6,7 @@
#include "internal.h"
#include "rccnames.h"
-#define TITLE_WIDTH 160
+#define TITLE_WIDTH 224
#define TITLE_HEIGHT 10
#define BOX_SPACING 1
#define BOX_BORDER 0
@@ -127,7 +127,7 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
list = gtk_menu_new();
for (i=0;charsets[i];i++) {
- item = gtk_menu_item_new_with_label(charsets[i]);
+ item = gtk_menu_item_new_with_label(rccUiGetCharsetName(uictx,charsets[i]));
gtk_widget_show(item);
gtk_menu_append(GTK_MENU(list), item);
}
@@ -154,7 +154,7 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) {
list = gtk_menu_new();
for (i=0;engines[i];i++) {
- item = gtk_menu_item_new_with_label(engines[i]->title);
+ item = gtk_menu_item_new_with_label(rccUiGetEngineName(uictx,engines[i]->title));
gtk_widget_show(item);
gtk_menu_append(GTK_MENU(list), item);
}
diff --git a/ui/internal.h b/ui/internal.h
index 64ee978..e814a9f 100644
--- a/ui/internal.h
+++ b/ui/internal.h
@@ -43,8 +43,11 @@ struct rcc_ui_context_t {
rcc_ui_internal internal;
- rcc_language_name *language_names;
+ rcc_name *language_names;
+ rcc_name *charset_names;
+ rcc_name *engine_names;
rcc_option_name *option_names;
+ unsigned char class_names;
rcc_ui_frame_context language_frame;
rcc_ui_frame_context charset_frame;
diff --git a/ui/librccui.c b/ui/librccui.c
index 2c7c632..608e04a 100644
--- a/ui/librccui.c
+++ b/ui/librccui.c
@@ -16,15 +16,41 @@
#define RCC_UI_LOCK_CODE 0x1111
-#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_OPTION_REQUEST "//Options/Option[@name=\"%s\"]/FullName[not(@locale)]"
#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"
+#define XPATH_VALUE_REQUEST "//Options/Option[@name=\"%s\"]/Value[@name=\"%s\"]/FullName[not(@locale)]"
+
+#define XPATH_PAGE "//Pages/Page[@name=\"RusXMMS\"]/FullName[not(@locale)]"
+#define XPATH_LANGUAGE_FRAME "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Language\"]/FullName[not(@locale)]"
+#define XPATH_LANGUAGE_BOX "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Language\"]/Boxes/Box[@name=\"Language\"]/FullName[not(@locale)]"
+#define XPATH_CHARSET_FRAME "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Charset\"]/FullName[not(@locale)]"
+#define XPATH_ENGINE_FRAME "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Engine\"]/FullName[not(@locale)]"
+#define XPATH_ENGINE_BOX "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Engine\"]/Boxes/Box[@name=\"Engine\"]/FullName[not(@locale)]"
+
+#define XPATH_PAGE_LOCALE "//Pages/Page[@name=\"RusXMMS\"]/FullName[@locale=\"%s\"]"
+#define XPATH_LANGUAGE_FRAME_LOCALE "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Language\"]/FullName[@locale=\"%s\"]"
+#define XPATH_LANGUAGE_BOX_LOCALE "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Language\"]/Boxes/Box[@name=\"Language\"]/FullName[@locale=\"%s\"]"
+#define XPATH_CHARSET_FRAME_LOCALE "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Charset\"]/FullName[@locale=\"%s\"]"
+#define XPATH_ENGINE_FRAME_LOCALE "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Engine\"]/FullName[@locale=\"%s\"]"
+#define XPATH_ENGINE_BOX_LOCALE "//Pages/Page[@name=\"RusXMMS\"]/Frames/Frame[@name=\"Engine\"]/Boxes/Box[@name=\"Engine\"]/FullName[@locale=\"%s\"]"
+
+#define XPATH_LANGUAGE "//Languages/Language[@name]"
+#define XPATH_LANGUAGE_REQUEST_LOCALE "//Languages/Language[@name=\"%s\"]/FullName[@locale=\"%s\"]"
+#define XPATH_LANGUAGE_REQUEST "//Languages/Language[@name=\"%s\"]/FullName[not(@locale)]"
+
+#define XPATH_CLASS "//Classes/Class[@name]"
+#define XPATH_CLASS_REQUEST_LOCALE "//Classes/Class[@name=\"%s\"]/FullName[@locale=\"%s\"]"
+#define XPATH_CLASS_REQUEST "//Classes/Class[@name=\"%s\"]/FullName[not(@locale)]"
+#define XPATH_CHARSET "//Charsets/Charset[@name]"
+#define XPATH_CHARSET_REQUEST_LOCALE "//Charsets/Charset[@name=\"%s\"]/FullName[@locale=\"%s\"]"
+#define XPATH_CHARSET_REQUEST "//Charsets/Charset[@name=\"%s\"]/FullName[not(@locale)]"
+#define XPATH_ENGINE "//Engines/Engine[@name]"
+#define XPATH_ENGINE_REQUEST_LOCALE "//Engines/Engine[@name=\"%s\"]/FullName[@locale=\"%s\"]"
+#define XPATH_ENGINE_REQUEST "//Engines/Engine[@name=\"%s\"]/FullName[not(@locale)]"
+
static const char *rccUiXmlGetText(xmlNodePtr node) {
if ((node)&&(node->children)&&(node->children->type == XML_TEXT_NODE)&&(node->children->content)) return node->children->content;
@@ -36,7 +62,7 @@ static xmlNodePtr rccUiNodeFind(xmlXPathContextPtr xpathctx, const char *request
xmlNodePtr res = NULL;
unsigned int i, args = 0;
- unsigned int size = 128;
+ unsigned int size = 256;
va_list ap;
char *req;
@@ -74,6 +100,77 @@ static xmlNodePtr rccUiNodeFind(xmlXPathContextPtr xpathctx, const char *request
return res;
}
+
+#define DO_PAGE(XPATH_ME, XPATH_ME_LOCALE, var) \
+ for (j=0, node = NULL;((search[j])&&(!node));j++) \
+ node = rccUiNodeFind(xpathctx, XPATH_ME_LOCALE, search[j]); \
+ if (!node) { \
+ node = rccUiNodeFind(xpathctx, XPATH_ME); \
+ } \
+ 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); \
+ } \
+ } \
+ var = fullname; \
+ } \
+ } \
+
+#define DO_NAME(XPATH_ME, XPATH_ME_REQUEST, XPATH_ME_REQUEST_LOCALE, my_name) \
+ obj = xmlXPathEvalExpression(XPATH_ME, xpathctx); \
+ if (obj) { \
+ node_set = obj->nodesetval; \
+ if (node_set) nnodes = node_set->nodeNr; \
+ else nnodes = 0; \
+ } else nnodes = 0; \
+ \
+ if (nnodes) { \
+ my_name = (rcc_name*)malloc((nnodes+1)*sizeof(rcc_name)); \
+ if (!my_name) nnodes = 0; \
+ } \
+ \
+ for (i=0,k=0;i<nnodes;i++) { \
+ node = node_set->nodeTab[i]; \
+ attr = xmlHasProp(node, "name"); \
+ class_name = attr->children->content; \
+ \
+ if ((!class_name)||(!class_name[0])) continue; \
+ \
+ for (j=0, node = NULL;((search[j])&&(!node));j++) { \
+ node = rccUiNodeFind(xpathctx, XPATH_ME_REQUEST_LOCALE, class_name, search[j]); \
+ } \
+ if (!node) { \
+ node = rccUiNodeFind(xpathctx, XPATH_ME_REQUEST, class_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); \
+ } \
+ } \
+ \
+ my_name[k].sn = class_name; \
+ my_name[k++].name = fullname; \
+ } \
+ } \
+ } \
+ if (my_name) my_name[k].sn = NULL; \
+ if (obj) xmlXPathFreeObject(obj);
+
+static int initialized = 0;
+
int rccUiInit() {
int err;
unsigned long i, j, k, nnodes;
@@ -86,9 +183,8 @@ int rccUiInit() {
xmlNodePtr node, cnode;
xmlAttrPtr attr;
- rcc_language_name *lang_name;
+ rcc_name *lang_name;
const char *lang, *fullname;
- const char *locale;
char *lpos;
char *search[4];
@@ -96,25 +192,32 @@ int rccUiInit() {
const char *opt, *val;
rcc_option_name *option_name;
const char *value_name;
+ const char *class_name;
unsigned int npos;
size_t newsize;
char tmpbuf[RCC_UI_MAX_STRING_CHARS+1];
char ctype_charset[32];
+ char locale[32];
rcc_iconv icnv;
+ if (initialized) return 0;
+
err = rccInit();
if (err) return err;
+ memcpy(rcc_default_language_names, rcc_default_language_names_embeded, (RCC_MAX_LANGUAGES+1)*sizeof(rcc_name));
+ memcpy(rcc_default_option_names, rcc_default_option_names_embeded, (RCC_MAX_OPTIONS+1)*sizeof(rcc_option_name));
+ memcpy(&rcc_ui_default_page_name, &rcc_ui_default_page_name_embeded, sizeof(rcc_ui_page_name));
+
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");
}
- locale = setlocale(LC_CTYPE, NULL);
- if (locale) {
+ if (!rccLocaleGetLanguage(locale, "LANGUAGE", 32)) {
search[0] = strdup(locale);
if (!search[0]) goto clean;
lpos = strrchr(search[0], '@');
@@ -256,6 +359,17 @@ int rccUiInit() {
}
if (obj) xmlXPathFreeObject(obj);
+ DO_PAGE(XPATH_PAGE, XPATH_PAGE_LOCALE, rcc_ui_default_page_name.title)
+ DO_PAGE(XPATH_LANGUAGE_FRAME, XPATH_LANGUAGE_FRAME_LOCALE, rcc_ui_default_page_name.language.title)
+ DO_PAGE(XPATH_LANGUAGE_BOX, XPATH_LANGUAGE_BOX_LOCALE, rcc_ui_default_page_name.language.language)
+ DO_PAGE(XPATH_CHARSET_FRAME, XPATH_CHARSET_FRAME_LOCALE, rcc_ui_default_page_name.charset.title)
+ DO_PAGE(XPATH_ENGINE_FRAME, XPATH_ENGINE_FRAME_LOCALE, rcc_ui_default_page_name.engine.title)
+ DO_PAGE(XPATH_ENGINE_BOX, XPATH_ENGINE_BOX_LOCALE, rcc_ui_default_page_name.engine.engine)
+
+ DO_NAME(XPATH_CLASS, XPATH_CLASS_REQUEST, XPATH_CLASS_REQUEST_LOCALE, rcc_default_class_names);
+ DO_NAME(XPATH_CHARSET, XPATH_CHARSET_REQUEST, XPATH_CHARSET_REQUEST_LOCALE, rcc_default_charset_names);
+ DO_NAME(XPATH_ENGINE, XPATH_ENGINE_REQUEST, XPATH_ENGINE_REQUEST_LOCALE, rcc_default_engine_names);
+
xmlXPathFreeContext(xpathctx);
}
@@ -263,10 +377,25 @@ clean:
for (j=0;search[j];j++) free(search[j]);
if (icnv) rccIConvClose(icnv);
+ initialized = 1;
+
return 0;
}
void rccUiFree() {
+ if (rcc_default_class_names) {
+ free(rcc_default_class_names);
+ rcc_default_class_names = NULL;
+ }
+ if (rcc_default_charset_names) {
+ free(rcc_default_charset_names);
+ rcc_default_charset_names = NULL;
+ }
+ if (rcc_default_engine_names) {
+ free(rcc_default_engine_names);
+ rcc_default_engine_names = NULL;
+ }
+ initialized = 0;
}
static rcc_ui_frame_context rccUiFrameCreateContext(rcc_ui_frame_type type, rcc_ui_context uictx) {
@@ -324,7 +453,10 @@ rcc_ui_context rccUiCreateContext(rcc_context rccctx) {
ctx->rccctx = rccctx;
ctx->language_names = NULL;
+ ctx->engine_names = NULL;
+ ctx->charset_names = NULL;
ctx->option_names = NULL;
+ ctx->class_names = 0;
ctx->internal = rccUiCreateInternal(ctx);
@@ -388,13 +520,27 @@ void rccUiFreeContext(rcc_ui_context ctx) {
free(ctx);
}
-int rccUiSetLanguageNames(rcc_ui_context ctx, rcc_language_name *names) {
+int rccUiSetLanguageNames(rcc_ui_context ctx, rcc_name *names) {
if (!ctx) return -1;
ctx->language_names = names;
return 0;
}
+int rccUiSetCharsetNames(rcc_ui_context ctx, rcc_name *names) {
+ if (!ctx) return -1;
+
+ ctx->charset_names = names;
+ return 0;
+}
+
+int rccUiSetEngineNames(rcc_ui_context ctx, rcc_name *names) {
+ if (!ctx) return -1;
+
+ ctx->engine_names = names;
+ return 0;
+}
+
int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names) {
if (!ctx) return -1;
@@ -402,6 +548,10 @@ int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names) {
return 0;
}
+int rccUiSetClassNames(rcc_ui_context ctx) {
+ if (!ctx) return -1;
+ ctx->class_names = 1;
+}
int rccUiRestoreLanguage(rcc_ui_context ctx) {
unsigned int i;
@@ -574,7 +724,7 @@ rcc_ui_box rccUiGetOptionBox(rcc_ui_context ctx, rcc_option option, const char *
}
-rcc_ui_frame rccUiGetLanguageFrame(rcc_ui_context ctx, const char *title) {
+rcc_ui_frame rccUiGetLanguageFrame(rcc_ui_context ctx, rcc_ui_language_frame_name *name) {
rcc_ui_frame_context framectx;
rcc_ui_frame frame;
rcc_ui_box language;
@@ -584,11 +734,13 @@ rcc_ui_frame rccUiGetLanguageFrame(rcc_ui_context ctx, const char *title) {
framectx = ctx->language_frame;
if (framectx->frame) return framectx->frame;
- frame = rccUiFrameCreate(ctx->language_frame, title);
+ if (!name) name = &rcc_ui_default_page_name.language;
+
+ frame = rccUiFrameCreate(ctx->language_frame, name->title);
if (frame) framectx->frame = frame;
else return NULL;
- language = rccUiGetLanguageBox(ctx, title);
+ language = rccUiGetLanguageBox(ctx, name->language);
if (!language) return NULL;
rccUiFrameAdd(framectx, language);
@@ -596,8 +748,9 @@ rcc_ui_frame rccUiGetLanguageFrame(rcc_ui_context ctx, const char *title) {
return frame;
}
-rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, const char *title) {
+rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, rcc_ui_charset_frame_name *name) {
unsigned int i;
+ const char *class_name;
rcc_class_ptr *classes;
rcc_ui_frame_context framectx;
rcc_ui_frame frame;
@@ -608,14 +761,18 @@ rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, const char *title) {
framectx = ctx->charset_frame;
if (framectx->frame) return framectx->frame;
- frame = rccUiFrameCreate(framectx, title);
+ if (!name) name = &rcc_ui_default_page_name.charset;
+
+ frame = rccUiFrameCreate(framectx, name->title);
if (frame) framectx->frame = frame;
else return NULL;
classes = rccGetClassList(ctx->rccctx);
for (i=0; classes[i]; i++) {
if (classes[i]->fullname) {
- charset = rccUiGetCharsetBox(ctx, (rcc_class_id)i, classes[i]->fullname);
+ class_name = rccUiGetClassName(ctx, classes[i]->name);
+ if (!class_name) class_name = classes[i]->fullname;
+ charset = rccUiGetCharsetBox(ctx, (rcc_class_id)i, class_name);
rccUiFrameAdd(framectx, charset);
}
}
@@ -625,7 +782,7 @@ rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, const char *title) {
}
-rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, const char *title) {
+rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, rcc_ui_engine_frame_name *name) {
unsigned int i;
rcc_ui_frame_context framectx;
rcc_ui_frame frame;
@@ -637,12 +794,14 @@ rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, const char *title) {
framectx = ctx->engine_frame;
if (framectx->frame) return framectx->frame;
+
+ if (!name) name = &rcc_ui_default_page_name.engine;
- frame = rccUiFrameCreate(framectx, title);
+ frame = rccUiFrameCreate(framectx, name->title);
if (frame) framectx->frame = frame;
else return NULL;
- engine = rccUiGetEngineBox(ctx, title);
+ engine = rccUiGetEngineBox(ctx, name->engine);
rccUiFrameAdd(framectx, engine);
for (i=0; i<RCC_MAX_OPTIONS; i++) {
@@ -659,7 +818,7 @@ 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) {
+rcc_ui_page rccUiGetPage(rcc_ui_context ctx, rcc_ui_page_name *name) {
rcc_ui_page page;
rcc_ui_frame frame;
@@ -667,16 +826,18 @@ rcc_ui_page rccUiGetPage(rcc_ui_context ctx, const char *title, const char *lang
if (ctx->page) return ctx->page;
- page = rccUiPageCreate(ctx, title);
+ if (!name) name = &rcc_ui_default_page_name;
+
+ page = rccUiPageCreate(ctx, name->title);
if (!page) return NULL;
- frame = rccUiGetLanguageFrame(ctx, language_title);
+ frame = rccUiGetLanguageFrame(ctx, &name->language);
rccUiPageAdd(page, frame);
- frame = rccUiGetCharsetsFrame(ctx, charset_title);
+ frame = rccUiGetCharsetsFrame(ctx, &name->charset);
rccUiPageAdd(page, frame);
- frame = rccUiGetEngineFrame(ctx, engine_title);
+ frame = rccUiGetEngineFrame(ctx, &name->engine);
rccUiPageAdd(page, frame);
ctx->page = page;
diff --git a/ui/librccui.h b/ui/librccui.h
index 5a8d034..e526c0a 100644
--- a/ui/librccui.h
+++ b/ui/librccui.h
@@ -7,13 +7,71 @@
extern "C" {
#endif
+typedef struct rcc_ui_context_t *rcc_ui_context;
+
+/*******************************************************************************
+************************************ Names *************************************
+*******************************************************************************/
+
+struct rcc_name_t {
+ const char *sn;
+ const char *name;
+};
+typedef struct rcc_name_t rcc_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_name *names);
+int rccUiSetCharsetNames(rcc_ui_context ctx, rcc_name *names);
+int rccUiSetEngineNames(rcc_ui_context ctx, rcc_name *names);
+
+int rccUiSetOptionNames(rcc_ui_context ctx, rcc_option_name *names);
+int rccUiSetClassNames(rcc_ui_context ctx);
+
+/* page & boxes */
+typedef const char *rcc_ui_box_name;
+struct rcc_ui_language_frame_name_t {
+ const char *title;
+ rcc_ui_box_name language;
+};
+typedef struct rcc_ui_language_frame_name_t rcc_ui_language_frame_name;
+struct rcc_ui_charset_frame_name_t {
+ const char *title;
+};
+typedef struct rcc_ui_charset_frame_name_t rcc_ui_charset_frame_name;
+struct rcc_ui_engine_frame_name_t {
+ const char *title;
+ rcc_ui_box_name engine;
+};
+typedef struct rcc_ui_engine_frame_name_t rcc_ui_engine_frame_name;
+struct rcc_ui_page_name_t {
+ const char *title;
+ rcc_ui_language_frame_name language;
+ rcc_ui_charset_frame_name charset;
+ rcc_ui_engine_frame_name engine;
+};
+typedef struct rcc_ui_page_name_t rcc_ui_page_name;
+
+rcc_ui_page_name *rccUiGetDefaultPageName();
+
+
+/*******************************************************************************
+************************************ API ***************************************
+*******************************************************************************/
+
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;
-
int rccUiInit();
void rccUiFree();
@@ -34,34 +92,11 @@ rcc_ui_box rccUiGetCharsetBox(rcc_ui_context ctx, rcc_class_id id, const char *t
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_frame rccUiGetLanguageFrame(rcc_ui_context ctx, rcc_ui_language_frame_name *name);
+rcc_ui_frame rccUiGetCharsetsFrame(rcc_ui_context ctx, rcc_ui_charset_frame_name *name);
+rcc_ui_frame rccUiGetEngineFrame(rcc_ui_context ctx, rcc_ui_engine_frame_name *name);
-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);
+rcc_ui_page rccUiGetPage(rcc_ui_context ctx, rcc_ui_page_name *name);
#ifdef __cplusplus
}
diff --git a/ui/rccnames.c b/ui/rccnames.c
index 5b3096a..933c910 100644
--- a/ui/rccnames.c
+++ b/ui/rccnames.c
@@ -3,8 +3,11 @@
#include <librcc.h>
#include "internal.h"
+#include "rccnames.h"
-rcc_language_name rcc_default_language_names[RCC_MAX_LANGUAGES+1] = {
+rcc_name rcc_default_language_names[RCC_MAX_LANGUAGES+1];
+
+rcc_name rcc_default_language_names_embeded[RCC_MAX_LANGUAGES+1] = {
{"default", "Autodetect"},
{"off", "Dissable"},
{"ru","Russian"},
@@ -28,7 +31,8 @@ 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_option_name rcc_default_option_names[RCC_MAX_OPTIONS+1];
+rcc_option_name rcc_default_option_names_embeded[RCC_MAX_OPTIONS+1] = {
{ RCC_OPTION_LEARNING_MODE, "Recodings Cache", rcc_default_option_learning_names },
{ RCC_OPTION_AUTODETECT_FS_NAMES, "Autodetect File Names", rcc_default_option_boolean_names },
{ RCC_OPTION_AUTODETECT_FS_TITLES, "Autodetect FS Titles", rcc_default_option_boolean_names },
@@ -36,31 +40,77 @@ rcc_option_name rcc_default_option_names[RCC_MAX_OPTIONS+1] = {
{ RCC_MAX_OPTIONS }
};
+rcc_ui_page_name rcc_ui_default_page_name;
+rcc_ui_page_name rcc_ui_default_page_name_embeded = {
+ "Encodings",
+ { "Language", "Language" },
+ { "Encodings" },
+ { "AutoDetection", "Engine" }
+};
+
-rcc_language_name *rccUiGetLanguageRccName(rcc_ui_context ctx, const char *lang) {
+rcc_name *rcc_default_class_names = NULL;
+rcc_name *rcc_default_charset_names = NULL;
+rcc_name *rcc_default_engine_names = NULL;
+
+typedef enum rcc_name_type_t {
+ RCC_NAME_TYPE_CLASS = 0,
+ RCC_NAME_TYPE_CHARSET,
+ RCC_NAME_TYPE_ENGINE,
+ RCC_NAME_TYPE_LANGUAGE,
+ RCC_NAME_TYPE_MAX
+} rcc_name_type;
+
+rcc_name *rccUiGetRccName(rcc_ui_context ctx, const char *findname, unsigned char type) {
const char *res;
unsigned int i,j;
- rcc_language_name *names;
+ rcc_name *names[2], *nm;
- if (!lang) return NULL;
+ if (!findname) return NULL;
- for (j=0;j<2;j++) {
- if (j) names = rcc_default_language_names;
- else names = ctx?ctx->language_names:NULL;
+ switch (type) {
+ case RCC_NAME_TYPE_LANGUAGE:
+ names[0] = ctx?ctx->language_names:NULL;
+ names[1] = rcc_default_language_names;
+ break;
+ case RCC_NAME_TYPE_CHARSET:
+ names[0] = ctx?ctx->charset_names:NULL;
+ names[1] = rcc_default_charset_names;
+ break;
+ case RCC_NAME_TYPE_ENGINE:
+ names[0] = ctx?ctx->engine_names:NULL;
+ names[1] = rcc_default_engine_names;
+ break;
+ case RCC_NAME_TYPE_CLASS:
+ if (ctx->class_names) return NULL;
+
+ names[0] = NULL;
+ names[1] = rcc_default_class_names;
+ break;
+ default:
+ return NULL;
+ }
+
- if (names) {
- for (i=0;names[i].sn;i++)
- if (!strcmp(lang, names[i].sn)) return names+i;
+ for (j=0;j<2;j++) {
+ nm = names[j];
+ if (nm) {
+ for (i=0;nm[i].sn;i++)
+ if (!strcasecmp(findname, nm[i].sn)) return nm+i;
}
}
return NULL;
}
+rcc_name *rccUiGetLanguageRccName(rcc_ui_context ctx, const char *lang) {
+ return rccUiGetRccName(ctx, lang, RCC_NAME_TYPE_LANGUAGE);
+}
+
const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang) {
const char *res;
unsigned int i,j;
- rcc_language_name *names;
+ rcc_name *names;
names = rccUiGetLanguageRccName(ctx, lang);
if ((names)&&(names->name)) return names->name;
@@ -68,6 +118,53 @@ const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang) {
return lang;
}
+rcc_name *rccUiGetCharsetRccName(rcc_ui_context ctx, const char *charset) {
+ return rccUiGetRccName(ctx, charset, RCC_NAME_TYPE_CHARSET);
+}
+
+const char *rccUiGetCharsetName(rcc_ui_context ctx, const char *charset) {
+ const char *res;
+ unsigned int i,j;
+ rcc_name *names;
+
+ names = rccUiGetCharsetRccName(ctx, charset);
+ if ((names)&&(names->name)) return names->name;
+
+ return charset;
+}
+
+rcc_name *rccUiGetEngineRccName(rcc_ui_context ctx, const char *engine) {
+ return rccUiGetRccName(ctx, engine, RCC_NAME_TYPE_ENGINE);
+}
+
+const char *rccUiGetEngineName(rcc_ui_context ctx, const char *engine) {
+ const char *res;
+ unsigned int i,j;
+ rcc_name *names;
+
+ names = rccUiGetEngineRccName(ctx, engine);
+ if ((names)&&(names->name)) return names->name;
+
+ return engine;
+}
+
+rcc_name *rccUiGetClassRccName(rcc_ui_context ctx, const char *cl) {
+ return rccUiGetRccName(ctx, cl, RCC_NAME_TYPE_CLASS);
+}
+
+const char *rccUiGetClassName(rcc_ui_context ctx, const char *cl) {
+ const char *res;
+ unsigned int i,j;
+ rcc_name *names;
+
+ names = rccUiGetClassRccName(ctx, cl);
+ if ((names)&&(names->name)) return names->name;
+
+ return NULL;
+}
+
+
+
rcc_option_name *rccUiGetOptionRccName(rcc_ui_context ctx, rcc_option option) {
unsigned int i,j;
rcc_option_name *names;
@@ -109,3 +206,7 @@ const char *rccUiGetOptionValueName(rcc_ui_context ctx, rcc_option option, rcc_o
return NULL;
}
+
+rcc_ui_page_name *rccUiGetDefaultPageName() {
+ return &rcc_ui_default_page_name;
+}
diff --git a/ui/rccnames.h b/ui/rccnames.h
index f73bd19..b026797 100644
--- a/ui/rccnames.h
+++ b/ui/rccnames.h
@@ -1,11 +1,26 @@
#ifndef _RCC_UI_NAMES_C
#define _RCC_UI_NAMES_H
-extern rcc_language_name rcc_default_language_names[];
+extern rcc_name rcc_default_language_names[];
+extern rcc_name rcc_default_language_names_embeded[];
extern rcc_option_name rcc_default_option_names[];
+extern rcc_option_name rcc_default_option_names_embeded[];
+extern rcc_ui_page_name rcc_ui_default_page_name;
+extern rcc_ui_page_name rcc_ui_default_page_name_embeded;
+extern rcc_name *rcc_default_class_names;
+extern rcc_name *rcc_default_charset_names;
+extern rcc_name *rcc_default_engine_names;
-rcc_language_name *rccUiGetLanguageRccName(rcc_ui_context ctx, const char *lang);
+
+rcc_name *rccUiGetLanguageRccName(rcc_ui_context ctx, const char *lang);
const char *rccUiGetLanguageName(rcc_ui_context ctx, const char *lang);
+rcc_name *rccUiGetCharsetRccName(rcc_ui_context ctx, const char *charset);
+const char *rccUiGetCharsetName(rcc_ui_context ctx, const char *charset);
+rcc_name *rccUiGetEngineRccName(rcc_ui_context ctx, const char *engine);
+const char *rccUiGetEngineName(rcc_ui_context ctx, const char *engine);
+rcc_name *rccUiGetClassRccName(rcc_ui_context ctx, const char *cl);
+const char *rccUiGetClassName(rcc_ui_context ctx, const char *cl);
+
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);