Initial commit for Plugins
Commits squashed, code style and naming changes by Adam Honse <calcprogrammer1@gmail.com>master
parent
5f5d50ffd8
commit
93231c3225
@ -0,0 +1,43 @@
|
||||
/*-----------------------------------------*\
|
||||
| OpenRGBPluginInterface.h |
|
||||
| |
|
||||
| OpenRGB Plugin Interface Class |
|
||||
| |
|
||||
| herosilas12 (CoffeeIsLife) 12/11/2020 |
|
||||
| Adam Honse (CalcProgrammer1) 1/5/2021 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ResourceManager.h"
|
||||
|
||||
#include <QtPlugin>
|
||||
#include <QLabel>
|
||||
|
||||
#define OpenRGBPluginInterface_IID "com.OpenRGBPluginInterface"
|
||||
|
||||
struct OpenRGBPluginInfo
|
||||
{
|
||||
std::string PluginName;
|
||||
std::string PluginDescription;
|
||||
std::string PluginLocation;
|
||||
|
||||
bool HasCustom;
|
||||
QLabel *PluginLabel;
|
||||
|
||||
std::string SettingName;
|
||||
};
|
||||
|
||||
class OpenRGBPluginInterface
|
||||
{
|
||||
public:
|
||||
virtual ~OpenRGBPluginInterface() {}
|
||||
|
||||
virtual OpenRGBPluginInfo Initialize(bool dark_theme, ResourceManager* resource_manager_ptr) = 0;
|
||||
|
||||
virtual QWidget *CreateGUI(QWidget* parent) = 0;
|
||||
|
||||
OpenRGBPluginInfo info;
|
||||
};
|
||||
|
||||
Q_DECLARE_INTERFACE(OpenRGBPluginInterface, OpenRGBPluginInterface_IID)
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "OpenRGBPluginInterface.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
#include <QPluginLoader>
|
||||
#include <QLabel>
|
||||
#include <QtPlugin>
|
||||
#include <QDir>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class PluginManager
|
||||
{
|
||||
public:
|
||||
std::vector<OpenRGBPluginInterface*> ActivePlugins;
|
||||
|
||||
void ScanAndLoadPlugins();
|
||||
};
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 191 B |
Binary file not shown.
|
After Width: | Height: | Size: 183 B |
Loading…
Reference in New Issue