* @brief Resolves a workspace by id or title against project.workspace.list. */
| 826 | * @brief Resolves a workspace by id or title against project.workspace.list. |
| 827 | */ |
| 828 | static QJsonObject resolveWorkspace(const QJsonObject& args) |
| 829 | { |
| 830 | const auto listReply = runCommand(QStringLiteral("project.workspace.list")); |
| 831 | if (!listReply.value(QStringLiteral("ok")).toBool()) |
| 832 | return listReply; |
| 833 | |
| 834 | const auto list = listReply.value(QStringLiteral("result")).toObject(); |
| 835 | const auto rows = list.value(QStringLiteral("workspaces")).toArray(); |
| 836 | const int wantedId = args.value(QStringLiteral("workspaceId")).toInt(-1); |
| 837 | const QString title = args.value(QStringLiteral("title")).toString(); |
| 838 | const auto titleFold = title.toCaseFolded(); |
| 839 | |
| 840 | if (wantedId < 0 && title.isEmpty() && !rows.isEmpty()) { |
| 841 | QJsonObject out; |
| 842 | out[QStringLiteral("ok")] = true; |
| 843 | out[QStringLiteral("workspace")] = rows.first().toObject(); |
| 844 | out[QStringLiteral("defaulted")] = true; |
| 845 | out[QStringLiteral("hint")] = |
| 846 | QStringLiteral("No workspace was specified, so the first active workspace was selected."); |
| 847 | return out; |
| 848 | } |
| 849 | |
| 850 | for (const auto& value : rows) { |
| 851 | const auto row = value.toObject(); |
| 852 | if (wantedId >= 0 && row.value(QStringLiteral("id")).toInt() == wantedId) { |
| 853 | QJsonObject out; |
| 854 | out[QStringLiteral("ok")] = true; |
| 855 | out[QStringLiteral("workspace")] = row; |
| 856 | return out; |
| 857 | } |
| 858 | |
| 859 | if (!title.isEmpty() |
| 860 | && row.value(QStringLiteral("title")).toString().toCaseFolded() == titleFold) { |
| 861 | QJsonObject out; |
| 862 | out[QStringLiteral("ok")] = true; |
| 863 | out[QStringLiteral("workspace")] = row; |
| 864 | return out; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | QJsonObject out; |
| 869 | out[QStringLiteral("ok")] = false; |
| 870 | out[QStringLiteral("error")] = QStringLiteral("workspace_not_resolved"); |
| 871 | out[QStringLiteral("workspaces")] = rows; |
| 872 | return out; |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * @brief Resolves a group by id or title against project.group.list. |
no test coverage detected