From 57d7a8abdc06a93028b88246eff3109d85b63254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sat, 20 Jul 2013 20:18:59 +0200 Subject: [PATCH] 7.0 fields added save current page on viewer close --- YACReader/main_window_viewer.cpp | 16 +++++- YACReader/main_window_viewer.h | 1 + YACReader/viewer.cpp | 5 ++ YACReader/viewer.h | 1 + YACReader/yacreader_local_client.cpp | 2 +- YACReaderLibrary/db/data_base_management.cpp | 38 +++++++++++++- YACReaderLibrary/db_helper.cpp | 46 ++++++++++++++++- YACReaderLibrary/db_helper.h | 1 + YACReaderLibrary/yacreader_local_server.cpp | 52 ++++++++++++++------ YACReaderLibrary/yacreader_local_server.h | 1 + common/comic_db.cpp | 2 +- 11 files changed, 141 insertions(+), 24 deletions(-) diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 5f81a596..8be8be79 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -54,7 +54,7 @@ public: #endif MainWindowViewer::MainWindowViewer() -:QMainWindow(),fullscreen(false),toolbars(true),alwaysOnTop(false),currentDirectory("."),currentDirectoryImgDest(".") +:QMainWindow(),fullscreen(false),toolbars(true),alwaysOnTop(false),currentDirectory("."),currentDirectoryImgDest("."),isClient(false) { loadConfiguration(); setupUI(); @@ -154,6 +154,7 @@ void MainWindowViewer::setupUI() if(QCoreApplication::argc() == 2) //only path... { + isClient = false; //TODO: new method open(QString) QString pathFile = QCoreApplication::arguments().at(1); QFileInfo fi(pathFile); @@ -166,6 +167,7 @@ void MainWindowViewer::setupUI() } else if(QCoreApplication::argc() == 5) { + isClient = true; QString pathFile = QCoreApplication::arguments().at(1); currentDirectory = pathFile; quint64 comicId = QCoreApplication::arguments().at(2).toULongLong(); @@ -596,7 +598,7 @@ void MainWindowViewer::open(QString path, ComicDB & comic, QList & sibl else setWindowTitle("YACReader - " + fi.fileName()); - viewer->open(path,comic.info.currentPage); + viewer->open(path,comic.info.currentPage-1); enableActions(); int index = siblings.indexOf(comic); @@ -840,6 +842,15 @@ void MainWindowViewer::newVersion() void MainWindowViewer::closeEvent ( QCloseEvent * event ) { + YACReaderLocalClient client; + if(isClient) + { + currentComicDB.info.currentPage = viewer->getCurrentPageNumber()+1; + currentComicDB.info.hasBeenOpened = true; + //viewer->getBookmarks(); + client.sendComicInfo(0,currentComicDB); + } + viewer->save(); Configuration & conf = Configuration::getConfiguration(); if(!fullscreen && !isMaximized()) @@ -980,6 +991,7 @@ void MainWindowViewer::dragEnterEvent(QDragEnterEvent *event) if (event->mimeData()->hasFormat("text/uri-list")) { event->acceptProposedAction(); + isClient = false; } } diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 2f8413b3..ea762dca 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -121,6 +121,7 @@ class YACReaderSliderAction; ComicDB currentComicDB; QList siblingComics; + bool isClient; signals: void closed(); protected: diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index c1539058..df9b637f 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -804,4 +804,9 @@ void Viewer::showIsLastMessage() unsigned int Viewer::getIndex() { return render->getIndex()+1; +} + +int Viewer::getCurrentPageNumber() +{ + return render->getIndex(); } \ No newline at end of file diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 07593ede..338a05a3 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -81,6 +81,7 @@ virtual void mouseReleaseEvent ( QMouseEvent * event ); void updateImageOptions(); void showIsCoverMessage(); void showIsLastMessage(); + int getCurrentPageNumber(); private: bool information; diff --git a/YACReader/yacreader_local_client.cpp b/YACReader/yacreader_local_client.cpp index 2b2f1876..81494e91 100644 --- a/YACReader/yacreader_local_client.cpp +++ b/YACReader/yacreader_local_client.cpp @@ -73,7 +73,7 @@ bool YACReaderLocalClient::sendComicInfo(quint64 libraryId, ComicDB & comic) QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_8); out << (quint16)0; - out << (quint8)YACReaderIPCMessages::RequestComicInfo; + out << (quint8)YACReaderIPCMessages::SendComicInfo; out << libraryId; out << comic; out.device()->seek(0); diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index ab69e6f3..4c73398e 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -37,7 +37,8 @@ static QString fields = "title ," "characters," "notes," - "hash"; + "hash" + ; DataBaseManagement::DataBaseManagement() :QObject(),dataBasesList() @@ -167,7 +168,19 @@ bool DataBaseManagement::createTables(QSqlDatabase & database) "hash TEXT UNIQUE NOT NULL," "edited BOOLEAN DEFAULT 0," - "read BOOLEAN DEFAULT 0)"); + "read BOOLEAN DEFAULT 0," +//now 7.0 fields + + "hasBeenOpened BOOLEAN DEFAULT 0," + + "currentPage INTEGER DEFAULT 1, " + "bookmark1 INTEGER DEFAULT -1, " + "bookmark2 INTEGER DEFAULT -1, " + "bookmark3 INTEGER DEFAULT -1, " + "brightness INTEGER DEFAULT -1, " + "contrast INTEGER DEFAULT -1, " + "gamma INTEGER DEFAULT -1 " + ")"); success = success && queryComicInfo.exec(); //queryComicInfo.finish(); @@ -550,6 +563,27 @@ bool DataBaseManagement::updateToCurrentVersion(const QString & fullPath) if(updateVersion.numRowsAffected() > 0) returnValue = true; + if(returnValue) //TODO: execute only if previous version was < 7.0 + { + //new 7.0 fields + QSqlQuery alterTableComicInfo(db); + alterTableComicInfo.prepare("ALTER TABLE comic_info ADD (" + "hasBeenOpened BOOLEAN DEFAULT 0," + + "currentPage INTEGER DEFAULT 1, " + "bookmark1 INTEGER DEFAULT -1, " + "bookmark2 INTEGER DEFAULT -1, " + "bookmark3 INTEGER DEFAULT -1, " + "brightness INTEGER DEFAULT -1, " + "contrast INTEGER DEFAULT -1, " + "gamma INTEGER DEFAULT -1 " + ")"); + alterTableComicInfo.exec(); + + returnValue = (alterTableComicInfo.numRowsAffected() > 0); + } + //TODO update hasBeenOpened value + } db.close(); diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index 4d744833..2fef321a 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -187,6 +187,17 @@ void DBHelper::update(ComicDB * comic, QSqlDatabase & db) //do nothing } +void DBHelper::update(const QString & libraryName, ComicInfo & comicInfo) +{ + QString libraryPath = DBHelper::getLibraries().value(libraryName); + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary"); + + DBHelper::update(&comicInfo,db); + + db.close(); + QSqlDatabase::removeDatabase(libraryPath); +} + void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db) { QSqlQuery updateComicInfo(db); @@ -225,8 +236,18 @@ void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db) "notes = :notes," "read = :read," - "edited = :edited" - + "edited = :edited," + //new 7.0 fields + "hasBeenOpened = :hasBeenOpened," + + "currentPage = :currentPage," + "bookmark1 = :bookmark1," + "bookmark2 = :bookmark2," + "bookmark3 = :bookmark3," + "brightness = :brightness," + "contrast = :contrast, " + "gamma = :gamma" + //-- " WHERE id = :id "); bindField(":title",comicInfo->title,updateComicInfo); @@ -264,6 +285,16 @@ void DBHelper::update(ComicInfo * comicInfo, QSqlDatabase & db) updateComicInfo.bindValue(":read", comicInfo->read?1:0); updateComicInfo.bindValue(":id", comicInfo->id); updateComicInfo.bindValue(":edited", comicInfo->edited?1:0); + + updateComicInfo.bindValue(":hasBeenOpened", comicInfo->hasBeenOpened?1:0); + updateComicInfo.bindValue(":currentPage", comicInfo->currentPage); + updateComicInfo.bindValue(":bookmark1", comicInfo->bookmark1); + updateComicInfo.bindValue(":bookmark2", comicInfo->bookmark2); + updateComicInfo.bindValue(":bookmark3", comicInfo->bookmark3); + updateComicInfo.bindValue(":brightness", comicInfo->brightness); + updateComicInfo.bindValue(":contrast", comicInfo->contrast); + updateComicInfo.bindValue(":gamma", comicInfo->gamma); + updateComicInfo.exec(); } @@ -548,6 +579,17 @@ ComicInfo DBHelper::loadComicInfo(QString hash, QSqlDatabase & db) comicInfo.read = record.value("read").toBool(); comicInfo.edited = record.value("edited").toBool(); + //new 7.0 fields + comicInfo.hasBeenOpened = record.value("hasBeenOpened").toBool(); + comicInfo.currentPage = record.value("currentPage").toInt(); + comicInfo.bookmark1 = record.value("bookmark1").toInt(); + comicInfo.bookmark2 = record.value("bookmark2").toInt(); + comicInfo.bookmark3 = record.value("bookmark3").toInt(); + comicInfo.brightness = record.value("brightness").toInt(); + comicInfo.contrast = record.value("contrast").toInt(); + comicInfo.gamma = record.value("gamma").toInt(); + //-- + setField("title",comicInfo.title,record); setField("numPages",comicInfo.numPages,record); diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 68c93601..79cf5b68 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -36,6 +36,7 @@ public: static qulonglong insert(Folder * folder, QSqlDatabase & db); static qulonglong insert(ComicDB * comic, QSqlDatabase & db); //updates + static void update(const QString & libraryName, ComicInfo & comicInfo); static void update(ComicDB * comics, QSqlDatabase & db); static void update(ComicInfo * comicInfo, QSqlDatabase & db); static void updateRead(ComicInfo * comicInfo, QSqlDatabase & db); diff --git a/YACReaderLibrary/yacreader_local_server.cpp b/YACReaderLibrary/yacreader_local_server.cpp index f9d05abf..050c7cd7 100644 --- a/YACReaderLibrary/yacreader_local_server.cpp +++ b/YACReaderLibrary/yacreader_local_server.cpp @@ -51,24 +51,39 @@ void YACReaderLocalServer::sendResponse() dataStream >> libraryId; dataStream >> comic; - QList siblings; - getComicInfo(libraryId,comic,siblings); - - QByteArray block; - QDataStream out(&block, QIODevice::WriteOnly); - out.setVersion(QDataStream::Qt_4_8); - out << (quint16)0; - out << comic; - out << siblings; - out.device()->seek(0); - out << (quint16)(block.size() - sizeof(quint16)); - - int written = 0; - while(written != block.size()) + switch (msgType) { - written += clientConnection->write(block); - clientConnection->flush(); + case YACReaderIPCMessages::RequestComicInfo: + { + QList siblings; + getComicInfo(libraryId,comic,siblings); + + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_4_8); + out << (quint16)0; + out << comic; + out << siblings; + out.device()->seek(0); + out << (quint16)(block.size() - sizeof(quint16)); + + int written = 0; + while(written != block.size()) + { + written += clientConnection->write(block); + clientConnection->flush(); + } + break; + } + case YACReaderIPCMessages::SendComicInfo: + { + updateComic(libraryId,comic); + //clientConnection->disconnectFromServer(); + break; + } + } + //clientConnection->waitForBytesWritten();*/ //clientConnection->disconnectFromServer(); } @@ -79,6 +94,11 @@ void YACReaderLocalServer::getComicInfo(quint64 libraryId, ComicDB & comic, QLis siblings = DBHelper::getSiblings(DBHelper::getLibrariesNames().at(libraryId), comic.parentId); } +void YACReaderLocalServer::updateComic(quint64 libraryId, ComicDB & comic) +{ + DBHelper::update(DBHelper::getLibrariesNames().at(libraryId), comic.info); +} + bool YACReaderLocalServer::isRunning() { QLocalSocket socket; diff --git a/YACReaderLibrary/yacreader_local_server.h b/YACReaderLibrary/yacreader_local_server.h index c3d1badf..8e193e16 100644 --- a/YACReaderLibrary/yacreader_local_server.h +++ b/YACReaderLibrary/yacreader_local_server.h @@ -19,6 +19,7 @@ public slots: void sendResponse(); static bool isRunning(); void getComicInfo(quint64 libraryId, ComicDB & comic, QList & sibling); + void updateComic(quint64 libraryId, ComicDB & comic); private: QLocalServer * localServer; diff --git a/common/comic_db.cpp b/common/comic_db.cpp index 796ce6a7..8a669a4f 100644 --- a/common/comic_db.cpp +++ b/common/comic_db.cpp @@ -113,7 +113,7 @@ ComicInfo::ComicInfo() :existOnDb(false), rating(-1), hasBeenOpened(false), - currentPage(0), + currentPage(1), bookmark1(-1), bookmark2(-1), bookmark3(-1),