Permalink
Browse files

Change language live (buggy)

  • Loading branch information...
1 parent e19d02d commit 0190a3a47d32f2c91431fc5600ef68293d312f18 @sbourdeauducq sbourdeauducq committed Jun 11, 2011
Showing with 62 additions and 1 deletion.
  1. +44 −1 lib/i18n.c
  2. +4 −0 lib/main.c
  3. +11 −0 lib/scope.c
  4. +3 −0 lib/scope.h
View
@@ -17,14 +17,50 @@
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
+#include "mtkstd.h"
+#include "appman.h"
+#include "scope.h"
+#include "widman.h"
+#include "label.h"
+#include "button.h"
+
#include <mtki18n.h>
+static struct appman_services *appman;
static struct mtk_i18n_entry *current_table;
+static void ec(char *name, char *type, WIDGET *w, void *user)
+{
+ char *s;
+
+ if(strcmp(type, "Button") == 0) {
+ BUTTON *b = (BUTTON *)w;
+
+ s = strdup(b->but->get_text(b));
+ b->but->set_text(b, s);
+ free(s);
+ } else if(strcmp(type, "Label") == 0) {
+ LABEL *l = (LABEL *)w;
+
+ s = strdup(l->lab->get_text(l));
+ l->lab->set_text(l, s);
+ free(s);
+ }
+}
+
void mtk_set_language(struct mtk_i18n_entry *table)
{
+ int i;
+ SCOPE *s;
+
current_table = table;
- /* TODO: notify widgets */
+
+ for(i=1;i<64;i++) {
+ s = appman->get_rootscope(i);
+ if(s != NULL)
+ s->scope->enumerate(s, ec, NULL);
+ }
}
const char *mtk_translate(char *original)
@@ -50,3 +86,10 @@ const char *mtk_translate(char *original)
printf("Warning: no translation found for '%s'\n", original);
return original;
}
+
+int init_i18n(struct mtk_services *d)
+{
+ appman = d->get_module("ApplicationManager 1.0");
+
+ return 1;
+}
View
@@ -77,6 +77,7 @@ extern int init_winlayout (struct mtk_services *);
extern int init_messenger (struct mtk_services *);
extern int init_sharedmem (struct mtk_services *);
extern int init_clipboard (struct mtk_services *);
+extern int init_i18n (struct mtk_services *);
/**
* Prototypes from eventloop.c
@@ -174,6 +175,9 @@ int mtk_init(void *fb, int width, int height)
INFO(printf("%sScope\n",dbg));
init_scope(&mtk);
+ INFO(printf("%si18n\n",dbg));
+ init_i18n(&mtk);
+
INFO(printf("%sButton\n",dbg));
init_button(&mtk);
View
@@ -153,6 +153,16 @@ static SCOPE *scope_get_subscope(SCOPE *s, char *name, int len)
return v->value;
}
+void scope_enumerate(SCOPE *s, scope_enum e, void *user)
+{
+ struct variable *v;
+
+ v = hashtab->get_first(s->sd->vars);
+ while(v != NULL) {
+ e(v->name, v->type, v->value, user);
+ v = hashtab->get_next(s->sd->vars, v);
+ }
+}
/**
* Import scope of another application
@@ -183,6 +193,7 @@ static struct scope_methods scope_methods = {
scope_get_var,
scope_get_vartype,
scope_get_subscope,
+ scope_enumerate,
};
View
@@ -28,11 +28,14 @@ struct scope {
struct scope_data *sd;
};
+typedef void (*scope_enum)(char *, char *, WIDGET *, void *);
+
struct scope_methods {
int (*set_var) (SCOPE *s, char *type, char *name, int len, WIDGET *value);
WIDGET *(*get_var) (SCOPE *s, char *name, int len);
char *(*get_vartype) (SCOPE *s, char *name, int len);
SCOPE *(*get_subscope) (SCOPE *s, char *name, int len);
+ void (*enumerate) (SCOPE *s, scope_enum e, void *user);
};
struct scope_services {

0 comments on commit 0190a3a

Please sign in to comment.