Centralise file loading, based on file type.

Change install paths:
- menus: <datadir>/config/menus -> <datadir>/menus
- icons: <datadir>/config/pix   -> <datadir>/icons
- pix:   <datadir>/config/pix   -> <datadir>/pix

SVN revision: 47695
This commit is contained in:
Kim Woelders 2010-04-02 15:27:58 +00:00
parent 60054a9bdc
commit 29a5b4489d
12 changed files with 76 additions and 60 deletions

View File

@ -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 \

View File

@ -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

View File

@ -1,4 +1,4 @@
iconsdir = $(pkgdatadir)/config/pix
iconsdir = $(pkgdatadir)/icons
icons_DATA = \
default.png \

View File

@ -1,4 +1,4 @@
pixdir = $(pkgdatadir)/config/pix
pixdir = $(pkgdatadir)/pix
pix_DATA = \
about.png elogo48.png \

11
src/E.h
View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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)
{

View File

@ -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;

View File

@ -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, &params);
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;

View File

@ -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);