Git init
[framework/uifw/e17-extra-modules.git] / illume2-slp / src / 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", "_config_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", "_config_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              if (!p)
77                {
78                   i++;
79                   continue;
80                }
81
82              e_widget_ilist_append(ow, NULL, strdup(p->api->label),
83                                    _e_mod_illume_config_policy_list_changed, NULL,
84                                    strdup(p->api->name));
85
86              if ((_e_illume_cfg->policy.name) &&
87                  (!strcmp(_e_illume_cfg->policy.name, p->api->name)))
88                sel = i;
89
90              e_object_del(E_OBJECT(p));
91              i++;
92           }
93      }
94
95    e_widget_size_min_set(ow, 100, 200);
96    e_widget_ilist_go(ow);
97    e_widget_ilist_selected_set(ow, sel);
98    e_widget_ilist_thaw(ow);
99    edje_thaw();
100    evas_event_thaw(evas);
101    e_widget_list_object_append(list, ow, 1, 0, 0.0);
102    return list;
103 }
104
105 static void
106 _e_mod_illume_config_policy_list_changed(void *data)
107 {
108    if (_e_illume_cfg->policy.name)
109      eina_stringshare_del(_e_illume_cfg->policy.name);
110    if (_policy_name)
111      _e_illume_cfg->policy.name = eina_stringshare_add(_policy_name);
112    if (_policy_change_timer) ecore_timer_del(_policy_change_timer);
113    _policy_change_timer =
114      ecore_timer_add(0.5, _e_mod_illume_config_policy_change_timeout, data);
115 }
116
117 static Eina_Bool
118 _e_mod_illume_config_policy_change_timeout(void *data __UNUSED__)
119 {
120    e_config_save_queue();
121    _policy_change_timer = NULL;
122    ecore_event_add(E_ILLUME_POLICY_EVENT_CHANGE, NULL, NULL, NULL);
123    return ECORE_CALLBACK_CANCEL;
124 }
125
126 static Eina_List *
127 _e_mod_illume_config_policy_policies_get(void)
128 {
129    Eina_List *l = NULL, *files;
130    char dir[PATH_MAX], *file;
131
132    snprintf(dir, sizeof(dir), "%s/policies", _e_illume_mod_dir);
133
134    if (!(files = ecore_file_ls(dir))) return NULL;
135
136    EINA_LIST_FREE(files, file)
137      {
138         E_Illume_Policy *p;
139
140         if (!strstr(file, ".so")) continue;
141         snprintf(dir, sizeof(dir),"%s/policies/%s", _e_illume_mod_dir, file);
142
143         p = E_OBJECT_ALLOC(E_Illume_Policy, E_ILLUME_POLICY_TYPE,
144                          _e_mod_illume_config_policy_policy_free);
145         if (!p) continue;
146
147         p->handle = dlopen(dir, RTLD_NOW | RTLD_GLOBAL);
148         if (!p->handle)
149           {
150              e_object_del(E_OBJECT(p));
151              continue;
152           }
153         p->api = dlsym(p->handle, "e_illume_policy_api");
154         if (!p->api)
155           {
156              e_object_del(E_OBJECT(p));
157              continue;
158           }
159         if (p->api->version < E_ILLUME_POLICY_API_VERSION)
160           {
161              e_object_del(E_OBJECT(p));
162              continue;
163           }
164         free(file);
165         l = eina_list_append(l, p);
166      }
167
168    return l;
169 }
170
171 static void
172 _e_mod_illume_config_policy_policy_free(E_Illume_Policy *p)
173 {
174    if (!p) return;
175
176    p->api = NULL;
177
178    if (p->handle) dlclose(p->handle);
179    p->handle = NULL;
180
181    E_FREE(p);
182 }