| 1172 | } |
| 1173 | |
| 1174 | void MainScreen::startTransferSend(void) |
| 1175 | { |
| 1176 | const size_t row = this->index(CELLS); |
| 1177 | if (!backupScrollEnabled || row == 0 || backupList->isReceiveRow(row)) { |
| 1178 | return; // contextual: only a highlighted existing backup can be sent |
| 1179 | } |
| 1180 | if (!KeyboardManager::get().isSystemKeyboardAvailable().first) { |
| 1181 | currentOverlay = std::make_shared<InfoOverlay>(*this, i18n::t("main.receiver_failed")); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
| 1185 | const size_t cellIndex = backupList->rowToCell(row); |
| 1186 | Title title; |
| 1187 | TitleCatalog::get().getTitle(title, g_currentUId, rawIndex()); |
| 1188 | std::string backupName = nameFromCell(cellIndex); |
| 1189 | std::string backupPath = title.fullPath(cellIndex); |
| 1190 | |
| 1191 | // Keyboard + validation on the UI thread; the blocking zip + socket IO runs |
| 1192 | // on the TransferJob worker. |
| 1193 | std::string lastAddress = Configuration::getInstance().lastTransferAddress(); |
| 1194 | std::pair<bool, std::string> ipResp = KeyboardManager::get().keyboard(lastAddress.empty() ? "192.168.0.10:8000" : lastAddress); |
| 1195 | if (!ipResp.first || ipResp.second.empty()) { |
| 1196 | return; |
| 1197 | } |
| 1198 | auto dst = Transfer::parseTarget(ipResp.second); |
| 1199 | if (!dst) { |
| 1200 | currentOverlay = std::make_shared<ErrorOverlay>(*this, -1, i18n::t("main.invalid_ip_port")); |
| 1201 | return; |
| 1202 | } |
| 1203 | // Remember a valid address so the next send prefills the keyboard with it. |
| 1204 | Configuration::getInstance().setLastTransferAddress(ipResp.second); |
| 1205 | |
| 1206 | std::pair<bool, std::string> pinResp = KeyboardManager::get().keyboard("1234"); |
| 1207 | if (!pinResp.first || pinResp.second.empty()) { |
| 1208 | return; |
| 1209 | } |
| 1210 | if (!Transfer::validPin(pinResp.second)) { |
| 1211 | currentOverlay = std::make_shared<ErrorOverlay>(*this, -1, i18n::t("main.pin_invalid")); |
| 1212 | return; |
| 1213 | } |
| 1214 | |
| 1215 | TransferJob::get().enqueueSend(std::move(title), std::move(backupPath), std::move(backupName), "save", std::move(dst->ip), dst->port, |
| 1216 | std::move(pinResp.second), i18n::t("transfer.completed")); |
| 1217 | TransferJob::get().start(); |
| 1218 | } |
| 1219 | |
| 1220 | std::string MainScreen::nameFromCell(size_t index) const |
| 1221 | { |
nothing calls this directly
no test coverage detected