Skip to content

Commit

Permalink
Add icon for Tor status (dashpay#27)
Browse files Browse the repository at this point in the history
-Use on-off icon
-Add icons to qt res folder
  • Loading branch information
wagerr-builder authored Feb 14, 2023
1 parent 86333de commit 0bf48a6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ RES_ICONS = \
qt/res/icons/transaction5.png \
qt/res/icons/transaction_abandoned.png \
qt/res/icons/transaction_locked.png \
qt/res/icons/tor.png \
qt/res/icons/tor2.png \
qt/res/icons/connect1_16.png \
qt/res/icons/connect2_16.png \
qt/res/icons/connect3_16.png \
Expand Down
4 changes: 4 additions & 0 deletions src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ bool CNetAddr::SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t addre

bool fAllowPrivateNet = DEFAULT_ALLOWPRIVATENET;

bool fTorEnabled = false;

/**
* Construct an unspecified IPv6 network address (::/128).
*
Expand Down Expand Up @@ -250,6 +252,7 @@ bool CNetAddr::SetSpecial(const std::string& str)
case ADDR_TORV2_SIZE:
m_net = NET_ONION;
m_addr.assign(input.begin(), input.end());
fTorEnabled = true;
return true;
case torv3::TOTAL_LEN: {
Span<const uint8_t> input_pubkey{input.data(), ADDR_TORV3_SIZE};
Expand All @@ -268,6 +271,7 @@ bool CNetAddr::SetSpecial(const std::string& str)
}

m_net = NET_ONION;
fTorEnabled = true;
m_addr.assign(input_pubkey.begin(), input_pubkey.end());
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <vector>

extern bool fAllowPrivateNet;
extern bool fTorEnabled;

/**
* A flag that is ORed into the protocol version to designate that addresses
Expand Down
42 changes: 41 additions & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <ui_interface.h>
#include <util/system.h>
#include <util/translation.h>
#include <net.h>

#include <QAction>
#include <QApplication>
Expand Down Expand Up @@ -67,7 +68,6 @@
#include <QVBoxLayout>
#include <QWindow>


const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
#if defined(Q_OS_MAC)
"macosx"
Expand Down Expand Up @@ -154,6 +154,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle,
labelConnectionsIcon = new GUIUtil::ClickableLabel();
labelProxyIcon = new GUIUtil::ClickableLabel();
labelBlocksIcon = new GUIUtil::ClickableLabel();
labelOnionIcon = new QLabel();
if(enableWallet)
{
frameBlocksLayout->addStretch();
Expand All @@ -166,13 +167,22 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle,
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelConnectionsIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelOnionIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(labelBlocksIcon);
frameBlocksLayout->addStretch();

// Hide the spinner/synced icon by default to avoid
// that the spinner starts before we have any connections
labelBlocksIcon->hide();

// TOR icon
QTimer *timerOnionIcon = new QTimer(labelOnionIcon);
connect(timerOnionIcon, SIGNAL(timeout()), this, SLOT(updateOnionIcon()));
//QTimer::singleShot(1000, this, SLOT(updateOnionIcon()));
timerOnionIcon->start(1000);
updateOnionIcon();

// Progress bar and label for blocks download
progressBarLabel = new QLabel();
progressBarLabel->setVisible(true);
Expand Down Expand Up @@ -820,6 +830,7 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
rpcConsole->setClientModel(_clientModel, tip_info->block_height, tip_info->block_time, tip_info->block_hash, tip_info->verification_progress);

updateProxyIcon();
updateOnionIcon();

#ifdef ENABLE_WALLET
if(walletFrame)
Expand Down Expand Up @@ -1211,6 +1222,7 @@ void BitcoinGUI::updateNetworkState()
case 6: case 7: icon = "connect_3"; break;
default: icon = "connect_4"; color = GUIUtil::ThemedColor::GREEN; break;
}
updateOnionIcon();

labelBlocksIcon->setVisible(count > 0);
updateProgressBarVisibility();
Expand Down Expand Up @@ -1257,6 +1269,33 @@ void BitcoinGUI::updateNetworkState()
}
}

void BitcoinGUI::updateOnionIcon()
{
// fTorEnabled is an extern defined in netaddress.h
bool onion_enabled = fTorEnabled;

std::string ipAddress;

LOCK(cs_mapLocalHost);
for (const std::pair<CNetAddr, LocalServiceInfo> &item : mapLocalHost)
{
ipAddress = item.first.ToString();
}
QString ipAddress_q = QString::fromStdString(ipAddress);
if (ipAddress.empty() || ipAddress.substr(ipAddress.length() - 6, 6).compare(".onion") != 0)
{
onion_enabled = false;
}
if (!onion_enabled) {
labelOnionIcon->setPixmap(GUIUtil::getIcon("tor2", GUIUtil::ThemedColor::RED).pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
labelOnionIcon->setToolTip(tr("Tor is <b>disabled</b>"));
} else {
labelOnionIcon->setPixmap(GUIUtil::getIcon("tor", GUIUtil::ThemedColor::GREEN).pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
labelOnionIcon->setToolTip(tr("Tor is <b>enabled</b>: %1").arg(ipAddress_q));
}
labelOnionIcon->show();
}

void BitcoinGUI::setNumConnections(int count)
{
updateNetworkState();
Expand All @@ -1265,6 +1304,7 @@ void BitcoinGUI::setNumConnections(int count)
void BitcoinGUI::setNetworkActive(bool networkActive)
{
updateNetworkState();
updateOnionIcon();
}

void BitcoinGUI::updateHeadersSyncProgressLabel()
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class BitcoinGUI : public QMainWindow
GUIUtil::ClickableLabel* labelConnectionsIcon = nullptr;
GUIUtil::ClickableLabel* labelProxyIcon = nullptr;
GUIUtil::ClickableLabel* labelBlocksIcon = nullptr;
QLabel* labelOnionIcon = nullptr;
QLabel* progressBarLabel = nullptr;
GUIUtil::ClickableProgressBar* progressBar = nullptr;
QProgressDialog* progressDialog = nullptr;
Expand Down Expand Up @@ -380,6 +381,7 @@ public Q_SLOTS:
/** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
void setTrayIconVisible(bool);

void updateOnionIcon();
void showModalOverlay();

void updateCoinJoinVisibility();
Expand Down
Binary file added src/qt/res/icons/tor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/qt/res/icons/tor2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/qt/wagerr.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<file alias="transaction_5">res/icons/transaction5.png</file>
<file alias="transaction_abandoned">res/icons/transaction_abandoned.png</file>
<file alias="transaction_locked">res/icons/transaction_locked.png</file>
<file alias="tor">res/icons/tor.png</file>
<file alias="tor2">res/icons/tor2.png</file>
<file alias="eye">res/icons/eye.png</file>
<file alias="eye_minus">res/icons/eye_minus.png</file>
<file alias="eye_plus">res/icons/eye_plus.png</file>
Expand Down

0 comments on commit 0bf48a6

Please sign in to comment.