Changeset View
Changeset View
Standalone View
Standalone View
kded/osdmanager.cpp
Show All 24 Lines | |||||
25 | #include <KScreen/Output> | 25 | #include <KScreen/Output> | ||
26 | 26 | | |||
27 | #include <QDBusConnection> | 27 | #include <QDBusConnection> | ||
28 | 28 | | |||
29 | #include <QQmlEngine> | 29 | #include <QQmlEngine> | ||
30 | 30 | | |||
31 | namespace KScreen { | 31 | namespace KScreen { | ||
32 | 32 | | |||
33 | OsdAction::OsdAction(QObject *parent) | | |||
34 | : QObject(parent) | | |||
35 | { | | |||
36 | } | | |||
37 | | ||||
38 | class OsdActionImpl : public OsdAction | 33 | class OsdActionImpl : public OsdAction | ||
39 | { | 34 | { | ||
40 | Q_OBJECT | 35 | Q_OBJECT | ||
41 | public: | 36 | public: | ||
42 | OsdActionImpl(QObject *parent = nullptr) | 37 | OsdActionImpl(QObject *parent = nullptr) | ||
43 | : OsdAction(parent) | 38 | : OsdAction(parent) | ||
44 | {} | 39 | {} | ||
45 | 40 | | |||
46 | void setOsd(Osd *osd) { | 41 | void setOsd(Osd *osd) { | ||
47 | connect(osd, &Osd::osdActionSelected, | 42 | connect(osd, &Osd::osdActionSelected, | ||
48 | this, [this](Action action) { | 43 | this, [this](Action action) { | ||
49 | Q_EMIT selected(action); | 44 | Q_EMIT selected(action); | ||
50 | deleteLater(); | 45 | deleteLater(); | ||
51 | }); | 46 | }); | ||
52 | } | 47 | } | ||
53 | }; | 48 | }; | ||
54 | 49 | | |||
55 | OsdManager::OsdManager(QObject *parent) | 50 | OsdManager::OsdManager(QObject *parent) | ||
56 | : QObject(parent) | 51 | : QObject(parent) | ||
57 | , m_cleanupTimer(new QTimer(this)) | 52 | , m_cleanupTimer(new QTimer(this)) | ||
58 | { | 53 | { | ||
59 | qmlRegisterUncreatableType<OsdAction>("org.kde.KScreen", 1, 0, "OsdAction", QStringLiteral("You cannot create OsdAction")); | 54 | qmlRegisterSingletonType<KScreen::OsdAction>("org.kde.KScreen", 1, 0, "OsdAction", [](QQmlEngine *, QJSEngine *) -> QObject* { | ||
55 | return new KScreen::OsdAction(); | ||||
56 | }); | ||||
60 | 57 | | |||
61 | // free up memory when the osd hasn't been used for more than 1 minute | 58 | // free up memory when the osd hasn't been used for more than 1 minute | ||
62 | m_cleanupTimer->setInterval(60000); | 59 | m_cleanupTimer->setInterval(60000); | ||
63 | m_cleanupTimer->setSingleShot(true); | 60 | m_cleanupTimer->setSingleShot(true); | ||
64 | connect(m_cleanupTimer, &QTimer::timeout, this, [this]() { | 61 | connect(m_cleanupTimer, &QTimer::timeout, this, [this]() { | ||
65 | hideOsd(); | 62 | hideOsd(); | ||
66 | }); | 63 | }); | ||
67 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kscreen.osdService")); | 64 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kscreen.osdService")); | ||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |