Commit 5711fdbf authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Provide a count of elements on the ApplicationsListPage title

Something like "Education - 3523 results"

In case all applications have not been fetched yet, we only show the
most relevant digit and the magnitude "Education - 3000+ results".

BUG: 389616
parent bcdf113f
......@@ -27,6 +27,7 @@ DiscoverPage {
property alias resourcesUrl: appsModel.resourcesUrl
property alias isBusy: appsModel.isBusy
property alias allBackends: appsModel.allBackends
property alias roughCount: appsModel.roughCount
property alias count: apps.count
property alias listHeader: apps.header
property alias listHeaderPositioning: apps.headerPositioning
......@@ -43,8 +44,28 @@ DiscoverPage {
return input.replace(regex, "");
}
title: search.length>0 ? i18n("Search: %1", stripHtml(search))
: category ? category.name : i18n("Search")
title: {
const rough = appsModel.roughCount;
if (search.length>0) {
if (rough.length > 0) {
return i18n("Search: %1 - %2 items", stripHtml(search), rough)
} else {
return i18n("Search: %1", stripHtml(search))
}
} else if (category) {
if (rough.length > 0) {
return i18n("%1 - %2 items", category.name, rough)
} else {
return category.name
}
} else {
if (rough.length > 0) {
return i18n("Search - %1 items", rough)
} else {
return i18n("Search")
}
}
}
signal clearSearch()
......@@ -156,8 +177,8 @@ DiscoverPage {
visible: appsModel.search.length > 0 && stateFilter !== AbstractResource.Installed
icon.name: "edit-none"
text: i18nc("%1 is the name of an application", "\"%1\" was not found in the available sources", appsModel.search)
explanation: i18nc("%1 is the name of an application", "\"%1\" may be available on the web. Software acquired from the web has not been reviewed by your distributor for functionality or stability. Use with caution.", appsModel.search)
text: visible ? i18nc("%1 is the name of an application", "\"%1\" was not found in the available sources", appsModel.search) : ""
explanation: visible ? i18nc("%1 is the name of an application", "\"%1\" may be available on the web. Software acquired from the web has not been reviewed by your distributor for functionality or stability. Use with caution.", appsModel.search) : ""
helpfulAction: Kirigami.Action {
text: i18nc("%1 is the name of an application", "Search the web for \"%1\"", appsModel.search)
icon.name: "internet-web-browser"
......
......@@ -9,10 +9,12 @@
#include "libdiscover_debug.h"
#include <QMetaProperty>
#include <cmath>
#include <utils.h>
#include "ResourcesModel.h"
#include <Category/CategoryModel.h>
#include <KLocalizedString>
#include <ReviewsBackend/Rating.h>
#include <Transaction/TransactionModel.h>
......@@ -55,6 +57,14 @@ ResourcesProxyModel::ResourcesProxyModel(QObject *parent)
connect(this, &QAbstractItemModel::modelReset, this, &ResourcesProxyModel::countChanged);
connect(this, &QAbstractItemModel::rowsInserted, this, &ResourcesProxyModel::countChanged);
connect(this, &QAbstractItemModel::rowsRemoved, this, &ResourcesProxyModel::countChanged);
QTimer *roughCountTimer = new QTimer(this);
roughCountTimer->setInterval(10);
roughCountTimer->setSingleShot(true);
connect(roughCountTimer, &QTimer::timeout, this, &ResourcesProxyModel::roughCountChanged);
connect(this, &ResourcesProxyModel::countChanged, roughCountTimer, qOverload<>(&QTimer::start));
connect(this, &ResourcesProxyModel::busyChanged, roughCountTimer, qOverload<>(&QTimer::start));
}
void ResourcesProxyModel::componentComplete()
......@@ -638,3 +648,21 @@ bool ResourcesProxyModel::sortByRelevancy() const
{
return m_sortByRelevancy;
}
QString ResourcesProxyModel::roughCount() const
{
const int rows = rowCount();
if (isBusy()) {
// We return an empty string because it's evidently confusing
if (rows == 0) {
return {};
}
// We convert rows=1234 into round=1000
const int round = std::pow(10, std::floor(std::log10(rows)));
if (round >= 1) {
return i18nc("an approximation number, like 3000+", "%1+", (rows / round) * round);
}
}
return QString::number(rows);
}
......@@ -40,6 +40,7 @@ class DISCOVERCOMMON_EXPORT ResourcesProxyModel : public QAbstractListModel, pub
Q_PROPERTY(bool isBusy READ isBusy NOTIFY busyChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(bool sortByRelevancy READ sortByRelevancy NOTIFY sortByRelevancyChanged)
Q_PROPERTY(QString roughCount READ roughCount NOTIFY roughCountChanged)
public:
explicit ResourcesProxyModel(QObject *parent = nullptr);
enum Roles {
......@@ -130,6 +131,8 @@ public:
}
void componentComplete() override;
QString roughCount() const;
private Q_SLOTS:
void refreshBackend(AbstractResourcesBackend *backend, const QVector<QByteArray> &properties);
void refreshResource(AbstractResource *resource, const QVector<QByteArray> &properties);
......@@ -159,6 +162,7 @@ private:
AggregatedResultsStream *m_currentStream;
Q_SIGNALS:
void roughCountChanged();
void busyChanged(bool isBusy);
void sortRoleChanged(int sortRole);
void sortOrderChanged(Qt::SortOrder order);
......
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