2021-04-13 13:39:47 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
|
|
|
*
|
|
|
|
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
2021-07-06 19:37:28 +02:00
|
|
|
* SPDX-FileCopyrightText: 2021 Anke Boersma <demm@kaosx.us>
|
2021-04-13 13:39:47 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PACKAGECHOOSER_CONFIG_H
|
|
|
|
#define PACKAGECHOOSER_CONFIG_H
|
|
|
|
|
|
|
|
#include "PackageModel.h"
|
|
|
|
|
|
|
|
#include "modulesystem/Config.h"
|
2021-04-16 14:53:13 +02:00
|
|
|
#include "modulesystem/InstanceKey.h"
|
2021-04-13 13:39:47 +02:00
|
|
|
|
|
|
|
#include <memory>
|
2021-09-03 17:29:21 +02:00
|
|
|
#include <optional>
|
2021-04-13 13:39:47 +02:00
|
|
|
|
2021-04-16 14:53:13 +02:00
|
|
|
enum class PackageChooserMode
|
|
|
|
{
|
|
|
|
Optional, // zero or one
|
|
|
|
Required, // exactly one
|
|
|
|
OptionalMultiple, // zero or more
|
|
|
|
RequiredMultiple // one or more
|
|
|
|
};
|
|
|
|
|
|
|
|
const NamedEnumTable< PackageChooserMode >& packageChooserModeNames();
|
|
|
|
|
|
|
|
enum class PackageChooserMethod
|
|
|
|
{
|
|
|
|
Legacy, // use contextualprocess or other custom
|
|
|
|
Packages, // use the packages module
|
|
|
|
};
|
|
|
|
|
|
|
|
const NamedEnumTable< PackageChooserMethod >& PackageChooserMethodNames();
|
|
|
|
|
2021-04-13 13:39:47 +02:00
|
|
|
class Config : public Calamares::ModuleSystem::Config
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2021-09-03 17:29:21 +02:00
|
|
|
/** @brief This is the single-select package-choice
|
|
|
|
*
|
|
|
|
* For (QML) modules that support only a single selection and
|
|
|
|
* just want to do things in a straightforward pick-this-one
|
|
|
|
* way, the packageChoice property is a (the) way to go.
|
|
|
|
*
|
|
|
|
* Writing to this property means that any other form of package-
|
|
|
|
* choice or selection is ignored.
|
|
|
|
*/
|
|
|
|
Q_PROPERTY( QString packageChoice READ packageChoice WRITE setPackageChoice NOTIFY packageChoiceChanged )
|
2021-07-06 19:37:28 +02:00
|
|
|
Q_PROPERTY( QString prettyStatus READ prettyStatus NOTIFY prettyStatusChanged FINAL )
|
|
|
|
|
2021-04-13 13:39:47 +02:00
|
|
|
public:
|
2021-04-23 22:04:15 +02:00
|
|
|
Config( QObject* parent = nullptr );
|
2021-04-13 13:39:47 +02:00
|
|
|
~Config() override;
|
|
|
|
|
2021-04-23 22:04:15 +02:00
|
|
|
/** @brief Sets the default Id for this Config
|
|
|
|
*
|
|
|
|
* The default Id is the (owning) module identifier for the config,
|
|
|
|
* and it is used when the Id read from the config file is empty.
|
|
|
|
* The **usual** configuration when using method *packages* is
|
|
|
|
* to rely on the default Id.
|
|
|
|
*/
|
|
|
|
void setDefaultId( const Calamares::ModuleSystem::InstanceKey& defaultId ) { m_defaultId = defaultId; }
|
2021-04-13 13:39:47 +02:00
|
|
|
void setConfigurationMap( const QVariantMap& ) override;
|
|
|
|
|
|
|
|
PackageChooserMode mode() const { return m_mode; }
|
|
|
|
PackageListModel* model() const { return m_model; }
|
|
|
|
QModelIndex defaultSelectionIndex() const { return m_defaultModelIndex; }
|
|
|
|
|
|
|
|
/** @brief Returns an "introductory package" which describes packagechooser
|
|
|
|
*
|
|
|
|
* If the model contains a "none" package, returns that one on
|
|
|
|
* the assumption that it is one to describe the whole; otherwise
|
|
|
|
* returns a totally generic description.
|
|
|
|
*/
|
|
|
|
const PackageItem& introductionPackage() const;
|
|
|
|
|
|
|
|
/** @brief Write selection to global storage
|
|
|
|
*
|
|
|
|
* Updates the GS keys for this packagechooser, marking all
|
|
|
|
* (and only) the packages in @p selected as selected.
|
|
|
|
*/
|
|
|
|
void updateGlobalStorage( const QStringList& selected ) const;
|
2021-09-03 22:41:13 +02:00
|
|
|
/** @brief Write selection to global storage
|
|
|
|
*
|
|
|
|
* Updates the GS keys for this packagechooser, marking **only**
|
|
|
|
* the package choice as selected. This assumes that the single-
|
|
|
|
* selection QML code is in use.
|
|
|
|
*/
|
|
|
|
void updateGlobalStorage() const;
|
2021-04-13 13:39:47 +02:00
|
|
|
|
2021-09-03 17:29:21 +02:00
|
|
|
QString packageChoice() const { return m_packageChoice.value_or( QString() ); }
|
|
|
|
void setPackageChoice( const QString& packageChoice );
|
2021-07-06 19:37:28 +02:00
|
|
|
|
|
|
|
QString prettyStatus() const;
|
|
|
|
|
|
|
|
signals:
|
2021-09-03 17:29:21 +02:00
|
|
|
void packageChoiceChanged( QString packageChoice );
|
2021-07-06 19:37:28 +02:00
|
|
|
void prettyStatusChanged();
|
|
|
|
|
2021-04-13 13:39:47 +02:00
|
|
|
private:
|
|
|
|
PackageListModel* m_model = nullptr;
|
|
|
|
QModelIndex m_defaultModelIndex;
|
|
|
|
|
2021-04-16 14:53:13 +02:00
|
|
|
/// Selection mode for this module
|
2021-04-13 13:39:47 +02:00
|
|
|
PackageChooserMode m_mode = PackageChooserMode::Optional;
|
2021-04-16 14:53:13 +02:00
|
|
|
/// How this module stores to GS
|
|
|
|
PackageChooserMethod m_method = PackageChooserMethod::Legacy;
|
|
|
|
/// Value to use for id if none is set in the config file
|
|
|
|
Calamares::ModuleSystem::InstanceKey m_defaultId;
|
2021-09-03 17:29:21 +02:00
|
|
|
/** @brief QML selection (for single-selection approaches)
|
|
|
|
*
|
|
|
|
* If there is no value, then there has been no selection.
|
|
|
|
* Reading the property will return an empty QString.
|
|
|
|
*/
|
|
|
|
std::optional< QString > m_packageChoice;
|
2021-04-13 13:39:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|