From 5e16802b16946816634f0e4038733263091d380d Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 12 Oct 2012 11:53:31 +0300 Subject: [PATCH] Enabled AsyncDownloading media for content. Fixed working on mac. --- src/board/UBBoardController.cpp | 42 ++++++++++++++++----------------- src/core/UBDownloadManager.cpp | 13 +++++----- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index c2721df4..b188a5d7 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -996,32 +996,30 @@ void UBBoardController::downloadURL(const QUrl& url, QString contentSourceUrl, c || contentType.startsWith("application/widget") || contentType.startsWith("application/vnd.apple-widget"); - - // TODO: claudio Fix it because it doesn't work with audio/video/flash items dropped from the teacher bar -// if (shouldLoadFileData) -// { + if (shouldLoadFileData) + { QFile file(fileName); file.open(QIODevice::ReadOnly); downloadFinished(true, formedUrl, QUrl(), contentType, file.readAll(), pPos, pSize, isBackground, internalData); file.close(); -// } -// else -// { -// // media items should be copyed in separate thread - -// sDownloadFileDesc desc; -// desc.modal = false; -// desc.srcUrl = sUrl; -// desc.originalSrcUrl = contentSourceUrl; -// desc.currentSize = 0; -// desc.name = QFileInfo(url.toString()).fileName(); -// desc.totalSize = 0; // The total size will be retrieved during the download -// desc.pos = pPos; -// desc.size = pSize; -// desc.isBackground = isBackground; - -// UBDownloadManager::downloadManager()->addFileToDownload(desc); -// } + } + else + { + // media items should be copyed in separate thread + + sDownloadFileDesc desc; + desc.modal = false; + desc.srcUrl = sUrl; + desc.originalSrcUrl = contentSourceUrl; + desc.currentSize = 0; + desc.name = QFileInfo(url.toString()).fileName(); + desc.totalSize = 0; // The total size will be retrieved during the download + desc.pos = pPos; + desc.size = pSize; + desc.isBackground = isBackground; + + UBDownloadManager::downloadManager()->addFileToDownload(desc); + } } else { diff --git a/src/core/UBDownloadManager.cpp b/src/core/UBDownloadManager.cpp index e120038a..74207826 100644 --- a/src/core/UBDownloadManager.cpp +++ b/src/core/UBDownloadManager.cpp @@ -33,19 +33,18 @@ UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, Q UBAsyncLocalFileDownloader *UBAsyncLocalFileDownloader::download() { - if (!QFile::exists(QUrl(mDesc.srcUrl).toLocalFile())) { - qDebug() << "file" << mDesc.srcUrl << "does not present in fs"; - return this; - } - start(); - return this; } void UBAsyncLocalFileDownloader::run() { + if(mDesc.srcUrl.startsWith("file://")) + mDesc.srcUrl = QUrl(mDesc.srcUrl).toLocalFile(); + else + mDesc.srcUrl = QUrl::fromLocalFile(mDesc.srcUrl).toLocalFile(); + QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mDesc.srcUrl); int position=mimeType.indexOf(";"); @@ -67,7 +66,7 @@ void UBAsyncLocalFileDownloader::run() QString uuid = QUuid::createUuid(); UBPersistenceManager::persistenceManager()->addFileToDocument(UBApplication::boardController->selectedDocument(), - QUrl(mDesc.srcUrl).toLocalFile(), + mDesc.srcUrl, destDirectory, uuid, mTo,