20 name = strdup(
"default");
35 const char *error = NULL;
37 const char *d = strrchr(FileName,
'/');
40 const char *n = strchr(FileName,
'-');
43 if (!strchr(++n,
'-')) {
44 const char *e = strchr(n,
'.');
45 if (e && strcmp(e,
".theme") == 0) {
50 name = strndup(n, e - n);
54 error =
"missing theme name";
57 error =
"invalid extension";
60 error =
"too many '-'";
63 error =
"missing skin name";
66 error =
"missing '-'";
71 esyslog(
"ERROR: invalid theme file name (%s): '%s'", error, FileName);
88 if (!OnlyDescriptions)
89 isyslog(
"loading %s", FileName);
90 FILE *f = fopen(FileName,
"r");
95 const char *error = NULL;
97 while ((s = ReadLine.
Read(f)) != NULL) {
99 char *p = strchr(s,
'#');
105 char *v = strchr(s,
'=');
110 if (strstr(n,
"Description") == n) {
112 char *l = strchr(n,
'.');
120 error =
"invalid language code";
122 else if (!OnlyDescriptions) {
128 tColor c = strtoul(v, &p, 16);
132 error =
"invalid color value";
137 error =
"unknown color name";
144 error =
"missing value";
152 esyslog(
"ERROR: error in %s, line %d%s%s", FileName, line, error ?
": " :
"", error ? error :
"");
225 for (
int i = 0; i < numThemes; i++) {
242 if (themesDirectory) {
245 while ((e = d.
Next()) != NULL) {
246 if (strstr(e->d_name, SkinName) == e->d_name && e->d_name[strlen(SkinName)] ==
'-') {
249 if (Theme.
Load(*FileName,
true)) {
250 if (
char **NewBuffer = (
char **)realloc(names, (numThemes + 1) *
sizeof(
char *))) {
252 names[numThemes] = strdup(Theme.
Name());
255 esyslog(
"ERROR: out of memory");
258 if (
char **NewBuffer = (
char **)realloc(fileNames, (numThemes + 1) *
sizeof(
char *))) {
259 fileNames = NewBuffer;
260 fileNames[numThemes] = strdup(*FileName);
263 esyslog(
"ERROR: out of memory");
266 if (
char **NewBuffer = (
char **)realloc(
descriptions, (numThemes + 1) *
sizeof(
char *))) {
271 esyslog(
"ERROR: out of memory");
278 return numThemes > 0;
286 for (
int i = 0; i < numThemes; i++) {
297 free(themesDirectory);
298 themesDirectory = strdup(ThemesDirectory);
305 if (access(FileName, F_OK) == 0)
306 Theme->
Load(FileName);
312 if (access(FileName, F_OK) != 0)
313 Theme->
Save(FileName);
struct dirent * Next(void)
static void SetThemesDirectory(const char *ThemesDirectory)
int I18nCurrentLanguage(void)
Returns the index of the current language.
cTheme(void)
Creates a new theme class.
bool Load(const char *SkinName)
static cString sprintf(const char *fmt,...) __attribute__((format(printf
int GetThemeIndex(const char *Description)
static void Save(const char *SkinName, cTheme *Theme)
bool Save(const char *FileName)
Saves the theme data to the given file.
bool FileNameOk(const char *FileName, bool SetName=false)
const char * Description(void)
Returns a user visible, single line description of this theme.
bool Load(const char *FileName, bool OnlyDescriptions=false)
Loads the theme data from the given file.
static char * themesDirectory
const char * I18nLanguageCode(int Language)
Returns the three letter language code of the given Language (which is an index as returned by I18nCu...
int AddColor(const char *Name, tColor Color)
Adds a color with the given Name to this theme, initializes it with Color and returns an index into t...
const cStringList * I18nLanguages(void)
Returns the list of available languages.
tColor colorValues[MaxThemeColors]
char * colorNames[MaxThemeColors]
int I18nLanguageIndex(const char *Code)
Returns the index of the language with the given three letter language Code.
tColor Color(int Subject)
Returns the color for the given Subject.