Skip to content

Commit

Permalink
qt: Add "All connections are via Tor" icon to the status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Sep 10, 2020
1 parent 285ee93 commit 082a680
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class NodeImpl : public Node
}
}
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }

bool hasTorOnlyConnections() override
{
return HasTorOnlyConnections();
}

size_t getNodeCount(CConnman::NumConnections flags) override
{
return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0;
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class Node
//! Get proxy.
virtual bool getProxy(Network net, proxyType& proxy_info) = 0;

//! Check if Tor only connections are allowed by settings.
virtual bool hasTorOnlyConnections() = 0;

//! Get number of connections.
virtual size_t getNodeCount(CConnman::NumConnections flags) = 0;

Expand Down
17 changes: 17 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
QMainWindow(parent),
m_node(node),
m_tor_icon{new GUIUtil::ClickableLabel()},
trayIconMenu{new QMenu()},
platformStyle(_platformStyle),
m_network_style(networkStyle)
Expand Down Expand Up @@ -160,6 +161,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
frameBlocksLayout->addWidget(labelWalletEncryptionIcon);
frameBlocksLayout->addWidget(labelWalletHDStatusIcon);
}
frameBlocksLayout->addWidget(m_tor_icon);
frameBlocksLayout->addWidget(labelProxyIcon);
frameBlocksLayout->addStretch();
frameBlocksLayout->addWidget(connectionsControl);
Expand Down Expand Up @@ -202,6 +204,9 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] {
openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);
});
connect(m_tor_icon, &GUIUtil::ClickableLabel::clicked, [this] {
openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);
});

connect(labelBlocksIcon, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::showModalOverlay);
connect(progressBar, &GUIUtil::ClickableProgressBar::clicked, this, &BitcoinGUI::showModalOverlay);
Expand Down Expand Up @@ -602,6 +607,7 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH

rpcConsole->setClientModel(_clientModel, tip_info->block_height, tip_info->block_time, tip_info->verification_progress);

updateTorIcon();
updateProxyIcon();

#ifdef ENABLE_WALLET
Expand Down Expand Up @@ -1317,6 +1323,17 @@ void BitcoinGUI::updateProxyIcon()
}
}

void BitcoinGUI::updateTorIcon()
{
if (clientModel->hasTorOnlyConnections()) {
m_tor_icon->setPixmap(platformStyle->SingleColorIcon(":/icons/tor_connected").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
m_tor_icon->setToolTip(tr("All connections are <b>via Tor</b> only"));
m_tor_icon->show();
} else {
m_tor_icon->hide();
}
}

void BitcoinGUI::updateWindowTitle()
{
QString window_title = PACKAGE_NAME;
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class BitcoinGUI : public QMainWindow
UnitDisplayStatusBarControl* unitDisplayControl = nullptr;
QLabel* labelWalletEncryptionIcon = nullptr;
QLabel* labelWalletHDStatusIcon = nullptr;
GUIUtil::ClickableLabel* m_tor_icon{nullptr};
GUIUtil::ClickableLabel* labelProxyIcon = nullptr;
GUIUtil::ClickableLabel* connectionsControl = nullptr;
GUIUtil::ClickableLabel* labelBlocksIcon = nullptr;
Expand Down Expand Up @@ -263,6 +264,7 @@ public Q_SLOTS:
private:
/** Set the proxy-enabled icon as shown in the UI. */
void updateProxyIcon();
void updateTorIcon();
void updateWindowTitle();

public Q_SLOTS:
Expand Down
5 changes: 5 additions & 0 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,8 @@ bool ClientModel::getProxyInfo(std::string& ip_port) const
}
return false;
}

bool ClientModel::hasTorOnlyConnections() const
{
return m_node.hasTorOnlyConnections();
}
2 changes: 2 additions & 0 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class ClientModel : public QObject

bool getProxyInfo(std::string& ip_port) const;

bool hasTorOnlyConnections() const;

// caches for the best header: hash, number of blocks and block time
mutable std::atomic<int> cachedBestHeaderHeight;
mutable std::atomic<int64_t> cachedBestHeaderTime;
Expand Down

0 comments on commit 082a680

Please sign in to comment.