mirror of https://github.com/zlatinb/muwire
Show which file is hashing, thanks to Aegon
parent
2d22f9c39e
commit
39808302df
|
@ -20,6 +20,7 @@ import com.muwire.core.download.UIDownloadPausedEvent
|
||||||
import com.muwire.core.download.UIDownloadResumedEvent
|
import com.muwire.core.download.UIDownloadResumedEvent
|
||||||
import com.muwire.core.files.FileDownloadedEvent
|
import com.muwire.core.files.FileDownloadedEvent
|
||||||
import com.muwire.core.files.FileHashedEvent
|
import com.muwire.core.files.FileHashedEvent
|
||||||
|
import com.muwire.core.files.FileHashingEvent
|
||||||
import com.muwire.core.files.FileHasher
|
import com.muwire.core.files.FileHasher
|
||||||
import com.muwire.core.files.FileLoadedEvent
|
import com.muwire.core.files.FileLoadedEvent
|
||||||
import com.muwire.core.files.FileManager
|
import com.muwire.core.files.FileManager
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.muwire.core.files
|
||||||
|
|
||||||
|
import com.muwire.core.Event
|
||||||
|
import com.muwire.core.SharedFile
|
||||||
|
|
||||||
|
class FileHashingEvent extends Event {
|
||||||
|
|
||||||
|
File hashingFile
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
super.toString() + " hashingFile " + hashingFile.getAbsolutePath()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -39,6 +39,7 @@ class HasherService {
|
||||||
} else if (f.length() > FileHasher.MAX_SIZE) {
|
} else if (f.length() > FileHasher.MAX_SIZE) {
|
||||||
eventBus.publish new FileHashedEvent(error: "$f is too large to be shared ${f.length()}")
|
eventBus.publish new FileHashedEvent(error: "$f is too large to be shared ${f.length()}")
|
||||||
} else {
|
} else {
|
||||||
|
eventBus.publish new FileHashingEvent(hashingFile: f)
|
||||||
def hash = hasher.hashFile f
|
def hash = hasher.hashFile f
|
||||||
eventBus.publish new FileHashedEvent(sharedFile: new SharedFile(f, hash, FileHasher.getPieceSize(f.length())))
|
eventBus.publish new FileHashedEvent(sharedFile: new SharedFile(f, hash, FileHasher.getPieceSize(f.length())))
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.muwire.core.download.Downloader
|
||||||
import com.muwire.core.files.AllFilesLoadedEvent
|
import com.muwire.core.files.AllFilesLoadedEvent
|
||||||
import com.muwire.core.files.FileDownloadedEvent
|
import com.muwire.core.files.FileDownloadedEvent
|
||||||
import com.muwire.core.files.FileHashedEvent
|
import com.muwire.core.files.FileHashedEvent
|
||||||
|
import com.muwire.core.files.FileHashingEvent
|
||||||
import com.muwire.core.files.FileLoadedEvent
|
import com.muwire.core.files.FileLoadedEvent
|
||||||
import com.muwire.core.files.FileSharedEvent
|
import com.muwire.core.files.FileSharedEvent
|
||||||
import com.muwire.core.files.FileUnsharedEvent
|
import com.muwire.core.files.FileUnsharedEvent
|
||||||
|
@ -72,6 +73,8 @@ class MainFrameModel {
|
||||||
|
|
||||||
@Observable int connections
|
@Observable int connections
|
||||||
@Observable String me
|
@Observable String me
|
||||||
|
@Observable int loadedFiles
|
||||||
|
@Observable File hashingFile
|
||||||
@Observable boolean downloadActionEnabled
|
@Observable boolean downloadActionEnabled
|
||||||
@Observable boolean trustButtonsEnabled
|
@Observable boolean trustButtonsEnabled
|
||||||
@Observable boolean cancelButtonEnabled
|
@Observable boolean cancelButtonEnabled
|
||||||
|
@ -86,7 +89,7 @@ class MainFrameModel {
|
||||||
@Observable boolean reviewButtonEnabled
|
@Observable boolean reviewButtonEnabled
|
||||||
@Observable boolean updateButtonEnabled
|
@Observable boolean updateButtonEnabled
|
||||||
@Observable boolean unsubscribeButtonEnabled
|
@Observable boolean unsubscribeButtonEnabled
|
||||||
|
|
||||||
private final Set<InfoHash> infoHashes = new HashSet<>()
|
private final Set<InfoHash> infoHashes = new HashSet<>()
|
||||||
|
|
||||||
private final Set<InfoHash> downloadInfoHashes = new HashSet<>()
|
private final Set<InfoHash> downloadInfoHashes = new HashSet<>()
|
||||||
|
@ -147,6 +150,7 @@ class MainFrameModel {
|
||||||
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(FileHashedEvent.class, this)
|
||||||
|
core.eventBus.register(FileHashingEvent.class, this)
|
||||||
core.eventBus.register(FileLoadedEvent.class, this)
|
core.eventBus.register(FileLoadedEvent.class, this)
|
||||||
core.eventBus.register(UploadEvent.class, this)
|
core.eventBus.register(UploadEvent.class, this)
|
||||||
core.eventBus.register(UploadFinishedEvent.class, this)
|
core.eventBus.register(UploadFinishedEvent.class, this)
|
||||||
|
@ -263,7 +267,17 @@ class MainFrameModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onFileHashingEvent(FileHashingEvent e) {
|
||||||
|
runInsideUIAsync {
|
||||||
|
loadedFiles = shared.size()
|
||||||
|
hashingFile = e.hashingFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void onFileHashedEvent(FileHashedEvent e) {
|
void onFileHashedEvent(FileHashedEvent e) {
|
||||||
|
runInsideUIAsync {
|
||||||
|
hashingFile = null
|
||||||
|
}
|
||||||
if (e.error != null)
|
if (e.error != null)
|
||||||
return // TODO do something
|
return // TODO do something
|
||||||
if (infoHashes.contains(e.sharedFile.infoHash))
|
if (infoHashes.contains(e.sharedFile.infoHash))
|
||||||
|
@ -271,6 +285,7 @@ class MainFrameModel {
|
||||||
infoHashes.add(e.sharedFile.infoHash)
|
infoHashes.add(e.sharedFile.infoHash)
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
shared << e.sharedFile
|
shared << e.sharedFile
|
||||||
|
loadedFiles = shared.size()
|
||||||
JTable table = builder.getVariable("shared-files-table")
|
JTable table = builder.getVariable("shared-files-table")
|
||||||
table.model.fireTableDataChanged()
|
table.model.fireTableDataChanged()
|
||||||
}
|
}
|
||||||
|
@ -282,6 +297,7 @@ class MainFrameModel {
|
||||||
infoHashes.add(e.loadedFile.infoHash)
|
infoHashes.add(e.loadedFile.infoHash)
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
shared << e.loadedFile
|
shared << e.loadedFile
|
||||||
|
loadedFiles = shared.size()
|
||||||
JTable table = builder.getVariable("shared-files-table")
|
JTable table = builder.getVariable("shared-files-table")
|
||||||
table.model.fireTableDataChanged()
|
table.model.fireTableDataChanged()
|
||||||
}
|
}
|
||||||
|
@ -293,6 +309,7 @@ class MainFrameModel {
|
||||||
return
|
return
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
shared.remove(e.unsharedFile)
|
shared.remove(e.unsharedFile)
|
||||||
|
loadedFiles = shared.size()
|
||||||
JTable table = builder.getVariable("shared-files-table")
|
JTable table = builder.getVariable("shared-files-table")
|
||||||
table.model.fireTableDataChanged()
|
table.model.fireTableDataChanged()
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,36 +161,53 @@ class MainFrameView {
|
||||||
panel (constraints: "uploads window"){
|
panel (constraints: "uploads window"){
|
||||||
gridLayout(cols : 1, rows : 2)
|
gridLayout(cols : 1, rows : 2)
|
||||||
panel {
|
panel {
|
||||||
gridLayout(cols : 2, rows : 1)
|
borderLayout()
|
||||||
panel {
|
panel (constraints : BorderLayout.NORTH) {
|
||||||
borderLayout()
|
label(text : bind {
|
||||||
panel (constraints : BorderLayout.NORTH) {
|
if (model.hashingFile == null) {
|
||||||
button(text : "Add directories to watch", actionPerformed : watchDirectories)
|
""
|
||||||
}
|
} else {
|
||||||
scrollPane (constraints : BorderLayout.CENTER) {
|
"hashing: " + model.hashingFile.getAbsolutePath() + " (" + DataHelper.formatSize2Decimal(model.hashingFile.length(), false).toString() + "B)"
|
||||||
table(id : "watched-directories-table", autoCreateRowSorter: true) {
|
}
|
||||||
tableModel(list : model.watched) {
|
})
|
||||||
closureColumn(header: "Watched Directories", type : String, read : { it })
|
}
|
||||||
|
panel (border : etchedBorder(), constraints : BorderLayout.CENTER) {
|
||||||
|
gridLayout(cols : 2, rows : 1)
|
||||||
|
panel (constraints : BorderLayout.WEST) {
|
||||||
|
borderLayout()
|
||||||
|
scrollPane (constraints : BorderLayout.CENTER) {
|
||||||
|
table(id : "watched-directories-table", autoCreateRowSorter: true) {
|
||||||
|
tableModel(list : model.watched) {
|
||||||
|
closureColumn(header: "Watched Directories", type : String, read : { it })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
panel (constraints : BorderLayout.SOUTH) {
|
||||||
|
button(text : "Add directories to watch", actionPerformed : watchDirectories)
|
||||||
|
button(text : "Share files", actionPerformed : shareFiles)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
panel (constraints : BorderLayout.EAST){
|
||||||
panel {
|
borderLayout()
|
||||||
borderLayout()
|
scrollPane(constraints : BorderLayout.CENTER) {
|
||||||
panel (constraints : BorderLayout.NORTH) {
|
table(id : "shared-files-table", autoCreateRowSorter: true) {
|
||||||
button(text : "Share files", actionPerformed : shareFiles)
|
tableModel(list : model.shared) {
|
||||||
}
|
closureColumn(header : "Name", preferredWidth : 500, type : String, read : {row -> row.getCachedPath()})
|
||||||
scrollPane(constraints : BorderLayout.CENTER) {
|
closureColumn(header : "Size", preferredWidth : 100, type : Long, read : {row -> row.getCachedLength() })
|
||||||
table(id : "shared-files-table", autoCreateRowSorter: true) {
|
}
|
||||||
tableModel(list : model.shared) {
|
}
|
||||||
closureColumn(header : "Name", preferredWidth : 500, type : String, read : {row -> row.getCachedPath()})
|
}
|
||||||
closureColumn(header : "Size", preferredWidth : 100, type : Long, read : {row -> row.getCachedLength() })
|
panel (constraints : BorderLayout.SOUTH) {
|
||||||
|
borderLayout()
|
||||||
|
panel (constraints : BorderLayout.EAST) {
|
||||||
|
label("Shared:")
|
||||||
|
label(text : bind {model.loadedFiles.toString()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panel {
|
panel (border : etchedBorder()) {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
panel (constraints : BorderLayout.NORTH){
|
panel (constraints : BorderLayout.NORTH){
|
||||||
label("Uploads")
|
label("Uploads")
|
||||||
|
|
Loading…
Reference in New Issue