mirror of
https://github.com/YACReader/yacreader
synced 2025-06-03 00:58:32 -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()
|
||||
{
|
||||
_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:
|
||||
|
@ -127,7 +127,7 @@ win32:RESOURCES += images_win.qrc
|
||||
unix:!macx:RESOURCES += images_win.qrc
|
||||
macx:RESOURCES += images_osx.qrc
|
||||
|
||||
include(../YACReader/YACReader.pri)
|
||||
#include(../YACReader/YACReader.pri)
|
||||
|
||||
RC_FILE = icon.rc
|
||||
|
||||
|
@ -105,6 +105,18 @@ ComicDB DBHelper::getComicInfo(const QString & libraryName, qulonglong id)
|
||||
QSqlDatabase::removeDatabase(libraryPath);
|
||||
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 libraryPath = DBHelper::getLibraries().value(libraryName);
|
||||
@ -351,6 +363,55 @@ QList<LibraryItem *> DBHelper::getFoldersFromParent(qulonglong parentId, QSqlDat
|
||||
|
||||
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 *> list;
|
||||
|
@ -22,6 +22,7 @@ public:
|
||||
static QList<LibraryItem *> getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId);
|
||||
static qulonglong getParentFromComicFolderId(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 QList<QString> getLibrariesNames();
|
||||
static QString getLibraryName(int id);
|
||||
@ -40,6 +41,7 @@ public:
|
||||
static void updateRead(ComicInfo * comicInfo, QSqlDatabase & db);
|
||||
//queries
|
||||
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);
|
||||
//load
|
||||
static Folder loadFolder(qulonglong id, QSqlDatabase & db);
|
||||
|
@ -55,7 +55,6 @@
|
||||
#include "comics_remover.h"
|
||||
#include "yacreader_library_list_widget.h"
|
||||
#include "yacreader_treeview.h"
|
||||
#include "main_window_viewer.h"
|
||||
//#include "yacreader_social_dialog.h"
|
||||
//
|
||||
|
||||
@ -1005,26 +1004,22 @@ void LibraryWindow::openComic()
|
||||
if(!importedCovers)
|
||||
{
|
||||
ComicDB comic = dmCV->getComic(comicView->currentIndex());
|
||||
QString path = currentPath() + comic.path;
|
||||
MainWindowViewer * viewer = new MainWindowViewer();
|
||||
QString path = currentPath();
|
||||
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...
|
||||
quint64 libraryId = selectedLibrary->currentIndex();
|
||||
int page = *(comic.info.numPages) / 2;*/
|
||||
int page = *(comic.info.numPages) / 2;
|
||||
|
||||
//#ifdef Q_OS_MAC
|
||||
//
|
||||
// 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)/*.arg(comicId).arg(libraryId).arg(page)*/,QStringList());
|
||||
//#endif
|
||||
#ifdef Q_OS_MAC
|
||||
|
||||
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\" \"%2\" \"%3\" \"%4\"").arg(path).arg(comicId).arg(libraryId).arg(page),QStringList());
|
||||
#endif
|
||||
//Comic is readed
|
||||
setCurrentComicReaded();
|
||||
}
|
||||
|
@ -23,79 +23,67 @@ bool YACReaderLocalServer::isListening()
|
||||
{
|
||||
return localServer->isListening();
|
||||
}
|
||||
|
||||
#include <QFile>
|
||||
void YACReaderLocalServer::sendResponse()
|
||||
{
|
||||
/*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();
|
||||
QLocalSocket *clientConnection = localServer->nextPendingConnection();
|
||||
connect(clientConnection, SIGNAL(disconnected()),
|
||||
clientConnection, SLOT(deleteLater()));
|
||||
|
||||
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 )
|
||||
|
||||
//QByteArray data;
|
||||
while(clientConnection->bytesAvailable() < sizeof(quint16))
|
||||
clientConnection->waitForReadyRead();
|
||||
QDataStream sizeStream(clientConnection->read(sizeof(quint16)));
|
||||
sizeStream.setVersion(QDataStream::Qt_4_8);
|
||||
quint16 totalSize = 0;
|
||||
sizeStream >> totalSize;
|
||||
|
||||
while(clientConnection->bytesAvailable() < totalSize )
|
||||
{
|
||||
data.append(clientConnection->read(1000000000));
|
||||
if(data.size()>=sizeof(quint16) && totalSize == 0)
|
||||
inputStream >> totalSize;
|
||||
clientConnection->waitForReadyRead();
|
||||
}
|
||||
inputStream >> libraryId;
|
||||
inputStream >> comic;
|
||||
QDataStream dataStream(clientConnection->read(totalSize));
|
||||
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;
|
||||
QDataStream out(&block, QIODevice::WriteOnly);
|
||||
out.setVersion(QDataStream::Qt_4_0);
|
||||
QDataStream out(&block, QIODevice::WriteOnly);
|
||||
out.setVersion(QDataStream::Qt_4_8);
|
||||
out << (quint16)0;
|
||||
out << comic;
|
||||
out << comic;
|
||||
out << siblings;
|
||||
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();
|
||||
|
||||
int written = 0;
|
||||
while(written != block.size())
|
||||
{
|
||||
written += clientConnection->write(block);
|
||||
clientConnection->flush();
|
||||
}
|
||||
//clientConnection->waitForBytesWritten();*/
|
||||
//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);
|
||||
siblings = DBHelper::getSiblings(DBHelper::getLibrariesNames().at(libraryId), comic.parentId);
|
||||
}
|
||||
|
||||
bool YACReaderLocalServer::isRunning()
|
||||
|
@ -18,7 +18,7 @@ public slots:
|
||||
bool isListening();
|
||||
void sendResponse();
|
||||
static bool isRunning();
|
||||
void getComicInfo(quint64 libraryId, ComicDB & comic);
|
||||
void getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & sibling);
|
||||
private:
|
||||
QLocalServer * localServer;
|
||||
|
||||
|
@ -61,5 +61,11 @@
|
||||
Custom
|
||||
};
|
||||
|
||||
enum YACReaderIPCMessages
|
||||
{
|
||||
RequestComicInfo = 0,
|
||||
SendComicInfo,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user