diff --git a/core/src/Plugin/PluginManager.cpp b/core/src/Plugin/PluginManager.cpp index 39246ac..bce6d8b 100644 --- a/core/src/Plugin/PluginManager.cpp +++ b/core/src/Plugin/PluginManager.cpp @@ -16,6 +16,38 @@ const auto PLUGIN_METADATA_KEY = QStringLiteral("MetaData"); /// Key for retrieving the name of the plugin in its metadata const auto PLUGIN_NAME_KEY = QStringLiteral("name"); +/// Helper to state the plugin loading operation +struct LoadPluginState { + explicit LoadPluginState(const QString &pluginPath) + : m_PluginPath{pluginPath}, m_Valid{true}, m_ErrorMessage{} + { + } + + void log() const + { + if (m_Valid) { + qCDebug(LOG_PluginManager()) + << QObject::tr("File '%1' has been loaded as a plugin").arg(m_PluginPath); + } + else { + qCWarning(LOG_PluginManager()) + << QObject::tr("File '%1' can't be loaded as a plugin: %2") + .arg(m_PluginPath) + .arg(m_ErrorMessage); + } + } + + void setError(const QString &errorMessage) + { + m_Valid = false; + m_ErrorMessage = errorMessage; + } + + QString m_PluginPath; + bool m_Valid; + QString m_ErrorMessage; +}; + } // namespace struct PluginManager::PluginManagerPrivate { @@ -29,6 +61,8 @@ struct PluginManager::PluginManagerPrivate { qCDebug(LOG_PluginManager()) << QObject::tr("Attempting to load file '%1' as a plugin").arg(pluginPath); + LoadPluginState loadState{pluginPath}; + if (QLibrary::isLibrary(pluginPath)) { QPluginLoader pluginLoader{pluginPath}; @@ -38,10 +72,10 @@ struct PluginManager::PluginManagerPrivate { auto pluginName = metadata.value(PLUGIN_NAME_KEY).toString(); if (pluginName.isEmpty()) { - /// @todo ALX : log error + loadState.setError(QObject::tr("empty file name")); } else if (m_RegisteredPlugins.contains(pluginName)) { - /// @todo ALX : log error + loadState.setError(QObject::tr("name '%1' already registered").arg(pluginName)); } else { if (auto pluginInstance = qobject_cast(pluginLoader.instance())) { @@ -49,13 +83,16 @@ struct PluginManager::PluginManagerPrivate { m_RegisteredPlugins.insert(pluginName, pluginPath); } else { - /// @todo ALX : log error + loadState.setError(QObject::tr("the file is not a Sciqlop plugin")); } } } else { - /// @todo ALX : log error + loadState.setError(QObject::tr("the file is not a library")); } + + // Log loading result + loadState.log(); } /// Registered plugins (key: plugin name, value: plugin path)