[plasmalnf] Prepare a new model
- start a model for available themes, to replace the list held by the widget which just duplicates information. - move preselected theme to Config.
This commit is contained in:
parent
cba2733471
commit
a19109ed0b
@ -15,8 +15,99 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
|
#ifdef WITH_KCONFIG
|
||||||
|
#include <KConfigGroup>
|
||||||
|
#include <KSharedConfig>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <KPackage/Package>
|
||||||
|
#include <KPackage/PackageLoader>
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
class ThemesModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
LabelRole = Qt::DisplayRole,
|
||||||
|
KeyRole = Qt::UserRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit ThemesModel( QObject* parent );
|
||||||
|
|
||||||
|
int rowCount( const QModelIndex& = QModelIndex() ) const override;
|
||||||
|
QVariant data( const QModelIndex& index, int role ) const override;
|
||||||
|
|
||||||
|
QHash< int, QByteArray > roleNames() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList< KPluginMetaData > m_themes;
|
||||||
|
};
|
||||||
|
|
||||||
|
ThemesModel::ThemesModel( QObject* parent )
|
||||||
|
: QAbstractListModel( parent )
|
||||||
|
, m_themes( KPackage::PackageLoader::self()->listPackages( "Plasma/LookAndFeel" ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ThemesModel::rowCount( const QModelIndex& ) const
|
||||||
|
{
|
||||||
|
return m_themes.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
ThemesModel::data( const QModelIndex& index, int role ) const
|
||||||
|
{
|
||||||
|
if ( !index.isValid() )
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
if ( index.row() < 0 || index.row() >= m_themes.count() )
|
||||||
|
{
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& item = m_themes.at( index.row() );
|
||||||
|
switch ( role )
|
||||||
|
{
|
||||||
|
case LabelRole:
|
||||||
|
return item.name();
|
||||||
|
case KeyRole:
|
||||||
|
return item.pluginId();
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
__builtin_unreachable();
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash< int, QByteArray >
|
||||||
|
ThemesModel::roleNames() const
|
||||||
|
{
|
||||||
|
return { { LabelRole, "label" }, { KeyRole, "key" } };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static QString
|
||||||
|
currentPlasmaTheme()
|
||||||
|
{
|
||||||
|
#ifdef WITH_KCONFIG
|
||||||
|
KConfigGroup cg( KSharedConfig::openConfig( QStringLiteral( "kdeglobals" ) ), "KDE" );
|
||||||
|
return cg.readEntry( "LookAndFeelPackage", QString() );
|
||||||
|
#else
|
||||||
|
cWarning() << "No KConfig support, cannot determine Plasma theme.";
|
||||||
|
return QString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Config::Config( QObject* parent )
|
Config::Config( QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
|
, m_themeModel( new ThemesModel( this ) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +122,13 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_liveUser = CalamaresUtils::getString( configurationMap, "liveuser" );
|
m_liveUser = CalamaresUtils::getString( configurationMap, "liveuser" );
|
||||||
|
|
||||||
|
QString preselect = CalamaresUtils::getString( configurationMap, "preselect" );
|
||||||
|
if ( preselect == QStringLiteral( "*" ) )
|
||||||
|
{
|
||||||
|
preselect = currentPlasmaTheme();
|
||||||
|
}
|
||||||
|
m_preselectThemeId = preselect;
|
||||||
}
|
}
|
||||||
|
|
||||||
Calamares::JobList
|
Calamares::JobList
|
||||||
@ -92,3 +190,7 @@ Config::setTheme( const QString& id )
|
|||||||
}
|
}
|
||||||
emit themeChanged( id );
|
emit themeChanged( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "utils/moc-warnings.h"
|
||||||
|
|
||||||
|
#include "Config.moc"
|
||||||
|
@ -14,15 +14,19 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class QAbstractItemModel;
|
||||||
|
|
||||||
class Config : public QObject
|
class Config : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY( QString preselectedTheme READ preselectedTheme CONSTANT )
|
||||||
Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
|
Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
|
||||||
|
Q_PROPERTY( QAbstractItemModel* themeModel READ themeModel CONSTANT )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config( QObject* parent = nullptr );
|
Config( QObject* parent = nullptr );
|
||||||
virtual ~Config() override = default;
|
virtual ~Config() override = default; // QObject cleans up the model pointer
|
||||||
|
|
||||||
void setConfigurationMap( const QVariantMap& );
|
void setConfigurationMap( const QVariantMap& );
|
||||||
Calamares::JobList createJobs() const;
|
Calamares::JobList createJobs() const;
|
||||||
@ -42,6 +46,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
QString theme() const { return m_themeId; }
|
QString theme() const { return m_themeId; }
|
||||||
|
|
||||||
|
/** @brief The theme we start with
|
||||||
|
*
|
||||||
|
* This can be configured, or is taken from the live environment
|
||||||
|
* if the environment is (also) KDE Plasma.
|
||||||
|
*/
|
||||||
|
QString preselectedTheme() const { return m_preselectThemeId; }
|
||||||
|
|
||||||
|
/** @brief The (list) model of available themes.
|
||||||
|
*/
|
||||||
|
QAbstractItemModel* themeModel() const { return m_themeModel; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setTheme( const QString& id );
|
void setTheme( const QString& id );
|
||||||
|
|
||||||
@ -52,7 +67,10 @@ private:
|
|||||||
QString m_lnfPath; // Path to the lnf tool
|
QString m_lnfPath; // Path to the lnf tool
|
||||||
QString m_liveUser; // Name of the live user (for OEM mode)
|
QString m_liveUser; // Name of the live user (for OEM mode)
|
||||||
|
|
||||||
|
QString m_preselectThemeId;
|
||||||
QString m_themeId; // Id of selected theme
|
QString m_themeId; // Id of selected theme
|
||||||
|
|
||||||
|
QAbstractItemModel* m_themeModel = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,28 +15,10 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Variant.h"
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
|
||||||
#ifdef WITH_KCONFIG
|
|
||||||
#include <KConfigGroup>
|
|
||||||
#include <KSharedConfig>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin< PlasmaLnfViewStep >(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin< PlasmaLnfViewStep >(); )
|
||||||
|
|
||||||
static QString
|
|
||||||
currentPlasmaTheme()
|
|
||||||
{
|
|
||||||
#ifdef WITH_KCONFIG
|
|
||||||
KConfigGroup cg( KSharedConfig::openConfig( QStringLiteral( "kdeglobals" ) ), "KDE" );
|
|
||||||
return cg.readEntry( "LookAndFeelPackage", QString() );
|
|
||||||
#else
|
|
||||||
cWarning() << "No KConfig support, cannot determine Plasma theme.";
|
|
||||||
return QString();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent )
|
PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent )
|
||||||
: Calamares::ViewStep( parent )
|
: Calamares::ViewStep( parent )
|
||||||
, m_config( new Config( this ) )
|
, m_config( new Config( this ) )
|
||||||
@ -117,16 +99,7 @@ PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
m_config->setConfigurationMap( configurationMap );
|
m_config->setConfigurationMap( configurationMap );
|
||||||
|
|
||||||
m_widget->setLnfPath( m_config->lnfToolPath() );
|
m_widget->setLnfPath( m_config->lnfToolPath() );
|
||||||
|
m_widget->setPreselect( m_config->preselectedTheme() );
|
||||||
QString preselect = CalamaresUtils::getString( configurationMap, "preselect" );
|
|
||||||
if ( preselect == QStringLiteral( "*" ) )
|
|
||||||
{
|
|
||||||
preselect = currentPlasmaTheme();
|
|
||||||
}
|
|
||||||
if ( !preselect.isEmpty() )
|
|
||||||
{
|
|
||||||
m_widget->setPreselect( preselect );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool showAll = CalamaresUtils::getBool( configurationMap, "showAll", false );
|
bool showAll = CalamaresUtils::getBool( configurationMap, "showAll", false );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user