forked from enlightenment/enlightenment
Better modules config dialog. Can now multi-select several modules to
enable/disable at one time. Added some APIs to e_widget_ilist to help with this. SVN revision: 30832
This commit is contained in:
parent
467c356faf
commit
5b8a3e7555
|
@ -488,6 +488,25 @@ e_ilist_selected_geometry_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Ev
|
|||
*y -= sd->y;
|
||||
}
|
||||
|
||||
EAPI int
|
||||
e_ilist_selected_count_get(Evas_Object *obj)
|
||||
{
|
||||
Evas_List *l = NULL;
|
||||
int count = 0;
|
||||
|
||||
API_ENTRY return 0;
|
||||
if (!sd->items) return 0;
|
||||
for (l = sd->items; l; l = l->next)
|
||||
{
|
||||
E_Ilist_Item *si;
|
||||
|
||||
si = l->data;
|
||||
if (!si) continue;
|
||||
if (si->selected) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
e_ilist_remove_num(Evas_Object *obj, int n)
|
||||
{
|
||||
|
|
|
@ -41,6 +41,7 @@ EAPI void *e_ilist_selected_data_get (Evas_Object *obj);
|
|||
EAPI void *e_ilist_selected_data2_get (Evas_Object *obj);
|
||||
EAPI Evas_Object *e_ilist_selected_icon_get (Evas_Object *obj);
|
||||
EAPI void e_ilist_selected_geometry_get (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
|
||||
EAPI int e_ilist_selected_count_get (Evas_Object *obj);
|
||||
EAPI void e_ilist_remove_num (Evas_Object *obj, int n);
|
||||
EAPI const char *e_ilist_nth_label_get (Evas_Object *obj, int n);
|
||||
EAPI void e_ilist_nth_label_set (Evas_Object *obj, int n, const char *label);
|
||||
|
|
|
@ -1,146 +1,102 @@
|
|||
/*
|
||||
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
||||
*/
|
||||
#include "e.h"
|
||||
|
||||
#define MOD_UNLOADED 0
|
||||
#define MOD_ENABLED 1
|
||||
|
||||
typedef struct _CFModule CFModule;
|
||||
|
||||
/* Dialog Protos */
|
||||
static void *_create_data(E_Config_Dialog *cfd);
|
||||
static void _fill_data(E_Config_Dialog_Data *cfdata);
|
||||
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
||||
static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
|
||||
static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
|
||||
|
||||
static void _ilist_cb_change(void *data, Evas_Object *obj);
|
||||
static int _sort_modules(void *data1, void *data2);
|
||||
static void _module_configure(void *data, void *data2);
|
||||
static void _module_about(void *data, void *data2);
|
||||
|
||||
static void _module_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, const char *path);
|
||||
static void _mod_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, const char *path);
|
||||
static void _dir_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, const char *path);
|
||||
/* Private Function Protos */
|
||||
static void _load_modules(E_Config_Dialog_Data *cfdata);
|
||||
static void _fill_list(E_Config_Dialog_Data *cfdata);
|
||||
static int _sort_modules(void *data1, void *data2);
|
||||
static void _fill_all(E_Config_Dialog_Data *cfdata);
|
||||
static void _fill_loaded(E_Config_Dialog_Data *cfdata);
|
||||
static const char *_get_icon(Efreet_Desktop *desk);
|
||||
static E_Module *_get_module(E_Config_Dialog_Data *cfdata, const char *lbl);
|
||||
|
||||
static Evas_List *monitors;
|
||||
/* Callbacks */
|
||||
static void _cb_monitor(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path);
|
||||
static void _cb_mod_monitor(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path);
|
||||
static void _cb_dir_monitor(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path);
|
||||
static void _cb_all_change(void *data, Evas_Object *obj);
|
||||
static void _cb_loaded_change(void *data, Evas_Object *obj);
|
||||
static void _cb_load(void *data, void *data2);
|
||||
static void _cb_unload(void *data, void *data2);
|
||||
static void _cb_about(void *data, void *data2);
|
||||
static void _cb_config(void *data, void *data2);
|
||||
|
||||
struct _E_Config_Dialog_Data
|
||||
{
|
||||
Evas_List *modules;
|
||||
Evas_Object *o_all, *o_loaded;
|
||||
Evas_Object *b_load, *b_unload;
|
||||
Evas_Object *b_about, *b_configure;
|
||||
};
|
||||
|
||||
static Evas_List *monitors = NULL;
|
||||
Ecore_File_Monitor *mod_mon, *dir_mon;
|
||||
|
||||
struct _CFModule
|
||||
{
|
||||
char *name;
|
||||
Efreet_Desktop *desktop;
|
||||
int state;
|
||||
};
|
||||
|
||||
struct _E_Config_Dialog_Data
|
||||
{
|
||||
E_Config_Dialog *cfd;
|
||||
Evas_List *modules;
|
||||
Evas *evas;
|
||||
int state;
|
||||
char *modname;
|
||||
struct {
|
||||
Evas_Object *configure, *about;
|
||||
Evas_Object *enabled, *unloaded, *list;
|
||||
} gui;
|
||||
};
|
||||
|
||||
EAPI E_Config_Dialog *
|
||||
e_int_config_modules(E_Container *con)
|
||||
e_int_config_modules(E_Container *con)
|
||||
{
|
||||
E_Config_Dialog *cfd;
|
||||
E_Config_Dialog_View *v;
|
||||
|
||||
|
||||
if (e_config_dialog_find("E", "_config_modules_dialog")) return NULL;
|
||||
|
||||
v = E_NEW(E_Config_Dialog_View, 1);
|
||||
v->create_cfdata = _create_data;
|
||||
v->free_cfdata = _free_data;
|
||||
v->basic.create_widgets = _basic_create;
|
||||
|
||||
v->create_cfdata = _create_data;
|
||||
v->free_cfdata = _free_data;
|
||||
v->basic.create_widgets = _basic_create_widgets;
|
||||
v->basic.apply_cfdata = _basic_apply_data;
|
||||
|
||||
cfd = e_config_dialog_new(con,
|
||||
_("Module Settings"),
|
||||
"E", "_config_modules_dialog",
|
||||
"enlightenment/modules", 0, v, NULL);
|
||||
cfd = e_config_dialog_new(con, _("Module Settings"), "E",
|
||||
"_config_modules_dialog", "enlightenment/modules",
|
||||
0, v, NULL);
|
||||
e_dialog_resizable_set(cfd->dia, 1);
|
||||
return cfd;
|
||||
}
|
||||
|
||||
static void
|
||||
_module_configure(void *data, void *data2)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
E_Module *m;
|
||||
|
||||
cfdata = data;
|
||||
if (!cfdata->modname) return;
|
||||
m = e_module_find(cfdata->modname);
|
||||
if (m)
|
||||
{
|
||||
if (m->func.config) m->func.config(m);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_module_about(void *data, void *data2)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
E_Module *m;
|
||||
|
||||
cfdata = data;
|
||||
if (!cfdata->modname) return;
|
||||
m = e_module_find(cfdata->modname);
|
||||
if (m)
|
||||
{
|
||||
if (m->func.about) m->func.about(m);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_fill_data(E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
Evas_List *l;
|
||||
|
||||
for (l = e_path_dir_list_get(path_modules); l; l = l->next)
|
||||
{
|
||||
E_Path_Dir *epd;
|
||||
|
||||
epd = l->data;
|
||||
if (ecore_file_is_dir(epd->dir))
|
||||
{
|
||||
Ecore_File_Monitor *monitor;
|
||||
monitor = ecore_file_monitor_add(epd->dir, _module_cb_monitor,
|
||||
cfdata);
|
||||
monitors = evas_list_append(monitors, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
_load_modules(cfdata);
|
||||
}
|
||||
|
||||
/* Dialog Functions */
|
||||
static void *
|
||||
_create_data(E_Config_Dialog *cfd)
|
||||
_create_data(E_Config_Dialog *cfd)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
|
||||
|
||||
cfdata = E_NEW(E_Config_Dialog_Data, 1);
|
||||
cfdata->cfd = cfd;
|
||||
_fill_data(cfdata);
|
||||
return cfdata;
|
||||
}
|
||||
|
||||
static void
|
||||
_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
|
||||
_fill_data(E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
Evas_List *l;
|
||||
|
||||
if (mod_mon)
|
||||
ecore_file_monitor_del(mod_mon);
|
||||
if (dir_mon)
|
||||
ecore_file_monitor_del(dir_mon);
|
||||
Evas_List *l = NULL, *mdirs = NULL;
|
||||
|
||||
/* Setup file monitors for module directories */
|
||||
mdirs = e_path_dir_list_get(path_modules);
|
||||
for (l = mdirs; l; l = l->next)
|
||||
{
|
||||
E_Path_Dir *epd;
|
||||
Ecore_File_Monitor *mon;
|
||||
|
||||
epd = l->data;
|
||||
if (!ecore_file_is_dir(epd->dir)) continue;
|
||||
mon = ecore_file_monitor_add(epd->dir, _cb_monitor, cfdata);
|
||||
monitors = evas_list_append(monitors, mon);
|
||||
}
|
||||
if (l) evas_list_free(l);
|
||||
if (mdirs) e_path_dir_list_free(mdirs);
|
||||
|
||||
/* Load available modules */
|
||||
_load_modules(cfdata);
|
||||
}
|
||||
|
||||
static void
|
||||
_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
/* Remove file monitors for module directories */
|
||||
if (mod_mon) ecore_file_monitor_del(mod_mon);
|
||||
if (dir_mon) ecore_file_monitor_del(dir_mon);
|
||||
while (monitors)
|
||||
{
|
||||
Ecore_File_Monitor *mon;
|
||||
|
@ -149,198 +105,270 @@ _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
|
|||
ecore_file_monitor_del(mon);
|
||||
monitors = evas_list_remove_list(monitors, monitors);
|
||||
}
|
||||
|
||||
while ((l = cfdata->modules))
|
||||
{
|
||||
CFModule *m;
|
||||
|
||||
m = l->data;
|
||||
cfdata->modules = evas_list_remove_list(cfdata->modules, l);
|
||||
E_FREE(m->name);
|
||||
E_FREE(m);
|
||||
}
|
||||
E_FREE(cfdata->modname);
|
||||
/* Free the stored list of modules */
|
||||
while (cfdata->modules)
|
||||
cfdata->modules = evas_list_remove_list(cfdata->modules, cfdata->modules);
|
||||
|
||||
E_FREE(cfdata);
|
||||
}
|
||||
|
||||
static int
|
||||
_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
E_Module *m;
|
||||
const char *v;
|
||||
int i;
|
||||
|
||||
v = cfdata->modname;
|
||||
if (!v) return 0;
|
||||
for (i = 0; i < evas_list_count(cfdata->modules); i++)
|
||||
{
|
||||
CFModule *cm;
|
||||
|
||||
cm = evas_list_nth(cfdata->modules, i);
|
||||
if ((cm) && (!strcmp(cm->name, v)))
|
||||
{
|
||||
if (cm->state != cfdata->state)
|
||||
{
|
||||
e_widget_disabled_set(cfdata->gui.configure, 1);
|
||||
e_widget_disabled_set(cfdata->gui.about, 1);
|
||||
|
||||
m = e_module_find(v);
|
||||
if (!m)
|
||||
{
|
||||
m = e_module_new(v);
|
||||
if (!m) break;
|
||||
}
|
||||
switch (cfdata->state)
|
||||
{
|
||||
case MOD_ENABLED:
|
||||
if (!m->enabled)
|
||||
{
|
||||
if (!e_module_enable(m))
|
||||
{
|
||||
cm->state = MOD_UNLOADED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m->enabled)
|
||||
{
|
||||
if (m->func.config)
|
||||
e_widget_disabled_set(cfdata->gui.configure, 0);
|
||||
if (m->func.about)
|
||||
e_widget_disabled_set(cfdata->gui.about, 0);
|
||||
cm->state = MOD_ENABLED;
|
||||
}
|
||||
break;
|
||||
case MOD_UNLOADED:
|
||||
if (m)
|
||||
{
|
||||
if (m->func.config)
|
||||
e_widget_disabled_set(cfdata->gui.configure, 1);
|
||||
if (m->func.about)
|
||||
e_widget_disabled_set(cfdata->gui.about, 1);
|
||||
e_module_disable(m);
|
||||
e_object_del(E_OBJECT(m));
|
||||
cm->state = MOD_UNLOADED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
|
||||
_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
Evas_Object *o, *of, *ob, *ot;
|
||||
E_Radio_Group *rg;
|
||||
Evas_Object *o, *of, *ob;
|
||||
|
||||
cfdata->evas = evas;
|
||||
cfdata->state = -1;
|
||||
|
||||
o = e_widget_list_add(evas, 0, 1);
|
||||
|
||||
of = e_widget_framelist_add(evas, _("Modules"), 1);
|
||||
ob = e_widget_ilist_add(evas, 24, 24, &(cfdata->modname));
|
||||
cfdata->gui.list = ob;
|
||||
e_widget_on_change_hook_set(ob, _ilist_cb_change, cfdata);
|
||||
_fill_list(cfdata);
|
||||
e_widget_framelist_object_append(of, ob);
|
||||
e_widget_list_object_append(o, of, 1, 1, 0.5);
|
||||
|
||||
ot = e_widget_table_add(evas, 1);
|
||||
of = e_widget_frametable_add(evas, _("Module State"), 0);
|
||||
rg = e_widget_radio_group_new(&(cfdata->state));
|
||||
|
||||
ob = e_widget_radio_add(evas, _("Enabled"), MOD_ENABLED, rg);
|
||||
cfdata->gui.enabled = ob;
|
||||
o = e_widget_table_add(evas, 0);
|
||||
|
||||
of = e_widget_frametable_add(evas, _("Available Modules"), 0);
|
||||
ob = e_widget_ilist_add(evas, 24, 24, NULL);
|
||||
e_widget_ilist_multi_select_set(ob, 1);
|
||||
e_widget_on_change_hook_set(ob, _cb_all_change, cfdata);
|
||||
cfdata->o_all = ob;
|
||||
_fill_all(cfdata);
|
||||
e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 1, 1, 1);
|
||||
ob = e_widget_button_add(evas, _("Load Module"), NULL, _cb_load, cfdata, NULL);
|
||||
cfdata->b_load = ob;
|
||||
e_widget_disabled_set(ob, 1);
|
||||
e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 0, 1, 0);
|
||||
ob = e_widget_radio_add(evas, _("Disabled"), MOD_UNLOADED, rg);
|
||||
cfdata->gui.unloaded = ob;
|
||||
e_widget_disabled_set(ob, 1);
|
||||
e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 1, 0, 1, 0);
|
||||
e_widget_table_object_append(ot, of, 0, 0, 1, 1, 1, 1, 1, 1);
|
||||
e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 1, 1, 1, 0);
|
||||
e_widget_table_object_append(o, of, 0, 0, 1, 1, 1, 1, 1, 1);
|
||||
|
||||
of = e_widget_frametable_add(evas, _("Module Actions"), 0);
|
||||
ob = e_widget_button_add(evas, _("Configure"), NULL, _module_configure, cfdata, NULL);
|
||||
cfdata->gui.configure = ob;
|
||||
of = e_widget_frametable_add(evas, _("Loaded Modules"), 0);
|
||||
ob = e_widget_ilist_add(evas, 24, 24, NULL);
|
||||
e_widget_ilist_multi_select_set(ob, 1);
|
||||
e_widget_on_change_hook_set(ob, _cb_loaded_change, cfdata);
|
||||
cfdata->o_loaded = ob;
|
||||
_fill_loaded(cfdata);
|
||||
e_widget_frametable_object_append(of, ob, 0, 0, 2, 1, 1, 1, 1, 1);
|
||||
|
||||
ob = e_widget_button_add(evas, _("Unload Module"), NULL, _cb_unload, cfdata, NULL);
|
||||
cfdata->b_unload = ob;
|
||||
e_widget_disabled_set(ob, 1);
|
||||
e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 0, 1, 0);
|
||||
ob = e_widget_button_add(evas, _("About"), NULL, _module_about, cfdata, NULL);
|
||||
cfdata->gui.about = ob;
|
||||
e_widget_disabled_set(ob, 1);
|
||||
e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 1, 0, 1, 0);
|
||||
e_widget_table_object_append(ot, of, 0, 1, 1, 1, 1, 1, 1, 1);
|
||||
e_widget_frametable_object_append(of, ob, 0, 2, 2, 1, 1, 1, 1, 0);
|
||||
|
||||
e_widget_list_object_append(o, ot, 1, 0, 0.5);
|
||||
e_dialog_resizable_set(cfd->dia, 1);
|
||||
return o;
|
||||
ob = e_widget_button_add(evas, _("About"), NULL, _cb_about, cfdata, NULL);
|
||||
cfdata->b_about = ob;
|
||||
e_widget_disabled_set(ob, 1);
|
||||
e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 1, 0, 0, 0);
|
||||
ob = e_widget_button_add(evas, _("Configure"), NULL, _cb_config, cfdata, NULL);
|
||||
cfdata->b_configure = ob;
|
||||
e_widget_disabled_set(ob, 1);
|
||||
e_widget_frametable_object_append(of, ob, 1, 1, 1, 1, 1, 0, 0, 0);
|
||||
|
||||
e_widget_table_object_append(o, of, 1, 0, 1, 1, 1, 1, 1, 1);
|
||||
return o;
|
||||
}
|
||||
|
||||
static void
|
||||
_ilist_cb_change(void *data, Evas_Object *obj)
|
||||
/* Private Functions */
|
||||
static void
|
||||
_load_modules(E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
E_Module *m;
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
Evas_List *l;
|
||||
const char *v;
|
||||
Evas_List *l = NULL, *mdirs = NULL;
|
||||
|
||||
cfdata = data;
|
||||
v = cfdata->modname;
|
||||
if (!v) return;
|
||||
for (l = cfdata->modules; l; l = l->next)
|
||||
if (!cfdata) return;
|
||||
|
||||
/* Free the stored list of modules */
|
||||
while (cfdata->modules)
|
||||
cfdata->modules = evas_list_remove_list(cfdata->modules, cfdata->modules);
|
||||
|
||||
/* Get list of modules to sort */
|
||||
mdirs = e_path_dir_list_get(path_modules);
|
||||
for (l = mdirs; l; l = l->next)
|
||||
{
|
||||
CFModule *cm;
|
||||
|
||||
cm = l->data;
|
||||
if ((cm) && (!strcmp(cm->name, v)))
|
||||
E_Path_Dir *epd;
|
||||
Ecore_List *dirs = NULL;
|
||||
char *mod;
|
||||
|
||||
epd = l->data;
|
||||
if (!ecore_file_is_dir(epd->dir)) continue;
|
||||
dirs = ecore_file_ls(epd->dir);
|
||||
if (!dirs) continue;
|
||||
ecore_list_goto_first(dirs);
|
||||
while (mod = ecore_list_next(dirs))
|
||||
{
|
||||
cfdata->state = cm->state;
|
||||
e_widget_disabled_set(cfdata->gui.enabled, 0);
|
||||
e_widget_disabled_set(cfdata->gui.unloaded, 0);
|
||||
switch (cm->state)
|
||||
{
|
||||
case MOD_ENABLED:
|
||||
e_widget_radio_toggle_set(cfdata->gui.enabled, 1);
|
||||
e_widget_radio_toggle_set(cfdata->gui.unloaded, 0);
|
||||
break;
|
||||
case MOD_UNLOADED:
|
||||
e_widget_radio_toggle_set(cfdata->gui.unloaded, 1);
|
||||
e_widget_radio_toggle_set(cfdata->gui.enabled, 0);
|
||||
break;
|
||||
}
|
||||
e_widget_disabled_set(cfdata->gui.about, 1);
|
||||
e_widget_disabled_set(cfdata->gui.configure, 1);
|
||||
m = e_module_find(v);
|
||||
if (m)
|
||||
{
|
||||
if (m->func.about)
|
||||
e_widget_disabled_set(cfdata->gui.about, 0);
|
||||
if (m->enabled && m->func.config)
|
||||
e_widget_disabled_set(cfdata->gui.configure, 0);
|
||||
}
|
||||
break;
|
||||
E_Module *module;
|
||||
char buf[4096];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s/module.desktop", epd->dir, mod);
|
||||
if (!ecore_file_exists(buf)) continue;
|
||||
module = e_module_find(mod);
|
||||
if (!module) module = e_module_new(mod);
|
||||
if (module)
|
||||
cfdata->modules = evas_list_append(cfdata->modules, module);
|
||||
}
|
||||
free(mod);
|
||||
ecore_list_destroy(dirs);
|
||||
}
|
||||
if (l) evas_list_free(l);
|
||||
if (mdirs) e_path_dir_list_free(mdirs);
|
||||
|
||||
/* Sort the modules */
|
||||
if (cfdata->modules)
|
||||
cfdata->modules = evas_list_sort(cfdata->modules, -1, _sort_modules);
|
||||
}
|
||||
|
||||
static int
|
||||
_sort_modules(void *data1, void *data2)
|
||||
_sort_modules(void *data1, void *data2)
|
||||
{
|
||||
CFModule *m1, *m2;
|
||||
|
||||
E_Module *m1, *m2;
|
||||
|
||||
if (!data1) return 1;
|
||||
if (!data2) return -1;
|
||||
|
||||
m1 = data1;
|
||||
m2 = data2;
|
||||
return (strcmp(m1->name, m2->name));
|
||||
}
|
||||
|
||||
static void
|
||||
_module_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, const char *path)
|
||||
_fill_all(E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
Evas *evas;
|
||||
Evas_List *l = NULL;
|
||||
Evas_Coord w;
|
||||
|
||||
if (!cfdata->o_all) return;
|
||||
|
||||
/* Freeze ilist */
|
||||
evas = evas_object_evas_get(cfdata->o_all);
|
||||
evas_event_freeze(evas);
|
||||
edje_freeze();
|
||||
e_widget_ilist_freeze(cfdata->o_all);
|
||||
e_widget_ilist_clear(cfdata->o_all);
|
||||
|
||||
/* Loop modules & load ilist */
|
||||
for (l = cfdata->modules; l; l = l->next)
|
||||
{
|
||||
E_Module *mod = NULL;
|
||||
Efreet_Desktop *desk = NULL;
|
||||
Evas_Object *oc = NULL;
|
||||
char buf[4096];
|
||||
const char *icon;
|
||||
|
||||
mod = l->data;
|
||||
if (!mod) continue;
|
||||
if (mod->enabled) continue;
|
||||
snprintf(buf, sizeof(buf), "%s/module.desktop", mod->dir);
|
||||
if (!ecore_file_exists(buf)) continue;
|
||||
desk = efreet_desktop_get(buf);
|
||||
if (!desk) continue;
|
||||
icon = _get_icon(desk);
|
||||
if (icon) oc = e_util_icon_add(icon, evas);
|
||||
e_widget_ilist_append(cfdata->o_all, oc, desk->name, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* Unfreeze ilist */
|
||||
e_widget_ilist_go(cfdata->o_all);
|
||||
e_widget_min_size_get(cfdata->o_all, &w, NULL);
|
||||
e_widget_min_size_set(cfdata->o_all, w, 200);
|
||||
e_widget_ilist_thaw(cfdata->o_all);
|
||||
edje_thaw();
|
||||
evas_event_thaw(evas);
|
||||
|
||||
e_widget_disabled_set(cfdata->b_load, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
_fill_loaded(E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
Evas *evas;
|
||||
Evas_List *l = NULL;
|
||||
Evas_Coord w;
|
||||
|
||||
if (!cfdata->o_loaded) return;
|
||||
|
||||
/* Freeze ilist */
|
||||
evas = evas_object_evas_get(cfdata->o_loaded);
|
||||
evas_event_freeze(evas);
|
||||
edje_freeze();
|
||||
e_widget_ilist_freeze(cfdata->o_loaded);
|
||||
e_widget_ilist_clear(cfdata->o_loaded);
|
||||
|
||||
/* Loop modules & load ilist */
|
||||
for (l = cfdata->modules; l; l = l->next)
|
||||
{
|
||||
E_Module *mod = NULL;
|
||||
Efreet_Desktop *desk = NULL;
|
||||
Evas_Object *oc = NULL;
|
||||
char buf[4096];
|
||||
const char *icon;
|
||||
|
||||
mod = l->data;
|
||||
if (!mod) continue;
|
||||
if (!mod->enabled) continue;
|
||||
snprintf(buf, sizeof(buf), "%s/module.desktop", mod->dir);
|
||||
if (!ecore_file_exists(buf)) continue;
|
||||
desk = efreet_desktop_get(buf);
|
||||
if (!desk) continue;
|
||||
icon = _get_icon(desk);
|
||||
if (icon) oc = e_util_icon_add(icon, evas);
|
||||
e_widget_ilist_append(cfdata->o_loaded, oc, desk->name, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* Unfreeze ilist */
|
||||
e_widget_ilist_go(cfdata->o_loaded);
|
||||
e_widget_min_size_get(cfdata->o_loaded, &w, NULL);
|
||||
e_widget_min_size_set(cfdata->o_loaded, w, 200);
|
||||
e_widget_ilist_thaw(cfdata->o_loaded);
|
||||
edje_thaw();
|
||||
evas_event_thaw(evas);
|
||||
|
||||
e_widget_disabled_set(cfdata->b_unload, 1);
|
||||
e_widget_disabled_set(cfdata->b_about, 1);
|
||||
e_widget_disabled_set(cfdata->b_configure, 1);
|
||||
}
|
||||
|
||||
static const char *
|
||||
_get_icon(Efreet_Desktop *desk)
|
||||
{
|
||||
const char *icon;
|
||||
|
||||
if (!desk) return NULL;
|
||||
if (desk->icon)
|
||||
{
|
||||
icon = efreet_icon_path_find(e_config->icon_theme, desk->icon, "24x24");
|
||||
if (!icon)
|
||||
{
|
||||
char *path;
|
||||
char buf[4096];
|
||||
|
||||
path = ecore_file_get_dir(desk->orig_path);
|
||||
snprintf(buf, sizeof(buf), "%s/%s.edj", path, desk->icon);
|
||||
icon = buf;
|
||||
free(path);
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static E_Module *
|
||||
_get_module(E_Config_Dialog_Data *cfdata, const char *lbl)
|
||||
{
|
||||
Evas_List *l = NULL;
|
||||
E_Module *mod = NULL;
|
||||
|
||||
if (!cfdata) return NULL;
|
||||
if (!lbl) return NULL;
|
||||
|
||||
for (l = cfdata->modules; l; l = l->next)
|
||||
{
|
||||
Efreet_Desktop *desk = NULL;
|
||||
char buf[4096];
|
||||
|
||||
mod = l->data;
|
||||
if (!mod) continue;
|
||||
snprintf(buf, sizeof(buf), "%s/module.desktop", mod->dir);
|
||||
if (!ecore_file_exists(buf)) continue;
|
||||
desk = efreet_desktop_get(buf);
|
||||
if (!desk) continue;
|
||||
if (!strcmp(desk->name, lbl)) break;
|
||||
}
|
||||
return mod;
|
||||
}
|
||||
|
||||
/* Callbacks */
|
||||
static void
|
||||
_cb_monitor(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
const char *file;
|
||||
|
@ -348,16 +376,17 @@ _module_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event,
|
|||
cfdata = data;
|
||||
if (!cfdata) return;
|
||||
|
||||
file = ecore_file_get_file(path);
|
||||
switch (event)
|
||||
{
|
||||
case ECORE_FILE_EVENT_CREATED_DIRECTORY:
|
||||
file = ecore_file_get_file(path);
|
||||
if (mod_mon) ecore_file_monitor_del(mod_mon);
|
||||
mod_mon = ecore_file_monitor_add(path, _mod_cb_monitor, cfdata);
|
||||
mod_mon = ecore_file_monitor_add(path, _cb_mod_monitor, cfdata);
|
||||
break;
|
||||
case ECORE_FILE_EVENT_DELETED_DIRECTORY:
|
||||
_load_modules(cfdata);
|
||||
_fill_list(cfdata);
|
||||
_fill_all(cfdata);
|
||||
_fill_loaded(cfdata);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -365,21 +394,21 @@ _module_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event,
|
|||
}
|
||||
|
||||
static void
|
||||
_mod_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, const char *path)
|
||||
_cb_mod_monitor(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
const char *f;
|
||||
const char *file;
|
||||
|
||||
cfdata = data;
|
||||
if (!cfdata) return;
|
||||
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case ECORE_FILE_EVENT_CREATED_DIRECTORY:
|
||||
f = ecore_file_get_file(path);
|
||||
if (!e_util_glob_case_match(f, MODULE_ARCH)) break;
|
||||
if (!dir_mon)
|
||||
dir_mon = ecore_file_monitor_add(path, _dir_cb_monitor, cfdata);
|
||||
file = ecore_file_get_file(path);
|
||||
if (!e_util_glob_case_match(file, MODULE_ARCH)) break;
|
||||
if (dir_mon) ecore_file_monitor_del(dir_mon);
|
||||
dir_mon = ecore_file_monitor_add(path, _cb_dir_monitor, cfdata);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -387,7 +416,7 @@ _mod_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, con
|
|||
}
|
||||
|
||||
static void
|
||||
_dir_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, const char *path)
|
||||
_cb_dir_monitor(void *data, Ecore_File_Monitor *monitor, Ecore_File_Event event, const char *path)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
|
||||
|
@ -403,9 +432,9 @@ _dir_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, con
|
|||
dir_mon = NULL;
|
||||
if (mod_mon) ecore_file_monitor_del(mod_mon);
|
||||
mod_mon = NULL;
|
||||
|
||||
_load_modules(cfdata);
|
||||
_fill_list(cfdata);
|
||||
_fill_all(cfdata);
|
||||
_fill_loaded(cfdata);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -414,120 +443,151 @@ _dir_cb_monitor(void *data, Ecore_File_Monitor *mon, Ecore_File_Event event, con
|
|||
}
|
||||
|
||||
static void
|
||||
_load_modules(E_Config_Dialog_Data *cfdata)
|
||||
_cb_all_change(void *data, Evas_Object *obj)
|
||||
{
|
||||
Evas_List *l;
|
||||
Ecore_List *dirs = NULL;
|
||||
|
||||
while ((l = cfdata->modules))
|
||||
{
|
||||
CFModule *m;
|
||||
|
||||
m = l->data;
|
||||
cfdata->modules = evas_list_remove_list(cfdata->modules, l);
|
||||
E_FREE(m->name);
|
||||
E_FREE(m);
|
||||
}
|
||||
|
||||
for (l = e_path_dir_list_get(path_modules); l; l = l->next)
|
||||
{
|
||||
E_Path_Dir *epd;
|
||||
|
||||
epd = l->data;
|
||||
if (ecore_file_is_dir(epd->dir))
|
||||
{
|
||||
dirs = ecore_file_ls(epd->dir);
|
||||
if (dirs)
|
||||
{
|
||||
char *mod;
|
||||
|
||||
ecore_list_goto_first(dirs);
|
||||
while ((mod = ecore_list_next(dirs)))
|
||||
{
|
||||
Efreet_Desktop *ef;
|
||||
CFModule *m;
|
||||
char buf[4096];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s/module.desktop", epd->dir, mod);
|
||||
if (!ecore_file_exists(buf)) continue;
|
||||
ef = efreet_desktop_get(buf);
|
||||
if (!ef) continue;
|
||||
|
||||
m = E_NEW(CFModule, 1);
|
||||
m->desktop = ef;
|
||||
m->name = strdup(mod);
|
||||
cfdata->modules =
|
||||
evas_list_append(cfdata->modules, m);
|
||||
}
|
||||
ecore_list_destroy(dirs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cfdata->modules)
|
||||
cfdata->modules = evas_list_sort(cfdata->modules,
|
||||
evas_list_count(cfdata->modules),
|
||||
_sort_modules);
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
|
||||
/* Free Lists */
|
||||
cfdata = data;
|
||||
if (!cfdata) return;
|
||||
e_widget_disabled_set(cfdata->b_load, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_loaded_change(void *data, Evas_Object *obj)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
E_Module *mod;
|
||||
const char *lbl;
|
||||
int count, idx;
|
||||
|
||||
cfdata = data;
|
||||
if (!cfdata) return;
|
||||
count = e_widget_ilist_selected_count_get(cfdata->o_loaded);
|
||||
e_widget_disabled_set(cfdata->b_about, 1);
|
||||
e_widget_disabled_set(cfdata->b_configure, 1);
|
||||
e_widget_disabled_set(cfdata->b_unload, 0);
|
||||
if (count == 1)
|
||||
{
|
||||
idx = e_widget_ilist_selected_get(cfdata->o_loaded);
|
||||
lbl = e_widget_ilist_nth_label_get(cfdata->o_loaded, idx);
|
||||
mod = _get_module(cfdata, lbl);
|
||||
if (!mod) return;
|
||||
if (mod->func.about) e_widget_disabled_set(cfdata->b_about, 0);
|
||||
if (mod->func.config) e_widget_disabled_set(cfdata->b_configure, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_load(void *data, void *data2)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
Evas_List *l = NULL;
|
||||
int idx;
|
||||
|
||||
cfdata = data;
|
||||
if (!cfdata) return;
|
||||
|
||||
/* Check that something is selected */
|
||||
idx = e_widget_ilist_selected_get(cfdata->o_all);
|
||||
if (idx < 0)
|
||||
{
|
||||
e_widget_ilist_unselect(cfdata->o_all);
|
||||
e_widget_disabled_set(cfdata->b_load, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Loop the selected items, loading modules which were asked for */
|
||||
for (idx = 0, l = e_widget_ilist_items_get(cfdata->o_all); l; l = l->next, idx++)
|
||||
{
|
||||
E_Ilist_Item *item = NULL;
|
||||
E_Module *mod = NULL;
|
||||
const char *lbl;
|
||||
|
||||
item = l->data;
|
||||
if (!item) continue;
|
||||
if (!item->selected) continue;
|
||||
lbl = e_widget_ilist_nth_label_get(cfdata->o_all, idx);
|
||||
mod = _get_module(cfdata, lbl);
|
||||
if ((mod) && (!mod->enabled))
|
||||
e_module_enable(mod);
|
||||
}
|
||||
if (l) evas_list_free(l);
|
||||
|
||||
/* Refill the lists */
|
||||
_fill_all(cfdata);
|
||||
_fill_loaded(cfdata);
|
||||
}
|
||||
|
||||
static void
|
||||
_fill_list(E_Config_Dialog_Data *cfdata)
|
||||
static void
|
||||
_cb_unload(void *data, void *data2)
|
||||
{
|
||||
E_Module *m;
|
||||
Evas_List *l;
|
||||
Evas_Coord w;
|
||||
char buf[4096];
|
||||
|
||||
if (!cfdata->gui.list) return;
|
||||
|
||||
evas_event_freeze(evas_object_evas_get(cfdata->gui.list));
|
||||
edje_freeze();
|
||||
e_widget_ilist_freeze(cfdata->gui.list);
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
Evas_List *l = NULL;
|
||||
int idx;
|
||||
|
||||
e_widget_ilist_clear(cfdata->gui.list);
|
||||
e_widget_ilist_go(cfdata->gui.list);
|
||||
|
||||
for (l = cfdata->modules; l; l = l->next)
|
||||
cfdata = data;
|
||||
if (!cfdata) return;
|
||||
|
||||
/* Check that something is selected */
|
||||
idx = e_widget_ilist_selected_get(cfdata->o_loaded);
|
||||
if (idx < 0)
|
||||
{
|
||||
CFModule *cm;
|
||||
|
||||
cm = l->data;
|
||||
if (cm)
|
||||
{
|
||||
Evas_Object *oc = NULL;
|
||||
|
||||
cm->state = MOD_UNLOADED;
|
||||
m = e_module_find(cm->name);
|
||||
if ((m) && (m->enabled)) cm->state = MOD_ENABLED;
|
||||
|
||||
if (cm->desktop->icon)
|
||||
{
|
||||
const char *icon;
|
||||
|
||||
icon = efreet_icon_path_find(e_config->icon_theme, cm->desktop->icon, "64x64");
|
||||
if (!icon)
|
||||
{
|
||||
char *path;
|
||||
path = ecore_file_get_dir(cm->desktop->orig_path);
|
||||
snprintf(buf, sizeof(buf), "%s/%s.edj",
|
||||
path, cm->desktop->icon);
|
||||
icon = buf;
|
||||
free(path);
|
||||
}
|
||||
oc = e_util_icon_add(icon, cfdata->evas);
|
||||
}
|
||||
e_widget_ilist_append(cfdata->gui.list, oc, cm->desktop->name,
|
||||
NULL, NULL, cm->name);
|
||||
}
|
||||
e_widget_ilist_unselect(cfdata->o_loaded);
|
||||
e_widget_disabled_set(cfdata->b_unload, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
e_widget_ilist_go(cfdata->gui.list);
|
||||
e_widget_min_size_get(cfdata->gui.list, &w, NULL);
|
||||
e_widget_min_size_set(cfdata->gui.list, w, 200);
|
||||
e_widget_ilist_thaw(cfdata->gui.list);
|
||||
edje_thaw();
|
||||
evas_event_thaw(evas_object_evas_get(cfdata->gui.list));
|
||||
/* Loop the selected items, unloading modules which were asked for */
|
||||
for (idx = 0, l = e_widget_ilist_items_get(cfdata->o_loaded); l; l = l->next, idx++)
|
||||
{
|
||||
E_Ilist_Item *item = NULL;
|
||||
E_Module *mod = NULL;
|
||||
const char *lbl;
|
||||
|
||||
item = l->data;
|
||||
if (!item) continue;
|
||||
if (!item->selected) continue;
|
||||
lbl = e_widget_ilist_nth_label_get(cfdata->o_loaded, idx);
|
||||
mod = _get_module(cfdata, lbl);
|
||||
if ((mod) && (mod->enabled)) e_module_disable(mod);
|
||||
}
|
||||
if (l) evas_list_free(l);
|
||||
|
||||
/* Refill the lists */
|
||||
_fill_all(cfdata);
|
||||
_fill_loaded(cfdata);
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_about(void *data, void *data2)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
E_Module *mod = NULL;
|
||||
const char *lbl;
|
||||
int idx;
|
||||
|
||||
cfdata = data;
|
||||
if (!cfdata) return;
|
||||
idx = e_widget_ilist_selected_get(cfdata->o_loaded);
|
||||
lbl = e_widget_ilist_nth_label_get(cfdata->o_loaded, idx);
|
||||
mod = _get_module(cfdata, lbl);
|
||||
if (!mod) return;
|
||||
if ((mod) && (mod->func.about)) mod->func.about(mod);
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_config(void *data, void *data2)
|
||||
{
|
||||
E_Config_Dialog_Data *cfdata;
|
||||
E_Module *mod = NULL;
|
||||
const char *lbl;
|
||||
int idx;
|
||||
|
||||
cfdata = data;
|
||||
if (!cfdata) return;
|
||||
idx = e_widget_ilist_selected_get(cfdata->o_loaded);
|
||||
lbl = e_widget_ilist_nth_label_get(cfdata->o_loaded, idx);
|
||||
mod = _get_module(cfdata, lbl);
|
||||
if (!mod) return;
|
||||
if ((mod) && (mod->func.config)) mod->func.config(mod);
|
||||
}
|
||||
|
|
|
@ -365,12 +365,21 @@ e_widget_ilist_selected_label_get(Evas_Object *obj)
|
|||
EAPI Evas_Object *
|
||||
e_widget_ilist_selected_icon_get(Evas_Object *obj)
|
||||
{
|
||||
E_Widget_Data *wd;
|
||||
E_Widget_Data *wd;
|
||||
|
||||
wd = e_widget_data_get(obj);
|
||||
return e_ilist_selected_icon_get(wd->o_ilist);
|
||||
}
|
||||
|
||||
EAPI int
|
||||
e_widget_ilist_selected_count_get(Evas_Object *obj)
|
||||
{
|
||||
E_Widget_Data *wd;
|
||||
|
||||
wd = e_widget_data_get(obj);
|
||||
return e_ilist_selected_count_get(wd->o_ilist);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
e_widget_ilist_unselect(Evas_Object *obj)
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@ EAPI void e_widget_ilist_selected_set(Evas_Object *obj, int n);
|
|||
EAPI int e_widget_ilist_selected_get(Evas_Object *obj);
|
||||
EAPI const char *e_widget_ilist_selected_label_get(Evas_Object *obj);
|
||||
EAPI Evas_Object *e_widget_ilist_selected_icon_get(Evas_Object *obj);
|
||||
EAPI int e_widget_ilist_selected_count_get(Evas_Object *obj);
|
||||
EAPI void e_widget_ilist_unselect(Evas_Object *obj);
|
||||
EAPI void e_widget_ilist_remove_num(Evas_Object *obj, int n);
|
||||
EAPI void e_widget_ilist_multi_select_set(Evas_Object *obj, int multi);
|
||||
|
|
Loading…
Reference in New Issue