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;
|
2010-02-26 16:58:01 +00:00
|
|
|
import java.util.Iterator;
|
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);
|
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))
|
2012-03-02 22:32:45 +00:00
|
|
|
buf.append("checked=\"checked\" ");
|
2009-10-22 22:25:53 +00:00
|
|
|
buf.append("value=\"").append(theme).append("\">").append(_(theme)).append("<br>\n");
|
|
|
|
}
|
2012-08-01 01:50:59 +00:00
|
|
|
boolean universalTheming = _context.getBooleanProperty(CSSHelper.PROP_UNIVERSAL_THEMING);
|
|
|
|
buf.append("<input type=\"checkbox\" name=\"universalTheming\" ");
|
|
|
|
if (universalTheming)
|
|
|
|
buf.append("checked=\"checked\" ");
|
|
|
|
buf.append("value=\"1\">")
|
2012-07-22 06:53:43 +00:00
|
|
|
.append(_("Set theme universally across all apps"))
|
|
|
|
.append("<br>\n");
|
2009-10-22 22:25: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() {
|
|
|
|
Set<String> rv = new TreeSet();
|
|
|
|
// 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
|
|
|
|
Set props = _context.getPropertyNames();
|
|
|
|
for (Iterator iter = props.iterator(); iter.hasNext(); ) {
|
|
|
|
String prop = (String) iter.next();
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Each language has the ISO code, the flag, and the name.
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-07-13 00:28:06 +00:00
|
|
|
private static final String langs[] = {"ar", "cs", "da", "de", "ee", "el", "en", "es", "fi",
|
2012-06-03 13:46:33 +00:00
|
|
|
"fr", "hu", "it", "nl", "pl", "pt", "ru",
|
2011-08-20 16:13:15 +00:00
|
|
|
"sv", "uk", "vi", "zh"};
|
2012-07-13 00:28:06 +00:00
|
|
|
private static final String flags[] = {"lang_ar", "cz", "dk", "de", "ee", "gr", "us", "es", "fi",
|
2012-06-03 13:46:33 +00:00
|
|
|
"fr", "hu", "it", "nl", "pl", "pt", "ru",
|
2011-08-20 16:13:15 +00:00
|
|
|
"se", "ua", "vn", "cn"};
|
2012-02-17 11:31:41 +00:00
|
|
|
private static final String xlangs[] = {_x("Arabic"), _x("Czech"), _x("Danish"),
|
2012-07-13 00:28:06 +00:00
|
|
|
_x("German"), _x("Estonian"), _x("Greek"), _x("English"), _x("Spanish"), _x("Finnish"),
|
2012-06-03 14:09:41 +00:00
|
|
|
_x("French"), _x("Hungarian"), _x("Italian"), _x("Dutch"), _x("Polish"),
|
2011-06-13 15:04:57 +00:00
|
|
|
_x("Portuguese"), _x("Russian"), _x("Swedish"),
|
2011-08-21 01:11:50 +00:00
|
|
|
_x("Ukrainian"), _x("Vietnamese"), _x("Chinese")};
|
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() {
|
|
|
|
StringBuilder buf = new StringBuilder(512);
|
|
|
|
String current = Messages.getLanguage(_context);
|
|
|
|
for (int i = 0; i < langs.length; i++) {
|
|
|
|
// we use "lang" so it is set automagically in CSSHelper
|
|
|
|
buf.append("<input type=\"radio\" class=\"optbox\" name=\"lang\" ");
|
|
|
|
if (langs[i].equals(current))
|
2012-03-02 22:32:45 +00:00
|
|
|
buf.append("checked=\"checked\" ");
|
2009-11-02 18:52:42 +00:00
|
|
|
buf.append("value=\"").append(langs[i]).append("\">")
|
|
|
|
.append("<img height=\"11\" width=\"16\" alt=\"\" src=\"/flags.jsp?c=").append(flags[i]).append("\"> ")
|
|
|
|
.append(_(xlangs[i])).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);
|
|
|
|
buf.append("<table>");
|
|
|
|
if (userpw.isEmpty()) {
|
|
|
|
buf.append("<tr><td colspan=\"3\">");
|
|
|
|
buf.append(_("Add a user and password to enable."));
|
|
|
|
buf.append("</td></tr>");
|
|
|
|
} else {
|
|
|
|
buf.append("<tr><th>")
|
|
|
|
.append(_("Remove"))
|
|
|
|
.append("</th><th>")
|
|
|
|
.append(_("User Name"))
|
|
|
|
.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>")
|
|
|
|
.append(_("Add")).append(":</b>" +
|
|
|
|
"</td><td align=\"left\"><input type=\"text\" name=\"name\">" +
|
|
|
|
"</td><td align=\"left\"><b>");
|
|
|
|
buf.append(_("Password")).append(":</b> " +
|
|
|
|
"<input type=\"password\" size=\"40\" name=\"pw\"></td></tr>" +
|
|
|
|
"</table>\n");
|
|
|
|
return buf.toString();
|
|
|
|
}
|
2009-07-12 03:21:20 +00:00
|
|
|
}
|