* @brief Save project */
| 1614 | * @brief Save project |
| 1615 | */ |
| 1616 | API::CommandResponse API::Handlers::ProjectHandler::fileSave(const QString& id, |
| 1617 | const QJsonObject& params) |
| 1618 | { |
| 1619 | const QString explicit_path = params.value(QStringLiteral("filePath")).toString(); |
| 1620 | |
| 1621 | DataModel::ProjectModel::instance().setSuppressMessageBoxes(true); |
| 1622 | bool success = false; |
| 1623 | if (!explicit_path.isEmpty()) { |
| 1624 | if (!API::isPathAllowed(explicit_path)) { |
| 1625 | DataModel::ProjectModel::instance().setSuppressMessageBoxes(false); |
| 1626 | return CommandResponse::makeError( |
| 1627 | id, ErrorCode::InvalidParam, QStringLiteral("filePath is not allowed")); |
| 1628 | } |
| 1629 | |
| 1630 | success = DataModel::ProjectModel::instance().apiSaveJsonFile(explicit_path); |
| 1631 | } else { |
| 1632 | const bool ask_path = params.value(QStringLiteral("askPath")).toBool(false); |
| 1633 | success = DataModel::ProjectModel::instance().saveJsonFile(ask_path); |
| 1634 | } |
| 1635 | |
| 1636 | DataModel::ProjectModel::instance().setSuppressMessageBoxes(false); |
| 1637 | |
| 1638 | if (!success) { |
| 1639 | return CommandResponse::makeError( |
| 1640 | id, ErrorCode::OperationFailed, QStringLiteral("Failed to save project")); |
| 1641 | } |
| 1642 | |
| 1643 | QJsonObject result; |
| 1644 | result[QStringLiteral("saved")] = true; |
| 1645 | result[QStringLiteral("filePath")] = DataModel::ProjectModel::instance().jsonFilePath(); |
| 1646 | return CommandResponse::makeSuccess(id, result); |
| 1647 | } |
| 1648 | |
| 1649 | //-------------------------------------------------------------------------------------------------- |
| 1650 | // Getters |
nothing calls this directly
no test coverage detected