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

Make it possible to display the remaining time for a transaction

It will work for backends that specify it.
For now just PackageKit supports it.

BUG: 425691
parent 99dcd465
......@@ -92,7 +92,8 @@ Kirigami.AbstractListItem {
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
elide: Text.ElideRight
text: listener.isActive && model.transaction.downloadSpeed>0 ? i18nc("TransactioName - TransactionStatus", "%1 - %2: %3", model.transaction.name, listener.statusText, model.transaction.downloadSpeedString) :
text: listener.isActive && model.transaction.remainingTime>0 ? i18nc("TransactioName - TransactionStatus: speed, remaining time", "%1 - %2: %3, %4 remaining", model.transaction.name, listener.statusText, model.transaction.downloadSpeedString, model.transaction.remainingTime) :
listener.isActive && model.transaction.downloadSpeed>0 ? i18nc("TransactioName - TransactionStatus: speed", "%1 - %2: %3", model.transaction.name, listener.statusText, model.transaction.downloadSpeedString) :
listener.isActive ? i18nc("TransactioName - TransactionStatus", "%1 - %2", model.transaction.name, listener.statusText)
: model.transaction.name
}
......
......@@ -133,3 +133,16 @@ QString Transaction::downloadSpeedString() const
{
return i18nc("@label Download rate", "%1/s", KFormat().formatByteSize(downloadSpeed()));
}
void Transaction::setRemainingTime(uint remainingTime)
{
if (remainingTime != m_remainingTime) {
m_remainingTime = remainingTime;
Q_EMIT remainingTimeChanged(remainingTime);
}
}
QString Transaction::remainingTimeString() const
{
return KFormat().formatSpelloutDuration(m_remainingTime * 1000);
}
......@@ -39,6 +39,8 @@ class DISCOVERCOMMON_EXPORT Transaction : public QObject
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)
Q_PROPERTY(QString remainingTimeString READ remainingTimeString NOTIFY remainingTimeChanged)
Q_PROPERTY(uint remainingTime READ remainingTime NOTIFY remainingTimeChanged)
public:
enum Status {
......@@ -139,7 +141,11 @@ public:
quint64 downloadSpeed() const { return m_downloadSpeed; }
void setDownloadSpeed(quint64 downloadSpeed);
uint remainingTime() const { return m_remainingTime; }
void setRemainingTime(uint seconds);
QString downloadSpeedString() const;
QString remainingTimeString() const;
private:
AbstractResource * const m_resource;
......@@ -150,6 +156,7 @@ private:
int m_progress;
bool m_visible = true;
quint64 m_downloadSpeed = 0;
uint m_remainingTime = 0;
Q_SIGNALS:
/**
......@@ -179,6 +186,8 @@ Q_SIGNALS:
void visibleChanged(bool visible);
void downloadSpeedChanged(quint64 downloadSpeed);
void remainingTimeChanged(uint remainingTime);
};
#endif // TRANSACTION_H
......@@ -95,6 +95,9 @@ void PKTransaction::trigger(PackageKit::Transaction::TransactionFlags flags)
connect(m_trans.data(), &PackageKit::Transaction::statusChanged, this, &PKTransaction::statusChanged);
connect(m_trans.data(), &PackageKit::Transaction::eulaRequired, this, &PKTransaction::eulaRequired);
connect(m_trans.data(), &PackageKit::Transaction::allowCancelChanged, this, &PKTransaction::cancellableChanged);
connect(m_trans.data(), &PackageKit::Transaction::remainingTimeChanged, this, [this]() {
setRemainingTime(m_trans->remainingTime());
});
connect(m_trans.data(), &PackageKit::Transaction::speedChanged, this, [this]() {
setDownloadSpeed(m_trans->speed());
});
......
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