Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| OpenRGBPluginsEntry.cpp |
|
||||
| |
|
||||
| User interface entry for OpenRGB plugin entry widget |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "OpenRGBPluginsEntry.h"
|
||||
#include "ui_OpenRGBPluginsEntry.h"
|
||||
#include "PluginManager.h"
|
||||
|
||||
OpenRGBPluginsEntry::OpenRGBPluginsEntry(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBPluginsEntry)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
EnableClickCallbackVal = nullptr;
|
||||
EnableClickCallbackArg = nullptr;
|
||||
}
|
||||
|
||||
OpenRGBPluginsEntry::~OpenRGBPluginsEntry()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OpenRGBPluginsEntry::fillFrom(const OpenRGBPluginEntry *plugin)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Fill in plugin information fields |
|
||||
\*---------------------------------------------------------*/
|
||||
ui->NameValue->setText(QString::fromStdString(plugin->info.Name));
|
||||
ui->DescriptionValue->setText(QString::fromStdString(plugin->info.Description));
|
||||
ui->VersionValue->setText(QString::fromStdString(plugin->info.Version));
|
||||
ui->CommitValue->setText(QString::fromStdString(plugin->info.Commit));
|
||||
ui->URLValue->setText(QString::fromStdString(plugin->info.URL));
|
||||
ui->APIVersionValue->setText(QString::number(plugin->api_version));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| If the plugin is incompatible, highlight the API version |
|
||||
| in red and disable the enable checkbox |
|
||||
\*---------------------------------------------------------*/
|
||||
if(plugin->incompatible)
|
||||
{
|
||||
ui->APIVersionValue->setStyleSheet("QLabel { color : red; }");
|
||||
ui->EnabledCheckBox->setEnabled(false);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Fill in plugin icon |
|
||||
\*---------------------------------------------------------*/
|
||||
QPixmap pixmap(QPixmap::fromImage(plugin->info.Icon));
|
||||
|
||||
ui->IconView->setPixmap(pixmap);
|
||||
ui->IconView->setScaledContents(true);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Fill in plugin path |
|
||||
\*---------------------------------------------------------*/
|
||||
ui->PathValue->setText(QString::fromStdString(plugin->path));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Fill in plugin enabled status |
|
||||
\*---------------------------------------------------------*/
|
||||
ui->EnabledCheckBox->setChecked((plugin->enabled));
|
||||
|
||||
is_system = plugin->is_system;
|
||||
}
|
||||
|
||||
bool OpenRGBPluginsEntry::isSystem() const
|
||||
{
|
||||
return is_system;
|
||||
}
|
||||
|
||||
bool OpenRGBPluginsEntry::isPluginEnabled() const
|
||||
{
|
||||
return ui->EnabledCheckBox->isChecked();
|
||||
}
|
||||
|
||||
std::string OpenRGBPluginsEntry::getName() const
|
||||
{
|
||||
return ui->NameValue->text().toStdString();
|
||||
}
|
||||
|
||||
std::string OpenRGBPluginsEntry::getDescription() const
|
||||
{
|
||||
return ui->DescriptionValue->text().toStdString();
|
||||
}
|
||||
|
||||
std::string OpenRGBPluginsEntry::getPath() const
|
||||
{
|
||||
return ui->PathValue->text().toStdString();
|
||||
}
|
||||
|
||||
void OpenRGBPluginsEntry::changeEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginsEntry::RegisterEnableClickCallback(EnableClickCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
EnableClickCallbackVal = new_callback;
|
||||
EnableClickCallbackArg = new_callback_arg;
|
||||
}
|
||||
|
||||
void OpenRGBPluginsEntry::on_EnabledCheckBox_stateChanged(int /*checked*/)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
if(EnableClickCallbackVal != nullptr)
|
||||
{
|
||||
EnableClickCallbackVal(EnableClickCallbackArg, this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| OpenRGBPluginsEntry.h |
|
||||
| |
|
||||
| User interface entry for OpenRGB plugin entry widget |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class OpenRGBPluginsEntry;
|
||||
}
|
||||
|
||||
typedef void (*EnableClickCallback)(void *, void *);
|
||||
|
||||
struct OpenRGBPluginEntry;
|
||||
|
||||
class OpenRGBPluginsEntry : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBPluginsEntry(QWidget *parent = nullptr);
|
||||
~OpenRGBPluginsEntry();
|
||||
void fillFrom(const OpenRGBPluginEntry* plugin);
|
||||
bool isSystem() const;
|
||||
bool isPluginEnabled() const;
|
||||
std::string getName() const;
|
||||
std::string getDescription() const;
|
||||
std::string getPath() const;
|
||||
|
||||
|
||||
void RegisterEnableClickCallback(EnableClickCallback new_callback, void * new_callback_arg);
|
||||
|
||||
private slots:
|
||||
void changeEvent(QEvent *event);
|
||||
void on_EnabledCheckBox_stateChanged(int checked);
|
||||
|
||||
private:
|
||||
EnableClickCallback EnableClickCallbackVal;
|
||||
void * EnableClickCallbackArg;
|
||||
Ui::OpenRGBPluginsEntry * ui;
|
||||
bool is_system;
|
||||
};
|
||||
@@ -0,0 +1,197 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBPluginsEntry</class>
|
||||
<widget class="QWidget" name="OpenRGBPluginsEntry">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>478</width>
|
||||
<height>238</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Plugins Entry</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="5" column="1">
|
||||
<widget class="QLabel" name="URLLabel">
|
||||
<property name="text">
|
||||
<string>URL:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="8">
|
||||
<widget class="QLabel" name="IconView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Icon</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QLabel" name="URLValue">
|
||||
<property name="text">
|
||||
<string notr="true">URL Value</string>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QLabel" name="EnabledLabel">
|
||||
<property name="text">
|
||||
<string>Enabled</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<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="2">
|
||||
<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 notr="true">Name Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="PathValue">
|
||||
<property name="text">
|
||||
<string notr="true">Path Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="VersionValue">
|
||||
<property name="text">
|
||||
<string notr="true">Version Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QLabel" name="CommitValue">
|
||||
<property name="text">
|
||||
<string notr="true">Commit Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<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="2" column="1">
|
||||
<widget class="QLabel" name="PathLabel">
|
||||
<property name="text">
|
||||
<string>Path:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="2">
|
||||
<widget class="QCheckBox" name="EnabledCheckBox">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="VersionLabel">
|
||||
<property name="text">
|
||||
<string>Version:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="CommitLabel">
|
||||
<property name="text">
|
||||
<string>Commit:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<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 notr="true">Description Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="APIVersionLabel">
|
||||
<property name="text">
|
||||
<string>API Version:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<widget class="QLabel" name="APIVersionValue">
|
||||
<property name="text">
|
||||
<string>API Version Value</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,53 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| OpenRGBPluginsList.cpp |
|
||||
| |
|
||||
| User interface entry for OpenRGB plugin list widget |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
#include "OpenRGBPluginsList.h"
|
||||
|
||||
OpenRGBPluginsList::OpenRGBPluginsList(QWidget *parent) : QListWidget (parent)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void OpenRGBPluginsList::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const QMimeData* mimeData = event->mimeData();
|
||||
|
||||
if (mimeData->hasUrls())
|
||||
{
|
||||
std::vector<std::string> path_list;
|
||||
|
||||
QList<QUrl> urls = mimeData->urls();
|
||||
|
||||
for(const QUrl& url: urls)
|
||||
{
|
||||
path_list.push_back(url.toLocalFile().toStdString());
|
||||
}
|
||||
|
||||
emit PluginsDropped(path_list);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginsList::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls())
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginsList::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| OpenRGBPluginsList.h |
|
||||
| |
|
||||
| User interface entry for OpenRGB plugin list widget |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QListWidget>
|
||||
#include <QDropEvent>
|
||||
#include <QDragEnterEvent>
|
||||
|
||||
class OpenRGBPluginsList : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OpenRGBPluginsList(QWidget *parent = nullptr);
|
||||
|
||||
signals:
|
||||
void PluginsDropped(std::vector<std::string>);
|
||||
|
||||
protected:
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
};
|
||||
@@ -0,0 +1,346 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| OpenRGBPluginsPage.cpp |
|
||||
| |
|
||||
| User interface entry for OpenRGB plugin settings |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsScene>
|
||||
#include "filesystem.h"
|
||||
#include "LogManager.h"
|
||||
#include "SettingsManager.h"
|
||||
#include "OpenRGBPluginsPage.h"
|
||||
#include "ui_OpenRGBPluginsPage.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
void EnableClickCallbackFunction(void* this_ptr, void* entry_ptr)
|
||||
{
|
||||
OpenRGBPluginsPage* this_page = (OpenRGBPluginsPage*)this_ptr;
|
||||
|
||||
this_page->on_EnableButton_clicked((OpenRGBPluginsEntry*)entry_ptr);
|
||||
}
|
||||
|
||||
OpenRGBPluginsPage::OpenRGBPluginsPage(PluginManager* plugin_manager_ptr, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::OpenRGBPluginsPage)
|
||||
{
|
||||
plugin_manager = plugin_manager_ptr;
|
||||
ui->setupUi(this);
|
||||
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
OpenRGBPluginsPage::~OpenRGBPluginsPage()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void OpenRGBPluginsPage::changeEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginsPage::RefreshList()
|
||||
{
|
||||
ui->PluginsList->clear();
|
||||
entries.clear();
|
||||
|
||||
for(const OpenRGBPluginEntry& plugin: plugin_manager->ActivePlugins)
|
||||
{
|
||||
OpenRGBPluginsEntry* entry = new OpenRGBPluginsEntry();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Fill in plugin information fields |
|
||||
\*---------------------------------------------------------*/
|
||||
entry->fillFrom(&plugin);
|
||||
|
||||
entry->RegisterEnableClickCallback(EnableClickCallbackFunction, this);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Add the entry to the plugin list |
|
||||
\*---------------------------------------------------------*/
|
||||
QListWidgetItem* item = new QListWidgetItem;
|
||||
|
||||
item->setSizeHint(entry->sizeHint());
|
||||
|
||||
ui->PluginsList->addItem(item);
|
||||
ui->PluginsList->setItemWidget(item, entry);
|
||||
|
||||
entries.push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginsPage::on_InstallPluginButton_clicked()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Open a file selection prompt to choose the plugin file|
|
||||
\*-----------------------------------------------------*/
|
||||
QString install_file = QFileDialog::getOpenFileName(this, tr("Install OpenRGB Plugin"), "", tr("Plugin files (*.dll *.dylib *.so *.so.*)"));
|
||||
|
||||
bool installed = InstallPlugin(install_file.toStdString());
|
||||
|
||||
if(installed)
|
||||
{
|
||||
RefreshList();
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenRGBPluginsPage::InstallPlugin(std::string install_file)
|
||||
{
|
||||
filesystem::path from_path = filesystem::u8path(install_file);
|
||||
filesystem::path to_path = ResourceManager::get()->GetConfigurationDirectory() / "plugins" / from_path.filename();
|
||||
bool match = false;
|
||||
|
||||
LOG_TRACE("[OpenRGBPluginsPage] Installing plugin %s", install_file.c_str());
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Check if a plugin with this path already exists |
|
||||
\*-----------------------------------------------------*/
|
||||
for(unsigned int plugin_idx = 0; plugin_idx < plugin_manager->ActivePlugins.size(); plugin_idx++)
|
||||
{
|
||||
if(to_path == plugin_manager->ActivePlugins[plugin_idx].path)
|
||||
{
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If this plugin already exists, prompt to replace it |
|
||||
\*-----------------------------------------------------*/
|
||||
if(match == true)
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
reply = QMessageBox::question(this, tr("Replace Plugin"), tr("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 false;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| When replacing, remove the existing plugin before |
|
||||
| copying the file and adding the new one |
|
||||
\*-----------------------------------------------------*/
|
||||
try
|
||||
{
|
||||
plugin_manager->RemovePlugin(to_path);
|
||||
|
||||
LOG_TRACE("[OpenRGBPluginsPage] Copying from %s to %s", from_path.c_str(), to_path.c_str());
|
||||
filesystem::copy(from_path, to_path, filesystem::copy_options::overwrite_existing);
|
||||
|
||||
plugin_manager->AddPlugin(to_path, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
LOG_ERROR("[OpenRGBPluginsPage] Failed to install plugin: %s", e.what());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OpenRGBPluginsPage::on_RemovePluginButton_clicked()
|
||||
{
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Confirm plugin removal with message box |
|
||||
\*-----------------------------------------------------*/
|
||||
reply = QMessageBox::question(this, tr("Remove Plugin"), tr("Are you sure you want to remove this plugin?"), QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if(reply != QMessageBox::Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get index of selected plugin entry |
|
||||
\*-----------------------------------------------------*/
|
||||
int cur_row = ui->PluginsList->currentRow();
|
||||
|
||||
if(cur_row < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Don't allow removing system plugins |
|
||||
\*-----------------------------------------------------*/
|
||||
if(entries[cur_row]->isSystem())
|
||||
{
|
||||
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]->getName())
|
||||
&&(plugin_settings["plugins"][plugin_idx]["description"] == entries[cur_row]->getDescription()))
|
||||
{
|
||||
/*-------------------------------------*\
|
||||
| Remove plugin from settings |
|
||||
\*-------------------------------------*/
|
||||
plugin_settings["plugins"].erase(plugin_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Mark plugin to be removed on next restart |
|
||||
\*-----------------------------------------------------*/
|
||||
plugin_settings["plugins_remove"][plugin_settings["plugins_remove"].size()] = entries[cur_row]->getPath();
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
|
||||
QMessageBox::information(this, tr("Restart Needed"), tr("The plugin will be fully removed after restarting OpenRGB."), QMessageBox::Ok);
|
||||
}
|
||||
|
||||
void OpenRGBPluginsPage::on_EnableButton_clicked(OpenRGBPluginsEntry* entry)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Open plugin list and check if plugin is in the list |
|
||||
\*-----------------------------------------------------*/
|
||||
json plugin_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Plugins");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Search the settings to find the correct index |
|
||||
\*-----------------------------------------------------*/
|
||||
std::string name = "";
|
||||
std::string description = "";
|
||||
bool enabled = entry->isPluginEnabled();
|
||||
bool found = false;
|
||||
unsigned int plugin_ct = 0;
|
||||
unsigned int plugin_idx = 0;
|
||||
|
||||
std::string entry_name = entry->getName();
|
||||
std::string entry_desc = entry->getDescription();
|
||||
std::string entry_path = entry->getPath();
|
||||
|
||||
if(plugin_settings.contains("plugins"))
|
||||
{
|
||||
plugin_ct = (unsigned int)plugin_settings["plugins"].size();
|
||||
|
||||
for(plugin_idx = 0; plugin_idx < (unsigned int)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((entry_name == name)
|
||||
&&(entry_desc == description))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| If the plugin was not in the list, add it to the list |
|
||||
| and default it to enabled, then save the settings |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!found)
|
||||
{
|
||||
plugin_settings["plugins"][plugin_ct]["name"] = entry_name;
|
||||
plugin_settings["plugins"][plugin_ct]["description"] = entry_desc;
|
||||
plugin_settings["plugins"][plugin_ct]["enabled"] = enabled;
|
||||
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin_settings["plugins"][plugin_idx]["enabled"] = enabled;
|
||||
ResourceManager::get()->GetSettingsManager()->SetSettings("Plugins", plugin_settings);
|
||||
ResourceManager::get()->GetSettingsManager()->SaveSettings();
|
||||
}
|
||||
|
||||
if(enabled)
|
||||
{
|
||||
plugin_manager->EnablePlugin(entry_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin_manager->DisablePlugin(entry_path);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginsPage::on_PluginsList_itemSelectionChanged()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Get index of selected plugin entry |
|
||||
\*-----------------------------------------------------*/
|
||||
int cur_row = ui->PluginsList->currentRow();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Disable the remove button if no item selected |
|
||||
\*-----------------------------------------------------*/
|
||||
if(cur_row == -1)
|
||||
{
|
||||
ui->RemovePluginButton->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Enable the remove button when there's a selected item |
|
||||
| and the selected item is not a system plugin |
|
||||
\*-----------------------------------------------------*/
|
||||
if(!entries[cur_row]->isSystem())
|
||||
{
|
||||
ui->RemovePluginButton->setEnabled(!ui->PluginsList->selectedItems().empty());
|
||||
ui->RemovePluginButton->setText("Remove Plugin");
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->RemovePluginButton->setEnabled(false);
|
||||
ui->RemovePluginButton->setText("System Plugin - Cannot Remove");
|
||||
}
|
||||
}
|
||||
|
||||
void OpenRGBPluginsPage::on_PluginsList_PluginsDropped(std::vector<std::string> path_list)
|
||||
{
|
||||
bool installed = false;
|
||||
|
||||
for(const std::string& file_path: path_list)
|
||||
{
|
||||
installed |= InstallPlugin(file_path);
|
||||
}
|
||||
|
||||
if(installed)
|
||||
{
|
||||
RefreshList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| OpenRGBPluginsPage.h |
|
||||
| |
|
||||
| User interface entry for OpenRGB plugin settings |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include "OpenRGBPluginsEntry.h"
|
||||
#include "PluginManager.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class OpenRGBPluginsPage;
|
||||
}
|
||||
|
||||
class OpenRGBPluginsPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBPluginsPage(PluginManager* plugin_manager_ptr, QWidget *parent = nullptr);
|
||||
~OpenRGBPluginsPage();
|
||||
|
||||
void on_EnableButton_clicked(OpenRGBPluginsEntry* entry);
|
||||
void RefreshList();
|
||||
|
||||
private slots:
|
||||
void changeEvent(QEvent *event);
|
||||
void on_InstallPluginButton_clicked();
|
||||
|
||||
void on_RemovePluginButton_clicked();
|
||||
|
||||
void on_PluginsList_itemSelectionChanged();
|
||||
|
||||
void on_PluginsList_PluginsDropped(std::vector<std::string>);
|
||||
|
||||
private:
|
||||
Ui::OpenRGBPluginsPage* ui;
|
||||
PluginManager* plugin_manager;
|
||||
std::vector<OpenRGBPluginsEntry*> entries;
|
||||
|
||||
bool InstallPlugin(std::string path);
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBPluginsPage</class>
|
||||
<widget class="QWidget" name="OpenRGBPluginsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Plugins Page</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="OpenRGBPluginsList" name="PluginsList">
|
||||
<property name="verticalScrollMode">
|
||||
<enum>QAbstractItemView::ScrollPerPixel</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="InstallPluginButton">
|
||||
<property name="text">
|
||||
<string>Install Plugin</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QPushButton" name="RemovePluginButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove Plugin</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="LinkLabel">
|
||||
<property name="text">
|
||||
<string><html><head/><body>Looking for plugins? See the official list at <a href="https://openrgb.org/plugins.html">OpenRGB.org</a></body></html></string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>OpenRGBPluginsList</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>qt/OpenRGBPluginsPage/OpenRGBPluginsList.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user