Fixed double copying of media items.

Refactored downloader for local files.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent afb18c1e15
commit 9b1d2932e4
  1. 2
      src/board/UBBoardController.cpp
  2. 38
      src/frameworks/UBFileSystemUtils.cpp
  3. 28
      src/frameworks/UBFileSystemUtils.h

@ -594,7 +594,7 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
sourceUrl = mitem->mediaFileUrl(); sourceUrl = mitem->mediaFileUrl();
downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false); downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false);
} }
}break; }return NULL; // async operation
case UBMimeType::VectorImage: case UBMimeType::VectorImage:
{ {

@ -859,24 +859,26 @@ QString UBFileSystemUtils::readTextFile(QString path)
} }
UBCopyThread::UBCopyThread(QObject *parent)
UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent)
: QThread(parent) : QThread(parent)
, mDesc(desc)
{ {
} }
void UBCopyThread::download(const sDownloadFileDesc &desc)
void UBAsyncLocalFileDownloader::download()
{ {
if (!QFile::exists(QUrl(desc.srcUrl).toLocalFile())) { if (!QFile::exists(QUrl(mDesc.srcUrl).toLocalFile())) {
qDebug() << "file" << desc.srcUrl << "does not present in fs"; qDebug() << "file" << mDesc.srcUrl << "does not present in fs";
return; return;
} }
mDesc = desc;
start(); start();
} }
void UBCopyThread::run() void UBAsyncLocalFileDownloader::run()
{ {
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mDesc.srcUrl); QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mDesc.srcUrl);
@ -906,25 +908,5 @@ void UBCopyThread::run()
if (mDesc.originalSrcUrl.isEmpty()) if (mDesc.originalSrcUrl.isEmpty())
mDesc.originalSrcUrl = mDesc.srcUrl; mDesc.originalSrcUrl = mDesc.srcUrl;
emit finished(mTo, mDesc.originalSrcUrl); emit signal_asyncCopyFinished(mDesc.id, !mTo.isEmpty(), QUrl::fromLocalFile(mTo), QUrl::fromLocalFile(mDesc.originalSrcUrl), "", NULL, mDesc.pos, mDesc.size, mDesc.isBackground);
}
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);
} }

@ -23,17 +23,19 @@
#include "core/UBDownloadManager.h" #include "core/UBDownloadManager.h"
class UBCopyThread : public QThread class UBAsyncLocalFileDownloader : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UBCopyThread(QObject *parent = 0); UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent = 0);
void download(const sDownloadFileDesc &desc); void download();
void run(); void run();
signals: signals:
void finished(QString srcUrl, QString resUrl); 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: private:
sDownloadFileDesc mDesc; sDownloadFileDesc mDesc;
@ -41,26 +43,6 @@ private:
QString mTo; 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 QuaZipFile;
class UBProcessingProgressListener; class UBProcessingProgressListener;

Loading…
Cancel
Save