New modapi!

If a module fails to load, don't unload it. Mark it with an error flag,
and ask the user if he wants to unload it.


SVN revision: 16918
This commit is contained in:
sebastid 2005-09-24 13:42:05 +00:00 committed by sebastid
parent 55f68789d3
commit f4498d11a3
25 changed files with 126 additions and 93 deletions

1
TODO
View File

@ -110,7 +110,6 @@ Some of the things (in very short form) that need to be done to E17...
* find all other instances of using e_error dialogs and use them only with low
level errors than need attention no matter what.
* cannot load module error - make that a "shall i unload this module" dialog
* winlist should support place for window "screenshot" in list as well as
app icon
* winlist should in theory allow horizontal list layout not just vertical (set

View File

@ -24,6 +24,8 @@ static E_Menu *_e_module_control_menu_new(E_Module *mod);
static void _e_module_menu_free(void *obj);
static void _e_module_control_menu_about(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_module_control_menu_enabled(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_module_dialog_disable_show(char *title, char *body, E_Module *m);
static void _e_module_cb_dialog_disable(void *data, E_Dialog *dia);
/* local subsystem globals */
static Evas_List *_e_modules = NULL;
@ -77,6 +79,7 @@ e_module_new(char *name)
{
E_Module *m;
char buf[4096];
char body[4096], title[1024];
char *modpath, *s;
Evas_List *l;
int in_list = 0;
@ -92,28 +95,28 @@ e_module_new(char *name)
modpath = strdup(name);
if (!modpath)
{
e_error_dialog_show(_("Error loading Module"),
_("There was an error loading module named: %s\n"
"No module named %s could be found in the\n"
"module search directories\n"),
name, buf);
free(m);
return NULL;
snprintf(body, sizeof(body), _("There was an error loading module named: %s<br>"
"No module named %s could be found in the<br>"
"module search directories.<br>"),
name, buf);
_e_module_dialog_disable_show(_("Error loading Module"), body, m);
m->error = 1;
goto init_done;
}
m->handle = dlopen(modpath, RTLD_NOW | RTLD_GLOBAL);
if (!m->handle)
{
e_error_dialog_show(_("Error loading Module"),
_("There was an error loading module named: %s\n"
"The full path to this module is:\n"
"%s\n"
"The error reported was:\n"
"%s"),
name, buf, dlerror());
free(m);
return NULL;
snprintf(body, sizeof(body), _("There was an error loading module named: %s<br>"
"The full path to this module is:<br>"
"%s<br>"
"The error reported was:<br>"
"%s<br>"),
name, buf, dlerror());
_e_module_dialog_disable_show(_("Error loading Module"), body, m);
m->error = 1;
goto init_done;
}
m->api = dlsym(m->handle, "e_module_api");
m->api = dlsym(m->handle, "e_modapi");
m->func.init = dlsym(m->handle, "e_modapi_init");
m->func.shutdown = dlsym(m->handle, "e_modapi_shutdown");
m->func.save = dlsym(m->handle, "e_modapi_save");
@ -127,34 +130,43 @@ e_module_new(char *name)
(!m->api)
)
{
e_error_dialog_show(_("Error loading Module"),
_("There was an error loading module named: %s\n"
"The full path to this module is:\n"
"%s\n"
"The error reported was:\n"
"%s"),
name, buf, dlerror());
snprintf(body, sizeof(body), _("There was an error loading module named: %s<br>"
"The full path to this module is:<br>"
"%s<br>"
"The error reported was:<br>"
"%s<br>"),
name, buf, dlerror());
_e_module_dialog_disable_show(_("Error loading Module"), body, m);
m->api = NULL;
m->func.init = NULL;
m->func.shutdown = NULL;
m->func.save = NULL;
m->func.info = NULL;
m->func.about = NULL;
dlclose(m->handle);
free(m);
return NULL;
m->handle = NULL;
m->error = 1;
goto init_done;
}
if (m->api->version < E_MODULE_API_VERSION)
{
char buf[4096], title[1024];
snprintf(buf, sizeof(buf), _("Module API Error<br>Error initializing Module: %s<br>"
"It requires a minimum module API version of: %i.<br>"
"The module API advertized by Enlightenment is: %i.<br>"),
_(m->api->name), E_MODULE_API_VERSION, m->api->version);
snprintf(body, sizeof(body), _("Module API Error<br>Error initializing Module: %s<br>"
"It requires a minimum module API version of: %i.<br>"
"The module API advertized by Enlightenment is: %i.<br>"),
_(m->api->name), E_MODULE_API_VERSION, m->api->version);
snprintf(title, sizeof(title), _("Enlightenment %s Module"), _(m->api->name));
e_module_dialog_show(title, buf);
_e_module_dialog_disable_show(title, body, m);
dlclose(m->handle);
free(m);
return NULL;
m->handle = NULL;
m->error = 1;
goto init_done;
}
init_done:
_e_modules = evas_list_append(_e_modules, m);
m->name = strdup(name);
s = ecore_file_get_dir(modpath);
@ -163,7 +175,8 @@ e_module_new(char *name)
m->dir = ecore_file_get_dir(s);
free(s);
}
m->func.info(m);
if (m->func.info)
m->func.info(m);
for (l = e_config->modules; l; l = l->next)
{
E_Config_Module *em;
@ -194,7 +207,7 @@ e_module_save(E_Module *m)
{
E_OBJECT_CHECK_RETURN(m, 0);
E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
if (!m->enabled) return 0;
if ((!m->enabled) || (m->error)) return 0;
return m->func.save(m);
}
@ -213,7 +226,7 @@ e_module_enable(E_Module *m)
E_OBJECT_CHECK_RETURN(m, 0);
E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
if (m->enabled) return 0;
if ((m->enabled) || (m->error)) return 0;
m->data = m->func.init(m);
if (m->data) m->enabled = 1;
for (l = e_config->modules; l; l = l->next)
@ -239,7 +252,7 @@ e_module_disable(E_Module *m)
E_OBJECT_CHECK_RETURN(m, 0);
E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
if (!m->enabled) return 0;
if ((!m->enabled) || (m->error)) return 0;
ret = m->func.shutdown(m);
m->data = NULL;
m->enabled = 0;
@ -278,7 +291,7 @@ e_module_save_all(void)
E_Module *m;
m = l->data;
if (m->enabled)
if ((m->enabled) && (!m->error))
{
if (!m->func.save(m)) ret = 0;
}
@ -328,7 +341,7 @@ e_module_menu_new(void)
mod = l->data;
mi = e_menu_item_new(m);
if (mod->label) e_menu_item_label_set(mi, mod->label);
if ((mod->api) && (mod->api->name)) e_menu_item_label_set(mi, mod->api->name);
else e_menu_item_label_set(mi, mod->name);
if (mod->edje_icon_file)
{
@ -340,8 +353,11 @@ e_module_menu_new(void)
else if (mod->icon_file)
e_menu_item_icon_file_set(mi, mod->icon_file);
subm = _e_module_control_menu_new(mod);
e_menu_item_submenu_set(mi, subm);
dat->submenus = evas_list_append(dat->submenus, subm);
if (subm)
{
e_menu_item_submenu_set(mi, subm);
dat->submenus = evas_list_append(dat->submenus, subm);
}
++mod_count;
}
if (mod_count == 0)
@ -352,6 +368,22 @@ e_module_menu_new(void)
return m;
}
void
e_module_dialog_show(char *title, char *body)
{
E_Dialog *dia;
dia = e_dialog_new(e_container_current_get(e_manager_current_get()));
if (!dia) return;
e_dialog_title_set(dia, title);
e_dialog_icon_set(dia, "enlightenment/e", 64);
e_dialog_text_set(dia, body);
e_dialog_button_add(dia, _("Ok"), NULL, NULL, NULL);
e_win_centered_set(dia->win, 1);
e_dialog_show(dia);
}
/* local subsystem functions */
static void
@ -378,16 +410,15 @@ _e_module_free(E_Module *m)
}
}
if (m->enabled)
if ((m->enabled) && (!m->error))
{
m->func.save(m);
m->func.shutdown(m);
}
if (m->name) free(m->name);
if (m->dir) free(m->dir);
dlclose(m->handle);
if (m->handle) dlclose(m->handle);
_e_modules = evas_list_remove(_e_modules, m);
if (m->label) free(m->label);
if (m->icon_file) free(m->icon_file);
if (m->edje_icon_file) free(m->edje_icon_file);
if (m->edje_icon_key) free(m->edje_icon_key);
@ -399,6 +430,8 @@ _e_module_control_menu_new(E_Module *mod)
{
E_Menu *m;
E_Menu_Item *mi;
if (mod->error) return NULL;
m = e_menu_new();
@ -470,21 +503,35 @@ _e_module_control_menu_enabled(void *data, E_Menu *m, E_Menu_Item *mi)
e_menu_item_toggle_set(mi, e_module_enabled_get(mod));
}
void
e_module_dialog_show(char *title, char *body)
static void
_e_module_dialog_disable_show(char *title, char *body, E_Module *m)
{
E_Dialog *dia;
char buf[4096];
dia = e_dialog_new (e_container_current_get (e_manager_current_get ()));
dia = e_dialog_new(e_container_current_get(e_manager_current_get()));
if (!dia) return;
e_dialog_title_set (dia, title);
e_dialog_icon_set (dia, "enlightenment/e", 64);
e_dialog_text_set (dia, body);
e_dialog_button_add (dia, _("Ok"), NULL, NULL, NULL);
e_win_centered_set (dia->win, 1);
e_dialog_show (dia);
snprintf(buf, sizeof(buf), "%s<br>%s", body,
_("Would you like to unload this module?<br>"));
e_dialog_title_set(dia, title);
e_dialog_icon_set(dia, "enlightenment/e", 64);
e_dialog_text_set(dia, buf);
e_dialog_button_add(dia, _("Yes"), NULL, _e_module_cb_dialog_disable, m);
e_dialog_button_add(dia, _("No"), NULL, NULL, NULL);
e_win_centered_set(dia->win, 1);
e_dialog_show(dia);
}
static void
_e_module_cb_dialog_disable(void *data, E_Dialog *dia)
{
E_Module *m;
m = data;
e_module_disable(m);
e_object_del(E_OBJECT(m));
e_object_del(E_OBJECT(dia));
e_config_save_queue();
}

View File

@ -3,7 +3,7 @@
*/
#ifdef E_TYPEDEFS
#define E_MODULE_API_VERSION 1
#define E_MODULE_API_VERSION 2
typedef struct _E_Module E_Module;
typedef struct _E_Module_Api E_Module_Api;
@ -33,6 +33,7 @@ struct _E_Module
} func;
unsigned char enabled : 1;
unsigned char error : 1;
/* the module is allowed to modify these */
void *data;
@ -41,7 +42,6 @@ struct _E_Module
/* modify these but only set them up when the info func is called */
/* e_module will free them when the module is freed. */
/* note you will need to malloc (strdup) these fields due to the free */
char *label;
char *icon_file;
char *edje_icon_file;
char *edje_icon_key;

View File

@ -65,7 +65,7 @@ static E_Config_DD *conf_face_edd;
static int battery_count;
/* public module routines. all modules must have these */
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Battery"
@ -111,7 +111,6 @@ e_modapi_info(E_Module *m)
{
char buf[4096];
m->label = strdup(_("Battery"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
m->icon_file = strdup(buf);
return 1;

View File

@ -86,7 +86,7 @@ struct _Status
char *time;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);

View File

@ -38,7 +38,7 @@ const int
;
/* public module routines. all modules must have these */
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Clock"
@ -85,7 +85,6 @@ e_modapi_info(E_Module *module)
{
char buf[4096];
module->label = strdup(_("Clock"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(module));
module->icon_file = strdup(buf);
return 1;

View File

@ -47,7 +47,7 @@ struct _Clock_Face
E_Gadman_Client *gmc;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *module);
EAPI int e_modapi_shutdown (E_Module *module);

View File

@ -57,7 +57,7 @@ static E_Config_DD *conf_face_edd;
static int cpufreq_count;
/* public module routines */
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Cpufreq"
@ -103,7 +103,6 @@ e_modapi_info(E_Module *module)
{
char buf[4096];
module->label = strdup(_("CpuFreq"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(module));
module->icon_file = strdup(buf);
return 1;

View File

@ -64,7 +64,7 @@ struct _Cpufreq_Face
E_Gadman_Client *gmc;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *module);
EAPI int e_modapi_shutdown (E_Module *module);

View File

@ -90,7 +90,7 @@ static void _tilebuf_free_render_rects(Evas_List *rects);
#define TILE(tb, x, y) ((tb)->tiles.tiles[((y) * (tb)->tiles.w) + (x)])
/* public module routines. all modules must have these */
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Dropshadow"
@ -176,7 +176,6 @@ e_modapi_info(E_Module *m)
{
char buf[4096];
m->label = strdup(_("Dropshadow"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
m->icon_file = strdup(buf);
return 1;

View File

@ -97,7 +97,7 @@ struct _Tilebuf_Tile
int redraw : 1;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);

View File

@ -110,7 +110,7 @@ static void _ibar_drag_cb_intercept_move(void *data, Evas_Object *o, Evas_Coo
static void _ibar_drag_cb_intercept_resize(void *data, Evas_Object *o, Evas_Coord w, Evas_Coord h);
/* public module routines. all modules must have these */
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"IBar"
@ -156,7 +156,6 @@ e_modapi_info(E_Module *m)
{
char buf[4096];
m->label = strdup(_("IBar"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
m->icon_file = strdup(buf);
return 1;

View File

@ -91,7 +91,7 @@ struct _IBar_Icon
unsigned char raise_on_hilight : 1;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);

View File

@ -92,7 +92,7 @@ static void _ibox_box_cb_menu_enabled(void *data, E_Menu *m, E_Menu_Item *mi)
static void _ibox_box_cb_menu_edit(void *data, E_Menu *m, E_Menu_Item *mi);
/* public module routines. all modules must have these */
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"IBox"
@ -138,7 +138,6 @@ e_modapi_info(E_Module *m)
{
char buf[4096];
m->label = strdup(_("IBox"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
m->icon_file = strdup(buf);
return 1;

View File

@ -84,7 +84,7 @@ struct _IBox_Icon
unsigned char raise_on_hilight : 1;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);

View File

@ -105,7 +105,7 @@ static E_Config_DD *_conf_edd;
static E_Config_DD *_conf_face_edd;
/* public module routines. all modules must have these */
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Pager"
@ -154,7 +154,6 @@ e_modapi_info(E_Module *module)
{
char buf[4096];
module->label = strdup(_("Pager"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(module));
module->icon_file = strdup(buf);
return 1;

View File

@ -141,7 +141,7 @@ struct _Pager_Popup
Ecore_Timer *timer;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *module);
EAPI int e_modapi_shutdown (E_Module *module);

View File

@ -27,7 +27,7 @@ static void _randr_save_res(Randr_Resolution *res);
static E_Config_DD *conf_edd;
static E_Config_DD *conf_manager_edd;
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"RandR"
@ -72,10 +72,7 @@ e_modapi_info(E_Module *m)
{
/*
char buf[4096];
*/
m->label = strdup(_("Randr"));
/*
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
m->icon_file = strdup(buf);
*/

View File

@ -42,7 +42,7 @@ struct _Randr_Resolution
Ecore_X_Screen_Size prev, next;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);

View File

@ -22,7 +22,7 @@ static int button_count;
static E_Config_DD *conf_edd;
static E_Config_DD *conf_face_edd;
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Start"
@ -67,7 +67,6 @@ e_modapi_info(E_Module *m)
{
char buf[4096];
m->label = strdup(_("Start"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
m->icon_file = strdup(buf);
return 1;

View File

@ -38,7 +38,7 @@ struct _Start_Face
E_Gadman_Client *gmc;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);

View File

@ -38,7 +38,7 @@ static E_Config_DD *conf_face_edd;
static int temperature_count;
/* public module routines. all modules must have these */
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Temperature"
@ -84,7 +84,6 @@ e_modapi_info(E_Module *m)
{
char buf[4096];
m->label = strdup(_("Temperature"));
snprintf(buf, sizeof(buf), "%s/module_icon.png", e_module_dir_get(m));
m->icon_file = strdup(buf);
return 1;

View File

@ -57,7 +57,7 @@ struct _Temperature_Face
E_Gadman_Client *gmc;
};
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);

View File

@ -4,7 +4,7 @@
#include "e.h"
#include "e_mod_main.h"
E_Module_Api e_module_api =
E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Test"
@ -53,7 +53,6 @@ e_modapi_save(E_Module *m)
int
e_modapi_info(E_Module *m)
{
m->label = strdup(_("Test!!!"));
return 1;
}

View File

@ -1,7 +1,7 @@
#ifndef E_MOD_MAIN_H
#define E_MOD_MAIN_H
extern E_Module_Api e_module_api;
extern E_Module_Api e_modapi;
EAPI void *e_modapi_init (E_Module *m);
EAPI int e_modapi_shutdown (E_Module *m);