AsyncLocalFileDownloader implemented for add media content to board.

preferencesAboutTextFull
Aleksei Kanash 12 years ago
commit 05d3ad9a55
  1. 2
      src/api/UBLibraryAPI.cpp
  2. 4
      src/api/UBWidgetUniboardAPI.cpp
  3. 97
      src/board/UBBoardController.cpp
  4. 8
      src/board/UBBoardController.h
  5. 1
      src/board/UBBoardPaletteManager.cpp
  6. 2
      src/board/UBFeaturesController.cpp
  7. 138
      src/core/UBDownloadManager.cpp
  8. 33
      src/core/UBDownloadManager.h
  9. 10
      src/domain/UBGraphicsMediaItem.cpp
  10. 5
      src/domain/UBGraphicsScene.cpp
  11. 2
      src/frameworks/UBFileSystemUtils.cpp
  12. 5
      src/frameworks/UBFileSystemUtils.h
  13. 4
      src/gui/UBFeaturesWidget.cpp
  14. 2
      src/web/UBTrapFlashController.cpp
  15. 2
      src/web/browser/WBWebTrapWebView.cpp

@ -40,7 +40,7 @@ UBLibraryAPI::~UBLibraryAPI()
void UBLibraryAPI::addObject(QString pUrl, int width, int height, int x, int y, bool background) void UBLibraryAPI::addObject(QString pUrl, int width, int height, int x, int y, bool background)
{ {
if (UBApplication::boardController) if (UBApplication::boardController)
UBApplication::boardController->downloadURL(QUrl(pUrl), QPointF(x, y), QSize(width, height), background); UBApplication::boardController->downloadURL(QUrl(pUrl), QString(), QPointF(x, y), QSize(width, height), background);
} }

@ -201,7 +201,7 @@ void UBWidgetUniboardAPI::addObject(QString pUrl, int width, int height, int x,
if (UBApplication::boardController->activeScene() != mScene) if (UBApplication::boardController->activeScene() != mScene)
return; return;
UBApplication::boardController->downloadURL(QUrl(pUrl), QPointF(x, y), QSize(width, height), background); UBApplication::boardController->downloadURL(QUrl(pUrl), QString(), QPointF(x, y), QSize(width, height), background);
} }
@ -506,7 +506,7 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QGraphicsSceneDragDropEvent *event)
sDownloadFileDesc desc; sDownloadFileDesc desc;
desc.dest = sDownloadFileDesc::graphicsWidget; desc.dest = sDownloadFileDesc::graphicsWidget;
desc.modal = true; desc.modal = true;
desc.url = url; desc.srcUrl = url;
desc.currentSize = 0; desc.currentSize = 0;
desc.name = QFileInfo(url).fileName(); desc.name = QFileInfo(url).fileName();
desc.totalSize = 0; // The total size will be retrieved during the download desc.totalSize = 0; // The total size will be retrieved during the download

@ -132,7 +132,7 @@ void UBBoardController::init()
, this, SLOT(lastWindowClosed())); , this, SLOT(lastWindowClosed()));
connect(UBDownloadManager::downloadManager(), SIGNAL(downloadModalFinished()), this, SLOT(onDownloadModalFinished())); connect(UBDownloadManager::downloadManager(), SIGNAL(downloadModalFinished()), this, SLOT(onDownloadModalFinished()));
connect(UBDownloadManager::downloadManager(), SIGNAL(addDownloadedFileToBoard(bool,QUrl,QString,QByteArray,QPointF,QSize,bool)), this, SLOT(downloadFinished(bool,QUrl,QString,QByteArray,QPointF,QSize,bool))); connect(UBDownloadManager::downloadManager(), SIGNAL(addDownloadedFileToBoard(bool,QUrl,QUrl,QString,QByteArray,QPointF,QSize,bool)), this, SLOT(downloadFinished(bool,QUrl,QUrl,QString,QByteArray,QPointF,QSize,bool)));
UBDocumentProxy* doc = UBPersistenceManager::persistenceManager()->createDocument(); UBDocumentProxy* doc = UBPersistenceManager::persistenceManager()->createDocument();
@ -563,7 +563,12 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
} }
UBMimeType::Enum itemMimeType; UBMimeType::Enum itemMimeType;
QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(item->sourceUrl().toLocalFile());
QString srcFile = item->sourceUrl().toLocalFile();
if (srcFile.isEmpty())
srcFile = item->sourceUrl().toString();
QString contentTypeHeader = UBFileSystemUtils::mimeTypeFromFileName(srcFile);
if(NULL != qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(commonItem)) if(NULL != qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(commonItem))
itemMimeType = UBMimeType::Group; itemMimeType = UBMimeType::Group;
else else
@ -588,8 +593,9 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
if (mitem) if (mitem)
{ {
sourceUrl = mitem->mediaFileUrl(); sourceUrl = mitem->mediaFileUrl();
downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false);
} }
}break; }return NULL; // async operation
case UBMimeType::VectorImage: case UBMimeType::VectorImage:
{ {
@ -662,7 +668,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
if (retItem) if (retItem)
return retItem; return retItem;
UBItem *createdItem = downloadFinished(true, sourceUrl, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false); UBItem *createdItem = downloadFinished(true, sourceUrl, sourceUrl, contentTypeHeader, pData, itemPos, QSize(itemSize.width(), itemSize.height()), false);
if (createdItem) if (createdItem)
{ {
createdItem->setSourceUrl(item->sourceUrl()); createdItem->setSourceUrl(item->sourceUrl());
@ -676,6 +682,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
retItem = dynamic_cast<UBGraphicsItem *>(createdItem); retItem = dynamic_cast<UBGraphicsItem *>(createdItem);
} }
return retItem; return retItem;
} }
@ -961,7 +968,7 @@ void UBBoardController::groupButtonClicked()
} }
} }
void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const QSize& pSize, bool isBackground, bool internalData) void UBBoardController::downloadURL(const QUrl& url, QString contentSourceUrl, const QPointF& pPos, const QSize& pSize, bool isBackground, bool internalData)
{ {
qDebug() << "something has been dropped on the board! Url is: " << url.toString(); qDebug() << "something has been dropped on the board! Url is: " << url.toString();
QString sUrl = url.toString(); QString sUrl = url.toString();
@ -972,7 +979,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const
if(sUrl.startsWith("uniboardTool://")) if(sUrl.startsWith("uniboardTool://"))
{ {
downloadFinished(true, url, "application/vnd.mnemis-uniboard-tool", QByteArray(), pPos, pSize, isBackground); downloadFinished(true, url, QUrl(), "application/vnd.mnemis-uniboard-tool", QByteArray(), pPos, pSize, isBackground);
} }
else if (sUrl.startsWith("file://") || sUrl.startsWith("/")) else if (sUrl.startsWith("file://") || sUrl.startsWith("/"))
{ {
@ -985,22 +992,37 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const
|| contentType.startsWith("application/widget") || contentType.startsWith("application/widget")
|| contentType.startsWith("application/vnd.apple-widget"); || contentType.startsWith("application/vnd.apple-widget");
QFile file(fileName);
if (shouldLoadFileData) if (shouldLoadFileData)
{
QFile file(fileName);
file.open(QIODevice::ReadOnly); 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
downloadFinished(true, formedUrl, contentType, file.readAll(), pPos, pSize, isBackground, internalData); 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;
if (shouldLoadFileData) UBDownloadManager::downloadManager()->addFileToDownload(desc);
file.close(); }
} }
else else
{ {
// When we fall there, it means that we are dropping something from the web to the board // When we fall there, it means that we are dropping something from the web to the board
sDownloadFileDesc desc; sDownloadFileDesc desc;
desc.modal = true; desc.modal = true;
desc.url = url.toString(); desc.srcUrl = url.toString();
desc.currentSize = 0; desc.currentSize = 0;
desc.name = QFileInfo(url.toString()).fileName(); desc.name = QFileInfo(url.toString()).fileName();
desc.totalSize = 0; // The total size will be retrieved during the download desc.totalSize = 0; // The total size will be retrieved during the download
@ -1023,7 +1045,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const
} }
UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader,
QByteArray pData, QPointF pPos, QSize pSize, QByteArray pData, QPointF pPos, QSize pSize,
bool isBackground, bool internalData) bool isBackground, bool internalData)
{ {
@ -1158,11 +1180,9 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
qDebug() << "accepting mime type" << mimeType << "as video"; qDebug() << "accepting mime type" << mimeType << "as video";
UBGraphicsMediaItem *mediaVideoItem = 0; UBGraphicsMediaItem *mediaVideoItem = 0;
QUuid uuid = QUuid::createUuid();
if (pData.length() > 0) if (pData.length() > 0)
{ {
QUuid uuid = QUuid::createUuid();
QString destFile; QString destFile;
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
sourceUrl.toString(), sourceUrl.toString(),
@ -1179,16 +1199,19 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
QUrl url = QUrl::fromLocalFile(destFile); QUrl url = QUrl::fromLocalFile(destFile);
mediaVideoItem = mActiveScene->addMedia(url, false, pPos); mediaVideoItem = mActiveScene->addMedia(url, false, pPos);
mediaVideoItem->setSourceUrl(sourceUrl);
mediaVideoItem->setUuid(uuid);
} }
else else
{ {
mediaVideoItem = addVideo(sourceUrl, false, pPos); qDebug() << sourceUrl.toString();
mediaVideoItem = addVideo(sourceUrl, false, pPos, true);
} }
if(mediaVideoItem){ if(mediaVideoItem){
if (contentUrl.isEmpty())
mediaVideoItem->setSourceUrl(sourceUrl);
else
mediaVideoItem->setSourceUrl(contentUrl);
mediaVideoItem->setUuid(uuid);
connect(this, SIGNAL(activeSceneChanged()), mediaVideoItem, SLOT(activeSceneChanged())); connect(this, SIGNAL(activeSceneChanged()), mediaVideoItem, SLOT(activeSceneChanged()));
} }
@ -1202,10 +1225,9 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
UBGraphicsMediaItem *audioMediaItem = 0; UBGraphicsMediaItem *audioMediaItem = 0;
QUuid uuid = QUuid::createUuid();
if (pData.length() > 0) if (pData.length() > 0)
{ {
QUuid uuid = QUuid::createUuid();
QString destFile; QString destFile;
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
sourceUrl.toString(), sourceUrl.toString(),
@ -1222,16 +1244,18 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri
QUrl url = QUrl::fromLocalFile(destFile); QUrl url = QUrl::fromLocalFile(destFile);
audioMediaItem = mActiveScene->addMedia(url, false, pPos); audioMediaItem = mActiveScene->addMedia(url, false, pPos);
audioMediaItem->setSourceUrl(sourceUrl);
audioMediaItem->setUuid(uuid);
} }
else else
{ {
audioMediaItem = addAudio(sourceUrl, false, pPos); audioMediaItem = addAudio(sourceUrl, false, pPos, true);
} }
if(audioMediaItem){ if(audioMediaItem){
if (contentUrl.isEmpty())
audioMediaItem->setSourceUrl(sourceUrl);
else
audioMediaItem->setSourceUrl(contentUrl);
audioMediaItem->setUuid(uuid);
connect(this, SIGNAL(activeSceneChanged()), audioMediaItem, SLOT(activeSceneChanged())); connect(this, SIGNAL(activeSceneChanged()), audioMediaItem, SLOT(activeSceneChanged()));
} }
@ -2027,11 +2051,14 @@ void UBBoardController::grabScene(const QRectF& pSceneRect)
} }
} }
UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos) UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos, bool bUseSource)
{ {
QUuid uuid = QUuid::createUuid(); QUuid uuid = QUuid::createUuid();
QUrl concreteUrl = pSourceUrl; QUrl concreteUrl = pSourceUrl;
// media file is not in document folder yet
if (!bUseSource)
{
QString destFile; QString destFile;
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
pSourceUrl.toLocalFile(), pSourceUrl.toLocalFile(),
@ -2044,6 +2071,8 @@ UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool st
return NULL; return NULL;
} }
concreteUrl = QUrl::fromLocalFile(destFile); concreteUrl = QUrl::fromLocalFile(destFile);
}// else we just use source Url.
UBGraphicsMediaItem* vi = mActiveScene->addMedia(concreteUrl, startPlay, pos); UBGraphicsMediaItem* vi = mActiveScene->addMedia(concreteUrl, startPlay, pos);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
@ -2057,11 +2086,14 @@ UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool st
} }
UBGraphicsMediaItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos) UBGraphicsMediaItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos, bool bUseSource)
{ {
QUuid uuid = QUuid::createUuid(); QUuid uuid = QUuid::createUuid();
QUrl concreteUrl = pSourceUrl; QUrl concreteUrl = pSourceUrl;
// media file is not in document folder yet
if (!bUseSource)
{
QString destFile; QString destFile;
bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(),
pSourceUrl.toLocalFile(), pSourceUrl.toLocalFile(),
@ -2074,6 +2106,7 @@ UBGraphicsMediaItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool st
return NULL; return NULL;
} }
concreteUrl = QUrl::fromLocalFile(destFile); concreteUrl = QUrl::fromLocalFile(destFile);
}// else we just use source Url.
UBGraphicsMediaItem* ai = mActiveScene->addMedia(concreteUrl, startPlay, pos); UBGraphicsMediaItem* ai = mActiveScene->addMedia(concreteUrl, startPlay, pos);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
@ -2247,7 +2280,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
if("" != url) if("" != url)
{ {
downloadURL(url, pPos); downloadURL(url, QString(), pPos);
return; return;
} }
} }
@ -2267,7 +2300,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
foreach(const QUrl url, urls){ foreach(const QUrl url, urls){
QPointF pos(pPos + QPointF(index * 15, index * 15)); QPointF pos(pPos + QPointF(index * 15, index * 15));
downloadURL(url, pos, QSize(), false, internalData); downloadURL(url, QString(), pos, QSize(), false, internalData);
index++; index++;
} }
@ -2293,7 +2326,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
// Sometimes, it is possible to have an URL as text. we check here if it is the case // Sometimes, it is possible to have an URL as text. we check here if it is the case
QString qsTmp = pMimeData->text().remove(QRegExp("[\\0]")); QString qsTmp = pMimeData->text().remove(QRegExp("[\\0]"));
if(qsTmp.startsWith("http")){ if(qsTmp.startsWith("http")){
downloadURL(QUrl(qsTmp), pPos); downloadURL(QUrl(qsTmp), QString(), pPos);
} }
else{ else{
mActiveScene->addTextHtml(pMimeData->html(), pPos); mActiveScene->addTextHtml(pMimeData->html(), pPos);
@ -2307,7 +2340,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
QString qsUrl = UBPlatformUtils::urlFromClipboard(); QString qsUrl = UBPlatformUtils::urlFromClipboard();
if("" != qsUrl){ if("" != qsUrl){
// We finally got the url of the dropped ressource! Let's import it! // We finally got the url of the dropped ressource! Let's import it!
downloadURL(qsUrl, pPos); downloadURL(qsUrl, qsUrl, pPos);
return; return;
} }
#endif #endif

@ -193,8 +193,8 @@ class UBBoardController : public UBDocumentContainer
void firstScene(); void firstScene();
void lastScene(); void lastScene();
void groupButtonClicked(); void groupButtonClicked();
void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false, bool internalData = false); void downloadURL(const QUrl& url, QString contentSourceUrl = QString(), const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false, bool internalData = false);
UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pHeader,
QByteArray pData, QPointF pPos, QSize pSize, QByteArray pData, QPointF pPos, QSize pSize,
bool isBackground = false, bool internalData = false); bool isBackground = false, bool internalData = false);
void changeBackground(bool isDark, bool isCrossed); void changeBackground(bool isDark, bool isCrossed);
@ -210,8 +210,8 @@ class UBBoardController : public UBDocumentContainer
void setRegularPageSize(bool checked); void setRegularPageSize(bool checked);
void stylusToolChanged(int tool); void stylusToolChanged(int tool);
void grabScene(const QRectF& pSceneRect); void grabScene(const QRectF& pSceneRect);
UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos); UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos, bool bUseSource = false);
UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos); UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos, bool bUseSource = false);
UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos); UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos);
void cut(); void cut();

@ -995,6 +995,7 @@ void UBBoardPaletteManager::startDownloads()
mDownloadInProgress = true; mDownloadInProgress = true;
mpDownloadWidget->setVisibleState(true); mpDownloadWidget->setVisibleState(true);
mRightPalette->addTab(mpDownloadWidget); mRightPalette->addTab(mpDownloadWidget);
mpDownloadWidget;
} }
} }

@ -711,7 +711,7 @@ void UBFeaturesController::addItemToPage(const UBFeature &item)
void UBFeaturesController::addItemAsBackground(const UBFeature &item) void UBFeaturesController::addItemAsBackground(const UBFeature &item)
{ {
UBApplication::boardController->downloadURL( item.getFullPath(), QPointF(), QSize(), true ); UBApplication::boardController->downloadURL( item.getFullPath(), QString(), QPointF(), QSize(), true );
} }
UBFeature UBFeaturesController::getDestinationFeatureForUrl( const QUrl &url ) UBFeature UBFeaturesController::getDestinationFeatureForUrl( const QUrl &url )

@ -14,12 +14,79 @@
*/ */
#include "UBDownloadManager.h" #include "UBDownloadManager.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "gui/UBMainWindow.h" #include "gui/UBMainWindow.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "board/UBBoardPaletteManager.h" #include "board/UBBoardPaletteManager.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/memcheck.h" #include "core/memcheck.h"
UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent)
: QThread(parent)
, mDesc(desc)
, m_bAborting(false)
{
}
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()
{
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mDesc.srcUrl);
int position=mimeType.indexOf(";");
if(position != -1)
mimeType=mimeType.left(position);
UBMimeType::Enum itemMimeType = UBFileSystemUtils::mimeTypeFromString(mimeType);
QString destDirectory;
if (UBMimeType::Video == itemMimeType)
destDirectory = UBPersistenceManager::videoDirectory;
else
if (UBMimeType::Audio == itemMimeType)
destDirectory = UBPersistenceManager::audioDirectory;
if (mDesc.originalSrcUrl.isEmpty())
mDesc.originalSrcUrl = mDesc.srcUrl;
QString uuid = QUuid::createUuid();
UBPersistenceManager::persistenceManager()->addFileToDocument(UBApplication::boardController->selectedDocument(),
QUrl(mDesc.srcUrl).toLocalFile(),
destDirectory,
uuid,
mTo,
NULL);
if (m_bAborting)
{
if (QFile::exists(mTo))
QFile::remove(mTo);
}
else
emit signal_asyncCopyFinished(mDesc.id, !mTo.isEmpty(), QUrl::fromLocalFile(mTo), QUrl::fromLocalFile(mDesc.originalSrcUrl), "", NULL, mDesc.pos, mDesc.size, mDesc.isBackground);
}
void UBAsyncLocalFileDownloader::abort()
{
m_bAborting = true;
}
/** The unique instance of the download manager */ /** The unique instance of the download manager */
static UBDownloadManager* pInstance = NULL; static UBDownloadManager* pInstance = NULL;
@ -100,7 +167,7 @@ void UBDownloadManager::init()
{ {
mCrntDL.clear(); mCrntDL.clear();
mPendingDL.clear(); mPendingDL.clear();
mReplies.clear(); mDownloads.clear();
mLastID = 1; mLastID = 1;
mDLAvailability.clear(); mDLAvailability.clear();
for(int i=0; i<SIMULTANEOUS_DOWNLOAD; i++) for(int i=0; i<SIMULTANEOUS_DOWNLOAD; i++)
@ -193,7 +260,8 @@ void UBDownloadManager::onDownloadProgress(int id, qint64 received, qint64 total
* \brief Called when the download of the given file is finished * \brief Called when the download of the given file is finished
* @param desc as the current downloaded file description * @param desc as the current downloaded file description
*/ */
void UBDownloadManager::onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground)
void UBDownloadManager::onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground)
{ {
// Temporary data for dnd do not delete it please // Temporary data for dnd do not delete it please
Q_UNUSED(pPos) Q_UNUSED(pPos)
@ -209,9 +277,9 @@ void UBDownloadManager::onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl
desc.contentTypeHeader = pContentTypeHeader; desc.contentTypeHeader = pContentTypeHeader;
emit downloadFinished(pSuccess, desc, pData); emit downloadFinished(pSuccess, desc, pData);
} else if(desc.modal) { } else if(desc.dest == sDownloadFileDesc::board) {
// The downloaded file is modal so we must put it on the board // The downloaded file is modal so we must put it on the board
emit addDownloadedFileToBoard(pSuccess, sourceUrl, pContentTypeHeader, pData, pPos, pSize, isBackground); emit addDownloadedFileToBoard(pSuccess, sourceUrl, contentUrl, pContentTypeHeader, pData, pPos, pSize, isBackground);
} }
else else
{ {
@ -259,7 +327,7 @@ void UBDownloadManager::updateFileCurrentSize(int id, qint64 received, qint64 to
mCrntDL.remove(i); mCrntDL.remove(i);
// Here we don't forget to remove the reply related to the finished download // Here we don't forget to remove the reply related to the finished download
mReplies.remove(id); mDownloads.remove(id);
// Free the download slot used by the finished file // Free the download slot used by the finished file
for(int j=0; j<mDLAvailability.size();j++) for(int j=0; j<mDLAvailability.size();j++)
@ -302,15 +370,28 @@ void UBDownloadManager::updateFileCurrentSize(int id, qint64 received, qint64 to
*/ */
void UBDownloadManager::startFileDownload(sDownloadFileDesc desc) void UBDownloadManager::startFileDownload(sDownloadFileDesc desc)
{ {
if (desc.srcUrl.startsWith("file://") || desc.srcUrl.startsWith("/"))
{
UBAsyncLocalFileDownloader * cpHelper = new UBAsyncLocalFileDownloader(desc, this);
connect(cpHelper, SIGNAL(signal_asyncCopyFinished(int, bool, QUrl, QUrl, QString, QByteArray, QPointF, QSize, bool)), this, SLOT(onDownloadFinished(int, bool, QUrl, QUrl,QString, QByteArray, QPointF, QSize, bool)));
QObject *res = dynamic_cast<QObject *>(cpHelper->download());
if (!res)
delete res;
else
mDownloads[desc.id] = res;
}
else
{
UBDownloadHttpFile* http = new UBDownloadHttpFile(desc.id, this); UBDownloadHttpFile* http = new UBDownloadHttpFile(desc.id, this);
connect(http, SIGNAL(downloadProgress(int, qint64,qint64)), this, SLOT(onDownloadProgress(int,qint64,qint64))); connect(http, SIGNAL(downloadProgress(int, qint64,qint64)), this, SLOT(onDownloadProgress(int,qint64,qint64)));
connect(http, SIGNAL(downloadFinished(int, bool, QUrl, QString, QByteArray, QPointF, QSize, bool)), this, SLOT(onDownloadFinished(int, bool, QUrl, QString, QByteArray, QPointF, QSize, bool))); connect(http, SIGNAL(downloadFinished(int, bool, QUrl, QUrl, QString, QByteArray, QPointF, QSize, bool)), this, SLOT(onDownloadFinished(int, bool, QUrl, QUrl, QString, QByteArray, QPointF, QSize, bool)));
//the desc.url is encoded. So we have to decode it before. //the desc.srcUrl is encoded. So we have to decode it before.
QUrl url; QUrl url;
url.setEncodedUrl(desc.url.toUtf8()); url.setEncodedUrl(desc.srcUrl.toUtf8());
// We send here the request and store its reply in order to be able to cancel it if needed // We send here the request and store its reply in order to be able to cancel it if needed
mReplies[desc.id] = http->get(url, desc.pos, desc.size, desc.isBackground); mDownloads[desc.id] = dynamic_cast<QObject *>(http->get(url, desc.pos, desc.size, desc.isBackground));
}
} }
/** /**
@ -356,10 +437,18 @@ void UBDownloadManager::checkIfModalRemains()
void UBDownloadManager::cancelDownloads() void UBDownloadManager::cancelDownloads()
{ {
// Stop the current downloads // Stop the current downloads
QMap<int, QNetworkReply*>::iterator it = mReplies.begin(); QMap<int, QObject*>::iterator it = mDownloads.begin();
for(; it!=mReplies.end();it++) for(; it!=mDownloads.end();it++)
{ {
dynamic_cast<QNetworkReply*>(it.value())->abort(); QNetworkReply *netReply = dynamic_cast<QNetworkReply*>(it.value());
if (netReply)
netReply->abort();
else
{
UBAsyncLocalFileDownloader *localDownload = dynamic_cast<UBAsyncLocalFileDownloader *>(it.value());
if (localDownload)
localDownload->abort();
}
} }
// Clear all the lists // Clear all the lists
@ -372,7 +461,8 @@ void UBDownloadManager::cancelDownloads()
void UBDownloadManager::onDownloadError(int id) void UBDownloadManager::onDownloadError(int id)
{ {
QNetworkReply* pReply = mReplies.value(id); QNetworkReply *pReply = dynamic_cast<QNetworkReply *>(mDownloads.value(id));
if(NULL != pReply) if(NULL != pReply)
{ {
// Check which error occured: // Check which error occured:
@ -402,9 +492,25 @@ void UBDownloadManager::finishDownloads(bool cancel)
void UBDownloadManager::cancelDownload(int id) void UBDownloadManager::cancelDownload(int id)
{ {
if (!mDownloads.size())
return;
// Stop the download // Stop the download
mReplies[id]->abort();
mReplies.remove(id); QNetworkReply *pNetworkDownload = dynamic_cast<QNetworkReply *>(mDownloads[id]);
if (pNetworkDownload)
pNetworkDownload->abort();
else
{
UBAsyncLocalFileDownloader *pLocalDownload = dynamic_cast<UBAsyncLocalFileDownloader *>(mDownloads[id]);
if (pLocalDownload)
{
if (pLocalDownload->isRunning())
pLocalDownload->abort();
}
}
mDownloads.remove(id);
// Remove the canceled download from the download lists // Remove the canceled download from the download lists
bool bFound = false; bool bFound = false;
@ -494,7 +600,7 @@ void UBDownloadHttpFile::onDownloadFinished(bool pSuccess, QUrl sourceUrl, QStri
if(pSuccess) if(pSuccess)
{ {
// Notify the end of the download // Notify the end of the download
emit downloadFinished(mId, pSuccess, sourceUrl, pContentTypeHeader, pData, pPos, pSize, isBackground); emit downloadFinished(mId, pSuccess, sourceUrl, sourceUrl, pContentTypeHeader, pData, pPos, pSize, isBackground);
} }
else else
{ {

@ -52,7 +52,8 @@ struct sDownloadFileDesc
int id; int id;
int totalSize; int totalSize;
int currentSize; int currentSize;
QString url; QString srcUrl;
QString originalSrcUrl;
QString contentTypeHeader; QString contentTypeHeader;
bool modal; bool modal;
QPointF pos; // For board drop only QPointF pos; // For board drop only
@ -75,7 +76,7 @@ public:
signals: signals:
void downloadProgress(int id, qint64 current,qint64 total); void downloadProgress(int id, qint64 current,qint64 total);
void downloadFinished(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); void downloadFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void downloadError(int id); void downloadError(int id);
private slots: private slots:
@ -86,6 +87,28 @@ private:
int mId; int mId;
}; };
class UBAsyncLocalFileDownloader : public QThread
{
Q_OBJECT
public:
UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent = 0);
UBAsyncLocalFileDownloader *download();
void run();
void abort();
signals:
void finished(QString srcUrl, QString resUrl);
void signal_asyncCopyFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
private:
sDownloadFileDesc mDesc;
bool m_bAborting;
QString mFrom;
QString mTo;
};
class UBDownloadManager : public QObject class UBDownloadManager : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -108,7 +131,7 @@ signals:
void downloadFinished(bool pSuccess, int id, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData); void downloadFinished(bool pSuccess, int id, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData);
void downloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData); void downloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData);
void downloadModalFinished(); void downloadModalFinished();
void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void addDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData); void addDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData);
void cancelAllDownloads(); void cancelAllDownloads();
void allDownloadsFinished(); void allDownloadsFinished();
@ -116,7 +139,7 @@ signals:
private slots: private slots:
void onUpdateDownloadLists(); void onUpdateDownloadLists();
void onDownloadProgress(int id, qint64 received, qint64 total); void onDownloadProgress(int id, qint64 received, qint64 total);
void onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); void onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void onDownloadError(int id); void onDownloadError(int id);
private: private:
@ -138,7 +161,7 @@ private:
/** The current download availability (-1 = free, otherwise the file ID is recorded)*/ /** The current download availability (-1 = free, otherwise the file ID is recorded)*/
QVector<int> mDLAvailability; QVector<int> mDLAvailability;
/** A map containing the replies of the GET operations */ /** A map containing the replies of the GET operations */
QMap<int, QNetworkReply*> mReplies; QMap<int, QObject*> mDownloads;
}; };
#endif // UBDOWNLOADMANAGER_H #endif // UBDOWNLOADMANAGER_H

@ -73,7 +73,11 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
mMediaObject = new Phonon::MediaObject(this); mMediaObject = new Phonon::MediaObject(this);
if (pMediaFileUrl.toLocalFile().contains("videos")) QString mediaPath = pMediaFileUrl.toString();
if ("" == mediaPath)
mediaPath = pMediaFileUrl.toLocalFile();
if (mediaPath.toLower().contains("videos"))
{ {
mMediaType = mediaType_Video; mMediaType = mediaType_Video;
@ -91,7 +95,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
haveLinkedImage = true; haveLinkedImage = true;
} }
else else
if (pMediaFileUrl.toLocalFile().contains("audios")) if (mediaPath.toLower().contains("audios"))
{ {
mMediaType = mediaType_Audio; mMediaType = mediaType_Audio;
mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
@ -191,7 +195,7 @@ void UBGraphicsMediaItem::setSourceUrl(const QUrl &pSourceUrl)
UBAudioPresentationWidget* pAudioWidget = dynamic_cast<UBAudioPresentationWidget*>(mAudioWidget); UBAudioPresentationWidget* pAudioWidget = dynamic_cast<UBAudioPresentationWidget*>(mAudioWidget);
if (pAudioWidget) if (pAudioWidget)
{ {
pAudioWidget->setTitle(UBFileSystemUtils::lastPathComponent(pSourceUrl.toString())); pAudioWidget->setTitle(UBFileSystemUtils::lastPathComponent(pSourceUrl.toLocalFile()));
} }
UBItem::setSourceUrl(pSourceUrl); UBItem::setSourceUrl(pSourceUrl);

@ -1217,6 +1217,11 @@ void UBGraphicsScene::textUndoCommandAdded(UBGraphicsTextItem *textItem)
} }
UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos) UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos)
{ {
qDebug() << pMediaFileUrl.toLocalFile();
if (!QFile::exists(pMediaFileUrl.toLocalFile()))
if (!QFile::exists(pMediaFileUrl.toString()))
return NULL;
UBGraphicsMediaItem* mediaItem = new UBGraphicsMediaItem(pMediaFileUrl); UBGraphicsMediaItem* mediaItem = new UBGraphicsMediaItem(pMediaFileUrl);
if(mediaItem){ if(mediaItem){
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), mediaItem, SLOT(activeSceneChanged())); connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), mediaItem, SLOT(activeSceneChanged()));

@ -19,7 +19,6 @@
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "document/UBDocumentContainer.h" #include "document/UBDocumentContainer.h"
#include "globals/UBGlobals.h" #include "globals/UBGlobals.h"
@ -855,4 +854,3 @@ QString UBFileSystemUtils::readTextFile(QString path)
return ""; return "";
} }

@ -17,14 +17,17 @@
#define UBFILESYSTEMUTILS_H_ #define UBFILESYSTEMUTILS_H_
#include <QtCore> #include <QtCore>
#include <QThread>
#include "core/UB.h" #include "core/UB.h"
class QuaZipFile; class QuaZipFile;
class UBProcessingProgressListener; class UBProcessingProgressListener;
class UBFileSystemUtils class UBFileSystemUtils : public QObject
{ {
Q_OBJECT
public: public:
UBFileSystemUtils(); UBFileSystemUtils();

@ -1048,8 +1048,8 @@ void UBFeatureProperties::onAddToLib()
desc.modal = false; desc.modal = false;
desc.name = QFileInfo( mpElement->getFullPath().toString()).fileName(); desc.name = QFileInfo( mpElement->getFullPath().toString()).fileName();
qDebug() << desc.name; qDebug() << desc.name;
desc.url = mpElement->getFullPath().toString(); desc.srcUrl = mpElement->getFullPath().toString();
qDebug() << desc.url; qDebug() << desc.srcUrl;
UBDownloadManager::downloadManager()->addFileToDownload(desc); UBDownloadManager::downloadManager()->addFileToDownload(desc);
} }
} }

@ -200,7 +200,7 @@ void UBTrapFlashController::createWidget()
// flash widget // flash widget
UBWebKitUtils::HtmlObject selectedObject = mAvailableFlashes.at(selectedIndex - 1); UBWebKitUtils::HtmlObject selectedObject = mAvailableFlashes.at(selectedIndex - 1);
UBApplication::applicationController->showBoard(); UBApplication::applicationController->showBoard();
UBApplication::boardController->downloadURL(QUrl(selectedObject.source), QPoint(0, 0), QSize(selectedObject.width, selectedObject.height)); UBApplication::boardController->downloadURL(QUrl(selectedObject.source), QString(), QPoint(0, 0), QSize(selectedObject.width, selectedObject.height));
} }
QString freezedWidgetPath = UBPlatformUtils::applicationResourcesDirectory() + "/etc/freezedWidgetWrapper.html"; QString freezedWidgetPath = UBPlatformUtils::applicationResourcesDirectory() + "/etc/freezedWidgetWrapper.html";

@ -281,7 +281,7 @@ void WBWebTrapWebView::trapElementAtPos(const QPoint& pos)
emit objectCaptured(QUrl(page()->currentFrame()->url().toString() + "/" + source), type, emit objectCaptured(QUrl(page()->currentFrame()->url().toString() + "/" + source), type,
htr.boundingRect().width(), htr.boundingRect().height()); htr.boundingRect().width(), htr.boundingRect().height());
UBApplication::boardController->downloadURL(QUrl(source), QPointF(0.0, 0.0)); UBApplication::boardController->downloadURL(QUrl(source));
UBApplication::applicationController->showBoard(); UBApplication::applicationController->showBoard();
} }
} }

Loading…
Cancel
Save