refactor: move third party integrations to plugins folder

This commit is contained in:
tobtoht
2023-03-28 22:26:53 +02:00
parent fbc3b89285
commit 8fd583a649
44 changed files with 30 additions and 30 deletions
+114
View File
@@ -0,0 +1,114 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2020-2023, The Monero Project.
#include "BountiesModel.h"
BountiesModel::BountiesModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
void BountiesModel::clear() {
beginResetModel();
m_bounties.clear();
endResetModel();
}
void BountiesModel::updateBounties(const QList<QSharedPointer<BountyEntry>> &posts) {
beginResetModel();
m_bounties.clear();
for (const auto& post : posts) {
m_bounties.push_back(post);
}
endResetModel();
}
int BountiesModel::rowCount(const QModelIndex &parent) const{
if (parent.isValid()) {
return 0;
}
return m_bounties.count();
}
int BountiesModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
}
return ModelColumn::COUNT;
}
QVariant BountiesModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_bounties.count())
return {};
QSharedPointer<BountyEntry> post = m_bounties.at(index.row());
if(role == Qt::DisplayRole) {
switch(index.column()) {
case Votes:
return QString::number(post->votes);
case Title:
return post->title;
case Status:
return post->status;
case Bounty: {
if (post->bountyAmount > 0) {
return QString("%1 XMR").arg(QString::number(post->bountyAmount, 'f', 5));
}
return "None";
}
default:
return {};
}
}
else if (role == Qt::TextAlignmentRole) {
switch(index.column()) {
case Votes:
case Status:
case Bounty:
return Qt::AlignRight;
default:
return {};
}
}
return {};
}
QVariant BountiesModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole) {
return QVariant();
}
if (orientation == Qt::Horizontal)
{
switch(section) {
case Votes:
return QString(" 🡅 ");
case Title:
return QString("Title");
case Status:
return QString(" Status ");
case Bounty:
return QString(" Bounty ");
default:
return QVariant();
}
}
return QVariant();
}
QSharedPointer<BountyEntry> BountiesModel::post(int row) {
if (row < 0 || row >= m_bounties.size()) {
qCritical("%s: no reddit post for index %d", __FUNCTION__, row);
return QSharedPointer<BountyEntry>();
}
return m_bounties.at(row);
}
+43
View File
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_BOUNTIESMODEL_H
#define FEATHER_BOUNTIESMODEL_H
#include <QAbstractTableModel>
#include <QSharedPointer>
#include "Bounty.h"
class BountiesModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum ModelColumn
{
Title = 0,
Votes,
Status,
Bounty,
COUNT
};
explicit BountiesModel(QObject *parent);
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void clear();
void updateBounties(const QList<QSharedPointer<BountyEntry>>& posts);
QSharedPointer<BountyEntry> post(int row);
private:
QList<QSharedPointer<BountyEntry>> m_bounties;
};
#endif //FEATHER_BOUNTIESMODEL_H
+77
View File
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "BountiesWidget.h"
#include "ui_BountiesWidget.h"
#include <QDesktopServices>
#include <QStandardItemModel>
#include <QTableWidget>
#include "BountiesModel.h"
#include "utils/Utils.h"
#include "utils/config.h"
BountiesWidget::BountiesWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::BountiesWidget)
, m_model(new BountiesModel(this))
, m_contextMenu(new QMenu(this))
{
ui->setupUi(this);
ui->tableView->setModel(m_model);
this->setupTable();
m_contextMenu->addAction("View Bounty", this, &BountiesWidget::linkClicked);
m_contextMenu->addAction("Donate", this, &BountiesWidget::donateClicked);
connect(ui->tableView, &QHeaderView::customContextMenuRequested, this, &BountiesWidget::showContextMenu);
connect(ui->tableView, &QTableView::doubleClicked, this, &BountiesWidget::linkClicked);
ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
BountiesModel * BountiesWidget::model() {
return m_model;
}
void BountiesWidget::linkClicked() {
QModelIndex index = ui->tableView->currentIndex();
auto post = m_model->post(index.row());
if (post)
Utils::externalLinkWarning(this, this->getLink(post->link));
}
void BountiesWidget::donateClicked() {
QModelIndex index = ui->tableView->currentIndex();
auto bounty = m_model->post(index.row());
if (bounty) {
emit donate(bounty->donationAddress, QString("Bounty: %1").arg(bounty->title));
}
}
void BountiesWidget::setupTable() {
ui->tableView->verticalHeader()->setVisible(false);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
void BountiesWidget::showContextMenu(const QPoint &pos) {
QModelIndex index = ui->tableView->indexAt(pos);
if (!index.isValid()) {
return;
}
m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos));
}
QString BountiesWidget::getLink(const QString &permaLink) {
QString frontend = config()->get(Config::bountiesFrontend).toString();
return QString("%1/%2").arg(frontend, permaLink);
}
BountiesWidget::~BountiesWidget() = default;
+44
View File
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_BOUNTIESWIDGET_H
#define FEATHER_BOUNTIESWIDGET_H
#include <QItemSelection>
#include <QMenu>
#include <QWidget>
#include "BountiesModel.h"
namespace Ui {
class BountiesWidget;
}
class BountiesWidget : public QWidget
{
Q_OBJECT
public:
explicit BountiesWidget(QWidget *parent = nullptr);
~BountiesWidget() override;
BountiesModel* model();
public slots:
void linkClicked();
signals:
void setStatusText(const QString &msg, bool override, int timeout);
void donate(const QString &address, const QString &description);
private:
void setupTable();
void showContextMenu(const QPoint &pos);
void donateClicked();
QString getLink(const QString &permaLink);
QScopedPointer<Ui::BountiesWidget> ui;
BountiesModel *m_model;
QMenu *m_contextMenu;
};
#endif //FEATHER_BOUNTIESWIDGET_H
+40
View File
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BountiesWidget</class>
<widget class="QWidget" name="BountiesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>566</width>
<height>372</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<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="QTableView" name="tableView">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
+23
View File
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2020-2021, The Monero Project.
#ifndef FEATHER_BOUNTY_H
#define FEATHER_BOUNTY_H
#include <QString>
#include <utility>
struct BountyEntry {
BountyEntry(int votes, QString title, double bountyAmount, QString link, QString donationAddress, QString status)
: votes(votes), title(std::move(title)), bountyAmount(bountyAmount), link(std::move(link)),
donationAddress(std::move(donationAddress)), status(std::move(status)){};
int votes;
QString title;
double bountyAmount;
QString link;
QString donationAddress;
QString status;
};
#endif //FEATHER_BOUNTY_H
+24
View File
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_CCSENTRY_H
#define FEATHER_CCSENTRY_H
#include <QString>
struct CCSEntry {
CCSEntry()= default;;
QString title = "";
QString date = "";
QString address = "";
QString author = "";
QString state = "";
QString url = "";
double target_amount = 0;
double raised_amount = 0;
double percentage_funded = 0;
int contributions = 0;
};
#endif //FEATHER_CCSENTRY_H
+96
View File
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "CCSModel.h"
CCSModel::CCSModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
void CCSModel::clear() {
beginResetModel();
m_entries.clear();
endResetModel();
}
void CCSModel::updateEntries(const QList<QSharedPointer<CCSEntry>>& entries) {
beginResetModel();
m_entries.clear();
for (const auto& entry : entries) {
m_entries.push_back(entry);
}
endResetModel();
}
int CCSModel::rowCount(const QModelIndex &parent) const{
if (parent.isValid()) {
return 0;
}
return m_entries.count();
}
int CCSModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
}
return ModelColumn::COUNT;
}
QVariant CCSModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_entries.count())
return QVariant();
QSharedPointer<CCSEntry> entry = m_entries.at(index.row());
if(role == Qt::DisplayRole) {
switch(index.column()) {
case Title:
return entry->title;
case Author:
return entry->author;
case Progress:
return QString("%1/%2 XMR").arg(entry->raised_amount).arg(entry->target_amount);
default:
return QVariant();
}
}
return QVariant();
}
QVariant CCSModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole) {
return QVariant();
}
if (orientation == Qt::Horizontal)
{
switch(section) {
case Title:
return QString("Community Crowdfunding Proposal");
case Author:
return QString("Author");
case Progress:
return QString("Progress");
default:
return QVariant();
}
}
return QVariant();
}
QSharedPointer<CCSEntry> CCSModel::entry(int row) {
if (row < 0 || row >= m_entries.size()) {
qCritical("%s: no reddit post for index %d", __FUNCTION__, row);
return QSharedPointer<CCSEntry>();
}
return m_entries.at(row);
}
+42
View File
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_CCSMODEL_H
#define FEATHER_CCSMODEL_H
#include <QAbstractTableModel>
#include <QSharedPointer>
#include "CCSEntry.h"
class CCSModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum ModelColumn
{
Title = 0,
Author,
Progress,
COUNT
};
explicit CCSModel(QObject *parent);
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void clear();
void updateEntries(const QList<QSharedPointer<CCSEntry>>& entries);
QSharedPointer<CCSEntry> entry(int row);
private:
QList<QSharedPointer<CCSEntry>> m_entries;
};
#endif //FEATHER_CCSMODEL_H
+39
View File
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "CCSProgressDelegate.h"
#include <QApplication>
CCSProgressDelegate::CCSProgressDelegate(CCSModel *model, QWidget *parent)
: QStyledItemDelegate(parent)
, m_model(model)
{
}
void CCSProgressDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const {
if (index.column() != CCSModel::Progress) {
QStyledItemDelegate::paint(painter, option, index);
return;
}
QStyleOptionProgressBar progressBarOption;
progressBarOption.state = QStyle::State_Enabled;
progressBarOption.direction = QApplication::layoutDirection();
progressBarOption.rect = option.rect;
progressBarOption.fontMetrics = QApplication::fontMetrics();
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.textAlignment = Qt::AlignCenter;
progressBarOption.textVisible = true;
QSharedPointer<CCSEntry> entry = m_model->entry(index.row());
auto target = QString("%1/%2 XMR").arg(entry->raised_amount).arg(entry->target_amount);
auto progress = (int)entry->percentage_funded;
progressBarOption.progress = progress < 0 ? 0 : progress;
progressBarOption.text = target;
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter); // Draw the progress bar onto the view.
}
+24
View File
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_CSSPROGRESSDELEGATE_H
#define FEATHER_CSSPROGRESSDELEGATE_H
#include <QStyledItemDelegate>
#include "CCSModel.h"
class CCSProgressDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit CCSProgressDelegate(CCSModel *model, QWidget *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private:
CCSModel *m_model;
};
#endif //FEATHER_CSSPROGRESSDELEGATE_H
+71
View File
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "CCSWidget.h"
#include "ui_CCSWidget.h"
#include <QDesktopServices>
#include <QStandardItemModel>
#include <QTableWidget>
#include "CCSProgressDelegate.h"
#include "utils/Utils.h"
CCSWidget::CCSWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::CSSWidget)
, m_model(new CCSModel(this))
, m_contextMenu(new QMenu(this))
{
ui->setupUi(this);
ui->tableView->setModel(m_model);
this->setupTable();
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);
ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
CCSModel* CCSWidget::model() {
return m_model;
}
void CCSWidget::linkClicked() {
QModelIndex index = ui->tableView->currentIndex();
auto entry = m_model->entry(index.row());
if (entry) {
Utils::externalLinkWarning(this, entry->url);
}
}
void CCSWidget::donateClicked() {
QModelIndex index = ui->tableView->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);
if (!index.isValid()) {
return;
}
m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos));
}
CCSWidget::~CCSWidget() = default;
+47
View File
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_CSSWIDGET_H
#define FEATHER_CSSWIDGET_H
#include <QItemDelegate>
#include <QMenu>
#include <QObject>
#include <QProgressBar>
#include <QWidget>
#include "CCSModel.h"
#include "CCSEntry.h"
namespace Ui {
class CSSWidget;
}
class CCSWidget : public QWidget
{
Q_OBJECT
public:
explicit CCSWidget(QWidget *parent = nullptr);
~CCSWidget();
CCSModel *model();
signals:
void selected(CCSEntry entry);
public slots:
void donateClicked();
private slots:
void linkClicked();
private:
void setupTable();
void showContextMenu(const QPoint &pos);
QScopedPointer<Ui::CSSWidget> ui;
CCSModel *m_model;
QMenu *m_contextMenu;
};
#endif // FEATHER_CSSWIDGET_H
+59
View File
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSSWidget</class>
<widget class="QWidget" name="CSSWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>893</width>
<height>396</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>4</number>
</property>
<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="QTableView" name="tableView">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<slots>
<slot>donateClicked()</slot>
<slot>linkClicked()</slot>
</slots>
</ui>
+119
View File
@@ -0,0 +1,119 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "LocalMoneroApi.h"
#include "utils/config.h"
LocalMoneroApi::LocalMoneroApi(QObject *parent, UtilsNetworking *network)
: QObject(parent)
, m_network(network)
{
}
void LocalMoneroApi::countryCodes() {
QString url = QString("%1/countrycodes").arg(this->getBaseUrl());
QNetworkReply *reply = m_network->getJson(url);
connect(reply, &QNetworkReply::finished, std::bind(&LocalMoneroApi::onResponse, this, reply, Endpoint::COUNTRY_CODES));
}
void LocalMoneroApi::currencies() {
QString url = QString("%1/currencies").arg(this->getBaseUrl());
QNetworkReply *reply = m_network->getJson(url);
connect(reply, &QNetworkReply::finished, std::bind(&LocalMoneroApi::onResponse, this, reply, Endpoint::CURRENCIES));
}
void LocalMoneroApi::paymentMethods(const QString &countryCode) {
QString url;
if (countryCode.isEmpty()) {
url = QString("%1/payment_methods").arg(this->getBaseUrl());
} else {
url = QString("%1/payment_methods/%2").arg(this->getBaseUrl(), countryCode);
}
QNetworkReply *reply = m_network->getJson(url);
connect(reply, &QNetworkReply::finished, std::bind(&LocalMoneroApi::onResponse, this, reply, Endpoint::PAYMENT_METHODS));
}
void LocalMoneroApi::buyMoneroOnline(const QString &currencyCode, const QString &countryCode,
const QString &paymentMethod, const QString &amount, int page)
{
QString url = this->getBuySellUrl(true, currencyCode, countryCode, paymentMethod, amount, page);
QNetworkReply *reply = m_network->getJson(url);
connect(reply, &QNetworkReply::finished, std::bind(&LocalMoneroApi::onResponse, this, reply, Endpoint::BUY_MONERO_ONLINE));
}
void LocalMoneroApi::sellMoneroOnline(const QString &currencyCode, const QString &countryCode,
const QString &paymentMethod, const QString &amount, int page)
{
QString url = this->getBuySellUrl(false, currencyCode, countryCode, paymentMethod, amount, page);
QNetworkReply *reply = m_network->getJson(url);
connect(reply, &QNetworkReply::finished, std::bind(&LocalMoneroApi::onResponse, this, reply, Endpoint::SELL_MONERO_ONLINE));
}
void LocalMoneroApi::accountInfo(const QString &username) {
QString url = QString("%1/account_info/%2").arg(this->getBaseUrl(), username);
QNetworkReply *reply = m_network->getJson(url);
connect(reply, &QNetworkReply::finished, std::bind(&LocalMoneroApi::onResponse, this, reply, Endpoint::ACCOUNT_INFO));
}
void LocalMoneroApi::onResponse(QNetworkReply *reply, LocalMoneroApi::Endpoint endpoint) {
const bool ok = reply->error() == QNetworkReply::NoError;
const QString err = reply->errorString();
QByteArray data = reply->readAll();
reply->deleteLater();
QJsonObject obj;
if (!data.isEmpty() && Utils::validateJSON(data)) {
auto doc = QJsonDocument::fromJson(data);
obj = doc.object();
}
else if (!ok) {
emit ApiResponse(LocalMoneroResponse{false, endpoint, err, {}});
return;
}
else {
emit ApiResponse(LocalMoneroResponse{false, endpoint, "Invalid response from LocalMonero", {}});
return;
}
if (obj.contains("error")) {
QString errorStr = QJsonDocument(obj["error"].toObject()).toJson(QJsonDocument::Compact);
emit ApiResponse(LocalMoneroResponse{false, endpoint, errorStr, obj});
return;
}
emit ApiResponse(LocalMoneroResponse{true, endpoint, "", obj});
}
QString LocalMoneroApi::getBuySellUrl(bool buy, const QString &currencyCode, const QString &countryCode,
const QString &paymentMethod, const QString &amount, int page)
{
QString url = QString("%1/%2-monero-online/%3").arg(this->getBaseUrl(), buy ? "buy" : "sell", currencyCode);
if (!countryCode.isEmpty() && paymentMethod.isEmpty())
url += QString("/%1").arg(countryCode);
else if (countryCode.isEmpty() && !paymentMethod.isEmpty())
url += QString("/%1").arg(paymentMethod);
else if (!countryCode.isEmpty() && !paymentMethod.isEmpty())
url += QString("/%1/%2").arg(countryCode, paymentMethod);
QUrlQuery query;
if (!amount.isEmpty() && amount != "0")
query.addQueryItem("amount", amount);
if (page > 0)
query.addQueryItem("page", QString::number(page));
url += "?" + query.toString();
return url;
}
QString LocalMoneroApi::getBaseUrl() {
if (config()->get(Config::proxy).toInt() == Config::Proxy::Tor && config()->get(Config::torOnlyAllowOnion).toBool()) {
return "http://nehdddktmhvqklsnkjqcbpmb63htee2iznpcbs5tgzctipxykpj6yrid.onion/api/v1";
}
if (config()->get(Config::proxy).toInt() == Config::Proxy::i2p) {
return "http://yeyar743vuwmm6fpgf3x6bzmj7fxb5uxhuoxx4ea76wqssdi4f3q.b32.i2p/api/v1";
}
return "https://agoradesk.com/api/v1";
}
+53
View File
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_LOCALMONEROAPI_H
#define FEATHER_LOCALMONEROAPI_H
#include <QObject>
#include "utils/networking.h"
class LocalMoneroApi : public QObject {
Q_OBJECT
public:
enum Endpoint {
COUNTRY_CODES,
CURRENCIES,
PAYMENT_METHODS,
BUY_MONERO_ONLINE,
SELL_MONERO_ONLINE,
ACCOUNT_INFO
};
struct LocalMoneroResponse {
bool ok;
Endpoint endpoint;
QString message;
QJsonObject obj;
};
explicit LocalMoneroApi(QObject *parent, UtilsNetworking *network);
void countryCodes();
void currencies();
void paymentMethods(const QString &countryCode = "");
void buyMoneroOnline(const QString &currencyCode, const QString &countryCode="", const QString &paymentMethod="", const QString &amount = "", int page = 0);
void sellMoneroOnline(const QString &currencyCode, const QString &countryCode="", const QString &paymentMethod="", const QString &amount = "", int page = 0);
void accountInfo(const QString &username);
signals:
void ApiResponse(LocalMoneroResponse resp);
private slots:
void onResponse(QNetworkReply *reply, Endpoint endpoint);
private:
QString getBuySellUrl(bool buy, const QString &currencyCode, const QString &countryCode="", const QString &paymentMethod="", const QString &amount = "", int page = 0);
QString getBaseUrl();
UtilsNetworking *m_network;
};
#endif //FEATHER_LOCALMONEROAPI_H
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "LocalMoneroInfoDialog.h"
#include "ui_LocalMoneroInfoDialog.h"
#include "utils/config.h"
#include "utils/Utils.h"
LocalMoneroInfoDialog::LocalMoneroInfoDialog(QWidget *parent, LocalMoneroModel *model, int row)
: WindowModalDialog(parent)
, ui(new Ui::LocalMoneroInfoDialog)
, m_model(model)
, m_row(row)
{
ui->setupUi(this);
setLabelText(ui->label_price, LocalMoneroModel::PriceXMR);
setLabelText(ui->label_seller, LocalMoneroModel::Seller);
setLabelText(ui->label_paymentMethod, LocalMoneroModel::PaymentMethod);
setLabelText(ui->label_paymentDetail, LocalMoneroModel::PaymentMethodDetail);
setLabelText(ui->label_tradeLimits, LocalMoneroModel::Limits);
QJsonObject offerData = model->getOffer(row);
QString details = offerData["data"].toObject()["msg"].toString();
details.remove("*");
if (details.isEmpty()) {
details = "No details.";
}
ui->info->setPlainText(details);
connect(ui->btn_goToOffer, &QPushButton::clicked, this, &LocalMoneroInfoDialog::onGoToOffer);
}
void LocalMoneroInfoDialog::setLabelText(QLabel *label, LocalMoneroModel::Column column) {
QString data = m_model->data(m_model->index(m_row, column)).toString();
label->setText(data);
}
void LocalMoneroInfoDialog::onGoToOffer() {
QJsonObject offerData = m_model->getOffer(m_row);
QString frontend = config()->get(Config::localMoneroFrontend).toString();
QString offerUrl = QString("%1/ad/%2").arg(frontend, offerData["data"].toObject()["ad_id"].toString());
Utils::externalLinkWarning(this, offerUrl);
}
LocalMoneroInfoDialog::~LocalMoneroInfoDialog() = default;
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_LOCALMONEROINFODIALOG_H
#define FEATHER_LOCALMONEROINFODIALOG_H
#include <QDialog>
#include <QLabel>
#include "components.h"
#include "LocalMoneroModel.h"
namespace Ui {
class LocalMoneroInfoDialog;
}
class LocalMoneroInfoDialog : public WindowModalDialog
{
Q_OBJECT
public:
explicit LocalMoneroInfoDialog(QWidget *parent, LocalMoneroModel *model, int row);
~LocalMoneroInfoDialog() override;
private slots:
void onGoToOffer();
private:
void setLabelText(QLabel *label, LocalMoneroModel::Column column);
QScopedPointer<Ui::LocalMoneroInfoDialog> ui;
LocalMoneroModel *m_model;
int m_row;
};
#endif //FEATHER_INFODIALOG_H
@@ -0,0 +1,195 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LocalMoneroInfoDialog</class>
<widget class="QDialog" name="LocalMoneroInfoDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>758</width>
<height>557</height>
</rect>
</property>
<property name="windowTitle">
<string>Offer info</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Info</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Price:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_price">
<property name="text">
<string>TextLabel</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Seller:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_seller">
<property name="text">
<string>TextLabel</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Payment method:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_paymentMethod">
<property name="text">
<string>TextLabel</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Trade limits:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_tradeLimits">
<property name="text">
<string>TextLabel</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Payment detail:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_paymentDetail">
<property name="text">
<string>TextLabel</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="info">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_goToOffer">
<property name="text">
<string>Go to offer</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>LocalMoneroInfoDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>LocalMoneroInfoDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@@ -0,0 +1,172 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "LocalMoneroModel.h"
#include <QColor>
#include "utils/Utils.h"
LocalMoneroModel::LocalMoneroModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
int LocalMoneroModel::rowCount(const QModelIndex &parent) const {
return m_data.count();
}
int LocalMoneroModel::columnCount(const QModelIndex &parent) const {
return Column::COUNT;
}
QVariant LocalMoneroModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
switch (section) {
case Seller:
return QString("Seller");
case Country:
return QString("Country");
case PaymentMethod:
return QString("Payment Method");
case PaymentMethodDetail:
return QString("Detail");
case PriceXMR:
return QString("Price/XMR");
case Limits:
return QString("Limits");
default:
return QVariant();
}
}
return QVariant();
}
QVariant LocalMoneroModel::data(const QModelIndex &index, int role) const {
const int col = index.column();
const auto row = m_data.at(index.row()).toObject()["data"].toObject();
if (row.isEmpty()) {
return QVariant();
}
if (role == Qt::DisplayRole) {
switch (col) {
case Column::Seller: {
auto seller = row["profile"].toObject();
return seller["name"].toString();
// TODO: online indicator
}
case Column::Country: {
return row["countrycode"].toString();
}
case Column::PaymentMethod: {
auto paymentMethodCode = row["online_provider"].toString();
if (paymentMethodCode == "NATIONAL_BANK") {
return QString("National bank transfer");
}
return m_paymentMethodNames.value(paymentMethodCode, paymentMethodCode);
}
case Column::PaymentMethodDetail: {
auto paymentMethodDetailText = row["payment_method_detail"].toString();
QString filteredString; // We can't display emojis in QTreeView
for (const auto &Char : paymentMethodDetailText) {
if (Char.unicode() < 256)
filteredString.append(Char);
else
filteredString.append(" ");
}
return filteredString.trimmed();
}
case Column::PriceXMR: {
return QString("%1 %2").arg(row["temp_price"].toString(), row["currency"].toString());
}
case Column::Limits: {
auto minAmount = row["min_amount"].toString();
auto maxAmount = row["max_amount"].toString();
if (maxAmount.isEmpty()) {
maxAmount = row["max_amount_available"].toString();
}
auto currency = row["currency"].toString();
if (minAmount.isEmpty() && maxAmount.isEmpty()) {
return QString("Up to any amount %1").arg(currency);
}
if (!minAmount.isEmpty() && maxAmount.isEmpty()) {
return QString("%1 - any amount %2").arg(minAmount, currency);
}
if (!minAmount.isEmpty() && !maxAmount.isEmpty()) {
return QString("%1 - %2 %3").arg(minAmount, maxAmount, currency);
}
if (minAmount.isEmpty() && !maxAmount.isEmpty()) {
return QString("Up to %1 %2").arg(maxAmount, currency);
}
return QVariant();
}
}
}
else if (role == Qt::ForegroundRole) {
switch (col) {
case Column::PriceXMR: {
return QVariant(QColor("#388538"));
}
}
}
else if (role == Qt::FontRole) {
switch (col) {
case Column::PriceXMR: {
auto bigFont = Utils::relativeFont(2);
bigFont.setBold(true);
return bigFont;
}
}
}
return QVariant();
}
void LocalMoneroModel::setData(const QJsonArray &data) {
beginResetModel();
m_data = data;
endResetModel();
}
void LocalMoneroModel::addData(const QJsonArray &data) {
beginResetModel();
for (const auto &row : data) {
m_data.append(row);
}
endResetModel();
}
void LocalMoneroModel::clearData() {
beginResetModel();
m_data = {};
endResetModel();
}
void LocalMoneroModel::setPaymentMethods(const QJsonObject &data) {
beginResetModel();
m_paymentMethods = data;
m_paymentMethodNames.clear();
for (const auto &payment_method : data) {
auto code = payment_method.toObject()["code"].toString();
auto name = payment_method.toObject()["name"].toString();
if (!code.isEmpty() && !name.isEmpty()) {
m_paymentMethodNames[code] = name;
}
}
endResetModel();
}
QJsonObject LocalMoneroModel::getOffer(int index) const {
return m_data.at(index).toObject();
}
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_LOCALMONEROMODEL_H
#define FEATHER_LOCALMONEROMODEL_H
#include <QAbstractTableModel>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
class LocalMoneroModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum Column
{
Seller = 0,
Country,
PaymentMethod,
PaymentMethodDetail,
PriceXMR,
Limits,
COUNT
};
LocalMoneroModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
void setData(const QJsonArray &data);
void setPaymentMethods(const QJsonObject &data);
void addData(const QJsonArray &data);
void clearData();
QJsonObject getOffer(int index) const;
private:
QJsonArray m_data;
QJsonObject m_paymentMethods;
QHash<QString, QString> m_paymentMethodNames;
};
#endif //FEATHER_LOCALMONEROMODEL_H
@@ -0,0 +1,208 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "LocalMoneroWidget.h"
#include "ui_LocalMoneroWidget.h"
#include <QMessageBox>
#include <QMenu>
#include "LocalMoneroInfoDialog.h"
#include "utils/ColorScheme.h"
#include "utils/Icons.h"
#include "utils/WebsocketNotifier.h"
LocalMoneroWidget::LocalMoneroWidget(QWidget *parent, Wallet *wallet)
: QWidget(parent)
, ui(new Ui::LocalMoneroWidget)
, m_wallet(wallet)
{
ui->setupUi(this);
QPixmap logo(":/assets/images/localMonero_logo.png");
ui->logo->setPixmap(logo.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
ui->combo_currency->addItem(config()->get(Config::preferredFiatCurrency).toString());
m_network = new UtilsNetworking(this);
m_api = new LocalMoneroApi(this, m_network);
m_model = new LocalMoneroModel(this);
ui->treeView->setModel(m_model);
ui->treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->treeView->header()->setSectionResizeMode(LocalMoneroModel::PaymentMethodDetail, QHeaderView::Stretch);
ui->treeView->header()->setStretchLastSection(false);
connect(ui->treeView, &QTreeView::doubleClicked, this, &LocalMoneroWidget::viewOfferDetails);
connect(ui->treeView, &QTreeView::customContextMenuRequested, this, &LocalMoneroWidget::showContextMenu);
connect(ui->btn_search, &QPushButton::clicked, this, &LocalMoneroWidget::onSearchClicked);
connect(ui->btn_signUp, &QPushButton::clicked, this, &LocalMoneroWidget::onSignUpClicked);
connect(m_api, &LocalMoneroApi::ApiResponse, this, &LocalMoneroWidget::onApiResponse);
connect(ui->btn_loadMore, &QPushButton::clicked, this, &LocalMoneroWidget::onLoadMore);
connect(websocketNotifier(), &WebsocketNotifier::LocalMoneroCountriesReceived, this, &LocalMoneroWidget::onWsCountriesReceived);
connect(websocketNotifier(), &WebsocketNotifier::LocalMoneroCurrenciesReceived, this, &LocalMoneroWidget::onWsCurrenciesReceived);
connect(websocketNotifier(), &WebsocketNotifier::LocalMoneroPaymentMethodsReceived, this, &LocalMoneroWidget::onWsPaymentMethodsReceived);
connect(ui->combo_currency, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &LocalMoneroWidget::updatePaymentMethods);
ui->frame_loadMore->hide();
QTimer::singleShot(1, [this]{
this->skinChanged();
});
}
void LocalMoneroWidget::skinChanged() {
if (ColorScheme::hasDarkBackground(this)) {
ui->radio_buy->setIcon(icons()->icon("localMonero_buy_white.svg"));
ui->radio_sell->setIcon(icons()->icon("localMonero_sell_white.svg"));
} else {
ui->radio_buy->setIcon(icons()->icon("localMonero_buy.svg"));
ui->radio_sell->setIcon(icons()->icon("localMonero_sell.svg"));
}
}
void LocalMoneroWidget::onSearchClicked() {
m_model->clearData();
m_currentPage = 0;
ui->btn_search->setEnabled(false);
this->searchOffers();
}
void LocalMoneroWidget::onSignUpClicked() {
QString signupUrl = QString("%1/signup").arg(config()->get(Config::localMoneroFrontend).toString());
Utils::externalLinkWarning(this, signupUrl);
}
void LocalMoneroWidget::onApiResponse(const LocalMoneroApi::LocalMoneroResponse &resp) {
ui->btn_search->setEnabled(true);
if (!resp.ok) {
QMessageBox::warning(this, "LocalMonero error", QString("Request failed:\n\n%1").arg(resp.message));
return;
}
if (resp.endpoint == LocalMoneroApi::BUY_MONERO_ONLINE
|| resp.endpoint == LocalMoneroApi::SELL_MONERO_ONLINE)
{
bool hasNextPage = resp.obj["pagination"].toObject().contains("next");
ui->frame_loadMore->setVisible(hasNextPage);
m_model->addData(resp.obj["data"].toObject()["ad_list"].toArray());
}
else if (resp.endpoint == LocalMoneroApi::PAYMENT_METHODS) {
m_model->setPaymentMethods(resp.obj["data"].toObject()["methods"].toObject());
}
}
void LocalMoneroWidget::onLoadMore() {
m_currentPage += 1;
this->searchOffers(m_currentPage);
}
void LocalMoneroWidget::onWsCountriesReceived(const QJsonArray &countries) {
ui->combo_country->clear();
ui->combo_country->addItem("Any country");
for (const auto country : countries) {
ui->combo_country->addItem(country[0].toString(), country[1].toString());
}
}
void LocalMoneroWidget::onWsCurrenciesReceived(const QJsonArray &currencies) {
QString currentText = ui->combo_currency->currentText();
ui->combo_currency->clear();
for (const auto currency : currencies) {
ui->combo_currency->addItem(currency.toString());
}
// restore previous selection
int index = ui->combo_currency->findText(currentText);
ui->combo_currency->setCurrentIndex(index);
}
void LocalMoneroWidget::onWsPaymentMethodsReceived(const QJsonObject &payment_methods) {
m_paymentMethods = payment_methods;
m_model->setPaymentMethods(payment_methods);
this->updatePaymentMethods();
}
void LocalMoneroWidget::searchOffers(int page) {
QString amount = ui->line_amount->text();
QString currencyCode = ui->combo_currency->currentText();
QString countryCode = ui->combo_country->currentData().toString();
QString paymentMethod = ui->combo_paymentMethod->currentData().toString();
if (ui->radio_buy->isChecked())
m_api->buyMoneroOnline(currencyCode, countryCode, paymentMethod, amount, page);
else if (ui->radio_sell->isChecked())
m_api->sellMoneroOnline(currencyCode, countryCode, paymentMethod, amount, page);
}
void LocalMoneroWidget::showContextMenu(const QPoint &point) {
QModelIndex index = ui->treeView->indexAt(point);
if (!index.isValid()) {
return;
}
QMenu menu(this);
menu.addAction("Go to offer", this, &LocalMoneroWidget::openOfferUrl);
menu.addAction("View offer details", this, &LocalMoneroWidget::viewOfferDetails);
menu.exec(ui->treeView->viewport()->mapToGlobal(point));
}
void LocalMoneroWidget::openOfferUrl() {
QModelIndex index = ui->treeView->currentIndex();
if (!index.isValid()) {
return;
}
QJsonObject offerData = m_model->getOffer(index.row());
QString frontend = config()->get(Config::localMoneroFrontend).toString();
QString offerUrl = QString("%1/ad/%2").arg(frontend, offerData["data"].toObject()["ad_id"].toString());
Utils::externalLinkWarning(this, offerUrl);
}
void LocalMoneroWidget::viewOfferDetails() {
QModelIndex index = ui->treeView->currentIndex();
if (!index.isValid()) {
return;
}
QJsonObject offerData = m_model->getOffer(index.row());
QString details = offerData["data"].toObject()["msg"].toString();
details.remove("*");
if (details.isEmpty()) {
details = "No details.";
}
LocalMoneroInfoDialog dialog(this, m_model, index.row());
dialog.exec();
}
void LocalMoneroWidget::updatePaymentMethods() {
QString currency = ui->combo_currency->currentText().toUpper();
ui->combo_paymentMethod->clear();
ui->combo_paymentMethod->addItem("Any payment method");
for (const auto &payment_method : m_paymentMethods.keys()) {
auto pm = m_paymentMethods[payment_method].toObject();
if (pm["currencies"].toArray().contains(currency)) {
QString name = pm["name"].toString();
if (name.isEmpty())
name = payment_method;
ui->combo_paymentMethod->addItem(name, payment_method);
}
}
}
LocalMoneroWidget::~LocalMoneroWidget() = default;
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_LOCALMONEROWIDGET_H
#define FEATHER_LOCALMONEROWIDGET_H
#include <QWidget>
#include "LocalMoneroApi.h"
#include "LocalMoneroModel.h"
#include "libwalletqt/Wallet.h"
namespace Ui {
class LocalMoneroWidget;
}
class LocalMoneroWidget : public QWidget
{
Q_OBJECT
public:
explicit LocalMoneroWidget(QWidget *parent, Wallet *wallet);
~LocalMoneroWidget() override;
public slots:
void skinChanged();
private slots:
void onSearchClicked();
void onSignUpClicked();
void onApiResponse(const LocalMoneroApi::LocalMoneroResponse &resp);
void onLoadMore();
void onWsCountriesReceived(const QJsonArray &countries);
void onWsCurrenciesReceived(const QJsonArray &currencies);
void onWsPaymentMethodsReceived(const QJsonObject &payment_methods);
private:
void searchOffers(int page = 0);
void showContextMenu(const QPoint &point);
void openOfferUrl();
void viewOfferDetails();
void updatePaymentMethods();
QScopedPointer<Ui::LocalMoneroWidget> ui;
Wallet *m_wallet;
int m_currentPage = 0;
LocalMoneroApi *m_api;
LocalMoneroModel *m_model;
UtilsNetworking *m_network;
QJsonObject m_paymentMethods;
};
#endif //FEATHER_LOCALMONEROWIDGET_H
@@ -0,0 +1,385 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LocalMoneroWidget</class>
<widget class="QWidget" name="LocalMoneroWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1003</width>
<height>607</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<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>
<layout class="QGridLayout" name="gridLayout_2"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QFrame" name="frame_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="logo">
<property name="text">
<string>logo</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>LocalMonero.co</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>80</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QComboBox" name="combo_paymentMethod">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>Any payment method</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="line_amount">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>Amount</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combo_currency">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="radio_sell">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sell XMR</string>
</property>
<property name="icon">
<iconset resource="../assets.qrc">
<normaloff>:/assets/images/localMonero_sell_white.svg</normaloff>:/assets/images/localMonero_sell_white.svg</iconset>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="btn_search">
<property name="text">
<string>Search</string>
</property>
<property name="icon">
<iconset resource="../assets.qrc">
<normaloff>:/assets/images/localMonero_search.svg</normaloff>:/assets/images/localMonero_search.svg</iconset>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="radio_buy">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Buy XMR</string>
</property>
<property name="icon">
<iconset resource="../assets.qrc">
<normaloff>:/assets/images/localMonero_buy_white.svg</normaloff>:/assets/images/localMonero_buy_white.svg</iconset>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QComboBox" name="combo_country">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>Any country</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>80</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Buy Monero.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Sell Monero.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Cash or online.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Anywhere.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_signUp">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sign up free</string>
</property>
<property name="icon">
<iconset resource="../assets.qrc">
<normaloff>:/assets/images/localMonero_register.svg</normaloff>:/assets/images/localMonero_register.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="treeView">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_loadMore">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<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>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_loadMore">
<property name="text">
<string>Load more</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>radio_buy</tabstop>
<tabstop>radio_sell</tabstop>
<tabstop>line_amount</tabstop>
<tabstop>combo_currency</tabstop>
<tabstop>combo_country</tabstop>
<tabstop>combo_paymentMethod</tabstop>
<tabstop>btn_search</tabstop>
<tabstop>btn_signUp</tabstop>
<tabstop>btn_loadMore</tabstop>
<tabstop>treeView</tabstop>
</tabstops>
<resources>
<include location="../assets.qrc"/>
</resources>
<connections/>
</ui>
+104
View File
@@ -0,0 +1,104 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "RedditModel.h"
RedditModel::RedditModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
void RedditModel::clear() {
beginResetModel();
m_posts.clear();
endResetModel();
}
void RedditModel::updatePosts(const QList<QSharedPointer<RedditPost>>& posts) {
beginResetModel();
m_posts.clear();
for (const auto& post : posts) {
m_posts.push_back(post);
}
endResetModel();
}
int RedditModel::rowCount(const QModelIndex &parent) const{
if (parent.isValid()) {
return 0;
}
return m_posts.count();
}
int RedditModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
}
return ModelColumn::COUNT;
}
QVariant RedditModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0 || index.row() >= m_posts.count())
return QVariant();
QSharedPointer<RedditPost> post = m_posts.at(index.row());
if(role == Qt::DisplayRole) {
switch(index.column()) {
case Title:
return post->title;
case Author:
return post->author;
case Comments:
return QString::number(post->comments);
default:
return QVariant();
}
}
else if (role == Qt::TextAlignmentRole) {
switch(index.column()) {
case Comments:
return Qt::AlignRight;
default:
return QVariant();
}
}
return QVariant();
}
QVariant RedditModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole) {
return QVariant();
}
if (orientation == Qt::Horizontal)
{
switch(section) {
case Title:
return QString("Reddit Post");
case Author:
return QString("Author");
case Comments:
return QString(" Comments ");
default:
return QVariant();
}
}
return QVariant();
}
QSharedPointer<RedditPost> RedditModel::post(int row) {
if (row < 0 || row >= m_posts.size()) {
qCritical("%s: no reddit post for index %d", __FUNCTION__, row);
return QSharedPointer<RedditPost>();
}
return m_posts.at(row);
}
+41
View File
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_REDDITMODEL_H
#define FEATHER_REDDITMODEL_H
#include <QAbstractTableModel>
#include <QSharedPointer>
#include "RedditPost.h"
class RedditModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum ModelColumn
{
Title = 0,
Author,
Comments,
COUNT
};
explicit RedditModel(QObject *parent);
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void clear();
void updatePosts(const QList<QSharedPointer<RedditPost>>& posts);
QSharedPointer<RedditPost> post(int row);
private:
QList<QSharedPointer<RedditPost>> m_posts;
};
#endif //FEATHER_REDDITMODEL_H
+19
View File
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_REDDITPOST_H
#define FEATHER_REDDITPOST_H
#include <QString>
struct RedditPost {
RedditPost(const QString &title, const QString &author, const QString &permalink, int comments)
: title(title), author(author), permalink(permalink), comments(comments){};
QString title;
QString author;
QString permalink;
int comments;
};
#endif //FEATHER_REDDITPOST_H
+78
View File
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "RedditWidget.h"
#include "ui_RedditWidget.h"
#include <QDesktopServices>
#include <QStandardItemModel>
#include <QTableWidget>
#include "RedditModel.h"
#include "utils/Utils.h"
#include "utils/config.h"
RedditWidget::RedditWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::RedditWidget)
, m_model(new RedditModel(this))
, m_contextMenu(new QMenu(this))
{
ui->setupUi(this);
ui->tableView->setModel(m_model);
this->setupTable();
m_contextMenu->addAction("View thread", this, &RedditWidget::linkClicked);
m_contextMenu->addAction("Copy link", this, &RedditWidget::copyUrl);
connect(ui->tableView, &QHeaderView::customContextMenuRequested, this, &RedditWidget::showContextMenu);
connect(ui->tableView, &QTableView::doubleClicked, this, &RedditWidget::linkClicked);
ui->tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}
RedditModel* RedditWidget::model() {
return m_model;
}
void RedditWidget::linkClicked() {
QModelIndex index = ui->tableView->currentIndex();
auto post = m_model->post(index.row());
if (post)
Utils::externalLinkWarning(this, this->getLink(post->permalink));
}
void RedditWidget::copyUrl() {
QModelIndex index = ui->tableView->currentIndex();
auto post = m_model->post(index.row());
if (post) {
Utils::copyToClipboard(this->getLink(post->permalink));
emit setStatusText("Link copied to clipboard", true, 1000);
}
}
void RedditWidget::setupTable() {
ui->tableView->verticalHeader()->setVisible(false);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch);
}
void RedditWidget::showContextMenu(const QPoint &pos) {
QModelIndex index = ui->tableView->indexAt(pos);
if (!index.isValid()) {
return;
}
m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos));
}
QString RedditWidget::getLink(const QString &permaLink) {
QString redditFrontend = config()->get(Config::redditFrontend).toString();
return QString("https://%1%2").arg(redditFrontend, permaLink);
}
RedditWidget::~RedditWidget() = default;
+43
View File
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_REDDITWIDGET_H
#define FEATHER_REDDITWIDGET_H
#include <QItemSelection>
#include <QMenu>
#include <QWidget>
#include "RedditModel.h"
namespace Ui {
class RedditWidget;
}
class RedditWidget : public QWidget
{
Q_OBJECT
public:
explicit RedditWidget(QWidget *parent = nullptr);
~RedditWidget();
RedditModel* model();
public slots:
void linkClicked();
signals:
void setStatusText(const QString &msg, bool override, int timeout);
private:
void setupTable();
void showContextMenu(const QPoint &pos);
void copyUrl();
QString getLink(const QString &permaLink);
QScopedPointer<Ui::RedditWidget> ui;
RedditModel* const m_model;
QMenu *m_contextMenu;
};
#endif // FEATHER_REDDITWIDGET_H
+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RedditWidget</class>
<widget class="QWidget" name="RedditWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>492</width>
<height>409</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>4</number>
</property>
<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="QTableView" name="tableView">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<slots>
<slot>linkClicked()</slot>
</slots>
</ui>
+19
View File
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 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
+92
View File
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 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
View File
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 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
+50
View File
@@ -0,0 +1,50 @@
<?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="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QListWidget" name="listWidget">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
<widget class="QTextBrowser" name="textBrowser">
<property name="html">
<string></string>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
+409
View File
@@ -0,0 +1,409 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include "XMRigWidget.h"
#include "ui_XMRigWidget.h"
#include <QDesktopServices>
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QScrollBar>
#include <QStandardItemModel>
#include <QTableWidget>
#include "utils/Icons.h"
#include "utils/Utils.h"
XMRigWidget::XMRigWidget(Wallet *wallet, QWidget *parent)
: QWidget(parent)
, ui(new Ui::XMRigWidget)
, m_wallet(wallet)
, m_XMRig(new XmRig(Config::defaultConfigDir().path()))
, m_model(new QStandardItemModel(this))
, m_contextMenu(new QMenu(this))
{
ui->setupUi(this);
connect(m_XMRig, &XmRig::stateChanged, this, &XMRigWidget::onXMRigStateChanged);
connect(m_XMRig, &XmRig::output, this, &XMRigWidget::onProcessOutput);
connect(m_XMRig, &XmRig::error, this, &XMRigWidget::onProcessError);
connect(m_XMRig, &XmRig::hashrate, this, &XMRigWidget::onHashrate);
// [Downloads] tab
ui->tableView->setModel(m_model);
m_contextMenu->addAction(icons()->icon("network.png"), "Download file", this, &XMRigWidget::linkClicked);
connect(ui->tableView, &QHeaderView::customContextMenuRequested, this, &XMRigWidget::showContextMenu);
connect(ui->tableView, &QTableView::doubleClicked, this, &XMRigWidget::linkClicked);
// [Settings] tab
ui->poolFrame->show();
ui->soloFrame->hide();
// XMRig executable
connect(ui->btn_browse, &QPushButton::clicked, this, &XMRigWidget::onBrowseClicked);
ui->lineEdit_path->setText(config()->get(Config::xmrigPath).toString());
// Run as admin/root
bool elevated = config()->get(Config::xmrigElevated).toBool();
if (elevated) {
ui->radio_elevateYes->setChecked(true);
} else {
ui->radio_elevateNo->setChecked(true);
}
connect(ui->radio_elevateYes, &QRadioButton::toggled, this, &XMRigWidget::onXMRigElevationChanged);
#if defined(Q_OS_WIN)
ui->radio_elevateYes->setToolTip("Not supported on Windows, yet.");
ui->radio_elevateYes->setEnabled(false);
ui->radio_elevateNo->setChecked(true);
#endif
// CPU threads
ui->threadSlider->setMinimum(1);
ui->threadSlider->setMaximum(QThread::idealThreadCount());
int threads = config()->get(Config::xmrigThreads).toInt();
ui->threadSlider->setValue(threads);
ui->label_threads->setText(QString("CPU threads: %1").arg(threads));
connect(ui->threadSlider, &QSlider::valueChanged, this, &XMRigWidget::onThreadsValueChanged);
// Mining mode
connect(ui->combo_miningMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &XMRigWidget::onMiningModeChanged);
ui->combo_miningMode->setCurrentIndex(config()->get(Config::miningMode).toInt());
// Pool/node address
this->updatePools();
connect(ui->combo_pools, &QComboBox::currentTextChanged, this, &XMRigWidget::onPoolChanged);
connect(ui->btn_poolConfig, &QPushButton::clicked, [this]{
QStringList pools = config()->get(Config::pools).toStringList();
bool ok;
QString poolStr = QInputDialog::getMultiLineText(this, "Pool addresses", "Set pool addresses (one per line):", pools.join("\n"), &ok);
if (!ok) {
return;
}
QStringList newPools = poolStr.split("\n");
newPools.removeAll("");
newPools.removeDuplicates();
config()->set(Config::pools, newPools);
this->updatePools();
});
// Network settings
connect(ui->check_tls, &QCheckBox::toggled, this, &XMRigWidget::onNetworkTLSToggled);
connect(ui->relayTor, &QCheckBox::toggled, this, &XMRigWidget::onNetworkTorToggled);
ui->check_tls->setChecked(config()->get(Config::xmrigNetworkTLS).toBool());
ui->relayTor->setChecked(config()->get(Config::xmrigNetworkTor).toBool());
// Receiving address
auto username = m_wallet->getCacheAttribute("feather.xmrig_username");
if (!username.isEmpty()) {
ui->lineEdit_address->setText(username);
}
connect(ui->lineEdit_address, &QLineEdit::textChanged, [=]() {
m_wallet->setCacheAttribute("feather.xmrig_username", ui->lineEdit_address->text());
});
connect(ui->btn_fillPrimaryAddress, &QPushButton::clicked, this, &XMRigWidget::onUsePrimaryAddressClicked);
// Password
auto password = m_wallet->getCacheAttribute("feather.xmrig_password");
if (!password.isEmpty()) {
ui->lineEdit_password->setText(password);
} else {
ui->lineEdit_password->setText("featherwallet");
m_wallet->setCacheAttribute("feather.xmrig_password", ui->lineEdit_password->text());
}
connect(ui->lineEdit_password, &QLineEdit::textChanged, [=]() {
m_wallet->setCacheAttribute("feather.xmrig_password", ui->lineEdit_password->text());
});
// [Status] tab
connect(ui->btn_start, &QPushButton::clicked, this, &XMRigWidget::onStartClicked);
connect(ui->btn_stop, &QPushButton::clicked, this, &XMRigWidget::onStopClicked);
connect(ui->btn_clear, &QPushButton::clicked, this, &XMRigWidget::onClearClicked);
ui->btn_stop->setEnabled(false);
ui->check_autoscroll->setChecked(true);
ui->label_status->setTextInteractionFlags(Qt::TextSelectableByMouse);
ui->label_status->hide();
this->printConsoleInfo();
}
bool XMRigWidget::isMining() {
return m_isMining;
}
void XMRigWidget::setDownloadsTabEnabled(bool enabled) {
ui->tabWidget->setTabVisible(2, enabled);
}
void XMRigWidget::onWalletClosed() {
this->onStopClicked();
}
void XMRigWidget::onThreadsValueChanged(int threads) {
config()->set(Config::xmrigThreads, threads);
ui->label_threads->setText(QString("CPU threads: %1").arg(threads));
}
void XMRigWidget::onPoolChanged(const QString &pool) {
if (!pool.isEmpty()) {
config()->set(Config::xmrigPool, pool);
}
}
void XMRigWidget::onXMRigElevationChanged(bool elevated) {
config()->set(Config::xmrigElevated, elevated);
}
void XMRigWidget::onBrowseClicked() {
QString fileName = QFileDialog::getOpenFileName(this, "Path to XMRig executable", QDir::homePath());
if (fileName.isEmpty()) {
return;
}
config()->set(Config::xmrigPath, fileName);
ui->lineEdit_path->setText(fileName);
}
void XMRigWidget::onClearClicked() {
ui->console->clear();
}
void XMRigWidget::onUsePrimaryAddressClicked() {
ui->lineEdit_address->setText(m_wallet->address(0, 0));
}
void XMRigWidget::onStartClicked() {
QString xmrigPath = config()->get(Config::xmrigPath).toString();
if (!this->checkXMRigPath()) {
return;
}
QString address = [this](){
if (ui->combo_miningMode->currentIndex() == Config::MiningMode::Pool) {
return config()->get(Config::xmrigPool).toString();
} else {
return ui->lineEdit_solo->text().trimmed();
}
}();
if (address.isEmpty()) {
ui->console->appendPlainText("No pool or node address set. Please configure on the Settings tab.");
return;
}
// username is receiving address usually
auto username = m_wallet->getCacheAttribute("feather.xmrig_username");
auto password = m_wallet->getCacheAttribute("feather.xmrig_password");
if (username.isEmpty()) {
ui->console->appendPlainText("Please specify a receiving address on the Settings screen.");
return;
}
if (address.contains("cryptonote.social") && !username.contains(".")) {
// cryptonote social requires <addr>.<username>, we'll just grab a few chars from primary addy
username = QString("%1.%2").arg(username, m_wallet->address(0, 0).mid(0, 6));
}
int threads = ui->threadSlider->value();
m_XMRig->start(xmrigPath, threads, address, username, password, ui->relayTor->isChecked(), ui->check_tls->isChecked(),
ui->radio_elevateYes->isChecked());
}
void XMRigWidget::onStopClicked() {
m_XMRig->stop();
}
void XMRigWidget::onProcessOutput(const QByteArray &data) {
auto output = Utils::barrayToString(data);
if(output.endsWith("\n"))
output = output.trimmed();
ui->console->appendPlainText(output);
if(ui->check_autoscroll->isChecked())
ui->console->verticalScrollBar()->setValue(ui->console->verticalScrollBar()->maximum());
}
void XMRigWidget::onProcessError(const QString &msg) {
ui->console->appendPlainText("\n" + msg);
ui->btn_start->setEnabled(true);
ui->btn_stop->setEnabled(false);
this->setMiningStopped();
}
void XMRigWidget::onHashrate(const QString &hashrate) {
ui->label_status->show();
ui->label_status->setText(QString("Mining at %1").arg(hashrate));
}
void XMRigWidget::onDownloads(const QJsonObject &data) {
// For the downloads table we'll manually update the table
// with items once, as opposed to creating a class in
// src/models/. Saves effort; full-blown model
// is unnecessary in this case.
m_model->clear();
m_urls.clear();
auto version = data.value("version").toString();
ui->label_latest_version->setText(QString("Latest version: %1").arg(version));
QJsonObject assets = data.value("assets").toObject();
const auto _linux = assets.value("linux").toArray();
const auto macos = assets.value("macos").toArray();
const auto windows = assets.value("windows").toArray();
auto info = QSysInfo::productType();
QJsonArray *os_assets;
if(info == "osx") {
os_assets = const_cast<QJsonArray *>(&macos);
} else if (info == "windows") {
os_assets = const_cast<QJsonArray *>(&windows);
} else {
// assume linux
os_assets = const_cast<QJsonArray *>(&_linux);
}
int i = 0;
for(const auto &entry: *os_assets) {
auto _obj = entry.toObject();
auto _name = _obj.value("name").toString();
auto _url = _obj.value("url").toString();
auto _created_at = _obj.value("created_at").toString();
m_urls.append(_url);
auto download_count = _obj.value("download_count").toInt();
m_model->setItem(i, 0, Utils::qStandardItem(_name));
m_model->setItem(i, 1, Utils::qStandardItem(_created_at));
m_model->setItem(i, 2, Utils::qStandardItem(QString::number(download_count)));
i++;
}
m_model->setHeaderData(0, Qt::Horizontal, tr("Filename"), Qt::DisplayRole);
m_model->setHeaderData(1, Qt::Horizontal, tr("Date"), Qt::DisplayRole);
m_model->setHeaderData(2, Qt::Horizontal, tr("Downloads"), Qt::DisplayRole);
ui->tableView->verticalHeader()->setVisible(false);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->tableView->setColumnWidth(2, 100);
}
void XMRigWidget::showContextMenu(const QPoint &pos) {
QModelIndex index = ui->tableView->indexAt(pos);
if (!index.isValid()) {
return;
}
m_contextMenu->exec(ui->tableView->viewport()->mapToGlobal(pos));
}
void XMRigWidget::updatePools() {
QStringList pools = config()->get(Config::pools).toStringList();
if (pools.isEmpty()) {
pools = m_defaultPools;
config()->set(Config::pools, pools);
}
ui->combo_pools->clear();
ui->combo_pools->insertItems(0, pools);
QString preferredPool = config()->get(Config::xmrigPool).toString();
if (pools.contains(preferredPool)) {
ui->combo_pools->setCurrentIndex(pools.indexOf(preferredPool));
} else {
preferredPool = pools.at(0);
config()->set(Config::xmrigPool, preferredPool);
}
}
void XMRigWidget::printConsoleInfo() {
ui->console->appendPlainText(QString("Detected %1 CPU threads.").arg(QThread::idealThreadCount()));
if (this->checkXMRigPath()) {
QString path = config()->get(Config::xmrigPath).toString();
ui->console->appendPlainText(QString("XMRig path set to %1").arg(path));
}
}
void XMRigWidget::onMiningModeChanged(int mode) {
config()->set(Config::miningMode, mode);
if (mode == Config::MiningMode::Pool) {
ui->poolFrame->show();
ui->soloFrame->hide();
ui->label_poolNodeAddress->setText("Pool address:");
ui->check_tls->setChecked(true);
} else { // Solo mining
ui->poolFrame->hide();
ui->soloFrame->show();
ui->label_poolNodeAddress->setText("Node address:");
ui->check_tls->setChecked(false);
}
}
void XMRigWidget::onNetworkTLSToggled(bool checked) {
config()->set(Config::xmrigNetworkTLS, checked);
}
void XMRigWidget::onNetworkTorToggled(bool checked) {
config()->set(Config::xmrigNetworkTor, checked);
}
void XMRigWidget::onXMRigStateChanged(QProcess::ProcessState state) {
if (state == QProcess::ProcessState::Starting) {
ui->btn_start->setEnabled(false);
ui->btn_stop->setEnabled(false);
this->setMiningStarted();
}
else if (state == QProcess::ProcessState::Running) {
ui->btn_start->setEnabled(false);
ui->btn_stop->setEnabled(true);
this->setMiningStarted();
}
else if (state == QProcess::ProcessState::NotRunning) {
ui->btn_start->setEnabled(true); // todo
ui->btn_stop->setEnabled(false);
ui->label_status->hide();
this->setMiningStopped();
}
}
void XMRigWidget::setMiningStopped() {
m_isMining = false;
emit miningEnded();
}
void XMRigWidget::setMiningStarted() {
m_isMining = true;
emit miningStarted();
}
bool XMRigWidget::checkXMRigPath() {
QString path = config()->get(Config::xmrigPath).toString();
if (path.isEmpty()) {
ui->console->appendPlainText("No XMRig executable is set. Please configure on the Settings tab.");
return false;
} else if (!Utils::fileExists(path)) {
ui->console->appendPlainText("Invalid path to XMRig executable detected. Please reconfigure on the Settings tab.");
return false;
} else {
return true;
}
}
void XMRigWidget::linkClicked() {
QModelIndex index = ui->tableView->currentIndex();
auto download_link = m_urls.at(index.row());
Utils::externalLinkWarning(this, download_link);
}
QStandardItemModel *XMRigWidget::model() {
return m_model;
}
XMRigWidget::~XMRigWidget() = default;
+77
View File
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_XMRIGWIDGET_H
#define FEATHER_XMRIGWIDGET_H
#include <QMenu>
#include <QWidget>
#include <QItemSelection>
#include <QStandardItemModel>
#include "xmrig.h"
#include "utils/config.h"
#include "libwalletqt/Wallet.h"
namespace Ui {
class XMRigWidget;
}
class XMRigWidget : public QWidget
{
Q_OBJECT
public:
explicit XMRigWidget(Wallet *wallet, QWidget *parent = nullptr);
~XMRigWidget() override;
QStandardItemModel *model();
bool isMining();
void setDownloadsTabEnabled(bool enabled);
public slots:
void onWalletClosed();
void onStartClicked();
void onStopClicked();
void onClearClicked();
void onUsePrimaryAddressClicked();
void onDownloads(const QJsonObject &data);
void linkClicked();
void onProcessError(const QString &msg);
void onProcessOutput(const QByteArray &msg);
void onHashrate(const QString &hashrate);
void onMiningModeChanged(int mode);
void onNetworkTLSToggled(bool checked);
void onNetworkTorToggled(bool checked);
void onXMRigStateChanged(QProcess::ProcessState state);
private slots:
void onBrowseClicked();
void onThreadsValueChanged(int date);
void onPoolChanged(const QString &pool);
void onXMRigElevationChanged(bool elevated);
signals:
void miningStarted();
void miningEnded();
private:
void showContextMenu(const QPoint &pos);
void updatePools();
void printConsoleInfo();
void setMiningStopped();
void setMiningStarted();
bool checkXMRigPath();
QScopedPointer<Ui::XMRigWidget> ui;
Wallet *m_wallet;
XmRig *m_XMRig;
QStandardItemModel *m_model;
QMenu *m_contextMenu;
bool m_isMining = false;
QStringList m_urls;
QStringList m_defaultPools{"pool.xmr.pt:9000", "pool.supportxmr.com:9000", "mine.xmrpool.net:443", "xmrpool.eu:9999", "xmr-eu1.nanopool.org:14433","monerohash.com:9999", "cryptonote.social:5555", "cryptonote.social:5556"};
};
#endif // FEATHER_XMRWIDGET_H
+505
View File
@@ -0,0 +1,505 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>XMRigWidget</class>
<widget class="QWidget" name="XMRigWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1329</width>
<height>540</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<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="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="tabMining">
<attribute name="title">
<string>Status</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QFrame" name="outputFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<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="QPlainTextEdit" name="console">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="btn_clear">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="check_autoscroll">
<property name="text">
<string>auto-scroll</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_status">
<property name="text">
<string>Mining at</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_stop">
<property name="text">
<string>Stop</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_start">
<property name="text">
<string>Start mining</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabSettings">
<attribute name="title">
<string>Settings</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>XMRig executable:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLineEdit" name="lineEdit_path">
<property name="placeholderText">
<string>/path/to/xmrig</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_browse">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Run as admin/root:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QRadioButton" name="radio_elevateYes">
<property name="text">
<string>Yes</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radio_elevateNo">
<property name="text">
<string>No</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_threads">
<property name="text">
<string>CPU threads: </string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSlider" name="threadSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Mining mode:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QComboBox" name="combo_miningMode">
<item>
<property name="text">
<string>Pool mining</string>
</property>
</item>
<item>
<property name="text">
<string>Solo mining</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_poolNodeAddress">
<property name="text">
<string>Pool/node address:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QFrame" name="poolFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="combo_pools">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_poolConfig">
<property name="text">
<string>Configure</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>414</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="soloFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit_solo">
<property name="text">
<string>127.0.0.1:18081</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>173</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Network settings:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QCheckBox" name="check_tls">
<property name="text">
<string>Secure connection (TLS)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="relayTor">
<property name="text">
<string>Connect via Tor</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Receiving address:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="lineEdit_address"/>
</item>
<item>
<widget class="QPushButton" name="btn_fillPrimaryAddress">
<property name="text">
<string>Use primary address</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Password (optional):</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="lineEdit_password"/>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabDownloads">
<attribute name="title">
<string>Downloads</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_latest_version">
<property name="text">
<string>Latest version:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_version">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>(right-click to download)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableView" name="tableView">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<slots>
<slot>linkClicked()</slot>
</slots>
</ui>
+125
View File
@@ -0,0 +1,125 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#include <QScreen>
#include <QDesktopServices>
#include "utils/config.h"
#include "utils/Utils.h"
#include "xmrig.h"
#include "utils/TorManager.h"
XmRig::XmRig(const QString &configDir, QObject *parent)
: QObject(parent)
, m_process(new ChildProcess(this))
{
m_process->setProcessChannelMode(QProcess::MergedChannels);
connect(m_process, &QProcess::readyReadStandardOutput, this, &XmRig::handleProcessOutput);
connect(m_process, &QProcess::errorOccurred, this, &XmRig::handleProcessError);
connect(m_process, &QProcess::stateChanged, this, &XmRig::onStateChanged);
}
void XmRig::stop() {
qDebug() << m_process->processId();
if (m_process->state() == QProcess::Running) {
#if defined(Q_OS_WIN)
m_process->kill(); // https://doc.qt.io/qt-5/qprocess.html#terminate
#elif defined(Q_OS_LINUX)
if (m_elevated) {
m_killProcess.start("pkexec", QStringList() << "kill" << QString::number(m_process->processId()));
return;
}
#endif
m_process->terminate();
}
}
void XmRig::start(const QString &path, int threads, const QString &address, const QString &username,
const QString &password, bool tor, bool tls, bool elevated)
{
m_elevated = elevated;
auto state = m_process->state();
if (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting) {
emit error("Can't start XMRig, already running or starting");
return;
}
if (path.isEmpty()) {
emit error("XmRig->Start path parameter missing.");
return;
}
if (!Utils::fileExists(path)) {
emit error(QString("Path to XMRig binary invalid; file does not exist: %1").arg(path));
return;
}
QStringList arguments;
if (m_elevated) {
arguments << path;
}
arguments << "-o" << address;
arguments << "-a" << "rx/0";
arguments << "-u" << username;
if (!password.isEmpty()) {
arguments << "-p" << password;
}
arguments << "--no-color";
arguments << "-t" << QString::number(threads);
if (tor) {
QString host = config()->get(Config::socks5Host).toString();
QString port = config()->get(Config::socks5Port).toString();
if (!torManager()->isLocalTor()) {
host = torManager()->featherTorHost;
port = QString::number(torManager()->featherTorPort);
}
arguments << "-x" << QString("%1:%2").arg(host, port);
}
if (tls) {
arguments << "--tls";
}
QString cmd = QString("%1 %2").arg(path, arguments.join(" "));
emit output(cmd.toUtf8());
if (m_elevated) {
m_process->start("pkexec", arguments);
} else {
m_process->start(path, arguments);
}
}
void XmRig::onStateChanged(QProcess::ProcessState state) {
emit stateChanged(state);
if (state == QProcess::ProcessState::Running) {
emit output("XMRig started");
}
else if (state == QProcess::ProcessState::NotRunning) {
emit output("XMRig stopped");
}
}
void XmRig::handleProcessOutput() {
QByteArray _output = m_process->readAllStandardOutput();
if(_output.contains("miner") && _output.contains("speed")) {
// detect hashrate
auto str = Utils::barrayToString(_output);
auto spl = str.mid(str.indexOf("speed")).split(" ");
auto rate = spl.at(2) + "H/s";
qDebug() << "mining hashrate: " << rate;
emit hashrate(rate);
}
emit output(_output);
}
void XmRig::handleProcessError(QProcess::ProcessError err) {
if (err == QProcess::ProcessError::Crashed)
emit error("XMRig crashed or killed");
else if (err == QProcess::ProcessError::FailedToStart) {
auto path = config()->get(Config::xmrigPath).toString();
emit error(QString("XMRig binary failed to start: %1").arg(path));
}
}
+44
View File
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2020-2023 The Monero Project
#ifndef FEATHER_XMRIG_H
#define FEATHER_XMRIG_H
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <QRegularExpression>
#include <QtNetwork>
#include <QApplication>
#include <QMainWindow>
#include "utils/childproc.h"
class XmRig : public QObject
{
Q_OBJECT
public:
explicit XmRig(const QString &configDir, QObject *parent = nullptr);
void start(const QString &path, int threads, const QString &address, const QString &username, const QString &password, bool tor = false, bool tls = true, bool elevated = false);
void stop();
signals:
void error(const QString &msg);
void output(const QByteArray &data);
void hashrate(const QString &rate);
void stateChanged(QProcess::ProcessState state);
private slots:
void onStateChanged(QProcess::ProcessState);
void handleProcessOutput();
void handleProcessError(QProcess::ProcessError error);
private:
ChildProcess *m_process;
QProcess m_killProcess;
bool m_elevated;
};
#endif //FEATHER_XMRIG_H