matrixion/src/CommandCompleter.cpp

259 lines
9.9 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "CommandCompleter.h"
#include "CompletionModelRoles.h"
CommandCompleter::CommandCompleter(QObject *parent)
: QAbstractListModel(parent)
{
}
QHash<int, QByteArray>
CommandCompleter::roleNames() const
{
return {
{CompletionModel::CompletionRole, "completionRole"},
{CompletionModel::SearchRole, "searchRole"},
{CompletionModel::SearchRole2, "searchRole2"},
{Roles::Name, "name"},
{Roles::Description, "description"},
};
}
QVariant
CommandCompleter::data(const QModelIndex &index, int role) const
{
if (hasIndex(index.row(), index.column(), index.parent())) {
switch (role) {
case CompletionModel::CompletionRole:
// append space where applicable in a completion
switch (index.row()) {
case Me:
return QStringLiteral("/me ");
case React:
return QStringLiteral("/react ");
case Join:
return QStringLiteral("/join ");
case Knock:
return QStringLiteral("/knock ");
case Part:
return QStringLiteral("/part ");
case Leave:
return QStringLiteral("/leave ");
case Invite:
return QStringLiteral("/invite @");
case Kick:
return QStringLiteral("/kick @");
case Ban:
return QStringLiteral("/ban @");
case Unban:
return QStringLiteral("/unban @");
case Redact:
return QStringLiteral("/redact ");
case Roomnick:
return QStringLiteral("/roomnick ");
case Shrug:
return QStringLiteral("/shrug");
case Fliptable:
return QStringLiteral("/fliptable");
case Unfliptable:
return QStringLiteral("/unfliptable");
case Sovietflip:
return QStringLiteral("/sovietflip");
case ClearTimeline:
return QStringLiteral("/clear-timeline");
case ResetState:
return QStringLiteral("/reset-state");
case RotateMegolmSession:
return QStringLiteral("/rotate-megolm-session");
case Md:
return QStringLiteral("/md ");
case Cmark:
return QStringLiteral("/cmark ");
case Plain:
return QStringLiteral("/plain ");
case Rainbow:
return QStringLiteral("/rainbow ");
case RainbowMe:
return QStringLiteral("/rainbowme ");
case Notice:
return QStringLiteral("/notice ");
case RainbowNotice:
return QStringLiteral("/rainbownotice ");
case Confetti:
return QStringLiteral("/confetti ");
case RainbowConfetti:
return QStringLiteral("/rainbowconfetti ");
case Rainfall:
return QStringLiteral("/rainfall ");
2023-03-22 02:44:00 +03:00
case Msgtype:
return QStringLiteral("/msgtype ");
case Goto:
return QStringLiteral("/goto ");
case ConvertToDm:
return QStringLiteral("/converttodm");
case ConvertToRoom:
return QStringLiteral("/converttoroom");
2023-12-12 04:29:36 +03:00
case Ignore:
return QStringLiteral("/ignore");
default:
return {};
}
case CompletionModel::SearchRole:
case Qt::DisplayRole:
case Roles::Name:
switch (index.row()) {
case Me:
return tr("/me <message>");
case React:
return tr("/react <text>");
case Join:
2023-02-10 22:56:05 +03:00
return tr("/join <!roomid|#alias> [reason]");
case Knock:
2023-02-10 22:56:05 +03:00
return tr("/knock <!roomid|#alias> [reason]");
case Part:
return tr("/part [reason]");
case Leave:
return tr("/leave [reason]");
case Invite:
2023-02-10 22:56:05 +03:00
return tr("/invite <@userid> [reason]");
case Kick:
2023-02-10 22:56:05 +03:00
return tr("/kick <@userid> [reason]");
case Ban:
2023-02-10 22:56:05 +03:00
return tr("/ban <@userid> [reason]");
case Unban:
2023-02-10 22:56:05 +03:00
return tr("/unban <@userid> [reason]");
case Redact:
2023-02-10 22:56:05 +03:00
return tr("/redact <$eventid|@userid>");
case Roomnick:
return tr("/roomnick <displayname>");
case Shrug:
return tr("/shrug [message]");
case Fliptable:
return QStringLiteral("/fliptable");
case Unfliptable:
return QStringLiteral("/unfliptable");
case Sovietflip:
return QStringLiteral("/sovietflip");
case ClearTimeline:
return QStringLiteral("/clear-timeline");
case ResetState:
return QStringLiteral("/reset-state");
case RotateMegolmSession:
return QStringLiteral("/rotate-megolm-session");
case Md:
2023-02-10 22:56:05 +03:00
return tr("/md <message>");
case Cmark:
2023-02-10 22:56:05 +03:00
return tr("/cmark <message>");
case Plain:
2023-02-10 22:56:05 +03:00
return tr("/plain <message>");
case Rainbow:
2023-02-10 22:56:05 +03:00
return tr("/rainbow <message>");
case RainbowMe:
2023-02-10 22:56:05 +03:00
return tr("/rainbowme <message>");
case Notice:
2023-02-10 22:56:05 +03:00
return tr("/notice <message>");
case RainbowNotice:
2023-02-10 22:56:05 +03:00
return tr("/rainbownotice <message>");
case Confetti:
return tr("/confetti [message]");
case RainbowConfetti:
return tr("/rainbowconfetti [message]");
case Rainfall:
return tr("/rainfall [message]");
2023-03-22 02:44:00 +03:00
case Msgtype:
return tr("/msgtype <msgtype> [message]");
case Goto:
2023-02-10 22:56:05 +03:00
return tr("/goto <message reference>");
case ConvertToDm:
return QStringLiteral("/converttodm");
case ConvertToRoom:
return QStringLiteral("/converttoroom");
2023-12-12 04:29:36 +03:00
case Ignore:
return QStringLiteral("/ignore <@userid>");
default:
return {};
}
case CompletionModel::SearchRole2:
case Roles::Description:
switch (index.row()) {
case Me:
return tr("Send a message expressing an action.");
case React:
return tr("Send <text> as a reaction when youre replying to a message.");
case Join:
return tr("Join a room. Reason is optional.");
case Knock:
return tr("Ask to join a room. Reason is optional.");
case Part:
return tr("Leave a room. Reason is optional.");
case Leave:
return tr("Leave a room. Reason is optional.");
case Invite:
return tr("Invite a user into the current room. Reason is optional.");
case Kick:
return tr("Kick a user from the current room. Reason is optional.");
case Ban:
return tr("Ban a user from the current room. Reason is optional.");
case Unban:
return tr("Unban a user in the current room. Reason is optional.");
case Redact:
return tr("Redact an event or all locally cached messages of a user.");
case Roomnick:
return tr("Change your displayname in this room.");
case Shrug:
return tr("¯\\_(ツ)_/¯ with an optional message.");
case Fliptable:
return tr("(╯°□°) ");
case Unfliptable:
return tr("┯━┯╭( º _ º╭)");
case Sovietflip:
return tr("ノ┬─┬ノ ︵ ( \\o°o)\\");
case ClearTimeline:
return tr("Clear the currently cached messages in this room.");
case ResetState:
return tr("Refetch the state in this room.");
case RotateMegolmSession:
return tr("Rotate the current symmetric encryption key.");
case Md:
return tr("Send a markdown formatted message (ignoring the global setting).");
case Cmark:
return tr(
"Send a commonmark formatted message disabling most extensions compared to /md.");
case Plain:
return tr("Send an unformatted message (ignoring the global setting).");
case Rainbow:
return tr("Send a message in rainbow colors.");
case RainbowMe:
return tr("Send /me in rainbow colors.");
case Notice:
return tr("Send a bot message.");
case RainbowNotice:
return tr("Send a bot message in rainbow colors.");
case Confetti:
return tr("Send a message with confetti.");
case RainbowConfetti:
return tr("Send a message in rainbow colors with confetti.");
case Rainfall:
return tr("Send a message with rain.");
2023-03-22 02:44:00 +03:00
case Msgtype:
return tr("Send a message with a custom message type.");
case Goto:
2023-02-10 22:56:05 +03:00
return tr("Go to a specific message using an event id, index or matrix: link");
case ConvertToDm:
return tr("Convert this room to a direct chat.");
case ConvertToRoom:
return tr("Convert this direct chat into a room.");
2023-12-12 04:29:36 +03:00
case Ignore:
return tr("Ignores a user.");
default:
return {};
}
}
}
return {};
}