Commit b3d8fbef authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

pk: Include an error message when there is not enough space for an update

It can prevent users getting in an unfortunate situation.
There are some cases where this error might not apply, so there's a
button to dismiss the message.

BUG: 457868
parent 82def543
Pipeline #225157 passed with stage
in 1 minute and 30 seconds
......@@ -134,10 +134,47 @@ DiscoverPage
text: page.unselected>0 ? i18n("Update Selected") : i18n("Update All")
visible: updateModel.toUpdateCount
iconName: "update-none"
enabled: !resourcesUpdatesModel.isProgressing && !ResourcesModel.isFetching
function anyVisible(items) {
for (const itemPos in items) {
const item = items[itemPos];
if (item.visible && item instanceof Kirigami.InlineMessage) {
return true
}
}
return false;
}
enabled: !resourcesUpdatesModel.isProgressing && !ResourcesModel.isFetching && !anyVisible(page.header.children)
onTriggered: resourcesUpdatesModel.updateAll()
}
header: ColumnLayout {
id: errorsColumn
Repeater {
model: resourcesUpdatesModel.errorMessages
delegate: Kirigami.InlineMessage {
id: inline
Layout.fillWidth: true
Layout.margins: Kirigami.Units.smallSpacing
text: modelData
visible: true
type: Kirigami.MessageType.Error
onVisibleChanged: errorsColumn.childrenChanged()
actions: [
Kirigami.Action {
icon.name: "dialog-cancel"
text: i18n("Ignore")
onTriggered: {
inline.visible = false
}
}
]
}
}
}
footer: ColumnLayout {
width: parent.width
spacing: 0
......
......@@ -39,6 +39,7 @@ DummyBackend::DummyBackend(QObject *parent)
if (!m_fetching)
m_reviews->initialize();
m_updater->setErrorMessage(QStringLiteral("I am super broken"));
SourcesModel::global()->addSourcesBackend(new DummySourcesBackend(this));
}
......
......@@ -13,6 +13,8 @@
#include <QSet>
#include <KConfigGroup>
#include <KFormat>
#include <KIO/FileSystemFreeSpaceJob>
#include <KLocalizedString>
#include <KSharedConfig>
......@@ -269,6 +271,13 @@ void PackageKitUpdater::prepare()
} else {
m_toUpgrade = candidates;
}
auto j = KIO::fileSystemFreeSpace(QUrl::fromLocalFile("/usr"));
connect(j, &KIO::FileSystemFreeSpaceJob::result, this, [this](KIO::Job * /*job*/, KIO::filesize_t /*size*/, KIO::filesize_t available) {
if (available < updateSize()) {
setErrorMessage(i18n("Not enough space to perform the update. Only have %1 available.", KFormat().formatByteSize(available)));
}
});
m_allUpgradeable = m_toUpgrade;
}
......
......@@ -54,3 +54,12 @@ void AbstractBackendUpdater::setOfflineUpdates(bool useOfflineUpdates)
{
Q_UNUSED(useOfflineUpdates);
}
void AbstractBackendUpdater::setErrorMessage(const QString &errorMessage)
{
if (errorMessage == m_errorMessage) {
return;
}
m_errorMessage = errorMessage;
Q_EMIT errorMessageChanged();
}
......@@ -43,6 +43,7 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
Q_PROPERTY(bool isProgressing READ isProgressing NOTIFY progressingChanged)
Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
Q_PROPERTY(quint64 downloadSpeed READ downloadSpeed NOTIFY downloadSpeedChanged)
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
public:
enum State {
None,
......@@ -159,6 +160,12 @@ public Q_SLOTS:
{
}
void setErrorMessage(const QString &errorMessage);
QString errorMessage() const
{
return m_errorMessage;
}
Q_SIGNALS:
/**
* The AbstractBackendUpdater should Q_EMIT this signal when the progress changed.
......@@ -218,9 +225,13 @@ Q_SIGNALS:
*/
void needsRebootChanged();
/** emitted when we find a new errorMessage to display */
void errorMessageChanged();
private:
bool m_needsReboot = false;
bool m_readyToReboot = false;
QString m_errorMessage;
};
#endif // ABSTRACTBACKENDUPDATER_H
......@@ -141,6 +141,7 @@ void ResourcesUpdatesModel::init()
connect(updater, &AbstractBackendUpdater::passiveMessage, this, &ResourcesUpdatesModel::passiveMessage);
connect(updater, &AbstractBackendUpdater::needsRebootChanged, this, &ResourcesUpdatesModel::needsRebootChanged);
connect(updater, &AbstractBackendUpdater::destroyed, this, &ResourcesUpdatesModel::updaterDestroyed);
connect(updater, &AbstractBackendUpdater::errorMessageChanged, this, &ResourcesUpdatesModel::errorMessagesChanged);
m_updaters += updater;
m_lastIsProgressing |= updater->isProgressing();
......@@ -174,6 +175,8 @@ void ResourcesUpdatesModel::init()
setTransaction(updateTransaction);
}
}
Q_EMIT errorMessagesChanged();
}
void ResourcesUpdatesModel::updaterDestroyed(QObject *obj)
......@@ -341,4 +344,17 @@ void ResourcesUpdatesModel::setOfflineUpdates(bool offline)
m_offlineUpdates = offline;
}
QStringList ResourcesUpdatesModel::errorMessages() const
{
QStringList ret;
for (auto updater : m_updaters) {
const auto error = updater->errorMessage();
if (!error.isEmpty()) {
ret << error;
}
}
ret.removeDuplicates();
return ret;
}
#include "ResourcesUpdatesModel.moc"
......@@ -27,6 +27,7 @@ class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
Q_PROPERTY(bool readyToReboot READ readyToReboot)
Q_PROPERTY(bool useUnattendedUpdates READ useUnattendedUpdates NOTIFY useUnattendedUpdatesChanged)
Q_PROPERTY(QStringList errorMessages READ errorMessages NOTIFY errorMessagesChanged)
public:
explicit ResourcesUpdatesModel(QObject *parent = nullptr);
......@@ -49,6 +50,7 @@ public:
bool needsReboot() const;
bool readyToReboot() const;
bool useUnattendedUpdates() const;
QStringList errorMessages() const;
Q_SIGNALS:
void downloadSpeedChanged();
......@@ -59,6 +61,7 @@ Q_SIGNALS:
void needsRebootChanged();
void useUnattendedUpdatesChanged();
void fetchingUpdatesProgressChanged(int percent);
void errorMessagesChanged();
public Q_SLOTS:
void updateAll();
......@@ -75,6 +78,7 @@ private:
bool m_lastIsProgressing;
bool m_offlineUpdates = false;
QPointer<UpdateTransaction> m_transaction;
QStringList m_errorMessages;
};
#endif // RESOURCESUPDATESMODEL_H
Supports Markdown
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