Tizen 2.1 release
[platform/core/uifw/e17.git] / src / modules / illume2 / e_mod_main.c
1 #include "e_illume_private.h"
2 #include "e_mod_main.h"
3 #include "e_mod_config.h"
4 #include "e_mod_policy.h"
5 #include "e_mod_kbd.h"
6 #include "e_mod_quickpanel.h"
7
8 /* NB: Initially I had done this rewrite with eina_logging enabled, but it 
9  * degraded performance so much that it was just not worth it. So now this 
10  * module just uses printfs on the console to report things */
11
12 /* external variables */
13 const char *_e_illume_mod_dir = NULL;
14 E_Illume_Keyboard *_e_illume_kbd = NULL;
15 Eina_List *_e_illume_qps = NULL;
16
17 EAPI E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Illume2" };
18
19 EAPI void *
20 e_modapi_init(E_Module *m) 
21 {
22    Eina_List *ml, *cl, *zl;
23    E_Manager *man;
24    E_Container *con;
25    E_Zone *zone;
26    Ecore_X_Window *zones;
27    int zcount = 0;
28
29    /* check if illume is loaded and bail out if it is.
30     * Illume1 and illume2 both cannot be loaded @ the same time */
31    if (e_module_find("illume")) return NULL;
32
33    /* set module priority so we load first */
34    e_module_priority_set(m, 100);
35
36    /* set module directory variable */
37    _e_illume_mod_dir = eina_stringshare_add(m->dir);
38
39    /* try to initialize the config subsystem */
40    if (!e_mod_illume_config_init()) 
41      {
42         /* clear module directory variable */
43         if (_e_illume_mod_dir) eina_stringshare_del(_e_illume_mod_dir);
44         _e_illume_mod_dir = NULL;
45
46         return NULL;
47      }
48
49    /* try to initialize the policy subsystem */
50    if (!e_mod_policy_init()) 
51      {
52         /* shutdown the config subsystem */
53         e_mod_illume_config_shutdown();
54
55         /* clear module directory variable */
56         if (_e_illume_mod_dir) eina_stringshare_del(_e_illume_mod_dir);
57         _e_illume_mod_dir = NULL;
58
59         return NULL;
60      }
61
62    /* initialize the keyboard subsystem */
63    e_mod_kbd_init();
64
65    /* initialize the quickpanel subsystem */
66    e_mod_quickpanel_init();
67
68    /* create a new vkbd & hide it initially */
69    _e_illume_kbd = e_mod_kbd_new();
70    e_mod_kbd_hide();
71
72    /* loop zones and get count */
73    EINA_LIST_FOREACH(e_manager_list(), ml, man) 
74      EINA_LIST_FOREACH(man->containers, cl, con) 
75        EINA_LIST_FOREACH(con->zones, zl, zone) 
76          zcount++;
77
78    /* allocate enough zones */
79    zones = calloc(zcount, sizeof(Ecore_X_Window));
80    if (!zones) 
81      {
82         /* free the keyboard */
83         E_FREE(_e_illume_kbd);
84
85         /* shutdown quickpanel & kbd sub-systems */
86         e_mod_quickpanel_shutdown();
87         e_mod_kbd_shutdown();
88
89         /* shutdown the config subsystem */
90         e_mod_illume_config_shutdown();
91
92         /* clear module directory variable */
93         if (_e_illume_mod_dir) eina_stringshare_del(_e_illume_mod_dir);
94         _e_illume_mod_dir = NULL;
95
96         return NULL;
97      }
98
99    zcount = 0;
100
101    /* loop the zones and create quickpanels for each one */
102    EINA_LIST_FOREACH(e_manager_list(), ml, man) 
103      {
104         EINA_LIST_FOREACH(man->containers, cl, con) 
105           {
106              EINA_LIST_FOREACH(con->zones, zl, zone) 
107                {
108                   E_Illume_Quickpanel *qp;
109
110                   /* set zone window in list of zones */
111                   zones[zcount] = zone->black_win;
112
113                   /* increment zone count */
114                   zcount++;
115
116                   /* try to create a new quickpanel for this zone */
117                   if (!(qp = e_mod_quickpanel_new(zone))) continue;
118
119                   /* append new qp to list */
120                   _e_illume_qps = eina_list_append(_e_illume_qps, qp);
121                }
122           }
123         /* set the zone list on this root. This is needed for some 
124          * elm apps like elm_indicator so that they know how many 
125          * indicators to create at startup */
126         ecore_x_e_illume_zone_list_set(man->root, zones, zcount);
127      }
128
129    /* free zones variable */
130    free(zones);
131
132    return m;
133 }
134
135 EAPI int 
136 e_modapi_shutdown(E_Module *m __UNUSED__) 
137 {
138    E_Illume_Quickpanel *qp;
139
140    /* delete the quickpanels */
141    EINA_LIST_FREE(_e_illume_qps, qp)
142      e_object_del(E_OBJECT(qp));
143
144    /* shutdown the quickpanel subsystem */
145    e_mod_quickpanel_shutdown();
146
147    /* delete the keyboard object */
148    if (_e_illume_kbd) e_object_del(E_OBJECT(_e_illume_kbd));
149    _e_illume_kbd = NULL;
150
151    /* shutdown the keyboard subsystem */
152    e_mod_kbd_shutdown();
153
154    /* shutdown the policy subsystem */
155    e_mod_policy_shutdown();
156
157    /* shutdown the config subsystem */
158    e_mod_illume_config_shutdown();
159
160    /* clear module directory variable */
161    if (_e_illume_mod_dir) eina_stringshare_del(_e_illume_mod_dir);
162    _e_illume_mod_dir = NULL;
163
164    return 1;
165 }
166
167 EAPI int 
168 e_modapi_save(E_Module *m __UNUSED__) 
169 {
170    return e_mod_illume_config_save();
171 }