File indexing completed on 2024-05-19 04:55:59

0001 /**
0002  * \file importclient.h
0003  * Client to connect to server with import data.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 09 Oct 2006
0008  *
0009  * Copyright (C) 2006-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 "httpclient.h"
0030 #include "kid3api.h"
0031 
0032 class ServerImporterConfig;
0033 
0034 /**
0035  * Client to connect to server with import data.
0036  */
0037 class KID3_CORE_EXPORT ImportClient : public HttpClient {
0038   Q_OBJECT
0039 public:
0040   /**
0041    * Constructor.
0042    *
0043    * @param netMgr  network access manager
0044    */
0045   explicit ImportClient(QNetworkAccessManager* netMgr);
0046 
0047   /**
0048    * Destructor.
0049    */
0050   ~ImportClient() override = default;
0051 
0052   /**
0053    * Send a query command to search on the server.
0054    * This method has to be reimplemented for the specific search command.
0055    *
0056    * @param cfg      import source configuration
0057    * @param artist   artist to search
0058    * @param album    album to search
0059    */
0060   virtual void sendFindQuery(
0061     const ServerImporterConfig* cfg,
0062     const QString& artist, const QString& album) = 0;
0063 
0064   /**
0065    * Send a query command to fetch the track list
0066    * from the server.
0067    * This method has to be reimplemented for the specific server.
0068    *
0069    * @param cfg      import source configuration
0070    * @param cat      category
0071    * @param id       ID
0072    */
0073   virtual void sendTrackListQuery(
0074     const ServerImporterConfig* cfg, const QString& cat, const QString& id) = 0;
0075 
0076   /**
0077    * Find artist, album on server.
0078    *
0079    * @param cfg    import source configuration
0080    * @param artist artist to search
0081    * @param album  album to search
0082    */
0083   void find(const ServerImporterConfig* cfg,
0084             const QString& artist, const QString& album);
0085 
0086   /**
0087    * Request track list from server.
0088    *
0089    * @param cfg import source configuration
0090    * @param cat category
0091    * @param id  ID
0092    */
0093   void getTrackList(const ServerImporterConfig* cfg,
0094                     const QString& cat, const QString& id);
0095 
0096  /**
0097   * Encode a query in an URL.
0098   * The query is percent-encoded with spaces collapsed and replaced by '+'.
0099   *
0100   * @param query query to encode
0101   *
0102   * @return encoded query.
0103   */
0104   static QString encodeUrlQuery(const QString& query);
0105 
0106 signals:
0107   /**
0108    * Emitted when find request finished.
0109    * Parameter: text containing result of find request
0110    */
0111   void findFinished(const QByteArray&);
0112 
0113   /**
0114    * Emitted when album track data request finished.
0115    * Parameter: text containing result of album request
0116    */
0117   void albumFinished(const QByteArray&);
0118 
0119 private slots:
0120   /**
0121    * Handle response when request is finished.
0122    * The data is sent to other objects via signals.
0123    *
0124    * @param rcvStr received data
0125    */
0126   void requestFinished(const QByteArray& rcvStr);
0127 
0128 private:
0129   /** type of current request */
0130   enum RequestType {
0131     RT_None,
0132     RT_Find,
0133     RT_Album
0134   } m_requestType;
0135 };