Add Plugins tab to settings for installing, enabling, disabling, and removing plugins
* Rework Plugin Manager so that plugins can be loaded after initialization * Use a callback function to add plugin tabs to the dialog * Install button lets you choose plugin file, copies it to plugins directory, and immediately loads it * Remove button deletes selected plugin file from plugins directory - need to add a means to unload it first
This commit is contained in:
parent
a28badafb9
commit
a20405a6ef
11 changed files with 557 additions and 70 deletions
|
|
@ -166,6 +166,8 @@ HEADERS +=
|
|||
qt/DeviceView.h \
|
||||
qt/OpenRGBDialog2.h \
|
||||
qt/OpenRGBPluginContainer.h \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.h \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.h \
|
||||
qt/OpenRGBProfileSaveDialog.h \
|
||||
qt/OpenRGBServerInfoPage.h \
|
||||
qt/OpenRGBSettingsPage.h \
|
||||
|
|
@ -485,6 +487,8 @@ SOURCES +=
|
|||
qt/DeviceView.cpp \
|
||||
qt/OpenRGBDialog2.cpp \
|
||||
qt/OpenRGBPluginContainer.cpp \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.cpp \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.cpp \
|
||||
qt/OpenRGBProfileSaveDialog.cpp \
|
||||
qt/OpenRGBServerInfoPage.cpp \
|
||||
qt/OpenRGBSettingsPage.cpp \
|
||||
|
|
@ -826,6 +830,8 @@ FORMS +=
|
|||
qt/OpenRGBDialog.ui \
|
||||
qt/OpenRGBDialog2.ui \
|
||||
qt/OpenRGBPluginContainer.ui \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.ui \
|
||||
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.ui \
|
||||
qt/OpenRGBProfileSaveDialog.ui \
|
||||
qt/OpenRGBServerInfoPage.ui \
|
||||
qt/OpenRGBSettingsPage.ui \
|
||||
|
|
|
|||
|
|
@ -1,39 +1,48 @@
|
|||
#include "LogManager.h"
|
||||
#include "PluginManager.h"
|
||||
|
||||
void PluginManager::ScanAndLoadPlugins(bool dark_theme)
|
||||
PluginManager::PluginManager(bool dark_theme_val)
|
||||
{
|
||||
dark_theme = dark_theme_val;
|
||||
}
|
||||
|
||||
void PluginManager::RegisterAddPluginTabCallback(AddPluginTabCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
AddPluginTabCallbacks.push_back(new_callback);
|
||||
AddPluginTabCallbackArgs.push_back(new_callback_arg);
|
||||
}
|
||||
|
||||
void PluginManager::ScanAndLoadPlugins()
|
||||
{
|
||||
LOG_INFO("Loading plugins");
|
||||
|
||||
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/";
|
||||
const QDir plugins_dir = QString().fromStdString(ResourceManager::get()->GetConfigurationDirectory()) + "plugins/";
|
||||
|
||||
std::vector<std::string> FileList;
|
||||
|
||||
for(int i = 0; i < QDir(pluginsDir).entryList(QDir::Files).size(); i++)
|
||||
for(int i = 0; i < QDir(plugins_dir).entryList(QDir::Files).size(); i++)
|
||||
{
|
||||
/*--------------------------------------*\
|
||||
| Add all of the Plugin Files to a list |
|
||||
\*--------------------------------------*/
|
||||
FileList.push_back(QDir(pluginsDir).entryList(QDir::Files)[i].toStdString());
|
||||
FileList.push_back(QDir(plugins_dir).entryList(QDir::Files)[i].toStdString());
|
||||
}
|
||||
|
||||
for(const std::string &fileName : FileList)
|
||||
for(const std::string &plugin_name : FileList)
|
||||
{
|
||||
const std::string filePath = pluginsDir.absoluteFilePath(QString().fromStdString(fileName)).toStdString();
|
||||
const std::string plugin_path = plugins_dir.absoluteFilePath(QString().fromStdString(plugin_name)).toStdString();
|
||||
|
||||
LOG_VERBOSE("Attempting to load: %s", filePath.c_str());
|
||||
LoadPlugin(plugin_path);
|
||||
}
|
||||
}
|
||||
|
||||
QPluginLoader loader(pluginsDir.absoluteFilePath(QString().fromStdString(fileName)));
|
||||
void PluginManager::LoadPlugin(std::string path)
|
||||
{
|
||||
OpenRGBPluginInterface *OpenRGBPlugin = nullptr;
|
||||
|
||||
LOG_VERBOSE("Attempting to load: %s", path.c_str());
|
||||
|
||||
QPluginLoader loader(QString().fromStdString(path));
|
||||
|
||||
if (QObject *instance = loader.instance())
|
||||
{
|
||||
|
|
@ -44,14 +53,82 @@ void PluginManager::ScanAndLoadPlugins(bool dark_theme)
|
|||
\*-----------------------------------------------------*/
|
||||
OpenRGBPlugin->info = OpenRGBPlugin->Initialize(dark_theme, ResourceManager::get());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Search the settings to see if it is enabled |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string name = "";
|
||||
std::string description = "";
|
||||
bool enabled = true;
|
||||
bool found = false;
|
||||
unsigned int plugin_ct = 0;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Open device disable list and read in disabled |
|
||||
| device strings |
|
||||
\*-------------------------------------------------*/
|
||||
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
|
||||
|
||||
if(plugin_settings.contains("plugins"))
|
||||
{
|
||||
plugin_ct = plugin_settings["plugins"].size();
|
||||
|
||||
for(unsigned int plugin_idx = 0; plugin_idx < plugin_settings["plugins"].size(); plugin_idx++)
|
||||
{
|
||||
if(plugin_settings["plugins"][plugin_idx].contains("name"))
|
||||
{
|
||||
name = plugin_settings["plugins"][plugin_idx]["name"];
|
||||
}
|
||||
|
||||
if(plugin_settings["plugins"][plugin_idx].contains("description"))
|
||||
{
|
||||
description = plugin_settings["plugins"][plugin_idx]["description"];
|
||||
}
|
||||
|
||||
if(plugin_settings["plugins"][plugin_idx].contains("enabled"))
|
||||
{
|
||||
enabled = plugin_settings["plugins"][plugin_idx]["enabled"];
|
||||
}
|
||||
|
||||
if((OpenRGBPlugin->info.PluginName == name)
|
||||
&&(OpenRGBPlugin->info.PluginDescription == description))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
plugin_settings["plugins"][plugin_ct]["name"] = OpenRGBPlugin->info.PluginName;
|
||||
plugin_settings["plugins"][plugin_ct]["description"] = OpenRGBPlugin->info.PluginDescription;
|
||||
plugin_settings["plugins"][plugin_ct]["enabled"] = enabled;
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
|
||||
LOG_VERBOSE("Loaded plugin %s", OpenRGBPlugin->info.PluginName.c_str());
|
||||
|
||||
PluginManager::ActivePlugins.push_back(OpenRGBPlugin);
|
||||
OpenRGBPluginEntry entry;
|
||||
|
||||
entry.plugin = OpenRGBPlugin;
|
||||
entry.path = path;
|
||||
entry.enabled = enabled;
|
||||
|
||||
PluginManager::ActivePlugins.push_back(entry);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int callback_idx = 0; callback_idx < AddPluginTabCallbacks.size(); callback_idx++)
|
||||
{
|
||||
AddPluginTabCallbacks[callback_idx](AddPluginTabCallbackArgs[callback_idx], OpenRGBPlugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << loader.errorString().toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,29 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
OpenRGBPluginInterface* plugin;
|
||||
std::string path;
|
||||
bool enabled;
|
||||
} OpenRGBPluginEntry;
|
||||
|
||||
typedef void (*AddPluginTabCallback)(void *, OpenRGBPluginInterface* plugin);
|
||||
|
||||
class PluginManager
|
||||
{
|
||||
public:
|
||||
std::vector<OpenRGBPluginInterface*> ActivePlugins;
|
||||
PluginManager(bool dark_theme);
|
||||
|
||||
void ScanAndLoadPlugins(bool dark_theme);
|
||||
void RegisterAddPluginTabCallback(AddPluginTabCallback new_callback, void * new_callback_arg);
|
||||
void ScanAndLoadPlugins();
|
||||
void LoadPlugin(std::string path);
|
||||
|
||||
std::vector<OpenRGBPluginEntry> ActivePlugins;
|
||||
|
||||
private:
|
||||
bool dark_theme;
|
||||
|
||||
std::vector<AddPluginTabCallback> AddPluginTabCallbacks;
|
||||
std::vector<void *> AddPluginTabCallbackArgs;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -96,6 +96,13 @@ static void UpdateDetectionProgressCallback(void * this_ptr)
|
|||
QMetaObject::invokeMethod(this_obj, "onDetectionProgressUpdated", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
static void CreatePluginTabCallback(void * this_ptr, OpenRGBPluginInterface * plugin)
|
||||
{
|
||||
OpenRGBDialog2 * this_obj = (OpenRGBDialog2 *)this_ptr;
|
||||
|
||||
this_obj->AddPluginTab(plugin);
|
||||
}
|
||||
|
||||
bool OpenRGBDialog2::IsDarkTheme()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
|
@ -402,6 +409,18 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
|
|||
\*-----------------------------------------------------*/
|
||||
AddSettingsPage();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize the plugin manager |
|
||||
\*-----------------------------------------------------*/
|
||||
plugin_manager = new PluginManager(IsDarkTheme());
|
||||
plugin_manager->RegisterAddPluginTabCallback(&CreatePluginTabCallback, this);
|
||||
plugin_manager->ScanAndLoadPlugins();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the Plugins page |
|
||||
\*-----------------------------------------------------*/
|
||||
AddPluginsPage(plugin_manager);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the E1.31 settings page |
|
||||
\*-----------------------------------------------------*/
|
||||
|
|
@ -424,24 +443,6 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
|
|||
{
|
||||
AddI2CToolsPage();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Add the various plugins tabs |
|
||||
\*-----------------------------------------------------*/
|
||||
plugin_manager = new PluginManager;
|
||||
|
||||
plugin_manager->ScanAndLoadPlugins(IsDarkTheme());
|
||||
|
||||
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 |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
AddPluginTab(plugin_manager, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OpenRGBDialog2::~OpenRGBDialog2()
|
||||
|
|
@ -492,6 +493,34 @@ void OpenRGBDialog2::closeEvent(QCloseEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddPluginsPage(PluginManager* plugin_manager)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the Plugins page |
|
||||
\*-----------------------------------------------------*/
|
||||
PluginsPage = new OpenRGBPluginsPage(plugin_manager);
|
||||
|
||||
ui->SettingsTabBar->addTab(PluginsPage, "");
|
||||
|
||||
QString PluginsLabelString;
|
||||
|
||||
if(IsDarkTheme())
|
||||
{
|
||||
PluginsLabelString = "plugin_dark.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
PluginsLabelString = "plugin.png";
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the tab label |
|
||||
\*-----------------------------------------------------*/
|
||||
TabLabel* PluginTabLabel = new TabLabel(PluginsLabelString, "Plugins");
|
||||
|
||||
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, PluginTabLabel);
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddSoftwareInfoPage()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
|
|
@ -661,7 +690,7 @@ void OpenRGBDialog2::AddSerialSettingsPage()
|
|||
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel);
|
||||
}
|
||||
|
||||
void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_index)
|
||||
void OpenRGBDialog2::AddPluginTab(OpenRGBPluginInterface* plugin)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Create Label for the Tab |
|
||||
|
|
@ -672,13 +701,13 @@ void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_inde
|
|||
| If the plugin has custom information, use it, |
|
||||
| otherwise generate it |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_manager->ActivePlugins[plugin_index]->info.HasCustom)
|
||||
if(plugin->info.HasCustom)
|
||||
{
|
||||
PluginTabLabel = plugin_manager->ActivePlugins[plugin_index]->info.PluginLabel;
|
||||
PluginTabLabel = plugin->info.PluginLabel;
|
||||
}
|
||||
else
|
||||
{
|
||||
QLabel *TabLabelText = plugin_manager->ActivePlugins[plugin_index]->info.PluginLabel;
|
||||
QLabel *TabLabelText = plugin->info.PluginLabel;
|
||||
QString PluginLabelString;
|
||||
|
||||
if(IsDarkTheme())
|
||||
|
|
@ -699,14 +728,14 @@ void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_inde
|
|||
/*-----------------------------------------------------*\
|
||||
| Determine plugin location |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string Location = plugin_manager->ActivePlugins[plugin_index]->info.PluginLocation;
|
||||
std::string Location = plugin->info.PluginLocation;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| InformationTab - Place plugin in the Information tab |
|
||||
\*-----------------------------------------------------*/
|
||||
if(Location == "InformationTab")
|
||||
{
|
||||
QWidget* NewPluginTab = plugin_manager->ActivePlugins[plugin_index]->CreateGUI(this);
|
||||
QWidget* NewPluginTab = plugin->CreateGUI(this);
|
||||
|
||||
OpenRGBPluginContainer* NewPluginContainer = new OpenRGBPluginContainer(NewPluginTab);
|
||||
|
||||
|
|
@ -719,7 +748,7 @@ void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_inde
|
|||
\*-----------------------------------------------------*/
|
||||
else if(Location == "DevicesTab")
|
||||
{
|
||||
QWidget* NewPluginTab = plugin_manager->ActivePlugins[plugin_index]->CreateGUI(this);
|
||||
QWidget* NewPluginTab = plugin->CreateGUI(this);
|
||||
|
||||
OpenRGBPluginContainer* NewPluginContainer = new OpenRGBPluginContainer(NewPluginTab);
|
||||
|
||||
|
|
@ -732,18 +761,18 @@ void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_inde
|
|||
\*-----------------------------------------------------*/
|
||||
else if(Location == "TopTabBar")
|
||||
{
|
||||
QWidget* NewPluginTab = plugin_manager->ActivePlugins[plugin_index]->CreateGUI(this);
|
||||
QWidget* NewPluginTab = plugin->CreateGUI(this);
|
||||
|
||||
OpenRGBPluginContainer* NewPluginContainer = new OpenRGBPluginContainer(NewPluginTab);
|
||||
|
||||
ui->MainTabBar->addTab(NewPluginContainer,QString().fromStdString(plugin_manager->ActivePlugins[plugin_index]->info.PluginName));
|
||||
ui->MainTabBar->addTab(NewPluginContainer,QString().fromStdString(plugin->info.PluginName));
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| SettingsTabBar - Place plugin in the Settings tab |
|
||||
\*-----------------------------------------------------*/
|
||||
else if(Location == "SettingsTabBar")
|
||||
{
|
||||
QWidget* NewPluginTab = plugin_manager->ActivePlugins[plugin_index]->CreateGUI(this);
|
||||
QWidget* NewPluginTab = plugin->CreateGUI(this);
|
||||
|
||||
OpenRGBPluginContainer* NewPluginContainer = new OpenRGBPluginContainer(NewPluginTab);
|
||||
|
||||
|
|
@ -757,7 +786,7 @@ void OpenRGBDialog2::AddPluginTab(PluginManager* plugin_manager, int plugin_inde
|
|||
\*-----------------------------------------------------*/
|
||||
else
|
||||
{
|
||||
std::cout << ("Cannot load plugin '" + plugin_manager->ActivePlugins[plugin_index]->info.PluginName + "' as it does not specify a valid location: " + Location + "\n");
|
||||
std::cout << ("Cannot load plugin '" + plugin->info.PluginName + "' as it does not specify a valid location: " + Location + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "ui_OpenRGBDialog2.h"
|
||||
|
||||
#include "OpenRGBClientInfoPage.h"
|
||||
#include "OpenRGBPluginsPage/OpenRGBPluginsPage.h"
|
||||
#include "OpenRGBSoftwareInfoPage.h"
|
||||
#include "OpenRGBSystemInfoPage.h"
|
||||
#include "OpenRGBSupportedDevicesPage.h"
|
||||
|
|
@ -44,6 +45,8 @@ public:
|
|||
void AddI2CToolsPage();
|
||||
void AddServerTab();
|
||||
|
||||
void AddPluginTab(OpenRGBPluginInterface* plugin);
|
||||
|
||||
void setMode(unsigned char mode_val);
|
||||
|
||||
static bool IsDarkTheme();
|
||||
|
|
@ -54,6 +57,7 @@ private:
|
|||
| Page pointers |
|
||||
\*-------------------------------------*/
|
||||
OpenRGBClientInfoPage *ClientInfoPage;
|
||||
OpenRGBPluginsPage *PluginsPage;
|
||||
OpenRGBSystemInfoPage *SMBusToolsPage;
|
||||
OpenRGBSoftwareInfoPage *SoftInfoPage;
|
||||
OpenRGBSupportedDevicesPage *SupportedPage;
|
||||
|
|
@ -81,7 +85,7 @@ private:
|
|||
void AddE131SettingsPage();
|
||||
void AddQMKORGBSettingsPage();
|
||||
void AddSerialSettingsPage();
|
||||
void AddPluginTab(PluginManager* plugin_manager,int plugin_index);
|
||||
void AddPluginsPage(PluginManager* plugin_manager);
|
||||
|
||||
void ClearDevicesList();
|
||||
void UpdateDevicesList();
|
||||
|
|
|
|||
16
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.cpp
Normal file
16
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include "OpenRGBPluginsEntry.h"
|
||||
#include "ui_OpenRGBPluginsEntry.h"
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
OpenRGBPluginsEntry::OpenRGBPluginsEntry(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBPluginsEntryUi)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
OpenRGBPluginsEntry::~OpenRGBPluginsEntry()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
21
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.h
Normal file
21
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef OPENRGBPLUGINSENTRY_H
|
||||
#define OPENRGBPLUGINSENTRY_H
|
||||
|
||||
#include "ui_OpenRGBPluginsEntry.h"
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class OpenRGBPluginsEntry;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBPluginsEntry : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBPluginsEntry(QWidget *parent = nullptr);
|
||||
~OpenRGBPluginsEntry();
|
||||
Ui::OpenRGBPluginsEntryUi *ui;
|
||||
};
|
||||
|
||||
#endif // OPENRGBPLUGINSENTRY_H
|
||||
110
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.ui
Normal file
110
qt/OpenRGBPluginsPage/OpenRGBPluginsEntry.ui
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBPluginsEntryUi</class>
|
||||
<widget class="QWidget" name="OpenRGBPluginsEntryUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>195</width>
|
||||
<height>109</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="DescriptionValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Description Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="EnabledLabel">
|
||||
<property name="text">
|
||||
<string>Enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="NameValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="DescriptionLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="NameLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="EnabledCheckBox">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="PathLabel">
|
||||
<property name="text">
|
||||
<string>Path</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="PathValue">
|
||||
<property name="text">
|
||||
<string>Path Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
132
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.cpp
Normal file
132
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.cpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "filesystem.h"
|
||||
#include "OpenRGBPluginsPage.h"
|
||||
#include "ui_OpenRGBPluginsPage.h"
|
||||
|
||||
Ui::OpenRGBPluginsPage::OpenRGBPluginsPage(PluginManager* plugin_manager_ptr, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBPluginsPageUi)
|
||||
{
|
||||
plugin_manager = plugin_manager_ptr;
|
||||
ui->setupUi(this);
|
||||
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
Ui::OpenRGBPluginsPage::~OpenRGBPluginsPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Ui::OpenRGBPluginsPage::RefreshList()
|
||||
{
|
||||
ui->PluginsList->clear();
|
||||
entries.clear();
|
||||
|
||||
for(unsigned int plugin_idx = 0; plugin_idx < plugin_manager->ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
OpenRGBPluginsEntry* entry = new OpenRGBPluginsEntry();
|
||||
|
||||
entry->ui->NameValue->setText(QString::fromStdString(plugin_manager->ActivePlugins[plugin_idx].plugin->info.PluginName));
|
||||
entry->ui->DescriptionValue->setText(QString::fromStdString(plugin_manager->ActivePlugins[plugin_idx].plugin->info.PluginDescription));
|
||||
entry->ui->PathValue->setText(QString::fromStdString(plugin_manager->ActivePlugins[plugin_idx].path));
|
||||
entry->ui->EnabledCheckBox->setChecked((plugin_manager->ActivePlugins[plugin_idx].enabled));
|
||||
|
||||
//TODO: Get plugin enable/disable working
|
||||
// Until then, hide the enable checkbox
|
||||
entry->ui->EnabledLabel->setVisible(false);
|
||||
entry->ui->EnabledCheckBox->setVisible(false);
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem;
|
||||
|
||||
item->setSizeHint(entry->sizeHint());
|
||||
|
||||
ui->PluginsList->addItem(item);
|
||||
ui->PluginsList->setItemWidget(item, entry);
|
||||
entries.push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBPluginsPage::on_InstallPluginButton_clicked()
|
||||
{
|
||||
QString install_file = QFileDialog::getOpenFileName(this, "Install OpenRGB Plugin", "", "DLL Files (*.dll; *.dylib; *.so; *.so.*)");
|
||||
|
||||
std::string from_path = install_file.toStdString();
|
||||
std::string to_path = ResourceManager::get()->GetConfigurationDirectory() + "plugins/";
|
||||
std::string to_file = to_path + filesystem::path(from_path).filename().string();
|
||||
bool match = false;
|
||||
|
||||
for(unsigned int plugin_idx = 0; plugin_idx < plugin_manager->ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(to_file == plugin_manager->ActivePlugins[plugin_idx].path)
|
||||
{
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(match == true)
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
reply = QMessageBox::question(this, "Replace Plugin", "A plugin with this filename is already installed. Are you sure you want to replace this plugin?", QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if(reply != QMessageBox::Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
filesystem::copy(from_path, to_path, filesystem::copy_options::update_existing);
|
||||
|
||||
//TODO: Unregister the old plugin and load the new one if matched
|
||||
// For now, don't load the new plugin
|
||||
|
||||
if(match == false)
|
||||
{
|
||||
plugin_manager->LoadPlugin(to_path + "/" + filesystem::path(from_path).filename().string());
|
||||
|
||||
RefreshList();
|
||||
}
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Ui::OpenRGBPluginsPage::on_RemovePluginButton_clicked()
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
reply = QMessageBox::question(this, "Remove Plugin", "Are you sure you want to remove this plugin?", QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if(reply != QMessageBox::Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int cur_row = ui->PluginsList->currentRow();
|
||||
|
||||
if(cur_row < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QListWidgetItem* item = ui->PluginsList->takeItem(cur_row);
|
||||
|
||||
ui->PluginsList->removeItemWidget(item);
|
||||
delete item;
|
||||
|
||||
//TODO: Unregister the plugin from the plugin manager
|
||||
|
||||
filesystem::remove(entries[cur_row]->ui->PathValue->text().toStdString());
|
||||
|
||||
delete entries[cur_row];
|
||||
entries.erase(entries.begin() + cur_row);
|
||||
}
|
||||
|
||||
35
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.h
Normal file
35
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef OPENRGBPLUGINSPAGE_H
|
||||
#define OPENRGBPLUGINSPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "OpenRGBPluginsEntry.h"
|
||||
#include "ui_OpenRGBPluginsPage.h"
|
||||
#include "PluginManager.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class OpenRGBPluginsPage;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBPluginsPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBPluginsPage(PluginManager* plugin_manager_ptr, QWidget *parent = nullptr);
|
||||
~OpenRGBPluginsPage();
|
||||
|
||||
private slots:
|
||||
void on_InstallPluginButton_clicked();
|
||||
|
||||
void on_RemovePluginButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBPluginsPageUi* ui;
|
||||
PluginManager* plugin_manager;
|
||||
std::vector<OpenRGBPluginsEntry*> entries;
|
||||
|
||||
void RefreshList();
|
||||
};
|
||||
|
||||
#endif // OPENRGBPLUGINSPAGE_H
|
||||
38
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.ui
Normal file
38
qt/OpenRGBPluginsPage/OpenRGBPluginsPage.ui
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBPluginsPageUi</class>
|
||||
<widget class="QWidget" name="OpenRGBPluginsPageUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="InstallPluginButton">
|
||||
<property name="text">
|
||||
<string>Install Plugin</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="RemovePluginButton">
|
||||
<property name="text">
|
||||
<string>Remove Plugin</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QListWidget" name="PluginsList"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Loading…
Add table
Add a link
Reference in a new issue