From 29a5b4489d2292a9ef76571d3ca5375c977656e5 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Fri, 2 Apr 2010 15:27:58 +0000 Subject: [PATCH] Centralise file loading, based on file type. Change install paths: - menus: /config/menus -> /menus - icons: /config/pix -> /icons - pix: /config/pix -> /pix SVN revision: 47695 --- config/Makefile.am | 2 +- config/matches.cfg | 12 ++++---- icons/Makefile.am | 2 +- pix/Makefile.am | 2 +- src/E.h | 11 ++++++-- src/backgrounds.c | 2 +- src/config.c | 68 +++++++++++++++++++++++++++++++++------------- src/cursors.c | 2 +- src/iclass.c | 4 +-- src/icons.c | 2 +- src/menus-misc.c | 27 ++---------------- src/sound.c | 2 +- 12 files changed, 76 insertions(+), 60 deletions(-) diff --git a/config/Makefile.am b/config/Makefile.am index 7d385968..92cc95d2 100644 --- a/config/Makefile.am +++ b/config/Makefile.am @@ -8,7 +8,7 @@ tconfdir = $(pkgdatadir)/config tconf_DATA = \ definitions actionclasses.cfg -menudir = $(pkgdatadir)/config/menus +menudir = $(pkgdatadir)/menus menu_DATA = \ desktop.menu enlightenment.menu maintenance.menu settings.menu \ winops.menu winops_groups.menu winops_layer.menu \ diff --git a/config/matches.cfg b/config/matches.cfg index f2094782..4d642f1b 100644 --- a/config/matches.cfg +++ b/config/matches.cfg @@ -39,12 +39,12 @@ Class Enlightenment_Dialog Border DIALOG Class Enlightenment_Pager Border PAGER # Default icons -Class Eterm Icon pix/mon.png -Class XTerm Icon pix/mon.png -Class GnomeTerminal Icon pix/mon.png -Class Enlightenment_Dialog Icon pix/e.png -Class Enlightenment_Iconbox Icon pix/iconbox.png -Class Enlightenment_Pager Icon pix/pager.png +Class Eterm Icon icons/mon.png +Class XTerm Icon icons/mon.png +Class GnomeTerminal Icon icons/mon.png +Class Enlightenment_Dialog Icon icons/e.png +Class Enlightenment_Iconbox Icon icons/iconbox.png +Class Enlightenment_Pager Icon icons/pager.png # Misc. Name *screensaver Winop fade off:opacity 100:shadow off diff --git a/icons/Makefile.am b/icons/Makefile.am index 47c4e0c8..befde520 100644 --- a/icons/Makefile.am +++ b/icons/Makefile.am @@ -1,4 +1,4 @@ -iconsdir = $(pkgdatadir)/config/pix +iconsdir = $(pkgdatadir)/icons icons_DATA = \ default.png \ diff --git a/pix/Makefile.am b/pix/Makefile.am index f746bb05..f958e5ea 100644 --- a/pix/Makefile.am +++ b/pix/Makefile.am @@ -1,4 +1,4 @@ -pixdir = $(pkgdatadir)/config/pix +pixdir = $(pkgdatadir)/pix pix_DATA = \ about.png elogo48.png \ diff --git a/src/E.h b/src/E.h index a13ceb37..e96fc6c8 100644 --- a/src/E.h +++ b/src/E.h @@ -445,13 +445,20 @@ void EspawnCmd(const char *cmd); int Esystem(const char *cmd); /* config.c */ +#define FILE_TYPE_CONFIG 0 +#define FILE_TYPE_BACKGROUND 1 +#define FILE_TYPE_IMAGE 1 +#define FILE_TYPE_CURSOR 1 +#define FILE_TYPE_SOUND 1 +#define FILE_TYPE_MENU 2 +#define FILE_TYPE_ICON 3 void SkipTillEnd(FILE * ConfigFile); char *GetLine(char *s, int size, FILE * f); int ConfigParseline1(char *str, char *s2, char **p2, char **p3); void ConfigParseError(const char *where, const char *line); void ConfigAlertLoad(const char *txt); -char *FindFile(const char *file, const char *themepath); -char *ThemeFileFind(const char *file); +char *FindFile(const char *file, const char *themepath, int type); +char *ThemeFileFind(const char *file, int type); char *ConfigFileFind(const char *name, const char *themepath, int pp); int ConfigFileLoad(const char *name, const char *themepath, diff --git a/src/backgrounds.c b/src/backgrounds.c index 37001b16..b2372901 100644 --- a/src/backgrounds.c +++ b/src/backgrounds.c @@ -74,7 +74,7 @@ _BackgroundGetFile(char **ptr) if (isabspath(path)) goto done; - path = ThemeFileFind(path); + path = ThemeFileFind(path, FILE_TYPE_BACKGROUND); if (!path) goto done; Efree(*ptr); diff --git a/src/config.c b/src/config.c index a648b364..6dcf89a5 100644 --- a/src/config.c +++ b/src/config.c @@ -419,6 +419,9 @@ FindFilePath(const char *name, const char *path) char s[FILEPATH_LEN_MAX]; int len; +#if 0 + Eprintf("%s: %s (%s)\n", __func__, name, path); +#endif if (path) { len = Esnprintf(s, sizeof(s), "%s/%s", path, name); @@ -437,9 +440,21 @@ FindFilePath(const char *name, const char *path) return NULL; } +/* *INDENT-OFF* */ +static const struct { + const char *where, *subdir; +} fprm[] = { + { "utE", "config" }, + { "ute", NULL }, + { "UuE", "menus" }, + { "UE", "icons" } +}; +/* *INDENT-ON* */ + char * -FindFile(const char *file, const char *themepath) +FindFile(const char *file, const char *themepath, int type) { + const char *w, *f, *path; char s[FILEPATH_LEN_MAX]; char *p; @@ -451,34 +466,49 @@ FindFile(const char *file, const char *themepath) goto done; } - /* look in ~/.e16 first */ - p = FindFilePath(file, EDirUser()); - if (p) - goto done; - - if (themepath) + p = NULL; + for (w = fprm[type].where; *w; w++) { - /* look in theme dir */ - p = FindFilePath(file, themepath); - if (p) - goto done; - } + f = file; + if (*w <= 'Z') + { + /* Look in subdir */ + Esnprintf(s, sizeof(s), "%s/%s", fprm[type].subdir, file); + f = s; + } - /* look in system config dir */ - Esnprintf(s, sizeof(s), "%s/config", EDirRoot()); - p = FindFilePath(file, s); + switch (*w & 0xdf) + { + default: + continue; + case 'U': /* User config */ + path = EDirUser(); + break; + case 'E': /* e16 config */ + path = EDirRoot(); + break; + case 'T': /* Theme */ + path = themepath; + if (!path) + continue; + break; + } + p = FindFilePath(f, path); + if (p) + break; + } done: #if 0 - Eprintf("%s %d: %s (%s): %s\n", __func__, 0, file, themepath, p); + Eprintf("%s %d: %s (%s): %s\n", __func__, type, file, themepath, p); #endif return p; } char * -ThemeFileFind(const char *file) +ThemeFileFind(const char *file, int type) { - return FindFile(file, Mode.theme.path); + return FindFile(file, Mode.theme.path, type); } char * @@ -488,7 +518,7 @@ ConfigFileFind(const char *name, const char *themepath, int pp) char *fullname, *file, *ppfile; int i, err; - fullname = FindFile(name, themepath); + fullname = FindFile(name, themepath, FILE_TYPE_CONFIG); if (!fullname) return NULL; diff --git a/src/cursors.c b/src/cursors.c index 4a3db25d..7baa4204 100644 --- a/src/cursors.c +++ b/src/cursors.c @@ -150,7 +150,7 @@ ECursorRealize(ECursor * ec) if (ec->file) { - img = ThemeFileFind(ec->file); + img = ThemeFileFind(ec->file, FILE_TYPE_CURSOR); _EFREE(ec->file); /* Ok or not - we never need file again */ if (!img) goto done; diff --git a/src/iclass.c b/src/iclass.c index 91454a99..8a544755 100644 --- a/src/iclass.c +++ b/src/iclass.c @@ -160,7 +160,7 @@ ThemeImageLoad(const char *file) return im; } - f = ThemeFileFind(file); + f = ThemeFileFind(file, FILE_TYPE_IMAGE); if (f) { im = EImageLoad(f); @@ -259,7 +259,7 @@ ImagestateRealize(ImageState * is) if (!is->im_file) return; /* No file - quit */ /* not loaded, load and setup */ - is->real_file = ThemeFileFind(is->im_file); + is->real_file = ThemeFileFind(is->im_file, FILE_TYPE_IMAGE); } if (is->real_file) { diff --git a/src/icons.c b/src/icons.c index 4ec13715..161c56ff 100644 --- a/src/icons.c +++ b/src/icons.c @@ -208,7 +208,7 @@ IB_GetFallbackIcon(EWin * ewin, int size) ImageClass *ic; EImage *im; - im = ThemeImageLoad("pix/default.png"); + im = ThemeImageLoad("icons/default.png"); if (im) return im; diff --git a/src/menus-misc.c b/src/menus-misc.c index e56126a0..e55b1a44 100644 --- a/src/menus-misc.c +++ b/src/menus-misc.c @@ -256,16 +256,6 @@ ScanBackgroundMenu(void) menu_scan_recursive = 0; } -static char * -find_icon(const char *file) -{ - char s[FILEPATH_LEN_MAX]; - - Esnprintf(s, sizeof(s), "%s/icons", EDirUser()); - - return FindFile(file, s); -} - static void FillFlatFileMenu(Menu * m, const char *file) { @@ -324,7 +314,7 @@ FillFlatFileMenu(Menu * m, const char *file) parse(s, "%S%T%S%S", &txt, &icon, &act, ¶ms); if (icon) - icon = find_icon(icon); + icon = FindFile(icon, NULL, FILE_TYPE_ICON); if (icon) { Esnprintf(wd, sizeof(wd), "__FM.%s", icon); @@ -385,7 +375,7 @@ MenuCreateFromFlatFile(const char *name, Menu * parent, MenuStyle * ms, const char *file) { Menu *m = NULL; - char *ff, buf[4096]; + char *ff; static int calls = 0; if (calls > 32) @@ -395,18 +385,7 @@ MenuCreateFromFlatFile(const char *name, Menu * parent, MenuStyle * ms, if (!file) file = name; - if (isabspath(file)) - { - ff = FindFile(file, NULL); - } - else - { - /* Check menus subdir first */ - Esnprintf(buf, sizeof(buf), "menus/%s", file); - ff = FindFile(buf, NULL); - if (!ff) - ff = FindFile(file, NULL); - } + ff = FindFile(file, NULL, FILE_TYPE_MENU); if (!ff) goto done; diff --git a/src/sound.c b/src/sound.c index 25b11fd2..8173a891 100644 --- a/src/sound.c +++ b/src/sound.c @@ -202,7 +202,7 @@ SclassApply(SoundClass * sclass) { char *file; - file = FindFile(sclass->file, SOUND_THEME_PATH); + file = FindFile(sclass->file, SOUND_THEME_PATH, FILE_TYPE_SOUND); if (file) { sclass->sample = ops->SampleLoad(file);