2022-12-12 16:45:31 +01:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
|
2022-11-28 09:48:11 +01:00
|
|
|
|
|
|
|
|
#include "axivionplugin.h"
|
|
|
|
|
|
|
|
|
|
#include "axivionoutputpane.h"
|
2022-12-13 11:17:12 +01:00
|
|
|
#include "axivionprojectsettings.h"
|
2022-12-14 12:11:03 +01:00
|
|
|
#include "axivionquery.h"
|
|
|
|
|
#include "axivionresultparser.h"
|
2022-11-28 09:48:11 +01:00
|
|
|
#include "axivionsettings.h"
|
|
|
|
|
#include "axivionsettingspage.h"
|
2022-12-13 11:17:12 +01:00
|
|
|
#include "axiviontr.h"
|
2022-11-28 09:48:11 +01:00
|
|
|
|
2022-12-12 16:45:31 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2022-12-14 12:11:03 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2022-12-12 16:45:31 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2022-12-13 11:17:12 +01:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/projectpanelfactory.h>
|
2022-12-14 12:11:03 +01:00
|
|
|
#include <projectexplorer/session.h>
|
2022-12-13 11:17:12 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2022-11-28 09:48:11 +01:00
|
|
|
|
|
|
|
|
#ifdef LICENSECHECKER
|
|
|
|
|
# include <licensechecker/licensecheckerplugin.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-12-13 15:13:13 +01:00
|
|
|
#include <QMessageBox>
|
2022-12-14 12:11:03 +01:00
|
|
|
#include <QTimer>
|
2022-12-13 15:13:13 +01:00
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
namespace Axivion::Internal {
|
|
|
|
|
|
2022-12-14 12:11:03 +01:00
|
|
|
class AxivionPluginPrivate : public QObject
|
2022-11-28 09:48:11 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2022-12-14 12:11:03 +01:00
|
|
|
void fetchProjectInfo(const QString &projectName);
|
|
|
|
|
void handleProjectInfo(const ProjectInfo &info);
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
AxivionSettings axivionSettings;
|
|
|
|
|
AxivionSettingsPage axivionSettingsPage{&axivionSettings};
|
|
|
|
|
AxivionOutputPane axivionOutputPane;
|
2022-12-13 11:17:12 +01:00
|
|
|
QHash<ProjectExplorer::Project *, AxivionProjectSettings *> projectSettings;
|
2022-12-14 12:11:03 +01:00
|
|
|
ProjectInfo currentProjectInfo;
|
|
|
|
|
bool runningQuery = false;
|
2022-11-28 09:48:11 +01:00
|
|
|
};
|
|
|
|
|
|
2022-12-13 15:13:13 +01:00
|
|
|
static AxivionPlugin *s_instance = nullptr;
|
2022-12-13 11:17:12 +01:00
|
|
|
static AxivionPluginPrivate *dd = nullptr;
|
|
|
|
|
|
2022-12-13 15:13:13 +01:00
|
|
|
AxivionPlugin::AxivionPlugin()
|
|
|
|
|
{
|
|
|
|
|
s_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
AxivionPlugin::~AxivionPlugin()
|
|
|
|
|
{
|
2022-12-13 11:17:12 +01:00
|
|
|
if (!dd->projectSettings.isEmpty()) {
|
|
|
|
|
qDeleteAll(dd->projectSettings);
|
|
|
|
|
dd->projectSettings.clear();
|
|
|
|
|
}
|
|
|
|
|
delete dd;
|
|
|
|
|
dd = nullptr;
|
2022-11-28 09:48:11 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-13 15:13:13 +01:00
|
|
|
AxivionPlugin *AxivionPlugin::instance()
|
|
|
|
|
{
|
|
|
|
|
return s_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
bool AxivionPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(errorMessage)
|
|
|
|
|
|
|
|
|
|
#ifdef LICENSECHECKER
|
|
|
|
|
LicenseChecker::LicenseCheckerPlugin *licenseChecker
|
|
|
|
|
= ExtensionSystem::PluginManager::getObject<LicenseChecker::LicenseCheckerPlugin>();
|
|
|
|
|
|
|
|
|
|
if (!licenseChecker || !licenseChecker->hasValidLicense() || !licenseChecker->enterpriseFeatures())
|
|
|
|
|
return true;
|
|
|
|
|
#endif // LICENSECHECKER
|
|
|
|
|
|
2022-12-13 11:17:12 +01:00
|
|
|
dd = new AxivionPluginPrivate;
|
|
|
|
|
dd->axivionSettings.fromSettings(Core::ICore::settings());
|
|
|
|
|
|
|
|
|
|
auto panelFactory = new ProjectExplorer::ProjectPanelFactory;
|
|
|
|
|
panelFactory->setPriority(250);
|
|
|
|
|
panelFactory->setDisplayName(Tr::tr("Axivion"));
|
|
|
|
|
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project){
|
|
|
|
|
return new AxivionProjectSettingsWidget(project);
|
|
|
|
|
});
|
|
|
|
|
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
|
2022-12-14 12:11:03 +01:00
|
|
|
connect(ProjectExplorer::SessionManager::instance(),
|
|
|
|
|
&ProjectExplorer::SessionManager::startupProjectChanged,
|
|
|
|
|
this, &AxivionPlugin::onStartupProjectChanged);
|
2022-11-28 09:48:11 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 12:11:03 +01:00
|
|
|
void AxivionPlugin::onStartupProjectChanged()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd, return);
|
|
|
|
|
ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
|
|
|
|
|
if (!project) {
|
|
|
|
|
dd->currentProjectInfo = ProjectInfo();
|
|
|
|
|
dd->axivionOutputPane.updateDashboard();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const AxivionProjectSettings *projSettings = projectSettings(project);
|
|
|
|
|
dd->fetchProjectInfo(projSettings->dashboardProjectName());
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 11:17:12 +01:00
|
|
|
AxivionSettings *AxivionPlugin::settings()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd, return nullptr);
|
|
|
|
|
return &dd->axivionSettings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AxivionProjectSettings *AxivionPlugin::projectSettings(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(project, return nullptr);
|
|
|
|
|
QTC_ASSERT(dd, return nullptr);
|
|
|
|
|
|
|
|
|
|
auto &settings = dd->projectSettings[project];
|
|
|
|
|
if (!settings)
|
|
|
|
|
settings = new AxivionProjectSettings(project);
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 15:13:13 +01:00
|
|
|
bool AxivionPlugin::handleCertificateIssue()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd, return false);
|
|
|
|
|
|
|
|
|
|
const QString serverHost = QUrl(dd->axivionSettings.server.dashboard).host();
|
|
|
|
|
if (QMessageBox::question(Core::ICore::dialogParent(), Tr::tr("Certificate Error"),
|
|
|
|
|
Tr::tr("Server certificate for %1 cannot be authenticated.\n"
|
|
|
|
|
"Do you want to disable SSL verification for this server?\n"
|
|
|
|
|
"Note: This can expose you to man-in-the-middle attack.")
|
|
|
|
|
.arg(serverHost))
|
|
|
|
|
!= QMessageBox::Yes) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
dd->axivionSettings.server.validateCert = false;
|
|
|
|
|
emit s_instance->settingsChanged();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 12:11:03 +01:00
|
|
|
void AxivionPlugin::fetchProjectInfo(const QString &projectName)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd, return);
|
|
|
|
|
dd->fetchProjectInfo(projectName);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 13:53:00 +01:00
|
|
|
ProjectInfo AxivionPlugin::projectInfo()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(dd, return {});
|
|
|
|
|
return dd->currentProjectInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 12:11:03 +01:00
|
|
|
void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName)
|
|
|
|
|
{
|
|
|
|
|
if (runningQuery) { // re-schedule
|
|
|
|
|
QTimer::singleShot(3000, [this, projectName]{ fetchProjectInfo(projectName); });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (projectName.isEmpty()) {
|
|
|
|
|
currentProjectInfo = ProjectInfo();
|
|
|
|
|
axivionOutputPane.updateDashboard();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
runningQuery = true;
|
|
|
|
|
|
|
|
|
|
AxivionQuery query(AxivionQuery::ProjectInfo, {projectName});
|
|
|
|
|
AxivionQueryRunner *runner = new AxivionQueryRunner(query, this);
|
|
|
|
|
connect(runner, &AxivionQueryRunner::resultRetrieved, this, [this](const QByteArray &result){
|
|
|
|
|
handleProjectInfo(ResultParser::parseProjectInfo(result));
|
|
|
|
|
});
|
|
|
|
|
connect(runner, &AxivionQueryRunner::finished, [runner]{ runner->deleteLater(); });
|
|
|
|
|
runner->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AxivionPluginPrivate::handleProjectInfo(const ProjectInfo &info)
|
|
|
|
|
{
|
|
|
|
|
runningQuery = false;
|
|
|
|
|
if (!info.error.isEmpty()) {
|
|
|
|
|
Core::MessageManager::writeFlashing("Axivion: " + info.error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentProjectInfo = info;
|
|
|
|
|
axivionOutputPane.updateDashboard();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 09:48:11 +01:00
|
|
|
} // Axivion::Internal
|