mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Update YACReaderLibrary <-> YACReader communication to support reading lists
This commit is contained in:
parent
945b24a8f8
commit
4fc60c72aa
@ -118,18 +118,22 @@ int main(int argc, char *argv[])
|
|||||||
parser.addPositionalArgument("[File|Directory]", "File or directory to open.");
|
parser.addPositionalArgument("[File|Directory]", "File or directory to open.");
|
||||||
QCommandLineOption comicId("comicId", "", "comicId");
|
QCommandLineOption comicId("comicId", "", "comicId");
|
||||||
QCommandLineOption libraryId("libraryId", "", "libraryId");
|
QCommandLineOption libraryId("libraryId", "", "libraryId");
|
||||||
|
QCommandLineOption readingListId("readingListId", "", "readingListId");
|
||||||
// hide comicId and libraryId from help
|
// hide comicId and libraryId from help
|
||||||
#if QT_VERSION >= 0x050800
|
#if QT_VERSION >= 0x050800
|
||||||
comicId.setFlags(QCommandLineOption::HiddenFromHelp);
|
comicId.setFlags(QCommandLineOption::HiddenFromHelp);
|
||||||
libraryId.setFlags(QCommandLineOption::HiddenFromHelp);
|
libraryId.setFlags(QCommandLineOption::HiddenFromHelp);
|
||||||
|
readingListId.setFlags(QCommandLineOption::HiddenFromHelp);
|
||||||
#else
|
#else
|
||||||
comicId.setHidden(true);
|
comicId.setHidden(true);
|
||||||
libraryId.setHidden(true);
|
libraryId.setHidden(true);
|
||||||
|
readingListId.setHidden(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// process
|
// process
|
||||||
parser.addOption(comicId);
|
parser.addOption(comicId);
|
||||||
parser.addOption(libraryId);
|
parser.addOption(libraryId);
|
||||||
|
parser.addOption(readingListId);
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
|
|
||||||
QString destLog = YACReader::getSettingsPath() + "/yacreader.log";
|
QString destLog = YACReader::getSettingsPath() + "/yacreader.log";
|
||||||
@ -173,7 +177,15 @@ int main(int argc, char *argv[])
|
|||||||
// some arguments need to be parsed after MainWindowViewer creation
|
// some arguments need to be parsed after MainWindowViewer creation
|
||||||
QStringList arglist = parser.positionalArguments();
|
QStringList arglist = parser.positionalArguments();
|
||||||
if (parser.isSet(comicId) && parser.isSet(libraryId) && arglist.count() >= 1) {
|
if (parser.isSet(comicId) && parser.isSet(libraryId) && arglist.count() >= 1) {
|
||||||
mwv->open(arglist.at(0), parser.value(comicId).toULongLong(), parser.value(libraryId).toULongLong());
|
OpenComicSource source;
|
||||||
|
|
||||||
|
if (parser.isSet(readingListId)) {
|
||||||
|
source = OpenComicSource { OpenComicSource::ReadingList, parser.value(readingListId).toULongLong() };
|
||||||
|
} else {
|
||||||
|
source = OpenComicSource { OpenComicSource::Folder, 33 }; //Folder is not needed to get the comic information, the comid id points to a unique comic
|
||||||
|
}
|
||||||
|
|
||||||
|
mwv->open(arglist.at(0), parser.value(comicId).toULongLong(), parser.value(libraryId).toULongLong(), source);
|
||||||
} else if (arglist.count() >= 1) {
|
} else if (arglist.count() >= 1) {
|
||||||
mwv->openComicFromPath(arglist.at(0));
|
mwv->openComicFromPath(arglist.at(0));
|
||||||
}
|
}
|
||||||
|
@ -851,11 +851,12 @@ void MainWindowViewer::open(QString path, ComicDB &comic, QList<ComicDB> &siblin
|
|||||||
optionsDialog->setFilters(currentComicDB.info.brightness, currentComicDB.info.contrast, currentComicDB.info.gamma);
|
optionsDialog->setFilters(currentComicDB.info.brightness, currentComicDB.info.contrast, currentComicDB.info.gamma);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId)
|
void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId, OpenComicSource source)
|
||||||
{
|
{
|
||||||
currentDirectory = path;
|
currentDirectory = path;
|
||||||
|
|
||||||
this->libraryId = libraryId;
|
this->libraryId = libraryId;
|
||||||
|
this->source = source;
|
||||||
|
|
||||||
enableActions();
|
enableActions();
|
||||||
|
|
||||||
@ -863,7 +864,7 @@ void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId)
|
|||||||
YACReaderLocalClient client;
|
YACReaderLocalClient client;
|
||||||
int tries = 1;
|
int tries = 1;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
while (!(success = client.requestComicInfo(libraryId, currentComicDB, siblingComics)) && tries != 0)
|
while (!(success = client.requestComicInfo(libraryId, currentComicDB, siblingComics, source)) && tries != 0)
|
||||||
tries--;
|
tries--;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
@ -1507,6 +1508,9 @@ void MainWindowViewer::openNextComic()
|
|||||||
if (currentIndex + 1 > 0 && currentIndex + 1 < siblingComics.count()) {
|
if (currentIndex + 1 > 0 && currentIndex + 1 < siblingComics.count()) {
|
||||||
siblingComics[currentIndex] = currentComicDB; //updated
|
siblingComics[currentIndex] = currentComicDB; //updated
|
||||||
currentComicDB = siblingComics.at(currentIndex + 1);
|
currentComicDB = siblingComics.at(currentIndex + 1);
|
||||||
|
|
||||||
|
QMessageBox::warning(nullptr, "", QString(" current dir %1 - path %2").arg(currentDirectory).arg(currentComicDB.path));
|
||||||
|
|
||||||
open(currentDirectory + currentComicDB.path, currentComicDB, siblingComics);
|
open(currentDirectory + currentComicDB.path, currentComicDB, siblingComics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "comic_db.h"
|
#include "comic_db.h"
|
||||||
|
#include "yacreader_global.h"
|
||||||
|
|
||||||
class Comic;
|
class Comic;
|
||||||
class Viewer;
|
class Viewer;
|
||||||
@ -25,6 +26,8 @@ class YACReaderSliderAction;
|
|||||||
class YACReaderSlider;
|
class YACReaderSlider;
|
||||||
class EditShortcutsDialog;
|
class EditShortcutsDialog;
|
||||||
|
|
||||||
|
namespace YACReader {
|
||||||
|
|
||||||
class MainWindowViewer : public QMainWindow
|
class MainWindowViewer : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -32,7 +35,7 @@ class MainWindowViewer : public QMainWindow
|
|||||||
public slots:
|
public slots:
|
||||||
void open();
|
void open();
|
||||||
void open(QString path, ComicDB &comic, QList<ComicDB> &siblings);
|
void open(QString path, ComicDB &comic, QList<ComicDB> &siblings);
|
||||||
void open(QString path, qint64 comicId, qint64 libraryId);
|
void open(QString path, qint64 comicId, qint64 libraryId, OpenComicSource source);
|
||||||
void openFolder();
|
void openFolder();
|
||||||
void openRecent();
|
void openRecent();
|
||||||
void openLatestComic();
|
void openLatestComic();
|
||||||
@ -175,6 +178,7 @@ private:
|
|||||||
bool isClient;
|
bool isClient;
|
||||||
QString startComicPath;
|
QString startComicPath;
|
||||||
quint64 libraryId;
|
quint64 libraryId;
|
||||||
|
OpenComicSource source;
|
||||||
|
|
||||||
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||||
Qt::WindowFlags previousWindowFlags;
|
Qt::WindowFlags previousWindowFlags;
|
||||||
@ -191,4 +195,7 @@ public:
|
|||||||
MainWindowViewer();
|
MainWindowViewer();
|
||||||
~MainWindowViewer() override;
|
~MainWindowViewer() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,7 +28,7 @@ void YACReaderLocalClient::readMessage()
|
|||||||
}
|
}
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB &comic, QList<ComicDB> &siblings)
|
bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB &comic, QList<ComicDB> &siblings, OpenComicSource source)
|
||||||
{
|
{
|
||||||
localSocket->connectToServer(YACREADERLIBRARY_GUID);
|
localSocket->connectToServer(YACREADERLIBRARY_GUID);
|
||||||
if (localSocket->isOpen()) {
|
if (localSocket->isOpen()) {
|
||||||
@ -38,6 +38,7 @@ bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB &comic, Q
|
|||||||
out << (quint32)0;
|
out << (quint32)0;
|
||||||
out << (quint8)YACReader::RequestComicInfo;
|
out << (quint8)YACReader::RequestComicInfo;
|
||||||
out << libraryId;
|
out << libraryId;
|
||||||
|
out << source;
|
||||||
out << comic;
|
out << comic;
|
||||||
out.device()->seek(0);
|
out.device()->seek(0);
|
||||||
out << (quint32)(block.size() - sizeof(quint32));
|
out << (quint32)(block.size() - sizeof(quint32));
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef YACREADER_LOCAL_CLIENT_H
|
#ifndef YACREADER_LOCAL_CLIENT_H
|
||||||
#define YACREADER_LOCAL_CLIENT_H
|
#define YACREADER_LOCAL_CLIENT_H
|
||||||
|
|
||||||
|
#include "yacreader_global.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QLocalSocket;
|
class QLocalSocket;
|
||||||
@ -16,7 +18,7 @@ signals:
|
|||||||
void finished();
|
void finished();
|
||||||
public slots:
|
public slots:
|
||||||
void readMessage();
|
void readMessage();
|
||||||
bool requestComicInfo(quint64 libraryId, ComicDB &comic, QList<ComicDB> &siblings);
|
bool requestComicInfo(quint64 libraryId, ComicDB &comic, QList<ComicDB> &siblings, YACReader::OpenComicSource source);
|
||||||
bool sendComicInfo(quint64 libraryId, ComicDB &comic);
|
bool sendComicInfo(quint64 libraryId, ComicDB &comic);
|
||||||
bool sendComicInfo(quint64 libraryId, ComicDB &comic, qulonglong nextComicId);
|
bool sendComicInfo(quint64 libraryId, ComicDB &comic, qulonglong nextComicId);
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ void YACReaderClientConnectionWorker::run()
|
|||||||
|
|
||||||
quint64 libraryId;
|
quint64 libraryId;
|
||||||
ComicDB comic;
|
ComicDB comic;
|
||||||
|
OpenComicSource source = { OpenComicSource::ReadingList, 0 };
|
||||||
qulonglong nextComicId;
|
qulonglong nextComicId;
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
int dataAvailable = 0;
|
int dataAvailable = 0;
|
||||||
@ -136,22 +137,20 @@ void YACReaderClientConnectionWorker::run()
|
|||||||
QDataStream dataStream(data);
|
QDataStream dataStream(data);
|
||||||
quint8 msgType;
|
quint8 msgType;
|
||||||
dataStream >> msgType;
|
dataStream >> msgType;
|
||||||
dataStream >> libraryId;
|
|
||||||
dataStream >> comic;
|
|
||||||
|
|
||||||
bool nextComicInfoAvailable;
|
|
||||||
|
|
||||||
if (dataStream.atEnd()) {
|
|
||||||
nextComicInfoAvailable = false;
|
|
||||||
} else {
|
|
||||||
nextComicInfoAvailable = true;
|
|
||||||
dataStream >> nextComicId;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (msgType) {
|
switch (msgType) {
|
||||||
case YACReader::RequestComicInfo: {
|
case YACReader::RequestComicInfo: {
|
||||||
|
dataStream >> libraryId;
|
||||||
|
dataStream >> source;
|
||||||
|
dataStream >> comic;
|
||||||
|
|
||||||
QList<ComicDB> siblings;
|
QList<ComicDB> siblings;
|
||||||
|
|
||||||
|
if (source.source == OpenComicSource::ReadingList) {
|
||||||
|
getComicInfoFromReadingList(libraryId, source.sourceId, comic, siblings);
|
||||||
|
} else {
|
||||||
getComicInfo(libraryId, comic, siblings);
|
getComicInfo(libraryId, comic, siblings);
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray block;
|
QByteArray block;
|
||||||
QDataStream out(&block, QIODevice::WriteOnly);
|
QDataStream out(&block, QIODevice::WriteOnly);
|
||||||
@ -179,6 +178,18 @@ void YACReaderClientConnectionWorker::run()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case YACReader::SendComicInfo: {
|
case YACReader::SendComicInfo: {
|
||||||
|
bool nextComicInfoAvailable;
|
||||||
|
|
||||||
|
dataStream >> libraryId;
|
||||||
|
dataStream >> comic;
|
||||||
|
|
||||||
|
if (dataStream.atEnd()) {
|
||||||
|
nextComicInfoAvailable = false;
|
||||||
|
} else {
|
||||||
|
nextComicInfoAvailable = true;
|
||||||
|
dataStream >> nextComicId;
|
||||||
|
}
|
||||||
|
|
||||||
if (nextComicInfoAvailable) {
|
if (nextComicInfoAvailable) {
|
||||||
updateComic(libraryId, comic, nextComicId);
|
updateComic(libraryId, comic, nextComicId);
|
||||||
} else {
|
} else {
|
||||||
@ -208,6 +219,13 @@ void YACReaderClientConnectionWorker::getComicInfo(quint64 libraryId, ComicDB &c
|
|||||||
siblings = DBHelper::getSiblings(libraryId, comic.parentId);
|
siblings = DBHelper::getSiblings(libraryId, comic.parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void YACReaderClientConnectionWorker::getComicInfoFromReadingList(quint64 libraryId, unsigned long long readingListId, ComicDB &comic, QList<ComicDB> &siblings)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&dbMutex);
|
||||||
|
comic = DBHelper::getComicInfo(libraryId, comic.id);
|
||||||
|
siblings = DBHelper::getReadingListFullContent(libraryId, readingListId, true);
|
||||||
|
}
|
||||||
|
|
||||||
void YACReaderClientConnectionWorker::updateComic(quint64 libraryId, ComicDB &comic)
|
void YACReaderClientConnectionWorker::updateComic(quint64 libraryId, ComicDB &comic)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&dbMutex);
|
QMutexLocker locker(&dbMutex);
|
||||||
|
@ -42,7 +42,8 @@ private:
|
|||||||
//static int count;
|
//static int count;
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
void getComicInfo(quint64 libraryId, ComicDB &comic, QList<ComicDB> &sibling);
|
void getComicInfo(quint64 libraryId, ComicDB &comic, QList<ComicDB> &siblings);
|
||||||
|
void getComicInfoFromReadingList(quint64 libraryId, unsigned long long readingListId, ComicDB &comic, QList<ComicDB> &siblings);
|
||||||
void updateComic(quint64 libraryId, ComicDB &comic);
|
void updateComic(quint64 libraryId, ComicDB &comic);
|
||||||
void updateComic(quint64 libraryId, ComicDB &comic, qulonglong nextComicId);
|
void updateComic(quint64 libraryId, ComicDB &comic, qulonglong nextComicId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user