mirror of https://github.com/zlatinb/muwire
show the shared files, controlled by property
parent
0df3e63288
commit
8c9a5585eb
|
@ -8,6 +8,7 @@ class MuWireSettings {
|
|||
boolean allowUntrusted
|
||||
String nickname
|
||||
File downloadLocation
|
||||
String sharedFiles
|
||||
CrawlerResponse crawlerResponse
|
||||
|
||||
MuWireSettings() {
|
||||
|
@ -21,6 +22,7 @@ class MuWireSettings {
|
|||
nickname = props.getProperty("nickname","MuWireUser")
|
||||
downloadLocation = new File((String)props.getProperty("downloadLocation",
|
||||
System.getProperty("user.home")))
|
||||
sharedFiles = props.getProperty("sharedFiles")
|
||||
}
|
||||
|
||||
void write(OutputStream out) throws IOException {
|
||||
|
@ -30,6 +32,8 @@ class MuWireSettings {
|
|||
props.setProperty("crawlerResponse", crawlerResponse.toString())
|
||||
props.setProperty("nickname", nickname)
|
||||
props.setProperty("downloadLocation", downloadLocation.getAbsolutePath())
|
||||
if (sharedFiles != null)
|
||||
props.setProperty("sharedFiles", sharedFiles)
|
||||
props.store(out, "")
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue