summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/Services/service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/src/Caelestia/Services/service.cpp')
-rw-r--r--plugin/src/Caelestia/Services/service.cpp26
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();
}
}