Fix transcript in transfer window.
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / DownloadController.java
blob3f4ff9812f154fcf5b54938d8f99b7dd93d19955
1 package ch.cyberduck.ui.cocoa;
3 /*
4 * Copyright (c) 2005 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * dkocher@cyberduck.ch
21 import ch.cyberduck.binding.application.NSAlert;
22 import ch.cyberduck.binding.application.NSTextField;
23 import ch.cyberduck.core.DefaultPathKindDetector;
24 import ch.cyberduck.core.Host;
25 import ch.cyberduck.core.HostParser;
26 import ch.cyberduck.core.LocalFactory;
27 import ch.cyberduck.core.LocaleFactory;
28 import ch.cyberduck.core.Path;
29 import ch.cyberduck.core.PathKindDetector;
30 import ch.cyberduck.core.PathNormalizer;
31 import ch.cyberduck.core.local.BrowserLauncherFactory;
32 import ch.cyberduck.core.preferences.PreferencesFactory;
33 import ch.cyberduck.core.transfer.DownloadTransfer;
34 import ch.cyberduck.core.transfer.Transfer;
36 import org.apache.commons.lang3.StringUtils;
37 import org.rococoa.cocoa.foundation.NSRect;
39 import java.util.EnumSet;
41 /**
42 * @version $Id$
44 public class DownloadController extends AlertController {
46 protected NSTextField urlField
47 = NSTextField.textfieldWithFrame(new NSRect(0, 22));
49 private PathKindDetector detector = new DefaultPathKindDetector();
51 @Override
52 public void beginSheet() {
53 this.setAccessoryView(urlField);
54 this.updateField(urlField, url);
55 alert.setShowsHelp(true);
56 super.beginSheet();
59 private String url;
61 public DownloadController(final WindowController parent) {
62 this(parent, StringUtils.EMPTY);
65 public DownloadController(final WindowController parent, final String url) {
66 super(parent, NSAlert.alert(
67 LocaleFactory.localizedString("New Download", "Download"),
68 LocaleFactory.localizedString("URL", "Download"),
69 LocaleFactory.localizedString("Download", "Download"),
70 null,
71 LocaleFactory.localizedString("Cancel", "Download")
72 ), NSAlert.NSInformationalAlertStyle);
73 this.url = url;
76 @Override
77 public void callback(final int returncode) {
78 if(returncode == DEFAULT_OPTION) {
79 final Host host = HostParser.parse(urlField.stringValue());
80 final Path file = new Path(PathNormalizer.normalize(host.getDefaultPath(), true),
81 EnumSet.of(detector.detect(host.getDefaultPath())));
82 host.setDefaultPath(file.getParent().getAbsolute());
83 final Transfer transfer = new DownloadTransfer(host, file,
84 LocalFactory.get(PreferencesFactory.get().getProperty("queue.download.folder"), file.getName()));
85 TransferControllerFactory.get().start(transfer);
89 @Override
90 protected void focus() {
91 // Focus accessory view.
92 urlField.selectText(null);
93 this.window().makeFirstResponder(urlField);
96 @Override
97 protected boolean validateInput() {
98 Host host = HostParser.parse(urlField.stringValue());
99 return StringUtils.isNotBlank(host.getDefaultPath());
102 @Override
103 protected void help() {
104 StringBuilder site = new StringBuilder(PreferencesFactory.get().getProperty("website.help"));
105 site.append("/howto/download");
106 BrowserLauncherFactory.get().open(site.toString());