[officechooser] sync with upstream
This commit is contained in:
parent
e7e25a11e7
commit
19f24a61bf
@ -1,7 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
* Copyright 2019, Philip Müller <philm@manjaro.org>
|
* Copyright 2019, Philip MÜller <philm@manjaro.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -31,11 +31,10 @@ PackageChooserPage::PackageChooserPage( PackageChooserMode mode, QWidget* parent
|
|||||||
, ui( new Ui::PackageChooserPage )
|
, ui( new Ui::PackageChooserPage )
|
||||||
, m_introduction( QString(),
|
, m_introduction( QString(),
|
||||||
QString(),
|
QString(),
|
||||||
tr( "Office Selection" ),
|
tr( "Office Suite" ),
|
||||||
tr( "Please pick a office suite from the list. The selected product will be installed." ) )
|
tr( "Please pick a office suite from the list. The selected product will be installed." ) )
|
||||||
{
|
{
|
||||||
m_introduction.screenshot = QPixmap( QStringLiteral( ":/images/choose-office.jpg" ) );
|
m_introduction.screenshot = QPixmap( QStringLiteral( ":/images/choose-office.jpg" ) );
|
||||||
cDebug() << m_introduction.screenshot;
|
|
||||||
|
|
||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
CALAMARES_RETRANSLATE( updateLabels(); )
|
CALAMARES_RETRANSLATE( updateLabels(); )
|
||||||
@ -43,9 +42,9 @@ PackageChooserPage::PackageChooserPage( PackageChooserMode mode, QWidget* parent
|
|||||||
switch ( mode )
|
switch ( mode )
|
||||||
{
|
{
|
||||||
case PackageChooserMode::Optional:
|
case PackageChooserMode::Optional:
|
||||||
case PackageChooserMode::Exclusive:
|
case PackageChooserMode::Required:
|
||||||
ui->products->setSelectionMode( QAbstractItemView::SingleSelection );
|
ui->products->setSelectionMode( QAbstractItemView::SingleSelection );
|
||||||
case PackageChooserMode::Multiple:
|
case PackageChooserMode::OptionalMultiple:
|
||||||
case PackageChooserMode::RequiredMultiple:
|
case PackageChooserMode::RequiredMultiple:
|
||||||
ui->products->setSelectionMode( QAbstractItemView::ExtendedSelection );
|
ui->products->setSelectionMode( QAbstractItemView::ExtendedSelection );
|
||||||
}
|
}
|
||||||
@ -88,6 +87,26 @@ void
|
|||||||
PackageChooserPage::setModel( QAbstractItemModel* model )
|
PackageChooserPage::setModel( QAbstractItemModel* model )
|
||||||
{
|
{
|
||||||
ui->products->setModel( model );
|
ui->products->setModel( model );
|
||||||
|
|
||||||
|
// Check if any of the items in the model is the "none" option.
|
||||||
|
// If so, copy its values into the introduction / none item.
|
||||||
|
for ( int r = 0; r < model->rowCount(); ++r )
|
||||||
|
{
|
||||||
|
auto index = model->index( r, 0 );
|
||||||
|
if ( index.isValid() )
|
||||||
|
{
|
||||||
|
QVariant v = model->data( index, PackageListModel::IdRole );
|
||||||
|
if ( v.isValid() && v.toString().isEmpty() )
|
||||||
|
{
|
||||||
|
m_introduction.name = model->data( index, PackageListModel::NameRole ).toString();
|
||||||
|
m_introduction.description = model->data( index, PackageListModel::DescriptionRole ).toString();
|
||||||
|
m_introduction.screenshot = model->data( index, PackageListModel::ScreenshotRole ).value< QPixmap >();
|
||||||
|
currentChanged( QModelIndex() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
connect( ui->products->selectionModel(),
|
connect( ui->products->selectionModel(),
|
||||||
&QItemSelectionModel::selectionChanged,
|
&QItemSelectionModel::selectionChanged,
|
||||||
this,
|
this,
|
||||||
@ -99,3 +118,24 @@ PackageChooserPage::hasSelection() const
|
|||||||
{
|
{
|
||||||
return ui && ui->products && ui->products->selectionModel() && ui->products->selectionModel()->hasSelection();
|
return ui && ui->products && ui->products->selectionModel() && ui->products->selectionModel()->hasSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
PackageChooserPage::selectedPackageIds() const
|
||||||
|
{
|
||||||
|
if ( !( ui && ui->products && ui->products->selectionModel() ) )
|
||||||
|
{
|
||||||
|
return QStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto* model = ui->products->model();
|
||||||
|
QStringList ids;
|
||||||
|
for ( const auto& index : ui->products->selectionModel()->selectedIndexes() )
|
||||||
|
{
|
||||||
|
QString pid = model->data( index, PackageListModel::IdRole ).toString();
|
||||||
|
if ( !pid.isEmpty() )
|
||||||
|
{
|
||||||
|
ids.append( pid );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
@ -37,7 +37,13 @@ public:
|
|||||||
|
|
||||||
void setModel( QAbstractItemModel* model );
|
void setModel( QAbstractItemModel* model );
|
||||||
|
|
||||||
|
/// @brief Is anything selected?
|
||||||
bool hasSelection() const;
|
bool hasSelection() const;
|
||||||
|
/** @brief Get the list of selected ids
|
||||||
|
*
|
||||||
|
* This list may be empty (if none is selected).
|
||||||
|
*/
|
||||||
|
QStringList selectedPackageIds() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void currentChanged( const QModelIndex& index );
|
void currentChanged( const QModelIndex& index );
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
* Copyright 2019, Philip Müller <philm@manjaro.org>
|
* Copyright 2019, Philip MÜller <philm@manjaro.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -38,7 +38,7 @@ PackageChooserViewStep::PackageChooserViewStep( QObject* parent )
|
|||||||
: Calamares::ViewStep( parent )
|
: Calamares::ViewStep( parent )
|
||||||
, m_widget( nullptr )
|
, m_widget( nullptr )
|
||||||
, m_model( nullptr )
|
, m_model( nullptr )
|
||||||
, m_mode( PackageChooserMode::Exclusive )
|
, m_mode( PackageChooserMode::Required )
|
||||||
{
|
{
|
||||||
emit nextStatusChanged( false );
|
emit nextStatusChanged( false );
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ PackageChooserViewStep::widget()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cWarning() << "PackageChooser Widget created before model.";
|
cWarning() << "OfficeChooser Widget created before model.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m_widget;
|
return m_widget;
|
||||||
@ -101,10 +101,10 @@ PackageChooserViewStep::isNextEnabled() const
|
|||||||
switch ( m_mode )
|
switch ( m_mode )
|
||||||
{
|
{
|
||||||
case PackageChooserMode::Optional:
|
case PackageChooserMode::Optional:
|
||||||
case PackageChooserMode::Multiple:
|
case PackageChooserMode::OptionalMultiple:
|
||||||
// zero or one OR zero or more
|
// zero or one OR zero or more
|
||||||
return true;
|
return true;
|
||||||
case PackageChooserMode::Exclusive:
|
case PackageChooserMode::Required:
|
||||||
case PackageChooserMode::RequiredMultiple:
|
case PackageChooserMode::RequiredMultiple:
|
||||||
// exactly one OR one or more
|
// exactly one OR one or more
|
||||||
return m_widget->hasSelection();
|
return m_widget->hasSelection();
|
||||||
@ -138,6 +138,15 @@ PackageChooserViewStep::isAtEnd() const
|
|||||||
void
|
void
|
||||||
PackageChooserViewStep::onLeave()
|
PackageChooserViewStep::onLeave()
|
||||||
{
|
{
|
||||||
|
QString key = QStringLiteral( "packagechooser_%1" ).arg( m_id );
|
||||||
|
QString value;
|
||||||
|
if ( m_widget->hasSelection() )
|
||||||
|
{
|
||||||
|
value = m_widget->selectedPackageIds().join( ',' );
|
||||||
|
}
|
||||||
|
Calamares::JobQueue::instance()->globalStorage()->insert( key, value );
|
||||||
|
|
||||||
|
cDebug() << "OfficeChooser" << key << "selected" << value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Calamares::JobList
|
Calamares::JobList
|
||||||
@ -150,16 +159,50 @@ PackageChooserViewStep::jobs() const
|
|||||||
void
|
void
|
||||||
PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
// TODO: use the configurationMap
|
QString mode = CalamaresUtils::getString( configurationMap, "mode" );
|
||||||
|
bool ok = false;
|
||||||
|
if ( !mode.isEmpty() )
|
||||||
|
{
|
||||||
|
m_mode = roleNames().find( mode, ok );
|
||||||
|
}
|
||||||
|
if ( !ok )
|
||||||
|
{
|
||||||
|
m_mode = PackageChooserMode::Required;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_id = CalamaresUtils::getString( configurationMap, "id" );
|
||||||
|
if ( m_id.isEmpty() )
|
||||||
|
{
|
||||||
|
// Not set, so use the instance id
|
||||||
|
// TODO: use a stronger type than QString for structured IDs
|
||||||
|
m_id = moduleInstanceKey().split( '@' ).last();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: replace this hard-coded model
|
||||||
if ( !m_model )
|
if ( !m_model )
|
||||||
{
|
{
|
||||||
|
|
||||||
m_model = new PackageListModel( nullptr );
|
m_model = new PackageListModel( nullptr );
|
||||||
m_model->addPackage( PackageItem { "libreoffice-still", "libreoffice-still", "LibreOffice", "LibreOffice is a powerful and free office suite, used by millions of people around the world. ts clean interface and feature-rich tools help you unleash your creativity and enhance your productivity.", ":/images/LibreOffice.jpg" } );
|
m_model->addPackage( PackageItem { QString(),
|
||||||
m_model->addPackage(
|
QString(),
|
||||||
PackageItem { "freeoffice", "freeoffice", "FreeOffice", "FreeOffice 2018 is a full-featured Office suite with word processing, spreadsheet and presentation software. It is seamlessly compatible with Microsoft Office. (Note: You need to register the product for free longterm usage)", ":/images/FreeOffice.jpg" } );
|
"No Office Suite",
|
||||||
|
"Please pick a Office Suite from the list. "
|
||||||
|
"If you don't want to install a Office Suite, that's fine, "
|
||||||
|
"you can install one later as needed.",
|
||||||
|
":/images/choose-office.jpg" } );
|
||||||
|
m_model->addPackage( PackageItem { "libreoffice-still",
|
||||||
|
"libreoffice-still",
|
||||||
|
"LibreOffice",
|
||||||
|
"LibreOffice is a powerful and free office suite, used by millions of people around the world. "
|
||||||
|
"Its clean interface and feature-rich tools help you unleash your creativity and enhance your productivity.",
|
||||||
|
":/images/LibreOffice.jpg" } );
|
||||||
|
|
||||||
|
m_model->addPackage( PackageItem { "freeoffice",
|
||||||
|
"freeoffice",
|
||||||
|
"FreeOffice",
|
||||||
|
"FreeOffice 2018 is a full-featured Office suite with word processing, "
|
||||||
|
"spreadsheet and presentation software. It is seamlessly compatible with Microsoft Office. "
|
||||||
|
"(Note: You need to register the product for free longterm usage)",
|
||||||
|
":/images/FreeOffice.jpg" } );
|
||||||
|
|
||||||
if ( m_widget )
|
if ( m_widget )
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
|
||||||
class PackageChooserPage;
|
class PackageChooserPage;
|
||||||
class PackageListModel;
|
|
||||||
|
|
||||||
class PLUGINDLLEXPORT PackageChooserViewStep : public Calamares::ViewStep
|
class PLUGINDLLEXPORT PackageChooserViewStep : public Calamares::ViewStep
|
||||||
{
|
{
|
||||||
@ -61,7 +60,10 @@ private:
|
|||||||
|
|
||||||
PackageChooserPage* m_widget;
|
PackageChooserPage* m_widget;
|
||||||
PackageListModel* m_model;
|
PackageListModel* m_model;
|
||||||
|
|
||||||
|
// Configuration
|
||||||
PackageChooserMode m_mode;
|
PackageChooserMode m_mode;
|
||||||
|
QString m_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( PackageChooserViewStepFactory )
|
CALAMARES_PLUGIN_FACTORY_DECLARATION( PackageChooserViewStepFactory )
|
||||||
|
@ -20,6 +20,26 @@
|
|||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
const NamedEnumTable< PackageChooserMode >&
|
||||||
|
roleNames()
|
||||||
|
{
|
||||||
|
static const NamedEnumTable< PackageChooserMode > names {
|
||||||
|
{ "optional", PackageChooserMode::Optional },
|
||||||
|
{ "required", PackageChooserMode::Required },
|
||||||
|
{ "optionalmultiple", PackageChooserMode::OptionalMultiple },
|
||||||
|
{ "requiredmultiple", PackageChooserMode::RequiredMultiple },
|
||||||
|
// and a bunch of aliases
|
||||||
|
{ "zero-or-one", PackageChooserMode::Optional },
|
||||||
|
{ "radio", PackageChooserMode::Required },
|
||||||
|
{ "one", PackageChooserMode::Required },
|
||||||
|
{ "set", PackageChooserMode::OptionalMultiple },
|
||||||
|
{ "zero-or-more", PackageChooserMode::OptionalMultiple },
|
||||||
|
{ "multiple", PackageChooserMode::RequiredMultiple },
|
||||||
|
{ "one-or-more", PackageChooserMode::RequiredMultiple }
|
||||||
|
};
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
PackageItem
|
PackageItem
|
||||||
PackageItem::fromAppStream( const QString& filename )
|
PackageItem::fromAppStream( const QString& filename )
|
||||||
{
|
{
|
||||||
@ -108,6 +128,10 @@ PackageListModel::data( const QModelIndex& index, int role ) const
|
|||||||
{
|
{
|
||||||
return m_packages[ row ].screenshot;
|
return m_packages[ row ].screenshot;
|
||||||
}
|
}
|
||||||
|
else if ( role == IdRole )
|
||||||
|
{
|
||||||
|
return m_packages[ row ].id;
|
||||||
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#ifndef PACKAGEMODEL_H
|
#ifndef PACKAGEMODEL_H
|
||||||
#define PACKAGEMODEL_H
|
#define PACKAGEMODEL_H
|
||||||
|
|
||||||
|
#include "utils/NamedEnum.h"
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
@ -27,11 +29,13 @@
|
|||||||
enum class PackageChooserMode
|
enum class PackageChooserMode
|
||||||
{
|
{
|
||||||
Optional, // zero or one
|
Optional, // zero or one
|
||||||
Exclusive, // exactly one
|
Required, // exactly one
|
||||||
Multiple, // zero or more
|
OptionalMultiple, // zero or more
|
||||||
RequiredMultiple // one or more
|
RequiredMultiple // one or more
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const NamedEnumTable< PackageChooserMode >& roleNames();
|
||||||
|
|
||||||
struct PackageItem
|
struct PackageItem
|
||||||
{
|
{
|
||||||
QString id;
|
QString id;
|
||||||
@ -69,7 +73,7 @@ class PackageListModel : public QAbstractListModel
|
|||||||
public:
|
public:
|
||||||
PackageListModel( PackageList&& items, QObject* parent );
|
PackageListModel( PackageList&& items, QObject* parent );
|
||||||
PackageListModel( QObject* parent );
|
PackageListModel( QObject* parent );
|
||||||
virtual ~PackageListModel();
|
virtual ~PackageListModel() override;
|
||||||
|
|
||||||
void addPackage( PackageItem&& p );
|
void addPackage( PackageItem&& p );
|
||||||
|
|
||||||
@ -80,7 +84,8 @@ public:
|
|||||||
{
|
{
|
||||||
NameRole = Qt::DisplayRole,
|
NameRole = Qt::DisplayRole,
|
||||||
DescriptionRole = Qt::UserRole,
|
DescriptionRole = Qt::UserRole,
|
||||||
ScreenshotRole
|
ScreenshotRole,
|
||||||
|
IdRole
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -36,23 +36,12 @@
|
|||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,3,1">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,3,1">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="productName">
|
<widget class="QLabel" name="productName">
|
||||||
<property name="font">
|
|
||||||
<font>
|
|
||||||
<pointsize>14</pointsize>
|
|
||||||
</font>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>TextLabel</string>
|
<string>TextLabel</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::AutoText</enum>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -76,6 +65,9 @@
|
|||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="openExternalLinks">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
Reference in New Issue
Block a user