d-pointerize CoreBackendManager

This commit is contained in:
Andrius Štikonas 2018-03-31 13:05:34 +01:00
parent 8f88efeefd
commit 00cb2c85d9
6 changed files with 57 additions and 24 deletions

View File

@ -26,7 +26,7 @@ set(VERSION_MAJOR "3")
set(VERSION_MINOR "3") set(VERSION_MINOR "3")
set(VERSION_RELEASE "0") set(VERSION_RELEASE "0")
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE}) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE})
set(SOVERSION "8") set(SOVERSION "9")
add_definitions(-D'VERSION="${VERSION}"') #" add_definitions(-D'VERSION="${VERSION}"') #"
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)

View File

@ -43,10 +43,11 @@ target_link_libraries( kpmcore PUBLIC
${UUID_LIBRARIES} ${UUID_LIBRARIES}
${BLKID_LIBRARIES} ${BLKID_LIBRARIES}
Qt5::DBus Qt5::DBus
KF5::Auth
KF5::I18n KF5::I18n
KF5::CoreAddons KF5::CoreAddons
KF5::WidgetsAddons KF5::WidgetsAddons
PRIVATE
KF5::Auth
) )
install(TARGETS kpmcore EXPORT KPMcoreTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) install(TARGETS kpmcore EXPORT KPMcoreTargets ${INSTALL_TARGETS_DEFAULT_ARGS})

View File

@ -18,6 +18,7 @@
*************************************************************************/ *************************************************************************/
#include "backend/corebackendmanager.h" #include "backend/corebackendmanager.h"
#include "backend/corebackendmanager_p.h"
#include "backend/corebackend.h" #include "backend/corebackend.h"
#include <QCoreApplication> #include <QCoreApplication>
@ -36,7 +37,7 @@
#include <KPluginMetaData> #include <KPluginMetaData>
CoreBackendManager::CoreBackendManager() : CoreBackendManager::CoreBackendManager() :
m_Backend(nullptr) d(std::make_unique<CoreBackendManagerPrivate>())
{ {
startExternalCommandHelper(); startExternalCommandHelper();
} }
@ -51,6 +52,10 @@ CoreBackendManager* CoreBackendManager::self()
return instance; return instance;
} }
CoreBackend* CoreBackendManager::backend() {
return d->m_Backend;
}
QVector<KPluginMetaData> CoreBackendManager::list() const QVector<KPluginMetaData> CoreBackendManager::list() const
{ {
auto filter = [&](const KPluginMetaData &metaData) { auto filter = [&](const KPluginMetaData &metaData) {
@ -68,17 +73,17 @@ void CoreBackendManager::startExternalCommandHelper()
action.setHelperId(QStringLiteral("org.kde.kpmcore.externalcommand")); action.setHelperId(QStringLiteral("org.kde.kpmcore.externalcommand"));
action.setTimeout(10 * 24 * 3600 * 1000); // 10 days action.setTimeout(10 * 24 * 3600 * 1000); // 10 days
QVariantMap arguments; QVariantMap arguments;
m_Uuid = QUuid::createUuid().toString(); d->m_Uuid = QUuid::createUuid().toString();
arguments.insert(QStringLiteral("callerUuid"), Uuid()); arguments.insert(QStringLiteral("callerUuid"), Uuid());
action.setArguments(arguments); action.setArguments(arguments);
m_job = action.execute(); d->m_job = action.execute();
job()->start(); job()->start();
// Wait until ExternalCommand Helper is ready (helper sends newData signal just before it enters event loop) // Wait until ExternalCommand Helper is ready (helper sends newData signal just before it enters event loop)
QEventLoop loop; QEventLoop loop;
auto exitLoop = [&] () {loop.exit();}; auto exitLoop = [&] () { loop.exit(); };
auto conn = QObject::connect(job(), &KAuth::ExecuteJob::newData, exitLoop); 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(); loop.exec();
QObject::disconnect(conn); QObject::disconnect(conn);
@ -107,7 +112,11 @@ void CoreBackendManager::stopExternalCommandHelper()
} }
KAuth::ExecuteJob* CoreBackendManager::job() { KAuth::ExecuteJob* CoreBackendManager::job() {
return m_job; return d->m_job;
}
QString& CoreBackendManager::Uuid() {
return d->m_Uuid;
} }
bool CoreBackendManager::load(const QString& name) bool CoreBackendManager::load(const QString& name)
@ -120,7 +129,7 @@ bool CoreBackendManager::load(const QString& name)
KPluginFactory* factory = loader.factory(); KPluginFactory* factory = loader.factory();
if (factory != nullptr) { if (factory != nullptr) {
m_Backend = factory->create<CoreBackend>(nullptr); d->m_Backend = factory->create<CoreBackend>(nullptr);
QString id = loader.metaData().toVariantMap().value(QStringLiteral("MetaData")) QString id = loader.metaData().toVariantMap().value(QStringLiteral("MetaData"))
.toMap().value(QStringLiteral("KPlugin")).toMap().value(QStringLiteral("Id")).toString(); .toMap().value(QStringLiteral("KPlugin")).toMap().value(QStringLiteral("Id")).toString();
@ -142,6 +151,4 @@ bool CoreBackendManager::load(const QString& name)
void CoreBackendManager::unload() void CoreBackendManager::unload()
{ {
delete m_Backend;
m_Backend = nullptr;
} }

View File

@ -16,13 +16,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.* * 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 #define KPMCORE_COREBACKENDMANAGER_H
#include "util/libpartitionmanagerexport.h" #include "util/libpartitionmanagerexport.h"
#include <KAuth> #include <memory>
#include <QObject> #include <QObject>
#include <QVector> #include <QVector>
@ -31,6 +31,8 @@ class QString;
class QStringList; class QStringList;
class KPluginMetaData; class KPluginMetaData;
class CoreBackend; class CoreBackend;
namespace KAuth { class ExecuteJob; }
struct CoreBackendManagerPrivate;
/** /**
* The backend manager class. * The backend manager class.
@ -77,16 +79,12 @@ public:
/** /**
* @return a pointer to the currently loaded backend * @return a pointer to the currently loaded backend
*/ */
CoreBackend* backend() { CoreBackend* backend();
return m_Backend;
}
/** /**
* @return a pointer to the currently loaded backend * @return a pointer to the currently loaded backend
*/ */
QString& Uuid() { QString& Uuid();
return m_Uuid;
}
/** /**
* @return a pointer to the KAuth job * @return a pointer to the KAuth job
@ -102,10 +100,7 @@ private:
void startExternalCommandHelper(); void startExternalCommandHelper();
private: private:
CoreBackend *m_Backend; std::unique_ptr<CoreBackendManagerPrivate> d;
KAuth::ExecuteJob *m_job;
QString m_Uuid;
}; };
#endif #endif

View File

@ -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

View File

@ -16,7 +16,7 @@ add_compile_options(-fPIC)
# and to add a test with the given name. # and to add a test with the given name.
# #
add_library(testhelpers STATIC helpers.cpp) add_library(testhelpers STATIC helpers.cpp)
target_link_libraries(testhelpers KF5::Auth) target_link_libraries(testhelpers)
macro (kpm_test name) macro (kpm_test name)
add_executable(${name} ${ARGN}) add_executable(${name} ${ARGN})