1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "valgrindreceiver.h"
6#include "mainframe/valgrindrunner.h"
7
8#include "services/project/projectinfo.h"
9#include "services/project/projectservice.h"
10#include "services/window/windowelement.h"
11#include "services/project/projectgenerator.h"
12#include "services/builder/builderglobals.h"
13#include "common/common.h"
14
15ValgrindReceiver::ValgrindReceiver(QObject *parent)
16 : dpf::EventHandler (parent)
17 , dpf::AutoEventHandlerRegister<ValgrindReceiver> ()
18{
19
20}
21
22dpf::EventHandler::Type ValgrindReceiver::type()
23{
24 return dpf::EventHandler::Type::Sync;
25}
26
27QStringList ValgrindReceiver::topics()
28{
29 return {project.topic, editor.topic};
30}
31
32void ValgrindReceiver::eventProcess(const dpf::Event &event)
33{
34 if (event.data() == project.activedProject.name) {
35 QVariant proInfoVar = event.property(project.activedProject.pKeys[0]);
36 dpfservice::ProjectInfo projectInfo = qvariant_cast<dpfservice::ProjectInfo>(proInfoVar);
37 QString buildFolder = projectInfo.buildFolder();
38 ValgrindRunner::instance()->saveCurrentProjectInfo(projectInfo);
39 } else if (event.data() == project.createdProject.name) {
40 QVariant proInfoVar = event.property(project.createdProject.pKeys[0]);
41 dpfservice::ProjectInfo projectInfo = qvariant_cast<dpfservice::ProjectInfo>(proInfoVar);
42 QString buildFolder = projectInfo.buildFolder();
43 ValgrindRunner::instance()->saveCurrentProjectInfo(projectInfo);
44 } else if (event.data() == project.deletedProject.name) {
45 QVariant proInfoVar = event.property(project.deletedProject.pKeys[0]);
46 dpfservice::ProjectInfo projectInfo = qvariant_cast<dpfservice::ProjectInfo>(proInfoVar);
47 ValgrindRunner::instance()->removeProjectInfo();
48 } else if (event.data() == editor.switchedFile.name) {
49 QString filePath = event.property(editor.switchedFile.pKeys[0]).toString();
50 ValgrindRunner::instance()->saveCurrentFilePath(filePath);
51 } else if (event.data() == editor.openedFile.name) {
52 QString filePath = event.property(editor.switchedFile.pKeys[0]).toString();
53 ValgrindRunner::instance()->saveCurrentFilePath(filePath);
54 } else if (event.data() == editor.closedFile.name) {
55 QString filePath = event.property(editor.switchedFile.pKeys[0]).toString();
56 ValgrindRunner::instance()->removeCurrentFilePath();
57 }
58}
59