MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / update

Method update

app/src/API/Handlers/WorkspacesHandler.cpp:942–1000  ·  view source on GitHub ↗

* @brief Patches workspace title and/or icon by id. */

Source from the content-addressed store, hash-verified

940 * @brief Patches workspace title and/or icon by id.
941 */
942API::CommandResponse API::Handlers::WorkspacesHandler::update(const QString& id,
943 const QJsonObject& params)
944{
945 if (!inProjectFileMode())
946 return CommandResponse::makeError(
947 id, ErrorCode::InvalidParam, QStringLiteral("Workspace mutations require ProjectFile mode"));
948
949 if (!params.contains(QStringLiteral("id")))
950 return CommandResponse::makeError(
951 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: id"));
952
953 auto& pm = DataModel::ProjectModel::instance();
954 if (!pm.customizeWorkspaces())
955 return CommandResponse::makeError(
956 id,
957 ErrorCode::InvalidParam,
958 QStringLiteral("customizeWorkspaces is off; call project.workspace.setCustomizeMode first"));
959
960 const int wid = params.value(QStringLiteral("id")).toInt();
961 const bool setTitle = params.contains(QStringLiteral("title"));
962 const bool setIcon = params.contains(QStringLiteral("icon"));
963 const bool setDescription = params.contains(QStringLiteral("description"));
964 if (!setTitle && !setIcon && !setDescription)
965 return CommandResponse::makeError(id,
966 ErrorCode::InvalidParam,
967 QStringLiteral("Provide at least one of: title, icon, "
968 "description"));
969
970 QString title;
971 QString icon;
972 QString description;
973 if (setTitle) {
974 title = params.value(QStringLiteral("title")).toString();
975 if (title.trimmed().isEmpty())
976 return CommandResponse::makeError(
977 id, ErrorCode::InvalidParam, QStringLiteral("Workspace title cannot be empty"));
978 }
979 if (setIcon)
980 icon = params.value(QStringLiteral("icon")).toString();
981
982 if (setDescription)
983 description = params.value(QStringLiteral("description")).toString();
984
985 pm.updateWorkspace(wid, title, icon, description, setTitle, setIcon, setDescription);
986
987 QJsonObject result;
988 result[QStringLiteral("id")] = wid;
989 if (setTitle)
990 result[QStringLiteral("title")] = title;
991
992 if (setIcon)
993 result[QStringLiteral("icon")] = icon;
994
995 if (setDescription)
996 result[QStringLiteral("description")] = description;
997
998 result[QStringLiteral("updated")] = true;
999 return CommandResponse::makeSuccess(id, result);

Callers 1

WindowMethod · 0.45

Calls 6

inProjectFileModeFunction · 0.85
customizeWorkspacesMethod · 0.80
isEmptyMethod · 0.80
updateWorkspaceMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected