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

@ -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<bool>(nPages,false);
_firstPage = bm->getLastPage();
_index = bm->getLastPage();
if(_firstPage == -1)
_firstPage = bm->getLastPage();
_index = _firstPage;
emit(openAt(_index));
for(int i=_index;i<nPages;i++)

View File

@ -38,11 +38,11 @@
//Constructors
Comic();
Comic(const QString & pathFile);
Comic(const QString & pathFile, int atPage = -1);
~Comic();
void setup();
//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 loadFromDir(const QString & pathDir);
@ -90,10 +90,10 @@
QList<QVector<quint32> > 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();
};

View File

@ -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 <ctime>
#include <algorithm>
@ -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();

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
#include "yacreader_local_client.h"
#include "comic_db.h"
#include "yacreader_global.h"
#include <QLocalSocket>
@ -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;
}

View File

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