[plasma/discover] /: Add sorting to the progress view
Aleix Pol <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit f9b02394e4ad73a14d448617ab457ad6746fb923 by Aleix Pol. Committed on 22/07/2026 at 22:28. Pushed by apol into branch 'master'. Add sorting to the progress view Makes sure that the transaction that is active at any given time is listed on top and easily reachable to the user. This is especially important since we removed the global entry on top of the whole update. Flatpak will take all of the things that need updating and update them at its own pace, so we better make it easy to the user when there's a bunch. Also adds some code to test in the dummy backend. M +10 -0 discover/qml/ProgressView.qml M +24 -4 libdiscover/backends/DummyBackend/DummyTransaction.cpp M +18 -0 libdiscover/backends/DummyBackend/DummyTransaction.h https://invent.kde.org/plasma/discover/-/commit/f9b02394e4ad73a14d448617ab457ad6746fb923 diff --git a/discover/qml/ProgressView.qml b/discover/qml/ProgressView.qml index 05b33f362..659167d85 100644 --- a/discover/qml/ProgressView.qml +++ b/discover/qml/ProgressView.qml @@ -1,3 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2012-2025 Aleix Pol Gonzalez <[email protected]> + * SPDX-FileCopyrightText: 2022 Nate Graham <[email protected]> + * SPDX-FileCopyrightText: 2023 ivan tkachenko <[email protected]> + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + pragma ComponentBehavior: Bound import QtQuick @@ -66,6 +74,8 @@ QQC2.ToolButton { } model: KItemModels.KSortFilterProxyModel { sourceModel: Discover.TransactionModel + sortRoleName: "status" + sortOrder: Qt.DescendingOrder filterRoleName: "visible" filterRowCallback: (sourceRow, sourceParent) => { const index = sourceModel.index(sourceRow, 0, sourceParent); diff --git a/libdiscover/backends/DummyBackend/DummyTransaction.cpp b/libdiscover/backends/DummyBackend/DummyTransaction.cpp index ae56ecd06..b45396b57 100644 --- a/libdiscover/backends/DummyBackend/DummyTransaction.cpp +++ b/libdiscover/backends/DummyBackend/DummyTransaction.cpp @@ -13,6 +13,9 @@ // #define TEST_PROCEED +static int m_concurrentTransactions = 0; +constexpr int MAX_CONCURRENT_TRANSACTIONS = 2; + DummyTransaction::DummyTransaction(DummyResource *app, Role role) : DummyTransaction(app, {}, role) { @@ -23,9 +26,21 @@ DummyTransaction::DummyTransaction(DummyResource *app, const AddonList &addons, , m_app(app) { setCancellable(true); - setStatus(DownloadingStatus); - iterateTransaction(); + considerStarting(); +} + +void DummyTransaction::considerStarting() +{ + // We can limit the concurrent jobs. Added to test the ProgressView with mixed statuses + if (m_concurrentTransactions < MAX_CONCURRENT_TRANSACTIONS) { + disconnect(OverseeTransactions::self(), &OverseeTransactions::transactionFinished, this, &DummyTransaction::considerStarting); + m_concurrentTransactions++; + iterateTransaction(); + } else { + connect(OverseeTransactions::self(), &OverseeTransactions::transactionFinished, this, &DummyTransaction::considerStarting); + setStatus(QueuedStatus); + } } void DummyTransaction::iterateTransaction() @@ -34,11 +49,12 @@ void DummyTransaction::iterateTransaction() return; if (progress() < 100) { + setStatus(DownloadingStatus); setProgress(qBound(0, progress() + QRandomGenerator::global()->bounded(5), 100)); - QTimer::singleShot(/*KRandom::random()%*/ 10, this, &DummyTransaction::iterateTransaction); + QTimer::singleShot(/*KRandom::random()%*/ 100, this, &DummyTransaction::iterateTransaction); } else if (status() == DownloadingStatus) { setStatus(CommittingStatus); - QTimer::singleShot(/*KRandom::random()%*/ 10, this, &DummyTransaction::iterateTransaction); + QTimer::singleShot(/*KRandom::random()%*/ 100, this, &DummyTransaction::iterateTransaction); #ifdef TEST_PROCEED } else if (resource()->name() == "Dummy 101") { Q_EMIT proceedRequest(QStringLiteral("yadda yadda"), @@ -60,10 +76,14 @@ void DummyTransaction::cancel() m_iterate = false; setStatus(CancelledStatus); + m_concurrentTransactions--; + Q_EMIT OverseeTransactions::self()->transactionFinished(); } void DummyTransaction::finishTransaction() { + m_concurrentTransactions--; + Q_EMIT OverseeTransactions::self()->transactionFinished(); AbstractResource::State newState = AbstractResource::State::Broken; switch (role()) { case InstallRole: diff --git a/libdiscover/backends/DummyBackend/DummyTransaction.h b/libdiscover/backends/DummyBackend/DummyTransaction.h index 4e57af0df..2befe119c 100644 --- a/libdiscover/backends/DummyBackend/DummyTransaction.h +++ b/libdiscover/backends/DummyBackend/DummyTransaction.h @@ -9,6 +9,23 @@ #include <Transaction/Transaction.h> class DummyResource; + +class OverseeTransactions : public QObject +{ + Q_OBJECT +public: + static OverseeTransactions *self() + { + static OverseeTransactions *m_self = nullptr; + if (!m_self) { + m_self = new OverseeTransactions; + } + return m_self; + } +Q_SIGNALS: + void transactionFinished(); +}; + class DummyTransaction : public Transaction { Q_OBJECT @@ -24,6 +41,7 @@ private Q_SLOTS: void finishTransaction(); private: + void considerStarting(); bool m_iterate = true; DummyResource *m_app; };