Ejemplo n.º 1
0
  public void refreshSelection() {

    LibraryPlaylistsListCell cell = (LibraryPlaylistsListCell) _list.getSelectedValue();

    if (cell == null) {
      // handle special case
      if (_model.getSize() == 2 && MediaPlayer.instance().getCurrentPlaylist() == null) {
        _list.setSelectedIndex(1);
      }
      return;
    }

    Playlist playlist = cell.getPlaylist();

    if (playlist != null) {
      playlist.refresh();
      LibraryMediator.instance().updateTableItems(playlist);
      String status =
          LibraryUtils.getPlaylistDurationInDDHHMMSS(playlist)
              + ", "
              + playlist.getItems().size()
              + " "
              + I18n.tr("tracks");
      LibraryMediator.instance().getLibrarySearch().setStatus(status);
    }

    executePendingRunnables();
  }
 private void resetAudioPlayerFileView() {
   Playlist playlist = MediaPlayer.instance().getCurrentPlaylist();
   if (playlist != null && playlist.equals(currentPlaylist)) {
     if (MediaPlayer.instance().getPlaylistFilesView() != null) {
       MediaPlayer.instance().setPlaylistFilesView(getFilesView());
     }
   }
 }
Ejemplo n.º 3
0
 public String getDescription() {
   if (_description != null) {
     return _description;
   } else if (_playlist != null && _playlist.getDescription() != null) {
     return _playlist.getDescription();
   } else {
     return "";
   }
 }
Ejemplo n.º 4
0
 public String getText() {
   if (_text != null) {
     return _text;
   } else if (_playlist != null && _playlist.getName() != null) {
     return _playlist.getName();
   } else {
     return "";
   }
 }
Ejemplo n.º 5
0
 public void actionPerformed(ActionEvent e) {
   Playlist playlist = getSelectedPlaylist();
   if (playlist != null) {
     List<File> files = new ArrayList<File>();
     for (PlaylistItem item : playlist.getItems()) {
       File file = new File(item.getFilePath());
       files.add(file);
     }
     iTunesMediator.instance().addSongsiTunes(playlist.getName(), files.toArray(new File[0]));
   }
 }
Ejemplo n.º 6
0
  private void renameSelectedItem(int index) {
    if (!_textName.isVisible() || _textName.getText().trim().length() == 0) {
      return;
    }

    Playlist selectedPlaylist = getSelectedPlaylist();

    selectedPlaylist.setName(_textName.getText().trim());
    selectedPlaylist.save();

    _list.repaint();
    _textName.setVisible(false);
  }
  /** Delete selected items from a playlist (not from disk) */
  public void removeSelection() {

    LibraryPlaylistsTableDataLine[] lines = getSelectedLibraryLines();

    if (currentPlaylist != null && currentPlaylist.getId() == LibraryDatabase.STARRED_PLAYLIST_ID) {
      for (LibraryPlaylistsTableDataLine line : lines) {
        PlaylistItem playlistItem = line.getInitializeObject();
        playlistItem.setStarred(false);
        playlistItem.save();
      }

      LibraryMediator.instance().getLibraryExplorer().refreshSelection();

    } else {

      for (LibraryPlaylistsTableDataLine line : lines) {
        PlaylistItem playlistItem = line.getInitializeObject();
        playlistItem.delete();
      }

      LibraryMediator.instance().getLibraryPlaylists().reselectPlaylist();

      clearSelection();
    }

    super.removeSelection();
  }
 public AddToPlaylistAction(Playlist playlist) {
   super(getTruncatedString(playlist.getName(), MAX_VISIBLE_PLAYLIST_NAME_LENGTH_IN_MENU));
   putValue(
       Action.LONG_DESCRIPTION,
       I18n.tr("Add to playlist") + " \"" + getValue(Action.NAME) + "\"");
   System.out.println("Truncated playlist name was:" + " " + getValue(Action.NAME));
   this.playlist = playlist;
 }
Ejemplo n.º 9
0
  private void createNewPlaylist() {
    if (!_textName.isVisible()) {
      return;
    }

    String name = _textName.getText();

    Library library = LibraryMediator.getLibrary();

    Playlist playlist = library.newPlaylist(name, name);
    playlist.save();
    LibraryPlaylistsListCell cell =
        new LibraryPlaylistsListCell(
            null, null, GUIMediator.getThemeImage("playlist"), playlist, _selectedPlaylistAction);
    _model.addElement(cell);
    _list.setSelectedValue(cell, true);

    _textName.setVisible(false);
  }
Ejemplo n.º 10
0
  /** Saves a playlist. */
  public void exportM3U(Playlist playlist) {

    if (playlist == null) {
      return;
    }

    String suggestedName = CommonUtils.convertFileName(playlist.getName());

    // get the user to select a new one.... avoid FrostWire installation folder.
    File suggested;
    File suggestedDirectory = FileChooserHandler.getLastInputDirectory();
    if (suggestedDirectory.equals(CommonUtils.getCurrentDirectory())) {
      suggestedDirectory = new File(CommonUtils.getUserHomeDir(), "Desktop");
    }

    suggested = new File(suggestedDirectory, suggestedName + ".m3u");

    File selFile =
        FileChooserHandler.getSaveAsFile(
            GUIMediator.getAppFrame(),
            I18nMarker.marktr("Save Playlist As"),
            suggested,
            new PlaylistListFileFilter());

    // didn't select a file?  nothing we can do.
    if (selFile == null) {
      return;
    }

    // if the file already exists and not the one just opened, ask if it should be
    //  overwritten.
    // TODO: this should be handled in the jfilechooser
    if (selFile.exists()) {
      DialogOption choice =
          GUIMediator.showYesNoMessage(
              I18n.tr(
                  "Warning: a file with the name {0} already exists in the folder. Overwrite this file?",
                  selFile.getName()),
              QuestionsHandler.PLAYLIST_OVERWRITE_OK,
              DialogOption.NO);
      if (choice != DialogOption.YES) return;
    }

    String path = selFile.getPath();
    try {
      path = FileUtils.getCanonicalPath(selFile);
    } catch (IOException ignored) {
      // LOG.warn("unable to get canonical path for file: " + selFile, ignored);
    }
    // force m3u on the end.
    if (!path.toLowerCase().endsWith(".m3u")) path += ".m3u";

    // create a new thread to handle saving the playlist to disk
    saveM3U(playlist, path);
  }
Ejemplo n.º 11
0
    public void actionPerformed(ActionEvent e) {

      Playlist selectedPlaylist = getSelectedPlaylist();

      if (selectedPlaylist != null) {

        int showConfirmDialog =
            JOptionPane.showConfirmDialog(
                GUIMediator.getAppFrame(),
                I18n.tr(
                    "Are you sure you want to delete the playlist?\n(No files will be deleted)"),
                I18n.tr("Are you sure?"),
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE);

        if (showConfirmDialog != JOptionPane.YES_OPTION) {
          return;
        }

        selectedPlaylist.delete();
        _model.removeElement(_list.getSelectedValue());
        LibraryMediator.instance().clearLibraryTable();
      }
    }
  /**
   * Updates the Table based on the selection of the given table. Perform lookups to remove any
   * store files from the shared folder view and to only display store files in the store view
   */
  void updateTableItems(Playlist playlist) {
    if (playlist == null) {
      return;
    }

    currentPlaylist = playlist;
    List<PlaylistItem> items = currentPlaylist.getItems();

    clearTable();
    for (final PlaylistItem item : items) {
      GUIMediator.safeInvokeLater(
          new Runnable() {
            @Override
            public void run() {
              addUnsorted(item);
            }
          });
    }
    forceResort();
  }
Ejemplo n.º 13
0
  public void selectCurrentSong() {
    // Select current playlist.
    Playlist currentPlaylist = AudioPlayer.instance().getCurrentPlaylist();
    final AudioSource currentSong = AudioPlayer.instance().getCurrentSong();

    // If the current song is being played from a playlist.
    if (currentPlaylist != null && currentSong != null && currentSong.getPlaylistItem() != null) {
      if (currentPlaylist.getId() != LibraryDatabase.STARRED_PLAYLIST_ID) {

        // select the song once it's available on the right hand side
        getLibraryPlaylists()
            .enqueueRunnable(
                new Runnable() {
                  public void run() {
                    GUIMediator.safeInvokeLater(
                        new Runnable() {
                          public void run() {
                            LibraryPlaylistsTableMediator.instance()
                                .setItemSelected(currentSong.getPlaylistItem());
                          }
                        });
                  }
                });

        // select the playlist
        getLibraryPlaylists().selectPlaylist(currentPlaylist);
      } else {
        LibraryExplorer libraryFiles = getLibraryExplorer();

        // select the song once it's available on the right hand side
        libraryFiles.enqueueRunnable(
            new Runnable() {
              public void run() {
                GUIMediator.safeInvokeLater(
                    new Runnable() {
                      public void run() {
                        LibraryPlaylistsTableMediator.instance()
                            .setItemSelected(currentSong.getPlaylistItem());
                      }
                    });
              }
            });

        libraryFiles.selectStarred();
      }

    } else if (currentSong != null && currentSong.getFile() != null) {
      // selects the audio node at the top
      LibraryExplorer libraryFiles = getLibraryExplorer();

      // select the song once it's available on the right hand side
      libraryFiles.enqueueRunnable(
          new Runnable() {
            public void run() {
              GUIMediator.safeInvokeLater(
                  new Runnable() {
                    public void run() {
                      LibraryFilesTableMediator.instance().setFileSelected(currentSong.getFile());
                    }
                  });
            }
          });

      libraryFiles.selectAudio();
    } else if (currentSong instanceof InternetRadioAudioSource) {
      // selects the audio node at the top
      LibraryExplorer libraryFiles = getLibraryExplorer();

      // select the song once it's available on the right hand side
      libraryFiles.enqueueRunnable(
          new Runnable() {
            public void run() {
              GUIMediator.safeInvokeLater(
                  new Runnable() {
                    public void run() {
                      LibraryInternetRadioTableMediator.instance()
                          .setItemSelected(
                              ((InternetRadioAudioSource) currentSong).getInternetRadioStation());
                    }
                  });
            }
          });

      libraryFiles.selectRadio();
    } else if (currentSong instanceof DeviceAudioSource) {
      // selects the audio node at the top
      LibraryExplorer libraryFiles = getLibraryExplorer();

      // select the song once it's available on the right hand side
      libraryFiles.enqueueRunnable(
          new Runnable() {
            public void run() {
              GUIMediator.safeInvokeLater(
                  new Runnable() {
                    public void run() {
                      LibraryDeviceTableMediator.instance()
                          .setItemSelected(((DeviceAudioSource) currentSong).getFileDescriptor());
                    }
                  });
            }
          });

      libraryFiles.selectDeviceFileType(
          ((DeviceAudioSource) currentSong).getDevice(),
          ((DeviceAudioSource) currentSong).getFileDescriptor().fileType);
    }

    // Scroll to current song.
  }
Ejemplo n.º 14
0
    private void copyPlaylistFilesToFolder(Playlist playlist) {
      if (playlist == null || playlist.getItems().isEmpty()) {
        return;
      }

      File suggestedDirectory = FileChooserHandler.getLastInputDirectory();
      if (suggestedDirectory.equals(CommonUtils.getCurrentDirectory())) {
        suggestedDirectory = new File(CommonUtils.getUserHomeDir(), "Desktop");
      }

      final File selFolder =
          FileChooserHandler.getSaveAsDir(
              GUIMediator.getAppFrame(),
              I18nMarker.marktr("Where do you want the playlist files copied to?"),
              suggestedDirectory);

      if (selFolder == null) {
        return;
      }

      // let's make a copy of the list in case the playlist will be modified during the copying.
      final List<PlaylistItem> playlistItems = new ArrayList<>(playlist.getItems());

      BackgroundExecutorService.schedule(
          new Thread("Library-copy-playlist-files") {
            @Override
            public void run() {

              int n = 0;
              int total = playlistItems.size();
              String targetName = selFolder.getName();

              for (PlaylistItem item : playlistItems) {
                File f = new File(item.getFilePath());
                if (f.isFile() && f.exists() && f.canRead()) {
                  try {
                    Path source = f.toPath();
                    Path target =
                        FileSystems.getDefault().getPath(selFolder.getAbsolutePath(), f.getName());
                    Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
                    n++;

                    // invoked on UI thread later
                    String status = String.format("Copied %d of %d to %s", n, total, targetName);
                    LibraryMediator.instance().getLibrarySearch().pushStatus(status);
                  } catch (IOException e) {
                    e.printStackTrace();
                  }
                }
              }

              GUIMediator.launchExplorer(selFolder);

              // and clear the output
              try {
                Thread.sleep(2000);
                LibraryMediator.instance().getLibrarySearch().pushStatus("");
              } catch (InterruptedException e) {
              }
            }
          });
    }