PluginManagerWindow.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /******************************************************************************
  2. Copyright (C) 2025 by FiniteSingularity <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "PluginManagerWindow.hpp"
  15. #include <OBSApp.hpp>
  16. #include <QCheckBox>
  17. #include <QDialogButtonBox>
  18. #include <QHBoxLayout>
  19. #include <QLabel>
  20. #include <QScrollArea>
  21. #include <QString>
  22. #include <QVBoxLayout>
  23. #include "moc_PluginManagerWindow.cpp"
  24. namespace OBS {
  25. PluginManagerWindow::PluginManagerWindow(std::vector<ModuleInfo> const &modules, QWidget *parent)
  26. : QDialog(parent),
  27. modules_(modules),
  28. ui(new Ui::PluginManagerWindow)
  29. {
  30. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  31. ui->setupUi(this);
  32. std::sort(modules_.begin(), modules_.end(), [](const ModuleInfo &a, const ModuleInfo &b) {
  33. std::string aName = !a.display_name.empty() ? a.display_name : a.module_name;
  34. std::string bName = !b.display_name.empty() ? b.display_name : b.module_name;
  35. return aName < bName;
  36. });
  37. for (auto &metadata : modules_) {
  38. std::string id = metadata.module_name;
  39. // Check if the module is missing:
  40. bool missing = !obs_get_module(id.c_str()) && !obs_get_disabled_module(id.c_str());
  41. QString name = !metadata.display_name.empty() ? metadata.display_name.c_str()
  42. : metadata.module_name.c_str();
  43. if (missing) {
  44. name += " " + QTStr("PluginManager.MissingPlugin");
  45. }
  46. auto item = new QListWidgetItem(name);
  47. item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
  48. item->setCheckState(metadata.enabled ? Qt::Checked : Qt::Unchecked);
  49. if (missing) {
  50. item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
  51. }
  52. ui->modulesList->addItem(item);
  53. }
  54. connect(ui->modulesList, &QListWidget::itemChanged, this, [this](QListWidgetItem *item) {
  55. auto row = ui->modulesList->row(item);
  56. bool checked = item->checkState() == Qt::Checked;
  57. modules_[row].enabled = checked;
  58. });
  59. connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
  60. connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
  61. }
  62. }; // namespace OBS