3 * Displays and customizes the iconbar.
5 * Copyright (c) 1996-2012 by the citadel.org team
7 * This program is open source software. You can redistribute it and/or
8 * modify it under the terms of the GNU General Public License, version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <sys/types.h>
27 #include "webserver.h"
29 HashList *AvailableThemes = NULL;
31 const StrBuf *DefaultTheme = NULL;
32 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) {
51 if ((WCC != NULL) && (WCC->IconTheme != NULL)) {
52 StrBufAppendTemplate(Target, TP, WCC->IconTheme, 0);
55 StrBufAppendTemplate(Target, TP, DefaultTheme, 0);
60 int LoadThemeDir(const char *DirName) {
64 struct dirent *filedir_entry;
68 filedir = opendir(DirName);
69 if (filedir == NULL) {
73 d = (struct dirent *) malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
78 while ((readdir_r(filedir, d, &filedir_entry) == 0) && (filedir_entry != NULL)) {
79 #ifdef _DIRENT_HAVE_D_NAMELEN
80 d_namelen = filedir_entry->d_namlen;
81 d_type = filedir_entry->d_type;
90 #define IFTODT(mode) (((mode) & 0170000) >> 12)
91 #define DTTOIF(dirtype) ((dirtype) << 12)
93 d_namelen = strlen(filedir_entry->d_name);
96 if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~')
97 continue; /* Ignore backup files... */
99 if ((d_namelen == 1) && (filedir_entry->d_name[0] == '.'))
102 if ((d_namelen == 2) && (filedir_entry->d_name[0] == '.') && (filedir_entry->d_name[1] == '.'))
105 if (d_type == DT_UNKNOWN) {
108 snprintf(path, PATH_MAX, "%s/%s", DirName, filedir_entry->d_name);
109 if (stat(path, &s) == 0) {
110 d_type = IFTODT(s.st_mode);
115 case DT_LNK: /* TODO: check whether its a file or a directory */
117 /* Skip directories we are not interested in... */
118 if ((strcmp(filedir_entry->d_name, ".svn") == 0) || (strcmp(filedir_entry->d_name, "t") == 0))
121 Dir = NewStrBufPlain(filedir_entry->d_name, d_namelen);
122 if (DefaultTheme == NULL)
124 Put(AvailableThemes, SKEY(Dir), Dir, HFreeStrBuf);
139 HashList *GetValidThemeHash(StrBuf * Target, WCTemplputParams * TP) {
140 return AvailableThemes;
143 void ServerStartModule_ICONTHEME(void) {
144 AvailableThemes = NewHash(1, NULL);
147 void InitModule_ICONTHEME(void) {
148 StrBuf *Themes = NewStrBufPlain(static_dirs[0], -1);
150 StrBufAppendBufPlain(Themes, HKEY("/"), 0);
151 StrBufAppendBufPlain(Themes, HKEY("webcit_icons"), 0);
152 LoadThemeDir(ChrPtr(Themes));
155 RegisterPreference("icontheme", _("Icon Theme"), PRF_STRING, LoadIconthemeSettings);
156 RegisterNamespace("ICONTHEME", 0, 0, tmplput_icontheme, NULL, CTX_NONE);
158 RegisterIterator("PREF:VALID:THEME", 0, NULL, GetValidThemeHash, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG);
161 void ServerShutdownModule_ICONTHEME(void) {
162 DeleteHash(&AvailableThemes);
165 void SessionDestroyModule_ICONTHEME(wcsession * sess) {
166 FreeStrBuf(&sess->IconTheme);