begin integration with bitcoin upstream

This commit is contained in:
Wladimir J. van der Laan
2011-05-14 10:31:46 +02:00
parent 4d1bb15e31
commit 1f2e0df865
38 changed files with 3489 additions and 35 deletions

12
gui/bitcoin.qrc Normal file
View File

@@ -0,0 +1,12 @@
<RCC>
<qresource prefix="/icons">
<file alias="address-book">res/icons/address-book.png</file>
<file alias="bitcoin">res/icons/bitcoin.png</file>
<file alias="quit">res/icons/quit.png</file>
<file alias="send">res/icons/send.png</file>
<file alias="toolbar">res/icons/toolbar.png</file>
</qresource>
<qresource prefix="/images">
<file alias="about">res/images/about.png</file>
</qresource>
</RCC>

162
gui/forms/aboutdialog.ui Normal file
View File

@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AboutDialog</class>
<widget class="QDialog" name="AboutDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>593</width>
<height>319</height>
</rect>
</property>
<property name="windowTitle">
<string>About Bitcoin</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../bitcoin.qrc">:/images/about</pixmap>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;b&gt;Bitcoin&lt;/b&gt; version</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="versionLabel">
<property name="text">
<string>0.3.666-beta</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Copyright (c) 2009-2011 Bitcoin Developers
This is experimental software.
Distributed under the MIT/X11 software license, see the accompanying file license.txt or http://www.opensource.org/licenses/mit-license.php.
This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org/) and cryptographic software written by Eric Young (eay@cryptsoft.com) and UPnP software written by Thomas Bernard.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../bitcoin.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AboutDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>360</x>
<y>308</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AboutDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>428</x>
<y>308</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddressBookDialog</class>
<widget class="QDialog" name="AddressBookDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>591</width>
<height>347</height>
</rect>
</property>
<property name="windowTitle">
<string>Address Book</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="sendTab">
<attribute name="title">
<string>Sending</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTableView" name="sendTableView">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="receiveTab">
<attribute name="title">
<string>Receiving</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>These are your Bitcoin addresses for receiving payments. You may want to give a different one to each sender so you can keep track of who is paying you. The highlighted address is displayed in the main window.</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="receiveTableView">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="newAddressButton">
<property name="text">
<string>&amp;New Address...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copyToClipboard">
<property name="text">
<string>&amp;Copy to Clipboard</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>&amp;Edit...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton">
<property name="text">
<string>&amp;Delete</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>receiveTableView</sender>
<signal>doubleClicked(QModelIndex)</signal>
<receiver>editButton</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>334</x>
<y>249</y>
</hint>
<hint type="destinationlabel">
<x>333</x>
<y>326</y>
</hint>
</hints>
</connection>
<connection>
<sender>sendTableView</sender>
<signal>doubleClicked(QModelIndex)</signal>
<receiver>editButton</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>329</x>
<y>261</y>
</hint>
<hint type="destinationlabel">
<x>332</x>
<y>326</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditAddressDialog</class>
<widget class="QDialog" name="EditAddressDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>EditAddressDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EditAddressDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SendCoinsDialog</class>
<widget class="QDialog" name="SendCoinsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>736</width>
<height>140</height>
</rect>
</property>
<property name="windowTitle">
<string>Send Coins</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Amount:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>payAmount</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Pay &amp;To:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>payTo</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="payTo">
<property name="maxLength">
<number>34</number>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="payAmount">
<property name="maximumSize">
<size>
<width>145</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="pasteButton">
<property name="text">
<string>&amp;Paste</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="addressBookButton">
<property name="text">
<string>Address &amp;Book...</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="sendButton">
<property name="text">
<string>&amp;Send</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/send</normaloff>:/icons/send</iconset>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../bitcoin.qrc"/>
</resources>
<connections>
<connection>
<sender>payAmount</sender>
<signal>returnPressed()</signal>
<receiver>sendButton</receiver>
<slot>click()</slot>
<hints>
<hint type="sourcelabel">
<x>191</x>
<y>65</y>
</hint>
<hint type="destinationlabel">
<x>570</x>
<y>121</y>
</hint>
</hints>
</connection>
</connections>
</ui>

25
gui/include/aboutdialog.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef ABOUTDIALOG_H
#define ABOUTDIALOG_H
#include <QDialog>
namespace Ui {
class AboutDialog;
}
class AboutDialog : public QDialog
{
Q_OBJECT
public:
explicit AboutDialog(QWidget *parent = 0);
~AboutDialog();
private:
Ui::AboutDialog *ui;
private slots:
void on_buttonBox_accepted();
};
#endif // ABOUTDIALOG_H

View File

@@ -0,0 +1,47 @@
#ifndef ADDRESSBOOKDIALOG_H
#define ADDRESSBOOKDIALOG_H
#include <QDialog>
namespace Ui {
class AddressBookDialog;
}
class AddressTableModel;
QT_BEGIN_NAMESPACE
class QTableView;
QT_END_NAMESPACE
class AddressBookDialog : public QDialog
{
Q_OBJECT
public:
explicit AddressBookDialog(QWidget *parent = 0);
~AddressBookDialog();
enum {
SendingTab = 0,
ReceivingTab = 1
} Tabs;
void setModel(AddressTableModel *model);
void setTab(int tab);
const QString &getReturnValue() const { return returnValue; }
private:
Ui::AddressBookDialog *ui;
AddressTableModel *model;
QString returnValue;
QTableView *getCurrentTable();
private slots:
void on_buttonBox_accepted();
void on_deleteButton_clicked();
void on_tabWidget_currentChanged(int index);
void on_newAddressButton_clicked();
void on_editButton_clicked();
void on_copyToClipboard_clicked();
};
#endif // ADDRESSBOOKDIALOG_H

View File

@@ -0,0 +1,32 @@
#ifndef ADDRESSTABLEMODEL_H
#define ADDRESSTABLEMODEL_H
#include <QAbstractTableModel>
class AddressTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit AddressTableModel(QObject *parent = 0);
enum {
Label = 0, /* User specified label */
Address = 1, /* Bitcoin address */
Type = 2 /* Send/Receive, used for filter */
} ColumnIndex;
static const QString Send; /* Send addres */
static const QString Receive; /* Receive address */
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
signals:
public slots:
};
#endif // ADDRESSTABLEMODEL_H

View File

@@ -0,0 +1,21 @@
#ifndef BITCOINADDRESSVALIDATOR_H
#define BITCOINADDRESSVALIDATOR_H
#include <QRegExpValidator>
#include <base58.h>
class BitcoinAddressValidator : public QRegExpValidator
{
Q_OBJECT
public:
explicit BitcoinAddressValidator(QObject *parent = 0);
static const QString valid_chars;
signals:
public slots:
};
#endif // BITCOINADDRESSVALIDATOR_H

69
gui/include/bitcoingui.h Normal file
View File

@@ -0,0 +1,69 @@
#ifndef BITCOINGUI_H
#define BITCOINGUI_H
#include <QMainWindow>
#include <QSystemTrayIcon>
/* Forward declarations */
class TransactionTableModel;
QT_BEGIN_NAMESPACE
class QLabel;
class QLineEdit;
QT_END_NAMESPACE
class BitcoinGUI : public QMainWindow
{
Q_OBJECT
public:
explicit BitcoinGUI(QWidget *parent = 0);
/* Transaction table tab indices */
enum {
AllTransactions = 0,
SentReceived = 1,
Sent = 2,
Received = 3
} TabIndex;
private:
TransactionTableModel *transaction_model;
QLineEdit *address;
QLabel *labelBalance;
QLabel *labelConnections;
QLabel *labelBlocks;
QLabel *labelTransactions;
QAction *quit;
QAction *sendcoins;
QAction *addressbook;
QAction *about;
QAction *receiving_addresses;
QAction *options;
QAction *openBitCoin;
QSystemTrayIcon *trayIcon;
void createActions();
QWidget *createTabs();
void createTrayIcon();
public slots:
void setBalance(double balance);
void setAddress(const QString &address);
void setNumConnections(int count);
void setNumBlocks(int count);
void setNumTransactions(int count);
private slots:
void sendcoinsClicked();
void addressbookClicked();
void optionsClicked();
void receivingAddressesClicked();
void aboutClicked();
void newAddressClicked();
void copyClipboardClicked();
};
#endif

View File

@@ -0,0 +1,22 @@
#ifndef EDITADDRESSDIALOG_H
#define EDITADDRESSDIALOG_H
#include <QDialog>
namespace Ui {
class EditAddressDialog;
}
class EditAddressDialog : public QDialog
{
Q_OBJECT
public:
explicit EditAddressDialog(QWidget *parent = 0);
~EditAddressDialog();
private:
Ui::EditAddressDialog *ui;
};
#endif // EDITADDRESSDIALOG_H

View File

@@ -0,0 +1,18 @@
#ifndef MAINOPTIONSPAGE_H
#define MAINOPTIONSPAGE_H
#include <QWidget>
class MainOptionsPage : public QWidget
{
Q_OBJECT
public:
explicit MainOptionsPage(QWidget *parent = 0);
signals:
public slots:
};
#endif // MAINOPTIONSPAGE_H

View File

@@ -0,0 +1,29 @@
#ifndef OPTIONSDIALOG_H
#define OPTIONSDIALOG_H
#include <QDialog>
QT_BEGIN_NAMESPACE
class QStackedWidget;
class QListWidget;
class QListWidgetItem;
QT_END_NAMESPACE
class OptionsDialog : public QDialog
{
Q_OBJECT
public:
explicit OptionsDialog(QWidget *parent = 0);
signals:
public slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
private:
QListWidget *contents_widget;
QStackedWidget *pages_widget;
void setupMainPage();
};
#endif // OPTIONSDIALOG_H

View File

@@ -0,0 +1,28 @@
#ifndef SENDCOINSDIALOG_H
#define SENDCOINSDIALOG_H
#include <QDialog>
namespace Ui {
class SendCoinsDialog;
}
class SendCoinsDialog : public QDialog
{
Q_OBJECT
public:
explicit SendCoinsDialog(QWidget *parent = 0);
~SendCoinsDialog();
private:
Ui::SendCoinsDialog *ui;
private slots:
void on_buttonBox_rejected();
void on_addressBookButton_clicked();
void on_pasteButton_clicked();
void on_sendButton_clicked();
};
#endif // SENDCOINSDIALOG_H

View File

@@ -0,0 +1,37 @@
#ifndef TRANSACTIONTABLEMODEL_H
#define TRANSACTIONTABLEMODEL_H
#include <QAbstractTableModel>
#include <QStringList>
class TransactionTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit TransactionTableModel(QObject *parent = 0);
enum {
Status = 0,
Date = 1,
Description = 2,
Debit = 3,
Credit = 4,
Type = 5
} ColumnIndex;
/* Transaction type */
static const QString Sent;
static const QString Received;
static const QString Generated;
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
private:
QStringList columns;
};
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
gui/res/icons/bitcoin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
gui/res/icons/quit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B

BIN
gui/res/icons/send.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
gui/res/icons/toolbar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 B

BIN
gui/res/images/about.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

19
gui/src/aboutdialog.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include "aboutdialog.h"
#include "ui_aboutdialog.h"
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AboutDialog)
{
ui->setupUi(this);
}
AboutDialog::~AboutDialog()
{
delete ui;
}
void AboutDialog::on_buttonBox_accepted()
{
close();
}

View File

@@ -0,0 +1,132 @@
#include "addressbookdialog.h"
#include "ui_addressbookdialog.h"
#include "addresstablemodel.h"
#include "editaddressdialog.h"
#include <QSortFilterProxyModel>
#include <QDebug>
AddressBookDialog::AddressBookDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AddressBookDialog),
model(0)
{
ui->setupUi(this);
model = new AddressTableModel(this);
setModel(model);
}
AddressBookDialog::~AddressBookDialog()
{
delete ui;
}
void AddressBookDialog::setModel(AddressTableModel *model)
{
/* Receive filter */
QSortFilterProxyModel *receive_model = new QSortFilterProxyModel(this);
receive_model->setSourceModel(model);
receive_model->setDynamicSortFilter(true);
receive_model->setFilterRole(Qt::UserRole);
receive_model->setFilterKeyColumn(AddressTableModel::Type);
receive_model->setFilterFixedString(AddressTableModel::Receive);
ui->receiveTableView->setModel(receive_model);
/* Send filter */
QSortFilterProxyModel *send_model = new QSortFilterProxyModel(this);
send_model->setSourceModel(model);
send_model->setDynamicSortFilter(true);
send_model->setFilterRole(Qt::UserRole);
send_model->setFilterKeyColumn(AddressTableModel::Type);
send_model->setFilterFixedString(AddressTableModel::Send);
ui->sendTableView->setModel(send_model);
/* Set column widths */
ui->receiveTableView->horizontalHeader()->resizeSection(
AddressTableModel::Address, 320);
ui->receiveTableView->horizontalHeader()->setResizeMode(
AddressTableModel::Label, QHeaderView::Stretch);
ui->sendTableView->horizontalHeader()->resizeSection(
AddressTableModel::Address, 320);
ui->sendTableView->horizontalHeader()->setResizeMode(
AddressTableModel::Label, QHeaderView::Stretch);
/* Hide "Type" column in both views as it is only used for filtering */
ui->receiveTableView->setColumnHidden(AddressTableModel::Type, true);
ui->sendTableView->setColumnHidden(AddressTableModel::Type, true);
}
void AddressBookDialog::setTab(int tab)
{
ui->tabWidget->setCurrentIndex(tab);
}
QTableView *AddressBookDialog::getCurrentTable()
{
switch(ui->tabWidget->currentIndex())
{
case SendingTab:
return ui->sendTableView;
case ReceivingTab:
return ui->receiveTableView;
default:
return 0;
}
}
void AddressBookDialog::on_copyToClipboard_clicked()
{
/* Copy currently selected address to clipboard */
}
void AddressBookDialog::on_editButton_clicked()
{
/* Double click should trigger edit button */
EditAddressDialog dlg;
dlg.exec();
}
void AddressBookDialog::on_newAddressButton_clicked()
{
EditAddressDialog dlg;
dlg.exec();
}
void AddressBookDialog::on_tabWidget_currentChanged(int index)
{
switch(index)
{
case SendingTab:
ui->deleteButton->show();
break;
case ReceivingTab:
ui->deleteButton->hide();
break;
}
}
void AddressBookDialog::on_deleteButton_clicked()
{
QTableView *table = getCurrentTable();
QModelIndexList indexes = table->selectionModel()->selectedRows();
foreach (QModelIndex index, indexes) {
table->model()->removeRow(index.row());
}
}
void AddressBookDialog::on_buttonBox_accepted()
{
QTableView *table = getCurrentTable();
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
foreach (QModelIndex index, indexes) {
QVariant address = table->model()->data(index);
returnValue = address.toString();
}
accept();
}

View File

@@ -0,0 +1,57 @@
#include "addresstablemodel.h"
const QString AddressTableModel::Send = "S";
const QString AddressTableModel::Receive = "R";
AddressTableModel::AddressTableModel(QObject *parent) :
QAbstractTableModel(parent)
{
}
int AddressTableModel::rowCount(const QModelIndex &parent) const
{
return 5;
}
int AddressTableModel::columnCount(const QModelIndex &parent) const
{
return 3;
}
QVariant AddressTableModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
if(role == Qt::DisplayRole)
{
/* index.row(), index.column() */
/* Return QString */
if(index.column() == Address)
return "1PC9aZC4hNX2rmmrt7uHTfYAS3hRbph4UN" + QString::number(index.row());
else
return "Description";
} else if (role == Qt::UserRole)
{
switch(index.row() % 2)
{
case 0: return Send;
case 1: return Receive;
}
}
return QVariant();
}
QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return QVariant();
}
Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemIsEnabled;
return QAbstractTableModel::flags(index);
}

24
gui/src/bitcoin.cpp Normal file
View File

@@ -0,0 +1,24 @@
/*
* W.J. van der Laan 2011
*/
#include "bitcoingui.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
BitcoinGUI window;
window.setBalance(1234.567890);
window.setNumConnections(4);
window.setNumTransactions(4);
window.setNumBlocks(33);
window.setAddress("123456789");
window.show();
/* Depending on settings: QApplication::setQuitOnLastWindowClosed(false); */
return app.exec();
}

View File

@@ -0,0 +1,8 @@
#include "bitcoinaddressvalidator.h"
const QString BitcoinAddressValidator::valid_chars = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
BitcoinAddressValidator::BitcoinAddressValidator(QObject *parent) :
QRegExpValidator(QRegExp("^["+valid_chars+"]+"), parent)
{
}

275
gui/src/bitcoingui.cpp Normal file
View File

@@ -0,0 +1,275 @@
/*
* Qt4 bitcoin GUI.
*
* W.J. van der Laan 2011
*/
#include "bitcoingui.h"
#include "transactiontablemodel.h"
#include "addressbookdialog.h"
#include "sendcoinsdialog.h"
#include "optionsdialog.h"
#include "aboutdialog.h"
#include <QApplication>
#include <QMainWindow>
#include <QMenuBar>
#include <QMenu>
#include <QIcon>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QWidget>
#include <QToolBar>
#include <QStatusBar>
#include <QLabel>
#include <QTableView>
#include <QLineEdit>
#include <QPushButton>
#include <QHeaderView>
#include <QLocale>
#include <QSortFilterProxyModel>
#include <QClipboard>
#include <QDebug>
#include <iostream>
BitcoinGUI::BitcoinGUI(QWidget *parent):
QMainWindow(parent), trayIcon(0)
{
resize(850, 550);
setWindowTitle(tr("Bitcoin"));
setWindowIcon(QIcon(":icons/bitcoin"));
createActions();
/* Menus */
QMenu *file = menuBar()->addMenu("&File");
file->addAction(sendcoins);
file->addSeparator();
file->addAction(quit);
QMenu *settings = menuBar()->addMenu("&Settings");
settings->addAction(receiving_addresses);
settings->addAction(options);
QMenu *help = menuBar()->addMenu("&Help");
help->addAction(about);
/* Toolbar */
QToolBar *toolbar = addToolBar("Main toolbar");
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toolbar->addAction(sendcoins);
toolbar->addAction(addressbook);
/* Address: <address>: New... : Paste to clipboard */
QHBoxLayout *hbox_address = new QHBoxLayout();
hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:")));
address = new QLineEdit();
address->setReadOnly(true);
hbox_address->addWidget(address);
QPushButton *button_new = new QPushButton(tr("&New..."));
QPushButton *button_clipboard = new QPushButton(tr("&Copy to clipboard"));
hbox_address->addWidget(button_new);
hbox_address->addWidget(button_clipboard);
/* Balance: <balance> */
QHBoxLayout *hbox_balance = new QHBoxLayout();
hbox_balance->addWidget(new QLabel(tr("Balance:")));
hbox_balance->addSpacing(5);/* Add some spacing between the label and the text */
labelBalance = new QLabel();
labelBalance->setFont(QFont("Teletype"));
hbox_balance->addWidget(labelBalance);
hbox_balance->addStretch(1);
QVBoxLayout *vbox = new QVBoxLayout();
vbox->addLayout(hbox_address);
vbox->addLayout(hbox_balance);
transaction_model = new TransactionTableModel(this);
vbox->addWidget(createTabs());
QWidget *centralwidget = new QWidget(this);
centralwidget->setLayout(vbox);
setCentralWidget(centralwidget);
/* Create status bar */
statusBar();
labelConnections = new QLabel();
labelConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
labelConnections->setMinimumWidth(130);
labelBlocks = new QLabel();
labelBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
labelBlocks->setMinimumWidth(130);
labelTransactions = new QLabel();
labelTransactions->setFrameStyle(QFrame::Panel | QFrame::Sunken);
labelTransactions->setMinimumWidth(130);
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()));
createTrayIcon();
}
void BitcoinGUI::createActions()
{
quit = new QAction(QIcon(":/icons/quit"), tr("&Exit"), this);
sendcoins = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
addressbook = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this);
about = new QAction(QIcon(":/icons/bitcoin"), tr("&About"), this);
receiving_addresses = new QAction(QIcon(":/icons/receiving-addresses"), tr("Your &Receiving Addresses..."), this);
options = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
openBitCoin = new QAction(QIcon(":/icons/bitcoin"), "Open Bitcoin", this);
connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(sendcoins, SIGNAL(triggered()), this, SLOT(sendcoinsClicked()));
connect(addressbook, SIGNAL(triggered()), this, SLOT(addressbookClicked()));
connect(receiving_addresses, SIGNAL(triggered()), this, SLOT(receivingAddressesClicked()));
connect(options, SIGNAL(triggered()), this, SLOT(optionsClicked()));
connect(about, SIGNAL(triggered()), this, SLOT(aboutClicked()));
}
void BitcoinGUI::createTrayIcon()
{
QMenu *trayIconMenu = new QMenu(this);
trayIconMenu->addAction(openBitCoin);
trayIconMenu->addAction(sendcoins);
trayIconMenu->addAction(options);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quit);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/icons/toolbar"));
trayIcon->show();
}
QWidget *BitcoinGUI::createTabs()
{
QStringList tab_filters, tab_labels;
tab_filters << "^."
<< "^["+TransactionTableModel::Sent+TransactionTableModel::Received+"]"
<< "^["+TransactionTableModel::Sent+"]"
<< "^["+TransactionTableModel::Received+"]";
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)
{
QSortFilterProxyModel *proxy_model = new QSortFilterProxyModel(this);
proxy_model->setSourceModel(transaction_model);
proxy_model->setDynamicSortFilter(true);
proxy_model->setFilterRole(Qt::UserRole);
proxy_model->setFilterKeyColumn(TransactionTableModel::Type);
proxy_model->setFilterRegExp(QRegExp(tab_filters.at(i)));
QTableView *transaction_table = new QTableView(this);
transaction_table->setModel(proxy_model);
transaction_table->setSelectionBehavior(QAbstractItemView::SelectRows);
transaction_table->setSelectionMode(QAbstractItemView::ExtendedSelection);
transaction_table->verticalHeader()->hide();
transaction_table->horizontalHeader()->resizeSection(
TransactionTableModel::Status, 112);
transaction_table->horizontalHeader()->resizeSection(
TransactionTableModel::Date, 112);
transaction_table->horizontalHeader()->setResizeMode(
TransactionTableModel::Description, QHeaderView::Stretch);
transaction_table->horizontalHeader()->resizeSection(
TransactionTableModel::Debit, 79);
transaction_table->horizontalHeader()->resizeSection(
TransactionTableModel::Credit, 79);
transaction_table->setColumnHidden(TransactionTableModel::Type, true);
tabs->addTab(transaction_table, tab_labels.at(i));
}
return tabs;
}
void BitcoinGUI::sendcoinsClicked()
{
qDebug() << "Send coins clicked";
SendCoinsDialog dlg;
dlg.exec();
}
void BitcoinGUI::addressbookClicked()
{
qDebug() << "Address book clicked";
AddressBookDialog dlg;
dlg.setTab(AddressBookDialog::SendingTab);
dlg.exec();
}
void BitcoinGUI::receivingAddressesClicked()
{
qDebug() << "Receiving addresses clicked";
AddressBookDialog dlg;
dlg.setTab(AddressBookDialog::ReceivingTab);
dlg.exec();
}
void BitcoinGUI::optionsClicked()
{
qDebug() << "Options clicked";
OptionsDialog dlg;
dlg.exec();
}
void BitcoinGUI::aboutClicked()
{
qDebug() << "About clicked";
AboutDialog dlg;
dlg.exec();
}
void BitcoinGUI::newAddressClicked()
{
qDebug() << "New address clicked";
/* TODO: generate new address */
}
void BitcoinGUI::copyClipboardClicked()
{
qDebug() << "Copy to clipboard";
/* Copy text in address to clipboard */
QApplication::clipboard()->setText(address->text());
}
void BitcoinGUI::setBalance(double balance)
{
labelBalance->setText(QLocale::system().toString(balance, 8));
}
void BitcoinGUI::setAddress(const QString &addr)
{
address->setText(addr);
}
void BitcoinGUI::setNumConnections(int count)
{
labelConnections->setText(QLocale::system().toString(count)+" "+tr("connections"));
}
void BitcoinGUI::setNumBlocks(int count)
{
labelBlocks->setText(QLocale::system().toString(count)+" "+tr("blocks"));
}
void BitcoinGUI::setNumTransactions(int count)
{
labelTransactions->setText(QLocale::system().toString(count)+" "+tr("transactions"));
}

View File

@@ -0,0 +1,14 @@
#include "editaddressdialog.h"
#include "ui_editaddressdialog.h"
EditAddressDialog::EditAddressDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::EditAddressDialog)
{
ui->setupUi(this);
}
EditAddressDialog::~EditAddressDialog()
{
delete ui;
}

View File

@@ -0,0 +1,67 @@
#include "mainoptionspage.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
MainOptionsPage::MainOptionsPage(QWidget *parent):
QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout();
QCheckBox *bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on window system startup"));
layout->addWidget(bitcoin_at_startup);
QCheckBox *minimize_to_tray = new QCheckBox(tr("&Minimize to the tray instead of the taskbar"));
layout->addWidget(minimize_to_tray);
QCheckBox *map_port_upnp = new QCheckBox(tr("Map port using &UPnP"));
layout->addWidget(map_port_upnp);
QCheckBox *minimize_on_close = new QCheckBox(tr("M&inimize on close"));
layout->addWidget(minimize_on_close);
QCheckBox *connect_socks4 = new QCheckBox(tr("&Connect through socks4 proxy:"));
layout->addWidget(connect_socks4);
QHBoxLayout *proxy_hbox = new QHBoxLayout();
proxy_hbox->addSpacing(18);
QLabel *proxy_ip_label = new QLabel(tr("Proxy &IP: "));
proxy_hbox->addWidget(proxy_ip_label);
QLineEdit *proxy_ip = new QLineEdit();
proxy_ip->setMaximumWidth(140);
proxy_ip_label->setBuddy(proxy_ip);
proxy_hbox->addWidget(proxy_ip);
QLabel *proxy_port_label = new QLabel(tr("&Port: "));
proxy_hbox->addWidget(proxy_port_label);
QLineEdit *proxy_port = new QLineEdit();
proxy_port->setMaximumWidth(55);
proxy_port_label->setBuddy(proxy_port);
proxy_hbox->addWidget(proxy_port);
proxy_hbox->addStretch(1);
layout->addLayout(proxy_hbox);
QLabel *fee_help = new QLabel(tr("Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended."));
fee_help->setWordWrap(true);
layout->addWidget(fee_help);
QHBoxLayout *fee_hbox = new QHBoxLayout();
fee_hbox->addSpacing(18);
QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
fee_hbox->addWidget(fee_label);
QLineEdit *fee_edit = new QLineEdit();
fee_edit->setMaximumWidth(70);
fee_label->setBuddy(fee_edit);
fee_hbox->addWidget(fee_edit);
fee_hbox->addStretch(1);
layout->addLayout(fee_hbox);
layout->addStretch(1); /* Extra space at bottom */
setLayout(layout);
}

57
gui/src/optionsdialog.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include "optionsdialog.h"
#include "mainoptionspage.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QListWidget>
#include <QStackedWidget>
OptionsDialog::OptionsDialog(QWidget *parent) :
QDialog(parent), contents_widget(0), pages_widget(0)
{
contents_widget = new QListWidget();
contents_widget->setMaximumWidth(128);
pages_widget = new QStackedWidget();
pages_widget->setMinimumWidth(300);
QListWidgetItem *item_main = new QListWidgetItem(tr("Main"));
contents_widget->addItem(item_main);
pages_widget->addWidget(new MainOptionsPage(this));
contents_widget->setCurrentRow(0);
QHBoxLayout *main_layout = new QHBoxLayout();
main_layout->addWidget(contents_widget);
main_layout->addWidget(pages_widget, 1);
QVBoxLayout *layout = new QVBoxLayout();
layout->addLayout(main_layout);
QHBoxLayout *buttons = new QHBoxLayout();
buttons->addStretch(1);
QPushButton *ok_button = new QPushButton(tr("OK"));
buttons->addWidget(ok_button);
QPushButton *cancel_button = new QPushButton(tr("Cancel"));
buttons->addWidget(cancel_button);
QPushButton *apply_button = new QPushButton(tr("Apply"));
buttons->addWidget(apply_button);
layout->addLayout(buttons);
setLayout(layout);
setWindowTitle(tr("Options"));
}
void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
{
Q_UNUSED(previous);
if(current)
{
pages_widget->setCurrentIndex(contents_widget->row(current));
}
}

View File

@@ -0,0 +1,45 @@
#include "sendcoinsdialog.h"
#include "ui_sendcoinsdialog.h"
#include "addressbookdialog.h"
#include "bitcoinaddressvalidator.h"
#include <QApplication>
#include <QClipboard>
SendCoinsDialog::SendCoinsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SendCoinsDialog)
{
ui->setupUi(this);
ui->payTo->setValidator(new BitcoinAddressValidator(this));
ui->payAmount->setValidator(new QDoubleValidator(this));
}
SendCoinsDialog::~SendCoinsDialog()
{
delete ui;
}
void SendCoinsDialog::on_sendButton_clicked()
{
accept();
}
void SendCoinsDialog::on_pasteButton_clicked()
{
/* Paste text from clipboard into recipient field */
ui->payTo->setText(QApplication::clipboard()->text());
}
void SendCoinsDialog::on_addressBookButton_clicked()
{
AddressBookDialog dlg;
dlg.exec();
ui->payTo->setText(dlg.getReturnValue());
}
void SendCoinsDialog::on_buttonBox_rejected()
{
reject();
}

View File

@@ -0,0 +1,88 @@
#include "transactiontablemodel.h"
#include <QLocale>
const QString TransactionTableModel::Sent = "s";
const QString TransactionTableModel::Received = "r";
const QString TransactionTableModel::Generated = "g";
/* Credit and Debit columns are right-aligned as they contain numbers */
static int column_alignments[] = {
Qt::AlignLeft|Qt::AlignVCenter,
Qt::AlignLeft|Qt::AlignVCenter,
Qt::AlignLeft|Qt::AlignVCenter,
Qt::AlignRight|Qt::AlignVCenter,
Qt::AlignRight|Qt::AlignVCenter,
Qt::AlignLeft|Qt::AlignVCenter
};
TransactionTableModel::TransactionTableModel(QObject *parent):
QAbstractTableModel(parent)
{
columns << tr("Status") << tr("Date") << tr("Description") << tr("Debit") << tr("Credit") << tr("Type");
}
int TransactionTableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 5;
}
int TransactionTableModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return columns.length();
}
QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
if(role == Qt::DisplayRole)
{
/* index.row(), index.column() */
/* Return QString */
return QLocale::system().toString(index.row());
} else if (role == Qt::TextAlignmentRole)
{
return column_alignments[index.column()];
} else if (role == Qt::UserRole)
{
/* user role: transaction type for filtering
"s" (sent)
"r" (received)
"g" (generated)
*/
switch(index.row() % 3)
{
case 0: return QString("s");
case 1: return QString("r");
case 2: return QString("o");
}
}
return QVariant();
}
QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role == Qt::DisplayRole)
{
if(orientation == Qt::Horizontal)
{
return columns[section];
}
} else if (role == Qt::TextAlignmentRole)
{
return column_alignments[section];
}
return QVariant();
}
Qt::ItemFlags TransactionTableModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::ItemIsEnabled;
return QAbstractTableModel::flags(index);
}