mirror of
https://github.com/AskDavis/Casinotest.git
synced 2026-01-02 20:09:47 -08:00
Version 1.1.0.0 update
This commit is contained in:
@@ -1,27 +1,33 @@
|
||||
/*
|
||||
* W.J. van der Laan 2011-2012
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "bitcoingui.h"
|
||||
#include "clientmodel.h"
|
||||
#include "walletmodel.h"
|
||||
#include "optionsmodel.h"
|
||||
#include "guiutil.h"
|
||||
#include "guiconstants.h"
|
||||
|
||||
#include "init.h"
|
||||
#include "util.h"
|
||||
#include "ui_interface.h"
|
||||
#include "qtipcserver.h"
|
||||
#include "paymentserver.h"
|
||||
#include "splashscreen.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <QTextCodec>
|
||||
#endif
|
||||
#include <QLocale>
|
||||
#include <QTimer>
|
||||
#include <QTranslator>
|
||||
#include <QSplashScreen>
|
||||
#include <QLibraryInfo>
|
||||
|
||||
#include <boost/interprocess/ipc/message_queue.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#ifdef Q_OS_MAC
|
||||
#include "macdockiconhandler.h"
|
||||
#endif
|
||||
|
||||
#if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)
|
||||
#define _BITCOIN_QT_PLUGINS_INCLUDED
|
||||
@@ -34,36 +40,44 @@ Q_IMPORT_PLUGIN(qkrcodecs)
|
||||
Q_IMPORT_PLUGIN(qtaccessiblewidgets)
|
||||
#endif
|
||||
|
||||
// Declare meta types used for QMetaObject::invokeMethod
|
||||
Q_DECLARE_METATYPE(bool*)
|
||||
|
||||
// Need a global reference for the notifications to find the GUI
|
||||
static BitcoinGUI *guiref;
|
||||
static QSplashScreen *splashref;
|
||||
static SplashScreen *splashref;
|
||||
|
||||
static void ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style)
|
||||
static bool ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
|
||||
{
|
||||
// Message from network thread
|
||||
if(guiref)
|
||||
{
|
||||
bool modal = (style & CClientUIInterface::MODAL);
|
||||
// in case of modal message, use blocking connection to wait for user to click OK
|
||||
QMetaObject::invokeMethod(guiref, "error",
|
||||
bool ret = false;
|
||||
// In case of modal message, use blocking connection to wait for user to click a button
|
||||
QMetaObject::invokeMethod(guiref, "message",
|
||||
modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
|
||||
Q_ARG(QString, QString::fromStdString(caption)),
|
||||
Q_ARG(QString, QString::fromStdString(message)),
|
||||
Q_ARG(bool, modal));
|
||||
Q_ARG(unsigned int, style),
|
||||
Q_ARG(bool*, &ret));
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: %s\n", caption.c_str(), message.c_str());
|
||||
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption)
|
||||
static bool ThreadSafeAskFee(int64 nFeeRequired)
|
||||
{
|
||||
if(!guiref)
|
||||
return false;
|
||||
if(nFeeRequired < MIN_TX_FEE || nFeeRequired <= nTransactionFee || fDaemon)
|
||||
if(nFeeRequired < CTransaction::nMinTxFee || nFeeRequired <= nTransactionFee || fDaemon)
|
||||
return true;
|
||||
|
||||
bool payFee = false;
|
||||
|
||||
QMetaObject::invokeMethod(guiref, "askFee", GUIUtil::blockingGUIThreadConnection(),
|
||||
@@ -73,27 +87,14 @@ static bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption)
|
||||
return payFee;
|
||||
}
|
||||
|
||||
static void ThreadSafeHandleURI(const std::string& strURI)
|
||||
{
|
||||
if(!guiref)
|
||||
return;
|
||||
|
||||
QMetaObject::invokeMethod(guiref, "handleURI", GUIUtil::blockingGUIThreadConnection(),
|
||||
Q_ARG(QString, QString::fromStdString(strURI)));
|
||||
}
|
||||
|
||||
static void InitMessage(const std::string &message)
|
||||
{
|
||||
if(splashref)
|
||||
{
|
||||
splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(255,255,200));
|
||||
QApplication::instance()->processEvents();
|
||||
splashref->showMessage(QString::fromStdString(message), Qt::AlignBottom|Qt::AlignHCenter, QColor(55,55,55));
|
||||
qApp->processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
static void QueueShutdown()
|
||||
{
|
||||
QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
|
||||
printf("init message: %s\n", message.c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -109,72 +110,56 @@ static std::string Translate(const char* psz)
|
||||
static void handleRunawayException(std::exception *e)
|
||||
{
|
||||
PrintExceptionContinue(e, "Runaway exception");
|
||||
QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occured. CasinoCoin can no longer continue safely and will quit.") + QString("\n\n") + QString::fromStdString(strMiscWarning));
|
||||
QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. CasinoCoin can no longer continue safely and will quit.") + QString("\n\n") + QString::fromStdString(strMiscWarning));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifndef BITCOIN_QT_TEST
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// TODO: implement URI support on the Mac.
|
||||
#if !defined(MAC_OSX)
|
||||
// Do this early as we don't want to bother initializing if we are just calling IPC
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (boost::algorithm::istarts_with(argv[i], "casinocoin:"))
|
||||
{
|
||||
const char *strURI = argv[i];
|
||||
try {
|
||||
boost::interprocess::message_queue mq(boost::interprocess::open_only, BITCOINURI_QUEUE_NAME);
|
||||
if (mq.try_send(strURI, strlen(strURI), 0))
|
||||
// if URI could be sent to the message queue exit here
|
||||
exit(0);
|
||||
else
|
||||
// if URI could not be sent to the message queue do a normal Bitcoin-Qt startup
|
||||
break;
|
||||
}
|
||||
catch (boost::interprocess::interprocess_exception &ex) {
|
||||
// don't log the "file not found" exception, because that's normal for
|
||||
// the first start of the first instance
|
||||
if (ex.get_error_code() != boost::interprocess::not_found_error)
|
||||
{
|
||||
printf("main() - boost interprocess exception #%d: %s\n", ex.get_error_code(), ex.what());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Command-line options take precedence:
|
||||
ParseParameters(argc, argv);
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
// Internal string conversion is all UTF-8
|
||||
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
|
||||
#endif
|
||||
|
||||
Q_INIT_RESOURCE(bitcoin);
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// Register meta types used for QMetaObject::invokeMethod
|
||||
qRegisterMetaType< bool* >();
|
||||
|
||||
// Do this early as we don't want to bother initializing if we are just calling IPC
|
||||
// ... but do it after creating app, so QCoreApplication::arguments is initialized:
|
||||
if (PaymentServer::ipcSendCommandLine())
|
||||
exit(0);
|
||||
PaymentServer* paymentServer = new PaymentServer(&app);
|
||||
|
||||
// Install global event filter that makes sure that long tooltips can be word-wrapped
|
||||
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
|
||||
|
||||
// Command-line options take precedence:
|
||||
ParseParameters(argc, argv);
|
||||
|
||||
// ... then bitcoin.conf:
|
||||
if (!boost::filesystem::is_directory(GetDataDir(false)))
|
||||
{
|
||||
fprintf(stderr, "Error: Specified directory does not exist\n");
|
||||
// This message can not be translated, as translation is not initialized yet
|
||||
// (which not yet possible because lang=XX can be overridden in bitcoin.conf in the data directory)
|
||||
QMessageBox::critical(0, "CasinoCoin",
|
||||
QString("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(mapArgs["-datadir"])));
|
||||
return 1;
|
||||
}
|
||||
ReadConfigFile(mapArgs, mapMultiArgs);
|
||||
|
||||
// Application identification (must be set before OptionsModel is initialized,
|
||||
// as it is used to locate QSettings)
|
||||
app.setOrganizationName("CasinoCoin");
|
||||
app.setOrganizationDomain("casinocoin.org");
|
||||
QApplication::setOrganizationName("CasinoCoin");
|
||||
QApplication::setOrganizationDomain("casinocoin.org");
|
||||
if(GetBoolArg("-testnet")) // Separate UI settings for testnet
|
||||
app.setApplicationName("CasinoCoin-Qt-testnet");
|
||||
QApplication::setApplicationName("CasinoCoin-Qt-testnet");
|
||||
else
|
||||
app.setApplicationName("CasinoCoin-Qt");
|
||||
QApplication::setApplicationName("CasinoCoin-Qt");
|
||||
|
||||
// ... then GUI settings:
|
||||
OptionsModel optionsModel;
|
||||
@@ -209,9 +194,7 @@ int main(int argc, char *argv[])
|
||||
// Subscribe to global signals from core
|
||||
uiInterface.ThreadSafeMessageBox.connect(ThreadSafeMessageBox);
|
||||
uiInterface.ThreadSafeAskFee.connect(ThreadSafeAskFee);
|
||||
uiInterface.ThreadSafeHandleURI.connect(ThreadSafeHandleURI);
|
||||
uiInterface.InitMessage.connect(InitMessage);
|
||||
uiInterface.QueueShutdown.connect(QueueShutdown);
|
||||
uiInterface.Translate.connect(Translate);
|
||||
|
||||
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
|
||||
@@ -223,7 +206,14 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
QSplashScreen splash(QPixmap(":/images/splash"), 0);
|
||||
#ifdef Q_OS_MAC
|
||||
// on mac, also change the icon now because it would look strange to have a testnet splash (green) and a std app icon (orange)
|
||||
if(GetBoolArg("-testnet")) {
|
||||
MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet"));
|
||||
}
|
||||
#endif
|
||||
|
||||
SplashScreen splash(QPixmap(), 0);
|
||||
if (GetBoolArg("-splash", true) && !GetBoolArg("-min"))
|
||||
{
|
||||
splash.show();
|
||||
@@ -232,18 +222,27 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
app.processEvents();
|
||||
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
try
|
||||
{
|
||||
#ifndef Q_OS_MAC
|
||||
// Regenerate startup link, to fix links to old versions
|
||||
// OSX: makes no sense on mac and might also scan/mount external (and sleeping) volumes (can take up some secs)
|
||||
if (GUIUtil::GetStartOnSystemStartup())
|
||||
GUIUtil::SetStartOnSystemStartup(true);
|
||||
#endif
|
||||
|
||||
boost::thread_group threadGroup;
|
||||
|
||||
BitcoinGUI window;
|
||||
guiref = &window;
|
||||
if(AppInit2())
|
||||
|
||||
QTimer* pollShutdownTimer = new QTimer(guiref);
|
||||
QObject::connect(pollShutdownTimer, SIGNAL(timeout()), guiref, SLOT(detectShutdown()));
|
||||
pollShutdownTimer->start(200);
|
||||
|
||||
if(AppInit2(threadGroup))
|
||||
{
|
||||
{
|
||||
// Put this in a block, so that the Model objects are cleaned up before
|
||||
@@ -255,10 +254,16 @@ int main(int argc, char *argv[])
|
||||
splash.finish(&window);
|
||||
|
||||
ClientModel clientModel(&optionsModel);
|
||||
WalletModel walletModel(pwalletMain, &optionsModel);
|
||||
WalletModel *walletModel = 0;
|
||||
if(pwalletMain)
|
||||
walletModel = new WalletModel(pwalletMain, &optionsModel);
|
||||
|
||||
window.setClientModel(&clientModel);
|
||||
window.setWalletModel(&walletModel);
|
||||
if(walletModel)
|
||||
{
|
||||
window.addWallet("~Default", walletModel);
|
||||
window.setCurrentWallet("~Default");
|
||||
}
|
||||
|
||||
// If -min option passed, start window minimized.
|
||||
if(GetBoolArg("-min"))
|
||||
@@ -269,41 +274,30 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
window.show();
|
||||
}
|
||||
// TODO: implement URI support on the Mac.
|
||||
#if !defined(MAC_OSX)
|
||||
|
||||
// Place this here as guiref has to be defined if we dont want to lose URIs
|
||||
ipcInit();
|
||||
// Now that initialization/startup is done, process any command-line
|
||||
// bitcoin: URIs
|
||||
QObject::connect(paymentServer, SIGNAL(receivedURI(QString)), &window, SLOT(handleURI(QString)));
|
||||
QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
|
||||
|
||||
// Check for URI in argv
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (boost::algorithm::istarts_with(argv[i], "casinocoin:"))
|
||||
{
|
||||
const char *strURI = argv[i];
|
||||
try {
|
||||
boost::interprocess::message_queue mq(boost::interprocess::open_only, BITCOINURI_QUEUE_NAME);
|
||||
mq.try_send(strURI, strlen(strURI), 0);
|
||||
}
|
||||
catch (boost::interprocess::interprocess_exception &ex) {
|
||||
printf("main() - boost interprocess exception #%d: %s\n", ex.get_error_code(), ex.what());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
app.exec();
|
||||
|
||||
window.hide();
|
||||
window.setClientModel(0);
|
||||
window.setWalletModel(0);
|
||||
window.removeAllWallets();
|
||||
guiref = 0;
|
||||
delete walletModel;
|
||||
}
|
||||
// Shutdown the core and it's threads, but don't exit Bitcoin-Qt here
|
||||
Shutdown(NULL);
|
||||
// Shutdown the core and its threads, but don't exit Bitcoin-Qt here
|
||||
threadGroup.interrupt_all();
|
||||
threadGroup.join_all();
|
||||
Shutdown();
|
||||
}
|
||||
else
|
||||
{
|
||||
threadGroup.interrupt_all();
|
||||
threadGroup.join_all();
|
||||
Shutdown();
|
||||
return 1;
|
||||
}
|
||||
} catch (std::exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user