Commit ede4a7c7 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Show an error if we couldn't find any resources from the featured apps

BUG: 401959
parent 8c059ef7
......@@ -46,14 +46,16 @@ FeaturedModel::FeaturedModel()
*featuredCache = dir+QLatin1String("/featured-5.9.json");
const QUrl featuredUrl(QStringLiteral("https://autoconfig.kde.org/discover/featured-5.9.json"));
auto *getJob = KIO::storedGet(featuredUrl, KIO::NoReload, KIO::HideProgressInfo);
connect(getJob, &KIO::StoredTransferJob::result, this, [this, getJob](){
auto *m_fetchJob = KIO::storedGet(featuredUrl, KIO::NoReload, KIO::HideProgressInfo);
connect(m_fetchJob, &KIO::StoredTransferJob::result, this, [this, m_fetchJob](){
QFile f(*featuredCache);
if (!f.open(QIODevice::WriteOnly))
qCWarning(DISCOVER_LOG) << "could not open" << *featuredCache << f.errorString();
f.write(getJob->data());
f.write(m_fetchJob->data());
f.close();
refresh();
Q_EMIT isFetchingChanged();
});
if (!ResourcesModel::global()->backends().isEmpty() && QFile::exists(*featuredCache))
......
......@@ -22,12 +22,15 @@
#define FEATUREDMODEL_H
#include <QAbstractListModel>
#include <QPointer>
namespace KIO { class StoredTransferJob; }
class AbstractResource;
class FeaturedModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(bool isFetching READ isFetching NOTIFY isFetchingChanged)
public:
FeaturedModel();
~FeaturedModel() override {}
......@@ -37,6 +40,11 @@ class FeaturedModel : public QAbstractListModel
int rowCount(const QModelIndex & parent) const override;
QHash<int, QByteArray> roleNames() const override;
bool isFetching() const { return !m_fetchJob.isNull(); }
Q_SIGNALS:
void isFetchingChanged();
private:
void setUris(const QVector<QUrl> &uris);
void refresh();
......@@ -44,6 +52,7 @@ class FeaturedModel : public QAbstractListModel
QVector<QUrl> m_uris;
QVector<AbstractResource*> m_resources;
QPointer<KIO::StoredTransferJob> m_fetchJob;
};
#endif // FEATUREDMODEL_H
......@@ -47,11 +47,19 @@ DiscoverPage
readonly property bool compact: page.width < 550 || !applicationWindow().wideScreen
Kirigami.CardsListView {
id: view
model: FeaturedModel {}
currentIndex: -1
delegate: ApplicationDelegate {
application: model.application
compact: page.compact
}
footer: Kirigami.Heading {
visible: view.count === 0
width: parent.width
horizontalAlignment: Text.AlignHCenter
text: i18n("Please check your connectivity")
}
}
}
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