1 #include "e_illume_private.h"
2 #include "e_mod_config_policy.h"
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);
14 Ecore_Timer *_policy_change_timer = NULL;
15 const char *_policy_name = NULL;
18 e_mod_illume_config_policy_show(E_Container *con, const char *params __UNUSED__)
21 E_Config_Dialog_View *v;
23 if (e_config_dialog_find("E", "_config_illume_policy")) return;
25 v = E_NEW(E_Config_Dialog_View, 1);
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;
34 cfd = e_config_dialog_new(con, _("Policy"), "E", "_config_illume_policy",
35 "enlightenment/policy", 0, v, NULL);
37 e_dialog_resizable_set(cfd->dia, 1);
42 _e_mod_illume_config_policy_create(E_Config_Dialog *cfd __UNUSED__)
48 _e_mod_illume_config_policy_free(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata __UNUSED__)
50 if (_policy_change_timer) ecore_timer_del(_policy_change_timer);
51 _policy_change_timer = NULL;
55 _e_mod_illume_config_policy_ui(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata __UNUSED__)
57 Evas_Object *list, *ow;
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);
67 e_widget_ilist_freeze(ow);
68 e_widget_ilist_clear(ow);
69 e_widget_ilist_go(ow);
71 policies = _e_mod_illume_config_policy_policies_get();
74 EINA_LIST_FREE(policies, p)
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));
86 if ((_e_illume_cfg->policy.name) &&
87 (!strcmp(_e_illume_cfg->policy.name, p->api->name)))
90 e_object_del(E_OBJECT(p));
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);
100 evas_event_thaw(evas);
101 e_widget_list_object_append(list, ow, 1, 0, 0.0);
106 _e_mod_illume_config_policy_list_changed(void *data)
108 if (_e_illume_cfg->policy.name)
109 eina_stringshare_del(_e_illume_cfg->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);
118 _e_mod_illume_config_policy_change_timeout(void *data __UNUSED__)
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;
127 _e_mod_illume_config_policy_policies_get(void)
129 Eina_List *l = NULL, *files;
130 char dir[PATH_MAX], *file;
132 snprintf(dir, sizeof(dir), "%s/policies", _e_illume_mod_dir);
134 if (!(files = ecore_file_ls(dir))) return NULL;
136 EINA_LIST_FREE(files, file)
140 if (!strstr(file, ".so")) continue;
141 snprintf(dir, sizeof(dir),"%s/policies/%s", _e_illume_mod_dir, file);
143 p = E_OBJECT_ALLOC(E_Illume_Policy, E_ILLUME_POLICY_TYPE,
144 _e_mod_illume_config_policy_policy_free);
147 p->handle = dlopen(dir, RTLD_NOW | RTLD_GLOBAL);
150 e_object_del(E_OBJECT(p));
153 p->api = dlsym(p->handle, "e_illume_policy_api");
156 e_object_del(E_OBJECT(p));
159 if (p->api->version < E_ILLUME_POLICY_API_VERSION)
161 e_object_del(E_OBJECT(p));
165 l = eina_list_append(l, p);
172 _e_mod_illume_config_policy_policy_free(E_Illume_Policy *p)
178 if (p->handle) dlclose(p->handle);