use real ParseMoney function to parse input to Send dialog
[novacoin.git] / gui / src / sendcoinsdialog.cpp
1 #include "sendcoinsdialog.h"
2 #include "ui_sendcoinsdialog.h"
3
4 #include "addressbookdialog.h"
5 #include "bitcoinaddressvalidator.h"
6
7 #include <QApplication>
8 #include <QClipboard>
9 #include <QMessageBox>
10 #include <QLocale>
11 #include <QDebug>
12
13 #include "util.h"
14 #include "base58.h"
15
16 SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
17     QDialog(parent),
18     ui(new Ui::SendCoinsDialog)
19 {
20     ui->setupUi(this);
21
22     /* Set up validators */
23     ui->payTo->setMaxLength(BitcoinAddressValidator::MaxAddressLength);
24     ui->payTo->setValidator(new BitcoinAddressValidator(this));
25     QDoubleValidator *amountValidator = new QDoubleValidator(this);
26     amountValidator->setDecimals(8);
27     amountValidator->setBottom(0.0);
28     ui->payAmount->setValidator(amountValidator);
29
30     /* Set initial address if provided */
31     if(!address.isEmpty())
32     {
33         ui->payTo->setText(address);
34         ui->payAmount->setFocus();
35     }
36 }
37
38 SendCoinsDialog::~SendCoinsDialog()
39 {
40     delete ui;
41 }
42
43 void SendCoinsDialog::on_sendButton_clicked()
44 {
45     QByteArray payTo = ui->payTo->text().toUtf8();
46     uint160 payToHash = 0;
47     int64 payAmount = 0.0;
48     bool valid = false;
49
50     if(!AddressToHash160(payTo.constData(), payToHash))
51     {
52         QMessageBox::warning(this, tr("Warning"),
53                                        tr("The recepient address is not valid, please recheck."),
54                                        QMessageBox::Ok,
55                                        QMessageBox::Ok);
56         ui->payTo->setFocus();
57         return;
58     }
59     valid = ParseMoney(ui->payAmount->text().toStdString(), payAmount);
60
61     if(!valid || payAmount <= 0)
62     {
63         QMessageBox::warning(this, tr("Warning"),
64                                        tr("The amount to pay must be a valid number larger than 0."),
65                                        QMessageBox::Ok,
66                                        QMessageBox::Ok);
67         ui->payAmount->setFocus();
68         return;
69     }
70     qDebug() << "Pay " << payAmount;
71
72     /* TODO: send command to core, once this succeeds do accept() */
73     accept();
74 }
75
76 void SendCoinsDialog::on_pasteButton_clicked()
77 {
78     /* Paste text from clipboard into recipient field */
79     ui->payTo->setText(QApplication::clipboard()->text());
80 }
81
82 void SendCoinsDialog::on_addressBookButton_clicked()
83 {
84     AddressBookDialog dlg;
85     dlg.exec();
86     ui->payTo->setText(dlg.getReturnValue());
87 }
88
89 void SendCoinsDialog::on_buttonBox_rejected()
90 {
91     reject();
92 }