diff --git a/CHANGES b/CHANGES index 377aa2271..0ecaafb51 100644 --- a/CHANGES +++ b/CHANGES @@ -37,8 +37,8 @@ This release contains contributions from (alphabetically by first name): - Multiple *netinstall* modules can exist side-by-side, and they each control the package installation for their part of the package list. Previously, a netinstall module would overwrite all of the package - configuration done by other netinstall modules. - #1303 + configuration done by other netinstall modules. Translations can be + provided in the configuration file, `netinstall.conf`. #1303 # 3.2.18 (2020-01-28) # diff --git a/src/modules/netinstall/NetInstallPage.cpp b/src/modules/netinstall/NetInstallPage.cpp index c3754e1c2..735610c3d 100644 --- a/src/modules/netinstall/NetInstallPage.cpp +++ b/src/modules/netinstall/NetInstallPage.cpp @@ -2,7 +2,7 @@ * Copyright 2016, Luca Giambonini * Copyright 2016, Lisa Vitolo * Copyright 2017, Kyle Robbertze - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2018, 2020, Adriaan de Groot * Copyright 2017, Gabriel Craciunescu * * Calamares is free software: you can redistribute it and/or modify @@ -34,8 +34,6 @@ #include #include -using CalamaresUtils::yamlToVariant; - NetInstallPage::NetInstallPage( QWidget* parent ) : QWidget( parent ) , ui( new Ui::Page_NetInst ) @@ -43,6 +41,38 @@ NetInstallPage::NetInstallPage( QWidget* parent ) , m_groups( nullptr ) { ui->setupUi( this ); + setPageTitle( nullptr ); + CALAMARES_RETRANSLATE_SLOT( &NetInstallPage::retranslate ); +} + +NetInstallPage::~NetInstallPage() +{ + delete m_groups; + delete m_reply; +} + +void +NetInstallPage::setPageTitle( CalamaresUtils::Locale::TranslatedString* t ) +{ + m_title.reset( t ); + if ( !m_title ) + { + ui->label->hide(); + } + else + { + ui->label->show(); + } + retranslate(); +} + +void +NetInstallPage::retranslate() +{ + if ( ui && m_title ) + { + ui->label->setText( m_title->get() ); // That's get() on the TranslatedString + } } bool @@ -58,8 +88,6 @@ NetInstallPage::readGroups( const QByteArray& yamlData ) } Q_ASSERT( groups.IsSequence() ); m_groups = new PackageModel( groups ); - CALAMARES_RETRANSLATE( m_groups->setHeaderData( 0, Qt::Horizontal, tr( "Name" ) ); - m_groups->setHeaderData( 1, Qt::Horizontal, tr( "Description" ) ); ) return true; } catch ( YAML::Exception& e ) @@ -121,6 +149,7 @@ NetInstallPage::dataIsHere() return; } + retranslate(); // For changed model ui->groupswidget->setModel( m_groups ); ui->groupswidget->header()->setSectionResizeMode( 0, QHeaderView::ResizeToContents ); ui->groupswidget->header()->setSectionResizeMode( 1, QHeaderView::Stretch ); diff --git a/src/modules/netinstall/NetInstallPage.h b/src/modules/netinstall/NetInstallPage.h index fbd60a8fd..12633c6b9 100644 --- a/src/modules/netinstall/NetInstallPage.h +++ b/src/modules/netinstall/NetInstallPage.h @@ -2,7 +2,7 @@ * Copyright 2016, Luca Giambonini * Copyright 2016, Lisa Vitolo * Copyright 2017, Kyle Robbertze - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2018, 2020, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,9 +24,13 @@ #include "PackageModel.h" #include "PackageTreeItem.h" +#include "locale/TranslatableConfiguration.h" + #include #include +#include + class QNetworkReply; namespace Ui @@ -39,6 +43,18 @@ class NetInstallPage : public QWidget Q_OBJECT public: NetInstallPage( QWidget* parent = nullptr ); + virtual ~NetInstallPage(); + + /** @brief Sets the page title + * + * In situations where there is more than one netinstall page, + * or you want some explanatory title above the treeview, + * set the page title. This page takes ownership of the + * TranslatedString object. + * + * Set to nullptr to remove the title. + */ + void setPageTitle( CalamaresUtils::Locale::TranslatedString* ); void onActivate(); @@ -63,6 +79,8 @@ public: public slots: void dataIsHere(); + void retranslate(); + signals: void checkReady( bool ); @@ -74,6 +92,8 @@ private: Ui::Page_NetInst* ui; + std::unique_ptr< CalamaresUtils::Locale::TranslatedString > m_title; // Above the treeview + QNetworkReply* m_reply; PackageModel* m_groups; bool m_required; diff --git a/src/modules/netinstall/NetInstallViewStep.cpp b/src/modules/netinstall/NetInstallViewStep.cpp index b0fe53083..3227ecd65 100644 --- a/src/modules/netinstall/NetInstallViewStep.cpp +++ b/src/modules/netinstall/NetInstallViewStep.cpp @@ -2,7 +2,7 @@ * Copyright 2016, Luca Giambonini * Copyright 2016, Lisa Vitolo * Copyright 2017, Kyle Robbertze - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2018, 2020, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +34,7 @@ NetInstallViewStep::NetInstallViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_widget( new NetInstallPage() ) , m_nextEnabled( false ) + , m_sidebarLabel( nullptr ) { emit nextStatusChanged( true ); connect( m_widget, &NetInstallPage::checkReady, this, &NetInstallViewStep::nextIsReady ); @@ -46,20 +47,14 @@ NetInstallViewStep::~NetInstallViewStep() { m_widget->deleteLater(); } + delete m_sidebarLabel; } QString NetInstallViewStep::prettyName() const { - return tr( "Package selection" ); -} - - -QString -NetInstallViewStep::prettyStatus() const -{ - return m_prettyStatus; + return m_sidebarLabel ? m_sidebarLabel->get() : tr( "Package selection" ); } @@ -128,9 +123,9 @@ NetInstallViewStep::onLeave() // Clear out existing operations for this module, going backwards: // Sometimes we remove an item, and we don't want the index to // fall off the end of the list. - for ( int index = packageOperations.length() - 1; 0 <= index ; index-- ) + for ( int index = packageOperations.length() - 1; 0 <= index; index-- ) { - const QVariantMap op = packageOperations.at(index).toMap(); + const QVariantMap op = packageOperations.at( index ).toMap(); if ( op.contains( "source" ) && op.value( "source" ).toString() == moduleInstanceKey().toString() ) { cDebug() << Logger::SubEntry << "Removing existing operations for" << moduleInstanceKey(); @@ -178,6 +173,12 @@ NetInstallViewStep::onLeave() } } +void +NetInstallViewStep::nextIsReady( bool b ) +{ + m_nextEnabled = b; + emit nextStatusChanged( b ); +} void NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap ) @@ -192,11 +193,16 @@ NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap ) Calamares::JobQueue::instance()->globalStorage()->insert( "groupsUrl", groupsUrl ); m_widget->loadGroupList( groupsUrl ); } -} -void -NetInstallViewStep::nextIsReady( bool b ) -{ - m_nextEnabled = b; - emit nextStatusChanged( b ); + bool bogus = false; + auto label = CalamaresUtils::getSubMap( configurationMap, "label", bogus ); + + if ( label.contains( "sidebar" ) ) + { + m_sidebarLabel = new CalamaresUtils::Locale::TranslatedString( label, "sidebar" ); + } + if ( label.contains( "title" ) ) + { + m_widget->setPageTitle( new CalamaresUtils::Locale::TranslatedString( label, "title" ) ); + } } diff --git a/src/modules/netinstall/NetInstallViewStep.h b/src/modules/netinstall/NetInstallViewStep.h index be92f5cc3..ad796b8b2 100644 --- a/src/modules/netinstall/NetInstallViewStep.h +++ b/src/modules/netinstall/NetInstallViewStep.h @@ -20,10 +20,10 @@ #ifndef NETINSTALLVIEWSTEP_H #define NETINSTALLVIEWSTEP_H -#include -#include - -#include +#include "DllMacro.h" +#include "locale/TranslatableConfiguration.h" +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" #include @@ -38,7 +38,6 @@ public: virtual ~NetInstallViewStep() override; QString prettyName() const override; - QString prettyStatus() const override; QWidget* widget() override; @@ -63,8 +62,7 @@ public slots: private: NetInstallPage* m_widget; bool m_nextEnabled; - QString m_prettyStatus; - + CalamaresUtils::Locale::TranslatedString* m_sidebarLabel; // As it appears in the sidebar QList< Calamares::job_ptr > m_jobs; }; diff --git a/src/modules/netinstall/PackageModel.cpp b/src/modules/netinstall/PackageModel.cpp index b5b256ae0..6d299f633 100644 --- a/src/modules/netinstall/PackageModel.cpp +++ b/src/modules/netinstall/PackageModel.cpp @@ -21,9 +21,11 @@ #include "utils/Yaml.h" +// TODO: see headerData(), remove after 3.2.19 +#include + PackageModel::PackageModel( const YAML::Node& data, QObject* parent ) : QAbstractItemModel( parent ) - , m_columnHeadings() { m_rootItem = new PackageTreeItem(); setupModelData( data, m_rootItem ); @@ -106,11 +108,7 @@ PackageModel::rowCount( const QModelIndex& parent ) const int PackageModel::columnCount( const QModelIndex& parent ) const { - if ( parent.isValid() ) - { - return static_cast< PackageTreeItem* >( parent.internalPointer() )->columnCount(); - } - return m_rootItem->columnCount(); + return 2; } QVariant @@ -154,26 +152,6 @@ PackageModel::setData( const QModelIndex& index, const QVariant& value, int role return true; } -bool -PackageModel::setHeaderData( int section, Qt::Orientation orientation, const QVariant& value, int role ) -{ - Q_UNUSED( role ) - - if ( orientation == Qt::Horizontal ) - { - if ( m_columnHeadings.value( section ) != QVariant() ) - { - m_columnHeadings.replace( section, value ); - } - else - { - m_columnHeadings.insert( section, value ); - } - emit headerDataChanged( orientation, section, section ); - } - return true; -} - Qt::ItemFlags PackageModel::flags( const QModelIndex& index ) const { @@ -193,7 +171,12 @@ PackageModel::headerData( int section, Qt::Orientation orientation, int role ) c { if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) { - return m_columnHeadings.value( section ); + // Unusual translation call uses the existing translation from the NetInstallPage + // class (now removed). + // + // TODO: after 3.2.19, change this to just tr() and push TX + return ( section == 0 ) ? QCoreApplication::translate( "NetInstallPage", "Name" ) + : QCoreApplication::translate( "NetInstallPage", "Description" ); } return QVariant(); } diff --git a/src/modules/netinstall/PackageModel.h b/src/modules/netinstall/PackageModel.h index cd8f676c8..25965cb7f 100644 --- a/src/modules/netinstall/PackageModel.h +++ b/src/modules/netinstall/PackageModel.h @@ -44,14 +44,15 @@ public: QVariant data( const QModelIndex& index, int role ) const override; bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override; - bool - setHeaderData( int section, Qt::Orientation orientation, const QVariant& value, int role = Qt::EditRole ) override; Qt::ItemFlags flags( const QModelIndex& index ) const override; - QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; + QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override; QModelIndex parent( const QModelIndex& index ) const override; + + QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; int rowCount( const QModelIndex& parent = QModelIndex() ) const override; int columnCount( const QModelIndex& parent = QModelIndex() ) const override; + PackageItemDataList getPackages() const; QList< PackageTreeItem* > getItemPackages( PackageTreeItem* item ) const; @@ -60,7 +61,6 @@ private: PackageTreeItem* m_rootItem; QList< PackageTreeItem* > m_hiddenItems; - QVariantList m_columnHeadings; }; #endif // PACKAGEMODEL_H diff --git a/src/modules/netinstall/PackageTreeItem.cpp b/src/modules/netinstall/PackageTreeItem.cpp index bbd85975e..59e82a659 100644 --- a/src/modules/netinstall/PackageTreeItem.cpp +++ b/src/modules/netinstall/PackageTreeItem.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright (c) 2017, Kyle Robbertze - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2020, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -105,12 +105,6 @@ PackageTreeItem::row() const return 0; } -int -PackageTreeItem::columnCount() const -{ - return m_columns; -} - QVariant PackageTreeItem::data( int column ) const { diff --git a/src/modules/netinstall/PackageTreeItem.h b/src/modules/netinstall/PackageTreeItem.h index c2672b4d4..18a509861 100644 --- a/src/modules/netinstall/PackageTreeItem.h +++ b/src/modules/netinstall/PackageTreeItem.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright (c) 2017, Kyle Robbertze - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2020, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -54,7 +54,6 @@ public: void appendChild( PackageTreeItem* child ); PackageTreeItem* child( int row ); int childCount() const; - int columnCount() const; QVariant data( int column ) const override; int row() const; @@ -90,7 +89,6 @@ private: PackageTreeItem* m_parentItem; QList< PackageTreeItem* > m_childItems; ItemData m_data; - const int m_columns = 2; // Name, description }; #endif // PACKAGETREEITEM_H diff --git a/src/modules/netinstall/netinstall.conf b/src/modules/netinstall/netinstall.conf index fd59c24c6..ab600326e 100644 --- a/src/modules/netinstall/netinstall.conf +++ b/src/modules/netinstall/netinstall.conf @@ -21,3 +21,17 @@ # This only has an effect if the netinstall data cannot be retrieved, # or is corrupt: having "required" set, means the install cannot proceed. required: false + +# To support multiple instances of this module, +# some strings are configurable and translatable here. +# - *sidebar* This is the name of the module in the progress-tree / sidebar +# in Calamares. +# - *title* This is displayed above the list of packages. +# If no *sidebar* values are provided, defaults to "Package selection" +# and existing translations. If no *title* values are provided, no string +# is displayed. +label: + sidebar: "Package selection" + sidebar[nl]: "Pakketkeuze" + title: "Office Package" + title[nl]: "Kantoorsoftware" diff --git a/src/modules/netinstall/page_netinst.ui b/src/modules/netinstall/page_netinst.ui index 3aa4e57ec..917057ff4 100644 --- a/src/modules/netinstall/page_netinst.ui +++ b/src/modules/netinstall/page_netinst.ui @@ -14,6 +14,16 @@ + + + + Title of Netinstall Module + + + Qt::AlignCenter + + + @@ -31,7 +41,7 @@ 0 0 981 - 434 + 407