File indexing completed on 2025-01-19 10:46:01
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Martin Klapetek <mklapetek@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef QMLHELPER_H 0008 #define QMLHELPER_H 0009 0010 #include <QObject> 0011 #include <QStringList> 0012 #include <QVariant> 0013 0014 namespace KIO 0015 { 0016 class Job; 0017 } 0018 class KJob; 0019 0020 class Service 0021 { 0022 Q_GADGET 0023 Q_PROPERTY(QString id MEMBER m_id) 0024 Q_PROPERTY(QString name MEMBER m_name) 0025 Q_PROPERTY(QString description MEMBER m_description) 0026 0027 public: 0028 QString m_id; 0029 QString m_name; 0030 QString m_description; 0031 }; 0032 0033 class OwncloudController : public QObject 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY(State state MEMBER m_state NOTIFY stateChanged) 0037 Q_PROPERTY(bool isWorking READ isWorking NOTIFY isWorkingChanged) 0038 Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) 0039 Q_PROPERTY(QVariantList availableServices READ availableServices CONSTANT) 0040 0041 public: 0042 enum State { 0043 Server = 0, 0044 Services, 0045 }; 0046 Q_ENUM(State) 0047 0048 explicit OwncloudController(QObject *parent = nullptr); 0049 ~OwncloudController(); 0050 0051 Q_INVOKABLE void checkServer(const QString &username, const QString &password, const QString &server); 0052 Q_INVOKABLE void finish(const QStringList &disabledServices); 0053 Q_INVOKABLE void cancel(); 0054 bool isWorking(); 0055 QString errorMessage() const; 0056 State state() const; 0057 QVariantList availableServices() const; 0058 0059 Q_SIGNALS: 0060 void isWorkingChanged(); 0061 void errorMessageChanged(); 0062 void wizardFinished(const QString &username, const QString &password, const QVariantMap &data); 0063 void stateChanged(); 0064 void wizardCancelled(); 0065 0066 private Q_SLOTS: 0067 void fileChecked(KJob *job); 0068 void dataReceived(KIO::Job *job, const QByteArray &data); 0069 void authCheckResult(KJob *job); 0070 0071 private: 0072 void checkServer(const QUrl &url); 0073 void figureOutServer(const QUrl &url); 0074 void setWorking(bool start); 0075 void serverCheckResult(bool result); 0076 0077 QByteArray m_json; 0078 QString m_errorMessage; 0079 QString m_server; 0080 QString m_username; 0081 QString m_password; 0082 QStringList m_disabledServices; 0083 bool m_isWorking; 0084 State m_state = Server; 0085 }; 0086 0087 #endif // QMLHELPER_H