From 9ab9e7d1b3b4a7eac46b4e4f273c68f4e737e5f7 Mon Sep 17 00:00:00 2001 From: Eric Shaw Jr Date: Tue, 28 Feb 2017 12:13:34 -0500 Subject: [PATCH] Add a button to open the config file in a text editor --- src/qt/forms/optionsdialog.ui | 102 +++++++++++++++++++++++----------- src/qt/guiutil.cpp | 16 ++++++ src/qt/guiutil.h | 3 + src/qt/optionsdialog.cpp | 12 ++++ src/qt/optionsdialog.h | 1 + 5 files changed, 102 insertions(+), 32 deletions(-) diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index 0b2920187..0f1b3f4a7 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -692,17 +692,34 @@ - - - Reset all client options to default. - - - &Reset Options - - - false - - + + + + + Open the %1 configuration file from the working directory. + + + Open Configuration File + + + false + + + + + + + Reset all client options to default. + + + &Reset Options + + + false + + + + @@ -756,27 +773,48 @@ - - - &OK - - - false - - - true - - - - - - - &Cancel - - - false - - + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + &OK + + + false + + + true + + + + + + + &Cancel + + + false + + + + + + diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index bb5b2d434..2c9d2b001 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -417,6 +417,22 @@ void openDebugLogfile() QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathDebug))); } +bool openBitcoinConf() +{ + boost::filesystem::path pathConfig = GetConfigFile(BITCOIN_CONF_FILENAME); + + /* Create the file */ + boost::filesystem::ofstream configFile(pathConfig, std::ios_base::app); + + if (!configFile.good()) + return false; + + configFile.close(); + + /* Open bitcoin.conf with the associated application */ + return QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig))); +} + void SubstituteFonts(const QString& language) { #if defined(Q_OS_MAC) diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 913aa5e24..36ae2453c 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -114,6 +114,9 @@ namespace GUIUtil // Open debug.log void openDebugLogfile(); + // Open the config file + bool openBitcoinConf(); + // Replace invalid default fonts with known good ones void SubstituteFonts(const QString& language); diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 7ff00b1e9..efb25aaf1 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -232,6 +232,18 @@ void OptionsDialog::on_resetButton_clicked() } } +void OptionsDialog::on_openBitcoinConfButton_clicked() +{ + /* explain the purpose of the config file */ + QMessageBox::information(this, tr("Configuration options"), + 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.")); + + /* 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.")); +} + void OptionsDialog::on_okButton_clicked() { mapper->submit(); diff --git a/src/qt/optionsdialog.h b/src/qt/optionsdialog.h index d98c1dc19..f9f5823c0 100644 --- a/src/qt/optionsdialog.h +++ b/src/qt/optionsdialog.h @@ -47,6 +47,7 @@ private Q_SLOTS: /* set OK button state (enabled / disabled) */ void setOkButtonState(bool fState); void on_resetButton_clicked(); + void on_openBitcoinConfButton_clicked(); void on_okButton_clicked(); void on_cancelButton_clicked();