Browse Source

Initial commit for Plugins

Commits squashed, code style and naming changes by Adam Honse <calcprogrammer1@gmail.com>
merge-requests/261/merge
silas 1 year ago
committed by Adam Honse
parent
commit
93231c3225
  1. 4
      OpenRGB.pro
  2. 43
      OpenRGBPluginInterface.h
  3. 45
      PluginManager.cpp
  4. 20
      PluginManager.h
  5. 28
      ProfileManager.h
  6. 8
      ResourceManager.cpp
  7. 34
      ResourceManager.h
  8. 24
      SettingsManager.h
  9. 118
      qt/OpenRGBDialog2.cpp
  10. 2
      qt/OpenRGBDialog2.h
  11. BIN
      qt/plugin.png
  12. BIN
      qt/plugin_dark.png
  13. 2
      qt/resources.qrc
  14. 40
      qt/windows_dark.qss

4
OpenRGB.pro

@ -112,6 +112,8 @@ HEADERS +=
NetworkClient.h \
NetworkProtocol.h \
NetworkServer.h \
OpenRGBPluginInterface.h \
PluginManager.h \
ProfileManager.h \
ResourceManager.h \
SettingsManager.h \
@ -284,7 +286,6 @@ HEADERS +=
RGBController/RGBController_Dummy.h \
RGBController/RGBController_Network.h \
SOURCES += \
dependencies/dmiinfo.cpp \
dependencies/ColorWheel/ColorWheel.cpp \
@ -293,6 +294,7 @@ SOURCES +=
cli.cpp \
NetworkClient.cpp \
NetworkServer.cpp \
PluginManager.cpp \
ProfileManager.cpp \
ResourceManager.cpp \
SettingsManager.cpp \

43
OpenRGBPluginInterface.h

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

45
PluginManager.cpp

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

20
PluginManager.h

@ -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();
};

28
ProfileManager.h

@ -2,7 +2,33 @@
#pragma once
class ProfileManager
class ProfileManagerInterface
{
public:
virtual bool SaveProfile(std::string profile_name) = 0;
virtual bool LoadProfile(std::string profile_name) = 0;
virtual bool LoadSizeFromProfile(std::string profile_name) = 0;
virtual void DeleteProfile(std::string profile_name) = 0;
std::vector<std::string> profile_list;
virtual bool LoadDeviceFromListWithOptions
(
std::vector<RGBController*>& temp_controllers,
std::vector<bool>& temp_controller_used,
RGBController* load_controller,
bool load_size,
bool load_settings
) = 0;
virtual std::vector<RGBController*> LoadProfileToList (std::string profile_name) = 0;
virtual void SetConfigurationDirectory(std::string directory) = 0;
protected:
virtual ~ProfileManagerInterface() {};
};
class ProfileManager: public ProfileManagerInterface
{
public:
ProfileManager(std::string config_dir);

8
ResourceManager.cpp

@ -18,7 +18,7 @@
#include <string>
#include <hidapi/hidapi.h>
std::unique_ptr<ResourceManager> ResourceManager::instance;
ResourceManager* ResourceManager::instance;
using namespace std::chrono_literals;
@ -26,10 +26,10 @@ ResourceManager *ResourceManager::get()
{
if(!instance)
{
instance = std::make_unique<ResourceManager>();
instance = new ResourceManager();
}
return instance.get();
return instance;
}
ResourceManager::ResourceManager()

34
ResourceManager.h

@ -50,7 +50,34 @@ typedef void (*DeviceListChangeCallback)(void *);
typedef void (*DetectionProgressCallback)(void *);
typedef void (*I2CBusListChangeCallback)(void *);
class ResourceManager
class ResourceManagerInterface
{
public:
virtual std::vector<i2c_smbus_interface*> & GetI2CBusses() = 0;
virtual void RegisterRGBController(RGBController *rgb_controller) = 0;
virtual void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback, void * new_callback_arg) = 0;
virtual void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback, void * new_callback_arg) = 0;
virtual void RegisterI2CBusListChangeCallback(I2CBusListChangeCallback new_callback, void * new_callback_arg) = 0;
virtual std::vector<RGBController*> & GetRGBControllers() = 0;
virtual std::string GetConfigurationDirectory() = 0;
virtual std::vector<NetworkClient*>& GetClients() = 0;
virtual NetworkServer* GetServer() = 0;
virtual ProfileManager* GetProfileManager() = 0;
virtual SettingsManager* GetSettingsManager() = 0;
virtual void DeviceListChanged() = 0;
protected:
virtual ~ResourceManagerInterface() {};
};
class ResourceManager: public ResourceManagerInterface
{
public:
static ResourceManager *get();
@ -110,7 +137,10 @@ public:
private:
void DetectDevicesThreadFunction();
static std::unique_ptr<ResourceManager> instance;
/*-------------------------------------------------------------------------------------*\
| Static pointer to shared instance of ResourceManager |
\*-------------------------------------------------------------------------------------*/
static ResourceManager* instance;
/*-------------------------------------------------------------------------------------*\
| Detection enabled flag |

24
SettingsManager.h

@ -15,19 +15,31 @@
using json = nlohmann::json;
class SettingsManager
class SettingsManagerInterface
{
public:
virtual json GetSettings(std::string settings_key) = 0;
virtual void SetSettings(std::string settings_key, json new_settings) = 0;
virtual void LoadSettings(std::string filename) = 0;
virtual void SaveSettings() = 0;
protected:
virtual ~SettingsManagerInterface() {};
};
class SettingsManager: public SettingsManagerInterface
{
public:
SettingsManager();
~SettingsManager();
json GetSettings(std::string settings_key);
void SetSettings(std::string settings_key, json new_settings);
json GetSettings(std::string settings_key) override;
void SetSettings(std::string settings_key, json new_settings) override;
void LoadSettings(std::string filename);
void SaveSettings();
void LoadSettings(std::string filename) override;
void SaveSettings() override;
private:
json settings_data;
json settings_prototype;

118
qt/OpenRGBDialog2.cpp

@ -1,4 +1,5 @@
#include "OpenRGBDialog2.h"
#include "PluginManager.h"
#include "OpenRGBDevicePage.h"
#include "OpenRGBDeviceInfoPage.h"
#include "OpenRGBServerInfoPage.h"
@ -88,7 +89,7 @@ static void UpdateDetectionProgressCallback(void * this_ptr)
bool OpenRGBDialog2::IsDarkTheme()
{
#ifdef _WIN32
#ifdef _WIN32
/*-------------------------------------------------*\
| Windows dark theme settings |
\*-------------------------------------------------*/
@ -131,12 +132,12 @@ bool OpenRGBDialog2::IsDarkTheme()
}
return false;
#else
#else
if(QPalette().window().color().value() < 127)
{
return true;
}
#endif
#endif
return false;
}
@ -287,6 +288,24 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
{
AddI2CToolsPage();
}
/*-----------------------------------------------------*\
| Add the various plugins tabs |
\*-----------------------------------------------------*/
PluginManager* plugin_manager = new PluginManager;
plugin_manager->ScanAndLoadPlugins();
if(plugin_manager->ActivePlugins.size() > 0)
{
for(int i = 0; i < int(plugin_manager->ActivePlugins.size()); i++)
{
/*---------------------------------------------------------------------------*\
| Start by getting location and then placing the widget where it needs to go |
\*---------------------------------------------------------------------------*/
OpenRGBDialog2::AddPluginTab(plugin_manager, i);
}
}
}
OpenRGBDialog2::~OpenRGBDialog2()
@ -358,6 +377,98 @@ void OpenRGBDialog2::AddSupportedDevicesPage()
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SupportedTabLabel);
}
void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_index)
{
/*-----------------------------------------------------*\
| Initialize the plugin |
\*-----------------------------------------------------*/
plugin_manager->ActivePlugins[plugin_index]->info = plugin_manager->ActivePlugins[plugin_index]->Initialize(OpenRGBDialog2::IsDarkTheme(), ResourceManager::get());
/*-----------------------------------------------------*\
| Create Label for the Tab |
\*-----------------------------------------------------*/
QLabel* PluginTabLabel = new QLabel;
/*-----------------------------------------------------*\
| If the plugin has custom information, use it, |
| otherwise generate it |
\*-----------------------------------------------------*/
if(plugin_manager->ActivePlugins[plugin_index]->info.HasCustom)
{
PluginTabLabel = plugin_manager->ActivePlugins[plugin_index]->info.PluginLabel;
}
else
{
QLabel *TabLabelText = plugin_manager->ActivePlugins[plugin_index]->info.PluginLabel;
QString NewTabLabelText = TabLabelText->text();
QString PluginLabelString = "<html><table><tr><td width='30'><img src='";
PluginLabelString += ":/plugin";
if (IsDarkTheme()) PluginLabelString += "_dark";
PluginLabelString+= ".png' height='16' width='16'></td><td>" + NewTabLabelText + "</td></tr></table></html>";
PluginTabLabel->setText(PluginLabelString);
PluginTabLabel->setIndent(20);
if(IsDarkTheme())
{
PluginTabLabel->setGeometry(0, 25, 200, 50);
}
else
{
PluginTabLabel->setGeometry(0, 0, 200, 25);
}
}
/*-----------------------------------------------------*\
| Determine plugin location |
\*-----------------------------------------------------*/
std::string Location = plugin_manager->ActivePlugins[plugin_index]->info.PluginLocation;
/*-----------------------------------------------------*\
| InformationTab - Place plugin in the Information tab |
\*-----------------------------------------------------*/
if(Location == "InformationTab")
{
QWidget* NewPluginTab = new QWidget;
NewPluginTab = plugin_manager->ActivePlugins[plugin_index]->CreateGUI(NewPluginTab);
ui->InformationTabBar->addTab(NewPluginTab," ");
ui->InformationTabBar->tabBar()->setTabButton((ui->InformationTabBar->count() - 1),QTabBar::LeftSide , PluginTabLabel);
}
/*-----------------------------------------------------*\
| DevicesTab - Place plugin in the Devices tab |
\*-----------------------------------------------------*/
else if(Location == "DevicesTab")
{
QWidget* NewPluginTab = new QWidget;
NewPluginTab = plugin_manager->ActivePlugins[plugin_index]->CreateGUI(NewPluginTab);
ui->DevicesTabBar->addTab(NewPluginTab," ");
ui->DevicesTabBar->tabBar()->setTabButton((ui->DevicesTabBar->count() - 1),QTabBar::LeftSide , PluginTabLabel);
}
/*-----------------------------------------------------*\
| TopTabBar - Place plugin as its own top level tab |
\*-----------------------------------------------------*/
else if(Location == "TopTabBar")
{
QWidget* NewPluginTab = new QWidget;
NewPluginTab = plugin_manager->ActivePlugins[plugin_index]->CreateGUI(NewPluginTab);
ui->MainTabBar->addTab(NewPluginTab,QString().fromStdString(plugin_manager->ActivePlugins[plugin_index]->info.PluginName));
}
/*-----------------------------------------------------*\
| Display an error message if the plugin does not |
| specify a valid location |
\*-----------------------------------------------------*/
else
{
std::cout << (plugin_manager->ActivePlugins[plugin_index]->info.PluginName + " Is broken\nNo valid location specified");
}
}
void OpenRGBDialog2::AddI2CToolsPage()
{
ShowI2CTools = true;
@ -934,6 +1045,7 @@ void Ui::OpenRGBDialog2::SetDetectionViewState(bool detection_showing)
ui->ProfileBox->setVisible(true);
}
}
void Ui::OpenRGBDialog2::on_ButtonRescan_clicked()
{
SetDetectionViewState(true);

2
qt/OpenRGBDialog2.h

@ -7,6 +7,7 @@
#include "OpenRGBSoftwareInfoPage.h"
#include "OpenRGBSystemInfoPage.h"
#include "OpenRGBSupportedDevicesPage.h"
#include "PluginManager.h"
#include <vector>
#include "i2c_smbus.h"
@ -66,6 +67,7 @@ private:
void AddSoftwareInfoPage();
void AddSupportedDevicesPage();
void AddPluginTab(PluginManager* plugin_manager,int plugin_index);
void ClearDevicesList();
void UpdateDevicesList();

BIN
qt/plugin.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

BIN
qt/plugin_dark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

2
qt/resources.qrc

@ -32,5 +32,7 @@
<file>windows_dark.qss</file>
<file>arrow-down.png</file>
<file>arrow-up.png</file>
<file>plugin.png</file>
<file>plugin_dark.png</file>
</qresource>
</RCC>

40
qt/windows_dark.qss

@ -58,10 +58,18 @@ QTabWidget QWidget QTabBar::tab
padding-top: 4px;
padding-bottom: 5px;
height: 50px;
border: 10px;
border: 1px solid #5c5c5c;
border-right: 1px solid #2e2e2e;
margin-right: 0px;
margin-bottom: 0px;
border: 1px solid #2e2e2e;
}
QTabWidget QWidget QTabBar::tab:!selected
{
background-color: #5c5c5c;
border-right: 1px solid #2e2e2e;
border-left: 1px solid #2e2e2e;
border-top: 1px solid #2e2e2e;
}
QTabWidget QWidget QTabBar::tab:selected
@ -71,6 +79,12 @@ QTabWidget QWidget QTabBar::tab:selected
border-right: 1px solid #454545;
}
QTabWidget QWidget QTabBar::tab:last:!selected
{
background-color: #5c5c5c;
border: 1px solid #2e2e2e;
}
QTabWidget QWidget QTabBar::tab:hover
{
background-color: #757575;
@ -78,6 +92,13 @@ QTabWidget QWidget QTabBar::tab:hover
border-right: 1px solid #2e2e2e;
}
QTabWidget QWidget QTabBar::tab:last:hover
{
background-color: #757575;
border: 1px solid #5c5c5c;
border-right: 1px solid #2e2e2e;
}
QTabWidget QWidget QTabWidget::pane /* The contents of the tab (colors, modes, leds, etc.) */
{
background-color: #454545;
@ -259,10 +280,15 @@ QDialog
background-color: #5c5c5c
}
/*
the default color is fine
QSlider::handle
/* QTableWidgets */
QTableWidget
{
background-color: #454545;
color: white;
}
QTableWidget QTableCornerButton::section
{
background: ;
background-color: #444444;
}
*/

Loading…
Cancel
Save