[OpenDocString] kdeconnect-kde (cpp)
screensaverinhibitplugin-macos.cpp
ScreensaverInhibitPlugin::ScreensaverInhibitPlugin(QObject *parent, const QVariantList &args)
    : KdeConnectPlugin(parent, args)
    , m_caffeinateProcess(nullptr)
{
    if (QFile::exists(QStringLiteral("/usr/bin/caffeinate"))) {
        m_caffeinateProcess = new QProcess();
        m_caffeinateProcess->setProgram(QStringLiteral("caffeinate"));
        m_caffeinateProcess->setArguments({QStringLiteral("-d")}); // Prevent the display from sleeping
        m_caffeinateProcess->start();
    } else {
        qWarning(KDECONNECT_PLUGIN_SCREENSAVERINHIBIT) << "Cannot find caffeinate on macOS install";
    }
}
This constructor builds a KdeConnectPlugin object and its m_caffeinateProcess object. It first checks if the caffeinate binary exists, and if it exists, sets up a QProcess object to run the screensaver inhibit process. It also sets up the signal sleeping process for the display.
ScreensaverInhibitPlugin::~ScreensaverInhibitPlugin()
{
    if (m_caffeinateProcess != nullptr) {
        m_caffeinateProcess->terminate();
        m_caffeinateProcess = nullptr;
    }
}
This removes the caffeinate process if it exists.
void ScreensaverInhibitPlugin::connected()
{
}
This implements the connection attempt at the end of the procedure.
bool ScreensaverInhibitPlugin::receivePacket(const NetworkPacket &np)
{
    Q_UNUSED(np);
    return false;
}
This retrieves a packet from the inhibit plugin and marks it for delivery.