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();
downloadURL(sourceUrl, srcFile, itemPos, QSize(itemSize.width(), itemSize.height()), false, false);
}
}break;
}return NULL; // async operation
case UBMimeType::VectorImage:
{

@ -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);
}

@ -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;

Loading…
Cancel
Save