1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "projectcmakereceiver.h"
6#include "cmake/project/mainframe/cmakeprojectgenerator.h"
7#include "cmake/project/mainframe/properties/targetsmanager.h"
8
9#include "services/project/projectinfo.h"
10#include "services/project/projectservice.h"
11#include "services/window/windowelement.h"
12#include "services/project/projectgenerator.h"
13#include "services/builder/builderglobals.h"
14#include "common/common.h"
15
16ProjectCmakeReceiver::ProjectCmakeReceiver(QObject *parent)
17 : dpf::EventHandler (parent)
18 , dpf::AutoEventHandlerRegister<ProjectCmakeReceiver> ()
19{
20
21}
22
23dpf::EventHandler::Type ProjectCmakeReceiver::type()
24{
25 return dpf::EventHandler::Type::Sync;
26}
27
28QStringList ProjectCmakeReceiver::topics()
29{
30 return { T_BUILDER, project.topic};
31}
32
33void ProjectCmakeReceiver::eventProcess(const dpf::Event &event)
34{
35 if (event.topic() == T_BUILDER) {
36 navigation.doSwitch(dpfservice::MWNA_EDIT);
37 builderEvent(event);
38 }
39
40 if (event.data() == project.activedProject.name) {
41 QVariant proInfoVar = event.property(project.activedProject.pKeys[0]);
42 dpfservice::ProjectInfo projectInfo = qvariant_cast<dpfservice::ProjectInfo>(proInfoVar);
43 TargetsManager::instance()->readTargets(projectInfo.buildFolder(), projectInfo.workspaceFolder());
44 }
45}
46
47void ProjectCmakeReceiver::builderEvent(const dpf::Event &event)
48{
49 if (event.data() == D_BUILD_STATE) {
50 BuildCommandInfo commandInfo = qvariant_cast<BuildCommandInfo>(event.property(P_ORIGINCMD));
51 if (ProjectCmakeProxy::instance()->getBuildCommandUuid() == commandInfo.uuid) {
52 int endStatus = event.property(P_STATE).toInt();
53 if (0 == endStatus) {
54 emit ProjectCmakeProxy::instance()->buildExecuteEnd(commandInfo);
55 } else {
56 // ContextDialog::ok(QDialog::tr("Failed open project, with build step."));
57 }
58 }
59 }
60}
61
62ProjectCmakeProxy *ProjectCmakeProxy::instance()
63{
64 static ProjectCmakeProxy ins;
65 return &ins;
66}
67
68void ProjectCmakeProxy::setBuildCommandUuid(QString buildCommandUuid)
69{
70 ProjectCmakeProxy::buildCommandUuid = buildCommandUuid;
71}
72
73QString ProjectCmakeProxy::getBuildCommandUuid()
74{
75 return buildCommandUuid;
76}
77