コード例 #1
0
  /**
   * Creates a returns a temporary local file/directory with the same extension as the specified
   * file/directory (guaranteed), and the same filename as much as possible (best effort). This
   * method returns <code>null</code> if the temporary file/directory could not be created.
   *
   * @param nonLocalFile the non-local file for which to create a temporary file.
   * @return a temporary local file/directory with the same extension as the specified
   *     file/directory
   */
  protected LocalFile createTempLocalFile(AbstractFile nonLocalFile) {
    try {
      // Note: the returned temporary file may be an AbstractArchiveFile if the filename's extension
      // corresponds
      // to a registered archive format
      LocalFile tempFile =
          FileFactory.getTemporaryFile(nonLocalFile.getName(), false).getAncestor(LocalFile.class);

      // create a directory
      if (nonLocalFile.isDirectory()) {
        tempFile.mkdir();
      } else { // create a regular file
        tempFile.getOutputStream().close();
      }
      return tempFile;
    } catch (IOException e) {
      return null;
    }
  }
コード例 #2
0
  public Icon getFileIcon(AbstractFile originalFile, Dimension preferredResolution) {
    // Specified file is a LocalFile or a ProxyFile proxying a LocalFile (e.g. an archive file):
    // let's simply get
    // the icon using #getLocalFileIcon(LocalFile)
    AbstractFile topFile = originalFile.getTopAncestor();
    Icon icon;

    if (topFile instanceof LocalFile) {
      icon = getLocalFileIcon((LocalFile) topFile, originalFile, preferredResolution);
    }
    // File is a remote file: create a temporary local file (or directory) with the same extension
    // to grab the icon
    // and then delete the file. This operation is I/O bound and thus expensive, so an LRU is used
    // to cache
    // frequently-accessed file extensions.
    else {
      // create the temporary, local file
      LocalFile tempFile = createTempLocalFile(topFile);
      if (tempFile == null) {
        // No temp file, no icon!
        return null;
      }

      // Get the file icon
      icon = getLocalFileIcon(tempFile, originalFile, preferredResolution);

      // Delete the temporary file
      try {
        tempFile.delete();
      } catch (IOException e) {
        // Not much to do
      }
    }

    return icon;
  }
コード例 #3
0
  /**
   * Tries to find an existing user Trash folder and returns it. If no existing Trash folder was
   * found, creates the standard Xfce user Trash folder and returns it.
   *
   * @return the user Trash folder, <code>null</code> if no user trash folder could be found or
   *     created
   */
  private static AbstractFile getTrashFolder() {
    AbstractFile userHome = LocalFile.getUserHome();

    AbstractFile trashDir = userHome.getChildSilently(".local/share/Trash/");
    if (isTrashFolder(trashDir)) {
      return trashDir;
    }

    // No existing user trash was found: create the folder, only if it doesn't already exist.
    if (!trashDir.exists()) {
      try {
        trashDir.mkdirs();
        trashDir.getChild("info").mkdir();
        trashDir.getChild("files").mkdir();

        return trashDir;
      } catch (IOException e) {
        // Will return null
      }
    }

    return null;
  }