show the shared files, controlled by property
This commit is contained in:
@@ -5,6 +5,7 @@ import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler
|
||||
|
||||
import com.muwire.core.Core
|
||||
import com.muwire.core.MuWireSettings
|
||||
import com.muwire.core.files.FileSharedEvent
|
||||
|
||||
import javax.annotation.Nonnull
|
||||
import javax.inject.Inject
|
||||
@@ -88,6 +89,12 @@ class Ready extends AbstractLifecycleHandler {
|
||||
application.getPropertyChangeListeners("core").each {
|
||||
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 com.muwire.core.Core
|
||||
import com.muwire.core.InfoHash
|
||||
import com.muwire.core.connection.ConnectionAttemptStatus
|
||||
import com.muwire.core.connection.ConnectionEvent
|
||||
import com.muwire.core.connection.DisconnectionEvent
|
||||
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 griffon.core.GriffonApplication
|
||||
@@ -27,8 +31,11 @@ class MainFrameModel {
|
||||
|
||||
@Observable def results = []
|
||||
@Observable def downloads = []
|
||||
@Observable def shared = []
|
||||
@Observable int connections
|
||||
@Observable String me
|
||||
|
||||
private final Set<InfoHash> infoHashes = new HashSet<>()
|
||||
|
||||
volatile Core core
|
||||
|
||||
@@ -41,6 +48,8 @@ class MainFrameModel {
|
||||
core.eventBus.register(DownloadStartedEvent.class, this)
|
||||
core.eventBus.register(ConnectionEvent.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.schedule({
|
||||
@@ -75,4 +84,28 @@ class MainFrameModel {
|
||||
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"){
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user