[app] Dropped BooksTask in favor of HarbourTask

This commit is contained in:
Slava Monich 2018-05-16 18:27:12 +03:00
parent b78201060b
commit 57801ed140
18 changed files with 152 additions and 337 deletions

View file

@ -123,7 +123,6 @@ SOURCES += \
src/BooksShelf.cpp \
src/BooksStorage.cpp \
src/BooksStorageModel.cpp \
src/BooksTask.cpp \
src/BooksTextStyle.cpp \
src/BooksTaskQueue.cpp \
src/BooksTextView.cpp \
@ -169,7 +168,6 @@ HEADERS += \
src/BooksShelf.h \
src/BooksStorage.h \
src/BooksStorageModel.h \
src/BooksTask.h \
src/BooksTaskQueue.h \
src/BooksTextView.h \
src/BooksTextStyle.h \

View file

@ -33,7 +33,6 @@
#include "BooksBook.h"
#include "BooksDefs.h"
#include "BooksTask.h"
#include "BooksTextView.h"
#include "BooksTextStyle.h"
#include "BooksPaintContext.h"
@ -42,6 +41,7 @@
#include "HarbourJson.h"
#include "HarbourDebug.h"
#include "HarbourTask.h"
#include "ZLImage.h"
#include "image/ZLQtImageManager.h"
@ -135,10 +135,11 @@ bool BooksBook::CoverPaintContext::gotIt() const
// BooksBook::CoverTask
// ==========================================================================
class BooksBook::CoverTask : public BooksTask
class BooksBook::CoverTask : public HarbourTask
{
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),
iCoverMissing(false) {}
@ -164,9 +165,10 @@ inline bool BooksBook::CoverTask::hasImage() const
class BooksBook::LoadCoverTask : public BooksBook::CoverTask
{
public:
LoadCoverTask(QString aStateDir, shared_ptr<Book> aBook,
shared_ptr<FormatPlugin> aFormatPlugin, QString aImagePath) :
BooksBook::CoverTask(aStateDir, aBook, aImagePath),
LoadCoverTask(QThreadPool* aPool, QString aStateDir,
shared_ptr<Book> aBook, shared_ptr<FormatPlugin> aFormatPlugin,
QString aImagePath) :
BooksBook::CoverTask(aPool, aStateDir, aBook, aImagePath),
iFormatPlugin(aFormatPlugin) {}
virtual void performTask();
@ -231,8 +233,9 @@ void BooksBook::LoadCoverTask::performTask()
class BooksBook::GuessCoverTask : public BooksBook::CoverTask
{
public:
GuessCoverTask(QString aStateDir, shared_ptr<Book> aBook, QString aImagePath) :
BooksBook::CoverTask(aStateDir, aBook, aImagePath) {}
GuessCoverTask(QThreadPool* aPool, QString aStateDir,
shared_ptr<Book> aBook, QString aImagePath) :
BooksBook::CoverTask(aPool, aStateDir, aBook, aImagePath) {}
virtual void performTask();
};
@ -294,10 +297,10 @@ void BooksBook::GuessCoverTask::performTask()
// BooksBook::HashTask
// ==========================================================================
class BooksBook::HashTask : public BooksTask
class BooksBook::HashTask : public HarbourTask
{
public:
HashTask(QString aPath, QThread* aThread);
HashTask(QThreadPool* aPool, QString aPath);
virtual void performTask();
@ -306,8 +309,8 @@ public:
QByteArray iHash;
};
BooksBook::HashTask::HashTask(QString aPath, QThread* aThread) :
BooksTask(aThread), iPath(aPath)
BooksBook::HashTask::HashTask(QThreadPool* aPool, QString aPath) :
HarbourTask(aPool), iPath(aPath)
{
}
@ -387,9 +390,9 @@ BooksBook::BooksBook(const BooksStorage& aStorage, QString aRelativePath,
if (iHash.isEmpty()) {
HDEBUG("need to calculate hash for" << qPrintable(iPath));
iHashTaskQueue = BooksTaskQueue::hashQueue();
iHashTask = new HashTask(iPath, thread());
connect(iHashTask, SIGNAL(done()), SLOT(onHashTaskDone()));
iHashTaskQueue->submit(iHashTask);
iHashTask = new HashTask(iHashTaskQueue->pool(), iPath);
iHashTask->moveToThread(thread());
iHashTask->submit(this, SLOT(onHashTaskDone()));
}
// Refcounted BooksBook objects are managed by C++ code
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
@ -543,10 +546,9 @@ bool BooksBook::requestCoverImage()
if (!iBook.isNull() && !iFormatPlugin.isNull() &&
!iCoverTasksDone && !iCoverTask) {
HDEBUG(iTitle);
iCoverTask = new LoadCoverTask(iStateDir, iBook, iFormatPlugin,
cachedImagePath());
connect(iCoverTask, SIGNAL(done()), SLOT(onLoadCoverTaskDone()));
iTaskQueue->submit(iCoverTask);
(iCoverTask = new LoadCoverTask(iTaskQueue->pool(), iStateDir, iBook,
iFormatPlugin, cachedImagePath()))->submit(this,
SLOT(onLoadCoverTaskDone()));
Q_EMIT loadingCoverChanged();
}
return iCoverTask != NULL;
@ -583,9 +585,9 @@ void BooksBook::onLoadCoverTaskDone()
iCoverTasksDone = true;
Q_EMIT loadingCoverChanged();
} else {
iCoverTask = new GuessCoverTask(iStateDir, iBook, cachedImagePath());
connect(iCoverTask, SIGNAL(done()), SLOT(onGuessCoverTaskDone()));
iTaskQueue->submit(iCoverTask);
(iCoverTask = new GuessCoverTask(iTaskQueue->pool(), iStateDir,
iBook, cachedImagePath()))->submit(this,
SLOT(onGuessCoverTaskDone()));
}
}

View file

@ -36,6 +36,7 @@
#include "BooksUtil.h"
#include "HarbourDebug.h"
#include "HarbourTask.h"
#include "ZLTextHyphenator.h"
@ -59,7 +60,7 @@ public:
// BooksBookModel::PagingTask
// ==========================================================================
class BooksBookModel::PagingTask : public BooksTask
class BooksBookModel::PagingTask : public HarbourTask
{
Q_OBJECT
@ -78,7 +79,8 @@ public:
quint32 count;
} __attribute__((packed));
PagingTask(BooksBookModel* aModel, shared_ptr<Book> aBook);
PagingTask(QThreadPool* aPool, BooksBookModel* aModel,
shared_ptr<Book> aBook);
~PagingTask();
void performTask();
@ -104,8 +106,9 @@ public:
const char BooksBookModel::PagingTask::MarksFileMagic[] = "MARK";
BooksBookModel::PagingTask::PagingTask(BooksBookModel* aModel,
shared_ptr<Book> aBook) :
BooksBookModel::PagingTask::PagingTask(QThreadPool* aPool,
BooksBookModel* aModel, shared_ptr<Book> aBook) :
HarbourTask(aPool),
iBook(aBook),
iTextStyle(aModel->textStyle()),
iPaint(aModel->width(), aModel->height()),
@ -621,8 +624,8 @@ void BooksBookModel::startReset(ResetReason aResetReason, bool aFullReset)
if (iBook && width() > 0 && height() > 0) {
HDEBUG("starting" << qPrintable(QString("%1x%2").arg(width()).
arg(height())) << "paging");
iPagingTask = new PagingTask(this, iBook->bookRef());
iTaskQueue->submit(iPagingTask);
(iPagingTask = new PagingTask(iTaskQueue->pool(), this,
iBook->bookRef()))->submit();
}
if (oldPageCount > 0) {

View file

@ -35,7 +35,6 @@
#define BOOKS_BOOK_MODEL_H
#include "BooksBook.h"
#include "BooksTask.h"
#include "BooksTaskQueue.h"
#include "BooksTextView.h"
#include "BooksSettings.h"

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* 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:
*
@ -34,6 +34,7 @@
#include "BooksCoverWidget.h"
#include "HarbourDebug.h"
#include "HarbourTask.h"
#include "ZLibrary.h"
@ -43,10 +44,11 @@
// BooksCoverWidget::ScaleTask
// ==========================================================================
class BooksCoverWidget::ScaleTask : public BooksTask
class BooksCoverWidget::ScaleTask : public HarbourTask
{
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);
void performTask();
@ -58,12 +60,9 @@ public:
bool iStretch;
};
BooksCoverWidget::ScaleTask::ScaleTask(QImage aImage, int aWidth, int aHeight,
bool aStretch) :
iImage(aImage),
iWidth(aWidth),
iHeight(aHeight),
iStretch(aStretch)
BooksCoverWidget::ScaleTask::ScaleTask(QThreadPool* aPool, QImage aImage,
int aWidth, int aHeight, bool aStretch) : HarbourTask(aPool),
iImage(aImage), iWidth(aWidth), iHeight(aHeight), iStretch(aStretch)
{
}
@ -367,9 +366,8 @@ void BooksCoverWidget::scaleImage(bool aWasEmpty)
iScaledImage = ScaleTask::scale(iCoverImage, w, h, iStretch);
update();
} else {
iScaleTask = new ScaleTask(iCoverImage, w, h, iStretch);
connect(iScaleTask, SIGNAL(done()), SLOT(onScaleTaskDone()));
iTaskQueue->submit(iScaleTask);
(iScaleTask = new ScaleTask(iTaskQueue->pool(), iCoverImage, w, h,
iStretch))->submit(this, SLOT(onScaleTaskDone()));
}
} else {
iScaledImage = QImage();

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* 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:
*
@ -35,7 +35,6 @@
#define BOOKS_COVER_WIDGET_H
#include "BooksTypes.h"
#include "BooksTask.h"
#include "BooksTaskQueue.h"
#include "BooksBook.h"

View file

@ -33,10 +33,10 @@
#include "BooksImportModel.h"
#include "BooksStorage.h"
#include "BooksTask.h"
#include "BooksUtil.h"
#include "HarbourDebug.h"
#include "HarbourTask.h"
#include <QDir>
@ -82,12 +82,11 @@ BooksImportModel::Data::~Data()
// BooksImportModel::Task
// ==========================================================================
class BooksImportModel::Task : public BooksTask
{
class BooksImportModel::Task : public HarbourTask {
Q_OBJECT
public:
Task(QString aDest);
Task(QThreadPool* aPool, QString aDest);
~Task();
void performTask();
@ -111,7 +110,8 @@ public:
int iProgress;
};
BooksImportModel::Task::Task(QString aDest) :
BooksImportModel::Task::Task(QThreadPool* aPool, QString aDest) :
HarbourTask(aPool),
iDestDir(aDest), iBufSize(0x1000), iBuf(NULL), iProgress(0)
{
}
@ -283,13 +283,13 @@ void BooksImportModel::refresh()
Q_EMIT progressChanged();
}
iTask = new Task(iDestination);
iTask = new Task(iTaskQueue->pool(), iDestination);
connect(iTask, SIGNAL(bookFound(BooksBook*)),
SLOT(onBookFound(BooksBook*)), Qt::QueuedConnection);
connect(iTask, SIGNAL(done()), SLOT(onTaskDone()));
connect(iTask, SIGNAL(progress(int)), SLOT(onScanProgress(int)),
Qt::QueuedConnection);
iTaskQueue->submit(iTask);
iTask->submit();
Q_EMIT busyChanged();
}
}

View file

@ -1,6 +1,6 @@
/*
* 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:
*
@ -41,6 +41,7 @@
#include "ZLStringUtil.h"
#include "HarbourDebug.h"
#include "HarbourTask.h"
#include <QGuiApplication>
#include <QClipboard>
@ -54,6 +55,8 @@ static const QString IMAGE_URL("image://%1/%2");
class BooksPageWidget::Data {
public:
typedef shared_ptr<Data> Ptr;
Data(shared_ptr<ZLTextModel> aModel, int aWidth, int aHeight) :
iModel(aModel), iPaintContext(aWidth, aHeight) {}
@ -80,10 +83,9 @@ bool BooksPageWidget::Data::paint(QPainter* aPainter)
// BooksPageWidget::ResetTask
// ==========================================================================
class BooksPageWidget::ResetTask : public BooksTask
{
class BooksPageWidget::ResetTask : public HarbourTask {
public:
ResetTask(shared_ptr<ZLTextModel> aModel,
ResetTask(QThreadPool* aPool, shared_ptr<ZLTextModel> aModel,
shared_ptr<ZLTextStyle> aTextStyle, int aWidth, int aHeight,
const BooksMargins& aMargins, const BooksPos& aPosition);
~ResetTask();
@ -97,9 +99,10 @@ public:
BooksPos iPosition;
};
BooksPageWidget::ResetTask::ResetTask(shared_ptr<ZLTextModel> aModel,
shared_ptr<ZLTextStyle> aTextStyle, int aWidth, int aHeight,
const BooksMargins& aMargins, const BooksPos& aPosition) :
BooksPageWidget::ResetTask::ResetTask(QThreadPool* aPool,
shared_ptr<ZLTextModel> aModel, shared_ptr<ZLTextStyle> aTextStyle,
int aWidth, int aHeight, const BooksMargins& aMargins,
const BooksPos& aPosition) : HarbourTask(aPool),
iData(new BooksPageWidget::Data(aModel, aWidth, aHeight)),
iTextStyle(aTextStyle),
iMargins(aMargins),
@ -135,15 +138,16 @@ void BooksPageWidget::ResetTask::performTask()
// BooksPageWidget::RenderTask
// ==========================================================================
class BooksPageWidget::RenderTask : public BooksTask {
class BooksPageWidget::RenderTask : public HarbourTask {
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) {}
void performTask();
public:
shared_ptr<BooksPageWidget::Data> iData;
Data::Ptr iData;
int iWidth;
int iHeight;
QImage iImage;
@ -165,16 +169,16 @@ void BooksPageWidget::RenderTask::performTask()
// BooksPageWidget::ClearSelectionTask
// ==========================================================================
class BooksPageWidget::ClearSelectionTask : public BooksTask {
class BooksPageWidget::ClearSelectionTask : public HarbourTask {
public:
ClearSelectionTask(shared_ptr<BooksPageWidget::Data> aData, int aWidth,
int aHeight) : iData(aData), iWidth(aWidth), iHeight(aHeight),
iImageUpdated(false) {}
ClearSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aWidth,
int aHeight) : HarbourTask(aPool),
iData(aData), iWidth(aWidth), iHeight(aHeight), iImageUpdated(false) {}
void performTask();
public:
shared_ptr<BooksPageWidget::Data> iData;
Data::Ptr iData;
int iWidth;
int iHeight;
QImage iImage;
@ -202,16 +206,17 @@ void BooksPageWidget::ClearSelectionTask::performTask()
// BooksPageWidget::StartSelectionTask
// ==========================================================================
class BooksPageWidget::StartSelectionTask : public BooksTask {
class BooksPageWidget::StartSelectionTask : public HarbourTask {
public:
StartSelectionTask(shared_ptr<BooksPageWidget::Data> aData, int aX, int aY,
int aWidth, int aHeight) : iData(aData), iX(aX), iY(aY),
iWidth(aWidth), iHeight(aHeight), iSelectionEmpty(true) {}
StartSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY,
int aWidth, int aHeight) : HarbourTask(aPool),
iData(aData), iX(aX), iY(aY), iWidth(aWidth), iHeight(aHeight),
iSelectionEmpty(true) {}
void performTask();
public:
shared_ptr<BooksPageWidget::Data> iData;
Data::Ptr iData;
int iX;
int iY;
int iWidth;
@ -239,17 +244,17 @@ void BooksPageWidget::StartSelectionTask::performTask()
// BooksPageWidget::ExtendSelectionTask
// ==========================================================================
class BooksPageWidget::ExtendSelectionTask : public BooksTask {
class BooksPageWidget::ExtendSelectionTask : public HarbourTask {
public:
ExtendSelectionTask(shared_ptr<BooksPageWidget::Data> aData, int aX, int aY,
int aWidth, int aHeight) : iData(aData), iX(aX), iY(aY),
iWidth(aWidth), iHeight(aHeight), iSelectionChanged(false),
iSelectionEmpty(true) {}
ExtendSelectionTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY,
int aWidth, int aHeight) : HarbourTask(aPool),
iData(aData), iX(aX), iY(aY), iWidth(aWidth), iHeight(aHeight),
iSelectionChanged(false), iSelectionEmpty(true) {}
void performTask();
public:
shared_ptr<BooksPageWidget::Data> iData;
Data::Ptr iData;
int iX;
int iY;
int iWidth;
@ -278,12 +283,12 @@ void BooksPageWidget::ExtendSelectionTask::performTask()
// BooksPageWidget::FootnoteTask
// ==========================================================================
class BooksPageWidget::FootnoteTask : public BooksTask, ZLTextArea::Properties {
class BooksPageWidget::FootnoteTask : public HarbourTask, ZLTextArea::Properties {
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,
shared_ptr<ZLTextModel> aTextModel, shared_ptr<ZLTextStyle> aTextStyle,
bool aInvertColors) :
bool aInvertColors) : HarbourTask(aPool),
iTextModel(aTextModel), iTextStyle(aTextStyle),
iInvertColors(aInvertColors), iX(aX), iY(aY),
iMaxWidth(aMaxWidth), iMaxHeight(aMaxHeight),
@ -367,16 +372,16 @@ void BooksPageWidget::FootnoteTask::performTask()
// BooksPageWidget::PressTask
// ==========================================================================
class BooksPageWidget::PressTask : public BooksTask {
class BooksPageWidget::PressTask : public HarbourTask {
public:
PressTask(shared_ptr<BooksPageWidget::Data> aData, int aX, int aY) :
iData(aData), iX(aX), iY(aY), iKind(REGULAR) {}
PressTask(QThreadPool* aPool, Data::Ptr aData, int aX, int aY) :
HarbourTask(aPool), iData(aData), iX(aX), iY(aY), iKind(REGULAR) {}
void performTask();
QString getLinkText(ZLTextWordCursor& aCursor);
public:
shared_ptr<BooksPageWidget::Data> iData;
Data::Ptr iData;
int iX;
int iY;
QRect iRect;
@ -765,9 +770,9 @@ void BooksPageWidget::resetView()
width() > 0 && height() > 0 && iModel) {
shared_ptr<ZLTextModel> textModel = iModel->bookTextModel();
if (!textModel.isNull()) {
iResetTask = new ResetTask(textModel, iTextStyle,
width(), height(), iMargins, iPageMark);
iTaskQueue->submit(iResetTask, this, SLOT(onResetTaskDone()));
(iResetTask = new ResetTask(iTaskQueue->pool(), textModel, iTextStyle,
width(), height(), iMargins, iPageMark))->
submit(this, SLOT(onResetTaskDone()));
cancelRepaint();
}
}
@ -793,8 +798,8 @@ void BooksPageWidget::scheduleRepaint()
const int h = height();
if (w > 0 && h > 0 && !iData.isNull() && !iData->iView.isNull()) {
iData->iView->setInvertColors(invertColors());
iRenderTask = new RenderTask(iData, w, h);
iTaskQueue->submit(iRenderTask, this, SLOT(onRenderTaskDone()));
(iRenderTask = new RenderTask(iTaskQueue->pool(), iData, w, h))->
submit(this, SLOT(onRenderTaskDone()));
} else {
update();
}
@ -962,12 +967,11 @@ void BooksPageWidget::onLongPressTaskDone()
// Render the footnote
HDEBUG("footnote" << QString(task->iLink.c_str()));
if (iFootnoteTask) iFootnoteTask->release(this);
iFootnoteTask = new FootnoteTask(task->iX, task->iY,
width()*3/4, height()*10, book->path(), task->iLinkText,
QString::fromStdString(task->iLink), note, iTextStyle,
iSettings->invertColors());
iTaskQueue->submit(iFootnoteTask, this,
SLOT(onFootnoteTaskDone()));
(iFootnoteTask = new FootnoteTask(iTaskQueue->pool(),
task->iX, task->iY, width()*3/4, height()*10, book->path(),
task->iLinkText, QString::fromStdString(task->iLink), note,
iTextStyle, iSettings->invertColors()))->
submit(this, SLOT(onFootnoteTaskDone()));
} else {
HDEBUG("bad footnote" << QString(task->iLink.c_str()));
}
@ -997,10 +1001,9 @@ void BooksPageWidget::onLongPressTaskDone()
task->iRect);
} else if (!iData.isNull()) {
if (iStartSelectionTask) iStartSelectionTask->release(this);
iStartSelectionTask = new StartSelectionTask(iData,
task->iX, task->iY, width(), height());
iTaskQueue->submit(iStartSelectionTask, this,
SLOT(onStartSelectionTaskDone()));
(iStartSelectionTask = new StartSelectionTask(iTaskQueue->pool(), iData,
task->iX, task->iY, width(), height()))->
submit(this, SLOT(onStartSelectionTaskDone()));
}
task->release(this);
@ -1045,8 +1048,8 @@ void BooksPageWidget::handleLongPress(int aX, int aY)
HDEBUG(aX << aY);
if (!iResetTask && !iRenderTask && !iData.isNull()) {
if (iLongPressTask) iLongPressTask->release(this);
iTaskQueue->submit(iLongPressTask = new PressTask(iData, aX, aY),
this, SLOT(onLongPressTaskDone()));
(iLongPressTask = new PressTask(iTaskQueue->pool(), iData, aX, aY))->
submit(this, SLOT(onLongPressTaskDone()));
}
}
@ -1055,8 +1058,8 @@ void BooksPageWidget::handlePress(int aX, int aY)
HDEBUG(aX << aY);
if (!iResetTask && !iRenderTask && !iData.isNull()) {
if (iPressTask) iPressTask->release(this);
iTaskQueue->submit(iPressTask = new PressTask(iData, aX, aY),
this, SLOT(onPressTaskDone()));
(iPressTask = new PressTask(iTaskQueue->pool(), iData, aX, aY))->
submit(this, SLOT(onPressTaskDone()));
}
}
@ -1076,8 +1079,9 @@ void BooksPageWidget::handlePositionChanged(int aX, int aY)
HDEBUG("dropped queued task," << i << "left");
}
}
task = new ExtendSelectionTask(iData, aX, aY, width(), height());
iTaskQueue->submit(task, this, SLOT(onExtendSelectionTaskDone()));
(task = new ExtendSelectionTask(iTaskQueue->pool(), iData,
aX, aY, width(), height()))->
submit(this, SLOT(onExtendSelectionTaskDone()));
iExtendSelectionTasks.append(task);
} else {
// Finger was moved before we entered selection mode
@ -1093,9 +1097,9 @@ void BooksPageWidget::clearSelection()
{
if (!iData.isNull()) {
if (iClearSelectionTask) iClearSelectionTask->release(this);
iTaskQueue->submit(iClearSelectionTask =
new ClearSelectionTask(iData, width(), height()),
this, SLOT(onClearSelectionTaskDone()));
(iClearSelectionTask =new ClearSelectionTask(iTaskQueue->pool(),
iData, width(), height()))->
submit(this, SLOT(onClearSelectionTaskDone()));
}
if (iSelecting) {
iSelecting = false;

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2017 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* 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:
*
@ -35,7 +35,6 @@
#define BOOKS_PAGE_WIDGET_H
#include "BooksTypes.h"
#include "BooksTask.h"
#include "BooksTaskQueue.h"
#include "BooksSettings.h"
#include "BooksBookModel.h"

View file

@ -36,8 +36,9 @@
#include "BooksBook.h"
#include "BooksUtil.h"
#include "HarbourJson.h"
#include "HarbourDebug.h"
#include "HarbourJson.h"
#include "HarbourTask.h"
#include <errno.h>
@ -56,12 +57,12 @@ enum BooksItemRole {
#define SHELF_STATE_FILE BOOKS_STATE_FILE_SUFFIX
#define SHELF_STATE_ORDER "order"
class BooksShelf::CopyTask : public BooksTask, BooksItem::CopyOperation
{
class BooksShelf::CopyTask : public HarbourTask, BooksItem::CopyOperation {
Q_OBJECT
public:
CopyTask(BooksShelf::Data* aDestData, BooksItem* aSrcItem);
CopyTask(QThreadPool* aPool, BooksShelf::Data* aDestData,
BooksItem* aSrcItem);
~CopyTask();
void performTask();
@ -89,10 +90,10 @@ public:
// BooksShelf::LoadTask
// ==========================================================================
class BooksShelf::LoadTask : public BooksTask
{
class BooksShelf::LoadTask : public HarbourTask {
public:
LoadTask(BooksStorage aStorage, QString aRelPath, QString aStateFile) :
LoadTask(QThreadPool* aPool, BooksStorage aStorage, QString aRelPath,
QString aStateFile) : HarbourTask(aPool),
iStorage(aStorage), iRelativePath(aRelPath),
iStateFilePath(aStateFile) {}
~LoadTask();
@ -322,7 +323,9 @@ inline bool BooksShelf::Data::copyingOut()
// BooksShelf::CopyTask
// ==========================================================================
BooksShelf::CopyTask::CopyTask(BooksShelf::Data* aDestData, BooksItem* aSrcItem) :
BooksShelf::CopyTask::CopyTask(QThreadPool* aPool, BooksShelf::Data* aDestData,
BooksItem* aSrcItem) :
HarbourTask(aPool),
iDestData(aDestData),
iDestStorage(aDestData->iShelf->storage()),
iDestRelPath(aDestData->iShelf->relativePath()),
@ -365,7 +368,7 @@ void BooksShelf::CopyTask::performTask()
bool BooksShelf::CopyTask::isCanceled() const
{
return BooksTask::isCanceled();
return HarbourTask::isCanceled();
}
void BooksShelf::CopyTask::copyProgressChanged(int aProgress)
@ -378,11 +381,10 @@ void BooksShelf::CopyTask::copyProgressChanged(int aProgress)
// BooksShelf::DeleteTask
// ==========================================================================
class BooksShelf::DeleteTask : public BooksTask
{
class BooksShelf::DeleteTask : public HarbourTask {
Q_OBJECT
public:
DeleteTask(BooksItem* aItem);
DeleteTask(QThreadPool* aPool, BooksItem* aItem);
~DeleteTask();
void performTask();
@ -390,7 +392,8 @@ public:
BooksItem* iItem;
};
BooksShelf::DeleteTask::DeleteTask(BooksItem* aItem) :
BooksShelf::DeleteTask::DeleteTask(QThreadPool* aPool, BooksItem* aItem) :
HarbourTask(aPool),
iItem(aItem)
{
iItem->retain();
@ -695,9 +698,8 @@ void BooksShelf::loadBookList()
iLoadTask = NULL;
} else {
HDEBUG(iPath);
iLoadTask = new LoadTask(iStorage, iRelativePath, stateFileName());
connect(iLoadTask, SIGNAL(done()), SLOT(onLoadTaskDone()));
iTaskQueue->submit(iLoadTask);
(iLoadTask = new LoadTask(iTaskQueue->pool(), iStorage, iRelativePath,
stateFileName()))->submit(this, SLOT(onLoadTaskDone()));
}
}
@ -912,7 +914,7 @@ bool BooksShelf::drop(QObject* aItem)
// Don't connect signals since it's not our item
data->setBook(book, true);
// Start copying the data
iTaskQueue->submit(new CopyTask(data, book));
(new CopyTask(iTaskQueue->pool(), data, book))->submit();
Q_EMIT hasDummyItemChanged();
Q_EMIT dummyItemIndexChanged();
Q_EMIT dataChanged(index, index);
@ -944,9 +946,9 @@ void BooksShelf::submitDeleteTask(int aIndex)
{
BooksItem* item = iList.at(aIndex)->iItem;
if (item) {
DeleteTask* task = new DeleteTask(item);
DeleteTask* task = new DeleteTask(iTaskQueue->pool(), item);
iDeleteTasks.append(task);
iTaskQueue->submit(task);
task->submit();
BooksBook* book = item->book();
if (book) {
book->cancelCoverRequest();
@ -1045,7 +1047,7 @@ void BooksShelf::importBook(QObject* aBook)
Counts counts(this);
Data* data = new Data(this, book->retain(), true);
iList.insert(0, data);
iTaskQueue->submit(new CopyTask(data, book));
(new CopyTask(iTaskQueue->pool(), data, book))->submit();
counts.emitSignals(this);
endInsertRows();
saveState();

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* 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:
*
@ -37,7 +37,6 @@
#include "BooksItem.h"
#include "BooksStorage.h"
#include "BooksSaveTimer.h"
#include "BooksTask.h"
#include "BooksTaskQueue.h"
#include "BooksLoadingProperty.h"

View file

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

View file

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

View file

@ -32,7 +32,6 @@
*/
#include "BooksTaskQueue.h"
#include "BooksTask.h"
#include "HarbourDebug.h"
@ -109,17 +108,3 @@ BooksTaskQueue::~BooksTaskQueue()
delete iPool;
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);
}

View file

@ -50,8 +50,7 @@ public:
static shared_ptr<BooksTaskQueue> hashQueue();
static void waitForDone(int aMsecs = -1);
void submit(BooksTask* aTask);
void submit(BooksTask* aTask, QObject* aTarget, const char* aSlot);
QThreadPool* pool() const;
private:
BooksTaskQueue(int aMaxThreadCount);
@ -63,4 +62,7 @@ private:
QThreadPool* iPool;
};
inline QThreadPool* BooksTaskQueue::pool() const
{ return iPool; }
#endif // BOOKS_TASK_QUEUE_H

View file

@ -33,8 +33,9 @@
#include "BooksUtil.h"
#include "BooksDefs.h"
#include "BooksTask.h"
#include "HarbourDebug.h"
#include "HarbourTask.h"
#include "ZLDir.h"
#include "formats/FormatPlugin.h"
@ -90,7 +91,7 @@ shared_ptr<Book> BooksUtil::bookFromFile(std::string aPath)
return book;
}
QByteArray BooksUtil::computeFileHash(QString aPath, const BooksTask* aTask)
QByteArray BooksUtil::computeFileHash(QString aPath, const HarbourTask* aTask)
{
QByteArray result;
QFile file(aPath);
@ -157,7 +158,7 @@ bool BooksUtil::setFileHashAttr(QString aPath, QByteArray aHash)
return false;
}
QByteArray BooksUtil::computeFileHashAndSetAttr(QString aPath, const BooksTask* aTask)
QByteArray BooksUtil::computeFileHashAndSetAttr(QString aPath, const HarbourTask* aTask)
{
QByteArray hash = computeFileHash(aPath, aTask);
if (!hash.isEmpty()) {

View file

@ -40,7 +40,7 @@
#include <QString>
class BooksTask;
class HarbourTask;
namespace BooksUtil {
shared_ptr<Book> bookFromFile(std::string aPath);
@ -48,8 +48,8 @@ namespace BooksUtil {
bool isValidFileName(QString aName);
QByteArray fileHashAttr(QString aPath);
bool setFileHashAttr(QString aPath, QByteArray aHash);
QByteArray computeFileHash(QString aPath, const BooksTask* aTask = NULL);
QByteArray computeFileHashAndSetAttr(QString aPath, const BooksTask* aTask = NULL);
QByteArray computeFileHash(QString aPath, const HarbourTask* aTask = NULL);
QByteArray computeFileHashAndSetAttr(QString aPath, const HarbourTask* aTask = NULL);
}
inline shared_ptr<Book> BooksUtil::bookFromFile(QString aPath)

@ -1 +1 @@
Subproject commit 9f91b79f34f75ca099c09819dc57d099b909c705
Subproject commit c8d907a11a3512672ed906fa2c3b41a65c9a9bd2