Merged in selmf/yacreader/small-fixes-9.0 (pull request #52)

Small fixes 9.0:
This commit is contained in:
Luis Ángel San Martín
2017-09-27 18:58:41 +00:00
5 changed files with 72 additions and 22 deletions

View File

@ -761,6 +761,8 @@ void Render::createComic(const QString & path)
if(comic!=0) if(comic!=0)
{ {
//comic->moveToThread(QApplication::instance()->thread()); //comic->moveToThread(QApplication::instance()->thread());
comic->invalidate();
comic->disconnect(); comic->disconnect();
comic->deleteLater(); comic->deleteLater();
} }
@ -777,19 +779,19 @@ void Render::createComic(const QString & path)
previousIndex = currentIndex = 0; previousIndex = currentIndex = 0;
connect(comic,SIGNAL(errorOpening()),this,SIGNAL(errorOpening())); connect(comic,SIGNAL(errorOpening()),this,SIGNAL(errorOpening()), Qt::QueuedConnection);
connect(comic,SIGNAL(errorOpening(QString)),this,SIGNAL(errorOpening(QString))); connect(comic,SIGNAL(errorOpening(QString)),this,SIGNAL(errorOpening(QString)), Qt::QueuedConnection);
connect(comic,SIGNAL(crcErrorFound(QString)),this,SIGNAL(crcError(QString))); connect(comic,SIGNAL(crcErrorFound(QString)),this,SIGNAL(crcError(QString)), Qt::QueuedConnection);
connect(comic,SIGNAL(errorOpening()),this,SLOT(reset())); connect(comic,SIGNAL(errorOpening()),this,SLOT(reset()), Qt::QueuedConnection);
connect(comic,SIGNAL(imageLoaded(int)),this,SIGNAL(imageLoaded(int))); connect(comic,SIGNAL(imageLoaded(int)),this,SIGNAL(imageLoaded(int)), Qt::QueuedConnection);
connect(comic,SIGNAL(imageLoaded(int)),this,SLOT(pageRawDataReady(int))); connect(comic,SIGNAL(imageLoaded(int)),this,SLOT(pageRawDataReady(int)), Qt::QueuedConnection);
connect(comic,SIGNAL(openAt(int)),this,SLOT(renderAt(int))); connect(comic,SIGNAL(openAt(int)),this,SLOT(renderAt(int)), Qt::QueuedConnection);
connect(comic,SIGNAL(numPages(unsigned int)),this,SIGNAL(numPages(unsigned int))); connect(comic,SIGNAL(numPages(unsigned int)),this,SIGNAL(numPages(unsigned int)), Qt::QueuedConnection);
connect(comic,SIGNAL(numPages(unsigned int)),this,SLOT(setNumPages(unsigned int))); connect(comic,SIGNAL(numPages(unsigned int)),this,SLOT(setNumPages(unsigned int)), Qt::QueuedConnection);
connect(comic,SIGNAL(imageLoaded(int,QByteArray)),this,SIGNAL(imageLoaded(int,QByteArray))); connect(comic,SIGNAL(imageLoaded(int,QByteArray)),this,SIGNAL(imageLoaded(int,QByteArray)), Qt::QueuedConnection);
connect(comic,SIGNAL(isBookmark(bool)),this,SIGNAL(currentPageIsBookmark(bool))); connect(comic,SIGNAL(isBookmark(bool)),this,SIGNAL(currentPageIsBookmark(bool)), Qt::QueuedConnection);
connect(comic,SIGNAL(bookmarksUpdated()),this,SIGNAL(bookmarksUpdated())); connect(comic,SIGNAL(bookmarksUpdated()),this,SIGNAL(bookmarksUpdated()), Qt::QueuedConnection);
//connect(comic,SIGNAL(isLast()),this,SIGNAL(isLast())); //connect(comic,SIGNAL(isLast()),this,SIGNAL(isLast()));
//connect(comic,SIGNAL(isCover()),this,SIGNAL(isCover())); //connect(comic,SIGNAL(isCover()),this,SIGNAL(isCover()));
@ -807,19 +809,21 @@ void Render::loadComic(const QString & path, int atPage)
void Render::startLoad() void Render::startLoad()
{ {
QThread * thread = NULL; QThread * thread = nullptr;
thread = new QThread(); thread = new QThread();
comic->moveToThread(thread); comic->moveToThread(thread);
connect(comic, SIGNAL(errorOpening()), thread, SLOT(quit())); connect(comic, SIGNAL(errorOpening()), thread, SLOT(quit()), Qt::QueuedConnection);
connect(comic, SIGNAL(errorOpening(QString)), thread, SLOT(quit())); connect(comic, SIGNAL(errorOpening(QString)), thread, SLOT(quit()), Qt::QueuedConnection);
connect(comic, SIGNAL(imagesLoaded()), thread, SLOT(quit())); connect(comic, SIGNAL(imagesLoaded()), thread, SLOT(quit()), Qt::QueuedConnection);
connect(comic, SIGNAL(destroyed()), thread, SLOT(quit()), Qt::QueuedConnection);
connect(comic, SIGNAL(invalidated()), thread, SLOT(quit()), Qt::QueuedConnection);
connect(thread, SIGNAL(started()), comic, SLOT(process())); connect(thread, SIGNAL(started()), comic, SLOT(process()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
if(thread != NULL) if(thread != nullptr)
thread->start(); thread->start();
invalidate(); invalidate();

View File

@ -243,6 +243,9 @@ void DBHelper::update(qulonglong libraryId, ComicInfo & comicInfo)
void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db) void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db)
{ {
if(comicInfo == nullptr)
return;
QSqlQuery updateComicInfo(db); QSqlQuery updateComicInfo(db);
updateComicInfo.prepare("UPDATE comic_info SET " updateComicInfo.prepare("UPDATE comic_info SET "
"title = :title," "title = :title,"
@ -385,7 +388,7 @@ void DBHelper::updateProgress(qulonglong libraryId, const ComicInfo &comicInfo)
comic.info.currentPage = comicInfo.currentPage; comic.info.currentPage = comicInfo.currentPage;
comic.info.hasBeenOpened = true; comic.info.hasBeenOpened = true;
DBHelper::update(&comic.info,db); DBHelper::updateReadingRemoteProgress(comic.info,db);
db.close(); db.close();
QSqlDatabase::removeDatabase(libraryPath); QSqlDatabase::removeDatabase(libraryPath);
@ -407,6 +410,8 @@ void DBHelper::updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatab
updateComicInfo.bindValue(":id", comicInfo.id); updateComicInfo.bindValue(":id", comicInfo.id);
updateComicInfo.bindValue(":rating", comicInfo.rating); updateComicInfo.bindValue(":rating", comicInfo.rating);
updateComicInfo.exec(); updateComicInfo.exec();
updateComicInfo.clear();
} }

View File

@ -244,6 +244,7 @@ void HttpSession::dismissCurrentComic()
{ {
if(dataPtr->yacreaderSessionData.comic != 0) if(dataPtr->yacreaderSessionData.comic != 0)
{ {
dataPtr->yacreaderSessionData.comic->invalidate();
dataPtr->yacreaderSessionData.comic->deleteLater(); dataPtr->yacreaderSessionData.comic->deleteLater();
dataPtr->yacreaderSessionData.comic = 0; dataPtr->yacreaderSessionData.comic = 0;
} }
@ -283,6 +284,7 @@ void HttpSession::dismissCurrentRemoteComic()
{ {
if(dataPtr->yacreaderSessionData.remoteComic != 0) if(dataPtr->yacreaderSessionData.remoteComic != 0)
{ {
dataPtr->yacreaderSessionData.remoteComic->invalidate();
dataPtr->yacreaderSessionData.remoteComic->deleteLater(); dataPtr->yacreaderSessionData.remoteComic->deleteLater();
dataPtr->yacreaderSessionData.remoteComic = 0; dataPtr->yacreaderSessionData.remoteComic = 0;
} }

View File

@ -44,7 +44,7 @@ const QStringList Comic::literalComicExtensions = LiteralComicArchiveExtensions;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
Comic::Comic() Comic::Comic()
:_pages(),_index(0),_path(),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false) :_pages(),_index(0),_path(),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false),_invalidated(false)
{ {
setup(); setup();
} }
@ -57,6 +57,7 @@ Comic::Comic(const QString & pathFile, int atPage )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
Comic::~Comic() Comic::~Comic()
{ {
emit destroyed();
delete bm; delete bm;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -200,6 +201,12 @@ void Comic::setPageLoaded(int page)
{ {
_loadedPages[page] = true; _loadedPages[page] = true;
} }
void Comic::invalidate()
{
_invalidated = true;
emit invalidated();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QByteArray Comic::getRawPage(int page) QByteArray Comic::getRawPage(int page)
{ {
@ -585,10 +592,20 @@ void FileComic::process()
for(int i = sectionIndex; i<sections.count() ; i++) for(int i = sectionIndex; i<sections.count() ; i++)
{ {
if(_invalidated)
{
moveToThread(QCoreApplication::instance()->thread());
return;
}
archive.getAllData(sections.at(i),this); archive.getAllData(sections.at(i),this);
} }
for(int i = 0; i<sectionIndex; i++) for(int i = 0; i<sectionIndex; i++)
{ {
if(_invalidated)
{
moveToThread(QCoreApplication::instance()->thread());
return;
}
archive.getAllData(sections.at(i),this); archive.getAllData(sections.at(i),this);
} }
//archive.getAllData(QVector<quint32>(),this); //archive.getAllData(QVector<quint32>(),this);
@ -688,6 +705,12 @@ void FolderComic::process()
int i=_firstPage; int i=_firstPage;
while(count<nPages) while(count<nPages)
{ {
if(_invalidated)
{
moveToThread(QCoreApplication::instance()->thread());
return;
}
QFile f(list.at(i).absoluteFilePath()); QFile f(list.at(i).absoluteFilePath());
f.open(QIODevice::ReadOnly); f.open(QIODevice::ReadOnly);
_pages[i]=f.readAll(); _pages[i]=f.readAll();
@ -843,10 +866,23 @@ void PDFComic::process()
int buffered_index = _index; int buffered_index = _index;
for(int i=buffered_index;i<nPages;i++) for(int i=buffered_index;i<nPages;i++)
{ {
if(_invalidated)
{
delete pdfComic;
moveToThread(QCoreApplication::instance()->thread());
return;
}
renderPage(i); renderPage(i);
} }
for(int i=0;i<buffered_index;i++) for(int i=0;i<buffered_index;i++)
{ {
if(_invalidated)
{
delete pdfComic;
moveToThread(QCoreApplication::instance()->thread());
return;
}
renderPage(i); renderPage(i);
} }

View File

@ -38,6 +38,8 @@ class Comic : public QObject
bool _isPDF; bool _isPDF;
bool _invalidated;
public: public:
static const QStringList imageExtensions; static const QStringList imageExtensions;
@ -79,7 +81,6 @@ class Comic : public QObject
static QList<QString> findValidComicFilesInFolder(const QString &path); static QList<QString> findValidComicFilesInFolder(const QString &path);
public slots: public slots:
void loadFinished(); void loadFinished();
void setBookmark(); void setBookmark();
void removeBookmark(); void removeBookmark();
@ -87,9 +88,11 @@ class Comic : public QObject
void checkIsBookmark(int index); void checkIsBookmark(int index);
void updateBookmarkImage(int); void updateBookmarkImage(int);
void setPageLoaded(int page); void setPageLoaded(int page);
void invalidate();
signals: signals:
void invalidated();
void destroyed();
void imagesLoaded(); void imagesLoaded();
void imageLoaded(int index); void imageLoaded(int index);
void imageLoaded(int index,const QByteArray & image); void imageLoaded(int index,const QByteArray & image);