File indexing completed on 2024-05-19 04:56:01
0001 /** 0002 * \file downloadclient.h 0003 * Client to download via http. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 12 Jun 2011 0008 * 0009 * Copyright (C) 2011-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include <QString> 0030 #include "httpclient.h" 0031 0032 /** 0033 * Client to download via HTTP. 0034 * @see DownloadDialog 0035 */ 0036 class KID3_CORE_EXPORT DownloadClient : public HttpClient { 0037 Q_OBJECT 0038 public: 0039 /** 0040 * Constructor. 0041 * 0042 * @param netMgr network access manager 0043 */ 0044 explicit DownloadClient(QNetworkAccessManager* netMgr); 0045 0046 /** 0047 * Destructor. 0048 */ 0049 ~DownloadClient() override = default; 0050 0051 /** 0052 * Send a download request. 0053 * 0054 * @param url URL of resource to download 0055 */ 0056 void startDownload(const QUrl& url); 0057 0058 /** 0059 * Get the URL of an image file. 0060 * The input URL is transformed using the match picture URL table to 0061 * get the URL of an image file. 0062 * 0063 * @param url URL from image drag 0064 * 0065 * @return URL of image file, empty if no image URL found. 0066 */ 0067 static QUrl getImageUrl(const QUrl& url); 0068 0069 public slots: 0070 /** 0071 * Cancel a download. 0072 */ 0073 void cancelDownload(); 0074 0075 signals: 0076 /** 0077 * Emitted when download is started 0078 * @param url URL of download 0079 */ 0080 void downloadStarted(const QString& url); 0081 0082 /** 0083 * Emitted when download finished. 0084 * @param data bytes containing download 0085 * @param contentType content type 0086 * @param url URL 0087 */ 0088 void downloadFinished(const QByteArray& data, const QString& contentType, 0089 const QString& url); 0090 0091 /** 0092 * Emitted when a download is aborted. 0093 */ 0094 void aborted(); 0095 0096 private slots: 0097 /** 0098 * Handle response when request is finished. 0099 * downloadFinished() is emitted. 0100 * 0101 * @param data received data 0102 */ 0103 void requestFinished(const QByteArray& data); 0104 0105 private: 0106 QUrl m_url; 0107 bool m_canceled; 0108 };