[plasmalnf] Import Plasma Look-and-Feel module independently

This commit is contained in:
Adriaan de Groot 2017-12-03 12:47:41 -05:00
parent 1f49f764a6
commit cddc4699aa
12 changed files with 721 additions and 0 deletions

View File

@ -0,0 +1,21 @@
find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE)
find_package( KF5 5.29 REQUIRED CoreAddons Plasma Service Package )
calamares_add_plugin( plasmalnf
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
PlasmaLnfViewStep.cpp
PlasmaLnfPage.cpp
PlasmaLnfJob.cpp
PlasmaLnfInfo.cpp
UI
page_plasmalnf.ui
LINK_PRIVATE_LIBRARIES
calamaresui
KF5::Package
KF5::Plasma
KF5::Service
SHARED_LIB
)

View File

@ -0,0 +1,140 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PlasmaLnfInfo.h"
#include <QDateTime>
#include <QDir>
#include <QProcess>
#include <QStandardPaths>
#include <QThread>
#include <KService>
#include <KServiceTypeTrader>
#include <KPluginLoader> // Future
#include <Plasma/PluginLoader> // TODO: port to KPluginLoader
#include <KPackage/Package>
#include <KPackage/PackageLoader>
#include "utils/Logger.h"
namespace Calamares
{
QStringList themes_by_package()
{
QStringList packages;
QList<KPluginMetaData> pkgs = KPackage::PackageLoader::self()->listPackages("Plasma/LookAndFeel");
for (const KPluginMetaData &data : pkgs) {
packages << data.pluginId();
}
return packages;
}
QStringList themes_by_service()
{
KService::List services;
KServiceTypeTrader* trader = KServiceTypeTrader::self();
cDebug() << "Plasma themes by service:";
QStringList packages;
services = trader->query("Plasma/Theme");
int c = 0;
for ( const auto s : services )
{
cDebug() << " .. Plasma theme" << s->name();
packages << s->name();
c++;
}
return packages;
}
QStringList themes_by_kcm()
{
QString component;
QList<Plasma::Package> packages;
QStringList paths;
QStringList packageNames;
const QStringList dataPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
for (const QString &path : dataPaths) {
QDir dir(path + "/plasma/look-and-feel");
paths << dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
}
cDebug() << "Plasma themes by kcm:";
for (const QString &path : paths) {
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
pkg.setPath(path);
pkg.setFallbackPackage(Plasma::Package());
if (component.isEmpty() || !pkg.filePath(component.toUtf8()).isEmpty()) {
packages << pkg;
packageNames << pkg.metadata().pluginName();
cDebug() << " .. Plasma theme" << pkg.metadata().pluginName();
}
}
return packageNames;
}
QStringList themes_by_lnftool()
{
QStringList packages;
QProcess lnftool;
lnftool.start( Calamares::lnftool(), {"--list"} );
if ( lnftool.waitForStarted(1000) && lnftool.waitForFinished( 1000 ) && (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) )
{
packages = QString::fromLocal8Bit( lnftool.readAllStandardOutput() ).trimmed().split('\n');
}
return packages;
}
QStringList plasma_themes()
{
QStringList l( themes_by_package() );
if (l.isEmpty())
return themes_by_lnftool();
return l;
}
static QString *p_lnfPath = nullptr;
QString lnftool()
{
if ( !p_lnfPath )
p_lnfPath = new QString("/usr/bin/lookandfeeltool");
return *p_lnfPath;
}
void set_lnftool( const QString& lnfPath )
{
if (p_lnfPath)
delete p_lnfPath;
p_lnfPath = new QString( lnfPath );
}
} // namespace Calamares

View File

@ -0,0 +1,39 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMALNFINFO_H
#define PLASMALNFINFO_H
#include <QString>
#include <QStringList>
namespace Calamares
{
QString lnftool();
void set_lnftool( const QString& );
/* Internal */
QStringList themes_by_package();
QStringList themes_by_service();
QStringList themes_by_kcm();
QStringList themes_by_lnftool();
QStringList plasma_themes();
}
#endif // PLASMALNFINFO_H

View File

@ -0,0 +1,93 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PlasmaLnfJob.h"
#include <QDateTime>
#include <QDir>
#include <QProcess>
#include <QStandardPaths>
#include <QThread>
#include <KService>
#include <KServiceTypeTrader>
#include <KPluginLoader> // Future
#include <Plasma/PluginLoader> // TODO: port to KPluginLoader
#include "CalamaresVersion.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h"
PlasmaLnfJob::PlasmaLnfJob( const QString& lnfPath, const QString& id )
: m_lnfPath( lnfPath )
, m_id(id)
{
}
PlasmaLnfJob::~PlasmaLnfJob()
{
}
QString
PlasmaLnfJob::prettyName() const
{
return tr( "Plasma Look-and-Feel Job" );
}
QString
PlasmaLnfJob::prettyDescription() const
{
return prettyName();
}
QString PlasmaLnfJob::prettyStatusMessage() const
{
return prettyName();
}
Calamares::JobResult
PlasmaLnfJob::exec()
{
cDebug() << "Plasma Look-and-Feel Job";
auto system = CalamaresUtils::System::instance();
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
QStringList command;
if ( !system->doChroot() )
command << "sudo" << "-E" << "-H" << "-u" << gs->value("username").toString();
command << m_lnfPath << "-platform" << "minimal" << "--resetLayout" << "--apply" << m_id;
int r = system->targetEnvCall( command );
if (r)
return Calamares::JobResult::error(
tr( "Could not select KDE Plasma Look-and-Feel package" ),
tr( "Could not select KDE Plasma Look-and-Feel package" ) );
return Calamares::JobResult::ok();
}

View File

@ -0,0 +1,46 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMALNFJOB_H
#define PLASMALNFJOB_H
#include <QObject>
#include <QVariantMap>
#include <Job.h>
class PlasmaLnfJob : public Calamares::Job
{
Q_OBJECT
public:
explicit PlasmaLnfJob( const QString& lnfPath, const QString& id );
virtual ~PlasmaLnfJob() override;
QString prettyName() const override;
QString prettyDescription() const override;
QString prettyStatusMessage() const override;
Calamares::JobResult exec() override;
private:
QString m_lnfPath;
QString m_id;
};
#endif // PLASMALNFJOB_H

View File

@ -0,0 +1,70 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PlasmaLnfPage.h"
#include "PlasmaLnfInfo.h"
#include "ui_page_plasmalnf.h"
#include "Branding.h"
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "utils/Logger.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Retranslator.h"
#include "ViewManager.h"
#include <QButtonGroup>
#include <QDesktopServices>
#include <QLabel>
#include <QProcess>
PlasmaLnfPage::PlasmaLnfPage(QWidget *parent)
: QWidget( parent )
, ui( new Ui::PlasmaLnfPage )
{
using StringEntry = Calamares::Branding::StringEntry;
ui->setupUi( this );
CALAMARES_RETRANSLATE(
ui->retranslateUi( this );
ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) );
)
Calamares::themes_by_package();
ui->lnfCombo->addItems( Calamares::plasma_themes() );
QObject::connect<void(QComboBox::*)(const QString&)>(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated);
}
void
PlasmaLnfPage::activated(const QString& name)
{
cDebug() << "Changed to" << name;
QProcess lnftool;
lnftool.start( Calamares::lnftool(), {"--resetLayout", "--apply", name} );
if ( lnftool.waitForStarted(1000) && lnftool.waitForFinished( 1000 ) && (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) )
; // OK
else
cDebug() << "WARNING: could not apply look-and-feel" << name;
emit plasmaThemeSelected( name );
}

View File

@ -0,0 +1,46 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMALNFPAGE_H
#define PLASMALNFPAGE_H
#include <QWidget>
#include <QUrl>
namespace Ui
{
class PlasmaLnfPage;
}
class PlasmaLnfPage : public QWidget
{
Q_OBJECT
public:
explicit PlasmaLnfPage( QWidget* parent = nullptr );
public slots:
void activated(const QString& name);
signals:
void plasmaThemeSelected( const QString &id );
private:
Ui::PlasmaLnfPage* ui;
};
#endif //PLASMALNFPAGE_H

View File

@ -0,0 +1,138 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, Adriaan de Groot <groot@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "JobQueue.h"
#include "GlobalStorage.h"
#include "utils/Logger.h"
#include "utils/CalamaresUtils.h"
#include "utils/CalamaresUtilsSystem.h"
#include "PlasmaLnfInfo.h"
#include "PlasmaLnfJob.h"
#include "PlasmaLnfPage.h"
#include "PlasmaLnfViewStep.h"
#include <QDesktopServices>
#include <QVariantMap>
CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin<PlasmaLnfViewStep>(); )
PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new PlasmaLnfPage )
{
connect( m_widget, &PlasmaLnfPage::plasmaThemeSelected, this, &PlasmaLnfViewStep::themeSelected );
emit nextStatusChanged( false );
}
PlasmaLnfViewStep::~PlasmaLnfViewStep()
{
if ( m_widget && m_widget->parent() == nullptr )
m_widget->deleteLater();
}
QString
PlasmaLnfViewStep::prettyName() const
{
return tr( "Look-and-Feel" );
}
QWidget*
PlasmaLnfViewStep::widget()
{
return m_widget;
}
void
PlasmaLnfViewStep::next()
{
emit done();
}
void
PlasmaLnfViewStep::back()
{}
bool
PlasmaLnfViewStep::isNextEnabled() const
{
return true;
}
bool
PlasmaLnfViewStep::isBackEnabled() const
{
return true;
}
bool
PlasmaLnfViewStep::isAtBeginning() const
{
return true;
}
bool
PlasmaLnfViewStep::isAtEnd() const
{
return true;
}
void PlasmaLnfViewStep::onLeave()
{
}
Calamares::JobList
PlasmaLnfViewStep::jobs() const
{
Calamares::JobList l;
cDebug() << "Creating Plasma LNF jobs ..";
if ( !m_themeId.isEmpty() && !m_lnfPath.isEmpty() )
{
l.append( Calamares::job_ptr( new PlasmaLnfJob( m_lnfPath, m_themeId ) ) );
}
return l;
}
void
PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
m_lnfPath = CalamaresUtils::getString( configurationMap, "lnftool" );
Calamares::set_lnftool( m_lnfPath );
if (m_lnfPath.isEmpty())
cDebug() << "WARNING: no lnftool given for plasmalnf module.";
}
void
PlasmaLnfViewStep::themeSelected( const QString& id )
{
m_themeId = id;
}

View File

@ -0,0 +1,70 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2017, Adriaan de Groot <groot@kde..org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calamares is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMALNFVIEWSTEP_H
#define PLASMALNFVIEWSTEP_H
#include <utils/PluginFactory.h>
#include <viewpages/ViewStep.h>
#include <PluginDllMacro.h>
#include <QObject>
#include <QUrl>
#include <QVariantMap>
class PlasmaLnfPage;
class PLUGINDLLEXPORT PlasmaLnfViewStep : public Calamares::ViewStep
{
Q_OBJECT
public:
explicit PlasmaLnfViewStep( QObject* parent = nullptr );
virtual ~PlasmaLnfViewStep() override;
QString prettyName() const override;
QWidget* widget() override;
void next() override;
void back() override;
bool isNextEnabled() const override;
bool isBackEnabled() const override;
bool isAtBeginning() const override;
bool isAtEnd() const override;
void onLeave() override;
Calamares::JobList jobs() const override;
void setConfigurationMap( const QVariantMap& configurationMap ) override;
public slots:
void themeSelected( const QString &id );
private:
PlasmaLnfPage* m_widget;
QString m_lnfPath;
QString m_themeId;
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( PlasmaLnfViewStepFactory )
#endif // PLASMALNFVIEWSTEP_H

View File

@ -0,0 +1 @@
<RCC/>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PlasmaLnfPage</class>
<widget class="QWidget" name="PlasmaLnfPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>799</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
<item>
<widget class="QLabel" name="generalExplanation">
<property name="styleSheet">
<string notr="true">margin-bottom: 1ex;
margin-left: 2em;</string>
</property>
<property name="text">
<string>Placeholder</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="lnfCombo"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="page_plasmalnf.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -0,0 +1,4 @@
---
# Full path to the Plasma look-and-feel tool (CLI program
# for querying and applying Plasma themes).
lnftool: "/usr/bin/lookandfeeltool"