update readme and splash screen text
[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 "walletmodel.h"
7 #include "optionsmodel.h"
8 #include "qtwin.h"
9
10 #include "headers.h"
11 #include "init.h"
12
13 #include <QApplication>
14 #include <QMessageBox>
15 #include <QThread>
16 #include <QLocale>
17 #include <QTranslator>
18 #include <QSplashScreen>
19 #include <QDebug>
20
21 // Need a global reference for the notifications to find the GUI
22 BitcoinGUI *guiref;
23 QSplashScreen *splashref;
24
25 int MyMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
26 {
27     // Message from main thread
28     if(guiref)
29     {
30         guiref->error(QString::fromStdString(caption),
31                       QString::fromStdString(message));
32     }
33     else
34     {
35         QMessageBox::critical(0, QString::fromStdString(caption),
36             QString::fromStdString(message),
37             QMessageBox::Ok, QMessageBox::Ok);
38     }
39     return 4;
40 }
41
42 int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style, wxWindow* parent, int x, int y)
43 {
44     // Message from network thread
45     if(guiref)
46     {
47         QMetaObject::invokeMethod(guiref, "error", Qt::QueuedConnection,
48                                    Q_ARG(QString, QString::fromStdString(caption)),
49                                    Q_ARG(QString, QString::fromStdString(message)));
50     }
51     else
52     {
53         printf("%s: %s\n", caption.c_str(), message.c_str());
54         fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
55     }
56     return 4;
57 }
58
59 bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent)
60 {
61     if(!guiref)
62         return false;
63     if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
64         return true;
65     bool payFee = false;
66
67     // Call slot on GUI thread.
68     // If called from another thread, use a blocking QueuedConnection.
69     Qt::ConnectionType connectionType = Qt::DirectConnection;
70     if(QThread::currentThread() != QCoreApplication::instance()->thread())
71     {
72         connectionType = Qt::BlockingQueuedConnection;
73     }
74
75     QMetaObject::invokeMethod(guiref, "askFee", connectionType,
76                                Q_ARG(qint64, nFeeRequired),
77                                Q_ARG(bool*, &payFee));
78
79     return payFee;
80 }
81
82 void CalledSetStatusBar(const std::string& strText, int nField)
83 {
84     // Only used for built-in mining, which is disabled, simple ignore
85 }
86
87 void UIThreadCall(boost::function0<void> fn)
88 {
89     // Only used for built-in mining, which is disabled, simple ignore
90 }
91
92 void MainFrameRepaint()
93 {
94 }
95
96 void InitMessage(const std::string &message)
97 {
98     if(splashref)
99     {
100         splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
101         QApplication::instance()->processEvents();
102     }
103 }
104
105 /*
106    Translate string to current locale using Qt.
107  */
108 std::string _(const char* psz)
109 {
110     return QCoreApplication::translate("bitcoin-core", psz).toStdString();
111 }
112
113 int main(int argc, char *argv[])
114 {
115     Q_INIT_RESOURCE(bitcoin);
116     QApplication app(argc, argv);
117
118     // Load language file for system locale
119     QString locale = QLocale::system().name();
120     QTranslator translator;
121     translator.load("bitcoin_"+locale);
122     app.installTranslator(&translator);
123
124     QSplashScreen splash(QPixmap(":/images/splash"), Qt::WindowStaysOnTopHint);
125     splash.show();
126     splash.setAutoFillBackground(true);
127     splashref = &splash;
128
129     app.processEvents();
130
131     app.setQuitOnLastWindowClosed(false);
132
133     try
134     {
135         if(AppInit2(argc, argv))
136         {
137             {
138                 // Put this in a block, so that BitcoinGUI is cleaned up properly before
139                 // calling shutdown.
140                 BitcoinGUI window;
141                 splash.finish(&window);
142                 OptionsModel optionsModel(pwalletMain);
143                 ClientModel clientModel(&optionsModel);
144                 WalletModel walletModel(pwalletMain, &optionsModel);
145
146                 guiref = &window;
147                 window.setClientModel(&clientModel);
148                 window.setWalletModel(&walletModel);
149
150                 if (QtWin::isCompositionEnabled())
151                 {
152 #ifdef Q_WS_WIN32
153                     // Windows-specific customization
154                     window.setAttribute(Qt::WA_TranslucentBackground);
155                     window.setAttribute(Qt::WA_NoSystemBackground, false);
156                     QPalette pal = window.palette();
157                     QColor bg = pal.window().color();
158                     bg.setAlpha(0);
159                     pal.setColor(QPalette::Window, bg);
160                     window.setPalette(pal);
161                     window.ensurePolished();
162                     window.setAttribute(Qt::WA_StyledBackground, false);
163 #endif
164                     QtWin::extendFrameIntoClientArea(&window);
165                     window.setContentsMargins(0, 0, 0, 0);
166                 }
167
168                 window.show();
169
170                 app.exec();
171
172                 guiref = 0;
173             }
174             Shutdown(NULL);
175         }
176         else
177         {
178             return 1;
179         }
180     } catch (std::exception& e) {
181         PrintException(&e, "Runaway exception");
182     } catch (...) {
183         PrintException(NULL, "Runaway exception");
184     }
185     return 0;
186 }