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

Method startTransferSend

switch/source/MainScreen.cpp:1221–1265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1219}
1220
1221void 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
1267std::string MainScreen::nameFromCell(size_t index) const
1268{

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