Browse Source

Reply to context menu

recurring
Aditya Kulkarni 6 years ago
parent
commit
d87adfae82
  1. 28
      src/mainwindow.cpp
  2. 2
      src/mainwindow.h
  3. 16
      src/sendtab.cpp
  4. 12
      src/settings.cpp

28
src/mainwindow.cpp

@ -937,6 +937,34 @@ void MainWindow::setupTransactionsTab() {
});
}
// If memo contains a reply to addess, add a "Reply to" menu item
if (!memo.isEmpty()) {
int lastPost = memo.trimmed().lastIndexOf(QRegExp("[\r\n]+"));
QString lastWord = memo.right(memo.length() - lastPost - 1);
qDebug() << lastWord;
if (Settings::getInstance()->isSaplingAddress(lastWord) ||
Settings::getInstance()->isSproutAddress(lastWord)) {
menu.addAction(tr("Reply to ") + lastWord.left(25) + "...", [=]() {
// First, cancel any pending stuff in the send tab by pretending to click
// the cancel button
cancelButton();
// Then set up the fields in the send tab
ui->Address1->setText(lastWord);
ui->Address1->setCursorPosition(0);
ui->Amount1->setText("0.0001");
// And switch to the send tab.
ui->tabWidget->setCurrentIndex(1);
qApp->processEvents();
// Click the memo button
this->memoButtonClicked(1, true);
});
}
}
menu.exec(ui->transactionsTable->viewport()->mapToGlobal(pos));
});
}

2
src/mainwindow.h

@ -82,7 +82,7 @@ private:
void addNewZaddr(bool sapling);
std::function<void(bool)> addZAddrsToComboList(bool sapling);
void memoButtonClicked(int number);
void memoButtonClicked(int number, bool includeReplyTo = false);
void setMemoEnabled(int number, bool enabled);
QString doSendTxValidations(Tx tx);

16
src/sendtab.cpp

@ -255,7 +255,7 @@ void MainWindow::setMemoEnabled(int number, bool enabled) {
}
}
void MainWindow::memoButtonClicked(int number) {
void MainWindow::memoButtonClicked(int number, bool includeReplyTo) {
// Memos can only be used with zAddrs. So check that first
auto addr = ui->sendToWidgets->findChild<QLineEdit*>(QString("Address") + QString::number(number));
if (!AddressBook::addressFromAddressLabel(addr->text()).startsWith("z")) {
@ -293,8 +293,7 @@ void MainWindow::memoButtonClicked(int number) {
});
// Insert From Address button
QObject::connect(memoDialog.btnInsertFrom, &QPushButton::clicked, [=, &dialog] () {
auto fnAddReplyTo = [=, &dialog]() {
QString replyTo = ui->inputsCombo->currentText();
if (!Settings::isZAddress(replyTo)) {
replyTo = rpc->getDefaultSaplingAddress();
@ -305,18 +304,23 @@ void MainWindow::memoButtonClicked(int number) {
if (curText.endsWith(replyTo))
return;
memoDialog.memoTxt->setPlainText(memoDialog.memoTxt->toPlainText() +
"\n" + tr("Reply to") + ":\n" + replyTo);
memoDialog.memoTxt->setPlainText(curText + "\n" + tr("Reply to") + ":\n" + replyTo);
// MacOS has a really annoying bug where the Plaintext doesn't refresh when the content is
// updated. So we do this ugly hack - resize the window slightly to force it to refresh
dialog.setGeometry(dialog.geometry().adjusted(0,0,0,1));
dialog.setGeometry(dialog.geometry().adjusted(0,0,0,-1));
});
};
// Insert From Address button
QObject::connect(memoDialog.btnInsertFrom, &QPushButton::clicked, fnAddReplyTo);
memoDialog.memoTxt->setPlainText(currentMemo);
memoDialog.memoTxt->setFocus();
if (includeReplyTo)
fnAddReplyTo();
if (dialog.exec() == QDialog::Accepted) {
memoTxt->setText(memoDialog.memoTxt->toPlainText());
}

12
src/settings.cpp

@ -54,19 +54,31 @@ void Settings::setTestnet(bool isTestnet) {
}
bool Settings::isSaplingAddress(QString addr) {
if (!isValidAddress(addr))
return false;
return ( isTestnet() && addr.startsWith("ztestsapling")) ||
(!isTestnet() && addr.startsWith("zs"));
}
bool Settings::isSproutAddress(QString addr) {
if (!isValidAddress(addr))
return false;
return isZAddress(addr) && !isSaplingAddress(addr);
}
bool Settings::isZAddress(QString addr) {
if (!isValidAddress(addr))
return false;
return addr.startsWith("z");
}
bool Settings::isTAddress(QString addr) {
if (!isValidAddress(addr))
return false;
return addr.startsWith("t");
}

Loading…
Cancel
Save