mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
server/client local ipc working fine
This commit is contained in:
parent
a0f2571711
commit
bf8c0109eb
@ -188,7 +188,7 @@ FileComic::FileComic(const QString & path, int atPage )
|
|||||||
|
|
||||||
FileComic::~FileComic()
|
FileComic::~FileComic()
|
||||||
{
|
{
|
||||||
_pages.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileComic::load(const QString & path, int atPage)
|
bool FileComic::load(const QString & path, int atPage)
|
||||||
|
@ -156,42 +156,40 @@ void MainWindowViewer::setupUI()
|
|||||||
{
|
{
|
||||||
//TODO: new method open(QString)
|
//TODO: new method open(QString)
|
||||||
QString pathFile = QCoreApplication::arguments().at(1);
|
QString pathFile = QCoreApplication::arguments().at(1);
|
||||||
currentDirectory = pathFile;
|
|
||||||
QFileInfo fi(pathFile);
|
QFileInfo fi(pathFile);
|
||||||
|
currentDirectory = fi.absoluteDir().path();
|
||||||
getSiblingComics(fi.absolutePath(),fi.fileName());
|
getSiblingComics(fi.absolutePath(),fi.fileName());
|
||||||
|
|
||||||
setWindowTitle("YACReader - " + fi.fileName());
|
setWindowTitle("YACReader - " + fi.fileName());
|
||||||
enableActions();
|
enableActions();
|
||||||
viewer->open(pathFile);
|
viewer->open(pathFile);
|
||||||
}
|
}
|
||||||
/*else if(QCoreApplication::argc() == 5)
|
else if(QCoreApplication::argc() == 5)
|
||||||
{
|
{
|
||||||
QString pathFile = QCoreApplication::arguments().at(1);
|
QString pathFile = QCoreApplication::arguments().at(1);
|
||||||
currentDirectory = pathFile;
|
currentDirectory = pathFile;
|
||||||
quint64 comicId = QCoreApplication::arguments().at(2).toULongLong();
|
quint64 comicId = QCoreApplication::arguments().at(2).toULongLong();
|
||||||
quint64 libraryId = QCoreApplication::arguments().at(3).toULongLong();
|
quint64 libraryId = QCoreApplication::arguments().at(3).toULongLong();
|
||||||
int page = QCoreApplication::arguments().at(4).toULongLong();
|
int page = QCoreApplication::arguments().at(4).toULongLong();
|
||||||
|
|
||||||
QFileInfo fi(pathFile);
|
|
||||||
|
|
||||||
enableActions();
|
enableActions();
|
||||||
|
|
||||||
//TODO request data to the server
|
//TODO request data to the server
|
||||||
ComicDB comic;
|
|
||||||
comic.id = comicId;
|
currentComicDB.id = comicId;
|
||||||
YACReaderLocalClient client;
|
YACReaderLocalClient client;
|
||||||
|
|
||||||
//if(client.requestComicInfo(libraryId,comic))
|
if(client.requestComicInfo(libraryId,currentComicDB,siblingComics))
|
||||||
{
|
{
|
||||||
if(comic.info.title == 0 || comic.info.title->isEmpty() )
|
if(currentComicDB.info.title == 0 || currentComicDB.info.title->isEmpty() )
|
||||||
setWindowTitle("YACReader - " + fi.fileName());
|
setWindowTitle("YACReader - " + currentComicDB.path);
|
||||||
else
|
else
|
||||||
setWindowTitle("YACReader - " + *comic.info.title);
|
setWindowTitle("YACReader - " + *currentComicDB.info.title);
|
||||||
}
|
}
|
||||||
//else
|
else
|
||||||
setWindowTitle("YACReader : " + fi.fileName());
|
setWindowTitle("YACReader : " + currentComicDB.path);
|
||||||
viewer->open(pathFile,page);
|
open(pathFile+currentComicDB.path,currentComicDB,siblingComics);
|
||||||
} */
|
}
|
||||||
|
|
||||||
versionChecker = new HttpVersionChecker();
|
versionChecker = new HttpVersionChecker();
|
||||||
|
|
||||||
@ -594,11 +592,10 @@ void MainWindowViewer::open()
|
|||||||
|
|
||||||
void MainWindowViewer::open(QString path, ComicDB & comic, QList<ComicDB> & siblings)
|
void MainWindowViewer::open(QString path, ComicDB & comic, QList<ComicDB> & siblings)
|
||||||
{
|
{
|
||||||
currentComicDB = comic;
|
//currentComicDB = comic;
|
||||||
siblingComics = siblings;
|
//siblingComics = siblings;
|
||||||
|
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
currentDirectory = fi.absoluteDir().path();
|
|
||||||
|
|
||||||
if(comic.info.title != 0 && !comic.info.title->isEmpty())
|
if(comic.info.title != 0 && !comic.info.title->isEmpty())
|
||||||
setWindowTitle("YACReader - " + *comic.info.title);
|
setWindowTitle("YACReader - " + *comic.info.title);
|
||||||
@ -866,8 +863,8 @@ void MainWindowViewer::openPreviousComic()
|
|||||||
if(!siblingComics.isEmpty())
|
if(!siblingComics.isEmpty())
|
||||||
{
|
{
|
||||||
int currentIndex = siblingComics.indexOf(currentComicDB);
|
int currentIndex = siblingComics.indexOf(currentComicDB);
|
||||||
ComicDB previoiusComic = siblingComics.at(currentIndex-1);
|
currentComicDB = siblingComics.at(currentIndex-1);
|
||||||
open(currentDirectory+previoiusComic.path,previoiusComic,siblingComics);
|
open(currentDirectory+currentComicDB.path,currentComicDB,siblingComics);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!previousComicPath.isEmpty())
|
if(!previousComicPath.isEmpty())
|
||||||
@ -885,8 +882,9 @@ void MainWindowViewer::openNextComic()
|
|||||||
if(!siblingComics.isEmpty())
|
if(!siblingComics.isEmpty())
|
||||||
{
|
{
|
||||||
int currentIndex = siblingComics.indexOf(currentComicDB);
|
int currentIndex = siblingComics.indexOf(currentComicDB);
|
||||||
ComicDB nextComic = siblingComics.at(currentIndex+1);
|
if(currentIndex+1 > 0 && currentIndex+1 < siblingComics.count())
|
||||||
open(currentDirectory+nextComic.path,nextComic,siblingComics);
|
currentComicDB = siblingComics.at(currentIndex+1);
|
||||||
|
open(currentDirectory+currentComicDB.path,currentComicDB,siblingComics);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!nextComicPath.isEmpty())
|
if(!nextComicPath.isEmpty())
|
||||||
|
@ -9,7 +9,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)));*/
|
||||||
@ -20,16 +20,22 @@ void YACReaderLocalClient::readMessage()
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#include <QFile>
|
||||||
bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic)
|
bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & siblings)
|
||||||
{
|
{
|
||||||
localSocket->connectToServer(YACREADERLIBRARY_GUID);
|
localSocket->connectToServer(YACREADERLIBRARY_GUID);
|
||||||
if(localSocket->isOpen())
|
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;
|
QByteArray block;
|
||||||
QDataStream out(&block, QIODevice::WriteOnly);
|
QDataStream out(&block, QIODevice::WriteOnly);
|
||||||
out.setVersion(QDataStream::Qt_4_0);
|
out.setVersion(QDataStream::Qt_4_8);
|
||||||
out << (quint16)0;
|
out << (quint16)0;
|
||||||
|
out << (quint8)YACReaderIPCMessages::RequestComicInfo;
|
||||||
out << libraryId;
|
out << libraryId;
|
||||||
out << comic;
|
out << comic;
|
||||||
out.device()->seek(0);
|
out.device()->seek(0);
|
||||||
@ -41,18 +47,23 @@ bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB & comic)
|
|||||||
written += localSocket->write(block);
|
written += localSocket->write(block);
|
||||||
localSocket->flush();
|
localSocket->flush();
|
||||||
}
|
}
|
||||||
localSocket->waitForReadyRead();
|
|
||||||
QByteArray data;
|
//QByteArray data;
|
||||||
QDataStream in(data);
|
while(localSocket->bytesAvailable() < sizeof(quint16))
|
||||||
in.setVersion(QDataStream::Qt_4_0);
|
localSocket->waitForReadyRead();
|
||||||
int totalSize = 0;
|
QDataStream sizeStream(localSocket->read(sizeof(quint16)));
|
||||||
while((data.size()-sizeof(quint16)) != totalSize )
|
sizeStream.setVersion(QDataStream::Qt_4_8);
|
||||||
|
quint16 totalSize = 0;
|
||||||
|
sizeStream >> totalSize;
|
||||||
|
|
||||||
|
while(localSocket->bytesAvailable() < totalSize )
|
||||||
{
|
{
|
||||||
data.append(localSocket->read(1000000000));
|
localSocket->waitForReadyRead();
|
||||||
if(data.size()>=sizeof(quint16) && totalSize == 0)
|
|
||||||
in >> totalSize;
|
|
||||||
}
|
}
|
||||||
in >> comic;
|
QDataStream dataStream(localSocket->read(totalSize));
|
||||||
|
dataStream >> comic;
|
||||||
|
dataStream >> siblings;
|
||||||
|
outt << QString(" despues : %1").arg(comic.id) << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -16,7 +16,7 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void readMessage();
|
void readMessage();
|
||||||
bool requestComicInfo(quint64 libraryId, ComicDB & comic);
|
bool requestComicInfo(quint64 libraryId, ComicDB & comic,QList<ComicDB> & siblings);
|
||||||
bool sendComicInfo(quint64 libraryId, ComicDB & comic);
|
bool sendComicInfo(quint64 libraryId, ComicDB & comic);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -127,7 +127,7 @@ win32:RESOURCES += images_win.qrc
|
|||||||
unix:!macx:RESOURCES += images_win.qrc
|
unix:!macx:RESOURCES += images_win.qrc
|
||||||
macx:RESOURCES += images_osx.qrc
|
macx:RESOURCES += images_osx.qrc
|
||||||
|
|
||||||
include(../YACReader/YACReader.pri)
|
#include(../YACReader/YACReader.pri)
|
||||||
|
|
||||||
RC_FILE = icon.rc
|
RC_FILE = icon.rc
|
||||||
|
|
||||||
|
@ -105,6 +105,18 @@ ComicDB DBHelper::getComicInfo(const QString & libraryName, qulonglong id)
|
|||||||
QSqlDatabase::removeDatabase(libraryPath);
|
QSqlDatabase::removeDatabase(libraryPath);
|
||||||
return comic;
|
return comic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ComicDB> DBHelper::getSiblings(const QString & libraryName, qulonglong parentId)
|
||||||
|
{
|
||||||
|
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||||
|
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
|
||||||
|
|
||||||
|
QList<ComicDB> comics = DBHelper::getSortedComicsFromParent(parentId,db);
|
||||||
|
db.close();
|
||||||
|
QSqlDatabase::removeDatabase(libraryPath);
|
||||||
|
return comics;
|
||||||
|
}
|
||||||
|
|
||||||
QString DBHelper::getFolderName(const QString & libraryName, qulonglong id)
|
QString DBHelper::getFolderName(const QString & libraryName, qulonglong id)
|
||||||
{
|
{
|
||||||
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
QString libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||||
@ -351,6 +363,55 @@ QList<LibraryItem *> DBHelper::getFoldersFromParent(qulonglong parentId, QSqlDat
|
|||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
QList<ComicDB> DBHelper::getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db)
|
||||||
|
{
|
||||||
|
|
||||||
|
QList <ComicDB> list;
|
||||||
|
|
||||||
|
QSqlQuery selectQuery(db);
|
||||||
|
selectQuery.prepare("select c.id,c.parentId,c.fileName,c.path,ci.hash from comic c inner join comic_info ci on (c.comicInfoId = ci.id) where c.parentId = :parentId");
|
||||||
|
selectQuery.bindValue(":parentId", parentId);
|
||||||
|
selectQuery.exec();
|
||||||
|
|
||||||
|
ComicDB currentItem;
|
||||||
|
while (selectQuery.next())
|
||||||
|
{
|
||||||
|
QList<QVariant> data;
|
||||||
|
QSqlRecord record = selectQuery.record();
|
||||||
|
for(int i=0;i<record.count();i++)
|
||||||
|
data << record.value(i);
|
||||||
|
|
||||||
|
currentItem.id = record.value("id").toULongLong();
|
||||||
|
currentItem.parentId = record.value(1).toULongLong();
|
||||||
|
currentItem.name = record.value(2).toString();
|
||||||
|
currentItem.path = record.value(3).toString();
|
||||||
|
currentItem.info = DBHelper::loadComicInfo(record.value(4).toString(),db);
|
||||||
|
int lessThan = 0;
|
||||||
|
if(list.isEmpty())
|
||||||
|
list.append(currentItem);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ComicDB last = static_cast<ComicDB>(list.back());
|
||||||
|
QString nameLast = last.name;
|
||||||
|
QString nameCurrent = currentItem.name;
|
||||||
|
QList<ComicDB>::iterator i;
|
||||||
|
i = list.end();
|
||||||
|
i--;
|
||||||
|
while ((0 > (lessThan = nameCurrent.localeAwareCompare(nameLast))) && i != list.begin()) //se usa la misma ordenación que en QDir
|
||||||
|
{
|
||||||
|
i--;
|
||||||
|
nameLast = (*i).name;
|
||||||
|
}
|
||||||
|
if(lessThan>0) //si se ha encontrado un elemento menor que current, se inserta justo después
|
||||||
|
list.insert(++i,currentItem);
|
||||||
|
else
|
||||||
|
list.insert(i,currentItem);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//selectQuery.finish();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
QList<LibraryItem *> DBHelper::getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort)
|
QList<LibraryItem *> DBHelper::getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort)
|
||||||
{
|
{
|
||||||
QList<LibraryItem *> list;
|
QList<LibraryItem *> list;
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
static QList<LibraryItem *> getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId);
|
static QList<LibraryItem *> getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId);
|
||||||
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
|
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
|
||||||
static ComicDB getComicInfo(const QString & libraryName, qulonglong id);
|
static ComicDB getComicInfo(const QString & libraryName, qulonglong id);
|
||||||
|
static QList<ComicDB> getSiblings(const QString & libraryName, qulonglong parentId);
|
||||||
static QString getFolderName(const QString & libraryName, qulonglong id);
|
static QString getFolderName(const QString & libraryName, qulonglong id);
|
||||||
static QList<QString> getLibrariesNames();
|
static QList<QString> getLibrariesNames();
|
||||||
static QString getLibraryName(int id);
|
static QString getLibraryName(int id);
|
||||||
@ -40,6 +41,7 @@ public:
|
|||||||
static void updateRead(ComicInfo * comicInfo, QSqlDatabase & db);
|
static void updateRead(ComicInfo * comicInfo, QSqlDatabase & db);
|
||||||
//queries
|
//queries
|
||||||
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||||
|
static QList<ComicDB> getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db);
|
||||||
static QList<LibraryItem *> getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
static QList<LibraryItem *> getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
|
||||||
//load
|
//load
|
||||||
static Folder loadFolder(qulonglong id, QSqlDatabase & db);
|
static Folder loadFolder(qulonglong id, QSqlDatabase & db);
|
||||||
|
@ -55,7 +55,6 @@
|
|||||||
#include "comics_remover.h"
|
#include "comics_remover.h"
|
||||||
#include "yacreader_library_list_widget.h"
|
#include "yacreader_library_list_widget.h"
|
||||||
#include "yacreader_treeview.h"
|
#include "yacreader_treeview.h"
|
||||||
#include "main_window_viewer.h"
|
|
||||||
//#include "yacreader_social_dialog.h"
|
//#include "yacreader_social_dialog.h"
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -1005,26 +1004,22 @@ void LibraryWindow::openComic()
|
|||||||
if(!importedCovers)
|
if(!importedCovers)
|
||||||
{
|
{
|
||||||
ComicDB comic = dmCV->getComic(comicView->currentIndex());
|
ComicDB comic = dmCV->getComic(comicView->currentIndex());
|
||||||
QString path = currentPath() + comic.path;
|
QString path = currentPath();
|
||||||
MainWindowViewer * viewer = new MainWindowViewer();
|
|
||||||
QList<ComicDB> siblings = dmCV->getAllComics();
|
QList<ComicDB> siblings = dmCV->getAllComics();
|
||||||
viewer->open(path,comic,siblings);
|
|
||||||
viewer->show();
|
|
||||||
|
|
||||||
connect(viewer,SIGNAL(closed()),viewer,SLOT(deleteLater()));
|
quint64 comicId = comic.id;
|
||||||
/*quint64 comicId = comic.id;
|
|
||||||
//TODO generate IDS for libraries...
|
//TODO generate IDS for libraries...
|
||||||
quint64 libraryId = selectedLibrary->currentIndex();
|
quint64 libraryId = selectedLibrary->currentIndex();
|
||||||
int page = *(comic.info.numPages) / 2;*/
|
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 /*<< comicId << libraryId << page*/);//,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)/*.arg(comicId).arg(libraryId).arg(page)*/,QStringList());
|
QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath())+QString("/YACReader \"%1\" \"%2\" \"%3\" \"%4\"").arg(path).arg(comicId).arg(libraryId).arg(page),QStringList());
|
||||||
//#endif
|
#endif
|
||||||
//Comic is readed
|
//Comic is readed
|
||||||
setCurrentComicReaded();
|
setCurrentComicReaded();
|
||||||
}
|
}
|
||||||
|
@ -23,79 +23,67 @@ bool YACReaderLocalServer::isListening()
|
|||||||
{
|
{
|
||||||
return localServer->isListening();
|
return localServer->isListening();
|
||||||
}
|
}
|
||||||
|
#include <QFile>
|
||||||
void YACReaderLocalServer::sendResponse()
|
void YACReaderLocalServer::sendResponse()
|
||||||
{
|
{
|
||||||
/*QLocalSocket *clientConnection = localServer->nextPendingConnection();
|
QLocalSocket *clientConnection = localServer->nextPendingConnection();
|
||||||
|
|
||||||
connect(clientConnection, SIGNAL(disconnected()),
|
|
||||||
clientConnection, SLOT(deleteLater()));
|
|
||||||
|
|
||||||
QDataStream in(clientConnection);
|
|
||||||
in.setVersion(QDataStream::Qt_4_0);
|
|
||||||
|
|
||||||
if (clientConnection->bytesAvailable() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (in.atEnd())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QString message;
|
|
||||||
in >> message;
|
|
||||||
|
|
||||||
QByteArray block;
|
|
||||||
QDataStream out(&block, QIODevice::WriteOnly);
|
|
||||||
out.setVersion(QDataStream::Qt_4_0);
|
|
||||||
out << QString("OK");
|
|
||||||
|
|
||||||
clientConnection->write(block);
|
|
||||||
clientConnection->flush();
|
|
||||||
clientConnection->disconnectFromServer();*/
|
|
||||||
|
|
||||||
QLocalSocket *clientConnection = localServer->nextPendingConnection();
|
|
||||||
connect(clientConnection, SIGNAL(disconnected()),
|
connect(clientConnection, SIGNAL(disconnected()),
|
||||||
clientConnection, SLOT(deleteLater()));
|
clientConnection, SLOT(deleteLater()));
|
||||||
|
|
||||||
quint64 libraryId;
|
quint64 libraryId;
|
||||||
ComicDB comic;
|
ComicDB comic;
|
||||||
clientConnection->waitForReadyRead();
|
|
||||||
QByteArray data;
|
//QByteArray data;
|
||||||
QDataStream inputStream(data);
|
while(clientConnection->bytesAvailable() < sizeof(quint16))
|
||||||
inputStream.setVersion(QDataStream::Qt_4_0);
|
clientConnection->waitForReadyRead();
|
||||||
int totalSize = 0;
|
QDataStream sizeStream(clientConnection->read(sizeof(quint16)));
|
||||||
while((data.size()-sizeof(quint16)) != totalSize )
|
sizeStream.setVersion(QDataStream::Qt_4_8);
|
||||||
|
quint16 totalSize = 0;
|
||||||
|
sizeStream >> totalSize;
|
||||||
|
|
||||||
|
while(clientConnection->bytesAvailable() < totalSize )
|
||||||
{
|
{
|
||||||
data.append(clientConnection->read(1000000000));
|
clientConnection->waitForReadyRead();
|
||||||
if(data.size()>=sizeof(quint16) && totalSize == 0)
|
|
||||||
inputStream >> totalSize;
|
|
||||||
}
|
}
|
||||||
inputStream >> libraryId;
|
QDataStream dataStream(clientConnection->read(totalSize));
|
||||||
inputStream >> comic;
|
quint8 msgType;
|
||||||
|
dataStream >> msgType;
|
||||||
|
dataStream >> libraryId;
|
||||||
|
dataStream >> comic;
|
||||||
|
QFile f("c:/temp/socket_server.txt");
|
||||||
|
f.open(QIODevice::WriteOnly);
|
||||||
|
QTextStream outt(&f);
|
||||||
|
outt << QString(" antes : %1 - size : %2").arg(comic.id).arg(totalSize) << endl;
|
||||||
|
|
||||||
getComicInfo(libraryId,comic);
|
QList<ComicDB> siblings;
|
||||||
|
getComicInfo(libraryId,comic,siblings);
|
||||||
|
|
||||||
|
|
||||||
|
outt << QString(" despues : %1 - num sib : %2").arg(comic.id).arg(siblings.count()) << endl;
|
||||||
|
|
||||||
QByteArray block;
|
QByteArray block;
|
||||||
QDataStream out(&block, QIODevice::WriteOnly);
|
QDataStream out(&block, QIODevice::WriteOnly);
|
||||||
out.setVersion(QDataStream::Qt_4_0);
|
out.setVersion(QDataStream::Qt_4_8);
|
||||||
out << (quint16)0;
|
out << (quint16)0;
|
||||||
out << comic;
|
out << comic;
|
||||||
|
out << siblings;
|
||||||
out.device()->seek(0);
|
out.device()->seek(0);
|
||||||
out << (quint16)(block.size() - sizeof(quint16));
|
out << (quint16)(block.size() - sizeof(quint16));
|
||||||
|
|
||||||
int written = 0;
|
int written = 0;
|
||||||
while(written != block.size())
|
while(written != block.size())
|
||||||
{
|
{
|
||||||
written += clientConnection->write(block);
|
written += clientConnection->write(block);
|
||||||
clientConnection->flush();
|
clientConnection->flush();
|
||||||
}
|
}
|
||||||
//clientConnection->waitForBytesWritten();
|
//clientConnection->waitForBytesWritten();*/
|
||||||
clientConnection->disconnectFromServer();
|
//clientConnection->disconnectFromServer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderLocalServer::getComicInfo(quint64 libraryId, ComicDB & comic)
|
void YACReaderLocalServer::getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & siblings)
|
||||||
{
|
{
|
||||||
comic = DBHelper::getComicInfo(DBHelper::getLibrariesNames().at(libraryId), comic.id);
|
comic = DBHelper::getComicInfo(DBHelper::getLibrariesNames().at(libraryId), comic.id);
|
||||||
|
siblings = DBHelper::getSiblings(DBHelper::getLibrariesNames().at(libraryId), comic.parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YACReaderLocalServer::isRunning()
|
bool YACReaderLocalServer::isRunning()
|
||||||
|
@ -18,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);
|
void getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & sibling);
|
||||||
private:
|
private:
|
||||||
QLocalServer * localServer;
|
QLocalServer * localServer;
|
||||||
|
|
||||||
|
@ -61,5 +61,11 @@
|
|||||||
Custom
|
Custom
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum YACReaderIPCMessages
|
||||||
|
{
|
||||||
|
RequestComicInfo = 0,
|
||||||
|
SendComicInfo,
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user