[plasmalnf] Move model to ThemeInfo files

main
Adriaan de Groot 4 years ago
parent 27f1e82a8f
commit 57907ca992

@ -36,6 +36,7 @@ if ( KF5Plasma_FOUND AND KF5Package_FOUND )
PlasmaLnfViewStep.cpp
PlasmaLnfPage.cpp
PlasmaLnfJob.cpp
ThemeInfo.cpp
ThemeWidget.cpp
RESOURCES
page_plasmalnf.qrc

@ -10,6 +10,7 @@
#include "Config.h"
#include "PlasmaLnfJob.h"
#include "ThemeInfo.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h"
@ -20,78 +21,6 @@
#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()
{
@ -190,7 +119,3 @@ Config::setTheme( const QString& id )
}
emit themeChanged( id );
}
#include "utils/moc-warnings.h"
#include "Config.moc"

@ -12,9 +12,9 @@
#include "Job.h"
#include <QObject>
#include "ThemeInfo.h"
class QAbstractItemModel;
#include <QObject>
class Config : public QObject
{
@ -70,7 +70,7 @@ private:
QString m_preselectThemeId;
QString m_themeId; // Id of selected theme
QAbstractItemModel* m_themeModel = nullptr;
ThemesModel* m_themeModel = nullptr;
};
#endif

@ -21,14 +21,6 @@
#include <KPackage/Package>
#include <KPackage/PackageLoader>
ThemeInfo::ThemeInfo( const KPluginMetaData& data )
: id( data.pluginId() )
, name( data.name() )
, description( data.description() )
, widget( nullptr )
{
}
static ThemeInfoList
plasma_themes()
{

@ -0,0 +1,69 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2020 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#include "ThemeInfo.h"
#include <KPackage/Package>
#include <KPackage/PackageLoader>
ThemesModel::ThemesModel( QObject* parent )
: QAbstractListModel( parent )
{
auto packages = KPackage::PackageLoader::self()->listPackages( "Plasma/LookAndFeel" );
m_themes.reserve( packages.length() );
for ( const auto& p : packages )
{
m_themes.append( ThemeInfo { p } );
}
}
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.id;
default:
return QVariant();
}
__builtin_unreachable();
}
QHash< int, QByteArray >
ThemesModel::roleNames() const
{
return { { LabelRole, "label" }, { KeyRole, "key" } };
}
ThemeInfo::ThemeInfo( const KPluginMetaData& data )
: id( data.pluginId() )
, name( data.name() )
, description( data.description() )
, widget( nullptr )
{
}

@ -10,6 +10,7 @@
#ifndef PLASMALNF_THEMEINFO_H
#define PLASMALNF_THEMEINFO_H
#include <QAbstractListModel>
#include <QList>
#include <QString>
@ -49,7 +50,6 @@ struct ThemeInfo
{
}
// Defined in PlasmaLnfPage.cpp
explicit ThemeInfo( const KPluginMetaData& );
bool isValid() const { return !id.isEmpty(); }
@ -88,4 +88,29 @@ public:
bool contains( const QString& id ) const { return findById( id ) != nullptr; }
};
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;
const ThemeInfo* findById( const QString& id ) const { return m_themes.findById( id ); }
private:
ThemeInfoList m_themes;
};
#endif

Loading…
Cancel
Save