update for beta release
[framework/uifw/e17.git] / src / modules / illume2 / e_mod_config_policy.c
1 #include "e_illume_private.h"
2 #include "e_mod_config_policy.h"
3
4 /* local function prototypes */
5 static void *_e_mod_illume_config_policy_create(E_Config_Dialog *cfd);
6 static void _e_mod_illume_config_policy_free(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
7 static Evas_Object *_e_mod_illume_config_policy_ui(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
8 static void _e_mod_illume_config_policy_list_changed(void *data);
9 static Eina_Bool _e_mod_illume_config_policy_change_timeout(void *data);
10 static Eina_List *_e_mod_illume_config_policy_policies_get(void);
11 static void _e_mod_illume_config_policy_policy_free(E_Illume_Policy *p);
12
13 /* local variables */
14 Ecore_Timer *_policy_change_timer = NULL;
15 const char *_policy_name = NULL;
16
17 void 
18 e_mod_illume_config_policy_show(E_Container *con, const char *params __UNUSED__) 
19 {
20    E_Config_Dialog *cfd;
21    E_Config_Dialog_View *v;
22
23    if (e_config_dialog_find("E", "illume/policy")) return;
24
25    v = E_NEW(E_Config_Dialog_View, 1);
26    if (!v) return;
27
28    v->create_cfdata = _e_mod_illume_config_policy_create;
29    v->free_cfdata = _e_mod_illume_config_policy_free;
30    v->basic.create_widgets = _e_mod_illume_config_policy_ui;
31    v->basic_only = 1;
32    v->normal_win = 1;
33    v->scroll = 1;
34    cfd = e_config_dialog_new(con, _("Policy"), "E", "illume/policy", 
35                              "enlightenment/policy", 0, v, NULL);
36    if (!cfd) return;
37    e_dialog_resizable_set(cfd->dia, 1);
38 }
39
40 /* local functions */
41 static void *
42 _e_mod_illume_config_policy_create(E_Config_Dialog *cfd __UNUSED__) 
43 {
44    return NULL;
45 }
46
47 static void 
48 _e_mod_illume_config_policy_free(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata __UNUSED__) 
49 {
50    if (_policy_change_timer) ecore_timer_del(_policy_change_timer);
51    _policy_change_timer = NULL;
52 }
53
54 static Evas_Object *
55 _e_mod_illume_config_policy_ui(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata __UNUSED__) 
56 {
57    Evas_Object *list, *ow;
58    Eina_List *policies;
59    E_Illume_Policy *p;
60    int i = 0, sel = 0;
61
62    list = e_widget_list_add(evas, 0, 0);
63    ow = e_widget_ilist_add(evas, 24, 24, &(_policy_name));
64    e_widget_ilist_selector_set(ow, 1);
65    evas_event_freeze(evas);
66    edje_freeze();
67    e_widget_ilist_freeze(ow);
68    e_widget_ilist_clear(ow);
69    e_widget_ilist_go(ow);
70
71    policies = _e_mod_illume_config_policy_policies_get();
72    if (policies) 
73      {
74         EINA_LIST_FREE(policies, p) 
75           {
76              e_widget_ilist_append(ow, NULL, strdup(p->api->label), 
77                                    _e_mod_illume_config_policy_list_changed, NULL, 
78                                    strdup(p->api->name));
79
80              if ((p) && (_e_illume_cfg->policy.name) && 
81                  (!strcmp(_e_illume_cfg->policy.name, p->api->name))) 
82                sel = i;
83
84              if (p) e_object_del(E_OBJECT(p));
85              i++;
86           }
87      }
88
89    e_widget_size_min_set(ow, 100, 200);
90    e_widget_ilist_go(ow);
91    e_widget_ilist_selected_set(ow, sel);
92    e_widget_ilist_thaw(ow);
93    edje_thaw();
94    evas_event_thaw(evas);
95    e_widget_list_object_append(list, ow, 1, 0, 0.0);
96    return list;
97 }
98
99 static void 
100 _e_mod_illume_config_policy_list_changed(void *data) 
101 {
102    if (_e_illume_cfg->policy.name) 
103      eina_stringshare_del(_e_illume_cfg->policy.name);
104    if (_policy_name) 
105      _e_illume_cfg->policy.name = eina_stringshare_add(_policy_name);
106    if (_policy_change_timer) ecore_timer_del(_policy_change_timer);
107    _policy_change_timer = 
108      ecore_timer_add(0.5, _e_mod_illume_config_policy_change_timeout, data);
109 }
110
111 static Eina_Bool
112 _e_mod_illume_config_policy_change_timeout(void *data __UNUSED__) 
113 {
114    e_config_save_queue();
115    _policy_change_timer = NULL;
116    ecore_event_add(E_ILLUME_POLICY_EVENT_CHANGE, NULL, NULL, NULL);
117    return ECORE_CALLBACK_CANCEL;
118 }
119
120 static Eina_List *
121 _e_mod_illume_config_policy_policies_get(void) 
122 {
123    Eina_List *l = NULL, *files;
124    char dir[PATH_MAX], *file;
125
126    snprintf(dir, sizeof(dir), "%s/policies", _e_illume_mod_dir);
127
128    if (!(files = ecore_file_ls(dir))) return NULL;
129
130    EINA_LIST_FREE(files, file)
131      {
132         E_Illume_Policy *p;
133
134         if (!strstr(file, ".so")) continue;
135         snprintf(dir, sizeof(dir),"%s/policies/%s", _e_illume_mod_dir, file);
136
137         p = E_OBJECT_ALLOC(E_Illume_Policy, E_ILLUME_POLICY_TYPE,
138                          _e_mod_illume_config_policy_policy_free);
139         if (!p) continue;
140
141         p->handle = dlopen(dir, RTLD_NOW | RTLD_GLOBAL);
142         if (!p->handle)
143           {
144              e_object_del(E_OBJECT(p));
145              continue;
146           }
147         p->api = dlsym(p->handle, "e_illume_policy_api");
148         if (!p->api)
149           {
150              e_object_del(E_OBJECT(p));
151              continue;
152           }
153         if (p->api->version < E_ILLUME_POLICY_API_VERSION)
154           {
155              e_object_del(E_OBJECT(p));
156              continue;
157           }
158         if (file) free(file);
159         l = eina_list_append(l, p);
160      }
161
162    return l;
163 }
164
165 static void 
166 _e_mod_illume_config_policy_policy_free(E_Illume_Policy *p) 
167 {
168    p->api = NULL;
169
170    if (p->handle) dlclose(p->handle);
171    p->handle = NULL;
172
173    E_FREE(p);
174 }