* i2psnark:

- Add data directory configuration to GUI (ticket #768)
   - Add page size configuration to GUI
This commit is contained in:
zzz
2013-04-15 18:39:59 +00:00
parent 11dd7f6b8c
commit efe7a7536d
2 changed files with 70 additions and 13 deletions

View File

@@ -92,6 +92,7 @@ public class SnarkManager implements CompleteListener {
//public static final String DEFAULT_LINK_PREFIX = "file:///";
public static final String PROP_STARTUP_DELAY = "i2psnark.startupDelay";
public static final String PROP_REFRESH_DELAY = "i2psnark.refreshSeconds";
public static final String PROP_PAGE_SIZE = "i2psnark.pageSize";
public static final String RC_PROP_THEME = "routerconsole.theme";
public static final String RC_PROP_UNIVERSAL_THEMING = "routerconsole.universal.theme";
public static final String PROP_THEME = "i2psnark.theme";
@@ -105,6 +106,7 @@ public class SnarkManager implements CompleteListener {
public static final int DEFAULT_MAX_UP_BW = 10;
public static final int DEFAULT_STARTUP_DELAY = 3;
public static final int DEFAULT_REFRESH_DELAY_SECS = 60;
private static final int DEFAULT_PAGE_SIZE = 50;
/**
* "name", "announceURL=websiteURL" pairs
@@ -270,6 +272,18 @@ public class SnarkManager implements CompleteListener {
}
}
/**
* For GUI
* @since 0.9.6
*/
public int getPageSize() {
try {
return Integer.parseInt(_config.getProperty(PROP_PAGE_SIZE));
} catch (NumberFormatException nfe) {
return DEFAULT_PAGE_SIZE;
}
}
private int getStartupDelayMinutes() {
try {
return Integer.parseInt(_config.getProperty(PROP_STARTUP_DELAY));
@@ -332,6 +346,8 @@ public class SnarkManager implements CompleteListener {
_config.setProperty(PROP_REFRESH_DELAY, Integer.toString(DEFAULT_REFRESH_DELAY_SECS));
if (!_config.containsKey(PROP_STARTUP_DELAY))
_config.setProperty(PROP_STARTUP_DELAY, Integer.toString(DEFAULT_STARTUP_DELAY));
if (!_config.containsKey(PROP_PAGE_SIZE))
_config.setProperty(PROP_PAGE_SIZE, Integer.toString(DEFAULT_PAGE_SIZE));
if (!_config.containsKey(PROP_THEME))
_config.setProperty(PROP_THEME, DEFAULT_THEME);
// no, so we can switch default to true later
@@ -450,10 +466,11 @@ public class SnarkManager implements CompleteListener {
}
public void updateConfig(String dataDir, boolean filesPublic, boolean autoStart, String refreshDelay,
String startDelay, String seedPct, String eepHost,
String startDelay, String pageSize, String seedPct, String eepHost,
String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts,
String upLimit, String upBW, boolean useOpenTrackers, boolean useDHT, String theme) {
boolean changed = false;
boolean interruptMonitor = false;
//if (eepHost != null) {
// // unused, we use socket eepget
// int port = _util.getEepProxyPort();
@@ -522,6 +539,39 @@ public class SnarkManager implements CompleteListener {
} catch (NumberFormatException nfe) {}
}
if (pageSize != null) {
try {
int size = Integer.parseInt(pageSize);
if (size <= 0)
size = 999999;
if (size != getPageSize() && size >= 5) {
changed = true;
pageSize = Integer.toString(size);
_config.setProperty(PROP_PAGE_SIZE, pageSize);
addMessage(_("Page size changed to {0}", pageSize));
}
} catch (NumberFormatException nfe) {}
}
if (dataDir != null && !dataDir.equals(getDataDir().getAbsolutePath())) {
File dd = new File(dataDir);
if (!dd.isAbsolute()) {
addMessage(_("Data directory must be an absolute path") + ": " + dataDir);
} else if (!dd.exists()) {
addMessage(_("Data directory does not exist") + ": " + dataDir);
} else if (!dd.isDirectory()) {
addMessage(_("Not a directory") + ": " + dataDir);
} else if (!dd.canRead()) {
addMessage(_("Unreadable") + ": " + dataDir);
} else {
changed = true;
interruptMonitor = true;
_config.setProperty(PROP_DIR, dataDir);
addMessage(_("Data directory changed to {0}", dataDir));
}
}
// Start of I2CP stuff.
// i2cpHost will generally be null since it is hidden from the form if in router context.
@@ -656,6 +706,9 @@ public class SnarkManager implements CompleteListener {
}
if (changed) {
saveConfig();
if (interruptMonitor)
// Data dir changed. this will stop and remove all old torrents, and add the new ones
_monitor.interrupt();
} else {
addMessage(_("Configuration unchanged."));
}

View File

@@ -61,7 +61,6 @@ public class I2PSnarkServlet extends BasicServlet {
private static final String DEFAULT_NAME = "i2psnark";
public static final String PROP_CONFIG_FILE = "i2psnark.configFile";
private static final int PAGE_SIZE = 50;
public I2PSnarkServlet() {
super();
@@ -506,10 +505,11 @@ public class I2PSnarkServlet extends BasicServlet {
start = Math.max(0, Math.min(snarks.size() - 1, Integer.parseInt(stParam)));
} catch (NumberFormatException nfe) {}
}
int pageSize = _manager.getPageSize();
for (int i = 0; i < snarks.size(); i++) {
Snark snark = (Snark)snarks.get(i);
boolean showPeers = showDebug || "1".equals(peerParam) || Base64.encode(snark.getInfoHash()).equals(peerParam);
boolean hide = i < start || i >= start + PAGE_SIZE;
boolean hide = i < start || i >= start + pageSize;
displaySnark(out, snark, uri, i, stats, showPeers, isDegraded, noThinsp, showDebug, hide);
}
@@ -523,7 +523,7 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<tfoot><tr>\n" +
" <th align=\"left\" colspan=\"6\">");
if (start > 0) {
int prev = Math.max(0, start - PAGE_SIZE);
int prev = Math.max(0, start - pageSize);
out.write("&nbsp;<a href=\"" + _contextPath + "?st=" + prev);
if (peerParam != null)
out.write("&p=" + peerParam);
@@ -532,8 +532,8 @@ public class I2PSnarkServlet extends BasicServlet {
_imgPath + "control_rewind_blue.png\">" +
"</a>&nbsp;");
}
if (start + PAGE_SIZE < snarks.size()) {
int next = start + PAGE_SIZE;
if (start + pageSize < snarks.size()) {
int next = start + pageSize;
out.write("&nbsp;<a href=\"" + _contextPath + "?st=" + next);
if (peerParam != null)
out.write("&p=" + peerParam);
@@ -792,11 +792,12 @@ public class I2PSnarkServlet extends BasicServlet {
String upBW = req.getParameter("upBW");
String refreshDel = req.getParameter("refreshDelay");
String startupDel = req.getParameter("startupDelay");
String pageSize = req.getParameter("pageSize");
boolean useOpenTrackers = req.getParameter("useOpenTrackers") != null;
boolean useDHT = req.getParameter("useDHT") != null;
//String openTrackers = req.getParameter("openTrackers");
String theme = req.getParameter("theme");
_manager.updateConfig(dataDir, filesPublic, autoStart, refreshDel, startupDel,
_manager.updateConfig(dataDir, filesPublic, autoStart, refreshDel, startupDel, pageSize,
seedPct, eepHost, eepPort, i2cpHost, i2cpPort, i2cpOpts,
upLimit, upBW, useOpenTrackers, useDHT, theme);
} else if ("Save2".equals(action)) {
@@ -1719,10 +1720,7 @@ public class I2PSnarkServlet extends BasicServlet {
"<table border=\"0\"><tr><td>");
out.write(_("Data directory"));
out.write(": <td><code>" + dataDir + "</code> <i>(");
// translators: parameter is a file name
out.write(_("Edit {0} and restart to change", _manager.getConfigFilename()));
out.write(")</i><br>\n" +
out.write(": <td><input name=\"dataDir\" size=\"80\" value=\"" + dataDir + "\"></td>\n" +
"<tr><td>");
out.write(_("Files readable by all"));
@@ -1774,8 +1772,14 @@ public class I2PSnarkServlet extends BasicServlet {
"<tr><td>");
out.write(_("Startup delay"));
out.write(": <td><input name=\"startupDelay\" size=\"3\" class=\"r\" value=\"" + _manager.util().getStartupDelay() + "\"> ");
out.write(": <td><input name=\"startupDelay\" size=\"4\" class=\"r\" value=\"" + _manager.util().getStartupDelay() + "\"> ");
out.write(_("minutes"));
out.write("<br>\n" +
"<tr><td>");
out.write(_("Page size"));
out.write(": <td><input name=\"pageSize\" size=\"4\" maxlength=\"6\" class=\"r\" value=\"" + _manager.getPageSize() + "\"> ");
out.write(_("torrents"));
out.write("<br>\n");
@@ -1801,7 +1805,7 @@ public class I2PSnarkServlet extends BasicServlet {
out.write("<tr><td>");
out.write(_("Total uploader limit"));
out.write(": <td><input type=\"text\" name=\"upLimit\" class=\"r\" value=\""
+ _manager.util().getMaxUploaders() + "\" size=\"3\" maxlength=\"3\" > ");
+ _manager.util().getMaxUploaders() + "\" size=\"4\" maxlength=\"3\" > ");
out.write(_("peers"));
out.write("<br>\n" +