[OpenDocString] kdeconnect-kde (cpp)
remotecommandsplugin.cpp
RemoteCommandsPlugin::RemoteCommandsPlugin(QObject *parent, const QVariantList &args)
    : KdeConnectPlugin(parent, args)
    , m_commands("{}")
    , m_canAddCommand(false)
{
}
Constructs a plugin object and adds remote commands to it.
RemoteCommandsPlugin::~RemoteCommandsPlugin() = default;
Sets the default configuration for the remote commands plugin.
bool RemoteCommandsPlugin::receivePacket(const NetworkPacket &np)
{
    if (np.has(QStringLiteral("commandList"))) {
        m_canAddCommand = np.get(QStringLiteral("canAddCommand"));
        setCommands(np.get(QStringLiteral("commandList")));
        return true;
    }

    return false;
}
This retrieves the canAddCommand value from a network packet and sets the commands list to it.
void RemoteCommandsPlugin::connected()
{
    NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{QStringLiteral("requestCommandList"), true}});
    sendPacket(np);
}
This sends a network packet that requests the command list from the remote commands plugin.
QString RemoteCommandsPlugin::dbusPath() const
{
    return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/remotecommands");
}
Returns the dbus path as a QString.
void RemoteCommandsPlugin::setCommands(const QByteArray &cmds)
{
    if (m_commands != cmds) {
        m_commands = cmds;
        Q_EMIT commandsChanged(m_commands);
    }
}
Sets the commands buffer to the internal list and emits the signal commandsChanged.
void RemoteCommandsPlugin::triggerCommand(const QString &key)
{
    NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{QStringLiteral("key"), key}});
    sendPacket(np);
}
This sends a network packet that triggers a command with the given key.
void RemoteCommandsPlugin::editCommands()
{
    NetworkPacket np(PACKET_TYPE_RUNCOMMAND_REQUEST, {{QStringLiteral("setup"), true}});
    sendPacket(np);
}
This sends a network packet that sets the setup parameter to true and then sends it to the end of the network package.