Initial commit for Plugins

Commits squashed, code style and naming changes by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
silas
2020-12-07 19:14:54 -06:00
committed by Adam Honse
parent 5f5d50ffd8
commit 93231c3225
14 changed files with 344 additions and 24 deletions

45
PluginManager.cpp Normal file
View File

@@ -0,0 +1,45 @@
#include "PluginManager.h"
void PluginManager::ScanAndLoadPlugins()
{
std::string OpenRGBConfigDir = ResourceManager::get()->GetConfigurationDirectory();
std::string PluginPath = OpenRGBConfigDir + "/Plugins";
/*--------------------------------------------------------------------------------------*\
| I used https://github.com/krf/cmake-qtqml-plugin-example to figure out how to do this |
| So BIG credit to krf |
\*--------------------------------------------------------------------------------------*/
OpenRGBPluginInterface *OpenRGBPlugin = nullptr;
const QDir pluginsDir = QString().fromStdString(ResourceManager::get()->GetConfigurationDirectory()) + "plugins/";
std::vector<std::string> FileList;
for(int i = 0; i < QDir(pluginsDir).entryList(QDir::Files).size(); i++)
{
/*--------------------------------------*\
| Add all of the Plugin Files to a list |
\*--------------------------------------*/
FileList.push_back(QDir(pluginsDir).entryList(QDir::Files)[i].toStdString());
}
for(const std::string &fileName : FileList)
{
const std::string filePath = pluginsDir.absoluteFilePath(QString().fromStdString(fileName)).toStdString();
QPluginLoader loader(pluginsDir.absoluteFilePath(QString().fromStdString(fileName)));
if (QObject *instance = loader.instance())
{
if ((OpenRGBPlugin = qobject_cast<OpenRGBPluginInterface*>(instance)))
{
PluginManager::ActivePlugins.push_back(OpenRGBPlugin);
}
}
else
{
std::cout << loader.errorString().toStdString() << std::endl;
}
}
}