Commit 2eafbe24 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Display the transaction speed in the ProgressView

CCBUG: 389626
parent 23d59493
......@@ -73,7 +73,7 @@ Kirigami.BasicListItem {
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
elide: Text.ElideRight
text: listener.isActive ? i18nc("TransactioName - TransactionStatus", "%1 - %2", model.transaction.name, listener.statusText) : model.transaction.name
text: listener.isActive ? i18nc("TransactioName - TransactionStatus", "%1 - %2: %3", model.transaction.name, listener.statusText, model.transaction.downloadSpeedString) : model.transaction.name
}
ToolButton {
iconName: "dialog-cancel"
......
......@@ -22,6 +22,8 @@
#include <resources/AbstractResource.h>
#include "TransactionModel.h"
#include <KFormat>
#include <KLocalizedString>
#include <QDebug>
Transaction::Transaction(QObject *parent, AbstractResource *resource,
......@@ -132,3 +134,16 @@ void Transaction::setVisible(bool visible)
Q_EMIT visibleChanged(visible);
}
}
void Transaction::setDownloadSpeed(quint64 downloadSpeed)
{
if (downloadSpeed != m_downloadSpeed) {
m_downloadSpeed = downloadSpeed;
Q_EMIT downloadSpeedChanged(downloadSpeed);
}
}
QString Transaction::downloadSpeedString() const
{
return i18nc("@label Download rate", "%1/s", KFormat().formatByteSize(downloadSpeed()));
}
......@@ -51,6 +51,8 @@ class DISCOVERCOMMON_EXPORT Transaction : public QObject
Q_PROPERTY(bool isCancellable READ isCancellable NOTIFY cancellableChanged)
Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(quint64 downloadSpeed READ downloadSpeed WRITE setDownloadSpeed NOTIFY downloadSpeedChanged)
Q_PROPERTY(QString downloadSpeedString READ downloadSpeedString NOTIFY downloadSpeedChanged)
public:
enum Status {
......@@ -148,6 +150,11 @@ public:
bool isVisible() const;
void setVisible(bool v);
quint64 downloadSpeed() const { return m_downloadSpeed; }
void setDownloadSpeed(quint64 downloadSpeed);
QString downloadSpeedString() const;
private:
AbstractResource * const m_resource;
const Role m_role;
......@@ -156,6 +163,7 @@ private:
bool m_isCancellable;
int m_progress;
bool m_visible = true;
quint64 m_downloadSpeed = 0;
Q_SIGNALS:
/**
......@@ -183,6 +191,8 @@ Q_SIGNALS:
void passiveMessage(const QString &message);
void visibleChanged(bool visible);
void downloadSpeedChanged(quint64 downloadSpeed);
};
#endif // TRANSACTION_H
......@@ -90,6 +90,9 @@ void PackageKitUpdater::setupTransaction(PackageKit::Transaction::TransactionFla
connect(m_transaction.data(), &PackageKit::Transaction::allowCancelChanged, this, &PackageKitUpdater::cancellableChanged);
connect(m_transaction.data(), &PackageKit::Transaction::percentageChanged, this, &PackageKitUpdater::percentageChanged);
connect(m_transaction.data(), &PackageKit::Transaction::itemProgress, this, &PackageKitUpdater::itemProgress);
connect(m_transaction.data(), &PackageKit::Transaction::speedChanged, this, [this] {
Q_EMIT downloadSpeedChanged(downloadSpeed());
});
}
QSet<AbstractResource*> PackageKitUpdater::packagesForPackageId(const QSet<QString>& pkgids) const
......@@ -389,3 +392,8 @@ double PackageKitUpdater::updateSize() const
}
return ret;
}
quint64 PackageKitUpdater::downloadSpeed() const
{
return m_transaction ? m_transaction->speed() : 0;
}
......@@ -47,6 +47,7 @@ class PackageKitUpdater : public AbstractBackendUpdater
bool isProgressing() const override;
void fetchChangelog() const override;
double updateSize() const override;
quint64 downloadSpeed() const override;
void proceed() override;
......
......@@ -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(quint64 downloadSpeed READ downloadSpeed NOTIFY downloadSpeedChanged)
public:
/**
* Constructs an AbstractBackendUpdater
......@@ -123,6 +124,11 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
*/
virtual double updateSize() const = 0;
/**
* @returns the speed at which we are downloading
*/
virtual quint64 downloadSpeed() const = 0;
public Q_SLOTS:
/**
* If \isCancelable is true during the transaction, this method has
......@@ -179,7 +185,7 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
* The AbstractBackendUpdater should emit this signal when the download speed changed.
* @see downloadSpeed
*/
void downloadSpeedChanged(quint64);
void downloadSpeedChanged(quint64 downloadSpeed);
/**
* Provides the @p progress of a specific @p resource in a percentage.
......
......@@ -42,6 +42,7 @@ public:
bool cancelable = false;
foreach(auto updater, m_allUpdaters) {
connect(updater, &AbstractBackendUpdater::progressingChanged, this, &UpdateTransaction::slotProgressingChanged);
connect(updater, &AbstractBackendUpdater::downloadSpeedChanged, this, &UpdateTransaction::slotDownloadSpeedChanged);
connect(updater, &AbstractBackendUpdater::progressChanged, this, &UpdateTransaction::slotUpdateProgress);
connect(updater, &AbstractBackendUpdater::proceedRequest, this, &UpdateTransaction::processProceedRequest);
connect(updater, &AbstractBackendUpdater::cancelableChanged, this, [this](bool cancelable){ if (cancelable) setCancellable(true); });
......@@ -94,6 +95,15 @@ public:
setProgress(total / m_allUpdaters.count());
}
void slotDownloadSpeedChanged()
{
quint64 total = 0;
foreach(AbstractBackendUpdater* updater, m_allUpdaters) {
total += updater->downloadSpeed();
}
setDownloadSpeed(total);
}
QVariant icon() const override { return QStringLiteral("update-low"); }
QString name() const override { return i18n("Update"); }
......
......@@ -74,6 +74,10 @@ void StandardBackendUpdater::start()
m_pendingResources += res;
auto t = m_backend->installApplication(res);
t->setVisible(false);
t->setProperty("updater", QVariant::fromValue<QObject*>(this));
connect(t, &Transaction::downloadSpeedChanged, this, [this](){
Q_EMIT downloadSpeedChanged(downloadSpeed());
});
connect(this, &StandardBackendUpdater::cancelTransaction, t, &Transaction::cancel);
TransactionModel::global()->addTransaction(t);
m_canCancel |= t->isCancellable();
......@@ -236,3 +240,14 @@ double StandardBackendUpdater::updateSize() const
}
return ret;
}
quint64 StandardBackendUpdater::downloadSpeed() const
{
quint64 ret = 0;
for(Transaction* t: TransactionModel::global()->transactions()) {
if (t->property("updater").value<QObject*>() == this)
ret += t->downloadSpeed();
}
return ret;
}
......@@ -52,6 +52,7 @@ class DISCOVERCOMMON_EXPORT StandardBackendUpdater : public AbstractBackendUpdat
void setProgress(qreal p);
int updatesCount() const;
void cancel() override;
quint64 downloadSpeed() const override;
Q_SIGNALS:
void cancelTransaction();
......
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