From 672ba402eab62d1d1aa000eaf7e2e714c0f5f546 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Mon, 20 Aug 2012 21:39:29 +0200 Subject: [PATCH] ICONTHEME: add a way to store a selected icontheme in the users preferences. - add the 'icontheme' setting - crawl all icon themes, remember it. - check which theme was selected (if) or choose a default theme. - add template token ICONTHEME to output the prefered icontheme or the default - add iterator PREF:VALID:THEME to output a list of available icon themes - add selector to the users preferences to choose the available icontheme. --- webcit/Makefile.in | 4 +- webcit/icontheme.c | 193 ++++++++++++++++++ webcit/static/t/prefs/box.html | 9 + .../t/prefs/section_icontheme_select.html | 1 + webcit/webcit.h | 2 + 5 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 webcit/icontheme.c create mode 100644 webcit/static/t/prefs/section_icontheme_select.html diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 8f671a23e..50098d9fb 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -59,7 +59,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \ useredit.o vcard_edit.o preferences.o html2html.o listsub.o roomchat.o \ graphics.o netconf.o siteconfig.o subst.o bbsview_renderer.o \ calendar.o calendar_tools.o calendar_view.o tasks.o event.o smtpqueue.o \ - availability.o iconbar.o crypto.o inetconf.o notes.o wiki.o \ + availability.o iconbar.o icontheme.o crypto.o inetconf.o notes.o wiki.o \ dav_main.o dav_get.o dav_propfind.o dav_report.o fmt_date.o \ dav_options.o autocompletion.o gettext.o tabs.o sieve.o sitemap.o \ dav_delete.o dav_put.o http_datestring.o setup_wizard.o \ @@ -76,7 +76,7 @@ webcit: webserver.o context_loop.o ical_dezonify.o \ useredit.o locate_host.o siteconfig.o subst.o vcard_edit.o roomchat.o \ graphics.o netconf.o preferences.o html2html.o openid.o bbsview_renderer.o \ summary.o calendar.o calendar_tools.o calendar_view.o tasks.o event.o wiki.o \ - availability.o ical_dezonify.o iconbar.o crypto.o inetconf.o notes.o \ + availability.o ical_dezonify.o iconbar.o icontheme.o crypto.o inetconf.o notes.o \ dav_main.o dav_get.o dav_propfind.o dav_report.o dav_delete.o \ dav_options.o autocompletion.o tabs.o smtpqueue.o sieve.o sitemap.o \ dav_put.o http_datestring.o setup_wizard.o fmt_date.o modules_init.o \ diff --git a/webcit/icontheme.c b/webcit/icontheme.c new file mode 100644 index 000000000..d8c9984fb --- /dev/null +++ b/webcit/icontheme.c @@ -0,0 +1,193 @@ +/* + * Displays and customizes the iconbar. + * + * Copyright (c) 1996-2012 by the citadel.org team + * + * This program is open source software. You can redistribute it and/or + * modify it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "webcit.h" +#include "webserver.h" + +HashList *AvailableThemes = NULL; + +const StrBuf *DefaultTheme = NULL; +void LoadIconthemeSettings(StrBuf *icontheme, long lvalue) +{ + wcsession *WCC = WC; + void *vTheme; + const StrBuf *theme; + + if (GetHash(AvailableThemes, SKEY(icontheme), &vTheme)) + theme = (StrBuf*)vTheme; + else + theme = DefaultTheme; + + if (WCC->IconTheme != NULL) + StrBufPlain(WCC->IconTheme, SKEY(theme)); + else + WCC->IconTheme = NewStrBufDup(theme); +} + + +void tmplput_icontheme(StrBuf *Target, WCTemplputParams *TP) +{ + wcsession *WCC = WC; + if ( (WCC != NULL) && + (WCC->IconTheme != NULL)) + { + StrBufAppendTemplate(Target, TP, WCC->IconTheme, 0); + } + else + { + StrBufAppendTemplate(Target, TP, DefaultTheme, 0); + } +} + + +int LoadThemeDir(const char *DirName) +{ + StrBuf *Dir = NULL; + DIR *filedir = NULL; + struct dirent *d; + struct dirent *filedir_entry; + int d_type = 0; + int d_namelen; + + filedir = opendir (DirName); + if (filedir == NULL) { + return 0; + } + + d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1); + if (d == NULL) { + return 0; + } + + while ((readdir_r(filedir, d, &filedir_entry) == 0) && + (filedir_entry != NULL)) + { +#ifdef _DIRENT_HAVE_D_NAMELEN + d_namelen = filedir_entry->d_namelen; + d_type = filedir_entry->d_type; +#else + +#ifndef DT_UNKNOWN +#define DT_UNKNOWN 0 +#define DT_DIR 4 +#define DT_REG 8 +#define DT_LNK 10 + +#define IFTODT(mode) (((mode) & 0170000) >> 12) +#define DTTOIF(dirtype) ((dirtype) << 12) +#endif + d_namelen = strlen(filedir_entry->d_name); + d_type = DT_UNKNOWN; +#endif + if ((d_namelen > 1) && filedir_entry->d_name[d_namelen - 1] == '~') + continue; /* Ignore backup files... */ + + if ((d_namelen == 1) && + (filedir_entry->d_name[0] == '.')) + continue; + + if ((d_namelen == 2) && + (filedir_entry->d_name[0] == '.') && + (filedir_entry->d_name[1] == '.')) + continue; + + if (d_type == DT_UNKNOWN) { + struct stat s; + char path[PATH_MAX]; + snprintf(path, PATH_MAX, "%s/%s", + DirName, filedir_entry->d_name); + if (stat(path, &s) == 0) { + d_type = IFTODT(s.st_mode); + } + } + + switch (d_type) + { + case DT_LNK: /* TODO: check whether its a file or a directory */ + case DT_DIR: + /* Skip directories we are not interested in... */ + if ((strcmp(filedir_entry->d_name, ".svn") == 0) || + (strcmp(filedir_entry->d_name, "t") == 0)) + break; + + Dir = NewStrBufPlain (filedir_entry->d_name, d_namelen); + if (DefaultTheme == NULL) + DefaultTheme = Dir; + Put(AvailableThemes, SKEY(Dir), Dir, HFreeStrBuf); + break; + case DT_REG: + default: + break; + } + + + } + free(d); + closedir(filedir); + + return 1; +} + +HashList *GetValidThemeHash(StrBuf *Target, WCTemplputParams *TP) +{ + return AvailableThemes; +} +void +ServerStartModule_ICONTHEME +(void) +{ + AvailableThemes = NewHash(1, NULL); +} +void +InitModule_ICONTHEME +(void) +{ + StrBuf *Themes = NewStrBufPlain(static_dirs[0], -1); + + StrBufAppendBufPlain(Themes, HKEY("/"), 0); + StrBufAppendBufPlain(Themes, HKEY("webcit_icons"), 0); + LoadThemeDir(ChrPtr(Themes)); + FreeStrBuf(&Themes); + + RegisterPreference("icontheme", _("Icon Theme"), PRF_STRING, LoadIconthemeSettings); + RegisterNamespace("ICONTHEME", 0, 0, tmplput_icontheme, NULL, CTX_NONE); + + RegisterIterator("PREF:VALID:THEME", 0, NULL, + GetValidThemeHash, NULL, NULL, CTX_STRBUF, CTX_NONE, IT_NOFLAG); +} + +void +ServerShutdownModule_ICONTHEME +(void) +{ + DeleteHash(&AvailableThemes); +} + +void +SessionDestroyModule_ICONTHEME +(wcsession *sess) +{ + FreeStrBuf(&sess->IconTheme); +} + diff --git a/webcit/static/t/prefs/box.html b/webcit/static/t/prefs/box.html index 0dabf5c64..ae7f1eb82 100644 --- a/webcit/static/t/prefs/box.html +++ b/webcit/static/t/prefs/box.html @@ -243,6 +243,15 @@ + + + + + + +
diff --git a/webcit/static/t/prefs/section_icontheme_select.html b/webcit/static/t/prefs/section_icontheme_select.html new file mode 100644 index 000000000..a31bba7e3 --- /dev/null +++ b/webcit/static/t/prefs/section_icontheme_select.html @@ -0,0 +1 @@ + diff --git a/webcit/webcit.h b/webcit/webcit.h index 1f71f45f9..65f2d11dc 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -490,6 +490,8 @@ struct wcsession { char last_chat_user[256]; + StrBuf *IconTheme; /* Icontheme setting */ + /* Iconbar controls */ int cache_max_folders; int cache_num_floors; -- 2.30.2