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

View File

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

View File

@ -377,46 +377,95 @@ ConfigFileRead(FILE * fs)
return 0; return 0;
} }
char * static char *
FindFile(const char *file, const char *themepath) FindFileLocalized(const char *name, const char *path, int localized)
{ {
char s[FILEPATH_LEN_MAX]; 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 absolute path - and file exists - return it */
if (isabspath(file)) if (isabspath(file))
{ {
strcpy(s, file); p = FindFileLocalized(file, NULL, localized);
if (findLocalizedFile(s) || isfile(s)) if (p)
return Estrdup(s); return p;
} }
/* look in ~/.e16 first */ /* look in ~/.e16 first */
p = FindFileLocalized(file, EDirUser(), localized);
Esnprintf(s, sizeof(s), "%s/%s", EDirUser(), file); if (p)
if (findLocalizedFile(s) || isfile(s)) return p;
return Estrdup(s);
if (themepath) if (themepath)
{ {
/* look in theme dir */ /* look in theme dir */
Esnprintf(s, sizeof(s), "%s/%s", themepath, file); p = FindFileLocalized(file, themepath, localized);
if (findLocalizedFile(s) || isfile(s)) if (p)
return Estrdup(s); return p;
} }
/* look in system config dir */ /* look in system config dir */
Esnprintf(s, sizeof(s), "%s/config/%s", EDirRoot(), file); Esnprintf(s, sizeof(s), "%s/config", EDirRoot());
if (findLocalizedFile(s) || isfile(s)) p = FindFileLocalized(file, s, localized);
return Estrdup(s); if (p)
return p;
/* not found.... NULL */ /* not found.... NULL */
return NULL; return NULL;
} }
char * 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 * char *
@ -426,7 +475,7 @@ ConfigFileFind(const char *name, const char *themepath, int pp)
char *fullname, *file, *ppfile; char *fullname, *file, *ppfile;
int i, err; int i, err;
fullname = FindFile(name, themepath); fullname = FindFile(name, themepath, 1);
if (!fullname) if (!fullname)
return NULL; return NULL;

View File

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

View File

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

View File

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

View File

@ -649,25 +649,6 @@ field(char *s, int fieldno)
return NULL; 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 int
canread(const char *s) canread(const char *s)
{ {
@ -832,40 +813,3 @@ pathtofile(const char *file)
} }
return NULL; 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 */ /* not loaded, load and setup */
if (!is->real_file) 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); is->im = ELoadImage(is->real_file);
imlib_context_set_image(is->im); imlib_context_set_image(is->im);
@ -1402,27 +1402,14 @@ ImageclassIpc(const char *params, Client * c __UNUSED__)
ic = ImageclassFind(param1, 0); ic = ImageclassFind(param1, 0);
if (ic) if (ic)
{ {
Imlib_Image *im = NULL; ImagestateRealize(ic->norm.normal);
if (ic->norm.normal->im)
if (ic->norm.normal->im_file)
{ {
if (!ic->norm.normal->real_file) imlib_context_set_image(ic->norm.normal->im);
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(), IpcPrintf("%i %i\n", imlib_image_get_width(),
imlib_image_get_height()); imlib_image_get_height());
imlib_free_image(); imlib_free_image();
} }
else
IpcPrintf("Error: Image does not exist\n");
}
else
IpcPrintf("Error: Image does not exist\n");
} }
else else
IpcPrintf("Error: Imageclass does not exist\n"); IpcPrintf("Error: Imageclass does not exist\n");

View File

@ -99,7 +99,7 @@ const char *
EstrInt2Enc(const char *str, int want_utf8) EstrInt2Enc(const char *str, int want_utf8)
{ {
#if HAVE_ICONV #if HAVE_ICONV
if (Mode.text.utf8_int == want_utf8) if (Mode.locale.utf8_int == want_utf8)
return str; return str;
if (str == NULL) if (str == NULL)
@ -119,7 +119,7 @@ void
EstrInt2EncFree(const char *str, int want_utf8) EstrInt2EncFree(const char *str, int want_utf8)
{ {
#if HAVE_ICONV #if HAVE_ICONV
if (Mode.text.utf8_int == want_utf8) if (Mode.locale.utf8_int == want_utf8)
return; return;
if (str) if (str)
@ -159,6 +159,7 @@ LangInit(void)
else else
enc_int = enc_loc; enc_int = enc_loc;
Mode.locale.lang = setlocale(LC_MESSAGES, NULL);
if (EventDebug(EDBUG_TYPE_VERBOSE)) if (EventDebug(EDBUG_TYPE_VERBOSE))
{ {
Eprintf("Locale: %s\n", setlocale(LC_ALL, NULL)); Eprintf("Locale: %s\n", setlocale(LC_ALL, NULL));
@ -167,12 +168,12 @@ LangInit(void)
} }
if (!strcasecmp(enc_loc, "utf8") || !strcasecmp(enc_loc, "utf-8")) 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")) if (!strcasecmp(enc_int, "utf8") || !strcasecmp(enc_int, "utf-8"))
Mode.text.utf8_int = 1; Mode.locale.utf8_int = 1;
#if HAVE_ICONV #if HAVE_ICONV
if (Mode.text.utf8_int) if (Mode.locale.utf8_int)
{ {
iconv_cd_loc2int = iconv_open("UTF-8", enc_loc); iconv_cd_loc2int = iconv_open("UTF-8", enc_loc);
iconv_cd_int2loc = iconv_open(enc_loc, "UTF-8"); 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; return NULL;
calls++; calls++;
ff = FindFile(file, NULL); ff = FindFile(file, NULL, 0);
if (!ff) if (!ff)
goto done; goto done;
@ -408,13 +408,12 @@ MenuCreateFromGnome(const char *name, Menu * parent, MenuStyle * ms,
Menu *m, *mm; Menu *m, *mm;
int i, num; int i, num;
char **list, s[4096], ss[4096]; char **list, s[4096], ss[4096];
MenuItem *mi; MenuItem *mi;
FILE *f; FILE *f;
char *lang, name_buf[20]; char name_buf[20];
if ((lang = setlocale(LC_MESSAGES, NULL)) != NULL) if (Mode.locale.lang)
Esnprintf(name_buf, sizeof(name_buf), "Name[%s]=", lang); Esnprintf(name_buf, sizeof(name_buf), "Name[%s]=", Mode.locale.lang);
else else
name_buf[0] = '\0'; name_buf[0] = '\0';

View File

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

View File

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