Search in sources :

Example 16 with PlaylistItem

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

the class LibraryPlaylistsTransferHandler method createNewPlaylist.

private boolean createNewPlaylist(TransferSupport support) {
    try {
        Transferable transferable = support.getTransferable();
        if (DNDUtils.contains(transferable.getTransferDataFlavors(), LibraryPlaylistsTableTransferable.ITEM_ARRAY)) {
            Object transferData = transferable.getTransferData(LibraryPlaylistsTableTransferable.ITEM_ARRAY);
            PlaylistItem[] playlistItems = null;
            if (transferData instanceof LibraryPlaylistsTableTransferable.Item[]) {
                playlistItems = LibraryUtils.convertToPlaylistItems((LibraryPlaylistsTableTransferable.Item[]) transferData);
            } else if (transferData instanceof LibraryPlaylistsTableTransferable.PlaylistItemContainer) {
                playlistItems = LibraryUtils.convertToPlaylistItems((LibraryPlaylistsTableTransferable.PlaylistItemContainer) transferData);
            }
            if (playlistItems != null) {
                LibraryUtils.createNewPlaylist(playlistItems);
            }
        } else {
            File[] files = DNDUtils.getFiles(support.getTransferable());
            if (files.length == 1 && files[0].getAbsolutePath().endsWith(".m3u")) {
                LibraryUtils.createNewPlaylist(files[0]);
            } else {
                LibraryUtils.createNewPlaylist(files);
            }
        }
        list.setSelectedIndex(list.getModel().getSize() - 1);
        LibraryMediator.instance().getLibraryPlaylists().refreshSelection();
    } catch (Throwable e) {
        e.printStackTrace();
        return true;
    }
    return false;
}
Also used : Transferable(java.awt.datatransfer.Transferable) File(java.io.File) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 17 with PlaylistItem

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

the class LibraryUtils method convertToPlaylistItems.

static PlaylistItem[] convertToPlaylistItems(LibraryPlaylistsTableTransferable.PlaylistItemContainer itemContainer) {
    List<PlaylistItem> playlistItems = new ArrayList<>(itemContainer.items.size());
    for (LibraryPlaylistsTableTransferable.Item item : itemContainer.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 18 with PlaylistItem

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

the class LibraryUtils method convertToItems.

static List<LibraryPlaylistsTableTransferable.Item> convertToItems(List<PlaylistItem> playlistItems) {
    List<LibraryPlaylistsTableTransferable.Item> items = new ArrayList<>(playlistItems.size());
    for (PlaylistItem playlistItem : playlistItems) {
        Item item = new LibraryPlaylistsTableTransferable.Item();
        item.id = playlistItem.getId();
        item.filePath = playlistItem.getFilePath();
        item.fileName = playlistItem.getFileName();
        item.fileSize = playlistItem.getFileSize();
        item.fileExtension = playlistItem.getFileExtension();
        item.trackTitle = playlistItem.getTrackTitle();
        item.trackDurationInSecs = playlistItem.getTrackDurationInSecs();
        item.trackArtist = playlistItem.getTrackArtist();
        item.trackAlbum = playlistItem.getTrackAlbum();
        item.coverArtPath = playlistItem.getCoverArtPath();
        item.trackBitrate = playlistItem.getTrackBitrate();
        item.trackComment = playlistItem.getTrackComment();
        item.trackGenre = playlistItem.getTrackGenre();
        item.trackNumber = playlistItem.getTrackNumber();
        item.trackYear = playlistItem.getTrackYear();
        item.starred = playlistItem.isStarred();
        items.add(item);
    }
    return items;
}
Also used : PlaylistItem(com.frostwire.alexandria.PlaylistItem) Item(com.frostwire.gui.library.LibraryPlaylistsTableTransferable.Item) ArrayList(java.util.ArrayList) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 19 with PlaylistItem

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

the class LibraryUtils method addToPlaylist.

private static void addToPlaylist(Playlist playlist, PlaylistItem[] playlistItems, boolean starred, int index) {
    List<PlaylistItem> items = playlist.getItems();
    if (index != -1 && index <= items.size()) {
        List<Integer> toRemove = new ArrayList<>(playlistItems.length);
        for (int i = 0; i < playlistItems.length && !playlist.isDeleted(); i++) {
            toRemove.add(playlistItems[i].getId());
            playlistItems[i].setId(LibraryDatabase.OBJECT_NOT_SAVED_ID);
            playlistItems[i].setPlaylist(playlist);
            items.add(index + i, playlistItems[i]);
            playlistItems[i].setStarred(starred || playlist.isStarred());
            playlistItems[i].save();
        }
        for (int i = 0; i < toRemove.size() && !playlist.isDeleted(); i++) {
            int id = toRemove.get(i);
            for (int j = 0; j < items.size() && !playlist.isDeleted(); j++) {
                if (items.get(j).getId() == id) {
                    items.remove(j);
                    break;
                }
            }
        }
        // update sort indexes now that the ordering in the list is correct
        items = playlist.getItems();
        for (int i = 0; i < items.size(); i++) {
            PlaylistItem item = items.get(i);
            // set index 1-based
            item.setSortIndexByTrackNumber(i + 1);
            item.save();
        }
    } else {
        for (int i = 0; i < playlistItems.length && !playlist.isDeleted(); i++) {
            items.add(playlistItems[i]);
            // set sort index to be at the end (1-based)
            playlistItems[i].setSortIndexByTrackNumber(items.size());
            playlistItems[i].setStarred(playlistItems[i].isStarred() || starred || playlist.isStarred());
            playlistItems[i].setPlaylist(playlist);
            playlistItems[i].save();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PlaylistItem(com.frostwire.alexandria.PlaylistItem)

Example 20 with PlaylistItem

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

the class LibraryFilesTransferHandler method importData.

@Override
public boolean importData(TransferSupport support) {
    if (!canImport(support)) {
        return false;
    }
    try {
        Transferable transferable = support.getTransferable();
        LibraryNode node = getNodeFromLocation(support.getDropLocation());
        {
            if (node instanceof DirectoryHolderNode) {
                DirectoryHolder dirHolder = ((DirectoryHolderNode) node).getDirectoryHolder();
                if (droppingFoldersToAddToLibrary(support, dirHolder, false)) {
                    try {
                        // add to library
                        File[] files = DNDUtils.getFiles(support.getTransferable());
                        for (File f : files) {
                            LibrarySettings.DIRECTORIES_TO_INCLUDE.add(f);
                            LibrarySettings.DIRECTORIES_NOT_TO_INCLUDE.remove(f);
                        }
                        LibraryMediator.instance().clearDirectoryHolderCaches();
                        // show tools -> library option pane
                        GUIMediator.instance().setOptionsVisible(true, OptionsConstructor.LIBRARY_KEY);
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            } else if (DNDUtils.contains(transferable.getTransferDataFlavors(), LibraryPlaylistsTableTransferable.ITEM_ARRAY)) {
                PlaylistItem[] playlistItems = LibraryUtils.convertToPlaylistItems((LibraryPlaylistsTableTransferable.Item[]) transferable.getTransferData(LibraryPlaylistsTableTransferable.ITEM_ARRAY));
                LibraryUtils.createNewPlaylist(playlistItems, isStarredDirectoryHolder(support.getDropLocation()));
            } else {
                File[] files = DNDUtils.getFiles(support.getTransferable());
                if (files.length == 1 && files[0].getAbsolutePath().endsWith(".m3u")) {
                    LibraryUtils.createNewPlaylist(files[0], isStarredDirectoryHolder(support.getDropLocation()));
                } else {
                    LibraryUtils.createNewPlaylist(files, isStarredDirectoryHolder(support.getDropLocation()));
                }
            }
        }
    } catch (Throwable e) {
        LOG.error("Error in LibraryFilesTransferHandler processing", e);
    }
    return false;
}
Also used : PlaylistItem(com.frostwire.alexandria.PlaylistItem) Transferable(java.awt.datatransfer.Transferable) File(java.io.File) 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