File indexing completed on 2024-05-12 05:22:15
0001 /* 0002 * This file is part of LibKGAPI 0003 * 0004 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #pragma once 0010 0011 #include "job.h" 0012 #include "kgapicore_export.h" 0013 0014 class QWidget; 0015 0016 namespace KGAPI2 0017 { 0018 0019 /** 0020 * @headerfile authjob.h 0021 * @brief A job to authenticate against Google and fetch tokens 0022 * 0023 * This job can be either used to refresh expired tokens (this is usually done 0024 * automatically by Job implementation), or to request tokens for a new account. 0025 * 0026 * In the latter case, the AuthJob will automatically open a browser window 0027 * where user has to provide Google account credentials and grant access to all 0028 * requested scopes (@see Account::scopes). 0029 * 0030 * @author Daniel Vrátil <dvratil@redhat.com> 0031 * @since 2.0 0032 */ 0033 class KGAPICORE_EXPORT AuthJob : public KGAPI2::Job 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 /** 0039 * @brief Creates a new authentication job 0040 * 0041 * When constructed without a parent, or with a non-QWidget parent, the 0042 * job might pop up the authentication dialog. 0043 * 0044 * @param account Account to authenticate. 0045 * @param apiKey Application API key 0046 * @param secretKey Application secret API key 0047 * @param parent 0048 */ 0049 explicit AuthJob(const AccountPtr &account, const QString &apiKey, const QString &secretKey, QObject *parent = nullptr); 0050 0051 /** 0052 * @brief Destructor 0053 */ 0054 ~AuthJob() override; 0055 0056 /** 0057 * @brief Returns reauthenticated account. 0058 * 0059 * @returns An account pointer passed to the AuthJob() constructor with 0060 * all fields filled and validated. When the job fails, the account 0061 * is unchanged. 0062 */ 0063 AccountPtr account() const; 0064 0065 /** 0066 * Sets the username that will be used when authenticate is called 0067 * 0068 * @param username username to use 0069 */ 0070 void setUsername(const QString &username); 0071 0072 /** 0073 * Sets the password that will be used when authenticate is called 0074 * 0075 * @param password password to use 0076 * @deprecated 0077 */ 0078 QT_DEPRECATED_X("It's no longer possible to prefill password") 0079 void setPassword(const QString &password); 0080 0081 protected: 0082 /** 0083 * @brief KGAPI2::Job::handleReply implementation 0084 * 0085 * @param reply 0086 * @param rawData 0087 */ 0088 void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override; 0089 0090 /** 0091 * @brief KGAPI2::Job::displayRequest implementation 0092 * 0093 * @param accessManager 0094 * @param request 0095 * @param data 0096 * @param contentType 0097 */ 0098 void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override; 0099 0100 /** 0101 * @brief KGAPI2::Job::start implementation 0102 */ 0103 void start() override; 0104 0105 private: 0106 class Private; 0107 QScopedPointer<Private> const d; 0108 friend class Private; 0109 }; 0110 0111 } // namespace KGAPI2