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.");
|
||||
QCommandLineOption comicId("comicId", "", "comicId");
|
||||
QCommandLineOption libraryId("libraryId", "", "libraryId");
|
||||
QCommandLineOption readingListId("readingListId", "", "readingListId");
|
||||
// hide comicId and libraryId from help
|
||||
#if QT_VERSION >= 0x050800
|
||||
comicId.setFlags(QCommandLineOption::HiddenFromHelp);
|
||||
libraryId.setFlags(QCommandLineOption::HiddenFromHelp);
|
||||
readingListId.setFlags(QCommandLineOption::HiddenFromHelp);
|
||||
#else
|
||||
comicId.setHidden(true);
|
||||
libraryId.setHidden(true);
|
||||
readingListId.setHidden(true);
|
||||
#endif
|
||||
|
||||
// process
|
||||
parser.addOption(comicId);
|
||||
parser.addOption(libraryId);
|
||||
parser.addOption(readingListId);
|
||||
parser.process(app);
|
||||
|
||||
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
|
||||
QStringList arglist = parser.positionalArguments();
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId)
|
||||
void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId, OpenComicSource source)
|
||||
{
|
||||
currentDirectory = path;
|
||||
|
||||
this->libraryId = libraryId;
|
||||
this->source = source;
|
||||
|
||||
enableActions();
|
||||
|
||||
@ -863,7 +864,7 @@ void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId)
|
||||
YACReaderLocalClient client;
|
||||
int tries = 1;
|
||||
bool success = false;
|
||||
while (!(success = client.requestComicInfo(libraryId, currentComicDB, siblingComics)) && tries != 0)
|
||||
while (!(success = client.requestComicInfo(libraryId, currentComicDB, siblingComics, source)) && tries != 0)
|
||||
tries--;
|
||||
|
||||
if (success) {
|
||||
@ -1507,6 +1508,9 @@ void MainWindowViewer::openNextComic()
|
||||
if (currentIndex + 1 > 0 && currentIndex + 1 < siblingComics.count()) {
|
||||
siblingComics[currentIndex] = currentComicDB; //updated
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#endif
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "yacreader_global.h"
|
||||
|
||||
class Comic;
|
||||
class Viewer;
|
||||
@ -25,6 +26,8 @@ class YACReaderSliderAction;
|
||||
class YACReaderSlider;
|
||||
class EditShortcutsDialog;
|
||||
|
||||
namespace YACReader {
|
||||
|
||||
class MainWindowViewer : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -32,7 +35,7 @@ class MainWindowViewer : public QMainWindow
|
||||
public slots:
|
||||
void open();
|
||||
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 openRecent();
|
||||
void openLatestComic();
|
||||
@ -175,6 +178,7 @@ private:
|
||||
bool isClient;
|
||||
QString startComicPath;
|
||||
quint64 libraryId;
|
||||
OpenComicSource source;
|
||||
|
||||
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||
Qt::WindowFlags previousWindowFlags;
|
||||
@ -191,4 +195,7 @@ public:
|
||||
MainWindowViewer();
|
||||
~MainWindowViewer() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -28,7 +28,7 @@ void YACReaderLocalClient::readMessage()
|
||||
}
|
||||
#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);
|
||||
if (localSocket->isOpen()) {
|
||||
@ -38,6 +38,7 @@ bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB &comic, Q
|
||||
out << (quint32)0;
|
||||
out << (quint8)YACReader::RequestComicInfo;
|
||||
out << libraryId;
|
||||
out << source;
|
||||
out << comic;
|
||||
out.device()->seek(0);
|
||||
out << (quint32)(block.size() - sizeof(quint32));
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef YACREADER_LOCAL_CLIENT_H
|
||||
#define YACREADER_LOCAL_CLIENT_H
|
||||
|
||||
#include "yacreader_global.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QLocalSocket;
|
||||
@ -16,7 +18,7 @@ signals:
|
||||
void finished();
|
||||
public slots:
|
||||
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, qulonglong nextComicId);
|
||||
|
||||
|
@ -95,6 +95,7 @@ void YACReaderClientConnectionWorker::run()
|
||||
|
||||
quint64 libraryId;
|
||||
ComicDB comic;
|
||||
OpenComicSource source = { OpenComicSource::ReadingList, 0 };
|
||||
qulonglong nextComicId;
|
||||
int tries = 0;
|
||||
int dataAvailable = 0;
|
||||
@ -136,22 +137,20 @@ void YACReaderClientConnectionWorker::run()
|
||||
QDataStream dataStream(data);
|
||||
quint8 msgType;
|
||||
dataStream >> msgType;
|
||||
dataStream >> libraryId;
|
||||
dataStream >> comic;
|
||||
|
||||
bool nextComicInfoAvailable;
|
||||
|
||||
if (dataStream.atEnd()) {
|
||||
nextComicInfoAvailable = false;
|
||||
} else {
|
||||
nextComicInfoAvailable = true;
|
||||
dataStream >> nextComicId;
|
||||
}
|
||||
|
||||
switch (msgType) {
|
||||
case YACReader::RequestComicInfo: {
|
||||
dataStream >> libraryId;
|
||||
dataStream >> source;
|
||||
dataStream >> comic;
|
||||
|
||||
QList<ComicDB> siblings;
|
||||
getComicInfo(libraryId, comic, siblings);
|
||||
|
||||
if (source.source == OpenComicSource::ReadingList) {
|
||||
getComicInfoFromReadingList(libraryId, source.sourceId, comic, siblings);
|
||||
} else {
|
||||
getComicInfo(libraryId, comic, siblings);
|
||||
}
|
||||
|
||||
QByteArray block;
|
||||
QDataStream out(&block, QIODevice::WriteOnly);
|
||||
@ -179,6 +178,18 @@ void YACReaderClientConnectionWorker::run()
|
||||
break;
|
||||
}
|
||||
case YACReader::SendComicInfo: {
|
||||
bool nextComicInfoAvailable;
|
||||
|
||||
dataStream >> libraryId;
|
||||
dataStream >> comic;
|
||||
|
||||
if (dataStream.atEnd()) {
|
||||
nextComicInfoAvailable = false;
|
||||
} else {
|
||||
nextComicInfoAvailable = true;
|
||||
dataStream >> nextComicId;
|
||||
}
|
||||
|
||||
if (nextComicInfoAvailable) {
|
||||
updateComic(libraryId, comic, nextComicId);
|
||||
} else {
|
||||
@ -208,6 +219,13 @@ void YACReaderClientConnectionWorker::getComicInfo(quint64 libraryId, ComicDB &c
|
||||
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)
|
||||
{
|
||||
QMutexLocker locker(&dbMutex);
|
||||
|
@ -42,7 +42,8 @@ private:
|
||||
//static int count;
|
||||
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, qulonglong nextComicId);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user