diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index e60c3957..e26635ab 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -7,6 +7,7 @@ class MuWireSettings { final boolean isLeaf boolean allowUntrusted String nickname + File downloadLocation CrawlerResponse crawlerResponse MuWireSettings() { @@ -18,6 +19,8 @@ class MuWireSettings { allowUntrusted = Boolean.valueOf(props.get("allowUntrusted","true")) crawlerResponse = CrawlerResponse.valueOf(props.get("crawlerResponse","REGISTERED")) nickname = props.getProperty("nickname","MuWireUser") + downloadLocation = new File((String)props.getProperty("downloadLocation", + System.getProperty("user.home"))) } void write(OutputStream out) throws IOException { @@ -26,6 +29,7 @@ class MuWireSettings { props.setProperty("allowUntrusted", allowUntrusted.toString()) props.setProperty("crawlerResponse", crawlerResponse.toString()) props.setProperty("nickname", nickname) + props.setProperty("downloadLocation", downloadLocation.getAbsolutePath()) props.store(out, "") } diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index b4fc9539..68367be4 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -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)) } diff --git a/gui/griffon-app/lifecycle/Ready.groovy b/gui/griffon-app/lifecycle/Ready.groovy index b472416c..b70c823c 100644 --- a/gui/griffon-app/lifecycle/Ready.groovy +++ b/gui/griffon-app/lifecycle/Ready.groovy @@ -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)