Commit 0ef13233 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Don't offer system updates while offline

Discover will start giving errors anyway and there's not much to do.

BUG: 404339
parent fc903987
......@@ -8,6 +8,7 @@ target_link_libraries(DiscoverNotifierDeclarativePlugin
KF5::KIOWidgets
Qt5::Qml
Qt5::DBus
Qt5::Network
Discover::Notifiers
)
......
......@@ -23,6 +23,7 @@
#include <QDebug>
#include <QDBusInterface>
#include <QDBusPendingReply>
#include <QNetworkConfigurationManager>
#include <KConfig>
#include <KConfigGroup>
#include <KRun>
......@@ -34,6 +35,7 @@
DiscoverNotifier::DiscoverNotifier(QObject * parent)
: QObject(parent)
, m_manager(new QNetworkConfigurationManager(this))
{
configurationChanged();
......@@ -44,7 +46,7 @@ DiscoverNotifier::DiscoverNotifier(QObject * parent)
if (!m_needsReboot) {
m_needsReboot = true;
showRebootNotification();
Q_EMIT updatesChanged();
Q_EMIT stateChanged();
Q_EMIT needsRebootChanged(true);
}
});
......@@ -55,6 +57,8 @@ DiscoverNotifier::DiscoverNotifier(QObject * parent)
m_timer.setSingleShot(true);
m_timer.setInterval(1000);
updateStatusNotifier();
connect(m_manager, &QNetworkConfigurationManager::onlineStateChanged, this, &DiscoverNotifier::stateChanged);
}
DiscoverNotifier::~DiscoverNotifier() = default;
......@@ -79,7 +83,7 @@ void DiscoverNotifier::showDiscoverUpdates()
void DiscoverNotifier::showUpdatesNotification()
{
if (state()==NoUpdates) {
if (state() != NormalUpdates && state() != SecurityUpdates) {
//it's not very helpful to notify that everything is in order
return;
}
......@@ -106,13 +110,15 @@ void DiscoverNotifier::updateStatusNotifier()
m_timer.start();
}
emit updatesChanged();
emit stateChanged();
}
DiscoverNotifier::State DiscoverNotifier::state() const
{
if (m_needsReboot)
return RebootRequired;
else if (!m_manager->isOnline())
return Offline;
else if (m_hasSecurityUpdates)
return SecurityUpdates;
else if (m_hasUpdates)
......@@ -132,6 +138,8 @@ QString DiscoverNotifier::iconName() const
return QStringLiteral("update-none");
case RebootRequired:
return QStringLiteral("system-reboot");
case Offline:
return QStringLiteral("offline");
}
return QString();
}
......@@ -147,6 +155,8 @@ QString DiscoverNotifier::message() const
return i18n("System up to date");
case RebootRequired:
return i18n("Computer needs to restart");
case Offline:
return i18n("Offline");
}
return QString();
}
......@@ -198,4 +208,3 @@ void DiscoverNotifier::foundUpgradeAction(UpgradeAction* action)
notification->sendEvent();
}
......@@ -25,22 +25,24 @@
#include <QStringList>
#include <QTimer>
class QNetworkConfigurationManager;
class KStatusNotifierItem;
class DiscoverNotifier : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList modules READ loadedModules CONSTANT)
Q_PROPERTY(QString iconName READ iconName NOTIFY updatesChanged)
Q_PROPERTY(QString message READ message NOTIFY updatesChanged)
Q_PROPERTY(State state READ state NOTIFY updatesChanged)
Q_PROPERTY(QString iconName READ iconName NOTIFY stateChanged)
Q_PROPERTY(QString message READ message NOTIFY stateChanged)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
public:
enum State {
NoUpdates,
NormalUpdates,
SecurityUpdates,
RebootRequired
RebootRequired,
Offline,
};
Q_ENUM(State)
......@@ -66,7 +68,7 @@ public Q_SLOTS:
void foundUpgradeAction(UpgradeAction* action);
Q_SIGNALS:
void updatesChanged();
void stateChanged();
bool needsRebootChanged(bool needsReboot);
void newUpgradeAction(UpgradeAction* action);
......@@ -80,6 +82,7 @@ private:
bool m_hasSecurityUpdates = false;
bool m_hasUpdates = false;
bool m_needsReboot = false;
QNetworkConfigurationManager* const m_manager;
};
#endif //ABSTRACTKDEDMODULE_H
......@@ -29,7 +29,9 @@ Item
Plasmoid.icon: DiscoverNotifier.iconName
Plasmoid.toolTipSubText: DiscoverNotifier.message
Plasmoid.status: {
switch (DiscoverNotifier.state) {
case DiscoverNotifier.Offline:
case DiscoverNotifier.NoUpdates:
return PlasmaCore.Types.PassiveStatus;
case DiscoverNotifier.NormalUpdates:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment