From 00c1f9590a094f48d18a31baa53e24c47703dee0 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sun, 1 Nov 2020 15:58:21 +0000 Subject: [PATCH] event for downloading collections --- .../UIDownloadCollectionEvent.groovy | 12 +++++++ .../muwire/gui/CollectionTabController.groovy | 36 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 core/src/main/groovy/com/muwire/core/collections/UIDownloadCollectionEvent.groovy diff --git a/core/src/main/groovy/com/muwire/core/collections/UIDownloadCollectionEvent.groovy b/core/src/main/groovy/com/muwire/core/collections/UIDownloadCollectionEvent.groovy new file mode 100644 index 00000000..b8c39548 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/collections/UIDownloadCollectionEvent.groovy @@ -0,0 +1,12 @@ +package com.muwire.core.collections + +import com.muwire.core.Event +import com.muwire.core.Persona + +class UIDownloadCollectionEvent extends Event { + + FileCollection collection + Set items + boolean full + Persona host +} diff --git a/gui/griffon-app/controllers/com/muwire/gui/CollectionTabController.groovy b/gui/griffon-app/controllers/com/muwire/gui/CollectionTabController.groovy index 20e87dcc..2275f7c0 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/CollectionTabController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/CollectionTabController.groovy @@ -6,7 +6,9 @@ import griffon.inject.MVCMember import griffon.metadata.ArtifactProviderFor import javax.annotation.Nonnull +import com.muwire.core.collections.FileCollection import com.muwire.core.collections.FileCollectionItem +import com.muwire.core.collections.UIDownloadCollectionEvent @ArtifactProviderFor(GriffonController) class CollectionTabController { @@ -15,14 +17,46 @@ class CollectionTabController { @MVCMember @Nonnull CollectionTabView view + private FileCollection selectedCollection() { + int row = view.selectedCollection() + if (row < 0) + return null + + return model.collections.get(row) + } + @ControllerAction void downloadCollection() { - + FileCollection collection = selectedCollection() + if (collection == null) + return + + UIDownloadCollectionEvent e = new UIDownloadCollectionEvent( + collection : collection, + items : collection.getFiles(), + full : true, + host : model.host + ) + model.eventBus.publish(e) } @ControllerAction void download() { + FileCollection collection = selectedCollection() + if (collection == null) + return + List items = view.selectedItems() + if (items.isEmpty()) + return + + UIDownloadCollectionEvent e = new UIDownloadCollectionEvent( + collection : collection, + items : new HashSet<>(items), + full : false, + host : model.host + ) + model.eventBus.publish(e) } @ControllerAction