File indexing completed on 2025-02-02 04:51:39
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "customsoundslistjob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 #include <QJsonDocument> 0011 #include <QJsonObject> 0012 #include <QNetworkReply> 0013 #include <QUrlQuery> 0014 using namespace RocketChatRestApi; 0015 CustomSoundsListJob::CustomSoundsListJob(QObject *parent) 0016 : RestApiAbstractJob(parent) 0017 { 0018 } 0019 0020 CustomSoundsListJob::~CustomSoundsListJob() = default; 0021 0022 bool CustomSoundsListJob::start() 0023 { 0024 if (!canStart()) { 0025 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "Impossible to start CustomSoundsJob job"; 0026 deleteLater(); 0027 return false; 0028 } 0029 submitGetRequest(); 0030 addStartRestApiInfo(QByteArrayLiteral("CustomSoundsJob: Ask custom sounds info")); 0031 0032 return true; 0033 } 0034 0035 void CustomSoundsListJob::onGetRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0036 { 0037 const QJsonObject replyObject = replyJson.object(); 0038 0039 if (replyObject[QLatin1String("success")].toBool()) { 0040 addLoggerInfo(QByteArrayLiteral("CustomSoundsJob done: ") + replyJson.toJson(QJsonDocument::Indented)); 0041 Q_EMIT customSoundsListDone(replyObject); // TODO fix return value! 0042 } else { 0043 emitFailedMessage(replyErrorString, replyObject); 0044 addLoggerWarning(QByteArrayLiteral("CustomSoundsJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0045 } 0046 } 0047 0048 bool CustomSoundsListJob::requireHttpAuthentication() const 0049 { 0050 return true; 0051 } 0052 0053 QNetworkRequest CustomSoundsListJob::request() const 0054 { 0055 QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::CustomSoundsList); 0056 0057 QUrlQuery queryUrl; 0058 addQueryParameter(queryUrl); 0059 url.setQuery(queryUrl); 0060 QNetworkRequest req(url); 0061 addAuthRawHeader(req); 0062 return req; 0063 } 0064 0065 bool CustomSoundsListJob::hasQueryParameterSupport() const 0066 { 0067 return true; 0068 } 0069 0070 #include "moc_customsoundslistjob.cpp"