Compare commits
40 Commits
partial-pi
...
split-ui
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a54b2dcda | ||
|
|
581293b24f | ||
|
|
cd072b9f76 | ||
|
|
6b74fc5956 | ||
|
|
3de2f872bb | ||
|
|
fcde917d08 | ||
|
|
4ded065010 | ||
|
|
18a1c7091a | ||
|
|
46aee19f80 | ||
|
|
92dd7064c6 | ||
|
|
b2e4dda677 | ||
|
|
e77a2c8961 | ||
|
|
ee2fd2ef68 | ||
|
|
3f95d2bf1d | ||
|
|
1390983732 | ||
|
|
ce660cefe9 | ||
|
|
72b81eb886 | ||
|
|
57d593a68a | ||
|
|
39a81a3376 | ||
|
|
fd0bf17c24 | ||
|
|
ac12bff69b | ||
|
|
feef773bac | ||
|
|
239d8f12a7 | ||
|
|
8bbc61a7cb | ||
|
|
7f31c4477f | ||
|
|
6bad67c1bf | ||
|
|
c76e6dc99f | ||
|
|
acf9db0db3 | ||
|
|
69b4f0b547 | ||
|
|
80e165b505 | ||
|
|
bcce55b873 | ||
|
|
d5c92560db | ||
|
|
f827c1c9bf | ||
|
|
88c5f1a02d | ||
|
|
d8e44f5f39 | ||
|
|
72ff47ffe5 | ||
|
|
066ee2c96d | ||
|
|
0a8016dea7 | ||
|
|
db36367b11 | ||
|
|
b6c9ccb7f6 |
@@ -25,7 +25,11 @@ Some of the UI tests will fail because they haven't been written yet :-/
|
|||||||
|
|
||||||
After you build the application, look inside `gui/build/distributions`. Untar/unzip one of the `shadow` files and then run the jar contained inside by typing `java -jar MuWire-x.y.z.jar` in a terminal or command prompt.
|
After you build the application, look inside `gui/build/distributions`. Untar/unzip one of the `shadow` files and then run the jar contained inside by typing `java -jar MuWire-x.y.z.jar` in a terminal or command prompt.
|
||||||
|
|
||||||
If you have an I2P router running on the same machine that is all you need to do. If you use a custom I2CP host and port, create a file `$HOME/.MuWire/i2p.properties` and put `i2cp.tcp.host=<host>` and `i2cp.tcp.port=<port>` in there.
|
If you have an I2P router running on the same machine that is all you need to do. If you use a custom I2CP host and port, create a file `i2p.properties` and put `i2cp.tcp.host=<host>` and `i2cp.tcp.port=<port>` in there. On Windows that file should go into `%HOME%\AppData\Roaming\MuWire`, on Mac into `$HOME/Library/Application Support/MuWire` and on Linux `$HOME/.MuWire`
|
||||||
|
|
||||||
If you do not have an I2P router, pass the following switch to the Java process: `-DembeddedRouter=true`. This will launch MuWire's embedded router. Be aware that this causes startup to take a lot longer.
|
If you do not have an I2P router, pass the following switch to the Java process: `-DembeddedRouter=true`. This will launch MuWire's embedded router. Be aware that this causes startup to take a lot longer.
|
||||||
|
|
||||||
|
### GPG Fingerprint
|
||||||
|
471B 9FD4 5517 A5ED 101F C57D A728 3207 2D52 5E41
|
||||||
|
|
||||||
|
You can find the full key at https://keybase.io/zlatinb
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Cli {
|
|||||||
|
|
||||||
Core core
|
Core core
|
||||||
try {
|
try {
|
||||||
core = new Core(props, home, "0.4.7")
|
core = new Core(props, home, "0.4.9")
|
||||||
} catch (Exception bad) {
|
} catch (Exception bad) {
|
||||||
bad.printStackTrace(System.out)
|
bad.printStackTrace(System.out)
|
||||||
println "Failed to initialize core, exiting"
|
println "Failed to initialize core, exiting"
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class CliDownloader {
|
|||||||
|
|
||||||
Core core
|
Core core
|
||||||
try {
|
try {
|
||||||
core = new Core(props, home, "0.4.7")
|
core = new Core(props, home, "0.4.9")
|
||||||
} catch (Exception bad) {
|
} catch (Exception bad) {
|
||||||
bad.printStackTrace(System.out)
|
bad.printStackTrace(System.out)
|
||||||
println "Failed to initialize core, exiting"
|
println "Failed to initialize core, exiting"
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ import com.muwire.core.trust.TrustSubscriptionEvent
|
|||||||
import com.muwire.core.update.UpdateClient
|
import com.muwire.core.update.UpdateClient
|
||||||
import com.muwire.core.upload.UploadManager
|
import com.muwire.core.upload.UploadManager
|
||||||
import com.muwire.core.util.MuWireLogManager
|
import com.muwire.core.util.MuWireLogManager
|
||||||
|
import com.muwire.core.content.ContentControlEvent
|
||||||
|
import com.muwire.core.content.ContentManager
|
||||||
|
|
||||||
import groovy.util.logging.Log
|
import groovy.util.logging.Log
|
||||||
import net.i2p.I2PAppContext
|
import net.i2p.I2PAppContext
|
||||||
@@ -90,6 +92,7 @@ public class Core {
|
|||||||
private final DirectoryWatcher directoryWatcher
|
private final DirectoryWatcher directoryWatcher
|
||||||
final FileManager fileManager
|
final FileManager fileManager
|
||||||
final UploadManager uploadManager
|
final UploadManager uploadManager
|
||||||
|
final ContentManager contentManager
|
||||||
|
|
||||||
private final Router router
|
private final Router router
|
||||||
|
|
||||||
@@ -289,6 +292,11 @@ public class Core {
|
|||||||
trustSubscriber = new TrustSubscriber(eventBus, i2pConnector, props)
|
trustSubscriber = new TrustSubscriber(eventBus, i2pConnector, props)
|
||||||
eventBus.register(UILoadedEvent.class, trustSubscriber)
|
eventBus.register(UILoadedEvent.class, trustSubscriber)
|
||||||
eventBus.register(TrustSubscriptionEvent.class, trustSubscriber)
|
eventBus.register(TrustSubscriptionEvent.class, trustSubscriber)
|
||||||
|
|
||||||
|
log.info("initializing content manager")
|
||||||
|
contentManager = new ContentManager()
|
||||||
|
eventBus.register(ContentControlEvent.class, contentManager)
|
||||||
|
eventBus.register(QueryEvent.class, contentManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startServices() {
|
public void startServices() {
|
||||||
@@ -353,7 +361,7 @@ public class Core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Core core = new Core(props, home, "0.4.7")
|
Core core = new Core(props, home, "0.4.9")
|
||||||
core.startServices()
|
core.startServices()
|
||||||
|
|
||||||
// ... at the end, sleep or execute script
|
// ... at the end, sleep or execute script
|
||||||
|
|||||||
@@ -48,4 +48,9 @@ class EventBus {
|
|||||||
}
|
}
|
||||||
currentHandlers.add handler
|
currentHandlers.add handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized void unregister(Class<? extends Event> eventType, def handler) {
|
||||||
|
log.info("Unregistering $handler for type $eventType")
|
||||||
|
handlers[eventType]?.remove(handler)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class MuWireSettings {
|
|||||||
int meshExpiration
|
int meshExpiration
|
||||||
boolean embeddedRouter
|
boolean embeddedRouter
|
||||||
int inBw, outBw
|
int inBw, outBw
|
||||||
|
Set<String> watchedKeywords
|
||||||
|
Set<String> watchedRegexes
|
||||||
|
|
||||||
MuWireSettings() {
|
MuWireSettings() {
|
||||||
this(new Properties())
|
this(new Properties())
|
||||||
@@ -54,11 +56,9 @@ class MuWireSettings {
|
|||||||
inBw = Integer.valueOf(props.getProperty("inBw","256"))
|
inBw = Integer.valueOf(props.getProperty("inBw","256"))
|
||||||
outBw = Integer.valueOf(props.getProperty("outBw","128"))
|
outBw = Integer.valueOf(props.getProperty("outBw","128"))
|
||||||
|
|
||||||
watchedDirectories = new HashSet<>()
|
watchedDirectories = readEncodedSet(props, "watchedDirectories")
|
||||||
if (props.containsKey("watchedDirectories")) {
|
watchedKeywords = readEncodedSet(props, "watchedKeywords")
|
||||||
String[] encoded = props.getProperty("watchedDirectories").split(",")
|
watchedRegexes = readEncodedSet(props, "watchedRegexes")
|
||||||
encoded.each { watchedDirectories << DataUtil.readi18nString(Base64.decode(it)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
trustSubscriptions = new HashSet<>()
|
trustSubscriptions = new HashSet<>()
|
||||||
if (props.containsKey("trustSubscriptions")) {
|
if (props.containsKey("trustSubscriptions")) {
|
||||||
@@ -66,6 +66,8 @@ class MuWireSettings {
|
|||||||
trustSubscriptions.add(new Persona(new ByteArrayInputStream(Base64.decode(it))))
|
trustSubscriptions.add(new Persona(new ByteArrayInputStream(Base64.decode(it))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(OutputStream out) throws IOException {
|
void write(OutputStream out) throws IOException {
|
||||||
@@ -89,12 +91,9 @@ class MuWireSettings {
|
|||||||
props.setProperty("inBw", String.valueOf(inBw))
|
props.setProperty("inBw", String.valueOf(inBw))
|
||||||
props.setProperty("outBw", String.valueOf(outBw))
|
props.setProperty("outBw", String.valueOf(outBw))
|
||||||
|
|
||||||
if (!watchedDirectories.isEmpty()) {
|
writeEncodedSet(watchedDirectories, "watchedDirectories", props)
|
||||||
String encoded = watchedDirectories.stream().
|
writeEncodedSet(watchedKeywords, "watchedKeywords", props)
|
||||||
map({Base64.encode(DataUtil.encodei18nString(it))}).
|
writeEncodedSet(watchedRegexes, "watchedRegexes", props)
|
||||||
collect(Collectors.joining(","))
|
|
||||||
props.setProperty("watchedDirectories", encoded)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!trustSubscriptions.isEmpty()) {
|
if (!trustSubscriptions.isEmpty()) {
|
||||||
String encoded = trustSubscriptions.stream().
|
String encoded = trustSubscriptions.stream().
|
||||||
@@ -105,6 +104,24 @@ class MuWireSettings {
|
|||||||
|
|
||||||
props.store(out, "")
|
props.store(out, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Set<String> readEncodedSet(Properties props, String property) {
|
||||||
|
Set<String> rv = new HashSet<>()
|
||||||
|
if (props.containsKey(property)) {
|
||||||
|
String[] encoded = props.getProperty(property).split(",")
|
||||||
|
encoded.each { rv << DataUtil.readi18nString(Base64.decode(it)) }
|
||||||
|
}
|
||||||
|
rv
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeEncodedSet(Set<String> set, String property, Properties props) {
|
||||||
|
if (set.isEmpty())
|
||||||
|
return
|
||||||
|
String encoded = set.stream().
|
||||||
|
map({Base64.encode(DataUtil.encodei18nString(it))}).
|
||||||
|
collect(Collectors.joining(","))
|
||||||
|
props.setProperty(property, encoded)
|
||||||
|
}
|
||||||
|
|
||||||
boolean isLeaf() {
|
boolean isLeaf() {
|
||||||
isLeaf
|
isLeaf
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.muwire.core.content
|
||||||
|
|
||||||
|
import com.muwire.core.Event
|
||||||
|
|
||||||
|
class ContentControlEvent extends Event {
|
||||||
|
String term
|
||||||
|
boolean regex
|
||||||
|
boolean add
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.muwire.core.content
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
|
import com.muwire.core.search.QueryEvent
|
||||||
|
|
||||||
|
import net.i2p.util.ConcurrentHashSet
|
||||||
|
|
||||||
|
class ContentManager {
|
||||||
|
|
||||||
|
Set<Matcher> matchers = new ConcurrentHashSet()
|
||||||
|
|
||||||
|
void onContentControlEvent(ContentControlEvent e) {
|
||||||
|
Matcher m
|
||||||
|
if (e.regex)
|
||||||
|
m = new RegexMatcher(e.term)
|
||||||
|
else
|
||||||
|
m = new KeywordMatcher(e.term)
|
||||||
|
if (e.add)
|
||||||
|
matchers.add(m)
|
||||||
|
else
|
||||||
|
matchers.remove(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
void onQueryEvent(QueryEvent e) {
|
||||||
|
if (e.searchEvent.searchTerms == null)
|
||||||
|
return
|
||||||
|
matchers.each { it.process(e) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.muwire.core.content
|
||||||
|
|
||||||
|
class KeywordMatcher extends Matcher {
|
||||||
|
private final String keyword
|
||||||
|
KeywordMatcher(String keyword) {
|
||||||
|
this.keyword = keyword
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean match(List<String> searchTerms) {
|
||||||
|
boolean found = false
|
||||||
|
searchTerms.each {
|
||||||
|
if (keyword == it)
|
||||||
|
found = true
|
||||||
|
}
|
||||||
|
found
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTerm() {
|
||||||
|
keyword
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
keyword.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof KeywordMatcher))
|
||||||
|
return false
|
||||||
|
KeywordMatcher other = (KeywordMatcher) o
|
||||||
|
keyword.equals(other.keyword)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.muwire.core.content
|
||||||
|
|
||||||
|
import com.muwire.core.Persona
|
||||||
|
|
||||||
|
class Match {
|
||||||
|
Persona persona
|
||||||
|
String [] keywords
|
||||||
|
long timestamp
|
||||||
|
}
|
||||||
20
core/src/main/groovy/com/muwire/core/content/Matcher.groovy
Normal file
20
core/src/main/groovy/com/muwire/core/content/Matcher.groovy
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.muwire.core.content
|
||||||
|
|
||||||
|
import com.muwire.core.search.QueryEvent
|
||||||
|
|
||||||
|
abstract class Matcher {
|
||||||
|
final List<Match> matches = Collections.synchronizedList(new ArrayList<>())
|
||||||
|
final Set<UUID> uuids = new HashSet<>()
|
||||||
|
|
||||||
|
protected abstract boolean match(List<String> searchTerms);
|
||||||
|
|
||||||
|
public abstract String getTerm();
|
||||||
|
|
||||||
|
public void process(QueryEvent qe) {
|
||||||
|
def terms = qe.searchEvent.searchTerms
|
||||||
|
if (match(terms) && uuids.add(qe.searchEvent.uuid)) {
|
||||||
|
long now = System.currentTimeMillis()
|
||||||
|
matches << new Match(persona : qe.originator, keywords : terms, timestamp : now)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.muwire.core.content
|
||||||
|
|
||||||
|
import java.util.regex.Pattern
|
||||||
|
import java.util.stream.Collectors
|
||||||
|
|
||||||
|
class RegexMatcher extends Matcher {
|
||||||
|
private final Pattern pattern
|
||||||
|
RegexMatcher(String pattern) {
|
||||||
|
this.pattern = Pattern.compile(pattern)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean match(List<String> keywords) {
|
||||||
|
String combined = keywords.join(" ")
|
||||||
|
return pattern.matcher(combined).find()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTerm() {
|
||||||
|
pattern.pattern()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
pattern.pattern().hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof RegexMatcher))
|
||||||
|
return false
|
||||||
|
RegexMatcher other = (RegexMatcher) o
|
||||||
|
pattern.pattern() == other.pattern.pattern()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,11 +79,12 @@ class DownloadSession {
|
|||||||
return false
|
return false
|
||||||
int piece = pieceAndPosition[0]
|
int piece = pieceAndPosition[0]
|
||||||
int position = pieceAndPosition[1]
|
int position = pieceAndPosition[1]
|
||||||
|
boolean steal = pieceAndPosition[2] == 1
|
||||||
boolean unclaim = true
|
boolean unclaim = true
|
||||||
|
|
||||||
log.info("will download piece $piece from position $position")
|
log.info("will download piece $piece from position $position steal $steal")
|
||||||
|
|
||||||
long pieceStart = piece * pieceSize
|
long pieceStart = piece * ((long)pieceSize)
|
||||||
long end = Math.min(fileLength, pieceStart + pieceSize) - 1
|
long end = Math.min(fileLength, pieceStart + pieceSize) - 1
|
||||||
long start = pieceStart + position
|
long start = pieceStart + position
|
||||||
String root = Base64.encode(infoHash.getRoot())
|
String root = Base64.encode(infoHash.getRoot())
|
||||||
@@ -208,7 +209,7 @@ class DownloadSession {
|
|||||||
pieces.markDownloaded(piece)
|
pieces.markDownloaded(piece)
|
||||||
unclaim = false
|
unclaim = false
|
||||||
} finally {
|
} finally {
|
||||||
if (unclaim)
|
if (unclaim && !steal)
|
||||||
pieces.unclaim(piece)
|
pieces.unclaim(piece)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -314,6 +314,10 @@ public class Downloader {
|
|||||||
piecesFileClosed = true
|
piecesFileClosed = true
|
||||||
piecesFile.delete()
|
piecesFile.delete()
|
||||||
}
|
}
|
||||||
|
activeWorkers.values().each {
|
||||||
|
if (it.destination != destination)
|
||||||
|
it.cancel()
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Files.move(incompleteFile.toPath(), file.toPath(), StandardCopyOption.ATOMIC_MOVE)
|
Files.move(incompleteFile.toPath(), file.toPath(), StandardCopyOption.ATOMIC_MOVE)
|
||||||
} catch (AtomicMoveNotSupportedException e) {
|
} catch (AtomicMoveNotSupportedException e) {
|
||||||
|
|||||||
@@ -20,14 +20,20 @@ class Pieces {
|
|||||||
|
|
||||||
synchronized int[] claim() {
|
synchronized int[] claim() {
|
||||||
int claimedCardinality = claimed.cardinality()
|
int claimedCardinality = claimed.cardinality()
|
||||||
if (claimedCardinality == nPieces)
|
if (claimedCardinality == nPieces) {
|
||||||
return null
|
// steal
|
||||||
|
int downloadedCardinality = done.cardinality()
|
||||||
|
if (downloadedCardinality == nPieces)
|
||||||
|
return null
|
||||||
|
int rv = done.nextClearBit(0)
|
||||||
|
return [rv, partials.getOrDefault(rv, 0), 1]
|
||||||
|
}
|
||||||
|
|
||||||
// if fuller than ratio just do sequential
|
// if fuller than ratio just do sequential
|
||||||
if ( (1.0f * claimedCardinality) / nPieces > ratio) {
|
if ( (1.0f * claimedCardinality) / nPieces > ratio) {
|
||||||
int rv = claimed.nextClearBit(0)
|
int rv = claimed.nextClearBit(0)
|
||||||
claimed.set(rv)
|
claimed.set(rv)
|
||||||
return [rv, partials.getOrDefault(rv, 0)]
|
return [rv, partials.getOrDefault(rv, 0), 0]
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
@@ -35,20 +41,28 @@ class Pieces {
|
|||||||
if (claimed.get(start))
|
if (claimed.get(start))
|
||||||
continue
|
continue
|
||||||
claimed.set(start)
|
claimed.set(start)
|
||||||
return [start, partials.getOrDefault(start,0)]
|
return [start, partials.getOrDefault(start,0), 0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized int[] claim(Set<Integer> available) {
|
synchronized int[] claim(Set<Integer> available) {
|
||||||
for (int i = claimed.nextSetBit(0); i >= 0; i = claimed.nextSetBit(i+1))
|
for (int i = done.nextSetBit(0); i >= 0; i = done.nextSetBit(i+1))
|
||||||
available.remove(i)
|
available.remove(i)
|
||||||
if (available.isEmpty())
|
if (available.isEmpty())
|
||||||
return -1
|
return null
|
||||||
List<Integer> toList = available.toList()
|
Set<Integer> availableCopy = new HashSet<>(available)
|
||||||
|
for (int i = claimed.nextSetBit(0); i >= 0; i = claimed.nextSetBit(i+1))
|
||||||
|
availableCopy.remove(i)
|
||||||
|
if (availableCopy.isEmpty()) {
|
||||||
|
// steal
|
||||||
|
int rv = available.first()
|
||||||
|
return [rv, partials.getOrDefault(rv, 0), 1]
|
||||||
|
}
|
||||||
|
List<Integer> toList = availableCopy.toList()
|
||||||
Collections.shuffle(toList)
|
Collections.shuffle(toList)
|
||||||
int rv = toList[0]
|
int rv = toList[0]
|
||||||
claimed.set(rv)
|
claimed.set(rv)
|
||||||
[rv, partials.getOrDefault(rv, 0)]
|
[rv, partials.getOrDefault(rv, 0), 0]
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized def getDownloaded() {
|
synchronized def getDownloaded() {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class ContentUploader extends Uploader {
|
|||||||
String xHave = DataUtil.encodeXHave(mesh.pieces.getDownloaded(), mesh.pieces.nPieces)
|
String xHave = DataUtil.encodeXHave(mesh.pieces.getDownloaded(), mesh.pieces.nPieces)
|
||||||
endpoint.getOutputStream().write("X-Have: $xHave\r\n".getBytes(StandardCharsets.US_ASCII))
|
endpoint.getOutputStream().write("X-Have: $xHave\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
|
|
||||||
Set<Persona> sources = mesh.getRandom(3, toExclude)
|
Set<Persona> sources = mesh.getRandom(9, toExclude)
|
||||||
if (!sources.isEmpty()) {
|
if (!sources.isEmpty()) {
|
||||||
String xAlts = sources.stream().map({ it.toBase64() }).collect(Collectors.joining(","))
|
String xAlts = sources.stream().map({ it.toBase64() }).collect(Collectors.joining(","))
|
||||||
endpoint.getOutputStream().write("X-Alt: $xAlts\r\n".getBytes(StandardCharsets.US_ASCII))
|
endpoint.getOutputStream().write("X-Alt: $xAlts\r\n".getBytes(StandardCharsets.US_ASCII))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
group = com.muwire
|
group = com.muwire
|
||||||
version = 0.4.7
|
version = 0.4.9
|
||||||
groovyVersion = 2.4.15
|
groovyVersion = 2.4.15
|
||||||
slf4jVersion = 1.7.25
|
slf4jVersion = 1.7.25
|
||||||
spockVersion = 1.1-groovy-2.4
|
spockVersion = 1.1-groovy-2.4
|
||||||
|
|||||||
34
gradlew
vendored
34
gradlew
vendored
@@ -11,21 +11,21 @@
|
|||||||
PRG="$0"
|
PRG="$0"
|
||||||
# Need this for relative symlinks.
|
# Need this for relative symlinks.
|
||||||
while [ -h "$PRG" ] ; do
|
while [ -h "$PRG" ] ; do
|
||||||
ls=`ls -ld "$PRG"`
|
ls=$(ls -ld "$PRG")
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
link=$(expr "$ls" : '.*-> \(.*\)$')
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
PRG="$link"
|
PRG="$link"
|
||||||
else
|
else
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
PRG=$(dirname "$PRG")"/$link"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
SAVED="$(pwd)"
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
cd "$(dirname "$PRG")/" >/dev/null
|
||||||
APP_HOME="`pwd -P`"
|
APP_HOME="$(pwd -P)"
|
||||||
cd "$SAVED" >/dev/null
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
APP_NAME="Gradle"
|
||||||
APP_BASE_NAME=`basename "$0"`
|
APP_BASE_NAME=$(basename "$0")
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS=""
|
DEFAULT_JVM_OPTS=""
|
||||||
@@ -49,7 +49,7 @@ cygwin=false
|
|||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$(uname)" in
|
||||||
CYGWIN* )
|
CYGWIN* )
|
||||||
cygwin=true
|
cygwin=true
|
||||||
;;
|
;;
|
||||||
@@ -90,7 +90,7 @@ fi
|
|||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
MAX_FD_LIMIT=$(ulimit -H -n)
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
@@ -111,12 +111,12 @@ fi
|
|||||||
|
|
||||||
# For Cygwin, switch paths to Windows format before running java
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
if $cygwin ; then
|
if $cygwin ; then
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
APP_HOME=$(cygpath --path --mixed "$APP_HOME")
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
CLASSPATH=$(cygpath --path --mixed "$CLASSPATH")
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
JAVACMD=$(cygpath --unix "$JAVACMD")
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null)
|
||||||
SEP=""
|
SEP=""
|
||||||
for dir in $ROOTDIRSRAW ; do
|
for dir in $ROOTDIRSRAW ; do
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
@@ -130,13 +130,13 @@ if $cygwin ; then
|
|||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
i=0
|
i=0
|
||||||
for arg in "$@" ; do
|
for arg in "$@" ; do
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
CHECK=$(echo "$arg"|egrep -c "$OURCYGPATTERN" -)
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
CHECK2=$(echo "$arg"|egrep -c "^-") ### Determine if an option
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
eval $(echo args$i)=$(cygpath --path --ignore --mixed "$arg")
|
||||||
else
|
else
|
||||||
eval `echo args$i`="\"$arg\""
|
eval $(echo args$i)="\"$arg\""
|
||||||
fi
|
fi
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -41,4 +41,9 @@ mvcGroups {
|
|||||||
view = 'com.muwire.gui.TrustListView'
|
view = 'com.muwire.gui.TrustListView'
|
||||||
controller = 'com.muwire.gui.TrustListController'
|
controller = 'com.muwire.gui.TrustListController'
|
||||||
}
|
}
|
||||||
|
'content-panel' {
|
||||||
|
model = 'com.muwire.gui.ContentPanelModel'
|
||||||
|
view = 'com.muwire.gui.ContentPanelView'
|
||||||
|
controller = 'com.muwire.gui.ContentPanelController'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import griffon.core.artifact.GriffonController
|
||||||
|
import griffon.core.controller.ControllerAction
|
||||||
|
import griffon.inject.MVCMember
|
||||||
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
|
import com.muwire.core.Core
|
||||||
|
import com.muwire.core.EventBus
|
||||||
|
import com.muwire.core.content.ContentControlEvent
|
||||||
|
import com.muwire.core.content.Match
|
||||||
|
import com.muwire.core.content.Matcher
|
||||||
|
import com.muwire.core.content.RegexMatcher
|
||||||
|
import com.muwire.core.trust.TrustEvent
|
||||||
|
import com.muwire.core.trust.TrustLevel
|
||||||
|
|
||||||
|
@ArtifactProviderFor(GriffonController)
|
||||||
|
class ContentPanelController {
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
ContentPanelModel model
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
ContentPanelView view
|
||||||
|
|
||||||
|
Core core
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void addRule() {
|
||||||
|
def term = view.ruleTextField.text
|
||||||
|
|
||||||
|
if (model.regex)
|
||||||
|
core.muOptions.watchedRegexes.add(term)
|
||||||
|
else
|
||||||
|
core.muOptions.watchedKeywords.add(term)
|
||||||
|
saveMuWireSettings()
|
||||||
|
|
||||||
|
core.eventBus.publish(new ContentControlEvent(term : term, regex : model.regex, add:true))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void deleteRule() {
|
||||||
|
int rule = view.getSelectedRule()
|
||||||
|
if (rule < 0)
|
||||||
|
return
|
||||||
|
Matcher matcher = model.rules[rule]
|
||||||
|
String term = matcher.getTerm()
|
||||||
|
if (matcher instanceof RegexMatcher)
|
||||||
|
core.muOptions.watchedRegexes.remove(term)
|
||||||
|
else
|
||||||
|
core.muOptions.watchedKeywords.remove(term)
|
||||||
|
saveMuWireSettings()
|
||||||
|
|
||||||
|
core.eventBus.publish(new ContentControlEvent(term : term, regex : (matcher instanceof RegexMatcher), add: false))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void keyword() {
|
||||||
|
model.regex = false
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void regex() {
|
||||||
|
model.regex = true
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void refresh() {
|
||||||
|
model.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void trust() {
|
||||||
|
int selectedHit = view.getSelectedHit()
|
||||||
|
if (selectedHit < 0)
|
||||||
|
return
|
||||||
|
Match m = model.hits[selectedHit]
|
||||||
|
core.eventBus.publish(new TrustEvent(persona : m.persona, level : TrustLevel.TRUSTED))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void distrust() {
|
||||||
|
int selectedHit = view.getSelectedHit()
|
||||||
|
if (selectedHit < 0)
|
||||||
|
return
|
||||||
|
Match m = model.hits[selectedHit]
|
||||||
|
core.eventBus.publish(new TrustEvent(persona : m.persona, level : TrustLevel.DISTRUSTED))
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveMuWireSettings() {
|
||||||
|
File f = new File(core.home, "MuWire.properties")
|
||||||
|
f.withOutputStream {
|
||||||
|
core.muOptions.write(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,6 +59,7 @@ class MainFrameController {
|
|||||||
Map<String, Object> params = new HashMap<>()
|
Map<String, Object> params = new HashMap<>()
|
||||||
params["search-terms"] = search
|
params["search-terms"] = search
|
||||||
params["uuid"] = uuid.toString()
|
params["uuid"] = uuid.toString()
|
||||||
|
params["core"] = core
|
||||||
def group = mvcGroup.createMVCGroup("SearchTab", uuid.toString(), params)
|
def group = mvcGroup.createMVCGroup("SearchTab", uuid.toString(), params)
|
||||||
model.results[uuid.toString()] = group
|
model.results[uuid.toString()] = group
|
||||||
|
|
||||||
@@ -96,6 +97,7 @@ class MainFrameController {
|
|||||||
Map<String, Object> params = new HashMap<>()
|
Map<String, Object> params = new HashMap<>()
|
||||||
params["search-terms"] = tabTitle
|
params["search-terms"] = tabTitle
|
||||||
params["uuid"] = uuid.toString()
|
params["uuid"] = uuid.toString()
|
||||||
|
params["core"] = core
|
||||||
def group = mvcGroup.createMVCGroup("SearchTab", uuid.toString(), params)
|
def group = mvcGroup.createMVCGroup("SearchTab", uuid.toString(), params)
|
||||||
model.results[uuid.toString()] = group
|
model.results[uuid.toString()] = group
|
||||||
|
|
||||||
@@ -106,20 +108,6 @@ class MainFrameController {
|
|||||||
originator : core.me))
|
originator : core.me))
|
||||||
}
|
}
|
||||||
|
|
||||||
private def selectedResult() {
|
|
||||||
def selected = builder.getVariable("result-tabs").getSelectedComponent()
|
|
||||||
def group = selected.getClientProperty("mvc-group")
|
|
||||||
def table = selected.getClientProperty("results-table")
|
|
||||||
int row = table.getSelectedRow()
|
|
||||||
if (row == -1)
|
|
||||||
return
|
|
||||||
def sortEvt = group.view.lastSortEvent
|
|
||||||
if (sortEvt != null) {
|
|
||||||
row = group.view.resultsTable.rowSorter.convertRowIndexToModel(row)
|
|
||||||
}
|
|
||||||
group.model.results[row]
|
|
||||||
}
|
|
||||||
|
|
||||||
private int selectedDownload() {
|
private int selectedDownload() {
|
||||||
def downloadsTable = builder.getVariable("downloads-table")
|
def downloadsTable = builder.getVariable("downloads-table")
|
||||||
def selected = downloadsTable.getSelectedRow()
|
def selected = downloadsTable.getSelectedRow()
|
||||||
@@ -130,39 +118,21 @@ class MainFrameController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void download() {
|
void trustPersonaFromSearch() {
|
||||||
def result = selectedResult()
|
int selected = builder.getVariable("searches-table").getSelectedRow()
|
||||||
if (result == null)
|
if (selected < 0)
|
||||||
return
|
return
|
||||||
|
Persona p = model.searches[selected].originator
|
||||||
if (!model.canDownload(result.infohash))
|
core.eventBus.publish( new TrustEvent(persona : p, level : TrustLevel.TRUSTED) )
|
||||||
return
|
|
||||||
|
|
||||||
def file = new File(application.context.get("muwire-settings").downloadLocation, result.name)
|
|
||||||
|
|
||||||
def selected = builder.getVariable("result-tabs").getSelectedComponent()
|
|
||||||
def group = selected.getClientProperty("mvc-group")
|
|
||||||
|
|
||||||
def resultsBucket = group.model.hashBucket[result.infohash]
|
|
||||||
def sources = group.model.sourcesBucket[result.infohash]
|
|
||||||
|
|
||||||
core.eventBus.publish(new UIDownloadEvent(result : resultsBucket, sources: sources, target : file))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void trust() {
|
void distrustPersonaFromSearch() {
|
||||||
def result = selectedResult()
|
int selected = builder.getVariable("searches-table").getSelectedRow()
|
||||||
if (result == null)
|
if (selected < 0)
|
||||||
return // TODO disable button
|
return
|
||||||
core.eventBus.publish( new TrustEvent(persona : result.sender, level : TrustLevel.TRUSTED))
|
Persona p = model.searches[selected].originator
|
||||||
}
|
core.eventBus.publish( new TrustEvent(persona : p, level : TrustLevel.DISTRUSTED) )
|
||||||
|
|
||||||
@ControllerAction
|
|
||||||
void distrust() {
|
|
||||||
def result = selectedResult()
|
|
||||||
if (result == null)
|
|
||||||
return // TODO disable button
|
|
||||||
core.eventBus.publish( new TrustEvent(persona : result.sender, level : TrustLevel.DISTRUSTED))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
|
|||||||
@@ -6,6 +6,65 @@ import griffon.inject.MVCMember
|
|||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
|
import com.muwire.core.Core
|
||||||
|
import com.muwire.core.download.UIDownloadEvent
|
||||||
|
import com.muwire.core.trust.TrustEvent
|
||||||
|
import com.muwire.core.trust.TrustLevel
|
||||||
|
|
||||||
@ArtifactProviderFor(GriffonController)
|
@ArtifactProviderFor(GriffonController)
|
||||||
class SearchTabController {
|
class SearchTabController {
|
||||||
|
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
SearchTabModel model
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
SearchTabView view
|
||||||
|
|
||||||
|
Core core
|
||||||
|
|
||||||
|
private def selectedResult() {
|
||||||
|
int row = view.resultsTable.getSelectedRow()
|
||||||
|
if (row == -1)
|
||||||
|
return null
|
||||||
|
def sortEvt = view.lastSortEvent
|
||||||
|
if (sortEvt != null) {
|
||||||
|
row = view.resultsTable.rowSorter.convertRowIndexToModel(row)
|
||||||
|
}
|
||||||
|
model.results[row]
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void download() {
|
||||||
|
def result = selectedResult()
|
||||||
|
if (result == null)
|
||||||
|
return
|
||||||
|
|
||||||
|
if (!mvcGroup.parentGroup.model.canDownload(result.infohash))
|
||||||
|
return
|
||||||
|
|
||||||
|
def file = new File(application.context.get("muwire-settings").downloadLocation, result.name)
|
||||||
|
|
||||||
|
def resultsBucket = model.hashBucket[result.infohash]
|
||||||
|
def sources = model.sourcesBucket[result.infohash]
|
||||||
|
|
||||||
|
core.eventBus.publish(new UIDownloadEvent(result : resultsBucket, sources: sources, target : file))
|
||||||
|
mvcGroup.parentGroup.view.showDownloadsWindow.call()
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void trust() {
|
||||||
|
int row = view.selectedSenderRow()
|
||||||
|
if (row < 0)
|
||||||
|
return
|
||||||
|
def sender = model.senders[row]
|
||||||
|
core.eventBus.publish( new TrustEvent(persona : sender, level : TrustLevel.TRUSTED))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void distrust() {
|
||||||
|
int row = view.selectedSenderRow()
|
||||||
|
if (row < 0)
|
||||||
|
return
|
||||||
|
def sender = model.senders[row]
|
||||||
|
core.eventBus.publish( new TrustEvent(persona : sender, level : TrustLevel.DISTRUSTED))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
|
import com.muwire.core.Core
|
||||||
|
import com.muwire.core.EventBus
|
||||||
|
import com.muwire.core.content.ContentControlEvent
|
||||||
|
import com.muwire.core.content.ContentManager
|
||||||
|
|
||||||
|
import griffon.core.artifact.GriffonModel
|
||||||
|
import griffon.inject.MVCMember
|
||||||
|
import griffon.transform.Observable
|
||||||
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
|
@ArtifactProviderFor(GriffonModel)
|
||||||
|
class ContentPanelModel {
|
||||||
|
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
ContentPanelView view
|
||||||
|
|
||||||
|
Core core
|
||||||
|
|
||||||
|
private ContentManager contentManager
|
||||||
|
|
||||||
|
def rules = []
|
||||||
|
def hits = []
|
||||||
|
|
||||||
|
@Observable boolean regex
|
||||||
|
@Observable boolean deleteButtonEnabled
|
||||||
|
@Observable boolean trustButtonsEnabled
|
||||||
|
|
||||||
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
|
contentManager = application.context.get("core").contentManager
|
||||||
|
rules.addAll(contentManager.matchers)
|
||||||
|
core.eventBus.register(ContentControlEvent.class, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
void mvcGroupDestroy() {
|
||||||
|
core.eventBus.unregister(ContentControlEvent.class, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
rules.clear()
|
||||||
|
rules.addAll(contentManager.matchers)
|
||||||
|
hits.clear()
|
||||||
|
view.rulesTable.model.fireTableDataChanged()
|
||||||
|
view.hitsTable.model.fireTableDataChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
void onContentControlEvent(ContentControlEvent e) {
|
||||||
|
runInsideUIAsync {
|
||||||
|
refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import com.muwire.core.RouterDisconnectedEvent
|
|||||||
import com.muwire.core.connection.ConnectionAttemptStatus
|
import com.muwire.core.connection.ConnectionAttemptStatus
|
||||||
import com.muwire.core.connection.ConnectionEvent
|
import com.muwire.core.connection.ConnectionEvent
|
||||||
import com.muwire.core.connection.DisconnectionEvent
|
import com.muwire.core.connection.DisconnectionEvent
|
||||||
|
import com.muwire.core.content.ContentControlEvent
|
||||||
import com.muwire.core.download.DownloadStartedEvent
|
import com.muwire.core.download.DownloadStartedEvent
|
||||||
import com.muwire.core.download.Downloader
|
import com.muwire.core.download.Downloader
|
||||||
import com.muwire.core.files.AllFilesLoadedEvent
|
import com.muwire.core.files.AllFilesLoadedEvent
|
||||||
@@ -75,8 +76,6 @@ class MainFrameModel {
|
|||||||
@Observable String me
|
@Observable String me
|
||||||
@Observable int loadedFiles
|
@Observable int loadedFiles
|
||||||
@Observable File hashingFile
|
@Observable File hashingFile
|
||||||
@Observable boolean downloadActionEnabled
|
|
||||||
@Observable boolean trustButtonsEnabled
|
|
||||||
@Observable boolean cancelButtonEnabled
|
@Observable boolean cancelButtonEnabled
|
||||||
@Observable boolean retryButtonEnabled
|
@Observable boolean retryButtonEnabled
|
||||||
@Observable boolean pauseButtonEnabled
|
@Observable boolean pauseButtonEnabled
|
||||||
@@ -89,6 +88,12 @@ class MainFrameModel {
|
|||||||
@Observable boolean reviewButtonEnabled
|
@Observable boolean reviewButtonEnabled
|
||||||
@Observable boolean updateButtonEnabled
|
@Observable boolean updateButtonEnabled
|
||||||
@Observable boolean unsubscribeButtonEnabled
|
@Observable boolean unsubscribeButtonEnabled
|
||||||
|
|
||||||
|
@Observable boolean searchesPaneButtonEnabled
|
||||||
|
@Observable boolean downloadsPaneButtonEnabled
|
||||||
|
@Observable boolean uploadsPaneButtonEnabled
|
||||||
|
@Observable boolean monitorPaneButtonEnabled
|
||||||
|
@Observable boolean trustPaneButtonEnabled
|
||||||
|
|
||||||
private final Set<InfoHash> infoHashes = new HashSet<>()
|
private final Set<InfoHash> infoHashes = new HashSet<>()
|
||||||
|
|
||||||
@@ -164,6 +169,13 @@ class MainFrameModel {
|
|||||||
core.eventBus.register(UpdateDownloadedEvent.class, this)
|
core.eventBus.register(UpdateDownloadedEvent.class, this)
|
||||||
core.eventBus.register(TrustSubscriptionUpdatedEvent.class, this)
|
core.eventBus.register(TrustSubscriptionUpdatedEvent.class, this)
|
||||||
|
|
||||||
|
core.muOptions.watchedKeywords.each {
|
||||||
|
core.eventBus.publish(new ContentControlEvent(term : it, regex: false, add: true))
|
||||||
|
}
|
||||||
|
core.muOptions.watchedRegexes.each {
|
||||||
|
core.eventBus.publish(new ContentControlEvent(term : it, regex: true, add: true))
|
||||||
|
}
|
||||||
|
|
||||||
timer.schedule({
|
timer.schedule({
|
||||||
if (core.shutdown.get())
|
if (core.shutdown.get())
|
||||||
return
|
return
|
||||||
@@ -192,6 +204,12 @@ class MainFrameModel {
|
|||||||
distrusted.addAll(core.trustService.bad.values())
|
distrusted.addAll(core.trustService.bad.values())
|
||||||
|
|
||||||
resumeButtonText = "Retry"
|
resumeButtonText = "Retry"
|
||||||
|
|
||||||
|
searchesPaneButtonEnabled = false
|
||||||
|
downloadsPaneButtonEnabled = true
|
||||||
|
uploadsPaneButtonEnabled = true
|
||||||
|
monitorPaneButtonEnabled = true
|
||||||
|
trustPaneButtonEnabled = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import javax.inject.Inject
|
|||||||
import javax.swing.JTable
|
import javax.swing.JTable
|
||||||
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
|
import com.muwire.core.Persona
|
||||||
import com.muwire.core.search.UIResultEvent
|
import com.muwire.core.search.UIResultEvent
|
||||||
|
|
||||||
import griffon.core.artifact.GriffonModel
|
import griffon.core.artifact.GriffonModel
|
||||||
@@ -17,14 +18,19 @@ import griffon.metadata.ArtifactProviderFor
|
|||||||
class SearchTabModel {
|
class SearchTabModel {
|
||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
FactoryBuilderSupport builder
|
FactoryBuilderSupport builder
|
||||||
|
|
||||||
|
@Observable boolean downloadActionEnabled
|
||||||
|
@Observable boolean trustButtonsEnabled
|
||||||
|
|
||||||
Core core
|
Core core
|
||||||
UISettings uiSettings
|
UISettings uiSettings
|
||||||
String uuid
|
String uuid
|
||||||
|
def senders = []
|
||||||
def results = []
|
def results = []
|
||||||
def hashBucket = [:]
|
def hashBucket = [:]
|
||||||
def sourcesBucket = [:]
|
def sourcesBucket = [:]
|
||||||
|
def sendersBucket = new LinkedHashMap<>()
|
||||||
|
|
||||||
|
|
||||||
void mvcGroupInit(Map<String, String> args) {
|
void mvcGroupInit(Map<String, String> args) {
|
||||||
core = mvcGroup.parentGroup.model.core
|
core = mvcGroup.parentGroup.model.core
|
||||||
@@ -48,6 +54,15 @@ class SearchTabModel {
|
|||||||
}
|
}
|
||||||
bucket << e
|
bucket << e
|
||||||
|
|
||||||
|
def senderBucket = sendersBucket.get(e.sender)
|
||||||
|
if (senderBucket == null) {
|
||||||
|
senderBucket = []
|
||||||
|
sendersBucket[e.sender] = senderBucket
|
||||||
|
senders.clear()
|
||||||
|
senders.addAll(sendersBucket.keySet())
|
||||||
|
}
|
||||||
|
senderBucket << e
|
||||||
|
|
||||||
Set sourceBucket = sourcesBucket.get(e.infohash)
|
Set sourceBucket = sourcesBucket.get(e.infohash)
|
||||||
if (sourceBucket == null) {
|
if (sourceBucket == null) {
|
||||||
sourceBucket = new HashSet()
|
sourceBucket = new HashSet()
|
||||||
@@ -55,8 +70,7 @@ class SearchTabModel {
|
|||||||
}
|
}
|
||||||
sourceBucket.addAll(e.sources)
|
sourceBucket.addAll(e.sources)
|
||||||
|
|
||||||
results << e
|
JTable table = builder.getVariable("senders-table")
|
||||||
JTable table = builder.getVariable("results-table")
|
|
||||||
table.model.fireTableDataChanged()
|
table.model.fireTableDataChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,6 +86,14 @@ class SearchTabModel {
|
|||||||
bucket = []
|
bucket = []
|
||||||
hashBucket[it.infohash] = bucket
|
hashBucket[it.infohash] = bucket
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def senderBucket = sendersBucket.get(it.sender)
|
||||||
|
if (senderBucket == null) {
|
||||||
|
senderBucket = []
|
||||||
|
sendersBucket[it.sender] = senderBucket
|
||||||
|
senders.clear()
|
||||||
|
senders.addAll(sendersBucket.keySet())
|
||||||
|
}
|
||||||
|
|
||||||
Set sourceBucket = sourcesBucket.get(it.infohash)
|
Set sourceBucket = sourcesBucket.get(it.infohash)
|
||||||
if (sourceBucket == null) {
|
if (sourceBucket == null) {
|
||||||
@@ -81,9 +103,9 @@ class SearchTabModel {
|
|||||||
sourceBucket.addAll(it.sources)
|
sourceBucket.addAll(it.sources)
|
||||||
|
|
||||||
bucket << it
|
bucket << it
|
||||||
results << it
|
senderBucket << it
|
||||||
}
|
}
|
||||||
JTable table = builder.getVariable("results-table")
|
JTable table = builder.getVariable("senders-table")
|
||||||
table.model.fireTableDataChanged()
|
table.model.fireTableDataChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
154
gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy
Normal file
154
gui/griffon-app/views/com/muwire/gui/ContentPanelView.groovy
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import griffon.core.artifact.GriffonView
|
||||||
|
import griffon.inject.MVCMember
|
||||||
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
|
import javax.swing.JDialog
|
||||||
|
import javax.swing.JLabel
|
||||||
|
import javax.swing.ListSelectionModel
|
||||||
|
import javax.swing.SwingConstants
|
||||||
|
import javax.swing.table.DefaultTableCellRenderer
|
||||||
|
|
||||||
|
import com.muwire.core.content.Matcher
|
||||||
|
import com.muwire.core.content.RegexMatcher
|
||||||
|
|
||||||
|
import java.awt.BorderLayout
|
||||||
|
import java.awt.event.WindowAdapter
|
||||||
|
import java.awt.event.WindowEvent
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
|
@ArtifactProviderFor(GriffonView)
|
||||||
|
class ContentPanelView {
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
FactoryBuilderSupport builder
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
ContentPanelModel model
|
||||||
|
|
||||||
|
def dialog
|
||||||
|
def mainFrame
|
||||||
|
def mainPanel
|
||||||
|
|
||||||
|
def rulesTable
|
||||||
|
def ruleTextField
|
||||||
|
def lastRulesSortEvent
|
||||||
|
def hitsTable
|
||||||
|
def lastHitsSortEvent
|
||||||
|
|
||||||
|
void initUI() {
|
||||||
|
mainFrame = application.windowManager.findWindow("main-frame")
|
||||||
|
dialog = new JDialog(mainFrame, "Content Control Panel", true)
|
||||||
|
|
||||||
|
mainPanel = builder.panel {
|
||||||
|
gridLayout(rows:1, cols:2)
|
||||||
|
panel {
|
||||||
|
borderLayout()
|
||||||
|
panel (constraints : BorderLayout.NORTH) {
|
||||||
|
label(text : "Rules")
|
||||||
|
}
|
||||||
|
scrollPane (constraints : BorderLayout.CENTER) {
|
||||||
|
rulesTable = table(id : "rules-table", autoCreateRowSorter : true) {
|
||||||
|
tableModel(list : model.rules) {
|
||||||
|
closureColumn(header: "Term", type:String, read: {row -> row.getTerm()})
|
||||||
|
closureColumn(header: "Regex?", type:Boolean, read: {row -> row instanceof RegexMatcher})
|
||||||
|
closureColumn(header: "Hits", type:Integer, read : {row -> row.matches.size()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel (constraints : BorderLayout.SOUTH) {
|
||||||
|
borderLayout()
|
||||||
|
ruleTextField = textField(constraints: BorderLayout.CENTER, action: addRuleAction)
|
||||||
|
panel (constraints: BorderLayout.EAST) {
|
||||||
|
buttonGroup(id : "ruleType")
|
||||||
|
radioButton(text: "Keyword", selected : true, buttonGroup: ruleType, keywordAction)
|
||||||
|
radioButton(text: "Regex", selected : false, buttonGroup: ruleType, regexAction)
|
||||||
|
button(text : "Add Rule", addRuleAction)
|
||||||
|
button(text : "Delete Rule", enabled : bind {model.deleteButtonEnabled}, deleteRuleAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel (border : etchedBorder()){
|
||||||
|
borderLayout()
|
||||||
|
panel (constraints : BorderLayout.NORTH) {
|
||||||
|
label(text : "Hits")
|
||||||
|
}
|
||||||
|
scrollPane(constraints : BorderLayout.CENTER) {
|
||||||
|
hitsTable = table(id : "hits-table", autoCreateRowSorter : true) {
|
||||||
|
tableModel(list : model.hits) {
|
||||||
|
closureColumn(header : "Searcher", type : String, read : {row -> row.persona.getHumanReadableName()})
|
||||||
|
closureColumn(header : "Keywords", type : String, read : {row -> row.keywords.join(" ")})
|
||||||
|
closureColumn(header : "Date", type : String, read : {row -> String.valueOf(new Date(row.timestamp))})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel (constraints : BorderLayout.SOUTH) {
|
||||||
|
button(text : "Refresh", refreshAction)
|
||||||
|
button(text : "Trust", enabled : bind {model.trustButtonsEnabled}, trustAction)
|
||||||
|
button(text : "Distrust", enabled : bind {model.trustButtonsEnabled}, distrustAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSelectedRule() {
|
||||||
|
int selectedRow = rulesTable.getSelectedRow()
|
||||||
|
if (selectedRow < 0)
|
||||||
|
return -1
|
||||||
|
if (lastRulesSortEvent != null)
|
||||||
|
selectedRow = rulesTable.rowSorter.convertRowIndexToModel(selectedRow)
|
||||||
|
selectedRow
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSelectedHit() {
|
||||||
|
int selectedRow = hitsTable.getSelectedRow()
|
||||||
|
if (selectedRow < 0)
|
||||||
|
return -1
|
||||||
|
if (lastHitsSortEvent != null)
|
||||||
|
selectedRow = hitsTable.rowSorter.convertRowIndexToModel(selectedRow)
|
||||||
|
selectedRow
|
||||||
|
}
|
||||||
|
|
||||||
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
|
def centerRenderer = new DefaultTableCellRenderer()
|
||||||
|
centerRenderer.setHorizontalAlignment(JLabel.CENTER)
|
||||||
|
rulesTable.setDefaultRenderer(Integer.class, centerRenderer)
|
||||||
|
rulesTable.rowSorter.addRowSorterListener({evt -> lastRulesSortEvent = evt})
|
||||||
|
rulesTable.rowSorter.setSortsOnUpdates(true)
|
||||||
|
def selectionModel = rulesTable.getSelectionModel()
|
||||||
|
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
||||||
|
selectionModel.addListSelectionListener({
|
||||||
|
int selectedRow = getSelectedRule()
|
||||||
|
if (selectedRow < 0) {
|
||||||
|
model.deleteButtonEnabled = false
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
model.deleteButtonEnabled = true
|
||||||
|
model.hits.clear()
|
||||||
|
Matcher matcher = model.rules[selectedRow]
|
||||||
|
model.hits.addAll(matcher.matches)
|
||||||
|
hitsTable.model.fireTableDataChanged()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
hitsTable.rowSorter.addRowSorterListener({evt -> lastHitsSortEvent = evt})
|
||||||
|
hitsTable.rowSorter.setSortsOnUpdates(true)
|
||||||
|
selectionModel = hitsTable.getSelectionModel()
|
||||||
|
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
||||||
|
selectionModel.addListSelectionListener({
|
||||||
|
int selectedRow = getSelectedHit()
|
||||||
|
model.trustButtonsEnabled = selectedRow >= 0
|
||||||
|
})
|
||||||
|
|
||||||
|
dialog.getContentPane().add(mainPanel)
|
||||||
|
dialog.pack()
|
||||||
|
dialog.setLocationRelativeTo(mainFrame)
|
||||||
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
||||||
|
dialog.addWindowListener(new WindowAdapter() {
|
||||||
|
public void windowClosed(WindowEvent e) {
|
||||||
|
mvcGroup.destroy()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,6 @@ import com.muwire.core.MuWireSettings
|
|||||||
import com.muwire.core.download.Downloader
|
import com.muwire.core.download.Downloader
|
||||||
import com.muwire.core.files.FileSharedEvent
|
import com.muwire.core.files.FileSharedEvent
|
||||||
import com.muwire.core.trust.RemoteTrustList
|
import com.muwire.core.trust.RemoteTrustList
|
||||||
|
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
import java.awt.CardLayout
|
import java.awt.CardLayout
|
||||||
import java.awt.FlowLayout
|
import java.awt.FlowLayout
|
||||||
@@ -73,6 +72,11 @@ class MainFrameView {
|
|||||||
menuBar {
|
menuBar {
|
||||||
menu (text : "Options") {
|
menu (text : "Options") {
|
||||||
menuItem("Configuration", actionPerformed : {mvcGroup.createMVCGroup("Options")})
|
menuItem("Configuration", actionPerformed : {mvcGroup.createMVCGroup("Options")})
|
||||||
|
menuItem("Content Control", actionPerformed : {
|
||||||
|
def env = [:]
|
||||||
|
env["core"] = model.core
|
||||||
|
mvcGroup.createMVCGroup("content-panel", env)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
menu (text : "Status") {
|
menu (text : "Status") {
|
||||||
menuItem("MuWire", actionPerformed : {mvcGroup.createMVCGroup("mu-wire-status")})
|
menuItem("MuWire", actionPerformed : {mvcGroup.createMVCGroup("mu-wire-status")})
|
||||||
@@ -85,11 +89,12 @@ class MainFrameView {
|
|||||||
borderLayout()
|
borderLayout()
|
||||||
panel (constraints: BorderLayout.WEST) {
|
panel (constraints: BorderLayout.WEST) {
|
||||||
gridLayout(rows:1, cols: 2)
|
gridLayout(rows:1, cols: 2)
|
||||||
button(text: "Searches", actionPerformed : showSearchWindow)
|
button(text: "Searches", enabled : bind{model.searchesPaneButtonEnabled},actionPerformed : showSearchWindow)
|
||||||
button(text: "Uploads", actionPerformed : showUploadsWindow)
|
button(text: "Downloads", enabled : bind{model.downloadsPaneButtonEnabled}, actionPerformed : showDownloadsWindow)
|
||||||
|
button(text: "Uploads", enabled : bind{model.uploadsPaneButtonEnabled}, actionPerformed : showUploadsWindow)
|
||||||
if (settings.showMonitor)
|
if (settings.showMonitor)
|
||||||
button(text: "Monitor", actionPerformed : showMonitorWindow)
|
button(text: "Monitor", enabled: bind{model.monitorPaneButtonEnabled},actionPerformed : showMonitorWindow)
|
||||||
button(text: "Trust", actionPerformed : showTrustWindow)
|
button(text: "Trust", enabled:bind{model.trustPaneButtonEnabled},actionPerformed : showTrustWindow)
|
||||||
}
|
}
|
||||||
panel(id: "top-panel", constraints: BorderLayout.CENTER) {
|
panel(id: "top-panel", constraints: BorderLayout.CENTER) {
|
||||||
cardLayout()
|
cardLayout()
|
||||||
@@ -113,48 +118,38 @@ class MainFrameView {
|
|||||||
cardLayout()
|
cardLayout()
|
||||||
panel (constraints : "search window") {
|
panel (constraints : "search window") {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
splitPane( orientation : JSplitPane.VERTICAL_SPLIT, dividerLocation : 500,
|
tabbedPane(id : "result-tabs", constraints: BorderLayout.CENTER)
|
||||||
continuousLayout : true, constraints : BorderLayout.CENTER) {
|
}
|
||||||
panel (constraints : JSplitPane.TOP) {
|
panel (constraints: "downloads window") {
|
||||||
borderLayout()
|
gridLayout(rows : 2, cols: 1)
|
||||||
tabbedPane(id : "result-tabs", constraints: BorderLayout.CENTER)
|
panel {
|
||||||
panel(constraints : BorderLayout.SOUTH) {
|
borderLayout()
|
||||||
button(text : "Download", enabled : bind {model.downloadActionEnabled}, downloadAction)
|
scrollPane (constraints : BorderLayout.CENTER) {
|
||||||
button(text : "Trust", enabled: bind {model.trustButtonsEnabled }, trustAction)
|
downloadsTable = table(id : "downloads-table", autoCreateRowSorter : true) {
|
||||||
button(text : "Distrust", enabled : bind {model.trustButtonsEnabled}, distrustAction)
|
tableModel(list: model.downloads) {
|
||||||
}
|
closureColumn(header: "Name", preferredWidth: 300, type: String, read : {row -> row.downloader.file.getName()})
|
||||||
}
|
closureColumn(header: "Status", preferredWidth: 50, type: String, read : {row -> row.downloader.getCurrentState().toString()})
|
||||||
panel (constraints : JSplitPane.BOTTOM) {
|
closureColumn(header: "Progress", preferredWidth: 70, type: Downloader, read: { row -> row.downloader })
|
||||||
borderLayout()
|
closureColumn(header: "Sources", preferredWidth : 10, type: Integer, read : {row -> row.downloader.activeWorkers()})
|
||||||
scrollPane (constraints : BorderLayout.CENTER) {
|
closureColumn(header: "Speed", preferredWidth: 50, type:String, read :{row ->
|
||||||
downloadsTable = table(id : "downloads-table", autoCreateRowSorter : true) {
|
DataHelper.formatSize2Decimal(row.downloader.speed(), false) + "B/sec"
|
||||||
tableModel(list: model.downloads) {
|
})
|
||||||
closureColumn(header: "Name", preferredWidth: 300, type: String, read : {row -> row.downloader.file.getName()})
|
|
||||||
closureColumn(header: "Status", preferredWidth: 50, type: String, read : {row -> row.downloader.getCurrentState().toString()})
|
|
||||||
closureColumn(header: "Progress", preferredWidth: 70, type: String, read: { row ->
|
|
||||||
int pieces = row.downloader.nPieces
|
|
||||||
int done = row.downloader.donePieces()
|
|
||||||
int percent = -1
|
|
||||||
if ( row.downloader.nPieces != 0 ) {
|
|
||||||
percent = (done * 100) / pieces
|
|
||||||
}
|
|
||||||
long size = row.downloader.pieceSize
|
|
||||||
size *= pieces
|
|
||||||
String totalSize = DataHelper.formatSize2Decimal(size, false) + "B"
|
|
||||||
String.format("%02d", percent) + "% of ${totalSize} ($done/$pieces pcs)".toString()
|
|
||||||
})
|
|
||||||
closureColumn(header: "Sources", preferredWidth : 10, type: Integer, read : {row -> row.downloader.activeWorkers()})
|
|
||||||
closureColumn(header: "Speed", preferredWidth: 50, type:String, read :{row ->
|
|
||||||
DataHelper.formatSize2Decimal(row.downloader.speed(), false) + "B/sec"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panel (constraints : BorderLayout.SOUTH) {
|
}
|
||||||
button(text: "Pause", enabled : bind {model.pauseButtonEnabled}, pauseAction)
|
panel (constraints : BorderLayout.SOUTH) {
|
||||||
button(text: "Cancel", enabled : bind {model.cancelButtonEnabled }, cancelAction )
|
button(text: "Pause", enabled : bind {model.pauseButtonEnabled}, pauseAction)
|
||||||
button(text: bind { model.resumeButtonText }, enabled : bind {model.retryButtonEnabled}, resumeAction)
|
button(text: "Cancel", enabled : bind {model.cancelButtonEnabled }, cancelAction )
|
||||||
}
|
button(text: bind { model.resumeButtonText }, enabled : bind {model.retryButtonEnabled}, resumeAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel {
|
||||||
|
borderLayout()
|
||||||
|
panel(constraints : BorderLayout.NORTH) {
|
||||||
|
label(text : "Download Details")
|
||||||
|
}
|
||||||
|
panel(constraints : BorderLayout.CENTER) {
|
||||||
|
label(text : "Details go here...")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,9 +413,11 @@ class MainFrameView {
|
|||||||
def centerRenderer = new DefaultTableCellRenderer()
|
def centerRenderer = new DefaultTableCellRenderer()
|
||||||
centerRenderer.setHorizontalAlignment(JLabel.CENTER)
|
centerRenderer.setHorizontalAlignment(JLabel.CENTER)
|
||||||
downloadsTable.setDefaultRenderer(Integer.class, centerRenderer)
|
downloadsTable.setDefaultRenderer(Integer.class, centerRenderer)
|
||||||
|
downloadsTable.setDefaultRenderer(Downloader.class, new DownloadProgressRenderer())
|
||||||
|
|
||||||
downloadsTable.rowSorter.addRowSorterListener({evt -> lastDownloadSortEvent = evt})
|
downloadsTable.rowSorter.addRowSorterListener({evt -> lastDownloadSortEvent = evt})
|
||||||
downloadsTable.rowSorter.setSortsOnUpdates(true)
|
downloadsTable.rowSorter.setSortsOnUpdates(true)
|
||||||
|
downloadsTable.rowSorter.setComparator(2, new DownloaderComparator())
|
||||||
|
|
||||||
downloadsTable.addMouseListener(new MouseAdapter() {
|
downloadsTable.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
@@ -465,9 +462,18 @@ class MainFrameView {
|
|||||||
// searches table
|
// searches table
|
||||||
def searchesTable = builder.getVariable("searches-table")
|
def searchesTable = builder.getVariable("searches-table")
|
||||||
JPopupMenu searchTableMenu = new JPopupMenu()
|
JPopupMenu searchTableMenu = new JPopupMenu()
|
||||||
|
|
||||||
JMenuItem copySearchToClipboard = new JMenuItem("Copy search to clipboard")
|
JMenuItem copySearchToClipboard = new JMenuItem("Copy search to clipboard")
|
||||||
copySearchToClipboard.addActionListener({mvcGroup.view.copySearchToClipboard(searchesTable)})
|
copySearchToClipboard.addActionListener({mvcGroup.view.copySearchToClipboard(searchesTable)})
|
||||||
|
JMenuItem trustSearcher = new JMenuItem("Trust searcher")
|
||||||
|
trustSearcher.addActionListener({mvcGroup.controller.trustPersonaFromSearch()})
|
||||||
|
JMenuItem distrustSearcher = new JMenuItem("Distrust searcher")
|
||||||
|
distrustSearcher.addActionListener({mvcGroup.controller.distrustPersonaFromSearch()})
|
||||||
|
|
||||||
searchTableMenu.add(copySearchToClipboard)
|
searchTableMenu.add(copySearchToClipboard)
|
||||||
|
searchTableMenu.add(trustSearcher)
|
||||||
|
searchTableMenu.add(distrustSearcher)
|
||||||
|
|
||||||
searchesTable.addMouseListener(new MouseAdapter() {
|
searchesTable.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
@@ -686,21 +692,51 @@ class MainFrameView {
|
|||||||
def showSearchWindow = {
|
def showSearchWindow = {
|
||||||
def cardsPanel = builder.getVariable("cards-panel")
|
def cardsPanel = builder.getVariable("cards-panel")
|
||||||
cardsPanel.getLayout().show(cardsPanel, "search window")
|
cardsPanel.getLayout().show(cardsPanel, "search window")
|
||||||
|
model.searchesPaneButtonEnabled = false
|
||||||
|
model.downloadsPaneButtonEnabled = true
|
||||||
|
model.uploadsPaneButtonEnabled = true
|
||||||
|
model.monitorPaneButtonEnabled = true
|
||||||
|
model.trustPaneButtonEnabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
def showDownloadsWindow = {
|
||||||
|
def cardsPanel = builder.getVariable("cards-panel")
|
||||||
|
cardsPanel.getLayout().show(cardsPanel, "downloads window")
|
||||||
|
model.searchesPaneButtonEnabled = true
|
||||||
|
model.downloadsPaneButtonEnabled = false
|
||||||
|
model.uploadsPaneButtonEnabled = true
|
||||||
|
model.monitorPaneButtonEnabled = true
|
||||||
|
model.trustPaneButtonEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
def showUploadsWindow = {
|
def showUploadsWindow = {
|
||||||
def cardsPanel = builder.getVariable("cards-panel")
|
def cardsPanel = builder.getVariable("cards-panel")
|
||||||
cardsPanel.getLayout().show(cardsPanel, "uploads window")
|
cardsPanel.getLayout().show(cardsPanel, "uploads window")
|
||||||
|
model.searchesPaneButtonEnabled = true
|
||||||
|
model.downloadsPaneButtonEnabled = true
|
||||||
|
model.uploadsPaneButtonEnabled = false
|
||||||
|
model.monitorPaneButtonEnabled = true
|
||||||
|
model.trustPaneButtonEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
def showMonitorWindow = {
|
def showMonitorWindow = {
|
||||||
def cardsPanel = builder.getVariable("cards-panel")
|
def cardsPanel = builder.getVariable("cards-panel")
|
||||||
cardsPanel.getLayout().show(cardsPanel,"monitor window")
|
cardsPanel.getLayout().show(cardsPanel,"monitor window")
|
||||||
|
model.searchesPaneButtonEnabled = true
|
||||||
|
model.downloadsPaneButtonEnabled = true
|
||||||
|
model.uploadsPaneButtonEnabled = true
|
||||||
|
model.monitorPaneButtonEnabled = false
|
||||||
|
model.trustPaneButtonEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
def showTrustWindow = {
|
def showTrustWindow = {
|
||||||
def cardsPanel = builder.getVariable("cards-panel")
|
def cardsPanel = builder.getVariable("cards-panel")
|
||||||
cardsPanel.getLayout().show(cardsPanel,"trust window")
|
cardsPanel.getLayout().show(cardsPanel,"trust window")
|
||||||
|
model.searchesPaneButtonEnabled = true
|
||||||
|
model.downloadsPaneButtonEnabled = true
|
||||||
|
model.uploadsPaneButtonEnabled = true
|
||||||
|
model.monitorPaneButtonEnabled = true
|
||||||
|
model.trustPaneButtonEnabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
def shareFiles = {
|
def shareFiles = {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import javax.swing.ListSelectionModel
|
|||||||
import javax.swing.SwingConstants
|
import javax.swing.SwingConstants
|
||||||
import javax.swing.table.DefaultTableCellRenderer
|
import javax.swing.table.DefaultTableCellRenderer
|
||||||
|
|
||||||
|
import com.muwire.core.Persona
|
||||||
import com.muwire.core.util.DataUtil
|
import com.muwire.core.util.DataUtil
|
||||||
|
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
@@ -37,23 +38,49 @@ class SearchTabView {
|
|||||||
def pane
|
def pane
|
||||||
def parent
|
def parent
|
||||||
def searchTerms
|
def searchTerms
|
||||||
|
def sendersTable
|
||||||
|
def lastSendersSortEvent
|
||||||
def resultsTable
|
def resultsTable
|
||||||
def lastSortEvent
|
def lastSortEvent
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
builder.with {
|
builder.with {
|
||||||
def resultsTable
|
def resultsTable
|
||||||
def pane = scrollPane {
|
def sendersTable
|
||||||
resultsTable = table(id : "results-table", autoCreateRowSorter : true) {
|
def pane = panel {
|
||||||
tableModel(list: model.results) {
|
gridLayout(rows : 2, cols: 1)
|
||||||
closureColumn(header: "Name", preferredWidth: 350, type: String, read : {row -> row.name.replace('<','_')})
|
panel {
|
||||||
closureColumn(header: "Size", preferredWidth: 20, type: Long, read : {row -> row.size})
|
borderLayout()
|
||||||
closureColumn(header: "Direct Sources", preferredWidth: 50, type : Integer, read : { row -> model.hashBucket[row.infohash].size()})
|
scrollPane (constraints : BorderLayout.CENTER) {
|
||||||
closureColumn(header: "Possible Sources", preferredWidth : 50, type : Integer, read : {row -> model.sourcesBucket[row.infohash].size()})
|
sendersTable = table(id : "senders-table", autoCreateRowSorter : true) {
|
||||||
closureColumn(header: "Sender", preferredWidth: 170, type: String, read : {row -> row.sender.getHumanReadableName()})
|
tableModel(list : model.senders) {
|
||||||
closureColumn(header: "Trust", preferredWidth: 50, type: String, read : {row ->
|
closureColumn(header : "Sender", preferredWidth : 500, type: String, read : {row -> row.getHumanReadableName()})
|
||||||
model.core.trustService.getLevel(row.sender.destination).toString()
|
closureColumn(header : "Results", preferredWidth : 20, type: Integer, read : {row -> model.sendersBucket[row].size()})
|
||||||
})
|
closureColumn(header : "Trust", preferredWidth : 50, type: String, read : { row ->
|
||||||
|
model.core.trustService.getLevel(row.destination).toString()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
|
button(text : "Trust", enabled: bind {model.trustButtonsEnabled }, trustAction)
|
||||||
|
button(text : "Distrust", enabled : bind {model.trustButtonsEnabled}, distrustAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel {
|
||||||
|
borderLayout()
|
||||||
|
scrollPane (constraints : BorderLayout.CENTER) {
|
||||||
|
resultsTable = table(id : "results-table", autoCreateRowSorter : true) {
|
||||||
|
tableModel(list: model.results) {
|
||||||
|
closureColumn(header: "Name", preferredWidth: 350, type: String, read : {row -> row.name.replace('<','_')})
|
||||||
|
closureColumn(header: "Size", preferredWidth: 20, type: Long, read : {row -> row.size})
|
||||||
|
closureColumn(header: "Direct Sources", preferredWidth: 50, type : Integer, read : { row -> model.hashBucket[row.infohash].size()})
|
||||||
|
closureColumn(header: "Possible Sources", preferredWidth : 50, type : Integer, read : {row -> model.sourcesBucket[row.infohash].size()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
|
button(text : "Download", enabled : bind {model.downloadActionEnabled}, downloadAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,17 +90,19 @@ class SearchTabView {
|
|||||||
this.pane.putClientProperty("results-table",resultsTable)
|
this.pane.putClientProperty("results-table",resultsTable)
|
||||||
|
|
||||||
this.resultsTable = resultsTable
|
this.resultsTable = resultsTable
|
||||||
|
this.sendersTable = sendersTable
|
||||||
|
|
||||||
def selectionModel = resultsTable.getSelectionModel()
|
def selectionModel = resultsTable.getSelectionModel()
|
||||||
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
||||||
selectionModel.addListSelectionListener( {
|
selectionModel.addListSelectionListener( {
|
||||||
int row = resultsTable.getSelectedRow()
|
int row = resultsTable.getSelectedRow()
|
||||||
if (row < 0)
|
if (row < 0) {
|
||||||
|
model.downloadActionEnabled = false
|
||||||
return
|
return
|
||||||
|
}
|
||||||
if (lastSortEvent != null)
|
if (lastSortEvent != null)
|
||||||
row = resultsTable.rowSorter.convertRowIndexToModel(row)
|
row = resultsTable.rowSorter.convertRowIndexToModel(row)
|
||||||
mvcGroup.parentGroup.model.trustButtonsEnabled = true
|
model.downloadActionEnabled = mvcGroup.parentGroup.model.canDownload(model.results[row].infohash)
|
||||||
mvcGroup.parentGroup.model.downloadActionEnabled = mvcGroup.parentGroup.model.canDownload(model.results[row].infohash)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,12 +127,11 @@ class SearchTabView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parent.setTabComponentAt(index, tabPanel)
|
parent.setTabComponentAt(index, tabPanel)
|
||||||
|
mvcGroup.parentGroup.view.showSearchWindow.call()
|
||||||
|
|
||||||
def centerRenderer = new DefaultTableCellRenderer()
|
def centerRenderer = new DefaultTableCellRenderer()
|
||||||
centerRenderer.setHorizontalAlignment(JLabel.CENTER)
|
centerRenderer.setHorizontalAlignment(JLabel.CENTER)
|
||||||
resultsTable.columnModel.getColumn(1).setCellRenderer(centerRenderer)
|
|
||||||
resultsTable.setDefaultRenderer(Integer.class,centerRenderer)
|
resultsTable.setDefaultRenderer(Integer.class,centerRenderer)
|
||||||
resultsTable.columnModel.getColumn(4).setCellRenderer(centerRenderer)
|
|
||||||
|
|
||||||
resultsTable.columnModel.getColumn(1).setCellRenderer(new SizeRenderer())
|
resultsTable.columnModel.getColumn(1).setCellRenderer(new SizeRenderer())
|
||||||
|
|
||||||
@@ -118,7 +146,7 @@ class SearchTabView {
|
|||||||
if (e.button == MouseEvent.BUTTON3)
|
if (e.button == MouseEvent.BUTTON3)
|
||||||
showPopupMenu(e)
|
showPopupMenu(e)
|
||||||
else if (e.button == MouseEvent.BUTTON1 && e.clickCount == 2)
|
else if (e.button == MouseEvent.BUTTON1 && e.clickCount == 2)
|
||||||
mvcGroup.parentGroup.controller.download()
|
mvcGroup.controller.download()
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
@@ -126,21 +154,42 @@ class SearchTabView {
|
|||||||
showPopupMenu(e)
|
showPopupMenu(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// senders table
|
||||||
|
sendersTable.setDefaultRenderer(Integer.class, centerRenderer)
|
||||||
|
sendersTable.rowSorter.addRowSorterListener({evt -> lastSendersSortEvent = evt})
|
||||||
|
sendersTable.rowSorter.setSortsOnUpdates(true)
|
||||||
|
def selectionModel = sendersTable.getSelectionModel()
|
||||||
|
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
||||||
|
selectionModel.addListSelectionListener({
|
||||||
|
int row = selectedSenderRow()
|
||||||
|
if (row < 0) {
|
||||||
|
model.trustButtonsEnabled = false
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
model.trustButtonsEnabled = true
|
||||||
|
model.results.clear()
|
||||||
|
Persona p = model.senders[row]
|
||||||
|
model.results.addAll(model.sendersBucket[p])
|
||||||
|
resultsTable.model.fireTableDataChanged()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def closeTab = {
|
def closeTab = {
|
||||||
int index = parent.indexOfTab(searchTerms)
|
int index = parent.indexOfTab(searchTerms)
|
||||||
parent.removeTabAt(index)
|
parent.removeTabAt(index)
|
||||||
mvcGroup.parentGroup.model.trustButtonsEnabled = false
|
model.trustButtonsEnabled = false
|
||||||
mvcGroup.parentGroup.model.downloadActionEnabled = false
|
model.downloadActionEnabled = false
|
||||||
mvcGroup.destroy()
|
mvcGroup.destroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
def showPopupMenu(MouseEvent e) {
|
def showPopupMenu(MouseEvent e) {
|
||||||
JPopupMenu menu = new JPopupMenu()
|
JPopupMenu menu = new JPopupMenu()
|
||||||
if (mvcGroup.parentGroup.model.downloadActionEnabled) {
|
if (model.downloadActionEnabled) {
|
||||||
JMenuItem download = new JMenuItem("Download")
|
JMenuItem download = new JMenuItem("Download")
|
||||||
download.addActionListener({mvcGroup.parentGroup.controller.download()})
|
download.addActionListener({mvcGroup.controller.download()})
|
||||||
menu.add(download)
|
menu.add(download)
|
||||||
}
|
}
|
||||||
JMenuItem copyHashToClipboard = new JMenuItem("Copy hash to clipboard")
|
JMenuItem copyHashToClipboard = new JMenuItem("Copy hash to clipboard")
|
||||||
@@ -160,4 +209,13 @@ class SearchTabView {
|
|||||||
def clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
|
def clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
|
||||||
clipboard.setContents(selection, null)
|
clipboard.setContents(selection, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int selectedSenderRow() {
|
||||||
|
int row = sendersTable.getSelectedRow()
|
||||||
|
if (row < 0)
|
||||||
|
return -1
|
||||||
|
if (lastSendersSortEvent != null)
|
||||||
|
row = sendersTable.rowSorter.convertRowIndexToModel(row)
|
||||||
|
row
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import griffon.core.test.GriffonFestRule
|
||||||
|
import org.fest.swing.fixture.FrameFixture
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail
|
||||||
|
|
||||||
|
class ContentPanelIntegrationTest {
|
||||||
|
static {
|
||||||
|
System.setProperty('griffon.swing.edt.violations.check', 'true')
|
||||||
|
System.setProperty('griffon.swing.edt.hang.monitor', 'true')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final GriffonFestRule fest = new GriffonFestRule()
|
||||||
|
|
||||||
|
private FrameFixture window
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void smokeTest() {
|
||||||
|
fail('Not implemented yet!')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import javax.swing.JComponent
|
||||||
|
import javax.swing.JLabel
|
||||||
|
import javax.swing.JTable
|
||||||
|
import javax.swing.table.DefaultTableCellRenderer
|
||||||
|
|
||||||
|
import com.muwire.core.download.Downloader
|
||||||
|
|
||||||
|
import net.i2p.data.DataHelper
|
||||||
|
|
||||||
|
class DownloadProgressRenderer extends DefaultTableCellRenderer {
|
||||||
|
DownloadProgressRenderer() {
|
||||||
|
setHorizontalAlignment(JLabel.CENTER)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
JComponent getTableCellRendererComponent(JTable table, Object value,
|
||||||
|
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||||
|
Downloader d = (Downloader) value
|
||||||
|
int pieces = d.nPieces
|
||||||
|
int done = d.donePieces()
|
||||||
|
int percent = -1
|
||||||
|
if (pieces != 0)
|
||||||
|
percent = (done * 100 / pieces)
|
||||||
|
String totalSize = DataHelper.formatSize2Decimal(d.length, false) + "B"
|
||||||
|
setText(String.format("%2d", percent) + "% of ${totalSize} ($done/$pieces pcs)".toString())
|
||||||
|
|
||||||
|
if (isSelected) {
|
||||||
|
setForeground(table.getSelectionForeground())
|
||||||
|
setBackground(table.getSelectionBackground())
|
||||||
|
} else {
|
||||||
|
setForeground(table.getForeground())
|
||||||
|
setBackground(table.getBackground())
|
||||||
|
}
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import com.muwire.core.download.Downloader
|
||||||
|
|
||||||
|
class DownloaderComparator implements Comparator<Downloader>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Downloader o1, Downloader o2) {
|
||||||
|
double d1 = o1.donePieces() * 1.0 / o1.nPieces
|
||||||
|
double d2 = o2.donePieces() * 1.0 / o2.nPieces
|
||||||
|
return Double.compare(d1, d2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import griffon.core.test.GriffonUnitRule
|
||||||
|
import griffon.core.test.TestFor
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail
|
||||||
|
|
||||||
|
@TestFor(ContentPanelController)
|
||||||
|
class ContentPanelControllerTest {
|
||||||
|
private ContentPanelController controller
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final GriffonUnitRule griffon = new GriffonUnitRule()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void smokeTest() {
|
||||||
|
fail('Not yet implemented!')
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user