use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PlayOnLinux.
the class ListWidgetElement method create.
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());
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PlayOnLinux.
the class LibraryFeaturePanelSkin method createCombinedListWidget.
private CombinedListWidget<ShortcutDTO> createCombinedListWidget() {
final FilteredList<ShortcutDTO> filteredShortcuts = ConcatenatedList.create(new MappedList<>(getControl().getCategories().sorted(Comparator.comparing(ShortcutCategoryDTO::getName)), ShortcutCategoryDTO::getShortcuts)).filtered(getControl().getFilter()::filter);
filteredShortcuts.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().getFilter().searchTermProperty(), getControl().getFilter().selectedShortcutCategoryProperty()));
final SortedList<ShortcutDTO> sortedShortcuts = filteredShortcuts.sorted(Comparator.comparing(shortcut -> shortcut.getInfo().getName()));
final ObservableList<ListWidgetElement<ShortcutDTO>> listWidgetEntries = new MappedList<>(sortedShortcuts, ListWidgetElement::create);
final CombinedListWidget<ShortcutDTO> combinedListWidget = new CombinedListWidget<>(listWidgetEntries, this.selectedListWidget);
// bind direction: controller property -> skin property
getControl().selectedShortcutProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
combinedListWidget.select(newValue);
} else {
combinedListWidget.deselect();
}
});
// bind direction: skin property -> controller properties
combinedListWidget.selectedElementProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
final ShortcutDTO selectedItem = newValue.getItem();
final MouseEvent event = newValue.getEvent();
getControl().setSelectedShortcut(selectedItem);
getControl().setOpenedDetailsPanel(new ShortcutInformation(selectedItem));
if (event.getClickCount() == 2) {
getControl().runShortcut(selectedItem);
}
} else {
getControl().setSelectedShortcut(null);
getControl().setOpenedDetailsPanel(new None());
}
});
return combinedListWidget;
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class LibraryManager method fetchShortcuts.
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()).withIcon(// choose one category icon
entry.getValue().get(0).getCategoryIcon()).build();
shortcuts.add(tr(category));
}
return shortcuts;
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class LibraryManager method fetchShortcutDTO.
private ShortcutDTO fetchShortcutDTO(File shortcutDirectory, File file) {
final String baseName = FilenameUtils.getBaseName(file.getName());
final File infoFile = new File(shortcutDirectory, baseName + ".info");
final File iconFile = new File(shortcutDirectory, baseName + ".icon");
final File categoryIconFile = new File(shortcutDirectory, baseName + "Category.icon");
final File miniatureFile = new File(shortcutDirectory, baseName + ".miniature");
final ShortcutInfoDTO.Builder shortcutInfoDTOBuilder;
if (infoFile.exists()) {
final ShortcutInfoDTO shortcutInfoDTOFromJsonFile = unSerializeShortcutInfo(infoFile);
shortcutInfoDTOBuilder = new ShortcutInfoDTO.Builder(shortcutInfoDTOFromJsonFile);
} else {
shortcutInfoDTOBuilder = new ShortcutInfoDTO.Builder();
shortcutInfoDTOBuilder.withName(baseName);
}
if (StringUtils.isBlank(shortcutInfoDTOBuilder.getName())) {
shortcutInfoDTOBuilder.withName(baseName);
}
if (StringUtils.isBlank(shortcutInfoDTOBuilder.getCategory())) {
shortcutInfoDTOBuilder.withCategory("Other");
}
final ShortcutInfoDTO shortcutInfoDTO = shortcutInfoDTOBuilder.build();
try {
final URI icon = iconFile.exists() ? iconFile.toURI() : getClass().getResource("phoenicis.png").toURI();
final URI categoryIcon = categoryIconFile.exists() ? categoryIconFile.toURI() : getClass().getResource("phoenicis.png").toURI();
final URI miniature = miniatureFile.exists() ? miniatureFile.toURI() : getClass().getResource("defaultMiniature.png").toURI();
return new ShortcutDTO.Builder().withId(baseName).withInfo(shortcutInfoDTO).withScript(IOUtils.toString(new FileInputStream(file), "UTF-8")).withIcon(icon).withCategoryIcon(categoryIcon).withMiniature(miniature).build();
} catch (URISyntaxException | IOException e) {
throw new IllegalStateException(e);
}
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class GenericContainersManager method fetchContainers.
/**
* fetches all containers in a given directory
*
* @param directory
* @return found containers
*/
private List<ContainerDTO> fetchContainers(File directory) {
final List<ContainerDTO> containers = new ArrayList<>();
final File[] containerDirectories = directory.listFiles();
if (containerDirectories != null) {
for (File containerDirectory : containerDirectories) {
if (!containerDirectory.isHidden()) {
final ConfigFile configFile = compatibleConfigFileFormatFactory.open(new File(containerDirectory, "phoenicis.cfg"));
final String containerPath = containerDirectory.getAbsolutePath();
final String containerName = containerPath.substring(containerPath.lastIndexOf('/') + 1);
// find shortcuts which use this container
List<ShortcutDTO> shortcutDTOS = libraryManager.fetchShortcuts().stream().flatMap(shortcutCategory -> shortcutCategory.getShortcuts().stream()).filter(shortcut -> {
boolean toAdd = false;
try {
final Map<String, Object> shortcutProperties = objectMapper.readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() {
});
toAdd = shortcutProperties.get("winePrefix").equals(containerName);
} catch (IOException e) {
LOGGER.warn("Could not parse shortcut script JSON", e);
}
return toAdd;
}).collect(Collectors.toList());
if (directory.getName().equals("wineprefix")) {
containers.add(new WinePrefixContainerDTO.Builder().withName(containerDirectory.getName()).withPath(containerPath).withInstalledShortcuts(shortcutDTOS).withArchitecture(configFile.readValue("wineArchitecture", "")).withDistribution(configFile.readValue("wineDistribution", "")).withVersion(configFile.readValue("wineVersion", "")).build());
}
}
}
containers.sort(ContainerDTO.nameComparator());
}
return containers;
}
Aggregations