UBAsyncLocalFileDownloader moved to DownloadManager.

preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent ac754bb6b5
commit 385a1c8eb7
  1. 53
      src/core/UBDownloadManager.cpp
  2. 20
      src/core/UBDownloadManager.h
  3. 56
      src/frameworks/UBFileSystemUtils.cpp
  4. 23
      src/frameworks/UBFileSystemUtils.h

@ -14,6 +14,7 @@
*/
#include "UBDownloadManager.h"
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
#include "gui/UBMainWindow.h"
#include "board/UBBoardController.h"
#include "board/UBBoardPaletteManager.h"
@ -21,6 +22,58 @@
#include "core/memcheck.h"
UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent)
: QThread(parent)
, mDesc(desc)
{
}
void UBAsyncLocalFileDownloader::download()
{
if (!QFile::exists(QUrl(mDesc.srcUrl).toLocalFile())) {
qDebug() << "file" << mDesc.srcUrl << "does not present in fs";
return;
}
start();
}
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;
QString uuid = QUuid::createUuid();
UBPersistenceManager::persistenceManager()->addFileToDocument(UBApplication::boardController->selectedDocument(),
QUrl(mDesc.srcUrl).toLocalFile(),
destDirectory,
uuid,
mTo,
NULL);
if (mDesc.originalSrcUrl.isEmpty())
mDesc.originalSrcUrl = mDesc.srcUrl;
emit signal_asyncCopyFinished(mDesc.id, !mTo.isEmpty(), QUrl::fromLocalFile(mTo), QUrl::fromLocalFile(mDesc.originalSrcUrl), "", NULL, mDesc.pos, mDesc.size, mDesc.isBackground);
}
/** The unique instance of the download manager */
static UBDownloadManager* pInstance = NULL;

@ -87,6 +87,26 @@ private:
int mId;
};
class UBAsyncLocalFileDownloader : public QThread
{
Q_OBJECT
public:
UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent = 0);
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;
QString mFrom;
QString mTo;
};
class UBDownloadManager : public QObject
{
Q_OBJECT

@ -19,11 +19,8 @@
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "document/UBDocumentContainer.h"
#include "core/UBPersistenceManager.h"
#include "globals/UBGlobals.h"
THIRD_PARTY_WARNINGS_DISABLE
@ -857,56 +854,3 @@ QString UBFileSystemUtils::readTextFile(QString path)
return "";
}
UBAsyncLocalFileDownloader::UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent)
: QThread(parent)
, mDesc(desc)
{
}
void UBAsyncLocalFileDownloader::download()
{
if (!QFile::exists(QUrl(mDesc.srcUrl).toLocalFile())) {
qDebug() << "file" << mDesc.srcUrl << "does not present in fs";
return;
}
start();
}
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;
QString uuid = QUuid::createUuid();
UBPersistenceManager::persistenceManager()->addFileToDocument(UBApplication::boardController->selectedDocument(),
QUrl(mDesc.srcUrl).toLocalFile(),
destDirectory,
uuid,
mTo,
NULL);
if (mDesc.originalSrcUrl.isEmpty())
mDesc.originalSrcUrl = mDesc.srcUrl;
emit signal_asyncCopyFinished(mDesc.id, !mTo.isEmpty(), QUrl::fromLocalFile(mTo), QUrl::fromLocalFile(mDesc.originalSrcUrl), "", NULL, mDesc.pos, mDesc.size, mDesc.isBackground);
}

@ -21,29 +21,6 @@
#include "core/UB.h"
#include "core/UBDownloadManager.h"
class UBAsyncLocalFileDownloader : public QThread
{
Q_OBJECT
public:
UBAsyncLocalFileDownloader(sDownloadFileDesc desc, QObject *parent = 0);
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;
QString mFrom;
QString mTo;
};
class QuaZipFile;
class UBProcessingProgressListener;

Loading…
Cancel
Save