diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index a3cc737a..d5117de1 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -1,5 +1,6 @@ package com.muwire.core +import com.muwire.core.download.UIDownloadLinkEvent import com.muwire.core.files.InfoHashEvent import com.muwire.core.files.NegativeFiles import com.muwire.core.files.PersisterDoneEvent @@ -469,6 +470,7 @@ public class Core { eventBus.register(DownloadHopelessEvent.class, downloadManager) eventBus.register(UIDownloadCollectionEvent.class, downloadManager) eventBus.register(UIDownloadAttachmentEvent.class, downloadManager) + eventBus.register(UIDownloadLinkEvent.class, downloadManager) log.info("initializing upload manager") uploadManager = new UploadManager(eventBus, fileManager, meshManager, diff --git a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy index 1ef023a7..94ebd09b 100644 --- a/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy +++ b/core/src/main/groovy/com/muwire/core/download/DownloadManager.groovy @@ -95,6 +95,17 @@ public class DownloadManager { } + void onUIDownloadLinkEvent(UIDownloadLinkEvent e) { + Set singleSource = new HashSet<>() + singleSource.add(e.host.destination) + + File target = muSettings.downloadLocation + target = new File(target, e.fileName) + + // TODO: sequential + doDownload(e.infoHash, target, null, e.length, e.pieceSizePow2, false, singleSource, null) + } + public void onUIDownloadFeedItemEvent(UIDownloadFeedItemEvent e) { Set singleSource = new HashSet<>() singleSource.add(e.item.getPublisher().getDestination()) diff --git a/core/src/main/groovy/com/muwire/core/download/UIDownloadLinkEvent.groovy b/core/src/main/groovy/com/muwire/core/download/UIDownloadLinkEvent.groovy new file mode 100644 index 00000000..dc02cfd8 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/download/UIDownloadLinkEvent.groovy @@ -0,0 +1,13 @@ +package com.muwire.core.download + +import com.muwire.core.Event +import com.muwire.core.InfoHash +import com.muwire.core.Persona + +class UIDownloadLinkEvent extends Event { + Persona host + InfoHash infoHash + String fileName + long length + int pieceSizePow2 +} diff --git a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy index e13c07a1..62f0a25b 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/MainFrameController.groovy @@ -1,10 +1,14 @@ package com.muwire.gui +import com.muwire.core.download.UIDownloadLinkEvent import com.muwire.core.files.DirectoryUnsharedEvent import com.muwire.core.files.directories.WatchedDirectory import com.muwire.core.messenger.UIFolderCreateEvent import com.muwire.core.messenger.UIFolderDeleteEvent import com.muwire.gui.MainFrameModel.UploaderWrapper +import com.muwire.gui.mulinks.FileMuLink +import com.muwire.gui.mulinks.InvalidMuLinkException +import com.muwire.gui.mulinks.MuLink import com.muwire.gui.profile.PersonaOrProfile import com.muwire.gui.profile.TrustPOP import com.muwire.gui.profile.ViewProfileHelper @@ -83,13 +87,28 @@ class MainFrameController { void search(ActionEvent evt) { if (evt?.getActionCommand() == null) return - def cardsPanel = builder.getVariable("cards-panel") - cardsPanel.getLayout().show(cardsPanel, "search window") - def searchField = builder.getVariable("search-field") - def search = searchField.getSelectedItem() - searchField.model.addElement(search) - performSearch(search, null) + def searchField = builder.getVariable("search-field") + String search = searchField.getSelectedItem() + + if(search.startsWith("muwire://")) { + try { + MuLink link = MuLink.parse(search) + if(!link.verify()) + throw new InvalidMuLinkException("failed verification") + if (link.getLinkType() == MuLink.LinkType.FILE) + downloadLink((FileMuLink)link) + } catch (InvalidMuLinkException e) { + JOptionPane.showMessageDialog(null, trans("INVALID_MULINK"), + trans("INVALID_MULINK"), JOptionPane.WARNING_MESSAGE) + } + } else { + searchField.model.addElement(search) + performSearch(search, null) + + def cardsPanel = builder.getVariable("cards-panel") + cardsPanel.getLayout().show(cardsPanel, "search window") + } } void repeatSearch(String terms, Integer tab, Boolean regex) { @@ -209,6 +228,16 @@ class MainFrameController { originator : core.me, sig : sig.data, queryTime : timestamp, sig2 : sig2)) } + private void downloadLink(FileMuLink link) { + view.showDownloadsWindow.call() + def event = new UIDownloadLinkEvent(host: link.host, + infoHash: link.infoHash, + fileName: link.name, + length: link.fileSize, + pieceSizePow2: link.pieceSizePow2) + core.eventBus.publish event + } + private List selectedDownloads() { int [] rows = view.selectedDownloaderRows() if (rows.length == 0) diff --git a/gui/griffon-app/i18n/messages.properties b/gui/griffon-app/i18n/messages.properties index 94f12fd6..13fe103e 100644 --- a/gui/griffon-app/i18n/messages.properties +++ b/gui/griffon-app/i18n/messages.properties @@ -263,6 +263,7 @@ PLEASE_SELECT_ONE_FILE_FOLDER=Please select only one file to open it's containin COPY_PASTE_SERVER_ADDRESS=Copy/paste the address of the server here INVALID_SERVER_ADDRESS=Invalid server address COPY_PASTE_FEED_ID=Copy/paste the full MuWire ID to subscribe to +INVALID_MULINK=Invalid MuWire link ## Search tab