mirror of
https://github.com/YACReader/yacreader
synced 2025-06-03 00:58:32 -04:00
7.0 fields added
save current page on viewer close
This commit is contained in:
parent
97db3f582a
commit
57d7a8abdc
@ -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<ComicDB> & 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,6 +121,7 @@ class YACReaderSliderAction;
|
||||
|
||||
ComicDB currentComicDB;
|
||||
QList<ComicDB> siblingComics;
|
||||
bool isClient;
|
||||
signals:
|
||||
void closed();
|
||||
protected:
|
||||
|
@ -804,4 +804,9 @@ void Viewer::showIsLastMessage()
|
||||
unsigned int Viewer::getIndex()
|
||||
{
|
||||
return render->getIndex()+1;
|
||||
}
|
||||
|
||||
int Viewer::getCurrentPageNumber()
|
||||
{
|
||||
return render->getIndex();
|
||||
}
|
@ -81,6 +81,7 @@ virtual void mouseReleaseEvent ( QMouseEvent * event );
|
||||
void updateImageOptions();
|
||||
void showIsCoverMessage();
|
||||
void showIsLastMessage();
|
||||
int getCurrentPageNumber();
|
||||
|
||||
private:
|
||||
bool information;
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -113,7 +113,7 @@ ComicInfo::ComicInfo()
|
||||
:existOnDb(false),
|
||||
rating(-1),
|
||||
hasBeenOpened(false),
|
||||
currentPage(0),
|
||||
currentPage(1),
|
||||
bookmark1(-1),
|
||||
bookmark2(-1),
|
||||
bookmark3(-1),
|
||||
|
Loading…
x
Reference in New Issue
Block a user