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

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

sync with github

File size: 3.3 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2016, Kevin Kofler <kevin.kofler@chello.at>
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 "CppJobModule.h"
21
22#include "utils/PluginFactory.h"
23#include "utils/Logger.h"
24#include "CppJob.h"
25
26#include <QDir>
27#include <QPluginLoader>
28
29namespace Calamares {
30
31
32Module::Type
33CppJobModule::type() const
34{
35    return Job;
36}
37
38
39Module::Interface
40CppJobModule::interface() const
41{
42    return QtPluginInterface;
43}
44
45
46void
47CppJobModule::loadSelf()
48{
49    if ( m_loader )
50    {
51        PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() );
52        if ( !pf )
53        {
54            cDebug() << Q_FUNC_INFO << m_loader->errorString();
55            return;
56        }
57
58        CppJob *cppJob = pf->create< Calamares::CppJob >();
59        if ( !cppJob )
60        {
61            cDebug() << Q_FUNC_INFO << m_loader->errorString();
62            return;
63        }
64//        cDebug() << "CppJobModule loading self for instance" << instanceKey()
65//                 << "\nCppJobModule at address" << this
66//                 << "\nCalamares::PluginFactory at address" << pf
67//                 << "\nCppJob at address" << cppJob;
68
69        cppJob->setModuleInstanceKey( instanceKey() );
70        cppJob->setConfigurationMap( m_configurationMap );
71        m_job = Calamares::job_ptr( static_cast< Calamares::Job * >( cppJob ) );
72        m_loaded = true;
73        cDebug() << "CppJobModule" << instanceKey() << "loading complete.";
74    }
75}
76
77
78JobList
79CppJobModule::jobs() const
80{
81    return JobList() << m_job;
82}
83
84
85void
86CppJobModule::initFrom( const QVariantMap& moduleDescriptor )
87{
88    Module::initFrom( moduleDescriptor );
89    QDir directory( location() );
90    QString load;
91    if ( !moduleDescriptor.value( "load" ).toString().isEmpty() )
92    {
93        load = moduleDescriptor.value( "load" ).toString();
94        load = directory.absoluteFilePath( load );
95    }
96    // If a load path is not specified, we look for a plugin to load in the directory.
97    if ( load.isEmpty() || !QLibrary::isLibrary( load ) )
98    {
99        const QStringList ls = directory.entryList( QStringList{ "*.so" } );
100        if ( !ls.isEmpty() )
101        {
102            for ( QString entry : ls )
103            {
104                entry = directory.absoluteFilePath( entry );
105                if ( QLibrary::isLibrary( entry ) )
106                {
107                    load = entry;
108                    break;
109                }
110            }
111        }
112    }
113
114    m_loader = new QPluginLoader( load );
115}
116
117CppJobModule::CppJobModule()
118    : Module()
119    , m_loader( nullptr )
120{
121}
122
123CppJobModule::~CppJobModule()
124{
125    delete m_loader;
126}
127
128} // namespace Calamares
Note: See TracBrowser for help on using the repository browser.