1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "actionanalysereceiver.h"
6#include "mainframe/analysekeeper.h"
7#include "mainframe/configure.h"
8
9#include "common/common.h"
10
11ActionAnalyseReceiver::ActionAnalyseReceiver(QObject *parent)
12 : dpf::EventHandler (parent)
13 , dpf::AutoEventHandlerRegister<ActionAnalyseReceiver> ()
14{
15
16}
17
18dpf::EventHandler::Type ActionAnalyseReceiver::type()
19{
20 return dpf::EventHandler::Type::Sync;
21}
22
23QStringList ActionAnalyseReceiver::topics()
24{
25 return {actionanalyse.topic, symbol.topic};
26}
27
28void ActionAnalyseReceiver::eventProcess(const dpf::Event &event)
29{
30 if (Configure::enabled()) {
31 if (event.data() == actionanalyse.analyse.name) { // "workspace", "language", "storage"
32 QString workspaceKey = actionanalyse.analyseDone.pKeys[0]; // workspace
33 QString languageKey = actionanalyse.analyseDone.pKeys[1]; // language
34 QString storageKey = actionanalyse.analyseDone.pKeys[2]; // storage
35 QString dataKey = actionanalyse.analyseDone.pKeys[3];
36 QString workspace = event.property(workspaceKey).toString();
37 QString language = event.property(languageKey).toString();
38 QString storage = event.property(storageKey).toString();
39 QVariant var = event.property(dataKey);
40 AnalysedData analyData = var.value<AnalysedData>();
41 AnalyseKeeper::instance()->doAnalyse({workspace, language, storage});
42 } else if (event.data() == symbol.parseDone.name) {
43 bool bSuccess = event.property("success").toBool();
44 if(bSuccess) {
45 QString workspace = event.property("workspace").toString();
46 QString language = event.property("language").toString();
47 const QString &storage = workspace;
48 AnalyseKeeper::instance()->doAnalyse({workspace, language, storage});
49 }
50 }
51 }
52}
53