save modules list and load it again
authorCarsten Haitzler <raster@rasterman.com>
Sun, 5 Dec 2004 09:34:59 +0000 (09:34 +0000)
committerCarsten Haitzler <raster@rasterman.com>
Sun, 5 Dec 2004 09:34:59 +0000 (09:34 +0000)
SVN revision: 12361

src/bin/e_config.c
src/bin/e_config.h
src/bin/e_main.c
src/bin/e_module.c

index be00c84..80fab9f 100644 (file)
@@ -18,12 +18,22 @@ static void _e_config_save_cb(void *data);
 
 /* local subsystem globals */
 static Ecore_Job *_e_config_save_job = NULL;
+
 static E_Config_DD *_e_config_edd = NULL;
+static E_Config_DD *_e_config_module_edd = NULL;
 
 /* externally accessible functions */
 int
 e_config_init(void)
 {
+   _e_config_module_edd = E_CONFIG_DD_NEW("E_Config", E_Config);   
+#undef T
+#undef D
+#define T E_Config_Module
+#define D _e_config_module_edd
+   E_CONFIG_VAL(D, T, name, STR);
+   E_CONFIG_VAL(D, T, enabled, UCHAR);
+   
    _e_config_edd = E_CONFIG_DD_NEW("E_Config", E_Config);   
 #undef T
 #undef D
@@ -36,11 +46,13 @@ e_config_init(void)
    E_CONFIG_VAL(D, T, framerate, DOUBLE);
    E_CONFIG_VAL(D, T, image_cache, INT);
    E_CONFIG_VAL(D, T, font_cache, INT);
+   E_CONFIG_LIST(D, T, modules, _e_config_module_edd);
 
    e_config = e_config_domain_load("e", _e_config_edd);
-   if (!e_config) e_config = E_NEW(E_Config, 1);
-   if (e_config)
+   if (!e_config)
      {
+       /* DEFAULT CONFIG */
+       e_config = E_NEW(E_Config, 1);
        e_config->desktop_default_background = strdup(PACKAGE_DATA_DIR"/data/themes/default.eet");
        e_config->menus_scroll_speed = 1000.0;
        e_config->menus_fast_mouse_move_thresthold = 300.0;
@@ -48,9 +60,24 @@ e_config_init(void)
        e_config->framerate = 30.0;
        e_config->image_cache = 2048;
        e_config->font_cache = 512;
+         {
+            E_Config_Module *em;
+            
+            em = E_NEW(E_Config_Module, 1);
+            em->name = strdup("ibar");
+            em->enabled = 1;
+            e_config->modules = evas_list_append(e_config->modules, em);
+            em = E_NEW(E_Config_Module, 1);
+            em->name = strdup("dropshadow");
+            em->enabled = 1;
+            e_config->modules = evas_list_append(e_config->modules, em);
+            em = E_NEW(E_Config_Module, 1);
+            em->name = strdup("clock");
+            em->enabled = 1;
+            e_config->modules = evas_list_append(e_config->modules, em);
+         }
      }
-   else
-     return 0;
+   
    E_CONFIG_LIMIT(e_config->menus_scroll_speed, 1.0, 20000.0);
    E_CONFIG_LIMIT(e_config->menus_fast_mouse_move_thresthold, 1.0, 2000.0);
    E_CONFIG_LIMIT(e_config->menus_click_drag_timeout, 0.0, 10.0);
@@ -65,13 +92,20 @@ e_config_shutdown(void)
 {
    if (e_config)
      {
+       while (e_config->modules)
+         {
+            E_Config_Module *em;
+            
+            em = e_config->modules->data;
+            e_config->modules = evas_list_remove(e_config->modules, em);
+            E_FREE(em->name);
+            E_FREE(em);
+         }
        E_FREE(e_config->desktop_default_background);
        E_FREE(e_config);
      }
-   if (_e_config_edd)
-     {
-       E_CONFIG_DD_FREE(_e_config_edd);
-     }
+   E_CONFIG_DD_FREE(_e_config_edd);
+   E_CONFIG_DD_FREE(_e_config_module_edd);
    return 1;
 }
 
index 2882ae4..5096e2b 100644 (file)
@@ -1,18 +1,27 @@
 #ifndef E_CONFIG_H
 #define E_CONFIG_H
 
-typedef struct _E_Config    E_Config;
+typedef struct _E_Config        E_Config;
+typedef struct _E_Config_Module E_Config_Module;
+
 typedef Eet_Data_Descriptor E_Config_DD;
 
 struct _E_Config
 {
-   char    *desktop_default_background;
-   double   menus_scroll_speed;
-   double   menus_fast_mouse_move_thresthold;
-   double   menus_click_drag_timeout;
-   double   framerate;
-   int      image_cache;
-   int      font_cache;
+   char       *desktop_default_background;
+   double      menus_scroll_speed;
+   double      menus_fast_mouse_move_thresthold;
+   double      menus_click_drag_timeout;
+   double      framerate;
+   int         image_cache;
+   int         font_cache;
+   Evas_List  *modules;
+};
+
+struct _E_Config_Module
+{
+   char          *name;
+   unsigned char  enabled;
 };
 
 #define E_CONFIG_DD_NEW(str, typ) \
index 188a3fd..3c16e0e 100644 (file)
@@ -277,10 +277,8 @@ main(int argc, char **argv)
    
    /* ask all modules to save their config and then shutdown */
    e_module_save_all();
-   e_module_shutdown();
-   
-   /* save our config FIXME: check return value */
    e_config_save();
+   e_module_shutdown();
 
    /* unroll our stack of shutdown functions with exit code of 0 */
    _e_main_shutdown(0);
index 97754e9..f65300b 100644 (file)
@@ -36,26 +36,21 @@ static E_Module_Api _e_module_api =
 int
 e_module_init(void)
 {
+   Evas_List *l;
+   
    _e_path_modules = e_path_new();
    if (!_e_path_modules) return 0;
    e_path_path_append(_e_path_modules, "~/.e/e/modules");
    e_path_path_append(_e_path_modules, PACKAGE_LIB_DIR"/enlightenment/modules");
    
-   /* FIXME: this is crap. need to have a separate call to load a list of */
-   /* modules that the user wants loaded */
+   for (l = e_config->modules; l; l = l->next)
      {
+       E_Config_Module *em;
        E_Module *m;
        
-       m = e_module_new("test");
-       if (m) e_module_enable(m);
-       m = e_module_new("ibar");
-       if (m) e_module_enable(m);
-       m = e_module_new("dropshadow");
-       if (m) e_module_enable(m);
-#if 1  
-       m = e_module_new("clock");
-       if (m) e_module_enable(m);
-#endif 
+       em = l->data;
+       m = e_module_new(em->name);
+       if ((em->enabled) && (m)) e_module_enable(m);
      }
    
    return 1;
@@ -82,6 +77,8 @@ e_module_new(char *name)
    E_Module *m;
    char buf[4096];
    const char *modpath, *tmp, *p;
+   Evas_List *l;
+   int in_list = 0;
 
    if (!name) return NULL;
    m = E_OBJECT_ALLOC(E_Module, _e_module_free);
@@ -143,6 +140,27 @@ e_module_new(char *name)
    m->name = strdup(name);
    m->dir = e_file_get_dir(modpath);
    m->func.info(m);
+   for (l = e_config->modules; l; l = l->next)
+     {
+       E_Config_Module *em;
+       
+       em = l->data;
+       if (!strcmp(em->name, m->name))
+         {
+            in_list = 1;
+            break;
+         }
+     }
+   if (!in_list)
+     {
+       E_Config_Module *em;
+       
+       em = E_NEW(E_Config_Module, 1);
+       em->name = strdup(m->name);
+       em->enabled = 0;
+       e_config->modules = evas_list_append(e_config->modules, em);
+       e_config_save_queue();
+     }
    return m;
 }
 
@@ -163,15 +181,30 @@ e_module_dir_get(E_Module *m)
 int
 e_module_enable(E_Module *m)
 {
+   Evas_List *l;
+   
    E_OBJECT_CHECK_RETURN(m, 0);
    if (m->enabled) return 0;
    m->data = m->func.init(m);
    if (m->data) m->enabled = 1;
+   for (l = e_config->modules; l; l = l->next)
+     {
+       E_Config_Module *em;
+       
+       em = l->data;
+       if (!strcmp(em->name, m->name))
+         {
+            em->enabled = 1;
+            e_config_save_queue();
+            break;
+         }
+     }
 }
 
 int
 e_module_disable(E_Module *m)
 {
+   Evas_List *l;
    int ret;
    
    E_OBJECT_CHECK_RETURN(m, 0);
@@ -179,6 +212,18 @@ e_module_disable(E_Module *m)
    ret = m->func.shutdown(m);
    m->data = NULL;
    m->enabled = 0;
+   for (l = e_config->modules; l; l = l->next)
+     {
+       E_Config_Module *em;
+       
+       em = l->data;
+       if (!strcmp(em->name, m->name))
+         {
+            em->enabled = 0;
+            e_config_save_queue();
+            break;
+         }
+     }
    return ret;
 }
 
@@ -273,6 +318,23 @@ e_module_menu_new(void)
 static void
 _e_module_free(E_Module *m)
 {
+   Evas_List *l;
+   
+   for (l = e_config->modules; l; l = l->next)
+     {
+       E_Config_Module *em;
+       
+       em = l->data;
+       if (!strcmp(em->name, m->name))
+         {
+            e_config->modules = evas_list_remove(e_config->modules, em);
+            E_FREE(em->name);
+            E_FREE(em);
+            e_config_save_queue();
+            break;
+         }
+     }
+   
    if (m->enabled) m->func.shutdown(m);
    if (m->name) free(m->name);
    if (m->dir) free(m->dir);