Skip to content

Conversation

mess110
Copy link
Contributor

@mess110 mess110 commented May 16, 2018

Clicking on the proxy icon will open settings showing the network tab

#11491 (comment)

@fanquake fanquake added the GUI label May 16, 2018
dlg.exec();
void BitcoinGUI::proxyIconClicked()
{
openOptionsDialogWithTabIndex(2);
Copy link
Contributor

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).

Copy link
Contributor Author

@mess110 mess110 May 28, 2018

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?

Copy link
Contributor

@promag promag May 28, 2018

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);
    }
}

Copy link
Contributor Author

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

@jonasschnelli
Copy link
Contributor

utACK a73098955f119690d270f8d4c872445873c41cc5

@sipa
Copy link
Member

sipa commented May 26, 2018

Concept ACK

@promag
Copy link
Contributor

promag commented May 28, 2018

Concept ACK.

@jonasschnelli
Copy link
Contributor

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);

@promag
Copy link
Contributor

promag commented May 30, 2018

Agree with @jonasschnelli suggestion. nit s/NULL/nullptr above.

@mess110 mess110 force-pushed the make_proxy_icon_clickable branch from 5fc5a53 to e937ff3 Compare May 30, 2018 19:12
@mess110
Copy link
Contributor Author

mess110 commented May 30, 2018

@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).

@@ -250,6 +250,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
subscribeToCoreSignals();

connect(connectionsControl, SIGNAL(clicked(QPoint)), this, SLOT(toggleNetworkActive()));
Copy link
Member

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);

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mess110 mess110 force-pushed the make_proxy_icon_clickable branch from e937ff3 to 0b54e89 Compare July 23, 2018 21:32
@@ -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()));
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

squashed

@mess110 mess110 force-pushed the make_proxy_icon_clickable branch 2 times, most recently from 82e6fc7 to 1081f76 Compare July 23, 2018 22:35
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 1081f76.

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

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 😄

@@ -50,7 +56,7 @@ private Q_SLOTS:
void on_openBitcoinConfButton_clicked();
void on_okButton_clicked();
void on_cancelButton_clicked();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, unnecessary change.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

@mess110 mess110 force-pushed the make_proxy_icon_clickable branch from 1081f76 to 76082cf Compare July 23, 2018 23:20
Copy link
Contributor

@promag promag left a 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;
Copy link
Contributor

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);
}

@@ -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())
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

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
@mess110 mess110 force-pushed the make_proxy_icon_clickable branch from dd4b263 to 6d5fcad Compare July 24, 2018 22:04
@laanwj
Copy link
Member

laanwj commented Aug 20, 2018

works-for-me ACK 6d5fcad

@laanwj laanwj merged commit 6d5fcad into bitcoin:master Aug 20, 2018
laanwj added a commit that referenced this pull request Aug 20, 2018
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
@mess110 mess110 deleted the make_proxy_icon_clickable branch August 21, 2018 21:08
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 25, 2019
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
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Jun 30, 2021
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
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Sep 8, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants