public void setDownloadPathPopup(NSPopUpButton downloadPathPopup) {
    this.downloadPathPopup = downloadPathPopup;
    this.downloadPathPopup.setTarget(this.id());
    final Selector action = Foundation.selector("downloadPathPopupClicked:");
    this.downloadPathPopup.setAction(action);
    this.downloadPathPopup.removeAllItems();

    // Default download folder
    this.addDownloadPath(action, host.getDownloadFolder());
    this.downloadPathPopup.menu().addItem(NSMenuItem.separatorItem());
    this.addDownloadPath(
        action,
        LocalFactory.createLocal(Preferences.instance().getProperty("queue.download.folder")));
    // Shortcut to the Desktop
    this.addDownloadPath(action, LocalFactory.createLocal("~/Desktop"));
    // Shortcut to user home
    this.addDownloadPath(action, LocalFactory.createLocal("~"));
    // Shortcut to user downloads for 10.5
    this.addDownloadPath(action, LocalFactory.createLocal("~/Downloads"));
    // Choose another folder

    // Choose another folder
    this.downloadPathPopup.menu().addItem(NSMenuItem.separatorItem());
    this.downloadPathPopup
        .menu()
        .addItemWithTitle_action_keyEquivalent(CHOOSE, action, StringUtils.EMPTY);
    this.downloadPathPopup.lastItem().setTarget(this.id());
  }
示例#2
0
 public void didMount(NSNotification notification) {
   log.debug("didMount");
   unmount = new CountDownLatch(1);
   try {
     Local folder = LocalFactory.createLocal(mountpoint, session.home().getAbsolute());
     reveal.reveal(folder);
   } catch (IOException e) {
     log.warn(e.getMessage());
   }
 }
 public void pkSelectionPanelDidEnd_returnCode_contextInfo(
     NSOpenPanel sheet, int returncode, ID contextInfo) {
   log.debug("pkSelectionPanelDidEnd");
   if (returncode == NSPanel.NSOKButton) {
     NSArray selected = sheet.filenames();
     NSEnumerator enumerator = selected.objectEnumerator();
     NSObject next;
     while (((next = enumerator.nextObject()) != null)) {
       host.getCredentials().setIdentity(LocalFactory.createLocal(next.toString()));
     }
   }
   if (returncode == NSPanel.NSCancelButton) {
     host.getCredentials().setIdentity(null);
   }
   this.init();
   this.itemChanged();
 }
 @Action
 public void downloadPathPopupClicked(final NSMenuItem sender) {
   if (sender.title().equals(CHOOSE)) {
     downloadPathPanel = NSOpenPanel.openPanel();
     downloadPathPanel.setCanChooseFiles(false);
     downloadPathPanel.setCanChooseDirectories(true);
     downloadPathPanel.setAllowsMultipleSelection(false);
     downloadPathPanel.setCanCreateDirectories(true);
     downloadPathPanel.beginSheetForDirectory(
         null,
         null,
         this.window,
         this.id(),
         Foundation.selector("downloadPathPanelDidEnd:returnCode:contextInfo:"),
         null);
   } else {
     host.setDownloadFolder(LocalFactory.createLocal(sender.representedObject()));
     this.itemChanged();
   }
 }
 public void downloadPathPanelDidEnd_returnCode_contextInfo(
     NSOpenPanel sheet, int returncode, ID contextInfo) {
   if (returncode == SheetCallback.DEFAULT_OPTION) {
     NSArray selected = sheet.filenames();
     if ((selected.lastObject()) != null) {
       host.setDownloadFolder(LocalFactory.createLocal(selected.lastObject().toString()));
     }
   }
   downloadPathPopup
       .itemAtIndex(new NSInteger(0))
       .setTitle(host.getDownloadFolder().getDisplayName());
   downloadPathPopup
       .itemAtIndex(new NSInteger(0))
       .setRepresentedObject(host.getDownloadFolder().getAbsolute());
   downloadPathPopup
       .itemAtIndex(new NSInteger(0))
       .setImage(IconCache.instance().iconForPath(host.getDownloadFolder(), 16));
   downloadPathPopup.selectItemAtIndex(new NSInteger(0));
   downloadPathPanel = null;
   this.itemChanged();
 }
 @Action
 public void pkCheckboxSelectionChanged(final NSButton sender) {
   log.debug("pkCheckboxSelectionChanged");
   if (sender.state() == NSCell.NSOnState) {
     publicKeyPanel = NSOpenPanel.openPanel();
     publicKeyPanel.setCanChooseDirectories(false);
     publicKeyPanel.setCanChooseFiles(true);
     publicKeyPanel.setAllowsMultipleSelection(false);
     publicKeyPanel.setMessage(
         Locale.localizedString("Select the private key in PEM or PuTTY format", "Credentials"));
     publicKeyPanel.setPrompt(Locale.localizedString("Choose"));
     publicKeyPanel.beginSheetForDirectory(
         LocalFactory.createLocal("~/.ssh").getAbsolute(),
         null,
         this.window(),
         this.id(),
         Foundation.selector("pkSelectionPanelDidEnd:returnCode:contextInfo:"),
         null);
   } else {
     this.pkSelectionPanelDidEnd_returnCode_contextInfo(
         publicKeyPanel, NSPanel.NSCancelButton, null);
   }
 }
示例#7
0
  @Override
  public void mount(Session s) {
    if (!this.isAvailable()) {
      this.invoke(
          new DefaultMainAction() {
            @Override
            public void run() {}
          });
      return;
    }
    session = s;
    filesystem = GMUserFileSystem.create((fileystemCallback = new FSCallback()).id(), true);

    NSNotificationCenter center = NSNotificationCenter.defaultCenter();
    center.addObserver(
        fileystemCallback.id(),
        Foundation.selector("mountFailed:"),
        GMUserFileSystem.kGMUserFileSystemMountFailed,
        null);
    center.addObserver(
        fileystemCallback.id(),
        Foundation.selector("didMount:"),
        GMUserFileSystem.kGMUserFileSystemDidMount,
        null);
    center.addObserver(
        fileystemCallback.id(),
        Foundation.selector("didUnmount:"),
        GMUserFileSystem.kGMUserFileSystemDidUnmount,
        null);

    final NSMutableArray options = NSMutableArray.array();
    options.addObject(
        "volicon="
            + NSBundle.mainBundle()
                .pathForResource_ofType(session.getHost().getProtocol().disk(), "icns"));
    // You can use the volname option to specify a name for the MacFUSE volume being mounted. This
    // is the name that would show up on the Desktop. In the absence of this option, MacFUSE will
    // automatically generate a name that would incorporate the MacFUSE device index and the
    // user-space file system being used. For example, an SSHFS mount might have an automatically
    // assigned name "MacFUSE Volume 0 (sshfs)".
    final String volume = session.getHost().getHostname();
    options.addObject("volname=" + volume);
    // By default, if MacFUSE detects a change in a file's size during getattr(), it will purge
    // that file's buffer cache. When auto_cache is enabled, MacFUSE will additionally
    // detect modification time changes during getattr() and open() and will automatically
    // purge the buffer cache and/or attributes of the file if necessary. It will also
    // generate the relevant kqueue messages. All this is subject to the attribute timeout.
    // That is, up to one purge can occur per attribute timeout window. As long as the
    // user-space file system's getattr() callback returns up-to-date size and modification
    // time information, this should work as intended. For user-space file systems that wish
    // the kernel to keep up with "remote" changes, this should obviate the need for explicit
    // purging. auto_cache is not enabled by default: it's opt-in.
    options.addObject("auto_cache");
    // This option makes MacFUSE deny all types of access to extended attributes that begin with the
    // "com.apple." prefix. On Mac OS X 10.5.x, this is the preferred option if you wish to disallow
    // entities such as resource forks and Finder information.
    options.addObject("noapplexattr");
    // This option makes MacFUSE deny all types of access to Apple Double (._) files and .DS_Store
    // files. Any existing files will become apparently non-existent. New files that match the
    // criteria will be disallowed from being created.
    options.addObject("noappledouble");
    mountpoint = LocalFactory.createLocal("/Volumes/" + volume);
    if (mountpoint.exists()) {
      // Make sure we do not mount to a already existing path
      final String parent = mountpoint.getParent().getAbsolute();
      int no = 0;
      while (mountpoint.exists()) {
        no++;
        String proposal = volume + "-" + no;
        mountpoint = LocalFactory.createLocal(parent, proposal);
      }
    }
    filesystem.mountAtPath_withOptions_shouldForeground_detachNewThread(
        mountpoint.getAbsolute(), options, true, true);
  }
示例#8
0
 /**
  * The custom folder if any or the default download location
  *
  * @return Absolute path
  */
 public Local getDownloadFolder() {
   if (null == downloadFolder) {
     return LocalFactory.createLocal(Preferences.instance().getProperty("queue.download.folder"));
   }
   return downloadFolder;
 }
示例#9
0
 /** @param serialized A valid bookmark dictionary */
 public <T> Host(T serialized) {
   final Deserializer dict = DeserializerFactory.createDeserializer(serialized);
   Object uuidObj = dict.stringForKey("UUID");
   if (uuidObj != null) {
     this.setUuid(uuidObj.toString());
   }
   Object protocolObj = dict.stringForKey("Protocol");
   if (protocolObj != null) {
     this.setProtocol(ProtocolFactory.forName(protocolObj.toString()));
   }
   Object providerObj = dict.stringForKey("Provider");
   if (providerObj != null) {
     this.setProtocol(ProtocolFactory.forName(providerObj.toString()));
   }
   Object hostnameObj = dict.stringForKey("Hostname");
   if (hostnameObj != null) {
     this.setHostname(hostnameObj.toString());
   }
   Object usernameObj = dict.stringForKey("Username");
   if (usernameObj != null) {
     credentials.setUsername(usernameObj.toString());
   }
   Object passwordObj = dict.stringForKey("Password");
   if (passwordObj != null) {
     credentials.setPassword(passwordObj.toString());
   }
   Object cdnCredentialsObj = dict.stringForKey("CDN Credentials");
   if (cdnCredentialsObj != null) {
     cdnCredentials.setUsername(cdnCredentialsObj.toString());
   }
   Object keyObj = dict.stringForKey("Private Key File");
   if (keyObj != null) {
     this.getCredentials().setIdentity(LocalFactory.createLocal(keyObj.toString()));
   }
   Object portObj = dict.stringForKey("Port");
   if (portObj != null) {
     this.setPort(Integer.parseInt(portObj.toString()));
   }
   Object pathObj = dict.stringForKey("Path");
   if (pathObj != null) {
     this.setDefaultPath(pathObj.toString());
   }
   Object workdirObj = dict.stringForKey("Workdir");
   if (workdirObj != null) {
     this.setWorkdir(workdirObj.toString());
   }
   Object nicknameObj = dict.stringForKey("Nickname");
   if (nicknameObj != null) {
     this.setNickname(nicknameObj.toString());
   }
   Object encodingObj = dict.stringForKey("Encoding");
   if (encodingObj != null) {
     this.setEncoding(encodingObj.toString());
   }
   Object connectModeObj = dict.stringForKey("FTP Connect Mode");
   if (connectModeObj != null) {
     if (connectModeObj.toString().equals(FTPConnectMode.PORT.toString())) {
       this.setFTPConnectMode(FTPConnectMode.PORT);
     }
     if (connectModeObj.toString().equals(FTPConnectMode.PASV.toString())) {
       this.setFTPConnectMode(FTPConnectMode.PASV);
     }
   }
   Object connObj = dict.stringForKey("Maximum Connections");
   if (connObj != null) {
     this.setMaxConnections(Integer.valueOf(connObj.toString()));
   }
   Object downloadObj = dict.stringForKey("Download Folder");
   if (downloadObj != null) {
     this.setDownloadFolder(LocalFactory.createLocal(downloadObj.toString()));
   }
   Object timezoneObj = dict.stringForKey("Timezone");
   if (timezoneObj != null) {
     this.setTimezone(TimeZone.getTimeZone(timezoneObj.toString()));
   }
   Object commentObj = dict.stringForKey("Comment");
   if (commentObj != null) {
     this.setComment(commentObj.toString());
   }
   Object urlObj = dict.stringForKey("Web URL");
   if (urlObj != null) {
     this.setWebURL(urlObj.toString());
   }
   Object accessObj = dict.stringForKey("Access Timestamp");
   if (accessObj != null) {
     this.setTimestamp(new Date(Long.parseLong(accessObj.toString())));
   }
 }
示例#10
0
/** @version $Id: IconCache.java 10832 2013-04-10 14:57:36Z dkocher $ */
public final class IconCache {
  private static Logger log = Logger.getLogger(IconCache.class);

  /**
   * No resizing of the cached image.
   *
   * @param name Icon filename with extension
   * @return Cached icon
   */
  public static NSImage iconNamed(final String name) {
    return IconCache.instance().iconForName(name);
  }

  /**
   * @param name Icon filename with extension
   * @param size Requested size
   * @return Cached icon
   */
  public static NSImage iconNamed(final String name, final Integer size) {
    return IconCache.instance().iconForName(name, size);
  }

  /**
   * @param name Name to lookup
   * @param width Requested size
   * @param height Requested size
   * @return Cached icon
   */
  public static NSImage iconNamed(final String name, final Integer width, final Integer height) {
    return IconCache.instance().iconForName(name, width, height);
  }

  /**
   * @param size Requested size
   * @return Standard folder icon for this platform
   */
  public static NSImage folderIcon(final Integer size) {
    return IconCache.instance().iconForFolder(size);
  }

  public static NSImage documentIcon(final String extension) {
    return IconCache.instance().iconForExtension(extension, null);
  }

  public static NSImage documentIcon(final String extension, final Integer size) {
    return IconCache.instance().iconForExtension(extension, size);
  }

  public static NSImage aliasIcon(final String extension, final Integer size) {
    return IconCache.instance()
        .badge(
            IconCache.instance().iconForName("aliasbadge.tiff", size),
            IconCache.instance().iconForExtension(extension, size));
  }

  private static IconCache instance = null;

  private static final Object lock = new Object();

  public static IconCache instance() {
    synchronized (lock) {
      if (null == instance) {
        instance = new IconCache();
      }
    }
    return instance;
  }

  private IconCache() {
    //
  }

  /** Cache limited to n entries */
  private Map<String, Map<Integer, NSImage>> cache =
      new LRUMap(Preferences.instance().getInteger("icon.cache.size")) {
        @Override
        protected boolean removeLRU(LinkEntry entry) {
          if (log.isDebugEnabled()) {
            log.debug("Removing from cache:" + entry);
          }
          return true;
        }
      };

  private void put(final String key, final NSImage image, final Integer size) {
    Map<Integer, NSImage> versions;
    if (cache.containsKey(key)) {
      versions = cache.get(key);
    } else {
      versions = new HashMap<Integer, NSImage>();
    }
    versions.put(size, image);
    cache.put(key, versions);
  }

  private NSImage load(final String key, final Integer size) {
    if (!cache.containsKey(key)) {
      log.debug(String.format("No cached image for %s", key));
      return null;
    }
    final Map<Integer, NSImage> versions = cache.get(key);
    return versions.get(size);
  }

  /**
   * @param extension File type
   * @param size Requested size
   * @return Cached icon
   */
  public NSImage iconForExtension(final String extension, final Integer size) {
    NSImage image = this.load(extension, size);
    if (null == image) {
      image = NSWorkspace.sharedWorkspace().iconForFileType(extension);
      this.put(extension, this.convert(image, size), size);
    }
    return image;
  }

  public NSImage iconForExtension(final NSImage badge, final String extension, final Integer size) {
    final String name = extension + badge.name();
    NSImage icon = this.iconForName(name, size);
    if (null == icon) {
      icon = this.badge(badge, this.iconForExtension(extension, size));
      this.put(name, icon, size);
    }
    return icon;
  }

  public NSImage iconForFolder(final Integer size) {
    NSImage folder = this.iconForName("NSFolder", size);
    if (null == folder) {
      return this.iconForPath(FOLDER_PATH, size);
    }
    return folder;
  }

  private NSImage iconForFolder(final NSImage badge, final Integer size) {
    final String name = String.format("NSFolder-%s", badge.name());
    NSImage folder = this.iconForName(name, size);
    if (null == folder) {
      folder = this.badge(badge, this.convert(FOLDER_ICON, size));
      this.put(name, folder, size);
    }
    return folder;
  }

  /**
   * Overlay badge image.
   *
   * @param badge Overlay
   * @param icon Icon
   * @return Cached icon
   */
  private NSImage badge(final NSImage badge, final NSImage icon) {
    NSImage f = NSImage.imageWithSize(icon.size());
    f.lockFocus();
    icon.drawInRect(
        new NSRect(new NSPoint(0, 0), icon.size()),
        NSZeroRect,
        NSGraphics.NSCompositeSourceOver,
        1.0f);
    badge.drawInRect(
        new NSRect(new NSPoint(0, 0), icon.size()),
        NSZeroRect,
        NSGraphics.NSCompositeSourceOver,
        1.0f);
    f.unlockFocus();
    return f;
  }

  /**
   * @param name Icon name
   * @return Cached image
   */
  protected NSImage iconForName(final String name) {
    return this.iconForName(name, null);
  }

  /**
   * @param name Icon filename with extension
   * @param size Requested size
   * @return Cached image
   * @see #convert(ch.cyberduck.ui.cocoa.application.NSImage, Integer)
   */
  protected NSImage iconForName(final String name, final Integer size) {
    return this.iconForName(name, size, size);
  }

  /**
   * @param name When looking for files in the application bundle, it is better (but not required)
   *     to include the filename extension in the name parameter
   * @param width Requested size
   * @param height Requested size
   * @return Cached icon
   * @see NSImage#imageNamed(String)
   * @see #convert(ch.cyberduck.ui.cocoa.application.NSImage, Integer, Integer)
   */
  protected NSImage iconForName(final String name, final Integer width, final Integer height) {
    NSImage image = this.load(name, width);
    if (null == image) {
      if (name.startsWith("/")) {
        image = NSImage.imageWithContentsOfFile(name);
      } else {
        image = NSImage.imageNamed(name);
      }
      if (null == image) {
        log.warn(String.format("No icon named %s", name));
        this.put(name, null, width);
      } else {
        // You can clear an image object from the cache explicitly by passing nil for the image
        // name.
        image.setName(null);
        this.put(name, this.convert(image, width, height), width);
      }
    }
    return image;
  }

  public NSImage iconForPath(final Local item) {
    return this.iconForPath(item, null);
  }

  /**
   * @param item File
   * @param size Requested size
   * @return Cached icon
   */
  public NSImage iconForPath(final Local item, final Integer size) {
    NSImage icon = null;
    if (item.exists()) {
      icon = this.load(item.getAbsolute(), size);
      if (null == icon) {
        icon = NSWorkspace.sharedWorkspace().iconForFile(item.getAbsolute());
        this.put(item.getAbsolute(), this.convert(icon, size), size);
      }
    }
    if (null == icon) {
      return this.iconForName("notfound.tiff", size);
    }
    return icon;
  }

  public NSImage iconForApplication(final String bundleIdentifier) {
    return this.iconForApplication(bundleIdentifier, null);
  }

  /**
   * @param bundleIdentifier Application
   * @param size Requested size
   * @return Cached icon
   */
  public NSImage iconForApplication(final String bundleIdentifier, final Integer size) {
    NSImage icon = this.load(bundleIdentifier, size);
    if (null == icon) {
      icon =
          NSWorkspace.sharedWorkspace()
              .iconForFile(
                  NSWorkspace.sharedWorkspace()
                      .absolutePathForAppBundleWithIdentifier(bundleIdentifier));
      this.put(bundleIdentifier, this.convert(icon, size), size);
    }
    if (null == icon) {
      return this.iconForName("notfound.tiff", size);
    }
    return icon;
  }

  private final NSRect NSZeroRect = new NSRect(0, 0);

  private static final Local FOLDER_PATH =
      LocalFactory.createLocal(Preferences.instance().getProperty("application.support.path"));

  private final NSImage FOLDER_ICON = this.iconForPath(FOLDER_PATH);

  /**
   * @param item File
   * @param size Requested size
   * @return Cached icon
   */
  public NSImage iconForPath(final Path item, final Integer size) {
    return this.iconForPath(
        item, size, Preferences.instance().getBoolean("browser.markInaccessibleFolders"));
  }

  public NSImage iconForPath(final Path item, final Integer size, final boolean overlay) {
    if (item.attributes().isSymbolicLink()) {
      final NSImage badge = this.iconForName("aliasbadge.tiff", size);
      badge.setName("aliasbadge");
      if (item.attributes().isDirectory()) {
        return this.iconForFolder(badge, size);
      }
      return this.iconForExtension(badge, item.getExtension(), size);
    }
    if (item.attributes().isFile()) {
      if (StringUtils.isEmpty(item.getExtension())) {
        if (item.attributes().getPermission().isExecutable()) {
          return this.iconForName("executable.tiff", size);
        }
      }
      return this.iconForExtension(item.getExtension(), size);
    }
    if (item.attributes().isVolume()) {
      return this.iconForName(item.getHost().getProtocol().disk(), size);
    }
    if (item.attributes().isDirectory()) {
      if (overlay) {
        if (!item.attributes().getPermission().isExecutable()) {
          final NSImage badge = this.iconForName("privatefolderbadge.tiff", size);
          badge.setName("privatefolderbadge");
          return this.iconForFolder(badge, size);
        }
        if (!item.attributes().getPermission().isReadable()) {
          if (item.attributes().getPermission().isWritable()) {
            final NSImage badge = this.iconForName("dropfolderbadge.tiff", size);
            badge.setName("dropfolderbadge");
            return this.iconForFolder(badge, size);
          }
        }
        if (!item.attributes().getPermission().isWritable()) {
          final NSImage badge = this.iconForName("readonlyfolderbadge.tiff", size);
          badge.setName("readonlyfolderbadge");
          return this.iconForFolder(badge, size);
        }
      }
      return this.iconForFolder(size);
    }
    return this.iconForName("notfound.tiff", size);
  }

  public NSImage convert(final NSImage icon, final Integer size) {
    return this.convert(icon, size, size);
  }

  public NSImage convert(final NSImage icon, final Integer width, final Integer height) {
    if (null == width || null == height) {
      log.debug(String.format("Return default size for %s", icon.name()));
      return icon;
    }
    icon.setSize(new NSSize(width, height));
    return icon;
  }
}