mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2025-12-23 23:37:48 -05:00
Remove plugin from active plugins list when removing plugin from user interface
This commit is contained in:
@@ -179,6 +179,31 @@ void PluginManager::AddPlugin(std::string path)
|
||||
}
|
||||
}
|
||||
|
||||
void PluginManager::RemovePlugin(std::string path)
|
||||
{
|
||||
unsigned int plugin_idx;
|
||||
|
||||
for(plugin_idx = 0; plugin_idx < ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(path == ActivePlugins[plugin_idx].path)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(plugin_idx == ActivePlugins.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(ActivePlugins[plugin_idx].loaded)
|
||||
{
|
||||
UnloadPlugin(path);
|
||||
}
|
||||
|
||||
ActivePlugins.erase(ActivePlugins.begin() + plugin_idx);
|
||||
}
|
||||
|
||||
void PluginManager::LoadPlugin(std::string path)
|
||||
{
|
||||
unsigned int plugin_idx;
|
||||
|
||||
@@ -36,6 +36,8 @@ public:
|
||||
void ScanAndLoadPlugins();
|
||||
|
||||
void AddPlugin(std::string path);
|
||||
void RemovePlugin(std::string path);
|
||||
|
||||
void LoadPlugin(std::string path);
|
||||
void UnloadPlugin(std::string path);
|
||||
|
||||
|
||||
@@ -800,14 +800,34 @@ void OpenRGBDialog2::RemovePluginTab(OpenRGBPluginEntry* plugin)
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin->info.Location == "InformationTab")
|
||||
{
|
||||
|
||||
for(int tab_idx = 0; tab_idx < ui->InformationTabBar->count(); tab_idx++)
|
||||
{
|
||||
if(dynamic_cast<OpenRGBPluginContainer*>(ui->InformationTabBar->widget(tab_idx)) != nullptr)
|
||||
{
|
||||
if(dynamic_cast<OpenRGBPluginContainer*>(ui->InformationTabBar->widget(tab_idx))->plugin_widget == plugin->widget)
|
||||
{
|
||||
ui->InformationTabBar->removeTab(tab_idx);
|
||||
delete plugin->widget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| DevicesTab - Place plugin in the Devices tab |
|
||||
\*-----------------------------------------------------*/
|
||||
else if(plugin->info.Location == "DevicesTab")
|
||||
{
|
||||
|
||||
for(int tab_idx = 0; tab_idx < ui->DevicesTabBar->count(); tab_idx++)
|
||||
{
|
||||
if(dynamic_cast<OpenRGBPluginContainer*>(ui->DevicesTabBar->widget(tab_idx)) != nullptr)
|
||||
{
|
||||
if(dynamic_cast<OpenRGBPluginContainer*>(ui->DevicesTabBar->widget(tab_idx))->plugin_widget == plugin->widget)
|
||||
{
|
||||
ui->DevicesTabBar->removeTab(tab_idx);
|
||||
delete plugin->widget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------*\
|
||||
| TopTabBar - Place plugin as its own top level tab |
|
||||
@@ -818,12 +838,10 @@ void OpenRGBDialog2::RemovePluginTab(OpenRGBPluginEntry* plugin)
|
||||
{
|
||||
if(dynamic_cast<OpenRGBPluginContainer*>(ui->MainTabBar->widget(tab_idx)) != nullptr)
|
||||
{
|
||||
std::cout << "found a plugin tab" << std::endl;
|
||||
if(dynamic_cast<OpenRGBPluginContainer*>(ui->MainTabBar->widget(tab_idx))->plugin_widget == plugin->widget)
|
||||
{
|
||||
std::cout << "found correct plugin tab" << std::endl;
|
||||
delete ui->MainTabBar->widget(tab_idx);
|
||||
ui->MainTabBar->removeTab(tab_idx);
|
||||
delete plugin->widget;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -833,7 +851,17 @@ void OpenRGBDialog2::RemovePluginTab(OpenRGBPluginEntry* plugin)
|
||||
\*-----------------------------------------------------*/
|
||||
else if(plugin->info.Location == "SettingsTabBar")
|
||||
{
|
||||
|
||||
for(int tab_idx = 0; tab_idx < ui->SettingsTabBar->count(); tab_idx++)
|
||||
{
|
||||
if(dynamic_cast<OpenRGBPluginContainer*>(ui->SettingsTabBar->widget(tab_idx)) != nullptr)
|
||||
{
|
||||
if(dynamic_cast<OpenRGBPluginContainer*>(ui->SettingsTabBar->widget(tab_idx))->plugin_widget == plugin->widget)
|
||||
{
|
||||
ui->SettingsTabBar->removeTab(tab_idx);
|
||||
delete plugin->widget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,9 @@ void Ui::OpenRGBPluginsPage::on_RemovePluginButton_clicked()
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Confirm plugin removal with message box |
|
||||
\*-----------------------------------------------------*/
|
||||
reply = QMessageBox::question(this, "Remove Plugin", "Are you sure you want to remove this plugin?", QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if(reply != QMessageBox::Yes)
|
||||
@@ -142,6 +145,9 @@ void Ui::OpenRGBPluginsPage::on_RemovePluginButton_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get index of selected plugin entry |
|
||||
\*-----------------------------------------------------*/
|
||||
int cur_row = ui->PluginsList->currentRow();
|
||||
|
||||
if(cur_row < 0)
|
||||
@@ -149,17 +155,54 @@ void Ui::OpenRGBPluginsPage::on_RemovePluginButton_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Open plugin settings |
|
||||
\*-----------------------------------------------------*/
|
||||
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Find plugin's entry in settings and remove it |
|
||||
\*-----------------------------------------------------*/
|
||||
if(plugin_settings.contains("plugins"))
|
||||
{
|
||||
for(unsigned int plugin_idx = 0; plugin_idx < plugin_settings["plugins"].size(); plugin_idx++)
|
||||
{
|
||||
if((plugin_settings["plugins"][plugin_idx].contains("name"))
|
||||
&&(plugin_settings["plugins"][plugin_idx].contains("description")))
|
||||
{
|
||||
if((plugin_settings["plugins"][plugin_idx]["name"] == entries[cur_row]->ui->NameValue->text().toStdString())
|
||||
&&(plugin_settings["plugins"][plugin_idx]["description"] == entries[cur_row]->ui->DescriptionValue->text().toStdString()))
|
||||
{
|
||||
plugin_settings["plugins"].erase(plugin_idx);
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Remove plugin entry from GUI plugin entries list |
|
||||
\*-----------------------------------------------------*/
|
||||
QListWidgetItem* item = ui->PluginsList->takeItem(cur_row);
|
||||
|
||||
ui->PluginsList->removeItemWidget(item);
|
||||
delete item;
|
||||
|
||||
//TODO: Unregister the plugin from the plugin manager
|
||||
/*-----------------------------------------------------*\
|
||||
| Command plugin manager to unload and remove the plugin|
|
||||
\*-----------------------------------------------------*/
|
||||
plugin_manager->RemovePlugin(entries[cur_row]->ui->PathValue->text().toStdString());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Delete the plugin file and refresh the GUI |
|
||||
\*-----------------------------------------------------*/
|
||||
filesystem::remove(entries[cur_row]->ui->PathValue->text().toStdString());
|
||||
|
||||
delete entries[cur_row];
|
||||
entries.erase(entries.begin() + cur_row);
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
void Ui::OpenRGBPluginsPage::on_EnableButton_clicked(OpenRGBPluginsEntry* entry)
|
||||
|
||||
Reference in New Issue
Block a user