Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 26ac7c78 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

pk: don't offer offline updates after they've been downloaded

Insist on rebooting instead

BUG: 399370
parent a6ac86e6
......@@ -264,6 +264,7 @@ DiscoverPage
state: ( updateModel.hasUpdates ? "has-updates"
: resourcesUpdatesModel.isProgressing ? "progressing"
: ResourcesModel.isFetching ? "fetching"
: resourcesUpdatesModel.needsReboot ? "reboot"
: secSinceUpdate < 0 ? "unknown"
: secSinceUpdate === 0 ? "now-uptodate"
: secSinceUpdate < 1000 * 60 * 60 * 24 ? "uptodate"
......@@ -286,6 +287,11 @@ DiscoverPage
name: "has-updates"
PropertyChanges { target: page; title: i18nc("@info", "Updates") }
},
State {
name: "reboot"
PropertyChanges { target: page; title: i18nc("@info", "The system requires a reboot") }
PropertyChanges { target: page; footerLabel: i18nc("@info", "Reboot") }
},
State {
name: "now-uptodate"
PropertyChanges { target: page; title: i18nc("@info", "The system is up to date") }
......
......@@ -45,6 +45,7 @@
#include <PackageKit/Transaction>
#include <PackageKit/Daemon>
#include <PackageKit/Offline>
#include <PackageKit/Details>
#include <KLocalizedString>
......@@ -90,6 +91,7 @@ PackageKitBackend::PackageKitBackend(QObject* parent)
m_delayedDetailsFetch.setInterval(100);
connect(&m_delayedDetailsFetch, &QTimer::timeout, this, &PackageKitBackend::performDetailsFetch);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::restartScheduled, m_updater, &PackageKitUpdater::enableNeedsReboot);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::updatesChanged, this, &PackageKitBackend::fetchUpdates);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::isRunningChanged, this, &PackageKitBackend::checkDaemonRunning);
connect(m_reviews.data(), &OdrsReviewsBackend::ratingsReady, this, &AbstractResourcesBackend::emitRatingsReady);
......@@ -488,6 +490,9 @@ bool PackageKitBackend::hasSecurityUpdates() const
int PackageKitBackend::updatesCount() const
{
if (PackageKit::Daemon::global()->offline()->updateTriggered())
return 0;
int ret = 0;
QSet<QString> packages;
for(auto res: upgradeablePackages()) {
......
......@@ -29,6 +29,7 @@
#include <QDebug>
#include <KNotification>
#include <PackageKit/Daemon>
#include <PackageKit/Offline>
#include <QDBusInterface>
#include <QFile>
#include <QFileSystemWatcher>
......@@ -50,6 +51,11 @@ PackageKitNotifier::PackageKitNotifier(QObject* parent)
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::updatesChanged, this, &PackageKitNotifier::recheckSystemUpdateNeeded);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::isRunningChanged, this, &PackageKitNotifier::recheckSystemUpdateNeeded);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::transactionListChanged, this, &PackageKitNotifier::transactionListChanged);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::restartScheduled, this, &PackageKitNotifier::nowNeedsReboot);
connect(PackageKit::Daemon::global(), &PackageKit::Daemon::changed, this, [this]{
if (PackageKit::Daemon::global()->offline()->updateTriggered())
nowNeedsReboot();
});
//Check if there's packages after 5'
QTimer::singleShot(5 * 60 * 1000, this, &PackageKitNotifier::refreshDatabase);
......@@ -140,6 +146,9 @@ void PackageKitNotifier::checkOfflineUpdates()
void PackageKitNotifier::recheckSystemUpdateNeeded()
{
if (PackageKit::Daemon::global()->offline()->updateTriggered())
return;
m_recheckTimer->start();
}
......@@ -250,6 +259,9 @@ QProcess* PackageKitNotifier::checkAptVariable(const QString &aptconfig, const Q
void PackageKitNotifier::transactionListChanged(const QStringList& tids)
{
if (PackageKit::Daemon::global()->offline()->updateTriggered())
return;
for (const auto &tid: tids) {
if (m_transactions.contains(tid))
continue;
......
......@@ -69,6 +69,13 @@ PackageKitUpdater::~PackageKitUpdater()
void PackageKitUpdater::prepare()
{
if (PackageKit::Daemon::global()->offline()->updateTriggered()) {
m_toUpgrade.clear();
m_allUpgradeable.clear();
enableNeedsReboot();
return;
}
Q_ASSERT(!m_transaction);
m_toUpgrade = m_backend->upgradeablePackages();
m_allUpgradeable = m_toUpgrade;
......@@ -172,6 +179,9 @@ bool PackageKitUpdater::useOfflineUpdates() const
void PackageKitUpdater::setUseOfflineUpdates(bool use)
{
// To enable from command line use:
// kwriteconfig5 --file discoverrc --group Software --key UseOfflineUpdates true
KConfigGroup group(KSharedConfig::openConfig(), "Software");
group.writeEntry<bool>("UseOfflineUpdates", use);
}
......
......@@ -37,3 +37,17 @@ void AbstractBackendUpdater::fetchChangelog() const
res->fetchChangelog();
}
}
void AbstractBackendUpdater::enableNeedsReboot()
{
if (m_needsReboot)
return;
m_needsReboot = true;
needsRebootChanged();
}
bool AbstractBackendUpdater::needsReboot() const
{
return m_needsReboot;
}
......@@ -56,6 +56,7 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(bool isCancelable READ isCancelable NOTIFY cancelableChanged)
Q_PROPERTY(bool isProgressing READ isProgressing NOTIFY progressingChanged)
Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
Q_PROPERTY(quint64 downloadSpeed READ downloadSpeed NOTIFY downloadSpeedChanged)
public:
/**
......@@ -129,6 +130,10 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
*/
virtual quint64 downloadSpeed() const = 0;
void enableNeedsReboot();
bool needsReboot() const;
public Q_SLOTS:
/**
* If \isCancelable is true during the transaction, this method has
......@@ -202,6 +207,14 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
* @sa proceed(), cancel()
*/
void proceedRequest(const QString &title, const QString &description);
/**
* emitted when the updater decides it needs to reboot
*/
void needsRebootChanged();
private:
bool m_needsReboot = false;
};
#endif // ABSTRACTBACKENDUPDATER_H
......@@ -137,6 +137,7 @@ void ResourcesUpdatesModel::init()
connect(updater, &AbstractBackendUpdater::downloadSpeedChanged, this, &ResourcesUpdatesModel::downloadSpeedChanged);
connect(updater, &AbstractBackendUpdater::resourceProgressed, this, &ResourcesUpdatesModel::resourceProgressed);
connect(updater, &AbstractBackendUpdater::passiveMessage, this, &ResourcesUpdatesModel::passiveMessage);
connect(updater, &AbstractBackendUpdater::needsRebootChanged, this, &ResourcesUpdatesModel::needsRebootChanged);
connect(updater, &AbstractBackendUpdater::destroyed, this, &ResourcesUpdatesModel::updaterDestroyed);
m_updaters += updater;
......@@ -281,4 +282,13 @@ Transaction* ResourcesUpdatesModel::transaction() const
return m_transaction.data();
}
bool ResourcesUpdatesModel::needsReboot() const
{
for(auto upd: m_updaters) {
if (upd->needsReboot())
return true;
}
return false;
}
#include "ResourcesUpdatesModel.moc"
......@@ -41,6 +41,7 @@ class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
Q_PROPERTY(QDateTime lastUpdate READ lastUpdate NOTIFY progressingChanged)
Q_PROPERTY(qint64 secsToLastUpdate READ secsToLastUpdate NOTIFY progressingChanged)
Q_PROPERTY(Transaction* transaction READ transaction NOTIFY progressingChanged)
Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
public:
explicit ResourcesUpdatesModel(QObject* parent = nullptr);
......@@ -57,6 +58,7 @@ class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
qint64 secsToLastUpdate() const;
QVector<AbstractBackendUpdater*> updaters() const { return m_updaters; }
Transaction* transaction() const;
bool needsReboot() const;
Q_SIGNALS:
void downloadSpeedChanged();
......@@ -64,6 +66,7 @@ class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
void finished();
void resourceProgressed(AbstractResource* resource, qreal progress);
void passiveMessage(const QString &message);
void needsRebootChanged();
public Q_SLOTS:
void updateAll();
......
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