From 1de6062233a7bc3fe7f2e7934333ec26c55bf6d6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 28 Nov 2019 13:31:16 +0100 Subject: [PATCH] [license] Add should-be-expanded display option to license entries - In code, add the necessary bool - document meaning in the config file - actually expand the full text if the entry is local and set to expanding- by-default. This implementation is a bit lazy since it just pretends to click on the toggle button. - While here, reduce scope for UB by initializing POD members --- src/modules/license/LicensePage.cpp | 1 + src/modules/license/LicensePage.h | 6 ++++-- src/modules/license/LicenseWidget.cpp | 7 +++++++ src/modules/license/license.conf | 5 +++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modules/license/LicensePage.cpp b/src/modules/license/LicensePage.cpp index 1cb42ea8b..45205dcd4 100644 --- a/src/modules/license/LicensePage.cpp +++ b/src/modules/license/LicensePage.cpp @@ -72,6 +72,7 @@ LicenseEntry::LicenseEntry( const QVariantMap& conf ) m_url = QUrl( conf[ "url" ].toString() ); m_required = CalamaresUtils::getBool( conf, "required", false ); + m_expand = CalamaresUtils::getBool( conf, "expand", false ); bool ok = false; QString typeString = conf.value( "type", "software" ).toString(); diff --git a/src/modules/license/LicensePage.h b/src/modules/license/LicensePage.h index 65f26b543..dcd3ea7b4 100644 --- a/src/modules/license/LicensePage.h +++ b/src/modules/license/LicensePage.h @@ -56,13 +56,15 @@ struct LicenseEntry bool isValid() const { return !m_id.isEmpty(); } bool isRequired() const { return m_required; } bool isLocal() const; + bool expandByDefault() const { return m_expand; } QString m_id; QString m_prettyName; QString m_prettyVendor; - Type m_type; + Type m_type = Type::Software; QUrl m_url; - bool m_required; + bool m_required = false; + bool m_expand = false; }; class LicensePage : public QWidget diff --git a/src/modules/license/LicenseWidget.cpp b/src/modules/license/LicenseWidget.cpp index 609e850a9..a4c1dfaaa 100644 --- a/src/modules/license/LicenseWidget.cpp +++ b/src/modules/license/LicenseWidget.cpp @@ -98,6 +98,13 @@ LicenseWidget::LicenseWidget( LicenseEntry entry, QWidget* parent ) vLayout->addWidget( m_fullText ); setLayout( vLayout ); + + if ( m_entry.expandByDefault() ) + { + // Since we started in a collapsed state, toggle it to expand. + // This can only be done once the full text has been added. + expandClicked(); + } } else { diff --git a/src/modules/license/license.conf b/src/modules/license/license.conf index 9057f8a51..8a1672887 100644 --- a/src/modules/license/license.conf +++ b/src/modules/license/license.conf @@ -14,6 +14,10 @@ # to the URL is provided, which opens in the default web browser. A local # URL (i.e. file:///) assumes that the contents are HTML or plain text, and # displays the license in-line. YAML: string, mandatory. +# - expand A boolean value only relevant for **local** URLs. If true, +# the license text is displayed in "expanded" form by +# default, rather than requiring the user to first open it up. +# YAML: boolean, optional, default is false. entries: - id: nvidia name: Nvidia @@ -43,3 +47,4 @@ entries: type: software required: true url: file:../LICENSE + expand: true