d-pointerize CoreBackendManager
This commit is contained in:
parent
8f88efeefd
commit
00cb2c85d9
|
@ -26,7 +26,7 @@ set(VERSION_MAJOR "3")
|
|||
set(VERSION_MINOR "3")
|
||||
set(VERSION_RELEASE "0")
|
||||
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE})
|
||||
set(SOVERSION "8")
|
||||
set(SOVERSION "9")
|
||||
add_definitions(-D'VERSION="${VERSION}"') #"
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
|
|
@ -43,10 +43,11 @@ target_link_libraries( kpmcore PUBLIC
|
|||
${UUID_LIBRARIES}
|
||||
${BLKID_LIBRARIES}
|
||||
Qt5::DBus
|
||||
KF5::Auth
|
||||
KF5::I18n
|
||||
KF5::CoreAddons
|
||||
KF5::WidgetsAddons
|
||||
PRIVATE
|
||||
KF5::Auth
|
||||
)
|
||||
|
||||
install(TARGETS kpmcore EXPORT KPMcoreTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "backend/corebackendmanager.h"
|
||||
#include "backend/corebackendmanager_p.h"
|
||||
#include "backend/corebackend.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
@ -36,7 +37,7 @@
|
|||
#include <KPluginMetaData>
|
||||
|
||||
CoreBackendManager::CoreBackendManager() :
|
||||
m_Backend(nullptr)
|
||||
d(std::make_unique<CoreBackendManagerPrivate>())
|
||||
{
|
||||
startExternalCommandHelper();
|
||||
}
|
||||
|
@ -51,6 +52,10 @@ CoreBackendManager* CoreBackendManager::self()
|
|||
return instance;
|
||||
}
|
||||
|
||||
CoreBackend* CoreBackendManager::backend() {
|
||||
return d->m_Backend;
|
||||
}
|
||||
|
||||
QVector<KPluginMetaData> CoreBackendManager::list() const
|
||||
{
|
||||
auto filter = [&](const KPluginMetaData &metaData) {
|
||||
|
@ -68,17 +73,17 @@ void CoreBackendManager::startExternalCommandHelper()
|
|||
action.setHelperId(QStringLiteral("org.kde.kpmcore.externalcommand"));
|
||||
action.setTimeout(10 * 24 * 3600 * 1000); // 10 days
|
||||
QVariantMap arguments;
|
||||
m_Uuid = QUuid::createUuid().toString();
|
||||
d->m_Uuid = QUuid::createUuid().toString();
|
||||
arguments.insert(QStringLiteral("callerUuid"), Uuid());
|
||||
action.setArguments(arguments);
|
||||
m_job = action.execute();
|
||||
d->m_job = action.execute();
|
||||
job()->start();
|
||||
|
||||
// Wait until ExternalCommand Helper is ready (helper sends newData signal just before it enters event loop)
|
||||
QEventLoop loop;
|
||||
auto exitLoop = [&] () {loop.exit();};
|
||||
auto exitLoop = [&] () { loop.exit(); };
|
||||
auto conn = QObject::connect(job(), &KAuth::ExecuteJob::newData, exitLoop);
|
||||
QObject::connect(job(), &KJob::finished, [=] () { if(job()->error()) exitLoop(); } );
|
||||
QObject::connect(job(), &KJob::finished, [=] () { if(d->m_job->error()) exitLoop(); } );
|
||||
loop.exec();
|
||||
QObject::disconnect(conn);
|
||||
|
||||
|
@ -107,7 +112,11 @@ void CoreBackendManager::stopExternalCommandHelper()
|
|||
}
|
||||
|
||||
KAuth::ExecuteJob* CoreBackendManager::job() {
|
||||
return m_job;
|
||||
return d->m_job;
|
||||
}
|
||||
|
||||
QString& CoreBackendManager::Uuid() {
|
||||
return d->m_Uuid;
|
||||
}
|
||||
|
||||
bool CoreBackendManager::load(const QString& name)
|
||||
|
@ -120,7 +129,7 @@ bool CoreBackendManager::load(const QString& name)
|
|||
KPluginFactory* factory = loader.factory();
|
||||
|
||||
if (factory != nullptr) {
|
||||
m_Backend = factory->create<CoreBackend>(nullptr);
|
||||
d->m_Backend = factory->create<CoreBackend>(nullptr);
|
||||
|
||||
QString id = loader.metaData().toVariantMap().value(QStringLiteral("MetaData"))
|
||||
.toMap().value(QStringLiteral("KPlugin")).toMap().value(QStringLiteral("Id")).toString();
|
||||
|
@ -142,6 +151,4 @@ bool CoreBackendManager::load(const QString& name)
|
|||
|
||||
void CoreBackendManager::unload()
|
||||
{
|
||||
delete m_Backend;
|
||||
m_Backend = nullptr;
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(KPMCORE_COREBACKENDMANAGER_H)
|
||||
#ifndef KPMCORE_COREBACKENDMANAGER_H
|
||||
|
||||
#define KPMCORE_COREBACKENDMANAGER_H
|
||||
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
|
||||
#include <KAuth>
|
||||
#include <memory>
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
@ -31,6 +31,8 @@ class QString;
|
|||
class QStringList;
|
||||
class KPluginMetaData;
|
||||
class CoreBackend;
|
||||
namespace KAuth { class ExecuteJob; }
|
||||
struct CoreBackendManagerPrivate;
|
||||
|
||||
/**
|
||||
* The backend manager class.
|
||||
|
@ -77,16 +79,12 @@ public:
|
|||
/**
|
||||
* @return a pointer to the currently loaded backend
|
||||
*/
|
||||
CoreBackend* backend() {
|
||||
return m_Backend;
|
||||
}
|
||||
CoreBackend* backend();
|
||||
|
||||
/**
|
||||
* @return a pointer to the currently loaded backend
|
||||
*/
|
||||
QString& Uuid() {
|
||||
return m_Uuid;
|
||||
}
|
||||
QString& Uuid();
|
||||
|
||||
/**
|
||||
* @return a pointer to the KAuth job
|
||||
|
@ -102,10 +100,7 @@ private:
|
|||
void startExternalCommandHelper();
|
||||
|
||||
private:
|
||||
CoreBackend *m_Backend;
|
||||
KAuth::ExecuteJob *m_job;
|
||||
|
||||
QString m_Uuid;
|
||||
std::unique_ptr<CoreBackendManagerPrivate> d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2018 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(KPMCORE_COREBACKENDMANAGER_P_H)
|
||||
|
||||
#define KPMCORE_COREBACKENDMANAGER_P_H
|
||||
|
||||
struct CoreBackendManagerPrivate
|
||||
{
|
||||
KAuth::ExecuteJob *m_job;
|
||||
CoreBackend *m_Backend;
|
||||
|
||||
QString m_Uuid;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -16,7 +16,7 @@ add_compile_options(-fPIC)
|
|||
# and to add a test with the given name.
|
||||
#
|
||||
add_library(testhelpers STATIC helpers.cpp)
|
||||
target_link_libraries(testhelpers KF5::Auth)
|
||||
target_link_libraries(testhelpers)
|
||||
|
||||
macro (kpm_test name)
|
||||
add_executable(${name} ${ARGN})
|
||||
|
|
Loading…
Reference in New Issue