Changeset View
Changeset View
Standalone View
Standalone View
colorcorrection/clockskewnotifier.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Vlad Zahorodnii <vladzzag@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License along | ||||
15 | * with this program; if not, write to the Free Software Foundation, Inc., | ||||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "clockskewnotifier.h" | ||||
20 | #include "clockskewnotifierengine_p.h" | ||||
21 | | ||||
22 | namespace KWin | ||||
23 | { | ||||
24 | | ||||
25 | class ClockSkewNotifier::Private | ||||
26 | { | ||||
27 | public: | ||||
28 | void loadNotifierEngine(); | ||||
29 | void unloadNotifierEngine(); | ||||
30 | | ||||
31 | ClockSkewNotifier *notifier = nullptr; | ||||
32 | ClockSkewNotifierEngine *engine = nullptr; | ||||
33 | bool isActive = false; | ||||
34 | }; | ||||
35 | | ||||
36 | void ClockSkewNotifier::Private::loadNotifierEngine() | ||||
37 | { | ||||
38 | engine = ClockSkewNotifierEngine::create(notifier); | ||||
39 | | ||||
40 | if (engine) { | ||||
41 | QObject::connect(engine, &ClockSkewNotifierEngine::clockSkewed, notifier, &ClockSkewNotifier::clockSkewed); | ||||
42 | } | ||||
43 | } | ||||
44 | | ||||
45 | void ClockSkewNotifier::Private::unloadNotifierEngine() | ||||
46 | { | ||||
47 | if (!engine) { | ||||
48 | return; | ||||
49 | } | ||||
50 | | ||||
51 | QObject::disconnect(engine, &ClockSkewNotifierEngine::clockSkewed, notifier, &ClockSkewNotifier::clockSkewed); | ||||
52 | engine->deleteLater(); | ||||
53 | | ||||
54 | engine = nullptr; | ||||
55 | } | ||||
56 | | ||||
57 | ClockSkewNotifier::ClockSkewNotifier(QObject *parent) | ||||
58 | : QObject(parent) | ||||
59 | , d(new Private) | ||||
60 | { | ||||
61 | d->notifier = this; | ||||
62 | } | ||||
63 | | ||||
64 | ClockSkewNotifier::~ClockSkewNotifier() | ||||
65 | { | ||||
66 | } | ||||
67 | | ||||
68 | bool ClockSkewNotifier::isActive() const | ||||
69 | { | ||||
70 | return d->isActive; | ||||
71 | } | ||||
72 | | ||||
73 | void ClockSkewNotifier::setActive(bool set) | ||||
74 | { | ||||
75 | if (d->isActive == set) { | ||||
76 | return; | ||||
77 | } | ||||
78 | | ||||
79 | d->isActive = set; | ||||
80 | | ||||
81 | if (d->isActive) { | ||||
82 | d->loadNotifierEngine(); | ||||
83 | } else { | ||||
84 | d->unloadNotifierEngine(); | ||||
85 | } | ||||
86 | | ||||
87 | emit activeChanged(); | ||||
88 | } | ||||
89 | | ||||
90 | } // namespace KWin |