File indexing completed on 2025-01-05 03:53:36
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2011-03-22 0007 * Description : a Iface C++ interface 0008 * 0009 * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2011 by Alexandre Mendes <alex dot mendes1988 at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "mediawiki_logout.h" 0017 0018 // Qt includes 0019 0020 #include <QDateTime> 0021 #include <QTimer> 0022 #include <QUrl> 0023 #include <QUrlQuery> 0024 #include <QXmlStreamReader> 0025 #include <QNetworkCookie> 0026 #include <QNetworkReply> 0027 #include <QNetworkRequest> 0028 0029 // Local includes 0030 0031 #include "mediawiki_iface.h" 0032 #include "mediawiki_job_p.h" 0033 0034 namespace MediaWiki 0035 { 0036 0037 class Q_DECL_HIDDEN LogoutPrivate : public JobPrivate 0038 { 0039 public: 0040 0041 explicit LogoutPrivate(Iface& MediaWiki) 0042 : JobPrivate(MediaWiki) 0043 { 0044 } 0045 }; 0046 0047 Logout::Logout(Iface& MediaWiki, QObject* const parent) 0048 : Job(*new LogoutPrivate(MediaWiki), parent) 0049 { 0050 } 0051 0052 Logout::~Logout() 0053 { 0054 } 0055 0056 void Logout::start() 0057 { 0058 QTimer::singleShot(0, this, SLOT(doWorkSendRequest())); 0059 } 0060 0061 void Logout::doWorkSendRequest() 0062 { 0063 Q_D(Logout); 0064 0065 QUrl url = d->MediaWiki.url(); 0066 QUrlQuery query; 0067 query.addQueryItem(QStringLiteral("format"), QStringLiteral("xml")); 0068 query.addQueryItem(QStringLiteral("action"), QStringLiteral("logout")); 0069 url.setQuery(query); 0070 0071 QByteArray cookie = ""; 0072 QList<QNetworkCookie> MediaWikiCookies = d->manager->cookieJar()->cookiesForUrl(d->MediaWiki.url()); 0073 0074 for (int i = 0 ; i < MediaWikiCookies.size() ; ++i) 0075 { 0076 cookie += MediaWikiCookies.at(i).toRawForm(QNetworkCookie::NameAndValueOnly); 0077 cookie += ';'; 0078 } 0079 0080 // Set the request 0081 QNetworkRequest request(url); 0082 request.setRawHeader("User-Agent", d->MediaWiki.userAgent().toUtf8()); 0083 request.setRawHeader("Cookie", cookie); 0084 0085 // Delete cookies 0086 d->manager->setCookieJar(new QNetworkCookieJar); 0087 0088 // Send the request 0089 d->reply = d->manager->get(request); 0090 connectReply(); 0091 0092 connect(d->reply, SIGNAL(finished()), 0093 this, SLOT(doWorkProcessReply())); 0094 } 0095 0096 void Logout::doWorkProcessReply() 0097 { 0098 Q_D(Logout); 0099 0100 disconnect(d->reply, SIGNAL(finished()), 0101 this, SLOT(doWorkProcessReply())); 0102 0103 this->setError(KJob::NoError); 0104 d->reply->close(); 0105 d->reply->deleteLater(); 0106 emitResult(); 0107 } 0108 0109 } // namespace MediaWiki 0110 0111 #include "moc_mediawiki_logout.cpp"