importdialog.cpp 18.3 KB
Newer Older
Urs Fleisch's avatar
Urs Fleisch committed
1
2
3
4
5
6
7
/**
 * \file importdialog.cpp
 * Import dialog.
 *
 * \b Project: Kid3
 * \author Urs Fleisch
 * \date 17 Sep 2003
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * Copyright (C) 2003-2007  Urs Fleisch
 *
 * This file is part of Kid3.
 *
 * Kid3 is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Kid3 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Urs Fleisch's avatar
Urs Fleisch committed
25
26
 */

Urs Fleisch's avatar
Urs Fleisch committed
27
#include "importdialog.h"
Urs Fleisch's avatar
Urs Fleisch committed
28
29
30
31
32
#include "config.h"
#ifdef CONFIG_USE_KDE
#include <kconfig.h>
#endif

Urs Fleisch's avatar
Urs Fleisch committed
33
34
35
36
37
38
#include <QLayout>
#include <QPushButton>
#include <QLabel>
#include <QCheckBox>
#include <QSpinBox>
#include <QString>
Urs Fleisch's avatar
Urs Fleisch committed
39
40
#include <QVBoxLayout>
#include <QHBoxLayout>
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <QComboBox>
#include <QLineEdit>
#include <QBitArray>
#include <QToolTip>
#include <QTableView>
#include <QHeaderView>
#include <QList>
#include <QGridLayout>
#include <QGroupBox>
#include <QDir>
#include "genres.h"
#include "freedbimporter.h"
#include "tracktypeimporter.h"
#include "musicbrainzreleaseimporter.h"
#include "discogsimporter.h"
#include "amazonimporter.h"
#include "serverimportdialog.h"
#include "textimportdialog.h"
59
#include "kid3.h"
60
61
62
63
64
#include "taggedfile.h"
#include "trackdata.h"
#include "trackdatamodel.h"
#include "frametablemodel.h"
#include "trackdatamatcher.h"
Urs Fleisch's avatar
Urs Fleisch committed
65
#include "qtcompatmac.h"
66
67
68
69
70
#include "config.h"
#ifdef HAVE_TUNEPIMP
#include "musicbrainzdialog.h"
#include "musicbrainzconfig.h"
#endif
Urs Fleisch's avatar
Urs Fleisch committed
71
72
73
74

/**
 * Constructor.
 *
Urs Fleisch's avatar
Urs Fleisch committed
75
76
77
78
 * @param parent        parent widget
 * @param caption       dialog title
 * @param trackDataList track data to be filled with imported values,
 *                      is passed with durations of files set
Urs Fleisch's avatar
Urs Fleisch committed
79
 */
Urs Fleisch's avatar
Urs Fleisch committed
80
ImportDialog::ImportDialog(QWidget* parent, QString& caption,
81
													 ImportTrackDataVector& trackDataList) :
82
	QDialog(parent), m_trackDataImported(false),
83
84
	m_autoStartSubDialog(ASD_None),
	m_trackDataVector(trackDataList)
Urs Fleisch's avatar
Urs Fleisch committed
85
{
86
	setObjectName("ImportDialog");
87
	setModal(true);
Urs Fleisch's avatar
Urs Fleisch committed
88
	setWindowTitle(caption);
Urs Fleisch's avatar
Urs Fleisch committed
89

90
91
92
93
94
95
96
97
98
99
100
	m_freedbImporter = 0;
	m_trackTypeImporter = 0;
	m_musicBrainzReleaseImporter = 0;
	m_discogsImporter = 0;
	m_amazonImporter = 0;
	m_serverImportDialog = 0;
	m_textImportDialog = 0;
#ifdef HAVE_TUNEPIMP
	m_musicBrainzDialog = 0;
#endif

Urs Fleisch's avatar
Urs Fleisch committed
101
	QVBoxLayout* vlayout = new QVBoxLayout(this);
Urs Fleisch's avatar
Urs Fleisch committed
102
103
	vlayout->setSpacing(6);
	vlayout->setMargin(6);
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

	m_trackDataModel = new TrackDataModel(this);
	m_trackDataTable = new QTableView(this);
	m_trackDataTable->setModel(m_trackDataModel);
	m_trackDataTable->resizeColumnsToContents();
	m_trackDataTable->verticalHeader()->setMovable(true);
	m_trackDataTable->horizontalHeader()->setMovable(true);
	m_trackDataTable->setItemDelegateForColumn(6, new FrameItemDelegate(this));
	connect(m_trackDataTable->verticalHeader(), SIGNAL(sectionMoved(int, int, int)),
					this, SLOT(moveTableRow(int, int, int)));
	vlayout->addWidget(m_trackDataTable);

	QWidget* butbox = new QWidget(this);
	QHBoxLayout* butlayout = new QHBoxLayout(butbox);
	butlayout->setMargin(0);
	butlayout->setSpacing(6);
	QPushButton* fileButton = new QPushButton(i18n("From F&ile/Clipboard..."),
																						butbox);
	fileButton->setAutoDefault(false);
	butlayout->addWidget(fileButton);
	QPushButton* serverButton = new QPushButton(i18n("&From Server:"), butbox);
	serverButton->setAutoDefault(false);
	butlayout->addWidget(serverButton);
	m_serverComboBox = new QComboBox(butbox);
	m_serverComboBox->setEditable(false);
	m_serverComboBox->insertItem(ImportConfig::ServerFreedb, i18n("gnudb.org"));
	m_serverComboBox->insertItem(ImportConfig::ServerTrackType, i18n("TrackType.org"));
	m_serverComboBox->insertItem(ImportConfig::ServerDiscogs, i18n("Discogs"));
	m_serverComboBox->insertItem(ImportConfig::ServerAmazon,
																	 i18n("Amazon"));
	m_serverComboBox->insertItem(ImportConfig::ServerMusicBrainzRelease,
																	 i18n("MusicBrainz Release"));
#ifdef HAVE_TUNEPIMP
	m_serverComboBox->insertItem(ImportConfig::ServerMusicBrainzFingerprint,
																	 i18n("MusicBrainz Fingerprint"));
#endif
	butlayout->addWidget(m_serverComboBox);
	QSpacerItem* butspacer = new QSpacerItem(16, 0, QSizePolicy::Expanding,
																				 QSizePolicy::Minimum);
	butlayout->addItem(butspacer);
	QLabel* destLabel = new QLabel(butbox);
	destLabel->setText(i18n("D&estination:"));
	butlayout->addWidget(destLabel);
	m_destComboBox = new QComboBox(butbox);
	m_destComboBox->setEditable(false);
	m_destComboBox->insertItem(ImportConfig::DestV1, i18n("Tag 1"));
	m_destComboBox->insertItem(ImportConfig::DestV2, i18n("Tag 2"));
	m_destComboBox->insertItem(ImportConfig::DestV1V2, i18n("Tag 1 and Tag 2"));
152
153
	connect(m_destComboBox, SIGNAL(activated(int)),
					this, SLOT(changeTagDestination()));
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
	destLabel->setBuddy(m_destComboBox);
	butlayout->addWidget(m_destComboBox);
	vlayout->addWidget(butbox);

	QWidget* matchBox = new QWidget(this);
	QHBoxLayout* matchLayout = new QHBoxLayout(matchBox);
	matchLayout->setMargin(0);
	matchLayout->setSpacing(6);
	m_mismatchCheckBox = new QCheckBox(
		i18n("Check maximum allowable time &difference (sec):"), matchBox);
	matchLayout->addWidget(m_mismatchCheckBox);
	m_maxDiffSpinBox = new QSpinBox(matchBox);
	m_maxDiffSpinBox->setMaximum(9999);
	matchLayout->addWidget(m_maxDiffSpinBox);
	QSpacerItem* matchSpacer = new QSpacerItem(16, 0, QSizePolicy::Expanding,
																						 QSizePolicy::Minimum);
	matchLayout->addItem(matchSpacer);
	QLabel* matchLabel = new QLabel(i18n("Match with:"), matchBox);
	matchLayout->addWidget(matchLabel);
	QPushButton* lengthButton = new QPushButton(i18n("&Length"), matchBox);
174
	lengthButton->setAutoDefault(false);
175
176
	matchLayout->addWidget(lengthButton);
	QPushButton* trackButton = new QPushButton(i18n("T&rack"), matchBox);
177
	trackButton->setAutoDefault(false);
178
179
	matchLayout->addWidget(trackButton);
	QPushButton* titleButton = new QPushButton(i18n("&Title"), matchBox);
180
	titleButton->setAutoDefault(false);
181
182
183
184
185
186
187
188
189
190
191
192
	matchLayout->addWidget(titleButton);
	vlayout->addWidget(matchBox);

	connect(fileButton, SIGNAL(clicked()), this, SLOT(fromText()));
	connect(serverButton, SIGNAL(clicked()), this, SLOT(fromServer()));
	connect(m_serverComboBox, SIGNAL(activated(int)), this, SLOT(fromServer()));
	connect(lengthButton, SIGNAL(clicked()), this, SLOT(matchWithLength()));
	connect(trackButton, SIGNAL(clicked()), this, SLOT(matchWithTrack()));
	connect(titleButton, SIGNAL(clicked()), this, SLOT(matchWithTitle()));
	connect(m_mismatchCheckBox, SIGNAL(toggled(bool)), this, SLOT(showPreview()));
	connect(m_maxDiffSpinBox, SIGNAL(valueChanged(int)), this, SLOT(maxDiffChanged()));
	connect(this, SIGNAL(finished(int)), this, SLOT(hideSubdialogs()));
Urs Fleisch's avatar
Urs Fleisch committed
193

194
	QHBoxLayout* hlayout = new QHBoxLayout;
Urs Fleisch's avatar
Urs Fleisch committed
195
	QSpacerItem* hspacer = new QSpacerItem(16, 0, QSizePolicy::Expanding,
Urs Fleisch's avatar
Urs Fleisch committed
196
	                                       QSizePolicy::Minimum);
Urs Fleisch's avatar
Urs Fleisch committed
197
	QPushButton* helpButton = new QPushButton(i18n("&Help"), this);
198
	helpButton->setAutoDefault(false);
Urs Fleisch's avatar
Urs Fleisch committed
199
	QPushButton* saveButton = new QPushButton(i18n("&Save Settings"), this);
200
	saveButton->setAutoDefault(false);
Urs Fleisch's avatar
Urs Fleisch committed
201
	QPushButton* okButton = new QPushButton(i18n("&OK"), this);
202
	okButton->setAutoDefault(false);
Urs Fleisch's avatar
Urs Fleisch committed
203
	QPushButton* cancelButton = new QPushButton(i18n("&Cancel"), this);
204
205
206
207
208
209
210
211
212
213
214
	cancelButton->setAutoDefault(false);
	hlayout->addWidget(helpButton);
	hlayout->addWidget(saveButton);
	hlayout->addItem(hspacer);
	hlayout->addWidget(okButton);
	hlayout->addWidget(cancelButton);
	connect(helpButton, SIGNAL(clicked()), this, SLOT(showHelp()));
	connect(saveButton, SIGNAL(clicked()), this, SLOT(saveConfig()));
	connect(okButton, SIGNAL(clicked()), this, SLOT(onOkButtonClicked()));
	connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
	vlayout->addLayout(hlayout);
Urs Fleisch's avatar
Urs Fleisch committed
215
216
217
218
219
220
}

/**
 * Destructor.
 */
ImportDialog::~ImportDialog()
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
{
	delete m_textImportDialog;
	delete m_serverImportDialog;
	delete m_freedbImporter;
	delete m_trackTypeImporter;
	delete m_musicBrainzReleaseImporter;
	delete m_discogsImporter;
	delete m_amazonImporter;
#ifdef HAVE_TUNEPIMP
	delete m_musicBrainzDialog;
#endif
}

/**
 * Import from server and preview in table.
 */
void ImportDialog::fromServer()
{
	if (m_serverComboBox) {
		switch (m_serverComboBox->currentIndex()) {
			case ImportConfig::ServerFreedb:
				fromFreedb();
				break;
			case ImportConfig::ServerTrackType:
				fromTrackType();
				break;
			case ImportConfig::ServerDiscogs:
				fromDiscogs();
				break;
			case ImportConfig::ServerAmazon:
				fromAmazon();
				break;
			case ImportConfig::ServerMusicBrainzRelease:
				fromMusicBrainzRelease();
				break;
			case ImportConfig::ServerMusicBrainzFingerprint:
				fromMusicBrainz();
				break;
		}
	}
}

/**
 * Import from text.
 */
void ImportDialog::fromText()
{
	if (!m_textImportDialog) {
		m_textImportDialog = new TextImportDialog(this, m_trackDataVector);
		connect(m_textImportDialog, SIGNAL(trackDataUpdated()),
271
						this, SLOT(showPreviewAfterImport()));
272
273
274
275
276
277
	}
	m_textImportDialog->clear();
	m_textImportDialog->show();
}

/**
278
 * Display server import dialog.
279
280
281
 *
 * @param source import source
 */
282
void ImportDialog::displayServerImportDialog(ServerImporter* source)
283
284
285
286
{
	if (!m_serverImportDialog) {
		m_serverImportDialog = new ServerImportDialog(this);
		connect(m_serverImportDialog, SIGNAL(trackDataUpdated()),
287
						this, SLOT(showPreviewAfterImport()));
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
	}
	if (m_serverImportDialog) {
		m_serverImportDialog->setImportSource(source);
		m_serverImportDialog->setArtistAlbum(m_trackDataVector.getArtist(),
																		m_trackDataVector.getAlbum());
		m_serverImportDialog->show();
	}
}

/**
 * Hide subdialogs.
 */
void ImportDialog::hideSubdialogs()
{
	if (m_serverImportDialog)
		m_serverImportDialog->hide();
	if (m_textImportDialog)
		m_textImportDialog->hide();
}

/**
 * Import from freedb.org and preview in table.
 */
void ImportDialog::fromFreedb()
{
	if (!m_freedbImporter) {
		m_freedbImporter = new FreedbImporter(this, m_trackDataVector);
	}
316
	displayServerImportDialog(m_freedbImporter);
317
318
319
320
321
322
323
324
325
326
}

/**
 * Import from TrackType.org and preview in table.
 */
void ImportDialog::fromTrackType()
{
	if (!m_trackTypeImporter) {
		m_trackTypeImporter = new TrackTypeImporter(this, m_trackDataVector);
	}
327
	displayServerImportDialog(m_trackTypeImporter);
328
329
330
331
332
333
334
335
336
337
338
}

/**
 * Import from MusicBrainz release database and preview in table.
 */
void ImportDialog::fromMusicBrainzRelease()
{
	if (!m_musicBrainzReleaseImporter) {
		m_musicBrainzReleaseImporter =
				new MusicBrainzReleaseImporter(this, m_trackDataVector);
	}
339
	displayServerImportDialog(m_musicBrainzReleaseImporter);
340
341
342
343
344
345
346
347
348
349
}

/**
 * Import from www.discogs.com and preview in table.
 */
void ImportDialog::fromDiscogs()
{
	if (!m_discogsImporter) {
		m_discogsImporter = new DiscogsImporter(this, m_trackDataVector);
	}
350
	displayServerImportDialog(m_discogsImporter);
351
352
353
354
355
356
357
358
359
360
}

/**
 * Import from www.amazon.com and preview in table.
 */
void ImportDialog::fromAmazon()
{
	if (!m_amazonImporter) {
		m_amazonImporter = new AmazonImporter(this, m_trackDataVector);
	}
361
	displayServerImportDialog(m_amazonImporter);
362
363
364
365
366
367
368
369
370
371
372
}

/**
 * Import from MusicBrainz and preview in table.
 */
void ImportDialog::fromMusicBrainz()
{
#ifdef HAVE_TUNEPIMP
	if (!m_musicBrainzDialog) {
		m_musicBrainzDialog = new MusicBrainzDialog(this, m_trackDataVector);
		connect(m_musicBrainzDialog, SIGNAL(trackDataUpdated()),
373
						this, SLOT(showPreviewAfterImport()));
374
375
376
377
378
379
380
	}
	if (m_musicBrainzDialog) {
		m_musicBrainzDialog->initTable();
		(void)m_musicBrainzDialog->exec();
	}
#endif
}
Urs Fleisch's avatar
Urs Fleisch committed
381

382
383
384
385
386
387
388
/**
 * Shows the dialog as a modal dialog.
 */
int ImportDialog::exec()
{
	switch (m_autoStartSubDialog) {
		case ASD_Freedb:
Urs Fleisch's avatar
Urs Fleisch committed
389
			show();
390
			fromFreedb();
Urs Fleisch's avatar
Urs Fleisch committed
391
			break;
392
393
		case ASD_TrackType:
			show();
394
			fromTrackType();
395
			break;
396
397
		case ASD_Discogs:
			show();
398
			fromDiscogs();
399
			break;
Urs Fleisch's avatar
Urs Fleisch committed
400
401
		case ASD_Amazon:
			show();
402
			fromAmazon();
Urs Fleisch's avatar
Urs Fleisch committed
403
			break;
404
405
		case ASD_MusicBrainzRelease:
			show();
406
			fromMusicBrainzRelease();
407
			break;
408
409
		case ASD_MusicBrainz:
			show();
410
			fromMusicBrainz();
Urs Fleisch's avatar
Urs Fleisch committed
411
412
413
			break;
		case ASD_None:
			break;
414
	}
Urs Fleisch's avatar
Urs Fleisch committed
415
	return QDialog::exec();
416
417
}

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
/**
 * Set dialog to be started automatically.
 *
 * @param asd dialog to be started
 */
void ImportDialog::setAutoStartSubDialog(AutoStartSubDialog asd)
{
	m_autoStartSubDialog = asd;

	ImportConfig::ImportServer server;
	switch (asd) {
		case ASD_Freedb:
			server = ImportConfig::ServerFreedb;
			break;
		case ASD_TrackType:
			server = ImportConfig::ServerTrackType;
			break;
		case ASD_Discogs:
			server = ImportConfig::ServerDiscogs;
			break;
Urs Fleisch's avatar
Urs Fleisch committed
438
439
440
		case ASD_Amazon:
			server = ImportConfig::ServerAmazon;
			break;
441
442
443
444
445
446
447
448
449
450
		case ASD_MusicBrainzRelease:
			server = ImportConfig::ServerMusicBrainzRelease;
			break;
		case ASD_MusicBrainz:
			server = ImportConfig::ServerMusicBrainzFingerprint;
			break;
		case ASD_None:
		default:
			return;
	}
451
	m_serverComboBox->setCurrentIndex(server);
452
453
}

454
455
456
457
458
/**
 * Clear dialog data.
 */
void ImportDialog::clear()
{
459
	m_trackDataImported = false;
460
461
462
463
464
465
466
	m_trackDataModel->setTrackData(ImportTrackDataVector());

	m_serverComboBox->setCurrentIndex(Kid3App::s_genCfg.m_importServer);
	m_destComboBox->setCurrentIndex(Kid3App::s_genCfg.m_importDest);

	m_mismatchCheckBox->setChecked(Kid3App::s_genCfg.m_enableTimeDifferenceCheck);
	m_maxDiffSpinBox->setValue(Kid3App::s_genCfg.m_maxTimeDifference);
467
468
469
470
471
472

	if (Kid3App::s_genCfg.m_importWindowWidth > 0 &&
			Kid3App::s_genCfg.m_importWindowHeight > 0) {
		resize(Kid3App::s_genCfg.m_importWindowWidth,
					 Kid3App::s_genCfg.m_importWindowHeight);
	}
473
474

	showPreview();
475
476
}

477
478
479
/**
 * Show fields to import in text as preview in table.
 */
480
481
void ImportDialog::showPreview()
{
482
483
484
485
486
487
488
489
490
491
492
	// make time difference check
	bool diffCheckEnable;
	int maxDiff;
	getTimeDifferenceCheck(diffCheckEnable, maxDiff);
	m_trackDataModel->setTimeDifferenceCheck(diffCheckEnable, maxDiff);
	m_trackDataModel->setTrackData(m_trackDataVector);
	m_trackDataTable->scrollToTop();
	m_trackDataTable->resizeColumnsToContents();
	m_trackDataTable->resizeRowsToContents();
}

493
494
495
496
497
498
499
500
501
502
503
/**
 * Show fields to import in text as preview in table.
 * This method also marks that an import was made and thus switching the tag
 * version is no longer possible.
 */
void ImportDialog::showPreviewAfterImport()
{
	m_trackDataImported = true;
	showPreview();
}

Urs Fleisch's avatar
Urs Fleisch committed
504
505
506
/**
 * Get import destination.
 *
507
 * @return DestV1, DestV2 or DestV1V2 for ID3v1, ID3v2 or both.
Urs Fleisch's avatar
Urs Fleisch committed
508
 */
509
ImportConfig::ImportDestination ImportDialog::getDestination() const
Urs Fleisch's avatar
Urs Fleisch committed
510
{
511
512
	return static_cast<ImportConfig::ImportDestination>(
		m_destComboBox->currentIndex());
Urs Fleisch's avatar
Urs Fleisch committed
513
514
}

515
516
517
518
519
520
521
/**
 * Set import destination.
 *
 * @param dest DestV1, DestV2 or DestV1V2 for ID3v1, ID3v2 or both
 */
void ImportDialog::setDestination(ImportConfig::ImportDestination dest)
{
522
	m_destComboBox->setCurrentIndex(dest);
523
524
}

Urs Fleisch's avatar
Urs Fleisch committed
525
/**
526
 * Show help.
Urs Fleisch's avatar
Urs Fleisch committed
527
 */
528
void ImportDialog::showHelp()
Urs Fleisch's avatar
Urs Fleisch committed
529
{
530
	Kid3App::displayHelp("import");
Urs Fleisch's avatar
Urs Fleisch committed
531
}
532
533
534
535
536
537

/**
 * Save the local settings to the configuration.
 */
void ImportDialog::saveConfig()
{
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
	Kid3App::s_genCfg.m_importDest = static_cast<ImportConfig::ImportDestination>(
				m_destComboBox->currentIndex());

	Kid3App::s_genCfg.m_importServer = static_cast<ImportConfig::ImportServer>(
		m_serverComboBox->currentIndex());
	getTimeDifferenceCheck(Kid3App::s_genCfg.m_enableTimeDifferenceCheck,
												 Kid3App::s_genCfg.m_maxTimeDifference);

	Kid3App::s_genCfg.m_importWindowWidth = size().width();
	Kid3App::s_genCfg.m_importWindowHeight = size().height();
}

/**
 * Get time difference check configuration.
 *
 * @param enable  true if check is enabled
 * @param maxDiff maximum allowed time difference
 */
void ImportDialog::getTimeDifferenceCheck(bool& enable, int& maxDiff) const
{
	enable = m_mismatchCheckBox->isChecked();
	maxDiff = m_maxDiffSpinBox->value();
}

/**
 * Called when the maximum time difference value is changed.
 */
void ImportDialog::maxDiffChanged() {
	if (m_mismatchCheckBox->isChecked()) {
		showPreview();
	}
}

/**
 * Move a table row.
 *
 * The first parameter @a section is not used.
 * @param fromIndex index of position moved from
 * @param fromIndex index of position moved to
 */
void ImportDialog::moveTableRow(int, int fromIndex, int toIndex) {
	QHeaderView* vHeader = qobject_cast<QHeaderView*>(sender());
	if (vHeader) {
		// revert movement, but avoid recursion
		disconnect(vHeader, SIGNAL(sectionMoved(int, int, int)), 0, 0);
		vHeader->moveSection(toIndex, fromIndex);
		connect(vHeader, SIGNAL(sectionMoved(int, int, int)), this, SLOT(moveTableRow(int, int, int)));
	}
	int numTracks = static_cast<int>(m_trackDataVector.size());
	if (fromIndex < numTracks && toIndex < numTracks) {
		// swap elements but keep file durations and names
		ImportTrackData fromData(m_trackDataVector[fromIndex]);
		ImportTrackData toData(m_trackDataVector[toIndex]);
		m_trackDataVector[fromIndex].setFrameCollection(toData.getFrameCollection());
		m_trackDataVector[toIndex].setFrameCollection(fromData.getFrameCollection());
		m_trackDataVector[fromIndex].setImportDuration(toData.getImportDuration());
		m_trackDataVector[toIndex].setImportDuration(fromData.getImportDuration());
		// redisplay the table
		showPreview();
	}
}

600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
/**
 * Called when OK is clicked.
 */
void ImportDialog::onOkButtonClicked()
{
	// Set changes made in the table in the track data.
	m_trackDataVector = m_trackDataModel->getTrackData();
	accept();
}

/**
 * Called when the destination combo box value is changed.
 */
void ImportDialog::changeTagDestination()
{
	// Prevent switching of track data after an import.
	if (!m_trackDataImported) {
		ImportConfig::ImportDestination dest = getDestination();

		TrackData::TagVersion tagVersion = TrackData::TagNone;
		switch (dest) {
		case ImportConfig::DestV1:
			tagVersion = TrackData::TagV1;
			break;
		case ImportConfig::DestV2:
			tagVersion = TrackData::TagV2;
			break;
		case ImportConfig::DestV1V2:
			tagVersion = TrackData::TagV2V1;
		}

		m_trackDataVector.readTags(tagVersion);
		showPreview();
	}
}

636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
/**
 * Match import data with length.
 */
void ImportDialog::matchWithLength()
{
	bool diffCheckEnable;
	int maxDiff;
	getTimeDifferenceCheck(diffCheckEnable, maxDiff);
	if (TrackDataMatcher::matchWithLength(m_trackDataVector, diffCheckEnable, maxDiff))
		showPreview();
}

/**
 * Match import data with track number.
 */
void ImportDialog::matchWithTrack()
{
	if (TrackDataMatcher::matchWithTrack(m_trackDataVector))
		showPreview();
}

/**
 * Match import data with title.
 */
void ImportDialog::matchWithTitle()
{
	if (TrackDataMatcher::matchWithTitle(m_trackDataVector))
		showPreview();
664
}