2022-12-24 23:49:50 +00:00
// Copyright (c) 2011-2022 The Bitcoin Core developers
2014-12-13 12:09:33 +08:00
// Distributed under the MIT software license, see the accompanying
2013-11-04 16:20:43 +01:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2013-05-27 19:55:01 -04:00
# if defined(HAVE_CONFIG_H)
2017-11-10 13:57:53 +13:00
# include <config/bitcoin-config.h>
2013-05-27 19:55:01 -04:00
# endif
2017-11-10 13:57:53 +13:00
# include <qt/optionsdialog.h>
2017-08-15 17:31:26 +02:00
# include <qt/forms/ui_optionsdialog.h>
2012-06-08 15:21:55 +02:00
2017-11-10 13:57:53 +13:00
# include <qt/bitcoinunits.h>
2022-06-12 11:59:50 -03:00
# include <qt/clientmodel.h>
2019-01-14 13:40:00 +02:00
# include <qt/guiconstants.h>
2017-11-10 13:57:53 +13:00
# include <qt/guiutil.h>
# include <qt/optionsmodel.h>
2011-05-12 14:44:52 +02:00
2023-05-08 11:32:13 +02:00
# include <common/system.h>
2018-04-07 03:42:02 -04:00
# include <interfaces/node.h>
2023-07-07 10:43:24 +01:00
# include <node/chainstatemanager_args.h>
2017-11-10 13:57:53 +13:00
# include <netbase.h>
2023-05-08 11:32:13 +02:00
# include <txdb.h>
2014-09-05 13:18:35 +02:00
2022-01-06 18:35:53 +02:00
# include <chrono>
2021-12-02 23:40:15 +00:00
# include <QApplication>
2014-10-23 19:08:10 +02:00
# include <QDataWidgetMapper>
2012-06-08 15:21:55 +02:00
# include <QDir>
2021-12-02 23:40:15 +00:00
# include <QFontDialog>
2012-06-08 15:21:55 +02:00
# include <QIntValidator>
2012-06-25 22:36:16 +02:00
# include <QLocale>
2012-05-08 23:03:41 +02:00
# include <QMessageBox>
2018-09-15 18:02:14 +03:00
# include <QSystemTrayIcon>
2013-12-03 09:10:10 +01:00
# include <QTimer>
2011-06-01 14:40:06 +02:00
2021-12-02 23:40:15 +00:00
int setFontChoice ( QComboBox * cb , const OptionsModel : : FontChoice & fc )
{
int i ;
for ( i = cb - > count ( ) ; - - i > = 0 ; ) {
QVariant item_data = cb - > itemData ( i ) ;
if ( ! item_data . canConvert < OptionsModel : : FontChoice > ( ) ) continue ;
if ( item_data . value < OptionsModel : : FontChoice > ( ) = = fc ) {
break ;
}
}
if ( i = = - 1 ) {
// New item needed
QFont chosen_font = OptionsModel : : getFontForChoice ( fc ) ;
QSignalBlocker block_currentindexchanged_signal ( cb ) ; // avoid triggering QFontDialog
cb - > insertItem ( 0 , QFontInfo ( chosen_font ) . family ( ) , QVariant : : fromValue ( fc ) ) ;
i = 0 ;
}
cb - > setCurrentIndex ( i ) ;
return i ;
}
void setupFontOptions ( QComboBox * cb , QLabel * preview )
{
QFont embedded_font { GUIUtil : : fixedPitchFont ( true ) } ;
QFont system_font { GUIUtil : : fixedPitchFont ( false ) } ;
cb - > addItem ( QObject : : tr ( " Embedded \" %1 \" " ) . arg ( QFontInfo ( embedded_font ) . family ( ) ) , QVariant : : fromValue ( OptionsModel : : FontChoice { OptionsModel : : FontChoiceAbstract : : EmbeddedFont } ) ) ;
cb - > addItem ( QObject : : tr ( " Default system font \" %1 \" " ) . arg ( QFontInfo ( system_font ) . family ( ) ) , QVariant : : fromValue ( OptionsModel : : FontChoice { OptionsModel : : FontChoiceAbstract : : BestSystemFont } ) ) ;
cb - > addItem ( QObject : : tr ( " Custom… " ) ) ;
const auto & on_font_choice_changed = [ cb , preview ] ( int index ) {
static int previous_index = - 1 ;
QVariant item_data = cb - > itemData ( index ) ;
QFont f ;
if ( item_data . canConvert < OptionsModel : : FontChoice > ( ) ) {
f = OptionsModel : : getFontForChoice ( item_data . value < OptionsModel : : FontChoice > ( ) ) ;
} else {
bool ok ;
f = QFontDialog : : getFont ( & ok , GUIUtil : : fixedPitchFont ( false ) , cb - > parentWidget ( ) ) ;
if ( ! ok ) {
cb - > setCurrentIndex ( previous_index ) ;
return ;
}
index = setFontChoice ( cb , OptionsModel : : FontChoice { f } ) ;
}
if ( preview ) {
preview - > setFont ( f ) ;
}
previous_index = index ;
} ;
QObject : : connect ( cb , QOverload < int > : : of ( & QComboBox : : currentIndexChanged ) , on_font_choice_changed ) ;
on_font_choice_changed ( cb - > currentIndex ( ) ) ;
}
2022-12-16 11:58:38 +00:00
OptionsDialog : : OptionsDialog ( QWidget * parent , bool enableWallet )
: QDialog ( parent , GUIUtil : : dialog_flags ) ,
ui ( new Ui : : OptionsDialog )
2012-05-07 21:49:22 +02:00
{
2012-06-08 15:21:55 +02:00
ui - > setupUi ( this ) ;
2013-12-03 09:10:10 +01:00
/* Main elements init */
2014-02-16 22:00:12 +01:00
ui - > databaseCache - > setMinimum ( nMinDbCache ) ;
ui - > databaseCache - > setMaximum ( nMaxDbCache ) ;
2015-07-01 17:38:15 +02:00
ui - > threadsScriptVerif - > setMinimum ( - GetNumCores ( ) ) ;
2014-02-18 12:48:16 +01:00
ui - > threadsScriptVerif - > setMaximum ( MAX_SCRIPTCHECK_THREADS ) ;
2018-05-15 12:46:19 +02:00
ui - > pruneWarning - > setVisible ( false ) ;
ui - > pruneWarning - > setStyleSheet ( " QLabel { color: red; } " ) ;
ui - > pruneSize - > setEnabled ( false ) ;
2018-06-24 16:18:22 +01:00
connect ( ui - > prune , & QPushButton : : toggled , ui - > pruneSize , & QWidget : : setEnabled ) ;
2012-05-07 21:49:22 +02:00
2012-06-08 15:21:55 +02:00
/* Network elements init */
# ifndef USE_UPNP
ui - > mapPortUpnp - > setEnabled ( false ) ;
2020-02-23 02:25:21 +02:00
# endif
# ifndef USE_NATPMP
ui - > mapPortNatpmp - > setEnabled ( false ) ;
2011-10-07 13:21:45 +02:00
# endif
2011-07-25 21:35:45 +02:00
2012-07-09 11:14:38 +02:00
ui - > proxyIp - > setEnabled ( false ) ;
ui - > proxyPort - > setEnabled ( false ) ;
ui - > proxyPort - > setValidator ( new QIntValidator ( 1 , 65535 , this ) ) ;
2014-07-25 18:20:40 +02:00
ui - > proxyIpTor - > setEnabled ( false ) ;
ui - > proxyPortTor - > setEnabled ( false ) ;
ui - > proxyPortTor - > setValidator ( new QIntValidator ( 1 , 65535 , this ) ) ;
2018-06-24 16:18:22 +01:00
connect ( ui - > connectSocks , & QPushButton : : toggled , ui - > proxyIp , & QWidget : : setEnabled ) ;
connect ( ui - > connectSocks , & QPushButton : : toggled , ui - > proxyPort , & QWidget : : setEnabled ) ;
connect ( ui - > connectSocks , & QPushButton : : toggled , this , & OptionsDialog : : updateProxyValidationState ) ;
2011-05-12 14:44:52 +02:00
2018-06-24 16:18:22 +01:00
connect ( ui - > connectSocksTor , & QPushButton : : toggled , ui - > proxyIpTor , & QWidget : : setEnabled ) ;
connect ( ui - > connectSocksTor , & QPushButton : : toggled , ui - > proxyPortTor , & QWidget : : setEnabled ) ;
connect ( ui - > connectSocksTor , & QPushButton : : toggled , this , & OptionsDialog : : updateProxyValidationState ) ;
2011-05-12 14:44:52 +02:00
2012-06-08 15:21:55 +02:00
/* Window elements init */
2022-04-26 01:13:29 +01:00
# ifdef Q_OS_MACOS
2013-05-03 15:18:28 +02:00
/* remove Window tab on Mac */
ui - > tabWidget - > removeTab ( ui - > tabWidget - > indexOf ( ui - > tabWindow ) ) ;
2019-11-22 18:12:00 -05:00
/* hide launch at startup option on macOS */
2019-01-18 21:47:01 -10:00
ui - > bitcoinAtStartup - > setVisible ( false ) ;
ui - > verticalLayout_Main - > removeWidget ( ui - > bitcoinAtStartup ) ;
ui - > verticalLayout_Main - > removeItem ( ui - > horizontalSpacer_0_Main ) ;
2012-05-10 15:33:01 +02:00
# endif
2011-07-25 21:35:45 +02:00
2019-12-09 10:57:39 +01:00
/* remove Wallet tab and 3rd party-URL textbox in case of -disablewallet */
2014-11-08 13:48:35 -05:00
if ( ! enableWallet ) {
ui - > tabWidget - > removeTab ( ui - > tabWidget - > indexOf ( ui - > tabWallet ) ) ;
2019-12-09 10:57:39 +01:00
ui - > thirdPartyTxUrlsLabel - > setVisible ( false ) ;
ui - > thirdPartyTxUrls - > setVisible ( false ) ;
2014-11-08 13:48:35 -05:00
}
2022-09-20 15:26:35 +01:00
# ifdef ENABLE_EXTERNAL_SIGNER
ui - > externalSignerPath - > setToolTip ( ui - > externalSignerPath - > toolTip ( ) . arg ( PACKAGE_NAME ) ) ;
# else
2021-06-15 19:11:09 +02:00
//: "External signing" means using devices such as hardware wallets.
ui - > externalSignerPath - > setToolTip ( tr ( " Compiled without external signing support (required for external signing) " ) ) ;
ui - > externalSignerPath - > setEnabled ( false ) ;
# endif
2012-06-08 15:21:55 +02:00
/* Display elements init */
QDir translations ( " :translations " ) ;
2015-12-09 10:53:12 +00:00
2019-06-26 10:28:13 -04:00
ui - > bitcoinAtStartup - > setToolTip ( ui - > bitcoinAtStartup - > toolTip ( ) . arg ( PACKAGE_NAME ) ) ;
ui - > bitcoinAtStartup - > setText ( ui - > bitcoinAtStartup - > text ( ) . arg ( PACKAGE_NAME ) ) ;
2015-12-09 10:53:12 +00:00
2019-06-26 10:28:13 -04:00
ui - > openBitcoinConfButton - > setToolTip ( ui - > openBitcoinConfButton - > toolTip ( ) . arg ( PACKAGE_NAME ) ) ;
2017-08-30 19:14:07 +01:00
2019-06-26 10:28:13 -04:00
ui - > lang - > setToolTip ( ui - > lang - > toolTip ( ) . arg ( PACKAGE_NAME ) ) ;
2012-06-08 15:21:55 +02:00
ui - > lang - > addItem ( QString ( " ( " ) + tr ( " default " ) + QString ( " ) " ) , QVariant ( " " ) ) ;
2017-06-02 03:25:02 +02:00
for ( const QString & langStr : translations . entryList ( ) )
2012-05-07 21:49:22 +02:00
{
2012-06-25 22:36:16 +02:00
QLocale locale ( langStr ) ;
/** check if the locale name consists of 2 parts (language_country) */
if ( langStr . contains ( " _ " ) )
{
2012-07-13 07:43:41 +02:00
/** display language strings as "native language - native country (locale name)", e.g. "Deutsch - Deutschland (de)" */
ui - > lang - > addItem ( locale . nativeLanguageName ( ) + QString ( " - " ) + locale . nativeCountryName ( ) + QString ( " ( " ) + langStr + QString ( " ) " ) , QVariant ( langStr ) ) ;
2012-06-25 22:36:16 +02:00
}
else
{
2012-07-13 07:43:41 +02:00
/** display language strings as "native language (locale name)", e.g. "Deutsch (de)" */
ui - > lang - > addItem ( locale . nativeLanguageName ( ) + QString ( " ( " ) + langStr + QString ( " ) " ) , QVariant ( langStr ) ) ;
2012-06-25 22:36:16 +02:00
}
2012-05-07 21:49:22 +02:00
}
2012-06-08 15:21:55 +02:00
ui - > unit - > setModel ( new BitcoinUnits ( this ) ) ;
2011-05-12 14:44:52 +02:00
2011-06-01 09:33:48 +02:00
/* Widget-to-option mapper */
2014-10-23 19:08:10 +02:00
mapper = new QDataWidgetMapper ( this ) ;
2011-05-31 22:24:53 +02:00
mapper - > setSubmitPolicy ( QDataWidgetMapper : : ManualSubmit ) ;
mapper - > setOrientation ( Qt : : Vertical ) ;
2012-06-08 15:21:55 +02:00
2018-07-30 22:47:48 +01:00
GUIUtil : : ItemDelegate * delegate = new GUIUtil : : ItemDelegate ( mapper ) ;
connect ( delegate , & GUIUtil : : ItemDelegate : : keyEscapePressed , this , & OptionsDialog : : reject ) ;
mapper - > setItemDelegate ( delegate ) ;
2014-07-25 18:20:40 +02:00
/* setup/change UI elements when proxy IPs are invalid/valid */
2015-11-16 10:43:36 +01:00
ui - > proxyIp - > setCheckValidator ( new ProxyAddressValidator ( parent ) ) ;
ui - > proxyIpTor - > setCheckValidator ( new ProxyAddressValidator ( parent ) ) ;
2018-06-24 16:18:22 +01:00
connect ( ui - > proxyIp , & QValidatedLineEdit : : validationDidChange , this , & OptionsDialog : : updateProxyValidationState ) ;
connect ( ui - > proxyIpTor , & QValidatedLineEdit : : validationDidChange , this , & OptionsDialog : : updateProxyValidationState ) ;
connect ( ui - > proxyPort , & QLineEdit : : textChanged , this , & OptionsDialog : : updateProxyValidationState ) ;
connect ( ui - > proxyPortTor , & QLineEdit : : textChanged , this , & OptionsDialog : : updateProxyValidationState ) ;
2018-09-15 18:02:14 +03:00
if ( ! QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
2020-10-25 00:34:41 +03:00
ui - > showTrayIcon - > setChecked ( false ) ;
ui - > showTrayIcon - > setEnabled ( false ) ;
2018-09-15 18:02:14 +03:00
ui - > minimizeToTray - > setChecked ( false ) ;
ui - > minimizeToTray - > setEnabled ( false ) ;
}
2019-04-07 21:33:35 +02:00
2021-12-02 23:40:15 +00:00
setupFontOptions ( ui - > moneyFont , ui - > moneyFont_preview ) ;
2021-02-21 20:58:19 +02:00
2019-04-07 21:33:35 +02:00
GUIUtil : : handleCloseWindowShortcut ( this ) ;
2012-06-08 15:21:55 +02:00
}
OptionsDialog : : ~ OptionsDialog ( )
{
delete ui ;
2011-05-31 22:24:53 +02:00
}
2022-06-12 11:59:50 -03:00
void OptionsDialog : : setClientModel ( ClientModel * client_model )
{
m_client_model = client_model ;
}
2016-09-09 13:43:29 +02:00
void OptionsDialog : : setModel ( OptionsModel * _model )
2011-05-31 22:24:53 +02:00
{
2016-09-09 13:43:29 +02:00
this - > model = _model ;
2011-05-31 22:24:53 +02:00
2016-09-09 13:43:29 +02:00
if ( _model )
2012-05-07 21:49:22 +02:00
{
2013-12-03 09:10:10 +01:00
/* check if client restart is needed and show persistent message */
2016-09-09 13:43:29 +02:00
if ( _model - > isRestartRequired ( ) )
2013-12-03 09:10:10 +01:00
showRestartWarning ( true ) ;
2019-04-11 23:39:59 +00:00
// Prune values are in GB to be consistent with intro.cpp
static constexpr uint64_t nMinDiskSpace = ( MIN_DISK_SPACE_FOR_BLOCK_FILES / GB_BYTES ) + ( MIN_DISK_SPACE_FOR_BLOCK_FILES % GB_BYTES ) ? 1 : 0 ;
2019-04-11 23:44:48 +00:00
ui - > pruneSize - > setRange ( nMinDiskSpace , std : : numeric_limits < int > : : max ( ) ) ;
2019-04-11 23:39:59 +00:00
2016-09-09 13:43:29 +02:00
QString strLabel = _model - > getOverriddenByCommandLine ( ) ;
2013-12-03 09:10:10 +01:00
if ( strLabel . isEmpty ( ) )
strLabel = tr ( " none " ) ;
ui - > overriddenByCommandLineLabel - > setText ( strLabel ) ;
2016-09-09 13:43:29 +02:00
mapper - > setModel ( _model ) ;
2012-06-08 15:21:55 +02:00
setMapper ( ) ;
mapper - > toFirst ( ) ;
2014-07-25 18:20:40 +02:00
2021-12-02 16:59:46 +00:00
const auto & font_for_money = _model - > data ( _model - > index ( OptionsModel : : FontForMoney , 0 ) , Qt : : EditRole ) . value < OptionsModel : : FontChoice > ( ) ;
2021-12-02 23:40:15 +00:00
setFontChoice ( ui - > moneyFont , font_for_money ) ;
2021-12-02 16:59:46 +00:00
2014-07-25 18:20:40 +02:00
updateDefaultProxyNets ( ) ;
2012-05-07 21:49:22 +02:00
}
2011-05-12 14:44:52 +02:00
2013-12-03 09:10:10 +01:00
/* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */
2012-08-02 09:02:05 +02:00
2013-12-03 09:10:10 +01:00
/* Main */
2018-06-24 16:18:22 +01:00
connect ( ui - > prune , & QCheckBox : : clicked , this , & OptionsDialog : : showRestartWarning ) ;
connect ( ui - > prune , & QCheckBox : : clicked , this , & OptionsDialog : : togglePruneWarning ) ;
2021-03-24 05:37:56 +02:00
connect ( ui - > pruneSize , qOverload < int > ( & QSpinBox : : valueChanged ) , this , & OptionsDialog : : showRestartWarning ) ;
connect ( ui - > databaseCache , qOverload < int > ( & QSpinBox : : valueChanged ) , this , & OptionsDialog : : showRestartWarning ) ;
2019-09-16 18:51:24 +02:00
connect ( ui - > externalSignerPath , & QLineEdit : : textChanged , [ this ] { showRestartWarning ( ) ; } ) ;
2021-03-24 05:37:56 +02:00
connect ( ui - > threadsScriptVerif , qOverload < int > ( & QSpinBox : : valueChanged ) , this , & OptionsDialog : : showRestartWarning ) ;
2014-04-07 19:26:30 +02:00
/* Wallet */
2018-06-24 16:18:22 +01:00
connect ( ui - > spendZeroConfChange , & QCheckBox : : clicked , this , & OptionsDialog : : showRestartWarning ) ;
2013-12-03 09:10:10 +01:00
/* Network */
2018-06-24 16:18:22 +01:00
connect ( ui - > allowIncoming , & QCheckBox : : clicked , this , & OptionsDialog : : showRestartWarning ) ;
2021-09-02 14:27:41 +02:00
connect ( ui - > enableServer , & QCheckBox : : clicked , this , & OptionsDialog : : showRestartWarning ) ;
2018-06-24 16:18:22 +01:00
connect ( ui - > connectSocks , & QCheckBox : : clicked , this , & OptionsDialog : : showRestartWarning ) ;
connect ( ui - > connectSocksTor , & QCheckBox : : clicked , this , & OptionsDialog : : showRestartWarning ) ;
2013-12-03 09:10:10 +01:00
/* Display */
2021-03-24 05:37:56 +02:00
connect ( ui - > lang , qOverload < > ( & QValueComboBox : : valueChanged ) , [ this ] { showRestartWarning ( ) ; } ) ;
2018-06-24 16:18:22 +01:00
connect ( ui - > thirdPartyTxUrls , & QLineEdit : : textChanged , [ this ] { showRestartWarning ( ) ; } ) ;
2011-05-12 14:44:52 +02:00
}
2018-05-16 23:05:09 +03:00
void OptionsDialog : : setCurrentTab ( OptionsDialog : : Tab tab )
{
QWidget * tab_widget = nullptr ;
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 ) ;
}
}
2012-06-08 15:21:55 +02:00
void OptionsDialog : : setMapper ( )
2011-05-12 14:44:52 +02:00
{
2012-06-08 15:21:55 +02:00
/* Main */
mapper - > addMapping ( ui - > bitcoinAtStartup , OptionsModel : : StartAtStartup ) ;
2013-12-03 09:10:10 +01:00
mapper - > addMapping ( ui - > threadsScriptVerif , OptionsModel : : ThreadsScriptVerif ) ;
mapper - > addMapping ( ui - > databaseCache , OptionsModel : : DatabaseCache ) ;
2018-05-15 12:46:19 +02:00
mapper - > addMapping ( ui - > prune , OptionsModel : : Prune ) ;
mapper - > addMapping ( ui - > pruneSize , OptionsModel : : PruneSize ) ;
2011-06-01 09:33:48 +02:00
2014-02-15 10:38:06 +01:00
/* Wallet */
mapper - > addMapping ( ui - > spendZeroConfChange , OptionsModel : : SpendZeroConfChange ) ;
2014-03-17 14:04:56 +01:00
mapper - > addMapping ( ui - > coinControlFeatures , OptionsModel : : CoinControlFeatures ) ;
2021-07-29 21:57:57 +05:30
mapper - > addMapping ( ui - > subFeeFromAmount , OptionsModel : : SubFeeFromAmount ) ;
2019-09-16 18:51:24 +02:00
mapper - > addMapping ( ui - > externalSignerPath , OptionsModel : : ExternalSignerPath ) ;
2020-04-28 15:29:12 -04:00
mapper - > addMapping ( ui - > m_enable_psbt_controls , OptionsModel : : EnablePSBTControls ) ;
2014-02-15 10:38:06 +01:00
2012-06-08 15:21:55 +02:00
/* Network */
mapper - > addMapping ( ui - > mapPortUpnp , OptionsModel : : MapPortUPnP ) ;
2020-02-23 02:25:21 +02:00
mapper - > addMapping ( ui - > mapPortNatpmp , OptionsModel : : MapPortNatpmp ) ;
2014-05-29 13:02:22 +02:00
mapper - > addMapping ( ui - > allowIncoming , OptionsModel : : Listen ) ;
2021-09-02 14:27:41 +02:00
mapper - > addMapping ( ui - > enableServer , OptionsModel : : Server ) ;
2012-07-09 11:14:38 +02:00
2012-06-08 15:21:55 +02:00
mapper - > addMapping ( ui - > connectSocks , OptionsModel : : ProxyUse ) ;
mapper - > addMapping ( ui - > proxyIp , OptionsModel : : ProxyIP ) ;
mapper - > addMapping ( ui - > proxyPort , OptionsModel : : ProxyPort ) ;
2011-06-01 09:33:48 +02:00
2014-07-25 18:20:40 +02:00
mapper - > addMapping ( ui - > connectSocksTor , OptionsModel : : ProxyUseTor ) ;
mapper - > addMapping ( ui - > proxyIpTor , OptionsModel : : ProxyIPTor ) ;
mapper - > addMapping ( ui - > proxyPortTor , OptionsModel : : ProxyPortTor ) ;
2012-06-08 15:21:55 +02:00
/* Window */
2022-04-26 01:13:29 +01:00
# ifndef Q_OS_MACOS
2018-09-15 18:02:14 +03:00
if ( QSystemTrayIcon : : isSystemTrayAvailable ( ) ) {
2020-10-25 00:34:41 +03:00
mapper - > addMapping ( ui - > showTrayIcon , OptionsModel : : ShowTrayIcon ) ;
2018-09-15 18:02:14 +03:00
mapper - > addMapping ( ui - > minimizeToTray , OptionsModel : : MinimizeToTray ) ;
}
2012-06-08 15:21:55 +02:00
mapper - > addMapping ( ui - > minimizeOnClose , OptionsModel : : MinimizeOnClose ) ;
# endif
2011-06-01 09:33:48 +02:00
2012-06-08 15:21:55 +02:00
/* Display */
mapper - > addMapping ( ui - > lang , OptionsModel : : Language ) ;
mapper - > addMapping ( ui - > unit , OptionsModel : : DisplayUnit ) ;
2014-04-24 22:21:45 +02:00
mapper - > addMapping ( ui - > thirdPartyTxUrls , OptionsModel : : ThirdPartyTxUrls ) ;
2011-06-01 09:33:48 +02:00
}
2013-12-03 09:10:10 +01:00
void OptionsDialog : : setOkButtonState ( bool fState )
2012-05-07 21:49:22 +02:00
{
2012-06-08 15:21:55 +02:00
ui - > okButton - > setEnabled ( fState ) ;
2012-05-07 21:49:22 +02:00
}
2012-08-18 15:54:39 +02:00
void OptionsDialog : : on_resetButton_clicked ( )
{
2022-06-12 11:59:50 -03:00
if ( model ) {
2012-08-18 15:54:39 +02:00
// confirmation dialog
2022-06-29 20:02:02 -04:00
/*: Text explaining that the settings changed will not come into effect
until the client is restarted . */
QString reset_dialog_text = tr ( " Client restart required to activate changes. " ) + " <br><br> " ;
/*: Text explaining to the user that the client's current settings
will be backed up at a specific location . % 1 is a stand - in
argument for the backup location ' s path . */
reset_dialog_text . append ( tr ( " Current settings will be backed up at \" %1 \" . " ) . arg ( m_client_model - > dataDir ( ) ) + " <br><br> " ) ;
/*: Text asking the user to confirm if they would like to proceed
with a client shutdown . */
reset_dialog_text . append ( tr ( " Client will be shut down. Do you want to proceed? " ) ) ;
//: Window title text of pop-up window shown when the user has chosen to reset options.
2012-08-18 15:54:39 +02:00
QMessageBox : : StandardButton btnRetVal = QMessageBox : : question ( this , tr ( " Confirm options reset " ) ,
2022-06-29 20:02:02 -04:00
reset_dialog_text , QMessageBox : : Yes | QMessageBox : : Cancel , QMessageBox : : Cancel ) ;
2012-08-18 15:54:39 +02:00
2022-06-12 11:59:50 -03:00
if ( btnRetVal = = QMessageBox : : Cancel )
2012-08-18 15:54:39 +02:00
return ;
2013-12-20 18:47:49 +01:00
/* reset all options and close GUI */
2012-08-18 15:54:39 +02:00
model - > Reset ( ) ;
2021-06-07 18:45:04 +03:00
close ( ) ;
Q_EMIT quitOnReset ( ) ;
2012-08-18 15:54:39 +02:00
}
}
2017-02-28 12:13:34 -05:00
void OptionsDialog : : on_openBitcoinConfButton_clicked ( )
{
2021-07-21 22:12:25 +05:30
QMessageBox config_msgbox ( this ) ;
config_msgbox . setIcon ( QMessageBox : : Information ) ;
//: Window title text of pop-up box that allows opening up of configuration file.
config_msgbox . setWindowTitle ( tr ( " Configuration options " ) ) ;
/*: Explanatory text about the priority order of instructions considered by client.
The order from high to low being : command - line , configuration file , GUI settings . */
config_msgbox . setText ( tr ( " The configuration file is used to specify advanced user options which override GUI settings. "
" Additionally, any command-line options will override this configuration file. " ) ) ;
QPushButton * open_button = config_msgbox . addButton ( tr ( " Continue " ) , QMessageBox : : ActionRole ) ;
config_msgbox . addButton ( tr ( " Cancel " ) , QMessageBox : : RejectRole ) ;
open_button - > setDefault ( true ) ;
config_msgbox . exec ( ) ;
if ( config_msgbox . clickedButton ( ) ! = open_button ) return ;
2017-02-28 12:13:34 -05:00
/* show an error if there was some problem opening the file */
if ( ! GUIUtil : : openBitcoinConf ( ) )
QMessageBox : : critical ( this , tr ( " Error " ) , tr ( " The configuration file could not be opened. " ) ) ;
}
2012-06-08 15:21:55 +02:00
void OptionsDialog : : on_okButton_clicked ( )
2012-05-07 21:49:22 +02:00
{
2021-12-02 23:40:15 +00:00
model - > setData ( model - > index ( OptionsModel : : FontForMoney , 0 ) , ui - > moneyFont - > itemData ( ui - > moneyFont - > currentIndex ( ) ) ) ;
2021-12-02 16:59:46 +00:00
2012-06-08 15:21:55 +02:00
mapper - > submit ( ) ;
accept ( ) ;
2014-07-25 18:20:40 +02:00
updateDefaultProxyNets ( ) ;
2012-05-07 21:49:22 +02:00
}
2012-06-08 15:21:55 +02:00
void OptionsDialog : : on_cancelButton_clicked ( )
2011-06-01 14:40:06 +02:00
{
2012-06-08 15:21:55 +02:00
reject ( ) ;
2012-05-07 21:49:22 +02:00
}
2020-10-25 00:34:41 +03:00
void OptionsDialog : : on_showTrayIcon_stateChanged ( int state )
2016-05-11 22:28:02 -04:00
{
2020-10-25 00:34:41 +03:00
if ( state = = Qt : : Checked ) {
ui - > minimizeToTray - > setEnabled ( true ) ;
} else {
2016-05-11 22:28:02 -04:00
ui - > minimizeToTray - > setChecked ( false ) ;
ui - > minimizeToTray - > setEnabled ( false ) ;
}
}
2018-05-15 12:46:19 +02:00
void OptionsDialog : : togglePruneWarning ( bool enabled )
{
ui - > pruneWarning - > setVisible ( ! ui - > pruneWarning - > isVisible ( ) ) ;
}
2013-12-03 09:10:10 +01:00
void OptionsDialog : : showRestartWarning ( bool fPersistent )
2012-05-07 21:49:22 +02:00
{
2013-12-03 09:10:10 +01:00
ui - > statusLabel - > setStyleSheet ( " QLabel { color: red; } " ) ;
2012-05-07 21:49:22 +02:00
2013-12-03 09:10:10 +01:00
if ( fPersistent )
{
ui - > statusLabel - > setText ( tr ( " Client restart required to activate changes. " ) ) ;
}
else
2012-05-08 23:03:41 +02:00
{
2013-12-03 09:10:10 +01:00
ui - > statusLabel - > setText ( tr ( " This change would require a client restart. " ) ) ;
// clear non-persistent status label after 10 seconds
// Todo: should perhaps be a class attribute, if we extend the use of statusLabel
2022-01-06 18:35:53 +02:00
QTimer : : singleShot ( 10 s , this , & OptionsDialog : : clearStatusLabel ) ;
2012-05-08 23:03:41 +02:00
}
}
2013-12-03 09:10:10 +01:00
void OptionsDialog : : clearStatusLabel ( )
2012-05-07 21:49:22 +02:00
{
2013-12-03 09:10:10 +01:00
ui - > statusLabel - > clear ( ) ;
2017-02-13 22:49:10 +00:00
if ( model & & model - > isRestartRequired ( ) ) {
showRestartWarning ( true ) ;
}
2012-05-07 21:49:22 +02:00
}
2015-11-18 14:02:14 +01:00
void OptionsDialog : : updateProxyValidationState ( )
2012-07-09 11:14:38 +02:00
{
2015-11-18 14:02:14 +01:00
QValidatedLineEdit * pUiProxyIp = ui - > proxyIp ;
2015-11-16 10:43:36 +01:00
QValidatedLineEdit * otherProxyWidget = ( pUiProxyIp = = ui - > proxyIpTor ) ? ui - > proxyIp : ui - > proxyIpTor ;
2015-11-18 14:02:14 +01:00
if ( pUiProxyIp - > isValid ( ) & & ( ! ui - > proxyPort - > isEnabled ( ) | | ui - > proxyPort - > text ( ) . toInt ( ) > 0 ) & & ( ! ui - > proxyPortTor - > isEnabled ( ) | | ui - > proxyPortTor - > text ( ) . toInt ( ) > 0 ) )
2012-07-09 11:14:38 +02:00
{
2015-11-16 10:43:36 +01:00
setOkButtonState ( otherProxyWidget - > isValid ( ) ) ; //only enable ok button if both proxys are valid
2017-02-13 22:49:10 +00:00
clearStatusLabel ( ) ;
2012-07-09 11:14:38 +02:00
}
else
{
2015-11-16 10:43:36 +01:00
setOkButtonState ( false ) ;
ui - > statusLabel - > setStyleSheet ( " QLabel { color: red; } " ) ;
ui - > statusLabel - > setText ( tr ( " The supplied proxy address is invalid. " ) ) ;
2012-07-09 11:14:38 +02:00
}
}
2014-07-25 18:20:40 +02:00
void OptionsDialog : : updateDefaultProxyNets ( )
{
2023-07-13 14:31:14 -04:00
std : : string proxyIpText { ui - > proxyIp - > text ( ) . toStdString ( ) } ;
if ( ! IsUnixSocketPath ( proxyIpText ) ) {
const std : : optional < CNetAddr > ui_proxy_netaddr { LookupHost ( proxyIpText , /*fAllowLookup=*/ false ) } ;
const CService ui_proxy { ui_proxy_netaddr . value_or ( CNetAddr { } ) , ui - > proxyPort - > text ( ) . toUShort ( ) } ;
proxyIpText = ui_proxy . ToStringAddrPort ( ) ;
}
2022-07-15 17:50:08 +02:00
2021-11-08 17:34:32 +01:00
Proxy proxy ;
2022-07-15 17:50:08 +02:00
bool has_proxy ;
has_proxy = model - > node ( ) . getProxy ( NET_IPV4 , proxy ) ;
2023-07-13 14:31:14 -04:00
ui - > proxyReachIPv4 - > setChecked ( has_proxy & & proxy . ToString ( ) = = proxyIpText ) ;
2022-07-15 17:50:08 +02:00
has_proxy = model - > node ( ) . getProxy ( NET_IPV6 , proxy ) ;
2023-07-13 14:31:14 -04:00
ui - > proxyReachIPv6 - > setChecked ( has_proxy & & proxy . ToString ( ) = = proxyIpText ) ;
2022-07-15 17:50:08 +02:00
has_proxy = model - > node ( ) . getProxy ( NET_ONION , proxy ) ;
2023-07-13 14:31:14 -04:00
ui - > proxyReachTor - > setChecked ( has_proxy & & proxy . ToString ( ) = = proxyIpText ) ;
2014-07-25 18:20:40 +02:00
}
2015-11-16 10:43:36 +01:00
ProxyAddressValidator : : ProxyAddressValidator ( QObject * parent ) :
QValidator ( parent )
2011-06-01 14:40:06 +02:00
{
2015-11-16 10:43:36 +01:00
}
QValidator : : State ProxyAddressValidator : : validate ( QString & input , int & pos ) const
{
Q_UNUSED ( pos ) ;
// Validate the proxy
2019-12-11 16:39:29 +00:00
CService serv ( LookupNumeric ( input . toStdString ( ) , DEFAULT_GUI_PROXY_PORT ) ) ;
2021-11-08 17:34:32 +01:00
Proxy addrProxy = Proxy ( serv , true ) ;
2015-11-16 10:43:36 +01:00
if ( addrProxy . IsValid ( ) )
return QValidator : : Acceptable ;
return QValidator : : Invalid ;
2011-07-25 21:35:45 +02:00
}