1 /**
2  * \file servertrackimportdialog.h
3  * Generic dialog for track based import from a server.
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 13 Sep 2005
8  *
9  * Copyright (C) 2005-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 #include <QVector>
32 
33 class QTableView;
34 class QLineEdit;
35 class QLabel;
36 class QComboBox;
37 class QPushButton;
38 class QCheckBox;
39 class QStatusBar;
40 class QModelIndex;
41 class StandardTableModel;
42 class TrackDataModel;
43 class ImportTrackData;
44 class ImportTrackDataVector;
45 class ServerTrackImporter;
46 
47 /**
48  * Generic dialog for track based import from a server.
49  */
50 class ServerTrackImportDialog : public QDialog {
51   Q_OBJECT
52 
53 public:
54   /**
55    * Constructor.
56    *
57    * @param parent          parent widget
58    * @param trackDataModel track data to be filled with imported values,
59    *                        is passed with filenames set
60    */
61   ServerTrackImportDialog(QWidget* parent,
62                           TrackDataModel* trackDataModel);
63 
64   /**
65    * Destructor.
66    */
67   virtual ~ServerTrackImportDialog() override;
68 
69   /**
70    * Set importer to be used.
71    *
72    * @param source  import source to use
73    */
74   void setImportSource(ServerTrackImporter* source);
75 
76   /**
77    * Initialize the table model.
78    * Has to be called before reusing the dialog with new track data.
79    */
80   void initTable();
81 
82   /**
83    * Get string with server and port.
84    *
85    * @return "servername:port".
86    */
87   QString getServer() const;
88 
89   /**
90    * Set string with server and port.
91    *
92    * @param srv "servername:port"
93    */
94   void setServer(const QString& srv);
95 
96 signals:
97   /**
98    * Emitted when the m_trackDataModel was updated with new imported data.
99    */
100   void trackDataUpdated();
101 
102 public slots:
103   /**
104    * Shows the dialog as a modal dialog.
105    */
106   virtual int exec() override;
107 
108 protected slots:
109   /**
110    * Hides the dialog and sets the result to QDialog::Accepted.
111    */
112   virtual void accept() override;
113 
114   /**
115    * Hides the dialog and sets the result to QDialog::Rejected.
116    */
117   virtual void reject() override;
118 
119 private slots:
120   /**
121    * Apply imported data.
122    */
123   void apply();
124 
125   /**
126    * Set the status of a file.
127    *
128    * @param index  index of file
129    * @param status status string
130    */
131   void setFileStatus(int index, const QString& status);
132 
133   /**
134    * Update the track data combo box of a file.
135    *
136    * @param index  index of file
137    */
138   void updateFileTrackData(int index);
139 
140   /**
141    * Set result list for a file.
142    *
143    * @param index           index of file
144    * @param trackDataVector result list
145    */
146   void setResults(int index, ImportTrackDataVector& trackDataVector);
147 
148   /**
149    * Save the local settings to the configuration.
150    */
151   void saveConfig();
152 
153   /**
154    * Show help.
155    */
156   void showHelp();
157 
158   /**
159    * Show the name of the current track in the status bar.
160    *
161    * @param index model index
162    */
163   void showFilenameInStatusBar(const QModelIndex& index);
164 
165 private:
166   /**
167    * Clear all results.
168    */
169   void clearResults();
170 
171  /**
172   * Create and start the track import client.
173   */
174   void startClient();
175 
176   /**
177    * Stop and destroy the track import client.
178    */
179   void stopClient();
180 
181   QLabel* m_serverLabel;
182   QComboBox* m_serverComboBox;
183   QTableView* m_albumTable;
184   QPushButton* m_helpButton;
185   QPushButton* m_saveButton;
186   StandardTableModel* m_albumTableModel;
187   QStatusBar* m_statusBar;
188   ServerTrackImporter* m_client;
189   TrackDataModel* m_trackDataModel;
190   QVector<ImportTrackDataVector> m_trackResults;
191 };
192