mirror of
https://github.com/YACReader/yacreader
synced 2025-07-22 23:15:14 -04:00
server/client local ipc working fine
This commit is contained in:
@ -188,7 +188,7 @@ FileComic::FileComic(const QString & path, int atPage )
|
||||
|
||||
FileComic::~FileComic()
|
||||
{
|
||||
_pages.clear();
|
||||
|
||||
}
|
||||
|
||||
bool FileComic::load(const QString & path, int atPage)
|
||||
|
@ -156,42 +156,40 @@ void MainWindowViewer::setupUI()
|
||||
{
|
||||
//TODO: new method open(QString)
|
||||
QString pathFile = QCoreApplication::arguments().at(1);
|
||||
currentDirectory = pathFile;
|
||||
QFileInfo fi(pathFile);
|
||||
currentDirectory = fi.absoluteDir().path();
|
||||
getSiblingComics(fi.absolutePath(),fi.fileName());
|
||||
|
||||
setWindowTitle("YACReader - " + fi.fileName());
|
||||
enableActions();
|
||||
viewer->open(pathFile);
|
||||
}
|
||||
/*else if(QCoreApplication::argc() == 5)
|
||||
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;
|
||||
|
||||
currentComicDB.id = comicId;
|
||||
YACReaderLocalClient client;
|
||||
|
||||
//if(client.requestComicInfo(libraryId,comic))
|
||||
if(client.requestComicInfo(libraryId,currentComicDB,siblingComics))
|
||||
{
|
||||
if(comic.info.title == 0 || comic.info.title->isEmpty() )
|
||||
setWindowTitle("YACReader - " + fi.fileName());
|
||||
if(currentComicDB.info.title == 0 || currentComicDB.info.title->isEmpty() )
|
||||
setWindowTitle("YACReader - " + currentComicDB.path);
|
||||
else
|
||||
setWindowTitle("YACReader - " + *comic.info.title);
|
||||
setWindowTitle("YACReader - " + *currentComicDB.info.title);
|
||||
}
|
||||
//else
|
||||
setWindowTitle("YACReader : " + fi.fileName());
|
||||
viewer->open(pathFile,page);
|
||||
} */
|
||||
else
|
||||
setWindowTitle("YACReader : " + currentComicDB.path);
|
||||
open(pathFile+currentComicDB.path,currentComicDB,siblingComics);
|
||||
}
|
||||
|
||||
versionChecker = new HttpVersionChecker();
|
||||
|
||||
@ -594,11 +592,10 @@ void MainWindowViewer::open()
|
||||
|
||||
void MainWindowViewer::open(QString path, ComicDB & comic, QList<ComicDB> & siblings)
|
||||
{
|
||||
currentComicDB = comic;
|
||||
siblingComics = siblings;
|
||||
//currentComicDB = comic;
|
||||
//siblingComics = siblings;
|
||||
|
||||
QFileInfo fi(path);
|
||||
currentDirectory = fi.absoluteDir().path();
|
||||
|
||||
if(comic.info.title != 0 && !comic.info.title->isEmpty())
|
||||
setWindowTitle("YACReader - " + *comic.info.title);
|
||||
@ -866,8 +863,8 @@ void MainWindowViewer::openPreviousComic()
|
||||
if(!siblingComics.isEmpty())
|
||||
{
|
||||
int currentIndex = siblingComics.indexOf(currentComicDB);
|
||||
ComicDB previoiusComic = siblingComics.at(currentIndex-1);
|
||||
open(currentDirectory+previoiusComic.path,previoiusComic,siblingComics);
|
||||
currentComicDB = siblingComics.at(currentIndex-1);
|
||||
open(currentDirectory+currentComicDB.path,currentComicDB,siblingComics);
|
||||
return;
|
||||
}
|
||||
if(!previousComicPath.isEmpty())
|
||||
@ -885,8 +882,9 @@ void MainWindowViewer::openNextComic()
|
||||
if(!siblingComics.isEmpty())
|
||||
{
|
||||
int currentIndex = siblingComics.indexOf(currentComicDB);
|
||||
ComicDB nextComic = siblingComics.at(currentIndex+1);
|
||||
open(currentDirectory+nextComic.path,nextComic,siblingComics);
|
||||
if(currentIndex+1 > 0 && currentIndex+1 < siblingComics.count())
|
||||
currentComicDB = siblingComics.at(currentIndex+1);
|
||||
open(currentDirectory+currentComicDB.path,currentComicDB,siblingComics);
|
||||
return;
|
||||
}
|
||||
if(!nextComicPath.isEmpty())
|
||||
|
@ -9,7 +9,7 @@ YACReaderLocalClient::YACReaderLocalClient(QObject *parent) :
|
||||
{
|
||||
localSocket = new QLocalSocket(this);
|
||||
|
||||
connect(localSocket, SIGNAL(readyRead()), this, SLOT(readMessage()));
|
||||
//connect(localSocket, SIGNAL(readyRead()), this, SLOT(readMessage()));
|
||||
|
||||
/*connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)),
|
||||
this, SLOT(displayError(QLocalSocket::LocalSocketError)));*/
|
||||
@ -20,16 +20,22 @@ void YACReaderLocalClient::readMessage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic)
|
||||
#include <QFile>
|
||||
bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & siblings)
|
||||
{
|
||||
localSocket->connectToServer(YACREADERLIBRARY_GUID);
|
||||
if(localSocket->isOpen())
|
||||
{
|
||||
QFile f("c:/temp/socket.txt");
|
||||
f.open(QIODevice::WriteOnly);
|
||||
QTextStream outt(&f);
|
||||
outt << QString(" antes : %1").arg(comic.id) << endl;
|
||||
|
||||
QByteArray block;
|
||||
QDataStream out(&block, QIODevice::WriteOnly);
|
||||
out.setVersion(QDataStream::Qt_4_0);
|
||||
out.setVersion(QDataStream::Qt_4_8);
|
||||
out << (quint16)0;
|
||||
out << (quint8)YACReaderIPCMessages::RequestComicInfo;
|
||||
out << libraryId;
|
||||
out << comic;
|
||||
out.device()->seek(0);
|
||||
@ -41,18 +47,23 @@ bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic)
|
||||
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 )
|
||||
|
||||
//QByteArray data;
|
||||
while(localSocket->bytesAvailable() < sizeof(quint16))
|
||||
localSocket->waitForReadyRead();
|
||||
QDataStream sizeStream(localSocket->read(sizeof(quint16)));
|
||||
sizeStream.setVersion(QDataStream::Qt_4_8);
|
||||
quint16 totalSize = 0;
|
||||
sizeStream >> totalSize;
|
||||
|
||||
while(localSocket->bytesAvailable() < totalSize )
|
||||
{
|
||||
data.append(localSocket->read(1000000000));
|
||||
if(data.size()>=sizeof(quint16) && totalSize == 0)
|
||||
in >> totalSize;
|
||||
localSocket->waitForReadyRead();
|
||||
}
|
||||
in >> comic;
|
||||
QDataStream dataStream(localSocket->read(totalSize));
|
||||
dataStream >> comic;
|
||||
dataStream >> siblings;
|
||||
outt << QString(" despues : %1").arg(comic.id) << endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -16,7 +16,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
void readMessage();
|
||||
bool requestComicInfo(quint64 libraryId, ComicDB & comic);
|
||||
bool requestComicInfo(quint64 libraryId, ComicDB & comic,QList<ComicDB> & siblings);
|
||||
bool sendComicInfo(quint64 libraryId, ComicDB & comic);
|
||||
|
||||
private:
|
||||
|
Reference in New Issue
Block a user