Permalink
Browse files

Add Stake For Charity to GUI

  • Loading branch information...
Tranz5 committed Aug 30, 2014
1 parent 0218150 commit 427ebdae3c04e3580d7f1dbc0b099b586465ad8d
View
@@ -161,6 +161,7 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/addressbookpage.h \
src/qt/signverifymessagedialog.h \
src/qt/aboutdialog.h \
src/qt/charitydialog.h \
src/qt/editaddressdialog.h \
src/qt/bitcoinaddressvalidator.h \
src/alert.h \
@@ -245,6 +246,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/qt/addressbookpage.cpp \
src/qt/signverifymessagedialog.cpp \
src/qt/aboutdialog.cpp \
src/qt/charitydialog.cpp \
src/qt/editaddressdialog.cpp \
src/qt/bitcoinaddressvalidator.cpp \
src/alert.cpp \
@@ -315,6 +317,7 @@ FORMS += \
src/qt/forms/addressbookpage.ui \
src/qt/forms/signverifymessagedialog.ui \
src/qt/forms/aboutdialog.ui \
src/qt/forms/charitydialog.ui \
src/qt/forms/editaddressdialog.ui \
src/qt/forms/transactiondescdialog.ui \
src/qt/forms/overviewpage.ui \
View
@@ -54,10 +54,12 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
ui->labelExplanation->setVisible(false);
ui->deleteButton->setVisible(true);
ui->signMessage->setVisible(false);
ui->stakeForCharityPushButton->setVisible(true);
break;
case ReceivingTab:
ui->deleteButton->setVisible(false);
ui->signMessage->setVisible(true);
ui->stakeForCharityPushButton->setVisible(false);
break;
}
@@ -68,6 +70,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
QAction *showQRCodeAction = new QAction(ui->showQRCode->text(), this);
QAction *signMessageAction = new QAction(ui->signMessage->text(), this);
QAction *verifyMessageAction = new QAction(ui->verifyMessage->text(), this);
QAction *stakeForCharityAction = new QAction(ui->stakeForCharityPushButton->text(), this);
deleteAction = new QAction(ui->deleteButton->text(), this);
// Build context menu
@@ -81,8 +84,11 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
contextMenu->addAction(showQRCodeAction);
if(tab == ReceivingTab)
contextMenu->addAction(signMessageAction);
else if(tab == SendingTab)
else if(tab == SendingTab) {
contextMenu->addAction(verifyMessageAction);
contextMenu->addSeparator();
contextMenu->addAction(stakeForCharityAction);
}
// Connect signals for context menu actions
connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(on_copyToClipboard_clicked()));
@@ -92,6 +98,7 @@ AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
connect(showQRCodeAction, SIGNAL(triggered()), this, SLOT(on_showQRCode_clicked()));
connect(signMessageAction, SIGNAL(triggered()), this, SLOT(on_signMessage_clicked()));
connect(verifyMessageAction, SIGNAL(triggered()), this, SLOT(on_verifyMessage_clicked()));
connect(stakeForCharityAction, SIGNAL(triggered()), this, SLOT(on_stakeForCharityPushButton_clicked()));
connect(ui->tableView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint)));
@@ -216,6 +223,22 @@ void AddressBookPage::on_verifyMessage_clicked()
emit verifyMessage(addr);
}
void AddressBookPage::on_stakeForCharityPushButton_clicked()
{
QTableView *table = ui->tableView;
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
QString addr;
foreach (QModelIndex index, indexes)
{
QVariant address = index.data();
addr = address.toString();
}
emit stakeForCharitySignal(addr);
}
void AddressBookPage::on_newAddressButton_clicked()
{
if(!model)
@@ -263,6 +286,8 @@ void AddressBookPage::selectionChanged()
ui->signMessage->setVisible(false);
ui->verifyMessage->setEnabled(true);
ui->verifyMessage->setVisible(true);
ui->stakeForCharityPushButton->setEnabled(true);
ui->stakeForCharityPushButton->setVisible(true);
break;
case ReceivingTab:
// Deleting receiving addresses, however, is not allowed
@@ -273,6 +298,8 @@ void AddressBookPage::selectionChanged()
ui->signMessage->setVisible(true);
ui->verifyMessage->setEnabled(false);
ui->verifyMessage->setVisible(false);
ui->stakeForCharityPushButton->setEnabled(false);
ui->stakeForCharityPushButton->setVisible(false);
break;
}
ui->copyToClipboard->setEnabled(true);
@@ -285,6 +312,7 @@ void AddressBookPage::selectionChanged()
ui->copyToClipboard->setEnabled(false);
ui->signMessage->setEnabled(false);
ui->verifyMessage->setEnabled(false);
ui->stakeForCharityPushButton->setEnabled(false);
}
}
View
@@ -64,6 +64,7 @@ private slots:
void on_copyToClipboard_clicked();
void on_signMessage_clicked();
void on_verifyMessage_clicked();
void on_stakeForCharityPushButton_clicked();
void selectionChanged();
void on_showQRCode_clicked();
/** Spawn contextual menu (right mouse menu) for address book entry */
@@ -80,6 +81,7 @@ private slots:
signals:
void signMessage(QString addr);
void verifyMessage(QString addr);
void stakeForCharitySignal(QString addr);
};
#endif // ADDRESSBOOKPAGE_H
View
@@ -310,6 +310,10 @@ void BitcoinGUI::createActions()
aboutAction->setStatusTip(tr("Show information about HoboNickels"));
aboutAction->setMenuRole(QAction::AboutRole);
charityAction = new QAction(QIcon(":/icons/send"), tr("Stake For &Charity"), this);
charityAction->setStatusTip(tr("Enable Stake For Charity"));
charityAction->setToolTip(charityAction->statusTip());
aboutQtAction = new QAction(QIcon(":/trolltech/qmessagebox/images/qtlogo-64.png"), tr("About &Qt"), this);
aboutQtAction->setStatusTip(tr("Show information about Qt"));
aboutQtAction->setMenuRole(QAction::AboutQtRole);
@@ -389,6 +393,7 @@ void BitcoinGUI::createActions()
connect(blocksIconAction, SIGNAL(triggered()), this, SLOT(blocksIconClicked()));
connect(connectionIconAction, SIGNAL(triggered()), this, SLOT(connectionIconClicked()));
connect(stakingIconAction, SIGNAL(triggered()), this, SLOT(stakingIconClicked()));
connect(charityAction, SIGNAL(triggered()), this, SLOT(charityClicked()));
}
void BitcoinGUI::createMenuBar()
@@ -421,6 +426,7 @@ void BitcoinGUI::createMenuBar()
QMenu *wallet = appMenuBar->addMenu(tr("&Wallet"));
wallet->addAction(encryptWalletAction);
wallet->addAction(changePassphraseAction);
wallet->addSeparator();
wallet->addAction(unlockWalletAction);
wallet->addAction(lockWalletAction);
wallet->addSeparator();
@@ -429,6 +435,9 @@ void BitcoinGUI::createMenuBar()
wallet->addSeparator();
wallet->addAction(signMessageAction);
wallet->addAction(verifyMessageAction);
wallet->addSeparator();
wallet->addAction(charityAction);
QMenu *network = appMenuBar->addMenu(tr("&Network"));
network->addAction(blockAction);
@@ -742,6 +751,8 @@ void BitcoinGUI::stakingIconClicked()
,CClientUIInterface::MODAL);
}
void BitcoinGUI::gotoBlockBrowser()
{
if (walletStack) walletStack->gotoBlockBrowser();
@@ -1263,6 +1274,11 @@ void BitcoinGUI::unlockWalletForMint()
if (walletStack) walletStack->unlockWalletForMint();
}
void BitcoinGUI::charityClicked(QString addr)
{
if (walletStack) walletStack->charityClicked(addr);
}
void BitcoinGUI::showNormalIfMinimized(bool fToggleHidden)
{
View
@@ -98,6 +98,7 @@ class BitcoinGUI : public QMainWindow
QAction *signMessageAction;
QAction *verifyMessageAction;
QAction *aboutAction;
QAction *charityAction;
QAction *receiveCoinsAction;
QAction *optionsAction;
QAction *toggleHideAction;
@@ -202,6 +203,8 @@ private slots:
void optionsClicked();
/** Show about dialog */
void aboutClicked();
/** Show Stake For Charity Dialog */
void charityClicked(QString addr = "");
/** Show information about network */
void blocksIconClicked();
/** Allow user to lock/unlock wallet from click */
View
@@ -0,0 +1,100 @@
#include "charitydialog.h"
#include "ui_charitydialog.h"
#include "walletmodel.h"
#include "base58.h"
#include "addressbookpage.h"
StakeForCharityDialog::StakeForCharityDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::StakeForCharityDialog),
model(0)
{
ui->setupUi(this);
ui->label_2->setFocus();
}
StakeForCharityDialog::~StakeForCharityDialog()
{
delete ui;
}
void StakeForCharityDialog::setModel(WalletModel *model)
{
this->model = model;
}
void StakeForCharityDialog::setAddress(const QString &address)
{
ui->charityAddressEdit->setText(address);
ui->charityAddressEdit->setFocus();
}
void StakeForCharityDialog::on_addressBookButton_clicked()
{
if (model && model->getAddressTableModel())
{
AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this);
dlg.setModel(model->getAddressTableModel());
if (dlg.exec())
{
setAddress(dlg.getReturnValue());
}
}
}
void StakeForCharityDialog::on_enableButton_clicked()
{
CBitcoinAddress address = ui->charityAddressEdit->text().toStdString();
if(model->getEncryptionStatus() == WalletModel::Locked)
{
ui->message->setStyleSheet("QLabel { color: black; }");
ui->message->setText(tr("Please unlock wallet before starting stake for charity."));
return;
}
if (!address.IsValid())
{
ui->message->setStyleSheet("QLabel { color: red; }");
ui->message->setText(tr("The entered address: ") + ui->charityAddressEdit->text() + tr(" is invalid.\nPlease check the address and try again."));
return;
}
QString str = ui->charityPercentEdit->text();
bool fIntConversion;
int nCharityPercent = str.toInt(&fIntConversion, 10);
if (!fIntConversion || nCharityPercent > 50 || nCharityPercent <= 0)
{
ui->message->setStyleSheet("QLabel { color: red; }");
ui->message->setText(tr("Please Enter 1 - 50 for percent."));
ui->charityPercentEdit->clear();
return;
}
model->setStakeForCharity(true, nCharityPercent, address);
ui->message->setStyleSheet("QLabel { color: green; }");
ui->message->setText(tr("Thank you for giving to\n") + QString(address.ToString().c_str()) + tr("."));
return;
}
void StakeForCharityDialog::on_disableButton_clicked()
{
model->setStakeForCharity(false,0,"");
ui->charityAddressEdit->clear();
ui->charityMaxEdit->clear();
ui->charityMinEdit->clear();
ui->charityPercentEdit->clear();
ui->message->setStyleSheet("QLabel { color: black; }");
ui->message->setText(tr("Stake for Charity is now off"));
return;
}
void StakeForCharityDialog::on_closeButton_clicked()
{
close();
}
View
@@ -0,0 +1,36 @@
#ifndef CHARITYDIALOG_H
#define CHARITYDIALOG_H
#include <QDialog>
namespace Ui {
class StakeForCharityDialog;
}
class WalletModel;
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
class StakeForCharityDialog : public QDialog
{
Q_OBJECT
public:
explicit StakeForCharityDialog(QWidget *parent = 0);
~StakeForCharityDialog();
void setModel(WalletModel *model);
void setAddress(const QString &address);
private slots:
void on_enableButton_clicked();
void on_disableButton_clicked();
void on_closeButton_clicked();
void on_addressBookButton_clicked();
private:
Ui::StakeForCharityDialog *ui;
WalletModel *model;
};
#endif // CHARITYDIALOG_H
@@ -124,6 +124,20 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stakeForCharityPushButton">
<property name="toolTip">
<string>Send a percentage of stake to a specified HoboNickels address</string>
</property>
<property name="text">
<string>&amp;Stake For Charity</string>
</property>
<property name="icon">
<iconset resource="../bitcoin.qrc">
<normaloff>:/icons/send</normaloff>:/icons/send</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton">
<property name="toolTip">
Oops, something went wrong.

0 comments on commit 427ebda

Please sign in to comment.