From a09b15f79e15d012aa26e0f4dc44cd717ff37df7 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Sat, 25 Nov 2023 14:27:22 +0100 Subject: [PATCH] ccs: add MAGIC monero fund --- src/MainWindow.cpp | 2 +- src/MainWindow.ui | 4 ++-- src/plugins/ccs/CCSEntry.h | 14 ++++++++------ src/plugins/ccs/CCSModel.cpp | 10 +++++++--- src/plugins/ccs/CCSModel.h | 1 + src/plugins/ccs/CCSWidget.cpp | 27 ++++++++++----------------- src/plugins/ccs/CCSWidget.h | 1 - src/plugins/ccs/CCSWidget.ui | 13 +++++-------- src/utils/WebsocketNotifier.cpp | 17 +++++++++++++++-- 9 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index f2578e2..f5719ae 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1111,7 +1111,7 @@ void MainWindow::payToMany() { } void MainWindow::showSendScreen(const CCSEntry &entry) { // TODO: rename this function - m_sendWidget->fill(entry.address, QString("CCS: %1").arg(entry.title)); + m_sendWidget->fill(entry.address, QString("Donation to %1: %2").arg(entry.organizer, entry.title)); ui->tabWidget->setCurrentIndex(Tabs::SEND); } diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 710e39e..f1bdc7e 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -122,7 +122,7 @@ - CCS + Crowdfunding @@ -479,7 +479,7 @@ 0 0 977 - 27 + 24 diff --git a/src/plugins/ccs/CCSEntry.h b/src/plugins/ccs/CCSEntry.h index bf1dfdc..07c5649 100644 --- a/src/plugins/ccs/CCSEntry.h +++ b/src/plugins/ccs/CCSEntry.h @@ -9,12 +9,14 @@ struct CCSEntry { CCSEntry()= default;; - QString title = ""; - QString date = ""; - QString address = ""; - QString author = ""; - QString state = ""; - QString url = ""; + QString title; + QString date; + QString address; + QString author; + QString state; + QString url; + QString organizer; + QString currency; double target_amount = 0; double raised_amount = 0; double percentage_funded = 0; diff --git a/src/plugins/ccs/CCSModel.cpp b/src/plugins/ccs/CCSModel.cpp index 769f9ea..a8e9d1c 100644 --- a/src/plugins/ccs/CCSModel.cpp +++ b/src/plugins/ccs/CCSModel.cpp @@ -54,10 +54,12 @@ QVariant CCSModel::data(const QModelIndex &index, int role) const switch(index.column()) { case Title: return entry->title; + case Organizer: + return entry->organizer; case Author: - return entry->author; + return QString("%1 ").arg(entry->author); case Progress: - return QString("%1/%2 XMR").arg(entry->raised_amount).arg(entry->target_amount); + return QString("%1/%2 %3").arg(QString::number(entry->raised_amount), QString::number(entry->target_amount), entry->currency); default: return QVariant(); } @@ -74,7 +76,9 @@ QVariant CCSModel::headerData(int section, Qt::Orientation orientation, int role { switch(section) { case Title: - return QString("Community Crowdfunding Proposal"); + return QString("Proposal"); + case Organizer: + return QString("Organizer"); case Author: return QString("Author"); case Progress: diff --git a/src/plugins/ccs/CCSModel.h b/src/plugins/ccs/CCSModel.h index 7b34416..d4d0dbe 100644 --- a/src/plugins/ccs/CCSModel.h +++ b/src/plugins/ccs/CCSModel.h @@ -17,6 +17,7 @@ public: enum ModelColumn { Title = 0, + Organizer, Author, Progress, COUNT diff --git a/src/plugins/ccs/CCSWidget.cpp b/src/plugins/ccs/CCSWidget.cpp index 96f3842..d2ace60 100644 --- a/src/plugins/ccs/CCSWidget.cpp +++ b/src/plugins/ccs/CCSWidget.cpp @@ -18,16 +18,17 @@ CCSWidget::CCSWidget(QWidget *parent) , m_contextMenu(new QMenu(this)) { ui->setupUi(this); - ui->tableView->setModel(m_model); - this->setupTable(); + ui->treeView->setModel(m_model); m_contextMenu->addAction("View proposal", this, &CCSWidget::linkClicked); m_contextMenu->addAction("Donate", this, &CCSWidget::donateClicked); - connect(ui->tableView, &QHeaderView::customContextMenuRequested, this, &CCSWidget::showContextMenu); - connect(ui->tableView, &QTableView::doubleClicked, this, &CCSWidget::linkClicked); + connect(ui->treeView, &QHeaderView::customContextMenuRequested, this, &CCSWidget::showContextMenu); + connect(ui->treeView, &QTreeView::doubleClicked, this, &CCSWidget::linkClicked); - ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + ui->treeView->header()->setSectionResizeMode(CCSModel::Title, QHeaderView::Stretch); } CCSModel* CCSWidget::model() { @@ -35,7 +36,7 @@ CCSModel* CCSWidget::model() { } void CCSWidget::linkClicked() { - QModelIndex index = ui->tableView->currentIndex(); + QModelIndex index = ui->treeView->currentIndex(); auto entry = m_model->entry(index.row()); if (entry) { @@ -44,28 +45,20 @@ void CCSWidget::linkClicked() { } void CCSWidget::donateClicked() { - QModelIndex index = ui->tableView->currentIndex(); + QModelIndex index = ui->treeView->currentIndex(); auto entry = m_model->entry(index.row()); if (entry) emit selected(*entry); } -void CCSWidget::setupTable() { - ui->tableView->verticalHeader()->setVisible(false); - ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); - - ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); - ui->tableView->setColumnWidth(2, 160); -} - void CCSWidget::showContextMenu(const QPoint &pos) { - QModelIndex index = ui->tableView->indexAt(pos); + QModelIndex index = ui->treeView->indexAt(pos); if (!index.isValid()) { return; } - m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos)); + m_contextMenu->exec(ui->treeView->viewport()->mapToGlobal(pos)); } CCSWidget::~CCSWidget() = default; \ No newline at end of file diff --git a/src/plugins/ccs/CCSWidget.h b/src/plugins/ccs/CCSWidget.h index 473bbb4..cd344cf 100644 --- a/src/plugins/ccs/CCSWidget.h +++ b/src/plugins/ccs/CCSWidget.h @@ -36,7 +36,6 @@ private slots: void linkClicked(); private: - void setupTable(); void showContextMenu(const QPoint &pos); QScopedPointer ui; diff --git a/src/plugins/ccs/CCSWidget.ui b/src/plugins/ccs/CCSWidget.ui index c02ad8f..51163e3 100644 --- a/src/plugins/ccs/CCSWidget.ui +++ b/src/plugins/ccs/CCSWidget.ui @@ -30,20 +30,17 @@ 0 - + Qt::CustomContextMenu - - QAbstractItemView::NoEditTriggers + + true - - QAbstractItemView::SingleSelection - - + false - + false diff --git a/src/utils/WebsocketNotifier.cpp b/src/utils/WebsocketNotifier.cpp index 4cf4c0d..346a8b6 100644 --- a/src/utils/WebsocketNotifier.cpp +++ b/src/utils/WebsocketNotifier.cpp @@ -156,7 +156,7 @@ void WebsocketNotifier::onWSReddit(const QJsonArray& reddit_data) { void WebsocketNotifier::onWSCCS(const QJsonArray &ccs_data) { QList> l; - for (auto &&entry: ccs_data) { + for (const auto& entry: ccs_data) { auto obj = entry.toObject(); auto c = QSharedPointer(new CCSEntry()); @@ -168,11 +168,24 @@ void WebsocketNotifier::onWSCCS(const QJsonArray &ccs_data) { c->author = obj.value("author").toString(); c->date = obj.value("date").toString(); c->title = obj.value("title").toString(); - c->url = obj.value("url").toString(); c->target_amount = obj.value("target_amount").toDouble(); c->raised_amount = obj.value("raised_amount").toDouble(); c->percentage_funded = obj.value("percentage_funded").toDouble(); c->contributions = obj.value("contributions").toInt(); + c->organizer = obj.value("organizer").toString(); + c->currency = obj.value("currency").toString(); + + QString urlpath = obj.value("urlpath").toString(); + if (c->organizer == "CCS") { + c->url = QString("https://ccs.getmonero.org/%1").arg(urlpath); + } + else if (c->organizer == "MAGIC") { + c->url = QString("https://monerofund.org/%1").arg(urlpath); + } + else { + continue; + } + l.append(c); }