public void createShortcut(ShortcutDTO shortcutDTO) { final ShortcutInfoDTO shortcutInfo = shortcutDTO.getInfo(); final String baseName = shortcutDTO.getId(); final File shortcutDirectoryFile = new File(this.shortcutDirectory); this.objectMapper.writeValue(infoFile, shortcutInfo); FileUtils.writeStringToFile(scriptFile, shortcutDTO.getScript(), ENCODING); if (shortcutDTO.getIcon() != null) { File file = createFileWithFallback(shortcutDTO.getIcon(), "phoenicis.png"); if (file.exists()) { FileUtils.copyFile(file, iconFile); if (shortcutDTO.getMiniature() != null) { File file = createFileWithFallback(shortcutDTO.getMiniature(), "defaultMiniature.png"); if (file.exists()) { FileUtils.copyFile(file, miniatureFile);
public ShortcutDTO build() { return new ShortcutDTO(this); } }
public static ListWidgetElement<ShortcutDTO> create(ShortcutDTO shortcut) { return new ListWidgetElement<>(shortcut, Optional.ofNullable(shortcut.getMiniature()), DEFAULT_MINIATURE, shortcut.getInfo().getName(), Collections.emptyList(), Collections.emptyList()); }
/** * Updates the shortcut of this {@link LibraryDetailsPanelSkin} instance */ private void updateShortcut() { final ShortcutDTO shortcut = getControl().getShortcut(); if (shortcut != null) { title.setValue(shortcut.getInfo().getName()); description.setValue(shortcut.getInfo().getDescription()); try { final Map<String, Object> shortcutProperties = getControl().getObjectMapper() .readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() { // nothing }); this.shortcutProperties.clear(); this.shortcutProperties.putAll(shortcutProperties); } catch (IOException e) { LOGGER.error("An error occurred during a shortcut update", e); } } }
public void updateShortcut(ShortcutDTO shortcutDTO) { final String baseName = shortcutDTO.getId(); final File shortcutDirectory = new File(this.shortcutDirectory); final URI shortcutIcon = shortcutDTO.getIcon(); final URI shortcutMiniature = shortcutDTO.getMiniature();
/** * Filters a given shortcut * * @param shortcut The to be filtered shortcut * @return True if the shortcut should be shown, false otherwise */ public boolean filter(ShortcutDTO shortcut) { final boolean searchTermConstraint = Optional.ofNullable(searchTerm.getValueSafe()) .map(searchTerm -> shortcut.getInfo().getName().toLowerCase().contains(searchTerm.toLowerCase())) .orElse(true); final boolean selectedShortcutCategoryConstraint = Optional.ofNullable(selectedShortcutCategory.getValue()) .map(selectedShortcutCategory -> selectedShortcutCategory.getShortcuts().contains(shortcut)) .orElse(true); return searchTermConstraint && selectedShortcutCategoryConstraint; }
public List<ShortcutCategoryDTO> fetchShortcuts() { final File shortcutDirectoryFile = new File(this.shortcutDirectory); if (!shortcutDirectoryFile.exists()) { shortcutDirectoryFile.mkdirs(); return Collections.emptyList(); } final File[] directoryContent = shortcutDirectoryFile.listFiles(); if (directoryContent == null) { return Collections.emptyList(); } HashMap<String, List<ShortcutDTO>> categoryMap = new HashMap<>(); for (File file : directoryContent) { if ("shortcut".equals(FilenameUtils.getExtension(file.getName()))) { ShortcutDTO shortcut = fetchShortcutDTO(shortcutDirectoryFile, file); String categoryId = shortcut.getInfo().getCategory(); if (!categoryMap.containsKey(categoryId)) { categoryMap.put(categoryId, new ArrayList<>()); } categoryMap.get(categoryId).add(shortcut); } } List<ShortcutCategoryDTO> shortcuts = new ArrayList<>(); for (Map.Entry<String, List<ShortcutDTO>> entry : categoryMap.entrySet()) { entry.getValue().sort(ShortcutDTO.nameComparator()); ShortcutCategoryDTO category = new ShortcutCategoryDTO.Builder().withId(entry.getKey()) .withName(entry.getKey()).withShortcuts(entry.getValue()).build(); shortcuts.add(tr(category)); } return shortcuts; }
try { final Map<String, Object> shortcutProperties = objectMapper .readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() { }); toAdd = shortcutProperties.get("winePrefix").equals(containerName);
/** * Updates the shortcut of this {@link LibraryDetailsPanelSkin} instance */ private void updateShortcut() { final ShortcutDTO shortcut = getControl().getShortcut(); if (shortcut != null) { title.setValue(shortcut.getInfo().getName()); description.setValue(shortcut.getInfo().getDescription()); try { final Map<String, Object> shortcutProperties = getControl().getObjectMapper() .readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() { // nothing }); this.shortcutProperties.clear(); this.shortcutProperties.putAll(shortcutProperties); } catch (IOException e) { LOGGER.error("An error occurred during a shortcut update", e); } } }
public static ListWidgetElement<ContainerDTO> create(ContainerDTO container) { final List<BufferedImage> miniatures = new ArrayList<>(); // do not use too many segments (cannot recognize the miniature if the segment is too small) final int maxSegments = 4; int currentSegment = 0; for (ShortcutDTO shortcutDTO : container.getInstalledShortcuts()) { if (currentSegment >= maxSegments) { break; } try { miniatures.add(ImageIO.read(shortcutDTO.getMiniature().toURL())); currentSegment++; } catch (IOException e) { LOGGER.warn( String.format("Could not read miniature for shortcut \"%s\"", shortcutDTO.getInfo().getName()), e); } } final BufferedImage segmentedMiniature = createSegmentedMiniature(miniatures); final Optional<URI> shortcutMiniature = saveBufferedImage(segmentedMiniature, container.getName()); return new ListWidgetElement<>(container, shortcutMiniature, CONTAINER_MINIATURE, container.getName(), Collections.emptyList(), Collections.emptyList()); }
public ShortcutDTO fetchShortcutsFromName(String name) { for (ShortcutCategoryDTO shortcutCategoryDTO : fetchShortcuts()) { for (ShortcutDTO shortcutDTO : shortcutCategoryDTO.getShortcuts()) { if (name.equals(shortcutDTO.getInfo().getName())) { return shortcutDTO; } } } return null; }
public void deleteShortcut(ShortcutDTO shortcutDTO) { final String baseName = shortcutDTO.getId(); final File shortcutDirectory = new File(this.shortcutDirectory); final File infoFile = new File(shortcutDirectory, baseName + ".info"); final File scriptFile = new File(shortcutDirectory, baseName + ".shortcut"); final File iconFile = new File(shortcutDirectory, baseName + ".icon"); final File miniatureFile = new File(shortcutDirectory, baseName + ".miniature"); if (infoFile.exists()) { infoFile.delete(); } if (scriptFile.exists()) { scriptFile.delete(); } if (iconFile.exists()) { iconFile.delete(); } if (miniatureFile.exists()) { miniatureFile.delete(); } if (this.desktopShortcutDirectory != null) { final File desktopShortcutDirectoryFile = new File(this.desktopShortcutDirectory); final File desktopShortcutFile = new File(desktopShortcutDirectoryFile, baseName + ".desktop"); if (desktopShortcutFile.exists()) { desktopShortcutFile.delete(); } } libraryManager.refresh(); }
.map(shortcutDTO -> shortcutDTO.getInfo().getName()).collect(Collectors.joining("; "))); installedShortcuts.setWrapText(true); informationContentPane.add(installedShortcuts, 1, 2);
private void uninstallShortcut(ShortcutDTO shortcut) { final String shortcutName = shortcut.getInfo().getName(); final ConfirmDialog confirmMessage = ConfirmDialog.builder() .withTitle(tr("Uninstall {0}", shortcutName)) .withMessage(tr("Are you sure you want to uninstall {0}?", shortcutName)) .withOwner(content.getScene().getWindow()) .withResizable(true) .withYesCallback(() -> shortcutManager.uninstallFromShortcut(shortcut, e -> { final ErrorDialog errorDialog = ErrorDialog.builder() .withMessage(tr("Error while uninstalling {0}", shortcutName)) .withException(e) .withOwner(content.getScene().getWindow()) .build(); errorDialog.showAndWait(); })) .build(); confirmMessage.showAndCallback(); }
.sorted(Comparator.comparing(shortcut -> shortcut.getInfo().getName()));