[plasmalnf] Move model to ThemeInfo files
This commit is contained in:
parent
27f1e82a8f
commit
57907ca992
@ -36,6 +36,7 @@ if ( KF5Plasma_FOUND AND KF5Package_FOUND )
|
|||||||
PlasmaLnfViewStep.cpp
|
PlasmaLnfViewStep.cpp
|
||||||
PlasmaLnfPage.cpp
|
PlasmaLnfPage.cpp
|
||||||
PlasmaLnfJob.cpp
|
PlasmaLnfJob.cpp
|
||||||
|
ThemeInfo.cpp
|
||||||
ThemeWidget.cpp
|
ThemeWidget.cpp
|
||||||
RESOURCES
|
RESOURCES
|
||||||
page_plasmalnf.qrc
|
page_plasmalnf.qrc
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "PlasmaLnfJob.h"
|
#include "PlasmaLnfJob.h"
|
||||||
|
#include "ThemeInfo.h"
|
||||||
|
|
||||||
#include "utils/CalamaresUtilsSystem.h"
|
#include "utils/CalamaresUtilsSystem.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
@ -20,78 +21,6 @@
|
|||||||
#include <KSharedConfig>
|
#include <KSharedConfig>
|
||||||
#endif
|
#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
|
static QString
|
||||||
currentPlasmaTheme()
|
currentPlasmaTheme()
|
||||||
{
|
{
|
||||||
@ -190,7 +119,3 @@ Config::setTheme( const QString& id )
|
|||||||
}
|
}
|
||||||
emit themeChanged( id );
|
emit themeChanged( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "utils/moc-warnings.h"
|
|
||||||
|
|
||||||
#include "Config.moc"
|
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
|
|
||||||
#include "Job.h"
|
#include "Job.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include "ThemeInfo.h"
|
||||||
|
|
||||||
class QAbstractItemModel;
|
#include <QObject>
|
||||||
|
|
||||||
class Config : public QObject
|
class Config : public QObject
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ private:
|
|||||||
QString m_preselectThemeId;
|
QString m_preselectThemeId;
|
||||||
QString m_themeId; // Id of selected theme
|
QString m_themeId; // Id of selected theme
|
||||||
|
|
||||||
QAbstractItemModel* m_themeModel = nullptr;
|
ThemesModel* m_themeModel = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -21,14 +21,6 @@
|
|||||||
#include <KPackage/Package>
|
#include <KPackage/Package>
|
||||||
#include <KPackage/PackageLoader>
|
#include <KPackage/PackageLoader>
|
||||||
|
|
||||||
ThemeInfo::ThemeInfo( const KPluginMetaData& data )
|
|
||||||
: id( data.pluginId() )
|
|
||||||
, name( data.name() )
|
|
||||||
, description( data.description() )
|
|
||||||
, widget( nullptr )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static ThemeInfoList
|
static ThemeInfoList
|
||||||
plasma_themes()
|
plasma_themes()
|
||||||
{
|
{
|
||||||
|
69
src/modules/plasmalnf/ThemeInfo.cpp
Normal file
69
src/modules/plasmalnf/ThemeInfo.cpp
Normal file
@ -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
|
#ifndef PLASMALNF_THEMEINFO_H
|
||||||
#define PLASMALNF_THEMEINFO_H
|
#define PLASMALNF_THEMEINFO_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
@ -49,7 +50,6 @@ struct ThemeInfo
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defined in PlasmaLnfPage.cpp
|
|
||||||
explicit ThemeInfo( const KPluginMetaData& );
|
explicit ThemeInfo( const KPluginMetaData& );
|
||||||
|
|
||||||
bool isValid() const { return !id.isEmpty(); }
|
bool isValid() const { return !id.isEmpty(); }
|
||||||
@ -88,4 +88,29 @@ public:
|
|||||||
bool contains( const QString& id ) const { return findById( id ) != nullptr; }
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user