refactor: move ActionHandler::commands to CommandModel::commands
This commit is contained in:
@@ -57,72 +57,6 @@ void ActionsHandler::setConnection(Connection *connection)
|
|||||||
Q_EMIT connectionChanged();
|
Q_EMIT connectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList ActionsHandler::commands()
|
|
||||||
{
|
|
||||||
QVariantList commands;
|
|
||||||
|
|
||||||
// Messages commands
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/me "),
|
|
||||||
QStringLiteral("<message>"),
|
|
||||||
i18n("Displays action")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/shrug "),
|
|
||||||
QStringLiteral("<message>"),
|
|
||||||
i18n("Prepends ¯\\_(ツ)_/¯ to a plain-text message")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/lenny "),
|
|
||||||
QStringLiteral("<message>"),
|
|
||||||
i18n("Prepends ( ͡° ͜ʖ ͡°) to a plain-text message")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/plain "),
|
|
||||||
QStringLiteral("<message>"),
|
|
||||||
i18n("Sends a message as plain text, without interpreting it as markdown")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/html "),
|
|
||||||
QStringLiteral("<message>"),
|
|
||||||
i18n("Sends a message as html, without interpreting it as markdown")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/rainbow "),
|
|
||||||
QStringLiteral("<message>"),
|
|
||||||
i18n("Sends the given message coloured as a rainbow")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/rainbowme "),
|
|
||||||
QStringLiteral("<message>"),
|
|
||||||
i18n("Sends the given emote coloured as a rainbow")}));
|
|
||||||
|
|
||||||
|
|
||||||
// Actions commands
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/join "), QStringLiteral("<room-address>"),
|
|
||||||
i18n("Joins room with given address")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/part "),
|
|
||||||
QStringLiteral("[<room-address>]"),
|
|
||||||
i18n("Leave room")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/invite "),
|
|
||||||
QStringLiteral("<user-id>"),
|
|
||||||
i18n("Invites user with given id to current room")}));
|
|
||||||
|
|
||||||
commands.append(QVariant::fromValue(Command{
|
|
||||||
QStringLiteral("/react "),
|
|
||||||
QStringLiteral("<reaction text>"),
|
|
||||||
i18n("React to this message with a text")}));
|
|
||||||
|
|
||||||
// TODO more see elements /help action
|
|
||||||
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionsHandler::postMessage(const QString &text,
|
void ActionsHandler::postMessage(const QString &text,
|
||||||
const QString &attachementPath,
|
const QString &attachementPath,
|
||||||
const QString &replyEventId,
|
const QString &replyEventId,
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ class ActionsHandler : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
/// \brief List of command definition. Useful for building an autocompletion
|
|
||||||
/// engine or an help dialog.
|
|
||||||
Q_PROPERTY(QVariantList commands READ commands CONSTANT)
|
|
||||||
|
|
||||||
/// \brief The connection that will handle sending the message.
|
/// \brief The connection that will handle sending the message.
|
||||||
Q_PROPERTY(Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
|
Q_PROPERTY(Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
|
||||||
@@ -36,7 +33,7 @@ public:
|
|||||||
explicit ActionsHandler(QObject *parent = nullptr);
|
explicit ActionsHandler(QObject *parent = nullptr);
|
||||||
~ActionsHandler();
|
~ActionsHandler();
|
||||||
|
|
||||||
static QVariantList commands();
|
|
||||||
|
|
||||||
[[nodiscard]] Connection *connection() const;
|
[[nodiscard]] Connection *connection() const;
|
||||||
void setConnection(Connection *connection);
|
void setConnection(Connection *connection);
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
// SPDX-FileCopyrightText: 2021 Srevin Saju <srevinsaju@sugarlabs.org>
|
// SPDX-FileCopyrightText: 2021 Srevin Saju <srevinsaju@sugarlabs.org>
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#include <QDebug>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
#include "commandmodel.h"
|
|
||||||
#include "actionshandler.h"
|
#include "actionshandler.h"
|
||||||
|
#include "commandmodel.h"
|
||||||
|
|
||||||
|
|
||||||
QVariantList CommandModel::filterModel(const QString &filter)
|
QVariantList CommandModel::filterModel(const QString &filter)
|
||||||
{
|
{
|
||||||
QVariantList result;
|
QVariantList result;
|
||||||
|
|
||||||
for (const QVariant &e : ActionsHandler::commands()) {
|
for (const QVariant &e : CommandModel::commands()) {
|
||||||
auto command = qvariant_cast<Command>(e);
|
auto command = qvariant_cast<Command>(e);
|
||||||
if (command.command.startsWith(filter)) {
|
if (command.command.startsWith(filter)) {
|
||||||
result.append(e);
|
result.append(e);
|
||||||
@@ -23,3 +23,71 @@ QVariantList CommandModel::filterModel(const QString &filter)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariantList CommandModel::commands()
|
||||||
|
{
|
||||||
|
QVariantList commands;
|
||||||
|
|
||||||
|
// Messages commands
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/me "),
|
||||||
|
QStringLiteral("<message>"),
|
||||||
|
i18n("Displays action")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/shrug "),
|
||||||
|
QStringLiteral("<message>"),
|
||||||
|
i18n("Prepends ¯\\_(ツ)_/¯ to a plain-text message")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/lenny "),
|
||||||
|
QStringLiteral("<message>"),
|
||||||
|
i18n("Prepends ( ͡° ͜ʖ ͡°) to a plain-text message")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/plain "),
|
||||||
|
QStringLiteral("<message>"),
|
||||||
|
i18n("Sends a message as plain text, without interpreting it as markdown")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/html "),
|
||||||
|
QStringLiteral("<message>"),
|
||||||
|
i18n("Sends a message as html, without interpreting it as markdown")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/rainbow "),
|
||||||
|
QStringLiteral("<message>"),
|
||||||
|
i18n("Sends the given message coloured as a rainbow")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/rainbowme "),
|
||||||
|
QStringLiteral("<message>"),
|
||||||
|
i18n("Sends the given emote coloured as a rainbow")}));
|
||||||
|
|
||||||
|
|
||||||
|
// Actions commands
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/join "), QStringLiteral("<room-address>"),
|
||||||
|
i18n("Joins room with given address")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/part "),
|
||||||
|
QStringLiteral("[<room-address>]"),
|
||||||
|
i18n("Leave room")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/invite "),
|
||||||
|
QStringLiteral("<user-id>"),
|
||||||
|
i18n("Invites user with given id to current room")}));
|
||||||
|
|
||||||
|
commands.append(QVariant::fromValue(Command{
|
||||||
|
QStringLiteral("/react "),
|
||||||
|
QStringLiteral("<reaction text>"),
|
||||||
|
i18n("React to this message with a text")}));
|
||||||
|
|
||||||
|
// TODO more see elements /help action
|
||||||
|
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,30 +10,14 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
struct Command {
|
struct Command {
|
||||||
Command(QString p, QString a, QString h)
|
Command(const QString &p, const QString &a, const QString &h)
|
||||||
: command(std::move(std::move(p)))
|
: command(p)
|
||||||
, parameter(std::move(std::move(a)))
|
, parameter(a)
|
||||||
, help(std::move(std::move(h)))
|
, help(h)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
Command() = default;
|
Command() = default;
|
||||||
|
|
||||||
friend QDataStream &operator<<(QDataStream &arch, const Command &object)
|
|
||||||
{
|
|
||||||
arch << object.command;
|
|
||||||
arch << object.parameter;
|
|
||||||
arch << object.help;
|
|
||||||
return arch;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend QDataStream &operator>>(QDataStream &arch, Command &object)
|
|
||||||
{
|
|
||||||
arch >> object.command;
|
|
||||||
arch >> object.parameter;
|
|
||||||
arch >> object.help;
|
|
||||||
return arch;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString command;
|
QString command;
|
||||||
QString parameter;
|
QString parameter;
|
||||||
QString help;
|
QString help;
|
||||||
@@ -42,6 +26,7 @@ Q_GADGET
|
|||||||
Q_PROPERTY(QString command MEMBER command)
|
Q_PROPERTY(QString command MEMBER command)
|
||||||
Q_PROPERTY(QString parameter MEMBER parameter)
|
Q_PROPERTY(QString parameter MEMBER parameter)
|
||||||
Q_PROPERTY(QString help MEMBER help)
|
Q_PROPERTY(QString help MEMBER help)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Command)
|
Q_DECLARE_METATYPE(Command)
|
||||||
@@ -57,5 +42,5 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE QVariantList filterModel(const QString &filter);
|
Q_INVOKABLE QVariantList filterModel(const QString &filter);
|
||||||
|
static QVariantList commands();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user