91116e9d52cfc607487162cee57d2e2973d16bcb
[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    return m;
24 }
25
26 EAPI int 
27 e_modapi_shutdown(E_Module *m __UNUSED__) 
28 {
29    _il_kbd_stop();
30    il_kbd_config_shutdown();
31    return 1;
32 }
33
34 EAPI int 
35 e_modapi_save(E_Module *m __UNUSED__) 
36 {
37    return il_kbd_config_save();
38 }
39
40 EAPI void 
41 il_kbd_cfg_update(void) 
42 {
43    _il_kbd_stop();
44    _il_kbd_start();
45 }
46
47 static void 
48 _il_kbd_stop(void) 
49 {
50    if (ki) e_kbd_int_free(ki);
51    ki = NULL;
52    if (_kbd_exe) ecore_exe_interrupt(_kbd_exe);
53    _kbd_exe = NULL;
54    if (_kbd_exe_exit_handler) ecore_event_handler_del(_kbd_exe_exit_handler);
55    _kbd_exe_exit_handler = NULL;
56 }
57
58 static void 
59 _il_kbd_start(void) 
60 {
61    if (il_kbd_cfg->use_internal) 
62      {
63         ki = e_kbd_int_new(il_kbd_cfg->mod_dir, 
64                            il_kbd_cfg->mod_dir, il_kbd_cfg->mod_dir);
65      }
66    else if (il_kbd_cfg->run_keyboard) 
67      {
68         E_Exec_Instance *inst;
69         Efreet_Desktop *desktop;
70
71         desktop = efreet_util_desktop_file_id_find(il_kbd_cfg->run_keyboard);
72         if (!desktop) 
73           {
74              Efreet_Desktop *d;
75              Eina_List *kbds, *l;
76
77              kbds = efreet_util_desktop_category_list("Keyboard");
78              if (kbds) 
79                {
80                   EINA_LIST_FOREACH(kbds, l, d) 
81                     {
82                        const char *dname;
83
84                        dname = ecore_file_file_get(d->orig_path);
85                        if (dname) 
86                          {
87                             if (!strcmp(dname, il_kbd_cfg->run_keyboard))
88                               {
89                                  desktop = d;
90                                  efreet_desktop_ref(desktop);
91                                  break;
92                               }
93                          }
94                     }
95                   EINA_LIST_FREE(kbds, d)
96                     efreet_desktop_free(d);
97                }
98           }
99         if (desktop) 
100           {
101              E_Zone *zone;
102
103              zone = e_util_zone_current_get(e_manager_current_get());
104              inst = e_exec(zone, desktop, NULL, NULL, "illume-keyboard");
105              if (inst) 
106                {
107                   _kbd_exe = inst->exe;
108                   _kbd_exe_exit_handler = 
109                     ecore_event_handler_add(ECORE_EXE_EVENT_DEL, 
110                                             _il_kbd_cb_exit, NULL);
111                }
112              efreet_desktop_free(desktop);
113           }
114      }
115 }
116
117 static Eina_Bool
118 _il_kbd_cb_exit(void *data __UNUSED__, int type __UNUSED__, void *event) 
119 {
120    Ecore_Exe_Event_Del *ev;
121
122    ev = event;
123    if (ev->exe == _kbd_exe) _kbd_exe = NULL;
124    return ECORE_CALLBACK_PASS_ON;
125 }