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

View file

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