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  ui->cb_Agree->setChecked(CBuildConfig::isLocalDeveloperDebugBuild());
33 
34  connect(ui->cb_CrashDumps, &QCheckBox::toggled, this, &CLegalInfoComponent::onAllowCrashDumps);
35  }
36 
38 
39  bool CLegalInfoComponent::isAgreedTo() const { return ui->cb_Agree->isChecked(); }
40 
42  {
43  if (this->isAgreedTo()) { return true; }
44  static const CStatusMessage m =
45  CStatusMessage(this).validationError(u"You need to agree with the swift license");
46  this->showOverlayMessage(m);
47  return false;
48  }
49 
50  void CLegalInfoComponent::onAllowCrashDumps(bool checked)
51  {
52  CLogMessage::preformatted(m_crashDumpUploadEnabled.setAndSave(checked));
53  }
54 
55  void CLegalInfoComponent::setChecklistInfo()
56  {
57  if (!sGui) { return; }
58  const CGlobalSetup gs = sGui->getGlobalSetup();
59  const CUrl url = gs.getHelpPageUrl("checklist");
60  ui->lbl_Tip->setText(QStringLiteral("Please read the <a href=\"%1\">checklist before your 1st flight</a>")
61  .arg(url.getFullUrl()));
62  ui->lbl_Tip->setTextFormat(Qt::RichText);
63  ui->lbl_Tip->setTextInteractionFlags(Qt::TextBrowserInteraction);
64  ui->lbl_Tip->setOpenExternalLinks(true);
65  }
66 
67  bool CLegalInfoWizardPage::validatePage() { return m_legalInfo && m_legalInfo->validateAgreement(); }
68 } // 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 QString &context={}) 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
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:13
Free functions in swift::misc.