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

0001 /**
0002  * \file serverimporter.h
0003  * Generic baseclass to import from a server.
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 <QString>
0030 #include "standardtablemodel.h"
0031 #include "importclient.h"
0032 
0033 class ServerImporterConfig;
0034 class ImportClient;
0035 class TrackDataModel;
0036 
0037 /**
0038  * Model containing list of albums which can be imported.
0039  */
0040 class KID3_CORE_EXPORT AlbumListModel : public StandardTableModel {
0041 public:
0042   /**
0043    * Constructor.
0044    * @param parent parent object
0045    */
0046   explicit AlbumListModel(QObject* parent = nullptr);
0047 
0048   /**
0049    * Get an album item.
0050    * @param row model row
0051    * @param text the text is returned here
0052    * @param category the category is returned here
0053    * @param id the internal ID is returned here
0054    */
0055   void getItem(int row, QString& text, QString& category, QString& id) const;
0056 
0057   /**
0058    * Append an album item.
0059    * @param text display test
0060    * @param category category, e.g. "release"
0061    * @param id internal ID
0062    */
0063   void appendItem(const QString& text,
0064                   const QString& category, const QString& id);
0065 };
0066 
0067 /**
0068  * Generic baseclass to import from an external source.
0069  */
0070 class KID3_CORE_EXPORT ServerImporter : public ImportClient {
0071   Q_OBJECT
0072 
0073 public:
0074   /**
0075    * Constructor.
0076    *
0077    * @param netMgr network access manager
0078    * @param trackDataModel track data to be filled with imported values
0079    */
0080   ServerImporter(QNetworkAccessManager* netMgr,
0081                  TrackDataModel *trackDataModel);
0082 
0083   /**
0084    * Destructor.
0085    */
0086   ~ServerImporter() override = default;
0087 
0088   /**
0089    * Name of import source.
0090    * @return name.
0091    */
0092   virtual const char* name() const = 0;
0093 
0094   /** NULL-terminated array of server strings, 0 if not used */
0095   virtual const char** serverList() const;
0096 
0097   /** default server, 0 to disable */
0098   virtual const char* defaultServer() const;
0099 
0100   /** default CGI path, 0 to disable */
0101   virtual const char* defaultCgiPath() const;
0102 
0103   /** anchor to online help, 0 to disable */
0104   virtual const char* helpAnchor() const;
0105 
0106   /** configuration, 0 if not used */
0107   virtual ServerImporterConfig* config() const;
0108 
0109   /** additional tags option, false if not used */
0110   virtual bool additionalTags() const;
0111 
0112   /**
0113    * Parse result of find request and populate m_albumListBox with results.
0114    * This method has to be reimplemented for the specific result data.
0115    *
0116    * @param searchStr search data received
0117    */
0118   virtual void parseFindResults(const QByteArray& searchStr) = 0;
0119 
0120   /**
0121    * Parse result of album request and populate m_trackDataModel with results.
0122    * This method has to be reimplemented for the specific result data.
0123    *
0124    * @param albumStr album data received
0125    */
0126   virtual void parseAlbumResults(const QByteArray& albumStr) = 0;
0127 
0128   /**
0129    * Get model with album list.
0130    *
0131    * @return album list item model.
0132    */
0133   AlbumListModel* getAlbumListModel() const { return m_albumListModel; }
0134 
0135   /**
0136    * Clear model data.
0137    */
0138   void clear();
0139 
0140   /**
0141    * Get standard tags option.
0142    *
0143    * @return true if standard tags are enabled.
0144    */
0145   bool getStandardTags() const { return m_standardTagsEnabled; }
0146 
0147   /**
0148    * Set standard tags option.
0149    *
0150    * @param enable true if standard tags are enabled
0151    */
0152   void setStandardTags(bool enable) { m_standardTagsEnabled = enable; }
0153 
0154   /**
0155    * Get additional tags option.
0156    *
0157    * @return true if additional tags are enabled.
0158    */
0159   bool getAdditionalTags() const { return m_additionalTagsEnabled; }
0160 
0161   /**
0162    * Set additional tags option.
0163    *
0164    * @param enable true if additional tags are enabled
0165    */
0166   void setAdditionalTags(bool enable) { m_additionalTagsEnabled = enable; }
0167 
0168   /**
0169    * Get cover art option.
0170    *
0171    * @return true if cover art are enabled.
0172    */
0173   bool getCoverArt() const { return m_coverArtEnabled; }
0174 
0175   /**
0176    * Set cover art option.
0177    *
0178    * @param enable true if cover art are enabled
0179    */
0180   void setCoverArt(bool enable) { m_coverArtEnabled = enable; }
0181 
0182   /**
0183    * Replace HTML entities in a string.
0184    *
0185    * @param str string with HTML entities (e.g. &quot;)
0186    *
0187    * @return string with replaced HTML entities.
0188    */
0189   static QString replaceHtmlEntities(QString str);
0190 
0191   /**
0192    * Replace HTML entities and remove HTML tags.
0193    *
0194    * @param str string containing HTML
0195    *
0196    * @return clean up string
0197    */
0198   static QString removeHtml(QString str);
0199 
0200 protected:
0201   AlbumListModel* m_albumListModel; /**< albums to select */
0202   TrackDataModel* m_trackDataModel; /**< model with tracks to import */
0203 
0204 private:
0205   bool m_standardTagsEnabled;
0206   bool m_additionalTagsEnabled;
0207   bool m_coverArtEnabled;
0208 };