From a7c8a7201ad998c040bffce72cce2d31aa7cc36d Mon Sep 17 00:00:00 2001 From: str4d <str4d@mail.i2p> Date: Sun, 22 Jul 2012 13:13:43 +0000 Subject: [PATCH] When fetching a theme, if theme config key is not found, write out the default This is required in order to get the theme config keys of the various apps into themes.config; this way, the routerconsole requires no knowledge of what apps support universal theming, and can just blanket apply themes to all known keys. --- .../java/src/org/klomp/snark/SnarkManager.java | 9 ++++++++- .../java/src/net/i2p/router/web/ConfigUIHandler.java | 11 ++++++----- apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java | 9 ++++++++- apps/susimail/src/src/i2p/susi/webmail/WebMail.java | 12 +++++++++++- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java index aee8212fa3..25a0f9a031 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java +++ b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java @@ -289,7 +289,14 @@ public class SnarkManager implements Snark.CompleteListener { if (!_config.containsKey(PROP_STARTUP_DELAY)) _config.setProperty(PROP_STARTUP_DELAY, Integer.toString(DEFAULT_STARTUP_DELAY)); // Fetch theme - _theme = _context.readConfigFile(THEME_CONFIG_FILE).getProperty(PROP_THEME, DEFAULT_THEME); + Properties themeProps = _context.readConfigFile(THEME_CONFIG_FILE); + _theme = themeProps.getProperty(PROP_THEME); + // Ensure that theme config line exists in config file + if (_theme == null) { + _theme = DEFAULT_THEME; + themeProps.put(PROP_THEME, _theme); + _context.writeConfigFile(THEME_CONFIG_FILE, themeProps); + } updateConfig(); } /** diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHandler.java index a9d1c4a04c..6599ffbeaf 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigUIHandler.java @@ -29,16 +29,17 @@ public class ConfigUIHandler extends FormHandler { return; Properties props = _context.readConfigFile(CSSHelper.THEME_CONFIG_FILE); String oldTheme = props.getProperty(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME); + // Save routerconsole theme first to ensure it is in config file + if (_config.equals("default")) // obsolete + props.put(CSSHelper.PROP_THEME_NAME, null); + else + props.put(CSSHelper.PROP_THEME_NAME, _config); if (_universalTheming) { + // The routerconsole theme gets set again, but oh well for (Iterator it = props.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); props.put(key, _config); } - } else { - if (_config.equals("default")) // obsolete - props.put(CSSHelper.PROP_THEME_NAME, null); - else - props.put(CSSHelper.PROP_THEME_NAME, _config); } boolean ok = _context.writeConfigFile(CSSHelper.THEME_CONFIG_FILE, props); if (ok) { diff --git a/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java b/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java index 7d229cd841..e157c745a3 100644 --- a/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java +++ b/apps/susidns/src/java/src/i2p/susi/dns/BaseBean.java @@ -47,7 +47,14 @@ public class BaseBean if( properties.getProperty(PRIVATE_BOOK) == null) properties.setProperty(PRIVATE_BOOK, DEFAULT_PRIVATE_BOOK); // Fetch theme - _theme = _context.readConfigFile(THEME_CONFIG_FILE).getProperty(PROP_THEME_NAME, DEFAULT_THEME); + Properties themeProps = _context.readConfigFile(THEME_CONFIG_FILE); + _theme = themeProps.getProperty(PROP_THEME_NAME); + // Ensure that theme config line exists in config file + if (_theme == null) { + _theme = DEFAULT_THEME; + themeProps.put(PROP_THEME_NAME, _theme); + _context.writeConfigFile(THEME_CONFIG_FILE, themeProps); + } configLastLoaded = currentTime; } catch (Exception e) { diff --git a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java index 1b47352a28..113f97bb07 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/WebMail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/WebMail.java @@ -49,6 +49,7 @@ import java.util.Enumeration; import java.util.Iterator; import java.util.ListIterator; import java.util.Locale; +import java.util.Properties; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -1190,6 +1191,15 @@ public class WebMail extends HttpServlet private void processRequest( HttpServletRequest httpRequest, HttpServletResponse response ) throws IOException, ServletException { + Properties themeProps = I2PAppContext.getGlobalContext().readConfigFile(THEME_CONFIG_FILE); + String theme = themeProps.getProperty(PROP_THEME); + // Ensure that theme config line exists in config file + if (theme == null) { + theme = DEFAULT_THEME; + themeProps.put(PROP_THEME, theme); + I2PAppContext.getGlobalContext().writeConfigFile(THEME_CONFIG_FILE, themeProps); + } + httpRequest.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); response.setHeader("X-Frame-Options", "SAMEORIGIN"); @@ -1209,7 +1219,7 @@ public class WebMail extends HttpServlet sessionObject.info = ""; sessionObject.pageChanged = false; sessionObject.showAttachment = null; - sessionObject.themePath = "/themes/susimail/" + I2PAppContext.getGlobalContext().readConfigFile(THEME_CONFIG_FILE).getProperty(PROP_THEME, DEFAULT_THEME) + '/'; + sessionObject.themePath = "/themes/susimail/" + theme + '/'; sessionObject.imgPath = sessionObject.themePath + "images/"; processStateChangeButtons( sessionObject, request ); -- GitLab