Home: Revuo Monero

This commit is contained in:
tobtoht 2022-05-25 22:40:56 +02:00
parent 13c3e9b8e2
commit d82905c460
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
8 changed files with 270 additions and 0 deletions

View file

@ -63,6 +63,7 @@ MainWindow::MainWindow(WindowManager *windowManager, Wallet *wallet, QWidget *pa
// Websocket notifier
connect(websocketNotifier(), &WebsocketNotifier::CCSReceived, ui->ccsWidget->model(), &CCSModel::updateEntries);
connect(websocketNotifier(), &WebsocketNotifier::RedditReceived, ui->redditWidget->model(), &RedditModel::updatePosts);
connect(websocketNotifier(), &WebsocketNotifier::RevuoReceived, ui->revuoWidget, &RevuoWidget::updateItems);
connect(websocketNotifier(), &WebsocketNotifier::UpdatesReceived, this, &MainWindow::onUpdatesAvailable);
#ifdef HAS_XMRIG
connect(websocketNotifier(), &WebsocketNotifier::XMRigDownloadsReceived, m_xmrig, &XMRigWidget::onDownloads);
@ -373,6 +374,10 @@ void MainWindow::initHome() {
connect(ui->ccsWidget, &CCSWidget::selected, this, &MainWindow::showSendScreen);
connect(ui->redditWidget, &RedditWidget::setStatusText, this, &MainWindow::setStatusText);
connect(ui->revuoWidget, &RevuoWidget::donate, [this](const QString &address, const QString &description){
m_sendWidget->fill(address, description);
ui->tabWidget->setCurrentIndex(Tabs::SEND);
});
}
void MainWindow::initWalletContext() {
@ -887,6 +892,7 @@ void MainWindow::updateWidgetIcons() {
m_localMoneroWidget->skinChanged();
#endif
ui->conversionWidget->skinChanged();
ui->revuoWidget->skinChanged();
m_statusBtnHwDevice->setIcon(this->hardwareDevicePairedIcon());
}

View file

@ -145,6 +145,28 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Revuo</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="RevuoWidget" name="revuoWidget" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
@ -872,6 +894,12 @@
<header>widgets/RedditWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>RevuoWidget</class>
<extends>QWidget</extends>
<header>widgets/RevuoWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="assets.qrc"/>

View file

@ -60,6 +60,11 @@ void WebsocketNotifier::onWSMessage(const QJsonObject &msg) {
emit TxFiatHistoryReceived(txFiatHistory_data);
}
else if(cmd == "revuo") {
auto revuo_data = msg.value("data").toArray();
this->onWSRevuo(revuo_data);
}
#if defined(CHECK_UPDATES)
else if (cmd == "updates") {
this->onWSUpdates(msg.value("data").toObject());
@ -176,6 +181,29 @@ void WebsocketNotifier::onWSCCS(const QJsonArray &ccs_data) {
emit CCSReceived(l);
}
void WebsocketNotifier::onWSRevuo(const QJsonArray &revuo_data) {
QList<QSharedPointer<RevuoItem>> l;
for (auto &&entry: revuo_data) {
auto obj = entry.toObject();
QStringList newsbytes;
for (const auto &n : obj.value("newsbytes").toArray()) {
newsbytes.append(n.toString());
}
auto revuoItem = new RevuoItem(
obj.value("title").toString(),
obj.value("url").toString(),
newsbytes);
QSharedPointer<RevuoItem> r = QSharedPointer<RevuoItem>(revuoItem);
l.append(r);
}
emit RevuoReceived(l);
}
void WebsocketNotifier::onWSUpdates(const QJsonObject &updates) {
emit UpdatesReceived(updates);
}

View file

@ -13,6 +13,7 @@
#include "prices.h"
#include "widgets/RedditPost.h"
#include "widgets/CCSEntry.h"
#include "widgets/RevuoItem.h"
#include "TxFiatHistory.h"
class WebsocketNotifier : public QObject {
@ -36,6 +37,7 @@ signals:
void FiatRatesReceived(const QJsonObject &fiat_rates);
void RedditReceived(QList<QSharedPointer<RedditPost>> L);
void CCSReceived(QList<QSharedPointer<CCSEntry>> L);
void RevuoReceived(QList<QSharedPointer<RevuoItem>> L);
void TxFiatHistoryReceived(const QJsonObject &data);
void UpdatesReceived(const QJsonObject &updates);
void XMRigDownloadsReceived(const QJsonObject &downloads);
@ -49,6 +51,7 @@ private slots:
void onWSNodes(const QJsonArray &nodes);
void onWSReddit(const QJsonArray &reddit_data);
void onWSCCS(const QJsonArray &ccs_data);
void onWSRevuo(const QJsonArray &revuo_data);
void onWSUpdates(const QJsonObject &updates);
void onWSXMRigDownloads(const QJsonObject &downloads);

19
src/widgets/RevuoItem.h Normal file
View file

@ -0,0 +1,19 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
#ifndef FEATHER_REVUOITEM_H
#define FEATHER_REVUOITEM_H
#include <QString>
#include <QStringList>
struct RevuoItem {
RevuoItem(const QString &title, const QString &url, const QStringList &newsbytes)
: title(title), url(url), newsbytes(newsbytes){};
QString title;
QString url;
QStringList newsbytes;
};
#endif //FEATHER_REVUOITEM_H

View file

@ -0,0 +1,92 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
#include "RevuoWidget.h"
#include "ui_RevuoWidget.h"
#include "utils/ColorScheme.h"
#include "Utils.h"
RevuoWidget::RevuoWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::RevuoWidget)
, m_contextMenu(new QMenu(this))
{
ui->setupUi(this);
ui->textBrowser->setOpenLinks(false);
ui->textBrowser->document()->setDefaultStyleSheet("a {color: white; }");
connect(ui->textBrowser, &QTextBrowser::anchorClicked, this, &RevuoWidget::onLinkActivated);
ui->textBrowser->setText("<h4>No item selected</h4>");
m_contextMenu->addAction("Open link", this, &RevuoWidget::onOpenLink);
m_contextMenu->addAction("Donate to author", this, &RevuoWidget::onDonate);
connect(ui->listWidget, &QListWidget::currentTextChanged, this, &RevuoWidget::onSelectItem);
connect(ui->listWidget, &QListWidget::customContextMenuRequested, this, &RevuoWidget::showContextMenu);
}
void RevuoWidget::updateItems(const QList<QSharedPointer<RevuoItem>> &items) {
QStringList titles;
for (const auto &item : items) {
titles << item->title;
QString text = "<h3>Recent News</h3>\n";
for (const auto &newsbyte : item->newsbytes) {
text += "<p> • " + newsbyte + "</p>\n";
}
text += "<br>\nEnjoy Revuo? Consider a <a href=\"feather://donate-revuo\">donation</a> to the author.";
m_items[item->title] = text;
m_links[item->title] = item->url;
}
ui->listWidget->clear();
ui->listWidget->addItems(titles);
ui->listWidget->setCurrentRow(0);
}
void RevuoWidget::onSelectItem(const QString &item) {
auto *currentItem = ui->listWidget->currentItem();
if (currentItem == nullptr) {
return;
}
QString title = currentItem->text();
ui->textBrowser->setText(m_items[title]);
}
void RevuoWidget::onLinkActivated(const QUrl &link) {
if (link.host() == "donate-revuo") {
this->onDonate();
return;
}
Utils::externalLinkWarning(this, link.toString());
}
void RevuoWidget::showContextMenu(const QPoint &pos) {
m_contextMenu->exec(ui->listWidget->viewport()->mapToGlobal(pos));
}
void RevuoWidget::onOpenLink() {
QString currentItem = ui->listWidget->currentItem()->text();
Utils::externalLinkWarning(this, m_links[currentItem]);
}
void RevuoWidget::onDonate() {
emit donate("89Esx7ZAoVcD9wiDw57gxgS7m52sFEEbQiFC4qq18YZy3CdcsXvJ67FYdcDFbmYEGK7xerxgmDptd1C2xLstCbgF3RUhSMT", "Donation to Revuo Monero");
}
void RevuoWidget::skinChanged() {
QString color = "black";
if (ColorScheme::hasDarkBackground(this)) {
color = "white";
}
auto stylesheet = QString("a {color: %1; }").arg(color);
ui->textBrowser->document()->setDefaultStyleSheet(stylesheet);
this->onSelectItem("");
}
RevuoWidget::~RevuoWidget() = default;

47
src/widgets/RevuoWidget.h Normal file
View file

@ -0,0 +1,47 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
#ifndef FEATHER_REVUOWIDGET_H
#define FEATHER_REVUOWIDGET_H
#include <QWidget>
#include <QMenu>
#include "RevuoItem.h"
namespace Ui {
class RevuoWidget;
}
class RevuoWidget : public QWidget
{
Q_OBJECT
public:
explicit RevuoWidget(QWidget *parent = nullptr);
~RevuoWidget();
signals:
void donate(const QString &address, const QString &description);
public slots:
void updateItems(const QList<QSharedPointer<RevuoItem>>& items);
void skinChanged();
private slots:
void onLinkActivated(const QUrl &link);
void onSelectItem(const QString &item);
void onOpenLink();
void onDonate();
void showContextMenu(const QPoint &pos);
private:
QScopedPointer<Ui::RevuoWidget> ui;
QMenu *m_contextMenu;
QHash<QString, QString> m_items;
QHash<QString, QString> m_links;
};
#endif //FEATHER_REVUOWIDGET_H

View file

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RevuoWidget</class>
<widget class="QWidget" name="RevuoWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>945</width>
<height>508</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListWidget" name="listWidget">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser">
<property name="html">
<string></string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>