| 426 | } |
| 427 | |
| 428 | QList<ShortcutData> BaseInstance::shortcuts() const |
| 429 | { |
| 430 | auto data = m_settings->get("shortcuts").toString().toUtf8(); |
| 431 | QJsonParseError parseError; |
| 432 | auto document = QJsonDocument::fromJson(data, &parseError); |
| 433 | if (parseError.error != QJsonParseError::NoError || !document.isArray()) |
| 434 | return {}; |
| 435 | |
| 436 | QList<ShortcutData> results; |
| 437 | for (const auto& elem : document.array()) { |
| 438 | if (!elem.isObject()) |
| 439 | continue; |
| 440 | auto dict = elem.toObject(); |
| 441 | if (!dict.contains("name") || !dict.contains("filePath") || !dict.contains("target")) |
| 442 | continue; |
| 443 | int value = dict["target"].toInt(-1); |
| 444 | if (!dict["name"].isString() || !dict["filePath"].isString() || value < 0 || value >= 3) |
| 445 | continue; |
| 446 | |
| 447 | QString shortcutName = dict["name"].toString(); |
| 448 | QString filePath = dict["filePath"].toString(); |
| 449 | if (!QDir(filePath).exists()) { |
| 450 | qWarning() << "Shortcut" << shortcutName << "for instance" << name() << "have non-existent path" << filePath; |
| 451 | continue; |
| 452 | } |
| 453 | results.append({ shortcutName, filePath, static_cast<ShortcutTarget>(value) }); |
| 454 | } |
| 455 | return results; |
| 456 | } |
| 457 | |
| 458 | QString BaseInstance::name() const |
| 459 | { |
no test coverage detected