Coherent UI allows for clients to download files. Downloads can be initiated during navigation - by navigating to a URL whose MIME type is not one that Coherent UI can render, or directly initiated by the client with the Coherent::UI::View::DownloadUrl
method.
Coherent UI does not save files on disk, it'll pass the downloaded data blob to the client.
Coherent::UI::EventListener::OnDownloadStarted
returns false, so all downloads are disabled.When a download is initiated, the client is notified via the Coherent::UI::EventListener::OnDownloadStarted
event. The Coherent::UI::Download
class encapsulates all information regarding the download. At this point the client must decide if the download task should continue or be stopped by returning either true or false. If the download is to continue (return true) than the client must also save the pointer to the Coherent::UI::Download
object and call Destroy on it when he is done with it - either when the download is complete, cancelled or failed. If the user returns false she implicitly cancels the task and the Coherent::UI::Download
object should not be used as it is automatically destroyed by the view context.
The Coherent::UI::EventListener::OnDownloadComplete
event is called as soon as the download task has completed. You can safely call Destroy on the download task from here. If some error occurs during a download the Coherent::UI::EventListener::OnDownloadFailed
event will be called with further details.
The progress of a download task can be monitored through the Coherent::UI::Download
class. The Coherent::UI::Download::GetDownloadedBytesSoFar
can be used to monitor progress. Keep in mind that downloads are performed on worker threads so this counter is not always up-to-date, it shows that at least so much bytes have already been downloaded. Tasks can be cancelled via the Coherent::UI::Download::Cancel
method. Even after a download has completed, has been cancelled or has failed, the Coherent::UI::Download
object remains valid. The user must call the Coherent::UI::Download::Destroy
method as soon as she doesn't need it anymore in order to free the resources bound to the download task.
Coherent::UI::EventListener::OnDownloadComplete
method, after that they are destroyed.