]> git.sur5r.net Git - minitube/blob - lib/js/jsresult.h
New upstream version 3.8
[minitube] / lib / js / jsresult.h
1 #ifndef JSRESULT_H
2 #define JSRESULT_H
3
4 #include <QtQml>
5
6 class JSResult : public QObject {
7     Q_OBJECT
8
9 public:
10     JSResult(QObject *parent = nullptr) : QObject(parent) {}
11     ~JSResult() { qDebug() << "Destroying result"; }
12
13     template <typename Functor> JSResult &onString(Functor lambda) {
14         connect(this, &JSResult::string, this, lambda);
15         return *this;
16     }
17     template <typename Functor> JSResult &onJson(Functor lambda) {
18         connect(this, &JSResult::json, this, lambda);
19         return *this;
20     }
21     template <typename Functor> JSResult &onError(Functor lambda) {
22         connect(this, &JSResult::error, this, lambda);
23         return *this;
24     }
25
26     Q_INVOKABLE QJSValue setData(QJSValue value);
27     Q_INVOKABLE QJSValue setError(QJSValue value);
28
29 signals:
30     void json(const QJsonDocument &doc);
31     void string(const QString &data);
32     void error(const QString &message);
33 };
34
35 #endif // JSRESULT_H