2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "plugindialog.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <extensionsystem/plugindetailsview.h>
|
|
|
|
#include <extensionsystem/pluginerrorview.h>
|
|
|
|
#include <extensionsystem/pluginspec.h>
|
2016-05-30 23:40:35 +03:00
|
|
|
#include <utils/theme/theme.h>
|
|
|
|
#include <utils/theme/theme_p.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QApplication>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-05-30 23:40:35 +03:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
PluginDialog::PluginDialog()
|
|
|
|
: m_view(new ExtensionSystem::PluginView(this))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
QVBoxLayout *vl = new QVBoxLayout(this);
|
2019-10-01 10:55:29 +02:00
|
|
|
vl->setContentsMargins(0, 0, 0, 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
vl->setSpacing(0);
|
|
|
|
vl->addWidget(m_view);
|
|
|
|
|
|
|
|
QHBoxLayout *hl = new QHBoxLayout;
|
|
|
|
vl->addLayout(hl);
|
2019-10-01 10:55:29 +02:00
|
|
|
hl->setContentsMargins(0, 0, 0, 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
hl->setSpacing(6);
|
2023-02-09 15:26:50 +01:00
|
|
|
m_detailsButton = new QPushButton("Details", this);
|
|
|
|
m_errorDetailsButton = new QPushButton("Error Details", this);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_detailsButton->setEnabled(false);
|
|
|
|
m_errorDetailsButton->setEnabled(false);
|
|
|
|
hl->addWidget(m_detailsButton);
|
|
|
|
hl->addWidget(m_errorDetailsButton);
|
|
|
|
hl->addStretch(5);
|
|
|
|
resize(650, 300);
|
2023-02-09 15:26:50 +01:00
|
|
|
setWindowTitle("Installed Plugins");
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-05-30 23:40:35 +03:00
|
|
|
connect(m_view, &ExtensionSystem::PluginView::currentPluginChanged,
|
|
|
|
this, &PluginDialog::updateButtons);
|
|
|
|
connect(m_view, &ExtensionSystem::PluginView::pluginActivated,
|
|
|
|
this, &PluginDialog::openDetails);
|
|
|
|
connect(m_detailsButton, &QAbstractButton::clicked, this, [this]() { openDetails(); });
|
|
|
|
connect(m_errorDetailsButton, &QAbstractButton::clicked, this, &PluginDialog::openErrorDetails);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginDialog::updateButtons()
|
|
|
|
{
|
|
|
|
ExtensionSystem::PluginSpec *selectedSpec = m_view->currentPlugin();
|
|
|
|
if (selectedSpec) {
|
|
|
|
m_detailsButton->setEnabled(true);
|
|
|
|
m_errorDetailsButton->setEnabled(selectedSpec->hasError());
|
|
|
|
} else {
|
|
|
|
m_detailsButton->setEnabled(false);
|
|
|
|
m_errorDetailsButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PluginDialog::openDetails(ExtensionSystem::PluginSpec *spec)
|
|
|
|
{
|
2016-05-30 23:40:35 +03:00
|
|
|
if (!spec) {
|
|
|
|
spec = m_view->currentPlugin();
|
|
|
|
if (!spec)
|
|
|
|
return;
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
QDialog dialog(this);
|
2023-02-09 15:26:50 +01:00
|
|
|
dialog.setWindowTitle(QString("Plugin Details of %1").arg(spec->name()));
|
2008-12-02 12:01:29 +01:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
|
|
dialog.setLayout(layout);
|
|
|
|
ExtensionSystem::PluginDetailsView *details = new ExtensionSystem::PluginDetailsView(&dialog);
|
|
|
|
layout->addWidget(details);
|
|
|
|
details->update(spec);
|
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
|
|
|
|
layout->addWidget(buttons);
|
2016-05-30 23:40:35 +03:00
|
|
|
connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
2008-12-02 12:01:29 +01:00
|
|
|
dialog.resize(400, 500);
|
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginDialog::openErrorDetails()
|
|
|
|
{
|
|
|
|
ExtensionSystem::PluginSpec *spec = m_view->currentPlugin();
|
|
|
|
if (!spec)
|
|
|
|
return;
|
|
|
|
QDialog dialog(this);
|
2023-02-09 15:26:50 +01:00
|
|
|
dialog.setWindowTitle(QString("Plugin Errors of %1").arg(spec->name()));
|
2008-12-02 12:01:29 +01:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
|
|
dialog.setLayout(layout);
|
|
|
|
ExtensionSystem::PluginErrorView *errors = new ExtensionSystem::PluginErrorView(&dialog);
|
|
|
|
layout->addWidget(errors);
|
|
|
|
errors->update(spec);
|
|
|
|
QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, &dialog);
|
|
|
|
layout->addWidget(buttons);
|
2016-05-30 23:40:35 +03:00
|
|
|
connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
2008-12-02 12:01:29 +01:00
|
|
|
dialog.resize(500, 300);
|
|
|
|
dialog.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
2016-05-30 23:40:35 +03:00
|
|
|
ExtensionSystem::PluginManager manager;
|
2022-02-01 12:05:20 +01:00
|
|
|
manager.setSettings(new QtcSettings);
|
|
|
|
|
2016-05-30 23:40:35 +03:00
|
|
|
manager.setPluginIID(QLatin1String("plugin"));
|
|
|
|
setCreatorTheme(new Theme("default", &app));
|
|
|
|
QObject::connect(&app, &QCoreApplication::aboutToQuit,
|
|
|
|
&manager, &ExtensionSystem::PluginManager::shutdown);
|
|
|
|
PluginDialog dialog;
|
2024-05-07 08:33:02 +02:00
|
|
|
manager.setPluginPaths({FilePath::fromUserInput(app.applicationDirPath()) / "plugins"});
|
2008-12-02 12:01:29 +01:00
|
|
|
manager.loadPlugins();
|
|
|
|
dialog.show();
|
|
|
|
app.exec();
|
2016-05-30 23:40:35 +03:00
|
|
|
return 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|