6 #include <QApplication>
10 #include <QTextStream>
39 #include <boost/filesystem/operations.hpp>
40 #include <QApplication>
41 #include <QLibraryInfo>
43 #include <QMessageBox>
46 #include <QTranslator>
49 #if defined(QT_STATICPLUGIN)
51 #if QT_VERSION < 0x050000
52 Q_IMPORT_PLUGIN(qcncodecs)
53 Q_IMPORT_PLUGIN(qjpcodecs)
54 Q_IMPORT_PLUGIN(qtwcodecs)
55 Q_IMPORT_PLUGIN(qkrcodecs)
56 Q_IMPORT_PLUGIN(qtaccessiblewidgets)
58 Q_IMPORT_PLUGIN(AccessibleFactory)
59 #if defined(QT_QPA_PLATFORM_XCB)
60 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
61 #elif defined(QT_QPA_PLATFORM_WINDOWS)
62 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
63 #elif defined(QT_QPA_PLATFORM_COCOA)
64 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
69 #if QT_VERSION < 0x050000
74 Q_DECLARE_METATYPE(
bool*)
76 static
void InitMessage(const
std::
string &message)
84 static std::string Translate(
const char* psz)
86 return QCoreApplication::translate(
"anoncoin-core", psz).toStdString();
90 static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
95 QApplication::removeTranslator(&qtTranslatorBase);
96 QApplication::removeTranslator(&qtTranslator);
97 QApplication::removeTranslator(&translatorBase);
98 QApplication::removeTranslator(&translator);
102 QString lang_territory = QLocale::system().name();
104 QString lang_territory_qsettings = settings.value(
"language",
"").toString();
105 if(!lang_territory_qsettings.isEmpty())
106 lang_territory = lang_territory_qsettings;
108 lang_territory = QString::fromStdString(
GetArg(
"-lang", lang_territory.toStdString()));
111 QString lang = lang_territory;
112 lang.truncate(lang_territory.lastIndexOf(
'_'));
119 if (qtTranslatorBase.load(
"qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
120 QApplication::installTranslator(&qtTranslatorBase);
123 if (qtTranslator.load(
"qt_" + lang_territory, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
124 QApplication::installTranslator(&qtTranslator);
127 if (translatorBase.load(lang,
":/translations/"))
128 QApplication::installTranslator(&translatorBase);
131 if (translator.load(lang_territory,
":/translations/"))
132 QApplication::installTranslator(&translator);
136 #if QT_VERSION < 0x050000
140 LogPrint(
"qt",
"GUI: %s\n", msg);
143 void DebugMessageHandler(QtMsgType type,
const QMessageLogContext& context,
const QString &msg)
147 LogPrint(
"qt",
"GUI: %s\n", qPrintable(msg));
185 void createPaymentServer();
233 #include "anoncoin.moc"
250 LogPrintf(
"Running AppInit2 in thread\n");
260 }
catch (std::exception& e) {
271 LogPrintf(
"Running Shutdown in thread\n");
277 }
catch (std::exception& e) {
285 QApplication(argc, argv),
290 pollShutdownTimer(0),
297 setQuitOnLastWindowClosed(
false);
311 delete paymentServer;
319 void AnoncoinApplication::createPaymentServer()
342 splash->setAttribute(Qt::WA_DeleteOnClose);
344 connect(
this, SIGNAL(
splashFinished(QWidget*)), splash, SLOT(slotFinish(QWidget*)));
360 connect(
this, SIGNAL(
stopThread()), executor, SLOT(deleteLater()));
380 window->removeAllWallets();
396 LogPrintf(
"Initialization result: %i\n", retval);
416 window->addWallet(
"~Default", walletModel);
417 window->setCurrentWallet(
"~Default");
438 connect(
window, SIGNAL(receivedURI(QString)),
439 paymentServer, SLOT(handleURIOrFile(QString)));
440 connect(paymentServer, SIGNAL(message(QString,QString,
unsigned int)),
441 window, SLOT(message(QString,QString,
unsigned int)));
442 QTimer::singleShot(100, paymentServer, SLOT(uiReady()));
451 LogPrintf(
"Shutdown result: %i\n", retval);
457 QMessageBox::critical(0,
"Runaway exception", AnoncoinGUI::tr(
"A fatal error occurred. Anoncoin can no longer continue safely and will quit.") + QString(
"\n\n") + message);
469 #ifndef ANONCOIN_QT_TEST
470 int main(
int argc,
char *argv[])
481 #if QT_VERSION < 0x050000
483 QTextCodec::setCodecForTr(QTextCodec::codecForName(
"UTF-8"));
484 QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
487 Q_INIT_RESOURCE(anoncoin);
492 #if QT_VERSION > 0x050100
494 QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
497 QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);
501 qRegisterMetaType< bool* >();
512 QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
513 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
531 if (!boost::filesystem::is_directory(
GetDataDir(
false)))
533 QMessageBox::critical(0, QObject::tr(
"Anoncoin"),
534 QObject::tr(
"Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(
mapArgs[
"-datadir"])));
548 }
catch(std::exception &e) {
549 QMessageBox::critical(0, QObject::tr(
"Anoncoin"),
550 QObject::tr(
"Error: Cannot parse configuration file: %1. Only use key=value syntax.").arg(e.what()));
566 QFile file(filename);
567 if( file.exists() ) {
568 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
569 QTextStream in(&file);
570 QString content =
"";
572 content.append(in.readLine());
573 app.setStyleSheet(content);
575 QMessageBox::warning( NULL, AnoncoinGUI::tr(
"Failed to open stylesheet file."),
576 filename.toLocal8Bit().data(),
577 QMessageBox::Ok, QMessageBox::Ok );
578 }
else if(
mapArgs.count(
"-style") )
579 QMessageBox::warning( NULL, AnoncoinGUI::tr(
"Failed to find stylesheet file."),
580 filename.toLocal8Bit().data(),
581 QMessageBox::Ok, QMessageBox::Ok );
585 app.setQuitOnLastWindowClosed(
false);
589 QMessageBox::critical(0, QObject::tr(
"Anoncoin"), QObject::tr(
"Error: Invalid combination of -regtest and -testnet."));
604 initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
618 app.createPaymentServer();
624 #if QT_VERSION < 0x050000
628 #if defined(Q_OS_WIN)
630 qApp->installNativeEventFilter(
new WinShutdownMonitor());
648 #if defined(Q_OS_WIN) && QT_VERSION >= 0x050000
649 WinShutdownMonitor::registerShutdownBlockReason(QObject::tr(
"Anoncoin Core didn't yet exit safely..."), (HWND)app.
getMainWinId());
654 }
catch (std::exception& e) {
663 #endif // ANONCOIN_QT_TEST
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
CClientUIInterface uiInterface
void handleRunawayException(const QString &message)
Handle runaway exceptions. Shows a message box with the problem and quits the program.
void handleRunawayException(std::exception *e)
Pass fatal exception message to UI thread.
Value help(const Array ¶ms, bool fHelp)
QTimer * pollShutdownTimer
class for the splashscreen with information of the running client
void initializeResult(int retval)
OptionsModel * optionsModel
void DebugMessageHandler(QtMsgType type, const char *msg)
int getReturnValue()
Get process return value.
void runawayException(const QString &message)
static void showShutdownWindow(AnoncoinGUI *window)
"Shutdown" window
bool SelectParamsFromCommandLine()
Looks for -regtest or -testnet and then calls SelectParams as appropriate.
boost::thread_group threadGroup
void createWindow(bool isaTestNet)
Create main window.
static bool ipcParseCommandLine(int argc, char *argv[])
static bool ipcSendCommandLine()
void SubstituteFonts()
Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text repre...
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
WId getMainWinId() const
Get window identifier of QMainWindow (AnoncoinGUI)
void createOptionsModel()
Create options model.
void requestedInitialize()
bool AppInit2(boost::thread_group &threadGroup)
Initialize anoncoin.
AnoncoinApplication(int &argc, char **argv)
void PrintExceptionContinue(std::exception *pex, const char *pszThread)
Main Anoncoin application object.
void ParseParameters(int argc, const char *const argv[])
Model for Anoncoin network client.
void createSplashScreen(bool isaTestNet)
Create splash screen.
boost::filesystem::path GetQtStyleFile()
void shutdownResult(int retval)
ClientModel * clientModel
#define QAPP_APP_NAME_DEFAULT
void initializeResult(int retval)
void ReadConfigFile(map< string, string > &mapSettingsRet, map< string, vector< string > > &mapMultiSettingsRet)
void splashFinished(QWidget *window)
Interface from Qt to configuration data structure for Anoncoin client.
const CChainParams & Params()
Return the currently selected parameters.
Interface to Anoncoin wallet from Qt view code.
void setClientModel(ClientModel *clientModel)
Set the client model.
static void pickDataDirectory()
Determine data directory.
#define QAPP_APP_NAME_TESTNET
Class encapsulating Anoncoin Core startup and shutdown.
void requestShutdown()
Request core shutdown.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
void shutdownResult(int retval)
"Help message" dialog box
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
QString boostPathToQString(const boost::filesystem::path &path)
static void LoadRootCAs(X509_STORE *store=NULL)
map< string, vector< string > > mapMultiArgs
int main(int argc, char *argv[])
virtual Network NetworkID() const =0
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
map< string, string > mapArgs
void requestInitialize()
Request core initialization.
boost::filesystem::path GetConfigFile()
void StartDummyRPCThread()