Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/HTMLViewer Mac/WebDownloadDelegateMBS Test
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/HTMLViewer Mac/WebDownloadDelegateMBS Test
This example is the version from Sun, 17th Mar 2012.
Project "WebDownloadDelegateMBS Test.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control HTMLViewer1 Inherits HTMLViewer
ControlInstance HTMLViewer1 Inherits HTMLViewer
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open() dd = new MyWebDownloadDelegateMBS pd = new MyWebPolicyDelegateMBS dd.l = List // install download handler so we get informed about all downloads HTMLViewer1.InstallWebDownloadDelegateMBS dd // install policy handler so we can have stuff downloaded HTMLViewer1.InstallWebPolicyDelegateMBS pd // go to a website HTMLViewer1.LoadURL "http://www.macsw.de/plugin/" End EventHandler
Property dd As MyWebDownloadDelegateMBS
Property pd As MyWebPolicyDelegateMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyWebPolicyDelegateMBS Inherits WebPolicyDelegateMBS
EventHandler Function decidePolicyForMIMEType(type as string,request as NSURLRequestMBS, frame as WebFrameMBS, decisionListener as WebPolicyDecisionListenerMBS) As boolean Select case type // show html file case "text/html" decisionListener.use Return true // download files and PDFs case "application/octet-stream" decisionListener.download Return true case "application/pdf" decisionListener.download Return true else break end Select End EventHandler
End Class
Class MyWebDownloadDelegateMBS Inherits WebDownloadDelegateMBS
EventHandler Sub decideDestinationWithSuggestedFilename(download as NSURLDownloadMBS, filename as string) l.AddRow "Download to desktop folder." dim file as FolderItem = SpecialFolder.Desktop.Child(filename) download.setDestination file, false End EventHandler
EventHandler Sub didBegin(download as NSURLDownloadMBS) l.AddRow "Download did begin." End EventHandler
EventHandler Sub didCreateDestination(download as NSURLDownloadMBS, path as string, file as folderitem) l.AddRow "Created Destination File: "+file.Name self.file = file End EventHandler
EventHandler Sub didFinish(download as NSURLDownloadMBS) l.AddRow "Download did finish." if file<>nil then // show file in finder dim w as new NSWorkspaceMBS call w.selectFile(File) end if End EventHandler
EventHandler Sub didReceiveDataOfLength(download as NSURLDownloadMBS, length as UInt64) downloaded = downloaded + length l.AddRow "Downloading "+Format(downloaded/expectedContentLength,"0%") End EventHandler
EventHandler Sub didReceiveResponse(download as NSURLDownloadMBS, response as NSURLResponseMBS) expectedContentLength = response.expectedContentLength l.AddRow "Did receive response: "+str(expectedContentLength)+" bytes" End EventHandler
Property downloaded As UInt64
Property expectedContentLength As uint64
Property file As FolderItem
Property l As listbox
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacControls Plugin.





Links
MBS FileMaker Plugins