mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-26 22:44:17 +00:00
8269a0953e
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).
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#ifndef PAYMENTSERVER_H
|
|
#define PAYMENTSERVER_H
|
|
|
|
//
|
|
// This class handles payment requests from clicking on
|
|
// bitcoin: URIs
|
|
//
|
|
// This is somewhat tricky, because we have to deal with
|
|
// the situation where the user clicks on a link during
|
|
// startup/initialization, when the splash-screen is up
|
|
// but the main window (and the Send Coins tab) is not.
|
|
//
|
|
// So, the strategy is:
|
|
//
|
|
// Create the server, and register the event handler,
|
|
// when the application is created. Save any URIs
|
|
// received at or during startup in a list.
|
|
//
|
|
// When startup is finished and the main window is
|
|
// show, a signal is sent to slot uiReady(), which
|
|
// emits a receivedURL() signal for any payment
|
|
// requests that happened during startup.
|
|
//
|
|
// After startup, receivedURL() happens as usual.
|
|
//
|
|
// This class has one more feature: a static
|
|
// method that finds URIs passed in the command line
|
|
// and, if a server is running in another process,
|
|
// sends them to the server.
|
|
//
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
class QApplication;
|
|
class QLocalServer;
|
|
|
|
class PaymentServer : public QObject
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
bool saveURIs;
|
|
QLocalServer* uriServer;
|
|
|
|
public:
|
|
// Returns true if there were URIs on the command line
|
|
// which were successfully sent to an already-running
|
|
// process.
|
|
static bool ipcSendCommandLine();
|
|
|
|
PaymentServer(QApplication* parent);
|
|
|
|
bool eventFilter(QObject *object, QEvent *event);
|
|
|
|
signals:
|
|
void receivedURI(QString);
|
|
|
|
public slots:
|
|
// Signal this when the main window's UI is ready
|
|
// to display payment requests to the user
|
|
void uiReady();
|
|
|
|
private slots:
|
|
void handleURIConnection();
|
|
};
|
|
|
|
#endif // PAYMENTSERVER_H
|