Search in sources :

Example 6 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class LibraryPlaylistsTransferHandler method importData.

@Override
public boolean importData(TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }
    DropLocation location = support.getDropLocation();
    int index = list.locationToIndex(location.getDropPoint());
    if (index != -1) {
        // depending on the mouse position detect which playlist item the drop was done
        Playlist playlist = getTargetPlaylist(location, index);
        if (playlist == null) {
            if (createNewPlaylist(support)) {
                return false;
            }
        } else {
            try {
                Transferable transferable = support.getTransferable();
                final DataFlavor[] dataFlavors = transferable.getTransferDataFlavors();
                if (DNDUtils.contains(dataFlavors, LibraryPlaylistsTableTransferable.ITEM_ARRAY)) {
                    PlaylistItem[] playlistItems = LibraryUtils.convertToPlaylistItems((LibraryPlaylistsTableTransferable.PlaylistItemContainer) transferable.getTransferData(LibraryPlaylistsTableTransferable.ITEM_ARRAY));
                    LibraryUtils.asyncAddToPlaylist(playlist, playlistItems);
                } else {
                    File[] files = DNDUtils.getFiles(support.getTransferable());
                    if (files.length == 1 && files[0].getAbsolutePath().endsWith(".m3u")) {
                        LibraryUtils.asyncAddToPlaylist(playlist, files[0]);
                    } else {
                        // importing a regular file
                        LibraryUtils.asyncAddToPlaylist(playlist, files);
                    }
                }
            } catch (Throwable e) {
                return false;
            }
        }
    } else {
        return false;
    }
    return false;
}
Also used : Playlist(com.frostwire.alexandria.Playlist) Transferable(java.awt.datatransfer.Transferable) File(java.io.File) PlaylistItem(com.frostwire.alexandria.PlaylistItem) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 7 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class LibraryUtils method convertToPlaylistItems.

static PlaylistItem[] convertToPlaylistItems(LibraryPlaylistsTableTransferable.Item[] items) {
    List<PlaylistItem> playlistItems = new ArrayList<>(items.length);
    for (LibraryPlaylistsTableTransferable.Item item : items) {
        PlaylistItem playlistItem = new PlaylistItem(null, item.id, item.filePath, item.fileName, item.fileSize, item.fileExtension, item.trackTitle, item.trackDurationInSecs, item.trackArtist, item.trackAlbum, item.coverArtPath, item.trackBitrate, item.trackComment, item.trackGenre, item.trackNumber, item.trackYear, item.starred);
        playlistItems.add(playlistItem);
    }
    return playlistItems.toArray(new PlaylistItem[0]);
}
Also used : Item(com.frostwire.gui.library.LibraryPlaylistsTableTransferable.Item) ArrayList(java.util.ArrayList) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 8 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class LibraryUtils method movePlaylistItemsToIndex.

static void movePlaylistItemsToIndex(Playlist playlist, int[] selectedIndexes, int index) {
    List<PlaylistItem> items = playlist.getItems();
    int targetIndex = index;
    // first, order items in list correctly
    for (int i = 0; i < selectedIndexes.length; i++) {
        int sourceIndex = selectedIndexes[i];
        if (sourceIndex != targetIndex) {
            items.add(targetIndex, items.get(sourceIndex));
            items.remove(sourceIndex < targetIndex ? sourceIndex : sourceIndex + 1);
            // adjust remaining selected indexes if insertion point is greater than their location
            for (int j = i + 1; j < selectedIndexes.length; j++) {
                if (targetIndex > selectedIndexes[j]) {
                    selectedIndexes[j]--;
                }
            }
            // update insertion point
            if (sourceIndex > targetIndex) {
                targetIndex++;
            }
        }
    }
    // second, generate new indexes based list order
    for (int i = 0; i < items.size(); i++) {
        PlaylistItem item = items.get(i);
        // set index (1-based)
        item.setSortIndexByTrackNumber(i + 1);
        item.save();
    }
    // initiate UI refresh
    GUIMediator.safeInvokeLater(new Runnable() {

        public void run() {
            LibraryMediator.instance().getLibraryPlaylists().refreshSelection();
        }
    });
}
Also used : PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 9 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class LibraryUtils method getPlaylistDurationInDDHHMMSS.

static String getPlaylistDurationInDDHHMMSS(Playlist playlist) {
    List<PlaylistItem> items = playlist.getItems();
    float totalSecs = 0;
    for (PlaylistItem item : items) {
        totalSecs += item.getTrackDurationInSecs();
    }
    return getSecondsInDDHHMMSS((int) totalSecs);
}
Also used : PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 10 with PlaylistItem

use of com.frostwire.alexandria.PlaylistItem in project frostwire by frostwire.

the class LibraryUtils method addPlaylistItem.

private static void addPlaylistItem(Playlist playlist, File file, boolean starred, int index) {
    try {
        LibraryMediator.instance().getLibrarySearch().pushStatus(I18n.tr("Importing") + " " + file.getName());
        TagsData mt = new TagsReader(file).parse();
        PlaylistItem item = playlist.newItem(file.getAbsolutePath(), file.getName(), file.length(), FilenameUtils.getExtension(file.getName()), mt.getTitle(), mt.getDuration(), mt.getArtist(), mt.getAlbum(), // TODO: cover art path
        "", mt.getBitrate(), mt.getComment(), mt.getGenre(), mt.getTrack(), mt.getYear(), starred || playlist.isStarred());
        List<PlaylistItem> items = playlist.getItems();
        if (index != -1 && index < items.size()) {
            // insert item
            items.add(index, item);
            // update all sort indexes from insertion point onwards
            for (int i = index; i < items.size(); i++) {
                PlaylistItem curItem = items.get(i);
                curItem.setSortIndexByTrackNumber(i + 1);
                curItem.save();
            }
        } else {
            items.add(item);
            // fall back index would be it being the last track.
            item.setSortIndexByTrackNumber(items.size());
            item.save(item.isStarred());
        }
        if (isPlaylistSelected(playlist)) {
            // refresh UI
            LibraryMediator.instance().getLibraryPlaylists().refreshSelection();
        }
    } finally {
        LibraryMediator.instance().getLibrarySearch().revertStatus();
    }
}
Also used : TagsData(com.frostwire.gui.library.tags.TagsData) TagsReader(com.frostwire.gui.library.tags.TagsReader) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Aggregations

PlaylistItem (com.frostwire.alexandria.PlaylistItem)28 ArrayList (java.util.ArrayList)8 File (java.io.File)7 Transferable (java.awt.datatransfer.Transferable)4 Playlist (com.frostwire.alexandria.Playlist)3 Item (com.frostwire.gui.library.LibraryPlaylistsTableTransferable.Item)3 List (java.util.List)3 TagsReader (com.frostwire.gui.library.tags.TagsReader)2 SkinMenuItem (com.frostwire.gui.theme.SkinMenuItem)2 SkinPopupMenu (com.frostwire.gui.theme.SkinPopupMenu)2 MigLayout (net.miginfocom.swing.MigLayout)2 TagsData (com.frostwire.gui.library.tags.TagsData)1 IsoFile (com.frostwire.mp4.IsoFile)1 FileTransferable (com.limegroup.gnutella.gui.dnd.FileTransferable)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 HashSet (java.util.HashSet)1