Send: allow pasting monero: uris in pay to field

This commit is contained in:
tobtoht 2024-01-05 16:40:08 +01:00
parent 8509924ebd
commit 1a597fd2d9
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
2 changed files with 19 additions and 7 deletions

View file

@ -80,22 +80,31 @@ bool PayToEdit::isOpenAlias() {
void PayToEdit::keyPressEvent(QKeyEvent *event) { void PayToEdit::keyPressEvent(QKeyEvent *event) {
if (event->matches(QKeySequence::Paste)) { if (event->matches(QKeySequence::Paste)) {
this->pasteEvent(QApplication::clipboard()->mimeData()); bool uri = this->pasteEvent(QApplication::clipboard()->mimeData());
event->accept(); if (uri) {
event->ignore();
return;
}
} }
QPlainTextEdit::keyPressEvent(event); QPlainTextEdit::keyPressEvent(event);
} }
void PayToEdit::pasteEvent(const QMimeData *mimeData) { bool PayToEdit::pasteEvent(const QMimeData *mimeData) {
if (mimeData->hasText() && mimeData->text().startsWith("monero:")) {
dataPasted(mimeData->text());
return true;
}
QImage image; QImage image;
if (mimeData->hasImage()) { if (mimeData->hasImage()) {
image = qvariant_cast<QImage>(mimeData->imageData()); image = qvariant_cast<QImage>(mimeData->imageData());
} }
else if (mimeData->hasUrls()) { else if (mimeData->hasUrls()) {
// Path to image file
QList<QUrl> urlList = mimeData->urls(); QList<QUrl> urlList = mimeData->urls();
if (urlList.count() > 1) { if (urlList.count() > 1) {
return; return false;
} }
QFileInfo file(urlList.at(0).toLocalFile()); QFileInfo file(urlList.at(0).toLocalFile());
if (file.exists()) { if (file.exists()) {
@ -103,12 +112,12 @@ void PayToEdit::pasteEvent(const QMimeData *mimeData) {
} }
} }
else { else {
return; return false;
} }
if (image.isNull()) { if (image.isNull()) {
qDebug() << "Invalid image"; qDebug() << "Invalid image";
return; return false;
} }
#if defined(WITH_SCANNER) #if defined(WITH_SCANNER)
@ -116,7 +125,10 @@ void PayToEdit::pasteEvent(const QMimeData *mimeData) {
QString result = QrCodeUtils::scanImage(image); QString result = QrCodeUtils::scanImage(image);
dataPasted(result); dataPasted(result);
return true;
#endif #endif
return false;
} }
void PayToEdit::checkText() { void PayToEdit::checkText() {

View file

@ -58,7 +58,7 @@ private:
void checkText(); void checkText();
void updateSize(); void updateSize();
void pasteEvent(const QMimeData *mimeData); bool pasteEvent(const QMimeData *mimeData);
PartialTxOutput parseAddressAndAmount(const QString &line); PartialTxOutput parseAddressAndAmount(const QString &line);
quint64 parseAmount(QString amount); quint64 parseAmount(QString amount);