diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 34e8b28..6b37355 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -45,6 +45,10 @@ MainWindow::MainWindow(QWidget *parent) :
rpc->checkForUpdate(false);
});
+ QObject::connect(ui->action_Recurring_Payments, &QAction::triggered, [=]() {
+ Recurring::getInstance()->showRecurringDialog();
+ });
+
// Pay Zcash URI
QObject::connect(ui->actionPay_URI, &QAction::triggered, this, &MainWindow::payZcashURI);
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 72647a6..cf6dcf8 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -346,8 +346,8 @@
0
0
- 920
- 301
+ 928
+ 353
@@ -1069,6 +1069,7 @@
+
@@ -1161,6 +1162,11 @@
Ctrl+M
+
+
+ &Recurring Payments
+
+
diff --git a/src/recurring.cpp b/src/recurring.cpp
index e01afbd..fe07b6a 100644
--- a/src/recurring.cpp
+++ b/src/recurring.cpp
@@ -4,6 +4,7 @@
#include "rpc.h"
#include "settings.h"
#include "ui_newrecurring.h"
+#include "ui_recurringdialog.h"
QString schedule_desc(Schedule s) {
switch (s) {
@@ -15,7 +16,6 @@ QString schedule_desc(Schedule s) {
}
}
-
RecurringPaymentInfo RecurringPaymentInfo::fromJson(QJsonObject j) {
RecurringPaymentInfo r;
r.hashid = j["hash"].toString();
@@ -209,7 +209,6 @@ QDateTime Recurring::getNextPaymentDate(Schedule s) {
return nextDate;
}
-
QString Recurring::writeableFile() {
auto filename = QStringLiteral("recurringpayments.json");
@@ -235,6 +234,22 @@ void Recurring::addRecurringInfo(const RecurringPaymentInfo& rpi) {
writeToStorage();
}
+
+void Recurring::readFromFile() {
+ QFile file(writeableFile());
+ file.open(QIODevice::ReadOnly);
+
+ QTextStream in(&file);
+ auto jsondoc = QJsonDocument::fromJson(in.readAll().toUtf8());
+
+ for (auto k : jsondoc.array()) {
+ auto p = RecurringPaymentInfo::fromJson(k.toObject());
+ p.updateHash();
+ payments.insert(p.hashid, p);
+ }
+}
+
+
void Recurring::writeToStorage() {
QFile file(writeableFile());
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
@@ -250,13 +265,36 @@ void Recurring::writeToStorage() {
file.close();
}
+Recurring* Recurring::getInstance() {
+ if (!instance) {
+ instance = new Recurring();
+ instance->readFromFile();
+ }
+
+ return instance;
+}
+
// Singleton
Recurring* Recurring::instance = nullptr;
+void Recurring::showRecurringDialog() {
+ Ui_RecurringDialog rd;
+ QDialog d;
+
+ rd.setupUi(&d);
+ Settings::saveRestore(&d);
+
+ auto model = new RecurringListViewModel(rd.tableView);
+ rd.tableView->setModel(model);
+
+ d.exec();
+ delete model;
+}
+
RecurringListViewModel::RecurringListViewModel(QTableView* parent) {
this->parent = parent;
- headers << tr("To") << tr("Amount") << tr("Schedule") << tr("Payments Left");
+ headers << tr("Amount") << tr("Schedule") << tr("Payments Left") << tr("To");
}
@@ -272,10 +310,11 @@ QVariant RecurringListViewModel::data(const QModelIndex &index, int role) const
auto rpi = Recurring::getInstance()->getAsList().at(index.row());
if (role == Qt::DisplayRole) {
switch (index.column()) {
- case 0: return rpi.toAddr;
- case 1: return rpi.getAmountPretty();
- case 2: return schedule_desc(rpi.schedule);
- case 3: return rpi.numPayments - rpi.completedPayments;
+ case 0: return rpi.getAmountPretty();
+ case 1: return tr("Every ") + schedule_desc(rpi.schedule);
+ case 2: return rpi.numPayments - rpi.completedPayments;
+ case 3: return rpi.toAddr;
+ //case 4: return Recurring::getNextPaymentDate(rpi.)
}
}
@@ -283,5 +322,15 @@ QVariant RecurringListViewModel::data(const QModelIndex &index, int role) const
}
QVariant RecurringListViewModel::headerData(int section, Qt::Orientation orientation, int role) const {
+ if (role == Qt::FontRole) {
+ QFont f;
+ f.setBold(true);
+ return f;
+ }
+
+ if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
+ return headers.at(section);
+ }
+
return QVariant();
}
\ No newline at end of file
diff --git a/src/recurring.h b/src/recurring.h
index 2ea1ca2..54ccefe 100644
--- a/src/recurring.h
+++ b/src/recurring.h
@@ -54,14 +54,16 @@ struct RecurringPaymentInfo {
class Recurring
{
public:
- static Recurring* getInstance() { if (!instance) { instance = new Recurring(); } return instance; }
+ static Recurring* getInstance();
- RecurringPaymentInfo* getNewRecurringFromTx(QWidget* parent, MainWindow* main, Tx tx, RecurringPaymentInfo* rpi);
-
- QDateTime getNextPaymentDate(Schedule s);
+ RecurringPaymentInfo* getNewRecurringFromTx(QWidget* parent, MainWindow* main, Tx tx, RecurringPaymentInfo* rpi);
+
void updateInfoWithTx(RecurringPaymentInfo* r, Tx tx);
-
QString writeableFile();
+ void readFromFile();
+
+ static void showRecurringDialog();
+ static QDateTime getNextPaymentDate(Schedule s);
void addRecurringInfo(const RecurringPaymentInfo& rpi);
void writeToStorage();
diff --git a/src/recurringdialog.ui b/src/recurringdialog.ui
index c957d87..164887a 100644
--- a/src/recurringdialog.ui
+++ b/src/recurringdialog.ui
@@ -15,7 +15,11 @@
-
-
+
+
+ true
+
+
-
diff --git a/src/rpc.cpp b/src/rpc.cpp
index 5f8276f..66908cf 100644
--- a/src/rpc.cpp
+++ b/src/rpc.cpp
@@ -748,15 +748,10 @@ void RPC::refreshBalances() {
ui->balTransparent->setText(Settings::getZECDisplayFormat(balT));
ui->balTotal ->setText(Settings::getZECDisplayFormat(balTotal));
-<<<<<<< HEAD
- ui->balSheilded ->setToolTip(Settings::getUSDFromZecAmount(balZ));
- ui->balTransparent->setToolTip(Settings::getUSDFromZecAmount(balT));
- ui->balTotal ->setToolTip(Settings::getUSDFromZecAmount(tot));
-=======
+
ui->balSheilded ->setToolTip(Settings::getUSDFormat(balZ));
ui->balTransparent->setToolTip(Settings::getUSDFormat(balT));
ui->balTotal ->setToolTip(Settings::getUSDFormat(balTotal));
->>>>>>> master
});
// 2. Get the UTXOs
diff --git a/src/sendtab.cpp b/src/sendtab.cpp
index 6cb7a86..4780a0f 100644
--- a/src/sendtab.cpp
+++ b/src/sendtab.cpp
@@ -99,11 +99,6 @@ void MainWindow::setupSendTab() {
// Recurring schedule button
QObject::connect(ui->btnRecurSchedule, &QPushButton::clicked, this, &MainWindow::editSchedule);
- // Hide the recurring section for now
- ui->chkRecurring->setVisible(false);
- ui->lblRecurDesc->setVisible(false);
- ui->btnRecurSchedule->setVisible(false);
-
// Set the default state for the whole page
clearSendForm();
}