[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [E-devel] [PATCH] E Protected File Registry



Modified version of the file registry, changed a hash for a list and
basically simplified it all so it now operates with ref counts. Had to
make some changes to setting and unsetting default desktops, but it's for
the best as it is now all in e_bg.c and consistent.

Any comments...you know where to find me.

metrics


On Tue, Oct 10, 2006 at 07:21:14PM +1000, Metrics wrote:
> Hi all,
> 
> I've attached some patches and additional files that add a protected
> file registry to E. Basically, the point of this is to protect files
> that are in use from being deleted by fm2 in its various guises.
> The patch adds file protection for themes and desktops at the moment,
> and works reliably. e_filereg.c and e_filereg.h go into e/src/bin (of
> course :)).
> 
> Any suggestions gratefully accepted.
> 
> metrics
? e_filereg.c
? e_filereg.h
Index: Makefile.am
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/Makefile.am,v
retrieving revision 1.160
diff -u -r1.160 Makefile.am
--- Makefile.am	14 Oct 2006 09:43:12 -0000	1.160
+++ Makefile.am	16 Oct 2006 02:42:42 -0000
@@ -173,6 +173,7 @@
 e_int_config_transitions.h \
 e_fwin.h \
 e_widget_aspect.h \
+e_filereg.h \
 e_widget_desk_preview.h \
 e_int_config_borders.h
  
@@ -324,6 +325,7 @@
 e_fwin.c \
 e_widget_aspect.c \
 e_widget_desk_preview.c \
+e_filereg.c \
 e_int_config_borders.c \
 $(ENLIGHTENMENTHEADERS)
 
Index: e_bg.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_bg.c,v
retrieving revision 1.20
diff -u -r1.20 e_bg.c
--- e_bg.c	9 Oct 2006 19:06:43 -0000	1.20
+++ e_bg.c	16 Oct 2006 02:42:44 -0000
@@ -7,8 +7,47 @@
 static void _e_bg_signal(void *data, Evas_Object *obj, const char *emission, const char *source);
 
 /* local subsystem globals */
+static int _e_bg_reg_files = 0;
 
 /* externally accessible functions */
+EAPI int 
+e_bg_init(void)
+{
+   Evas_List *l;
+
+   /* Register files in use */
+   if (e_config->desktop_default_background)
+      e_filereg_register(e_config->desktop_default_background);
+
+   for (l = e_config->desktop_backgrounds; l; l = l->next)
+     {
+       E_Config_Desktop_Background *cfbg;
+       cfbg = l->data;
+       e_filereg_register(cfbg->file);
+     }
+
+   return 1;
+}
+
+EAPI int 
+e_bg_shutdown(void)
+{
+   Evas_List *l;
+
+   /* Register files in use */
+   if (e_config->desktop_default_background)
+      e_filereg_deregister(e_config->desktop_default_background);
+
+   for (l = e_config->desktop_backgrounds; l; l = l->next)
+     {
+       E_Config_Desktop_Background *cfbg;
+       cfbg = l->data;
+       e_filereg_deregister(cfbg->file);
+     }
+
+   return 1;
+}
+
 EAPI const char *
 e_bg_file_get(E_Zone *zone, E_Desk *desk)
 {
@@ -77,7 +116,7 @@
    Evas_Object *o;
    const char *bgfile = "";
    const char *trans = "";
-   
+
    if (transition == E_BG_TRANSITION_START) trans = e_config->transition_start;
    else if (transition == E_BG_TRANSITION_DESK) trans = e_config->transition_desk;
    else if (transition == E_BG_TRANSITION_CHANGE) trans = e_config->transition_change;
@@ -149,6 +188,24 @@
 }
 
 EAPI void
+e_bg_default_set(char * file)
+{
+    if (e_config->desktop_default_background)
+      {
+	 evas_stringshare_del(e_config->desktop_default_background);
+	 e_filereg_deregister(e_config->desktop_default_background);
+      }
+
+    if (file)
+      {
+	 e_filereg_register(file);
+	 e_config->desktop_default_background = evas_stringshare_add(file);
+      }
+    else
+       e_config->desktop_default_background = NULL;
+}
+
+EAPI void
 e_bg_add(int container, int zone, int desk_x, int desk_y, char *file)
 {
    E_Config_Desktop_Background *cfbg;
@@ -161,6 +218,7 @@
    cfbg->desk_y = desk_y;
    cfbg->file = evas_stringshare_add(file);
    e_config->desktop_backgrounds = evas_list_append(e_config->desktop_backgrounds, cfbg);
+   e_filereg_register(cfbg->file);
 }
 
 EAPI void
@@ -177,6 +235,7 @@
 	    (cfbg->desk_x == desk_x) && (cfbg->desk_y == desk_y))
 	  {
 	     e_config->desktop_backgrounds = evas_list_remove_list(e_config->desktop_backgrounds, l);
+	     e_filereg_deregister(cfbg->file);
 	     if (cfbg->file) evas_stringshare_del(cfbg->file);
 	     free(cfbg);
 	     break;
@@ -191,7 +250,7 @@
    E_Manager *man;
    E_Container *con;
    E_Zone *zone;
-   
+
    for (l = e_manager_list(); l; l = l->next)
      {
 	man = l->data;
@@ -232,3 +291,4 @@
    evas_object_clip_set(zone->bg_object, zone->bg_clip_object);
    evas_object_show(zone->bg_object);
 }
+
Index: e_bg.h
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_bg.h,v
retrieving revision 1.6
diff -u -r1.6 e_bg.h
--- e_bg.h	9 Oct 2006 19:06:43 -0000	1.6
+++ e_bg.h	16 Oct 2006 02:42:45 -0000
@@ -14,10 +14,14 @@
 #ifndef E_BG_H
 #define E_BG_H
 
+EAPI int e_bg_init(void);
+EAPI int e_bg_shutdown(void);
+
 EAPI const char *e_bg_file_get(E_Zone *zone, E_Desk *desk);
 EAPI void e_bg_zone_update(E_Zone *zone, E_Bg_Transition transition);
 EAPI void e_bg_add(int container, int zone, int desk_x, int desk_y, char *file);
 EAPI void e_bg_del(int container, int zone, int desk_x, int desk_y);
+EAPI void e_bg_default_set(char *file);
 EAPI void e_bg_update(void);
     
 #endif
Index: e_fm.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_fm.c,v
retrieving revision 1.93
diff -u -r1.93 e_fm.c
--- e_fm.c	15 Oct 2006 23:52:36 -0000	1.93
+++ e_fm.c	16 Oct 2006 02:44:48 -0000
@@ -4223,7 +4223,7 @@
    E_Manager *man;
    E_Container *con;
    E_Zone *zone;
-   int x, y, can_w, can_w2;
+   int x, y, can_w, can_w2, protected;
    char buf[4096];
    
    sd = ic->sd;
@@ -4308,7 +4308,11 @@
 	  snprintf(buf, sizeof(buf), "%s/.order", sd->realpath);
 	if (ecore_file_can_write(buf)) can_w = 1;
      }
-   if ((can_w) && (can_w2))
+   
+   snprintf(buf, sizeof(buf), "%s/%s", sd->realpath, ic->info.file);
+   protected = e_filereg_file_protected(buf);
+
+   if ((can_w) && (can_w2) && !(protected))
      {
 	mi = e_menu_item_new(mn);
 	e_menu_item_separator_set(mi, 1);
Index: e_includes.h
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_includes.h,v
retrieving revision 1.137
diff -u -r1.137 e_includes.h
--- e_includes.h	14 Oct 2006 09:43:12 -0000	1.137
+++ e_includes.h	16 Oct 2006 02:44:50 -0000
@@ -148,6 +148,7 @@
 #include "e_int_config_transitions.h"
 #include "e_obj_dialog.h"
 #include "e_fwin.h"
+#include "e_filereg.h"
 #include "e_widget_aspect.h"
 #include "e_widget_desk_preview.h"
 #include "e_int_config_borders.h"
Index: e_int_config_wallpaper.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_int_config_wallpaper.c,v
retrieving revision 1.18
diff -u -r1.18 e_int_config_wallpaper.c
--- e_int_config_wallpaper.c	8 Oct 2006 08:04:17 -0000	1.18
+++ e_int_config_wallpaper.c	16 Oct 2006 02:45:01 -0000
@@ -515,12 +515,10 @@
 	cfbg = e_config->desktop_backgrounds->data;
 	e_bg_del(cfbg->container, cfbg->zone, cfbg->desk_x, cfbg->desk_y);
      }
-   if (e_config->desktop_default_background)
-     evas_stringshare_del(e_config->desktop_default_background);
    if ((cfdata->use_theme_bg) || (!cfdata->bg))
-     e_config->desktop_default_background = NULL;
+     e_bg_default_set(NULL);
    else
-     e_config->desktop_default_background = evas_stringshare_add(cfdata->bg);
+     e_bg_default_set(cfdata->bg);
    
    cfdata->all_this_desk_screen = 0;
    
@@ -681,9 +679,7 @@
 	     cfbg = e_config->desktop_backgrounds->data;
 	     e_bg_del(cfbg->container, cfbg->zone, cfbg->desk_x, cfbg->desk_y);
 	  }
-	if (e_config->desktop_default_background)
-	  evas_stringshare_del(e_config->desktop_default_background);
-	e_config->desktop_default_background = NULL;
+	  e_bg_default_set(NULL);
      }
    else
      {
@@ -695,9 +691,7 @@
 		  cfbg = e_config->desktop_backgrounds->data;
 		  e_bg_del(cfbg->container, cfbg->zone, cfbg->desk_x, cfbg->desk_y);
 	       }
-	     if (e_config->desktop_default_background)
-	       evas_stringshare_del(e_config->desktop_default_background);
-	     e_config->desktop_default_background = evas_stringshare_add(cfdata->bg);
+	     e_bg_default_set(cfdata->bg);
 	  }
 	else if (cfdata->all_this_desk_screen == 1)
 	  {
Index: e_main.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_main.c,v
retrieving revision 1.190
diff -u -r1.190 e_main.c
--- e_main.c	30 Sep 2006 04:49:31 -0000	1.190
+++ e_main.c	16 Oct 2006 02:45:13 -0000
@@ -68,6 +68,9 @@
 	sigaltstack(&ss, NULL);
      }
 #endif
+#ifdef HAVE_FONTCONFIG
+   printf("HAVE_FONTCONFIG WAS DEFINED\n");
+#endif
    
    action.sa_sigaction = e_sigseg_act;
    action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
@@ -489,6 +492,13 @@
 	_e_main_shutdown(-1);
      }
    _e_main_shutdown_push(_e_main_dirs_shutdown);
+   /* setup file registry */
+   if (!e_filereg_init())
+     {
+	e_error_message_show(_("Enlightenment cannot set up its file registry system."));
+	_e_main_shutdown(-1);
+     }
+   _e_main_shutdown_push(e_filereg_shutdown);
    /* init config system */
    if (!e_config_init())
      {
@@ -553,6 +563,13 @@
 	_e_main_shutdown(-1);
      }
    _e_main_shutdown_push(e_theme_shutdown);
+   /* init desktop background system */
+   if (!e_bg_init())
+     {
+	e_error_message_show(_("Enlightenment cannot set up its desktop background system."));
+	_e_main_shutdown(-1);
+     }
+   _e_main_shutdown_push(e_bg_init);
    if (!((!e_config->show_splash) || (after_restart)))
      {
 	/* setup init status window/screen */
Index: e_theme.c
===================================================================
RCS file: /var/cvs/e/e17/apps/e/src/bin/e_theme.c,v
retrieving revision 1.24
diff -u -r1.24 e_theme.c
--- e_theme.c	23 Aug 2006 14:00:31 -0000	1.24
+++ e_theme.c	16 Oct 2006 02:45:17 -0000
@@ -271,6 +271,7 @@
 e_theme_file_set(const char *category, const char *file)
 {
    E_Theme_Result *res;
+   char buf[4096];
 
    if (group_cache)
      {
@@ -282,12 +283,16 @@
    if (res)
      {
 	mappings = evas_hash_del(mappings, category, res);
-	if (res->file) evas_stringshare_del(res->file);
+	if (res->file) {
+	     evas_stringshare_del(res->file);
+	     e_filereg_deregister(res->file);
+	}
 	if (res->cache) evas_stringshare_del(res->cache);
 	free(res);
      }
    res = calloc(1, sizeof(E_Theme_Result));
    res->file = evas_stringshare_add(file);
+   e_filereg_register(res->file);
    mappings = evas_hash_add(mappings, category, res);
 }
 
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

/*
 * Implementation of a protected file registry. Any files that are
 * currently being used by E in core components should be registered
 * here and will be protected as best as E can. :)
 */

/* Local subsystem globals */
static Evas_List *_e_filereg = NULL;

typedef struct _Filereg_Item Filereg_Item;

struct _Filereg_Item
{
   char * path;
   int ref_count;
};

/* Externally accessible functions */
EAPI int
e_filereg_init(void)
{
   return 1;
}

EAPI int
e_filereg_shutdown(void)
{
   Evas_List * ll;
   Filereg_Item * item;

   /* Delete all strings in the hash */
   for (ll = _e_filereg; ll; ll = ll->next)
     {
	item = ll->data;	
	E_FREE(item->path);
	E_FREE(item);
     }

   _e_filereg = evas_list_free(_e_filereg);
}

EAPI int
e_filereg_register(const char * path)
{
   Evas_List * ll;
   Filereg_Item * item;

   for (ll = _e_filereg; ll; ll = ll->next)
     {
	item = ll->data;	
	if (!strcmp(item->path, path))
	  {
	     /* File already registered, increment ref. count */
	     item->ref_count++;
	     return 1;
	  }
     }

   /* Doesn't exist so add to list. */
   item = E_NEW(Filereg_Item, 1);
   if (!item) return 0;

   item->path = strdup(path);
   item->ref_count = 1;
   _e_filereg = evas_list_append(_e_filereg, item);

   return 1;
}

EAPI void
e_filereg_deregister(const char * path)
{
   Evas_List * ll;
   Filereg_Item * item;

   for (ll = _e_filereg; ll; ll = ll->next)
     {
	item = ll->data;	
	if (!strcmp(item->path, path))
	  {
	     item->ref_count--;
	     if (item->ref_count == 0) 
	       {
		_e_filereg = evas_list_remove_list(_e_filereg, ll);	
		E_FREE(item->path);
		E_FREE(item);
	       }

	     return;
	  }
     }
}

EAPI Evas_Bool
e_filereg_file_protected(const char * path)
{
   Evas_List * ll;
   Filereg_Item * item;

   for (ll = _e_filereg; ll; ll = ll->next)
     {
	item = ll->data;	
	if (!strcmp(item->path, path))
	     return 1;
     }

   return 0;
}
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#ifdef E_TYPEDEFS

#else
#ifndef E_FILEREG_H
#define E_FILEREG_H

EAPI int e_filereg_init(void);
EAPI int e_filereg_shutdown(void);

EAPI int e_filereg_register(const char * path);
EAPI void e_filereg_deregister(const char * path);
EAPI Evas_Bool e_filereg_file_protected(const char * path);

#endif
#endif