Update CMakeLists.txt - play with openssl
[novacoin.git] / src / qt / sendcoinsentry.cpp
1 #include "sendcoinsentry.h"
2 #include "ui_sendcoinsentry.h"
3 #include "guiutil.h"
4 #include "bitcoinunits.h"
5 #include "addressbookpage.h"
6 #include "walletmodel.h"
7 #include "optionsmodel.h"
8 #include "addresstablemodel.h"
9
10 #include <QApplication>
11 #include <QClipboard>
12
13 SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
14     QFrame(parent),
15     ui(new Ui::SendCoinsEntry),
16     model(0)
17 {
18     ui->setupUi(this);
19
20 #ifdef Q_OS_MAC
21     ui->payToLayout->setSpacing(4);
22 #endif
23 #if QT_VERSION >= 0x040700
24     /* Do not move this to the XML file, Qt before 4.7 will choke on it */
25     ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
26     ui->payTo->setPlaceholderText(tr("Enter a NovaCoin address (e.g. 4Zo1ga6xuKuQ7JV7M9rGDoxdbYwV5zgQJ5)"));
27 #endif
28     setFocusPolicy(Qt::TabFocus);
29     setFocusProxy(ui->payTo);
30
31     GUIUtil::setupAddressWidget(ui->payTo, this);
32 }
33
34 SendCoinsEntry::~SendCoinsEntry()
35 {
36     delete ui;
37 }
38
39 void SendCoinsEntry::on_pasteButton_clicked()
40 {
41     // Paste text from clipboard into recipient field
42     ui->payTo->setText(QApplication::clipboard()->text());
43 }
44
45 void SendCoinsEntry::on_addressBookButton_clicked()
46 {
47     if(!model)
48         return;
49     AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
50     dlg.setModel(model->getAddressTableModel());
51     if(dlg.exec())
52     {
53         ui->payTo->setText(dlg.getReturnValue());
54         ui->payAmount->setFocus();
55     }
56 }
57
58 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
59 {
60     if(!model)
61         return;
62     // Fill in label from address book
63     ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
64 }
65
66 void SendCoinsEntry::setModel(WalletModel *model)
67 {
68     this->model = model;
69
70     if(model && model->getOptionsModel())
71         connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
72
73     connect(ui->payAmount, SIGNAL(textChanged()), this, SIGNAL(payAmountChanged()));
74
75     clear();
76 }
77
78 void SendCoinsEntry::setRemoveEnabled(bool enabled)
79 {
80     ui->deleteButton->setEnabled(enabled);
81 }
82
83 void SendCoinsEntry::clear()
84 {
85     ui->payTo->clear();
86     ui->addAsLabel->clear();
87     ui->payAmount->clear();
88     ui->payTo->setFocus();
89     // update the display unit, to not use the default ("BTC")
90     updateDisplayUnit();
91 }
92
93 void SendCoinsEntry::on_deleteButton_clicked()
94 {
95     emit removeEntry(this);
96 }
97
98 bool SendCoinsEntry::validate()
99 {
100     // Check input validity
101     bool retval = true;
102
103     if(!ui->payAmount->validate())
104     {
105         retval = false;
106     }
107     else
108     {
109         if(ui->payAmount->value() <= 0)
110         {
111             // Cannot send 0 coins or less
112             ui->payAmount->setValid(false);
113             retval = false;
114         }
115     }
116
117     if(!ui->payTo->hasAcceptableInput() ||
118        (model && !model->validateAddress(ui->payTo->text())))
119     {
120         ui->payTo->setValid(false);
121         retval = false;
122     }
123
124     return retval;
125 }
126
127 SendCoinsRecipient SendCoinsEntry::getValue()
128 {
129     SendCoinsRecipient rv;
130
131     rv.address = ui->payTo->text();
132     rv.label = ui->addAsLabel->text();
133     rv.amount = ui->payAmount->value();
134
135     return rv;
136 }
137
138 QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
139 {
140     QWidget::setTabOrder(prev, ui->payTo);
141     QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
142     QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
143     QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
144     QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
145     return ui->payAmount->setupTabChain(ui->addAsLabel);
146 }
147
148 void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
149 {
150     ui->payTo->setText(value.address);
151     ui->addAsLabel->setText(value.label);
152     ui->payAmount->setValue(value.amount);
153 }
154
155 bool SendCoinsEntry::isClear()
156 {
157     return ui->payTo->text().isEmpty();
158 }
159
160 void SendCoinsEntry::setFocus()
161 {
162     ui->payTo->setFocus();
163 }
164
165 void SendCoinsEntry::updateDisplayUnit()
166 {
167     if(model && model->getOptionsModel())
168     {
169         // Update payAmount with the current unit
170         ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
171     }
172 }