source: calamares/trunk/fuentes/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 5.4 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include "PlasmaLnfViewStep.h"
19
20#include "PlasmaLnfJob.h"
21#include "PlasmaLnfPage.h"
22#include "ThemeInfo.h"
23
24#include "utils/CalamaresUtils.h"
25#include "utils/Logger.h"
26
27#include <QProcess>
28#include <QVariantMap>
29
30#ifdef WITH_KCONFIG
31#include <KConfigGroup>
32#include <KSharedConfig>
33#endif
34
35CALAMARES_PLUGIN_FACTORY_DEFINITION( PlasmaLnfViewStepFactory, registerPlugin<PlasmaLnfViewStep>(); )
36
37static QString
38currentPlasmaTheme()
39{
40#ifdef WITH_KCONFIG
41    KConfigGroup cg( KSharedConfig::openConfig( QStringLiteral( "kdeglobals" ) ), "KDE" );
42    return cg.readEntry( "LookAndFeelPackage", QString() );
43#else
44    cWarning() << "No KConfig support, cannot determine Plasma theme.";
45    return QString();
46#endif
47}
48
49PlasmaLnfViewStep::PlasmaLnfViewStep( QObject* parent )
50    : Calamares::ViewStep( parent )
51    , m_widget( new PlasmaLnfPage )
52{
53    connect( m_widget, &PlasmaLnfPage::plasmaThemeSelected, this, &PlasmaLnfViewStep::themeSelected );
54    emit nextStatusChanged( false );
55}
56
57
58PlasmaLnfViewStep::~PlasmaLnfViewStep()
59{
60    if ( m_widget && m_widget->parent() == nullptr )
61        m_widget->deleteLater();
62}
63
64
65QString
66PlasmaLnfViewStep::prettyName() const
67{
68    return tr( "Look-and-Feel" );
69}
70
71
72QWidget*
73PlasmaLnfViewStep::widget()
74{
75    return m_widget;
76}
77
78
79void
80PlasmaLnfViewStep::next()
81{
82    emit done();
83}
84
85
86void
87PlasmaLnfViewStep::back()
88{}
89
90
91bool
92PlasmaLnfViewStep::isNextEnabled() const
93{
94    return true;
95}
96
97
98bool
99PlasmaLnfViewStep::isBackEnabled() const
100{
101    return true;
102}
103
104
105bool
106PlasmaLnfViewStep::isAtBeginning() const
107{
108    return true;
109}
110
111
112bool
113PlasmaLnfViewStep::isAtEnd() const
114{
115    return true;
116}
117
118
119void PlasmaLnfViewStep::onLeave()
120{
121}
122
123
124Calamares::JobList
125PlasmaLnfViewStep::jobs() const
126{
127    Calamares::JobList l;
128
129    cDebug() << "Creating Plasma LNF jobs ..";
130    if ( !m_themeId.isEmpty() )
131    {
132        if ( !m_lnfPath.isEmpty() )
133            l.append( Calamares::job_ptr( new PlasmaLnfJob( m_lnfPath, m_themeId ) ) );
134        else
135            cWarning() << "no lnftool given for plasmalnf module.";
136    }
137    return l;
138}
139
140
141void
142PlasmaLnfViewStep::setConfigurationMap( const QVariantMap& configurationMap )
143{
144    m_lnfPath = CalamaresUtils::getString( configurationMap, "lnftool" );
145    m_widget->setLnfPath( m_lnfPath );
146
147    if ( m_lnfPath.isEmpty() )
148        cWarning() << "no lnftool given for plasmalnf module.";
149
150    m_liveUser = CalamaresUtils::getString( configurationMap, "liveuser" );
151
152    QString preselect = CalamaresUtils::getString( configurationMap, "preselect" );
153    if ( preselect == QStringLiteral( "*" ) )
154        preselect = currentPlasmaTheme();
155    if ( !preselect.isEmpty() )
156        m_widget->setPreselect( preselect );
157
158    bool showAll = CalamaresUtils::getBool( configurationMap, "showAll", false );
159
160    if ( configurationMap.contains( "themes" ) &&
161        configurationMap.value( "themes" ).type() == QVariant::List )
162    {
163        ThemeInfoList listedThemes;
164        auto themeList = configurationMap.value( "themes" ).toList();
165        // Create the ThemInfo objects for the listed themes; information
166        // about the themes from Plasma (e.g. human-readable name and description)
167        // are filled in by update_names() in PlasmaLnfPage.
168        for ( const auto& i : themeList )
169            if ( i.type() == QVariant::Map )
170            {
171                auto iv = i.toMap();
172                listedThemes.append( ThemeInfo( iv.value( "theme" ).toString(), iv.value( "image" ).toString() ) );
173            }
174            else if ( i.type() == QVariant::String )
175                listedThemes.append( ThemeInfo( i.toString() ) );
176
177        if ( listedThemes.length() == 1 )
178            cWarning() << "only one theme enabled in plasmalnf";
179        m_widget->setEnabledThemes( listedThemes, showAll );
180    }
181    else
182        m_widget->setEnabledThemesAll();  // All of them
183}
184
185void
186PlasmaLnfViewStep::themeSelected( const QString& id )
187{
188    m_themeId = id;
189    if ( m_lnfPath.isEmpty() )
190    {
191        cWarning() << "no lnftool given for plasmalnf module.";
192        return;
193    }
194
195    QProcess lnftool;
196    if ( !m_liveUser.isEmpty() )
197        lnftool.start( "sudo", {"-E", "-H", "-u", m_liveUser, m_lnfPath, "--resetLayout", "--apply", id} );
198    else
199        lnftool.start( m_lnfPath, {"--resetLayout", "--apply", id} );
200
201    if ( !lnftool.waitForStarted( 1000 ) )
202    {
203        cWarning() << "could not start look-and-feel" << m_lnfPath;
204        return;
205    }
206    if ( !lnftool.waitForFinished() )
207    {
208        cWarning() << m_lnfPath << "timed out.";
209        return;
210    }
211
212    if ( ( lnftool.exitCode() == 0 ) && ( lnftool.exitStatus() == QProcess::NormalExit ) )
213        cDebug() << "Plasma look-and-feel applied" << id;
214    else
215        cWarning() << "could not apply look-and-feel" << id;
216}
Note: See TracBrowser for help on using the repository browser.