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)
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));
80 if ((p) && (_e_illume_cfg->policy.name) &&
81 (!strcmp(_e_illume_cfg->policy.name, p->api->name)))
84 if (p) e_object_del(E_OBJECT(p));
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);
94 evas_event_thaw(evas);
95 e_widget_list_object_append(list, ow, 1, 0, 0.0);
100 _e_mod_illume_config_policy_list_changed(void *data)
102 if (_e_illume_cfg->policy.name)
103 eina_stringshare_del(_e_illume_cfg->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);
112 _e_mod_illume_config_policy_change_timeout(void *data __UNUSED__)
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;
121 _e_mod_illume_config_policy_policies_get(void)
123 Eina_List *l = NULL, *files;
124 char dir[PATH_MAX], *file;
126 snprintf(dir, sizeof(dir), "%s/policies", _e_illume_mod_dir);
128 if (!(files = ecore_file_ls(dir))) return NULL;
130 EINA_LIST_FREE(files, file)
134 if (!strstr(file, ".so")) continue;
135 snprintf(dir, sizeof(dir),"%s/policies/%s", _e_illume_mod_dir, file);
137 p = E_OBJECT_ALLOC(E_Illume_Policy, E_ILLUME_POLICY_TYPE,
138 _e_mod_illume_config_policy_policy_free);
141 p->handle = dlopen(dir, RTLD_NOW | RTLD_GLOBAL);
144 e_object_del(E_OBJECT(p));
147 p->api = dlsym(p->handle, "e_illume_policy_api");
150 e_object_del(E_OBJECT(p));
153 if (p->api->version < E_ILLUME_POLICY_API_VERSION)
155 e_object_del(E_OBJECT(p));
158 if (file) free(file);
159 l = eina_list_append(l, p);
166 _e_mod_illume_config_policy_policy_free(E_Illume_Policy *p)
170 if (p->handle) dlclose(p->handle);