mirror of
https://github.com/wownero/wowlet.git
synced 2026-12-04 05:54:01 +01:00
Documentation browser, improved error messages
This commit is contained in:
@@ -38,7 +38,7 @@ QNetworkAccessManager* getNetworkClearnet()
|
||||
|
||||
QNetworkAccessManager* getNetwork(const QString &address)
|
||||
{
|
||||
if (config()->get(Config::proxy).toInt() == Config::Proxy::None) {
|
||||
if (conf()->get(Config::proxy).toInt() == Config::Proxy::None) {
|
||||
return getNetworkClearnet();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ void Networking::setUserAgent(const QString &userAgent) {
|
||||
}
|
||||
|
||||
QNetworkReply* Networking::get(QObject *parent, const QString &url) {
|
||||
if (config()->get(Config::offlineMode).toBool()) {
|
||||
if (conf()->get(Config::offlineMode).toBool()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ QNetworkReply* Networking::get(QObject *parent, const QString &url) {
|
||||
}
|
||||
|
||||
QNetworkReply* Networking::getJson(QObject *parent, const QString &url) {
|
||||
if (config()->get(Config::offlineMode).toBool()) {
|
||||
if (conf()->get(Config::offlineMode).toBool()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ QNetworkReply* Networking::getJson(QObject *parent, const QString &url) {
|
||||
}
|
||||
|
||||
QNetworkReply* Networking::postJson(QObject *parent, const QString &url, const QJsonObject &data) {
|
||||
if (config()->get(Config::offlineMode).toBool()) {
|
||||
if (conf()->get(Config::offlineMode).toBool()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ void TorManager::init() {
|
||||
m_started = false;
|
||||
}
|
||||
|
||||
featherTorPort = config()->get(Config::torManagedPort).toString().toUShort();
|
||||
featherTorPort = conf()->get(Config::torManagedPort).toString().toUShort();
|
||||
}
|
||||
|
||||
void TorManager::stop() {
|
||||
@@ -118,13 +118,13 @@ void TorManager::checkConnection() {
|
||||
this->setConnectionState(code == 0);
|
||||
}
|
||||
|
||||
else if (config()->get(Config::proxy).toInt() != Config::Proxy::Tor) {
|
||||
else if (conf()->get(Config::proxy).toInt() != Config::Proxy::Tor) {
|
||||
this->setConnectionState(false);
|
||||
}
|
||||
|
||||
else if (m_localTor) {
|
||||
QString host = config()->get(Config::socks5Host).toString();
|
||||
quint16 port = config()->get(Config::socks5Port).toString().toUShort();
|
||||
QString host = conf()->get(Config::socks5Host).toString();
|
||||
quint16 port = conf()->get(Config::socks5Port).toString().toUShort();
|
||||
this->setConnectionState(Utils::portOpen(host, port));
|
||||
}
|
||||
|
||||
@@ -237,8 +237,8 @@ bool TorManager::isStarted() {
|
||||
}
|
||||
|
||||
bool TorManager::shouldStartTorDaemon() {
|
||||
QString torHost = config()->get(Config::socks5Host).toString();
|
||||
quint16 torPort = config()->get(Config::socks5Port).toString().toUShort();
|
||||
QString torHost = conf()->get(Config::socks5Host).toString();
|
||||
quint16 torPort = conf()->get(Config::socks5Port).toString().toUShort();
|
||||
QString torHostPort = QString("%1:%2").arg(torHost, QString::number(torPort));
|
||||
|
||||
// Don't start a Tor daemon if Feather is run with Torsocks
|
||||
@@ -258,12 +258,12 @@ bool TorManager::shouldStartTorDaemon() {
|
||||
#endif
|
||||
|
||||
// Don't start a Tor daemon if our proxy config isn't set to Tor
|
||||
if (config()->get(Config::proxy).toInt() != Config::Proxy::Tor) {
|
||||
if (conf()->get(Config::proxy).toInt() != Config::Proxy::Tor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't start a Tor daemon if --use-local-tor is specified
|
||||
if (config()->get(Config::useLocalTor).toBool()) {
|
||||
if (conf()->get(Config::useLocalTor).toBool()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+80
-5
@@ -16,6 +16,7 @@
|
||||
#include "utils/config.h"
|
||||
#include "utils/os/tails.h"
|
||||
#include "utils/os/whonix.h"
|
||||
#include "WindowManager.h"
|
||||
|
||||
namespace Utils {
|
||||
bool fileExists(const QString &path) {
|
||||
@@ -46,6 +47,17 @@ QByteArray fileOpenQRC(const QString &path) {
|
||||
return data;
|
||||
}
|
||||
|
||||
QString loadQrc(const QString &qrc) {
|
||||
QFile file(qrc);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "Failed to open resource:" << qrc;
|
||||
return QString();
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
return in.readAll();
|
||||
}
|
||||
|
||||
bool fileWrite(const QString &path, const QString &data) {
|
||||
QFile file(path);
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
@@ -292,7 +304,7 @@ bool xdgDesktopEntryRegister() {
|
||||
}
|
||||
|
||||
bool portOpen(const QString &hostname, quint16 port) { // TODO: this call should be async
|
||||
if (config()->get(Config::offlineMode).toBool()) {
|
||||
if (conf()->get(Config::offlineMode).toBool()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -469,16 +481,15 @@ QString blockExplorerLink(const QString &blockExplorer, NetworkType::Type nettyp
|
||||
}
|
||||
|
||||
void externalLinkWarning(QWidget *parent, const QString &url){
|
||||
if (!config()->get(Config::warnOnExternalLink).toBool()) {
|
||||
if (!conf()->get(Config::warnOnExternalLink).toBool()) {
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
return;
|
||||
}
|
||||
|
||||
QString body = QString("You are about to open the following link:\n\n%1").arg(url);
|
||||
|
||||
QMessageBox linkWarning(parent);
|
||||
linkWarning.setWindowTitle("External link warning");
|
||||
linkWarning.setText(body);
|
||||
linkWarning.setText("You are about to open the following link:");
|
||||
linkWarning.setInformativeText(url);
|
||||
QPushButton *copy = linkWarning.addButton("Copy link", QMessageBox::HelpRole);
|
||||
linkWarning.addButton(QMessageBox::Cancel);
|
||||
linkWarning.addButton(QMessageBox::Ok);
|
||||
@@ -574,4 +585,68 @@ bool isLocalUrl(const QUrl &url) {
|
||||
QRegularExpression localNetwork(R"((^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.))");
|
||||
return (localNetwork.match(url.host()).hasMatch() || url.host() == "localhost");
|
||||
}
|
||||
|
||||
void showError(QWidget *parent, const QString &title, const QString &description, const QStringList &helpItems, const QString &doc, const QString &highlight, const QString &link) {
|
||||
showMsg(parent, QMessageBox::Warning, "Error", title, description, helpItems, doc, highlight, link);
|
||||
}
|
||||
|
||||
void showInfo(QWidget *parent, const QString &title, const QString &description, const QStringList &helpItems, const QString &doc, const QString &highlight, const QString &link) {
|
||||
showMsg(parent, QMessageBox::Information,"Info", title, description, helpItems, doc, highlight, link);
|
||||
}
|
||||
|
||||
void showWarning(QWidget *parent, const QString &title, const QString &description, const QStringList &helpItems, const QString &doc, const QString &highlight, const QString &link) {
|
||||
showMsg(parent, QMessageBox::Warning, "Warning", title, description, helpItems, doc, highlight, link);
|
||||
}
|
||||
|
||||
void showMsg(QWidget *parent, QMessageBox::Icon icon, const QString &windowTitle, const QString &title, const QString &description, const QStringList &helpItems, const QString &doc, const QString &highlight, const QString &link) {
|
||||
QString informativeText = description;
|
||||
if (!helpItems.isEmpty()) {
|
||||
informativeText += "\n";
|
||||
}
|
||||
for (const auto &item : helpItems) {
|
||||
informativeText += QString("\n• %1").arg(item);
|
||||
}
|
||||
|
||||
auto *msgBox = new QMessageBox(parent);
|
||||
msgBox->setText(title);
|
||||
msgBox->setInformativeText(informativeText);
|
||||
msgBox->setIcon(icon);
|
||||
msgBox->setWindowTitle(windowTitle);
|
||||
msgBox->setStandardButtons(doc.isEmpty() ? QMessageBox::Ok : (QMessageBox::Ok | QMessageBox::Help));
|
||||
msgBox->setDefaultButton(QMessageBox::Ok);
|
||||
|
||||
QPushButton *openLinkButton = nullptr;
|
||||
if (!link.isEmpty()) {
|
||||
openLinkButton = msgBox->addButton("Open link", QMessageBox::ActionRole);
|
||||
}
|
||||
|
||||
msgBox->exec();
|
||||
|
||||
if (openLinkButton && msgBox->clickedButton() == openLinkButton) {
|
||||
Utils::externalLinkWarning(parent, link);
|
||||
}
|
||||
|
||||
if (msgBox->result() == QMessageBox::Help) {
|
||||
windowManager()->showDocs(parent, doc);
|
||||
windowManager()->setDocsHighlight(highlight);
|
||||
}
|
||||
|
||||
msgBox->deleteLater();
|
||||
}
|
||||
|
||||
void showMsg(const Message &m) {
|
||||
showMsg(m.parent, QMessageBox::Warning, "Error", m.title, m.description, m.helpItems, m.doc, m.highlight);
|
||||
}
|
||||
|
||||
QWindow *windowForQObject(QObject* object) {
|
||||
while (object) {
|
||||
if (auto widget = qobject_cast<QWidget*>(object)) {
|
||||
if (widget->windowHandle()) {
|
||||
return widget->windowHandle();
|
||||
}
|
||||
}
|
||||
object = object->parent();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,40 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTextCharFormat>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "libwalletqt/Wallet.h"
|
||||
#include "networktype.h"
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
enum MessageType
|
||||
{
|
||||
INFO = 0,
|
||||
WARNING,
|
||||
ERROR
|
||||
};
|
||||
|
||||
struct Message
|
||||
{
|
||||
QWidget *parent;
|
||||
MessageType type;
|
||||
QString title;
|
||||
QString description;
|
||||
QStringList helpItems;
|
||||
QString doc;
|
||||
QString highlight;
|
||||
QString link;
|
||||
|
||||
QString toString() const {
|
||||
return QString("%1: %2").arg(title, description);
|
||||
}
|
||||
};
|
||||
|
||||
bool fileExists(const QString &path);
|
||||
QByteArray fileOpen(const QString &path);
|
||||
QByteArray fileOpenQRC(const QString &path);
|
||||
QString loadQrc(const QString &qrc);
|
||||
bool fileWrite(const QString &path, const QString &data);
|
||||
bool pixmapWrite(const QString &path, const QPixmap &pixmap);
|
||||
QStringList fileFind(const QRegularExpression &pattern, const QString &baseDir, int level, int depth, int maxPerDir);
|
||||
@@ -74,6 +99,14 @@ namespace Utils
|
||||
QString QtEnumToString (QEnum value) {
|
||||
return QString::fromStdString(std::string(QMetaEnum::fromType<QEnum>().valueToKey(value)));
|
||||
}
|
||||
|
||||
void showError(QWidget *parent, const QString &title, const QString &description = "", const QStringList &helpItems = {}, const QString &doc = "", const QString &highlight = "", const QString &link = "");
|
||||
void showInfo(QWidget *parent, const QString &title, const QString &description = "", const QStringList &helpItems = {}, const QString &doc = "", const QString &highlight = "", const QString &link = "");
|
||||
void showWarning(QWidget *parent, const QString &title, const QString &description = "", const QStringList &helpItems = {}, const QString &doc = "", const QString &highlight = "", const QString &link = "");
|
||||
void showMsg(QWidget *parent, QMessageBox::Icon icon, const QString &windowTitle, const QString &title, const QString &description, const QStringList &helpItems = {}, const QString &doc = "", const QString &highlight = "", const QString &link = "");
|
||||
void showMsg(const Message &message);
|
||||
|
||||
QWindow* windowForQObject(QObject* object);
|
||||
}
|
||||
|
||||
#endif //FEATHER_UTILS_H
|
||||
|
||||
@@ -45,11 +45,11 @@ void WebsocketClient::start() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config()->get(Config::offlineMode).toBool()) {
|
||||
if (conf()->get(Config::offlineMode).toBool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config()->get(Config::disableWebsocket).toBool()) {
|
||||
if (conf()->get(Config::disableWebsocket).toBool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,11 +107,11 @@ void WebsocketClient::nextWebsocketUrl() {
|
||||
}
|
||||
|
||||
Config::Proxy WebsocketClient::networkType() {
|
||||
if (config()->get(Config::proxy).toInt() == Config::Proxy::Tor && config()->get(Config::torOnlyAllowOnion).toBool()) {
|
||||
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor && conf()->get(Config::torOnlyAllowOnion).toBool()) {
|
||||
// Websocket performance with onion services is abysmal, connect to clearnet server unless instructed otherwise
|
||||
return Config::Proxy::Tor;
|
||||
}
|
||||
else if (config()->get(Config::proxy).toInt() == Config::Proxy::i2p) {
|
||||
else if (conf()->get(Config::proxy).toInt() == Config::Proxy::i2p) {
|
||||
return Config::Proxy::i2p;
|
||||
}
|
||||
else {
|
||||
|
||||
+1
-1
@@ -171,7 +171,7 @@ private:
|
||||
QHash<QString, QVariant> m_defaults;
|
||||
};
|
||||
|
||||
inline Config* config()
|
||||
inline Config* conf()
|
||||
{
|
||||
return Config::instance();
|
||||
}
|
||||
|
||||
+19
-19
@@ -32,7 +32,7 @@ bool NodeList::addNode(const QString &node, NetworkType::Type networkType, NodeL
|
||||
netTypeObj[sourceStr] = sourceArray;
|
||||
obj[networkTypeStr] = netTypeObj;
|
||||
|
||||
config()->set(Config::nodes, obj);
|
||||
conf()->set(Config::nodes, obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void NodeList::setNodes(const QStringList &nodes, NetworkType::Type networkType,
|
||||
netTypeObj[sourceStr] = sourceArray;
|
||||
obj[networkTypeStr] = netTypeObj;
|
||||
|
||||
config()->set(Config::nodes, obj);
|
||||
conf()->set(Config::nodes, obj);
|
||||
}
|
||||
|
||||
QStringList NodeList::getNodes(NetworkType::Type networkType, NodeList::Type source) {
|
||||
@@ -70,11 +70,11 @@ QStringList NodeList::getNodes(NetworkType::Type networkType, NodeList::Type sou
|
||||
}
|
||||
|
||||
QJsonObject NodeList::getConfigData() {
|
||||
QJsonObject obj = config()->get(Config::nodes).toJsonObject();
|
||||
QJsonObject obj = conf()->get(Config::nodes).toJsonObject();
|
||||
|
||||
// Load old config format
|
||||
if (obj.isEmpty()) {
|
||||
auto jsonData = config()->get(Config::nodes).toByteArray();
|
||||
auto jsonData = conf()->get(Config::nodes).toByteArray();
|
||||
if (Utils::validateJSON(jsonData)) {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(jsonData);
|
||||
obj = doc.object();
|
||||
@@ -208,11 +208,11 @@ void Nodes::connectToNode(const FeatherNode &node) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config()->get(Config::offlineMode).toBool()) {
|
||||
if (conf()->get(Config::offlineMode).toBool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config()->get(Config::proxy).toInt() == Config::Proxy::Tor && config()->get(Config::torOnlyAllowOnion).toBool()) {
|
||||
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor && conf()->get(Config::torOnlyAllowOnion).toBool()) {
|
||||
if (!node.isOnion() && !node.isLocal()) {
|
||||
// We only want to connect to .onion nodes, but local nodes get an exception.
|
||||
return;
|
||||
@@ -230,11 +230,11 @@ void Nodes::connectToNode(const FeatherNode &node) {
|
||||
|
||||
QString proxyAddress;
|
||||
if (useSocks5Proxy(node)) {
|
||||
if (config()->get(Config::proxy).toInt() == Config::Proxy::Tor && !torManager()->isLocalTor()) {
|
||||
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor && !torManager()->isLocalTor()) {
|
||||
proxyAddress = QString("%1:%2").arg(torManager()->featherTorHost, QString::number(torManager()->featherTorPort));
|
||||
} else {
|
||||
proxyAddress = QString("%1:%2").arg(config()->get(Config::socks5Host).toString(),
|
||||
config()->get(Config::socks5Port).toString());
|
||||
proxyAddress = QString("%1:%2").arg(conf()->get(Config::socks5Host).toString(),
|
||||
conf()->get(Config::socks5Port).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ void Nodes::setCustomNodes(const QList<FeatherNode> &nodes) {
|
||||
}
|
||||
|
||||
void Nodes::onWalletRefreshed() {
|
||||
if (config()->get(Config::proxy) == Config::Proxy::Tor && config()->get(Config::torPrivacyLevel).toInt() == Config::allTorExceptInitSync) {
|
||||
if (conf()->get(Config::proxy) == Config::Proxy::Tor && conf()->get(Config::torPrivacyLevel).toInt() == Config::allTorExceptInitSync) {
|
||||
// Don't reconnect if we're connected to a local node (traffic will not be routed through Tor)
|
||||
if (m_connection.isLocal())
|
||||
return;
|
||||
@@ -414,15 +414,15 @@ void Nodes::onWalletRefreshed() {
|
||||
}
|
||||
|
||||
bool Nodes::useOnionNodes() {
|
||||
if (config()->get(Config::proxy) != Config::Proxy::Tor) {
|
||||
if (conf()->get(Config::proxy) != Config::Proxy::Tor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config()->get(Config::torOnlyAllowOnion).toBool()) {
|
||||
if (conf()->get(Config::torOnlyAllowOnion).toBool()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto privacyLevel = config()->get(Config::torPrivacyLevel).toInt();
|
||||
auto privacyLevel = conf()->get(Config::torPrivacyLevel).toInt();
|
||||
if (privacyLevel == Config::allTor) {
|
||||
return true;
|
||||
}
|
||||
@@ -433,7 +433,7 @@ bool Nodes::useOnionNodes() {
|
||||
}
|
||||
|
||||
if (appData()->heights.contains(constants::networkType)) {
|
||||
int initSyncThreshold = config()->get(Config::initSyncThreshold).toInt();
|
||||
int initSyncThreshold = conf()->get(Config::initSyncThreshold).toInt();
|
||||
int networkHeight = appData()->heights[constants::networkType];
|
||||
|
||||
if (m_wallet && m_wallet->blockChainHeight() > (networkHeight - initSyncThreshold)) {
|
||||
@@ -446,7 +446,7 @@ bool Nodes::useOnionNodes() {
|
||||
}
|
||||
|
||||
bool Nodes::useI2PNodes() {
|
||||
if (config()->get(Config::proxy) == Config::Proxy::i2p) {
|
||||
if (conf()->get(Config::proxy) == Config::Proxy::i2p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@ bool Nodes::useSocks5Proxy(const FeatherNode &node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (config()->get(Config::proxy).toInt() == Config::Proxy::None) {
|
||||
if (conf()->get(Config::proxy).toInt() == Config::Proxy::None) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -477,12 +477,12 @@ bool Nodes::useSocks5Proxy(const FeatherNode &node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (config()->get(Config::proxy).toInt() == Config::Proxy::Tor) {
|
||||
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor) {
|
||||
// Don't use socks5 proxy if initial sync traffic is excluded.
|
||||
return this->useOnionNodes();
|
||||
}
|
||||
|
||||
if (config()->get(Config::proxy).toInt() != Config::Proxy::None) {
|
||||
if (conf()->get(Config::proxy).toInt() != Config::Proxy::None) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -556,7 +556,7 @@ FeatherNode Nodes::connection() {
|
||||
}
|
||||
|
||||
NodeSource Nodes::source() {
|
||||
return static_cast<NodeSource>(config()->get(Config::nodeSource).toInt());
|
||||
return static_cast<NodeSource>(conf()->get(Config::nodeSource).toInt());
|
||||
}
|
||||
|
||||
int Nodes::modeHeight(const QList<FeatherNode> &nodes) {
|
||||
|
||||
@@ -173,10 +173,10 @@ QString Updater::getPlatformTag() {
|
||||
}
|
||||
|
||||
QString Updater::getWebsiteUrl() {
|
||||
if (config()->get(Config::proxy).toInt() == Config::Proxy::Tor && config()->get(Config::torOnlyAllowOnion).toBool()) {
|
||||
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor && conf()->get(Config::torOnlyAllowOnion).toBool()) {
|
||||
return "http://featherdvtpi7ckdbkb2yxjfwx3oyvr3xjz3oo4rszylfzjdg6pbm3id.onion";
|
||||
}
|
||||
else if (config()->get(Config::proxy).toInt() == Config::Proxy::i2p) {
|
||||
else if (conf()->get(Config::proxy).toInt() == Config::Proxy::i2p) {
|
||||
return "http://rwzulgcql2y3n6os2jhmhg6un2m33rylazfnzhf56likav47aylq.b32.i2p";
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user