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