remove commented code, use // for one-line comments and comments inside functions
[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     QApplication app(argc, argv);
100     app.setQuitOnLastWindowClosed(false);
101
102     try
103     {
104         if(AppInit2(argc, argv))
105         {
106             BitcoinGUI window;
107             ClientModel model;
108             guiref = &window;
109             window.setModel(&model);
110
111             window.show();
112
113             int retval = app.exec();
114
115             guiref = 0;
116             Shutdown(NULL);
117
118             return retval;
119         }
120         else
121         {
122             return 1;
123         }
124     } catch (std::exception& e) {
125         PrintException(&e, "Runaway exception");
126     } catch (...) {
127         PrintException(NULL, "Runaway exception");
128     }
129 }