aboutsummaryrefslogtreecommitdiff
path: root/src/qt/paymentserver.h
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-02-11 18:52:30 -0500
committerGavin Andresen <gavinandresen@gmail.com>2013-02-12 15:41:31 -0500
commit8269a0953ee9ccbdc422433fc37184e60f94b178 (patch)
tree9e5a3c73057afdba5e7351e051072ac2365ca924 /src/qt/paymentserver.h
parent2f0fa79db290d5139c27409055b2035099afa6fd (diff)
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).
Diffstat (limited to 'src/qt/paymentserver.h')
-rw-r--r--src/qt/paymentserver.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/qt/paymentserver.h b/src/qt/paymentserver.h
new file mode 100644
index 0000000000..cfc48afb38
--- /dev/null
+++ b/src/qt/paymentserver.h
@@ -0,0 +1,66 @@
+#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