Merge pull request #361 from svost/master
[novacoin.git] / src / ui_interface.h
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_UI_INTERFACE_H
6 #define BITCOIN_UI_INTERFACE_H
7
8 #include <string>
9 #include <boost/signals2/signal.hpp>
10 #include <boost/signals2/last_value.hpp>
11
12 #include "util.h"
13
14 class CBasicKeyStore;
15 class CWallet;
16 class uint256;
17
18 /** General change type (added, updated, removed). */
19 enum ChangeType
20 {
21     CT_NEW,
22     CT_UPDATED,
23     CT_DELETED
24 };
25
26 /** Signals for UI communication. */
27 class CClientUIInterface
28 {
29 public:
30     /** Flags for CClientUIInterface::ThreadSafeMessageBox */
31     enum MessageBoxFlags
32     {
33         YES                   = 0x00000002,
34         OK                    = 0x00000004,
35         NO                    = 0x00000008,
36         YES_NO                = (YES|NO),
37         CANCEL                = 0x00000010,
38         APPLY                 = 0x00000020,
39         CLOSE                 = 0x00000040,
40         OK_DEFAULT            = 0x00000000,
41         YES_DEFAULT           = 0x00000000,
42         NO_DEFAULT            = 0x00000080,
43         CANCEL_DEFAULT        = 0x80000000,
44         ICON_EXCLAMATION      = 0x00000100,
45         ICON_HAND             = 0x00000200,
46         ICON_WARNING          = ICON_EXCLAMATION,
47         ICON_ERROR            = ICON_HAND,
48         ICON_QUESTION         = 0x00000400,
49         ICON_INFORMATION      = 0x00000800,
50         ICON_STOP             = ICON_HAND,
51         ICON_ASTERISK         = ICON_INFORMATION,
52         ICON_MASK             = (0x00000100|0x00000200|0x00000400|0x00000800),
53         FORWARD               = 0x00001000,
54         BACKWARD              = 0x00002000,
55         RESET                 = 0x00004000,
56         HELP                  = 0x00008000,
57         MORE                  = 0x00010000,
58         SETUP                 = 0x00020000,
59         // Force blocking, modal message box dialog (not just OS notification)
60         MODAL                 = 0x00040000,
61
62         /** Predefined combinations for certain default usage cases */
63         MSG_INFORMATION = ICON_INFORMATION,
64         MSG_WARNING = (ICON_WARNING | OK | MODAL),
65         MSG_ERROR = (ICON_ERROR | OK | MODAL)
66
67     };
68
69     /** Show message box. */
70     boost::signals2::signal<void (const std::string& message, const std::string& caption, int style)> ThreadSafeMessageBox;
71
72     /** Ask the user whether they want to pay a fee or not. */
73     boost::signals2::signal<bool (int64_t nFeeRequired, const std::string& strCaption), boost::signals2::last_value<bool> > ThreadSafeAskFee;
74
75     /** Handle a URL passed at the command line. */
76     boost::signals2::signal<void (const std::string& strURI)> ThreadSafeHandleURI;
77
78     /** Progress message during initialization. */
79     boost::signals2::signal<void (const std::string &message)> InitMessage;
80
81     /** Initiate client shutdown. */
82     boost::signals2::signal<void ()> QueueShutdown;
83
84     /** Translate a message to the native language of the user. */
85     boost::signals2::signal<std::string (const char* psz)> Translate;
86
87     /** Block chain changed. */
88     boost::signals2::signal<void ()> NotifyBlocksChanged;
89
90     /** Number of network connections changed. */
91     boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged;
92
93     /**
94      * New, updated or cancelled alert.
95      * @note called with lock cs_mapAlerts held.
96      */
97     boost::signals2::signal<void (const uint256 &hash, ChangeType status)> NotifyAlertChanged;
98 };
99
100 extern CClientUIInterface uiInterface;
101
102 /**
103  * Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
104  * If no translation slot is registered, nothing is returned, and simply return the input.
105  */
106 inline std::string _(const char* psz)
107 {
108     boost::optional<std::string> rv = uiInterface.Translate(psz);
109     return rv ? (*rv) : psz;
110 }
111
112 #endif