Changeset View
Changeset View
Standalone View
Standalone View
dataengines/powermanagement/powermanagementjob.cpp
Show All 35 Lines | 35 | PowerManagementJob::PowerManagementJob(const QString &operation, QMap<QString, QVariant> ¶meters, QObject *parent) : | |||
---|---|---|---|---|---|
36 | ServiceJob(parent->objectName(), operation, parameters, parent) | 36 | ServiceJob(parent->objectName(), operation, parameters, parent) | ||
37 | { | 37 | { | ||
38 | } | 38 | } | ||
39 | 39 | | |||
40 | PowerManagementJob::~PowerManagementJob() | 40 | PowerManagementJob::~PowerManagementJob() | ||
41 | { | 41 | { | ||
42 | } | 42 | } | ||
43 | 43 | | |||
44 | static void callWhenFinished(const QDBusPendingCall& pending, std::function<void()> func, QObject* parent) | ||||
45 | { | ||||
46 | QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(pending, parent); | ||||
47 | QObject::connect(watcher, &QDBusPendingCallWatcher::finished, | ||||
48 | parent, [func](QDBusPendingCallWatcher* watcher) { | ||||
49 | watcher->deleteLater(); | ||||
50 | func(); | ||||
51 | }); | ||||
52 | } | ||||
53 | | ||||
44 | void PowerManagementJob::start() | 54 | void PowerManagementJob::start() | ||
45 | { | 55 | { | ||
46 | const QString operation = operationName(); | 56 | const QString operation = operationName(); | ||
47 | //qDebug() << "starting operation ... " << operation; | 57 | //qDebug() << "starting operation ... " << operation; | ||
48 | 58 | | |||
49 | if (operation == QLatin1String("lockScreen")) { | 59 | if (operation == QLatin1String("lockScreen")) { | ||
50 | if (KAuthorized::authorizeAction(QStringLiteral("lock_screen"))) { | 60 | if (KAuthorized::authorizeAction(QStringLiteral("lock_screen"))) { | ||
51 | const QString interface(QStringLiteral("org.freedesktop.ScreenSaver")); | 61 | const QString interface(QStringLiteral("org.freedesktop.ScreenSaver")); | ||
Show All 35 Lines | 95 | } else if (operation == QLatin1String("stopSuppressingSleep")) { | |||
87 | return; | 97 | return; | ||
88 | } else if (operation == QLatin1String("beginSuppressingScreenPowerManagement")) { | 98 | } else if (operation == QLatin1String("beginSuppressingScreenPowerManagement")) { | ||
89 | setResult(Solid::PowerManagement::beginSuppressingScreenPowerManagement(parameters().value(QStringLiteral("reason")).toString())); | 99 | setResult(Solid::PowerManagement::beginSuppressingScreenPowerManagement(parameters().value(QStringLiteral("reason")).toString())); | ||
90 | return; | 100 | return; | ||
91 | } else if (operation == QLatin1String("stopSuppressingScreenPowerManagement")) { | 101 | } else if (operation == QLatin1String("stopSuppressingScreenPowerManagement")) { | ||
92 | setResult(Solid::PowerManagement::stopSuppressingScreenPowerManagement(parameters().value(QStringLiteral("cookie")).toInt())); | 102 | setResult(Solid::PowerManagement::stopSuppressingScreenPowerManagement(parameters().value(QStringLiteral("cookie")).toInt())); | ||
93 | return; | 103 | return; | ||
94 | } else if (operation == QLatin1String("setBrightness")) { | 104 | } else if (operation == QLatin1String("setBrightness")) { | ||
95 | setScreenBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool()); | 105 | auto pending = setScreenBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool()); | ||
96 | setResult(true); | 106 | callWhenFinished(pending, [this] { setResult(true); }, this); | ||
97 | return; | 107 | return; | ||
98 | } else if (operation == QLatin1String("setKeyboardBrightness")) { | 108 | } else if (operation == QLatin1String("setKeyboardBrightness")) { | ||
99 | setKeyboardBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool()); | 109 | auto pending = setKeyboardBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool()); | ||
100 | setResult(true); | 110 | callWhenFinished(pending, [this] { setResult(true); }, this); | ||
101 | return; | 111 | return; | ||
102 | } | 112 | } | ||
103 | 113 | | |||
104 | qDebug() << "don't know what to do with " << operation; | 114 | qDebug() << "don't know what to do with " << operation; | ||
105 | setResult(false); | 115 | setResult(false); | ||
106 | } | 116 | } | ||
107 | 117 | | |||
108 | void PowerManagementJob::setScreenBrightness(int value, bool silent) | 118 | QDBusPendingCall PowerManagementJob::setScreenBrightness(int value, bool silent) | ||
109 | { | 119 | { | ||
110 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"), | 120 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"), | ||
111 | QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"), | 121 | QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"), | ||
112 | QStringLiteral("org.kde.Solid.PowerManagement.Actions.BrightnessControl"), | 122 | QStringLiteral("org.kde.Solid.PowerManagement.Actions.BrightnessControl"), | ||
113 | silent ? "setBrightnessSilent" : "setBrightness"); | 123 | silent ? "setBrightnessSilent" : "setBrightness"); | ||
114 | msg << value; | 124 | msg << value; | ||
115 | QDBusConnection::sessionBus().asyncCall(msg); | 125 | return QDBusConnection::sessionBus().asyncCall(msg); | ||
116 | } | 126 | } | ||
117 | 127 | | |||
118 | void PowerManagementJob::setKeyboardBrightness(int value, bool silent) | 128 | QDBusPendingCall PowerManagementJob::setKeyboardBrightness(int value, bool silent) | ||
119 | { | 129 | { | ||
120 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"), | 130 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.Solid.PowerManagement"), | ||
121 | QStringLiteral("/org/kde/Solid/PowerManagement/Actions/KeyboardBrightnessControl"), | 131 | QStringLiteral("/org/kde/Solid/PowerManagement/Actions/KeyboardBrightnessControl"), | ||
122 | QStringLiteral("org.kde.Solid.PowerManagement.Actions.KeyboardBrightnessControl"), | 132 | QStringLiteral("org.kde.Solid.PowerManagement.Actions.KeyboardBrightnessControl"), | ||
123 | silent ? "setKeyboardBrightnessSilent" : "setKeyboardBrightness"); | 133 | silent ? "setKeyboardBrightnessSilent" : "setKeyboardBrightness"); | ||
124 | msg << value; | 134 | msg << value; | ||
125 | QDBusConnection::sessionBus().asyncCall(msg); | 135 | return QDBusConnection::sessionBus().asyncCall(msg); | ||
126 | } | 136 | } | ||
127 | 137 | | |||
128 | void PowerManagementJob::requestShutDown() | 138 | void PowerManagementJob::requestShutDown() | ||
129 | { | 139 | { | ||
130 | KWorkSpace::requestShutDown(); | 140 | KWorkSpace::requestShutDown(); | ||
131 | } | 141 | } | ||
132 | 142 | |