1999-10-04 15:06:00 -07:00
|
|
|
/*
|
2000-01-06 00:13:30 -08:00
|
|
|
* Copyright (C) 2000 Carsten Haitzler, Geoff Harrison and various contributors
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies of the Software, its documentation and marketing & publicity
|
|
|
|
* materials, and acknowledgment shall be given in the documentation, materials
|
|
|
|
* and software packages that this Software was used.
|
2000-04-05 16:22:56 -07:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
1999-08-17 15:56:46 -07:00
|
|
|
#include "E.h"
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifdef __EMX__
|
|
|
|
#include <process.h>
|
|
|
|
extern char *__XOS2RedirRoot(const char *);
|
|
|
|
|
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
char *
|
|
|
|
append_merge_dir(char *dir, char ***list, int *count)
|
|
|
|
{
|
2000-02-20 10:16:48 -08:00
|
|
|
char s[FILEPATH_LEN_MAX], ss[FILEPATH_LEN_MAX], **str =
|
2000-06-04 12:45:55 -07:00
|
|
|
NULL, *def = NULL;
|
1999-08-17 15:56:46 -07:00
|
|
|
char already, *tmp, *tmp2, ok;
|
|
|
|
int i, j, num;
|
|
|
|
|
|
|
|
str = ls(dir, &num);
|
|
|
|
if (str)
|
2000-06-04 12:45:55 -07:00
|
|
|
{
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
already = 0;
|
|
|
|
for (j = 0; (j < (*count)) && (!already); j++)
|
|
|
|
{
|
|
|
|
tmp = fileof((*list)[j]);
|
|
|
|
tmp2 = fileof(str[i]);
|
|
|
|
if ((tmp != NULL) && (tmp2 != NULL) && (!strcmp(tmp, tmp2)))
|
|
|
|
already = 1;
|
|
|
|
if (tmp)
|
|
|
|
Efree(tmp);
|
|
|
|
if (tmp2)
|
|
|
|
Efree(tmp2);
|
|
|
|
}
|
|
|
|
if (!already)
|
|
|
|
{
|
|
|
|
if (!strcmp(str[i], "DEFAULT"))
|
|
|
|
{
|
|
|
|
Esnprintf(ss, sizeof(ss), "%s/%s", dir, str[i]);
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
2000-06-04 12:45:55 -07:00
|
|
|
if (readlink(ss, s, sizeof(s)) > 0)
|
|
|
|
{
|
|
|
|
if (s[0] == '/')
|
|
|
|
def = duplicate(s);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Esnprintf(s, sizeof(s), "%s/%s", dir, s);
|
|
|
|
def = duplicate(s);
|
|
|
|
}
|
|
|
|
}
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
2000-06-04 12:45:55 -07:00
|
|
|
if (isdir(ss))
|
|
|
|
{
|
|
|
|
def = duplicate(ss);
|
|
|
|
(*count)++;
|
|
|
|
(*list) = Erealloc(*list, (*count) * sizeof(char *));
|
1999-10-18 10:42:01 -07:00
|
|
|
|
2000-06-04 12:45:55 -07:00
|
|
|
(*list)[(*count) - 1] = duplicate(ss);
|
|
|
|
}
|
1999-10-18 10:42:01 -07:00
|
|
|
#endif
|
2000-06-04 12:45:55 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok = 0;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(s, sizeof(s), "%s/%s", dir, str[i]);
|
|
|
|
if ((isdir(s)) && (SanitiseThemeDir(s)))
|
|
|
|
ok = 1;
|
|
|
|
else if ((isfile(s)) && (FileExtension(s))
|
|
|
|
&& (!strcmp(FileExtension(s), "etheme")))
|
|
|
|
ok = 1;
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
(*count)++;
|
|
|
|
(*list) = Erealloc(*list, (*count) * sizeof(char *));
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2000-06-04 12:45:55 -07:00
|
|
|
(*list)[(*count) - 1] = duplicate(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
freestrlist(str, num);
|
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
char **
|
|
|
|
ListThemes(int *number)
|
|
|
|
{
|
1999-12-06 09:12:20 -08:00
|
|
|
char s[FILEPATH_LEN_MAX], **list = NULL, *def = NULL, *def2 =
|
|
|
|
|
2000-06-04 12:45:55 -07:00
|
|
|
NULL;
|
1999-08-17 15:56:46 -07:00
|
|
|
int count = 0;
|
|
|
|
|
1999-08-24 12:00:07 -07:00
|
|
|
Esnprintf(s, sizeof(s), "%s/themes", UserEDir());
|
1999-08-17 15:56:46 -07:00
|
|
|
def = append_merge_dir(s, &list, &count);
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
1999-08-17 15:56:46 -07:00
|
|
|
Esnprintf(s, sizeof(s), "%s/themes", ENLIGHTENMENT_ROOT);
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
|
|
|
Esnprintf(s, sizeof(s), "%s/themes", __XOS2RedirRoot(ENLIGHTENMENT_ROOT));
|
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
def2 = append_merge_dir(s, &list, &count);
|
|
|
|
|
|
|
|
if ((def) && (def2))
|
2000-06-04 12:45:55 -07:00
|
|
|
{
|
|
|
|
Efree(def2);
|
|
|
|
def2 = NULL;
|
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
else if ((!def) && (def2))
|
|
|
|
def = def2;
|
|
|
|
else if ((!def) && (!def2))
|
|
|
|
fprintf(stderr, "errrrrrrrr no default theme?\n");
|
|
|
|
*number = count;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
GetDefaultTheme(void)
|
|
|
|
{
|
1999-08-24 12:00:07 -07:00
|
|
|
char s[FILEPATH_LEN_MAX], ss[FILEPATH_LEN_MAX];
|
1999-08-17 15:56:46 -07:00
|
|
|
char *def = NULL;
|
|
|
|
int count;
|
|
|
|
|
1999-08-24 12:00:07 -07:00
|
|
|
Esnprintf(ss, sizeof(ss), "%s/themes/DEFAULT", UserEDir());
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
1999-08-17 15:56:46 -07:00
|
|
|
count = readlink(ss, s, sizeof(s));
|
|
|
|
if ((exists(ss)) && (count > 0))
|
2000-06-04 12:45:55 -07:00
|
|
|
{
|
|
|
|
s[count] = 0;
|
|
|
|
if (s[0] == '/')
|
|
|
|
def = duplicate(s);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Esnprintf(ss, sizeof(ss), "%s/themes/%s", UserEDir(), s);
|
|
|
|
def = duplicate(ss);
|
|
|
|
}
|
|
|
|
}
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
|
|
|
if (isdir(ss))
|
|
|
|
def = duplicate(ss);
|
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
if (!def)
|
2000-06-04 12:45:55 -07:00
|
|
|
{
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(ss, sizeof(ss), "%s/themes/DEFAULT", ENLIGHTENMENT_ROOT);
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(ss, sizeof(ss), "%s/themes/DEFAULT",
|
|
|
|
__XOS2RedirRoot(ENLIGHTENMENT_ROOT));
|
1999-10-18 10:42:01 -07:00
|
|
|
#endif
|
|
|
|
#ifndef __EMX__
|
2000-06-04 12:45:55 -07:00
|
|
|
count = readlink(ss, s, sizeof(s));
|
|
|
|
if ((exists(ss)) && (count > 0))
|
|
|
|
{
|
|
|
|
s[count] = 0;
|
|
|
|
if (s[0] == '/')
|
|
|
|
def = duplicate(s);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Esnprintf(ss, sizeof(ss), "%s/themes/%s", ENLIGHTENMENT_ROOT, s);
|
|
|
|
def = duplicate(ss);
|
|
|
|
}
|
|
|
|
}
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
2000-06-04 12:45:55 -07:00
|
|
|
if (isdir(ss))
|
|
|
|
def = duplicate(ss);
|
1999-10-18 10:42:01 -07:00
|
|
|
#endif
|
2000-06-04 12:45:55 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetDefaultTheme(char *theme)
|
|
|
|
{
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
|
|
|
/* os2 has no symlink,
|
|
|
|
* but it doesn't matter since we have ~/.enlightenment/user_theme.cfg
|
|
|
|
*/
|
1999-08-24 12:00:07 -07:00
|
|
|
char ss[FILEPATH_LEN_MAX];
|
1999-08-17 15:56:46 -07:00
|
|
|
|
1999-08-24 12:00:07 -07:00
|
|
|
Esnprintf(ss, sizeof(ss), "%s/themes/DEFAULT", UserEDir());
|
1999-08-17 15:56:46 -07:00
|
|
|
if (exists(ss))
|
|
|
|
rm(ss);
|
|
|
|
if (theme)
|
|
|
|
symlink(theme, ss);
|
1999-10-18 10:42:01 -07:00
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
ExtractTheme(char *theme)
|
|
|
|
{
|
|
|
|
char s[FILEPATH_LEN_MAX];
|
|
|
|
char th[FILEPATH_LEN_MAX];
|
|
|
|
FILE *f;
|
|
|
|
unsigned char buf[320];
|
|
|
|
|
|
|
|
EDBUG(7, "ExtractTheme");
|
|
|
|
mustdel = 0;
|
|
|
|
/* its a directory - just use it "as is" */
|
|
|
|
if (isdir(theme))
|
2000-06-04 12:45:55 -07:00
|
|
|
{
|
|
|
|
if (SanitiseThemeDir(theme))
|
|
|
|
{
|
|
|
|
EDBUG_RETURN(duplicate(theme));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EDBUG_RETURN(NULL);
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
/* its a file - check its type */
|
|
|
|
if (isfile(theme))
|
2000-06-04 12:45:55 -07:00
|
|
|
{
|
|
|
|
f = fopen(theme, "r");
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
char *themename;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2000-06-04 12:45:55 -07:00
|
|
|
fread(buf, 1, 320, f);
|
|
|
|
fclose(f);
|
|
|
|
/* make the temp dir */
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2000-06-04 12:45:55 -07:00
|
|
|
themename = fileof(theme);
|
|
|
|
Esnprintf(th, sizeof(th), "%s/themes/%s", UserEDir(), themename);
|
|
|
|
Efree(themename);
|
|
|
|
md(th);
|
|
|
|
/* check magic numbers */
|
|
|
|
if ((buf[0] == 31) && (buf[1] == 139))
|
|
|
|
{
|
|
|
|
/*gzipped tarball */
|
|
|
|
Esnprintf(s, sizeof(s), "gzip -d -c < %s | (cd %s ; tar -xf -)",
|
|
|
|
theme, th);
|
|
|
|
}
|
|
|
|
else if ((buf[257] == 'u') && (buf[258] == 's') && (buf[259] == 't')
|
|
|
|
&& (buf[260] == 'a') && (buf[261] == 'r'))
|
|
|
|
{
|
|
|
|
/*vanilla tarball */
|
|
|
|
Esnprintf(s, sizeof(s), "(cd %s ; tar -xf %s)", th, theme);
|
|
|
|
}
|
|
|
|
/* exec the untar if tarred */
|
|
|
|
system(s);
|
|
|
|
/* we made a temp dir - flag for deletion */
|
|
|
|
if (SanitiseThemeDir(th))
|
|
|
|
{
|
|
|
|
EDBUG_RETURN(duplicate(th));
|
|
|
|
}
|
|
|
|
else if (mustdel)
|
|
|
|
{
|
|
|
|
char sss[FILEPATH_LEN_MAX];
|
1999-08-17 15:56:46 -07:00
|
|
|
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(sss, sizeof(sss), "/bin/rm -rf %s", themepath);
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(sss, sizeof(sss), "rm.exe -rf %s", themepath);
|
1999-10-18 10:42:01 -07:00
|
|
|
#endif
|
2000-06-04 12:45:55 -07:00
|
|
|
system(sss);
|
|
|
|
mustdel = 0;
|
|
|
|
EDBUG_RETURN(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
EDBUG_RETURN(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
FindTheme(char *theme)
|
|
|
|
{
|
|
|
|
char s[FILEPATH_LEN_MAX];
|
1999-08-24 12:00:07 -07:00
|
|
|
char *ret = NULL;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
EDBUG(6, "FindTheme");
|
1999-12-21 00:09:27 -08:00
|
|
|
badreason = _("Unknown\n");
|
1999-08-17 15:56:46 -07:00
|
|
|
if (!theme[0])
|
2000-06-04 12:45:55 -07:00
|
|
|
{
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(s, sizeof(s), "%s/themes/DEFAULT", ENLIGHTENMENT_ROOT);
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(s, sizeof(s), "%s/themes/DEFAULT",
|
|
|
|
__XOS2RedirRoot(ENLIGHTENMENT_ROOT));
|
1999-10-18 10:42:01 -07:00
|
|
|
#endif
|
2000-06-04 12:45:55 -07:00
|
|
|
EDBUG_RETURN(duplicate(s));
|
|
|
|
}
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
1999-08-17 15:56:46 -07:00
|
|
|
if (theme[0] == '/')
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
|
|
|
if (_fnisabs(theme))
|
|
|
|
#endif
|
1999-08-17 15:56:46 -07:00
|
|
|
ret = ExtractTheme(theme);
|
|
|
|
if (!ret)
|
2000-06-04 12:45:55 -07:00
|
|
|
{
|
|
|
|
Esnprintf(s, sizeof(s), "%s/themes/%s", UserEDir(), theme);
|
|
|
|
if (exists(s))
|
|
|
|
ret = ExtractTheme(s);
|
|
|
|
else
|
|
|
|
badreason = _("Theme file/directory does not exist\n");
|
|
|
|
if (!ret)
|
|
|
|
{
|
1999-10-18 10:42:01 -07:00
|
|
|
#ifndef __EMX__
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(s, sizeof(s), "%s/themes/%s", ENLIGHTENMENT_ROOT, theme);
|
1999-10-18 10:42:01 -07:00
|
|
|
#else
|
2000-06-04 12:45:55 -07:00
|
|
|
Esnprintf(s, sizeof(s), "%s/themes/%s",
|
|
|
|
__XOS2RedirRoot(ENLIGHTENMENT_ROOT), theme);
|
1999-10-18 10:42:01 -07:00
|
|
|
#endif
|
2000-06-04 12:45:55 -07:00
|
|
|
if (exists(s))
|
|
|
|
ret = ExtractTheme(s);
|
|
|
|
else
|
|
|
|
badreason = _("Theme file/directory does not exist\n");
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
ret = GetDefaultTheme();
|
|
|
|
badtheme = duplicate(theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
EDBUG_RETURN(ret);
|
|
|
|
}
|
1999-10-03 09:24:00 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
BadThemeDialog(void)
|
|
|
|
{
|
|
|
|
char s[1024];
|
|
|
|
|
|
|
|
if (!badtheme)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Esnprintf(s, sizeof(s),
|
2000-06-04 12:45:55 -07:00
|
|
|
_("The theme:\n" "%s\n"
|
|
|
|
"Is a badly formed theme package and is thus not being used.\n"
|
|
|
|
"Enlightenment has fallen back to using the DEFAULT theme.\n"
|
|
|
|
"\n" "The reason this theme is bad is:\n" "%s"), badtheme,
|
|
|
|
badreason);
|
1999-12-21 00:09:27 -08:00
|
|
|
DIALOG_OK(_("Bad Theme"), s);
|
1999-10-03 09:24:00 -07:00
|
|
|
}
|