Commit 2d8c028c authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Don't calculate updates on the updates notification plasmoid

BUG: 385754
BUG: 405533
parent 69a41b42
......@@ -35,12 +35,3 @@ void DummyNotifier::recheckSystemUpdateNeeded()
emit foundUpdates();
}
uint DummyNotifier::securityUpdatesCount()
{
return 0;
}
uint DummyNotifier::updatesCount()
{
return 0;
}
......@@ -32,8 +32,8 @@ public:
~DummyNotifier() override;
void recheckSystemUpdateNeeded() override;
uint securityUpdatesCount() override;
uint updatesCount() override;
bool hasSecurityUpdates() override { return false; }
bool hasUpdates() override { return false; }
bool needsReboot() const override { return false; }
};
......
......@@ -45,10 +45,8 @@ static void installationChanged(GFileMonitor *monitor, GFile *child, GFile *othe
FlatpakNotifier::FlatpakNotifier(QObject* parent)
: BackendNotifierModule(parent)
, m_userInstallationUpdates(0)
, m_systemInstallationUpdates(0)
, m_cancellable(g_cancellable_new())
{
m_cancellable = g_cancellable_new();
checkUpdates();
......@@ -57,12 +55,14 @@ FlatpakNotifier::FlatpakNotifier(QObject* parent)
connect(dailyCheck, &QTimer::timeout, this, &FlatpakNotifier::checkUpdates);
}
FlatpakNotifier::Installation::~Installation()
{
g_object_unref(m_monitor);
g_object_unref(m_installation);
}
FlatpakNotifier::~FlatpakNotifier()
{
g_object_unref(m_userInstallationMonitor);
g_object_unref(m_systemInstallationMonitor);
g_object_unref(m_flatpakInstallationSystem);
g_object_unref(m_flatpakInstallationUser);
g_object_unref(m_cancellable);
}
......@@ -71,16 +71,6 @@ void FlatpakNotifier::recheckSystemUpdateNeeded()
checkUpdates();
}
uint FlatpakNotifier::securityUpdatesCount()
{
return 0;
}
uint FlatpakNotifier::updatesCount()
{
return m_systemInstallationUpdates + m_userInstallationUpdates;
}
void FlatpakNotifier::checkUpdates()
{
g_autoptr(GError) error = nullptr;
......@@ -90,19 +80,19 @@ void FlatpakNotifier::checkUpdates()
qWarning() << "Failed to setup flatpak installations: " << error->message;
} else {
// Load updates from remote repositories
loadRemoteUpdates(m_flatpakInstallationSystem);
loadRemoteUpdates(m_flatpakInstallationUser);
loadRemoteUpdates(m_system.m_installation);
loadRemoteUpdates(m_user.m_installation);
}
}
void FlatpakNotifier::onFetchUpdatesFinished(FlatpakInstallation *flatpakInstallation, GPtrArray *updates)
{
bool changed = false;
uint validUpdates = 0;
bool hasUpdates = false;
g_autoptr(GPtrArray) fetchedUpdates = updates;
for (uint i = 0; i < fetchedUpdates->len; i++) {
for (uint i = 0; !hasUpdates && i < fetchedUpdates->len; i++) {
FlatpakInstalledRef *ref = FLATPAK_INSTALLED_REF(g_ptr_array_index(fetchedUpdates, i));
const QString refName = QString::fromUtf8(flatpak_ref_get_name(FLATPAK_REF(ref)));
// FIXME right now I can't think of any other filter than this, in FlatpakBackend updates are matched
......@@ -111,15 +101,15 @@ void FlatpakNotifier::onFetchUpdatesFinished(FlatpakInstallation *flatpakInstall
if (refName.endsWith(QStringLiteral(".Locale")) || refName.endsWith(QStringLiteral(".Debug"))) {
continue;
}
validUpdates++;
hasUpdates = true;
}
if (flatpak_installation_get_is_user(flatpakInstallation)) {
changed = m_userInstallationUpdates != validUpdates;
m_userInstallationUpdates = validUpdates;
changed = m_user.m_hasUpdates != hasUpdates;
m_user.m_hasUpdates = hasUpdates;
} else {
changed = m_systemInstallationUpdates != validUpdates;
m_systemInstallationUpdates = validUpdates;
changed = m_system.m_hasUpdates != hasUpdates;
m_system.m_hasUpdates = hasUpdates;
}
if (changed) {
......@@ -147,38 +137,43 @@ void FlatpakNotifier::loadRemoteUpdates(FlatpakInstallation *installation)
});
}
bool FlatpakNotifier::hasUpdates()
{
return m_system.m_hasUpdates || m_user.m_hasUpdates;
}
bool FlatpakNotifier::setupFlatpakInstallations(GError **error)
{
if (!m_flatpakInstallationSystem) {
m_flatpakInstallationSystem = flatpak_installation_new_system(m_cancellable, error);
if (!m_flatpakInstallationSystem) {
if (!m_system.m_installation) {
m_system.m_installation = flatpak_installation_new_system(m_cancellable, error);
if (!m_system.m_installation) {
return false;
}
}
if (!m_flatpakInstallationUser) {
m_flatpakInstallationUser = flatpak_installation_new_user(m_cancellable, error);
if (!m_flatpakInstallationUser) {
if (!m_user.m_installation) {
m_user.m_installation = flatpak_installation_new_user(m_cancellable, error);
if (!m_user.m_installation) {
return false;
}
}
if (!m_systemInstallationMonitor) {
m_systemInstallationMonitor = flatpak_installation_create_monitor(m_flatpakInstallationSystem, m_cancellable, error);
if (!m_systemInstallationMonitor) {
if (!m_system.m_monitor) {
m_system.m_monitor = flatpak_installation_create_monitor(m_system.m_installation, m_cancellable, error);
if (!m_system.m_monitor) {
return false;
}
g_signal_connect(m_systemInstallationMonitor, "changed", G_CALLBACK(installationChanged), this);
g_signal_connect(m_system.m_monitor, "changed", G_CALLBACK(installationChanged), this);
}
if (!m_userInstallationMonitor) {
m_userInstallationMonitor = flatpak_installation_create_monitor(m_flatpakInstallationUser, m_cancellable, error);
if (!m_userInstallationMonitor) {
if (!m_user.m_monitor) {
m_user.m_monitor = flatpak_installation_create_monitor(m_user.m_installation, m_cancellable, error);
if (!m_user.m_monitor) {
return false;
}
g_signal_connect(m_userInstallationMonitor, "changed", G_CALLBACK(installationChanged), this);
g_signal_connect(m_user.m_monitor, "changed", G_CALLBACK(installationChanged), this);
}
return true;
......
......@@ -36,9 +36,9 @@ public:
explicit FlatpakNotifier(QObject* parent = nullptr);
~FlatpakNotifier() override;
bool hasUpdates() override;
bool hasSecurityUpdates() override { return false; }
void recheckSystemUpdateNeeded() override;
uint securityUpdatesCount() override;
uint updatesCount() override;
bool needsReboot() const override { return false; }
public Q_SLOTS:
......@@ -49,13 +49,16 @@ private:
void loadRemoteUpdates(FlatpakInstallation *flatpakInstallation);
bool setupFlatpakInstallations(GError **error);
uint m_userInstallationUpdates;
uint m_systemInstallationUpdates;
GCancellable *m_cancellable;
GFileMonitor *m_userInstallationMonitor = nullptr;
GFileMonitor *m_systemInstallationMonitor = nullptr;
FlatpakInstallation *m_flatpakInstallationUser = nullptr;
FlatpakInstallation *m_flatpakInstallationSystem = nullptr;
struct Installation {
~Installation();
bool m_hasUpdates = false;
GFileMonitor *m_monitor = nullptr;
FlatpakInstallation *m_installation = nullptr;
};
Installation m_user;
Installation m_system;
GCancellable * const m_cancellable;
};
#endif
......@@ -208,16 +208,17 @@ void PackageKitNotifier::finished(PackageKit::Transaction::Exit /*exit*/, uint)
}
}
uint PackageKitNotifier::securityUpdatesCount()
bool PackageKitNotifier::hasUpdates()
{
return m_securityUpdates;
return m_normalUpdates > 0;
}
uint PackageKitNotifier::updatesCount()
bool PackageKitNotifier::hasSecurityUpdates()
{
return m_normalUpdates;
return m_securityUpdates > 0;
}
void PackageKitNotifier::onDistroUpgrade(PackageKit::Transaction::DistroUpgrade /*type*/, const QString& name, const QString& description)
{
auto a = new UpgradeAction(name, description, this);
......
......@@ -38,8 +38,8 @@ public:
explicit PackageKitNotifier(QObject* parent = nullptr);
~PackageKitNotifier() override;
uint securityUpdatesCount() override;
uint updatesCount() override;
bool hasUpdates() override;
bool hasSecurityUpdates() override;
void recheckSystemUpdateNeeded() override;
void refreshDatabase();
bool needsReboot() const override { return m_needsReboot; }
......
......@@ -60,13 +60,14 @@ public:
virtual void recheckSystemUpdateNeeded() = 0;
/*** @returns count of !security updates only. **/
virtual uint updatesCount() = 0;
virtual bool hasUpdates() = 0;
/*** @returns count of security updates only. **/
virtual uint securityUpdatesCount() = 0;
virtual bool hasSecurityUpdates() = 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.
......
......@@ -30,9 +30,10 @@
#include <KNotification>
#include <KPluginFactory>
#include "../libdiscover/utils.h"
DiscoverNotifier::DiscoverNotifier(QObject * parent)
: QObject(parent)
, m_verbose(false)
{
configurationChanged();
......@@ -83,7 +84,7 @@ void DiscoverNotifier::showUpdatesNotification()
return;
}
auto e = KNotification::event(QStringLiteral("Update"), message(), extendedMessage(), iconName(), nullptr, KNotification::CloseOnTimeout, QStringLiteral("discoverabstractnotifier"));
auto e = KNotification::event(QStringLiteral("Update"), message(), {}, iconName(), nullptr, KNotification::CloseOnTimeout, QStringLiteral("discoverabstractnotifier"));
const QString name = i18n("Update");
e->setDefaultAction(name);
e->setActions({name});
......@@ -92,23 +93,18 @@ void DiscoverNotifier::showUpdatesNotification()
void DiscoverNotifier::updateStatusNotifier()
{
uint securityCount = 0;
for (BackendNotifierModule* module: m_backends)
securityCount += module->securityUpdatesCount();
uint count = securityCount;
foreach(BackendNotifierModule* module, m_backends)
count += module->updatesCount();
const bool hasSecurityUpdates = kContains(m_backends, [](BackendNotifierModule* module) { return module->hasSecurityUpdates(); });
const bool hasUpdates = hasSecurityUpdates || kContains(m_backends, [](BackendNotifierModule* module) { return module->hasUpdates(); });
if (m_count == count && m_securityCount == securityCount)
if (m_hasUpdates == hasUpdates && m_hasSecurityUpdates == hasSecurityUpdates )
return;
if (state() != NoUpdates && count > m_count) {
if (state() != NoUpdates) {
m_timer.start();
}
m_securityCount = securityCount;
m_count = count;
m_hasSecurityUpdates = hasSecurityUpdates;
m_hasUpdates = hasUpdates;
emit updatesChanged();
}
......@@ -116,9 +112,9 @@ DiscoverNotifier::State DiscoverNotifier::state() const
{
if (m_needsReboot)
return RebootRequired;
else if (m_securityCount)
else if (m_hasSecurityUpdates)
return SecurityUpdates;
else if (m_count)
else if (m_hasUpdates)
return NormalUpdates;
else
return NoUpdates;
......@@ -154,42 +150,12 @@ QString DiscoverNotifier::message() const
return QString();
}
QString DiscoverNotifier::extendedMessage() const
{
if (m_count > 0 && m_securityCount > 0) {
QString allUpdates = i18ncp("First part of '%1, %2'",
"1 package to update", "%1 packages to update", m_count);
QString securityUpdates = i18ncp("Second part of '%1, %2'",
"of which 1 is security update", "of which %1 are security updates", m_securityCount);
return i18nc("%1 is '%1 packages to update' and %2 is 'of which %1 is security updates'",
"%1, %2", allUpdates, securityUpdates);
} else if (m_count > 0) {
return i18np("1 package to update", "%1 packages to update", m_count);
} else if (m_securityCount > 0) {
return i18np("1 security update", "%1 security updates", m_securityCount);
} else {
return i18n("No packages to update");
}
}
void DiscoverNotifier::recheckSystemUpdateNeeded()
{
foreach(BackendNotifierModule* module, m_backends)
module->recheckSystemUpdateNeeded();
}
uint DiscoverNotifier::securityUpdatesCount() const
{
return m_securityCount;
}
uint DiscoverNotifier::updatesCount() const
{
return m_count;
}
QStringList DiscoverNotifier::loadedModules() const
{
QStringList ret;
......@@ -232,7 +198,3 @@ void DiscoverNotifier::foundUpgradeAction(UpgradeAction* action)
notification->sendEvent();
}
bool DiscoverNotifier::isSystemUpToDate() const
{
return m_count==0 && m_securityCount==0;
}
......@@ -31,10 +31,8 @@ class DiscoverNotifier : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList modules READ loadedModules CONSTANT)
Q_PROPERTY(bool isSystemUpToDate READ isSystemUpToDate NOTIFY updatesChanged)
Q_PROPERTY(QString iconName READ iconName NOTIFY updatesChanged)
Q_PROPERTY(QString message READ message NOTIFY updatesChanged)
Q_PROPERTY(QString extendedMessage READ extendedMessage NOTIFY updatesChanged)
Q_PROPERTY(State state READ state NOTIFY updatesChanged)
Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
public:
......@@ -49,16 +47,11 @@ public:
explicit DiscoverNotifier(QObject* parent = nullptr);
~DiscoverNotifier() override;
bool isSystemUpToDate() const;
State state() const;
QString iconName() const;
QString message() const;
QString extendedMessage() const;
/*** @returns count of normal updates only **/
uint updatesCount() const;
/*** @returns count of security updates only **/
uint securityUpdatesCount() const;
bool hasUpdates() const { return m_hasUpdates; }
bool hasSecurityUpdates() const { return m_hasSecurityUpdates; }
QStringList loadedModules() const;
bool needsReboot() const { return m_needsReboot; }
......@@ -82,10 +75,10 @@ private:
void updateStatusNotifier();
QList<BackendNotifierModule*> m_backends;
bool m_verbose;
bool m_verbose = false;
QTimer m_timer;
uint m_securityCount = 0;
uint m_count = 0;
bool m_hasSecurityUpdates = false;
bool m_hasUpdates = false;
bool m_needsReboot = false;
};
......
/***************************************************************************
* Copyright (C) 2013 by Aleix Pol Gonzalez <aleixpol@blue-systems.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
import QtQuick 2.1
import QtQml.Models 2.11
import QtQuick.Layouts 1.1
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components 2.0
import org.kde.discovernotifier 1.0
Item {
PlasmaExtras.Heading {
width: parent.width
level: 3
wrapMode: Text.WordWrap
text: DiscoverNotifier.message
}
ColumnLayout {
anchors.verticalCenter: parent.verticalCenter
width: parent.width
spacing: units.smallSpacing * 2
Label {
visible: !DiscoverNotifier.isSystemUpToDate
Layout.fillWidth: true
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
text: DiscoverNotifier.extendedMessage
}
Button {
visible: !DiscoverNotifier.isSystemUpToDate
Layout.alignment: Qt.AlignHCenter
iconSource: DiscoverNotifier.iconName
text: i18n("View Updates")
tooltip: i18n("Launches Discover to update the software")
onClicked: DiscoverNotifier.showDiscoverUpdates()
}
Button {
visible: DiscoverNotifier.needsReboot
Layout.alignment: Qt.AlignHCenter
iconSource: "system-reboot"
text: i18n("Restart")
tooltip: i18n("Restart the system")
onClicked: DiscoverNotifier.reboot()
}
Repeater {
model: ObjectModel {
id: upgrades
Connections {
target: DiscoverNotifier
onNewUpgradeAction: upgrades.append(action)
}
}
delegate: Button {
visible: DiscoverNotifier.needsReboot
Layout.alignment: Qt.AlignHCenter
iconSource: "system-upgrade"
text: description
onClicked: model.trigger()
}
}
}
}
......@@ -18,13 +18,14 @@
***************************************************************************/
import QtQuick 2.2
import QtQml.Models 2.3
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.discovernotifier 1.0
Item
{
Plasmoid.fullRepresentation: Full {}
id: root
Plasmoid.icon: DiscoverNotifier.iconName
Plasmoid.toolTipSubText: DiscoverNotifier.message
Plasmoid.status: {
......@@ -38,10 +39,56 @@ Item
}
}
Plasmoid.onActivated: action_discover()
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
Plasmoid.compactRepresentation: PlasmaCore.IconItem {
source: plasmoid.icon
MouseArea {
anchors.fill: parent
onClicked: action_discover()
}
}
Component.onCompleted: {
plasmoid.setAction("discover", i18n("Open Software Center..."), "plasma-discover");
plasmoid.setAction("update", i18n("See Updates..."), "system-software-update");
plasmoid.setAction("refresh", i18n("Refresh..."), "view-refresh");
if (DiscoverNotifier.needsReboot)
plasmoid.setAction("reboot", i18n("Restart..."), "system-reboot");
}
Connections {
target: DiscoverNotifier
onNeedsRebootChanged: plasmoid.setAction("reboot", i18n("Restart..."), "system-reboot");
}
function action_reboot() {
DiscoverNotifier.reboot()
}
Instantiator {
Connections {
target: DiscoverNotifier
onNewUpgradeAction: {
upgrades.append(action)
}
}
model: ObjectModel {
id: upgrades
}
onObjectAdded: {
plasmoid.setAction(index, object.description, "system-upgrade")
}
}
function actionTriggered(actionName) {
var index = parseInt(actionName);
if (index)
upgrades.get(index).trigger()
}
function action_discover() {
......
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