Search in sources :

Example 1 with PlaylistEntry

use of se.light.assembly64.model.PlaylistEntry 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 PlaylistEntry

use of se.light.assembly64.model.PlaylistEntry 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 PlaylistEntry

use of se.light.assembly64.model.PlaylistEntry 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 PlaylistEntry

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

the class SidifyMainContoller method playSong.

private SidTune playSong(PlaylistEntry song) throws InterruptedException, SongNotAvailableException, SpecifyFileIdException {
    // Ugly, but needed for the nextsub to know
    SidTune sidTune = null;
    setIconPlaying(true);
    Platform.runLater(() -> nowPlaying.setText(song.getNameMasked()));
    try {
        int retries = 0;
        while (true) {
            try {
                File sid = Support.getSid(song);
                if (!sid.exists() && isOffline()) {
                    throw new SongNotAvailableException();
                } else if (!sid.exists()) {
                    downloadService.downloadTo(sid, song.getId(), song.getCategory(), song.getFileId());
                    Platform.runLater(() -> {
                        // update downloaded status
                        songlist.getColumns().get(0).setVisible(false);
                        songlist.getColumns().get(0).setVisible(true);
                    });
                }
                sidTune = sidPlayService.getSidTune(sid);
                sidPlayService.playSid(sidTune, getSongIndex(sidTune) + 1);
                break;
            } catch (Exception e) {
                if (e instanceof SpecifyFileIdException) {
                    throw e;
                } else if (retries > 3 || e instanceof SongNotAvailableException) {
                    throw e;
                }
                retries++;
            }
        }
        // load image async
        ReturningTask<Void> task = () -> {
            if (!Support.isOffline()) {
                Set<TargetAndPath> images = MetadataService.getInstance().resolve(song).getImages();
                if (images.size() > 0) {
                    imageView.setImage(new Image(imageCache.getImage(images.iterator().next())));
                }
            } else {
                imageView.setImage(MetadataService.getInstance().getNoPreview());
            }
            return null;
        };
        ExecutorUtil.executeAsyncWithRetry(task, 1);
    } catch (Exception e) {
        if (e instanceof SpecifyFileIdException) {
            throw new SpecifyFileIdException();
        }
        setIconPlaying(false);
        progressUpdater.stop();
        GenericMessageDialogController.withErrorProps("Sidify", "Sid seems to be broken!", true).showAndWait();
        throw new InterruptedException();
    }
    return sidTune;
}
Also used : SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException) Set(java.util.Set) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) Image(javafx.scene.image.Image) SidTune(libsidplay.sidtune.SidTune) File(java.io.File) SearchException(se.light.assembly64.model.SearchException) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException)

Example 5 with PlaylistEntry

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

the class SidifyMainContoller method doSearch.

private void doSearch(String searchCriteria2) {
    stopPlay();
    songs.clear();
    try {
        String criteria = searchCriteria2;
        Integer period = searchPeriod.getSelectionModel().getSelectedItem().getDays();
        if (period > -1 && criteria.length() == 0) {
            criteria = "***";
        } else if (StringUtils.isEmpty(criteria) && period.equals(-1)) {
            GenericMessageDialogController.withErrorProps("Oops", "Please enter valid searchcriterias").showAndWait();
            return;
        }
        List<PlaylistEntry> items = SearchService.getInstance().search2(criteria, criteria, "***", "***", "***", "***", "***", "n", "n", "N", "N", "N", "N", "N", "N", "Y", "N", "N", "Y", period).stream().map(item -> {
            PlaylistEntry entry = new PlaylistEntry(item.getId(), item.getCategory(), null, item.getName());
            entry.setGroup(item.getGroup());
            if (item.getYear() != null) {
                entry.setYear(String.valueOf(item.getYear()));
            }
            return entry;
        }).collect(Collectors.toList());
        Comparator<PlaylistEntry> nameComp = (item1, item2) -> item1.getName().compareToIgnoreCase(item2.getName());
        Collections.sort(items, nameComp);
        for (PlaylistEntry entry : items) {
            songs.add(entry);
        }
        songlist.setItems(songs);
        playListService.addTmpPlaylist(items);
    } catch (SearchException se) {
        GenericMessageDialogController.withErrorProps("Sidify", "Please refine search!").showAndWait();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventHandler(javafx.event.EventHandler) Support.isOffline(se.light.assembly64.Support.isOffline) ListCell(javafx.scene.control.ListCell) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) PathService(se.light.assembly64.service.PathService) StringUtils(org.apache.commons.lang3.StringUtils) ContentEntryInfo(se.light.assembly64.model.ContentEntryInfo) CachedImageService(se.light.assembly64.service.CachedImageService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextMenu(javafx.scene.control.ContextMenu) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) ContentEntry(se.light.assembly64.model.ContentEntry) Pane(javafx.scene.layout.Pane) TextField(javafx.scene.control.TextField) PlaylistEntryMenuItem(se.light.assembly64.model.PlaylistEntryMenuItem) MenuItem(javafx.scene.control.MenuItem) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) SidTune(libsidplay.sidtune.SidTune) SidFileInfo(se.light.assembly64.model.SidFileInfo) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) SearchException(se.light.assembly64.model.SearchException) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) DataFormat(javafx.scene.input.DataFormat) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) AnchorPane(javafx.scene.layout.AnchorPane) ObservableList(javafx.collections.ObservableList) ClipboardContent(javafx.scene.input.ClipboardContent) ReturningTask(se.light.assembly64.model.ReturningTask) MouseButton(javafx.scene.input.MouseButton) ListView(javafx.scene.control.ListView) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) MouseEvent(javafx.scene.input.MouseEvent) SearchService(se.light.assembly64.service.SearchService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FXCollections(javafx.collections.FXCollections) PoisonPill(se.light.assembly64.model.PoisonPill) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) TransferMode(javafx.scene.input.TransferMode) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Support.isSearchActive(se.light.assembly64.Support.isSearchActive) Dragboard(javafx.scene.input.Dragboard) Slider(javafx.scene.control.Slider) GuiUtils(se.light.assembly64.util.GuiUtils) Support(se.light.assembly64.Support) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MetadataService(se.light.assembly64.fx.mdresolve.MetadataService) DownloadArtifactsService(se.light.assembly64.service.DownloadArtifactsService) PlaylistService(se.light.assembly64.service.PlaylistService) BaseGuiController(se.light.assembly64.model.BaseGuiController) Analytics(se.light.assembly64.Analytics) KeyCode(javafx.scene.input.KeyCode) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) TargetAndPath(se.light.assembly64.model.TargetAndPath) TableRow(javafx.scene.control.TableRow) ContentEntryInfoMenuItem(se.light.assembly64.model.ContentEntryInfoMenuItem) Support.resolveFilename(se.light.assembly64.Support.resolveFilename) Support.setSearchActive(se.light.assembly64.Support.setSearchActive) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) Support.isPlaylistMine(se.light.assembly64.Support.isPlaylistMine) File(java.io.File) ChoiceBox(javafx.scene.control.ChoiceBox) Menu(javafx.scene.control.Menu) SIDPlayerService(se.light.assembly64.service.SIDPlayerService) TimeUnit(java.util.concurrent.TimeUnit) ActionEvent(javafx.event.ActionEvent) SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) LocalDBService(se.light.assembly64.service.LocalDBService) ObservableValue(javafx.beans.value.ObservableValue) SEARCH_PERIOD(se.light.assembly64.Support.SEARCH_PERIOD) Comparator(java.util.Comparator) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) Image(javafx.scene.image.Image) SearchException(se.light.assembly64.model.SearchException) PlaylistEntry(se.light.assembly64.model.PlaylistEntry)

Aggregations

PlaylistEntry (se.light.assembly64.model.PlaylistEntry)19 PlaylistInfo (se.light.assembly64.model.PlaylistInfo)11 File (java.io.File)9 ContentEntry (se.light.assembly64.model.ContentEntry)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)6 Set (java.util.Set)5 Executors (java.util.concurrent.Executors)5 SidTune (libsidplay.sidtune.SidTune)5 SearchException (se.light.assembly64.model.SearchException)5 SongNotAvailableException (se.light.assembly64.model.SongNotAvailableException)5 SpecifyFileIdException (se.light.assembly64.model.SpecifyFileIdException)5 Comparator (java.util.Comparator)4 ChangeListener (javafx.beans.value.ChangeListener)4 ObservableValue (javafx.beans.value.ObservableValue)4 ActionEvent (javafx.event.ActionEvent)4 ContextMenu (javafx.scene.control.ContextMenu)4 Menu (javafx.scene.control.Menu)4 MenuItem (javafx.scene.control.MenuItem)4