1 /*
2  *   SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3  *
4  *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5  */
6 
7 #ifndef DISCOVERNOTIFIERMODULE_H
8 #define DISCOVERNOTIFIERMODULE_H
9 
10 #include <BackendNotifierModule.h>
11 #include <QPointer>
12 #include <QStringList>
13 #include <QTimer>
14 
15 #include <KConfigWatcher>
16 #include <KNotification>
17 
18 class KNotification;
19 class QNetworkConfigurationManager;
20 class UnattendedUpdates;
21 
22 class DiscoverNotifier : public QObject
23 {
24     Q_OBJECT
25     Q_PROPERTY(QStringList modules READ loadedModules CONSTANT)
26     Q_PROPERTY(QString iconName READ iconName NOTIFY stateChanged)
27     Q_PROPERTY(QString message READ message NOTIFY stateChanged)
28     Q_PROPERTY(State state READ state NOTIFY stateChanged)
29     Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
30     Q_PROPERTY(bool isBusy READ isBusy NOTIFY busyChanged)
31 public:
32     enum State {
33         NoUpdates,
34         NormalUpdates,
35         SecurityUpdates,
36         Busy,
37         RebootRequired,
38         Offline,
39     };
40     Q_ENUM(State)
41 
42     explicit DiscoverNotifier(QObject *parent = nullptr);
43     ~DiscoverNotifier() override;
44 
45     State state() const;
46     QString iconName() const;
47     QString message() const;
hasUpdates()48     bool hasUpdates() const
49     {
50         return m_hasUpdates;
51     }
hasSecurityUpdates()52     bool hasSecurityUpdates() const
53     {
54         return m_hasSecurityUpdates;
55     }
56 
57     QStringList loadedModules() const;
needsReboot()58     bool needsReboot() const
59     {
60         return m_needsReboot;
61     }
62 
63     void setBusy(bool isBusy);
isBusy()64     bool isBusy() const
65     {
66         return m_isBusy;
67     }
68 
69 public Q_SLOTS:
70     void recheckSystemUpdateNeeded();
71     void showDiscover(const QString &xdgActivationToken);
72     void showDiscoverUpdates(const QString &xdgActivationToken);
73     void showUpdatesNotification();
74     void reboot();
75     void foundUpgradeAction(UpgradeAction *action);
76 
77 Q_SIGNALS:
78     void stateChanged();
79     bool needsRebootChanged(bool needsReboot);
80     void newUpgradeAction(UpgradeAction *action);
81     bool busyChanged(bool isBusy);
82 
83 private:
84     void showRebootNotification();
85     void updateStatusNotifier();
86     void refreshUnattended();
87 
88     QList<BackendNotifierModule *> m_backends;
89     QTimer m_timer;
90     bool m_hasSecurityUpdates = false;
91     bool m_hasUpdates = false;
92     bool m_needsReboot = false;
93     bool m_isBusy = false;
94     QNetworkConfigurationManager *m_manager = nullptr;
95     QPointer<KNotification> m_updatesAvailableNotification;
96     UnattendedUpdates *m_unattended = nullptr;
97     KConfigWatcher::Ptr m_settingsWatcher;
98     class UpdatesSettings *m_settings;
99 };
100 
101 #endif // ABSTRACTKDEDMODULE_H
102