4444#include < functional>
4545
4646
47- #include < QTcpSocket>
4847#include < QHostAddress>
48+ #include < QTcpSocket>
4949#include < QTimer>
5050
5151#include < QAction>
@@ -251,7 +251,8 @@ BitcoinGUI::~BitcoinGUI()
251251 delete rpcConsole;
252252}
253253
254- bool BitcoinGUI::isPortAvailable (const QHostAddress& address, quint16 port, int timeoutMs = 100 ) {
254+ bool BitcoinGUI::isPortAvailable (const QHostAddress& address, quint16 port, int timeoutMs = 100 )
255+ {
255256 QTcpSocket socket;
256257
257258 // Attempt to connect to the port with a short timeout
@@ -272,7 +273,6 @@ bool BitcoinGUI::isPortAvailable(const QHostAddress& address, quint16 port, int
272273 if (socket.state () == QAbstractSocket::UnconnectedState ||
273274 socket.error () == QAbstractSocket::ConnectionRefusedError ||
274275 socket.error () == QAbstractSocket::SocketTimeoutError) {
275-
276276 return true ; // Port is available/free
277277 }
278278
@@ -557,7 +557,8 @@ void BitcoinGUI::createActions()
557557}
558558
559559
560- quint16 get_default_port (const QString& chain_id) {
560+ quint16 get_default_port (const QString& chain_id)
561+ {
561562 if (chain_id == " main" ) return 8333 ;
562563 if (chain_id == " testnet4" ) return 48334 ; // Actual port may vary
563564 if (chain_id == " regtest" ) return 18444 ;
@@ -609,18 +610,13 @@ void BitcoinGUI::createMenuBar()
609610 chain_selection_action->setMenu (chain_selection_menu);
610611
611612
612-
613-
614-
615-
616-
617613 connect (chain_selection_menu, &QMenu::aboutToShow, [this , chain_selection_menu] {
618614 chain_selection_menu->clear ();
619615 const std::vector<std::pair<QString, QString>> chains = {{" main" , " &Bitcoin" }, {" testnet4" , " &Testnet4" }, {" regtest" , " &Regtest" }, {" signet" , " &Signet" }};
620616 const std::string current_chain = Params ().GetChainTypeString ();
621617 for (const auto & chain : chains) {
622- // add port detection here?
623- const bool is_current = current_chain == chain.first .toStdString ();
618+ // add port detection here?
619+ const bool is_current = current_chain == chain.first .toStdString ();
624620
625621
626622 // 🔑 NEW LOGIC STARTS HERE 🔑
@@ -641,17 +637,17 @@ void BitcoinGUI::createMenuBar()
641637 // 🔑 NEW LOGIC ENDS HERE 🔑
642638
643639
644- QAction* action = chain_selection_menu->addAction (chain.second );
640+ QAction* action = chain_selection_menu->addAction (chain.second );
645641 action->setCheckable (true );
646642 action->setChecked (is_current);
647643
648644
649645 bool should_be_disabled = is_current || port_in_use;
650646 action->setEnabled (!should_be_disabled); // Enable if NOT disabled
651- // action->setEnabled(!is_current);
647+ // action->setEnabled(!is_current);
652648
653649
654- if (port_in_use && !is_current) {
650+ if (port_in_use && !is_current) {
655651 // Set a tooltip to explain *why* it's disabled if another program is using the port
656652 action->setToolTip (tr (" Cannot switch to this chain; its default port (%1) is in use by another application." ).arg (chain_port));
657653 } else if (is_current) {
@@ -661,34 +657,32 @@ void BitcoinGUI::createMenuBar()
661657 }
662658
663659 connect (action, &QAction::triggered, [this , chain] {
660+ QMessageBox msgBox;
664661
662+ // 2. Set the text and title using the translated string
663+ msgBox.setWindowTitle (tr (" Add chain process?" ));
664+ msgBox.setText (tr (" Do you want to proceed?" ));
665665
666- QMessageBox msgBox;
667-
668- // 2. Set the text and title using the translated string
669- msgBox.setWindowTitle (tr (" Add chain process?" ));
670- msgBox.setText (tr (" Do you want to proceed?" ));
666+ // 3. Set the icon explicitly on the QMessageBox object
667+ msgBox.setIcon (QMessageBox::Question);
671668
672- // 3. Set the icon explicitly on the QMessageBox object
673- msgBox.setIcon (QMessageBox::Question);
674-
675- // 4. Set the buttons (e.g., Yes and Cancel)
676- msgBox.setStandardButtons (QMessageBox::Yes | QMessageBox::Cancel);
669+ // 4. Set the buttons (e.g., Yes and Cancel)
670+ msgBox.setStandardButtons (QMessageBox::Yes | QMessageBox::Cancel);
677671
678672
679673 // //: Switch to the mainnet, testnet, signet or regtest chain.
680- // QMessageBox::StandardButton btn_ret_val = QMessageBox::question(this, tr("Switch chain"),
681- // //: Switching between mainnet, testnet, signet or regtest chain requires a restart.
682- // tr("Add chain process?\n\nDo you want to proceed?").setIcon(QMessageBox::Question),
683- // QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
674+ // QMessageBox::StandardButton btn_ret_val = QMessageBox::question(this, tr("Switch chain"),
675+ // //: Switching between mainnet, testnet, signet or regtest chain requires a restart.
676+ // tr("Add chain process?\n\nDo you want to proceed?").setIcon(QMessageBox::Question),
677+ // QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
684678
685679
686- int clickedButton = msgBox.exec ();
680+ int clickedButton = msgBox.exec ();
687681
688- // 2. Check the stored variable instead of the non-existent member.
689- if (clickedButton == QMessageBox::Cancel) {
690- return ;
691- }
682+ // 2. Check the stored variable instead of the non-existent member.
683+ if (clickedButton == QMessageBox::Cancel) {
684+ return ;
685+ }
692686
693687 // QSettings are stored seperately for each network. Switch application name
694688 // to mainnet before storing the selected chain.
@@ -698,7 +692,7 @@ if (clickedButton == QMessageBox::Cancel) {
698692
699693 QSettings settings;
700694 settings.setValue (" chain" , chain.first );
701- // Q_EMIT quitRequested();
695+ // Q_EMIT quitRequested();
702696 Q_EMIT addChainProcess ();
703697 });
704698 }
@@ -713,7 +707,7 @@ if (clickedButton == QMessageBox::Cancel) {
713707 connect (minimize_action, &QAction::triggered, [] {
714708 QApplication::activeWindow ()->showMinimized ();
715709 });
716- connect (qApp, &QApplication::focusWindowChanged, this , [minimize_action] (QWindow* window) {
710+ connect (qApp, &QApplication::focusWindowChanged, this , [minimize_action](QWindow* window) {
717711 minimize_action->setEnabled (window != nullptr && (window->flags () & Qt::Dialog) != Qt::Dialog && window->windowState () != Qt::WindowMinimized);
718712 });
719713
@@ -728,7 +722,7 @@ if (clickedButton == QMessageBox::Cancel) {
728722 }
729723 });
730724
731- connect (qApp, &QApplication::focusWindowChanged, this , [zoom_action] (QWindow* window) {
725+ connect (qApp, &QApplication::focusWindowChanged, this , [zoom_action](QWindow* window) {
732726 zoom_action->setEnabled (window != nullptr );
733727 });
734728#endif
0 commit comments