diff --git a/src/mainwindow.h b/src/mainwindow.h index 5b5350e..d37ce6c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -38,6 +38,7 @@ public: ~MainWindow(); void updateLabelsAutoComplete(); + RPC* getRPC() { return rpc; } void setDefaultPayFrom(); @@ -76,6 +77,8 @@ private: void addAddressSection(); void maxAmountChecked(int checked); + void editSchedule(); + void addressChanged(int number, const QString& text); void amountChanged (int number, const QString& text); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 799fc90..e86c960 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -346,8 +346,8 @@ 0 0 - 928 - 380 + 920 + 301 @@ -531,29 +531,36 @@ - + - + - Miner Fee + Recurring payment - - - - 0 - 0 - + + + Every month, starting 12-May-2012, for 6 payments + + + + - 0 + Edit Schedule + + + false + + + false - + Qt::Horizontal @@ -565,34 +572,57 @@ + + + + - + - + Miner Fee - + + + + 0 + 0 + + - This transaction does not recur + 0 - + - Setup Recurring Payment + - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -1013,7 +1043,7 @@ 0 0 968 - 19 + 22 diff --git a/src/newrecurring.ui b/src/newrecurring.ui index d1b70fa..f8f8521 100644 --- a/src/newrecurring.ui +++ b/src/newrecurring.ui @@ -1,29 +1,26 @@ - Dialog - + newRecurringDialog + 0 0 - 400 - 300 + 740 + 403 - Dialog + Edit Schedule - - - - - + + - + - + Qt::Horizontal @@ -37,10 +34,7 @@ - - - - + Qt::Horizontal @@ -50,85 +44,51 @@ - - - - - - - To - - - - - - - From - - - - + Schedule - - - - Number of payments - - - - - - - Amount - - - - - + + - Next Payment + Payment Description - - + + TextLabel - - - - Payment Description + + + + Qt::Horizontal - - - - - + + - - - Every + + + + 0 + 0 + - + - - - - + Qt::Horizontal @@ -142,17 +102,50 @@ - + + + + + + + From + + + + + + + Number of payments + + + + + + + Amount + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + - - - - - - Forever - - + @@ -169,21 +162,57 @@ - - - - Qt::Horizontal + + + + Next Payment + + + + + + + + + + To + + + + + + + + + + Memo + + + AddressCombo + QComboBox +
addresscombo.h
+
+
+ + txtDesc + cmbFromAddress + txtToAddr + txtAmt + cmbCurrency + cmbSchedule + txtNumPayments + buttonBox accepted() - Dialog + newRecurringDialog accept() @@ -199,7 +228,7 @@ buttonBox rejected() - Dialog + newRecurringDialog reject() diff --git a/src/recurring.cpp b/src/recurring.cpp index 032794a..64affec 100644 --- a/src/recurring.cpp +++ b/src/recurring.cpp @@ -1,14 +1,48 @@ #include "recurring.h" -#include "ui_recurringdialog.h" - -RecurringDialog::RecurringDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::RecurringDialog) -{ - ui->setupUi(this); -} - -RecurringDialog::~RecurringDialog() -{ - delete ui; -} + +#include "mainwindow.h" +#include "rpc.h" +#include "settings.h" +#include "ui_newrecurring.h" + +void Recurring::showEditDialog(QWidget* parent, MainWindow* main, Tx tx) { + Ui_newRecurringDialog ui; + QDialog d(parent); + ui.setupUi(&d); + Settings::saveRestore(&d); + + // Add all the from addresses + auto allBalances = main->getRPC()->getAllBalances(); + for (QString addr : allBalances->keys()) { + ui.cmbFromAddress->addItem(addr, allBalances->value(addr)); + } + + if (!tx.fromAddr.isEmpty()) { + ui.cmbFromAddress->setCurrentText(tx.fromAddr); + ui.cmbFromAddress->setEnabled(false); + } + + ui.cmbCurrency->addItem(Settings::getTokenName()); + ui.cmbCurrency->addItem("USD"); + + if (tx.toAddrs.length() > 0) { + ui.txtToAddr->setText(tx.toAddrs[0].addr); + ui.txtToAddr->setEnabled(false); + + ui.txtAmt->setText(Settings::getDecimalString(tx.toAddrs[0].amount)); + ui.txtAmt->setEnabled(false); + + ui.txtMemo->setPlainText(tx.toAddrs[0].txtMemo); + ui.txtMemo->setEnabled(false); + } + + ui.cmbSchedule->addItem("Every Day", QVariant(Schedule::DAY)); + ui.cmbSchedule->addItem("Every Week", QVariant(Schedule::WEEK)); + ui.cmbSchedule->addItem("Every Month", QVariant(Schedule::MONTH)); + ui.cmbSchedule->addItem("Every Year", QVariant(Schedule::YEAR)); + + ui.txtNumPayments->setText("10"); + + ui.txtDesc->setFocus(); + d.exec(); +} \ No newline at end of file diff --git a/src/recurring.h b/src/recurring.h index 2cc86ae..3f27115 100644 --- a/src/recurring.h +++ b/src/recurring.h @@ -1,22 +1,36 @@ #ifndef RECURRING_H #define RECURRING_H -#include +#include "precompiled.h" -namespace Ui { -class RecurringDialog; -} +#include "mainwindow.h" -class RecurringDialog : public QDialog -{ - Q_OBJECT +enum Schedule { + DAY = 1, + WEEK, + MONTH, + YEAR +}; + +struct RecurringPaymentInfo { + QString desc; + QString fromAddr; + QString toAddr; + double amt; + QString currency; + Schedule schedule; + int numPayments; + long startBlock; + int completedPayments; +}; + +class Recurring +{ public: - explicit RecurringDialog(QWidget *parent = nullptr); - ~RecurringDialog(); + Recurring(); -private: - Ui::RecurringDialog *ui; + static void showEditDialog(QWidget* parent, MainWindow* main, Tx tx); }; -#endif // RECURRING_H +#endif // RECURRING_H \ No newline at end of file diff --git a/src/sendtab.cpp b/src/sendtab.cpp index d5f51d7..05ce4dc 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -3,8 +3,10 @@ #include "addressbook.h" #include "ui_confirm.h" #include "ui_memodialog.h" +#include "ui_newrecurring.h" #include "settings.h" #include "rpc.h" +#include "recurring.h" using json = nlohmann::json; @@ -80,6 +82,29 @@ void MainWindow::setupSendTab() { QFont f = ui->Address1->font(); f.setPointSize(f.pointSize() - 1); ui->MemoTxt1->setFont(f); + + // Recurring button + QObject::connect(ui->chkRecurring, &QCheckBox::stateChanged, [=] (int checked) { + if (checked) { + ui->btnRecurSchedule->setEnabled(true); + } else { + ui->btnRecurSchedule->setEnabled(false); + ui->lblRecurDesc->setText(""); + } + + }); + + // Recurring schedule button + QObject::connect(ui->btnRecurSchedule, &QPushButton::clicked, this, &MainWindow::editSchedule); + + // Set the default state for the whole page + removeExtraAddresses(); +} + +void MainWindow::editSchedule() { + // Open the edit schedule dialog + Recurring::showEditDialog(this, this, createTxFromSendPage()); + } void MainWindow::updateLabelsAutoComplete() { @@ -354,6 +379,11 @@ void MainWindow::removeExtraAddresses() { delete addressGroupBox; } + + // Reset the recurring button + ui->chkRecurring->setCheckState(Qt::Unchecked); + ui->btnRecurSchedule->setEnabled(false); + ui->lblRecurDesc->setText(""); } void MainWindow::maxAmountChecked(int checked) {