source: calamares/trunk/fuentes/src/libcalamaresui/modulesystem/ViewModule.cpp @ 7538

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

sync with github

File size: 3.4 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "ViewModule.h"
21
22#include "utils/PluginFactory.h"
23#include "utils/Logger.h"
24#include "viewpages/ViewStep.h"
25#include "ViewManager.h"
26
27#include <QDir>
28#include <QPluginLoader>
29
30namespace Calamares {
31
32
33Module::Type
34ViewModule::type() const
35{
36    return View;
37}
38
39
40Module::Interface
41ViewModule::interface() const
42{
43    return QtPluginInterface;
44}
45
46
47void
48ViewModule::loadSelf()
49{
50    if ( m_loader )
51    {
52        PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() );
53        if ( !pf )
54        {
55            cWarning() << Q_FUNC_INFO << "No factory:" << m_loader->errorString();
56            return;
57        }
58
59        m_viewStep = pf->create< Calamares::ViewStep >();
60        if ( !m_viewStep )
61        {
62            cWarning() << Q_FUNC_INFO << "create() failed" << m_loader->errorString();
63            return;
64        }
65    }
66
67    // TODO: allow internal view steps to be created here; they would
68    //       have to be linked into the main application somehow.
69
70    // If any method created the view step, use it now.
71    if ( m_viewStep )
72    {
73        m_viewStep->setModuleInstanceKey( instanceKey() );
74        m_viewStep->setConfigurationMap( m_configurationMap );
75        ViewManager::instance()->addViewStep( m_viewStep );
76        m_loaded = true;
77        cDebug() << "ViewModule" << instanceKey() << "loading complete.";
78    }
79    else
80        cWarning() << Q_FUNC_INFO << "No view step was created";
81}
82
83
84JobList
85ViewModule::jobs() const
86{
87    return m_viewStep->jobs();
88}
89
90
91void
92ViewModule::initFrom( const QVariantMap& moduleDescriptor )
93{
94    Module::initFrom( moduleDescriptor );
95    QDir directory( location() );
96    QString load;
97    if ( !moduleDescriptor.value( "load" ).toString().isEmpty() )
98    {
99        load = moduleDescriptor.value( "load" ).toString();
100        load = directory.absoluteFilePath( load );
101    }
102    // If a load path is not specified, we look for a plugin to load in the directory.
103    if ( load.isEmpty() || !QLibrary::isLibrary( load ) )
104    {
105        const QStringList ls = directory.entryList( QStringList{ "*.so" } );
106        if ( !ls.isEmpty() )
107        {
108            for ( QString entry : ls )
109            {
110                entry = directory.absoluteFilePath( entry );
111                if ( QLibrary::isLibrary( entry ) )
112                {
113                    load = entry;
114                    break;
115                }
116            }
117        }
118    }
119
120    m_loader = new QPluginLoader( load );
121}
122
123ViewModule::ViewModule()
124    : Module()
125    , m_loader( nullptr )
126{
127}
128
129ViewModule::~ViewModule()
130{
131    delete m_loader;
132}
133
134} // namespace Calamares
Note: See TracBrowser for help on using the repository browser.