swift
legalinfocomponent.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 
4 #include "legalinfocomponent.h"
5 
6 #include <QPointer>
7 
8 #include "ui_legalinfocomponent.h"
9 
10 #include "config/buildconfig.h"
11 #include "core/data/globalsetup.h"
12 #include "gui/guiapplication.h"
13 #include "misc/logmessage.h"
14 #include "misc/network/url.h"
15 #include "misc/statusmessage.h"
16 
17 using namespace swift::misc;
18 using namespace swift::misc::network;
19 using namespace swift::core::data;
20 using namespace swift::config;
21 
22 namespace swift::gui::components
23 {
24  CLegalInfoComponent::CLegalInfoComponent(QWidget *parent)
25  : COverlayMessagesFrame(parent), ui(new Ui::CLegalInfoComponent)
26  {
27  ui->setupUi(this);
28  this->setChecklistInfo();
29 
30  const bool crashDumpUploadEnabled = m_crashDumpUploadEnabled.getThreadLocal();
31  ui->cb_CrashDumps->setChecked(crashDumpUploadEnabled);
32 
33  connect(ui->cb_CrashDumps, &QCheckBox::toggled, this, &CLegalInfoComponent::onAllowCrashDumps);
34  }
35 
37 
38  bool CLegalInfoComponent::isAgreedTo() const { return ui->cb_Agree->isChecked(); }
39 
41  {
42  if (this->isAgreedTo()) { return true; }
43  static const CStatusMessage m =
44  CStatusMessage(this).validationError(u"You need to agree with the swift license");
45  this->showOverlayMessage(m);
46  return false;
47  }
48 
49  void CLegalInfoComponent::onAllowCrashDumps(bool checked)
50  {
51  CLogMessage::preformatted(m_crashDumpUploadEnabled.setAndSave(checked));
52  }
53 
54  void CLegalInfoComponent::setChecklistInfo()
55  {
56  if (!sGui) { return; }
57  const CGlobalSetup gs = sGui->getGlobalSetup();
58  const CUrl url = gs.getHelpPageUrl().withAppendedPath("checklist");
59  ui->lbl_Tip->setText(QStringLiteral("Please read the <a href=\"%1\">checklist before your 1st flight</a>")
60  .arg(url.getFullUrl()));
61  ui->lbl_Tip->setTextFormat(Qt::RichText);
62  ui->lbl_Tip->setTextInteractionFlags(Qt::TextBrowserInteraction);
63  ui->lbl_Tip->setOpenExternalLinks(true);
64  }
65 
66  bool CLegalInfoWizardPage::validatePage() { return m_legalInfo && m_legalInfo->validateAgreement(); }
67 } // namespace swift::gui::components
data::CGlobalSetup getGlobalSetup() const
Global setup.
Global settings for readers, debug flags, etc.
Definition: globalsetup.h:31
swift::misc::network::CUrl getHelpPageUrl() const
Help page URL.
Definition: globalsetup.cpp:44
bool showOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show single message.
Using this class provides a QFrame with the overlay functionality already integrated.
CStatusMessage setAndSave(const T &value, qint64 timestamp=0)
Write and save in the same step. Must be called from the thread in which the owner lives.
Definition: valuecache.h:417
const T & getThreadLocal() const
Read the current value.
Definition: valuecache.h:400
Derived & validationError(const char16_t(&format)[N])
Set the severity to error, providing a format string, and adding the validation category.
Streamable status message, e.g.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition: url.h:27
CUrl withAppendedPath(const QString &path) const
Append path.
Definition: url.cpp:115
QString getFullUrl(bool withQuery=true) const
Qualified name.
Definition: url.cpp:84
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Core data traits (aka cached values) and classes.
High level reusable GUI components.
Definition: aboutdialog.cpp:14
Free functions in swift::misc.
void toggled(bool checked)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
RichText
TextBrowserInteraction