Search in sources :

Example 6 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class GenericContainersManager method deleteContainer.

/**
 * {@inheritDoc}
 */
@Override
public void deleteContainer(ContainerDTO container, Consumer<ContainerDTO> onSuccess, Consumer<Exception> onError) {
    try {
        final File containerFile = new File(container.getPath());
        FileUtils.deleteDirectory(containerFile);
    } catch (IOException e) {
        LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
        onError.accept(e);
    }
    // TODO: better way to get engine ID
    final String engineId = container.getEngine().toLowerCase();
    final List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
    // remove the shortcuts leading to the container
    categories.stream().flatMap(shortcutCategory -> shortcutCategory.getShortcuts().stream()).forEach(shortcut -> {
        final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
        interactiveScriptSession.eval("include(\"engines." + engineId + ".shortcuts.reader\");", result -> {
            final org.graalvm.polyglot.Value shortcutReaderClass = (org.graalvm.polyglot.Value) result;
            final ShortcutReader shortcutReader = shortcutReaderClass.newInstance().as(ShortcutReader.class);
            shortcutReader.of(shortcut);
            final String containerName = shortcutReader.getContainer();
            if (containerName.equals(container.getName())) {
                this.shortcutManager.deleteShortcut(shortcut);
            }
        }, onError);
    });
    onSuccess.accept(container);
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) ShortcutReader(org.phoenicis.library.ShortcutReader) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) Map(java.util.Map) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) Consumer(java.util.function.Consumer) List(java.util.List) ShortcutManager(org.phoenicis.library.ShortcutManager) ConfigFile(org.phoenicis.tools.config.ConfigFile) Safe(org.phoenicis.configuration.security.Safe) CompatibleConfigFileFormatFactory(org.phoenicis.tools.config.CompatibleConfigFileFormatFactory) CollectionUtils(org.springframework.util.CollectionUtils) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) IOException(java.io.IOException) ShortcutReader(org.phoenicis.library.ShortcutReader) Value(org.springframework.beans.factory.annotation.Value) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile)

Example 7 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO 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;
}
Also used : CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) StringBindings(org.phoenicis.javafx.utils.StringBindings) ObjectExpression(javafx.beans.binding.ObjectExpression) MappedList(org.phoenicis.javafx.collections.MappedList) MouseEvent(javafx.scene.input.MouseEvent) ShortcutEditing(org.phoenicis.javafx.components.library.panelstates.ShortcutEditing) Bindings(javafx.beans.binding.Bindings) SidebarBase(org.phoenicis.javafx.components.common.control.SidebarBase) org.phoenicis.javafx.components.library.control(org.phoenicis.javafx.components.library.control) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) ShortcutInformation(org.phoenicis.javafx.components.library.panelstates.ShortcutInformation) ShortcutCreation(org.phoenicis.javafx.components.library.panelstates.ShortcutCreation) TabPane(javafx.scene.control.TabPane) None(org.phoenicis.javafx.components.common.panelstates.None) FeaturePanelSkin(org.phoenicis.javafx.components.common.skin.FeaturePanelSkin) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) SwitchBinding(org.phoenicis.javafx.utils.SwitchBinding) SortedList(javafx.collections.transformation.SortedList) ListWidgetType(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetType) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) FilteredList(javafx.collections.transformation.FilteredList) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Observable(javafx.beans.Observable) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) OpenDetailsPanel(org.phoenicis.javafx.components.common.panelstates.OpenDetailsPanel) DetailsPanel(org.phoenicis.javafx.components.common.control.DetailsPanel) Optional(java.util.Optional) ObjectBindings(org.phoenicis.javafx.utils.ObjectBindings) ObservableList(javafx.collections.ObservableList) ConcatenatedList(org.phoenicis.javafx.collections.ConcatenatedList) Comparator(java.util.Comparator) CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) MouseEvent(javafx.scene.input.MouseEvent) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) ShortcutInformation(org.phoenicis.javafx.components.library.panelstates.ShortcutInformation) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) MappedList(org.phoenicis.javafx.collections.MappedList) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) None(org.phoenicis.javafx.components.common.panelstates.None)

Example 8 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class LibraryController method setDefaultLibraryCategoryIcons.

/**
 * sets the default category icons for the library sidebar buttons
 *
 * We cannot use the default category buttons for this purpose for several reasons:
 * - It cannot be guaranteed that the repository which contained the category of a certain app does still exist
 * after the app has been installed (e.g. the repository might have been deleted).
 * - It should not be required to fetch the repository to use the library.
 *
 * Therefore, use the following approach:
 * - When installing an app, store the icon for its category together with the shortcut (i.e. in the library).
 * - Use this icon as fallback if the theme does not specify an icon for this category.
 *
 * @param categories list of shortcut categories
 */
private void setDefaultLibraryCategoryIcons(List<ShortcutCategoryDTO> categories) {
    Platform.runLater(() -> {
        try {
            StringBuilder cssBuilder = new StringBuilder();
            for (ShortcutCategoryDTO category : categories) {
                cssBuilder.append("#" + LibrarySidebarToggleGroupSkin.getToggleButtonId(category.getId()) + "{\n");
                final String categoryIconPath = Optional.ofNullable(category.getIcon()).map(categoryIcon -> categoryIcon.toString()).orElse("/org/phoenicis/javafx/views/common/phoenicis.png");
                cssBuilder.append(String.format("-fx-background-image: url('%s');\n", categoryIconPath));
                cssBuilder.append("}\n");
            }
            String css = cssBuilder.toString();
            Path temp = Files.createTempFile("defaultLibraryCategoryIcons", ".css").toAbsolutePath();
            File tempFile = temp.toFile();
            tempFile.deleteOnExit();
            Files.write(temp, css.getBytes());
            String defaultLibraryCategoryIconsCss = temp.toUri().toString();
            this.themeManager.setDefaultLibraryCategoryIconsCss(defaultLibraryCategoryIconsCss);
        } catch (IOException e) {
            LOGGER.warn("Could not set default category icons.", e);
        }
    });
}
Also used : LibraryFeaturePanel(org.phoenicis.javafx.components.library.control.LibraryFeaturePanel) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) LibrarySidebarToggleGroupSkin(org.phoenicis.javafx.components.library.skin.LibrarySidebarToggleGroupSkin) Logger(org.slf4j.Logger) Files(java.nio.file.Files) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) File(java.io.File) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) Platform(javafx.application.Platform) List(java.util.List) ThemeManager(org.phoenicis.javafx.themes.ThemeManager) Optional(java.util.Optional) URI(java.net.URI) LibraryManager(org.phoenicis.library.LibraryManager) Path(java.nio.file.Path) Path(java.nio.file.Path) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) IOException(java.io.IOException) File(java.io.File)

Example 9 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class LibrarySidebarSkin method createSidebarToggleGroup.

/**
 * Creates the {@link LibrarySidebarToggleGroup} which contains all known shortcut categories
 */
private LibrarySidebarToggleGroup createSidebarToggleGroup() {
    final FilteredList<ShortcutCategoryDTO> filteredShortcutCategories = getControl().getItems().filtered(getControl().getFilter()::filter);
    filteredShortcutCategories.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().searchTermProperty()));
    final LibrarySidebarToggleGroup categoryView = new LibrarySidebarToggleGroup(tr("Categories"), filteredShortcutCategories);
    getControl().selectedShortcutCategoryProperty().bind(categoryView.selectedElementProperty());
    return categoryView;
}
Also used : LibrarySidebarToggleGroup(org.phoenicis.javafx.components.library.control.LibrarySidebarToggleGroup) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO)

Example 10 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PlayOnLinux.

the class LibraryFeaturePanelSkin method createSidebar.

/**
 * {@inheritDoc}
 */
@Override
public ObjectExpression<SidebarBase<?, ?, ?>> createSidebar() {
    final SortedList<ShortcutCategoryDTO> sortedCategories = getControl().getCategories().sorted(Comparator.comparing(ShortcutCategoryDTO::getName));
    final LibrarySidebar sidebar = new LibrarySidebar(getControl().getFilter(), sortedCategories, this.selectedListWidget);
    sidebar.applicationNameProperty().bind(getControl().applicationNameProperty());
    sidebar.javaFxSettingsManagerProperty().bind(getControl().javaFxSettingsManagerProperty());
    sidebar.setOnCreateShortcut(() -> {
        // deselect the currently selected shortcut
        getControl().setSelectedShortcut(null);
        // open the shortcut creation details panel
        getControl().setOpenedDetailsPanel(new ShortcutCreation());
    });
    sidebar.setOnOpenConsole(getControl()::openConsole);
    // set the default selection
    sidebar.setSelectedListWidget(Optional.ofNullable(getControl().getJavaFxSettingsManager()).map(JavaFxSettingsManager::getLibraryListType).orElse(ListWidgetType.ICONS_LIST));
    // save changes to the list widget selection to the hard drive
    sidebar.selectedListWidgetProperty().addListener((observable, oldValue, newValue) -> {
        final JavaFxSettingsManager javaFxSettingsManager = getControl().getJavaFxSettingsManager();
        if (newValue != null) {
            javaFxSettingsManager.setLibraryListType(newValue);
            javaFxSettingsManager.save();
        }
    });
    return new SimpleObjectProperty<>(sidebar);
}
Also used : SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ShortcutCreation(org.phoenicis.javafx.components.library.panelstates.ShortcutCreation) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager)

Aggregations

ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)11 File (java.io.File)8 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)7 IOException (java.io.IOException)5 List (java.util.List)5 LibraryManager (org.phoenicis.library.LibraryManager)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Map (java.util.Map)4 Consumer (java.util.function.Consumer)4 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)4 ShortcutManager (org.phoenicis.library.ShortcutManager)4 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)3 Safe (org.phoenicis.configuration.security.Safe)3