| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
|---|---|
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "configure.h" |
| 6 | |
| 7 | #include "common/common.h" |
| 8 | |
| 9 | QString Configure::filePath() |
| 10 | { |
| 11 | return CustomPaths::user(CustomPaths::Flags::Configures) |
| 12 | + QDir::separator() + "user_action_analyse.support"; |
| 13 | } |
| 14 | |
| 15 | QJsonDocument Configure::doc() |
| 16 | { |
| 17 | QJsonDocument doc; |
| 18 | QFile file(filePath()); |
| 19 | if (!file.exists()) { |
| 20 | if (file.open(QFile::ReadWrite | QFile::NewOnly)) { |
| 21 | QJsonObject defaultConf{ {"enabled", false} }; |
| 22 | doc.setObject(defaultConf); |
| 23 | file.write(doc.toJson()); |
| 24 | file.close(); |
| 25 | } |
| 26 | } else { |
| 27 | if (file.open(QFile::ReadOnly)) { |
| 28 | doc = QJsonDocument::fromJson(file.readAll()); |
| 29 | file.close(); |
| 30 | } |
| 31 | } |
| 32 | return doc; |
| 33 | } |
| 34 | |
| 35 | bool Configure::enabled() |
| 36 | { |
| 37 | return doc().object().value("enabled").toBool(); |
| 38 | } |
| 39 | |
| 40 | void Configure::setEnabled(bool enabled) |
| 41 | { |
| 42 | QJsonObject obj = doc().object(); |
| 43 | obj["enabled"] = enabled; |
| 44 | QJsonDocument doc(obj); |
| 45 | QFile file(filePath()); |
| 46 | if (file.open(QFile::WriteOnly)) { |
| 47 | file.write(doc.toJson()); |
| 48 | file.close(); |
| 49 | } |
| 50 | actionanalyse.enabled(enabled); |
| 51 | } |
| 52 |