load(path,atPage) added in viewer,render and comic classes

updated CHANGELOG
This commit is contained in:
Luis Ángel San Martín 2013-07-16 21:50:02 +02:00
parent e7fa648461
commit e886f160cc
15 changed files with 352 additions and 63 deletions

View File

@ -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 6.5
Nueva interfaz principal de YACReaderLibrary y YACReader Nueva interfaz principal de YACReaderLibrary y YACReader
Corregido bug que causaba que el servidor no se activase en el primer arranque en MacOSX Corregido bug que causaba que el servidor no se activase en el primer arranque en MacOSX

View File

@ -19,8 +19,8 @@ Comic::Comic()
setup(); setup();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
Comic::Comic(const QString & pathFile) Comic::Comic(const QString & pathFile, int atPage )
:_pages(),_index(0),_path(pathFile),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false) :_pages(),_index(0),_path(pathFile),_loaded(false),bm(new Bookmarks()),_loadedPages(),_isPDF(false),_firstPage(atPage)
{ {
setup(); setup();
} }
@ -180,10 +180,10 @@ FileComic::FileComic()
} }
FileComic::FileComic(const QString & path) FileComic::FileComic(const QString & path, int atPage )
:Comic(path) :Comic(path,atPage)
{ {
load(path); load(path,atPage);
} }
FileComic::~FileComic() FileComic::~FileComic()
@ -191,14 +191,18 @@ FileComic::~FileComic()
//Comic::~Comic(); //Comic::~Comic();
} }
bool FileComic::load(const QString & path) bool FileComic::load(const QString & path, int atPage)
{ {
QFileInfo fi(path); QFileInfo fi(path);
if(fi.exists()) if(fi.exists())
{ {
bm->newComic(path); if(atPage == -1)
emit bookmarksUpdated(); {
bm->newComic(path);
emit bookmarksUpdated();
}
_firstPage = atPage;
//emit bookmarksLoaded(*bm); //emit bookmarksLoaded(*bm);
_path = QDir::cleanPath(path); _path = QDir::cleanPath(path);
@ -393,8 +397,9 @@ void FileComic::process()
out << "tiempo en ordenar : " << myTimer.elapsed() << endl; out << "tiempo en ordenar : " << myTimer.elapsed() << endl;
_firstPage = bm->getLastPage(); if(_firstPage == -1)
_index = bm->getLastPage(); _firstPage = bm->getLastPage();
_index = _firstPage;
emit(openAt(_index)); emit(openAt(_index));
int sectionIndex; int sectionIndex;
@ -463,10 +468,10 @@ FolderComic::FolderComic()
} }
FolderComic::FolderComic(const QString & path) FolderComic::FolderComic(const QString & path, int atPage )
:Comic(path) :Comic(path, atPage )
{ {
load(path); load(path, atPage );
} }
FolderComic::~FolderComic() FolderComic::~FolderComic()
@ -474,11 +479,15 @@ FolderComic::~FolderComic()
} }
bool FolderComic::load(const QString & path) bool FolderComic::load(const QString & path, int atPage )
{ {
_path = path; _path = path;
bm->newComic(_path); if(atPage == -1)
emit bookmarksUpdated(); {
bm->newComic(_path);
emit bookmarksUpdated();
}
_firstPage = atPage;
//emit bookmarksLoaded(*bm); //emit bookmarksLoaded(*bm);
return true; return true;
} }
@ -508,8 +517,11 @@ void FolderComic::process()
} }
else else
{ {
_firstPage = bm->getLastPage(); if(_firstPage == -1)
_index = bm->getLastPage(); _firstPage = bm->getLastPage();
_index = _firstPage;
emit(openAt(_index)); emit(openAt(_index));
emit pageChanged(0); // this indicates new comic, index=0 emit pageChanged(0); // this indicates new comic, index=0
@ -544,10 +556,10 @@ PDFComic::PDFComic()
} }
PDFComic::PDFComic(const QString & path) PDFComic::PDFComic(const QString & path, int atPage)
:Comic(path) :Comic(path,atPage)
{ {
load(path); load(path,atPage);
} }
PDFComic::~PDFComic() PDFComic::~PDFComic()
@ -555,11 +567,15 @@ PDFComic::~PDFComic()
} }
bool PDFComic::load(const QString & path) bool PDFComic::load(const QString & path, int atPage)
{ {
_path = path; _path = path;
bm->newComic(_path); if(atPage == -1)
emit bookmarksUpdated(); {
bm->newComic(_path);
emit bookmarksUpdated();
}
_firstPage = atPage;
//emit bookmarksLoaded(*bm); //emit bookmarksLoaded(*bm);
return true; return true;
} }
@ -590,8 +606,9 @@ void PDFComic::process()
_pages.resize(nPages); _pages.resize(nPages);
_loadedPages = QVector<bool>(nPages,false); _loadedPages = QVector<bool>(nPages,false);
_firstPage = bm->getLastPage(); if(_firstPage == -1)
_index = bm->getLastPage(); _firstPage = bm->getLastPage();
_index = _firstPage;
emit(openAt(_index)); emit(openAt(_index));
for(int i=_index;i<nPages;i++) for(int i=_index;i<nPages;i++)

View File

@ -38,11 +38,11 @@
//Constructors //Constructors
Comic(); Comic();
Comic(const QString & pathFile); Comic(const QString & pathFile, int atPage = -1);
~Comic(); ~Comic();
void setup(); void setup();
//Load pages from file //Load pages from file
virtual bool load(const QString & path) = 0; virtual bool load(const QString & path, int atPage = -1) = 0;
/*void loadFromFile(const QString & pathFile); /*void loadFromFile(const QString & pathFile);
void loadFromDir(const QString & pathDir); void loadFromDir(const QString & pathDir);
@ -90,10 +90,10 @@
QList<QVector<quint32> > getSections(int & sectionIndex); QList<QVector<quint32> > getSections(int & sectionIndex);
public: public:
FileComic(); FileComic();
FileComic(const QString & path); FileComic(const QString & path, int atPage = -1);
~FileComic(); ~FileComic();
void fileExtracted(int index, const QByteArray & rawData); void fileExtracted(int index, const QByteArray & rawData);
virtual bool load(const QString & path); virtual bool load(const QString & path, int atPage = -1);
public slots: public slots:
void process(); void process();
@ -109,10 +109,10 @@
//void run(); //void run();
public: public:
FolderComic(); FolderComic();
FolderComic(const QString & path); FolderComic(const QString & path, int atPage = -1);
~FolderComic(); ~FolderComic();
virtual bool load(const QString & path); virtual bool load(const QString & path, int atPage = -1);
public slots: public slots:
void process(); void process();
@ -129,10 +129,10 @@
//void run(); //void run();
public: public:
PDFComic(); PDFComic();
PDFComic(const QString & path); PDFComic(const QString & path, int atPage = -1);
~PDFComic(); ~PDFComic();
virtual bool load(const QString & path); virtual bool load(const QString & path, int atPage = -1);
public slots: public slots:
void process(); void process();
}; };

View File

@ -13,6 +13,9 @@
#include "help_about_dialog.h" #include "help_about_dialog.h"
#include "yacreader_tool_bar_stretch.h" #include "yacreader_tool_bar_stretch.h"
#include "comic_db.h"
#include "yacreader_local_client.h"
#include <ctime> #include <ctime>
#include <algorithm> #include <algorithm>
@ -115,7 +118,7 @@ void MainWindowViewer::setupUI()
setWindowTitle("YACReader"); setWindowTitle("YACReader");
if(QCoreApplication::argc()>1) if(QCoreApplication::argc() == 2) //only path...
{ {
//TODO: new method open(QString) //TODO: new method open(QString)
QString pathFile = QCoreApplication::arguments().at(1); QString pathFile = QCoreApplication::arguments().at(1);
@ -124,12 +127,37 @@ void MainWindowViewer::setupUI()
getSiblingComics(fi.absolutePath(),fi.fileName()); getSiblingComics(fi.absolutePath(),fi.fileName());
setWindowTitle("YACReader - " + 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(); 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(); versionChecker = new HttpVersionChecker();

View File

@ -564,7 +564,7 @@ void Render::update()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Comic interface // Comic interface
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Render::load(const QString & path) void Render::load(const QString & path, int atPage)
{ {
if(comic!=0) if(comic!=0)
{ {
@ -612,7 +612,7 @@ void Render::load(const QString & path)
pagesReady.clear(); 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) if(thread != NULL)
thread->start(); thread->start();

View File

@ -132,7 +132,7 @@ public slots:
//--comic interface //--comic interface
void nextPage(); void nextPage();
void previousPage(); void previousPage();
void load(const QString & path); void load(const QString & path, int atPage);
void rotateRight(); void rotateRight();
void rotateLeft(); void rotateLeft();
unsigned int getIndex(); unsigned int getIndex();

View File

@ -156,14 +156,14 @@ void Viewer::createConnections()
connect(render,SIGNAL(bookmarksUpdated()),this,SLOT(setBookmarks())); connect(render,SIGNAL(bookmarksUpdated()),this,SLOT(setBookmarks()));
} }
void Viewer::open(QString pathFile) void Viewer::open(QString pathFile, int atPage)
{ {
if(render->hasLoadedComic()) if(render->hasLoadedComic())
save(); save();
//bd->setBookmarks(*bm); //bd->setBookmarks(*bm);
goToFlow->reset(); goToFlow->reset();
render->load(pathFile); render->load(pathFile, atPage);
//render->update(); //render->update();
verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum()); verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum());

View File

@ -35,7 +35,7 @@ class NotificationsLabelWidget;
public: public:
bool fullscreen; //TODO, change by the right use of windowState(); bool fullscreen; //TODO, change by the right use of windowState();
public slots: public slots:
void open(QString pathFile); void open(QString pathFile, int atPage = -1);
void prev(); void prev();
void next(); void next();
void showGoToDialog(); void showGoToDialog();

View File

@ -1,5 +1,6 @@
#include "yacreader_local_client.h" #include "yacreader_local_client.h"
#include "comic_db.h" #include "comic_db.h"
#include "yacreader_global.h"
#include <QLocalSocket> #include <QLocalSocket>
@ -9,6 +10,7 @@ YACReaderLocalClient::YACReaderLocalClient(QObject *parent) :
localSocket = new QLocalSocket(this); localSocket = new QLocalSocket(this);
connect(localSocket, SIGNAL(readyRead()), this, SLOT(readMessage())); connect(localSocket, SIGNAL(readyRead()), this, SLOT(readMessage()));
/*connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)), /*connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)),
this, SLOT(displayError(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;
} }

View File

@ -16,8 +16,8 @@ signals:
public slots: public slots:
void readMessage(); void readMessage();
void requestComicInfo(QString library, ComicDB & comic); bool requestComicInfo(quint64 libraryId, ComicDB & comic);
void sendComicInfo(QString library, ComicDB & comic); bool sendComicInfo(quint64 libraryId, ComicDB & comic);
private: private:
QLocalSocket * localSocket; QLocalSocket * localSocket;

View File

@ -1004,15 +1004,20 @@ void LibraryWindow::openComic()
{ {
if(!importedCovers) 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 #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 //Comic is readed
#else #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 #endif
//Comic is readed //Comic is readed
setCurrentComicReaded(); setCurrentComicReaded();

View File

@ -4,6 +4,9 @@
#include <QLocalSocket> #include <QLocalSocket>
#include "yacreader_global.h" #include "yacreader_global.h"
#include "db_helper.h"
#include "comic_db.h"
YACReaderLocalServer::YACReaderLocalServer(QObject *parent) : YACReaderLocalServer::YACReaderLocalServer(QObject *parent) :
QObject(parent) QObject(parent)
@ -49,24 +52,52 @@ void YACReaderLocalServer::sendResponse()
clientConnection->flush(); clientConnection->flush();
clientConnection->disconnectFromServer();*/ 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(); QLocalSocket *clientConnection = localServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()), connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater())); clientConnection, SLOT(deleteLater()));
clientConnection->write(block); quint64 libraryId;
clientConnection->flush(); 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(); clientConnection->disconnectFromServer();
} }
void YACReaderLocalServer::getComicInfo(quint64 libraryId, ComicDB & comic)
{
comic = DBHelper::getComicInfo(DBHelper::getLibrariesNames().at(libraryId), comic.id);
}
bool YACReaderLocalServer::isRunning() bool YACReaderLocalServer::isRunning()
{ {
QLocalSocket socket; QLocalSocket socket;

View File

@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
class QLocalServer; class QLocalServer;
class ComicDB;
class YACReaderLocalServer : public QObject class YACReaderLocalServer : public QObject
{ {
@ -17,7 +18,7 @@ public slots:
bool isListening(); bool isListening();
void sendResponse(); void sendResponse();
static bool isRunning(); static bool isRunning();
void getComicInfo(quint64 libraryId, ComicDB & comic);
private: private:
QLocalServer * localServer; QLocalServer * localServer;

View File

@ -405,4 +405,163 @@ QPixmap ComicInfo::getCover(const QString & basePath)
QPixmap c; QPixmap c;
c.convertFromImage(cover); c.convertFromImage(cover);
return c; 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;
} }

View File

@ -91,6 +91,10 @@ public:
QPixmap getCover(const QString & basePath); QPixmap getCover(const QString & basePath);
friend QDataStream &operator<<(QDataStream & stream, const ComicInfo & comicInfo);
friend QDataStream &operator>>(QDataStream & stream, ComicInfo & comicInfo);
private: private:
void setValue(QString * & field, const QString & value); void setValue(QString * & field, const QString & value);
void setValue(int * & field, int value); void setValue(int * & field, int value);
@ -115,6 +119,9 @@ public:
QString toTXT(); QString toTXT();
ComicInfo info; ComicInfo info;
friend QDataStream &operator<<(QDataStream &, const ComicDB &);
friend QDataStream &operator>>(QDataStream &, ComicDB &);
}; };