From 1503fe538326a7b61b9b220f8ea3d134a1d0ef17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 20 May 2018 14:49:07 +0200 Subject: [PATCH] Add method for marking a comic as reading without opening it first. Usefull when closing the a comic in the last page to mark the next one and the next being readed. --- YACReaderLibrary/db_helper.cpp | 49 ++++++++++++++++++++++------------ YACReaderLibrary/db_helper.h | 1 + 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index c5ee5c5f..3f62129c 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -193,9 +193,9 @@ QList DBHelper::getLabelComics(qulonglong libraryId, qulonglong labelId } db.close(); - } - //TODO ? - //QSqlDatabase::removeDatabase(db.connectionName()); + } + //TODO ? + //QSqlDatabase::removeDatabase(db.connectionName()); return list; } @@ -237,8 +237,8 @@ QList DBHelper::getFavorites(qulonglong libraryId) db.close(); } - //TODO ? - //QSqlDatabase::removeDatabase(db.connectionName()); + //TODO ? + //QSqlDatabase::removeDatabase(db.connectionName()); return list; } @@ -277,8 +277,8 @@ QList DBHelper::getReading(qulonglong libraryId) db.close(); } - //TODO ? - //QSqlDatabase::removeDatabase(db.connectionName()); + //TODO ? + //QSqlDatabase::removeDatabase(db.connectionName()); return list; } @@ -316,9 +316,9 @@ QList DBHelper::getReadingLists(qulonglong libraryId) list.insert(i,item); } } - - //TODO ? - //QSqlDatabase::removeDatabase(db.connectionName()); + + //TODO ? + //QSqlDatabase::removeDatabase(db.connectionName()); return list; } @@ -371,10 +371,10 @@ QList DBHelper::getReadingListFullContent(qulonglong libraryId, qulongl list.append(comic); } } - } + } - //TODO ? - //QSqlDatabase::removeDatabase(db.connectionName()); + //TODO ? + //QSqlDatabase::removeDatabase(db.connectionName()); return list; } @@ -704,6 +704,21 @@ void DBHelper::updateProgress(qulonglong libraryId, const ComicInfo &comicInfo) QSqlDatabase::removeDatabase(db.connectionName()); } +void DBHelper::setComicAsReading(qulonglong libraryId, const ComicInfo &comicInfo) +{ + QString libraryPath = DBHelper::getLibraries().getPath(libraryId); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + ComicDB comic = DBHelper::loadComic(comicInfo.id,db); + comic.info.hasBeenOpened = true; + comic.info.read = comic.info.read || comic.info.currentPage == comic.info.numPages; + + DBHelper::updateReadingRemoteProgress(comic.info,db); + + db.close(); + QSqlDatabase::removeDatabase(db.connectionName()); +} + void DBHelper::updateReadingRemoteProgress(const ComicInfo &comicInfo, QSqlDatabase &db) { QSqlQuery updateComicInfo(db); @@ -952,8 +967,8 @@ void DBHelper::insertComicsInFavorites(const QList &comicsList, QSqlDat query.bindValue(":ordering", numComics++); query.exec(); } - - QLOG_TRACE() << query.lastError(); + + QLOG_TRACE() << query.lastError(); db.commit(); } @@ -978,8 +993,8 @@ void DBHelper::insertComicsInLabel(const QList &comicsList, qulonglong query.bindValue(":ordering", numComics++); query.exec(); } - - QLOG_TRACE() << query.lastError(); + + QLOG_TRACE() << query.lastError(); db.commit(); } diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 7a240a2a..c1faf0d3 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -68,6 +68,7 @@ public: static void updateChildrenInfo(qulonglong folderId, QSqlDatabase & db); static void updateChildrenInfo(QSqlDatabase & db); static void updateProgress(qulonglong libraryId,const ComicInfo & comicInfo); + static void setComicAsReading(qulonglong libraryId, const ComicInfo &comicInfo); static void updateReadingRemoteProgress(const ComicInfo & comicInfo, QSqlDatabase & db); static void updateFromRemoteClient(qulonglong libraryId,const ComicInfo & comicInfo); static void renameLabel(qulonglong id, const QString & name, QSqlDatabase & db);