mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
incoming connections to local server are now proccessed in threads
This commit is contained in:
parent
db9aad8521
commit
85dd3f862c
@ -264,7 +264,6 @@ public:
|
|||||||
void importLibraryPackage();
|
void importLibraryPackage();
|
||||||
void updateComicsView(quint64 libraryId, const ComicDB & comic);
|
void updateComicsView(quint64 libraryId, const ComicDB & comic);
|
||||||
void setCurrentComicOpened();
|
void setCurrentComicOpened();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,7 +50,6 @@ int main( int argc, char ** argv )
|
|||||||
LibraryWindow * mw = new LibraryWindow();
|
LibraryWindow * mw = new LibraryWindow();
|
||||||
|
|
||||||
mw->connect(localServer,SIGNAL(comicUpdated(quint64, const ComicDB &)),mw,SLOT(updateComicsView(quint64, const ComicDB &)));
|
mw->connect(localServer,SIGNAL(comicUpdated(quint64, const ComicDB &)),mw,SLOT(updateComicsView(quint64, const ComicDB &)));
|
||||||
|
|
||||||
//connections to localServer
|
//connections to localServer
|
||||||
|
|
||||||
mw->show();
|
mw->show();
|
||||||
|
@ -30,6 +30,33 @@ void YACReaderLocalServer::sendResponse()
|
|||||||
connect(clientConnection, SIGNAL(disconnected()),
|
connect(clientConnection, SIGNAL(disconnected()),
|
||||||
clientConnection, SLOT(deleteLater()));
|
clientConnection, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
qRegisterMetaType<ComicDB>("ComicDB");
|
||||||
|
YACReaderClientConnectionWorker * worker = new YACReaderClientConnectionWorker(clientConnection);
|
||||||
|
connect(worker,SIGNAL(comicUpdated(quint64, ComicDB)),this,SIGNAL(comicUpdated(quint64, ComicDB)));
|
||||||
|
connect(worker,SIGNAL(finished()),worker,SLOT(deleteLater()));
|
||||||
|
worker->start();
|
||||||
|
//clientConnection->waitForBytesWritten();*/
|
||||||
|
//clientConnection->disconnectFromServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool YACReaderLocalServer::isRunning()
|
||||||
|
{
|
||||||
|
QLocalSocket socket;
|
||||||
|
socket.connectToServer(YACREADERLIBRARY_GUID);
|
||||||
|
if (socket.waitForConnected(500))
|
||||||
|
return true; // Server is running (another instance of YACReaderLibrary has been launched)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
YACReaderClientConnectionWorker::YACReaderClientConnectionWorker( QLocalSocket *cc)
|
||||||
|
:QThread(),clientConnection(cc)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void YACReaderClientConnectionWorker::run()
|
||||||
|
{
|
||||||
quint64 libraryId;
|
quint64 libraryId;
|
||||||
ComicDB comic;
|
ComicDB comic;
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
@ -100,28 +127,16 @@ void YACReaderLocalServer::sendResponse()
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//clientConnection->waitForBytesWritten();*/
|
|
||||||
//clientConnection->disconnectFromServer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderLocalServer::getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & siblings)
|
void YACReaderClientConnectionWorker::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);
|
siblings = DBHelper::getSiblings(DBHelper::getLibrariesNames().at(libraryId), comic.parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YACReaderLocalServer::updateComic(quint64 libraryId, ComicDB & comic)
|
void YACReaderClientConnectionWorker::updateComic(quint64 libraryId, ComicDB & comic)
|
||||||
{
|
{
|
||||||
DBHelper::update(DBHelper::getLibrariesNames().at(libraryId), comic.info);
|
DBHelper::update(DBHelper::getLibrariesNames().at(libraryId), comic.info);
|
||||||
emit comicUpdated(libraryId, comic);
|
emit comicUpdated(libraryId, comic);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YACReaderLocalServer::isRunning()
|
|
||||||
{
|
|
||||||
QLocalSocket socket;
|
|
||||||
socket.connectToServer(YACREADERLIBRARY_GUID);
|
|
||||||
if (socket.waitForConnected(500))
|
|
||||||
return true; // Server is running (another instance of YACReaderLibrary has been launched)
|
|
||||||
return false;
|
|
||||||
}
|
|
@ -2,8 +2,10 @@
|
|||||||
#define YACREADER_LOCAL_SERVER_H
|
#define YACREADER_LOCAL_SERVER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
class QLocalServer;
|
class QLocalServer;
|
||||||
|
class QLocalSocket;
|
||||||
class ComicDB;
|
class ComicDB;
|
||||||
|
|
||||||
class YACReaderLocalServer : public QObject
|
class YACReaderLocalServer : public QObject
|
||||||
@ -18,11 +20,25 @@ public slots:
|
|||||||
bool isListening();
|
bool isListening();
|
||||||
void sendResponse();
|
void sendResponse();
|
||||||
static bool isRunning();
|
static bool isRunning();
|
||||||
void getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & sibling);
|
|
||||||
void updateComic(quint64 libraryId, ComicDB & comic);
|
|
||||||
private:
|
private:
|
||||||
QLocalServer * localServer;
|
QLocalServer * localServer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class YACReaderClientConnectionWorker : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
YACReaderClientConnectionWorker( QLocalSocket *clientConnection);
|
||||||
|
signals:
|
||||||
|
void comicUpdated(quint64 libraryId, const ComicDB & comic);
|
||||||
|
private:
|
||||||
|
void run();
|
||||||
|
|
||||||
|
void getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & sibling);
|
||||||
|
void updateComic(quint64 libraryId, ComicDB & comic);
|
||||||
|
|
||||||
|
QLocalSocket *clientConnection;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // YACREADER_LOCAL_SERVER_H
|
#endif // YACREADER_LOCAL_SERVER_H
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
class ComicInfo
|
class ComicInfo
|
||||||
{
|
{
|
||||||
@ -141,5 +142,6 @@ public:
|
|||||||
friend QDataStream &operator>>(QDataStream &, ComicDB &);
|
friend QDataStream &operator>>(QDataStream &, ComicDB &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(ComicDB);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user