Commit 5aa99884 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

notifier: abstract distupgrade and move to the notifier

parent c2c5c833
......@@ -204,25 +204,11 @@ uint PackageKitNotifier::updatesCount()
void PackageKitNotifier::onDistroUpgrade(PackageKit::Transaction::DistroUpgrade type, const QString& name, const QString& description)
{
KNotification *notification = new KNotification(QLatin1String("distupgrade-notification"), KNotification::Persistent | KNotification::DefaultEvent);
notification->setIconName(QStringLiteral("system-software-update"));
notification->setActions(QStringList{QLatin1String("Upgrade")});
notification->setTitle(i18n("Upgrade available"));
switch(type) {
case PackageKit::Transaction::DistroUpgradeUnknown:
case PackageKit::Transaction::DistroUpgradeUnstable:
notification->setText(i18n("New unstable version: %1", description));
break;
case PackageKit::Transaction::DistroUpgradeStable:
notification->setText(i18n("New version: %1", description));
break;
}
connect(notification, &KNotification::action1Activated, this, [name] () {
auto a = new UpgradeAction(name, description, this);
connect(a, &UpgradeAction::triggered, this, [] (const QString &name) {
PackageKit::Daemon::upgradeSystem(name, PackageKit::Transaction::UpgradeKindDefault);
});
notification->sendEvent();
Q_EMIT foundUpgradeAction(a);
}
void PackageKitNotifier::refreshDatabase()
......
......@@ -24,6 +24,31 @@
#include <QObject>
#include "discovernotifiers_export.h"
class DISCOVERNOTIFIERS_EXPORT UpgradeAction : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT)
public:
UpgradeAction(const QString& name, const QString& description, QObject* parent)
: QObject(parent)
, m_name(name)
, m_description(description)
{}
QString name() const { return m_name; }
QString description() const { return m_description; }
void trigger() { triggered(m_name); }
Q_SIGNALS:
void triggered(const QString & name);
private:
const QString m_name;
const QString m_description;
};
class DISCOVERNOTIFIERS_EXPORT BackendNotifierModule : public QObject
{
Q_OBJECT
......@@ -51,6 +76,9 @@ Q_SIGNALS:
/** Notifies that the system needs a reboot. @see needsReboot */
void needsRebootChanged();
/** notifies about an available upgrade */
void foundUpgradeAction(UpgradeAction* action);
};
Q_DECLARE_INTERFACE(BackendNotifierModule, "org.kde.discover.BackendNotifierModule")
......
......@@ -47,6 +47,8 @@ DiscoverNotifier::DiscoverNotifier(QObject * parent)
Q_EMIT needsRebootChanged(true);
}
});
connect(module, &BackendNotifierModule::foundUpgradeAction, this, &DiscoverNotifier::foundUpgradeAction);
}
connect(&m_timer, &QTimer::timeout, this, &DiscoverNotifier::showUpdatesNotification);
m_timer.setSingleShot(true);
......@@ -214,3 +216,18 @@ void DiscoverNotifier::reboot()
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
}
void DiscoverNotifier::foundUpgradeAction(UpgradeAction* action)
{
KNotification *notification = new KNotification(QLatin1String("distupgrade-notification"), KNotification::Persistent | KNotification::DefaultEvent);
notification->setIconName(QStringLiteral("system-software-update"));
notification->setActions(QStringList{QLatin1String("Upgrade")});
notification->setTitle(i18n("Upgrade available"));
notification->setText(i18n("New version: %1", action->description()));
connect(notification, &KNotification::action1Activated, this, [action] () {
action->trigger();
});
notification->sendEvent();
}
......@@ -70,6 +70,7 @@ public Q_SLOTS:
void showDiscoverUpdates();
void showUpdatesNotification();
void reboot();
void foundUpgradeAction(UpgradeAction* action);
Q_SIGNALS:
void updatesChanged();
......
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