Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Oct 18, 2024
1 parent 2361e0e commit a4e5475
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 142 deletions.
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/command/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
103 changes: 103 additions & 0 deletions app/src/frontend/directive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#ifndef DIRECTIVE_H
#define DIRECTIVE_H

// Qt Includes
#include <QString>

// Qx Includes
#include <qx/core/qx-error.h>

//-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<typename T>
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<typename T>
concept SyncDirectiveT = requires(SyncDirective sd, T t) { sd = t; };

//-Any---------------------------------------------------------------------
template<typename T>
concept DirectiveT = AsyncDirectiveT<T> || SyncDirectiveT<T>;

//-Metatype Declarations-----------------------------------------------------------------------------------------
Q_DECLARE_METATYPE(AsyncDirective);
Q_DECLARE_METATYPE(SyncDirective);

#endif // DIRECTIVE_H
14 changes: 0 additions & 14 deletions app/src/frontend/message.h

This file was deleted.

66 changes: 8 additions & 58 deletions app/src/kernel/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<QString> file = QSharedPointer<QString>::create();

// Emit and get response
emit saveFileRequested(file, request);

// Return response
return *file;
}

QString Core::requestExistingDirPath(const ExistingDirRequest& request)
{
// Response holder
QSharedPointer<QString> dir = QSharedPointer<QString>::create();

// Emit and get response
emit existingDirRequested(dir, request);

// Return response
return *dir;
}

QString Core::requestItemSelection(const ItemSelectionRequest& request)
{
// Response holder
QSharedPointer<QString> item = QSharedPointer<QString>::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<bool> response = QSharedPointer<bool>::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; }
Expand Down
77 changes: 10 additions & 67 deletions app/src/kernel/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// Project Includes
#include "task/task.h"
#include "frontend/directive.h"
#include "project_vars.h"
#include "kernel/buildinfo.h"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -339,25 +297,20 @@ 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);
void logError(const QString& src, const Qx::Error& error);
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;
Expand All @@ -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<int> response, const Core::BlockingError& blockingError);
void saveFileRequested(QSharedPointer<QString> file, const Core::SaveFileRequest& request);
void existingDirRequested(QSharedPointer<QString> dir, const Core::ExistingDirRequest& request);
void itemSelectionRequested(QSharedPointer<QString> item, const Core::ItemSelectionRequest& request);
void message(const Message& message);
void clipboardUpdateRequested(const QString& text);
void questionAnswerRequested(QSharedPointer<bool> 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
2 changes: 1 addition & 1 deletion app/src/task/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <qx/core/qx-error.h>

// Project Includes
#include "frontend/message.h"
#include "frontend/directive.h"

class Task : public QObject
{
Expand Down

0 comments on commit a4e5475

Please sign in to comment.