Changeset View
Changeset View
Standalone View
Standalone View
notifier/DiscoverNotifier.cpp
Show All 29 Lines | |||||
30 | #include <KLocalizedString> | 30 | #include <KLocalizedString> | ||
31 | #include <KNotification> | 31 | #include <KNotification> | ||
32 | #include <KPluginFactory> | 32 | #include <KPluginFactory> | ||
33 | 33 | | |||
34 | #include "../libdiscover/utils.h" | 34 | #include "../libdiscover/utils.h" | ||
35 | 35 | | |||
36 | DiscoverNotifier::DiscoverNotifier(QObject * parent) | 36 | DiscoverNotifier::DiscoverNotifier(QObject * parent) | ||
37 | : QObject(parent) | 37 | : QObject(parent) | ||
38 | , m_manager(new QNetworkConfigurationManager(this)) | | |||
39 | { | 38 | { | ||
40 | configurationChanged(); | 39 | configurationChanged(); | ||
41 | 40 | | |||
42 | m_backends = BackendNotifierFactory().allBackends(); | 41 | m_backends = BackendNotifierFactory().allBackends(); | ||
43 | foreach(BackendNotifierModule* module, m_backends) { | 42 | foreach(BackendNotifierModule* module, m_backends) { | ||
44 | connect(module, &BackendNotifierModule::foundUpdates, this, &DiscoverNotifier::updateStatusNotifier); | 43 | connect(module, &BackendNotifierModule::foundUpdates, this, &DiscoverNotifier::updateStatusNotifier); | ||
45 | connect(module, &BackendNotifierModule::needsRebootChanged, this, [this]() { | 44 | connect(module, &BackendNotifierModule::needsRebootChanged, this, [this]() { | ||
46 | if (!m_needsReboot) { | 45 | if (!m_needsReboot) { | ||
47 | m_needsReboot = true; | 46 | m_needsReboot = true; | ||
48 | showRebootNotification(); | 47 | showRebootNotification(); | ||
49 | Q_EMIT stateChanged(); | 48 | Q_EMIT stateChanged(); | ||
50 | Q_EMIT needsRebootChanged(true); | 49 | Q_EMIT needsRebootChanged(true); | ||
51 | } | 50 | } | ||
52 | }); | 51 | }); | ||
53 | 52 | | |||
54 | connect(module, &BackendNotifierModule::foundUpgradeAction, this, &DiscoverNotifier::foundUpgradeAction); | 53 | connect(module, &BackendNotifierModule::foundUpgradeAction, this, &DiscoverNotifier::foundUpgradeAction); | ||
55 | } | 54 | } | ||
56 | connect(&m_timer, &QTimer::timeout, this, &DiscoverNotifier::showUpdatesNotification); | 55 | connect(&m_timer, &QTimer::timeout, this, &DiscoverNotifier::showUpdatesNotification); | ||
57 | m_timer.setSingleShot(true); | 56 | m_timer.setSingleShot(true); | ||
58 | m_timer.setInterval(1000); | 57 | m_timer.setInterval(1000); | ||
59 | updateStatusNotifier(); | 58 | updateStatusNotifier(); | ||
60 | 59 | | |||
61 | connect(m_manager, &QNetworkConfigurationManager::onlineStateChanged, this, &DiscoverNotifier::stateChanged); | | |||
62 | | ||||
63 | //Only fetch updates after the system is comfortably booted | 60 | //Only fetch updates after the system is comfortably booted | ||
64 | QTimer::singleShot(10000, this, &DiscoverNotifier::recheckSystemUpdateNeeded); | 61 | QTimer::singleShot(10000, this, &DiscoverNotifier::recheckSystemUpdateNeeded); | ||
65 | } | 62 | } | ||
66 | 63 | | |||
67 | DiscoverNotifier::~DiscoverNotifier() = default; | 64 | DiscoverNotifier::~DiscoverNotifier() = default; | ||
68 | 65 | | |||
69 | void DiscoverNotifier::configurationChanged() | 66 | void DiscoverNotifier::configurationChanged() | ||
70 | { | 67 | { | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 99 | { | |||
115 | 112 | | |||
116 | emit stateChanged(); | 113 | emit stateChanged(); | ||
117 | } | 114 | } | ||
118 | 115 | | |||
119 | DiscoverNotifier::State DiscoverNotifier::state() const | 116 | DiscoverNotifier::State DiscoverNotifier::state() const | ||
120 | { | 117 | { | ||
121 | if (m_needsReboot) | 118 | if (m_needsReboot) | ||
122 | return RebootRequired; | 119 | return RebootRequired; | ||
123 | else if (!m_manager->isOnline()) | 120 | else if (m_manager && !m_manager->isOnline()) | ||
124 | return Offline; | 121 | return Offline; | ||
125 | else if (m_hasSecurityUpdates) | 122 | else if (m_hasSecurityUpdates) | ||
126 | return SecurityUpdates; | 123 | return SecurityUpdates; | ||
127 | else if (m_hasUpdates) | 124 | else if (m_hasUpdates) | ||
128 | return NormalUpdates; | 125 | return NormalUpdates; | ||
129 | else | 126 | else | ||
130 | return NoUpdates; | 127 | return NoUpdates; | ||
131 | } | 128 | } | ||
Show All 29 Lines | 149 | switch(state()) { | |||
161 | case Offline: | 158 | case Offline: | ||
162 | return i18n("Offline"); | 159 | return i18n("Offline"); | ||
163 | } | 160 | } | ||
164 | return QString(); | 161 | return QString(); | ||
165 | } | 162 | } | ||
166 | 163 | | |||
167 | void DiscoverNotifier::recheckSystemUpdateNeeded() | 164 | void DiscoverNotifier::recheckSystemUpdateNeeded() | ||
168 | { | 165 | { | ||
166 | if (!m_manager) { | ||||
apol: Explain why in a short comment. Something like `// delay initializing, Qt does a bunch of… | |||||
167 | m_manager = new QNetworkConfigurationManager(this); | ||||
168 | connect(m_manager, &QNetworkConfigurationManager::onlineStateChanged, this, &DiscoverNotifier::stateChanged); | ||||
169 | if (!m_manager->isOnline()) { | ||||
170 | emit stateChanged(); | ||||
171 | } | ||||
172 | } | ||||
173 | | ||||
169 | foreach(BackendNotifierModule* module, m_backends) | 174 | foreach(BackendNotifierModule* module, m_backends) | ||
170 | module->recheckSystemUpdateNeeded(); | 175 | module->recheckSystemUpdateNeeded(); | ||
171 | } | 176 | } | ||
172 | 177 | | |||
173 | QStringList DiscoverNotifier::loadedModules() const | 178 | QStringList DiscoverNotifier::loadedModules() const | ||
174 | { | 179 | { | ||
175 | QStringList ret; | 180 | QStringList ret; | ||
176 | for(BackendNotifierModule* module : m_backends) | 181 | for(BackendNotifierModule* module : m_backends) | ||
Show All 37 Lines |
Explain why in a short comment. Something like // delay initializing, Qt does a bunch of blocking calls there when using networkmanager