2009-07-12 03:21:20 +00:00
|
|
|
package net.i2p.router.web;
|
|
|
|
|
2009-10-31 18:18:36 +00:00
|
|
|
import java.io.File;
|
2012-10-13 21:20:16 +00:00
|
|
|
import java.util.Map;
|
2009-10-31 18:18:36 +00:00
|
|
|
import java.util.Set;
|
2012-10-13 21:20:16 +00:00
|
|
|
import java.util.TreeSet;
|
2009-10-31 18:18:36 +00:00
|
|
|
|
2009-07-12 03:21:20 +00:00
|
|
|
public class ConfigUIHelper extends HelperBase {
|
|
|
|
|
|
|
|
public String getSettings() {
|
|
|
|
StringBuilder buf = new StringBuilder(512);
|
2016-04-18 04:12:15 +00:00
|
|
|
buf.append("<div id=\"availablethemes\">");
|
2012-08-01 01:50:59 +00:00
|
|
|
String current = _context.getProperty(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);
|
2009-10-31 18:18:36 +00:00
|
|
|
Set<String> themes = themeSet();
|
2009-07-12 03:21:20 +00:00
|
|
|
for (String theme : themes) {
|
2009-07-30 23:10:48 +00:00
|
|
|
buf.append("<input type=\"radio\" class=\"optbox\" name=\"theme\" ");
|
2009-07-12 03:21:20 +00:00
|
|
|
if (theme.equals(current))
|
2015-12-18 14:43:31 +00:00
|
|
|
buf.append(CHECKED);
|
2015-09-25 19:55:36 +00:00
|
|
|
buf.append("value=\"").append(theme).append("\">").append(_t(theme)).append("<br>\n");
|
2009-10-22 22:25:53 +00:00
|
|
|
}
|
2012-08-01 01:50:59 +00:00
|
|
|
boolean universalTheming = _context.getBooleanProperty(CSSHelper.PROP_UNIVERSAL_THEMING);
|
2016-04-18 04:12:15 +00:00
|
|
|
buf.append("</div><div id=\"themeoptions\">");
|
2012-08-01 01:50:59 +00:00
|
|
|
buf.append("<input type=\"checkbox\" name=\"universalTheming\" ");
|
|
|
|
if (universalTheming)
|
2015-12-18 14:43:31 +00:00
|
|
|
buf.append(CHECKED);
|
2012-08-01 01:50:59 +00:00
|
|
|
buf.append("value=\"1\">")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Set theme universally across all apps"))
|
2012-07-22 06:53:43 +00:00
|
|
|
.append("<br>\n");
|
2009-10-22 22:25:53 +00:00
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2013-01-21 05:59:53 +00:00
|
|
|
public String getForceMobileConsole() {
|
|
|
|
StringBuilder buf = new StringBuilder(256);
|
|
|
|
boolean forceMobileConsole = _context.getBooleanProperty(CSSHelper.PROP_FORCE_MOBILE_CONSOLE);
|
|
|
|
buf.append("<input type=\"checkbox\" name=\"forceMobileConsole\" ");
|
|
|
|
if (forceMobileConsole)
|
2015-12-18 14:43:31 +00:00
|
|
|
buf.append(CHECKED);
|
2013-01-21 05:59:53 +00:00
|
|
|
buf.append("value=\"1\">")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Force the mobile console to be used"))
|
2016-04-18 04:12:15 +00:00
|
|
|
.append("</div>\n");
|
2013-01-21 05:59:53 +00:00
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2010-02-26 16:58:01 +00:00
|
|
|
static final String PROP_THEME_PFX = "routerconsole.theme.";
|
|
|
|
|
2009-10-31 18:18:36 +00:00
|
|
|
/** @return standard and user-installed themes, sorted (untranslated) */
|
|
|
|
private Set<String> themeSet() {
|
2013-11-21 11:31:50 +00:00
|
|
|
Set<String> rv = new TreeSet<String>();
|
2009-10-31 18:18:36 +00:00
|
|
|
// add a failsafe even if we can't find any themes
|
|
|
|
rv.add(CSSHelper.DEFAULT_THEME);
|
|
|
|
File dir = new File(_context.getBaseDir(), "docs/themes/console");
|
|
|
|
File[] files = dir.listFiles();
|
|
|
|
if (files == null)
|
|
|
|
return rv;
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
|
String name = files[i].getName();
|
|
|
|
if (files[i].isDirectory() && ! name.equals("images"))
|
|
|
|
rv.add(name);
|
|
|
|
}
|
2010-02-26 16:58:01 +00:00
|
|
|
// user themes
|
2013-11-21 11:31:50 +00:00
|
|
|
Set<String> props = _context.getPropertyNames();
|
2013-11-28 11:10:57 +00:00
|
|
|
for (String prop : props) {
|
2010-02-26 16:58:01 +00:00
|
|
|
if (prop.startsWith(PROP_THEME_PFX) && prop.length() > PROP_THEME_PFX.length())
|
|
|
|
rv.add(prop.substring(PROP_THEME_PFX.length()));
|
|
|
|
}
|
2009-10-31 18:18:36 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-06-26 19:07:01 +00:00
|
|
|
/**
|
2013-11-18 23:18:46 +00:00
|
|
|
* Each language has the ISO code, the flag, the name, and the optional country name.
|
2011-06-26 19:07:01 +00:00
|
|
|
* Alphabetical by the ISO code please.
|
|
|
|
* See http://en.wikipedia.org/wiki/ISO_639-1 .
|
|
|
|
* Any language-specific flag added to the icon set must be
|
|
|
|
* added to the top-level build.xml for the updater.
|
2014-03-12 12:29:38 +00:00
|
|
|
* As of 0.9.12, ISO 639-2 three-letter codes are supported also.
|
2011-06-26 19:07:01 +00:00
|
|
|
*/
|
2013-11-18 23:18:46 +00:00
|
|
|
private static final String langs[][] = {
|
|
|
|
{ "ar", "lang_ar", _x("Arabic"), null },
|
|
|
|
{ "cs", "cz", _x("Czech"), null },
|
|
|
|
{ "da", "dk", _x("Danish"), null },
|
|
|
|
{ "de", "de", _x("German"), null },
|
|
|
|
{ "et", "ee", _x("Estonian"), null },
|
|
|
|
{ "el", "gr", _x("Greek"), null },
|
|
|
|
{ "en", "us", _x("English"), null },
|
|
|
|
{ "es", "es", _x("Spanish"), null },
|
|
|
|
{ "fi", "fi", _x("Finnish"), null },
|
|
|
|
{ "fr", "fr", _x("French"), null },
|
|
|
|
{ "hu", "hu", _x("Hungarian"), null },
|
|
|
|
{ "it", "it", _x("Italian"), null },
|
2013-11-22 22:19:06 +00:00
|
|
|
{ "ja", "jp", _x("Japanese"), null },
|
2015-04-09 11:59:17 +00:00
|
|
|
{ "mg", "mg", _x("Malagasy"), null },
|
2014-02-02 14:39:41 +00:00
|
|
|
{ "nl", "nl", _x("Dutch"), null },
|
|
|
|
{ "nb", "no", _x("Norwegian Bokmaal"), null },
|
2013-11-18 23:18:46 +00:00
|
|
|
{ "pl", "pl", _x("Polish"), null },
|
|
|
|
{ "pt", "pt", _x("Portuguese"), null },
|
2014-01-09 19:24:11 +00:00
|
|
|
{ "pt_BR", "br", _x("Portuguese"), "Brazil" },
|
2014-01-10 06:15:17 +00:00
|
|
|
{ "ro", "ro", _x("Romanian"), null },
|
2013-11-18 23:18:46 +00:00
|
|
|
{ "ru", "ru", _x("Russian"), null },
|
2014-05-15 23:14:38 +00:00
|
|
|
{ "sk", "sk", _x("Slovak"), null },
|
2013-11-18 23:18:46 +00:00
|
|
|
{ "sv", "se", _x("Swedish"), null },
|
|
|
|
{ "tr", "tr", _x("Turkish"), null },
|
|
|
|
{ "uk", "ua", _x("Ukrainian"), null },
|
|
|
|
{ "vi", "vn", _x("Vietnamese"), null },
|
2016-01-15 00:04:04 +00:00
|
|
|
{ "zh", "cn", _x("Chinese"), null },
|
2016-02-13 16:29:49 +00:00
|
|
|
{ "zh_TW", "tw", _x("Chinese"), "Taiwan" },
|
|
|
|
{ "xx", "a1", "Debug: Find untagged strings", null },
|
2013-11-18 23:18:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-22 22:25:53 +00:00
|
|
|
|
2009-10-31 18:18:36 +00:00
|
|
|
/** todo sort by translated string */
|
2009-10-22 22:25:53 +00:00
|
|
|
public String getLangSettings() {
|
2014-02-10 14:22:43 +00:00
|
|
|
String clang = Messages.getLanguage(_context);
|
|
|
|
String current = clang;
|
2013-11-18 23:18:46 +00:00
|
|
|
String country = Messages.getCountry(_context);
|
|
|
|
if (country != null && country.length() > 0)
|
|
|
|
current += '_' + country;
|
2014-02-10 14:22:43 +00:00
|
|
|
// find best match
|
|
|
|
boolean found = false;
|
|
|
|
for (int i = 0; i < langs.length; i++) {
|
|
|
|
if (langs[i][0].equals(current)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
if (country != null && country.length() > 0) {
|
|
|
|
current = clang;
|
|
|
|
for (int i = 0; i < langs.length; i++) {
|
|
|
|
if (langs[i][0].equals(current)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
current = "en";
|
|
|
|
}
|
|
|
|
StringBuilder buf = new StringBuilder(512);
|
2009-10-22 22:25:53 +00:00
|
|
|
for (int i = 0; i < langs.length; i++) {
|
2013-11-18 23:18:46 +00:00
|
|
|
String lang = langs[i][0];
|
2016-02-13 16:29:49 +00:00
|
|
|
if (lang.equals("xx") && !isAdvanced())
|
|
|
|
continue;
|
2016-04-18 04:32:55 +00:00
|
|
|
// we use "lang" so it is set automagically in CSSHelper
|
|
|
|
buf.append("<input type=\"radio\" class=\"optbox\" name=\"lang\" ");
|
2013-11-18 23:18:46 +00:00
|
|
|
if (lang.equals(current))
|
2015-12-18 14:43:31 +00:00
|
|
|
buf.append(CHECKED);
|
2013-11-18 23:18:46 +00:00
|
|
|
buf.append("value=\"").append(lang).append("\">")
|
|
|
|
.append("<img height=\"11\" width=\"16\" alt=\"\" src=\"/flags.jsp?c=").append(langs[i][1]).append("\"> ");
|
2014-03-12 12:29:38 +00:00
|
|
|
int under = lang.indexOf('_');
|
|
|
|
String slang = (under > 0) ? lang.substring(0, under) : lang;
|
2013-11-18 23:18:46 +00:00
|
|
|
buf.append(Messages.getDisplayLanguage(slang, langs[i][2], _context));
|
|
|
|
String name = langs[i][3];
|
|
|
|
if (name != null) {
|
|
|
|
buf.append(" (")
|
|
|
|
.append(Messages.getString(name, _context, Messages.COUNTRY_BUNDLE_NAME))
|
|
|
|
.append(')');
|
|
|
|
}
|
|
|
|
buf.append("<br>\n");
|
2009-07-12 03:21:20 +00:00
|
|
|
}
|
|
|
|
return buf.toString();
|
|
|
|
}
|
2012-10-13 21:20:16 +00:00
|
|
|
|
|
|
|
/** @since 0.9.4 */
|
|
|
|
public String getPasswordForm() {
|
|
|
|
StringBuilder buf = new StringBuilder(512);
|
|
|
|
ConsolePasswordManager mgr = new ConsolePasswordManager(_context);
|
|
|
|
Map<String, String> userpw = mgr.getMD5(RouterConsoleRunner.PROP_CONSOLE_PW);
|
2016-04-18 04:12:15 +00:00
|
|
|
buf.append("<table id=\"consolepass\">");
|
2012-10-13 21:20:16 +00:00
|
|
|
if (userpw.isEmpty()) {
|
|
|
|
buf.append("<tr><td colspan=\"3\">");
|
2015-09-25 19:55:36 +00:00
|
|
|
buf.append(_t("Add a user and password to enable."));
|
2012-10-13 21:20:16 +00:00
|
|
|
buf.append("</td></tr>");
|
|
|
|
} else {
|
|
|
|
buf.append("<tr><th>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Remove"))
|
2012-10-13 21:20:16 +00:00
|
|
|
.append("</th><th>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("User Name"))
|
2012-10-13 21:20:16 +00:00
|
|
|
.append("</th><th> </th></tr>\n");
|
|
|
|
for (String name : userpw.keySet()) {
|
|
|
|
buf.append("<tr><td align=\"center\"><input type=\"checkbox\" class=\"optbox\" name=\"delete_")
|
|
|
|
.append(name)
|
|
|
|
.append("\"></td><td colspan=\"2\">")
|
|
|
|
.append(name)
|
|
|
|
.append("</td></tr>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.append("<tr><td align=\"center\"><b>")
|
2015-09-25 19:55:36 +00:00
|
|
|
.append(_t("Add")).append(":</b>" +
|
2012-10-13 21:20:16 +00:00
|
|
|
"</td><td align=\"left\"><input type=\"text\" name=\"name\">" +
|
|
|
|
"</td><td align=\"left\"><b>");
|
2015-09-25 19:55:36 +00:00
|
|
|
buf.append(_t("Password")).append(":</b> " +
|
2014-08-03 13:58:51 +00:00
|
|
|
"<input type=\"password\" size=\"40\" name=\"nofilter_pw\"></td></tr>" +
|
2012-10-13 21:20:16 +00:00
|
|
|
"</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
2009-07-12 03:21:20 +00:00
|
|
|
}
|