From 9b1d2932e438fafec2c81655104d06fdd68a54e6 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 24 Sep 2012 17:53:57 +0300 Subject: [PATCH] Fixed double copying of media items. Refactored downloader for local files. --- src/board/UBBoardController.cpp | 2 +- src/frameworks/UBFileSystemUtils.cpp | 40 ++++++++-------------------- src/frameworks/UBFileSystemUtils.h | 28 ++++--------------- 3 files changed, 17 insertions(+), 53 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 0a69f25d..6ebf07bf 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -594,7 +594,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) sourceUrl = mitem->mediaFileUrl(); downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false); } - }break; + }return NULL; // async operation case UBMimeType::VectorImage: { diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index 877c6885..785fff67 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -859,24 +859,26 @@ QString UBFileSystemUtils::readTextFile(QString path) } -UBCopyThread::UBCopyThread(QObject *parent) + +UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent) : QThread(parent) -{ + , mDesc(desc) +{ + } -void UBCopyThread::download(const sDownloadFileDesc &desc) + +void UBAsyncLocalFileDownloader::download() { - if (!QFile::exists(QUrl(desc.srcUrl).toLocalFile())) { - qDebug() << "file" << desc.srcUrl << "does not present in fs"; + if (!QFile::exists(QUrl(mDesc.srcUrl).toLocalFile())) { + qDebug() << "file" << mDesc.srcUrl << "does not present in fs"; return; } - mDesc = desc; - start(); } -void UBCopyThread::run() +void UBAsyncLocalFileDownloader::run() { QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mDesc.srcUrl); @@ -906,25 +908,5 @@ void UBCopyThread::run() if (mDesc.originalSrcUrl.isEmpty()) mDesc.originalSrcUrl = mDesc.srcUrl; - emit finished(mTo, mDesc.originalSrcUrl); -} - - -UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent) - : QObject(parent) - , mDesc(desc) -{ - -} - -void UBAsyncLocalFileDownloader::download() -{ - UBCopyThread *cpThread = new UBCopyThread(this); // possible memory leak. Delete helper at signal_asyncCopyFinished() handler - connect(cpThread, SIGNAL(finished(QString, QString)), this, SLOT(slot_asyncCopyFinished(QString, QString))); - cpThread->download(mDesc); -} - -void UBAsyncLocalFileDownloader::slot_asyncCopyFinished(QString srcUrl, QString contentUrl) -{ - emit signal_asyncCopyFinished(mDesc.id, !srcUrl.isEmpty(), QUrl::fromLocalFile(srcUrl), QUrl::fromLocalFile(contentUrl), "", NULL, mDesc.pos, mDesc.size, mDesc.isBackground); + emit signal_asyncCopyFinished(mDesc.id, !mTo.isEmpty(), QUrl::fromLocalFile(mTo), QUrl::fromLocalFile(mDesc.originalSrcUrl), "", 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 bb857ee4..5e34e627 100644 --- a/src/frameworks/UBFileSystemUtils.h +++ b/src/frameworks/UBFileSystemUtils.h @@ -23,17 +23,19 @@ #include "core/UBDownloadManager.h" -class UBCopyThread : public QThread +class UBAsyncLocalFileDownloader : public QThread { Q_OBJECT public: - explicit UBCopyThread(QObject *parent = 0); + UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent = 0); - void download(const sDownloadFileDesc &desc); + void download(); void run(); 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; @@ -41,26 +43,6 @@ private: QString mTo; }; -class UBAsyncLocalFileDownloader : public QObject -{ - Q_OBJECT - -public: - UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent = 0); - - void download(); - -public slots: - void slot_asyncCopyFinished(QString srcUrl, QString resUrl); - -signals: - void signal_asyncCopyFinished(int id, bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); - -private: - QString mFrom; - QString mTo; - sDownloadFileDesc mDesc; -}; class QuaZipFile; class UBProcessingProgressListener;