1 /**
2  * \file importdialog.h
3  * Import dialog.
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 17 Sep 2003
8  *
9  * Copyright (C) 2003-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 <QScopedPointer>
31 #include "frame.h"
32 
33 class IPlatformTools;
34 class QString;
35 class QPushButton;
36 class QComboBox;
37 class QLineEdit;
38 class QCheckBox;
39 class QSpinBox;
40 class QTableView;
41 class QLabel;
42 class TrackDataModel;
43 class GenreModel;
44 class ServerTrackImportDialog;
45 class ServerImporter;
46 class ServerImportDialog;
47 class TextImportDialog;
48 class TagImportDialog;
49 class ImportTrackDataVector;
50 class FrameCollection;
51 class FreedbConfig;
52 class ServerTrackImporter;
53 
54 /**
55  * Import dialog.
56  */
57 class ImportDialog : public QDialog {
58   Q_OBJECT
59 public:
60   /**
61    * Constructor.
62    *
63    * @param platformTools platform tools
64    * @param parent        parent widget
65    * @param caption       dialog title
66    * @param genreModel    genre model
67    * @param trackDataModel track data to be filled with imported values,
68    *                      is passed with durations of files set
69    * @param importers     server importers
70    * @param trackImporters server track importers
71    */
72   ImportDialog(IPlatformTools* platformTools,
73                QWidget* parent, QString& caption,
74                TrackDataModel* trackDataModel,
75                GenreModel* genreModel,
76                const QList<ServerImporter*>& importers,
77                const QList<ServerTrackImporter*>& trackImporters);
78 
79   /**
80    * Destructor.
81    */
82   virtual ~ImportDialog() override;
83 
84   /**
85    * Shows the dialog as a modeless dialog.
86    *
87    * @param importerIndex index of importer to use, -1 for none
88    */
89   void showWithSubDialog(int importerIndex);
90 
91   /**
92    * Clear dialog data.
93    */
94   void clear();
95 
96   /**
97    * Get import destination.
98    *
99    * @return TagV1, TagV2 or TagV2V1 for ID3v1, ID3v2 or both.
100    */
101   Frame::TagVersion getDestination() const;
102 
103 private slots:
104   /**
105    * Show help.
106    */
107   void showHelp();
108 
109   /**
110    * Save the local settings to the configuration.
111    */
112   void saveConfig();
113 
114   /**
115    * Called when the maximum time difference value is changed.
116    */
117   void maxDiffChanged();
118 
119   /**
120    * Move a table row.
121    *
122    * The first parameter @a section is not used.
123    * @param fromIndex index of position moved from
124    * @param toIndex   index of position moved to
125    */
126   void moveTableRow(int, int fromIndex, int toIndex);
127 
128   /**
129    * Import from server and preview in table.
130    */
131   void fromServer();
132 
133   /**
134    * Import from text.
135    */
136   void fromText();
137 
138   /**
139    * Import from tags.
140    */
141   void fromTags();
142 
143   /**
144    * Show fields to import in text as preview in table.
145    */
146   void showPreview();
147 
148   /**
149    * Called when server import dialog is closed.
150    */
151   void onServerImportDialogClosed();
152 
153   /**
154    * Match import data with length.
155    */
156   void matchWithLength();
157 
158   /**
159    * Match import data with track number.
160    */
161   void matchWithTrack();
162 
163   /**
164    * Match import data with title.
165    */
166   void matchWithTitle();
167 
168   /**
169    * Hide subdialogs.
170    */
171   void hideSubdialogs();
172 
173   /**
174    * Called when the destination combo box value is changed.
175    */
176   void changeTagDestination();
177 
178   /**
179    * Display custom context menu for horizontal table header.
180    *
181    * @param pos position where context menu is drawn on screen
182    */
183   void showTableHeaderContextMenu(const QPoint& pos);
184 
185   /**
186    * Toggle visibility of table column.
187    *
188    * @param visible true to make column visible
189    */
190   void toggleTableColumnVisibility(bool visible);
191 
192 private:
193   /**
194    * Get time difference check configuration.
195    *
196    * @param enable  true if check is enabled
197    * @param maxDiff maximum allowed time difference
198    */
199   void getTimeDifferenceCheck(bool& enable, int& maxDiff) const;
200 
201   /**
202    * Display server import dialog.
203    *
204    * @param importerIdx importer index, if invalid but not negative the
205    *                    MusicBrainz Fingerprint dialog is displayed
206    */
207   void displayServerImportDialog(int importerIdx);
208 
209   /**
210    * Display server import dialog.
211    *
212    * @param source import source
213    */
214   void displayServerImportDialog(ServerImporter* source);
215 
216   /**
217    * Import from track server and preview in table.
218    *
219    * @param source import source
220    */
221   void displayServerTrackImportDialog(ServerTrackImporter* source);
222 
223   IPlatformTools* m_platformTools;
224   /** Index of importer for subdialog to open when starting, -1 for none */
225   int m_autoStartSubDialog;
226   /** Mask for visibility of optional columns */
227   quint64 m_columnVisibility;
228   /** Preview table */
229   QTableView* m_trackDataTable;
230   /** Track data model */
231   TrackDataModel* m_trackDataModel;
232   /** Accuracy value */
233   QLabel* m_accuracyPercentLabel;
234   /** URL of cover art to be imported */
235   QLabel* m_coverArtUrlLabel;
236   /** combobox with import servers */
237   QComboBox* m_serverComboBox;
238   /** combobox with import destinations */
239   QComboBox* m_destComboBox;
240   QCheckBox* m_mismatchCheckBox;
241   QSpinBox* m_maxDiffSpinBox;
242   /** importers for different servers */
243   QList<ServerImporter*> m_importers;
244   /** track importers for different servers */
245   QList<ServerTrackImporter*> m_trackImporters;
246   /** Server track import dialog */
247   QScopedPointer<ServerTrackImportDialog> m_serverTrackImportDialog;
248   /** Server import dialog */
249   QScopedPointer<ServerImportDialog> m_serverImportDialog;
250   /** Text import dialog */
251   QScopedPointer<TextImportDialog> m_textImportDialog;
252   /** Tag import dialog */
253   QScopedPointer<TagImportDialog> m_tagImportDialog;
254 };
255