2 * Displays and customizes the iconbar.
4 * Copyright (c) 1996-2012 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <sys/types.h>
26 #include "webserver.h"
28 HashList *AvailableThemes = NULL;
30 const StrBuf *DefaultTheme = NULL;
31 void LoadIconthemeSettings(StrBuf *icontheme, long lvalue)
37 if (GetHash(AvailableThemes, SKEY(icontheme), &vTheme))
38 theme = (StrBuf*)vTheme;
42 if (WCC->IconTheme != NULL)
43 StrBufPlain(WCC->IconTheme, SKEY(theme));
45 WCC->IconTheme = NewStrBufDup(theme);
49 void tmplput_icontheme(StrBuf *Target, WCTemplputParams *TP)
53 (WCC->IconTheme != NULL))
55 StrBufAppendTemplate(Target, TP, WCC->IconTheme, 0);
59 StrBufAppendTemplate(Target, TP, DefaultTheme, 0);
64 int LoadThemeDir(const char *DirName)
69 struct dirent *filedir_entry;
73 filedir = opendir (DirName);
74 if (filedir == NULL) {
78 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
83 while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
84 (filedir_entry != NULL))
86 #ifdef _DIRENT_HAVE_D_NAMELEN
87 d_namelen = filedir_entry->d_namlen;
88 d_type = filedir_entry->d_type;
97 #define IFTODT(mode) (((mode) & 0170000) >> 12)
98 #define DTTOIF(dirtype) ((dirtype) << 12)
100 d_namelen = strlen(filedir_entry->d_name);
103 if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~')
104 continue; /* Ignore backup files... */
106 if ((d_namelen == 1) &&
107 (filedir_entry->d_name[0] == '.'))
110 if ((d_namelen == 2) &&
111 (filedir_entry->d_name[0] == '.') &&
112 (filedir_entry->d_name[1] == '.'))
115 if (d_type == DT_UNKNOWN) {
118 snprintf(path, PATH_MAX, "%s/%s",
119 DirName, filedir_entry->d_name);
120 if (stat(path, &s) == 0) {
121 d_type = IFTODT(s.st_mode);
127 case DT_LNK: /* TODO: check whether its a file or a directory */
129 /* Skip directories we are not interested in... */
130 if ((strcmp(filedir_entry->d_name, ".svn") == 0) ||
131 (strcmp(filedir_entry->d_name, "t") == 0))
134 Dir = NewStrBufPlain (filedir_entry->d_name, d_namelen);
135 if (DefaultTheme == NULL)
137 Put(AvailableThemes, SKEY(Dir), Dir, HFreeStrBuf);
152 HashList *GetValidThemeHash(StrBuf *Target, WCTemplputParams *TP)
154 return AvailableThemes;
157 ServerStartModule_ICONTHEME
160 AvailableThemes = NewHash(1, NULL);
166 StrBuf *Themes = NewStrBufPlain(static_dirs[0], -1);
168 StrBufAppendBufPlain(Themes, HKEY("/"), 0);
169 StrBufAppendBufPlain(Themes, HKEY("webcit_icons"), 0);
170 LoadThemeDir(ChrPtr(Themes));
173 RegisterPreference("icontheme", _("Icon Theme"), PRF_STRING, LoadIconthemeSettings);
174 RegisterNamespace("ICONTHEME", 0, 0, tmplput_icontheme, NULL, CTX_NONE);
176 RegisterIterator("PREF:VALID:THEME", 0, NULL,
177 GetValidThemeHash, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
181 ServerShutdownModule_ICONTHEME
184 DeleteHash(&AvailableThemes);
188 SessionDestroyModule_ICONTHEME
191 FreeStrBuf(&sess->IconTheme);