mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 15:15:39 +08:00
About info, fix relative files in onAnchorClicked
This commit is contained in:
committed by
Mat Sutcliffe
parent
072bb34a32
commit
8be1465f24
@@ -10,9 +10,14 @@
|
|||||||
#include "blackmisc/fileutils.h"
|
#include "blackmisc/fileutils.h"
|
||||||
#include "blackmisc/directoryutils.h"
|
#include "blackmisc/directoryutils.h"
|
||||||
#include "abouthtmlcomponent.h"
|
#include "abouthtmlcomponent.h"
|
||||||
|
#include "blackmisc/directoryutils.h"
|
||||||
|
#include "blackmisc/fileutils.h"
|
||||||
#include "ui_abouthtmlcomponent.h"
|
#include "ui_abouthtmlcomponent.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
|
|
||||||
@@ -26,6 +31,8 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
const QPointer<CAboutHtmlComponent> myself(this);
|
const QPointer<CAboutHtmlComponent> myself(this);
|
||||||
|
connect(ui->tbr_About, &QTextBrowser::anchorClicked, this, &CAboutHtmlComponent::onAnchorClicked, Qt::QueuedConnection);
|
||||||
|
|
||||||
QTimer::singleShot(2500, this, [ = ]
|
QTimer::singleShot(2500, this, [ = ]
|
||||||
{
|
{
|
||||||
if (!myself) { return; }
|
if (!myself) { return; }
|
||||||
@@ -38,6 +45,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CAboutHtmlComponent::loadAbout()
|
void CAboutHtmlComponent::loadAbout()
|
||||||
{
|
{
|
||||||
|
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||||
|
|
||||||
// make links absolute
|
// make links absolute
|
||||||
static const QString htmlFixed = [ = ]
|
static const QString htmlFixed = [ = ]
|
||||||
{
|
{
|
||||||
@@ -45,10 +54,33 @@ namespace BlackGui
|
|||||||
// 1) Only reading as HTML gives proper formatting
|
// 1) Only reading as HTML gives proper formatting
|
||||||
// 2) Reading the file resource fails (likely because of the style sheet)
|
// 2) Reading the file resource fails (likely because of the style sheet)
|
||||||
const QString html = CFileUtils::readFileToString(CDirectoryUtils::aboutFilePath());
|
const QString html = CFileUtils::readFileToString(CDirectoryUtils::aboutFilePath());
|
||||||
const QString legalDir = sGui->getGlobalSetup().getLegalDirectoryUrl().getFullUrl();
|
return html;
|
||||||
return QString(html).replace(QLatin1String("href=\"./"), "href=\"" + legalDir);
|
|
||||||
|
// no longer replacing the URLs, doing this on anchor clicked
|
||||||
|
// const QString legalDir = sGui->getGlobalSetup().getLegalDirectoryUrl().getFullUrl();
|
||||||
|
// return QString(html).replace(QLatin1String("href=\"./"), "href=\"" + legalDir);
|
||||||
}();
|
}();
|
||||||
|
|
||||||
ui->tbr_About->setHtml(htmlFixed);
|
ui->tbr_About->setHtml(htmlFixed);
|
||||||
|
ui->tbr_About->setOpenLinks(false);
|
||||||
|
|
||||||
|
// base URL
|
||||||
|
// ui->tbr_About->document()->setMetaInformation(QTextDocument::DocumentUrl, "https://datastore.swift-project.org/legal");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAboutHtmlComponent::onAnchorClicked(const QUrl &url)
|
||||||
|
{
|
||||||
|
if (!url.isRelative())
|
||||||
|
{
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QString possibleLegalFile = CFileUtils::appendFilePaths(CDirectoryUtils::legalDirectory(), url.fileName());
|
||||||
|
QFile f(possibleLegalFile);
|
||||||
|
if (f.exists())
|
||||||
|
{
|
||||||
|
QDesktopServices::openUrl(QUrl::fromLocalFile(possibleLegalFile));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#define BLACKGUI_COMPONENTS_ABOUTHTMLCOMPONENT_H
|
#define BLACKGUI_COMPONENTS_ABOUTHTMLCOMPONENT_H
|
||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
|
#include <QUrl>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
@@ -32,12 +33,15 @@ namespace BlackGui
|
|||||||
explicit CAboutHtmlComponent(QWidget *parent = nullptr);
|
explicit CAboutHtmlComponent(QWidget *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CAboutHtmlComponent();
|
virtual ~CAboutHtmlComponent() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Load credits and legal info
|
//! Load credits and legal info
|
||||||
void loadAbout();
|
void loadAbout();
|
||||||
|
|
||||||
|
//! Anchor has been clicked
|
||||||
|
void onAnchorClicked(const QUrl &url);
|
||||||
|
|
||||||
QScopedPointer<Ui::CAboutHtmlComponent> ui;
|
QScopedPointer<Ui::CAboutHtmlComponent> ui;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user