forked from I2P_Developers/i2p.i2p
/confighome:
- config search engines - add icons - restore defaults button
This commit is contained in:
@ -22,6 +22,7 @@ public class ConfigHomeHandler extends FormHandler {
|
|||||||
String group = getJettyString("group");
|
String group = getJettyString("group");
|
||||||
boolean deleting = _action.equals(_("Delete selected"));
|
boolean deleting = _action.equals(_("Delete selected"));
|
||||||
boolean adding = _action.equals(_("Add item"));
|
boolean adding = _action.equals(_("Add item"));
|
||||||
|
boolean restoring = _action.equals(_("Restore defaults"));
|
||||||
if (_action.equals(_("Save")) && "0".equals(group)) {
|
if (_action.equals(_("Save")) && "0".equals(group)) {
|
||||||
boolean old = _context.getBooleanProperty(HomeHelper.PROP_OLDHOME);
|
boolean old = _context.getBooleanProperty(HomeHelper.PROP_OLDHOME);
|
||||||
boolean nnew = getJettyString("oldHome") != null;
|
boolean nnew = getJettyString("oldHome") != null;
|
||||||
@ -29,7 +30,7 @@ public class ConfigHomeHandler extends FormHandler {
|
|||||||
_context.router().saveConfig(HomeHelper.PROP_OLDHOME, "" + nnew);
|
_context.router().saveConfig(HomeHelper.PROP_OLDHOME, "" + nnew);
|
||||||
addFormNotice(_("Home page changed"));
|
addFormNotice(_("Home page changed"));
|
||||||
}
|
}
|
||||||
} else if (adding || deleting) {
|
} else if (adding || deleting || restoring) {
|
||||||
String prop;
|
String prop;
|
||||||
String dflt;
|
String dflt;
|
||||||
if ("1".equals(group)) {
|
if ("1".equals(group)) {
|
||||||
@ -38,12 +39,24 @@ public class ConfigHomeHandler extends FormHandler {
|
|||||||
} else if ("2".equals(group)) {
|
} else if ("2".equals(group)) {
|
||||||
prop = HomeHelper.PROP_SERVICES;
|
prop = HomeHelper.PROP_SERVICES;
|
||||||
dflt = HomeHelper.DEFAULT_SERVICES;
|
dflt = HomeHelper.DEFAULT_SERVICES;
|
||||||
|
} else if ("3".equals(group)) {
|
||||||
|
prop = SearchHelper.PROP_ENGINES;
|
||||||
|
dflt = SearchHelper.ENGINES_DEFAULT;
|
||||||
} else {
|
} else {
|
||||||
addFormError("Bad group");
|
addFormError("Bad group");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (restoring) {
|
||||||
|
_context.router().saveConfig(prop, dflt);
|
||||||
|
addFormNotice(_("Restored default settings"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
String config = _context.getProperty(prop, dflt);
|
String config = _context.getProperty(prop, dflt);
|
||||||
Collection<HomeHelper.App> apps = HomeHelper.buildApps(_context, config);
|
Collection<HomeHelper.App> apps;
|
||||||
|
if ("3".equals(group))
|
||||||
|
apps = HomeHelper.buildSearchApps(config);
|
||||||
|
else
|
||||||
|
apps = HomeHelper.buildApps(_context, config);
|
||||||
if (adding) {
|
if (adding) {
|
||||||
String name = getJettyString("name");
|
String name = getJettyString("name");
|
||||||
if (name == null || name.length() <= 0) {
|
if (name == null || name.length() <= 0) {
|
||||||
@ -80,7 +93,7 @@ public class ConfigHomeHandler extends FormHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HomeHelper.saveApps(_context, prop, apps);
|
HomeHelper.saveApps(_context, prop, apps, !("3".equals(group)));
|
||||||
} else {
|
} else {
|
||||||
addFormError(_("Unsupported"));
|
addFormError(_("Unsupported"));
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,10 @@ public class HomeHelper extends HelperBase {
|
|||||||
return configTable(PROP_FAVORITES, DEFAULT_FAVORITES);
|
return configTable(PROP_FAVORITES, DEFAULT_FAVORITES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getConfigSearch() {
|
||||||
|
return configTable(SearchHelper.PROP_ENGINES, SearchHelper.ENGINES_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
public String getConfigHome() {
|
public String getConfigHome() {
|
||||||
boolean oldHome = _context.getBooleanProperty(PROP_OLDHOME);
|
boolean oldHome = _context.getBooleanProperty(PROP_OLDHOME);
|
||||||
return oldHome ? "checked=\"true\"" : "";
|
return oldHome ? "checked=\"true\"" : "";
|
||||||
@ -96,7 +100,11 @@ public class HomeHelper extends HelperBase {
|
|||||||
|
|
||||||
private String configTable(String prop, String dflt) {
|
private String configTable(String prop, String dflt) {
|
||||||
String config = _context.getProperty(prop, dflt);
|
String config = _context.getProperty(prop, dflt);
|
||||||
Collection<App> apps = buildApps(_context, config);
|
Collection<App> apps;
|
||||||
|
if (prop.equals(SearchHelper.PROP_ENGINES))
|
||||||
|
apps = buildSearchApps(config);
|
||||||
|
else
|
||||||
|
apps = buildApps(_context, config);
|
||||||
return renderConfig(apps);
|
return renderConfig(apps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,13 +121,26 @@ public class HomeHelper extends HelperBase {
|
|||||||
return apps;
|
return apps;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveApps(RouterContext ctx, String prop, Collection<App> apps) {
|
static Collection<App> buildSearchApps(String config) {
|
||||||
|
String[] args = config.split("" + S);
|
||||||
|
Set<App> apps = new TreeSet(new AppComparator());
|
||||||
|
for (int i = 0; i < args.length - 1; i += 2) {
|
||||||
|
String name = args[i];
|
||||||
|
String url = args[i+1];
|
||||||
|
apps.add(new App(name, null, url, null));
|
||||||
|
}
|
||||||
|
return apps;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void saveApps(RouterContext ctx, String prop, Collection<App> apps, boolean full) {
|
||||||
StringBuilder buf = new StringBuilder(1024);
|
StringBuilder buf = new StringBuilder(1024);
|
||||||
for (App app : apps) {
|
for (App app : apps) {
|
||||||
buf.append(app.name).append(S)
|
buf.append(app.name).append(S);
|
||||||
.append(app.desc).append(S)
|
if (full)
|
||||||
.append(app.url).append(S)
|
buf.append(app.desc).append(S);
|
||||||
.append(app.icon).append(S);
|
buf.append(app.url).append(S);
|
||||||
|
if (full)
|
||||||
|
buf.append(app.icon).append(S);
|
||||||
}
|
}
|
||||||
ctx.router().saveConfig(prop, buf.toString());
|
ctx.router().saveConfig(prop, buf.toString());
|
||||||
}
|
}
|
||||||
@ -152,7 +173,7 @@ public class HomeHelper extends HelperBase {
|
|||||||
StringBuilder buf = new StringBuilder(1024);
|
StringBuilder buf = new StringBuilder(1024);
|
||||||
buf.append("<table><tr><th>")
|
buf.append("<table><tr><th>")
|
||||||
.append(_("Remove"))
|
.append(_("Remove"))
|
||||||
.append("</th><th>")
|
.append("</th><th colspan=\"2\">")
|
||||||
.append(_("Name"))
|
.append(_("Name"))
|
||||||
.append("</th><th>")
|
.append("</th><th>")
|
||||||
.append(_("URL"))
|
.append(_("URL"))
|
||||||
@ -160,7 +181,11 @@ public class HomeHelper extends HelperBase {
|
|||||||
for (App app : apps) {
|
for (App app : apps) {
|
||||||
buf.append("<tr><td align=\"center\"><input type=\"checkbox\" class=\"optbox\" name=\"delete_")
|
buf.append("<tr><td align=\"center\"><input type=\"checkbox\" class=\"optbox\" name=\"delete_")
|
||||||
.append(app.name)
|
.append(app.name)
|
||||||
.append("\"></td><td align=\"left\">")
|
.append("\"></td><td align=\"center\">");
|
||||||
|
if (app.icon != null) {
|
||||||
|
buf.append("<img height=\"16\" src=\"").append(app.icon).append("\">");
|
||||||
|
}
|
||||||
|
buf.append("</td><td align=\"left\">")
|
||||||
.append(app.name)
|
.append(app.name)
|
||||||
.append("</td><td align=\"left\"><a href=\"")
|
.append("</td><td align=\"left\"><a href=\"")
|
||||||
.append(app.url)
|
.append(app.url)
|
||||||
@ -168,7 +193,7 @@ public class HomeHelper extends HelperBase {
|
|||||||
.append(app.url)
|
.append(app.url)
|
||||||
.append("</a></td></tr>\n");
|
.append("</a></td></tr>\n");
|
||||||
}
|
}
|
||||||
buf.append("<tr><td align=\"center\"><b>")
|
buf.append("<tr><td colspan=\"2\" align=\"center\"><b>")
|
||||||
.append(_("Add")).append(":</b>" +
|
.append(_("Add")).append(":</b>" +
|
||||||
"</td><td align=\"left\"><input type=\"text\" name=\"name\"></td>" +
|
"</td><td align=\"left\"><input type=\"text\" name=\"name\"></td>" +
|
||||||
"<td align=\"left\"><input type=\"text\" size=\"40\" name=\"url\"></td></tr>");
|
"<td align=\"left\"><input type=\"text\" size=\"40\" name=\"url\"></td></tr>");
|
||||||
|
@ -17,10 +17,10 @@ public class SearchHelper extends HelperBase {
|
|||||||
private Map<String, String> _engines = new TreeMap();
|
private Map<String, String> _engines = new TreeMap();
|
||||||
|
|
||||||
private static final char S = ';';
|
private static final char S = ';';
|
||||||
private static final String PROP_ENGINES = "routerconsole.searchEngines";
|
static final String PROP_ENGINES = "routerconsole.searchEngines";
|
||||||
private static final String PROP_DEFAULT = "routerconsole.searchEngine";
|
private static final String PROP_DEFAULT = "routerconsole.searchEngine";
|
||||||
|
|
||||||
private static final String PROP_DEFAULTS =
|
static final String ENGINES_DEFAULT =
|
||||||
"eepsites.i2p" + S + "http://eepsites.i2p/Content/Search/SearchResults.aspx?inpQuery=%s" + S +
|
"eepsites.i2p" + S + "http://eepsites.i2p/Content/Search/SearchResults.aspx?inpQuery=%s" + S +
|
||||||
"epsilon.i2p" + S + "http://epsilon.i2p/search.jsp?q=%s" + S +
|
"epsilon.i2p" + S + "http://epsilon.i2p/search.jsp?q=%s" + S +
|
||||||
"sprongle.i2p" + S + "http://sprongle.i2p/sprongle.php?q=%s" + S +
|
"sprongle.i2p" + S + "http://sprongle.i2p/sprongle.php?q=%s" + S +
|
||||||
@ -40,7 +40,7 @@ public class SearchHelper extends HelperBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildEngineMap() {
|
private void buildEngineMap() {
|
||||||
String config = _context.getProperty(PROP_ENGINES, PROP_DEFAULTS);
|
String config = _context.getProperty(PROP_ENGINES, ENGINES_DEFAULT);
|
||||||
String[] args = config.split("" + S);
|
String[] args = config.split("" + S);
|
||||||
for (int i = 0; i < args.length - 1; i += 2) {
|
for (int i = 0; i < args.length - 1; i += 2) {
|
||||||
String name = args[i];
|
String name = args[i];
|
||||||
|
@ -33,6 +33,19 @@
|
|||||||
<input type="submit" name="action" class="accept" value="<%=intl._("Save")%>" >
|
<input type="submit" name="action" class="accept" value="<%=intl._("Save")%>" >
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<h3><%=intl._("Search Engines")%></h3>
|
||||||
|
<form action="" method="POST">
|
||||||
|
<input type="hidden" name="nonce" value="<%=pageNonce%>" >
|
||||||
|
<input type="hidden" name="group" value="3">
|
||||||
|
<jsp:getProperty name="homehelper" property="configSearch" />
|
||||||
|
<div class="formaction">
|
||||||
|
<input type="submit" name="action" class="delete" value="<%=intl._("Delete selected")%>" >
|
||||||
|
<input type="reset" class="cancel" value="<%=intl._("Cancel")%>" >
|
||||||
|
<input type="submit" name="action" class="reload" value="<%=intl._("Restore defaults")%>" >
|
||||||
|
<input type="submit" name="action" class="add" value="<%=intl._("Add item")%>" >
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
<h3><%=intl._("Recommended Eepsites")%></h3>
|
<h3><%=intl._("Recommended Eepsites")%></h3>
|
||||||
<form action="" method="POST">
|
<form action="" method="POST">
|
||||||
<input type="hidden" name="nonce" value="<%=pageNonce%>" >
|
<input type="hidden" name="nonce" value="<%=pageNonce%>" >
|
||||||
@ -41,6 +54,7 @@
|
|||||||
<div class="formaction">
|
<div class="formaction">
|
||||||
<input type="submit" name="action" class="delete" value="<%=intl._("Delete selected")%>" >
|
<input type="submit" name="action" class="delete" value="<%=intl._("Delete selected")%>" >
|
||||||
<input type="reset" class="cancel" value="<%=intl._("Cancel")%>" >
|
<input type="reset" class="cancel" value="<%=intl._("Cancel")%>" >
|
||||||
|
<input type="submit" name="action" class="reload" value="<%=intl._("Restore defaults")%>" >
|
||||||
<input type="submit" name="action" class="add" value="<%=intl._("Add item")%>" >
|
<input type="submit" name="action" class="add" value="<%=intl._("Add item")%>" >
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -53,6 +67,7 @@
|
|||||||
<div class="formaction">
|
<div class="formaction">
|
||||||
<input type="submit" name="action" class="delete" value="<%=intl._("Delete selected")%>" >
|
<input type="submit" name="action" class="delete" value="<%=intl._("Delete selected")%>" >
|
||||||
<input type="reset" class="cancel" value="<%=intl._("Cancel")%>" >
|
<input type="reset" class="cancel" value="<%=intl._("Cancel")%>" >
|
||||||
|
<input type="submit" name="action" class="reload" value="<%=intl._("Restore defaults")%>" >
|
||||||
<input type="submit" name="action" class="add" value="<%=intl._("Add item")%>" >
|
<input type="submit" name="action" class="add" value="<%=intl._("Add item")%>" >
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Reference in New Issue
Block a user