]> git.sur5r.net Git - minitube/blobdiff - lib/js/jsresult.h
Update upstream source from tag 'upstream/3.8'
[minitube] / lib / js / jsresult.h
diff --git a/lib/js/jsresult.h b/lib/js/jsresult.h
new file mode 100644 (file)
index 0000000..6fe64cf
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef JSRESULT_H
+#define JSRESULT_H
+
+#include <QtQml>
+
+class JSResult : public QObject {
+    Q_OBJECT
+
+public:
+    JSResult(QObject *parent = nullptr) : QObject(parent) {}
+    ~JSResult() { qDebug() << "Destroying result"; }
+
+    template <typename Functor> JSResult &onString(Functor lambda) {
+        connect(this, &JSResult::string, this, lambda);
+        return *this;
+    }
+    template <typename Functor> JSResult &onJson(Functor lambda) {
+        connect(this, &JSResult::json, this, lambda);
+        return *this;
+    }
+    template <typename Functor> JSResult &onError(Functor lambda) {
+        connect(this, &JSResult::error, this, lambda);
+        return *this;
+    }
+
+    Q_INVOKABLE QJSValue setData(QJSValue value);
+    Q_INVOKABLE QJSValue setError(QJSValue value);
+
+signals:
+    void json(const QJsonDocument &doc);
+    void string(const QString &data);
+    void error(const QString &message);
+};
+
+#endif // JSRESULT_H