show the shared files, controlled by property
This commit is contained in:
@@ -8,6 +8,7 @@ class MuWireSettings {
|
|||||||
boolean allowUntrusted
|
boolean allowUntrusted
|
||||||
String nickname
|
String nickname
|
||||||
File downloadLocation
|
File downloadLocation
|
||||||
|
String sharedFiles
|
||||||
CrawlerResponse crawlerResponse
|
CrawlerResponse crawlerResponse
|
||||||
|
|
||||||
MuWireSettings() {
|
MuWireSettings() {
|
||||||
@@ -21,6 +22,7 @@ class MuWireSettings {
|
|||||||
nickname = props.getProperty("nickname","MuWireUser")
|
nickname = props.getProperty("nickname","MuWireUser")
|
||||||
downloadLocation = new File((String)props.getProperty("downloadLocation",
|
downloadLocation = new File((String)props.getProperty("downloadLocation",
|
||||||
System.getProperty("user.home")))
|
System.getProperty("user.home")))
|
||||||
|
sharedFiles = props.getProperty("sharedFiles")
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(OutputStream out) throws IOException {
|
void write(OutputStream out) throws IOException {
|
||||||
@@ -30,6 +32,8 @@ class MuWireSettings {
|
|||||||
props.setProperty("crawlerResponse", crawlerResponse.toString())
|
props.setProperty("crawlerResponse", crawlerResponse.toString())
|
||||||
props.setProperty("nickname", nickname)
|
props.setProperty("nickname", nickname)
|
||||||
props.setProperty("downloadLocation", downloadLocation.getAbsolutePath())
|
props.setProperty("downloadLocation", downloadLocation.getAbsolutePath())
|
||||||
|
if (sharedFiles != null)
|
||||||
|
props.setProperty("sharedFiles", sharedFiles)
|
||||||
props.store(out, "")
|
props.store(out, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler
|
|||||||
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
import com.muwire.core.MuWireSettings
|
import com.muwire.core.MuWireSettings
|
||||||
|
import com.muwire.core.files.FileSharedEvent
|
||||||
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -88,6 +89,12 @@ class Ready extends AbstractLifecycleHandler {
|
|||||||
application.getPropertyChangeListeners("core").each {
|
application.getPropertyChangeListeners("core").each {
|
||||||
it.propertyChange(new PropertyChangeEvent(this, "core", null, core))
|
it.propertyChange(new PropertyChangeEvent(this, "core", null, core))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.sharedFiles != null) {
|
||||||
|
props.sharedFiles.split(",").each {
|
||||||
|
core.eventBus.publish(new FileSharedEvent(file : new File(it)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,10 +5,14 @@ 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.InfoHash
|
||||||
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.download.DownloadStartedEvent
|
import com.muwire.core.download.DownloadStartedEvent
|
||||||
|
import com.muwire.core.files.FileHashedEvent
|
||||||
|
import com.muwire.core.files.FileLoadedEvent
|
||||||
|
import com.muwire.core.files.FileSharedEvent
|
||||||
import com.muwire.core.search.UIResultEvent
|
import com.muwire.core.search.UIResultEvent
|
||||||
|
|
||||||
import griffon.core.GriffonApplication
|
import griffon.core.GriffonApplication
|
||||||
@@ -27,8 +31,11 @@ class MainFrameModel {
|
|||||||
|
|
||||||
@Observable def results = []
|
@Observable def results = []
|
||||||
@Observable def downloads = []
|
@Observable def downloads = []
|
||||||
|
@Observable def shared = []
|
||||||
@Observable int connections
|
@Observable int connections
|
||||||
@Observable String me
|
@Observable String me
|
||||||
|
|
||||||
|
private final Set<InfoHash> infoHashes = new HashSet<>()
|
||||||
|
|
||||||
volatile Core core
|
volatile Core core
|
||||||
|
|
||||||
@@ -41,6 +48,8 @@ class MainFrameModel {
|
|||||||
core.eventBus.register(DownloadStartedEvent.class, this)
|
core.eventBus.register(DownloadStartedEvent.class, this)
|
||||||
core.eventBus.register(ConnectionEvent.class, this)
|
core.eventBus.register(ConnectionEvent.class, this)
|
||||||
core.eventBus.register(DisconnectionEvent.class, this)
|
core.eventBus.register(DisconnectionEvent.class, this)
|
||||||
|
core.eventBus.register(FileHashedEvent.class, this)
|
||||||
|
core.eventBus.register(FileLoadedEvent.class, this)
|
||||||
})
|
})
|
||||||
Timer timer = new Timer("download-pumper", true)
|
Timer timer = new Timer("download-pumper", true)
|
||||||
timer.schedule({
|
timer.schedule({
|
||||||
@@ -75,4 +84,28 @@ class MainFrameModel {
|
|||||||
connections = core.connectionManager.getConnections().size()
|
connections = core.connectionManager.getConnections().size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onFileHashedEvent(FileHashedEvent e) {
|
||||||
|
if (e.error != null)
|
||||||
|
return // TODO do something
|
||||||
|
if (infoHashes.contains(e.sharedFile.infoHash))
|
||||||
|
return
|
||||||
|
infoHashes.add(e.sharedFile.infoHash)
|
||||||
|
runInsideUIAsync {
|
||||||
|
shared << e.sharedFile
|
||||||
|
JTable table = builder.getVariable("shared-files-table")
|
||||||
|
table.model.fireTableDataChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onFileLoadedEvent(FileLoadedEvent e) {
|
||||||
|
if (infoHashes.contains(e.loadedFile.infoHash))
|
||||||
|
return
|
||||||
|
infoHashes.add(e.loadedFile.infoHash)
|
||||||
|
runInsideUIAsync {
|
||||||
|
shared << e.loadedFile
|
||||||
|
JTable table = builder.getVariable("shared-files-table")
|
||||||
|
table.model.fireTableDataChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -102,7 +102,22 @@ class MainFrameView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
panel (constraints: "uploads window"){
|
panel (constraints: "uploads window"){
|
||||||
label("card 2")
|
gridLayout(cols : 1, rows : 2)
|
||||||
|
panel {
|
||||||
|
borderLayout()
|
||||||
|
label(text : "Shared files", constraints: BorderLayout.NORTH)
|
||||||
|
scrollPane ( constraints : BorderLayout.CENTER) {
|
||||||
|
table(id : "shared-files-table") {
|
||||||
|
tableModel(list : model.shared) {
|
||||||
|
closureColumn(header : "Name", type : String, read : {row -> row.file.getAbsolutePath()})
|
||||||
|
closureColumn(header : "Size", type : Long, read : {row -> row.file.length()})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panel {
|
||||||
|
label("Uploads go here")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panel (border: etchedBorder(), constraints : BorderLayout.SOUTH) {
|
panel (border: etchedBorder(), constraints : BorderLayout.SOUTH) {
|
||||||
|
Reference in New Issue
Block a user