From b74dcb3b4aa29958d22135f2d6c015578069e83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Tim=C3=B3n?= Date: Thu, 16 Apr 2015 16:20:01 +0200 Subject: [PATCH] Separate CTranslationInterface from CClientUIInterface --- src/bitcoin-cli.cpp | 2 -- src/bitcoin-tx.cpp | 2 -- src/bitcoind.cpp | 1 - src/init.cpp | 2 +- src/qt/bitcoin.cpp | 2 +- src/qt/transactiondesc.cpp | 1 - src/rpcclient.cpp | 1 - src/test/test_bitcoin.cpp | 2 +- src/ui_interface.h | 13 ------------- src/util.cpp | 1 + src/util.h | 20 ++++++++++++++++++++ 11 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 2fa8de6fd8..1269d7a119 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -12,8 +12,6 @@ #include -#define _(x) std::string(x) /* Keep the _() around in case gettext or such will be used later to translate non-UI */ - using namespace std; using namespace json_spirit; diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 78f5c2c4b6..075d529408 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -11,7 +11,6 @@ #include "keystore.h" #include "script/script.h" #include "script/sign.h" -#include "ui_interface.h" // for _(...) #include "univalue/univalue.h" #include "util.h" #include "utilstrencodings.h" @@ -26,7 +25,6 @@ using namespace std; static bool fCreateBlank; static map registers; -CClientUIInterface uiInterface; static bool AppInitRawTx(int argc, char* argv[]) { diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index a0a96c2dfa..84df00527c 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -8,7 +8,6 @@ #include "init.h" #include "main.h" #include "noui.h" -#include "ui_interface.h" #include "util.h" #include diff --git a/src/init.cpp b/src/init.cpp index 4d9c233c8c..7f95b5f927 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -68,7 +68,7 @@ enum BindFlags { }; static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat"; -CClientUIInterface uiInterface; +CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h ////////////////////////////////////////////////////////////////////////////// // diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 3ae780abfd..1abce1eb21 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -533,7 +533,7 @@ int main(int argc, char *argv[]) // Now that QSettings are accessible, initialize translations QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator; initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator); - uiInterface.Translate.connect(Translate); + translationInterface.Translate.connect(Translate); // Show help message immediately after parsing command-line options (for "-lang") and setting locale, // but before showing splash screen. diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 9b235f9130..a7f705d2b2 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -14,7 +14,6 @@ #include "main.h" #include "script/script.h" #include "timedata.h" -#include "ui_interface.h" #include "util.h" #include "wallet/wallet.h" diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 428e1049dc..ccb7cf15e9 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -7,7 +7,6 @@ #include "rpcprotocol.h" #include "util.h" -#include "ui_interface.h" #include #include diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index a2cb78c989..4057eccbed 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -20,7 +20,7 @@ #include #include -CClientUIInterface uiInterface; +CClientUIInterface uiInterface; // Declared but not defined in ui_interface.h CWallet* pwalletMain; extern bool fPrintToConsole; diff --git a/src/ui_interface.h b/src/ui_interface.h index 3f11a1ddab..32a92a4b81 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -78,9 +78,6 @@ public: /** Progress message during initialization. */ boost::signals2::signal InitMessage; - /** Translate a message to the native language of the user. */ - boost::signals2::signal Translate; - /** Number of network connections changed. */ boost::signals2::signal NotifyNumConnectionsChanged; @@ -102,14 +99,4 @@ public: extern CClientUIInterface uiInterface; -/** - * Translation function: Call Translate signal on UI interface, which returns a boost::optional result. - * If no translation slot is registered, nothing is returned, and simply return the input. - */ -inline std::string _(const char* psz) -{ - boost::optional rv = uiInterface.Translate(psz); - return rv ? (*rv) : psz; -} - #endif // BITCOIN_UI_INTERFACE_H diff --git a/src/util.cpp b/src/util.cpp index 5fef3a40dd..78c7731500 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -104,6 +104,7 @@ string strMiscWarning; bool fLogTimestamps = false; bool fLogIPs = false; volatile bool fReopenDebugLog = false; +CTranslationInterface translationInterface; /** Init OpenSSL library multithreading support */ static CCriticalSection** ppmutexOpenSSL; diff --git a/src/util.h b/src/util.h index 9b5a4153dd..483d9d7858 100644 --- a/src/util.h +++ b/src/util.h @@ -25,8 +25,17 @@ #include #include +#include #include +/** Signals for translation. */ +class CTranslationInterface +{ +public: + /** Translate a message to the native language of the user. */ + boost::signals2::signal Translate; +}; + extern std::map mapArgs; extern std::map > mapMultiArgs; extern bool fDebug; @@ -37,6 +46,17 @@ extern std::string strMiscWarning; extern bool fLogTimestamps; extern bool fLogIPs; extern volatile bool fReopenDebugLog; +extern CTranslationInterface translationInterface; + +/** + * Translation function: Call Translate signal on UI interface, which returns a boost::optional result. + * If no translation slot is registered, nothing is returned, and simply return the input. + */ +inline std::string _(const char* psz) +{ + boost::optional rv = translationInterface.Translate(psz); + return rv ? (*rv) : psz; +} void SetupEnvironment();