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);
}
}
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()));
}
});
}
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);
}
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;
}
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();
}
}
Aggregations