Changeset View
Changeset View
Standalone View
Standalone View
greeter/greeterapp.cpp
Show All 23 Lines | |||||
24 | #include "noaccessnetworkaccessmanagerfactory.h" | 24 | #include "noaccessnetworkaccessmanagerfactory.h" | ||
25 | 25 | | |||
26 | // KDE | 26 | // KDE | ||
27 | #include <KAuthorized> | 27 | #include <KAuthorized> | ||
28 | #include <KCrash> | 28 | #include <KCrash> | ||
29 | #include <kdeclarative/kdeclarative.h> | 29 | #include <kdeclarative/kdeclarative.h> | ||
30 | #include <KDeclarative/KQuickAddons/QuickViewSharedEngine> | 30 | #include <KDeclarative/KQuickAddons/QuickViewSharedEngine> | ||
31 | #include <KUser> | 31 | #include <KUser> | ||
32 | #include <Solid/PowerManagement> | | |||
33 | //Plasma | 32 | //Plasma | ||
34 | #include <KPackage/Package> | 33 | #include <KPackage/Package> | ||
35 | #include <KPackage/PackageStructure> | 34 | #include <KPackage/PackageStructure> | ||
36 | #include <KPackage/PackageLoader> | 35 | #include <KPackage/PackageLoader> | ||
37 | // KWayland | 36 | // KWayland | ||
38 | #include <KWayland/Client/connection_thread.h> | 37 | #include <KWayland/Client/connection_thread.h> | ||
39 | #include <KWayland/Client/event_queue.h> | 38 | #include <KWayland/Client/event_queue.h> | ||
40 | #include <KWayland/Client/plasmashell.h> | 39 | #include <KWayland/Client/plasmashell.h> | ||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | 176 | { | |||
178 | const int nScreens = screens().count(); | 177 | const int nScreens = screens().count(); | ||
179 | // remove useless views and savers | 178 | // remove useless views and savers | ||
180 | while (m_views.count() > nScreens) { | 179 | while (m_views.count() > nScreens) { | ||
181 | m_views.takeLast()->deleteLater(); | 180 | m_views.takeLast()->deleteLater(); | ||
182 | } | 181 | } | ||
183 | 182 | | |||
184 | // extend views and savers to current demand | 183 | // extend views and savers to current demand | ||
185 | const bool canLogout = KAuthorized::authorizeKAction(QStringLiteral("logout")) && KAuthorized::authorize(QStringLiteral("logout")); | 184 | const bool canLogout = KAuthorized::authorizeKAction(QStringLiteral("logout")) && KAuthorized::authorize(QStringLiteral("logout")); | ||
186 | const QSet<Solid::PowerManagement::SleepState> spdMethods = Solid::PowerManagement::supportedSleepStates(); | | |||
187 | for (int i = m_views.count(); i < nScreens; ++i) { | 185 | for (int i = m_views.count(); i < nScreens; ++i) { | ||
188 | connect(QGuiApplication::screens()[i], &QObject::destroyed, this, &UnlockApp::desktopResized); | 186 | connect(QGuiApplication::screens()[i], &QObject::destroyed, this, &UnlockApp::desktopResized); | ||
189 | // create the view | 187 | // create the view | ||
190 | auto *view = new KQuickAddons::QuickViewSharedEngine(); | 188 | auto *view = new KQuickAddons::QuickViewSharedEngine(); | ||
191 | view->setColor(Qt::black); | 189 | view->setColor(Qt::black); | ||
192 | 190 | | |||
193 | // first create KDeclarative, to be sure that it created a KIO Network Factory | 191 | // first create KDeclarative, to be sure that it created a KIO Network Factory | ||
194 | KDeclarative::KDeclarative declarative; | 192 | KDeclarative::KDeclarative declarative; | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 238 | if (view->status() == QQmlComponent::Error) { | |||
245 | view->setSource(fallbackUrl); | 243 | view->setSource(fallbackUrl); | ||
246 | } | 244 | } | ||
247 | view->setResizeMode(KQuickAddons::QuickViewSharedEngine::SizeRootObjectToView); | 245 | view->setResizeMode(KQuickAddons::QuickViewSharedEngine::SizeRootObjectToView); | ||
248 | 246 | | |||
249 | QQmlProperty lockProperty(view->rootObject(), QStringLiteral("locked")); | 247 | QQmlProperty lockProperty(view->rootObject(), QStringLiteral("locked")); | ||
250 | lockProperty.write(m_immediateLock || (!m_noLock && !m_delayedLockTimer)); | 248 | lockProperty.write(m_immediateLock || (!m_noLock && !m_delayedLockTimer)); | ||
251 | 249 | | |||
252 | QQmlProperty sleepProperty(view->rootObject(), QStringLiteral("suspendToRamSupported")); | 250 | QQmlProperty sleepProperty(view->rootObject(), QStringLiteral("suspendToRamSupported")); | ||
253 | sleepProperty.write(spdMethods.contains(Solid::PowerManagement::SuspendState)); | 251 | sleepProperty.write(m_canSuspend); | ||
254 | if (spdMethods.contains(Solid::PowerManagement::SuspendState) && | 252 | if (view->rootObject()->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("suspendToRam()").constData()) != -1) { | ||
255 | view->rootObject()->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("suspendToRam()").constData()) != -1) { | | |||
256 | connect(view->rootObject(), SIGNAL(suspendToRam()), SLOT(suspendToRam())); | 253 | connect(view->rootObject(), SIGNAL(suspendToRam()), SLOT(suspendToRam())); | ||
257 | } | 254 | } | ||
258 | 255 | | |||
259 | QQmlProperty hibernateProperty(view->rootObject(), QStringLiteral("suspendToDiskSupported")); | 256 | QQmlProperty hibernateProperty(view->rootObject(), QStringLiteral("suspendToDiskSupported")); | ||
260 | hibernateProperty.write(spdMethods.contains(Solid::PowerManagement::HibernateState)); | 257 | hibernateProperty.write(m_canHibernate); | ||
261 | if (spdMethods.contains(Solid::PowerManagement::HibernateState) && | 258 | if (view->rootObject()->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("suspendToDisk()").constData()) != -1) { | ||
262 | view->rootObject()->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("suspendToDisk()").constData()) != -1) { | | |||
263 | connect(view->rootObject(), SIGNAL(suspendToDisk()), SLOT(suspendToDisk())); | 259 | connect(view->rootObject(), SIGNAL(suspendToDisk()), SLOT(suspendToDisk())); | ||
264 | } | 260 | } | ||
265 | 261 | | |||
266 | // verify that the engine's controller didn't change | 262 | // verify that the engine's controller didn't change | ||
267 | Q_ASSERT(dynamic_cast<NoAccessNetworkAccessManagerFactory*>(view->engine()->networkAccessManagerFactory())); | 263 | Q_ASSERT(dynamic_cast<NoAccessNetworkAccessManagerFactory*>(view->engine()->networkAccessManagerFactory())); | ||
268 | 264 | | |||
269 | m_views << view; | 265 | m_views << view; | ||
270 | } | 266 | } | ||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Line(s) | |||||
381 | { | 377 | { | ||
382 | if (m_ignoreRequests) { | 378 | if (m_ignoreRequests) { | ||
383 | return; | 379 | return; | ||
384 | } | 380 | } | ||
385 | 381 | | |||
386 | m_ignoreRequests = true; | 382 | m_ignoreRequests = true; | ||
387 | m_resetRequestIgnoreTimer->start(); | 383 | m_resetRequestIgnoreTimer->start(); | ||
388 | 384 | | |||
389 | Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState, 0, 0); | 385 | org_kde_ksld_suspendSystem(m_ksldInterface); | ||
390 | 386 | | |||
391 | } | 387 | } | ||
392 | 388 | | |||
393 | void UnlockApp::suspendToDisk() | 389 | void UnlockApp::suspendToDisk() | ||
394 | { | 390 | { | ||
395 | if (m_ignoreRequests) { | 391 | if (m_ignoreRequests) { | ||
396 | return; | 392 | return; | ||
397 | } | 393 | } | ||
398 | 394 | | |||
399 | m_ignoreRequests = true; | 395 | m_ignoreRequests = true; | ||
400 | m_resetRequestIgnoreTimer->start(); | 396 | m_resetRequestIgnoreTimer->start(); | ||
401 | 397 | | |||
402 | Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState, 0, 0); | 398 | org_kde_ksld_hibernateSystem(m_ksldInterface); | ||
403 | } | 399 | } | ||
404 | 400 | | |||
405 | void UnlockApp::setTesting(bool enable) | 401 | void UnlockApp::setTesting(bool enable) | ||
406 | { | 402 | { | ||
407 | m_testing = enable; | 403 | m_testing = enable; | ||
408 | if (m_views.isEmpty()) { | 404 | if (m_views.isEmpty()) { | ||
409 | return; | 405 | return; | ||
410 | } | 406 | } | ||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | |||||
518 | } | 514 | } | ||
519 | 515 | | |||
520 | static void osdText(void *data, org_kde_ksld *org_kde_ksld, const char *icon, const char *text) | 516 | static void osdText(void *data, org_kde_ksld *org_kde_ksld, const char *icon, const char *text) | ||
521 | { | 517 | { | ||
522 | Q_UNUSED(org_kde_ksld) | 518 | Q_UNUSED(org_kde_ksld) | ||
523 | reinterpret_cast<UnlockApp*>(data)->osdText(QString::fromUtf8(icon), QString::fromUtf8(text)); | 519 | reinterpret_cast<UnlockApp*>(data)->osdText(QString::fromUtf8(icon), QString::fromUtf8(text)); | ||
524 | } | 520 | } | ||
525 | 521 | | |||
522 | static void canSuspend(void *data, org_kde_ksld *org_kde_ksld, uint suspend) | ||||
523 | { | ||||
524 | Q_UNUSED(org_kde_ksld) | ||||
525 | reinterpret_cast<UnlockApp*>(data)->updateCanSuspend(suspend); | ||||
526 | } | ||||
527 | | ||||
528 | static void canHibernate(void *data, org_kde_ksld *org_kde_ksld, uint hibernate) | ||||
529 | { | ||||
530 | Q_UNUSED(org_kde_ksld) | ||||
531 | reinterpret_cast<UnlockApp*>(data)->updateCanHibernate(hibernate); | ||||
532 | } | ||||
533 | | ||||
526 | static const struct org_kde_ksld_listener s_listener { | 534 | static const struct org_kde_ksld_listener s_listener { | ||
527 | osdProgress, | 535 | osdProgress, | ||
528 | osdText | 536 | osdText, | ||
537 | canSuspend, | ||||
538 | canHibernate | ||||
529 | }; | 539 | }; | ||
530 | 540 | | |||
531 | void UnlockApp::setKsldSocket(int socket) | 541 | void UnlockApp::setKsldSocket(int socket) | ||
532 | { | 542 | { | ||
533 | using namespace KWayland::Client; | 543 | using namespace KWayland::Client; | ||
534 | m_ksldConnection = new ConnectionThread; | 544 | m_ksldConnection = new ConnectionThread; | ||
535 | m_ksldConnection->setSocketFd(socket); | 545 | m_ksldConnection->setSocketFd(socket); | ||
536 | 546 | | |||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 599 | for (auto v : m_views) { | |||
593 | } | 603 | } | ||
594 | osd->setProperty("showingProgress", false); | 604 | osd->setProperty("showingProgress", false); | ||
595 | osd->setProperty("osdValue", additionalText); | 605 | osd->setProperty("osdValue", additionalText); | ||
596 | osd->setProperty("icon", icon); | 606 | osd->setProperty("icon", icon); | ||
597 | QMetaObject::invokeMethod(osd, "show"); | 607 | QMetaObject::invokeMethod(osd, "show"); | ||
598 | } | 608 | } | ||
599 | } | 609 | } | ||
600 | 610 | | |||
611 | void UnlockApp::updateCanSuspend(bool set) | ||||
612 | { | ||||
613 | if (m_canSuspend == set) { | ||||
614 | return; | ||||
615 | } | ||||
616 | m_canSuspend = set; | ||||
617 | for (auto it = m_views.constBegin(), end = m_views.constEnd(); it != end; ++it) { | ||||
broulik: perhaps cache the end?
for (auto it = m_views.constBegin(), end = m_views.constEnd(); it !=… | |||||
618 | QQmlProperty sleepProperty((*it)->rootObject(), QStringLiteral("suspendToRamSupported")); | ||||
619 | sleepProperty.write(m_canSuspend); | ||||
620 | } | ||||
621 | } | ||||
622 | | ||||
623 | void UnlockApp::updateCanHibernate(bool set) | ||||
624 | { | ||||
625 | if (m_canHibernate == set) { | ||||
626 | return; | ||||
627 | } | ||||
628 | m_canHibernate = set; | ||||
629 | for (auto it = m_views.constBegin(), end = m_views.constEnd(); it != end; ++it) { | ||||
630 | QQmlProperty hibernateProperty((*it)->rootObject(), QStringLiteral("suspendToDiskSupported")); | ||||
631 | hibernateProperty.write(m_canHibernate); | ||||
632 | } | ||||
633 | } | ||||
634 | | ||||
601 | } // namespace | 635 | } // namespace | ||
602 | 636 | |
perhaps cache the end?
for (auto it = m_views.constBegin(), end = m_views.constEnd(); it != end; ++it)