This commit is contained in:
tobtoht
2023-12-04 20:47:19 +01:00
parent 14712341e7
commit db0c8d66da
96 changed files with 3060 additions and 725 deletions
+16 -1
View File
@@ -445,7 +445,7 @@ QString amountToCurrencyString(double amount, const QString &currencyCode) {
if (currencyCode == "USD")
return locale.toCurrencyString(amount, "$").remove("\xC2\xA0");
return locale.toCurrencyString(amount).remove("\xC2\xA0");
return QString("%1%2").arg(locale.currencySymbol(), QString::number(amount, 'f', 2));
}
QStandardItem *qStandardItem(const QString& text) {
@@ -693,4 +693,19 @@ QWindow *windowForQObject(QObject* object) {
}
return nullptr;
}
void clearLayout(QLayout* layout, bool deleteWidgets)
{
while (QLayoutItem *item = layout->takeAt(0)) {
if (deleteWidgets) {
if (QWidget *widget = item->widget()) {
widget->deleteLater();
}
}
if (QLayout *childLayout = item->layout()) {
clearLayout(childLayout, deleteWidgets);
}
delete item;
}
}
}
+1
View File
@@ -113,6 +113,7 @@ namespace Utils
void openDir(QWidget *parent, const QString &message, const QString& dir);
QWindow* windowForQObject(QObject* object);
void clearLayout(QLayout *layout, bool deleteWidgets = true);
}
#endif //FEATHER_UTILS_H
+7 -135
View File
@@ -5,6 +5,7 @@
#include "Utils.h"
#include "utils/os/tails.h"
#include "utils/os/whonix.h"
#include "plugins/PluginRegistry.h"
#include <QJsonObject>
@@ -13,6 +14,10 @@ WebsocketNotifier::WebsocketNotifier(QObject *parent)
, websocketClient(new WebsocketClient(this))
{
connect(websocketClient, &WebsocketClient::WSMessage, this, &WebsocketNotifier::onWSMessage);
for (const auto& plugin : PluginRegistry::getPlugins()) {
m_pluginSubscriptions << plugin->socketData();
}
}
QPointer<WebsocketNotifier> WebsocketNotifier::m_instance(nullptr);
@@ -45,56 +50,20 @@ void WebsocketNotifier::onWSMessage(const QJsonObject &msg) {
emit FiatRatesReceived(fiat_rates);
}
else if(cmd == "reddit") {
QJsonArray reddit_data = msg.value("data").toArray();
this->onWSReddit(reddit_data);
}
else if(cmd == "ccs") {
auto ccs_data = msg.value("data").toArray();
this->onWSCCS(ccs_data);
}
else if(cmd == "bounties") {
auto data = msg.value("data").toArray();
this->onWSBounties(data);
}
else if(cmd == "txFiatHistory") {
auto txFiatHistory_data = msg.value("data").toObject();
emit TxFiatHistoryReceived(txFiatHistory_data);
}
else if(cmd == "revuo") {
auto revuo_data = msg.value("data").toArray();
this->onWSRevuo(revuo_data);
}
#if defined(CHECK_UPDATES)
else if (cmd == "updates") {
this->onWSUpdates(msg.value("data").toObject());
}
#endif
#if defined(HAS_XMRIG)
else if(cmd == "xmrig") {
this->onWSXMRigDownloads(msg.value("data").toObject());
else if (m_pluginSubscriptions.contains(cmd)) {
emit dataReceived(cmd, msg.value("data"));
}
#endif
#if defined(HAS_LOCALMONERO)
else if (cmd == "localmonero_countries") {
emit LocalMoneroCountriesReceived(msg.value("data").toArray());
}
else if (cmd == "localmonero_currencies") {
emit LocalMoneroCurrenciesReceived(msg.value("data").toArray());
}
else if (cmd == "localmonero_payment_methods") {
emit LocalMoneroPaymentMethodsReceived(msg.value("data").toObject());
}
#endif
}
void WebsocketNotifier::emitCache() {
@@ -136,103 +105,6 @@ void WebsocketNotifier::onWSNodes(const QJsonArray &nodes) {
emit NodesReceived(l);
}
void WebsocketNotifier::onWSReddit(const QJsonArray& reddit_data) {
QList<QSharedPointer<RedditPost>> l;
for (auto &&entry: reddit_data) {
auto obj = entry.toObject();
auto redditPost = new RedditPost(
obj.value("title").toString(),
obj.value("author").toString(),
obj.value("permalink").toString(),
obj.value("comments").toInt());
QSharedPointer<RedditPost> r = QSharedPointer<RedditPost>(redditPost);
l.append(r);
}
emit RedditReceived(l);
}
void WebsocketNotifier::onWSCCS(const QJsonArray &ccs_data) {
QList<QSharedPointer<CCSEntry>> l;
for (const auto& entry: ccs_data) {
auto obj = entry.toObject();
auto c = QSharedPointer<CCSEntry>(new CCSEntry());
if (obj.value("state").toString() != "FUNDING-REQUIRED")
continue;
c->state = obj.value("state").toString();
c->address = obj.value("address").toString();
c->author = obj.value("author").toString();
c->date = obj.value("date").toString();
c->title = obj.value("title").toString();
c->target_amount = obj.value("target_amount").toDouble();
c->raised_amount = obj.value("raised_amount").toDouble();
c->percentage_funded = obj.value("percentage_funded").toDouble();
c->contributions = obj.value("contributions").toInt();
c->organizer = obj.value("organizer").toString();
c->currency = obj.value("currency").toString();
QString urlpath = obj.value("urlpath").toString();
if (c->organizer == "CCS") {
c->url = QString("https://ccs.getmonero.org/%1").arg(urlpath);
}
else if (c->organizer == "MAGIC") {
c->url = QString("https://monerofund.org/%1").arg(urlpath);
}
else {
continue;
}
l.append(c);
}
emit CCSReceived(l);
}
void WebsocketNotifier::onWSRevuo(const QJsonArray &revuo_data) {
QList<QSharedPointer<RevuoItem>> l;
for (auto &&entry: revuo_data) {
auto obj = entry.toObject();
QStringList newsbytes;
for (const auto &n : obj.value("newsbytes").toArray()) {
newsbytes.append(n.toString());
}
auto revuoItem = new RevuoItem(
obj.value("title").toString(),
obj.value("url").toString(),
newsbytes);
QSharedPointer<RevuoItem> r = QSharedPointer<RevuoItem>(revuoItem);
l.append(r);
}
emit RevuoReceived(l);
}
void WebsocketNotifier::onWSBounties(const QJsonArray &bounties_data) {
QList<QSharedPointer<BountyEntry>> l;
for (const auto& entry : bounties_data) {
QJsonObject obj = entry.toObject();
auto bounty = new BountyEntry(obj.value("votes").toInt(),
obj.value("title").toString(),
obj.value("amount").toDouble(),
obj.value("link").toString(),
obj.value("address").toString(),
obj.value("status").toString());
QSharedPointer<BountyEntry> b = QSharedPointer<BountyEntry>(bounty);
l.append(b);
}
emit BountyReceived(l);
}
void WebsocketNotifier::onWSUpdates(const QJsonObject &updates) {
emit UpdatesReceived(updates);
}
+2 -12
View File
@@ -11,10 +11,6 @@
#include "networktype.h"
#include "nodes.h"
#include "prices.h"
#include "plugins/bounties/Bounty.h"
#include "plugins/reddit/RedditPost.h"
#include "plugins/ccs/CCSEntry.h"
#include "plugins/revuo/RevuoItem.h"
#include "TxFiatHistory.h"
class WebsocketNotifier : public QObject {
@@ -36,31 +32,25 @@ signals:
void NodesReceived(QList<FeatherNode> &L);
void CryptoRatesReceived(const QJsonArray &data);
void FiatRatesReceived(const QJsonObject &fiat_rates);
void RedditReceived(QList<QSharedPointer<RedditPost>> L);
void CCSReceived(QList<QSharedPointer<CCSEntry>> L);
void BountyReceived(QList<QSharedPointer<BountyEntry>> L);
void RevuoReceived(QList<QSharedPointer<RevuoItem>> L);
void TxFiatHistoryReceived(const QJsonObject &data);
void UpdatesReceived(const QJsonObject &updates);
void XMRigDownloadsReceived(const QJsonObject &downloads);
void LocalMoneroCountriesReceived(const QJsonArray &countries);
void LocalMoneroCurrenciesReceived(const QJsonArray &currencies);
void LocalMoneroPaymentMethodsReceived(const QJsonObject &payment_methods);
void dataReceived(const QString &type, const QJsonValue &json);
private slots:
void onWSMessage(const QJsonObject &msg);
void onWSNodes(const QJsonArray &nodes);
void onWSReddit(const QJsonArray &reddit_data);
void onWSCCS(const QJsonArray &ccs_data);
void onWSBounties(const QJsonArray &bounties_data);
void onWSRevuo(const QJsonArray &revuo_data);
void onWSUpdates(const QJsonObject &updates);
void onWSXMRigDownloads(const QJsonObject &downloads);
private:
static QPointer<WebsocketNotifier> m_instance;
QStringList m_pluginSubscriptions;
QHash<QString, QJsonObject> m_cache;
QDateTime m_lastMessageReceived;
};
+8 -6
View File
@@ -43,11 +43,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::useOnionNodes,{QS("useOnionNodes"), false}},
// Tabs
{Config::showTabHome,{QS("showTabHome"), true}},
{Config::showTabCoins,{QS("showTabCoins"), false}},
{Config::showTabExchange, {QS("showTabExchange"), false}},
{Config::showTabXMRig,{QS("showTabXMRig"), false}},
{Config::showTabCalc,{QS("showTabCalc"), true}},
{Config::enabledTabs, {QS("enabledTabs"), QStringList{"Home", "History", "Send", "Receive", "Calc"}}},
{Config::showSearchbar,{QS("showSearchbar"), true}},
// Receive
@@ -120,7 +116,13 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::socks5Pass, {QS("socks5Pass"), ""}}, // Unused
{Config::torManagedPort, {QS("torManagedPort"), "19450"}},
{Config::useLocalTor, {QS("useLocalTor"), false}},
{Config::initSyncThreshold, {QS("initSyncThreshold"), 360}}
{Config::initSyncThreshold, {QS("initSyncThreshold"), 360}},
{Config::enabledPlugins, {QS("enabledPlugins"), QStringList{"tickers", "crowdfunding", "bounties", "reddit", "revuo", "localmonero", "calc", "xmrig"}}},
{Config::restartRequired, {QS("restartRequired"), false}},
{Config::tickers, {QS("tickers"), QStringList{"XMR", "BTC", "XMR/BTC"}}},
{Config::tickersShowFiatBalance, {QS("tickersShowFiatBalance"), true}},
};
+8 -5
View File
@@ -46,11 +46,7 @@ public:
useOnionNodes,
// Tabs
showTabHome,
showTabCoins,
showTabExchange,
showTabCalc,
showTabXMRig,
enabledTabs,
showSearchbar,
// Receive
@@ -141,6 +137,13 @@ public:
fiatSymbols,
cryptoSymbols,
enabledPlugins,
restartRequired,
// Tickers
tickers,
tickersShowFiatBalance,
};
enum PrivacyLevel {