Browse Source

Add GetTrayMenu to plugin API to provide a dedicated interface for registering a tray menu for a plugin

plugin_api_devel
Adam Honse 5 months ago
parent
commit
2800e76e9d
  1. 2
      OpenRGBPluginInterface.h
  2. 34
      PluginManager.cpp
  3. 17
      PluginManager.h
  4. 32
      qt/OpenRGBDialog2.cpp
  5. 5
      qt/OpenRGBDialog2.h

2
OpenRGBPluginInterface.h

@ -13,6 +13,7 @@
#include <QtPlugin>
#include <QLabel>
#include <QMenu>
#define OpenRGBPluginInterface_IID "com.OpenRGBPluginInterface"
@ -68,6 +69,7 @@ public:
\*-------------------------------------------------------------------------------------------------*/
virtual void Load(bool dark_theme, ResourceManager* resource_manager_ptr) = 0;
virtual QWidget* GetWidget() = 0;
virtual QMenu* GetTrayMenu() = 0;
virtual void Unload() = 0;
};

34
PluginManager.cpp

@ -6,23 +6,23 @@ PluginManager::PluginManager(bool dark_theme_val)
/*---------------------------------------------------------*\
| Initialize plugin manager class variables |
\*---------------------------------------------------------*/
dark_theme = dark_theme_val;
AddPluginTabCallbackVal = nullptr;
AddPluginTabCallbackArg = nullptr;
RemovePluginTabCallbackVal = nullptr;
RemovePluginTabCallbackArg = nullptr;
dark_theme = dark_theme_val;
AddPluginCallbackVal = nullptr;
AddPluginCallbackArg = nullptr;
RemovePluginCallbackVal = nullptr;
RemovePluginCallbackArg = nullptr;
}
void PluginManager::RegisterAddPluginTabCallback(AddPluginTabCallback new_callback, void * new_callback_arg)
void PluginManager::RegisterAddPluginCallback(AddPluginCallback new_callback, void * new_callback_arg)
{
AddPluginTabCallbackVal = new_callback;
AddPluginTabCallbackArg = new_callback_arg;
AddPluginCallbackVal = new_callback;
AddPluginCallbackArg = new_callback_arg;
}
void PluginManager::RegisterRemovePluginTabCallback(RemovePluginTabCallback new_callback, void * new_callback_arg)
void PluginManager::RegisterRemovePluginCallback(RemovePluginCallback new_callback, void * new_callback_arg)
{
RemovePluginTabCallbackVal = new_callback;
RemovePluginTabCallbackArg = new_callback_arg;
RemovePluginCallbackVal = new_callback;
RemovePluginCallbackArg = new_callback_arg;
}
void PluginManager::ScanAndLoadPlugins()
@ -272,11 +272,11 @@ void PluginManager::LoadPlugin(std::string path)
plugin->Load(dark_theme, ResourceManager::get());
/*-------------------------------------------------*\
| Call the Add Plugin Tab callback |
| Call the Add Plugin callback |
\*-------------------------------------------------*/
if(AddPluginTabCallbackArg != nullptr)
if(AddPluginCallbackArg != nullptr)
{
AddPluginTabCallbackVal(AddPluginTabCallbackArg, &ActivePlugins[plugin_idx]);
AddPluginCallbackVal(AddPluginCallbackArg, &ActivePlugins[plugin_idx]);
}
}
}
@ -318,11 +318,11 @@ void PluginManager::UnloadPlugin(std::string path)
ActivePlugins[plugin_idx].plugin->Unload();
/*-------------------------------------------------*\
| Call the Remove Plugin Tab callback |
| Call the Remove Plugin callback |
\*-------------------------------------------------*/
if(RemovePluginTabCallbackVal != nullptr)
if(RemovePluginCallbackVal != nullptr)
{
RemovePluginTabCallbackVal(RemovePluginTabCallbackArg, &ActivePlugins[plugin_idx]);
RemovePluginCallbackVal(RemovePluginCallbackArg, &ActivePlugins[plugin_idx]);
}
ActivePlugins[plugin_idx].loader->unload();

17
PluginManager.h

@ -18,20 +18,21 @@ typedef struct
QPluginLoader* loader;
bool loaded;
QWidget* widget;
QMenu* traymenu;
std::string path;
bool enabled;
} OpenRGBPluginEntry;
typedef void (*AddPluginTabCallback)(void *, OpenRGBPluginEntry* plugin);
typedef void (*RemovePluginTabCallback)(void *, OpenRGBPluginEntry* plugin);
typedef void (*AddPluginCallback)(void *, OpenRGBPluginEntry* plugin);
typedef void (*RemovePluginCallback)(void *, OpenRGBPluginEntry* plugin);
class PluginManager
{
public:
PluginManager(bool dark_theme);
void RegisterAddPluginTabCallback(AddPluginTabCallback new_callback, void * new_callback_arg);
void RegisterRemovePluginTabCallback(RemovePluginTabCallback new_callback, void * new_callback_arg);
void RegisterAddPluginCallback(AddPluginCallback new_callback, void * new_callback_arg);
void RegisterRemovePluginCallback(RemovePluginCallback new_callback, void * new_callback_arg);
void ScanAndLoadPlugins();
@ -46,9 +47,9 @@ public:
private:
bool dark_theme;
AddPluginTabCallback AddPluginTabCallbackVal;
void * AddPluginTabCallbackArg;
AddPluginCallback AddPluginCallbackVal;
void * AddPluginCallbackArg;
RemovePluginTabCallback RemovePluginTabCallbackVal;
void * RemovePluginTabCallbackArg;
RemovePluginCallback RemovePluginCallbackVal;
void * RemovePluginCallbackArg;
};

32
qt/OpenRGBDialog2.cpp

@ -96,18 +96,18 @@ static void UpdateDetectionProgressCallback(void * this_ptr)
QMetaObject::invokeMethod(this_obj, "onDetectionProgressUpdated", Qt::QueuedConnection);
}
static void CreatePluginTabCallback(void * this_ptr, OpenRGBPluginEntry* plugin)
static void CreatePluginCallback(void * this_ptr, OpenRGBPluginEntry* plugin)
{
OpenRGBDialog2 * this_obj = (OpenRGBDialog2 *)this_ptr;
this_obj->AddPluginTab(plugin);
this_obj->AddPlugin(plugin);
}
static void DeletePluginTabCallback(void * this_ptr, OpenRGBPluginEntry* plugin)
static void DeletePluginCallback(void * this_ptr, OpenRGBPluginEntry* plugin)
{
OpenRGBDialog2 * this_obj = (OpenRGBDialog2 *)this_ptr;
this_obj->RemovePluginTab(plugin);
this_obj->RemovePlugin(plugin);
}
bool OpenRGBDialog2::IsDarkTheme()
@ -286,7 +286,7 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
/*-----------------------------------------------------*\
| Set up tray icon menu |
\*-----------------------------------------------------*/
QMenu* trayIconMenu = new QMenu( this );
trayIconMenu = new QMenu( this );
trayIcon = new QSystemTrayIcon(this);
@ -420,8 +420,8 @@ OpenRGBDialog2::OpenRGBDialog2(QWidget *parent) : QMainWindow(parent), ui(new Op
| Initialize the plugin manager |
\*-----------------------------------------------------*/
plugin_manager = new PluginManager(IsDarkTheme());
plugin_manager->RegisterAddPluginTabCallback(&CreatePluginTabCallback, this);
plugin_manager->RegisterRemovePluginTabCallback(&DeletePluginTabCallback, this);
plugin_manager->RegisterAddPluginCallback(&CreatePluginCallback, this);
plugin_manager->RegisterRemovePluginCallback(&DeletePluginCallback, this);
plugin_manager->ScanAndLoadPlugins();
/*-----------------------------------------------------*\
@ -698,7 +698,7 @@ void OpenRGBDialog2::AddSerialSettingsPage()
ui->SettingsTabBar->tabBar()->setTabButton(ui->SettingsTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SettingsTabLabel);
}
void OpenRGBDialog2::AddPluginTab(OpenRGBPluginEntry* plugin)
void OpenRGBDialog2::AddPlugin(OpenRGBPluginEntry* plugin)
{
/*-----------------------------------------------------*\
| Create Label for the Tab |
@ -791,9 +791,18 @@ void OpenRGBDialog2::AddPluginTab(OpenRGBPluginEntry* plugin)
{
std::cout << ("Cannot load plugin '" + plugin->info.Name + "' as it does not specify a valid location.\n");
}
QMenu* NewTrayMenu = plugin->plugin->GetTrayMenu();
plugin->traymenu = NewTrayMenu;
if(NewTrayMenu)
{
trayIconMenu->addMenu(NewTrayMenu);
}
}
void OpenRGBDialog2::RemovePluginTab(OpenRGBPluginEntry* plugin)
void OpenRGBDialog2::RemovePlugin(OpenRGBPluginEntry* plugin)
{
/*-----------------------------------------------------*\
| Place plugin as its own top level tab |
@ -863,6 +872,11 @@ void OpenRGBDialog2::RemovePluginTab(OpenRGBPluginEntry* plugin)
}
}
}
if(plugin->traymenu)
{
trayIconMenu->removeAction(plugin->traymenu->menuAction());
}
}
void OpenRGBDialog2::AddI2CToolsPage()

5
qt/OpenRGBDialog2.h

@ -45,8 +45,8 @@ public:
void AddI2CToolsPage();
void AddServerTab();
void AddPluginTab(OpenRGBPluginEntry* plugin);
void RemovePluginTab(OpenRGBPluginEntry* plugin);
void AddPlugin(OpenRGBPluginEntry* plugin);
void RemovePlugin(OpenRGBPluginEntry* plugin);
void setMode(unsigned char mode_val);
@ -73,6 +73,7 @@ private:
| System tray icon and menu |
\*-------------------------------------*/
QSystemTrayIcon* trayIcon;
QMenu* trayIconMenu;
QMenu* profileMenu;
/*-------------------------------------*\

Loading…
Cancel
Save