#include "addressbookpage.h"
#include "optionsmodel.h"
#include "sendcoinsentry.h"
-
+#include "guiutil.h"
+#include "askpassphrasedialog.h"
#include <QMessageBox>
#include <QLocale>
{
ui->setupUi(this);
+#ifdef Q_WS_MAC // Icons on push buttons are very uncommon on Mac
+ ui->addButton->setIcon(QIcon());
+ ui->clearButton->setIcon(QIcon());
+ ui->sendButton->setIcon(QIcon());
+#endif
+
addEntry();
connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
+ connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
}
void SendCoinsDialog::setModel(WalletModel *model)
entry->setModel(model);
}
}
+ if(model)
+ {
+ setBalance(model->getBalance(), model->getUnconfirmedBalance());
+ connect(model, SIGNAL(balanceChanged(qint64, qint64)), this, SLOT(setBalance(qint64, qint64)));
+ }
}
SendCoinsDialog::~SendCoinsDialog()
{
QList<SendCoinsRecipient> recipients;
bool valid = true;
+
+ if(!model)
+ return;
+
for(int i = 0; i < ui->entries->count(); ++i)
{
SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(i)->widget());
return;
}
+ WalletModel::UnlockContext ctx(model->requestUnlock());
+ if(!ctx.isValid())
+ {
+ // Unlock wallet was cancelled
+ return;
+ }
+
WalletModel::SendCoinsReturn sendstatus = model->sendCoins(recipients);
switch(sendstatus.status)
{
tr("Error: Transaction creation failed "),
QMessageBox::Ok, QMessageBox::Ok);
break;
- break;
case WalletModel::TransactionCommitFailed:
QMessageBox::warning(this, tr("Send Coins"),
tr("Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."),
void SendCoinsDialog::clear()
{
// Remove entries until only one left
- while(ui->entries->count() > 1)
+ while(ui->entries->count())
{
delete ui->entries->takeAt(0)->widget();
}
-
- // Reset the entry that is left to empty
- SendCoinsEntry *entry = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(0)->widget());
- if(entry)
- {
- entry->clear();
- }
+ addEntry();
updateRemoveEnabled();
clear();
}
-void SendCoinsDialog::addEntry()
+SendCoinsEntry *SendCoinsDialog::addEntry()
{
SendCoinsEntry *entry = new SendCoinsEntry(this);
entry->setModel(model);
// Focus the field, so that entry can start immediately
entry->clear();
+ return entry;
}
void SendCoinsDialog::updateRemoveEnabled()
QWidget::setTabOrder(ui->addButton, ui->sendButton);
return ui->sendButton;
}
+
+void SendCoinsDialog::pasteEntry(const SendCoinsRecipient &rv)
+{
+ SendCoinsEntry *entry = 0;
+ // Replace the first entry if it is still unused
+ if(ui->entries->count() == 1)
+ {
+ SendCoinsEntry *first = qobject_cast<SendCoinsEntry*>(ui->entries->itemAt(0)->widget());
+ if(first->isClear())
+ {
+ entry = first;
+ }
+ }
+ if(!entry)
+ {
+ entry = addEntry();
+ }
+
+ entry->setValue(rv);
+}
+
+
+void SendCoinsDialog::handleURL(const QUrl *url)
+{
+ SendCoinsRecipient rv;
+ if(!GUIUtil::parseBitcoinURL(url, &rv))
+ {
+ return;
+ }
+ pasteEntry(rv);
+}
+
+void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance)
+{
+ Q_UNUSED(unconfirmedBalance);
+ if(!model || !model->getOptionsModel())
+ return;
+
+ int unit = model->getOptionsModel()->getDisplayUnit();
+ ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance));
+}