diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-22 22:08:46 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-22 22:08:46 +1000 |
| commit | f9fa8390137e93da8c9b93271e7ce85dfed55b7f (patch) | |
| tree | 3de5488479524c86231d0d06a67edfcc583e13e4 /plugin/src/Caelestia/Services/service.cpp | |
| parent | plugin: delete entries after emitting signal (diff) | |
| download | caelestia-shell-f9fa8390137e93da8c9b93271e7ce85dfed55b7f.tar.gz caelestia-shell-f9fa8390137e93da8c9b93271e7ce85dfed55b7f.tar.bz2 caelestia-shell-f9fa8390137e93da8c9b93271e7ce85dfed55b7f.zip | |
plugin/service: ref by object
Use QSet and auto unref on sender destruction
Diffstat (limited to 'plugin/src/Caelestia/Services/service.cpp')
| -rw-r--r-- | plugin/src/Caelestia/Services/service.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/plugin/src/Caelestia/Services/service.cpp b/plugin/src/Caelestia/Services/service.cpp index e63b990..4993772 100644 --- a/plugin/src/Caelestia/Services/service.cpp +++ b/plugin/src/Caelestia/Services/service.cpp @@ -6,31 +6,19 @@ namespace caelestia { Service::Service(QObject* parent) - : QObject(parent) - , m_refCount(0) {} + : QObject(parent) {} -int Service::refCount() const { - return m_refCount; -} - -void Service::ref() { - if (m_refCount == 0) { +void Service::ref(QObject* sender) { + if (m_refs.isEmpty()) { start(); } - m_refCount++; - emit refCountChanged(); + QObject::connect(sender, &QObject::destroyed, this, &Service::unref); + m_refs << sender; } -void Service::unref() { - if (m_refCount == 0) { - return; - } - - m_refCount--; - emit refCountChanged(); - - if (m_refCount == 0) { +void Service::unref(QObject* sender) { + if (m_refs.remove(sender) && m_refs.isEmpty()) { stop(); } } |