From 539d51998791cd7c08d2a6e6ed9cc9b93f613e66 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sat, 1 May 2021 17:16:21 +0300 Subject: [PATCH] feat: improve commands() method of ActionHandler to use Command type --- src/actionshandler.cpp | 115 +++++++++++++++++------------------------ src/actionshandler.h | 2 +- 2 files changed, 49 insertions(+), 68 deletions(-) diff --git a/src/actionshandler.cpp b/src/actionshandler.cpp index 51400e730..a1c453341 100644 --- a/src/actionshandler.cpp +++ b/src/actionshandler.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "actionshandler.h" +#include "commandmodel.h" #include "csapi/joining.h" @@ -56,86 +57,66 @@ void ActionsHandler::setConnection(Connection *connection) Q_EMIT connectionChanged(); } -QVariantList ActionsHandler::commands() const +QVariantList ActionsHandler::commands() { QVariantList commands; + // Messages commands - commands.append({QStringLiteral("prefix"), - QStringLiteral("/shrug "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Prepends ¯\\_(ツ)_/¯ to a plain-text message")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/me "), + QStringLiteral(""), + i18n("Displays action")})); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/lenny "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Prepends ( ͡° ͜ʖ ͡°) to a plain-text message")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/shrug "), + QStringLiteral(""), + i18n("Prepends ¯\\_(ツ)_/¯ to a plain-text message")})); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/plain "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Sends a message as plain text, without interpreting it as markdown")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/lenny "), + QStringLiteral(""), + i18n("Prepends ( ͡° ͜ʖ ͡°) to a plain-text message")})); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/html "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Sends a message as html, without interpreting it as markdown")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/plain "), + QStringLiteral(""), + i18n("Sends a message as plain text, without interpreting it as markdown")})); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/rainbow "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Sends the given message coloured as a rainbow")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/html "), + QStringLiteral(""), + i18n("Sends a message as html, without interpreting it as markdown")})); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/rainbowme "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Sends the given emote coloured as a rainbow")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/rainbow "), + QStringLiteral(""), + i18n("Sends the given message coloured as a rainbow")})); + + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/rainbowme "), + QStringLiteral(""), + i18n("Sends the given emote coloured as a rainbow")})); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/me "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Displays action")}); // Actions commands - commands.append({QStringLiteral("prefix"), - QStringLiteral("/join "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Joins room with given address")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/join "), QStringLiteral(""), + i18n("Joins room with given address")})); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/part "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", "[]"), - QStringLiteral("help"), - i18n("Leave room")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/part "), + QStringLiteral("[]"), + i18n("Leave room")})); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/invite "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("Invites user with given id to current room")}); - commands.append({QStringLiteral("prefix"), - QStringLiteral("/react "), - QStringLiteral("parameter"), - i18nc("@label Parameter of a command", ""), - QStringLiteral("help"), - i18n("React to this message with a text")}); + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/invite "), + QStringLiteral(""), + i18n("Invites user with given id to current room")})); + + commands.append(QVariant::fromValue(Command{ + QStringLiteral("/react "), + QStringLiteral(""), + i18n("React to this message with a text")})); // TODO more see elements /help action diff --git a/src/actionshandler.h b/src/actionshandler.h index 7880ae9ac..0e36cc60c 100644 --- a/src/actionshandler.h +++ b/src/actionshandler.h @@ -36,7 +36,7 @@ public: explicit ActionsHandler(QObject *parent = nullptr); ~ActionsHandler(); - QVariantList commands() const; + static QVariantList commands(); [[nodiscard]] Connection *connection() const; void setConnection(Connection *connection);