adityapk00
5 years ago
24 changed files with 831 additions and 189 deletions
After Width: | Height: | Size: 7.5 KiB |
@ -0,0 +1,52 @@ |
|||
#include "memoedit.h" |
|||
|
|||
MemoEdit::MemoEdit(QWidget* parent) : QPlainTextEdit(parent) { |
|||
QObject::connect(this, &QPlainTextEdit::textChanged, this, &MemoEdit::updateDisplay); |
|||
} |
|||
|
|||
void MemoEdit::updateDisplay() { |
|||
QString txt = this->toPlainText(); |
|||
if (lenDisplayLabel) |
|||
lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen)); |
|||
|
|||
if (txt.toUtf8().size() <= maxlen) { |
|||
// Everything is fine
|
|||
if (acceptButton) |
|||
acceptButton->setEnabled(true); |
|||
|
|||
if (lenDisplayLabel) |
|||
lenDisplayLabel->setStyleSheet(""); |
|||
} |
|||
else { |
|||
// Overweight
|
|||
if (acceptButton) |
|||
acceptButton->setEnabled(false); |
|||
|
|||
if (lenDisplayLabel) |
|||
lenDisplayLabel->setStyleSheet("color: red;"); |
|||
} |
|||
} |
|||
|
|||
void MemoEdit::setMaxLen(int len) { |
|||
this->maxlen = len; |
|||
updateDisplay(); |
|||
} |
|||
|
|||
void MemoEdit::setLenDisplayLabel(QLabel* label) { |
|||
this->lenDisplayLabel = label; |
|||
} |
|||
|
|||
void MemoEdit::setAcceptButton(QPushButton* button) { |
|||
this->acceptButton = button; |
|||
} |
|||
|
|||
void MemoEdit::includeReplyTo(QString addr) { |
|||
if (addr.isEmpty()) |
|||
return; |
|||
|
|||
auto curText = this->toPlainText(); |
|||
if (curText.endsWith(addr)) |
|||
return; |
|||
|
|||
this->setPlainText(curText + "\n" + tr("Reply to") + ":\n" + addr); |
|||
} |
@ -0,0 +1,23 @@ |
|||
#ifndef MEMOEDIT_H |
|||
#define MEMOEDIT_H |
|||
|
|||
#include "precompiled.h" |
|||
|
|||
class MemoEdit : public QPlainTextEdit |
|||
{ |
|||
public: |
|||
MemoEdit(QWidget* parent); |
|||
|
|||
void setMaxLen(int len); |
|||
void setLenDisplayLabel(QLabel* label); |
|||
void setAcceptButton(QPushButton* button); |
|||
void includeReplyTo(QString replyToAddress); |
|||
void updateDisplay(); |
|||
|
|||
private: |
|||
int maxlen = 512; |
|||
QLabel* lenDisplayLabel = nullptr; |
|||
QPushButton* acceptButton = nullptr; |
|||
}; |
|||
|
|||
#endif // MEMOEDIT_H
|
@ -0,0 +1,139 @@ |
|||
#include "requestdialog.h" |
|||
#include "ui_requestdialog.h" |
|||
#include "settings.h" |
|||
#include "addressbook.h" |
|||
#include "mainwindow.h" |
|||
#include "rpc.h" |
|||
#include "settings.h" |
|||
|
|||
#include "precompiled.h" |
|||
|
|||
RequestDialog::RequestDialog(QWidget *parent) : |
|||
QDialog(parent), |
|||
ui(new Ui::RequestDialog) |
|||
{ |
|||
ui->setupUi(this); |
|||
} |
|||
|
|||
RequestDialog::~RequestDialog() |
|||
{ |
|||
delete ui; |
|||
} |
|||
|
|||
void RequestDialog::setupDialog(MainWindow* main, QDialog* d, Ui_RequestDialog* req) { |
|||
req->setupUi(d); |
|||
Settings::saveRestore(d); |
|||
|
|||
// Setup
|
|||
req->txtMemo->setLenDisplayLabel(req->lblMemoLen); |
|||
req->lblAmount->setText(req->lblAmount->text() + Settings::getTokenName()); |
|||
|
|||
if (!main || !main->getRPC() || !main->getRPC()->getAllZAddresses() || !main->getRPC()->getAllBalances()) |
|||
return; |
|||
|
|||
for (auto addr : *main->getRPC()->getAllZAddresses()) { |
|||
auto bal = main->getRPC()->getAllBalances()->value(addr); |
|||
if (Settings::getInstance()->isSaplingAddress(addr)) { |
|||
req->cmbMyAddress->addItem(addr, bal); |
|||
} |
|||
} |
|||
req->cmbMyAddress->setCurrentText(main->getRPC()->getDefaultSaplingAddress()); |
|||
|
|||
QIcon icon(":/icons/res/paymentreq.gif"); |
|||
req->lblPixmap->setPixmap(icon.pixmap(48, 48)); |
|||
} |
|||
|
|||
// Static method that shows an incoming payment request and prompts the user to pay it
|
|||
void RequestDialog::showPaymentConfirmation(MainWindow* main, QString paymentURI) { |
|||
PaymentURI payInfo = Settings::parseURI(paymentURI); |
|||
if (!payInfo.error.isEmpty()) { |
|||
QMessageBox::critical(main, tr("Error paying zcash URI"), |
|||
tr("URI should be of the form 'zcash:<addr>?amt=x&memo=y") + "\n" + payInfo.error); |
|||
return; |
|||
} |
|||
|
|||
QDialog d(main); |
|||
Ui_RequestDialog req; |
|||
setupDialog(main, &d, &req); |
|||
|
|||
// In the view mode, all fields are read-only
|
|||
req.txtAmount->setReadOnly(true); |
|||
req.txtFrom->setReadOnly(true); |
|||
req.txtMemo->setReadOnly(true); |
|||
|
|||
// Payment is "to"
|
|||
req.lblAddress->setText(tr("Pay To")); |
|||
|
|||
// No Addressbook
|
|||
req.btnAddressBook->setVisible(false); |
|||
|
|||
// No "address is visible" warning
|
|||
req.lblAddressInfo->setVisible(false); |
|||
|
|||
req.txtFrom->setText(payInfo.addr); |
|||
req.txtMemo->setPlainText(payInfo.memo); |
|||
req.txtAmount->setText(payInfo.amt); |
|||
req.txtAmountUSD->setText(Settings::getUSDFormat(req.txtAmount->text().toDouble())); |
|||
|
|||
req.buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Pay")); |
|||
|
|||
req.lblHeader->setText(tr("You are paying a payment request. Your address will not be visible to the person requesting this payment.")); |
|||
|
|||
if (d.exec() == QDialog::Accepted) { |
|||
main->payZcashURI(paymentURI, req.cmbMyAddress->currentText()); |
|||
} |
|||
} |
|||
|
|||
// Static method that shows the request dialog
|
|||
void RequestDialog::showRequestZcash(MainWindow* main) { |
|||
QDialog d(main); |
|||
Ui_RequestDialog req; |
|||
|
|||
setupDialog(main, &d, &req); |
|||
|
|||
// Setup the Label completer for the Address
|
|||
req.txtFrom->setCompleter(main->getLabelCompleter()); |
|||
QObject::connect(req.txtFrom, &QLineEdit::textChanged, [=] (auto text) { |
|||
auto addr = AddressBook::addressFromAddressLabel(text); |
|||
if (!Settings::getInstance()->isSaplingAddress(addr)) { |
|||
req.lblSaplingWarning->setText(tr("Can only request from Sapling addresses")); |
|||
req.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); |
|||
} else { |
|||
req.lblSaplingWarning->setText(""); |
|||
req.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); |
|||
} |
|||
}); |
|||
|
|||
// Wire up AddressBook button
|
|||
QObject::connect(req.btnAddressBook, &QPushButton::clicked, [=] () { |
|||
AddressBook::open(main, req.txtFrom); |
|||
}); |
|||
|
|||
// Amount textbox
|
|||
req.txtAmount->setValidator(main->getAmountValidator()); |
|||
QObject::connect(req.txtAmount, &QLineEdit::textChanged, [=] (auto text) { |
|||
req.txtAmountUSD->setText(Settings::getUSDFormat(text.toDouble())); |
|||
}); |
|||
req.txtAmountUSD->setText(Settings::getUSDFormat(req.txtAmount->text().toDouble())); |
|||
|
|||
req.txtMemo->setAcceptButton(req.buttonBox->button(QDialogButtonBox::Ok)); |
|||
req.txtMemo->setLenDisplayLabel(req.lblMemoLen); |
|||
req.txtMemo->setMaxLen(400); |
|||
|
|||
req.txtFrom->setFocus(); |
|||
|
|||
if (d.exec() == QDialog::Accepted) { |
|||
// Construct a zcash Payment URI with the data and pay it immediately.
|
|||
QString memoURI = "zcash:" + req.cmbMyAddress->currentText() |
|||
+ "?amt=" + Settings::getDecimalString(req.txtAmount->text().toDouble()) |
|||
+ "&memo=" + QUrl::toPercentEncoding(req.txtMemo->toPlainText()); |
|||
|
|||
QString sendURI = "zcash:" + AddressBook::addressFromAddressLabel(req.txtFrom->text()) |
|||
+ "?amt=0.0001" |
|||
+ "&memo=" + QUrl::toPercentEncoding(memoURI); |
|||
|
|||
// If the disclosed address in the memo doesn't have a balance, it will automatically fallback to the default
|
|||
// sapling address
|
|||
main->payZcashURI(sendURI, req.cmbMyAddress->currentText()); |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
#ifndef REQUESTDIALOG_H |
|||
#define REQUESTDIALOG_H |
|||
|
|||
#include <QDialog> |
|||
#include "mainwindow.h" |
|||
#include "ui_requestdialog.h" |
|||
|
|||
namespace Ui { |
|||
class RequestDialog; |
|||
} |
|||
|
|||
class RequestDialog : public QDialog |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
explicit RequestDialog(QWidget *parent = nullptr); |
|||
~RequestDialog(); |
|||
|
|||
static void showRequestZcash(MainWindow* main); |
|||
static void showPaymentConfirmation(MainWindow* main, QString paymentURI); |
|||
static void setupDialog(MainWindow* main, QDialog* d, Ui_RequestDialog* req); |
|||
private: |
|||
Ui::RequestDialog *ui; |
|||
}; |
|||
|
|||
#endif // REQUESTDIALOG_H
|
@ -0,0 +1,279 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>RequestDialog</class> |
|||
<widget class="QDialog" name="RequestDialog"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>663</width> |
|||
<height>529</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Payment Request</string> |
|||
</property> |
|||
<layout class="QGridLayout" name="gridLayout"> |
|||
<item row="18" column="1" colspan="3"> |
|||
<widget class="AddressCombo" name="cmbMyAddress"/> |
|||
</item> |
|||
<item row="2" column="3"> |
|||
<layout class="QHBoxLayout" name="horizontalLayout"> |
|||
<item> |
|||
<spacer name="horizontalSpacer"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>40</width> |
|||
<height>20</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item> |
|||
<widget class="QPushButton" name="btnAddressBook"> |
|||
<property name="text"> |
|||
<string>AddressBook</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</item> |
|||
<item row="21" column="0" colspan="4"> |
|||
<widget class="Line" name="line"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="2" column="1"> |
|||
<widget class="QLabel" name="lblAddress"> |
|||
<property name="text"> |
|||
<string>Request From</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="15" column="1"> |
|||
<widget class="QLabel" name="label_2"> |
|||
<property name="text"> |
|||
<string>My Address</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="5" column="1" colspan="3"> |
|||
<widget class="QLabel" name="lblSaplingWarning"> |
|||
<property name="styleSheet"> |
|||
<string notr="true">color: red;</string> |
|||
</property> |
|||
<property name="text"> |
|||
<string/> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="6" column="1"> |
|||
<widget class="QLabel" name="lblAmount"> |
|||
<property name="text"> |
|||
<string>Amount in </string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="10" column="1"> |
|||
<widget class="QLabel" name="label"> |
|||
<property name="text"> |
|||
<string/> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="24" column="2" colspan="2"> |
|||
<widget class="QDialogButtonBox" name="buttonBox"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
<property name="standardButtons"> |
|||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="14" column="1"> |
|||
<widget class="QLabel" name="label_4"> |
|||
<property name="text"> |
|||
<string/> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="4" column="1" colspan="3"> |
|||
<widget class="QLineEdit" name="txtFrom"> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>0</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> |
|||
</property> |
|||
<property name="placeholderText"> |
|||
<string>z address</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="1" column="1" colspan="3"> |
|||
<widget class="Line" name="line_3"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="12" column="1" colspan="3"> |
|||
<widget class="MemoEdit" name="txtMemo"> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>0</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="7" column="1" colspan="3"> |
|||
<widget class="QLineEdit" name="txtAmount"> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> |
|||
</property> |
|||
<property name="placeholderText"> |
|||
<string>Amount</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="13" column="1" colspan="3"> |
|||
<widget class="Line" name="line_2"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Horizontal</enum> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="15" column="3"> |
|||
<widget class="QLabel" name="lblAddressInfo"> |
|||
<property name="text"> |
|||
<string>The recipient will see this address in the "to" field when they pay your request.</string> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="11" column="3"> |
|||
<widget class="QLabel" name="lblMemoLen"> |
|||
<property name="text"> |
|||
<string notr="true">0 / 512</string> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="9" column="1"> |
|||
<widget class="QLabel" name="txtAmountUSD"> |
|||
<property name="text"> |
|||
<string>Amount USD</string> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="20" column="1"> |
|||
<spacer name="verticalSpacer"> |
|||
<property name="orientation"> |
|||
<enum>Qt::Vertical</enum> |
|||
</property> |
|||
<property name="sizeHint" stdset="0"> |
|||
<size> |
|||
<width>20</width> |
|||
<height>40</height> |
|||
</size> |
|||
</property> |
|||
</spacer> |
|||
</item> |
|||
<item row="11" column="1"> |
|||
<widget class="QLabel" name="label_3"> |
|||
<property name="text"> |
|||
<string>Memo</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="0" column="1"> |
|||
<widget class="QLabel" name="lblPixmap"> |
|||
<property name="text"> |
|||
<string>TextLabel</string> |
|||
</property> |
|||
<property name="alignment"> |
|||
<set>Qt::AlignCenter</set> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="0" column="2" colspan="2"> |
|||
<widget class="QLabel" name="lblHeader"> |
|||
<property name="text"> |
|||
<string>Request payment from a Sapling address. You'll send a ZEC 0.0001 transaction to the address with a zcash payment URI. The memo will be included in the transaction when the address pays you.</string> |
|||
</property> |
|||
<property name="wordWrap"> |
|||
<bool>true</bool> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
<customwidgets> |
|||
<customwidget> |
|||
<class>MemoEdit</class> |
|||
<extends>QPlainTextEdit</extends> |
|||
<header>memoedit.h</header> |
|||
</customwidget> |
|||
<customwidget> |
|||
<class>AddressCombo</class> |
|||
<extends>QComboBox</extends> |
|||
<header>addresscombo.h</header> |
|||
</customwidget> |
|||
</customwidgets> |
|||
<tabstops> |
|||
<tabstop>txtAmount</tabstop> |
|||
<tabstop>txtMemo</tabstop> |
|||
</tabstops> |
|||
<resources/> |
|||
<connections> |
|||
<connection> |
|||
<sender>buttonBox</sender> |
|||
<signal>accepted()</signal> |
|||
<receiver>RequestDialog</receiver> |
|||
<slot>accept()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>248</x> |
|||
<y>254</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>157</x> |
|||
<y>274</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
<connection> |
|||
<sender>buttonBox</sender> |
|||
<signal>rejected()</signal> |
|||
<receiver>RequestDialog</receiver> |
|||
<slot>reject()</slot> |
|||
<hints> |
|||
<hint type="sourcelabel"> |
|||
<x>316</x> |
|||
<y>260</y> |
|||
</hint> |
|||
<hint type="destinationlabel"> |
|||
<x>286</x> |
|||
<y>274</y> |
|||
</hint> |
|||
</hints> |
|||
</connection> |
|||
</connections> |
|||
</ui> |
@ -0,0 +1,116 @@ |
|||
#!/bin/bash |
|||
|
|||
# Setup |
|||
bold=$(tput bold) |
|||
normal=$(tput sgr0) |
|||
|
|||
# Print the usage and exit |
|||
do_help() { |
|||
echo "codesign.sh v0.1"; |
|||
echo ""; |
|||
echo "Sign release binaries with gpg keysigning" |
|||
echo ""; |
|||
echo "Usage:" |
|||
echo "codesign.sh --version [version_id] file [file ...]"; |
|||
echo "" |
|||
exit 1; |
|||
} |
|||
|
|||
# Print the usage for the version parameter and exit |
|||
do_version_missing() { |
|||
echo "No release version identifier specified"; |
|||
echo "Please specify a release version with ${bold}--version${normal}" |
|||
echo |
|||
echo "Example:" |
|||
echo "./codesign.sh --version 1.4 filename.msi" |
|||
exit 1; |
|||
} |
|||
|
|||
# Print the instructions for how to install dependencies |
|||
do_missing_command() { |
|||
echo "Error: ${bold}$1${normal} was not installed" |
|||
echo "" |
|||
echo "One or more dependencies are missing. Please install all dependencies by running:" |
|||
echo "${bold}brew install gsha256sum gnupg${normal}" |
|||
exit 1; |
|||
} |
|||
|
|||
# Print error message for missing private key |
|||
do_missing_gpg_key() { |
|||
echo "Error: Couldn't find a local private key to sign with." |
|||
echo |
|||
echo "The command ${bold}gpg -K${normal} didn't return any keys. Did you forget to install the private keys on this machine?" |
|||
exit 1; |
|||
} |
|||
|
|||
# Accept the variables as command line arguments as well |
|||
POSITIONAL=() |
|||
while [[ $# -gt 0 ]] |
|||
do |
|||
key="$1" |
|||
|
|||
case $key in |
|||
-h|--help) |
|||
do_help |
|||
;; |
|||
-v|--version) |
|||
APP_VERSION="$2" |
|||
shift # past argument |
|||
shift # past value |
|||
;; |
|||
*) # unknown option |
|||
POSITIONAL+=("$1") # save it in an array for later |
|||
shift # past argument |
|||
;; |
|||
esac |
|||
done |
|||
set -- "${POSITIONAL[@]}" # restore positional parameters |
|||
|
|||
if [ -z $APP_VERSION ]; then |
|||
do_version_missing |
|||
fi |
|||
|
|||
# Check for existance of the gpg and sha256sum commands |
|||
hash gsha256sum 2>/dev/null || { |
|||
do_missing_command gsha256sum |
|||
exit 1; |
|||
} |
|||
|
|||
hash gpg 2>/dev/null || { |
|||
do_missing_command gpg |
|||
exit 1; |
|||
} |
|||
|
|||
hash zip 2>/dev/null || { |
|||
do_missing_command zip |
|||
exit 1; |
|||
} |
|||
|
|||
# Check to see that we have a private key installed on this machine |
|||
if [[ -z $(gpg -K) ]]; then |
|||
do_missing_gpg_key |
|||
fi |
|||
|
|||
PackageContents=() |
|||
|
|||
# Calculate the sha256sum for all input files |
|||
gsha256sum $@ > sha256sum.txt |
|||
PackageContents+=("sha256sum.txt") |
|||
|
|||
# Sign all the files |
|||
for var in "$@" |
|||
do |
|||
rm -f $var.sig |
|||
echo "Signing" $var |
|||
gpg --batch --output $var.sig --detach-sig $var |
|||
PackageContents+=("$var.sig") |
|||
done |
|||
|
|||
# Zip up everything into a neat package |
|||
ZipName=signatures-v$APP_VERSION.zip |
|||
echo "Zipping files into $ZipName" |
|||
rm -f $ZipName |
|||
zip $ZipName ${PackageContents[@]} 2>&1 >/dev/null |
|||
|
|||
# Clean up intermediate files |
|||
rm ${PackageContents[@]} |
@ -1 +1 @@ |
|||
#define APP_VERSION "0.6.3" |
|||
#define APP_VERSION "0.6.4" |
|||
|
Loading…
Reference in new issue