#include "Ecore_IMF.h"
#include "ecore_imf_private.h"
-static void _ecore_imf_module_load_all(void);
-static void _ecore_imf_module_append(Ecore_Plugin *plugin, const Ecore_IMF_Context_Info *info, Ecore_IMF_Context *(*imf_module_create)(void));
static void _ecore_imf_module_free(Ecore_IMF_Module *module);
static int _ecore_imf_modules_exists(const char *ctx_id);
void *selected;
} Ecore_IMF_Selector;
-static Ecore_Path_Group *ecore_imf_modules_path = NULL;
static Eina_Hash *modules = NULL;
+static Eina_Array *module_list = NULL;
void
ecore_imf_module_init(void)
{
- char pathname[PATH_MAX];
- const char *homedir;
+ char *homedir;
- ecore_imf_modules_path = ecore_path_group_new();
- snprintf(pathname, sizeof(pathname), "%s/ecore/immodules/",
- PACKAGE_LIB_DIR);
- ecore_path_group_add(ecore_imf_modules_path, pathname);
-
- homedir = getenv("HOME");
+ module_list = eina_module_list_get(NULL, PACKAGE_LIB_DIR "/ecore/immodules", 0, NULL, NULL);
+ homedir = eina_module_environment_path_get("HOME", "/.ecore/immodules");
if (homedir)
{
- snprintf(pathname, sizeof(pathname), "%s/.ecore/immodules/",
- homedir);
- ecore_path_group_add(ecore_imf_modules_path, pathname);
+ module_list = eina_module_list_get(module_list, homedir, 0, NULL, NULL);
+ free(homedir);
}
-
- modules = NULL;
- _ecore_imf_module_load_all();
+ eina_module_list_load(module_list);
}
void
eina_hash_free(modules);
modules = NULL;
}
-
- ecore_path_group_del(ecore_imf_modules_path);
- ecore_imf_modules_path = NULL;
+ if (module_list)
+ {
+ eina_module_list_free(module_list);
+ modules = NULL;
+ }
}
static Eina_Bool
Eina_List *
ecore_imf_module_available_get(void)
{
- Eina_List *values = NULL;
+ Eina_List *values;
Eina_Iterator *it = NULL;
if (!modules) return NULL;
return values;
}
-static void
-_ecore_imf_module_load_all(void)
-{
- Eina_List *avail;
- char *filename;
- Ecore_Plugin *plugin;
- const Ecore_IMF_Context_Info *info = NULL;
- int (*imf_module_init)(const Ecore_IMF_Context_Info **info);
- Ecore_IMF_Context *(*imf_module_create)(void);
-
- avail = ecore_plugin_available_get(ecore_imf_modules_path);
- if (!avail) return;
-
- EINA_LIST_FREE(avail, filename)
- {
- plugin = ecore_plugin_load(ecore_imf_modules_path, filename, NULL);
- if (!plugin)
- {
- ERR("** Error loading input method plugin %s!",
- filename);
- continue;
- }
-
- imf_module_init = ecore_plugin_symbol_get(plugin, "imf_module_init");
- if (!imf_module_init || !imf_module_init(&info) || !info)
- {
- ERR("** Error initializing input method plugin %s! "
- "'imf_module_init' is missing or failed to run!",
- filename);
- ecore_plugin_unload(plugin);
- continue;
- }
-
- if (_ecore_imf_modules_exists(info->id))
- {
- ERR("** ecore_imf: Error loading input method plugin %s! "
- "Plugin with id='%s' already exists!",
- filename, info->id);
- ecore_plugin_unload(plugin);
- continue;
- }
-
- imf_module_create = ecore_plugin_symbol_get(plugin, "imf_module_create");
- if (!imf_module_create)
- {
- ERR("** ecore_imf: Error setting up input method plugin %s! "
- "'imf_module_create' is missing!",
- filename);
- ecore_plugin_unload(plugin);
- continue;
- }
-
- _ecore_imf_module_append(plugin, info, imf_module_create);
- }
-}
-
-static void
-_ecore_imf_module_append(Ecore_Plugin *plugin,
- const Ecore_IMF_Context_Info *info,
- Ecore_IMF_Context *(*imf_module_create)(void))
+EAPI void
+ecore_imf_module_register(const Ecore_IMF_Context_Info *info,
+ Ecore_IMF_Context *(*imf_module_create)(void),
+ Ecore_IMF_Context *(*imf_module_exit)(void))
{
Ecore_IMF_Module *module;
+ if (_ecore_imf_modules_exists(info->id)) return;
+
if (!modules)
modules = eina_hash_string_superfast_new(EINA_FREE_CB(_ecore_imf_module_free));
module = malloc(sizeof(Ecore_IMF_Module));
- module->plugin = plugin;
module->info = info;
/* cache imf_module_create as it may be used several times */
module->create = imf_module_create;
+ module->exit = imf_module_exit;
eina_hash_add(modules, info->id, module);
}
static void
_ecore_imf_module_free(Ecore_IMF_Module *module)
{
- int (*imf_module_exit)(void);
-
- imf_module_exit = ecore_plugin_symbol_get(module->plugin, "imf_module_exit");
- if (imf_module_exit) imf_module_exit();
- ecore_plugin_unload(module->plugin);
+ if (module->exit) module->exit();
free(module);
}