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