Search in sources :

Example 1 with PlaylistInfo

use of se.light.assembly64.model.PlaylistInfo in project assembly64fx by freabemania.

the class SearchViewFilesController method handleMouseClicked.

private void handleMouseClicked(MouseEvent event) {
    if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
        final ContextMenu contextMenu = new ContextMenu();
        List<ContentEntry> selectedItems = table.getSelectionModel().getSelectedItems();
        // do not show downloadbuttons if we're coming from treeview
        if (fromSearch) {
            MenuItem view = new MenuItem("Download to installbase");
            view.setOnAction((ActionEvent event2) -> {
                if (userService.getPrimaryInstallation().exists()) {
                    downloadFilesAsync(selectedItems, UserService.getInstance().resolveDownloadFolderAsString());
                } else {
                    GenericMessageDialogController.withErrorProps("Ooops..", "No valid downloadlocation is present").showAndWait();
                }
            });
            if (userService.isLocationSelectedAndExisting()) {
                contextMenu.getItems().add(view);
            }
            MenuItem downloadTo = new MenuItem("Download to...");
            downloadTo.setOnAction((ActionEvent event2) -> {
                File tmp = new DirectoryChooser().showDialog(getStage());
                Analytics.sendEvent("search", "installfilecustompath");
                if (tmp != null) {
                    downloadFilesAsync(selectedItems, Support.getAndfixPathAsString(tmp));
                }
            });
            contextMenu.getItems().add(downloadTo);
        }
        MenuItem openBrowser = new MenuItem("Open browser");
        openBrowser.setOnAction((ActionEvent event2) -> {
            openFile(true);
        });
        contextMenu.getItems().add(openBrowser);
        MenuItem loadStar = new MenuItem("LOAD \"*\",8,1");
        loadStar.setOnAction((ActionEvent event2) -> {
            openFile(false, true);
        });
        contextMenu.getItems().add(loadStar);
        if (selectedItems.size() == 1) {
            MenuItem browseAction = new MenuItem("Browse image");
            browseAction.setOnAction((ActionEvent event2) -> {
                openFile(true);
            });
            if (selectedItems.size() == 1) {
                ContentEntry selectedItem = selectedItems.get(0);
                if (selectedItem.getName().toLowerCase().endsWith(".sid")) {
                    Menu addToPlaylist = new Menu("Add to playlist");
                    for (PlaylistInfo plist : playlistService.getPlaylistInfo()) {
                        PlaylistMenuItem mItem = new PlaylistMenuItem(plist);
                        mItem.setOnAction((ActionEvent event2) -> {
                            PlaylistMenuItem item = (PlaylistMenuItem) event2.getSource();
                            PlaylistEntry song = new PlaylistEntry(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), selectedItem.getName());
                            selectedItem.setFullPlaylistInfo(song);
                            playlistService.addSong(item.getPlaylist(), selectedItem);
                        });
                        addToPlaylist.getItems().add(mItem);
                    }
                    contextMenu.getItems().add(addToPlaylist);
                }
            }
            contextMenu.getItems().add(browseAction);
        }
        table.setContextMenu(contextMenu);
        Analytics.sendEvent("search", "installfile");
    } else if (event.getClickCount() == 2) {
        openFile(false);
    }
}
Also used : PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ContentEntry(se.light.assembly64.model.ContentEntry) ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser)

Example 2 with PlaylistInfo

use of se.light.assembly64.model.PlaylistInfo in project assembly64fx by freabemania.

the class SidifyChooseMultipleSongsController method init.

public void init(List<ContentEntry> contentEntries) {
    Analytics.sendEvent("sidify", "choose_multi");
    name.setCellValueFactory(new PropertyValueFactory<ContentEntry, String>("name"));
    playListService = PlaylistService.getInstance();
    sidPlayService = SIDPlayerService.getInstance();
    downloadService = DownloadArtifactsService.getInstance();
    pathService = PathService.getInstance();
    songs.clear();
    contentEntries.stream().forEach(songs::add);
    songlist.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    songlist.setItems(songs);
    songlist.setOnMousePressed(event -> {
        List<ContentEntry> selectedItems = songlist.getSelectionModel().getSelectedItems();
        if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
            final ContextMenu contextMenu = new ContextMenu();
            Menu addToPlaylist = new Menu("Add to playlist");
            for (PlaylistInfo plist : playListService.getPlaylistInfo()) {
                PlaylistMenuItem mItem = new PlaylistMenuItem(plist);
                mItem.setOnAction((ActionEvent event2) -> {
                    playListService.addSongs(plist, selectedItems.stream().map(item -> item.getFullPlaylistInfo()).collect(Collectors.toList()), selectedItems.stream().map(item -> Collections.singletonList(item)).collect(toList()));
                    songlist.getSelectionModel().clearSelection();
                });
                addToPlaylist.getItems().add(mItem);
            }
            MenuItem mItem = new MenuItem("Add to new playlist");
            mItem.setOnAction((ActionEvent event2) -> {
                SidifyCreatePlaylistController controller = GuiUtils.showDialog("sidifyCreateNewPlaylist.fxml", Boolean.TRUE, "Create new playlist", getStage(), new Object[] { null, true });
                PlaylistInfo newPlaylist = controller.getNewlyCreatedPlayList();
                if (newPlaylist != null) {
                    playListService.addSongs(newPlaylist, selectedItems.stream().map(item -> item.getFullPlaylistInfo()).collect(Collectors.toList()), selectedItems.stream().map(item -> Collections.singletonList(item)).collect(toList()));
                    songlist.getSelectionModel().clearSelection();
                }
            });
            addToPlaylist.getItems().add(mItem);
            contextMenu.getItems().add(addToPlaylist);
            songlist.setContextMenu(contextMenu);
        } else if (event.getClickCount() == 2) {
            playSong(new PlaylistEntry(selectedItems.get(0).getFullPlaylistInfo().getId(), selectedItems.get(0).getFullPlaylistInfo().getCategory(), selectedItems.get(0).getId(), selectedItems.get(0).getName()));
        }
    });
}
Also used : ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ContentEntry(se.light.assembly64.model.ContentEntry) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) PlaylistEntry(se.light.assembly64.model.PlaylistEntry)

Example 3 with PlaylistInfo

use of se.light.assembly64.model.PlaylistInfo in project assembly64fx by freabemania.

the class SidifyExportPlaylistController method export.

public void export() throws Exception {
    int idx = locations.getSelectionModel().getSelectedIndex();
    List<String> exportLocations = new ArrayList<>();
    if (idx != 0) {
        exportLocations.addAll(Collections.singletonList(locations.getSelectionModel().getSelectedItem()));
    } else {
        exportLocations.addAll(locations.getItems().stream().filter(item -> !item.equals(ALL_LOCATIONS)).collect(Collectors.toList()));
    }
    int items = playlists.stream().map(item -> playlistService.getSongsForPlaylist(item)).map(item -> item.size()).mapToInt(i -> i.intValue()).sum() * exportLocations.size();
    CancelableTask cancelTask = CancelableTask.of();
    ProgressDBController controller = GuiUtils.showDialogOwnerNoWait("progressBarDbUpdate.fxml", "Progress", true, NullWindowOwner.of(), new Object[] { items, cancelTask, exportLocations.get(0) + MUSIC_SIDIFY, "Playlist exported to <location>/Music/Sidify" });
    NonReturningTask t = () -> {
        try {
            for (PlaylistInfo playlist : playlists) {
                List<PlaylistEntry> songsForPlaylist = playlistService.getSongsForPlaylist(playlist);
                int padding = Integer.valueOf(String.valueOf(songsForPlaylist.size()).length());
                for (String dir : exportLocations) {
                    File exportDir = new File(dir + MUSIC_SIDIFY + playlist.getName());
                    FileUtils.deleteQuietly(exportDir);
                    FileUtils.forceMkdir(exportDir);
                    int ctr = 1;
                    for (PlaylistEntry entry : playlistService.getSongsForPlaylist(playlist)) {
                        String pos = String.format("%0" + padding + "d", ctr);
                        try {
                            controller.increaseProgress();
                            controller.setProgressLabel("Exporting " + entry.getNameMasked());
                            FileUtils.copyFile(downloadService.getSid(entry), new File(exportDir + "/" + pos + "_" + entry.getNameMasked() + ".sid"));
                            ctr++;
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        if (cancelTask.isCancelled()) {
                            FileUtils.deleteQuietly(exportDir);
                            break;
                        }
                    }
                }
                if (cancelTask.isCancelled()) {
                    break;
                }
            }
        } finally {
            controller.progressDone();
        }
    };
    ExecutorUtil.executeAsync(t);
}
Also used : NonReturningTask(se.light.assembly64.model.NonReturningTask) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) FileUtils(org.apache.commons.io.FileUtils) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) Collectors(java.util.stream.Collectors) File(java.io.File) ChoiceBox(javafx.scene.control.ChoiceBox) UserService(se.light.assembly64.service.UserService) ArrayList(java.util.ArrayList) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GuiUtils(se.light.assembly64.util.GuiUtils) CancelableTask(se.light.assembly64.model.CancelableTask) WorkLocation(se.light.assembly64.model.WorkLocation) DownloadArtifactsService(se.light.assembly64.service.DownloadArtifactsService) PlaylistService(se.light.assembly64.service.PlaylistService) Collections(java.util.Collections) BaseGuiController(se.light.assembly64.model.BaseGuiController) ArrayList(java.util.ArrayList) NonReturningTask(se.light.assembly64.model.NonReturningTask) ArrayList(java.util.ArrayList) List(java.util.List) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) File(java.io.File) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 4 with PlaylistInfo

use of se.light.assembly64.model.PlaylistInfo in project assembly64fx by freabemania.

the class SidifyMainContoller method populateLeftList.

private void populateLeftList() {
    wordsList.clear();
    leftlist.getItems().clear();
    String playlistUsage = " (" + playListService.getPlaylistInfo().size() + " of " + MAX_PLAYLISTS + ")";
    playlistsHeaderLabel.setText("Playlists " + playlistUsage);
    final ContextMenu contextMenu = new ContextMenu();
    // Menu addToPlaylist = new Menu("Add to playlist");
    MenuItem tmp = new MenuItem("Export all playlists");
    tmp.setOnAction((ActionEvent event2) -> {
        GuiUtils.showDialog("sidifyExportPlaylist.fxml", Boolean.TRUE, "Playlistinfo", getStage(), new Object[] { null });
    });
    // addToPlaylist.getItems().add(tmp);
    contextMenu.getItems().add(tmp);
    playlistsHeaderLabel.setContextMenu(contextMenu);
    for (PlaylistInfo list : playListService.getPlaylistInfo()) {
        PlayerItem playerItem = null;
        boolean availableOffline = list.isAvailableOffline();
        boolean isPublic = !Support.isPlaylistMine(list) && Support.isPublicPlaylist(list);
        String label = list.getName() + " ";
        if (availableOffline || isPublic) {
            label += "(";
            label += availableOffline ? "*" : "";
            label += isPublic ? "P" : "";
            label += ")";
        }
        if (Support.isPlaylistMine(list)) {
            playerItem = new PlayerItem(label, MENU_TYPE.PLAYLIST);
        } else {
            playerItem = new PlayerItem(label, MENU_TYPE.PUBLICLIST);
        }
        playerItem.setPlaylist(list);
        wordsList.add(playerItem);
        // leftlist.getItems()
        if (activePlaylist != null && activePlaylist.getId().equals(list.getId())) {
            leftlist.getSelectionModel().select(playerItem);
        }
    }
    wordsList.add(new PlayerItem("", MENU_TYPE.NONCLICKABLE));
    wordsList.add(new PlayerItem("", MENU_TYPE.NONCLICKABLE));
    leftlist.setItems(wordsList);
    leftlist.refresh();
}
Also used : ActionEvent(javafx.event.ActionEvent) ContextMenu(javafx.scene.control.ContextMenu) PlaylistEntryMenuItem(se.light.assembly64.model.PlaylistEntryMenuItem) MenuItem(javafx.scene.control.MenuItem) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) ContentEntryInfoMenuItem(se.light.assembly64.model.ContentEntryInfoMenuItem) PlaylistInfo(se.light.assembly64.model.PlaylistInfo)

Example 5 with PlaylistInfo

use of se.light.assembly64.model.PlaylistInfo in project assembly64fx by freabemania.

the class SidifyViewPublicPlaylistsController method populateList.

private void populateList() {
    items.clear();
    Set<String> myLists = playListService.myPlaylistIds();
    for (PlaylistInfo item : playListService.getPublicPlaylists()) {
        if (!myLists.contains(item.getId())) {
            if (filter.getText().length() == 0 || (filter.getText().length() > 0 && item.getName().toLowerCase().startsWith(filter.getText().toLowerCase()))) {
                items.add(item);
            }
        }
    }
    publicLists.setItems(items);
    if (myLists.size() > 0) {
        publicLists.getSelectionModel().select(0);
        publicLists.getFocusModel().focus(0);
    }
}
Also used : PlaylistInfo(se.light.assembly64.model.PlaylistInfo)

Aggregations

PlaylistInfo (se.light.assembly64.model.PlaylistInfo)17 PlaylistEntry (se.light.assembly64.model.PlaylistEntry)14 ContentEntry (se.light.assembly64.model.ContentEntry)7 File (java.io.File)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)4 ActionEvent (javafx.event.ActionEvent)4 ContextMenu (javafx.scene.control.ContextMenu)4 MenuItem (javafx.scene.control.MenuItem)4 PlaylistMenuItem (se.light.assembly64.model.PlaylistMenuItem)4 Set (java.util.Set)3 Executors (java.util.concurrent.Executors)3 Menu (javafx.scene.control.Menu)3 GenericType (javax.ws.rs.core.GenericType)3 SidTune (libsidplay.sidtune.SidTune)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Analytics (se.light.assembly64.Analytics)3 Support (se.light.assembly64.Support)3