update core to d0d80170a2ca73004e08fb85007fe055cbf4e411 (CWallet class)
[novacoin.git] / src / qt / bitcoin.cpp
1 /*
2  * W.J. van der Laan 2011
3  */
4 #include "bitcoingui.h"
5 #include "clientmodel.h"
6
7 #include "headers.h"
8 #include "init.h"
9
10 #include <QApplication>
11 #include <QMessageBox>
12 #include <QThread>
13 #include <QLocale>
14 #include <QTranslator>
15
16 // Need a global reference for the notifications to find the GUI
17 BitcoinGUI *guiref;
18
19 int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
20 {
21     // Message from main thread
22     if(guiref)
23     {
24         guiref->error(QString::fromStdString(caption),
25                       QString::fromStdString(message));
26     }
27     else
28     {
29         QMessageBox::critical(0, QString::fromStdString(caption),
30             QString::fromStdString(message),
31             QMessageBox::Ok, QMessageBox::Ok);
32     }
33     return 4;
34 }
35
36 int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
37 {
38     // Message from network thread
39     if(guiref)
40     {
41         QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
42                                    Q_ARG(QString, QString::fromStdString(caption)),
43                                    Q_ARG(QString, QString::fromStdString(message)));
44     }
45     else
46     {
47         printf("%s: %s\n", caption.c_str(), message.c_str());
48         fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
49     }
50     return 4;
51 }
52
53 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
54 {
55     if(!guiref)
56         return false;
57     if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
58         return true;
59     bool payFee = false;
60
61     // Call slot on GUI thread.
62     // If called from another thread, use a blocking QueuedConnection.
63     Qt::ConnectionType connectionType = Qt::DirectConnection;
64     if(QThread::currentThread() != QCoreApplication::instance()->thread())
65     {
66         connectionType = Qt::BlockingQueuedConnection;
67     }
68
69     QMetaObject::invokeMethod(guiref, "askFee", connectionType,
70                                Q_ARG(qint64, nFeeRequired),
71                                Q_ARG(bool*, &payFee));
72
73     return payFee;
74 }
75
76 void CalledSetStatusBar(const std::string& strText, int nField)
77 {
78     // Only used for built-in mining, which is disabled, simple ignore
79 }
80
81 void UIThreadCall(boost::function0<void> fn)
82 {
83     // Only used for built-in mining, which is disabled, simple ignore
84 }
85
86 void MainFrameRepaint()
87 {
88 }
89
90 /*
91    Translate string to current locale using Qt.
92  */
93 std::string _(const char* psz)
94 {
95     return QCoreApplication::translate("bitcoin-core", psz).toStdString();
96 }
97
98 int main(int argc, char *argv[])
99 {
100     Q_INIT_RESOURCE(bitcoin);
101     QApplication app(argc, argv);
102
103     // Load language file for system locale
104     QString locale = QLocale::system().name();
105     QTranslator translator;
106     translator.load("bitcoin_"+locale);
107     app.installTranslator(&translator);
108
109     app.setQuitOnLastWindowClosed(false);
110
111     try
112     {
113         if(AppInit2(argc, argv))
114         {
115             BitcoinGUI window;
116             ClientModel model(pwalletMain);
117             guiref = &window;
118             window.setModel(&model);
119
120             window.show();
121
122             int retval = app.exec();
123
124             guiref = 0;
125             Shutdown(NULL);
126
127             return retval;
128         }
129         else
130         {
131             return 1;
132         }
133     } catch (std::exception& e) {
134         PrintException(&e, "Runaway exception");
135     } catch (...) {
136         PrintException(NULL, "Runaway exception");
137     }
138 }