Changeset View
Changeset View
Standalone View
Standalone View
daemon/actions/bundled/keyboardbrightnesscontrol.cpp
Show All 37 Lines | |||||
38 | #include <KGlobalAccel> | 38 | #include <KGlobalAccel> | ||
39 | 39 | | |||
40 | #include <QDBusInterface> | 40 | #include <QDBusInterface> | ||
41 | #include <QDBusPendingCall> | 41 | #include <QDBusPendingCall> | ||
42 | 42 | | |||
43 | namespace PowerDevil { | 43 | namespace PowerDevil { | ||
44 | namespace BundledActions { | 44 | namespace BundledActions { | ||
45 | 45 | | |||
46 | static const QString s_globalAccelComponent = QStringLiteral("kded5"); | | |||
47 | | ||||
48 | KeyboardBrightnessControl::KeyboardBrightnessControl(QObject* parent) | 46 | KeyboardBrightnessControl::KeyboardBrightnessControl(QObject* parent) | ||
49 | : Action(parent) | 47 | : Action(parent) | ||
50 | { | 48 | { | ||
51 | // DBus | 49 | // DBus | ||
52 | new KeyboardBrightnessControlAdaptor(this); | 50 | new KeyboardBrightnessControlAdaptor(this); | ||
53 | 51 | | |||
54 | setRequiredPolicies(PowerDevil::PolicyAgent::ChangeScreenSettings); | 52 | setRequiredPolicies(PowerDevil::PolicyAgent::ChangeScreenSettings); | ||
55 | 53 | | |||
56 | connect(core()->backend(), &PowerDevil::BackendInterface::brightnessChanged, this, &PowerDevil::BundledActions::KeyboardBrightnessControl::onBrightnessChangedFromBackend); | 54 | connect(core()->backend(), &PowerDevil::BackendInterface::brightnessChanged, this, &PowerDevil::BundledActions::KeyboardBrightnessControl::onBrightnessChangedFromBackend); | ||
57 | 55 | | |||
58 | KActionCollection* actionCollection = new KActionCollection( this ); | 56 | KActionCollection* actionCollection = new KActionCollection( this ); | ||
59 | actionCollection->setComponentDisplayName(i18nc("Name for powerdevil shortcuts category", "Power Management")); | 57 | actionCollection->setComponentDisplayName(i18nc("Name for powerdevil shortcuts category", "Power Management")); | ||
60 | KGlobalAccel *accel = KGlobalAccel::self(); | 58 | KGlobalAccel *accel = KGlobalAccel::self(); | ||
61 | 59 | | |||
62 | QAction *globalAction = actionCollection->addAction(QLatin1String("Increase Keyboard Brightness")); | 60 | QAction *globalAction = actionCollection->addAction(QLatin1String("Increase Keyboard Brightness")); | ||
63 | globalAction->setText(i18nc("@action:inmenu Global shortcut", "Increase Keyboard Brightness")); | 61 | globalAction->setText(i18nc("@action:inmenu Global shortcut", "Increase Keyboard Brightness")); | ||
64 | globalAction->setProperty("componentName", s_globalAccelComponent); | | |||
65 | accel->setGlobalShortcut(globalAction, Qt::Key_KeyboardBrightnessUp); | 62 | accel->setGlobalShortcut(globalAction, Qt::Key_KeyboardBrightnessUp); | ||
66 | connect(globalAction, SIGNAL(triggered(bool)), SLOT(increaseKeyboardBrightness())); | 63 | connect(globalAction, SIGNAL(triggered(bool)), SLOT(increaseKeyboardBrightness())); | ||
67 | 64 | | |||
68 | globalAction = actionCollection->addAction(QLatin1String("Decrease Keyboard Brightness")); | 65 | globalAction = actionCollection->addAction(QLatin1String("Decrease Keyboard Brightness")); | ||
69 | globalAction->setText(i18nc("@action:inmenu Global shortcut", "Decrease Keyboard Brightness")); | 66 | globalAction->setText(i18nc("@action:inmenu Global shortcut", "Decrease Keyboard Brightness")); | ||
70 | globalAction->setProperty("componentName", s_globalAccelComponent); | | |||
71 | accel->setGlobalShortcut(globalAction, Qt::Key_KeyboardBrightnessDown); | 67 | accel->setGlobalShortcut(globalAction, Qt::Key_KeyboardBrightnessDown); | ||
72 | connect(globalAction, SIGNAL(triggered(bool)), SLOT(decreaseKeyboardBrightness())); | 68 | connect(globalAction, SIGNAL(triggered(bool)), SLOT(decreaseKeyboardBrightness())); | ||
73 | 69 | | |||
74 | globalAction = actionCollection->addAction("Toggle Keyboard Backlight"); | 70 | globalAction = actionCollection->addAction("Toggle Keyboard Backlight"); | ||
75 | globalAction->setText(i18nc("@action:inmenu Global shortcut", "Toggle Keyboard Backlight")); | 71 | globalAction->setText(i18nc("@action:inmenu Global shortcut", "Toggle Keyboard Backlight")); | ||
76 | globalAction->setProperty("componentName", s_globalAccelComponent); | | |||
77 | accel->setGlobalShortcut(globalAction, Qt::Key_KeyboardLightOnOff); | 72 | accel->setGlobalShortcut(globalAction, Qt::Key_KeyboardLightOnOff); | ||
78 | connect(globalAction, SIGNAL(triggered(bool)), SLOT(toggleKeyboardBacklight())); | 73 | connect(globalAction, SIGNAL(triggered(bool)), SLOT(toggleKeyboardBacklight())); | ||
79 | 74 | | |||
80 | // My laptop sets the keyboard brightness to zero when I close the lid and it suspends | 75 | // My laptop sets the keyboard brightness to zero when I close the lid and it suspends | ||
81 | // this makes sure the keyboard brightness is restored when we wake up :) | 76 | // this makes sure the keyboard brightness is restored when we wake up :) | ||
82 | connect(backend(), &PowerDevil::BackendInterface::resumeFromSuspend, this, [this] { | 77 | connect(backend(), &PowerDevil::BackendInterface::resumeFromSuspend, this, [this] { | ||
83 | setKeyboardBrightnessSilent(keyboardBrightness()); | 78 | setKeyboardBrightnessSilent(keyboardBrightness()); | ||
84 | }); | 79 | }); | ||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |