Disclaimer: this post is mainly for Developers!!
That said, I thought a blog post would have been better to explain the new, cool Inhibition feature in PowerDevil/Solid. On my message to the list I’ve been unclear, and let me say _don’t use the DBus interface_ but the provided methods. So let me show a sample of an application inhibiting suspension.
kDebug() << "Setting inhibition";
m_cookie = Solid::PowerManagement::beginSuppressingSleep("We're testing inhibition, don't bother us!");
kDebug() << "Releasing inhibition";
int main(int argc, char **argv)
KAboutData aboutData( "testinhibit", 0, ki18n("Test Inhibition"),
"1.0", ki18n(""), KAboutData::License_GPL,
KCmdLineArgs::init(argc, argv, &aboutData);
QTimer::singleShot(15000, &test, SLOT(releaseInhibition()));
Seen how easy it is? You just have to call the static method Solid::PowerManagement::beginSuppressingSleep() specifying a reason for your inhibition, and store the cookie it returns. If you try to suspend after you call it, you get this:
Yeah, I’ve also improved notifications, but this will come in a future post😀 The user will be notified and suspension won’t happen.
When you want to release the lock, Solid::PowerManagement::stopSuppressingSleep() is your friend, just pass it the cookie you stored before (you did store it, right?), and that’s enough.
This feature is really cool. I see a lot of cool usages, for example in video players, package managers, whatever else. And given the fact it’s just a private member+2 lines of code, integration is really easy🙂
P.S.: A post with all new cool stuff in Powerdevil is coming, and PowerDevil 1.3.0 for KDE4.1 is coming too🙂