namespacing, user friendly base58 entry, addressbook work
This commit is contained in:
@@ -87,14 +87,20 @@ void AddressBookDialog::on_copyToClipboard_clicked()
|
||||
|
||||
void AddressBookDialog::on_editButton_clicked()
|
||||
{
|
||||
/* Double click triggers edit button */
|
||||
EditAddressDialog dlg;
|
||||
/* Double click also triggers edit button */
|
||||
EditAddressDialog dlg(
|
||||
ui->tabWidget->currentIndex() == SendingTab ?
|
||||
EditAddressDialog::EditSendingAddress :
|
||||
EditAddressDialog::EditReceivingAddress);
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
void AddressBookDialog::on_newAddressButton_clicked()
|
||||
{
|
||||
EditAddressDialog dlg;
|
||||
EditAddressDialog dlg(
|
||||
ui->tabWidget->currentIndex() == SendingTab ?
|
||||
EditAddressDialog::NewSendingAddress :
|
||||
EditAddressDialog::NewReceivingAddress);
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
@@ -103,10 +109,10 @@ void AddressBookDialog::on_tabWidget_currentChanged(int index)
|
||||
switch(index)
|
||||
{
|
||||
case SendingTab:
|
||||
ui->deleteButton->show();
|
||||
ui->deleteButton->setEnabled(true);
|
||||
break;
|
||||
case ReceivingTab:
|
||||
ui->deleteButton->hide();
|
||||
ui->deleteButton->setEnabled(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "guiutil.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <QFont>
|
||||
|
||||
const QString AddressTableModel::Send = "S";
|
||||
const QString AddressTableModel::Receive = "R";
|
||||
|
||||
@@ -108,7 +110,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(index.column() == Address)
|
||||
{
|
||||
return bitcoinAddressFont();
|
||||
return GUIUtil::bitcoinAddressFont();
|
||||
}
|
||||
} else if (role == TypeRole)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,44 @@
|
||||
|
||||
#include "base58.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
/* Base58 characters are:
|
||||
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||
|
||||
This is:
|
||||
- All numbers except for '0'
|
||||
- All uppercase letters except for 'I' and 'O'
|
||||
- All lowercase letters except for 'l'
|
||||
|
||||
User friendly Base58 input can map
|
||||
- 'l' and 'I' to '1'
|
||||
- '0' and 'O' to 'o'
|
||||
*/
|
||||
|
||||
BitcoinAddressValidator::BitcoinAddressValidator(QObject *parent) :
|
||||
QRegExpValidator(QRegExp(QString("^[")+QString(pszBase58)+QString("]+")), parent)
|
||||
{
|
||||
}
|
||||
|
||||
QValidator::State BitcoinAddressValidator::validate(QString &input, int &pos) const
|
||||
{
|
||||
for(int idx=0; idx<input.size(); ++idx)
|
||||
{
|
||||
switch(input.at(idx).unicode())
|
||||
{
|
||||
case 'l':
|
||||
case 'I':
|
||||
input[idx] = QChar('1');
|
||||
break;
|
||||
case '0':
|
||||
case 'O':
|
||||
input[idx] = QChar('o');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return QRegExpValidator::validate(input, pos);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "optionsdialog.h"
|
||||
#include "aboutdialog.h"
|
||||
#include "clientmodel.h"
|
||||
#include "guiutil.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
@@ -70,6 +71,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
|
||||
hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:")));
|
||||
address = new QLineEdit();
|
||||
address->setReadOnly(true);
|
||||
address->setFont(GUIUtil::bitcoinAddressFont());
|
||||
hbox_address->addWidget(address);
|
||||
|
||||
QPushButton *button_new = new QPushButton(tr("&New..."));
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#include "editaddressdialog.h"
|
||||
#include "ui_editaddressdialog.h"
|
||||
#include "guiutil.h"
|
||||
|
||||
EditAddressDialog::EditAddressDialog(QWidget *parent) :
|
||||
EditAddressDialog::EditAddressDialog(Mode mode, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::EditAddressDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
GUIUtil::setupAddressWidget(ui->addressEdit, this);
|
||||
}
|
||||
|
||||
EditAddressDialog::~EditAddressDialog()
|
||||
|
||||
@@ -1,16 +1,37 @@
|
||||
#include "guiutil.h"
|
||||
#include "bitcoinaddressvalidator.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QDoubleValidator>
|
||||
#include <QFont>
|
||||
#include <QLineEdit>
|
||||
|
||||
QString DateTimeStr(qint64 nTime)
|
||||
QString GUIUtil::DateTimeStr(qint64 nTime)
|
||||
{
|
||||
QDateTime date = QDateTime::fromMSecsSinceEpoch(nTime*1000);
|
||||
return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm");
|
||||
}
|
||||
|
||||
QFont bitcoinAddressFont()
|
||||
QFont GUIUtil::bitcoinAddressFont()
|
||||
{
|
||||
QFont font("Monospace");
|
||||
font.setStyleHint(QFont::TypeWriter);
|
||||
return font;
|
||||
}
|
||||
|
||||
void GUIUtil::setupAddressWidget(QLineEdit *widget, QWidget *parent)
|
||||
{
|
||||
widget->setMaxLength(BitcoinAddressValidator::MaxAddressLength);
|
||||
widget->setValidator(new BitcoinAddressValidator(parent));
|
||||
widget->setFont(bitcoinAddressFont());
|
||||
}
|
||||
|
||||
void GUIUtil::setupAmountWidget(QLineEdit *widget, QWidget *parent)
|
||||
{
|
||||
QDoubleValidator *amountValidator = new QDoubleValidator(parent);
|
||||
amountValidator->setDecimals(8);
|
||||
amountValidator->setBottom(0.0);
|
||||
widget->setValidator(amountValidator);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "sendcoinsdialog.h"
|
||||
#include "ui_sendcoinsdialog.h"
|
||||
#include "clientmodel.h"
|
||||
#include "guiutil.h"
|
||||
|
||||
#include "addressbookdialog.h"
|
||||
#include "bitcoinaddressvalidator.h"
|
||||
#include "optionsmodel.h"
|
||||
|
||||
#include <QApplication>
|
||||
@@ -22,13 +22,8 @@ SendCoinsDialog::SendCoinsDialog(QWidget *parent, const QString &address) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
/* Set up validators */
|
||||
ui->payTo->setMaxLength(BitcoinAddressValidator::MaxAddressLength);
|
||||
ui->payTo->setValidator(new BitcoinAddressValidator(this));
|
||||
QDoubleValidator *amountValidator = new QDoubleValidator(this);
|
||||
amountValidator->setDecimals(8);
|
||||
amountValidator->setBottom(0.0);
|
||||
ui->payAmount->setValidator(amountValidator);
|
||||
GUIUtil::setupAddressWidget(ui->payTo, this);
|
||||
GUIUtil::setupAmountWidget(ui->payAmount, this);
|
||||
|
||||
/* Set initial address if provided */
|
||||
if(!address.isEmpty())
|
||||
|
||||
@@ -159,7 +159,7 @@ QVariant TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) con
|
||||
status = tr("Open for %n block(s)","",wtx->status.open_for);
|
||||
break;
|
||||
case TransactionStatus::OpenUntilDate:
|
||||
status = tr("Open until ") + DateTimeStr(wtx->status.open_for);
|
||||
status = tr("Open until ") + GUIUtil::DateTimeStr(wtx->status.open_for);
|
||||
break;
|
||||
case TransactionStatus::Offline:
|
||||
status = tr("%1/offline").arg(wtx->status.depth);
|
||||
@@ -179,7 +179,7 @@ QVariant TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const
|
||||
{
|
||||
if(wtx->time)
|
||||
{
|
||||
return QVariant(DateTimeStr(wtx->time));
|
||||
return QVariant(GUIUtil::DateTimeStr(wtx->time));
|
||||
} else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user