File indexing completed on 2024-04-28 05:26:46
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include <BackendNotifierModule.h> 0010 #include <QPointer> 0011 #include <QStringList> 0012 #include <QTimer> 0013 0014 #include <KConfigWatcher> 0015 #include <KNotification> 0016 0017 class KNotification; 0018 class UnattendedUpdates; 0019 class UpdatesSettings; 0020 0021 class DiscoverNotifier : public QObject 0022 { 0023 Q_OBJECT 0024 Q_PROPERTY(QStringList modules READ loadedModules CONSTANT) 0025 Q_PROPERTY(QString iconName READ iconName NOTIFY stateChanged) 0026 Q_PROPERTY(QString message READ message NOTIFY stateChanged) 0027 Q_PROPERTY(State state READ state NOTIFY stateChanged) 0028 Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged) 0029 Q_PROPERTY(bool busy READ isBusy NOTIFY busyChanged) 0030 public: 0031 enum State { 0032 NoUpdates, 0033 NormalUpdates, 0034 SecurityUpdates, 0035 Busy, 0036 RebootRequired, 0037 Offline, 0038 }; 0039 Q_ENUM(State) 0040 0041 explicit DiscoverNotifier(QObject *parent = nullptr); 0042 ~DiscoverNotifier() override; 0043 0044 State state() const; 0045 QString iconName() const; 0046 QString message() const; 0047 bool hasUpdates() const 0048 { 0049 return m_hasUpdates; 0050 } 0051 bool hasSecurityUpdates() const 0052 { 0053 return m_hasSecurityUpdates; 0054 } 0055 0056 QStringList loadedModules() const; 0057 bool needsReboot() const 0058 { 0059 return m_needsReboot; 0060 } 0061 0062 void setBusy(bool isBusy); 0063 bool isBusy() const 0064 { 0065 return m_isBusy; 0066 } 0067 UpdatesSettings *settings() const 0068 { 0069 return m_settings; 0070 } 0071 0072 public Q_SLOTS: 0073 void recheckSystemUpdateNeeded(); 0074 void showDiscover(const QString &xdgActivationToken); 0075 void showDiscoverUpdates(const QString &xdgActivationToken); 0076 void showUpdatesNotification(); 0077 void reboot(); 0078 void foundUpgradeAction(UpgradeAction *action); 0079 0080 Q_SIGNALS: 0081 void stateChanged(); 0082 bool needsRebootChanged(bool needsReboot); 0083 void newUpgradeAction(UpgradeAction *action); 0084 bool busyChanged(); 0085 0086 private: 0087 void showRebootNotification(); 0088 void updateStatusNotifier(); 0089 void refreshUnattended(); 0090 0091 bool notifyAboutUpdates() const; 0092 0093 QList<BackendNotifierModule *> m_backends; 0094 QTimer m_timer; 0095 bool m_hasSecurityUpdates = false; 0096 bool m_hasUpdates = false; 0097 bool m_needsReboot = false; 0098 bool m_isBusy = false; 0099 QPointer<KNotification> m_updatesAvailableNotification; 0100 UnattendedUpdates *m_unattended = nullptr; 0101 KConfigWatcher::Ptr m_settingsWatcher; 0102 UpdatesSettings *m_settings; 0103 };