Search in sources :

Example 1 with ContentEntry

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

the class SearchController method downloadEntryAndSubItems.

private boolean downloadEntryAndSubItems(SearchResultItem selectedItem, String downloadPath) {
    List<ContentEntry> searchItems = searchService.getSearchItems(selectedItem.getId(), selectedItem.getCategory()).getContentEntry();
    boolean success = true;
    for (ContentEntry entry : searchItems) {
        try {
            DownloadArtifactsService.getInstance().downloadItem(selectedItem.getId(), selectedItem.getCategory(), entry.getId(), selectedItem.getName(), entry.getName(), selectedItem.getCategoryShortName(), FILE_ACTION.DOWNLOAD, downloadPath);
        } catch (Exception e) {
            success = false;
        }
    }
    return success;
}
Also used : ContentEntry(se.light.assembly64.model.ContentEntry) SearchException(se.light.assembly64.model.SearchException)

Example 2 with ContentEntry

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

the class SearchViewFilesController method openFile.

private void openFile(boolean launchExplorerEvenIfOneFile, boolean loadStar) {
    ContentEntry selectedItem = table.getSelectionModel().getSelectedItem();
    try {
        File file = null;
        if (fromSearch) {
            file = downloadService.downloadItem(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), searchedItem.getName(), selectedItem.getName(), searchedItem.getCategoryShortName(), FILE_ACTION.TMPDOWNLOAD);
        } else {
            // we're using the id as pathfield
            file = new File(selectedItem.getId());
        }
        String path = file.getAbsolutePath().toLowerCase();
        if (path.endsWith(".d64") || path.endsWith(".d71") || path.endsWith(".d81")) {
            GuiUtils.showDialogWithOwner("viewimage.fxml", "Browsing diskimage for " + selectedItem.getName(), getStage(), new Object[] { file, launchExplorerEvenIfOneFile, loadStar });
        } else if (path.endsWith(".sid")) {
            GuiUtils.showDialog("sidifyPlaySid.fxml", true, "Sidplay", getStage(), file);
        } else {
            if (StringUtils.isNotEmpty(localDb.getLocalDBSetting("vicepath"))) {
                Analytics.sendEvent("search", "viceopen");
                if (fromSearch) {
                    downloadService.downloadItem(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), searchedItem.getName(), selectedItem.getName(), searchedItem.getCategoryShortName(), FILE_ACTION.EXECUTE);
                } else {
                    viceService.execVice(file);
                }
            } else {
                Analytics.sendEvent("search", "novice");
                GenericMessageDialogController.withErrorProps("Specify vicepath", "In order to run files you need to specify Vicepath in settings").showAndWait();
            }
        }
    } catch (Exception e) {
        GenericMessageDialogController.withErrorProps("Specify vicepath", "Unable to view files").showAndWait();
    }
}
Also used : ContentEntry(se.light.assembly64.model.ContentEntry) File(java.io.File)

Example 3 with ContentEntry

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

the class SearchViewFilesController method downloadFilesAsync.

private void downloadFilesAsync(List<ContentEntry> selectedItems, String customPath) {
    CancelableTask cancelTask = CancelableTask.of();
    ProgressDBController controller = GuiUtils.showDialogOwnerNoWait("progressBarDbUpdate.fxml", "Progress", true, getStage(), new Object[] { selectedItems.size(), cancelTask, customPath + searchedItem.getCategoryShortName() + "/" + searchedItem.getName(), "Files were installed to " + customPath + searchedItem.getName() });
    ReturningTask<Void> task = () -> {
        int failureCtr = 0;
        for (ContentEntry selectedItem : selectedItems) {
            if (cancelTask.isCancelled()) {
                break;
            }
            try {
                downloadService.downloadItem(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), searchedItem.getName(), selectedItem.getName(), searchedItem.getCategoryShortName(), FILE_ACTION.DOWNLOAD, customPath);
            } catch (Exception e) {
                failureCtr++;
            }
            controller.setProgressLabel("Installing " + selectedItem.getName());
            controller.increaseProgress();
        }
        if (failureCtr == 0) {
            controller.progressDone();
        } else {
            controller.progressDone(failureCtr + " of " + selectedItems.size() + " could not be installed to " + customPath);
        }
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task, 3);
}
Also used : ContentEntry(se.light.assembly64.model.ContentEntry) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 4 with ContentEntry

use of se.light.assembly64.model.ContentEntry 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 5 with ContentEntry

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

the class SearchViewFilesController method init.

public void init(SearchResultItem searchedItem, ContentEntryInfo contentEntry, boolean fromSearch) {
    localDb = LocalDBService.getInstance();
    downloadService = DownloadArtifactsService.getInstance();
    playlistService = PlaylistService.getInstance();
    viceService = ViceService.getInstance();
    userService = UserService.getInstance();
    this.fromSearch = fromSearch;
    ReturningTask<Void> task = () -> {
        MetadataService metaDataSercice = MetadataService.getInstance();
        metadata = metaDataSercice.resolve(searchedItem);
        if (metadata.getUrl() == null) {
            toSourceButton.setVisible(false);
        }
        Platform.runLater(() -> {
            if (isNotEmpty(metadata.getEvent()) && isNotEmpty(metadata.getEventType())) {
                eventName.setText(capitalize(metadata.getEvent()));
                eventType.setText(capitalize(metadata.getEventType()));
                showEventName();
            }
            if (isNotEmpty(metadata.getReleaseDate())) {
                date.setText(metadata.getReleaseDate());
                showDate();
            }
            if (isNotEmpty(metadata.getName())) {
                releaseName.setText(capitalize(metadata.getName()));
                showReleaseName();
            }
            if (isNotEmpty(metadata.getGroup())) {
                group.setText(capitalize(metadata.getGroup()));
                showGroup();
            }
            if (isNotEmpty(metadata.getRating())) {
                rating.setText(metadata.getRating());
                showRating();
            }
            if (isNotEmpty(metadata.getPlace())) {
                place.setText("#" + metadata.getPlace());
                showPlace();
            }
            if (metadata.getImages().size() == 1) {
                try {
                    ReturningTask<Void> task2 = () -> {
                        TargetAndPath name = metadata.getImages().iterator().next();
                        fadeUpImage(new Image(CachedImageService.getInstance().getImage(name)));
                        return null;
                    };
                    ExecutorUtil.executeAsyncWithRetry(task2);
                } catch (Exception e) {
                    imageView.setImage(metaDataSercice.getNoPreview());
                }
            } else if (metadata.getImages().size() > 1) {
                loopImages(metadata.getImages());
            } else {
                fadeUpImage(metaDataSercice.getNoPreview());
            }
        });
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task);
    this.searchedItem = searchedItem;
    name.setCellValueFactory(new PropertyValueFactory<ContentEntry, String>("name"));
    EventHandler<MouseEvent> mouseEventHandle = (MouseEvent event) -> {
        handleMouseClicked(event);
    };
    table.addEventHandler(MouseEvent.MOUSE_PRESSED, mouseEventHandle);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    contentEntry.getContentEntry().sort((i1, i2) -> i1.getName().toLowerCase().compareTo(i2.getName().toLowerCase()));
    data.addAll(contentEntry.getContentEntry());
    table.setItems(data);
    getStage().setOnCloseRequest(event -> {
        closeImageLoop();
    });
    table.setOnKeyTyped(event -> {
        if (event.getCharacter().charAt(0) == Support.ENTER_KEY) {
            openFile(false);
        }
    });
    Executors.newSingleThreadExecutor().execute(() -> {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        }
        Platform.runLater(() -> {
            GuiUtils.selectFirstInList(table);
        });
    });
}
Also used : TargetAndPath(se.light.assembly64.model.TargetAndPath) MouseEvent(javafx.scene.input.MouseEvent) ReturningTask(se.light.assembly64.model.ReturningTask) Image(javafx.scene.image.Image) MetadataService(se.light.assembly64.fx.mdresolve.MetadataService) ContentEntry(se.light.assembly64.model.ContentEntry)

Aggregations

ContentEntry (se.light.assembly64.model.ContentEntry)13 File (java.io.File)7 List (java.util.List)7 PlaylistEntry (se.light.assembly64.model.PlaylistEntry)7 ArrayList (java.util.ArrayList)6 ActionEvent (javafx.event.ActionEvent)5 ContextMenu (javafx.scene.control.ContextMenu)5 MenuItem (javafx.scene.control.MenuItem)5 PlaylistInfo (se.light.assembly64.model.PlaylistInfo)5 Comparator (java.util.Comparator)3 Executors (java.util.concurrent.Executors)3 Collectors (java.util.stream.Collectors)3 ChangeListener (javafx.beans.value.ChangeListener)3 ObservableValue (javafx.beans.value.ObservableValue)3 ObservableList (javafx.collections.ObservableList)3 Menu (javafx.scene.control.Menu)3 PlaylistMenuItem (se.light.assembly64.model.PlaylistMenuItem)3 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Label (javafx.scene.control.Label)2 TextField (javafx.scene.control.TextField)2