summaryrefslogtreecommitdiff
path: root/DisplayManual.cpp
diff options
context:
space:
mode:
authorChristoph Berg <christoph.berg@credativ.de>2022-08-23 10:23:31 +0200
committerChristoph Berg <christoph.berg@credativ.de>2022-08-23 10:23:31 +0200
commit0e579a45e2e5823f90e2632073749583cd15fa0d (patch)
tree5e709e13d41c8ea0da0968fb6c4566057b4b7909 /DisplayManual.cpp
parent28d1767618141cd6481de2e93e36e3dfa555d4b4 (diff)
parent2d1068e60bce7ae1fff11623454900e8cee956b1 (diff)
Update upstream source from tag 'upstream/2.6.0_rc3+repack'
Update to upstream version '2.6.0~rc3+repack' with Debian dir 9ee8bc3a4b60bb88f4d57c7d1f2d37dbc1632144
Diffstat (limited to 'DisplayManual.cpp')
-rwxr-xr-xDisplayManual.cpp318
1 files changed, 159 insertions, 159 deletions
diff --git a/DisplayManual.cpp b/DisplayManual.cpp
index c5b9021b..5d910c95 100755
--- a/DisplayManual.cpp
+++ b/DisplayManual.cpp
@@ -1,159 +1,159 @@
-#include "DisplayManual.hpp"
-
-#include <QObject>
-#include <QNetworkAccessManager>
-#include <QNetworkRequest>
-#include <QNetworkReply>
-#include <QUrl>
-#include <QString>
-#include <QDir>
-#include <QFileInfo>
-#include <QDesktopServices>
-#include <QLocale>
-
-#include "revision_utils.hpp"
-
-#include "pimpl_impl.hpp"
-
-namespace
-{
- class token
- : public QObject
- {
- Q_OBJECT
- public:
- token (QUrl const& url, QString const& lang, QString const& name_we, QObject * parent = nullptr)
- : QObject {parent}
- , url_ {url}
- , lang_ {lang}
- , name_we_ {name_we}
- {
- }
-
- QUrl url_;
- QString lang_;
- QString name_we_;
- };
-}
-
-class DisplayManual::impl final
- : public QObject
-{
- Q_OBJECT
-public:
- impl (QNetworkAccessManager * qnam)
- : qnam_ {qnam}
- {
- connect (qnam_, &QNetworkAccessManager::finished, this, &DisplayManual::impl::reply_finished);
- }
-
- void display (QUrl const& url, QString const& name_we)
- {
-#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
- if (QNetworkAccessManager::Accessible != qnam_->networkAccessible ()) {
- // try and recover network access for QNAM
- qnam_->setNetworkAccessible (QNetworkAccessManager::Accessible);
- }
-#endif
-
- // try and find a localized manual
- auto lang = QLocale::system ().name ();
- // try for language and country first
- auto file = name_we + '_' + lang + '-' + version () + ".html";
- auto target = url.resolved (file);
- QNetworkRequest request {target};
- request.setRawHeader ("User-Agent", "WSJT-X Manual Checker");
- request.setOriginatingObject (new token {url, lang, name_we, this});
- auto * reply = qnam_->head (request);
- outstanding_requests_ << reply;
- }
-
- void reply_finished (QNetworkReply * reply)
- {
- if (outstanding_requests_.contains (reply))
- {
- QUrl target;
- if (reply->error ())
- {
- if (auto * tok = qobject_cast<token *> (reply->request ().originatingObject ()))
- {
- auto pos = tok->lang_.lastIndexOf ('_');
- QString file;
- if (pos >= 0)
- {
- tok->lang_.truncate (pos);
- file = tok->name_we_ + '_' + tok->lang_ + '-' + version () + ".html";
- target = tok->url_.resolved (file);
- QNetworkRequest request {target};
- request.setRawHeader ("User-Agent", "WSJT-X Manual Checker");
- request.setOriginatingObject (tok);
- auto * reply = qnam_->head (request);
- outstanding_requests_ << reply;
- }
- else
- {
- // give up looking and request the default
- file = tok->name_we_ + '-' + version () + ".html";
- target = tok->url_.resolved (file);
- QDesktopServices::openUrl (target);
- delete tok;
- }
- }
- }
- else
- {
- // found it
- if (auto * tok = qobject_cast<token *> (reply->request ().originatingObject ()))
- {
- delete tok;
- }
- QDesktopServices::openUrl (reply->request ().url ());
- }
-
- outstanding_requests_.removeOne (reply);
- reply->deleteLater ();
- }
- }
-
- QNetworkAccessManager * qnam_;
- QList<QNetworkReply *> outstanding_requests_;
-};
-
-#include "DisplayManual.moc"
-
-DisplayManual::DisplayManual (QNetworkAccessManager * qnam, QObject * parent)
- : QObject {parent}
- , m_ {qnam}
-{
-}
-
-DisplayManual::~DisplayManual ()
-{
-}
-
-void DisplayManual::display_html_url (QUrl const& url, QString const& name_we)
-{
- m_->display (url, name_we);
-}
-
-void DisplayManual::display_html_file (QDir const& dir, QString const& name_we)
-{
- // try and find a localized manual
- auto lang = QLocale::system ().name ();
- // try for language and country first
- auto file = dir.absoluteFilePath (name_we + '_' + lang + '-' + version () + ".html");
- if (!QFileInfo::exists (file))
- {
- // try for language
- lang.truncate (lang.lastIndexOf ('_'));
- file = dir.absoluteFilePath (name_we + '_' + lang + '-' + version () + ".html");
- if (!QFileInfo::exists (file))
- {
- // use default
- file = dir.absoluteFilePath (name_we + '-' + version () + ".html");
- }
- }
- // may fail but browser 404 error is a good as anything
- QDesktopServices::openUrl (QUrl {"file:///" + file});
-}
-
+#include "DisplayManual.hpp"
+
+#include <QObject>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QUrl>
+#include <QString>
+#include <QDir>
+#include <QFileInfo>
+#include <QDesktopServices>
+#include <QLocale>
+
+#include "revision_utils.hpp"
+
+#include "pimpl_impl.hpp"
+
+namespace
+{
+ class token
+ : public QObject
+ {
+ Q_OBJECT
+ public:
+ token (QUrl const& url, QString const& lang, QString const& name_we, QObject * parent = nullptr)
+ : QObject {parent}
+ , url_ {url}
+ , lang_ {lang}
+ , name_we_ {name_we}
+ {
+ }
+
+ QUrl url_;
+ QString lang_;
+ QString name_we_;
+ };
+}
+
+class DisplayManual::impl final
+ : public QObject
+{
+ Q_OBJECT
+public:
+ impl (QNetworkAccessManager * qnam)
+ : qnam_ {qnam}
+ {
+ connect (qnam_, &QNetworkAccessManager::finished, this, &DisplayManual::impl::reply_finished);
+ }
+
+ void display (QUrl const& url, QString const& name_we)
+ {
+#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
+ if (QNetworkAccessManager::Accessible != qnam_->networkAccessible ()) {
+ // try and recover network access for QNAM
+ qnam_->setNetworkAccessible (QNetworkAccessManager::Accessible);
+ }
+#endif
+
+ // try and find a localized manual
+ auto lang = QLocale::system ().name ();
+ // try for language and country first
+ auto file = name_we + '_' + lang + '-' + version () + ".html";
+ auto target = url.resolved (file);
+ QNetworkRequest request {target};
+ request.setRawHeader ("User-Agent", "WSJT-X Manual Checker");
+ request.setOriginatingObject (new token {url, lang, name_we, this});
+ auto * reply = qnam_->head (request);
+ outstanding_requests_ << reply;
+ }
+
+ void reply_finished (QNetworkReply * reply)
+ {
+ if (outstanding_requests_.contains (reply))
+ {
+ QUrl target;
+ if (reply->error ())
+ {
+ if (auto * tok = qobject_cast<token *> (reply->request ().originatingObject ()))
+ {
+ auto pos = tok->lang_.lastIndexOf ('_');
+ QString file;
+ if (pos >= 0)
+ {
+ tok->lang_.truncate (pos);
+ file = tok->name_we_ + '_' + tok->lang_ + '-' + version () + ".html";
+ target = tok->url_.resolved (file);
+ QNetworkRequest request {target};
+ request.setRawHeader ("User-Agent", "WSJT-X Manual Checker");
+ request.setOriginatingObject (tok);
+ auto * reply = qnam_->head (request);
+ outstanding_requests_ << reply;
+ }
+ else
+ {
+ // give up looking and request the default
+ file = tok->name_we_ + '-' + version () + ".html";
+ target = tok->url_.resolved (file);
+ QDesktopServices::openUrl (target);
+ delete tok;
+ }
+ }
+ }
+ else
+ {
+ // found it
+ if (auto * tok = qobject_cast<token *> (reply->request ().originatingObject ()))
+ {
+ delete tok;
+ }
+ QDesktopServices::openUrl (reply->request ().url ());
+ }
+
+ outstanding_requests_.removeOne (reply);
+ reply->deleteLater ();
+ }
+ }
+
+ QNetworkAccessManager * qnam_;
+ QList<QNetworkReply *> outstanding_requests_;
+};
+
+#include "DisplayManual.moc"
+
+DisplayManual::DisplayManual (QNetworkAccessManager * qnam, QObject * parent)
+ : QObject {parent}
+ , m_ {qnam}
+{
+}
+
+DisplayManual::~DisplayManual ()
+{
+}
+
+void DisplayManual::display_html_url (QUrl const& url, QString const& name_we)
+{
+ m_->display (url, name_we);
+}
+
+void DisplayManual::display_html_file (QDir const& dir, QString const& name_we)
+{
+ // try and find a localized manual
+ auto lang = QLocale::system ().name ();
+ // try for language and country first
+ auto file = dir.absoluteFilePath (name_we + '_' + lang + '-' + version () + ".html");
+ if (!QFileInfo::exists (file))
+ {
+ // try for language
+ lang.truncate (lang.lastIndexOf ('_'));
+ file = dir.absoluteFilePath (name_we + '_' + lang + '-' + version () + ".html");
+ if (!QFileInfo::exists (file))
+ {
+ // use default
+ file = dir.absoluteFilePath (name_we + '-' + version () + ".html");
+ }
+ }
+ // may fail but browser 404 error is a good as anything
+ QDesktopServices::openUrl (QUrl {"file:///" + file});
+}
+