swift
Loading...
Searching...
No Matches
abouthtmlcomponent.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2018 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QDesktopServices>
7#include <QFile>
8#include <QPointer>
9#include <QTimer>
10
11#include "ui_abouthtmlcomponent.h"
12
13#include "gui/guiapplication.h"
14#include "misc/directoryutils.h"
15#include "misc/fileutils.h"
17
18using namespace swift::misc;
19
21{
23 {
24 ui->setupUi(this);
25 const QPointer<CAboutHtmlComponent> myself(this);
26 connect(ui->tbr_About, &QTextBrowser::anchorClicked, this, &CAboutHtmlComponent::onAnchorClicked,
28
29 QTimer::singleShot(2500, this, [=] {
30 if (!myself)
31 {
32 return;
33 }
34 myself->loadAbout();
35 });
36 }
37
39
40 void CAboutHtmlComponent::loadAbout()
41 {
42 if (!sGui || sGui->isShuttingDown())
43 {
44 return;
45 }
46
47 // make links absolute
48 static const QString htmlFixed = [=] {
49 // workaround:
50 // 1) Only reading as HTML gives proper formatting
51 // 2) Reading the file resource fails (likely because of the style sheet)
53 return html;
54
55 // no longer replacing the URLs, doing this on anchor clicked
56 // const QString legalDir = sGui->getGlobalSetup().getLegalDirectoryUrl().getFullUrl();
57 // return QString(html).replace(QLatin1String("href=\"./"), "href=\"" + legalDir);
58 }();
59
60 ui->tbr_About->setHtml(htmlFixed);
61 ui->tbr_About->setOpenLinks(false);
62
63 // base URL
64 // ui->tbr_About->document()->setMetaInformation(QTextDocument::DocumentUrl,
65 // "https://datastore.swift-project.org/legal");
66 }
67
68 void CAboutHtmlComponent::onAnchorClicked(const QUrl &url)
69 {
70 if (!url.isRelative())
71 {
73 return;
74 }
75 const QString possibleLegalFile =
77 QFile f(possibleLegalFile);
78 if (f.exists())
79 {
81 };
82 }
83} // namespace swift::gui::components
CAboutHtmlComponent(QWidget *parent=nullptr)
Constructor.
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
static QString readFileToString(const QString &fileNameAndPath)
Read file into string.
Definition fileutils.cpp:83
static const QString & legalDirectory()
Where Legal files are located.
static const QString & aboutFilePath()
The about document file location.
High level reusable GUI components.
Free functions in swift::misc.
bool openUrl(const QUrl &url)
QFrame(QWidget *parent, Qt::WindowFlags f)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QueuedConnection
void anchorClicked(const QUrl &link)
QString fileName(QUrl::ComponentFormattingOptions options) const const
QUrl fromLocalFile(const QString &localFile)
bool isRelative() const const
QWidget(QWidget *parent, Qt::WindowFlags f)