download links pasted in search box

dbus-notify
Zlatin Balevsky 2022-08-04 16:38:55 +01:00
parent 660da951d9
commit eab7f96c66
No known key found for this signature in database
GPG Key ID: A72832072D525E41
5 changed files with 62 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package com.muwire.core package com.muwire.core
import com.muwire.core.download.UIDownloadLinkEvent
import com.muwire.core.files.InfoHashEvent import com.muwire.core.files.InfoHashEvent
import com.muwire.core.files.NegativeFiles import com.muwire.core.files.NegativeFiles
import com.muwire.core.files.PersisterDoneEvent import com.muwire.core.files.PersisterDoneEvent
@ -469,6 +470,7 @@ public class Core {
eventBus.register(DownloadHopelessEvent.class, downloadManager) eventBus.register(DownloadHopelessEvent.class, downloadManager)
eventBus.register(UIDownloadCollectionEvent.class, downloadManager) eventBus.register(UIDownloadCollectionEvent.class, downloadManager)
eventBus.register(UIDownloadAttachmentEvent.class, downloadManager) eventBus.register(UIDownloadAttachmentEvent.class, downloadManager)
eventBus.register(UIDownloadLinkEvent.class, downloadManager)
log.info("initializing upload manager") log.info("initializing upload manager")
uploadManager = new UploadManager(eventBus, fileManager, meshManager, uploadManager = new UploadManager(eventBus, fileManager, meshManager,

View File

@ -95,6 +95,17 @@ public class DownloadManager {
} }
void onUIDownloadLinkEvent(UIDownloadLinkEvent e) {
Set<Destination> 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) { public void onUIDownloadFeedItemEvent(UIDownloadFeedItemEvent e) {
Set<Destination> singleSource = new HashSet<>() Set<Destination> singleSource = new HashSet<>()
singleSource.add(e.item.getPublisher().getDestination()) singleSource.add(e.item.getPublisher().getDestination())

View File

@ -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
}

View File

@ -1,10 +1,14 @@
package com.muwire.gui package com.muwire.gui
import com.muwire.core.download.UIDownloadLinkEvent
import com.muwire.core.files.DirectoryUnsharedEvent import com.muwire.core.files.DirectoryUnsharedEvent
import com.muwire.core.files.directories.WatchedDirectory import com.muwire.core.files.directories.WatchedDirectory
import com.muwire.core.messenger.UIFolderCreateEvent import com.muwire.core.messenger.UIFolderCreateEvent
import com.muwire.core.messenger.UIFolderDeleteEvent import com.muwire.core.messenger.UIFolderDeleteEvent
import com.muwire.gui.MainFrameModel.UploaderWrapper 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.PersonaOrProfile
import com.muwire.gui.profile.TrustPOP import com.muwire.gui.profile.TrustPOP
import com.muwire.gui.profile.ViewProfileHelper import com.muwire.gui.profile.ViewProfileHelper
@ -83,13 +87,28 @@ class MainFrameController {
void search(ActionEvent evt) { void search(ActionEvent evt) {
if (evt?.getActionCommand() == null) if (evt?.getActionCommand() == null)
return return
def cardsPanel = builder.getVariable("cards-panel")
cardsPanel.getLayout().show(cardsPanel, "search window")
def searchField = builder.getVariable("search-field") def searchField = builder.getVariable("search-field")
def search = searchField.getSelectedItem() String search = searchField.getSelectedItem()
searchField.model.addElement(search)
performSearch(search, null) 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) { void repeatSearch(String terms, Integer tab, Boolean regex) {
@ -209,6 +228,16 @@ class MainFrameController {
originator : core.me, sig : sig.data, queryTime : timestamp, sig2 : sig2)) 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<Downloader> selectedDownloads() { private List<Downloader> selectedDownloads() {
int [] rows = view.selectedDownloaderRows() int [] rows = view.selectedDownloaderRows()
if (rows.length == 0) if (rows.length == 0)

View File

@ -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 COPY_PASTE_SERVER_ADDRESS=Copy/paste the address of the server here
INVALID_SERVER_ADDRESS=Invalid server address INVALID_SERVER_ADDRESS=Invalid server address
COPY_PASTE_FEED_ID=Copy/paste the full MuWire ID to subscribe to COPY_PASTE_FEED_ID=Copy/paste the full MuWire ID to subscribe to
INVALID_MULINK=Invalid MuWire link
## Search tab ## Search tab