From e70bec3a51d0c33d501a57eab1cb5274fc6bac0e Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 10 Mar 2020 12:44:25 +0000 Subject: [PATCH] hook up feed subscription --- .../core/filefeeds/UIFeedConfigurationEvent.groovy | 1 + .../com/muwire/gui/SearchTabController.groovy | 11 +++++++++++ .../models/com/muwire/gui/MainFrameModel.groovy | 13 +++++++++++++ .../views/com/muwire/gui/MainFrameView.groovy | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/src/main/groovy/com/muwire/core/filefeeds/UIFeedConfigurationEvent.groovy b/core/src/main/groovy/com/muwire/core/filefeeds/UIFeedConfigurationEvent.groovy index 9917c30c..3e0e176e 100644 --- a/core/src/main/groovy/com/muwire/core/filefeeds/UIFeedConfigurationEvent.groovy +++ b/core/src/main/groovy/com/muwire/core/filefeeds/UIFeedConfigurationEvent.groovy @@ -8,4 +8,5 @@ import com.muwire.core.Event */ class UIFeedConfigurationEvent extends Event { Feed feed + boolean newFeed } diff --git a/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy b/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy index 34a508f2..cc7f07d0 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy @@ -12,6 +12,8 @@ import javax.swing.JOptionPane import com.muwire.core.Core import com.muwire.core.Persona import com.muwire.core.download.UIDownloadEvent +import com.muwire.core.filefeeds.Feed +import com.muwire.core.filefeeds.UIFeedConfigurationEvent import com.muwire.core.search.UIResultEvent import com.muwire.core.trust.TrustEvent import com.muwire.core.trust.TrustLevel @@ -109,7 +111,16 @@ class SearchTabController { @ControllerAction void subscribe() { + def sender = view.selectedSender() + if (sender == null) + return + + Feed feed = new Feed(sender) + // TODO: defaults + feed.setUpdateInterval(60 * 1000) + core.eventBus.publish(new UIFeedConfigurationEvent(feed : feed, newFeed: true)) + mvcGroup.parentGroup.view.showFeedsWindow.call() } @ControllerAction diff --git a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy index 2ebcc217..2259fc84 100644 --- a/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/MainFrameModel.groovy @@ -30,6 +30,7 @@ import com.muwire.core.download.Downloader import com.muwire.core.filecert.CertificateCreatedEvent import com.muwire.core.filefeeds.FeedFetchEvent import com.muwire.core.filefeeds.FeedLoadedEvent +import com.muwire.core.filefeeds.UIFeedConfigurationEvent import com.muwire.core.files.AllFilesLoadedEvent import com.muwire.core.files.DirectoryUnsharedEvent import com.muwire.core.files.DirectoryWatchedEvent @@ -230,6 +231,7 @@ class MainFrameModel { core.eventBus.register(CertificateCreatedEvent.class, this) core.eventBus.register(FeedLoadedEvent.class, this) core.eventBus.register(FeedFetchEvent.class, this) + core.eventBus.register(UIFeedConfigurationEvent.class, this) core.muOptions.watchedKeywords.each { core.eventBus.publish(new ContentControlEvent(term : it, regex: false, add: true)) @@ -681,4 +683,15 @@ class MainFrameModel { view.refreshFeeds() } } + + void onUIFeedConfigurationEvent(UIFeedConfigurationEvent e) { + if (!e.newFeed) + return + runInsideUIAsync { + if (feeds.contains(e.feed)) + return + feeds << e.feed + view.refreshFeeds() + } + } } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy index 6f237270..3375d8f5 100644 --- a/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/MainFrameView.groovy @@ -444,7 +444,7 @@ class MainFrameView { scrollPane(constraints : BorderLayout.CENTER) { table(id : "feeds-table", autoCreateRowSorter : true, rowHeight : rowHeight) { tableModel(list : model.feeds) { - closureColumn(header : "Publisher", type : String, read : {it.getPublisher()}) + closureColumn(header : "Publisher", type : String, read : {it.getPublisher().getHumanReadableName()}) closureColumn(header : "Files", type : Integer, read : {model.core.feedManager.getFeedItems(it.getPublisher()).size()}) closureColumn(header : "Last Updated", type : Long, read : {it.getLastUpdated()}) closureColumn(header : "Status", type : String, read : {it.getStatus()})