File indexing completed on 2024-04-21 05:46:11

0001 /*
0002     SPDX-FileCopyrightText: 2017 by Adriaan de Groot <groot@kde.org>
0003     SPDX-FileCopyrightText: 2018 Andrius Štikonas <andrius@stikonas.eu>
0004 
0005     SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 
0008 #include "helpers.h"
0009 
0010 #include "backend/corebackendmanager.h"
0011 #include "util/externalcommand.h"
0012 
0013 #include <QDebug>
0014 #include <QString>
0015 
0016 static bool s_initialized = false;
0017 
0018 KPMCoreInitializer::KPMCoreInitializer() :
0019     m_isValid( s_initialized )
0020 {
0021     if ( !s_initialized )
0022     {
0023         QByteArray env = qgetenv( "KPMCORE_BACKEND" );
0024         auto backendName = env.isEmpty() ? CoreBackendManager::defaultBackendName() : QString::fromLatin1( env );
0025 
0026         if ( !CoreBackendManager::self()->load( backendName ) )
0027             qWarning() << "Failed to load backend plugin" << backendName;
0028         else
0029             m_isValid = s_initialized = true;
0030     }
0031 }
0032 
0033 KPMCoreInitializer::KPMCoreInitializer( const QString& backendName ) :
0034     m_isValid( s_initialized )
0035 {
0036     if ( !s_initialized )
0037     {
0038         if ( !CoreBackendManager::self()->load( backendName ) )
0039             qWarning() << "Failed to load backend plugin" << backendName;
0040         else
0041             m_isValid = s_initialized = true;
0042     }
0043 }
0044 
0045 KPMCoreInitializer::KPMCoreInitializer( const char* backend ) : KPMCoreInitializer( QString::fromLatin1( backend ) )
0046 {
0047 }
0048