From 0802609fd88341f37c34d197b0a6d569881a18cf Mon Sep 17 00:00:00 2001 From: Anselm Busse Date: Fri, 12 Mar 2021 16:22:16 +0100 Subject: [PATCH] Correcting for PR comments --- app/cli/commandlineparser.cpp | 13 ++++++++++-- app/cli/commandlineparser.h | 2 ++ app/cli/listapps.cpp | 37 +++++++++++++++++++++++------------ app/cli/listapps.h | 3 ++- app/gui/CliListAppsSegue.qml | 2 +- app/main.cpp | 2 +- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/app/cli/commandlineparser.cpp b/app/cli/commandlineparser.cpp index d2c2ac7b..e09215f1 100644 --- a/app/cli/commandlineparser.cpp +++ b/app/cli/commandlineparser.cpp @@ -541,18 +541,22 @@ void ListCommandLineParser::parse(const QStringList &args) parser.setupCommonOptions(); parser.setApplicationDescription( "\n" - "List the available apps on the given host as CSV:\n" - "\tName, ID, HDR Support, App Collection Game, Hidden, Direct Launch, Path to Boxart" + "List the available apps on the given host." ); parser.addPositionalArgument("list", "list available apps"); parser.addPositionalArgument("host", "Host computer name, UUID, or IP address", ""); + parser.addFlagOption("csv", "Print as CSV with additional information"); + if (!parser.parse(args)) { parser.showError(parser.errorText()); } parser.handleUnknownOptions(); + + m_PrintCSV = parser.isSet("csv"); + // This method will not return and terminates the process if --version or // --help is specified parser.handleHelpAndVersionOptions(); @@ -569,3 +573,8 @@ QString ListCommandLineParser::getHost() const { return m_Host; } + +bool ListCommandLineParser::isPrintCSV() const +{ + return m_PrintCSV; +} diff --git a/app/cli/commandlineparser.h b/app/cli/commandlineparser.h index d003d7fb..13201dad 100644 --- a/app/cli/commandlineparser.h +++ b/app/cli/commandlineparser.h @@ -83,7 +83,9 @@ public: void parse(const QStringList &args); QString getHost() const; + bool isPrintCSV() const; private: QString m_Host; + bool m_PrintCSV; }; diff --git a/app/cli/listapps.cpp b/app/cli/listapps.cpp index ee5e621c..9b8ddbf4 100644 --- a/app/cli/listapps.cpp +++ b/app/cli/listapps.cpp @@ -102,9 +102,7 @@ public: // Occurs when a computer is updated case Event::ComputerUpdated: if (m_State == StateSeekApp) { - for (int i = 0; i < m_Computer->appList.length(); i++) { - printApp(m_Computer->appList[i]); - } + m_PrintCSV ? printAppsCSV(m_Computer->appList) : printApps(m_Computer->appList); QCoreApplication::exit(0); } @@ -112,15 +110,28 @@ public: } } - void printApp(NvApp app) const + void printApps(QVector apps) { + for (int i = 0; i < apps.length(); i++) { + fprintf(stdout, "%s\n", qPrintable(apps[i].name)); + } + } + + void printAppsCSV(QVector apps) { + fprintf(stdout, "Name, ID, HDR Support, App Collection Game, Hidden, Direct Launch, Boxart URL\n"); + for (int i = 0; i < apps.length(); i++) { + printAppCSV(apps[i]); + } + } + + void printAppCSV(NvApp app) const { - fprintf(stdout, "%s,%d,%s,%s,%s,%s,%s\n", qPrintable(app.name), - app.id, - app.hdrSupported ? "true" : "false", - app.isAppCollectorGame ? "true" : "false", - app.hidden ? "true" : "false", - app.directLaunch ? "true" : "false", - qPrintable(m_BoxArtManager->loadBoxArt(m_Computer, app).toDisplayString())); + fprintf(stdout, "\"%s\",%d,%s,%s,%s,%s,\"%s\"\n", qPrintable(app.name), + app.id, + app.hdrSupported ? "true" : "false", + app.isAppCollectorGame ? "true" : "false", + app.hidden ? "true" : "false", + app.directLaunch ? "true" : "false", + qPrintable(m_BoxArtManager->loadBoxArt(m_Computer, app).toDisplayString())); } Launcher *q_ptr; @@ -131,9 +142,10 @@ public: NvComputer *m_Computer; State m_State; QTimer *m_TimeoutTimer; + bool m_PrintCSV; }; -Launcher::Launcher(QString computer, QObject *parent) +Launcher::Launcher(QString computer, bool printCSV, QObject *parent) : QObject(parent), m_DPtr(new LauncherPrivate(this)) { @@ -142,6 +154,7 @@ Launcher::Launcher(QString computer, QObject *parent) d->m_State = StateInit; d->m_TimeoutTimer = new QTimer(this); d->m_TimeoutTimer->setSingleShot(true); + d->m_PrintCSV = printCSV; connect(d->m_TimeoutTimer, &QTimer::timeout, this, &Launcher::onComputerSeekTimeout); } diff --git a/app/cli/listapps.h b/app/cli/listapps.h index 84181246..b982a11a 100644 --- a/app/cli/listapps.h +++ b/app/cli/listapps.h @@ -17,7 +17,7 @@ class Launcher : public QObject Q_DECLARE_PRIVATE_D(m_DPtr, Launcher) public: - explicit Launcher(QString computer, QObject *parent = nullptr); + explicit Launcher(QString computer, bool printCSV, QObject *parent = nullptr); ~Launcher(); Q_INVOKABLE void execute(ComputerManager *manager); @@ -35,6 +35,7 @@ private slots: private: QScopedPointer m_DPtr; + bool m_Print_CSV; }; } diff --git a/app/gui/CliListAppsSegue.qml b/app/gui/CliListAppsSegue.qml index ccbe860c..5bac64df 100644 --- a/app/gui/CliListAppsSegue.qml +++ b/app/gui/CliListAppsSegue.qml @@ -10,7 +10,7 @@ Item { } function onSearchingApps() { - stageLabel.text = qsTr("Searching for Apps...") + stageLabel.text = qsTr("Loading app list...") } function onFailure(message) { diff --git a/app/main.cpp b/app/main.cpp index ab0d00a6..72fae03a 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -626,7 +626,7 @@ int main(int argc, char *argv[]) initialView = "qrc:/gui/CliListAppsSegue.qml"; ListCommandLineParser listParser; listParser.parse(app.arguments()); - auto launcher = new CliListApps::Launcher(listParser.getHost(), &app); + auto launcher = new CliListApps::Launcher(listParser.getHost(), listParser.isPrintCSV(), &app); engine.rootContext()->setContextProperty("launcher", launcher); break; }