#pragma once #include #include #include #include #include #include #include class Root; class API : public QObject { friend class Root; Q_OBJECT public: enum State {Offline, NoServer, NotAuthenticated, Authenticated}; Q_ENUM(State) private: Q_PROPERTY(QUrl address READ getAddress NOTIFY addressChanged) Q_PROPERTY(State state READ getState NOTIFY stateChanged) public: explicit API(const QUrl& path = QString(), QObject* parent = nullptr); QUrl getAddress() const; State getState() const; signals: void addressChanged(const QUrl& path); void stateChanged(State state); public slots: void test(const QString& path, const QJSValue& finished = QJSValue()); void sendRegister(const QString& login, const QString& password, const QJSValue& finished = QJSValue()); private slots: void onTestFinished(QNetworkReply* reply, const QUrl& addr, const QJSValue& finished); void onRegisterFinished(QNetworkReply* reply, const QJSValue& finished) const; private: void callCallback(const QJSValue& callback, const QString& error = QString(), const QJSValueList& arguments = QJSValueList()) const; void setAddress(const QUrl& path); private: QUrl address; QNetworkAccessManager network; State state; };