Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
sendcoinsentry.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "sendcoinsentry.h"
6 #include "ui_sendcoinsentry.h"
7 
8 #include "addressbookpage.h"
9 #include "addresstablemodel.h"
10 #include "guiutil.h"
11 #include "optionsmodel.h"
12 #include "walletmodel.h"
13 
14 #include <QApplication>
15 #include <QClipboard>
16 
18  QStackedWidget(parent),
19  ui(new Ui::SendCoinsEntry),
20  model(0)
21 {
22  ui->setupUi(this);
23 
24  setCurrentWidget(ui->SendCoins);
25 
26 #ifdef Q_OS_MAC
27  ui->payToLayout->setSpacing(4);
28 #endif
29 #if QT_VERSION >= 0x040700
30  ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
31 #endif
32 
33  // normal bitcoin address field
35  // just a label for displaying bitcoin address(es)
37 }
38 
40 {
41  delete ui;
42 }
43 
45 {
46  // Paste text from clipboard into recipient field
47  ui->payTo->setText(QApplication::clipboard()->text());
48 }
49 
51 {
52  if(!model)
53  return;
56  if(dlg.exec())
57  {
58  ui->payTo->setText(dlg.getReturnValue());
59  ui->payAmount->setFocus();
60  }
61 }
62 
63 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
64 {
65  updateLabel(address);
66 }
67 
69 {
70  this->model = model;
71 
72  if (model && model->getOptionsModel())
73  connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
74 
75  connect(ui->payAmount, SIGNAL(textChanged()), this, SIGNAL(payAmountChanged()));
76  connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
77  connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
78  connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
79 
80  clear();
81 }
82 
84 {
85  // clear UI elements for normal payment
86  ui->payTo->clear();
87  ui->addAsLabel->clear();
88  ui->payAmount->clear();
89  ui->messageTextLabel->clear();
90  ui->messageTextLabel->hide();
91  ui->messageLabel->hide();
92  // clear UI elements for insecure payment request
93  ui->payTo_is->clear();
94  ui->memoTextLabel_is->clear();
95  ui->payAmount_is->clear();
96  // clear UI elements for secure payment request
97  ui->payTo_s->clear();
98  ui->memoTextLabel_s->clear();
99  ui->payAmount_s->clear();
100 
101  // update the display unit, to not use the default ("BTC")
103 }
104 
106 {
107  emit removeEntry(this);
108 }
109 
111 {
112  if (!model)
113  return false;
114 
115  // Check input validity
116  bool retval = true;
117 
118  // Skip checks for payment request
120  return retval;
121 
122  if (!model->validateAddress(ui->payTo->text()))
123  {
124  ui->payTo->setValid(false);
125  retval = false;
126  }
127 
128  if (!ui->payAmount->validate())
129  {
130  retval = false;
131  }
132 
133  // Reject dust outputs:
134  if (retval && GUIUtil::isDust(ui->payTo->text(), ui->payAmount->value())) {
135  ui->payAmount->setValid(false);
136  retval = false;
137  }
138 
139  return retval;
140 }
141 
143 {
144  // Payment request
146  return recipient;
147 
148  // Normal payment
149  recipient.address = ui->payTo->text();
150  recipient.label = ui->addAsLabel->text();
153 
154  return recipient;
155 }
156 
158 {
159  QWidget::setTabOrder(prev, ui->payTo);
160  QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
162  QWidget::setTabOrder(w, ui->addressBookButton);
163  QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
164  QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
165  return ui->deleteButton;
166 }
167 
169 {
170  recipient = value;
171 
172  if (recipient.paymentRequest.IsInitialized()) // payment request
173  {
174  if (recipient.authenticatedMerchant.isEmpty()) // insecure
175  {
176  ui->payTo_is->setText(recipient.address);
179  ui->payAmount_is->setReadOnly(true);
180  setCurrentWidget(ui->SendCoins_InsecurePaymentRequest);
181  }
182  else // secure
183  {
185  ui->memoTextLabel_s->setText(recipient.message);
187  ui->payAmount_s->setReadOnly(true);
188  setCurrentWidget(ui->SendCoins_SecurePaymentRequest);
189  }
190  }
191  else // normal payment
192  {
193  // message
195  ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
196  ui->messageLabel->setVisible(!recipient.message.isEmpty());
197 
198  ui->addAsLabel->clear();
199  ui->payTo->setText(recipient.address); // this may set a label from addressbook
200  if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, dont overwrite with an empty label
201  ui->addAsLabel->setText(recipient.label);
203  }
204 }
205 
206 void SendCoinsEntry::setAddress(const QString &address)
207 {
208  ui->payTo->setText(address);
209  ui->payAmount->setFocus();
210 }
211 
213 {
214  return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
215 }
216 
218 {
219  ui->payTo->setFocus();
220 }
221 
223 {
224  if(model && model->getOptionsModel())
225  {
226  // Update payAmount with the current unit
230  }
231 }
232 
233 bool SendCoinsEntry::updateLabel(const QString &address)
234 {
235  if(!model)
236  return false;
237 
238  // Fill in label from address book, if address has an associated label
239  QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
240  if(!associatedLabel.isEmpty())
241  {
242  ui->addAsLabel->setText(associatedLabel);
243  return true;
244  }
245 
246  return false;
247 }
BitcoinAmountField * payAmount_s
QHBoxLayout * payToLayout
bool validate()
Perform input validation, mark field as invalid if entered value is not valid.
QLineEdit * addAsLabel
Ui::SendCoinsEntry * ui
void setValue(const SendCoinsRecipient &value)
void payAmountChanged()
PaymentRequestPlus paymentRequest
Definition: walletmodel.h:55
bool IsInitialized() const
QLabel * messageLabel
void setReadOnly(bool fReadOnly)
Make read-only.
QToolButton * deleteButton
QLabel * memoTextLabel_is
QLabel * payTo_is
QLabel * messageTextLabel
void setFocus()
SendCoinsRecipient getValue()
QValidatedLineEdit * payTo
void setModel(AddressTableModel *model)
const QString & getReturnValue() const
void setAddress(const QString &address)
~SendCoinsEntry()
bool updateLabel(const QString &address)
QWidget * setupTabChain(QWidget *prev)
Qt messes up the tab chain by default in some cases (issue https://bugreports.qt-project.org/browse/QTBUG-10907), in these cases we have to set it up manually.
void deleteClicked()
void on_payTo_textChanged(const QString &address)
BitcoinAmountField * payAmount_is
QToolButton * deleteButton_s
Open address book to pick address.
AddressTableModel * getAddressTableModel()
void updateDisplayUnit()
bool validate()
A single entry in the dialog for sending bitcoins.
QLabel * memoTextLabel_s
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
void clear()
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:94
QToolButton * deleteButton_is
bool isDust(const QString &address, qint64 amount)
Definition: guiutil.cpp:214
void setupUi(QStackedWidget *SendCoinsEntry)
int getDisplayUnit()
Definition: optionsmodel.h:58
Widget that shows a list of sending or receiving addresses.
void removeEntry(SendCoinsEntry *entry)
QFrame * SendCoins_SecurePaymentRequest
bool isClear()
Return whether the entry is still empty and unedited.
bool validateAddress(const QString &address)
QLabel * payTo_s
QToolButton * pasteButton
QFrame * SendCoins_InsecurePaymentRequest
void on_pasteButton_clicked()
QString labelForAddress(const QString &address) const
WalletModel * model
QFrame * SendCoins
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:96
void clear()
Make field empty and ready for new input.
SendCoinsRecipient recipient
void on_addressBookButton_clicked()
void setModel(WalletModel *model)
void setValid(bool valid)
Mark current value as invalid in UI.
SendCoinsEntry(QWidget *parent=0)
QToolButton * addressBookButton
void setDisplayUnit(int unit)
Change unit used to display amount.
QString authenticatedMerchant
Definition: walletmodel.h:57
void setValue(qint64 value)
void setValid(bool valid)
BitcoinAmountField * payAmount
QFont bitcoinAddressFont()
Definition: guiutil.cpp:83
OptionsModel * getOptionsModel()