Commit d082ab02 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Include a "needs reboot" state in the discover notifier

It will permanently remind the user to restart the system.
parent 8f0fb642
......@@ -34,6 +34,7 @@ public:
void recheckSystemUpdateNeeded() override;
uint securityUpdatesCount() override;
uint updatesCount() override;
bool needsReboot() const override { return false; }
};
#endif
......@@ -39,6 +39,7 @@ public:
void recheckSystemUpdateNeeded() override;
uint securityUpdatesCount() override;
uint updatesCount() override;
bool needsReboot() const override { return false; }
public Q_SLOTS:
void checkUpdates();
......
......@@ -273,8 +273,13 @@ void PackageKitNotifier::transactionListChanged(const QStringList& tids)
connect(t, &PackageKit::Transaction::requireRestart, this, &PackageKitNotifier::onRequireRestart);
connect(t, &PackageKit::Transaction::finished, this, [this, t](){
auto restart = t->property("requireRestart");
if (!restart.isNull())
requireRestartNotification(PackageKit::Transaction::Restart(restart.toInt()));
if (!restart.isNull()) {
auto restartEvent = PackageKit::Transaction::Restart(restart.toInt());
if (restartEvent >= PackageKit::Transaction::RestartSession) {
m_needsReboot = true;
Q_EMIT needsRebootChanged();
}
}
m_transactions.remove(t->tid().path());
t->deleteLater();
});
......@@ -288,33 +293,3 @@ void PackageKitNotifier::onRequireRestart(PackageKit::Transaction::Restart type,
t->setProperty("requireRestart", qMax<int>(t->property("requireRestart").toInt(), type));
qDebug() << "RESTART" << type << "is required for package" << packageID;
}
void PackageKitNotifier::requireRestartNotification(PackageKit::Transaction::Restart type)
{
if (type < PackageKit::Transaction::RestartSession) {
return;
}
KNotification *notification = new KNotification(QLatin1String("notification"), KNotification::Persistent | KNotification::DefaultEvent);
notification->setIconName(QStringLiteral("system-software-update"));
if (type == PackageKit::Transaction::RestartSystem || type == PackageKit::Transaction::RestartSecuritySystem) {
notification->setActions(QStringList{QLatin1String("Restart")});
notification->setTitle(i18n("Restart is required"));
notification->setText(i18n("The system needs to be restarted for the updates to take effect."));
} else {
notification->setActions(QStringList{QLatin1String("Logout")});
notification->setTitle(i18n("Session restart is required"));
notification->setText(i18n("You will need to log out and back in for the update to take effect."));
}
connect(notification, &KNotification::action1Activated, this, [type] () {
QDBusInterface interface(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QStringLiteral("org.kde.KSMServerInterface"), QDBusConnection::sessionBus());
if (type == PackageKit::Transaction::RestartSystem) {
interface.asyncCall(QStringLiteral("logout"), 0, 1, 2); // Options: do not ask again | reboot | force
} else {
interface.asyncCall(QStringLiteral("logout"), 0, 0, 2); // Options: do not ask again | logout | force
}
});
notification->sendEvent();
}
......@@ -42,6 +42,7 @@ public:
uint updatesCount() override;
void recheckSystemUpdateNeeded() override;
void refreshDatabase();
bool needsReboot() const override { return m_needsReboot; }
private Q_SLOTS:
void package(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary);
......@@ -57,6 +58,7 @@ private:
void setupGetUpdatesTransaction(PackageKit::Transaction* transaction);
QProcess* checkAptVariable(const QString &aptconfig, const QLatin1String& varname, std::function<void(const QStringRef& val)> func);
bool m_needsReboot = false;
uint m_securityUpdates;
uint m_normalUpdates;
QPointer<PackageKit::Transaction> m_refresher;
......
......@@ -40,12 +40,17 @@ public:
/*** @returns count of security updates only. **/
virtual uint securityUpdatesCount() = 0;
/** @returns whether the system changed in a way that needs to be rebooted. */
virtual bool needsReboot() const = 0;
Q_SIGNALS:
/**
* This signal is emitted when any new updates are available.
* @see recheckSystemUpdateNeeded
*/
void foundUpdates();
/** Notifies that the system needs a reboot. @see needsReboot */
void needsRebootChanged();
};
Q_DECLARE_INTERFACE(BackendNotifierModule, "org.kde.discover.BackendNotifierModule")
......
......@@ -7,6 +7,7 @@ target_link_libraries(DiscoverNotifierDeclarativePlugin
KF5::I18n
KF5::KIOWidgets
Qt5::Qml
Qt5::DBus
Discover::Notifiers
)
......
......@@ -20,9 +20,11 @@
#include "DiscoverNotifier.h"
#include "BackendNotifierFactory.h"
#include <QDebug>
#include <QDBusInterface>
#include <QDBusPendingReply>
#include <KConfig>
#include <KConfigGroup>
#include <QDebug>
#include <KRun>
#include <KLocalizedString>
#include <KNotification>
......@@ -37,6 +39,12 @@ DiscoverNotifier::DiscoverNotifier(QObject * parent)
m_backends = BackendNotifierFactory().allBackends();
foreach(BackendNotifierModule* module, m_backends) {
connect(module, &BackendNotifierModule::foundUpdates, this, &DiscoverNotifier::updateStatusNotifier);
connect(module, &BackendNotifierModule::needsRebootChanged, this, [this]() {
if (!m_needsReboot) {
m_needsReboot = true;
showRebootNotification();
}
});
}
connect(&m_timer, &QTimer::timeout, this, &DiscoverNotifier::showUpdatesNotification);
m_timer.setSingleShot(true);
......@@ -119,6 +127,8 @@ QString DiscoverNotifier::iconName() const
return QStringLiteral("update-low");
case NoUpdates:
return QStringLiteral("update-none");
case RebootRequired:
return QStringLiteral("system-reboot");
}
return QString();
}
......@@ -132,6 +142,8 @@ QString DiscoverNotifier::message() const
return i18n("Updates available");
case NoUpdates:
return i18n("System up to date");
case RebootRequired:
return i18n("Computer needs to restart");
}
return QString();
}
......@@ -179,3 +191,19 @@ QStringList DiscoverNotifier::loadedModules() const
ret += QString::fromLatin1(module->metaObject()->className());
return ret;
}
void DiscoverNotifier::showRebootNotification()
{
KNotification *notification = new KNotification(QLatin1String("notification"), KNotification::Persistent | KNotification::DefaultEvent);
notification->setIconName(QStringLiteral("system-software-update"));
notification->setActions(QStringList{QLatin1String("Restart")});
notification->setTitle(i18n("Restart is required"));
notification->setText(i18n("The system needs to be restarted for the updates to take effect."));
connect(notification, &KNotification::action1Activated, this, [] () {
QDBusInterface interface(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QStringLiteral("org.kde.KSMServerInterface"), QDBusConnection::sessionBus());
interface.asyncCall(QStringLiteral("logout"), 0, 1, 2); // Options: do not ask again | reboot | force
});
notification->sendEvent();
}
......@@ -40,7 +40,8 @@ public:
enum State {
NoUpdates,
NormalUpdates,
SecurityUpdates
SecurityUpdates,
RebootRequired
};
Q_ENUM(State)
......@@ -65,12 +66,13 @@ public Q_SLOTS:
void recheckSystemUpdateNeeded();
void showDiscover();
void showDiscoverUpdates();
void showUpdatesNotification();
Q_SIGNALS:
void updatesChanged();
private:
void showUpdatesNotification();
void showRebootNotification();
void updateStatusNotifier();
void loadBackends();
......@@ -79,6 +81,7 @@ private:
QTimer m_timer;
uint m_securityCount = 0;
uint m_count = 0;
bool m_needsReboot = false;
};
#endif //ABSTRACTKDEDMODULE_H
......@@ -33,6 +33,7 @@ Item
return PlasmaCore.Types.PassiveStatus;
case DiscoverNotifier.NormalUpdates:
case DiscoverNotifier.SecurityUpdates:
case DiscoverNotifier.RebootRequired:
return PlasmaCore.Types.ActiveStatus;
}
}
......
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