Fix transcript in transfer window.
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / BookmarkController.java
blobc32fe15398df60f1c35e0e4681bf7b1efc8c785e
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.*;
22 import ch.cyberduck.binding.foundation.NSArray;
23 import ch.cyberduck.binding.foundation.NSData;
24 import ch.cyberduck.binding.foundation.NSNotification;
25 import ch.cyberduck.binding.foundation.NSNotificationCenter;
26 import ch.cyberduck.binding.foundation.NSObject;
27 import ch.cyberduck.binding.foundation.NSURL;
28 import ch.cyberduck.core.AbstractCollectionListener;
29 import ch.cyberduck.core.BookmarkCollection;
30 import ch.cyberduck.core.BookmarkNameProvider;
31 import ch.cyberduck.core.DefaultCharsetProvider;
32 import ch.cyberduck.core.Host;
33 import ch.cyberduck.core.HostParser;
34 import ch.cyberduck.core.HostUrlProvider;
35 import ch.cyberduck.core.Local;
36 import ch.cyberduck.core.LocalFactory;
37 import ch.cyberduck.core.LocaleFactory;
38 import ch.cyberduck.core.Protocol;
39 import ch.cyberduck.core.ProtocolFactory;
40 import ch.cyberduck.core.diagnostics.ReachabilityFactory;
41 import ch.cyberduck.core.exception.BackgroundException;
42 import ch.cyberduck.core.ftp.FTPConnectMode;
43 import ch.cyberduck.core.local.BrowserLauncherFactory;
44 import ch.cyberduck.core.preferences.Preferences;
45 import ch.cyberduck.core.preferences.PreferencesFactory;
46 import ch.cyberduck.core.resources.IconCacheFactory;
47 import ch.cyberduck.core.threading.AbstractBackgroundAction;
48 import ch.cyberduck.ui.browser.DownloadDirectoryFinder;
50 import org.apache.commons.lang3.StringUtils;
51 import org.apache.log4j.Logger;
52 import org.rococoa.Foundation;
53 import org.rococoa.ID;
54 import org.rococoa.Selector;
55 import org.rococoa.cocoa.foundation.NSInteger;
56 import org.rococoa.cocoa.foundation.NSSize;
58 import java.util.Arrays;
59 import java.util.Collections;
60 import java.util.Comparator;
61 import java.util.List;
62 import java.util.TimeZone;
64 /**
65 * @version $Id$
67 public class BookmarkController extends WindowController {
68 private static Logger log = Logger.getLogger(BookmarkController.class);
70 private final Preferences preferences = PreferencesFactory.get();
72 @Outlet
73 private NSPopUpButton protocolPopup;
75 public void setProtocolPopup(NSPopUpButton protocolPopup) {
76 this.protocolPopup = protocolPopup;
77 this.protocolPopup.setEnabled(true);
78 this.protocolPopup.setTarget(this.id());
79 this.protocolPopup.setAction(Foundation.selector("protocolSelectionChanged:"));
80 this.protocolPopup.removeAllItems();
81 for(Protocol protocol : ProtocolFactory.getEnabledProtocols()) {
82 final String title = protocol.getDescription();
83 this.protocolPopup.addItemWithTitle(title);
84 final NSMenuItem item = this.protocolPopup.itemWithTitle(title);
85 item.setRepresentedObject(String.valueOf(protocol.hashCode()));
86 item.setImage(IconCacheFactory.<NSImage>get().iconNamed(protocol.icon(), 16));
90 @Action
91 public void protocolSelectionChanged(final NSPopUpButton sender) {
92 final Protocol selected = ProtocolFactory.forName(protocolPopup.selectedItem().representedObject());
93 if(log.isDebugEnabled()) {
94 log.debug(String.format("Protocol selection changed to %s", selected));
96 host.setPort(selected.getDefaultPort());
97 if(!host.getProtocol().isHostnameConfigurable()) {
98 // Previously selected protocol had a default hostname. Change to default
99 // of newly selected protocol.
100 host.setHostname(selected.getDefaultHostname());
102 if(!selected.isHostnameConfigurable()) {
103 // Hostname of newly selected protocol is not configurable. Change to default.
104 host.setHostname(selected.getDefaultHostname());
106 if(StringUtils.isNotBlank(selected.getDefaultHostname())) {
107 // Prefill with default hostname
108 host.setHostname(selected.getDefaultHostname());
110 host.setProtocol(selected);
111 this.itemChanged();
112 this.init();
113 this.reachable();
116 @Outlet
117 private NSPopUpButton encodingPopup;
119 public void setEncodingPopup(NSPopUpButton encodingPopup) {
120 this.encodingPopup = encodingPopup;
121 this.encodingPopup.setEnabled(true);
122 this.encodingPopup.removeAllItems();
123 this.encodingPopup.addItemWithTitle(DEFAULT);
124 this.encodingPopup.menu().addItem(NSMenuItem.separatorItem());
125 this.encodingPopup.addItemsWithTitles(NSArray.arrayWithObjects(new DefaultCharsetProvider().availableCharsets()));
126 if(null == host.getEncoding()) {
127 this.encodingPopup.selectItemWithTitle(DEFAULT);
129 else {
130 this.encodingPopup.selectItemWithTitle(host.getEncoding());
132 this.encodingPopup.setTarget(this.id());
133 final Selector action = Foundation.selector("encodingSelectionChanged:");
134 this.encodingPopup.setAction(action);
137 @Action
138 public void encodingSelectionChanged(final NSPopUpButton sender) {
139 if(sender.selectedItem().title().equals(DEFAULT)) {
140 host.setEncoding(null);
142 else {
143 host.setEncoding(sender.selectedItem().title());
145 this.itemChanged();
148 @Outlet
149 private NSTextField nicknameField;
151 public void setNicknameField(NSTextField nicknameField) {
152 this.nicknameField = nicknameField;
153 NSNotificationCenter.defaultCenter().addObserver(this.id(),
154 Foundation.selector("nicknameInputDidChange:"),
155 NSControl.NSControlTextDidChangeNotification,
156 this.nicknameField);
159 @Outlet
160 private NSTextField hostField;
162 public void setHostField(NSTextField hostField) {
163 this.hostField = hostField;
164 NSNotificationCenter.defaultCenter().addObserver(this.id(),
165 Foundation.selector("hostFieldDidChange:"),
166 NSControl.NSControlTextDidChangeNotification,
167 hostField);
170 @Outlet
171 private NSButton alertIcon;
173 public void setAlertIcon(NSButton alertIcon) {
174 this.alertIcon = alertIcon;
175 this.alertIcon.setEnabled(false);
176 this.alertIcon.setImage(null);
177 this.alertIcon.setTarget(this.id());
178 this.alertIcon.setAction(Foundation.selector("launchNetworkAssistant:"));
181 @Action
182 public void launchNetworkAssistant(final NSButton sender) {
183 ReachabilityFactory.get().diagnose(host);
186 @Outlet
187 private NSTextField portField;
189 public void setPortField(NSTextField portField) {
190 this.portField = portField;
191 NSNotificationCenter.defaultCenter().addObserver(this.id(),
192 Foundation.selector("portInputDidEndEditing:"),
193 NSControl.NSControlTextDidChangeNotification,
194 this.portField);
197 @Outlet
198 private NSTextField pathField;
200 public void setPathField(NSTextField pathField) {
201 this.pathField = pathField;
202 NSNotificationCenter.defaultCenter().addObserver(this.id(),
203 Foundation.selector("pathInputDidChange:"),
204 NSControl.NSControlTextDidChangeNotification,
205 this.pathField);
208 @Outlet
209 private NSTextField urlField;
211 public void setUrlField(NSTextField urlField) {
212 this.urlField = urlField;
213 this.urlField.setAllowsEditingTextAttributes(true);
214 this.urlField.setSelectable(true);
217 @Outlet
218 private NSTextField usernameField;
220 public void setUsernameField(NSTextField usernameField) {
221 this.usernameField = usernameField;
222 NSNotificationCenter.defaultCenter().addObserver(this.id(),
223 Foundation.selector("usernameInputDidChange:"),
224 NSControl.NSControlTextDidChangeNotification,
225 this.usernameField);
228 @Outlet
229 private NSButton anonymousCheckbox;
231 public void setAnonymousCheckbox(NSButton anonymousCheckbox) {
232 this.anonymousCheckbox = anonymousCheckbox;
233 this.anonymousCheckbox.setTarget(this.id());
234 this.anonymousCheckbox.setAction(Foundation.selector("anonymousCheckboxClicked:"));
235 this.anonymousCheckbox.setState(NSCell.NSOffState);
238 @Outlet
239 private NSTextField webURLField;
241 public void setWebURLField(NSTextField webURLField) {
242 this.webURLField = webURLField;
243 final NSTextFieldCell cell = this.webURLField.cell();
244 cell.setPlaceholderString(host.getDefaultWebURL());
245 NSNotificationCenter.defaultCenter().addObserver(this.id(),
246 Foundation.selector("webURLInputDidChange:"),
247 NSControl.NSControlTextDidChangeNotification,
248 this.webURLField);
251 @Outlet
252 private NSButton webUrlImage;
254 public void setWebUrlImage(NSButton b) {
255 this.webUrlImage = b;
256 this.webUrlImage.setTarget(this.id());
257 this.webUrlImage.setAction(Foundation.selector("openWebUrl:"));
258 this.webUrlImage.setImage(IconCacheFactory.<NSImage>get().iconNamed("site.tiff", 16));
261 private NSImage favicon;
266 private void updateFavicon() {
267 if(preferences.getBoolean("bookmark.favicon.download")) {
268 this.background(new AbstractBackgroundAction<Void>() {
269 @Override
270 public Void run() throws BackgroundException {
271 final String f = host.getProtocol().favicon();
272 if(StringUtils.isNotBlank(f)) {
273 favicon = IconCacheFactory.<NSImage>get().iconNamed(f, 16);
275 else {
276 String url = host.getWebURL() + "/favicon.ico";
277 // Default favicon location
278 final NSData data = NSData.dataWithContentsOfURL(NSURL.URLWithString(url));
279 if(null == data) {
280 return null;
282 favicon = NSImage.imageWithData(data);
284 if(null != favicon) {
285 favicon.setSize(new NSSize(16, 16));
287 return null;
290 @Override
291 public void cleanup() {
292 if(null != favicon) {
293 webUrlImage.setImage(favicon);
297 @Override
298 public Object lock() {
299 return host;
305 @Action
306 public void openWebUrl(final NSButton sender) {
307 BrowserLauncherFactory.get().open(host.getWebURL());
310 @Outlet
311 private NSTextView commentField;
313 public void setCommentField(NSTextView commentField) {
314 this.commentField = commentField;
315 this.commentField.setFont(NSFont.userFixedPitchFontOfSize(11f));
316 NSNotificationCenter.defaultCenter().addObserver(this.id(),
317 Foundation.selector("commentInputDidChange:"),
318 NSText.TextDidChangeNotification,
319 this.commentField);
323 * Calculate timezone
325 protected static final String AUTO = LocaleFactory.localizedString("Auto");
327 @Outlet
328 private NSPopUpButton timezonePopup;
330 private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
332 private static final String TIMEZONE_CONTINENT_PREFIXES =
333 "^(Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific)/.*";
335 public void setTimezonePopup(NSPopUpButton timezonePopup) {
336 this.timezonePopup = timezonePopup;
337 this.timezonePopup.setTarget(this.id());
338 this.timezonePopup.setAction(Foundation.selector("timezonePopupClicked:"));
339 this.timezonePopup.removeAllItems();
340 final List<String> timezones = Arrays.asList(TimeZone.getAvailableIDs());
341 this.timezonePopup.addItemWithTitle(UTC.getID());
342 this.timezonePopup.lastItem().setRepresentedObject(UTC.getID());
343 this.timezonePopup.menu().addItem(NSMenuItem.separatorItem());
344 Collections.sort(timezones, new Comparator<String>() {
345 @Override
346 public int compare(String o1, String o2) {
347 return TimeZone.getTimeZone(o1).getID().compareTo(TimeZone.getTimeZone(o2).getID());
350 for(String tz : timezones) {
351 if(tz.matches(TIMEZONE_CONTINENT_PREFIXES)) {
352 this.timezonePopup.addItemWithTitle(String.format("%s", tz));
353 this.timezonePopup.lastItem().setRepresentedObject(tz);
358 @Action
359 public void timezonePopupClicked(NSPopUpButton sender) {
360 String selected = sender.selectedItem().representedObject();
361 if(selected.equals(AUTO)) {
362 host.setTimezone(null);
364 else {
365 String[] ids = TimeZone.getAvailableIDs();
366 for(String id : ids) {
367 TimeZone tz;
368 if((tz = TimeZone.getTimeZone(id)).getID().equals(selected)) {
369 host.setTimezone(tz);
370 break;
374 this.itemChanged();
377 @Outlet
378 private NSPopUpButton connectmodePopup;
380 public void setConnectmodePopup(NSPopUpButton connectmodePopup) {
381 this.connectmodePopup = connectmodePopup;
382 this.connectmodePopup.setTarget(this.id());
383 this.connectmodePopup.setAction(Foundation.selector("connectmodePopupClicked:"));
384 this.connectmodePopup.removeAllItems();
385 for(FTPConnectMode m : FTPConnectMode.values()) {
386 this.connectmodePopup.addItemWithTitle(m.toString());
387 this.connectmodePopup.lastItem().setRepresentedObject(m.name());
388 if(m.equals(FTPConnectMode.unknown)) {
389 this.connectmodePopup.menu().addItem(NSMenuItem.separatorItem());
394 @Action
395 public void connectmodePopupClicked(final NSPopUpButton sender) {
396 host.setFTPConnectMode(FTPConnectMode.valueOf(sender.selectedItem().representedObject()));
397 this.itemChanged();
400 @Outlet
401 private NSPopUpButton transferPopup;
403 public void setTransferPopup(NSPopUpButton transferPopup) {
404 this.transferPopup = transferPopup;
405 this.transferPopup.setTarget(this.id());
406 this.transferPopup.setAction(Foundation.selector("transferPopupClicked:"));
407 this.transferPopup.removeAllItems();
408 final Host.TransferType unknown = Host.TransferType.unknown;
409 this.transferPopup.addItemWithTitle(unknown.toString());
410 this.transferPopup.lastItem().setRepresentedObject(unknown.name());
411 this.transferPopup.menu().addItem(NSMenuItem.separatorItem());
412 for(String name : preferences.getList("queue.transfer.type.enabled")) {
413 final Host.TransferType t = Host.TransferType.valueOf(name);
414 this.transferPopup.addItemWithTitle(t.toString());
415 this.transferPopup.lastItem().setRepresentedObject(t.name());
419 @Action
420 public void transferPopupClicked(final NSPopUpButton sender) {
421 host.setTransfer(Host.TransferType.valueOf(sender.selectedItem().representedObject()));
422 this.itemChanged();
425 @Outlet
426 private NSPopUpButton downloadPathPopup;
428 private static final String CHOOSE = LocaleFactory.localizedString("Choose") + "…";
430 public void setDownloadPathPopup(NSPopUpButton downloadPathPopup) {
431 this.downloadPathPopup = downloadPathPopup;
432 this.downloadPathPopup.setTarget(this.id());
433 final Selector action = Foundation.selector("downloadPathPopupClicked:");
434 this.downloadPathPopup.setAction(action);
435 this.downloadPathPopup.removeAllItems();
437 // Default download folder
438 this.addDownloadPath(action, new DownloadDirectoryFinder().find(host));
439 this.downloadPathPopup.menu().addItem(NSMenuItem.separatorItem());
440 this.addDownloadPath(action, LocalFactory.get(preferences.getProperty("queue.download.folder")));
441 // Shortcut to the Desktop
442 this.addDownloadPath(action, LocalFactory.get("~/Desktop"));
443 // Shortcut to user home
444 this.addDownloadPath(action, LocalFactory.get("~"));
445 // Shortcut to user downloads for 10.5
446 this.addDownloadPath(action, LocalFactory.get("~/Downloads"));
447 // Choose another folder
449 // Choose another folder
450 this.downloadPathPopup.menu().addItem(NSMenuItem.separatorItem());
451 this.downloadPathPopup.menu().addItemWithTitle_action_keyEquivalent(CHOOSE, action, StringUtils.EMPTY);
452 this.downloadPathPopup.lastItem().setTarget(this.id());
455 private void addDownloadPath(Selector action, Local f) {
456 if(downloadPathPopup.menu().itemWithTitle(f.getDisplayName()) == null) {
457 downloadPathPopup.menu().addItemWithTitle_action_keyEquivalent(f.getDisplayName(), action, StringUtils.EMPTY);
458 downloadPathPopup.lastItem().setTarget(this.id());
459 downloadPathPopup.lastItem().setImage(IconCacheFactory.<NSImage>get().fileIcon(f, 16));
460 downloadPathPopup.lastItem().setRepresentedObject(f.getAbsolute());
461 if(new DownloadDirectoryFinder().find(host).equals(f)) {
462 downloadPathPopup.selectItem(downloadPathPopup.lastItem());
467 private NSOpenPanel downloadPathPanel;
469 @Action
470 public void downloadPathPopupClicked(final NSMenuItem sender) {
471 if(sender.title().equals(CHOOSE)) {
472 downloadPathPanel = NSOpenPanel.openPanel();
473 downloadPathPanel.setCanChooseFiles(false);
474 downloadPathPanel.setCanChooseDirectories(true);
475 downloadPathPanel.setAllowsMultipleSelection(false);
476 downloadPathPanel.setCanCreateDirectories(true);
477 downloadPathPanel.beginSheetForDirectory(null, null, this.window, this.id(),
478 Foundation.selector("downloadPathPanelDidEnd:returnCode:contextInfo:"), null);
480 else {
481 final Local folder = LocalFactory.get(sender.representedObject());
482 host.setDownloadFolder(folder);
483 this.itemChanged();
487 public void downloadPathPanelDidEnd_returnCode_contextInfo(NSOpenPanel sheet, int returncode, ID contextInfo) {
488 if(returncode == SheetCallback.DEFAULT_OPTION) {
489 final NSObject selected = sheet.filenames().lastObject();
490 if(selected != null) {
491 host.setDownloadFolder(LocalFactory.get(selected.toString()));
494 final NSMenuItem item = downloadPathPopup.itemAtIndex(new NSInteger(0));
495 final Local folder = new DownloadDirectoryFinder().find(host);
496 item.setTitle(folder.getDisplayName());
497 item.setRepresentedObject(folder.getAbsolute());
498 item.setImage(IconCacheFactory.<NSImage>get().fileIcon(folder, 16));
499 downloadPathPopup.selectItem(item);
500 downloadPathPanel = null;
501 this.itemChanged();
504 @Outlet
505 private NSButton toggleOptionsButton;
507 public void setToggleOptionsButton(NSButton toggleOptionsButton) {
508 this.toggleOptionsButton = toggleOptionsButton;
512 * The bookmark
514 private Host host;
517 * @param host The bookmark to edit
519 public BookmarkController(final Host host) {
520 this.host = host;
521 // Register for bookmark delete event. Will close this window.
522 BookmarkCollection.defaultCollection().addListener(bookmarkCollectionListener);
523 this.loadBundle();
526 private final AbstractCollectionListener<Host> bookmarkCollectionListener = new AbstractCollectionListener<Host>() {
527 @Override
528 public void collectionItemRemoved(Host item) {
529 if(item.equals(host)) {
530 final NSWindow window = window();
531 if(null != window) {
532 window.close();
538 @Override
539 public void invalidate() {
540 preferences.setProperty("bookmark.toggle.options", this.toggleOptionsButton.state());
541 BookmarkCollection.defaultCollection().removeListener(bookmarkCollectionListener);
542 super.invalidate();
545 @Override
546 protected String getBundleName() {
547 return "Bookmark";
550 @Override
551 public void awakeFromNib() {
552 this.cascade();
553 this.init();
554 this.setState(this.toggleOptionsButton, preferences.getBoolean("bookmark.toggle.options"));
555 this.reachable();
556 this.updateFavicon();
558 super.awakeFromNib();
561 @Override
562 public void setWindow(NSWindow window) {
563 window.setContentMinSize(window.frame().size);
564 window.setContentMaxSize(new NSSize(600, window.frame().size.height.doubleValue()));
565 super.setWindow(window);
568 @Outlet
569 private NSTextField pkLabel;
571 public void setPkLabel(NSTextField pkLabel) {
572 this.pkLabel = pkLabel;
575 @Outlet
576 private NSButton pkCheckbox;
578 public void setPkCheckbox(NSButton pkCheckbox) {
579 this.pkCheckbox = pkCheckbox;
580 this.pkCheckbox.setTarget(this.id());
581 this.pkCheckbox.setAction(Foundation.selector("pkCheckboxSelectionChanged:"));
584 private NSOpenPanel publicKeyPanel;
586 @Action
587 public void pkCheckboxSelectionChanged(final NSButton sender) {
588 if(sender.state() == NSCell.NSOnState) {
589 publicKeyPanel = NSOpenPanel.openPanel();
590 publicKeyPanel.setCanChooseDirectories(false);
591 publicKeyPanel.setCanChooseFiles(true);
592 publicKeyPanel.setAllowsMultipleSelection(false);
593 publicKeyPanel.setMessage(LocaleFactory.localizedString("Select the private key in PEM or PuTTY format", "Credentials"));
594 publicKeyPanel.setPrompt(LocaleFactory.localizedString("Choose"));
595 publicKeyPanel.beginSheetForDirectory(LocalFactory.get("~/.ssh").getAbsolute(), null, this.window(), this.id(),
596 Foundation.selector("publicKeyPanelDidEnd:returnCode:contextInfo:"), null);
598 else {
599 this.publicKeyPanelDidEnd_returnCode_contextInfo(publicKeyPanel, NSPanel.NSCancelButton, null);
603 public void publicKeyPanelDidEnd_returnCode_contextInfo(NSOpenPanel sheet, int returncode, ID contextInfo) {
604 if(returncode == NSPanel.NSOKButton) {
605 final NSObject selected = publicKeyPanel.filenames().lastObject();
606 if(selected != null) {
607 final Local key = LocalFactory.get(selected.toString());
608 host.getCredentials().setIdentity(key);
611 if(returncode == NSPanel.NSCancelButton) {
612 host.getCredentials().setIdentity(null);
614 this.init();
615 this.itemChanged();
618 @Action
619 public void hostFieldDidChange(final NSNotification sender) {
620 final String input = hostField.stringValue();
621 final Host parsed = HostParser.parse(input);
622 host.setHostname(parsed.getHostname());
623 if(ProtocolFactory.isURL(input)) {
624 host.setProtocol(parsed.getProtocol());
625 host.setPort(parsed.getPort());
626 host.setDefaultPath(parsed.getDefaultPath());
628 this.itemChanged();
629 this.init();
630 this.reachable();
633 private void reachable() {
634 if(StringUtils.isNotBlank(host.getHostname())) {
635 this.background(new AbstractBackgroundAction<Boolean>() {
636 boolean reachable = false;
638 @Override
639 public Boolean run() throws BackgroundException {
640 return reachable = ReachabilityFactory.get().isReachable(host);
643 @Override
644 public void cleanup() {
645 alertIcon.setEnabled(!reachable);
646 alertIcon.setImage(reachable ? null : IconCacheFactory.<NSImage>get().iconNamed("alert.tiff"));
650 else {
651 alertIcon.setImage(IconCacheFactory.<NSImage>get().iconNamed("alert.tiff"));
652 alertIcon.setEnabled(false);
656 @Action
657 public void portInputDidEndEditing(final NSNotification sender) {
658 try {
659 host.setPort(Integer.valueOf(portField.stringValue()));
661 catch(NumberFormatException e) {
662 host.setPort(-1);
664 this.itemChanged();
665 this.init();
666 this.reachable();
669 @Action
670 public void pathInputDidChange(final NSNotification sender) {
671 host.setDefaultPath(pathField.stringValue());
672 this.itemChanged();
673 this.init();
676 @Action
677 public void nicknameInputDidChange(final NSNotification sender) {
678 host.setNickname(nicknameField.stringValue());
679 this.itemChanged();
680 this.init();
683 @Action
684 public void usernameInputDidChange(final NSNotification sender) {
685 host.getCredentials().setUsername(usernameField.stringValue());
686 this.itemChanged();
687 this.init();
690 @Action
691 public void anonymousCheckboxClicked(final NSButton sender) {
692 if(sender.state() == NSCell.NSOnState) {
693 host.getCredentials().setUsername(preferences.getProperty("connection.login.anon.name"));
695 if(sender.state() == NSCell.NSOffState) {
696 if(preferences.getProperty("connection.login.name").equals(
697 preferences.getProperty("connection.login.anon.name"))) {
698 host.getCredentials().setUsername(StringUtils.EMPTY);
700 else {
701 host.getCredentials().setUsername(preferences.getProperty("connection.login.name"));
704 this.itemChanged();
705 this.init();
708 @Action
709 public void webURLInputDidChange(final NSNotification sender) {
710 host.setWebURL(webURLField.stringValue());
711 this.updateFavicon();
712 this.itemChanged();
715 @Action
716 public void commentInputDidChange(final NSNotification sender) {
717 host.setComment(commentField.textStorage().string());
718 this.itemChanged();
722 * Updates the window title and url label with the properties of this bookmark
723 * Propagates all fields with the properties of this bookmark
725 private void itemChanged() {
726 BookmarkCollection.defaultCollection().collectionItemChanged(host);
729 private void init() {
730 window.setTitle(BookmarkNameProvider.toString(host));
731 this.updateField(hostField, host.getHostname());
732 hostField.setEnabled(host.getProtocol().isHostnameConfigurable());
733 hostField.cell().setPlaceholderString(host.getProtocol().getDefaultHostname());
734 this.updateField(nicknameField, BookmarkNameProvider.toString(host));
735 urlField.setAttributedStringValue(HyperlinkAttributedStringFactory.create(new HostUrlProvider(true, true).get(host)));
736 this.updateField(portField, String.valueOf(host.getPort()));
737 portField.setEnabled(host.getProtocol().isPortConfigurable());
738 this.updateField(pathField, host.getDefaultPath());
739 this.updateField(usernameField, host.getCredentials().getUsername());
740 usernameField.cell().setPlaceholderString(host.getProtocol().getUsernamePlaceholder());
741 usernameField.setEnabled(!host.getCredentials().isAnonymousLogin());
742 anonymousCheckbox.setEnabled(host.getProtocol().isAnonymousConfigurable());
743 anonymousCheckbox.setState(host.getCredentials().isAnonymousLogin() ? NSCell.NSOnState : NSCell.NSOffState);
744 protocolPopup.selectItemAtIndex(
745 protocolPopup.indexOfItemWithRepresentedObject(String.valueOf(host.getProtocol().hashCode()))
747 transferPopup.selectItemAtIndex(transferPopup.indexOfItemWithRepresentedObject(host.getTransfer().name()));
748 encodingPopup.setEnabled(host.getProtocol().isEncodingConfigurable());
749 connectmodePopup.setEnabled(host.getProtocol().getType() == Protocol.Type.ftp);
750 if(host.getProtocol().getType() == Protocol.Type.ftp) {
751 connectmodePopup.selectItemAtIndex(connectmodePopup.indexOfItemWithRepresentedObject(host.getFTPConnectMode().name()));
753 pkCheckbox.setEnabled(host.getProtocol().getType() == Protocol.Type.ssh);
754 if(host.getCredentials().isPublicKeyAuthentication()) {
755 pkCheckbox.setState(NSCell.NSOnState);
756 this.updateField(pkLabel, host.getCredentials().getIdentity().getAbbreviatedPath(), TRUNCATE_MIDDLE_ATTRIBUTES);
757 pkLabel.setTextColor(NSColor.textColor());
759 else {
760 pkCheckbox.setState(NSCell.NSOffState);
761 pkLabel.setStringValue(LocaleFactory.localizedString("No private key selected"));
762 pkLabel.setTextColor(NSColor.disabledControlTextColor());
764 final String webURL = host.getWebURL();
765 webUrlImage.setToolTip(webURL);
766 this.updateField(webURLField, host.getDefaultWebURL().equals(webURL) ? null : webURL);
767 this.updateField(commentField, host.getComment());
768 this.timezonePopup.setEnabled(!host.getProtocol().isUTCTimezone());
769 if(null == host.getTimezone()) {
770 if(host.getProtocol().isUTCTimezone()) {
771 this.timezonePopup.setTitle(UTC.getID());
773 else {
774 if(preferences.getBoolean("ftp.timezone.auto")) {
775 this.timezonePopup.setTitle(AUTO);
777 else {
778 this.timezonePopup.setTitle(
779 TimeZone.getTimeZone(preferences.getProperty("ftp.timezone.default")).getID()
784 else {
785 this.timezonePopup.setTitle(host.getTimezone().getID());