1 /**
2  * \file serverimportdialog.h
3  * Generic dialog to import from a server.
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 09 Oct 2006
8  *
9  * Copyright (C) 2006-2018  Urs Fleisch
10  *
11  * This file is part of Kid3.
12  *
13  * Kid3 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * Kid3 is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #pragma once
28 
29 #include <QDialog>
30 #include <QString>
31 
32 class QLineEdit;
33 class QLabel;
34 class QComboBox;
35 class QPushButton;
36 class QCheckBox;
37 class QStatusBar;
38 class QListView;
39 class ServerImporter;
40 class ServerImporterConfig;
41 class ImportTrackDataVector;
42 
43 /**
44  * Generic dialog to import from an external source.
45  */
46 class ServerImportDialog : public QDialog {
47   Q_OBJECT
48 public:
49   /**
50    * Constructor.
51    *
52    * @param parent  parent widget
53    */
54   explicit ServerImportDialog(QWidget* parent);
55 
56   /**
57    * Destructor.
58    */
59   virtual ~ServerImportDialog() override = default;
60 
61   /**
62    * Set importer to be used.
63    *
64    * @param source  import source to use
65    */
66   void setImportSource(ServerImporter* source);
67 
68   /**
69    * Get string with server and port.
70    *
71    * @return "servername:port".
72    */
73   QString getServer() const;
74 
75   /**
76    * Set string with server and port.
77    *
78    * @param srv "servername:port"
79    */
80   void setServer(const QString& srv);
81 
82   /**
83    * Get string with CGI path.
84    *
85    * @return CGI path, e.g. "/~cddb/cddb.cgi".
86    */
87   QString getCgiPath() const;
88 
89   /**
90    * Set string with CGI path.
91    *
92    * @param cgi CGI path, e.g. "/~cddb/cddb.cgi".
93    */
94   void setCgiPath(const QString& cgi);
95 
96   /**
97    * Get token to access API server.
98    * @return token.
99    */
100   QString getToken() const;
101 
102   /**
103    * Set token to access API server.
104    * @param token access token
105    */
106   void setToken(const QString& token);
107 
108   /**
109    * Get standard tags option.
110    *
111    * @return true if standard tags are enabled.
112    */
113   bool getStandardTags() const;
114 
115   /**
116    * Set standard tags option.
117    *
118    * @param enable true if standard tags are enabled
119    */
120   void setStandardTags(bool enable);
121 
122   /**
123    * Get additional tags option.
124    *
125    * @return true if additional tags are enabled.
126    */
127   bool getAdditionalTags() const;
128 
129   /**
130    * Set additional tags option.
131    *
132    * @param enable true if additional tags are enabled
133    */
134   void setAdditionalTags(bool enable);
135 
136   /**
137    * Get cover art option.
138    *
139    * @return true if cover art are enabled.
140    */
141   bool getCoverArt() const;
142 
143   /**
144    * Set cover art option.
145    *
146    * @param enable true if cover art are enabled
147    */
148   void setCoverArt(bool enable);
149 
150   /**
151    * Set a find string from artist and album information.
152    *
153    * @param artist artist
154    * @param album  album
155    */
156   void setArtistAlbum(const QString& artist, const QString& album);
157 
158 private slots:
159   /**
160    * Query a search for a keyword from the server.
161    */
162   void slotFind();
163 
164   /**
165    * Process finished find request.
166    *
167    * @param searchStr search data received
168    */
169   void slotFindFinished(const QByteArray& searchStr);
170 
171   /**
172    * Process finished album data.
173    *
174    * @param albumStr album track data received
175    */
176   void slotAlbumFinished(const QByteArray& albumStr);
177 
178   /**
179    * Request track list from server.
180    *
181    * @param category category, e.g. "release"
182    * @param id internal ID
183    */
184   void requestTrackList(const QString& category, const QString& id);
185 
186   /**
187    * Request track list from server.
188    *
189    * @param index model index of list containing an AlbumListItem
190    */
191   void requestTrackList(const QModelIndex& index);
192 
193   /**
194    * Save the local settings to the configuration.
195    */
196   void saveConfig();
197 
198   /**
199    * Show help.
200    */
201   void showHelp();
202 
203   /**
204    * Display message in status bar.
205    *
206    * @param msg status message
207    */
208   void showStatusMessage(const QString& msg);
209 
210 signals:
211   /**
212    * Emitted when the m_trackDataVector was updated with new imported data.
213    */
214   void trackDataUpdated();
215 
216 protected:
217   QListView* m_albumListBox; /**< list box with albums to select */
218 
219 private:
220   /**
221    * Get the local configuration.
222    *
223    * @param cfg configuration
224    */
225   void getImportSourceConfig(ServerImporterConfig* cfg) const;
226 
227   QComboBox* m_artistLineEdit;
228   QComboBox* m_albumLineEdit;
229   QPushButton* m_findButton;
230   QLabel* m_serverLabel;
231   QComboBox* m_serverComboBox;
232   QLabel* m_cgiLabel;
233   QLineEdit* m_cgiLineEdit;
234   QLabel* m_tokenLabel;
235   QLineEdit* m_tokenLineEdit;
236   QCheckBox* m_standardTagsCheckBox;
237   QCheckBox* m_additionalTagsCheckBox;
238   QCheckBox* m_coverArtCheckBox;
239   QPushButton* m_helpButton;
240   QPushButton* m_saveButton;
241   QStatusBar* m_statusBar;
242   ServerImporter* m_source;
243 };
244