update for beta release
[framework/uifw/e17.git] / src / modules / illume-keyboard / e_mod_main.c
1 #include "e.h"
2 #include "e_mod_main.h"
3 #include "e_mod_config.h"
4 #include "e_kbd_int.h"
5
6 /* local function prototypes */
7 static void _il_kbd_stop(void);
8 static void _il_kbd_start(void);
9 static Eina_Bool _il_kbd_cb_exit(void *data, int type, void *event);
10
11 /* local variables */
12 static E_Kbd_Int *ki = NULL;
13 static Ecore_Exe *_kbd_exe = NULL;
14 static Ecore_Event_Handler *_kbd_exe_exit_handler = NULL;
15
16 EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Illume Keyboard" };
17
18 EAPI void *
19 e_modapi_init(E_Module *m) 
20 {
21    if (!il_kbd_config_init(m)) return NULL;
22    _il_kbd_start();
23    e_module_delayed_set(m, 1); 
24    return m;
25 }
26
27 EAPI int 
28 e_modapi_shutdown(E_Module *m __UNUSED__) 
29 {
30    _il_kbd_stop();
31    il_kbd_config_shutdown();
32    return 1;
33 }
34
35 EAPI int 
36 e_modapi_save(E_Module *m __UNUSED__) 
37 {
38    return il_kbd_config_save();
39 }
40
41 EAPI void 
42 il_kbd_cfg_update(void) 
43 {
44    _il_kbd_stop();
45    _il_kbd_start();
46 }
47
48 static void 
49 _il_kbd_stop(void) 
50 {
51    if (ki) e_kbd_int_free(ki);
52    ki = NULL;
53    if (_kbd_exe) ecore_exe_interrupt(_kbd_exe);
54    _kbd_exe = NULL;
55    if (_kbd_exe_exit_handler) ecore_event_handler_del(_kbd_exe_exit_handler);
56    _kbd_exe_exit_handler = NULL;
57 }
58
59 static void 
60 _il_kbd_start(void) 
61 {
62    if (il_kbd_cfg->use_internal) 
63      {
64         ki = e_kbd_int_new(il_kbd_cfg->mod_dir, 
65                            il_kbd_cfg->mod_dir, il_kbd_cfg->mod_dir);
66      }
67    else if (il_kbd_cfg->run_keyboard) 
68      {
69         E_Exec_Instance *inst;
70         Efreet_Desktop *desktop;
71
72         desktop = efreet_util_desktop_file_id_find(il_kbd_cfg->run_keyboard);
73         if (!desktop) 
74           {
75              Efreet_Desktop *d;
76              Eina_List *kbds, *l;
77
78              kbds = efreet_util_desktop_category_list("Keyboard");
79              if (kbds) 
80                {
81                   EINA_LIST_FOREACH(kbds, l, d) 
82                     {
83                        const char *dname;
84
85                        dname = ecore_file_file_get(d->orig_path);
86                        if (dname) 
87                          {
88                             if (!strcmp(dname, il_kbd_cfg->run_keyboard))
89                               {
90                                  desktop = d;
91                                  efreet_desktop_ref(desktop);
92                                  break;
93                               }
94                          }
95                     }
96                   EINA_LIST_FREE(kbds, d)
97                     efreet_desktop_free(d);
98                }
99           }
100         if (desktop) 
101           {
102              E_Zone *zone;
103
104              zone = e_util_zone_current_get(e_manager_current_get());
105              inst = e_exec(zone, desktop, NULL, NULL, "illume-keyboard");
106              if (inst) 
107                {
108                   _kbd_exe = inst->exe;
109                   _kbd_exe_exit_handler = 
110                     ecore_event_handler_add(ECORE_EXE_EVENT_DEL, 
111                                             _il_kbd_cb_exit, NULL);
112                }
113              efreet_desktop_free(desktop);
114           }
115      }
116 }
117
118 static Eina_Bool
119 _il_kbd_cb_exit(void *data __UNUSED__, int type __UNUSED__, void *event) 
120 {
121    Ecore_Exe_Event_Del *ev;
122
123    ev = event;
124    if (ev->exe == _kbd_exe) _kbd_exe = NULL;
125    return ECORE_CALLBACK_PASS_ON;
126 }