MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / startTransferSend

Method startTransferSend

switch/source/MainScreen.cpp:1174–1218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1172}
1173
1174void 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
1220std::string MainScreen::nameFromCell(size_t index) const
1221{

Callers

nothing calls this directly

Calls 15

indexMethod · 0.95
getFunction · 0.85
parseTargetFunction · 0.85
validPinFunction · 0.50
isReceiveRowMethod · 0.45
rowToCellMethod · 0.45
getTitleMethod · 0.45
fullPathMethod · 0.45
lastTransferAddressMethod · 0.45
keyboardMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected