* @brief Adds a new source (Commercial only). */
| 239 | * @brief Adds a new source (Commercial only). |
| 240 | */ |
| 241 | API::CommandResponse API::Handlers::SourceHandler::sourceAdd(const QString& id, |
| 242 | const QJsonObject& params) |
| 243 | { |
| 244 | (void)params; |
| 245 | |
| 246 | #ifndef BUILD_COMMERCIAL |
| 247 | return CommandResponse::makeError(id, |
| 248 | QStringLiteral("COMMERCIAL_REQUIRED"), |
| 249 | QStringLiteral("Multiple data sources require a Pro license")); |
| 250 | #else |
| 251 | const int countBefore = DataModel::ProjectModel::instance().sourceCount(); |
| 252 | QMetaObject::invokeMethod(&DataModel::ProjectModel::instance(), "addSource"); |
| 253 | |
| 254 | const int countAfter = DataModel::ProjectModel::instance().sourceCount(); |
| 255 | if (countAfter <= countBefore) |
| 256 | return CommandResponse::makeError( |
| 257 | id, QStringLiteral("OPERATION_FAILED"), QStringLiteral("Failed to add source")); |
| 258 | |
| 259 | QJsonObject result; |
| 260 | result[Keys::SourceId] = countAfter - 1; |
| 261 | return CommandResponse::makeSuccess(id, result); |
| 262 | #endif |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * @brief Deletes a source (Commercial only; sourceId must be >= 1). |
nothing calls this directly
no test coverage detected