Commit 4ef91fa6 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Switch to 2 progress bars on the UpdatesPage delegate

We show them consecutively, we show "Installing" while installing.

BUG: 396140
parent 5468ddce
......@@ -29,6 +29,7 @@
#include <resources/ResourcesModel.h>
#include <resources/SourcesModel.h>
#include <resources/AbstractSourcesBackend.h>
#include <resources/AbstractBackendUpdater.h>
#include <resources/ResourcesProxyModel.h>
#include <ReviewsBackend/Rating.h>
#include <ReviewsBackend/AbstractReviewsBackend.h>
......@@ -70,6 +71,7 @@ void DiscoverDeclarativePlugin::registerTypes(const char* /*uri*/)
qmlRegisterUncreatableType<AbstractSourcesBackend>("org.kde.discover", 2, 0, "AbstractSourcesBackend", QStringLiteral("should come from the SourcesModel"));
qmlRegisterUncreatableType<Transaction>("org.kde.discover", 2, 0, "Transaction", QStringLiteral("should come from the backends"));
qmlRegisterUncreatableType<SourcesModel>("org.kde.discover", 2, 0, "SourcesModelClass", QStringLiteral("should come from the backends"));
qmlRegisterUncreatableType<SourcesModel>("org.kde.discover", 2, 0, "AbstractBackendUpdater", QStringLiteral("should come from the backends"));
qmlRegisterType<Rating>();
qmlRegisterType<AbstractResourcesBackend>();
qmlRegisterType<AbstractReviewsBackend>();
......
......@@ -246,7 +246,7 @@ DiscoverPage
LabelBackground {
Layout.minimumWidth: Kirigami.Units.gridUnit * 6
text: size
text: resourceState == 2 ? i18n("Installing") : size
progress: resourceProgress/100
}
......
......@@ -29,7 +29,6 @@
UpdateItem::UpdateItem(AbstractResource *app)
: m_app(app)
, m_progress(0)
{
}
......
......@@ -25,6 +25,7 @@
#include <QSet>
#include <QString>
#include "discovercommon_export.h"
#include "resources/AbstractBackendUpdater.h"
#include <QIcon>
......@@ -39,6 +40,9 @@ public:
void setProgress(qreal progress);
qreal progress() const;
AbstractBackendUpdater::State state() const { return m_state; }
void setState(AbstractBackendUpdater::State state) { m_state = state; }
QString changelog() const;
void setChangelog(const QString &changelog);
......@@ -58,7 +62,8 @@ private:
const QString m_categoryName;
const QIcon m_categoryIcon;
qreal m_progress;
qreal m_progress = 0.;
AbstractBackendUpdater::State m_state = AbstractBackendUpdater::None;
QString m_changelog;
};
......
......@@ -61,6 +61,7 @@ QHash<int,QByteArray> UpdateModel::roleNames() const
return QAbstractItemModel::roleNames().unite({
{ Qt::CheckStateRole, "checked" },
{ ResourceProgressRole, "resourceProgress" },
{ ResourceStateRole, "resourceState" },
{ ResourceRole, "resource" },
{ SizeRole, "size" },
{ SectionRole, "section" },
......@@ -84,15 +85,16 @@ void UpdateModel::setBackend(ResourcesUpdatesModel* updates)
activityChanged();
}
void UpdateModel::resourceHasProgressed(AbstractResource* res, qreal progress)
void UpdateModel::resourceHasProgressed(AbstractResource* res, qreal progress, AbstractBackendUpdater::State state)
{
UpdateItem* item = itemFromResource(res);
if (!item)
return;
item->setProgress(progress);
item->setState(state);
const QModelIndex idx = indexFromItem(item);
Q_EMIT dataChanged(idx, idx, { ResourceProgressRole, SectionResourceProgressRole });
Q_EMIT dataChanged(idx, idx, { ResourceProgressRole, ResourceStateRole, SectionResourceProgressRole });
}
void UpdateModel::activityChanged()
......@@ -135,6 +137,8 @@ QVariant UpdateModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue<QObject*>(item->resource());
case ResourceProgressRole:
return item->progress();
case ResourceStateRole:
return item->state();
case ChangelogRole:
return item->changelog();
case SectionRole: {
......
......@@ -22,6 +22,7 @@
#define UPDATEMODEL_H
#include <QAbstractListModel>
#include "resources/AbstractBackendUpdater.h"
#include "discovercommon_export.h"
class QTimer;
......@@ -43,11 +44,12 @@ public:
SizeRole = Qt::UserRole + 1,
ResourceRole,
ResourceProgressRole,
ResourceStateRole,
SectionResourceProgressRole,
ChangelogRole,
SectionRole,
InstalledVersionRole,
AvailableVersionRole
AvailableVersionRole,
};
Q_ENUM(Roles)
......@@ -95,7 +97,7 @@ private:
void integrateChangelog(const QString &changelog);
QModelIndex indexFromItem(UpdateItem* item) const;
UpdateItem* itemFromResource(AbstractResource* res);
void resourceHasProgressed(AbstractResource* res, qreal progress);
void resourceHasProgressed(AbstractResource* res, qreal progress, AbstractBackendUpdater::State state);
void activityChanged();
QTimer* const m_updateSizeTimer;
......
......@@ -37,6 +37,8 @@ DummyTransaction::DummyTransaction(DummyResource* app, const AddonList& addons,
, m_app(app)
{
setCancellable(true);
setStatus(DownloadingStatus);
iterateTransaction();
}
......@@ -45,10 +47,13 @@ void DummyTransaction::iterateTransaction()
if (!m_iterate)
return;
setStatus(CommittingStatus);
if(progress()<100) {
setProgress(qBound(0, progress()+(KRandom::random()%30), 100));
QTimer::singleShot(/*KRandom::random()%*/100, this, &DummyTransaction::iterateTransaction);
} else if (status() == DownloadingStatus) {
setStatus(CommittingStatus);
setProgress(0);
QTimer::singleShot(/*KRandom::random()%*/100, this, &DummyTransaction::iterateTransaction);
} else
#ifdef TEST_PROCEED
Q_EMIT proceedRequest(QStringLiteral("yadda yadda"), QStringLiteral("Biii BOooo<ul><li>A</li><li>A</li><li>A</li><li>A</li></ul>"));
......
......@@ -355,16 +355,34 @@ void PackageKitUpdater::lastUpdateTimeReceived(QDBusPendingCallWatcher* w)
w->deleteLater();
}
AbstractBackendUpdater::State toUpdateState(PackageKit::Transaction::Status t)
{
switch(t) {
case PackageKit::Transaction::StatusUnknown:
case PackageKit::Transaction::StatusDownload:
return AbstractBackendUpdater::Downloading;
case PackageKit::Transaction::StatusDepResolve:
case PackageKit::Transaction::StatusSigCheck:
case PackageKit::Transaction::StatusTestCommit:
case PackageKit::Transaction::StatusInstall:
case PackageKit::Transaction::StatusCommit:
return AbstractBackendUpdater::Installing;
case PackageKit::Transaction::StatusFinished:
case PackageKit::Transaction::StatusCancel:
return AbstractBackendUpdater::Done;
default:
qDebug() << "unknown packagekit status" << t;
return AbstractBackendUpdater::None;
}
Q_UNREACHABLE();
}
void PackageKitUpdater::itemProgress(const QString& itemID, PackageKit::Transaction::Status status, uint percentage)
{
auto res = packagesForPackageId({itemID});
const auto actualPercentage = percentageWithStatus(status, percentage);
if (actualPercentage<0)
return;
const auto res = packagesForPackageId({itemID});
foreach(auto r, res) {
Q_EMIT resourceProgressed(r, actualPercentage);
Q_EMIT resourceProgressed(r, percentage, toUpdateState(status));
}
}
......
......@@ -59,6 +59,9 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged)
Q_PROPERTY(quint64 downloadSpeed READ downloadSpeed NOTIFY downloadSpeedChanged)
public:
enum State { None, Downloading, Installing, Done };
Q_ENUM(State);
/**
* Constructs an AbstractBackendUpdater
*/
......@@ -195,7 +198,7 @@ class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject
/**
* Provides the @p progress of a specific @p resource in a percentage.
*/
void resourceProgressed(AbstractResource* resource, qreal progress);
void resourceProgressed(AbstractResource* resource, qreal progress, State state);
void passiveMessage(const QString &message);
......
......@@ -25,14 +25,14 @@
#include <QDateTime>
#include <QPointer>
#include "discovercommon_export.h"
#include "resources/AbstractBackendUpdater.h"
class AbstractResourcesBackend;
class AbstractResource;
class QAction;
class AbstractBackendUpdater;
class ResourcesModel;
class Transaction;
class UpdateTransaction;
class Transaction;
class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
{
......@@ -64,7 +64,7 @@ class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel
void downloadSpeedChanged();
void progressingChanged();
void finished();
void resourceProgressed(AbstractResource* resource, qreal progress);
void resourceProgressed(AbstractResource* resource, qreal progress, AbstractBackendUpdater::State state);
void passiveMessage(const QString &message);
void needsRebootChanged();
......
......@@ -105,12 +105,31 @@ void StandardBackendUpdater::transactionAdded(Transaction* newTransaction)
return;
connect(newTransaction, &Transaction::progressChanged, this, &StandardBackendUpdater::transactionProgressChanged);
connect(newTransaction, &Transaction::statusChanged, this, &StandardBackendUpdater::transactionProgressChanged);
}
void StandardBackendUpdater::transactionProgressChanged(int percentage)
AbstractBackendUpdater::State toUpdateState(Transaction* t)
{
switch(t->status()) {
case Transaction::SetupStatus:
case Transaction::QueuedStatus:
return AbstractBackendUpdater::None;
case Transaction::DownloadingStatus:
return AbstractBackendUpdater::Downloading;
case Transaction::CommittingStatus:
return AbstractBackendUpdater::Installing;
case Transaction::DoneStatus:
case Transaction::DoneWithErrorStatus:
case Transaction::CancelledStatus:
return AbstractBackendUpdater::Done;
}
Q_UNREACHABLE();
}
void StandardBackendUpdater::transactionProgressChanged()
{
Transaction* t = qobject_cast<Transaction*>(sender());
Q_EMIT resourceProgressed(t->resource(), percentage);
Q_EMIT resourceProgressed(t->resource(), t->progress(), toUpdateState(t));
}
void StandardBackendUpdater::transactionRemoved(Transaction* t)
......
......@@ -66,7 +66,7 @@ class DISCOVERCOMMON_EXPORT StandardBackendUpdater : public AbstractBackendUpdat
void resourcesChanged(AbstractResource* res, const QVector<QByteArray>& props);
void refreshUpdateable();
void transactionAdded(Transaction* newTransaction);
void transactionProgressChanged(int percentage);
void transactionProgressChanged();
QSet<AbstractResource*> m_toUpgrade;
QSet<AbstractResource*> m_upgradeable;
......
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