[plasmalnf] Enable translations

- Move tool-running to the view-step
 - Enable translations by showing name instead of theme-id
 - More verbose logging
This commit is contained in:
Adriaan de Groot 2017-12-04 06:40:13 -05:00
parent 71966b5330
commit eb92755b0a
3 changed files with 49 additions and 25 deletions

View File

@ -34,16 +34,19 @@
#include <QButtonGroup>
#include <QDesktopServices>
#include <QLabel>
#include <QProcess>
static QStringList plasma_themes()
static PlasmaLnfList plasma_themes()
{
QStringList packages;
PlasmaLnfList packages;
QList<KPluginMetaData> pkgs = KPackage::PackageLoader::self()->listPackages("Plasma/LookAndFeel");
for (const KPluginMetaData &data : pkgs) {
packages << data.pluginId();
packages << PlasmaLnfDescriptor{ data.pluginId(), data.name() };
cDebug() << "LNF Package" << data.pluginId();
cDebug() << " .." << data.name();
cDebug() << " .." << data.description();
cDebug() << " .." << 'V' << data.isValid() << 'H' << data.isHidden() << 'D' << data.isEnabledByDefault();
}
return packages;
@ -60,36 +63,28 @@ PlasmaLnfPage::PlasmaLnfPage(QWidget *parent)
CALAMARES_RETRANSLATE(
ui->retranslateUi( this );
ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop, below." ) );
m_availableLnf = plasma_themes();
ui->lnfCombo->clear();
for ( const auto& p : m_availableLnf )
ui->lnfCombo->addItem( p.name );
)
ui->lnfCombo->addItems( plasma_themes() );
QObject::connect<void(QComboBox::*)(const QString&)>(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated);
QObject::connect<void(QComboBox::*)(int)>(ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated);
}
void
PlasmaLnfPage::activated(const QString& name)
PlasmaLnfPage::activated( int index )
{
cDebug() << "Changed to" << name;
QProcess lnftool;
lnftool.start( m_lnfPath, {"--resetLayout", "--apply", name} );
if ( !lnftool.waitForStarted( 1000 ) )
if ( (index < 0) || (index > m_availableLnf.length()) )
{
cDebug() << "WARNING: could not start look-and-feel" << m_lnfPath;
return;
}
if ( !lnftool.waitForFinished() )
{
cDebug() << "WARNING:" << m_lnfPath << "timed out.";
cDebug() << "Plasma LNF index" << index << "out of range.";
return;
}
if ( (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) )
emit plasmaThemeSelected( name );
else
cDebug() << "WARNING: could not apply look-and-feel" << name;
const PlasmaLnfDescriptor& lnf = m_availableLnf.at( index );
cDebug() << "Changed to" << index << lnf.id << lnf.name;
emit plasmaThemeSelected( lnf.id );
}
void

View File

@ -27,6 +27,14 @@ namespace Ui
class PlasmaLnfPage;
}
struct PlasmaLnfDescriptor
{
QString id;
QString name;
} ;
using PlasmaLnfList = QList<PlasmaLnfDescriptor>;
class PlasmaLnfPage : public QWidget
{
Q_OBJECT
@ -36,7 +44,7 @@ public:
void setLnfPath( const QString& path );
public slots:
void activated(const QString& name);
void activated( int index );
signals:
void plasmaThemeSelected( const QString& id );
@ -44,6 +52,7 @@ signals:
private:
Ui::PlasmaLnfPage* ui;
QString m_lnfPath;
PlasmaLnfList m_availableLnf;
};
#endif //PLASMALNFPAGE_H

View File

@ -27,6 +27,7 @@
#include "PlasmaLnfViewStep.h"
#include <QDesktopServices>
#include <QProcess>
#include <QVariantMap>
CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin<PlasmaLnfViewStep>(); )
@ -137,4 +138,23 @@ void
PlasmaLnfViewStep::themeSelected( const QString& id )
{
m_themeId = id;
QProcess lnftool;
lnftool.start( m_lnfPath, {"--resetLayout", "--apply", id} );
if ( !lnftool.waitForStarted( 1000 ) )
{
cDebug() << "WARNING: could not start look-and-feel" << m_lnfPath;
return;
}
if ( !lnftool.waitForFinished() )
{
cDebug() << "WARNING:" << m_lnfPath << "timed out.";
return;
}
if ( (lnftool.exitCode() == 0) && (lnftool.exitStatus() == QProcess::NormalExit ) )
cDebug() << "Plasma look-and-feel applied" << id;
else
cDebug() << "WARNING: could not apply look-and-feel" << id;
}