-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d44a2e0
commit b1922eb
Showing
8 changed files
with
229 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#================= Common Build ========================= | ||
|
||
set(PRETTY_NAME "${PROJECT_NAME}-C") | ||
|
||
# Add via ob standard executable | ||
include(OB/Executable) | ||
ob_add_standard_executable(${APP_CONSOLE_TARGET_NAME} | ||
ALIAS "${APP_CONSOLE_ALIAS_NAME}" | ||
OUTPUT_NAME "${PRETTY_NAME}" | ||
SOURCE | ||
frontend/console.h | ||
frontend/console.cpp | ||
main.cpp | ||
LINKS | ||
PRIVATE | ||
CLIFp::FrontendFramework | ||
magic_enum::magic_enum | ||
CONFIG STANDARD | ||
) | ||
|
||
# Add exe details on Windows | ||
if(CMAKE_SYSTEM_NAME STREQUAL Windows) | ||
include(FrontendFramework) | ||
set_clip_exe_details(${APP_CONSOLE_TARGET_NAME} ${PRETTY_NAME}) | ||
endif() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Unit Include | ||
#include "console.h" | ||
|
||
// Qt Includes | ||
#include <QGuiApplication> | ||
|
||
// Qx Includes | ||
#include <qx/core/qx-iostream.h> | ||
|
||
// Magic enum | ||
#include "magic_enum_utility.hpp" | ||
|
||
//=============================================================================================================== | ||
// FrontendConsole | ||
//=============================================================================================================== | ||
|
||
//-Constructor------------------------------------------------------------------------------------------------------- | ||
//Public: | ||
FrontendConsole::FrontendConsole(QGuiApplication* app) : | ||
FrontendFramework(app) | ||
{ | ||
// We don't make windows in this frontend, but just to be safe | ||
app->setQuitOnLastWindowClosed(false); | ||
} | ||
|
||
//-Class Functions-------------------------------------------------------------------------------------------------------- | ||
//Private: | ||
|
||
//-Instance Functions------------------------------------------------------------------------------------------------------ | ||
//Private: | ||
void FrontendConsole::handleDirective(const DMessage& d) | ||
{ | ||
// TODO: Probably should add a heading like "Notice)" or something | ||
Qx::cout << d.text << Qt::endl; | ||
} | ||
|
||
void FrontendConsole::handleDirective(const DError& d) { Qx::cout << d.error << Qt::endl;} | ||
|
||
void FrontendConsole::handleDirective(const DProcedureStart& d) | ||
{ | ||
// Set label | ||
mProgressDialog.setLabelText(d.label); | ||
|
||
// Show right away | ||
mProgressDialog.setValue(0); | ||
} | ||
|
||
void FrontendConsole::handleDirective(const DProcedureStop& d) | ||
{ | ||
Q_UNUSED(d); | ||
/* Always reset the dialog regardless of whether it is visible or not as it may not be currently visible, | ||
* but queued to be visible on the next event loop iteration and therefore still needs to be hidden | ||
* immediately after. | ||
*/ | ||
mProgressDialog.reset(); | ||
} | ||
|
||
void FrontendConsole::handleDirective(const DProcedureProgress& d) { mProgressDialog.setValue(d.current); } | ||
void FrontendConsole::handleDirective(const DProcedureScale& d) { mProgressDialog.setMaximum(d.max); } | ||
void FrontendConsole::handleDirective(const DStatusUpdate& d) { mStatusHeading = d.heading; mStatusMessage = d.message; } | ||
// TODO: ^ Figure out what to do with these, since there is no tray icon here, if anything | ||
|
||
// Sync directive handlers | ||
void FrontendConsole::handleDirective(const DBlockingMessage& d) | ||
{ | ||
// TODO: Probably should add a heading like "Notice)" or something | ||
Qx::cout << d.text << Qt::endl; | ||
} | ||
|
||
// Request directive handlers | ||
void FrontendConsole::handleDirective(const DBlockingError& d, DBlockingError::Choice* response) | ||
{ | ||
Q_ASSERT(d.choices != DBlockingError::Choice::NoChoice); | ||
auto btns = choicesToButtons(d.choices); | ||
auto def = smChoiceButtonMap.toRight(d.defaultChoice); | ||
int rawRes = Qx::postBlockingError(d.error, btns, def); | ||
*response = smChoiceButtonMap.toLeft(static_cast<QMessageBox::StandardButton>(rawRes)); | ||
} | ||
|
||
void FrontendConsole::handleDirective(const DSaveFilename& d, QString* response) | ||
{ | ||
*response = QFileDialog::getSaveFileName(nullptr, d.caption, d.dir, d.filter, d.selectedFilter); | ||
} | ||
|
||
void FrontendConsole::handleDirective(const DExistingDir& d, QString* response) | ||
{ | ||
*response = QFileDialog::getExistingDirectory(nullptr, d.caption, d.startingDir); | ||
} | ||
|
||
void FrontendConsole::handleDirective(const DItemSelection& d, QString* response) | ||
{ | ||
*response = QInputDialog::getItem(nullptr, d.caption, d.label, d.items, 0, false); | ||
} | ||
|
||
void FrontendConsole::handleDirective(const DYesOrNo& d, bool* response) | ||
{ | ||
*response = QMessageBox::question(nullptr, QString(), d.question) == QMessageBox::Yes; | ||
} | ||
|
||
void FrontendConsole::setupProgressDialog() | ||
{ | ||
// Initialize dialog | ||
mProgressDialog.setCancelButtonText(u"Cancel"_s); | ||
mProgressDialog.setWindowModality(Qt::NonModal); | ||
mProgressDialog.setMinimumDuration(0); | ||
mProgressDialog.setAutoClose(true); | ||
mProgressDialog.setAutoReset(false); | ||
mProgressDialog.reset(); // Stops the auto-show timer that is started by QProgressDialog's ctor | ||
connect(&mProgressDialog, &QProgressDialog::canceled, this, [this]{ | ||
/* A bit of a bodge. Pressing the Cancel button on a progress dialog | ||
* doesn't count as closing it (it doesn't fire a close event) by the strict definition of | ||
* QWidget, so here when the progress bar is closed we manually check to see if it was | ||
* the last window if the application is ready to exit. | ||
* | ||
* Normally the progress bar should never still be open by that point, but this is here as | ||
* a fail-safe as otherwise the application would deadlock when the progress bar is closed | ||
* via the Cancel button. | ||
*/ | ||
if(readyToExit() && !windowsAreOpen()) | ||
exit(); | ||
else | ||
cancelDriverTask(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef CONSOLE_H | ||
#define CONSOLE_H | ||
|
||
// Project Includes | ||
#include "frontend/framework.h" | ||
|
||
class FrontendConsole final : public FrontendFramework | ||
{ | ||
//-Class Variables-------------------------------------------------------------------------------------------------------- | ||
private: | ||
|
||
//-Instance Variables---------------------------------------------------------------------------------------------- | ||
private: | ||
QProgressDialog mProgressDialog; | ||
QString mStatusHeading; | ||
QString mStatusMessage; | ||
|
||
//-Constructor------------------------------------------------------------------------------------------------------- | ||
public: | ||
explicit FrontendConsole(QGuiApplication* app); | ||
|
||
//-Class Functions-------------------------------------------------------------------------------------------------------- | ||
//Private: | ||
|
||
//-Instance Functions------------------------------------------------------------------------------------------------------ | ||
private: | ||
// Async directive handlers | ||
void handleDirective(const DMessage& d) override; | ||
void handleDirective(const DError& d) override; | ||
void handleDirective(const DProcedureStart& d) override; | ||
void handleDirective(const DProcedureStop& d) override; | ||
void handleDirective(const DProcedureProgress& d) override; | ||
void handleDirective(const DProcedureScale& d) override; | ||
void handleDirective(const DStatusUpdate& d) override; | ||
|
||
// Sync directive handlers | ||
void handleDirective(const DBlockingMessage& d) override; | ||
|
||
// Request directive handlers | ||
void handleDirective(const DBlockingError& d, DBlockingError::Choice* response) override; | ||
void handleDirective(const DSaveFilename& d, QString* response) override; | ||
void handleDirective(const DExistingDir& d, QString* response) override; | ||
void handleDirective(const DItemSelection& d, QString* response) override; | ||
void handleDirective(const DYesOrNo& d, bool* response) override; | ||
|
||
// Derived | ||
void setupProgressDialog(); NEEED IN NEW WAY?; | ||
}; | ||
|
||
#endif // CONSOLE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Qt Includes | ||
#include <QGuiApplication> // Seems odd, but that's just what we need for this | ||
|
||
// Project Includes | ||
#include "frontend/console.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QGuiApplication app(argc, argv); | ||
FrontendConsole frontend(&app); | ||
return frontend.exec(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters