File indexing completed on 2024-04-28 16:44:05

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 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0019 class QNetworkConfigurationManager;
0020 #endif
0021 class UnattendedUpdates;
0022 class UpdatesSettings;
0023 
0024 class DiscoverNotifier : public QObject
0025 {
0026     Q_OBJECT
0027     Q_PROPERTY(QStringList modules READ loadedModules CONSTANT)
0028     Q_PROPERTY(QString iconName READ iconName NOTIFY stateChanged)
0029     Q_PROPERTY(QString message READ message NOTIFY stateChanged)
0030     Q_PROPERTY(State state READ state NOTIFY stateChanged)
0031     Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
0032     Q_PROPERTY(bool isBusy READ isBusy NOTIFY busyChanged)
0033 public:
0034     enum State {
0035         NoUpdates,
0036         NormalUpdates,
0037         SecurityUpdates,
0038         Busy,
0039         RebootRequired,
0040         Offline,
0041     };
0042     Q_ENUM(State)
0043 
0044     explicit DiscoverNotifier(QObject *parent = nullptr);
0045     ~DiscoverNotifier() override;
0046 
0047     State state() const;
0048     QString iconName() const;
0049     QString message() const;
0050     bool hasUpdates() const
0051     {
0052         return m_hasUpdates;
0053     }
0054     bool hasSecurityUpdates() const
0055     {
0056         return m_hasSecurityUpdates;
0057     }
0058 
0059     QStringList loadedModules() const;
0060     bool needsReboot() const
0061     {
0062         return m_needsReboot;
0063     }
0064 
0065     void setBusy(bool isBusy);
0066     bool isBusy() const
0067     {
0068         return m_isBusy;
0069     }
0070     UpdatesSettings *settings() const
0071     {
0072         return m_settings;
0073     }
0074 
0075 public Q_SLOTS:
0076     void recheckSystemUpdateNeeded();
0077     void showDiscover(const QString &xdgActivationToken);
0078     void showDiscoverUpdates(const QString &xdgActivationToken);
0079     void showUpdatesNotification();
0080     void reboot();
0081     void foundUpgradeAction(UpgradeAction *action);
0082 
0083 Q_SIGNALS:
0084     void stateChanged();
0085     bool needsRebootChanged(bool needsReboot);
0086     void newUpgradeAction(UpgradeAction *action);
0087     bool busyChanged(bool isBusy);
0088 
0089 private:
0090     void showRebootNotification();
0091     void updateStatusNotifier();
0092     void refreshUnattended();
0093 
0094     bool notifyAboutUpdates() const;
0095 
0096     QList<BackendNotifierModule *> m_backends;
0097     QTimer m_timer;
0098     bool m_hasSecurityUpdates = false;
0099     bool m_hasUpdates = false;
0100     bool m_needsReboot = false;
0101     bool m_isBusy = false;
0102 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0103     QNetworkConfigurationManager *m_manager = nullptr;
0104 #endif
0105     QPointer<KNotification> m_updatesAvailableNotification;
0106     UnattendedUpdates *m_unattended = nullptr;
0107     KConfigWatcher::Ptr m_settingsWatcher;
0108     UpdatesSettings *m_settings;
0109 };