From e886f160ccc79327885ed796aa7af974eeabcd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 16 Jul 2013 21:50:02 +0200 Subject: [PATCH] load(path,atPage) added in viewer,render and comic classes updated CHANGELOG --- CHANGELOG.txt | 6 + YACReader/comic.cpp | 69 +++++---- YACReader/comic.h | 16 +- YACReader/main_window_viewer.cpp | 36 ++++- YACReader/render.cpp | 4 +- YACReader/render.h | 2 +- YACReader/viewer.cpp | 4 +- YACReader/viewer.h | 2 +- YACReader/yacreader_local_client.cpp | 41 ++++- YACReader/yacreader_local_client.h | 4 +- YACReaderLibrary/library_window.cpp | 11 +- YACReaderLibrary/yacreader_local_server.cpp | 51 +++++-- YACReaderLibrary/yacreader_local_server.h | 3 +- common/comic_db.cpp | 159 ++++++++++++++++++++ common/comic_db.h | 7 + 15 files changed, 352 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9d030a7e..d33ca57b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,9 @@ +6.6 (No pública) +Modificado YACReader para que abra los archivos comprimidos usando 7z.dll (.so, .dylib) +YACReader abre ahora los cómics por la última página leída. +Corregido bug que causaba que algunos cómics no se pudiesen abrir desde YACReaderLibrary en YACReader +Corregido el modo en el que se actualizaba la "information label" + 6.5 Nueva interfaz principal de YACReaderLibrary y YACReader Corregido bug que causaba que el servidor no se activase en el primer arranque en MacOSX diff --git a/YACReader/comic.cpp b/YACReader/comic.cpp index 86ff51a4..b9675039 100644 --- a/YACReader/comic.cpp +++ b/YACReader/comic.cpp @@ -19,8 +19,8 @@ Comic::Comic() setup(); } //----------------------------------------------------------------------------- -Comic::Comic(const QString & pathFile) -:_pages(),_index(0),_path(pathFile),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false) +Comic::Comic(const QString & pathFile, int atPage ) +:_pages(),_index(0),_path(pathFile),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false),_firstPage(atPage) { setup(); } @@ -180,10 +180,10 @@ FileComic::FileComic() } -FileComic::FileComic(const QString & path) - :Comic(path) +FileComic::FileComic(const QString & path, int atPage ) + :Comic(path,atPage) { - load(path); + load(path,atPage); } FileComic::~FileComic() @@ -191,14 +191,18 @@ FileComic::~FileComic() //Comic::~Comic(); } -bool FileComic::load(const QString & path) +bool FileComic::load(const QString & path, int atPage) { QFileInfo fi(path); if(fi.exists()) { - bm->newComic(path); - emit bookmarksUpdated(); + if(atPage == -1) + { + bm->newComic(path); + emit bookmarksUpdated(); + } + _firstPage = atPage; //emit bookmarksLoaded(*bm); _path = QDir::cleanPath(path); @@ -393,8 +397,9 @@ void FileComic::process() out << "tiempo en ordenar : " << myTimer.elapsed() << endl; - _firstPage = bm->getLastPage(); - _index = bm->getLastPage(); + if(_firstPage == -1) + _firstPage = bm->getLastPage(); + _index = _firstPage; emit(openAt(_index)); int sectionIndex; @@ -463,10 +468,10 @@ FolderComic::FolderComic() } -FolderComic::FolderComic(const QString & path) - :Comic(path) +FolderComic::FolderComic(const QString & path, int atPage ) + :Comic(path, atPage ) { - load(path); + load(path, atPage ); } FolderComic::~FolderComic() @@ -474,11 +479,15 @@ FolderComic::~FolderComic() } -bool FolderComic::load(const QString & path) +bool FolderComic::load(const QString & path, int atPage ) { _path = path; - bm->newComic(_path); - emit bookmarksUpdated(); + if(atPage == -1) + { + bm->newComic(_path); + emit bookmarksUpdated(); + } + _firstPage = atPage; //emit bookmarksLoaded(*bm); return true; } @@ -508,8 +517,11 @@ void FolderComic::process() } else { - _firstPage = bm->getLastPage(); - _index = bm->getLastPage(); + if(_firstPage == -1) + _firstPage = bm->getLastPage(); + + _index = _firstPage; + emit(openAt(_index)); emit pageChanged(0); // this indicates new comic, index=0 @@ -544,10 +556,10 @@ PDFComic::PDFComic() } -PDFComic::PDFComic(const QString & path) - :Comic(path) +PDFComic::PDFComic(const QString & path, int atPage) + :Comic(path,atPage) { - load(path); + load(path,atPage); } PDFComic::~PDFComic() @@ -555,11 +567,15 @@ PDFComic::~PDFComic() } -bool PDFComic::load(const QString & path) +bool PDFComic::load(const QString & path, int atPage) { _path = path; - bm->newComic(_path); - emit bookmarksUpdated(); + if(atPage == -1) + { + bm->newComic(_path); + emit bookmarksUpdated(); + } + _firstPage = atPage; //emit bookmarksLoaded(*bm); return true; } @@ -590,8 +606,9 @@ void PDFComic::process() _pages.resize(nPages); _loadedPages = QVector(nPages,false); - _firstPage = bm->getLastPage(); - _index = bm->getLastPage(); + if(_firstPage == -1) + _firstPage = bm->getLastPage(); + _index = _firstPage; emit(openAt(_index)); for(int i=_index;i > getSections(int & sectionIndex); public: FileComic(); - FileComic(const QString & path); + FileComic(const QString & path, int atPage = -1); ~FileComic(); void fileExtracted(int index, const QByteArray & rawData); - virtual bool load(const QString & path); + virtual bool load(const QString & path, int atPage = -1); public slots: void process(); @@ -109,10 +109,10 @@ //void run(); public: FolderComic(); - FolderComic(const QString & path); + FolderComic(const QString & path, int atPage = -1); ~FolderComic(); - virtual bool load(const QString & path); + virtual bool load(const QString & path, int atPage = -1); public slots: void process(); @@ -129,10 +129,10 @@ //void run(); public: PDFComic(); - PDFComic(const QString & path); + PDFComic(const QString & path, int atPage = -1); ~PDFComic(); - virtual bool load(const QString & path); + virtual bool load(const QString & path, int atPage = -1); public slots: void process(); }; diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 14fce3a1..300a8ead 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -13,6 +13,9 @@ #include "help_about_dialog.h" #include "yacreader_tool_bar_stretch.h" +#include "comic_db.h" +#include "yacreader_local_client.h" + #include #include @@ -115,7 +118,7 @@ void MainWindowViewer::setupUI() setWindowTitle("YACReader"); - if(QCoreApplication::argc()>1) + if(QCoreApplication::argc() == 2) //only path... { //TODO: new method open(QString) QString pathFile = QCoreApplication::arguments().at(1); @@ -124,12 +127,37 @@ void MainWindowViewer::setupUI() getSiblingComics(fi.absolutePath(),fi.fileName()); setWindowTitle("YACReader - " + fi.fileName()); + enableActions(); + viewer->open(pathFile); + } + /*else if(QCoreApplication::argc() == 5) + { + QString pathFile = QCoreApplication::arguments().at(1); + currentDirectory = pathFile; + quint64 comicId = QCoreApplication::arguments().at(2).toULongLong(); + quint64 libraryId = QCoreApplication::arguments().at(3).toULongLong(); + int page = QCoreApplication::arguments().at(4).toULongLong(); + + QFileInfo fi(pathFile); enableActions(); + + //TODO request data to the server + ComicDB comic; + comic.id = comicId; + YACReaderLocalClient client; - viewer->open(pathFile); - - } + //if(client.requestComicInfo(libraryId,comic)) + { + if(comic.info.title == 0 || comic.info.title->isEmpty() ) + setWindowTitle("YACReader - " + fi.fileName()); + else + setWindowTitle("YACReader - " + *comic.info.title); + } + //else + setWindowTitle("YACReader : " + fi.fileName()); + viewer->open(pathFile,page); + } */ versionChecker = new HttpVersionChecker(); diff --git a/YACReader/render.cpp b/YACReader/render.cpp index 9e783bda..b728f537 100644 --- a/YACReader/render.cpp +++ b/YACReader/render.cpp @@ -564,7 +564,7 @@ void Render::update() //----------------------------------------------------------------------------- // Comic interface //----------------------------------------------------------------------------- -void Render::load(const QString & path) +void Render::load(const QString & path, int atPage) { if(comic!=0) { @@ -612,7 +612,7 @@ void Render::load(const QString & path) pagesReady.clear(); - comic->load(path); //garantiza que se va a intentar abrir el cómic + comic->load(path,atPage); //garantiza que se va a intentar abrir el cómic if(thread != NULL) thread->start(); diff --git a/YACReader/render.h b/YACReader/render.h index 495a2b1c..c2ade034 100644 --- a/YACReader/render.h +++ b/YACReader/render.h @@ -132,7 +132,7 @@ public slots: //--comic interface void nextPage(); void previousPage(); - void load(const QString & path); + void load(const QString & path, int atPage); void rotateRight(); void rotateLeft(); unsigned int getIndex(); diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index c8c17c24..d304332b 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -156,14 +156,14 @@ void Viewer::createConnections() connect(render,SIGNAL(bookmarksUpdated()),this,SLOT(setBookmarks())); } -void Viewer::open(QString pathFile) +void Viewer::open(QString pathFile, int atPage) { if(render->hasLoadedComic()) save(); //bd->setBookmarks(*bm); goToFlow->reset(); - render->load(pathFile); + render->load(pathFile, atPage); //render->update(); verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum()); diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 505d594b..6b46b72e 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -35,7 +35,7 @@ class NotificationsLabelWidget; public: bool fullscreen; //TODO, change by the right use of windowState(); public slots: - void open(QString pathFile); + void open(QString pathFile, int atPage = -1); void prev(); void next(); void showGoToDialog(); diff --git a/YACReader/yacreader_local_client.cpp b/YACReader/yacreader_local_client.cpp index acae1262..ad03f2f6 100644 --- a/YACReader/yacreader_local_client.cpp +++ b/YACReader/yacreader_local_client.cpp @@ -1,5 +1,6 @@ #include "yacreader_local_client.h" #include "comic_db.h" +#include "yacreader_global.h" #include @@ -9,6 +10,7 @@ YACReaderLocalClient::YACReaderLocalClient(QObject *parent) : localSocket = new QLocalSocket(this); connect(localSocket, SIGNAL(readyRead()), this, SLOT(readMessage())); + /*connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(displayError(QLocalSocket::LocalSocketError)));*/ } @@ -19,12 +21,45 @@ void YACReaderLocalClient::readMessage() } -void YACReaderLocalClient::requestComicInfo(QString library, ComicDB & comic) +bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic) { + localSocket->connectToServer(YACREADERLIBRARY_GUID); + if(localSocket->isOpen()) + { + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_4_0); + out << (quint16)0; + out << libraryId; + out << comic; + out.device()->seek(0); + out << (quint16)(block.size() - sizeof(quint16)); + int written = 0; + while(written != block.size()) + { + written += localSocket->write(block); + localSocket->flush(); + } + localSocket->waitForReadyRead(); + QByteArray data; + QDataStream in(data); + in.setVersion(QDataStream::Qt_4_0); + int totalSize = 0; + while((data.size()-sizeof(quint16)) != totalSize ) + { + data.append(localSocket->read(1000000000)); + if(data.size()>=sizeof(quint16) && totalSize == 0) + in >> totalSize; + } + in >> comic; + return true; + } + else + return false; } -void YACReaderLocalClient::sendComicInfo(QString library, ComicDB & comic) +bool YACReaderLocalClient::sendComicInfo(quint64 libraryId, ComicDB & comic) { - + return true; } diff --git a/YACReader/yacreader_local_client.h b/YACReader/yacreader_local_client.h index 7c230f87..96de6693 100644 --- a/YACReader/yacreader_local_client.h +++ b/YACReader/yacreader_local_client.h @@ -16,8 +16,8 @@ signals: public slots: void readMessage(); - void requestComicInfo(QString library, ComicDB & comic); - void sendComicInfo(QString library, ComicDB & comic); + bool requestComicInfo(quint64 libraryId, ComicDB & comic); + bool sendComicInfo(quint64 libraryId, ComicDB & comic); private: QLocalSocket * localSocket; diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index a2f054e3..5b166716 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -1004,15 +1004,20 @@ void LibraryWindow::openComic() { if(!importedCovers) { - QString path = currentPath() + dmCV->getComicPath(comicView->currentIndex()); + ComicDB comic = dmCV->getComic(comicView->currentIndex()); + QString path = currentPath() + comic.path; + /*quint64 comicId = comic.id; + //TODO generate IDS for libraries... + quint64 libraryId = selectedLibrary->currentIndex(); + int page = *(comic.info.numPages) / 2;*/ #ifdef Q_OS_MAC - QProcess::startDetached("open", QStringList() << "-n" << QDir::cleanPath(QCoreApplication::applicationDirPath()+"/../../../YACReader.app") << "--args" << path);//,QStringList() << path); + QProcess::startDetached("open", QStringList() << "-n" << QDir::cleanPath(QCoreApplication::applicationDirPath()+"/../../../YACReader.app") << "--args" << path /*<< comicId << libraryId << page*/);//,QStringList() << path); //Comic is readed #else - QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+QString("/YACReader \"%1\"").arg(path),QStringList()); + QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+QString("/YACReader \"%1\"").arg(path)/*.arg(comicId).arg(libraryId).arg(page)*/,QStringList()); #endif //Comic is readed setCurrentComicReaded(); diff --git a/YACReaderLibrary/yacreader_local_server.cpp b/YACReaderLibrary/yacreader_local_server.cpp index b9db83fa..d4d8c1db 100644 --- a/YACReaderLibrary/yacreader_local_server.cpp +++ b/YACReaderLibrary/yacreader_local_server.cpp @@ -4,6 +4,9 @@ #include #include "yacreader_global.h" +#include "db_helper.h" + +#include "comic_db.h" YACReaderLocalServer::YACReaderLocalServer(QObject *parent) : QObject(parent) @@ -49,24 +52,52 @@ void YACReaderLocalServer::sendResponse() clientConnection->flush(); clientConnection->disconnectFromServer();*/ - QByteArray block; - QDataStream out(&block, QIODevice::WriteOnly); - out.setVersion(QDataStream::Qt_4_0); - out << (quint16)0; - out << QString("ok"); - out.device()->seek(0); - out << (quint16)(block.size() - sizeof(quint16)); - QLocalSocket *clientConnection = localServer->nextPendingConnection(); connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater())); - clientConnection->write(block); - clientConnection->flush(); + quint64 libraryId; + ComicDB comic; + clientConnection->waitForReadyRead(); + QByteArray data; + QDataStream inputStream(data); + inputStream.setVersion(QDataStream::Qt_4_0); + int totalSize = 0; + while((data.size()-sizeof(quint16)) != totalSize ) + { + data.append(clientConnection->read(1000000000)); + if(data.size()>=sizeof(quint16) && totalSize == 0) + inputStream >> totalSize; + } + inputStream >> libraryId; + inputStream >> comic; + + getComicInfo(libraryId,comic); + + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_4_0); + out << (quint16)0; + out << comic; + out.device()->seek(0); + out << (quint16)(block.size() - sizeof(quint16)); + + int written = 0; + while(written != block.size()) + { + written += clientConnection->write(block); + clientConnection->flush(); + } + //clientConnection->waitForBytesWritten(); clientConnection->disconnectFromServer(); } +void YACReaderLocalServer::getComicInfo(quint64 libraryId, ComicDB & comic) +{ + comic = DBHelper::getComicInfo(DBHelper::getLibrariesNames().at(libraryId), comic.id); +} + bool YACReaderLocalServer::isRunning() { QLocalSocket socket; diff --git a/YACReaderLibrary/yacreader_local_server.h b/YACReaderLibrary/yacreader_local_server.h index 8f4845e6..a48be198 100644 --- a/YACReaderLibrary/yacreader_local_server.h +++ b/YACReaderLibrary/yacreader_local_server.h @@ -4,6 +4,7 @@ #include class QLocalServer; +class ComicDB; class YACReaderLocalServer : public QObject { @@ -17,7 +18,7 @@ public slots: bool isListening(); void sendResponse(); static bool isRunning(); - + void getComicInfo(quint64 libraryId, ComicDB & comic); private: QLocalServer * localServer; diff --git a/common/comic_db.cpp b/common/comic_db.cpp index 55aaa5b7..eb3c1742 100644 --- a/common/comic_db.cpp +++ b/common/comic_db.cpp @@ -405,4 +405,163 @@ QPixmap ComicInfo::getCover(const QString & basePath) QPixmap c; c.convertFromImage(cover); return c; +} +QDataStream &operator<<(QDataStream & stream, const ComicDB & comic) +{ + stream << comic.id; + stream << comic.name; + stream << comic.parentId; + stream << comic.path; + stream << comic._hasCover; + stream << comic.info; + return stream; +} + +QDataStream &operator>>(QDataStream & stream, ComicDB & comic) +{ + stream >> comic.id; + stream >> comic.name; + stream >> comic.parentId; + stream >> comic.path; + stream >> comic._hasCover; + stream >> comic.info; + return stream; +} + +void serializeField(QDataStream & stream, QString * field) +{ + stream << (field!=0); + if (field!=0) stream << *field; +} + +void serializeField(QDataStream & stream, int * field) +{ + stream << (field!=0); + if (field!=0) stream << *field; +} + +void serializeField(QDataStream & stream, bool * field) +{ + stream << (field!=0); + if (field!=0) stream << *field; +} + +void deserializeField(QDataStream & stream, QString * & field) +{ + bool isData; + stream >> isData; + if(isData) + { + field = new QString(); + stream >> *field; + } +} + +void deserializeField(QDataStream & stream, int * & field) +{ + bool isData; + stream >> isData; + if(isData) + { + field = new int; + stream >> *field; + } +} + +void deserializeField(QDataStream & stream, bool * & field) +{ + bool isData; + stream >> isData; + if(isData) + { + field = new bool; + stream >> *field; + } +} + + +QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo) +{ + stream << comicInfo.id; + stream << comicInfo.read; + stream << comicInfo.edited; + stream << comicInfo.hash; + stream << comicInfo.existOnDb; + + serializeField(stream,comicInfo.title); + + serializeField(stream,comicInfo.coverPage); + serializeField(stream,comicInfo.numPages); + + serializeField(stream,comicInfo.number); + serializeField(stream,comicInfo.isBis); + serializeField(stream,comicInfo.count); + + serializeField(stream,comicInfo.volume); + serializeField(stream,comicInfo.storyArc); + serializeField(stream,comicInfo.arcNumber); + serializeField(stream,comicInfo.arcCount); + + serializeField(stream,comicInfo.genere); + + serializeField(stream,comicInfo.writer); + serializeField(stream,comicInfo.penciller); + serializeField(stream,comicInfo.inker); + serializeField(stream,comicInfo.colorist); + serializeField(stream,comicInfo.letterer); + serializeField(stream,comicInfo.coverArtist); + + serializeField(stream,comicInfo.date); + serializeField(stream,comicInfo.publisher); + serializeField(stream,comicInfo.format); + serializeField(stream,comicInfo.color); + serializeField(stream,comicInfo.ageRating); + + serializeField(stream,comicInfo.synopsis); + serializeField(stream,comicInfo.characters); + serializeField(stream,comicInfo.notes); + return stream; +} + +QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo) +{ + stream >> comicInfo.id; + stream >> comicInfo.read; + stream >> comicInfo.edited; + stream >> comicInfo.hash; + stream >> comicInfo.existOnDb; + + deserializeField(stream,comicInfo.title); + + deserializeField(stream,comicInfo.coverPage); + deserializeField(stream,comicInfo.numPages); + + deserializeField(stream,comicInfo.number); + deserializeField(stream,comicInfo.isBis); + deserializeField(stream,comicInfo.count); + + deserializeField(stream,comicInfo.volume); + deserializeField(stream,comicInfo.storyArc); + deserializeField(stream,comicInfo.arcNumber); + deserializeField(stream,comicInfo.arcCount); + + deserializeField(stream,comicInfo.genere); + + deserializeField(stream,comicInfo.writer); + deserializeField(stream,comicInfo.penciller); + deserializeField(stream,comicInfo.inker); + deserializeField(stream,comicInfo.colorist); + deserializeField(stream,comicInfo.letterer); + deserializeField(stream,comicInfo.coverArtist); + + deserializeField(stream,comicInfo.date); + deserializeField(stream,comicInfo.publisher); + deserializeField(stream,comicInfo.format); + deserializeField(stream,comicInfo.color); + deserializeField(stream,comicInfo.ageRating); + + deserializeField(stream,comicInfo.synopsis); + deserializeField(stream,comicInfo.characters); + deserializeField(stream,comicInfo.notes); + return stream; } \ No newline at end of file diff --git a/common/comic_db.h b/common/comic_db.h index 93142cbe..b9fed60f 100644 --- a/common/comic_db.h +++ b/common/comic_db.h @@ -91,6 +91,10 @@ public: QPixmap getCover(const QString & basePath); + friend QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo); + + friend QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo); + private: void setValue(QString * & field, const QString & value); void setValue(int * & field, int value); @@ -115,6 +119,9 @@ public: QString toTXT(); ComicInfo info; + + friend QDataStream &operator<<(QDataStream &, const ComicDB &); + friend QDataStream &operator>>(QDataStream &, ComicDB &); };