From 0a11ffa805abfe38100b41f3fe2aaefa1a12e5ba Mon Sep 17 00:00:00 2001 From: octaeder <102688820+octaeder@users.noreply.github.com> Date: Tue, 13 Feb 2024 03:52:04 +0100 Subject: [PATCH] TemplateSelector: Handle host not available --- src/templateselector.cpp | 27 +++++++++++++++++++++++++-- src/templateselector.h | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/templateselector.cpp b/src/templateselector.cpp index 1a63eb2a71..c61ba6ff15 100644 --- a/src/templateselector.cpp +++ b/src/templateselector.cpp @@ -104,6 +104,10 @@ TemplateSelector::TemplateSelector(QString name, QWidget *parent) TemplateSelector::~TemplateSelector() { + if (networkManager) { + networkManager->deleteLater(); + networkManager=nullptr; + } } void TemplateSelector::addResource(AbstractTemplateResource *res) @@ -157,7 +161,10 @@ const QNetworkRequest::Attribute tplAttributeItem = static_castget(request); connect(reply, &QNetworkReply::finished, this, &TemplateSelector::onRequestCompleted); +#if QT_VERSION_MAJOR<6 + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onRequestError())); +#else + connect(reply, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), SLOT(onRequestError())); +#endif } /*! @@ -203,7 +215,6 @@ void TemplateSelector::saveToCache(const QByteArray &data, const QString &path) } } - void TemplateSelector::itemExpanded(QTreeWidgetItem* item){ bool populated=item->data(0,PopulatedRole).toBool(); if(populated) return; @@ -614,3 +625,15 @@ void TemplateSelector::openTemplateLocation() } } +void TemplateSelector::onRequestError() +{ + QNetworkReply *reply = qobject_cast(sender()); + if (!reply) return; + + QTreeWidgetItem *rootItem=reply->request().attribute(tplAttributeItem).value(); + if (!rootItem) return; + rootItem->child(0)->setText(0,tr("Repository not found. Network error:%1").arg("\n"+reply->errorString())); + + networkManager->deleteLater(); + networkManager=nullptr; +} diff --git a/src/templateselector.h b/src/templateselector.h index a2a388fbe7..6a9ad4b89f 100644 --- a/src/templateselector.h +++ b/src/templateselector.h @@ -75,6 +75,7 @@ private slots: void editTemplateInfo(); void removeTemplate(); void openTemplateLocation(); + void onRequestError(); private: QString orDefault(const QString &val, const QString &defaultIfValEmpty) const