diff --git a/YACReader/render.cpp b/YACReader/render.cpp index ff4177c9..9557ff28 100644 --- a/YACReader/render.cpp +++ b/YACReader/render.cpp @@ -761,6 +761,8 @@ void Render::createComic(const QString & path) if(comic!=0) { //comic->moveToThread(QApplication::instance()->thread()); + comic->invalidate(); + comic->disconnect(); comic->deleteLater(); } @@ -777,19 +779,19 @@ void Render::createComic(const QString & path) previousIndex = currentIndex = 0; - connect(comic,SIGNAL(errorOpening()),this,SIGNAL(errorOpening())); - connect(comic,SIGNAL(errorOpening(QString)),this,SIGNAL(errorOpening(QString))); - connect(comic,SIGNAL(crcErrorFound(QString)),this,SIGNAL(crcError(QString))); - connect(comic,SIGNAL(errorOpening()),this,SLOT(reset())); - connect(comic,SIGNAL(imageLoaded(int)),this,SIGNAL(imageLoaded(int))); - connect(comic,SIGNAL(imageLoaded(int)),this,SLOT(pageRawDataReady(int))); - connect(comic,SIGNAL(openAt(int)),this,SLOT(renderAt(int))); - connect(comic,SIGNAL(numPages(unsigned int)),this,SIGNAL(numPages(unsigned int))); - connect(comic,SIGNAL(numPages(unsigned int)),this,SLOT(setNumPages(unsigned int))); - connect(comic,SIGNAL(imageLoaded(int,QByteArray)),this,SIGNAL(imageLoaded(int,QByteArray))); - connect(comic,SIGNAL(isBookmark(bool)),this,SIGNAL(currentPageIsBookmark(bool))); + connect(comic,SIGNAL(errorOpening()),this,SIGNAL(errorOpening()), Qt::QueuedConnection); + connect(comic,SIGNAL(errorOpening(QString)),this,SIGNAL(errorOpening(QString)), Qt::QueuedConnection); + connect(comic,SIGNAL(crcErrorFound(QString)),this,SIGNAL(crcError(QString)), Qt::QueuedConnection); + connect(comic,SIGNAL(errorOpening()),this,SLOT(reset()), Qt::QueuedConnection); + connect(comic,SIGNAL(imageLoaded(int)),this,SIGNAL(imageLoaded(int)), Qt::QueuedConnection); + connect(comic,SIGNAL(imageLoaded(int)),this,SLOT(pageRawDataReady(int)), Qt::QueuedConnection); + connect(comic,SIGNAL(openAt(int)),this,SLOT(renderAt(int)), Qt::QueuedConnection); + connect(comic,SIGNAL(numPages(unsigned int)),this,SIGNAL(numPages(unsigned int)), Qt::QueuedConnection); + connect(comic,SIGNAL(numPages(unsigned int)),this,SLOT(setNumPages(unsigned int)), Qt::QueuedConnection); + connect(comic,SIGNAL(imageLoaded(int,QByteArray)),this,SIGNAL(imageLoaded(int,QByteArray)), Qt::QueuedConnection); + 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(isCover()),this,SIGNAL(isCover())); @@ -807,19 +809,21 @@ void Render::loadComic(const QString & path, int atPage) void Render::startLoad() { - QThread * thread = NULL; + QThread * thread = nullptr; thread = new QThread(); comic->moveToThread(thread); - connect(comic, SIGNAL(errorOpening()), thread, SLOT(quit())); - connect(comic, SIGNAL(errorOpening(QString)), thread, SLOT(quit())); - connect(comic, SIGNAL(imagesLoaded()), thread, SLOT(quit())); + connect(comic, SIGNAL(errorOpening()), thread, SLOT(quit()), Qt::QueuedConnection); + connect(comic, SIGNAL(errorOpening(QString)), thread, SLOT(quit()), Qt::QueuedConnection); + 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(finished()), thread, SLOT(deleteLater())); - if(thread != NULL) + if(thread != nullptr) thread->start(); invalidate(); diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index 5340671a..f4621918 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -243,6 +243,9 @@ void DBHelper::update(qulonglong libraryId, ComicInfo & comicInfo) void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db) { + if(comicInfo == nullptr) + return; + QSqlQuery updateComicInfo(db); updateComicInfo.prepare("UPDATE comic_info SET " "title = :title," @@ -385,7 +388,7 @@ void DBHelper::updateProgress(qulonglong libraryId, const ComicInfo &comicInfo) comic.info.currentPage = comicInfo.currentPage; comic.info.hasBeenOpened = true; - DBHelper::update(&comic.info,db); + DBHelper::updateReadingRemoteProgress(comic.info,db); db.close(); QSqlDatabase::removeDatabase(libraryPath); @@ -407,6 +410,8 @@ void DBHelper::updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatab updateComicInfo.bindValue(":id", comicInfo.id); updateComicInfo.bindValue(":rating", comicInfo.rating); updateComicInfo.exec(); + + updateComicInfo.clear(); } diff --git a/YACReaderLibrary/server/lib/bfHttpServer/httpsession.cpp b/YACReaderLibrary/server/lib/bfHttpServer/httpsession.cpp index 1bfe2f07..cfe9ccb0 100644 --- a/YACReaderLibrary/server/lib/bfHttpServer/httpsession.cpp +++ b/YACReaderLibrary/server/lib/bfHttpServer/httpsession.cpp @@ -244,6 +244,7 @@ void HttpSession::dismissCurrentComic() { if(dataPtr->yacreaderSessionData.comic != 0) { + dataPtr->yacreaderSessionData.comic->invalidate(); dataPtr->yacreaderSessionData.comic->deleteLater(); dataPtr->yacreaderSessionData.comic = 0; } @@ -283,6 +284,7 @@ void HttpSession::dismissCurrentRemoteComic() { if(dataPtr->yacreaderSessionData.remoteComic != 0) { + dataPtr->yacreaderSessionData.remoteComic->invalidate(); dataPtr->yacreaderSessionData.remoteComic->deleteLater(); dataPtr->yacreaderSessionData.remoteComic = 0; } diff --git a/common/comic.cpp b/common/comic.cpp index a55ab575..00dc3581 100644 --- a/common/comic.cpp +++ b/common/comic.cpp @@ -44,7 +44,7 @@ const QStringList Comic::literalComicExtensions = LiteralComicArchiveExtensions; //----------------------------------------------------------------------------- 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(); } @@ -57,6 +57,7 @@ Comic::Comic(const QString & pathFile, int atPage ) //----------------------------------------------------------------------------- Comic::~Comic() { + emit destroyed(); delete bm; } //----------------------------------------------------------------------------- @@ -198,7 +199,13 @@ void Comic::updateBookmarkImage(int index) //----------------------------------------------------------------------------- void Comic::setPageLoaded(int page) { - _loadedPages[page] = true; + _loadedPages[page] = true; +} + +void Comic::invalidate() +{ + _invalidated = true; + emit invalidated(); } //----------------------------------------------------------------------------- QByteArray Comic::getRawPage(int page) @@ -585,10 +592,20 @@ void FileComic::process() for(int i = sectionIndex; ithread()); + return; + } archive.getAllData(sections.at(i),this); } for(int i = 0; ithread()); + return; + } archive.getAllData(sections.at(i),this); } //archive.getAllData(QVector(),this); @@ -688,6 +705,12 @@ void FolderComic::process() int i=_firstPage; while(countthread()); + return; + } + QFile f(list.at(i).absoluteFilePath()); f.open(QIODevice::ReadOnly); _pages[i]=f.readAll(); @@ -843,10 +866,23 @@ void PDFComic::process() int buffered_index = _index; for(int i=buffered_index;ithread()); + return; + } + renderPage(i); } for(int i=0;ithread()); + return; + } renderPage(i); } diff --git a/common/comic.h b/common/comic.h index 4dd17ce8..90cc314f 100644 --- a/common/comic.h +++ b/common/comic.h @@ -38,6 +38,8 @@ class Comic : public QObject bool _isPDF; + bool _invalidated; + public: static const QStringList imageExtensions; @@ -79,7 +81,6 @@ class Comic : public QObject static QList findValidComicFilesInFolder(const QString &path); public slots: - void loadFinished(); void setBookmark(); void removeBookmark(); @@ -87,9 +88,11 @@ class Comic : public QObject void checkIsBookmark(int index); void updateBookmarkImage(int); void setPageLoaded(int page); + void invalidate(); signals: - + void invalidated(); + void destroyed(); void imagesLoaded(); void imageLoaded(int index); void imageLoaded(int index,const QByteArray & image);