Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
sendcoinsentry.cpp
Go to the documentation of this file.
1 #include "sendcoinsentry.h"
2 #include "ui_sendcoinsentry.h"
3 
4 #include "guiutil.h"
5 #include "bitcoinunits.h"
6 #include "addressbookpage.h"
7 #include "walletmodel.h"
8 #include "optionsmodel.h"
9 #include "addresstablemodel.h"
10 
11 #include <QApplication>
12 #include <QClipboard>
13 
15  QFrame(parent),
16  ui(new Ui::SendCoinsEntry),
17  model(0)
18 {
19  ui->setupUi(this);
20 
21 #ifdef Q_OS_MAC
22  ui->payToLayout->setSpacing(4);
23 #endif
24 #if QT_VERSION >= 0x040700
25  /* Do not move this to the XML file, Qt before 4.7 will choke on it */
26  ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
27  ui->payTo->setPlaceholderText(tr("Enter a Feathercoin address (e.g. 6nqmPL9tX4Uz3uQhbz8GrgLfXQNQEXstVu)"));
28 #endif
29  setFocusPolicy(Qt::TabFocus);
30  setFocusProxy(ui->payTo);
31 
32  GUIUtil::setupAddressWidget(ui->payTo, this);
33 }
34 
36 {
37  delete ui;
38 }
39 
41 {
42  // Paste text from clipboard into recipient field
43  ui->payTo->setText(QApplication::clipboard()->text());
44 }
45 
47 {
48  if(!model)
49  return;
52  if(dlg.exec())
53  {
54  ui->payTo->setText(dlg.getReturnValue());
55  ui->payAmount->setFocus();
56  }
57 }
58 
59 void SendCoinsEntry::on_payTo_textChanged(const QString &address)
60 {
61  if(!model)
62  return;
63  // Fill in label from address book, if address has an associated label
64  QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
65  if(!associatedLabel.isEmpty())
66  ui->addAsLabel->setText(associatedLabel);
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 
78  clear();
79 }
80 
82 {
83  ui->deleteButton->setEnabled(enabled);
84 }
85 
87 {
88  ui->payTo->clear();
89  ui->addAsLabel->clear();
90  ui->payAmount->clear();
91  ui->payTo->setFocus();
92  // update the display unit, to not use the default ("BTC")
94 }
95 
97 {
98  emit removeEntry(this);
99 }
100 
102 {
103  // Check input validity
104  bool retval = true;
105 
106  if(!ui->payAmount->validate())
107  {
108  retval = false;
109  }
110  else
111  {
112  if(ui->payAmount->value() <= 0)
113  {
114  // Cannot send 0 coins or less
115  ui->payAmount->setValid(false);
116  retval = false;
117  }
118  }
119 
120  if(!ui->payTo->hasAcceptableInput() ||
121  (model && !model->validateAddress(ui->payTo->text())))
122  {
123  ui->payTo->setValid(false);
124  retval = false;
125  }
126 
127  return retval;
128 }
129 
131 {
133 
134  rv.address = ui->payTo->text();
135  rv.label = ui->addAsLabel->text();
136  rv.amount = ui->payAmount->value();
137 
138  return rv;
139 }
140 
142 {
143  QWidget::setTabOrder(prev, ui->payTo);
144  QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
145  QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
146  QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
147  QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
148  return ui->payAmount->setupTabChain(ui->addAsLabel);
149 }
150 
152 {
153  ui->payTo->setText(value.address);
154  ui->addAsLabel->setText(value.label);
155  ui->payAmount->setValue(value.amount);
156 }
157 
158 void SendCoinsEntry::setAddress(const QString &address)
159 {
160  //may have been scanned in so it must be parsed first
161  if (address.size() > 34) {
162  QString _address;
163  QString _label;
164  QString _amount;
165  int x = address.indexOf(":", 0, Qt::CaseInsensitive);
166  if (x)
167  _address = address.mid(x+1, 34);
168  //Todo: parse out label and amount from incoming string
169  ui->payTo->setText(_address);
170  }
171  else {
172  ui->payTo->setText(address);
173  }
174  ui->payAmount->setFocus();
175 }
176 
178 {
179  return ui->payTo->text().isEmpty();
180 }
181 
183 {
184  ui->payTo->setFocus();
185 }
186 
188 {
189  if(model && model->getOptionsModel())
190  {
191  // Update payAmount with the current unit
192  ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
193  }
194 }
LRUHandle * prev
Definition: cache.cc:30
Ui::SendCoinsEntry * ui
void setValue(const SendCoinsRecipient &value)
void payAmountChanged()
std::string * value
Definition: version_set.cc:270
void setFocus()
SendCoinsRecipient getValue()
void setModel(AddressTableModel *model)
Definition: aboutdialog.h:6
const QString & getReturnValue() const
void setAddress(const QString &address)
~SendCoinsEntry()
void on_payTo_textChanged(const QString &address)
AddressTableModel * getAddressTableModel()
void setupAddressWidget(QLineEdit *widget, QWidget *parent)
Definition: guiutil.cpp:68
void updateDisplayUnit()
bool validate()
A single entry in the dialog for sending bitcoins.
QWidget * setupTabChain(QWidget *prev)
Set up the tab chain manually, as Qt messes up the tab chain by default in some cases (issue https://...
Open address book to pick address for sending.
void clear()
void on_deleteButton_clicked()
int getDisplayUnit()
Definition: optionsmodel.h:50
Widget that shows a list of sending or receiving addresses.
void removeEntry(SendCoinsEntry *entry)
void setRemoveEnabled(bool enabled)
bool isClear()
Return whether the entry is still empty and unedited.
bool validateAddress(const QString &address)
void on_pasteButton_clicked()
QString labelForAddress(const QString &address) const
WalletModel * model
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:36
void on_addressBookButton_clicked()
void setModel(WalletModel *model)
SendCoinsEntry(QWidget *parent=0)
OptionsModel * getOptionsModel()