diff --git a/src/api/UBLibraryAPI.cpp b/src/api/UBLibraryAPI.cpp index 8d75a568..073ed404 100644 --- a/src/api/UBLibraryAPI.cpp +++ b/src/api/UBLibraryAPI.cpp @@ -40,7 +40,7 @@ UBLibraryAPI::~UBLibraryAPI() void UBLibraryAPI::addObject(QString pUrl, int width, int height, int x, int y, bool background) { 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); } diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index e49bfe63..32c62f32 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -201,7 +201,7 @@ void UBWidgetUniboardAPI::addObject(QString pUrl, int width, int height, int x, if (UBApplication::boardController->activeScene() != mScene) 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); } diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 358ce4ce..0a69f25d 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -131,7 +131,7 @@ void UBBoardController::init() , this, SLOT(lastWindowClosed())); 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(); @@ -562,7 +562,12 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) } 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(commonItem)) itemMimeType = UBMimeType::Group; else @@ -587,6 +592,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) if (mitem) { sourceUrl = mitem->mediaFileUrl(); + downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false); } }break; @@ -661,7 +667,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) if (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) { createdItem->setSourceUrl(item->sourceUrl()); @@ -675,6 +681,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) retItem = dynamic_cast(createdItem); } + return retItem; } @@ -960,7 +967,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(); QString sUrl = url.toString(); @@ -971,7 +978,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const 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("/")) { @@ -988,7 +995,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const { QFile file(fileName); file.open(QIODevice::ReadOnly); - downloadFinished(true, formedUrl, contentType, file.readAll(), pPos, pSize, isBackground, internalData); + downloadFinished(true, formedUrl, QUrl(), contentType, file.readAll(), pPos, pSize, isBackground, internalData); file.close(); } else @@ -998,6 +1005,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const 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 @@ -1036,7 +1044,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, bool isBackground, bool internalData) { @@ -1198,7 +1206,10 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri } if(mediaVideoItem){ - mediaVideoItem->setSourceUrl(sourceUrl); + if (contentUrl.isEmpty()) + mediaVideoItem->setSourceUrl(sourceUrl); + else + mediaVideoItem->setSourceUrl(contentUrl); mediaVideoItem->setUuid(uuid); connect(this, SIGNAL(activeSceneChanged()), mediaVideoItem, SLOT(activeSceneChanged())); } @@ -1239,7 +1250,10 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri } if(audioMediaItem){ - audioMediaItem->setSourceUrl(sourceUrl); + if (contentUrl.isEmpty()) + audioMediaItem->setSourceUrl(sourceUrl); + else + audioMediaItem->setSourceUrl(contentUrl); audioMediaItem->setUuid(uuid); connect(this, SIGNAL(activeSceneChanged()), audioMediaItem, SLOT(activeSceneChanged())); } @@ -2262,7 +2276,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint if("" != url) { - downloadURL(url, pPos); + downloadURL(url, QString(), pPos); return; } } @@ -2282,7 +2296,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint foreach(const QUrl url, urls){ QPointF pos(pPos + QPointF(index * 15, index * 15)); - downloadURL(url, pos, QSize(), false, internalData); + downloadURL(url, QString(), pos, QSize(), false, internalData); index++; } @@ -2308,7 +2322,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 QString qsTmp = pMimeData->text().remove(QRegExp("[\\0]")); if(qsTmp.startsWith("http")){ - downloadURL(QUrl(qsTmp), pPos); + downloadURL(QUrl(qsTmp), QString(), pPos); } else{ mActiveScene->addTextHtml(pMimeData->html(), pPos); diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index 68468188..4f0bb231 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -193,8 +193,8 @@ class UBBoardController : public UBDocumentContainer void firstScene(); void lastScene(); 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); - UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, + 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, QUrl contentUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false, bool internalData = false); void changeBackground(bool isDark, bool isCrossed); diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index a9bbeb08..049ee301 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -711,7 +711,7 @@ void UBFeaturesController::addItemToPage(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 ) diff --git a/src/core/UBDownloadManager.cpp b/src/core/UBDownloadManager.cpp index 89e975bc..90862470 100644 --- a/src/core/UBDownloadManager.cpp +++ b/src/core/UBDownloadManager.cpp @@ -194,7 +194,8 @@ void UBDownloadManager::onDownloadProgress(int id, qint64 received, qint64 total * \brief Called when the download of the given file is finished * @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 Q_UNUSED(pPos) @@ -212,7 +213,7 @@ void UBDownloadManager::onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl } else if(desc.dest == sDownloadFileDesc::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 { @@ -306,8 +307,8 @@ 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, QString, QByteArray, QPointF, QSize, bool)), this, SLOT(onDownloadFinished(int, bool, QUrl, QString, QByteArray, QPointF, QSize, bool))); - cpHelper->copyFile(QUrl(desc.srcUrl).toLocalFile(), QUrl(desc.dstUrl).toLocalFile(), true); + 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))); + cpHelper->download(); } else { diff --git a/src/core/UBDownloadManager.h b/src/core/UBDownloadManager.h index 9e185563..0a5cffc9 100644 --- a/src/core/UBDownloadManager.h +++ b/src/core/UBDownloadManager.h @@ -53,7 +53,7 @@ struct sDownloadFileDesc int totalSize; int currentSize; QString srcUrl; - QString dstUrl; + QString originalSrcUrl; QString contentTypeHeader; bool modal; QPointF pos; // For board drop only @@ -109,7 +109,7 @@ signals: void downloadFinished(bool pSuccess, int id, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData); void downloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData); 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 cancelAllDownloads(); void allDownloadsFinished(); @@ -117,7 +117,7 @@ signals: private slots: void onUpdateDownloadLists(); 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); private: diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index 74b378f8..9d3c8705 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -195,7 +195,7 @@ void UBGraphicsMediaItem::setSourceUrl(const QUrl &pSourceUrl) UBAudioPresentationWidget* pAudioWidget = dynamic_cast(mAudioWidget); if (pAudioWidget) { - pAudioWidget->setTitle(UBFileSystemUtils::lastPathComponent(pSourceUrl.toString())); + pAudioWidget->setTitle(UBFileSystemUtils::lastPathComponent(pSourceUrl.toLocalFile())); } UBItem::setSourceUrl(pSourceUrl); diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index 5fb3376d..877c6885 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -864,31 +864,14 @@ UBCopyThread::UBCopyThread(QObject *parent) { } -void UBCopyThread::copyFile(const QString &source, const QString &destination, bool overwrite) +void UBCopyThread::download(const sDownloadFileDesc &desc) { - if (!QFile::exists(source)) { - qDebug() << "file" << source << "does not present in fs"; + if (!QFile::exists(QUrl(desc.srcUrl).toLocalFile())) { + qDebug() << "file" << desc.srcUrl << "does not present in fs"; return; } - QString normalizedDestination = destination; - if (QFile::exists(normalizedDestination)) { - if (QFileInfo(normalizedDestination).isFile() && overwrite) { - QFile::remove(normalizedDestination); - } - } else { - normalizedDestination = normalizedDestination.replace(QString("\\"), QString("/")); - int pos = normalizedDestination.lastIndexOf("/"); - if (pos != -1) { - QString newpath = normalizedDestination.left(pos); - if (!QDir().mkpath(newpath)) { - qDebug() << "can't create a new path at " << newpath; - } - } - } - - mFrom = source; - mTo = normalizedDestination; + mDesc = desc; start(); } @@ -896,7 +879,7 @@ void UBCopyThread::copyFile(const QString &source, const QString &destination, b void UBCopyThread::run() { - QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mFrom); + QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mDesc.srcUrl); int position=mimeType.indexOf(";"); if(position != -1) @@ -914,13 +897,16 @@ void UBCopyThread::run() QString uuid = QUuid::createUuid(); UBPersistenceManager::persistenceManager()->addFileToDocument(UBApplication::boardController->selectedDocument(), - mFrom, + QUrl(mDesc.srcUrl).toLocalFile(), destDirectory, uuid, mTo, NULL); - emit finished(mTo); + if (mDesc.originalSrcUrl.isEmpty()) + mDesc.originalSrcUrl = mDesc.srcUrl; + + emit finished(mTo, mDesc.originalSrcUrl); } @@ -931,18 +917,14 @@ UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, Q } -void UBAsyncLocalFileDownloader::copyFile(QString &source, QString &destination, bool bOverwrite) +void UBAsyncLocalFileDownloader::download() { - mFrom = source; - mTo = destination; - UBCopyThread *cpThread = new UBCopyThread(this); // possible memory leak. Delete helper at signal_asyncCopyFinished() handler - connect(cpThread, SIGNAL(finished(QString)), this, SLOT(slot_asyncCopyFinished(QString))); - cpThread->copyFile(source, destination, bOverwrite); + connect(cpThread, SIGNAL(finished(QString, QString)), this, SLOT(slot_asyncCopyFinished(QString, QString))); + cpThread->download(mDesc); } -void UBAsyncLocalFileDownloader::slot_asyncCopyFinished(QString resUrl) +void UBAsyncLocalFileDownloader::slot_asyncCopyFinished(QString srcUrl, QString contentUrl) { - emit signal_asyncCopyFinished(mDesc.id, !resUrl.isEmpty(), QUrl(resUrl), "", NULL, mDesc.pos, mDesc.size, mDesc.isBackground); - + emit signal_asyncCopyFinished(mDesc.id, !srcUrl.isEmpty(), QUrl::fromLocalFile(srcUrl), QUrl::fromLocalFile(contentUrl), "", NULL, mDesc.pos, mDesc.size, mDesc.isBackground); } \ No newline at end of file diff --git a/src/frameworks/UBFileSystemUtils.h b/src/frameworks/UBFileSystemUtils.h index b5c5a961..bb857ee4 100644 --- a/src/frameworks/UBFileSystemUtils.h +++ b/src/frameworks/UBFileSystemUtils.h @@ -29,13 +29,14 @@ class UBCopyThread : public QThread public: explicit UBCopyThread(QObject *parent = 0); - void copyFile(const QString &source, const QString &destination, bool overwrite); + void download(const sDownloadFileDesc &desc); void run(); signals: - void finished(QString resUrl); + void finished(QString srcUrl, QString resUrl); private: + sDownloadFileDesc mDesc; QString mFrom; QString mTo; }; @@ -47,13 +48,13 @@ class UBAsyncLocalFileDownloader : public QObject public: UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent = 0); - void copyFile(QString &source, QString &destination, bool bOverwrite); + void download(); public slots: - void slot_asyncCopyFinished(QString resUrl); + void slot_asyncCopyFinished(QString srcUrl, QString resUrl); signals: - void signal_asyncCopyFinished(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); + void signal_asyncCopyFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); private: QString mFrom; diff --git a/src/web/UBTrapFlashController.cpp b/src/web/UBTrapFlashController.cpp index 25cb37e9..6458f203 100644 --- a/src/web/UBTrapFlashController.cpp +++ b/src/web/UBTrapFlashController.cpp @@ -200,7 +200,7 @@ void UBTrapFlashController::createWidget() // flash widget UBWebKitUtils::HtmlObject selectedObject = mAvailableFlashes.at(selectedIndex - 1); 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"; diff --git a/src/web/browser/WBWebTrapWebView.cpp b/src/web/browser/WBWebTrapWebView.cpp index 971ed75c..2c97626c 100644 --- a/src/web/browser/WBWebTrapWebView.cpp +++ b/src/web/browser/WBWebTrapWebView.cpp @@ -281,7 +281,7 @@ void WBWebTrapWebView::trapElementAtPos(const QPoint& pos) emit objectCaptured(QUrl(page()->currentFrame()->url().toString() + "/" + source), type, htr.boundingRect().width(), htr.boundingRect().height()); - UBApplication::boardController->downloadURL(QUrl(source), QPointF(0.0, 0.0)); + UBApplication::boardController->downloadURL(QUrl(source)); UBApplication::applicationController->showBoard(); } }