diff --git a/src/modules/everything-aspell/e_mod_main.c b/src/modules/everything-aspell/e_mod_main.c index f052b8767..524619dcf 100644 --- a/src/modules/everything-aspell/e_mod_main.c +++ b/src/modules/everything-aspell/e_mod_main.c @@ -6,11 +6,16 @@ #include "e_mod_main.h" #include -static const char TRIGGER[] = "aspell "; +static const char TRIGGER[] = "s "; static const char LANG_MODIFIER[] = "lang="; typedef struct _Plugin Plugin; +typedef struct _Module_Config Module_Config; +static Module_Config *_conf; +static char _config_path[] = "extensions/everthing-aspell"; +static char _config_domain[] = "module.everyhing-aspell"; +static E_Config_DD *_conf_edd = NULL; struct _Plugin { @@ -26,8 +31,26 @@ struct _Plugin Eina_Bool is_first; }; +struct _Module_Config +{ + int version; + + const char *lang; + const char *custom; + int command; + + E_Config_Dialog *cfd; + E_Module *module; +}; + static Plugin *_plug = NULL; +static char *commands[] = + { + "aspell -a --encoding=UTF-8 %s%s", + "hunspell -a -d %s%s" + }; + static Eina_Bool _exe_restart(Plugin *p) { @@ -40,14 +63,19 @@ _exe_restart(Plugin *p) lang_opt = "-l"; lang_val = p->lang; } + else if (_conf->lang) + { + lang_opt = _conf->lang; + lang_val = ""; + } else { lang_opt = ""; lang_val = ""; } - + len = snprintf(cmd, sizeof(cmd), - "aspell -a --encoding=UTF-8 %s%s", + commands[_conf->command - 1], lang_opt, lang_val); if (len >= (int)sizeof(cmd)) return 0; @@ -102,8 +130,7 @@ _suggestions_add(Plugin *p, const char *line) s = strchr(line, ':'); if (!s) { - fprintf(stderr, "ASPELL: ERROR missing suggestion delimiter: '%s'\n", - line); + ERR("ASPELL: ERROR missing suggestion delimiter: '%s'", line); return; } s++; @@ -149,7 +176,7 @@ _cb_data(void *data, int type __UNUSED__, void *event) if (p->is_first) { - fprintf(stderr, "ASPELL: %s\n", l->line); + ERR("ASPELL: %s", l->line); p->is_first = 0; continue; } @@ -171,7 +198,7 @@ _cb_data(void *data, int type __UNUSED__, void *event) case '\0': break; default: - fprintf(stderr, "ASPELL: unknown output: '%s'\n", l->line); + ERR("ASPELL: unknown output: '%s'", l->line); } if (*word_end) @@ -353,7 +380,213 @@ _plugins_shutdown(void) /***************************************************************************/ -static E_Module *module = NULL; +struct _E_Config_Dialog_Data +{ + int command; + char *custom; + char *lang; +}; + +static void *_create_data(E_Config_Dialog *cfd); +static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); +static void _fill_data(E_Config_Dialog_Data *cfdata); +static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); +static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); + +static E_Config_Dialog * +_conf_dialog(E_Container *con, const char *params) +{ + E_Config_Dialog *cfd = NULL; + E_Config_Dialog_View *v = NULL; + char buf[4096]; + + if (e_config_dialog_find(_config_path, _config_path)) + return NULL; + + v = E_NEW(E_Config_Dialog_View, 1); + if (!v) return NULL; + + v->create_cfdata = _create_data; + v->free_cfdata = _free_data; + v->basic.create_widgets = _basic_create; + v->basic.apply_cfdata = _basic_apply; + + snprintf(buf, sizeof(buf), "%s/e-module.edj", _conf->module->dir); + + cfd = e_config_dialog_new(con, _("Everything Aspell"), + _config_path, _config_path, buf, 0, v, NULL); + + _conf->cfd = cfd; + return cfd; +} + +static Evas_Object * +_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) +{ + Evas_Object *o = NULL, *of = NULL, *ow = NULL; + E_Radio_Group *rg; + o = e_widget_list_add(evas, 0, 0); + + of = e_widget_framelist_add(evas, _("General"), 0); + e_widget_framelist_content_align_set(of, 0.0, 0.0); + + rg = e_widget_radio_group_new(&cfdata->command); + + ow = e_widget_label_add(evas, _("Spell checker")); + e_widget_framelist_object_append(of, ow); + + ow = e_widget_radio_add(evas, _("Aspell"), 1, rg); + e_widget_framelist_object_append(of, ow); + + ow = e_widget_radio_add(evas, _("Hunspell"), 2, rg); + e_widget_framelist_object_append(of, ow); + + ow = e_widget_radio_add(evas, _("Custom"), 0, rg); + e_widget_disabled_set(ow, 1); + e_widget_framelist_object_append(of, ow); + + ow = e_widget_label_add(evas, _("Custom Command")); + e_widget_framelist_object_append(of, ow); + ow = e_widget_entry_add(evas, &cfdata->custom, NULL, NULL, NULL); + e_widget_disabled_set(ow, 1); + e_widget_framelist_object_append(of, ow); + + + ow = e_widget_label_add(evas, _("Language")); + e_widget_framelist_object_append(of, ow); + ow = e_widget_entry_add(evas, &cfdata->lang, NULL, NULL, NULL); + e_widget_framelist_object_append(of, ow); + + e_widget_list_object_append(o, of, 1, 1, 0.5); + return o; +} + +static void * +_create_data(E_Config_Dialog *cfd) +{ + E_Config_Dialog_Data *cfdata = NULL; + + cfdata = E_NEW(E_Config_Dialog_Data, 1); + _fill_data(cfdata); + return cfdata; +} + +static void +_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) +{ + E_FREE(cfdata->custom); + E_FREE(cfdata->lang); + _conf->cfd = NULL; + E_FREE(cfdata); +} + +static void +_fill_data(E_Config_Dialog_Data *cfdata) +{ +#define CP(_name) cfdata->_name = _conf->_name ? strdup(_conf->_name) : strdup(""); +#define C(_name) cfdata->_name = _conf->_name; + C(command); + CP(custom); + CP(lang); +#undef CP +#undef C +} + +static int +_basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) +{ +#define CP(_name) \ + if (_conf->_name) \ + eina_stringshare_del(_conf->_name); \ + _conf->_name = eina_stringshare_add(cfdata->_name); +#define C(_name) _conf->_name = cfdata->_name; + C(command); + CP(custom); + CP(lang); +#undef CP +#undef C + + e_config_domain_save(_config_domain, _conf_edd, _conf); + e_config_save_queue(); + return 1; +} + +static void +_conf_new(void) +{ + _conf = E_NEW(Module_Config, 1); + _conf->version = (MOD_CONFIG_FILE_EPOCH << 16); + +#define IFMODCFG(v) if ((_conf->version & 0xffff) < v) { +#define IFMODCFGEND } + + /* setup defaults */ + IFMODCFG(0x008d); + _conf->command = 1; + _conf->custom = NULL; + _conf->lang = eina_stringshare_add("en_US"); + IFMODCFGEND; + + _conf->version = MOD_CONFIG_FILE_VERSION; + + e_config_save_queue(); +} + +static void +_conf_free(void) +{ + if (_conf) + { + if (_conf->custom) eina_stringshare_del(_conf->custom); + if (_conf->lang) eina_stringshare_del(_conf->lang); + + E_FREE(_conf); + } +} + +static void +_conf_init(E_Module *m) +{ + char buf[4096]; + snprintf(buf, sizeof(buf), "%s/e-module.edj", m->dir); + + e_configure_registry_item_add(_config_path, 110, _("Everything Aspell"), + NULL, buf, _conf_dialog); + + _conf_edd = E_CONFIG_DD_NEW("Module_Config", Module_Config); + +#undef T +#undef D +#define T Module_Config +#define D _conf_edd + E_CONFIG_VAL(D, T, version, INT); + E_CONFIG_VAL(D, T, command, INT); + E_CONFIG_VAL(D, T, custom, STR); + E_CONFIG_VAL(D, T, lang, STR); +#undef T +#undef D + + _conf = e_config_domain_load(_config_domain, _conf_edd); + + if (_conf && !evry_util_module_config_check(_("Everything Aspell"), _conf->version, + MOD_CONFIG_FILE_EPOCH, MOD_CONFIG_FILE_VERSION)) + _conf_free(); + + if (!_conf) _conf_new(); + + _conf->module = m; +} + +static void +_conf_shutdown(void) +{ + _conf_free(); + + E_CONFIG_DD_FREE(_conf_edd); +} + +/***************************************************************************/ + static Eina_Bool active = EINA_FALSE; EAPI E_Module_Api e_modapi = @@ -365,11 +598,11 @@ EAPI E_Module_Api e_modapi = EAPI void * e_modapi_init(E_Module *m) { - module = m; - if (e_datastore_get("everything_loaded")) active = _plugins_init(); + _conf_init(m); + e_module_delayed_set(m, 1); return m; @@ -381,7 +614,7 @@ e_modapi_shutdown(E_Module *m) if (active && e_datastore_get("everything_loaded")) _plugins_shutdown(); - module = NULL; + _conf_shutdown(); return 1; } diff --git a/src/modules/everything-aspell/e_mod_main.h b/src/modules/everything-aspell/e_mod_main.h index 2eb60362e..33ac9b219 100644 --- a/src/modules/everything-aspell/e_mod_main.h +++ b/src/modules/everything-aspell/e_mod_main.h @@ -4,6 +4,11 @@ #ifndef E_MOD_MAIN_H #define E_MOD_MAIN_H +#define MOD_CONFIG_FILE_EPOCH 0x0002 +#define MOD_CONFIG_FILE_GENERATION 0x008d +#define MOD_CONFIG_FILE_VERSION \ + ((MOD_CONFIG_FILE_EPOCH << 16) | MOD_CONFIG_FILE_GENERATION) + EAPI extern E_Module_Api e_modapi; EAPI void *e_modapi_init (E_Module *m);