Only look for localized versions of theme config files (not image, sound, etc.). Cleanups.

SVN revision: 15799
This commit is contained in:
Kim Woelders 2005-07-17 12:55:13 +00:00
parent 048a4164f1
commit 18227d6e5f
12 changed files with 110 additions and 139 deletions

20
src/E.h
View File

@ -794,6 +794,12 @@ typedef struct
Window pointer_grab_window;
} grabs;
struct
{
const char *lang;
char utf8_int; /* Use UTF-8 internally */
char utf8_loc; /* Locale is UTF-8 */
} locale;
struct
{
unsigned int numlock;
unsigned int scrollock;
@ -812,11 +818,6 @@ typedef struct
char doing_slide;
} place;
struct
{
char utf8_int; /* Use UTF-8 internally */
char utf8_loc; /* Locale is UTF-8 */
} text;
struct
{
char *path;
} theme;
@ -1102,8 +1103,9 @@ void CommsBroadcastToSlaveWMs(const char *s);
int ConfigSkipIfExists(FILE * fs, const char *name, int type);
char *GetLine(char *s, int size, FILE * f);
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 localized);
char *ThemeFileFind(const char *file, int localized);
char *ConfigFileFind(const char *name, const char *themepath,
int pp);
int ConfigFileLoad(const char *name, const char *themepath,
@ -1374,9 +1376,7 @@ char *pathtoexec(const char *file);
char *pathtofile(const char *file);
const char *FileExtension(const char *file);
char *field(char *s, int fieldno);
int fillfield(char *s, int fieldno, char *buf);
void fword(char *s, int num, char *wd);
int findLocalizedFile(char *fname);
/* finders.c */
EWin *EwinFindByPtr(const EWin * ewin);
@ -1883,5 +1883,3 @@ extern RealRoot RRoot;
extern VirtRoot VRoot;
extern EConf Conf;
extern EMode Mode;
#define FILEPATH_LEN_MAX 4096

View File

@ -78,7 +78,7 @@ BackgroundGetUniqueString(Background * bg)
{
char *f;
f = ThemeFileFind(bg->bg.file);
f = ThemeFileFind(bg->bg.file, 0);
if (f)
{
f1 = fileinode(f);
@ -91,7 +91,7 @@ BackgroundGetUniqueString(Background * bg)
{
char *f;
f = ThemeFileFind(bg->top.file);
f = ThemeFileFind(bg->top.file, 0);
if (f)
{
f4 = fileinode(f);
@ -242,7 +242,7 @@ BackgroundDelete(Background * bg)
/* And delete the actual image files */
if (bg->bg.file)
{
f = ThemeFileFind(bg->bg.file);
f = ThemeFileFind(bg->bg.file, 0);
if (f)
{
E_rm(f);
@ -251,7 +251,7 @@ BackgroundDelete(Background * bg)
}
if (bg->top.file)
{
f = ThemeFileFind(bg->top.file);
f = ThemeFileFind(bg->top.file, 0);
if (f)
{
E_rm(f);
@ -494,14 +494,14 @@ BackgroundApply(Background * bg, Window win, int setbg)
if (bg->bg.file && !bg->bg.im)
{
if (!bg->bg.real_file)
bg->bg.real_file = ThemeFileFind(bg->bg.file);
bg->bg.real_file = ThemeFileFind(bg->bg.file, 0);
bg->bg.im = ELoadImage(bg->bg.real_file);
}
if (bg->top.file && !bg->top.im)
{
if (!bg->top.real_file)
bg->top.real_file = ThemeFileFind(bg->top.file);
bg->top.real_file = ThemeFileFind(bg->top.file, 0);
bg->top.im = ELoadImage(bg->top.real_file);
}
@ -950,7 +950,7 @@ BackgroundsConfigLoad(FILE * fs)
/* check first if we can actually find the files */
if (bg1)
{
tmp = ThemeFileFind(bg1);
tmp = ThemeFileFind(bg1, 0);
if (!tmp)
{
ok = 0;
@ -962,7 +962,7 @@ BackgroundsConfigLoad(FILE * fs)
}
if (bg2)
{
tmp = ThemeFileFind(bg2);
tmp = ThemeFileFind(bg2, 0);
if (!tmp)
{
ok = 0;
@ -1148,10 +1148,10 @@ BackgroundsConfigSave(void)
fprintf(fs, "560 %d %d %d\n", r, g, b);
if ((bglist[i]->bg.file) && (!bglist[i]->bg.real_file))
bglist[i]->bg.real_file = ThemeFileFind(bglist[i]->bg.file);
bglist[i]->bg.real_file = ThemeFileFind(bglist[i]->bg.file, 0);
if ((bglist[i]->top.file) && (!bglist[i]->top.real_file))
bglist[i]->top.real_file = ThemeFileFind(bglist[i]->top.file);
bglist[i]->top.real_file = ThemeFileFind(bglist[i]->top.file, 0);
if ((bglist[i]->bg.file) && (bglist[i]->bg.real_file))
{

View File

@ -377,46 +377,95 @@ ConfigFileRead(FILE * fs)
return 0;
}
char *
FindFile(const char *file, const char *themepath)
static char *
FindFileLocalized(const char *name, const char *path, int localized)
{
char s[FILEPATH_LEN_MAX];
const char *lang;
char *p[4];
int i, len;
if (path)
len = Esnprintf(s, sizeof(s), "%s/%s", path, name);
else
len = Esnprintf(s, sizeof(s), "%s", name);
if (len <= 0)
return NULL;
lang = Mode.locale.lang;
if (!localized || !lang)
{
if (isfile(s))
return Estrdup(s);
else
return NULL;
}
if (len + 1 + strlen(lang) >= sizeof(s))
return NULL;
s[len] = '.';
strcpy(s + len + 1, lang);
p[0] = s + len + 1 + strlen(lang); /* .da_DK.UTF-8 */
p[1] = strchr(s + len + 1, '.'); /* .da_DK */
p[2] = strchr(s + len + 1, '_'); /* .da */
p[3] = s + len;
for (i = 0; i < 4; i++)
{
if (p[i] == NULL)
continue;
*p[i] = '\0';
if (isfile(s))
return Estrdup(s);
}
return NULL;
}
char *
FindFile(const char *file, const char *themepath, int localized)
{
char s[FILEPATH_LEN_MAX];
char *p;
/* if absolute path - and file exists - return it */
if (isabspath(file))
{
strcpy(s, file);
if (findLocalizedFile(s) || isfile(s))
return Estrdup(s);
p = FindFileLocalized(file, NULL, localized);
if (p)
return p;
}
/* look in ~/.e16 first */
Esnprintf(s, sizeof(s), "%s/%s", EDirUser(), file);
if (findLocalizedFile(s) || isfile(s))
return Estrdup(s);
p = FindFileLocalized(file, EDirUser(), localized);
if (p)
return p;
if (themepath)
{
/* look in theme dir */
Esnprintf(s, sizeof(s), "%s/%s", themepath, file);
if (findLocalizedFile(s) || isfile(s))
return Estrdup(s);
p = FindFileLocalized(file, themepath, localized);
if (p)
return p;
}
/* look in system config dir */
Esnprintf(s, sizeof(s), "%s/config/%s", EDirRoot(), file);
if (findLocalizedFile(s) || isfile(s))
return Estrdup(s);
Esnprintf(s, sizeof(s), "%s/config", EDirRoot());
p = FindFileLocalized(file, s, localized);
if (p)
return p;
/* not found.... NULL */
return NULL;
}
char *
ThemeFileFind(const char *file)
ThemeFileFind(const char *file, int localized)
{
return FindFile(file, Mode.theme.path);
return FindFile(file, Mode.theme.path, localized);
}
char *
@ -426,7 +475,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, 1);
if (!fullname)
return NULL;

View File

@ -54,7 +54,7 @@ ECursorCreate(const char *name, const char *image, int native_id, XColor * fg,
if (image)
{
img = FindFile(image, Mode.theme.path);
img = FindFile(image, Mode.theme.path, 0);
if (!img)
return NULL;

View File

@ -1060,7 +1060,7 @@ Imlib_Image *
ELoadImage(const char *file)
{
Imlib_Image *im;
char *f = NULL;
char *f;
if (!file)
return NULL;
@ -1071,7 +1071,7 @@ ELoadImage(const char *file)
return im;
}
f = ThemeFileFind(file);
f = ThemeFileFind(file, 0);
if (f)
{
im = imlib_load_image(f);

View File

@ -85,7 +85,7 @@ ExtInitWinMain(void)
{
Window w2, ww;
char *f, s[1024];
char s[1024];
Imlib_Image *im;
struct timeval tv;
int dd, x, y;
@ -123,14 +123,7 @@ ExtInitWinMain(void)
if (EventDebug(EDBUG_TYPE_SESSION))
Eprintf("ExtInitWinCreate - child %s\n", s);
f = ThemeFileFind(s);
im = NULL;
if (f)
{
im = imlib_load_image(f);
Efree(f);
}
im = ELoadImage(s);
if (im)
{
imlib_context_set_image(im);

View File

@ -649,25 +649,6 @@ field(char *s, int fieldno)
return NULL;
}
int
fillfield(char *s, int fieldno, char *buf)
{
if (!buf)
return 0;
buf[0] = 0;
fword(s, fieldno + 1, buf);
if (buf[0])
{
if ((!strcmp(buf, "NULL")) || (!strcmp(buf, "(null)")))
{
buf[0] = 0;
return 0;
}
return 1;
}
return 0;
}
int
canread(const char *s)
{
@ -832,40 +813,3 @@ pathtofile(const char *file)
}
return NULL;
}
int
findLocalizedFile(char *fname)
{
char *tmp, *lang, *p[3];
int i;
if (!(lang = setlocale(LC_MESSAGES, NULL)))
return 0;
tmp = Estrdup(fname);
lang = Estrdup(lang); /* lang may be in static space, thus it must
* * * be duplicated before we change it below */
p[0] = lang + strlen(lang);
p[1] = strchr(lang, '.');
p[2] = strchr(lang, '_');
for (i = 0; i < 3; i++)
{
if (p[i] == NULL)
continue;
*p[i] = '\0';
sprintf(fname, "%s.%s", tmp, lang);
if (isfile(fname))
{
free(tmp);
free(lang);
return 1;
}
}
strcpy(fname, tmp);
free(tmp);
free(lang);
return 0;
}

View File

@ -189,7 +189,7 @@ ImagestateRealize(ImageState * is)
/* not loaded, load and setup */
if (!is->real_file)
is->real_file = ThemeFileFind(is->im_file);
is->real_file = ThemeFileFind(is->im_file, 0);
is->im = ELoadImage(is->real_file);
imlib_context_set_image(is->im);
@ -1402,27 +1402,14 @@ ImageclassIpc(const char *params, Client * c __UNUSED__)
ic = ImageclassFind(param1, 0);
if (ic)
{
Imlib_Image *im = NULL;
if (ic->norm.normal->im_file)
ImagestateRealize(ic->norm.normal);
if (ic->norm.normal->im)
{
if (!ic->norm.normal->real_file)
ic->norm.normal->real_file =
ThemeFileFind(ic->norm.normal->im_file);
if (ic->norm.normal->real_file)
im = imlib_load_image(ic->norm.normal->real_file);
if (im)
{
imlib_context_set_image(im);
IpcPrintf("%i %i\n", imlib_image_get_width(),
imlib_image_get_height());
imlib_free_image();
}
else
IpcPrintf("Error: Image does not exist\n");
imlib_context_set_image(ic->norm.normal->im);
IpcPrintf("%i %i\n", imlib_image_get_width(),
imlib_image_get_height());
imlib_free_image();
}
else
IpcPrintf("Error: Image does not exist\n");
}
else
IpcPrintf("Error: Imageclass does not exist\n");

View File

@ -99,7 +99,7 @@ const char *
EstrInt2Enc(const char *str, int want_utf8)
{
#if HAVE_ICONV
if (Mode.text.utf8_int == want_utf8)
if (Mode.locale.utf8_int == want_utf8)
return str;
if (str == NULL)
@ -119,7 +119,7 @@ void
EstrInt2EncFree(const char *str, int want_utf8)
{
#if HAVE_ICONV
if (Mode.text.utf8_int == want_utf8)
if (Mode.locale.utf8_int == want_utf8)
return;
if (str)
@ -159,6 +159,7 @@ LangInit(void)
else
enc_int = enc_loc;
Mode.locale.lang = setlocale(LC_MESSAGES, NULL);
if (EventDebug(EDBUG_TYPE_VERBOSE))
{
Eprintf("Locale: %s\n", setlocale(LC_ALL, NULL));
@ -167,12 +168,12 @@ LangInit(void)
}
if (!strcasecmp(enc_loc, "utf8") || !strcasecmp(enc_loc, "utf-8"))
Mode.text.utf8_loc = 1;
Mode.locale.utf8_loc = 1;
if (!strcasecmp(enc_int, "utf8") || !strcasecmp(enc_int, "utf-8"))
Mode.text.utf8_int = 1;
Mode.locale.utf8_int = 1;
#if HAVE_ICONV
if (Mode.text.utf8_int)
if (Mode.locale.utf8_int)
{
iconv_cd_loc2int = iconv_open("UTF-8", enc_loc);
iconv_cd_int2loc = iconv_open(enc_loc, "UTF-8");

View File

@ -379,7 +379,7 @@ MenuCreateFromFlatFile(const char *name, Menu * parent, MenuStyle * ms,
return NULL;
calls++;
ff = FindFile(file, NULL);
ff = FindFile(file, NULL, 0);
if (!ff)
goto done;
@ -408,13 +408,12 @@ MenuCreateFromGnome(const char *name, Menu * parent, MenuStyle * ms,
Menu *m, *mm;
int i, num;
char **list, s[4096], ss[4096];
MenuItem *mi;
FILE *f;
char *lang, name_buf[20];
char name_buf[20];
if ((lang = setlocale(LC_MESSAGES, NULL)) != NULL)
Esnprintf(name_buf, sizeof(name_buf), "Name[%s]=", lang);
if (Mode.locale.lang)
Esnprintf(name_buf, sizeof(name_buf), "Name[%s]=", Mode.locale.lang);
else
name_buf[0] = '\0';

View File

@ -74,7 +74,7 @@ LoadWav(const char *file)
int bytes_per_frame, frames_read;
double in_rate;
find = FindFile(file, Mode.theme.path);
find = FindFile(file, Mode.theme.path, 0);
if (!find)
{
DialogOK(_("Error finding sound file"),

View File

@ -148,7 +148,7 @@ TextStateLoadFont(TextState * ts)
if ((ts->efont) || (ts->xfont) || (ts->xfontset))
return;
ts->need_utf8 = Mode.text.utf8_int;
ts->need_utf8 = Mode.locale.utf8_int;
/* Try FreeType */
{