From a4e54753e8f0798c911e409307cb12ba6e26a928 Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Fri, 18 Oct 2024 17:08:35 -0400 Subject: [PATCH] WIP --- app/CMakeLists.txt | 2 +- app/src/command/command.h | 2 +- app/src/frontend/directive.h | 103 +++++++++++++++++++++++++++++++++++ app/src/frontend/message.h | 14 ----- app/src/kernel/core.cpp | 66 +++------------------- app/src/kernel/core.h | 77 ++++---------------------- app/src/task/task.h | 2 +- 7 files changed, 124 insertions(+), 142 deletions(-) create mode 100644 app/src/frontend/directive.h delete mode 100644 app/src/frontend/message.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index eca7181..6eaefb7 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -57,7 +57,7 @@ set(CLIFP_SOURCE tools/mounter_qmp.cpp tools/mounter_router.h tools/mounter_router.cpp - frontend/message.h + frontend/directive.h frontend/statusrelay.h frontend/statusrelay.cpp controller.h diff --git a/app/src/command/command.h b/app/src/command/command.h index 54b1e5e..1203ae5 100644 --- a/app/src/command/command.h +++ b/app/src/command/command.h @@ -169,7 +169,7 @@ class Command void logTask(const Task* task) const; ErrorCode logFinish(Qx::Error errorState) const; void postError(Qx::Error error, bool log = true) const; - int postBlockingError(Qx::Error error, bool log = true, QMessageBox::StandardButtons bs = QMessageBox::Ok, QMessageBox::StandardButton def = QMessageBox::NoButton) const; + int postBlockingError(Qx::Error error, bool log = true, DBlockingError::Choices bs = DBlockingError::Choice::Ok, DBlockingError::Choice def = DBlockingError::Choice::No) const; public: virtual bool requiresFlashpoint() const; diff --git a/app/src/frontend/directive.h b/app/src/frontend/directive.h new file mode 100644 index 0000000..683aa30 --- /dev/null +++ b/app/src/frontend/directive.h @@ -0,0 +1,103 @@ +#ifndef DIRECTIVE_H +#define DIRECTIVE_H + +// Qt Includes +#include + +// Qx Includes +#include + +//-Non-blocking Directives----------------------------------------------------------------- +struct DMessage +{ + QString text; + bool selectable = false; +}; + +struct DError +{ + QString source; + Qx::Error error; +}; + +struct DClipboardUpdate +{ + QString text; +}; + +using AsyncDirective = std::variant< + DMessage, + DError, + DClipboardUpdate +>; + +template +concept AsyncDirectiveT = requires(AsyncDirective ad, T t) { ad = t; }; + +//-Blocking Directives--------------------------------------------------------------------- +struct DBlockingMessage +{ + QString text; + bool selectable = false; +}; + +struct DBlockingError +{ + enum class Choice {Ok, Yes, No}; + Q_DECLARE_FLAGS(Choices, Choice); + + QString source; + Qx::Error error; + Choices choices = Choice::Ok; + Choice defaultChoice = Choice::No; +}; +Q_DECLARE_OPERATORS_FOR_FLAGS(DBlockingError::Choices); + +struct DSaveFilename +{ + QString caption; + QString dir; + QString filter; + QString* selectedFilter = nullptr; +}; + +struct DExistingDir +{ + QString caption; + QString dir; + // TODO: Make sure to use QFileDialog::ShowDirsOnly on receiving end +}; + +struct DItemSelection +{ + QString caption; + QString label; + QStringList items; +}; + +struct DYesOrNo +{ + QString question; +}; + +using SyncDirective = std::variant< + DBlockingMessage, + DBlockingError, + DSaveFilename, + DExistingDir, + DItemSelection, + DYesOrNo +>; + +template +concept SyncDirectiveT = requires(SyncDirective sd, T t) { sd = t; }; + +//-Any--------------------------------------------------------------------- +template +concept DirectiveT = AsyncDirectiveT || SyncDirectiveT; + +//-Metatype Declarations----------------------------------------------------------------------------------------- +Q_DECLARE_METATYPE(AsyncDirective); +Q_DECLARE_METATYPE(SyncDirective); + +#endif // DIRECTIVE_H diff --git a/app/src/frontend/message.h b/app/src/frontend/message.h deleted file mode 100644 index cfa4880..0000000 --- a/app/src/frontend/message.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef MESSAGE_H -#define MESSAGE_H - -// Qt Includes -#include - -struct Message -{ - QString text; - bool blocking = false; - bool selectable = false; -}; - -#endif // MESSAGE_H diff --git a/app/src/kernel/core.cpp b/app/src/kernel/core.cpp index 827b530..6cb3fa2 100644 --- a/app/src/kernel/core.cpp +++ b/app/src/kernel/core.cpp @@ -943,6 +943,14 @@ ErrorCode Core::logFinish(const QString& src, const Qx::Error& errorState) return code; } +void Core::postDirective(const Directive& directive) +{ + std::visit(qxFuncAggregate{ + [this](const AsyncDirective& ad) { emit asyncDirectiveAccounced(ad); }, + [this](const SyncDirective& sd) { emit syncDirectiveAccounced(sd); } + }, directive); +} + void Core::postError(const QString& src, const Qx::Error& error, bool log) { // Logging @@ -993,64 +1001,6 @@ int Core::postBlockingError(const QString& src, const Qx::Error& error, bool log return def; } -void Core::postMessage(const Message& msg) { emit message(msg); } - -QString Core::requestSaveFilePath(const SaveFileRequest& request) -{ - // Response holder - QSharedPointer file = QSharedPointer::create(); - - // Emit and get response - emit saveFileRequested(file, request); - - // Return response - return *file; -} - -QString Core::requestExistingDirPath(const ExistingDirRequest& request) -{ - // Response holder - QSharedPointer dir = QSharedPointer::create(); - - // Emit and get response - emit existingDirRequested(dir, request); - - // Return response - return *dir; -} - -QString Core::requestItemSelection(const ItemSelectionRequest& request) -{ - // Response holder - QSharedPointer item = QSharedPointer::create(); - - // Emit and get response - emit itemSelectionRequested(item, request); - - // Return response - return *item; -} - -void Core::requestClipboardUpdate(const QString& text) { emit clipboardUpdateRequested(text); } - -bool Core::requestQuestionAnswer(const QString& question) -{ - // Show question if allowed - if(mNotificationVerbosity != NotificationVerbosity::Silent) - { - // Response holder - QSharedPointer response = QSharedPointer::create(false); - - // Emit and get response - emit questionAnswerRequested(response, question); - - // Return response - return *response; - } - else - return false; // Assume "No" -} - Fp::Install& Core::fpInstall() { return *mFlashpointInstall; } const QProcessEnvironment& Core::childTitleProcessEnvironment() { return mChildTitleProcEnv; } Core::NotificationVerbosity Core::notifcationVerbosity() const { return mNotificationVerbosity; } diff --git a/app/src/kernel/core.h b/app/src/kernel/core.h index fefae10..939c220 100644 --- a/app/src/kernel/core.h +++ b/app/src/kernel/core.h @@ -23,6 +23,7 @@ // Project Includes #include "task/task.h" +#include "frontend/directive.h" #include "project_vars.h" #include "kernel/buildinfo.h" @@ -92,49 +93,6 @@ class Core : public QObject enum class NotificationVerbosity { Full, Quiet, Silent }; enum ServicesMode { Standalone, Companion }; -//-Class Structs--------------------------------------------------------------------- -public: - /* TODO: These should be made their own files like message.h is in frontend - * (or one file, like "requests.h"), or message.h should be removed with its - * struct moved to here - */ - struct Error - { - QString source; - Qx::Error errorInfo; - }; - - struct BlockingError - { - QString source; - Qx::Error errorInfo; - QMessageBox::StandardButtons choices; - QMessageBox::StandardButton defaultChoice; - }; - - struct SaveFileRequest - { - QString caption; - QString dir; - QString filter; - QString* selectedFilter = nullptr; - QFileDialog::Options options; - }; - - struct ExistingDirRequest - { - QString caption; - QString dir; - QFileDialog::Options options = QFileDialog::ShowDirsOnly; - }; - - struct ItemSelectionRequest - { - QString caption; - QString label; - QStringList items; - }; - //-Class Variables------------------------------------------------------------------------------------------------------ public: // Single Instance ID @@ -315,7 +273,7 @@ class Core : public QObject void logTask(const Task* task); ErrorCode logFinish(const Qx::Error& errorState); void postError(const Qx::Error& error, bool log = true); - int postBlockingError(const Qx::Error& error, bool log = true, QMessageBox::StandardButtons bs = QMessageBox::Ok, QMessageBox::StandardButton def = QMessageBox::NoButton); + int postBlockingError(const Qx::Error& error, bool log = true, DBlockingError::Choices bs = QMessageBox::Ok, DBlockingError::Choice def = DBlockingError::Choice::No); public: // Setup @@ -339,10 +297,7 @@ class Core : public QObject Qx::Error enqueueDataPackTasks(const Fp::GameData& gameData); void enqueueSingleTask(Task* task); - // Notifications/Logging - /* TODO: Within each place that uses the log options that need the src parameter, like the Commands, and maybe even Core itself, add methods - * with the same names that call mCore.logX(NAME, ...) automatically so that NAME doesn't need to be passed every time - */ + // Logging bool isLogOpen() const; void logCommand(const QString& src, const QString& commandName); void logCommandOptions(const QString& src, const QString& commandOptions); @@ -350,14 +305,12 @@ class Core : public QObject void logEvent(const QString& src, const QString& event); void logTask(const QString& src, const Task* task); ErrorCode logFinish(const QString& src, const Qx::Error& errorState); + + // Directives + void postDirective(const Directive& directive); void postError(const QString& src, const Qx::Error& error, bool log = true); - int postBlockingError(const QString& src, const Qx::Error& error, bool log = true, QMessageBox::StandardButtons bs = QMessageBox::Ok, QMessageBox::StandardButton def = QMessageBox::NoButton); - void postMessage(const Message& msg); - QString requestSaveFilePath(const SaveFileRequest& request); - QString requestExistingDirPath(const ExistingDirRequest& request); - QString requestItemSelection(const ItemSelectionRequest& request); - void requestClipboardUpdate(const QString& text); - bool requestQuestionAnswer(const QString& question); + int postBlockingError(const QString& src, const Qx::Error& error, bool log = true, DBlockingError::Choices bs = DBlockingError::Choice::Ok, DBlockingError::Choice def = DBlockingError::Choice::No); + // Member access ServicesMode mode() const; @@ -380,21 +333,11 @@ class Core : public QObject //-Signals & Slots------------------------------------------------------------------------------------------------------------ signals: void statusChanged(const QString& statusHeading, const QString& statusMessage); - void errorOccurred(const Core::Error& error); - void blockingErrorOccurred(QSharedPointer response, const Core::BlockingError& blockingError); - void saveFileRequested(QSharedPointer file, const Core::SaveFileRequest& request); - void existingDirRequested(QSharedPointer dir, const Core::ExistingDirRequest& request); - void itemSelectionRequested(QSharedPointer item, const Core::ItemSelectionRequest& request); - void message(const Message& message); - void clipboardUpdateRequested(const QString& text); - void questionAnswerRequested(QSharedPointer response, const QString& question); + void asyncDirectiveAccounced(const AsyncDirective& aDirective); + void syncDirectiveAccounced(const SyncDirective& sDirective); // Driver specific void abort(CoreError err); }; -//-Metatype Declarations----------------------------------------------------------------------------------------- -Q_DECLARE_METATYPE(Core::Error); -Q_DECLARE_METATYPE(Core::BlockingError); - #endif // CORE_H diff --git a/app/src/task/task.h b/app/src/task/task.h index 304c078..8b5e711 100644 --- a/app/src/task/task.h +++ b/app/src/task/task.h @@ -9,7 +9,7 @@ #include // Project Includes -#include "frontend/message.h" +#include "frontend/directive.h" class Task : public QObject {