add scan button to qr display dialog to progress immediately to scanning

This commit is contained in:
Craig Raw 2023-09-21 14:07:58 +02:00
parent 31842cc0f2
commit 3dcbe34485
2 changed files with 22 additions and 8 deletions

View file

@ -32,7 +32,7 @@ import java.util.Locale;
import java.util.Optional; import java.util.Optional;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class QRDisplayDialog extends Dialog<UR> { public class QRDisplayDialog extends Dialog<ButtonType> {
private static final Logger log = LoggerFactory.getLogger(QRDisplayDialog.class); private static final Logger log = LoggerFactory.getLogger(QRDisplayDialog.class);
private static final int MIN_FRAGMENT_LENGTH = 10; private static final int MIN_FRAGMENT_LENGTH = 10;
@ -58,14 +58,14 @@ public class QRDisplayDialog extends Dialog<UR> {
private static boolean initialDensityChange; private static boolean initialDensityChange;
public QRDisplayDialog(String type, byte[] data, boolean addLegacyEncodingOption) throws UR.URException { public QRDisplayDialog(String type, byte[] data, boolean addLegacyEncodingOption) throws UR.URException {
this(UR.fromBytes(type, data), addLegacyEncodingOption); this(UR.fromBytes(type, data), addLegacyEncodingOption, false);
} }
public QRDisplayDialog(UR ur) { public QRDisplayDialog(UR ur) {
this(ur, false); this(ur, false, false);
} }
public QRDisplayDialog(UR ur, boolean addLegacyEncodingOption) { public QRDisplayDialog(UR ur, boolean addLegacyEncodingOption, boolean addScanButton) {
this.ur = ur; this.ur = ur;
this.addLegacyEncodingOption = addLegacyEncodingOption; this.addLegacyEncodingOption = addLegacyEncodingOption;
this.encoder = new UREncoder(ur, Config.get().getQrDensity().getMaxFragmentLength(), MIN_FRAGMENT_LENGTH, 0); this.encoder = new UREncoder(ur, Config.get().getQrDensity().getMaxFragmentLength(), MIN_FRAGMENT_LENGTH, 0);
@ -98,11 +98,16 @@ public class QRDisplayDialog extends Dialog<UR> {
dialogPane.getButtonTypes().add(densityButtonType); dialogPane.getButtonTypes().add(densityButtonType);
} }
if(addScanButton) {
final ButtonType scanButtonType = new javafx.scene.control.ButtonType("Scan QR", ButtonBar.ButtonData.NEXT_FORWARD);
dialogPane.getButtonTypes().add(scanButtonType);
}
dialogPane.setPrefWidth(40 + QR_WIDTH + 40); dialogPane.setPrefWidth(40 + QR_WIDTH + 40);
dialogPane.setPrefHeight(40 + QR_HEIGHT + 85); dialogPane.setPrefHeight(40 + QR_HEIGHT + 85);
AppServices.moveToActiveWindowScreen(this); AppServices.moveToActiveWindowScreen(this);
setResultConverter(dialogButton -> dialogButton != cancelButtonType ? ur : null); setResultConverter(dialogButton -> dialogButton);
} }
public QRDisplayDialog(String data) { public QRDisplayDialog(String data) {
@ -125,7 +130,7 @@ public class QRDisplayDialog extends Dialog<UR> {
dialogPane.setPrefHeight(40 + QR_HEIGHT + 85); dialogPane.setPrefHeight(40 + QR_HEIGHT + 85);
AppServices.moveToActiveWindowScreen(this); AppServices.moveToActiveWindowScreen(this);
setResultConverter(dialogButton -> dialogButton != cancelButtonType ? ur : null); setResultConverter(dialogButton -> dialogButton);
} }
private void createAnimateQRService() { private void createAnimateQRService() {
@ -280,6 +285,12 @@ public class QRDisplayDialog extends Dialog<UR> {
return density; return density;
} }
} else if(buttonType.getButtonData() == ButtonBar.ButtonData.NEXT_FORWARD) {
Button scanButton = (Button)super.createButton(buttonType);
scanButton.setGraphicTextGap(5);
scanButton.setGraphic(getGlyph(FontAwesome5.Glyph.CAMERA));
return scanButton;
} }
return super.createButton(buttonType); return super.createButton(buttonType);

View file

@ -874,8 +874,11 @@ public class HeadersController extends TransactionFormController implements Init
//Don't include non witness utxo fields for segwit wallets when displaying the PSBT as a QR - it can add greatly to the time required for scanning //Don't include non witness utxo fields for segwit wallets when displaying the PSBT as a QR - it can add greatly to the time required for scanning
boolean includeNonWitnessUtxos = !Arrays.asList(ScriptType.WITNESS_TYPES).contains(headersForm.getSigningWallet().getScriptType()); boolean includeNonWitnessUtxos = !Arrays.asList(ScriptType.WITNESS_TYPES).contains(headersForm.getSigningWallet().getScriptType());
CryptoPSBT cryptoPSBT = new CryptoPSBT(headersForm.getPsbt().serialize(true, includeNonWitnessUtxos)); CryptoPSBT cryptoPSBT = new CryptoPSBT(headersForm.getPsbt().serialize(true, includeNonWitnessUtxos));
QRDisplayDialog qrDisplayDialog = new QRDisplayDialog(cryptoPSBT.toUR(), addLegacyEncodingOption); QRDisplayDialog qrDisplayDialog = new QRDisplayDialog(cryptoPSBT.toUR(), addLegacyEncodingOption, true);
qrDisplayDialog.show(); Optional<ButtonType> optButtonType = qrDisplayDialog.showAndWait();
if(optButtonType.isPresent() && optButtonType.get().getButtonData() == ButtonBar.ButtonData.NEXT_FORWARD) {
scanPSBT(event);
}
} }
public void scanPSBT(ActionEvent event) { public void scanPSBT(ActionEvent event) {