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