Do not clear uploads by default

This commit is contained in:
Zlatin Balevsky
2019-10-26 16:45:21 +01:00
parent c6fb76610d
commit 56d44e6458
9 changed files with 77 additions and 8 deletions

View File

@@ -123,4 +123,13 @@ class ContentUploader extends Uploader {
public long getTotalSize() { public long getTotalSize() {
return file.length(); return file.length();
} }
@Override
public boolean equals(Object o) {
if (!(o instanceof ContentUploader))
return false
ContentUploader other = (ContentUploader)o
request.infoHash == other.request.infoHash &&
request.getDownloader() == other.request.getDownloader()
}
} }

View File

@@ -65,4 +65,12 @@ class HashListUploader extends Uploader {
public long getTotalSize() { public long getTotalSize() {
return -1; return -1;
} }
@Override
public boolean equals(Object o) {
if (!(o instanceof HashListUploader))
return false
HashListUploader other = (HashListUploader)o
infoHash == other.infoHash && request.downloader == other.request.downloader
}
} }

View File

@@ -292,6 +292,11 @@ class MainFrameController {
params['core'] = core params['core'] = core
mvcGroup.createMVCGroup("add-comment", "Add Comment", params) mvcGroup.createMVCGroup("add-comment", "Add Comment", params)
} }
@ControllerAction
void clearUploads() {
model.uploads.removeAll { it.finished }
}
void saveMuWireSettings() { void saveMuWireSettings() {
File f = new File(core.home, "MuWire.properties") File f = new File(core.home, "MuWire.properties")

View File

@@ -157,6 +157,10 @@ class OptionsController {
boolean excludeLocalResult = view.excludeLocalResultCheckbox.model.isSelected() boolean excludeLocalResult = view.excludeLocalResultCheckbox.model.isSelected()
model.excludeLocalResult = excludeLocalResult model.excludeLocalResult = excludeLocalResult
uiSettings.excludeLocalResult = excludeLocalResult uiSettings.excludeLocalResult = excludeLocalResult
boolean clearUploads = view.clearUploadsCheckbox.model.isSelected()
model.clearUploads = clearUploads
uiSettings.clearUploads = clearUploads
File uiSettingsFile = new File(core.home, "gui.properties") File uiSettingsFile = new File(core.home, "gui.properties")
uiSettingsFile.withOutputStream { uiSettingsFile.withOutputStream {

View File

@@ -46,6 +46,7 @@ import com.muwire.core.update.UpdateAvailableEvent
import com.muwire.core.update.UpdateDownloadedEvent import com.muwire.core.update.UpdateDownloadedEvent
import com.muwire.core.upload.UploadEvent import com.muwire.core.upload.UploadEvent
import com.muwire.core.upload.UploadFinishedEvent import com.muwire.core.upload.UploadFinishedEvent
import com.muwire.core.upload.Uploader
import griffon.core.GriffonApplication import griffon.core.GriffonApplication
import griffon.core.artifact.GriffonModel import griffon.core.artifact.GriffonModel
@@ -378,7 +379,19 @@ class MainFrameModel {
void onUploadEvent(UploadEvent e) { void onUploadEvent(UploadEvent e) {
runInsideUIAsync { runInsideUIAsync {
uploads << e.uploader UploaderWrapper wrapper = null
uploads.each {
if (it.uploader == e.uploader) {
wrapper = it
return
}
}
if (wrapper != null) {
wrapper.uploader = e.uploader
wrapper.requests++
wrapper.finished = false
} else
uploads << new UploaderWrapper(uploader : e.uploader)
JTable table = builder.getVariable("uploads-table") JTable table = builder.getVariable("uploads-table")
table.model.fireTableDataChanged() table.model.fireTableDataChanged()
view.refreshSharedFiles() view.refreshSharedFiles()
@@ -387,7 +400,18 @@ class MainFrameModel {
void onUploadFinishedEvent(UploadFinishedEvent e) { void onUploadFinishedEvent(UploadFinishedEvent e) {
runInsideUIAsync { runInsideUIAsync {
uploads.remove(e.uploader) UploaderWrapper wrapper = null
uploads.each {
if (it.uploader == e.uploader) {
wrapper = it
return
}
}
if (uiSettings.clearUploads) {
uploads.remove(wrapper)
} else {
wrapper.finished = true
}
JTable table = builder.getVariable("uploads-table") JTable table = builder.getVariable("uploads-table")
table.model.fireTableDataChanged() table.model.fireTableDataChanged()
} }
@@ -584,4 +608,10 @@ class MainFrameModel {
boolean canDownload(InfoHash hash) { boolean canDownload(InfoHash hash) {
!downloadInfoHashes.contains(hash) !downloadInfoHashes.contains(hash)
} }
class UploaderWrapper {
Uploader uploader
int requests
boolean finished
}
} }

View File

@@ -38,6 +38,7 @@ class OptionsModel {
@Observable boolean clearFinishedDownloads @Observable boolean clearFinishedDownloads
@Observable boolean excludeLocalResult @Observable boolean excludeLocalResult
@Observable boolean showSearchHashes @Observable boolean showSearchHashes
@Observable boolean clearUploads
// bw options // bw options
@Observable String inBw @Observable String inBw
@@ -81,6 +82,7 @@ class OptionsModel {
clearFinishedDownloads = uiSettings.clearFinishedDownloads clearFinishedDownloads = uiSettings.clearFinishedDownloads
excludeLocalResult = uiSettings.excludeLocalResult excludeLocalResult = uiSettings.excludeLocalResult
showSearchHashes = uiSettings.showSearchHashes showSearchHashes = uiSettings.showSearchHashes
clearUploads = uiSettings.clearUploads
if (core.router != null) { if (core.router != null) {
inBw = String.valueOf(settings.inBw) inBw = String.valueOf(settings.inBw)

View File

@@ -271,31 +271,35 @@ class MainFrameView {
scrollPane (constraints : BorderLayout.CENTER) { scrollPane (constraints : BorderLayout.CENTER) {
table(id : "uploads-table") { table(id : "uploads-table") {
tableModel(list : model.uploads) { tableModel(list : model.uploads) {
closureColumn(header : "Name", type : String, read : {row -> row.getName() }) closureColumn(header : "Name", type : String, read : {row -> row.uploader.getName() })
closureColumn(header : "Progress", type : String, read : { row -> closureColumn(header : "Progress", type : String, read : { row ->
int percent = row.getProgress() int percent = row.uploader.getProgress()
"$percent% of piece".toString() "$percent% of piece".toString()
}) })
closureColumn(header : "Downloader", type : String, read : { row -> closureColumn(header : "Downloader", type : String, read : { row ->
row.getDownloader() row.uploader.getDownloader()
}) })
closureColumn(header : "Remote Pieces", type : String, read : { row -> closureColumn(header : "Remote Pieces", type : String, read : { row ->
int pieces = row.getTotalPieces() int pieces = row.uploader.getTotalPieces()
int done = row.getDonePieces() int done = row.uploader.getDonePieces()
int percent = -1 int percent = -1
if ( pieces != 0 ) { if ( pieces != 0 ) {
percent = (done * 100) / pieces percent = (done * 100) / pieces
} }
long size = row.getTotalSize() long size = row.uploader.getTotalSize()
String totalSize = "" String totalSize = ""
if (size >= 0 ) { if (size >= 0 ) {
totalSize = " of " + DataHelper.formatSize2Decimal(size, false) + "B" totalSize = " of " + DataHelper.formatSize2Decimal(size, false) + "B"
} }
String.format("%02d", percent) + "% ${totalSize} ($done/$pieces pcs)".toString() String.format("%02d", percent) + "% ${totalSize} ($done/$pieces pcs)".toString()
}) })
closureColumn(header : "Requests", type : Integer, read : {row -> row.requests})
} }
} }
} }
panel (constraints : BorderLayout.SOUTH) {
button(text : "Clear Finished Uploads", clearUploadsAction)
}
} }
} }
panel (constraints: "monitor window") { panel (constraints: "monitor window") {

View File

@@ -58,6 +58,7 @@ class OptionsView {
def clearFinishedDownloadsCheckbox def clearFinishedDownloadsCheckbox
def excludeLocalResultCheckbox def excludeLocalResultCheckbox
def showSearchHashesCheckbox def showSearchHashesCheckbox
def clearUploadsCheckbox
def inBwField def inBwField
def outBwField def outBwField
@@ -197,6 +198,9 @@ class OptionsView {
label(text : "Exclude local files from results", constraints: gbc(gridx:0, gridy:3, anchor : GridBagConstraints.LINE_START, weightx: 100)) label(text : "Exclude local files from results", constraints: gbc(gridx:0, gridy:3, anchor : GridBagConstraints.LINE_START, weightx: 100))
excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult}, excludeLocalResultCheckbox = checkBox(selected : bind {model.excludeLocalResult},
constraints : gbc(gridx: 1, gridy : 3, anchor : GridBagConstraints.LINE_END)) constraints : gbc(gridx: 1, gridy : 3, anchor : GridBagConstraints.LINE_END))
label(text : "Clear finished uploads", constraints:gbc(gridx:0, gridy:4, anchor: GridBagConstraints.LINE_START, weightx : 100))
clearUploadsCheckbox = checkBox(selected : bind {model.clearUploads},
constraints : gbc(gridx:1, gridy: 4, anchor:GridBagConstraints.LINE_END))
} }
panel (constraints : gbc(gridx: 0, gridy: 2, weighty: 100)) panel (constraints : gbc(gridx: 0, gridy: 2, weighty: 100))
} }

View File

@@ -12,6 +12,7 @@ class UISettings {
boolean excludeLocalResult boolean excludeLocalResult
boolean showSearchHashes boolean showSearchHashes
boolean closeWarning boolean closeWarning
boolean clearUploads
UISettings(Properties props) { UISettings(Properties props) {
lnf = props.getProperty("lnf", "system") lnf = props.getProperty("lnf", "system")
@@ -24,6 +25,7 @@ class UISettings {
autoFontSize = Boolean.parseBoolean(props.getProperty("autoFontSize","false")) autoFontSize = Boolean.parseBoolean(props.getProperty("autoFontSize","false"))
fontSize = Integer.parseInt(props.getProperty("fontSize","12")) fontSize = Integer.parseInt(props.getProperty("fontSize","12"))
closeWarning = Boolean.parseBoolean(props.getProperty("closeWarning","true")) closeWarning = Boolean.parseBoolean(props.getProperty("closeWarning","true"))
clearUploads = Boolean.parseBoolean(props.getProperty("clearUploads","false"))
} }
void write(OutputStream out) throws IOException { void write(OutputStream out) throws IOException {
@@ -37,6 +39,7 @@ class UISettings {
props.setProperty("autoFontSize", String.valueOf(autoFontSize)) props.setProperty("autoFontSize", String.valueOf(autoFontSize))
props.setProperty("fontSize", String.valueOf(fontSize)) props.setProperty("fontSize", String.valueOf(fontSize))
props.setProperty("closeWarning", String.valueOf(closeWarning)) props.setProperty("closeWarning", String.valueOf(closeWarning))
props.setProperty("clearUploads", String.valueOf(clearUploads))
if (font != null) if (font != null)
props.setProperty("font", font) props.setProperty("font", font)