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