Split torrent info and dir info on snark filemanager into two separate tables

This commit is contained in:
str4d
2012-07-08 21:35:49 +00:00
parent 78691ba344
commit fb629404c6

View File

@ -2049,40 +2049,68 @@ public class I2PSnarkServlet extends DefaultServlet {
boolean showPriority = ls != null && snark != null && snark.getStorage() != null && !snark.getStorage().complete(); boolean showPriority = ls != null && snark != null && snark.getStorage() != null && !snark.getStorage().complete();
if (showPriority) if (showPriority)
buf.append("<form action=\"").append(base).append("\" method=\"POST\">\n"); buf.append("<form action=\"").append(base).append("\" method=\"POST\">\n");
buf.append("<TABLE BORDER=0 class=\"snarkTorrents\" ><thead>\n");
if (snark != null) { if (snark != null) {
// first row - torrent info // first table - torrent info
// FIXME center buf.append("<table class=\"snarkTorrentInfo\">\n");
buf.append("<tr><th colspan=\"" + (showPriority ? '5' : '4') + "\"><div>") buf.append("<tr><th>")
.append(_("Torrent")).append(": ").append(snark.getBaseName()); .append(_("Torrent"))
.append(":</th><td>")
.append(snark.getBaseName())
.append("</td></tr>\n");
int pieces = snark.getPieces(); int pieces = snark.getPieces();
double completion = (pieces - snark.getNeeded()) / (double) pieces; double completion = (pieces - snark.getNeeded()) / (double) pieces;
if (completion < 1.0) if (completion < 1.0)
buf.append("<br>").append(_("Completion")).append(": ").append((new DecimalFormat("0.00%")).format(completion)); buf.append("<tr><th>")
.append(_("Completion"))
.append(":</th><td>")
.append((new DecimalFormat("0.00%")).format(completion))
.append("</td></tr>\n");
else else
buf.append("<br>").append(_("Complete")); buf.append("<tr><td colspan=\"2\">")
.append(_("Complete"))
.append("</td></tr>\n");
// else unknown // else unknown
long needed = snark.getNeededLength(); long needed = snark.getNeededLength();
if (needed > 0) if (needed > 0)
buf.append("<br>").append(_("Remaining")).append(": ").append(formatSize(needed)); buf.append("<tr><th>")
buf.append("<br>").append(_("Size")).append(": ").append(formatSize(snark.getTotalLength())); .append(_("Remaining"))
.append(":</th><td>")
.append(formatSize(needed))
.append("</td></tr>\n");
buf.append("<tr><th>")
.append(_("Size"))
.append(":</th><td>")
.append(formatSize(snark.getTotalLength()))
.append("</td></tr>\n");
MetaInfo meta = snark.getMetaInfo(); MetaInfo meta = snark.getMetaInfo();
if (meta != null) { if (meta != null) {
List files = meta.getFiles(); List files = meta.getFiles();
int fileCount = files != null ? files.size() : 1; int fileCount = files != null ? files.size() : 1;
buf.append("<br>").append(_("Files")).append(": ").append(fileCount); buf.append("<tr><th>")
.append(_("Files"))
.append(":</th><td>")
.append(fileCount)
.append("</td></tr>\n");
} }
buf.append("<br>").append(_("Pieces")).append(": ").append(pieces); buf.append("<tr><th>")
buf.append("<br>").append(_("Piece size")).append(": ").append(formatSize(snark.getPieceLength(0))); .append(_("Pieces"))
.append(":</th><td>")
.append(pieces)
.append("</td></tr>\n");
buf.append("<tr><th>")
.append(_("Piece size"))
.append(":</th><td>")
.append(formatSize(snark.getPieceLength(0)))
.append("</td></tr>\n");
if (meta != null) { if (meta != null) {
String announce = meta.getAnnounce(); String announce = meta.getAnnounce();
if (announce != null) { if (announce != null) {
buf.append("<br>"); buf.append("<tr><th>");
String trackerLink = getTrackerLink(announce, snark.getInfoHash()); String trackerLink = getTrackerLink(announce, snark.getInfoHash());
if (trackerLink != null) if (trackerLink != null)
buf.append(trackerLink).append(' '); buf.append(trackerLink).append(' ');
buf.append(_("Tracker")).append(": "); buf.append(_("Tracker")).append(":</th><td>");
if (announce.startsWith("http://")) if (announce.startsWith("http://"))
announce = announce.substring(7); announce = announce.substring(7);
int slsh = announce.indexOf('/'); int slsh = announce.indexOf('/');
@ -2090,23 +2118,31 @@ public class I2PSnarkServlet extends DefaultServlet {
announce = announce.substring(0, slsh); announce = announce.substring(0, slsh);
if (announce.length() > 67) if (announce.length() > 67)
announce = announce.substring(0, 40) + "&hellip;" + announce.substring(announce.length() - 8); announce = announce.substring(0, 40) + "&hellip;" + announce.substring(announce.length() - 8);
buf.append(announce); buf.append(announce).append("</td></tr>");
} }
} }
String hex = I2PSnarkUtil.toHex(snark.getInfoHash()); String hex = I2PSnarkUtil.toHex(snark.getInfoHash());
if (meta == null || !meta.isPrivate()) { if (meta == null || !meta.isPrivate()) {
buf.append("<br>").append(toImg("magnet", _("Magnet link"))).append(" <a href=\"") buf.append("<tr><th>")
.append(toImg("magnet", _("Magnet link")))
.append("</th><td><a href=\"")
.append(MAGNET_FULL).append(hex).append("\">") .append(MAGNET_FULL).append(hex).append("\">")
.append(MAGNET_FULL).append(hex).append("</a>"); .append(MAGNET_FULL).append(hex).append("</a>")
.append("</td></tr>\n");
} else { } else {
buf.append("<br>").append(_("Private torrent")); buf.append("<tr><td colspan=\"2\">")
.append(_("Private torrent"))
.append("</td></tr>\n");
} }
// We don't have the hash of the torrent file // We don't have the hash of the torrent file
//buf.append("<br>").append(_("Maggot link")).append(": <a href=\"").append(MAGGOT).append(hex).append(':').append(hex).append("\">") //buf.append("<tr><th>").append(_("Maggot link")).append(":</th><td><a href=\"").append(MAGGOT).append(hex).append(':').append(hex).append("\">")
// .append(MAGGOT).append(hex).append(':').append(hex).append("</a>"); // .append(MAGGOT).append(hex).append(':').append(hex).append("</a></td></tr>");
buf.append("<br>").append(_("Torrent file")).append(": ").append(snark.getName()); buf.append("<tr><th>")
buf.append("</div></th></tr>\n"); .append(_("Torrent file"))
.append(":</th><td>")
.append(snark.getName())
.append("</td></tr>\n");
} else { } else {
// shouldn't happen // shouldn't happen
buf.append("<tr><th>Not found<br>resource=\"").append(r.toString()) buf.append("<tr><th>Not found<br>resource=\"").append(r.toString())
@ -2114,13 +2150,15 @@ public class I2PSnarkServlet extends DefaultServlet {
.append("\"<br>torrent=\"").append(torrentName) .append("\"<br>torrent=\"").append(torrentName)
.append("\"</th></tr>\n"); .append("\"</th></tr>\n");
} }
buf.append("</table>\n");
if (ls == null) { if (ls == null) {
// We are only showing the torrent info section // We are only showing the torrent info section
buf.append("</thead></table></div></div></BODY></HTML>"); buf.append("</div></div></BODY></HTML>");
return buf.toString(); return buf.toString();
} }
// second row - dir info // second table - dir info
buf.append("<table class=\"snarkDirInfo\"><thead>\n");
buf.append("<tr>\n") buf.append("<tr>\n")
.append("<th colspan=2>") .append("<th colspan=2>")
.append("<img alt=\"\" border=\"0\" src=\"" + _imgPath + "file.png\" >&nbsp;") .append("<img alt=\"\" border=\"0\" src=\"" + _imgPath + "file.png\" >&nbsp;")
@ -2273,11 +2311,11 @@ public class I2PSnarkServlet extends DefaultServlet {
buf.append(_("Save priorities")); buf.append(_("Save priorities"));
buf.append("\" name=\"foo\" ></th></tr></thead>\n"); buf.append("\" name=\"foo\" ></th></tr></thead>\n");
} }
buf.append("</TABLE>\n"); buf.append("</table>\n");
if (showPriority) if (showPriority)
buf.append("</form>"); buf.append("</form>");
buf.append("</div></div></BODY></HTML>\n"); buf.append("</div></div></BODY></HTML>\n");
return buf.toString(); return buf.toString();
} }