#include "editaddressdialog.h"
#include "optionsmodel.h"
#include "transactiondescdialog.h"
+#include "addresstablemodel.h"
+#include "transactionview.h"
-#include "main.h"
+#include "headers.h"
#include <QApplication>
#include <QMainWindow>
#include <QToolBar>
#include <QStatusBar>
#include <QLabel>
-#include <QTableView>
#include <QLineEdit>
#include <QPushButton>
-#include <QHeaderView>
#include <QLocale>
-#include <QSortFilterProxyModel>
#include <QClipboard>
#include <QMessageBox>
+#include <QProgressBar>
#include <QDebug>
QPushButton *button_new = new QPushButton(tr("&New..."));
button_new->setToolTip(tr("Create new receiving address"));
+ button_new->setIcon(QIcon(":/icons/add"));
QPushButton *button_clipboard = new QPushButton(tr("&Copy to clipboard"));
button_clipboard->setToolTip(tr("Copy current receiving address to the system clipboard"));
+ button_clipboard->setIcon(QIcon(":/icons/editcopy"));
hbox_address->addWidget(button_new);
hbox_address->addWidget(button_clipboard);
hbox_balance->addSpacing(5);/* Add some spacing between the label and the text */
labelBalance = new QLabel();
- labelBalance->setFont(QFont("Monospace"));
+ labelBalance->setFont(QFont("Monospace", -1, QFont::Bold));
labelBalance->setToolTip(tr("Your current balance"));
hbox_balance->addWidget(labelBalance);
hbox_balance->addStretch(1);
vbox->addLayout(hbox_address);
vbox->addLayout(hbox_balance);
- vbox->addWidget(createTabs());
+ transactionView = new TransactionView(this);
+ connect(transactionView, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(transactionDetails(const QModelIndex&)));
+ vbox->addWidget(transactionView);
QWidget *centralwidget = new QWidget(this);
centralwidget->setLayout(vbox);
labelTransactions->setMinimumWidth(130);
labelTransactions->setToolTip(tr("Number of transactions in your wallet"));
+ // Progress bar for blocks download
+ progressBarLabel = new QLabel(tr("Synchronizing with network..."));
+ progressBarLabel->setVisible(false);
+ progressBar = new QProgressBar();
+ progressBar->setToolTip(tr("Block chain synchronization in progress"));
+ progressBar->setVisible(false);
+
+ statusBar()->addWidget(progressBarLabel);
+ statusBar()->addWidget(progressBar);
statusBar()->addPermanentWidget(labelConnections);
statusBar()->addPermanentWidget(labelBlocks);
statusBar()->addPermanentWidget(labelTransactions);
-
+
// Action bindings
connect(button_new, SIGNAL(clicked()), this, SLOT(newAddressClicked()));
connect(button_clipboard, SIGNAL(clicked()), this, SLOT(copyClipboardClicked()));
addressbook->setToolTip(tr("Edit the list of stored addresses and labels"));
about = new QAction(QIcon(":/icons/bitcoin"), tr("&About"), this);
about->setToolTip(tr("Show information about Bitcoin"));
- receivingAddresses = new QAction(QIcon(":/icons/receiving-addresses"), tr("Your &Receiving Addresses..."), this);
+ receivingAddresses = new QAction(QIcon(":/icons/receiving_addresses"), tr("Your &Receiving Addresses..."), this);
receivingAddresses->setToolTip(tr("Show the list of receiving addresses and edit their labels"));
options = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
options->setToolTip(tr("Modify configuration options for bitcoin"));
setNumBlocks(model->getNumBlocks());
connect(model, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
- setAddress(model->getAddress());
- connect(model, SIGNAL(addressChanged(QString)), this, SLOT(setAddress(QString)));
+ setAddress(model->getAddressTableModel()->getDefaultAddress());
+ connect(model->getAddressTableModel(), SIGNAL(defaultAddressChanged(QString)), this, SLOT(setAddress(QString)));
// Report errors from network/worker thread
connect(model, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
// Put transaction list in tabs
- setTabsModel(model->getTransactionTableModel());
+ transactionView->setModel(model->getTransactionTableModel());
+
+ // Balloon popup for new transaction
+ connect(model->getTransactionTableModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+ this, SLOT(incomingTransaction(const QModelIndex &, int, int)));
}
void BitcoinGUI::createTrayIcon()
}
}
-QWidget *BitcoinGUI::createTabs()
-{
- QStringList tab_labels;
- tab_labels << tr("All transactions")
- << tr("Sent/Received")
- << tr("Sent")
- << tr("Received");
-
- QTabWidget *tabs = new QTabWidget(this);
- for(int i = 0; i < tab_labels.size(); ++i)
- {
- QTableView *view = new QTableView(this);
- tabs->addTab(view, tab_labels.at(i));
-
- connect(view, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(transactionDetails(const QModelIndex&)));
- transactionViews.append(view);
- }
-
- return tabs;
-}
-
-void BitcoinGUI::setTabsModel(QAbstractItemModel *transaction_model)
-{
- QStringList tab_filters;
- tab_filters << "^."
- << "^["+TransactionTableModel::Sent+TransactionTableModel::Received+"]"
- << "^["+TransactionTableModel::Sent+"]"
- << "^["+TransactionTableModel::Received+"]";
-
- for(int i = 0; i < transactionViews.size(); ++i)
- {
- QSortFilterProxyModel *proxy_model = new QSortFilterProxyModel(this);
- proxy_model->setSourceModel(transaction_model);
- proxy_model->setDynamicSortFilter(true);
- proxy_model->setFilterRole(TransactionTableModel::TypeRole);
- proxy_model->setFilterRegExp(QRegExp(tab_filters.at(i)));
- proxy_model->setSortRole(Qt::EditRole);
-
- QTableView *transaction_table = transactionViews.at(i);
- transaction_table->setModel(proxy_model);
- transaction_table->setSelectionBehavior(QAbstractItemView::SelectRows);
- transaction_table->setSelectionMode(QAbstractItemView::ExtendedSelection);
- transaction_table->setSortingEnabled(true);
- transaction_table->sortByColumn(TransactionTableModel::Status, Qt::DescendingOrder);
- transaction_table->verticalHeader()->hide();
-
- transaction_table->horizontalHeader()->resizeSection(
- TransactionTableModel::Status, 23);
- transaction_table->horizontalHeader()->resizeSection(
- TransactionTableModel::Date, 120);
- transaction_table->horizontalHeader()->setResizeMode(
- TransactionTableModel::Description, QHeaderView::Stretch);
- transaction_table->horizontalHeader()->resizeSection(
- TransactionTableModel::Debit, 79);
- transaction_table->horizontalHeader()->resizeSection(
- TransactionTableModel::Credit, 79);
- }
-
- connect(transaction_model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
- this, SLOT(incomingTransaction(const QModelIndex &, int, int)));
-}
-
void BitcoinGUI::sendcoinsClicked()
{
SendCoinsDialog dlg;
if(dlg.exec())
{
QString newAddress = dlg.saveCurrentRow();
- // Set returned address as new default addres
- if(!newAddress.isEmpty())
- {
- model->setAddress(newAddress);
- }
}
}
void BitcoinGUI::setBalance(qint64 balance)
{
- labelBalance->setText(QString::fromStdString(FormatMoney(balance)));
+ labelBalance->setText(QString::fromStdString(FormatMoney(balance)) + QString(" BTC"));
}
void BitcoinGUI::setAddress(const QString &addr)
default: icon = ":/icons/connect_4"; break;
}
labelConnections->setTextFormat(Qt::RichText);
- labelConnections->setText("<img src=\""+icon+"\"> " + QLocale::system().toString(count)+" "+tr("connection(s)", "", count));
+ labelConnections->setText("<img src=\""+icon+"\"> " + tr("%n connection(s)", "", count));
}
void BitcoinGUI::setNumBlocks(int count)
{
- labelBlocks->setText(QLocale::system().toString(count)+" "+tr("block(s)", "", count));
+ int total = model->getTotalBlocksEstimate();
+ if(count < total)
+ {
+ progressBarLabel->setVisible(true);
+ progressBar->setVisible(true);
+ progressBar->setMaximum(total);
+ progressBar->setValue(count);
+ }
+ else
+ {
+ progressBarLabel->setVisible(false);
+ progressBar->setVisible(false);
+ }
+
+ labelBlocks->setText(tr("%n block(s)", "", count));
}
void BitcoinGUI::setNumTransactions(int count)
{
- labelTransactions->setText(QLocale::system().toString(count)+" "+tr("transaction(s)", "", count));
+ labelTransactions->setText(tr("%n transaction(s)", "", count));
}
void BitcoinGUI::error(const QString &title, const QString &message)
void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
{
TransactionTableModel *ttm = model->getTransactionTableModel();
- qint64 credit = ttm->index(start, TransactionTableModel::Credit, parent)
- .data(Qt::EditRole).toULongLong();
- qint64 debit = ttm->index(start, TransactionTableModel::Debit, parent)
+ qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent)
.data(Qt::EditRole).toULongLong();
- if((credit+debit)>0 && !model->inInitialBlockDownload())
+ if(amount>0 && !model->inInitialBlockDownload())
{
// On incoming transaction, make an info balloon
// Unless the initial block download is in progress, to prevent balloon-spam
QString date = ttm->index(start, TransactionTableModel::Date, parent)
.data().toString();
- QString description = ttm->index(start, TransactionTableModel::Description, parent)
+ QString type = ttm->index(start, TransactionTableModel::Type, parent)
+ .data().toString();
+ QString address = ttm->index(start, TransactionTableModel::ToAddress, parent)
.data().toString();
trayIcon->showMessage(tr("Incoming transaction"),
- "Date: " + date + "\n" +
- "Amount: " + QString::fromStdString(FormatMoney(credit+debit, true)) + "\n" +
- description,
+ tr("Date: ") + date + "\n" +
+ tr("Amount: ") + QString::fromStdString(FormatMoney(amount, true)) + "\n" +
+ tr("Type: ") + type + "\n" +
+ tr("Address: ") + address + "\n",
QSystemTrayIcon::Information);
}
}