-
Notifications
You must be signed in to change notification settings - Fork 37.7k
[gui] Make proxy icon from statusbar clickable #13248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/qt/bitcoingui.cpp
Outdated
dlg.exec(); | ||
void BitcoinGUI::proxyIconClicked() | ||
{ | ||
openOptionsDialogWithTabIndex(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not sure if setting by the object name would make more sense.
Something like setCurrentWidget(ui->tabNetwork)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would need to get ui->tabNetwork
and ui->tabMain
at BitcoinGUI
level and in my opinion that is not worth it. The main concern is related to magic values or if the tabs change. Magic values are not a real concern because they are "labeled" by the method calling them (ex: proxyIconClicked
). I don't think the order will change. Will it?
I tried something similar to this:
OptionsDialog dlg(this, enableWallet);
- dlg.setCurrentTabIndex(tabIndex);
+ if (tabIndex == 0) {
+ dlg.setTabMain();
+ } else {
+ dlg.setTabNetwork();
+ }
It adds 2 new methods to OptionsDialog
, but still needed to pass tabIndex
because I would need to make a methods which return ui->tabNetwork
and ui->tabMain
.
So I think I prefer the current implementation. Opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could create an enum for tab indexes? So it would be something like
void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab)
// and
void OptionsDialog::setCurrentTab(OptionsDialog::Tab tab)
{
int index = tab;
if (ui->tabWidget->currentIndex() != index) {
ui->tabWidget->setCurrentIndex(index);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the enum
, makes the code more readable, thx
utACK a73098955f119690d270f8d4c872445873c41cc5 |
Concept ACK |
Concept ACK. |
Sorry for nitpicking...and thanks, it's better, but we still have static index positions (that is what I'm trying to avoid) which violates MVC (need to change the code if we change the tab order). After this (see diff), it would be independent: diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp
index 8c9fc0def..5aeb659e3 100644
--- a/src/qt/optionsdialog.cpp
+++ b/src/qt/optionsdialog.cpp
@@ -172,9 +172,11 @@ void OptionsDialog::setModel(OptionsModel *_model)
void OptionsDialog::setCurrentTab(OptionsDialog::Tab tab)
{
- int index = tab;
- if (ui->tabWidget->currentIndex() != index) {
- ui->tabWidget->setCurrentIndex(index);
+ QWidget *tab_widget = NULL;
+ if (tab == OptionsDialog::Tab::TAB_NETWORK) tab_widget = ui->tabNetwork;
+ if (tab == OptionsDialog::Tab::TAB_MAIN) tab_widget = ui->tabMain;
+ if (tab_widget && ui->tabWidget->currentWidget() != tab_widget) {
+ ui->tabWidget->setCurrentWidget(tab_widget);
}
}
diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h
index ca537d92c..99b2fa7a2 100644
--- a/src/qt/optionsdialog.h
+++ b/src/qt/optionsdialog.h
@@ -41,8 +41,8 @@ public:
~OptionsDialog();
enum Tab {
- TAB_MAIN = 0,
- TAB_NETWORK = 2,
+ TAB_MAIN,
+ TAB_NETWORK,
};
void setModel(OptionsModel *model); |
Agree with @jonasschnelli suggestion. nit |
5fc5a53
to
e937ff3
Compare
@jonasschnelli with me at least, don't be sorry for nitpicking. My goal is to write quality code and your suggestion is indeed an improvement. And it helps me learn. Thanks for the suggestion (@promag as well). |
src/qt/bitcoingui.cpp
Outdated
@@ -250,6 +250,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty | |||
subscribeToCoreSignals(); | |||
|
|||
connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind to use the new connect syntax here?
connect(connectionsControl, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::toggleNetworkActive);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must change type of connectionsControl too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either wait for #13529 merge or do like
https://github.com/bitcoin/bitcoin/pull/13529/files#diff-827883cef269471106f7a18fd8199c47R102
e937ff3
to
0b54e89
Compare
src/qt/bitcoingui.cpp
Outdated
@@ -193,7 +193,8 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty | |||
// Subscribe to notifications from core | |||
subscribeToCoreSignals(); | |||
|
|||
connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive())); | |||
connect(connectionsControl, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::toggleNetworkActive); | |||
connect(labelProxyIcon, SIGNAL(clicked(QPoint)), this, SLOT(proxyIconClicked())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use new syntax here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ops, I changed the wrong one and assumed the other ones will be merged in #13529. Fixed now
@MarcoFalke @promag I had to add GUIUtil
namespace in the header file, hope the other PR will merge easily.
Should I squash the commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Should I squash the commits?
I guess you could separate in 2 commits, the 1st add tab, 2nd make it clickable. However 1 commit should be just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
squashed
82e6fc7
to
1081f76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 1081f76.
src/qt/bitcoingui.cpp
Outdated
@@ -193,7 +193,8 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty | |||
// Subscribe to notifications from core | |||
subscribeToCoreSignals(); | |||
|
|||
connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive())); | |||
connect(connectionsControl, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::toggleNetworkActive); | |||
connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::proxyIconClicked); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, I now have a preference for:
connect(labelProxyIcon, &GUIUtil::ClickableLabel::clicked, [this] {
openOptionsDialogWithTab(OptionsDialog::TAB_NETWORK);
});
for these kind of private slots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, now that I know of it, I like it more as well 😄
src/qt/optionsdialog.h
Outdated
@@ -50,7 +56,7 @@ private Q_SLOTS: | |||
void on_openBitcoinConfButton_clicked(); | |||
void on_okButton_clicked(); | |||
void on_cancelButton_clicked(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, unnecessary change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call that unnecessary addition. If I were to make a PR which removes all whitespaces it would most likely be rejected, so instead, when I make a change to a file and I see whitespace on the screen, I remove it.
If its ok, I would like to keep it this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove this change to avoid conflict with #13753.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it, even though intentionally adding whitespaces (the ones I removed) caused a bit of sadness inside. Even if it was for a good cause.
There was another instance, I removed that as well.
At the end of the day, all trailing whitespaces will be removed which gives me a warm fuzzy feeling.
Thx for the reviews btw
1081f76
to
76082cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 76082cf.
@@ -170,6 +170,16 @@ void OptionsDialog::setModel(OptionsModel *_model) | |||
connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning())); | |||
} | |||
|
|||
void OptionsDialog::setCurrentTab(OptionsDialog::Tab tab) | |||
{ | |||
QWidget *tab_widget = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
if (tab == OptionsDialog::Tab::TAB_NETWORK) {
ui->tabWidget->setCurrentWidget(ui->tabNetwork);
} else {
ui->tabWidget->setCurrentWidget(ui->tabMain);
}
src/qt/bitcoingui.cpp
Outdated
@@ -764,6 +764,17 @@ void BitcoinGUI::updateHeadersSyncProgressLabel() | |||
progressBarLabel->setText(tr("Syncing Headers (%1%)...").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1))); | |||
} | |||
|
|||
void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab) | |||
{ | |||
if(!clientModel || !clientModel->getOptionsModel()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, add space after if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
76082cf
to
dd4b263
Compare
Clicking on the proxy icon will open settings showing the network tab Create enum Tab in OptionsModel Use new connect syntax Use lambda for private slots
dd4b263
to
6d5fcad
Compare
works-for-me ACK 6d5fcad |
6d5fcad [gui] Make proxy icon from statusbar clickable (Cristian Mircea Messel) Pull request description: Clicking on the proxy icon will open settings showing the network tab #11491 (comment) Tree-SHA512: c3549749296918818694a371326d1a3b1075478918aaee940b5c7119a7e2cb991dcfda78f20d44d6d001157b9b82951f0d5157b17f4f0d1a0a242795efade036
Summary: 6d5fcad576962e5950641f7e7b113a6ac6f397e5 [gui] Make proxy icon from statusbar clickable (Cristian Mircea Messel) Pull request description: Clicking on the proxy icon will open settings showing the network tab bitcoin/bitcoin#11491 (comment) Tree-SHA512: c3549749296918818694a371326d1a3b1075478918aaee940b5c7119a7e2cb991dcfda78f20d44d6d001157b9b82951f0d5157b17f4f0d1a0a242795efade036 Backport of Core PR13248 bitcoin/bitcoin#13248 Depends on D4269 Test Plan: make check ./bitcoin-qt -proxy=<valid proxy> Clicking the `P` icon in the bottom right corner should open up the `network` tab in the `options` menu. Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D4270
6d5fcad [gui] Make proxy icon from statusbar clickable (Cristian Mircea Messel) Pull request description: Clicking on the proxy icon will open settings showing the network tab bitcoin#11491 (comment) Tree-SHA512: c3549749296918818694a371326d1a3b1075478918aaee940b5c7119a7e2cb991dcfda78f20d44d6d001157b9b82951f0d5157b17f4f0d1a0a242795efade036 # Conflicts: # src/qt/bitcoingui.cpp # src/qt/bitcoingui.h
6d5fcad [gui] Make proxy icon from statusbar clickable (Cristian Mircea Messel) Pull request description: Clicking on the proxy icon will open settings showing the network tab bitcoin#11491 (comment) Tree-SHA512: c3549749296918818694a371326d1a3b1075478918aaee940b5c7119a7e2cb991dcfda78f20d44d6d001157b9b82951f0d5157b17f4f0d1a0a242795efade036
Clicking on the proxy icon will open settings showing the network tab
#11491 (comment)