select where files should be downloaded

This commit is contained in:
Zlatin Balevsky
2019-05-31 11:53:23 +01:00
parent 71473cf541
commit 0df3e63288
3 changed files with 23 additions and 3 deletions

View File

@@ -38,7 +38,7 @@ class MainFrameController {
def resultsTable = builder.getVariable("results-table")
int row = resultsTable.getSelectedRow()
def result = model.results[row]
def file = new File(System.getProperty("user.home"), result.name) // TODO: move elsewhere
def file = new File(application.context.get("muwire-settings").downloadLocation, result.name)
core.eventBus.publish(new UIDownloadEvent(result : result, target : file))
}

View File

@@ -8,6 +8,7 @@ import com.muwire.core.MuWireSettings
import javax.annotation.Nonnull
import javax.inject.Inject
import javax.swing.JFileChooser
import javax.swing.JOptionPane
import static griffon.util.GriffonApplicationUtils.isMacOSX
@@ -49,16 +50,31 @@ class Ready extends AbstractLifecycleHandler {
"Your nickname is displayed when you send search results so other MuWire users can choose to trust you",
"Please choose a nickname", JOptionPane.PLAIN_MESSAGE)
if (nickname == null || nickname.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Nickname cannot be empty")
JOptionPane.showMessageDialog(null, "Nickname cannot be empty", "Select another nickname",
JOptionPane.WARNING_MESSAGE)
continue
}
if (nickname.contains("@")) {
JOptionPane.showMessageDialog(null, "Nickname cannot contain @, choose another")
JOptionPane.showMessageDialog(null, "Nickname cannot contain @, choose another",
"Select another nickname", JOptionPane.WARNING_MESSAGE)
continue
}
nickname = nickname.trim()
break
}
while(true) {
def chooser = new JFileChooser()
chooser.setDialogTitle("Select a directory where downloads will be saved")
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
int rv = chooser.showOpenDialog(null)
if (rv != JFileChooser.APPROVE_OPTION) {
JOptionPane.showMessageDialog(null, "MuWire will now exit")
System.exit(0)
}
props.downloadLocation = chooser.getSelectedFile()
break
}
props.setNickname(nickname)
propsFile.withOutputStream {
props.write(it)