Reimplement click-to-pay links. Add OSX support.
Switch to using Qt's QLocalServer/QLocalSocket to handle bitcoin payment links (bitcoin:... URIs) Reason for switch: the boost::interprocess mechanism seemed flaky, and doesn't mesh as well with "The Qt Way" qtipcserver.cpp/h is replaced by paymentserver.cpp/h Click-to-pay now also works on OSX, with a custom Info.plist that registers Bitcoin-Qt as a handler for bitcoin: URLs and an event listener on the main QApplication that handles QFileOpenEvents (Qt translates 'url clicked' AppleEvents into QFileOpenEvents automagically).
This commit is contained in:
@@ -9,12 +9,13 @@
|
||||
#include "guiconstants.h"
|
||||
#include "init.h"
|
||||
#include "ui_interface.h"
|
||||
#include "qtipcserver.h"
|
||||
#include "paymentserver.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QTextCodec>
|
||||
#include <QLocale>
|
||||
#include <QTimer>
|
||||
#include <QTranslator>
|
||||
#include <QSplashScreen>
|
||||
#include <QLibraryInfo>
|
||||
@@ -70,15 +71,6 @@ static bool ThreadSafeAskFee(int64 nFeeRequired)
|
||||
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)
|
||||
@@ -117,14 +109,6 @@ int main(int argc, char *argv[])
|
||||
// Command-line options take precedence:
|
||||
ParseParameters(argc, argv);
|
||||
|
||||
if(GetBoolArg("-testnet")) // Separate message queue name for testnet
|
||||
strBitcoinURIQueueName = BITCOINURI_QUEUE_NAME_TESTNET;
|
||||
else
|
||||
strBitcoinURIQueueName = BITCOINURI_QUEUE_NAME_MAINNET;
|
||||
|
||||
// Do this early as we don't want to bother initializing if we are just calling IPC
|
||||
ipcScanRelay(argc, argv);
|
||||
|
||||
// Internal string conversion is all UTF-8
|
||||
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
|
||||
@@ -132,6 +116,12 @@ int main(int argc, char *argv[])
|
||||
Q_INIT_RESOURCE(bitcoin);
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// 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));
|
||||
|
||||
@@ -188,7 +178,6 @@ 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);
|
||||
@@ -249,8 +238,10 @@ int main(int argc, char *argv[])
|
||||
window.show();
|
||||
}
|
||||
|
||||
// Place this here as guiref has to be defined if we don't want to lose URIs
|
||||
ipcInit(argc, argv);
|
||||
// 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()));
|
||||
|
||||
app.exec();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user