1
0
mirror of https://github.com/chylex/Nextcloud-Desktop.git synced 2025-08-20 22:49:46 +02:00
Files
.github
.tx
admin
cmake
doc
man
shell_integration
src
3rdparty
cmd
common
README
asserts.h
c_jhash.h
checksums.cpp
checksums.h
common.cmake
filesystembase.cpp
filesystembase.h
ownsql.cpp
ownsql.h
plugin.cpp
plugin.h
remotepermissions.cpp
remotepermissions.h
syncjournaldb.cpp
syncjournaldb.h
syncjournalfilerecord.cpp
syncjournalfilerecord.h
utility.cpp
utility.h
utility_mac.cpp
utility_unix.cpp
utility_win.cpp
vfs.cpp
vfs.h
crashreporter
csync
gui
libsync
CMakeLists.txt
test
theme
translations
.clang-format
.clang-tidy
.drone.yml
.git-blame-ignore-revs
.gitattributes
.gitignore
.gitmodules
.tag
CMakeLists.txt
CONTRIBUTING.md
COPYING
COPYING.documentation
CPackOptions.cmake.in
ChangeLog
NEXTCLOUD.cmake
NextcloudCPack.cmake
README.md
VERSION.cmake
appveyor.ini
appveyor.yml
config.h.in
mirall.desktop.in
resources.qrc
sync-exclude.lst
theme.qrc
version.h.in
Nextcloud-Desktop/src/common/plugin.cpp
2020-12-15 10:58:23 +01:00

74 lines
2.2 KiB
C++

/*
* Copyright (C) by Dominik Schmidt <dschmidt@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "plugin.h"
#include "config.h"
#include <QPluginLoader>
#include <QDir>
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(lcPluginLoader, "pluginLoader", QtInfoMsg)
namespace OCC {
PluginFactory::~PluginFactory() = default;
QString PluginLoader::pluginName(const QString &type, const QString &name)
{
return QString(QLatin1String("%1sync_%2_%3"))
.arg(APPLICATION_EXECUTABLE)
.arg(type)
.arg(name);
}
bool PluginLoader::isAvailable(const QString &type, const QString &name)
{
QPluginLoader loader(pluginName(type, name));
return loader.load();
}
QObject *PluginLoader::load(const QString &type, const QString &name)
{
QString fileName = pluginName(type, name);
QPluginLoader pluginLoader(fileName);
if (pluginLoader.load()) {
qCInfo(lcPluginLoader) << "Loaded plugin" << fileName;
} else {
qCWarning(lcPluginLoader) << "Could not load plugin"
<< fileName <<":"
<< pluginLoader.errorString()
<< "from" << QDir::currentPath();
}
return pluginLoader.instance();
}
QObject *PluginLoader::create(const QString &type, const QString &name, QObject *parent)
{
auto factory = qobject_cast<PluginFactory *>(load(type, name));
if (!factory) {
return nullptr;
} else {
return factory->create(parent);
}
}
}