Exemple #1
0
void
i18n_init(void)
{
  prop_t *s = settings_add_dir(NULL, _p("Languages"), "i18n", NULL,
			       _p("Preferred languages"),
			       "settings:i18n");
  int i;

  nls_init(s);

#ifdef STOS
  setting_create(SETTING_STRING, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Timezone")),
                 SETTING_CALLBACK(set_timezone, NULL),
                 SETTING_STORE("i18n", "timezone"),
                 NULL);

#endif

  setting_create(SETTING_MULTIOPT, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Time format")),
                 SETTING_STORE("i18n", "timeformat"),
                 SETTING_WRITE_INT(&gconf.time_format),
                 SETTING_OPTION(gconf.time_format_system ? "0" : NULL,
                                _p("System default")),
                 SETTING_OPTION("1", _p("24 Hour")),
                 SETTING_OPTION("2", _p("12 Hour")),
                 NULL);


  settings_create_info(s,
		       NULL,
		       _p("Language codes should be configured as three character ISO codes, example (eng, swe, fra)"));

  setting_create(SETTING_STRING, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Primary audio language code")),
                 SETTING_CALLBACK(set_lang, &lang_audio[0]),
                 SETTING_STORE("i18n", "audio1"),
                 NULL);

  setting_create(SETTING_STRING, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Secondary audio language code")),
                 SETTING_CALLBACK(set_lang, &lang_audio[1]),
                 SETTING_STORE("i18n", "audio2"),
                 NULL);

  setting_create(SETTING_STRING, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Tertiary audio language code")),
                 SETTING_CALLBACK(set_lang, &lang_audio[2]),
                 SETTING_STORE("i18n", "audio3"),
                 NULL);


  setting_create(SETTING_STRING, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Primary subtitle language code")),
                 SETTING_CALLBACK(&set_lang, &lang_subtitle[0]),
                 SETTING_STORE("i18n", "subtitle1"),
                 NULL);

  setting_create(SETTING_STRING, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Secondary subtitle language code")),
                 SETTING_CALLBACK(&set_lang, &lang_subtitle[1]),
                 SETTING_STORE("i18n", "subtitle2"),
                 NULL);

  setting_create(SETTING_STRING, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Tertiary subtitle language code")),
                 SETTING_CALLBACK(&set_lang, &lang_subtitle[2]),
                 SETTING_STORE("i18n", "subtitle3"),
                 NULL);

  const char **optlist = NULL;
  const charset_t *cs;
  for(i = 0; (cs = charset_get_idx(i)) != NULL; i++) {}

  optlist = alloca((i * 2 + 3) * sizeof(const char *));

  optlist[0] = "auto";
  optlist[1] = "Auto";

  for(i = 0; (cs = charset_get_idx(i)) != NULL; i++) {
    optlist[i * 2 + 2] = cs->id;
    optlist[i * 2 + 3] = cs->title;
  }
  optlist[i * 2 + 2] = NULL;

  setting_create(SETTING_MULTIOPT, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Default character set")),
                 SETTING_STORE("i18n", "default_charset"),
                 SETTING_CALLBACK(set_default_charset, NULL),
                 SETTING_OPTION_LIST(optlist),
                 NULL);

  setting_create(SETTING_BOOL, s, SETTINGS_INITIAL_UPDATE,
                 SETTING_TITLE(_p("Ignore 'The' at beginning of words when sorting")),
                 SETTING_STORE("i18n", "skipthe"),
                 SETTING_WRITE_BOOL(&gconf.ignore_the_prefix),
                 NULL);
}
Exemple #2
0
static JSBool 
js_createMultiOpt(JSContext *cx, JSObject *obj, uintN argc, 
		  jsval *argv, jsval *rval)
{
  js_setting_group_t *jsg = JS_GetPrivate(cx, obj);
  const char *id;
  const char *title;
  JSObject *func;
  JSObject *optlist;
  JSBool persistent = JS_FALSE;

  if(!JS_ConvertArguments(cx, argc, argv, "ssoo/b",
			  &id, &title, &optlist, &func, &persistent))
    return JS_FALSE;

  js_setting_t *jss = jss_create(cx, obj, id, rval, func, jsg, persistent);
  if(jss == NULL)
    return JS_FALSE;

  char **options = NULL;
  JSIdArray *opts, *opt;
  int i;

  char *defvalue = NULL;

  if((opts = JS_Enumerate(cx, optlist)) != NULL) {

    for(i = 0; i < opts->length; i++) {
      jsval name, value, id, title, def;
      if(!JS_IdToValue(cx, opts->vector[i], &name) ||
         !JSVAL_IS_INT(name) ||
         !JS_GetElement(cx, optlist, JSVAL_TO_INT(name), &value) ||
         !JSVAL_IS_OBJECT(value) ||
         (opt = JS_Enumerate(cx, JSVAL_TO_OBJECT(value))) == NULL)
        continue;

      if(opt->length >= 2 &&
         JS_GetElement(cx, JSVAL_TO_OBJECT(value), 0, &id) &&
         JS_GetElement(cx, JSVAL_TO_OBJECT(value), 1, &title)) {

        if(opt->length < 3 ||
           !JS_GetElement(cx, JSVAL_TO_OBJECT(value), 2, &def))
          def = JSVAL_FALSE;

        const char *k = JS_GetStringBytes(JS_ValueToString(cx, id));

        if(def == JSVAL_TRUE)
          mystrset(&defvalue, k);

        strvec_addp(&options, k);
        strvec_addp(&options, JS_GetStringBytes(JS_ValueToString(cx, title)));
      }
      JS_DestroyIdArray(cx, opt);
    }
    JS_DestroyIdArray(cx, opts);
  }

  rstr_t *r = NULL;
  if(persistent && jsg->jsg_kv_url)
    r = kv_url_opt_get_rstr(jsg->jsg_kv_url, KVSTORE_DOMAIN_PLUGIN, id);


  jss->jss_s =
    setting_create(SETTING_MULTIOPT, jsg->jsg_root,
                   SETTINGS_INITIAL_UPDATE | jsg->jsg_settings_flags,
                   SETTING_TITLE_CSTR(title),
                   SETTING_COURIER(js_global_pc),
                   SETTING_CALLBACK(js_store_update_string, jss),
                   SETTING_VALUE(r ? rstr_get(r) : defvalue),
                   SETTING_OPTION_LIST(options),
                   SETTING_HTSMSG_CUSTOM_SAVER(id, jsg->jsg_store,
                                               js_setting_group_save, jsg),
                   NULL);

  strvec_free(options);
  rstr_release(r);
  jss->jss_cx = NULL;
  return JS_TRUE;
}