File indexing completed on 2024-10-06 12:54:05
0001 // SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include <QObject> 0007 #include <QUrl> 0008 0009 namespace Quotient 0010 { 0011 class Connection; 0012 } 0013 0014 /** 0015 * @class Login 0016 * 0017 * A helper class for logging into a Matrix account. 0018 */ 0019 class Login : public QObject 0020 { 0021 Q_OBJECT 0022 0023 /** 0024 * @brief Whether the home server for the account is reachable. 0025 */ 0026 Q_PROPERTY(bool homeserverReachable READ homeserverReachable NOTIFY homeserverReachableChanged) 0027 0028 /** 0029 * @brief Whether the connection to the home server is being tested. 0030 * 0031 * True if NeoChat is trying to resolve the home server, false if not started 0032 * or complete. 0033 */ 0034 Q_PROPERTY(bool testing READ testing NOTIFY testingChanged) 0035 0036 /** 0037 * @brief The Matrix ID of the account that is being logged into. 0038 */ 0039 Q_PROPERTY(QString matrixId READ matrixId WRITE setMatrixId NOTIFY matrixIdChanged) 0040 0041 /** 0042 * @brief The password entered by the user to login to the account. 0043 */ 0044 Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) 0045 0046 /** 0047 * @brief The device name to assign to this session. 0048 */ 0049 Q_PROPERTY(QString deviceName READ deviceName WRITE setDeviceName NOTIFY deviceNameChanged) 0050 0051 /** 0052 * @brief Whether the home server of the account supports single sign on login. 0053 */ 0054 Q_PROPERTY(bool supportsSso READ supportsSso NOTIFY loginFlowsChanged STORED false) 0055 0056 /** 0057 * @brief Whether the home server of the account supports password login. 0058 */ 0059 Q_PROPERTY(bool supportsPassword READ supportsPassword NOTIFY loginFlowsChanged STORED false) 0060 0061 /** 0062 * @brief The URL for the single sign on session. 0063 */ 0064 Q_PROPERTY(QUrl ssoUrl READ ssoUrl NOTIFY ssoUrlChanged) 0065 0066 /** 0067 * @brief Whether login process is ongoing. 0068 */ 0069 Q_PROPERTY(bool isLoggingIn READ isLoggingIn NOTIFY isLoggingInChanged) 0070 0071 /** 0072 * @brief Whether login has successfully completed. 0073 */ 0074 Q_PROPERTY(bool isLoggedIn READ isLoggedIn NOTIFY isLoggedInChanged) 0075 0076 public: 0077 explicit Login(QObject *parent = nullptr); 0078 0079 Q_INVOKABLE void init(); 0080 0081 bool homeserverReachable() const; 0082 0083 QString matrixId() const; 0084 void setMatrixId(const QString &matrixId); 0085 0086 QString password() const; 0087 void setPassword(const QString &password); 0088 0089 QString deviceName() const; 0090 void setDeviceName(const QString &deviceName); 0091 0092 bool supportsPassword() const; 0093 bool supportsSso() const; 0094 0095 bool testing() const; 0096 0097 QUrl ssoUrl() const; 0098 0099 bool isLoggingIn() const; 0100 0101 bool isLoggedIn() const; 0102 0103 Q_INVOKABLE void login(); 0104 Q_INVOKABLE void loginWithSso(); 0105 0106 Q_SIGNALS: 0107 void homeserverReachableChanged(); 0108 void testHomeserverFinished(); 0109 void matrixIdChanged(); 0110 void passwordChanged(); 0111 void deviceNameChanged(); 0112 void loginFlowsChanged(); 0113 void ssoUrlChanged(); 0114 void connected(); 0115 void errorOccured(const QString &message); 0116 void testingChanged(); 0117 void isLoggingInChanged(); 0118 void isLoggedInChanged(); 0119 0120 private: 0121 void setHomeserverReachable(bool reachable); 0122 0123 bool m_homeserverReachable; 0124 QString m_matrixId; 0125 QString m_password; 0126 QString m_deviceName; 0127 bool m_supportsSso = false; 0128 bool m_supportsPassword = false; 0129 Quotient::Connection *m_connection = nullptr; 0130 QUrl m_ssoUrl; 0131 bool m_testing = false; 0132 bool m_isLoggingIn = false; 0133 bool m_isLoggedIn = false; 0134 };