Exemple #1
0
IoObject *IoAppleSensors_setKeyboardBrightness(IoAppleSensors *self, IoObject *locals, IoMessage *m)
{
	/*doc AppleSensors setKeyboardBrightness(aNumber)
		Sets the keyboard brightness. Returns self.
	*/
	float v = IoMessage_locals_floatArgAt_(m, locals, 0);
	setKeyboardBrightness(v);
	return self;
}
int
main(int argc, char **argv)
{
    float x;
    float setb;
    /**
    if (argc > 1 && sscanf(argv[1], "%f", &setb) == 1) {
        setKeyboardBrightness(setb);
    }**/
    for (int i = 0; i < 10; i++) {
        x += 0.1;
        usleep(100000);
        printf("%s", "\tSleeping\n");
        setKeyboardBrightness(x);
        printf("%f", getKeyboardBrightness());
    }
  exit(0);
}
void PowerManagementJob::start()
{
    const QString operation = operationName();
    //qDebug() << "starting operation  ... " << operation;

    if (operation == QLatin1String("lockScreen")) {
        if (KAuthorized::authorizeKAction(QStringLiteral("lock_screen"))) {
            const QString interface(QStringLiteral("org.freedesktop.ScreenSaver"));
            QDBusInterface screensaver(interface, QStringLiteral("/ScreenSaver"));
            screensaver.asyncCall(QStringLiteral("Lock"));
            setResult(true);
            return;
        }
        qDebug() << "operation denied " << operation;
        setResult(false);
        return;
    } else if (operation == QLatin1String("suspend") || operation == QLatin1String("suspendToRam")) {
        Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState, 0, 0);
        setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::SuspendState));
        return;
    } else if (operation == QLatin1String("suspendToDisk")) {
        Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState, 0, 0);
        setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::HibernateState));
        return;
    } else if (operation == QLatin1String("suspendHybrid")) {
        Solid::PowerManagement::requestSleep(Solid::PowerManagement::HybridSuspendState, 0, 0);
        setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::HybridSuspendState));
        return;
    } else if (operation == QLatin1String("requestShutDown")) {
        requestShutDown();
        setResult(true);
        return;
    } else if (operation == QLatin1String("switchUser")) {
        // Taken from kickoff/core/itemhandlers.cpp
        org::kde::krunner::App krunner(QStringLiteral("org.kde.krunner"), QStringLiteral("/App"), QDBusConnection::sessionBus());
        krunner.switchUser();
        setResult(true);
        return;
    } else if (operation == QLatin1String("beginSuppressingSleep")) {
        setResult(Solid::PowerManagement::beginSuppressingSleep(parameters().value(QStringLiteral("reason")).toString()));
        return;
    } else if (operation == QLatin1String("stopSuppressingSleep")) {
        setResult(Solid::PowerManagement::stopSuppressingSleep(parameters().value(QStringLiteral("cookie")).toInt()));
        return;
    } else if (operation == QLatin1String("beginSuppressingScreenPowerManagement")) {
        setResult(Solid::PowerManagement::beginSuppressingScreenPowerManagement(parameters().value(QStringLiteral("reason")).toString()));
        return;
    } else if (operation == QLatin1String("stopSuppressingScreenPowerManagement")) {
        setResult(Solid::PowerManagement::stopSuppressingScreenPowerManagement(parameters().value(QStringLiteral("cookie")).toInt()));
        return;
    } else if (operation == QLatin1String("setBrightness")) {
        setScreenBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool());
        setResult(true);
        return;
    } else if (operation == QLatin1String("setKeyboardBrightness")) {
        setKeyboardBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool());
        setResult(true);
        return;
    }

    qDebug() << "don't know what to do with " << operation;
    setResult(false);
}