7.0 fields added

save current page on viewer close
This commit is contained in:
Luis Ángel San Martín
2013-07-20 20:18:59 +02:00
parent 97db3f582a
commit 57d7a8abdc
11 changed files with 141 additions and 24 deletions

View File

@ -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();

View File

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

View File

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

View File

@ -51,24 +51,39 @@ void YACReaderLocalServer::sendResponse()
dataStream >> libraryId;
dataStream >> comic;
QList<ComicDB> 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<ComicDB> 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;

View File

@ -19,6 +19,7 @@ public slots:
void sendResponse();
static bool isRunning();
void getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & sibling);
void updateComic(quint64 libraryId, ComicDB & comic);
private:
QLocalServer * localServer;