[app] Dropped BooksTask in favor of HarbourTask
This commit is contained in:
parent
b78201060b
commit
57801ed140
18 changed files with 152 additions and 337 deletions
|
@ -123,7 +123,6 @@ SOURCES += \
|
||||||
src/BooksShelf.cpp \
|
src/BooksShelf.cpp \
|
||||||
src/BooksStorage.cpp \
|
src/BooksStorage.cpp \
|
||||||
src/BooksStorageModel.cpp \
|
src/BooksStorageModel.cpp \
|
||||||
src/BooksTask.cpp \
|
|
||||||
src/BooksTextStyle.cpp \
|
src/BooksTextStyle.cpp \
|
||||||
src/BooksTaskQueue.cpp \
|
src/BooksTaskQueue.cpp \
|
||||||
src/BooksTextView.cpp \
|
src/BooksTextView.cpp \
|
||||||
|
@ -169,7 +168,6 @@ HEADERS += \
|
||||||
src/BooksShelf.h \
|
src/BooksShelf.h \
|
||||||
src/BooksStorage.h \
|
src/BooksStorage.h \
|
||||||
src/BooksStorageModel.h \
|
src/BooksStorageModel.h \
|
||||||
src/BooksTask.h \
|
|
||||||
src/BooksTaskQueue.h \
|
src/BooksTaskQueue.h \
|
||||||
src/BooksTextView.h \
|
src/BooksTextView.h \
|
||||||
src/BooksTextStyle.h \
|
src/BooksTextStyle.h \
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
|
|
||||||
#include "BooksBook.h"
|
#include "BooksBook.h"
|
||||||
#include "BooksDefs.h"
|
#include "BooksDefs.h"
|
||||||
#include "BooksTask.h"
|
|
||||||
#include "BooksTextView.h"
|
#include "BooksTextView.h"
|
||||||
#include "BooksTextStyle.h"
|
#include "BooksTextStyle.h"
|
||||||
#include "BooksPaintContext.h"
|
#include "BooksPaintContext.h"
|
||||||
|
@ -42,6 +41,7 @@
|
||||||
|
|
||||||
#include "HarbourJson.h"
|
#include "HarbourJson.h"
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
|
#include "HarbourTask.h"
|
||||||
|
|
||||||
#include "ZLImage.h"
|
#include "ZLImage.h"
|
||||||
#include "image/ZLQtImageManager.h"
|
#include "image/ZLQtImageManager.h"
|
||||||
|
@ -135,10 +135,11 @@ bool BooksBook::CoverPaintContext::gotIt() const
|
||||||
// BooksBook::CoverTask
|
// BooksBook::CoverTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksBook::CoverTask : public BooksTask
|
class BooksBook::CoverTask : public HarbourTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CoverTask(QString aStateDir, shared_ptr<Book> aBook, QString aImagePath) :
|
CoverTask(QThreadPool* aPool, QString aStateDir, shared_ptr<Book> aBook,
|
||||||
|
QString aImagePath) : HarbourTask(aPool),
|
||||||
iStateDir(aStateDir), iBook(aBook), iImagePath(aImagePath),
|
iStateDir(aStateDir), iBook(aBook), iImagePath(aImagePath),
|
||||||
iCoverMissing(false) {}
|
iCoverMissing(false) {}
|
||||||
|
|
||||||
|
@ -164,9 +165,10 @@ inline bool BooksBook::CoverTask::hasImage() const
|
||||||
class BooksBook::LoadCoverTask : public BooksBook::CoverTask
|
class BooksBook::LoadCoverTask : public BooksBook::CoverTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LoadCoverTask(QString aStateDir, shared_ptr<Book> aBook,
|
LoadCoverTask(QThreadPool* aPool, QString aStateDir,
|
||||||
shared_ptr<FormatPlugin> aFormatPlugin, QString aImagePath) :
|
shared_ptr<Book> aBook, shared_ptr<FormatPlugin> aFormatPlugin,
|
||||||
BooksBook::CoverTask(aStateDir, aBook, aImagePath),
|
QString aImagePath) :
|
||||||
|
BooksBook::CoverTask(aPool, aStateDir, aBook, aImagePath),
|
||||||
iFormatPlugin(aFormatPlugin) {}
|
iFormatPlugin(aFormatPlugin) {}
|
||||||
|
|
||||||
virtual void performTask();
|
virtual void performTask();
|
||||||
|
@ -231,8 +233,9 @@ void BooksBook::LoadCoverTask::performTask()
|
||||||
class BooksBook::GuessCoverTask : public BooksBook::CoverTask
|
class BooksBook::GuessCoverTask : public BooksBook::CoverTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuessCoverTask(QString aStateDir, shared_ptr<Book> aBook, QString aImagePath) :
|
GuessCoverTask(QThreadPool* aPool, QString aStateDir,
|
||||||
BooksBook::CoverTask(aStateDir, aBook, aImagePath) {}
|
shared_ptr<Book> aBook, QString aImagePath) :
|
||||||
|
BooksBook::CoverTask(aPool, aStateDir, aBook, aImagePath) {}
|
||||||
|
|
||||||
virtual void performTask();
|
virtual void performTask();
|
||||||
};
|
};
|
||||||
|
@ -294,10 +297,10 @@ void BooksBook::GuessCoverTask::performTask()
|
||||||
// BooksBook::HashTask
|
// BooksBook::HashTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksBook::HashTask : public BooksTask
|
class BooksBook::HashTask : public HarbourTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HashTask(QString aPath, QThread* aThread);
|
HashTask(QThreadPool* aPool, QString aPath);
|
||||||
|
|
||||||
virtual void performTask();
|
virtual void performTask();
|
||||||
|
|
||||||
|
@ -306,8 +309,8 @@ public:
|
||||||
QByteArray iHash;
|
QByteArray iHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
BooksBook::HashTask::HashTask(QString aPath, QThread* aThread) :
|
BooksBook::HashTask::HashTask(QThreadPool* aPool, QString aPath) :
|
||||||
BooksTask(aThread), iPath(aPath)
|
HarbourTask(aPool), iPath(aPath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,9 +390,9 @@ BooksBook::BooksBook(const BooksStorage& aStorage, QString aRelativePath,
|
||||||
if (iHash.isEmpty()) {
|
if (iHash.isEmpty()) {
|
||||||
HDEBUG("need to calculate hash for" << qPrintable(iPath));
|
HDEBUG("need to calculate hash for" << qPrintable(iPath));
|
||||||
iHashTaskQueue = BooksTaskQueue::hashQueue();
|
iHashTaskQueue = BooksTaskQueue::hashQueue();
|
||||||
iHashTask = new HashTask(iPath, thread());
|
iHashTask = new HashTask(iHashTaskQueue->pool(), iPath);
|
||||||
connect(iHashTask, SIGNAL(done()), SLOT(onHashTaskDone()));
|
iHashTask->moveToThread(thread());
|
||||||
iHashTaskQueue->submit(iHashTask);
|
iHashTask->submit(this, SLOT(onHashTaskDone()));
|
||||||
}
|
}
|
||||||
// Refcounted BooksBook objects are managed by C++ code
|
// Refcounted BooksBook objects are managed by C++ code
|
||||||
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
|
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
|
||||||
|
@ -543,10 +546,9 @@ bool BooksBook::requestCoverImage()
|
||||||
if (!iBook.isNull() && !iFormatPlugin.isNull() &&
|
if (!iBook.isNull() && !iFormatPlugin.isNull() &&
|
||||||
!iCoverTasksDone && !iCoverTask) {
|
!iCoverTasksDone && !iCoverTask) {
|
||||||
HDEBUG(iTitle);
|
HDEBUG(iTitle);
|
||||||
iCoverTask = new LoadCoverTask(iStateDir, iBook, iFormatPlugin,
|
(iCoverTask = new LoadCoverTask(iTaskQueue->pool(), iStateDir, iBook,
|
||||||
cachedImagePath());
|
iFormatPlugin, cachedImagePath()))->submit(this,
|
||||||
connect(iCoverTask, SIGNAL(done()), SLOT(onLoadCoverTaskDone()));
|
SLOT(onLoadCoverTaskDone()));
|
||||||
iTaskQueue->submit(iCoverTask);
|
|
||||||
Q_EMIT loadingCoverChanged();
|
Q_EMIT loadingCoverChanged();
|
||||||
}
|
}
|
||||||
return iCoverTask != NULL;
|
return iCoverTask != NULL;
|
||||||
|
@ -583,9 +585,9 @@ void BooksBook::onLoadCoverTaskDone()
|
||||||
iCoverTasksDone = true;
|
iCoverTasksDone = true;
|
||||||
Q_EMIT loadingCoverChanged();
|
Q_EMIT loadingCoverChanged();
|
||||||
} else {
|
} else {
|
||||||
iCoverTask = new GuessCoverTask(iStateDir, iBook, cachedImagePath());
|
(iCoverTask = new GuessCoverTask(iTaskQueue->pool(), iStateDir,
|
||||||
connect(iCoverTask, SIGNAL(done()), SLOT(onGuessCoverTaskDone()));
|
iBook, cachedImagePath()))->submit(this,
|
||||||
iTaskQueue->submit(iCoverTask);
|
SLOT(onGuessCoverTaskDone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "BooksUtil.h"
|
#include "BooksUtil.h"
|
||||||
|
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
|
#include "HarbourTask.h"
|
||||||
|
|
||||||
#include "ZLTextHyphenator.h"
|
#include "ZLTextHyphenator.h"
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ public:
|
||||||
// BooksBookModel::PagingTask
|
// BooksBookModel::PagingTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksBookModel::PagingTask : public BooksTask
|
class BooksBookModel::PagingTask : public HarbourTask
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -78,7 +79,8 @@ public:
|
||||||
quint32 count;
|
quint32 count;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
PagingTask(BooksBookModel* aModel, shared_ptr<Book> aBook);
|
PagingTask(QThreadPool* aPool, BooksBookModel* aModel,
|
||||||
|
shared_ptr<Book> aBook);
|
||||||
~PagingTask();
|
~PagingTask();
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
|
@ -104,8 +106,9 @@ public:
|
||||||
|
|
||||||
const char BooksBookModel::PagingTask::MarksFileMagic[] = "MARK";
|
const char BooksBookModel::PagingTask::MarksFileMagic[] = "MARK";
|
||||||
|
|
||||||
BooksBookModel::PagingTask::PagingTask(BooksBookModel* aModel,
|
BooksBookModel::PagingTask::PagingTask(QThreadPool* aPool,
|
||||||
shared_ptr<Book> aBook) :
|
BooksBookModel* aModel, shared_ptr<Book> aBook) :
|
||||||
|
HarbourTask(aPool),
|
||||||
iBook(aBook),
|
iBook(aBook),
|
||||||
iTextStyle(aModel->textStyle()),
|
iTextStyle(aModel->textStyle()),
|
||||||
iPaint(aModel->width(), aModel->height()),
|
iPaint(aModel->width(), aModel->height()),
|
||||||
|
@ -621,8 +624,8 @@ void BooksBookModel::startReset(ResetReason aResetReason, bool aFullReset)
|
||||||
if (iBook && width() > 0 && height() > 0) {
|
if (iBook && width() > 0 && height() > 0) {
|
||||||
HDEBUG("starting" << qPrintable(QString("%1x%2").arg(width()).
|
HDEBUG("starting" << qPrintable(QString("%1x%2").arg(width()).
|
||||||
arg(height())) << "paging");
|
arg(height())) << "paging");
|
||||||
iPagingTask = new PagingTask(this, iBook->bookRef());
|
(iPagingTask = new PagingTask(iTaskQueue->pool(), this,
|
||||||
iTaskQueue->submit(iPagingTask);
|
iBook->bookRef()))->submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldPageCount > 0) {
|
if (oldPageCount > 0) {
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#define BOOKS_BOOK_MODEL_H
|
#define BOOKS_BOOK_MODEL_H
|
||||||
|
|
||||||
#include "BooksBook.h"
|
#include "BooksBook.h"
|
||||||
#include "BooksTask.h"
|
|
||||||
#include "BooksTaskQueue.h"
|
#include "BooksTaskQueue.h"
|
||||||
#include "BooksTextView.h"
|
#include "BooksTextView.h"
|
||||||
#include "BooksSettings.h"
|
#include "BooksSettings.h"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Jolla Ltd.
|
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* You may use this file under the terms of the BSD license as follows:
|
||||||
*
|
*
|
||||||
|
@ -34,6 +34,7 @@
|
||||||
#include "BooksCoverWidget.h"
|
#include "BooksCoverWidget.h"
|
||||||
|
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
|
#include "HarbourTask.h"
|
||||||
|
|
||||||
#include "ZLibrary.h"
|
#include "ZLibrary.h"
|
||||||
|
|
||||||
|
@ -43,10 +44,11 @@
|
||||||
// BooksCoverWidget::ScaleTask
|
// BooksCoverWidget::ScaleTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksCoverWidget::ScaleTask : public BooksTask
|
class BooksCoverWidget::ScaleTask : public HarbourTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScaleTask(QImage aImage, int aWidth, int aHeight, bool aStretch);
|
ScaleTask(QThreadPool* aPool, QImage aImage, int aWidth, int aHeight,
|
||||||
|
bool aStretch);
|
||||||
static QImage scale(QImage aImage, int aWidth, int aHeight, bool aStretch);
|
static QImage scale(QImage aImage, int aWidth, int aHeight, bool aStretch);
|
||||||
void performTask();
|
void performTask();
|
||||||
|
|
||||||
|
@ -58,12 +60,9 @@ public:
|
||||||
bool iStretch;
|
bool iStretch;
|
||||||
};
|
};
|
||||||
|
|
||||||
BooksCoverWidget::ScaleTask::ScaleTask(QImage aImage, int aWidth, int aHeight,
|
BooksCoverWidget::ScaleTask::ScaleTask(QThreadPool* aPool, QImage aImage,
|
||||||
bool aStretch) :
|
int aWidth, int aHeight, bool aStretch) : HarbourTask(aPool),
|
||||||
iImage(aImage),
|
iImage(aImage), iWidth(aWidth), iHeight(aHeight), iStretch(aStretch)
|
||||||
iWidth(aWidth),
|
|
||||||
iHeight(aHeight),
|
|
||||||
iStretch(aStretch)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,9 +366,8 @@ void BooksCoverWidget::scaleImage(bool aWasEmpty)
|
||||||
iScaledImage = ScaleTask::scale(iCoverImage, w, h, iStretch);
|
iScaledImage = ScaleTask::scale(iCoverImage, w, h, iStretch);
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
iScaleTask = new ScaleTask(iCoverImage, w, h, iStretch);
|
(iScaleTask = new ScaleTask(iTaskQueue->pool(), iCoverImage, w, h,
|
||||||
connect(iScaleTask, SIGNAL(done()), SLOT(onScaleTaskDone()));
|
iStretch))->submit(this, SLOT(onScaleTaskDone()));
|
||||||
iTaskQueue->submit(iScaleTask);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
iScaledImage = QImage();
|
iScaledImage = QImage();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 Jolla Ltd.
|
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* You may use this file under the terms of the BSD license as follows:
|
||||||
*
|
*
|
||||||
|
@ -35,7 +35,6 @@
|
||||||
#define BOOKS_COVER_WIDGET_H
|
#define BOOKS_COVER_WIDGET_H
|
||||||
|
|
||||||
#include "BooksTypes.h"
|
#include "BooksTypes.h"
|
||||||
#include "BooksTask.h"
|
|
||||||
#include "BooksTaskQueue.h"
|
#include "BooksTaskQueue.h"
|
||||||
#include "BooksBook.h"
|
#include "BooksBook.h"
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,10 @@
|
||||||
|
|
||||||
#include "BooksImportModel.h"
|
#include "BooksImportModel.h"
|
||||||
#include "BooksStorage.h"
|
#include "BooksStorage.h"
|
||||||
#include "BooksTask.h"
|
|
||||||
#include "BooksUtil.h"
|
#include "BooksUtil.h"
|
||||||
|
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
|
#include "HarbourTask.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
@ -82,12 +82,11 @@ BooksImportModel::Data::~Data()
|
||||||
// BooksImportModel::Task
|
// BooksImportModel::Task
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksImportModel::Task : public BooksTask
|
class BooksImportModel::Task : public HarbourTask {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Task(QString aDest);
|
Task(QThreadPool* aPool, QString aDest);
|
||||||
~Task();
|
~Task();
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
|
@ -111,7 +110,8 @@ public:
|
||||||
int iProgress;
|
int iProgress;
|
||||||
};
|
};
|
||||||
|
|
||||||
BooksImportModel::Task::Task(QString aDest) :
|
BooksImportModel::Task::Task(QThreadPool* aPool, QString aDest) :
|
||||||
|
HarbourTask(aPool),
|
||||||
iDestDir(aDest), iBufSize(0x1000), iBuf(NULL), iProgress(0)
|
iDestDir(aDest), iBufSize(0x1000), iBuf(NULL), iProgress(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -283,13 +283,13 @@ void BooksImportModel::refresh()
|
||||||
Q_EMIT progressChanged();
|
Q_EMIT progressChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
iTask = new Task(iDestination);
|
iTask = new Task(iTaskQueue->pool(), iDestination);
|
||||||
connect(iTask, SIGNAL(bookFound(BooksBook*)),
|
connect(iTask, SIGNAL(bookFound(BooksBook*)),
|
||||||
SLOT(onBookFound(BooksBook*)), Qt::QueuedConnection);
|
SLOT(onBookFound(BooksBook*)), Qt::QueuedConnection);
|
||||||
connect(iTask, SIGNAL(done()), SLOT(onTaskDone()));
|
connect(iTask, SIGNAL(done()), SLOT(onTaskDone()));
|
||||||
connect(iTask, SIGNAL(progress(int)), SLOT(onScanProgress(int)),
|
connect(iTask, SIGNAL(progress(int)), SLOT(onScanProgress(int)),
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
iTaskQueue->submit(iTask);
|
iTask->submit();
|
||||||
Q_EMIT busyChanged();
|
Q_EMIT busyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015-2018 Jolla Ltd.
|
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* You may use this file under the terms of the BSD license as follows:
|
||||||
*
|
*
|
||||||
|
@ -41,6 +41,7 @@
|
||||||
#include "ZLStringUtil.h"
|
#include "ZLStringUtil.h"
|
||||||
|
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
|
#include "HarbourTask.h"
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
@ -54,6 +55,8 @@ static const QString IMAGE_URL("image://%1/%2");
|
||||||
|
|
||||||
class BooksPageWidget::Data {
|
class BooksPageWidget::Data {
|
||||||
public:
|
public:
|
||||||
|
typedef shared_ptr<Data> Ptr;
|
||||||
|
|
||||||
Data(shared_ptr<ZLTextModel> aModel, int aWidth, int aHeight) :
|
Data(shared_ptr<ZLTextModel> aModel, int aWidth, int aHeight) :
|
||||||
iModel(aModel), iPaintContext(aWidth, aHeight) {}
|
iModel(aModel), iPaintContext(aWidth, aHeight) {}
|
||||||
|
|
||||||
|
@ -80,10 +83,9 @@ bool BooksPageWidget::Data::paint(QPainter* aPainter)
|
||||||
// BooksPageWidget::ResetTask
|
// BooksPageWidget::ResetTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksPageWidget::ResetTask : public BooksTask
|
class BooksPageWidget::ResetTask : public HarbourTask {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
ResetTask(shared_ptr<ZLTextModel> aModel,
|
ResetTask(QThreadPool* aPool, shared_ptr<ZLTextModel> aModel,
|
||||||
shared_ptr<ZLTextStyle> aTextStyle, int aWidth, int aHeight,
|
shared_ptr<ZLTextStyle> aTextStyle, int aWidth, int aHeight,
|
||||||
const BooksMargins& aMargins, const BooksPos& aPosition);
|
const BooksMargins& aMargins, const BooksPos& aPosition);
|
||||||
~ResetTask();
|
~ResetTask();
|
||||||
|
@ -97,9 +99,10 @@ public:
|
||||||
BooksPos iPosition;
|
BooksPos iPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
BooksPageWidget::ResetTask::ResetTask(shared_ptr<ZLTextModel> aModel,
|
BooksPageWidget::ResetTask::ResetTask(QThreadPool* aPool,
|
||||||
shared_ptr<ZLTextStyle> aTextStyle, int aWidth, int aHeight,
|
shared_ptr<ZLTextModel> aModel, shared_ptr<ZLTextStyle> aTextStyle,
|
||||||
const BooksMargins& aMargins, const BooksPos& aPosition) :
|
int aWidth, int aHeight, const BooksMargins& aMargins,
|
||||||
|
const BooksPos& aPosition) : HarbourTask(aPool),
|
||||||
iData(new BooksPageWidget::Data(aModel, aWidth, aHeight)),
|
iData(new BooksPageWidget::Data(aModel, aWidth, aHeight)),
|
||||||
iTextStyle(aTextStyle),
|
iTextStyle(aTextStyle),
|
||||||
iMargins(aMargins),
|
iMargins(aMargins),
|
||||||
|
@ -135,15 +138,16 @@ void BooksPageWidget::ResetTask::performTask()
|
||||||
// BooksPageWidget::RenderTask
|
// BooksPageWidget::RenderTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksPageWidget::RenderTask : public BooksTask {
|
class BooksPageWidget::RenderTask : public HarbourTask {
|
||||||
public:
|
public:
|
||||||
RenderTask(shared_ptr<BooksPageWidget::Data> aData, int aWidth, int aHeight) :
|
RenderTask(QThreadPool* aPool, Data::Ptr aData,
|
||||||
|
int aWidth, int aHeight) : HarbourTask(aPool),
|
||||||
iData(aData), iWidth(aWidth), iHeight(aHeight) {}
|
iData(aData), iWidth(aWidth), iHeight(aHeight) {}
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shared_ptr<BooksPageWidget::Data> iData;
|
Data::Ptr iData;
|
||||||
int iWidth;
|
int iWidth;
|
||||||
int iHeight;
|
int iHeight;
|
||||||
QImage iImage;
|
QImage iImage;
|
||||||
|
@ -165,16 +169,16 @@ void BooksPageWidget::RenderTask::performTask()
|
||||||
// BooksPageWidget::ClearSelectionTask
|
// BooksPageWidget::ClearSelectionTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksPageWidget::ClearSelectionTask : public BooksTask {
|
class BooksPageWidget::ClearSelectionTask : public HarbourTask {
|
||||||
public:
|
public:
|
||||||
ClearSelectionTask(shared_ptr<BooksPageWidget::Data> aData, int aWidth,
|
ClearSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aWidth,
|
||||||
int aHeight) : iData(aData), iWidth(aWidth), iHeight(aHeight),
|
int aHeight) : HarbourTask(aPool),
|
||||||
iImageUpdated(false) {}
|
iData(aData), iWidth(aWidth), iHeight(aHeight), iImageUpdated(false) {}
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shared_ptr<BooksPageWidget::Data> iData;
|
Data::Ptr iData;
|
||||||
int iWidth;
|
int iWidth;
|
||||||
int iHeight;
|
int iHeight;
|
||||||
QImage iImage;
|
QImage iImage;
|
||||||
|
@ -202,16 +206,17 @@ void BooksPageWidget::ClearSelectionTask::performTask()
|
||||||
// BooksPageWidget::StartSelectionTask
|
// BooksPageWidget::StartSelectionTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksPageWidget::StartSelectionTask : public BooksTask {
|
class BooksPageWidget::StartSelectionTask : public HarbourTask {
|
||||||
public:
|
public:
|
||||||
StartSelectionTask(shared_ptr<BooksPageWidget::Data> aData, int aX, int aY,
|
StartSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY,
|
||||||
int aWidth, int aHeight) : iData(aData), iX(aX), iY(aY),
|
int aWidth, int aHeight) : HarbourTask(aPool),
|
||||||
iWidth(aWidth), iHeight(aHeight), iSelectionEmpty(true) {}
|
iData(aData), iX(aX), iY(aY), iWidth(aWidth), iHeight(aHeight),
|
||||||
|
iSelectionEmpty(true) {}
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shared_ptr<BooksPageWidget::Data> iData;
|
Data::Ptr iData;
|
||||||
int iX;
|
int iX;
|
||||||
int iY;
|
int iY;
|
||||||
int iWidth;
|
int iWidth;
|
||||||
|
@ -239,17 +244,17 @@ void BooksPageWidget::StartSelectionTask::performTask()
|
||||||
// BooksPageWidget::ExtendSelectionTask
|
// BooksPageWidget::ExtendSelectionTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksPageWidget::ExtendSelectionTask : public BooksTask {
|
class BooksPageWidget::ExtendSelectionTask : public HarbourTask {
|
||||||
public:
|
public:
|
||||||
ExtendSelectionTask(shared_ptr<BooksPageWidget::Data> aData, int aX, int aY,
|
ExtendSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY,
|
||||||
int aWidth, int aHeight) : iData(aData), iX(aX), iY(aY),
|
int aWidth, int aHeight) : HarbourTask(aPool),
|
||||||
iWidth(aWidth), iHeight(aHeight), iSelectionChanged(false),
|
iData(aData), iX(aX), iY(aY), iWidth(aWidth), iHeight(aHeight),
|
||||||
iSelectionEmpty(true) {}
|
iSelectionChanged(false), iSelectionEmpty(true) {}
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shared_ptr<BooksPageWidget::Data> iData;
|
Data::Ptr iData;
|
||||||
int iX;
|
int iX;
|
||||||
int iY;
|
int iY;
|
||||||
int iWidth;
|
int iWidth;
|
||||||
|
@ -278,12 +283,12 @@ void BooksPageWidget::ExtendSelectionTask::performTask()
|
||||||
// BooksPageWidget::FootnoteTask
|
// BooksPageWidget::FootnoteTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksPageWidget::FootnoteTask : public BooksTask, ZLTextArea::Properties {
|
class BooksPageWidget::FootnoteTask : public HarbourTask, ZLTextArea::Properties {
|
||||||
public:
|
public:
|
||||||
FootnoteTask(int aX, int aY, int aMaxWidth, int aMaxHeight,
|
FootnoteTask(QThreadPool* aPool, int aX, int aY, int aMaxWidth, int aMaxHeight,
|
||||||
QString aPath, QString aLinkText, QString aRef,
|
QString aPath, QString aLinkText, QString aRef,
|
||||||
shared_ptr<ZLTextModel> aTextModel, shared_ptr<ZLTextStyle> aTextStyle,
|
shared_ptr<ZLTextModel> aTextModel, shared_ptr<ZLTextStyle> aTextStyle,
|
||||||
bool aInvertColors) :
|
bool aInvertColors) : HarbourTask(aPool),
|
||||||
iTextModel(aTextModel), iTextStyle(aTextStyle),
|
iTextModel(aTextModel), iTextStyle(aTextStyle),
|
||||||
iInvertColors(aInvertColors), iX(aX), iY(aY),
|
iInvertColors(aInvertColors), iX(aX), iY(aY),
|
||||||
iMaxWidth(aMaxWidth), iMaxHeight(aMaxHeight),
|
iMaxWidth(aMaxWidth), iMaxHeight(aMaxHeight),
|
||||||
|
@ -367,16 +372,16 @@ void BooksPageWidget::FootnoteTask::performTask()
|
||||||
// BooksPageWidget::PressTask
|
// BooksPageWidget::PressTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksPageWidget::PressTask : public BooksTask {
|
class BooksPageWidget::PressTask : public HarbourTask {
|
||||||
public:
|
public:
|
||||||
PressTask(shared_ptr<BooksPageWidget::Data> aData, int aX, int aY) :
|
PressTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY) :
|
||||||
iData(aData), iX(aX), iY(aY), iKind(REGULAR) {}
|
HarbourTask(aPool), iData(aData), iX(aX), iY(aY), iKind(REGULAR) {}
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
QString getLinkText(ZLTextWordCursor& aCursor);
|
QString getLinkText(ZLTextWordCursor& aCursor);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
shared_ptr<BooksPageWidget::Data> iData;
|
Data::Ptr iData;
|
||||||
int iX;
|
int iX;
|
||||||
int iY;
|
int iY;
|
||||||
QRect iRect;
|
QRect iRect;
|
||||||
|
@ -765,9 +770,9 @@ void BooksPageWidget::resetView()
|
||||||
width() > 0 && height() > 0 && iModel) {
|
width() > 0 && height() > 0 && iModel) {
|
||||||
shared_ptr<ZLTextModel> textModel = iModel->bookTextModel();
|
shared_ptr<ZLTextModel> textModel = iModel->bookTextModel();
|
||||||
if (!textModel.isNull()) {
|
if (!textModel.isNull()) {
|
||||||
iResetTask = new ResetTask(textModel, iTextStyle,
|
(iResetTask = new ResetTask(iTaskQueue->pool(), textModel, iTextStyle,
|
||||||
width(), height(), iMargins, iPageMark);
|
width(), height(), iMargins, iPageMark))->
|
||||||
iTaskQueue->submit(iResetTask, this, SLOT(onResetTaskDone()));
|
submit(this, SLOT(onResetTaskDone()));
|
||||||
cancelRepaint();
|
cancelRepaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -793,8 +798,8 @@ void BooksPageWidget::scheduleRepaint()
|
||||||
const int h = height();
|
const int h = height();
|
||||||
if (w > 0 && h > 0 && !iData.isNull() && !iData->iView.isNull()) {
|
if (w > 0 && h > 0 && !iData.isNull() && !iData->iView.isNull()) {
|
||||||
iData->iView->setInvertColors(invertColors());
|
iData->iView->setInvertColors(invertColors());
|
||||||
iRenderTask = new RenderTask(iData, w, h);
|
(iRenderTask = new RenderTask(iTaskQueue->pool(), iData, w, h))->
|
||||||
iTaskQueue->submit(iRenderTask, this, SLOT(onRenderTaskDone()));
|
submit(this, SLOT(onRenderTaskDone()));
|
||||||
} else {
|
} else {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -962,12 +967,11 @@ void BooksPageWidget::onLongPressTaskDone()
|
||||||
// Render the footnote
|
// Render the footnote
|
||||||
HDEBUG("footnote" << QString(task->iLink.c_str()));
|
HDEBUG("footnote" << QString(task->iLink.c_str()));
|
||||||
if (iFootnoteTask) iFootnoteTask->release(this);
|
if (iFootnoteTask) iFootnoteTask->release(this);
|
||||||
iFootnoteTask = new FootnoteTask(task->iX, task->iY,
|
(iFootnoteTask = new FootnoteTask(iTaskQueue->pool(),
|
||||||
width()*3/4, height()*10, book->path(), task->iLinkText,
|
task->iX, task->iY, width()*3/4, height()*10, book->path(),
|
||||||
QString::fromStdString(task->iLink), note, iTextStyle,
|
task->iLinkText, QString::fromStdString(task->iLink), note,
|
||||||
iSettings->invertColors());
|
iTextStyle, iSettings->invertColors()))->
|
||||||
iTaskQueue->submit(iFootnoteTask, this,
|
submit(this, SLOT(onFootnoteTaskDone()));
|
||||||
SLOT(onFootnoteTaskDone()));
|
|
||||||
} else {
|
} else {
|
||||||
HDEBUG("bad footnote" << QString(task->iLink.c_str()));
|
HDEBUG("bad footnote" << QString(task->iLink.c_str()));
|
||||||
}
|
}
|
||||||
|
@ -997,10 +1001,9 @@ void BooksPageWidget::onLongPressTaskDone()
|
||||||
task->iRect);
|
task->iRect);
|
||||||
} else if (!iData.isNull()) {
|
} else if (!iData.isNull()) {
|
||||||
if (iStartSelectionTask) iStartSelectionTask->release(this);
|
if (iStartSelectionTask) iStartSelectionTask->release(this);
|
||||||
iStartSelectionTask = new StartSelectionTask(iData,
|
(iStartSelectionTask = new StartSelectionTask(iTaskQueue->pool(), iData,
|
||||||
task->iX, task->iY, width(), height());
|
task->iX, task->iY, width(), height()))->
|
||||||
iTaskQueue->submit(iStartSelectionTask, this,
|
submit(this, SLOT(onStartSelectionTaskDone()));
|
||||||
SLOT(onStartSelectionTaskDone()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task->release(this);
|
task->release(this);
|
||||||
|
@ -1045,8 +1048,8 @@ void BooksPageWidget::handleLongPress(int aX, int aY)
|
||||||
HDEBUG(aX << aY);
|
HDEBUG(aX << aY);
|
||||||
if (!iResetTask && !iRenderTask && !iData.isNull()) {
|
if (!iResetTask && !iRenderTask && !iData.isNull()) {
|
||||||
if (iLongPressTask) iLongPressTask->release(this);
|
if (iLongPressTask) iLongPressTask->release(this);
|
||||||
iTaskQueue->submit(iLongPressTask = new PressTask(iData, aX, aY),
|
(iLongPressTask = new PressTask(iTaskQueue->pool(), iData, aX, aY))->
|
||||||
this, SLOT(onLongPressTaskDone()));
|
submit(this, SLOT(onLongPressTaskDone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1055,8 +1058,8 @@ void BooksPageWidget::handlePress(int aX, int aY)
|
||||||
HDEBUG(aX << aY);
|
HDEBUG(aX << aY);
|
||||||
if (!iResetTask && !iRenderTask && !iData.isNull()) {
|
if (!iResetTask && !iRenderTask && !iData.isNull()) {
|
||||||
if (iPressTask) iPressTask->release(this);
|
if (iPressTask) iPressTask->release(this);
|
||||||
iTaskQueue->submit(iPressTask = new PressTask(iData, aX, aY),
|
(iPressTask = new PressTask(iTaskQueue->pool(), iData, aX, aY))->
|
||||||
this, SLOT(onPressTaskDone()));
|
submit(this, SLOT(onPressTaskDone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1076,8 +1079,9 @@ void BooksPageWidget::handlePositionChanged(int aX, int aY)
|
||||||
HDEBUG("dropped queued task," << i << "left");
|
HDEBUG("dropped queued task," << i << "left");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
task = new ExtendSelectionTask(iData, aX, aY, width(), height());
|
(task = new ExtendSelectionTask(iTaskQueue->pool(), iData,
|
||||||
iTaskQueue->submit(task, this, SLOT(onExtendSelectionTaskDone()));
|
aX, aY, width(), height()))->
|
||||||
|
submit(this, SLOT(onExtendSelectionTaskDone()));
|
||||||
iExtendSelectionTasks.append(task);
|
iExtendSelectionTasks.append(task);
|
||||||
} else {
|
} else {
|
||||||
// Finger was moved before we entered selection mode
|
// Finger was moved before we entered selection mode
|
||||||
|
@ -1093,9 +1097,9 @@ void BooksPageWidget::clearSelection()
|
||||||
{
|
{
|
||||||
if (!iData.isNull()) {
|
if (!iData.isNull()) {
|
||||||
if (iClearSelectionTask) iClearSelectionTask->release(this);
|
if (iClearSelectionTask) iClearSelectionTask->release(this);
|
||||||
iTaskQueue->submit(iClearSelectionTask =
|
(iClearSelectionTask =new ClearSelectionTask(iTaskQueue->pool(),
|
||||||
new ClearSelectionTask(iData, width(), height()),
|
iData, width(), height()))->
|
||||||
this, SLOT(onClearSelectionTaskDone()));
|
submit(this, SLOT(onClearSelectionTaskDone()));
|
||||||
}
|
}
|
||||||
if (iSelecting) {
|
if (iSelecting) {
|
||||||
iSelecting = false;
|
iSelecting = false;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015-2017 Jolla Ltd.
|
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* You may use this file under the terms of the BSD license as follows:
|
||||||
*
|
*
|
||||||
|
@ -35,7 +35,6 @@
|
||||||
#define BOOKS_PAGE_WIDGET_H
|
#define BOOKS_PAGE_WIDGET_H
|
||||||
|
|
||||||
#include "BooksTypes.h"
|
#include "BooksTypes.h"
|
||||||
#include "BooksTask.h"
|
|
||||||
#include "BooksTaskQueue.h"
|
#include "BooksTaskQueue.h"
|
||||||
#include "BooksSettings.h"
|
#include "BooksSettings.h"
|
||||||
#include "BooksBookModel.h"
|
#include "BooksBookModel.h"
|
||||||
|
|
|
@ -36,8 +36,9 @@
|
||||||
#include "BooksBook.h"
|
#include "BooksBook.h"
|
||||||
#include "BooksUtil.h"
|
#include "BooksUtil.h"
|
||||||
|
|
||||||
#include "HarbourJson.h"
|
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
|
#include "HarbourJson.h"
|
||||||
|
#include "HarbourTask.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -56,12 +57,12 @@ enum BooksItemRole {
|
||||||
#define SHELF_STATE_FILE BOOKS_STATE_FILE_SUFFIX
|
#define SHELF_STATE_FILE BOOKS_STATE_FILE_SUFFIX
|
||||||
#define SHELF_STATE_ORDER "order"
|
#define SHELF_STATE_ORDER "order"
|
||||||
|
|
||||||
class BooksShelf::CopyTask : public BooksTask, BooksItem::CopyOperation
|
class BooksShelf::CopyTask : public HarbourTask, BooksItem::CopyOperation {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CopyTask(BooksShelf::Data* aDestData, BooksItem* aSrcItem);
|
CopyTask(QThreadPool* aPool, BooksShelf::Data* aDestData,
|
||||||
|
BooksItem* aSrcItem);
|
||||||
~CopyTask();
|
~CopyTask();
|
||||||
|
|
||||||
void performTask();
|
void performTask();
|
||||||
|
@ -89,10 +90,10 @@ public:
|
||||||
// BooksShelf::LoadTask
|
// BooksShelf::LoadTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksShelf::LoadTask : public BooksTask
|
class BooksShelf::LoadTask : public HarbourTask {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
LoadTask(BooksStorage aStorage, QString aRelPath, QString aStateFile) :
|
LoadTask(QThreadPool* aPool, BooksStorage aStorage, QString aRelPath,
|
||||||
|
QString aStateFile) : HarbourTask(aPool),
|
||||||
iStorage(aStorage), iRelativePath(aRelPath),
|
iStorage(aStorage), iRelativePath(aRelPath),
|
||||||
iStateFilePath(aStateFile) {}
|
iStateFilePath(aStateFile) {}
|
||||||
~LoadTask();
|
~LoadTask();
|
||||||
|
@ -322,7 +323,9 @@ inline bool BooksShelf::Data::copyingOut()
|
||||||
// BooksShelf::CopyTask
|
// BooksShelf::CopyTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
BooksShelf::CopyTask::CopyTask(BooksShelf::Data* aDestData, BooksItem* aSrcItem) :
|
BooksShelf::CopyTask::CopyTask(QThreadPool* aPool, BooksShelf::Data* aDestData,
|
||||||
|
BooksItem* aSrcItem) :
|
||||||
|
HarbourTask(aPool),
|
||||||
iDestData(aDestData),
|
iDestData(aDestData),
|
||||||
iDestStorage(aDestData->iShelf->storage()),
|
iDestStorage(aDestData->iShelf->storage()),
|
||||||
iDestRelPath(aDestData->iShelf->relativePath()),
|
iDestRelPath(aDestData->iShelf->relativePath()),
|
||||||
|
@ -365,7 +368,7 @@ void BooksShelf::CopyTask::performTask()
|
||||||
|
|
||||||
bool BooksShelf::CopyTask::isCanceled() const
|
bool BooksShelf::CopyTask::isCanceled() const
|
||||||
{
|
{
|
||||||
return BooksTask::isCanceled();
|
return HarbourTask::isCanceled();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BooksShelf::CopyTask::copyProgressChanged(int aProgress)
|
void BooksShelf::CopyTask::copyProgressChanged(int aProgress)
|
||||||
|
@ -378,11 +381,10 @@ void BooksShelf::CopyTask::copyProgressChanged(int aProgress)
|
||||||
// BooksShelf::DeleteTask
|
// BooksShelf::DeleteTask
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
class BooksShelf::DeleteTask : public BooksTask
|
class BooksShelf::DeleteTask : public HarbourTask {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DeleteTask(BooksItem* aItem);
|
DeleteTask(QThreadPool* aPool, BooksItem* aItem);
|
||||||
~DeleteTask();
|
~DeleteTask();
|
||||||
void performTask();
|
void performTask();
|
||||||
|
|
||||||
|
@ -390,7 +392,8 @@ public:
|
||||||
BooksItem* iItem;
|
BooksItem* iItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
BooksShelf::DeleteTask::DeleteTask(BooksItem* aItem) :
|
BooksShelf::DeleteTask::DeleteTask(QThreadPool* aPool, BooksItem* aItem) :
|
||||||
|
HarbourTask(aPool),
|
||||||
iItem(aItem)
|
iItem(aItem)
|
||||||
{
|
{
|
||||||
iItem->retain();
|
iItem->retain();
|
||||||
|
@ -695,9 +698,8 @@ void BooksShelf::loadBookList()
|
||||||
iLoadTask = NULL;
|
iLoadTask = NULL;
|
||||||
} else {
|
} else {
|
||||||
HDEBUG(iPath);
|
HDEBUG(iPath);
|
||||||
iLoadTask = new LoadTask(iStorage, iRelativePath, stateFileName());
|
(iLoadTask = new LoadTask(iTaskQueue->pool(), iStorage, iRelativePath,
|
||||||
connect(iLoadTask, SIGNAL(done()), SLOT(onLoadTaskDone()));
|
stateFileName()))->submit(this, SLOT(onLoadTaskDone()));
|
||||||
iTaskQueue->submit(iLoadTask);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -912,7 +914,7 @@ bool BooksShelf::drop(QObject* aItem)
|
||||||
// Don't connect signals since it's not our item
|
// Don't connect signals since it's not our item
|
||||||
data->setBook(book, true);
|
data->setBook(book, true);
|
||||||
// Start copying the data
|
// Start copying the data
|
||||||
iTaskQueue->submit(new CopyTask(data, book));
|
(new CopyTask(iTaskQueue->pool(), data, book))->submit();
|
||||||
Q_EMIT hasDummyItemChanged();
|
Q_EMIT hasDummyItemChanged();
|
||||||
Q_EMIT dummyItemIndexChanged();
|
Q_EMIT dummyItemIndexChanged();
|
||||||
Q_EMIT dataChanged(index, index);
|
Q_EMIT dataChanged(index, index);
|
||||||
|
@ -944,9 +946,9 @@ void BooksShelf::submitDeleteTask(int aIndex)
|
||||||
{
|
{
|
||||||
BooksItem* item = iList.at(aIndex)->iItem;
|
BooksItem* item = iList.at(aIndex)->iItem;
|
||||||
if (item) {
|
if (item) {
|
||||||
DeleteTask* task = new DeleteTask(item);
|
DeleteTask* task = new DeleteTask(iTaskQueue->pool(), item);
|
||||||
iDeleteTasks.append(task);
|
iDeleteTasks.append(task);
|
||||||
iTaskQueue->submit(task);
|
task->submit();
|
||||||
BooksBook* book = item->book();
|
BooksBook* book = item->book();
|
||||||
if (book) {
|
if (book) {
|
||||||
book->cancelCoverRequest();
|
book->cancelCoverRequest();
|
||||||
|
@ -1045,7 +1047,7 @@ void BooksShelf::importBook(QObject* aBook)
|
||||||
Counts counts(this);
|
Counts counts(this);
|
||||||
Data* data = new Data(this, book->retain(), true);
|
Data* data = new Data(this, book->retain(), true);
|
||||||
iList.insert(0, data);
|
iList.insert(0, data);
|
||||||
iTaskQueue->submit(new CopyTask(data, book));
|
(new CopyTask(iTaskQueue->pool(), data, book))->submit();
|
||||||
counts.emitSignals(this);
|
counts.emitSignals(this);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
saveState();
|
saveState();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015-2016 Jolla Ltd.
|
* Copyright (C) 2015-2018 Jolla Ltd.
|
||||||
* Contact: Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* You may use this file under the terms of the BSD license as follows:
|
||||||
*
|
*
|
||||||
|
@ -37,7 +37,6 @@
|
||||||
#include "BooksItem.h"
|
#include "BooksItem.h"
|
||||||
#include "BooksStorage.h"
|
#include "BooksStorage.h"
|
||||||
#include "BooksSaveTimer.h"
|
#include "BooksSaveTimer.h"
|
||||||
#include "BooksTask.h"
|
|
||||||
#include "BooksTaskQueue.h"
|
#include "BooksTaskQueue.h"
|
||||||
#include "BooksLoadingProperty.h"
|
#include "BooksLoadingProperty.h"
|
||||||
|
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2015-2018 Jolla Ltd.
|
|
||||||
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
|
||||||
*
|
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in
|
|
||||||
* the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
* * Neither the name of Jolla Ltd nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "BooksTask.h"
|
|
||||||
#include "BooksTaskQueue.h"
|
|
||||||
|
|
||||||
#include "HarbourDebug.h"
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
BooksTask::BooksTask(QThread* aThread) :
|
|
||||||
iAboutToQuit(false),
|
|
||||||
iSubmitted(false),
|
|
||||||
iStarted(false),
|
|
||||||
iReleased(false),
|
|
||||||
iDone(false)
|
|
||||||
{
|
|
||||||
setAutoDelete(false);
|
|
||||||
if (aThread) moveToThread(aThread);
|
|
||||||
connect(qApp, SIGNAL(aboutToQuit()), SLOT(onAboutToQuit()));
|
|
||||||
connect(this, SIGNAL(runFinished()), SLOT(onRunFinished()),
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
BooksTask::~BooksTask()
|
|
||||||
{
|
|
||||||
HASSERT(iReleased);
|
|
||||||
if (iSubmitted) wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BooksTask::release(QObject* aHandler)
|
|
||||||
{
|
|
||||||
disconnect(aHandler);
|
|
||||||
iReleased = true;
|
|
||||||
if (!iSubmitted || iDone) {
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BooksTask::run()
|
|
||||||
{
|
|
||||||
HASSERT(!iStarted);
|
|
||||||
iStarted = true;
|
|
||||||
performTask();
|
|
||||||
Q_EMIT runFinished();
|
|
||||||
}
|
|
||||||
|
|
||||||
void BooksTask::onRunFinished()
|
|
||||||
{
|
|
||||||
HASSERT(!iDone);
|
|
||||||
if (!iReleased) {
|
|
||||||
Q_EMIT done();
|
|
||||||
}
|
|
||||||
iDone = true;
|
|
||||||
if (iReleased) {
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BooksTask::onAboutToQuit()
|
|
||||||
{
|
|
||||||
HDEBUG("OK");
|
|
||||||
iAboutToQuit = true;
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2015-2018 Jolla Ltd.
|
|
||||||
* Copyright (C) 2015-2018 Slava Monich <slava.monich@jolla.com>
|
|
||||||
*
|
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in
|
|
||||||
* the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
* * Neither the name of Jolla Ltd nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this
|
|
||||||
* software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BOOKS_TASK_H
|
|
||||||
#define BOOKS_TASK_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QRunnable>
|
|
||||||
|
|
||||||
class BooksTaskQueue;
|
|
||||||
|
|
||||||
class BooksTask : public QObject, public QRunnable
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
friend class BooksTaskQueue;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
BooksTask(QThread* aThread = NULL);
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual ~BooksTask();
|
|
||||||
|
|
||||||
bool isStarted() const;
|
|
||||||
bool isCanceled() const;
|
|
||||||
void release(QObject* aHandler);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void run();
|
|
||||||
virtual void performTask() = 0;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void runFinished();
|
|
||||||
void done();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void onAboutToQuit();
|
|
||||||
void onRunFinished();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool iAboutToQuit;
|
|
||||||
bool iSubmitted;
|
|
||||||
bool iStarted;
|
|
||||||
bool iReleased;
|
|
||||||
bool iDone;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool BooksTask::isStarted() const
|
|
||||||
{ return iStarted; }
|
|
||||||
inline bool BooksTask::isCanceled() const
|
|
||||||
{ return iReleased || iAboutToQuit; }
|
|
||||||
|
|
||||||
#endif // BOOKS_TASK_H
|
|
|
@ -32,7 +32,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BooksTaskQueue.h"
|
#include "BooksTaskQueue.h"
|
||||||
#include "BooksTask.h"
|
|
||||||
|
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
|
|
||||||
|
@ -109,17 +108,3 @@ BooksTaskQueue::~BooksTaskQueue()
|
||||||
delete iPool;
|
delete iPool;
|
||||||
HDEBUG("deleted");
|
HDEBUG("deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BooksTaskQueue::submit(BooksTask* aTask)
|
|
||||||
{
|
|
||||||
HASSERT(!aTask->iSubmitted);
|
|
||||||
aTask->iSubmitted = true;
|
|
||||||
iPool->start(aTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BooksTaskQueue::submit(BooksTask* aTask, QObject* aTarget,
|
|
||||||
const char* aSlot)
|
|
||||||
{
|
|
||||||
QObject::connect(aTask, SIGNAL(done()), aTarget, aSlot);
|
|
||||||
submit(aTask);
|
|
||||||
}
|
|
||||||
|
|
|
@ -50,8 +50,7 @@ public:
|
||||||
static shared_ptr<BooksTaskQueue> hashQueue();
|
static shared_ptr<BooksTaskQueue> hashQueue();
|
||||||
static void waitForDone(int aMsecs = -1);
|
static void waitForDone(int aMsecs = -1);
|
||||||
|
|
||||||
void submit(BooksTask* aTask);
|
QThreadPool* pool() const;
|
||||||
void submit(BooksTask* aTask, QObject* aTarget, const char* aSlot);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BooksTaskQueue(int aMaxThreadCount);
|
BooksTaskQueue(int aMaxThreadCount);
|
||||||
|
@ -63,4 +62,7 @@ private:
|
||||||
QThreadPool* iPool;
|
QThreadPool* iPool;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline QThreadPool* BooksTaskQueue::pool() const
|
||||||
|
{ return iPool; }
|
||||||
|
|
||||||
#endif // BOOKS_TASK_QUEUE_H
|
#endif // BOOKS_TASK_QUEUE_H
|
||||||
|
|
|
@ -33,8 +33,9 @@
|
||||||
|
|
||||||
#include "BooksUtil.h"
|
#include "BooksUtil.h"
|
||||||
#include "BooksDefs.h"
|
#include "BooksDefs.h"
|
||||||
#include "BooksTask.h"
|
|
||||||
#include "HarbourDebug.h"
|
#include "HarbourDebug.h"
|
||||||
|
#include "HarbourTask.h"
|
||||||
|
|
||||||
#include "ZLDir.h"
|
#include "ZLDir.h"
|
||||||
#include "formats/FormatPlugin.h"
|
#include "formats/FormatPlugin.h"
|
||||||
|
@ -90,7 +91,7 @@ shared_ptr<Book> BooksUtil::bookFromFile(std::string aPath)
|
||||||
return book;
|
return book;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray BooksUtil::computeFileHash(QString aPath, const BooksTask* aTask)
|
QByteArray BooksUtil::computeFileHash(QString aPath, const HarbourTask* aTask)
|
||||||
{
|
{
|
||||||
QByteArray result;
|
QByteArray result;
|
||||||
QFile file(aPath);
|
QFile file(aPath);
|
||||||
|
@ -157,7 +158,7 @@ bool BooksUtil::setFileHashAttr(QString aPath, QByteArray aHash)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray BooksUtil::computeFileHashAndSetAttr(QString aPath, const BooksTask* aTask)
|
QByteArray BooksUtil::computeFileHashAndSetAttr(QString aPath, const HarbourTask* aTask)
|
||||||
{
|
{
|
||||||
QByteArray hash = computeFileHash(aPath, aTask);
|
QByteArray hash = computeFileHash(aPath, aTask);
|
||||||
if (!hash.isEmpty()) {
|
if (!hash.isEmpty()) {
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class BooksTask;
|
class HarbourTask;
|
||||||
|
|
||||||
namespace BooksUtil {
|
namespace BooksUtil {
|
||||||
shared_ptr<Book> bookFromFile(std::string aPath);
|
shared_ptr<Book> bookFromFile(std::string aPath);
|
||||||
|
@ -48,8 +48,8 @@ namespace BooksUtil {
|
||||||
bool isValidFileName(QString aName);
|
bool isValidFileName(QString aName);
|
||||||
QByteArray fileHashAttr(QString aPath);
|
QByteArray fileHashAttr(QString aPath);
|
||||||
bool setFileHashAttr(QString aPath, QByteArray aHash);
|
bool setFileHashAttr(QString aPath, QByteArray aHash);
|
||||||
QByteArray computeFileHash(QString aPath, const BooksTask* aTask = NULL);
|
QByteArray computeFileHash(QString aPath, const HarbourTask* aTask = NULL);
|
||||||
QByteArray computeFileHashAndSetAttr(QString aPath, const BooksTask* aTask = NULL);
|
QByteArray computeFileHashAndSetAttr(QString aPath, const HarbourTask* aTask = NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline shared_ptr<Book> BooksUtil::bookFromFile(QString aPath)
|
inline shared_ptr<Book> BooksUtil::bookFromFile(QString aPath)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9f91b79f34f75ca099c09819dc57d099b909c705
|
Subproject commit c8d907a11a3512672ed906fa2c3b41a65c9a9bd2
|
Loading…
Reference in a new issue