예제 #1
0
 public void delete(ContainerSelection _selection, IConfirmationListener _confirmationListener) {
   if (_selection.getSize() == 1) {
     Object obj = _selection.getValueAt(0);
     if (obj instanceof FIDPlaylistTreeNode) {
       FIDPlaylistTreeNode playlistTreeNode = (FIDPlaylistTreeNode) obj;
       FIDPlaylist playlist = playlistTreeNode.getPlaylist();
       int confirmation =
           _confirmationListener.confirm(
               "Are you sure want to remove the " + playlist.getTitle() + " soup?", playlist);
       if (confirmation == IConfirmationListener.YES) {
         int index = _selection.getIndexAt(0);
         BasicContainerTreeNode containerTreeNode =
             (BasicContainerTreeNode) _selection.getContainer();
         containerTreeNode.remove(index);
         if (playlist.getReferenceCount() == 0) {
           playlist.delete();
         }
         DefaultTreeModel treeModel = playlistTreeNode.getTreeModel();
         treeModel.nodesWereRemoved(
             containerTreeNode, new int[] {index}, new Object[] {playlistTreeNode});
         SoupUtils.removeTransientSoupPlaylist(index - 1);
       }
     }
   }
 }
예제 #2
0
 public void actionPerformed(ActionEvent _event) {
   ContainerSelection selection = myContext.getSelection();
   if (selection != null) {
     IContainer container = selection.getContainer();
     if (container instanceof IFIDPlaylistWrapper) {
       FIDPlaylist playlist = ((IFIDPlaylistWrapper) container).getPlaylist();
       int[] selectedIndexes = selection.getSelectedIndexes();
       int[] newIndexes = playlist.reposition(selectedIndexes, -1);
       // MODIFIED
       myContext.setSelection(this, new ContainerSelection(myContext, playlist, newIndexes));
     }
   }
 }
예제 #3
0
  public synchronized void performSearch() throws ParseException {
    PlayerDatabase playerDatabase = myContext.getPlayerDatabase();
    IPredicate predicate = getPredicate();
    NodeFinder searcher = new NodeFinder(playerDatabase);
    FIDPlaylist searchPlaylist;
    if (predicate == null) {
      searchPlaylist = null;
    } else {
      searchPlaylist = searcher.findMatches(predicate.toString(), predicate, true);
    }
    showSearchResults(searchPlaylist);

    if (myLastSearchPlaylist != null && myLastSearchPlaylist.getReferenceCount() == 0) {
      myLastSearchPlaylist.delete();
    }

    myLastSearchPlaylist = searchPlaylist;
  }
예제 #4
0
  /**
   * Downloads the given node from the device onto your local machine, performing filename
   * evaluation and tag rewriting if you have any tagwriters installed. Normally this would be in
   * SynchronizeUI with all the other downloading code, but if you ever wanted to initiate a
   * download without a UI, you could call this method.
   *
   * @param _path a treepath that points to the desired node (this can be a path of one entry that
   *     is the node's parent if you have EmplodeConstants.DOWNLOAD_FULL_PATH_PROPERTY disabled)
   * @param _node the node to download
   * @param _index the index of the node in its parent (some evaluated tags care about this)
   * @param _protocolClient the ProtocolClient to download with
   * @param _baseDir the base folder to download into
   * @param _changeSet the change set that will contain the results of the download
   * @param _packetSize the packet size to download with
   * @param _useHijack lame, but it has to come from somewhere -- this says whether or not the
   *     hijack API's should be used
   * @param _progressListener the progress listener to report download status to
   * @throws IOException if the download files
   */
  public static void downloadFile(
      TreePath _path,
      IFIDNode _node,
      int _index,
      IProtocolClient _protocolClient,
      File _baseDir,
      FIDChangeSet _changeSet,
      int _packetSize,
      boolean _useHijack,
      IProgressListener _progressListener)
      throws IOException {
    if (!_progressListener.isStopRequested()) {
      PropertiesManager propertiesManager = PropertiesManager.getInstance();
      try {
        _progressListener.operationStarted(ResourceBundleUtils.getUIString("download.operation"));

        File targetDir;
        boolean downloadFullPath =
            propertiesManager.getBooleanProperty(JEmplodeProperties.DOWNLOAD_FULL_PATH_PROPERTY);
        if (downloadFullPath) {
          StringBuffer fullPath = new StringBuffer();
          int size = _path.getPathCount();
          for (int i = size - 1; i >= 0; i--) {
            IFIDNode node = (IFIDNode) _path.getPathComponent(i);
            fullPath.insert(0, File.separator);
            fullPath.insert(0, FileUtils.cleanseFilename(node.getTitle(), true));
          }
          targetDir = new File(_baseDir, fullPath.toString());
        } else {
          targetDir = _baseDir;
        }

        File targetFile = null;
        if (_node instanceof FIDPlaylist) {
          FIDPlaylist playlist = (FIDPlaylist) _node;

          String filenameFormatBase =
              (playlist.isTransient())
                  ? JEmplodeProperties.FILENAME_FORMAT_SOUP_BASE
                  : JEmplodeProperties.FILENAME_FORMAT_BASE;
          String filenameFormat =
              propertiesManager.getProperty(
                  filenameFormatBase + playlist.getTags().getValue(DatabaseTags.TYPE_TAG));
          String parsedName =
              FileUtils.cleanseFilename(
                  new NodeTagStringEvaluator(playlist).evaluate(filenameFormat), false);
          if (filenameFormat == null || filenameFormat.indexOf('{') == -1) {
            filenameFormat =
                PropertiesManager.getDefaults()
                    .getProperty(JEmplodeProperties.FILENAME_FORMAT_PLAYLIST_KEY);
          }
          targetFile = new File(targetDir, parsedName);
          targetFile.mkdirs();

          int size = playlist.getSize();
          _progressListener.operationUpdated(0, size);
          for (int i = 0; i < size; i++) {
            IFIDNode node = playlist.getNodeAt(i);
            File newDir = (downloadFullPath) ? _baseDir : targetFile;
            downloadFile(
                _path.pathByAddingChild(playlist),
                node,
                i,
                _protocolClient,
                newDir,
                _changeSet,
                _packetSize,
                _useHijack,
                _progressListener);
            _progressListener.operationStarted(
                ResourceBundleUtils.getUIString(
                    "download.downloadFile.operation", new Object[] {parsedName}));
            _progressListener.operationUpdated(i + 1, size);
          }
        } else {
          try {
            FIDPlaylist parentPlaylist = (FIDPlaylist) _path.getLastPathComponent();
            IFIDNode child = parentPlaylist.getNodeAt(_index);
            String filenameFormatBase =
                (parentPlaylist.isTransient())
                    ? JEmplodeProperties.FILENAME_FORMAT_SOUP_BASE
                    : JEmplodeProperties.FILENAME_FORMAT_BASE;
            String filenameFormat =
                propertiesManager.getProperty(
                    filenameFormatBase + child.getTags().getValue(DatabaseTags.TYPE_TAG));
            if (filenameFormat == null || filenameFormat.indexOf('{') == -1) {
              filenameFormat =
                  PropertiesManager.getDefaults()
                      .getProperty(JEmplodeProperties.FILENAME_FORMAT_TAXI_KEY);
            }
            String parsedName =
                FileUtils.cleanseFilename(
                    new NodeTagStringEvaluator(parentPlaylist, _index).evaluate(filenameFormat),
                    false);

            targetFile = new File(targetDir, parsedName);
            String targetFileStr = targetFile.getParent();
            if (targetFileStr != null) {
              // make sure all directories are created
              new File(targetFileStr).mkdirs();
            }

            if (!targetFile.exists()) {
              OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile));
              _progressListener.taskStarted(
                  ResourceBundleUtils.getUIString(
                      "download.downloadFile.operation", new Object[] {parsedName}));
              RemoteImportFile remoteFile = RemoteImportFile.createInstance(_node, _protocolClient);
              InputStream is = remoteFile.getInputStream(_useHijack);
              try {
                StreamUtils.copy(is, os, _packetSize, _node.getLength(), _progressListener);
              } finally {
                is.close();
              }
              os.close();
              _changeSet.nodeAdded(_node);

              try {
                ITagWriter tagWriter = TagWriterFactory.createTagWriter(_node);
                tagWriter.writeTags(_node, parentPlaylist, targetFile);
              } catch (Throwable t) {
                // That's OK ...
                Debug.println(Debug.WARNING, t);
              }
            } else {
              IImportFile importFile = ImportFileFactory.createImportFile(targetFile);
              _changeSet.fileSkipped(
                  importFile, ResourceBundleUtils.getUIString("download.downloadFile.skipped"));
            }
          } catch (IOException e) {
            Debug.println(e);
            IImportFile importFile = ImportFileFactory.createImportFile(targetFile);
            _changeSet.fileFailed(importFile, e);
            try {
              targetFile.delete();
            } catch (Throwable t) {
              Debug.println(e);
            }
            // myEmplode.handleError("Failed to download " + targetFile.getName(), e);
          }
        }
      } finally {
        _progressListener.operationUpdated(1, 1);
      }
    }
  }