| 1229 | } |
| 1230 | |
| 1231 | void MainScreen::startTransferSend(void) |
| 1232 | { |
| 1233 | const size_t row = this->index(CELLS); |
| 1234 | if (!backupScrollEnabled || row == 0 || backupList->isReceiveRow(row)) { |
| 1235 | return; // contextual: only a highlighted existing backup can be sent |
| 1236 | } |
| 1237 | if (!KeyboardManager::get().isSystemKeyboardAvailable().first) { |
| 1238 | currentOverlay = std::make_shared<InfoOverlay>(*this, i18n::t("main.receiver_failed")); |
| 1239 | return; |
| 1240 | } |
| 1241 | |
| 1242 | const size_t cellIndex = backupList->rowToCell(row); |
| 1243 | Title title; |
| 1244 | TitleCatalog::get().getTitle(title, g_currentUId, rawIndex()); |
| 1245 | std::string backupName = nameFromCell(cellIndex); |
| 1246 | std::string backupPath = title.fullPath(cellIndex); |
| 1247 | |
| 1248 | // Keyboard + validation on the UI thread; the blocking zip + socket IO runs |
| 1249 | // on the TransferJob worker. |
| 1250 | std::string lastAddress = Configuration::getInstance().lastTransferAddress(); |
| 1251 | std::pair<bool, std::string> ipResp = KeyboardManager::get().keyboard(lastAddress.empty() ? "192.168.0.10:8000" : lastAddress); |
| 1252 | if (!ipResp.first || ipResp.second.empty()) { |
| 1253 | return; |
| 1254 | } |
| 1255 | auto dst = Transfer::parseTarget(ipResp.second); |
| 1256 | if (!dst) { |
| 1257 | currentOverlay = std::make_shared<ErrorOverlay>(*this, -1, i18n::t("main.invalid_ip_port")); |
| 1258 | return; |
| 1259 | } |
| 1260 | // Remember a valid address so the next send prefills the keyboard with it. |
| 1261 | Configuration::getInstance().setLastTransferAddress(ipResp.second); |
| 1262 | |
| 1263 | std::pair<bool, std::string> pinResp = KeyboardManager::get().keyboard("1234"); |
| 1264 | if (!pinResp.first || pinResp.second.empty()) { |
| 1265 | return; |
| 1266 | } |
| 1267 | if (!Transfer::validPin(pinResp.second)) { |
| 1268 | currentOverlay = std::make_shared<ErrorOverlay>(*this, -1, i18n::t("main.pin_invalid")); |
| 1269 | return; |
| 1270 | } |
| 1271 | |
| 1272 | TransferJob::get().enqueueSend(std::move(title), std::move(backupPath), std::move(backupName), "save", std::move(dst->ip), dst->port, |
| 1273 | std::move(pinResp.second), i18n::t("transfer.completed")); |
| 1274 | TransferJob::get().start(); |
| 1275 | } |
| 1276 | |
| 1277 | std::string MainScreen::nameFromCell(size_t index) const |
| 1278 | { |
nothing calls this directly
no test coverage detected