Пример #1
0
static void on_tts_combobox_changed(GtkComboBox *widget, gpointer data)
{
	gint index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
	if (index == 1)
		voice_engine = "voice_kal_diphone";
	else if (index == 2)
		voice_engine = "voice_ked_diphone";
	else if (index == 3)
		voice_engine = "voice_cmu_us_jmk_arctic_hts";
	else if (index == 4)
		voice_engine = "voice_cmu_us_bdl_arctic_hts";
	else if (index == 5)
		voice_engine = "voice_cmu_us_awb_arctic_hts";
	else if (index == 6)
		voice_engine = "voice_cmu_us_slt_arctic_hts";
	else
		voice_engine.clear();
	if (!voice_engine.empty()) {
		std::string command = "(";
		command += voice_engine;
		command += ")";
		festival_eval_command(command.c_str());
	}
	gchar *data1 = g_strdup_printf("[festival]\nvoice=%s\n", voice_engine.c_str());
	std::string res = get_cfg_filename();
	g_file_set_contents(res.c_str(), data1, -1, NULL);
	g_free(data1);
}
static void configure()
{
	GtkWidget *window = gtk_dialog_new_with_buttons(_("Dict.cn configuration"), GTK_WINDOW(plugin_info->pluginwin), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
	GtkWidget *vbox = gtk_vbox_new(false, 5);
	GtkWidget *xml_button = gtk_radio_button_new_with_label(NULL, _("Query by XML API."));
	gtk_box_pack_start(GTK_BOX(vbox), xml_button, false, false, 0);
	GtkWidget *html_button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(xml_button), _("Query by HTML API."));
	gtk_box_pack_start(GTK_BOX(vbox), html_button, false, false, 0);
	if (use_html_or_xml) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(html_button), true);
	} else {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(xml_button), true);
	}
	gtk_widget_show_all(vbox);
	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(window)->vbox), vbox);
	gtk_dialog_run(GTK_DIALOG(window));
	gboolean new_use_html_or_xml = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(html_button));
	if (new_use_html_or_xml != use_html_or_xml) {
		use_html_or_xml = new_use_html_or_xml;
		const char *tmp;
		if (use_html_or_xml) {
			tmp = "true";
		} else {
			tmp = "false";
		}
		gchar *data = g_strdup_printf("[dictdotcn]\nuse_html_or_xml=%s\n", tmp);
		std::string res = get_cfg_filename();
		g_file_set_contents(res.c_str(), data, -1, NULL);
		g_free(data);
	}
	gtk_widget_destroy (window);
}
Пример #3
0
//----------------------------------------------------------------------
static int idaapi notify(processor_t::idp_notify msgid, ...)
{
  va_list va;

  va_start(va, msgid);

  // A well behaving processor module should call invoke_callbacks()
  // in his notify() function. If this function returns 0, then
  // the processor module should process the notification itself
  // Otherwise the code should be returned to the caller:

  int code = invoke_callbacks(HT_IDP, msgid, va);

  if (code)
    return code;

  switch (msgid)
  {
    case processor_t::init:
      inf.mf = 0;
      inf.s_genflags |= INFFL_LZERO;
      helper.create("$ CR16");
    default:
      break;

    case processor_t::term:
      free_ioports(ports, numports);
      break;

    case processor_t::newfile:
      // ask for a  processor from the config file
      // use it to handle ports and registers
      {
        char cfgfile[QMAXFILE];

        get_cfg_filename(cfgfile, sizeof(cfgfile));
        if ( choose_ioport_device(cfgfile, device, sizeof(device), parse_area_line0) )
          set_device_name(device, IORESP_ALL);
      }
      break;

    case processor_t::newprc:
      {
        char buf[MAXSTR];
        if (helper.supval(-1, buf, sizeof(buf)) > 0)
          set_device_name(buf, IORESP_PORT);
      }
      break;

    case processor_t::newseg:
      {
        segment_t *s = va_arg(va, segment_t *);
        // Set default value of DS register for all segments
        set_default_dataseg(s->sel);
      }
      break;
  }
  va_end(va);
  return 1;
}
Пример #4
0
bool stardict_tts_plugin_init(StarDictTtsPlugInObject *obj)
{
	festival_initialize(1, 210000);
	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[festival]\nvoice=\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	gchar *str = g_key_file_get_string(keyfile, "festival", "voice", NULL);
	g_key_file_free(keyfile);
	if (str) {
		voice_engine = str;
		g_free(str);
	}
	if (!voice_engine.empty()) {
		std::string command = "(";
		command += voice_engine;
		command += ")";
		festival_eval_command(command.c_str());
	}
	obj->saytext_func = saytext;
	obj->tts_name = _("Festival TTS");
	g_print(_("Festival plug-in loaded.\n"));
	return false;
}
Пример #5
0
DLLIMPORT bool stardict_specialdict_plugin_init(StarDictSpecialDictPlugInObject *obj)
{
	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[wordnet]\ntext_or_graphic_mode=false\nwidth=400\nheight=300\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	GError *err;
	err = NULL;
	text_or_graphic_mode = g_key_file_get_boolean(keyfile, "wordnet", "text_or_graphic_mode", &err);
	if (err) {
		g_error_free (err);
		text_or_graphic_mode = false;
	}
	err = NULL;
	widget_width = g_key_file_get_integer(keyfile, "wordnet", "width", &err);
	if (err) {
		g_error_free (err);
		widget_width = 400;
	}
	err = NULL;
	widget_height = g_key_file_get_integer(keyfile, "wordnet", "height", &err);
	if (err) {
		g_error_free (err);
		widget_height = 300;
	}
	g_key_file_free(keyfile);
	obj->render_widget_func = render_widget;
	obj->dict_type = "wordnet";
	g_print(_("WordNet dict rendering plug-in loaded.\n"));
	return false;
}
Пример #6
0
static void on_tts_combobox_changed(GtkComboBox *widget, gpointer data)
{
	gint index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
	if (index == 1)
		voice_engine = "kal";
	else if (index == 2)
		voice_engine = "awb_time";
	else if (index == 3)
		voice_engine = "kal16";
	else if (index == 4)
		voice_engine = "awb";
	else if (index == 5)
		voice_engine = "rms";
	else if (index == 6)
		voice_engine = "slt";
	else
		voice_engine.clear();
	if (!voice_engine.empty()) {
		now_voice = flite_voice_select(voice_engine.c_str());
	} else {
		now_voice = flite_voice_select(NULL);
	}
	gchar *data1 = g_strdup_printf("[flite]\nvoice=%s\n", voice_engine.c_str());
	std::string res = get_cfg_filename();
	g_file_set_contents(res.c_str(), data1, -1, NULL);
	g_free(data1);
}
Пример #7
0
inline static void idaapi choose_device(TView *[] = NULL, int = 0)
{
  char cfgfile[QMAXFILE];
  get_cfg_filename(cfgfile, sizeof(cfgfile));
  if ( choose_ioport_device(cfgfile, device, sizeof(device), NULL) )
    set_device_name(device, IORESP_NONE);
}
Пример #8
0
bool stardict_tts_plugin_init(StarDictTtsPlugInObject *obj)
{
	flite_init();

	register_cmu_us_kal(NULL);
	register_cmu_time_awb(NULL);
	register_cmu_us_kal16(NULL);
	register_cmu_us_awb(NULL);
	register_cmu_us_rms(NULL);
	register_cmu_us_slt(NULL);

	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[flite]\nvoice=\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	gchar *str = g_key_file_get_string(keyfile, "flite", "voice", NULL);
	g_key_file_free(keyfile);
	if (str) {
		voice_engine = str;
		g_free(str);
	}
	if (!voice_engine.empty()) {
		now_voice = flite_voice_select(voice_engine.c_str());
	} else {
		now_voice = flite_voice_select(NULL);
	}
	obj->saytext_func = saytext;
	obj->tts_name = _("Flite TTS");
	g_print(_("Flite plug-in loaded.\n"));
	return false;
}
Пример #9
0
int configfile_get_value(const char* filename, const char* name)
{
    int fd;
    char *pname;
    char *pval;
    char buf[MAX_PATH];

    get_cfg_filename(buf, MAX_PATH, filename);
    fd = rb->open(buf, O_RDONLY);
    if(fd < 0)
        return -1;

    while(rb->read_line(fd, buf, MAX_PATH) > 0)
    {
        rb->settings_parseline(buf, &pname, &pval);
        if(!rb->strcmp(name, pname))
        {
          rb->close(fd);
          return rb->atoi(pval);
        }
    }

    rb->close(fd);
    return -1;
}
Пример #10
0
//------------------------------------------------------------------
const char *idaapi set_idp_options(const char *keyword,int /*value_type*/,const void * /*value*/)
{
  if ( keyword != NULL ) return IDPOPT_BADKEY;
  char cfgfile[QMAXFILE];
  get_cfg_filename(cfgfile, sizeof(cfgfile));
  if ( choose_ioport_device(cfgfile, device, sizeof(device), parse_area_line0) )
    set_device_name(device, IORESP_NONE);
  return IDPOPT_OK;
}
Пример #11
0
//----------------------------------------------------------------------
static int idaapi notify(processor_t::idp_notify msgid, ...)
{
  va_list va;
  va_start(va, msgid);

  // A well behaving processor module should call invoke_callbacks()
  // in his notify() function. If this function returns 0, then
  // the processor module should process the notification itself
  // Otherwise the code should be returned to the caller:
  int code = invoke_callbacks(HT_IDP, msgid, va);
  if ( code != 0 )
    return code;

  switch ( msgid )
  {
    case processor_t::init:
      inf.mf = 0;
      inf.s_genflags |= INFFL_LZERO;
      helper.create("$ C39");
    default:
      break;

    case processor_t::term:
      free_ioports(ports, numports);
      break;

    case processor_t::newfile:
      //Выводит длг. окно процессоров, и позволяет выбрать нужный, считывает для выбраного
      //процессора информацию из cfg. По считаной информации подписывает порты и регстры
      {
        char cfgfile[QMAXFILE];
        get_cfg_filename(cfgfile, sizeof(cfgfile));
        if ( choose_ioport_device(cfgfile, device, sizeof(device), parse_area_line0) )
          set_device_name(device, IORESP_ALL);
      }
      break;

    case processor_t::newprc:
      {
        char buf[MAXSTR];
        if ( helper.supval(-1, buf, sizeof(buf)) > 0 )
          set_device_name(buf, IORESP_PORT);
      }
      break;

    case processor_t::newseg:
      {
        segment_t *s = va_arg(va, segment_t *);
        // Set default value of DS register for all segments
        set_default_dataseg(s->sel);
      }
      break;
  }
  va_end(va);
  return(1);
}
Пример #12
0
DLLIMPORT bool stardict_tts_plugin_init(StarDictTtsPlugInObject *obj)
{
	if (FAILED(::CoInitialize(NULL)))
		return true;
	HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
	if(!SUCCEEDED(hr)) {
		::CoUninitialize();
		return true;
	}
	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[sapi_tts]\nvoice=\nvolume=100\nrate=0\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	gchar *text = g_key_file_get_string(keyfile, "sapi_tts", "voice", NULL);
	if (text) {
		if (text[0] != '\0') {
			DWORD dwNum = MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
			wchar_t *pwText;
			pwText = new wchar_t[dwNum];
			MultiByteToWideChar(CP_UTF8, 0, text, -1, pwText, dwNum);
			ISpObjectToken *pToken;
			if (SpGetTokenFromId(pwText , &pToken) == S_OK) {
				pVoice->SetVoice(pToken);
				pToken->Release();
			}
			delete []pwText;
		}
		g_free(text);
	}
	GError *err;
	err = NULL;
	USHORT volume = g_key_file_get_integer(keyfile, "sapi_tts", "volume", &err);
	if (err) {
		g_error_free (err);
		volume = 100;
	}
	err = NULL;
	long rate = g_key_file_get_integer(keyfile, "sapi_tts", "rate", &err);
	if (err) {
		g_error_free (err);
		rate = 0;
	}
	g_key_file_free(keyfile);
	pVoice->SetVolume(volume);
	pVoice->SetRate(rate);
	obj->saytext_func = saytext;
	obj->tts_name = _("SAPI TTS");
	g_print(_("SAPI tts plug-in loaded.\n"));
	return false;
}
Пример #13
0
static void save_conf_file()
{
	const char *tmp;
	if (text_or_graphic_mode) {
		tmp = "true";
	} else {
		tmp = "false";
	}
	gchar *data = g_strdup_printf("[wordnet]\ntext_or_graphic_mode=%s\nwidth=%d\nheight=%d\n", tmp, widget_width, widget_height);
	std::string res = get_cfg_filename();
	g_file_set_contents(res.c_str(), data, -1, NULL);
	g_free(data);
}
Пример #14
0
static int notify(processor_t::idp_notify msgid, ...) { // Various messages:
  va_list va;
  va_start(va, msgid);

// A well behaving processor module should call invoke_callbacks()
// in his notify() function. If this function returns 0, then
// the processor module should process the notification itself
// Otherwise the code should be returned to the caller:

  int code = invoke_callbacks(HT_IDP, msgid, va);
  if ( code ) return code;

  switch ( msgid )
  {
    case processor_t::init:
      helper.create("$ z80");
      break;

    case processor_t::newprc:
      {
        int np = va_arg(va, int);
        pflag = features[np];
        ph.assemblers = i8085asms;
        if ( isZ80() ) ph.assemblers = Z80asms;
        if ( is64180() ) ph.assemblers = HD64180asms;
        if ( isGB() ) ph.assemblers = GBasms;
        {
          char buf[MAXSTR];
          if ( helper.supval(-1, buf, sizeof(buf)) > 0 )
            set_device_name(buf, IORESP_NONE);
        }
      }
      break;

    case processor_t::newfile:
      if ( strcmp(inf.procName, "z180") == 0 )
      {
        char cfgfile[QMAXFILE];
        get_cfg_filename(cfgfile, sizeof(cfgfile));
        if ( choose_ioport_device(cfgfile, device, sizeof(device), parse_area_line0) )
          set_device_name(device, IORESP_AREA);
      }
      break;

    default:
      break;
  }
  va_end(va);

  return(1);
}
Пример #15
0
int configfile_save(const char *filename, struct configdata *cfg,
                    int num_items, int version)
{
    int fd;
    int i;
    char buf[MAX_PATH];

    get_cfg_filename(buf, MAX_PATH, filename);
    fd = rb->creat(buf, 0666);
    if(fd < 0)
        return fd*10 - 1;

    /* pre-allocate 10 bytes for INT */
    rb->fdprintf(fd, "file version: %10d\n", version);
    
    for(i = 0;i < num_items;i++) {
        switch(cfg[i].type) {
            case TYPE_INT:
                /* pre-allocate 10 bytes for INT */
                rb->fdprintf(fd, "%s: %10d\n",
                                cfg[i].name,
                                *cfg[i].int_p);
                break;

            case TYPE_BOOL:
                rb->fdprintf(fd, "%s: %10d\n",
                                cfg[i].name,
                                (int)*cfg[i].bool_p);
                break;

            case TYPE_ENUM:
                rb->fdprintf(fd, "%s: %s\n",
                                cfg[i].name,
                                cfg[i].values[*cfg[i].int_p]);
                break;

            case TYPE_STRING:
                rb->fdprintf(fd, "%s: %s\n",
                                cfg[i].name,
                                cfg[i].string);
                break;

        }
    }

    rb->close(fd);
    return 0;
}
Пример #16
0
//----------------------------------------------------------------------
static bool select_device(int respect_info)
{
  char cfgfile[QMAXFILE];
  get_cfg_filename(cfgfile, sizeof(cfgfile));
  if ( !choose_ioport_device(cfgfile, device, sizeof(device), NULL) )
  {
    qstrncpy(device, NONEPROC, sizeof(device));
    return false;
  }

  if ( !display_infotype_dialog(IORESP_ALL, &respect_info, cfgfile) )
    return false;

  set_device_name(device, respect_info);
  return true;
}
DLLIMPORT bool stardict_misc_plugin_init(void)
{
	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[update]\nlatest_version_num=0\nlast_prompt_num=0\nversion_msg_title=\nversion_msg_content=\nlatest_news=\n[misc]\nshow_ads=true\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	GError *err;
	err = NULL;
	latest_version_num = g_key_file_get_integer(keyfile, "update", "latest_version_num", &err);
	if (err) {
		g_error_free (err);
		latest_version_num = 0;
	}
	err = NULL;
	last_prompt_num = g_key_file_get_integer(keyfile, "update", "last_prompt_num", &err);
	if (err) {
		g_error_free (err);
		last_prompt_num = 0;
	}
	char *str;
	str = g_key_file_get_string(keyfile, "update", "version_msg_title", NULL);
	if (str) {
		version_msg_title = str;
		g_free(str);
	}
	str = g_key_file_get_string(keyfile, "update", "version_msg_content", NULL);
	if (str) {
		version_msg_content = str;
		g_free(str);
	}
	str = g_key_file_get_string(keyfile, "update", "latest_news", NULL);
	if (str) {
		latest_news = str;
		g_free(str);
	}
	err = NULL;
	show_ads = g_key_file_get_boolean(keyfile, "misc", "show_ads", &err);
	if (err) {
		g_error_free (err);
		show_ads = true;
	}
	g_key_file_free(keyfile);
	g_print(_("Update info plug-in loaded.\n"));
	return false;
}
Пример #18
0
//------------------------------------------------------------------
static bool apply_config_file(int _respect_info)
{
  if ( strcmp(device, NONEPROC) == 0 )  // processor not selected
    return true;

  char cfgfile[QMAXFILE];
  char cfgpath[QMAXPATH];
  get_cfg_filename(cfgfile, sizeof(cfgfile));
  if ( getsysfile(cfgpath, sizeof(cfgpath), cfgfile, CFG_SUBDIR) == NULL )
  {
#ifndef SILENT
    warning("ICON ERROR\n"
            "Can not open %s, I/O port definitions are not loaded", cfgfile);
#endif
    return false;
  }
  deviceparams[0] = '\0';
  if ( !CHECK_IORESP ) _respect_info = 0;
  respect_info = _respect_info;
  free_ioports(ports, numports);
  ports = read_ioports(&numports, cfgpath, device, sizeof(device), callback);
  if ( respect_info & IORESP_PORT )
  {
    for ( int i=0; i < numports; i++ )
    {
      ioport_t *p = ports + i;
#ifdef I8051
      segment_t *s = get_segm_by_name("FSR");
      if ( s != NULL )
      {
        set_name(p->address + s->startEA - 0x80, p->name);
        set_cmt(p->address + s->startEA - 0x80, p->cmt, true);
      }
#else
      set_name(p->address, p->name);
      set_cmt(p->address, p->cmt, true);
#endif
    }
  }
  return true;
}
Пример #19
0
int configfile_update_entry(const char* filename, const char* name, int val)
{
    int fd;
    char *pname;
    char *pval;
    char path[MAX_PATH];
    char buf[256];
    int found = 0;
    int line_len = 0;
    int pos = 0;
    
    /* open the current config file */
    get_cfg_filename(path, MAX_PATH, filename);
    fd = rb->open(path, O_RDWR);
    if(fd < 0)
        return -1;
    
    /* read in the current stored settings */
    while((line_len = rb->read_line(fd, buf, 256)) > 0)
    {
        rb->settings_parseline(buf, &pname, &pval);
        if(!rb->strcmp(name, pname))
        {
            found = 1;
            rb->lseek(fd, pos, SEEK_SET);
            /* pre-allocate 10 bytes for INT */
            rb->fdprintf(fd, "%s: %10d\n", pname, val);
            break;
        }
        pos += line_len;
    }
    
    /* if (name/val) is a new entry just append to file */
    if (found == 0)
        /* pre-allocate 10 bytes for INT */
        rb->fdprintf(fd, "%s: %10d\n", name, val);
    
    rb->close(fd);
    
    return found;
}
Пример #20
0
const char *idaapi set_idp_options(
    const char *keyword,
    int /*value_type*/,
    const void * /*value*/ )
{
    if ( keyword != NULL )
        return IDPOPT_BADKEY;

    char cfgfile[QMAXFILE];
    get_cfg_filename(cfgfile, sizeof(cfgfile));
    if ( !choose_ioport_device(cfgfile, device, sizeof(device), NULL)
      && strcmp(device, NONEPROC) == 0 )
    {
      warning("No devices are defined in the configuration file %s", cfgfile);
    }
    else
    {
      set_device_name(device, IORESP_NONE);
    }
    return IDPOPT_OK;
}
DLLIMPORT bool stardict_netdict_plugin_init(StarDictNetDictPlugInObject *obj)
{
	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[dictdotcn]\nuse_html_or_xml=false\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	GError *err = NULL;
	use_html_or_xml = g_key_file_get_boolean(keyfile, "dictdotcn", "use_html_or_xml", &err);
	if (err) {
		g_error_free (err);
		use_html_or_xml = false;
	}
	g_key_file_free(keyfile);
	obj->lookup_func = lookup;
	obj->dict_name = _("Dict.cn");
	obj->dict_link = "http://www.dict.cn";
	obj->dict_cacheid = DICTDOTCN;
	g_print(_("Dict.cn plug-in loaded.\n"));
	return false;
}
Пример #22
0
int configfile_load(const char *filename, struct configdata *cfg,
                    int num_items, int min_version)
{
    int fd;
    int i, j;
    char *name;
    char *val;
    char buf[MAX_PATH];
    int file_version = -1;
    int tmp;

    get_cfg_filename(buf, MAX_PATH, filename);
    fd = rb->open(buf, O_RDONLY);
    if(fd < 0)
        return fd*10 - 1;

    while(rb->read_line(fd, buf, MAX_PATH) > 0) {
        rb->settings_parseline(buf, &name, &val);

        /* Bail out if the file version is too old */
        if(!rb->strcmp("file version", name)) {
            file_version = rb->atoi(val);
            if(file_version < min_version) {
                rb->close(fd);
                return -1;
            }
        }
        
        for(i = 0;i < num_items;i++) {
            if(!rb->strcmp(cfg[i].name, name)) {
                switch(cfg[i].type) {
                    case TYPE_INT:
                        tmp = rb->atoi(val);
                        /* Only set it if it's within range */
                        if(tmp >= cfg[i].min && tmp <= cfg[i].max)
                            *cfg[i].int_p = tmp;
                        break;

                    case TYPE_BOOL:
                        tmp = rb->atoi(val);
                        *cfg[i].bool_p = (bool)tmp;
                        break;

                    case TYPE_ENUM:
                        for(j = 0;j < cfg[i].max;j++) {
                            if(!rb->strcmp(cfg[i].values[j], val)) {
                                *cfg[i].int_p = j;
                            }
                        }
                        break;

                    case TYPE_STRING:
                        rb->strlcpy(cfg[i].string, val, cfg[i].max);
                        break;
                }
            }
        }
    }
    
    rb->close(fd);
    return 0;
}
static void on_get_http_response(char *buffer, size_t buffer_len, gpointer userdata)
{
	if (!buffer)
		return;
	const char *p = g_strstr_len(buffer, buffer_len, "\r\n\r\n");
	if (!p) {
		return;
	}
	p += 4;
	if(g_str_has_prefix(p, UTF8_BOM))
		p += (sizeof(UTF8_BOM)-1); // better than strlen(UTF8_BOM);
	updateinfo_ParseUserData Data;
	Data.latest_version_num = 0;
	const gchar* const *languages = g_get_language_names();
	const char *locale = languages[0];
	if (locale && locale[0] != '\0') {
		const char *p = strchr(locale, '.');
		if (p) {
			Data.locale_name.assign(locale, p - locale);
		} else {
			Data.locale_name = locale;
		}
	}
	GMarkupParser parser;
	parser.start_element = NULL;
	parser.end_element = NULL;
	parser.text = updateinfo_parse_text;
	parser.passthrough = NULL;
	parser.error = NULL;
	GMarkupParseContext* context = g_markup_parse_context_new(&parser, (GMarkupParseFlags)0, &Data, NULL);
	g_markup_parse_context_parse(context, p, buffer_len - (p - buffer), NULL);
	g_markup_parse_context_end_parse(context, NULL);
	g_markup_parse_context_free(context);

	bool updated = false;
	if (Data.latest_version_num != latest_version_num) {
		updated = true;
		latest_version_num = Data.latest_version_num;
		version_msg_title = Data.version_msg_title;
		version_msg_content = Data.version_msg_content;
	}
	if (Data.latest_version_num > my_version_num && Data.latest_version_num != last_prompt_num) {
		std::string content = version_msg_content;
		content += "\n\n";
		content += _("Visit StarDict website now?");
		GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(plugin_info->mainwin), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_YES_NO, "%s", content.c_str());
		GtkWidget *prompt = gtk_check_button_new_with_mnemonic(_("_Don't show this until the next update."));
		gtk_widget_show(prompt);
		gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), prompt);
		gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
		gtk_window_set_title (GTK_WINDOW (dialog), version_msg_title.c_str());
		if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) {
			plugin_service->show_url("http://www.stardict.org");
		}
		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(prompt))) {
			updated = true;
			last_prompt_num = Data.latest_version_num;
		}
		gtk_widget_destroy (dialog);
	}
	if (Data.latest_news != latest_news) {
		updated = true;
		latest_news = Data.latest_news;
	}
	if (updated) {
		GKeyFile *keyfile = g_key_file_new();
		g_key_file_set_string(keyfile, "update", "version_msg_title", version_msg_title.c_str());
		g_key_file_set_string(keyfile, "update", "version_msg_content", version_msg_content.c_str());
		g_key_file_set_string(keyfile, "update", "latest_news", latest_news.c_str());
		g_key_file_set_integer(keyfile, "update", "latest_version_num", latest_version_num);
		g_key_file_set_integer(keyfile, "update", "last_prompt_num", last_prompt_num);
		g_key_file_set_boolean(keyfile, "misc", "show_ads", show_ads);
		gsize length;
		gchar *content = g_key_file_to_data(keyfile, &length, NULL);
		std::string res = get_cfg_filename();
		g_file_set_contents(res.c_str(), content, length, NULL);
		g_free(content);
	}
	if (show_ads) {
		plugin_service->set_news(latest_news.c_str(), Data.links.c_str());
	}
}
Пример #24
0
//----------------------------------------------------------------------
static int idaapi notify(processor_t::idp_notify msgid, ...)
{
  va_list va;
  va_start(va, msgid);

  // A well behaving processor module should call invoke_callbacks()
  // in his notify() function. If this function returns 0, then
  // the processor module should process the notification itself
  // Otherwise the code should be returned to the caller:

  int code = invoke_callbacks(HT_IDP, msgid, va);
  if ( code )
    return code;

  switch ( msgid )
  {
    case processor_t::init:
      inf.mf = 0;
      helper.create("$ 78k0s");
    default:
      break;

    case processor_t::term:
      free_ioports(ports, numports);
      break;

    case processor_t::newfile:
      {
      //функция "выбирает" из указанного файла *.cfg все записи(процессора)
      //и отображает их в диалоговом окне, в котором пользователь может выбрать
      //нужный ему процессор. После выбора имя процессора заносится в переменную device
      //Поумолчанию в DLG выделен процессор который указан в переменной .default
      //которая распологается в начале файла *.cfg
      inf.s_genflags |= INFFL_LZERO;
      char cfgfile[QMAXFILE];
      get_cfg_filename(cfgfile, sizeof(cfgfile));
      if ( choose_ioport_device(cfgfile, device, sizeof(device), parse_area_line0) )
        //Устанавливает в ядре иды имя выбранного процессора
        //Вычитывает все "записи"(порты)  относящиеся к этому процессору
        //И подписывает в файле все байты вычитанные из *.cfg файла
        set_device_name(device, IORESP_ALL);
      } break;

    case processor_t::newprc:
      {
      char buf[MAXSTR];
      if ( helper.supval(-1, buf, sizeof(buf)) > 0 )
        set_device_name(buf, IORESP_PORT);
      } break;

    case processor_t::newseg:    // new segment
      {
      segment_t *s = va_arg(va, segment_t *);
      // Set default value of DS register for all segments
      set_default_dataseg(s->sel);
      } break;

  }
  va_end(va);
  return 1;
}
Пример #25
0
static void configure()
{
	configure_changed = false;
	GtkWidget *window = gtk_dialog_new_with_buttons(_("SAPI TTS configuration"), GTK_WINDOW(plugin_info->pluginwin), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
	GtkWidget *vbox = gtk_vbox_new(false, 5);
	gtk_container_set_border_width(GTK_CONTAINER(vbox),5);
	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(window)->vbox), vbox);
	GtkWidget *frame = gtk_frame_new(_("TTS voice engine"));
	gtk_box_pack_start(GTK_BOX(vbox), frame, false, false, 3);
	GtkWidget *table = gtk_table_new(2, 3, false);
	gtk_container_set_border_width(GTK_CONTAINER(table),8);
	gtk_container_add (GTK_CONTAINER (frame), table);
	GtkWidget *label = gtk_label_new(_("Voice :"));
	gtk_misc_set_alignment (GTK_MISC (label), 0, .5);
	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, (GtkAttachOptions)0, 5, 0);
	GtkWidget *combobox = gtk_combo_box_new_text();
	gtk_table_attach(GTK_TABLE(table), combobox, 1, 2, 0, 1, GtkAttachOptions(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 5, 0);

	ULONG ulNumTokens;
	WCHAR** ppszTokenIds = NULL;
	CComPtr<IEnumSpObjectTokens> cpEnum;
	HRESULT hr = SpEnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum);
	if ( S_OK == hr ) {
		hr = cpEnum->GetCount( &ulNumTokens );
		if ( SUCCEEDED( hr ) && 0 != ulNumTokens ) {
			WCHAR *pszCurTokenId = NULL;
			ISpObjectToken *pToken;
			HRESULT hr = pVoice->GetVoice( &pToken );
			if ( SUCCEEDED( hr ) ) {
				pToken->GetId( &pszCurTokenId );
				pToken->Release();
			}
			if (pszCurTokenId) {
				ppszTokenIds = new WCHAR* [ulNumTokens];
				ZeroMemory( ppszTokenIds, ulNumTokens*sizeof( WCHAR* ) );
				LONG ulCurToken = -1;
				ULONG ulIndex = 0;
				while (cpEnum->Next(1, &pToken, NULL) == S_OK) {
					WCHAR *description;
					SpGetDescription( pToken, &description);
					DWORD dwNum = WideCharToMultiByte(CP_UTF8,NULL,description,-1,NULL,0,NULL,FALSE);
					char *text = new char[dwNum];
					WideCharToMultiByte (CP_UTF8,NULL,description,-1,text,dwNum,NULL,FALSE);
					gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), text);
					delete []text;
					CoTaskMemFree(description);
					pToken->GetId( &ppszTokenIds[ulIndex]);
					if (ulCurToken == -1 && _wcsicmp( pszCurTokenId, ppszTokenIds[ulIndex]) == 0) {
						ulCurToken = ulIndex;
					}
					ulIndex++;
					pToken->Release();
				}
				CoTaskMemFree( pszCurTokenId );
				if (ulCurToken != -1)
					gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), ulCurToken);
			}
		}
	}
	g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (on_voice_combobox_changed), ppszTokenIds);

	label = gtk_label_new(_("Volume :"));
	gtk_misc_set_alignment (GTK_MISC (label), 0, .5);
	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, (GtkAttachOptions)0, 5, 0);
	GtkWidget *volume_hscale = gtk_hscale_new_with_range(0, 100, 1);
	gtk_table_attach(GTK_TABLE(table), volume_hscale, 1, 2, 1, 2, GtkAttachOptions(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 5, 0);
	USHORT volume;
	pVoice->GetVolume(&volume);
	gtk_range_set_value(GTK_RANGE(volume_hscale), volume);
	g_signal_connect(G_OBJECT(volume_hscale),"value-changed", G_CALLBACK(on_volume_hscale_value_changed), NULL);
	label = gtk_label_new(_("Rate :"));
	gtk_misc_set_alignment (GTK_MISC (label), 0, .5);
	gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_FILL, (GtkAttachOptions)0, 5, 0);
	GtkWidget *rate_hscale = gtk_hscale_new_with_range(-10, 10, 1);
	gtk_table_attach(GTK_TABLE(table), rate_hscale, 1, 2, 2, 3, GtkAttachOptions(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)0, 5, 0);
	long rate;
	pVoice->GetRate(&rate);
	gtk_range_set_value(GTK_RANGE(rate_hscale), rate);
	g_signal_connect(G_OBJECT(rate_hscale),"value-changed", G_CALLBACK(on_rate_hscale_value_changed), NULL);

	GtkWidget *vbox1 = gtk_vbox_new(false, 5);
	gtk_box_pack_start(GTK_BOX(vbox), vbox1, false, false, 10);
	label = gtk_label_new(_("Input the test text:"));
	gtk_misc_set_alignment (GTK_MISC (label), 0, .5);
	gtk_box_pack_start(GTK_BOX(vbox1), label, false, false, 0);
	GtkWidget *hbox = gtk_hbox_new(false, 5);
	gtk_box_pack_start(GTK_BOX(vbox1), hbox, false, false, 0);
	GtkWidget *entry = gtk_entry_new();
	gtk_entry_set_text(GTK_ENTRY(entry), "This is the test text");
	gtk_box_pack_start(GTK_BOX(hbox), entry, true, true, 0);
	GtkWidget *button = gtk_button_new_with_label(_("Test"));
	gtk_box_pack_start(GTK_BOX(hbox), button, false, false, 0);
	g_signal_connect(G_OBJECT(button),"clicked", G_CALLBACK(on_test_tts_button_clicked), GTK_ENTRY(entry));

	gtk_widget_show_all(vbox);
	gtk_dialog_run(GTK_DIALOG(window));
	if (configure_changed) {
		char *voice = NULL;
		ISpObjectToken *pToken;
		HRESULT hr = pVoice->GetVoice( &pToken );
		if ( SUCCEEDED( hr ) ) {
			WCHAR *id;
			pToken->GetId( &id );
			DWORD dwNum = WideCharToMultiByte(CP_UTF8,NULL,id,-1,NULL,0,NULL,FALSE);
			voice = new char[dwNum];
			WideCharToMultiByte (CP_UTF8,NULL,id,-1,voice,dwNum,NULL,FALSE);
			CoTaskMemFree(id);
			pToken->Release();
		}
		if (voice) {
			gint volume = (gint)gtk_range_get_value(GTK_RANGE(volume_hscale));
			gint rate = (gint)gtk_range_get_value(GTK_RANGE(rate_hscale));
			gchar *data = g_strdup_printf("[sapi_tts]\nvoice=%s\nvolume=%d\nrate=%d\n", voice, volume, rate);
			std::string res = get_cfg_filename();
			g_file_set_contents(res.c_str(), data, -1, NULL);
			g_free(data);
			delete []voice;
		}
	}
	ULONG ulIndex;
	if ( ppszTokenIds ) {
		for ( ulIndex = 0; ulIndex < ulNumTokens; ulIndex++ ) {
			if ( NULL != ppszTokenIds[ulIndex] ) {
				CoTaskMemFree( ppszTokenIds[ulIndex] );
			}
		}
		delete [] ppszTokenIds;
	}
	gtk_widget_destroy (window);
}
static void configure()
{
	GtkWidget *window = gtk_dialog_new_with_buttons(_("Update information"), GTK_WINDOW(plugin_info->pluginwin), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
#if GTK_MAJOR_VERSION >= 3
	GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
#else
	GtkWidget *vbox = gtk_vbox_new(false, 5);
#endif

	std::string content;
	if (latest_version_num > my_version_num) {
		content += _("You are using an old version of StarDict!");
	} else {
		content += _("You are using the newest version of StarDict!");
	}
	content += "\n\n";
	content += _("Latest version information:");
	content += "\n";
	content += version_msg_title;
	content += "\n";
	content += version_msg_content;
	content += "\n\n";
	content += _("Latest news:");
	content += "\n";
	content += latest_news;
	GtkWidget *label = gtk_label_new(content.c_str());
	gtk_label_set_line_wrap(GTK_LABEL(label), true);
	gtk_label_set_selectable(GTK_LABEL(label), true);
	gtk_box_pack_start(GTK_BOX(vbox), label, false, false, 5);


	GtkWidget *check_button = gtk_check_button_new_with_mnemonic(_("_Show advertisements."));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_button), show_ads);
	gtk_box_pack_start(GTK_BOX(vbox), check_button, false, false, 0);

	gtk_widget_show_all(vbox);
	gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(window))), vbox);
	gtk_dialog_run(GTK_DIALOG(window));

	gboolean new_show_ads = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_button));
	if (new_show_ads != show_ads) {
		show_ads = new_show_ads;

		GKeyFile *keyfile = g_key_file_new();
		g_key_file_set_string(keyfile, "update", "version_msg_title", version_msg_title.c_str());
		g_key_file_set_string(keyfile, "update", "version_msg_content", version_msg_content.c_str());
		g_key_file_set_string(keyfile, "update", "latest_news", latest_news.c_str());
		g_key_file_set_integer(keyfile, "update", "latest_version_num", latest_version_num);
		g_key_file_set_integer(keyfile, "update", "last_prompt_num", last_prompt_num);
		g_key_file_set_boolean(keyfile, "misc", "show_ads", show_ads);
		gsize length;
		gchar *content = g_key_file_to_data(keyfile, &length, NULL);
		std::string res = get_cfg_filename();
		g_file_set_contents(res.c_str(), content, length, NULL);
		g_free(content);

		if (new_show_ads) {
			plugin_service->send_http_request("www.stardict.org", "/UPDATE", on_get_http_response, NULL);
		} else {
			plugin_service->set_news(NULL, NULL);
		}
	}
	gtk_widget_destroy (window);
}
static void configure()
{
    GtkWidget *window = gtk_dialog_new_with_buttons(_("Festival TTS configuration"), GTK_WINDOW(plugin_info->pluginwin), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
    GtkWidget *hbox = gtk_hbox_new(false, 5);
    GtkWidget *label = gtk_label_new(_("Voice type:"));
    gtk_box_pack_start(GTK_BOX(hbox), label, false, false, 0);
    GtkWidget *combobox = gtk_combo_box_new_text();
    gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), _("Default"));
    gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "Male1-kal");
    gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "Male2-ked");
    gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "Male3-jmk");
    gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "Male4-bdl");
    gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "Male5-awb");
    gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), "Female1-slt");
    gint old_index;
    if (voice_engine == "voice_kal_diphone")
        old_index = 1;
    else if (voice_engine == "voice_ked_diphone")
        old_index = 2;
    else if (voice_engine == "voice_cmu_us_jmk_arctic_hts")
        old_index = 3;
    else if (voice_engine == "voice_cmu_us_bdl_arctic_hts")
        old_index = 4;
    else if (voice_engine == "voice_cmu_us_awb_arctic_hts")
        old_index = 5;
    else if (voice_engine == "voice_cmu_us_slt_arctic_hts")
        old_index = 6;
    else
        old_index = 0;
    gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), old_index);
    gtk_box_pack_start(GTK_BOX(hbox), combobox, false, false, 0);
    gtk_widget_show_all(hbox);
    gtk_container_add (GTK_CONTAINER (GTK_DIALOG(window)->vbox), hbox);
    gtk_dialog_run(GTK_DIALOG(window));
    gint index = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox));
    if (index != old_index) {
        if (index == 1)
            voice_engine = "voice_kal_diphone";
        else if (index == 2)
            voice_engine = "voice_ked_diphone";
        else if (index == 3)
            voice_engine = "voice_cmu_us_jmk_arctic_hts";
        else if (index == 4)
            voice_engine = "voice_cmu_us_bdl_arctic_hts";
        else if (index == 5)
            voice_engine = "voice_cmu_us_awb_arctic_hts";
        else if (index == 6)
            voice_engine = "voice_cmu_us_slt_arctic_hts";
        else
            voice_engine.clear();
        if (!voice_engine.empty()) {
            std::string command = "(";
            command += voice_engine;
            command += ")";
            festival_eval_command(command.c_str());
        }
        gchar *data = g_strdup_printf("[festival]\nvoice=%s\n", voice_engine.c_str());
        std::string res = get_cfg_filename();
        g_file_set_contents(res.c_str(), data, -1, NULL);
        g_free(data);
    }
    gtk_widget_destroy (window);
}