~ubuntu-branches/ubuntu/gutsy/kid3/gutsy

« back to all changes in this revision

Viewing changes to kid3/kid3.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sarah Hobbs
  • Date: 2006-07-14 12:25:16 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060714122516-p2wk0iyzumu6jx42
Tags: 0.7-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include <qcursor.h>
17
17
#include <qprogressbar.h>
18
18
#include <qmessagebox.h>
 
19
#include <qgroupbox.h>
19
20
 
20
21
#ifdef CONFIG_USE_KDE
21
22
#include <kapp.h>
46
47
#include "mp3framelist.h"
47
48
#include "configdialog.h"
48
49
#include "importdialog.h"
 
50
#include "exportdialog.h"
 
51
#include "numbertracksdialog.h"
49
52
#include "formatconfig.h"
50
53
#include "importconfig.h"
51
54
#include "miscconfig.h"
134
137
 * @param name name
135
138
 */
136
139
 
137
 
Kid3App::Kid3App()
 
140
Kid3App::Kid3App() :
 
141
        m_importDialog(0), m_exportDialog(0), m_numberTracksDialog(0)
138
142
{
139
143
        miscCfg = new MiscConfig("General Options");
140
144
        genCfg = new ImportConfig("General Options");
171
175
 
172
176
Kid3App::~Kid3App()
173
177
{
 
178
        delete m_importDialog;
 
179
        delete m_numberTracksDialog;
174
180
}
175
181
 
176
182
/**
190
196
            this, SLOT(slotFileSave()), actionCollection());
191
197
        fileQuit = KStdAction::quit(
192
198
            this, SLOT(slotFileQuit()), actionCollection());
 
199
#if KDE_VERSION < 0x30200
193
200
        viewToolBar = KStdAction::showToolbar(
194
201
            this, SLOT(slotViewToolBar()), actionCollection());
195
202
        viewStatusBar = KStdAction::showStatusbar(
196
203
            this, SLOT(slotViewStatusBar()), actionCollection());
197
 
    settingsShortcuts = KStdAction::keyBindings(
 
204
        viewToolBar->setStatusText(i18n("Enables/disables the toolbar"));
 
205
        viewStatusBar->setStatusText(i18n("Enables/disables the statusbar"));
 
206
#else
 
207
        setStandardToolBarMenuEnabled(true);
 
208
        createStandardStatusBarAction();
 
209
#endif
 
210
        settingsShortcuts = KStdAction::keyBindings(
198
211
                this, SLOT(slotSettingsShortcuts()), actionCollection());
199
212
        settingsConfigure = KStdAction::preferences(
200
213
            this, SLOT(slotSettingsConfigure()), actionCollection());
205
218
            i18n("Reverts the changes of all or the selected files"));
206
219
        fileSave->setStatusText(i18n("Saves the changed files"));
207
220
        fileQuit->setStatusText(i18n("Quits the application"));
208
 
        viewToolBar->setStatusText(i18n("Enables/disables the toolbar"));
209
 
        viewStatusBar->setStatusText(i18n("Enables/disables the statusbar"));
210
221
        settingsShortcuts->setStatusText(i18n("Configure Shortcuts"));
211
222
        settingsConfigure->setStatusText(i18n("Preferences dialog"));
212
223
 
213
224
        new KAction(i18n("&Import..."), 0, this,
214
225
                    SLOT(slotImport()), actionCollection(),
215
226
                    "import");
 
227
        new KAction(i18n("Import from &freedb.org..."), 0, this,
 
228
                    SLOT(slotImportFreedb()), actionCollection(),
 
229
                    "import_freedb");
 
230
#ifdef HAVE_TUNEPIMP
 
231
        new KAction(i18n("Import from &MusicBrainz..."), 0, this,
 
232
                    SLOT(slotImportMusicBrainz()), actionCollection(),
 
233
                    "import_musicbrainz");
 
234
#endif
 
235
        new KAction(i18n("&Export..."), 0, this,
 
236
                    SLOT(slotExport()), actionCollection(),
 
237
                    "export");
216
238
        new KAction(i18n("&Create Playlist"), 0, this,
217
239
                    SLOT(slotCreatePlaylist()), actionCollection(),
218
240
                    "create_playlist");
219
 
        new KAction(i18n("&Apply Format"), 0, this,
220
 
                    SLOT(slotApplyFormat()), actionCollection(),
221
 
                    "apply_format");
 
241
        new KAction(i18n("Apply &Filename Format"), 0, this,
 
242
                    SLOT(slotApplyFilenameFormat()), actionCollection(),
 
243
                    "apply_filename_format");
 
244
        new KAction(i18n("Apply &ID3 Format"), 0, this,
 
245
                    SLOT(slotApplyId3Format()), actionCollection(),
 
246
                    "apply_id3_format");
222
247
        new KAction(i18n("&Rename Directory..."), 0, this,
223
248
                    SLOT(slotRenameDirectory()), actionCollection(),
224
249
                    "rename_directory");
 
250
        new KAction(i18n("&Number Tracks..."), 0, this,
 
251
                    SLOT(slotNumberTracks()), actionCollection(),
 
252
                    "number_tracks");
 
253
        settingsShowHideV1 =
 
254
                new KAction(i18n("Hide ID3v&1.1"), 0, this,
 
255
                                                                SLOT(slotSettingsShowHideV1()), actionCollection(),
 
256
                                                                "hide_v1");
 
257
        settingsShowHideV2 =
 
258
                new KAction(i18n("Hide ID3v&2.3"), 0, this,
 
259
                                                                SLOT(slotSettingsShowHideV2()), actionCollection(),
 
260
                                                                "hide_v2");
225
261
 
226
262
        new KAction(i18n("Select &All"), KShortcut("Alt+A"), this,
227
263
                    SLOT(slotSelectAll()), actionCollection(),
303
339
                connect(fileImport, SIGNAL(activated()),
304
340
                        this, SLOT(slotImport()));
305
341
        }
 
342
        fileImportFreedb = new QAction(this);
 
343
        if (fileImportFreedb) {
 
344
                fileImportFreedb->setText(i18n("Import from freedb.org"));
 
345
                fileImportFreedb->setMenuText(i18n("Import from &freedb.org..."));
 
346
                connect(fileImportFreedb, SIGNAL(activated()),
 
347
                        this, SLOT(slotImportFreedb()));
 
348
        }
 
349
#ifdef HAVE_TUNEPIMP
 
350
        fileImportMusicBrainz = new QAction(this);
 
351
        if (fileImportMusicBrainz) {
 
352
                fileImportMusicBrainz->setText(i18n("Import from MusicBrainz"));
 
353
                fileImportMusicBrainz->setMenuText(i18n("Import from &MusicBrainz..."));
 
354
                connect(fileImportMusicBrainz, SIGNAL(activated()),
 
355
                        this, SLOT(slotImportMusicBrainz()));
 
356
        }
 
357
#endif
 
358
        fileExport = new QAction(this);
 
359
        if (fileExport) {
 
360
                fileExport->setText(i18n("Export to file or clipboard"));
 
361
                fileExport->setMenuText(i18n("&Export..."));
 
362
                connect(fileExport, SIGNAL(activated()),
 
363
                        this, SLOT(slotExport()));
 
364
        }
306
365
        fileCreatePlaylist = new QAction(this);
307
366
        if (fileCreatePlaylist) {
308
367
                fileCreatePlaylist->setText(i18n("Create M3U Playlist"));
339
398
                connect(helpAboutQt, SIGNAL(activated()),
340
399
                        this, SLOT(slotHelpAboutQt()));
341
400
        }
342
 
        toolsApplyFormat = new QAction(this);
343
 
        if (toolsApplyFormat) {
344
 
                toolsApplyFormat->setText(i18n("Apply Format"));
345
 
                toolsApplyFormat->setMenuText(i18n("&Apply Format"));
346
 
                connect(toolsApplyFormat, SIGNAL(activated()),
347
 
                        this, SLOT(slotApplyFormat()));
 
401
        toolsApplyFilenameFormat = new QAction(this);
 
402
        if (toolsApplyFilenameFormat) {
 
403
                toolsApplyFilenameFormat->setText(i18n("Apply Filename Format"));
 
404
                toolsApplyFilenameFormat->setMenuText(i18n("Apply &Filename Format"));
 
405
                connect(toolsApplyFilenameFormat, SIGNAL(activated()),
 
406
                        this, SLOT(slotApplyFilenameFormat()));
 
407
        }
 
408
        toolsApplyId3Format = new QAction(this);
 
409
        if (toolsApplyId3Format) {
 
410
                toolsApplyId3Format->setText(i18n("Apply ID3 Format"));
 
411
                toolsApplyId3Format->setMenuText(i18n("Apply &ID3 Format"));
 
412
                connect(toolsApplyId3Format, SIGNAL(activated()),
 
413
                        this, SLOT(slotApplyId3Format()));
348
414
        }
349
415
        toolsRenameDirectory = new QAction(this);
350
416
        if (toolsRenameDirectory) {
353
419
                connect(toolsRenameDirectory, SIGNAL(activated()),
354
420
                        this, SLOT(slotRenameDirectory()));
355
421
        }
 
422
        toolsNumberTracks = new QAction(this);
 
423
        if (toolsNumberTracks) {
 
424
                toolsNumberTracks->setText(i18n("Number Tracks"));
 
425
                toolsNumberTracks->setMenuText(i18n("&Number Tracks..."));
 
426
                connect(toolsNumberTracks, SIGNAL(activated()),
 
427
                        this, SLOT(slotNumberTracks()));
 
428
        }
 
429
        settingsShowHideV1 = new QAction(this);
 
430
        if (settingsShowHideV1) {
 
431
                settingsShowHideV1->setText(i18n("Hide ID3v1.1"));
 
432
                settingsShowHideV1->setMenuText(i18n("Hide ID3v&1.1"));
 
433
                connect(settingsShowHideV1, SIGNAL(activated()),
 
434
                        this, SLOT(slotSettingsShowHideV1()));
 
435
        }
 
436
        settingsShowHideV2 = new QAction(this);
 
437
        if (settingsShowHideV2) {
 
438
                settingsShowHideV2->setText(i18n("Hide ID3v2.3"));
 
439
                settingsShowHideV2->setMenuText(i18n("Hide ID3v&2.3"));
 
440
                connect(settingsShowHideV2, SIGNAL(activated()),
 
441
                        this, SLOT(slotSettingsShowHideV2()));
 
442
        }
356
443
        settingsConfigure = new QAction(this);
357
444
        if (settingsConfigure) {
358
445
                settingsConfigure->setText(i18n("Configure Kid3"));
372
459
                fileRevert->addTo(fileMenu);
373
460
                fileMenu->insertSeparator();
374
461
                fileImport->addTo(fileMenu);
 
462
                fileImportFreedb->addTo(fileMenu);
 
463
#ifdef HAVE_TUNEPIMP
 
464
                fileImportMusicBrainz->addTo(fileMenu);
 
465
#endif
 
466
                fileExport->addTo(fileMenu);
375
467
                fileCreatePlaylist->addTo(fileMenu);
376
468
                fileMenu->insertSeparator();
377
469
                fileQuit->addTo(fileMenu);
378
470
                menubar->insertItem((i18n("&File")), fileMenu);
379
471
 
380
 
                toolsApplyFormat->addTo(toolsMenu);
 
472
                toolsApplyFilenameFormat->addTo(toolsMenu);
 
473
                toolsApplyId3Format->addTo(toolsMenu);
381
474
                toolsRenameDirectory->addTo(toolsMenu);
 
475
                toolsNumberTracks->addTo(toolsMenu);
382
476
                menubar->insertItem((i18n("&Tools")), toolsMenu);
383
477
 
 
478
                settingsShowHideV1->addTo(settingsMenu);
 
479
                settingsShowHideV2->addTo(settingsMenu);
 
480
                settingsMenu->insertSeparator();
384
481
                settingsConfigure->addTo(settingsMenu);
385
482
                menubar->insertItem(i18n("&Settings"), settingsMenu);
386
483
 
478
575
        miscCfg->formatItem = view->formatComboBox->currentItem();
479
576
        miscCfg->formatText = view->formatComboBox->currentText();
480
577
 
 
578
        miscCfg->m_customGenres.clear();
 
579
        int idx, numGenres = view->genreV2ComboBox->count();
 
580
        for (idx = Genres::count + 1; idx < numGenres; ++idx) {
 
581
                miscCfg->m_customGenres.append(view->genreV2ComboBox->text(idx));
 
582
        }
 
583
 
481
584
        miscCfg->writeToConfig(config);
482
585
        fnFormatCfg->writeToConfig(config);
483
586
        id3FormatCfg->writeToConfig(config);
502
605
#ifdef HAVE_TUNEPIMP
503
606
        m_musicBrainzCfg->readFromConfig(config);
504
607
#endif
 
608
        updateHideV1();
 
609
        updateHideV2();
505
610
#ifdef CONFIG_USE_KDE
506
611
        setAutoSaveSettings();
507
612
        fileOpenRecent->loadEntries(config,"Recent Files");
 
613
#if KDE_VERSION < 0x30200
508
614
        viewToolBar->setChecked(!toolBar("mainToolBar")->isHidden());
509
615
        viewStatusBar->setChecked(!statusBar()->isHidden());
 
616
#endif
510
617
#else
511
618
        if (miscCfg->windowWidth != -1 && miscCfg->windowHeight != -1) {
512
619
                resize(miscCfg->windowWidth, miscCfg->windowHeight);
544
651
#if QT_VERSION >= 300
545
652
        view->formatComboBox->setCurrentText(miscCfg->formatText);
546
653
#endif
 
654
        view->genreV2ComboBox->insertStringList(miscCfg->m_customGenres);
547
655
}
548
656
 
549
657
#ifdef CONFIG_USE_KDE
889
997
}
890
998
 
891
999
#ifdef CONFIG_USE_KDE
 
1000
#if KDE_VERSION < 0x30200
892
1001
/**
893
1002
 * Turn tool bar on or off.
894
1003
 */
920
1029
        }
921
1030
        slotStatusMsg(i18n("Ready."));
922
1031
}
 
1032
#else
 
1033
 
 
1034
void Kid3App::slotViewToolBar() {}
 
1035
void Kid3App::slotViewStatusBar() {}
 
1036
 
 
1037
#endif
923
1038
 
924
1039
/**
925
1040
 * Shortcuts configuration.
962
1077
        QMessageBox::about(
963
1078
                (Kid3App*)parent(), "Kid3",
964
1079
                "Kid3 " VERSION
965
 
                "\n(c) 2003-2005 Urs Fleisch\nufleisch@users.sourceforge.net");
 
1080
                "\n(c) 2003-2006 Urs Fleisch\nufleisch@users.sourceforge.net");
966
1081
}
967
1082
 
968
1083
/**
1059
1174
}
1060
1175
 
1061
1176
/**
1062
 
 * Import.
 
1177
 * Update track data and create import dialog.
1063
1178
 */
1064
 
 
1065
 
void Kid3App::slotImport(void)
 
1179
void Kid3App::setupImportDialog()
1066
1180
{
1067
 
        ImportTrackDataVector trackDataList;
 
1181
        m_trackDataList.clear();
1068
1182
        TaggedFile *mp3file = view->mp3ListBox->first();
 
1183
        bool firstTrack = true;
1069
1184
        while (mp3file != 0) {
1070
1185
                mp3file->readTags(false);
 
1186
                if (firstTrack) {
 
1187
                        StandardTags st;
 
1188
                        mp3file->getStandardTagsV2(&st);
 
1189
                        if (st.artist.isEmpty() && st.album.isEmpty()) {
 
1190
                                mp3file->getStandardTagsV1(&st);
 
1191
                        }
 
1192
                        m_trackDataList.artist = st.artist;
 
1193
                        m_trackDataList.album = st.album;
 
1194
                        firstTrack = false;
 
1195
                }
1071
1196
#if QT_VERSION >= 300
1072
 
                trackDataList.push_back(ImportTrackData(mp3file->getAbsFilename(),
 
1197
                m_trackDataList.push_back(ImportTrackData(mp3file->getAbsFilename(),
1073
1198
                                            mp3file->getDuration()));
1074
1199
#else
1075
 
                trackDataList.append(ImportTrackData(mp3file->getAbsFilename(),
 
1200
                m_trackDataList.append(ImportTrackData(mp3file->getAbsFilename(),
1076
1201
                                            mp3file->getDuration()));
1077
1202
#endif
1078
1203
                mp3file = view->mp3ListBox->next();
1079
1204
        }
1080
1205
 
1081
 
        QString caption(i18n("Import"));
1082
 
        ImportDialog *dialog =
1083
 
                new ImportDialog(NULL, caption, trackDataList);
1084
 
        if (dialog) {
1085
 
                dialog->setDestV1(genCfg->importDestV1);
1086
 
                dialog->setImportFormat(genCfg->importFormatNames,
 
1206
        if (!m_importDialog) {
 
1207
                QString caption(i18n("Import"));
 
1208
                m_importDialog =
 
1209
                        new ImportDialog(NULL, caption, m_trackDataList);
 
1210
        }
 
1211
        if (m_importDialog) {
 
1212
                m_importDialog->clear();
 
1213
                m_importDialog->setDestV1(genCfg->importDestV1);
 
1214
                m_importDialog->setImportFormat(genCfg->importFormatNames,
1087
1215
                                                                genCfg->importFormatHeaders,
1088
1216
                                                                genCfg->importFormatTracks,
1089
1217
                                                                genCfg->importFormatIdx);
1090
 
                dialog->setTimeDifferenceCheck(genCfg->enableTimeDifferenceCheck,
 
1218
                m_importDialog->setTimeDifferenceCheck(genCfg->enableTimeDifferenceCheck,
1091
1219
                                                                           genCfg->maxTimeDifference);
1092
 
                dialog->setFreedbConfig(freedbCfg);
1093
 
#ifdef HAVE_TUNEPIMP
1094
 
                dialog->setMusicBrainzConfig(m_musicBrainzCfg);
1095
 
#endif
1096
 
                if (dialog->exec() == QDialog::Accepted) {
1097
 
                        genCfg->importDestV1 = dialog->getDestV1();
1098
 
                        QString name, header, track;
1099
 
                        genCfg->importFormatIdx = dialog->getImportFormat(name, header, track);
1100
 
                        genCfg->importFormatNames[genCfg->importFormatIdx] = name;
1101
 
                        genCfg->importFormatHeaders[genCfg->importFormatIdx] = header;
1102
 
                        genCfg->importFormatTracks[genCfg->importFormatIdx] = track;
1103
 
                        dialog->getTimeDifferenceCheck(genCfg->enableTimeDifferenceCheck,
1104
 
                                                                                   genCfg->maxTimeDifference);
1105
 
                        dialog->getFreedbConfig(freedbCfg);
1106
 
#ifdef HAVE_TUNEPIMP
1107
 
                        dialog->getMusicBrainzConfig(m_musicBrainzCfg);
1108
 
#endif
1109
 
 
1110
 
                        slotStatusMsg(i18n("Import..."));
1111
 
#if QT_VERSION >= 300
1112
 
                        ImportTrackDataVector::const_iterator it = trackDataList.begin();
1113
 
#else
1114
 
                        ImportTrackDataVector::ConstIterator it = trackDataList.begin();
1115
 
#endif
1116
 
                        StandardTags st;
1117
 
                        StandardTagsFilter flt(genCfg->importDestV1 ?
1118
 
                                                                                                                 view->getFilterFromID3V1() :
1119
 
                                                                                                                 view->getFilterFromID3V2());
1120
 
                        bool no_selection = view->numFilesSelected() == 0;
1121
 
                        TaggedFile *mp3file = view->mp3ListBox->first();
1122
 
                        while (mp3file != 0) {
1123
 
                                mp3file->readTags(false);
1124
 
                                if (genCfg->importDestV1) {
1125
 
                                        mp3file->getStandardTagsV1(&st);
1126
 
                                } else {
1127
 
                                        mp3file->getStandardTagsV2(&st);
1128
 
                                }
1129
 
                                if (it != trackDataList.end()) {
1130
 
                                        (*it).copyActiveTags(st);
1131
 
                                        ++it;
1132
 
                                } else {
1133
 
                                        break;
1134
 
                                }
1135
 
                                if (genCfg->importDestV1) {
1136
 
                                        mp3file->setStandardTagsV1(&st, flt);
1137
 
                                } else {
1138
 
                                        mp3file->setStandardTagsV2(&st, flt);
1139
 
                                }
1140
 
                                mp3file = view->mp3ListBox->next();
1141
 
                        }
1142
 
                        if (!no_selection) {
1143
 
                                StandardTags st; // empty
1144
 
                                view->setStandardTagsV1(&st);
1145
 
                                view->setStandardTagsV2(&st);
1146
 
                                view->nameLineEdit->setEnabled(FALSE);
1147
 
                                fileSelected();
1148
 
                        }
1149
 
                        else {
1150
 
                                updateModificationState();
1151
 
                        }
1152
 
                        slotStatusMsg(i18n("Ready."));
1153
 
                        QApplication::restoreOverrideCursor();
1154
 
                }
1155
 
                delete dialog;
1156
 
        }
 
1220
                m_importDialog->setFreedbConfig(freedbCfg);
 
1221
#ifdef HAVE_TUNEPIMP
 
1222
                m_importDialog->setMusicBrainzConfig(m_musicBrainzCfg);
 
1223
#endif
 
1224
        }
 
1225
}
 
1226
 
 
1227
/**
 
1228
 * Execute the import dialog.
 
1229
 */
 
1230
void Kid3App::execImportDialog()
 
1231
{
 
1232
        if (m_importDialog &&
 
1233
                        m_importDialog->exec() == QDialog::Accepted) {
 
1234
                genCfg->importDestV1 = m_importDialog->getDestV1();
 
1235
                QString name, header, track;
 
1236
                genCfg->importFormatIdx = m_importDialog->getImportFormat(name, header, track);
 
1237
                genCfg->importFormatNames[genCfg->importFormatIdx] = name;
 
1238
                genCfg->importFormatHeaders[genCfg->importFormatIdx] = header;
 
1239
                genCfg->importFormatTracks[genCfg->importFormatIdx] = track;
 
1240
                m_importDialog->getTimeDifferenceCheck(genCfg->enableTimeDifferenceCheck,
 
1241
                                                                                                                                                                         genCfg->maxTimeDifference);
 
1242
                m_importDialog->getFreedbConfig(freedbCfg);
 
1243
#ifdef HAVE_TUNEPIMP
 
1244
                m_importDialog->getMusicBrainzConfig(m_musicBrainzCfg);
 
1245
#endif
 
1246
 
 
1247
                slotStatusMsg(i18n("Import..."));
 
1248
#if QT_VERSION >= 300
 
1249
                ImportTrackDataVector::const_iterator it = m_trackDataList.begin();
 
1250
#else
 
1251
                ImportTrackDataVector::ConstIterator it = m_trackDataList.begin();
 
1252
#endif
 
1253
                StandardTags st;
 
1254
                StandardTagsFilter flt(genCfg->importDestV1 ?
 
1255
                                                                                                         view->getFilterFromID3V1() :
 
1256
                                                                                                         view->getFilterFromID3V2());
 
1257
                bool no_selection = view->numFilesSelected() == 0;
 
1258
                TaggedFile *mp3file = view->mp3ListBox->first();
 
1259
                while (mp3file != 0) {
 
1260
                        mp3file->readTags(false);
 
1261
                        if (genCfg->importDestV1) {
 
1262
                                mp3file->getStandardTagsV1(&st);
 
1263
                        } else {
 
1264
                                mp3file->getStandardTagsV2(&st);
 
1265
                        }
 
1266
                        if (it != m_trackDataList.end()) {
 
1267
                                (*it).copyActiveTags(st);
 
1268
                                ++it;
 
1269
                        } else {
 
1270
                                break;
 
1271
                        }
 
1272
                        formatStandardTagsIfEnabled(&st);
 
1273
                        if (genCfg->importDestV1) {
 
1274
                                mp3file->setStandardTagsV1(&st, flt);
 
1275
                        } else {
 
1276
                                mp3file->setStandardTagsV2(&st, flt);
 
1277
                        }
 
1278
                        mp3file = view->mp3ListBox->next();
 
1279
                }
 
1280
                if (!no_selection) {
 
1281
                        StandardTags st; // empty
 
1282
                        view->setStandardTagsV1(&st);
 
1283
                        view->setStandardTagsV2(&st);
 
1284
                        view->nameLineEdit->setEnabled(FALSE);
 
1285
                        fileSelected();
 
1286
                }
 
1287
                else {
 
1288
                        updateModificationState();
 
1289
                }
 
1290
                slotStatusMsg(i18n("Ready."));
 
1291
                QApplication::restoreOverrideCursor();
 
1292
        }
 
1293
}
 
1294
 
 
1295
/**
 
1296
 * Import.
 
1297
 */
 
1298
 
 
1299
void Kid3App::slotImport(void)
 
1300
{
 
1301
        setupImportDialog();
 
1302
        if (m_importDialog) {
 
1303
                m_importDialog->setAutoStartSubDialog(ImportDialog::ASD_None);
 
1304
                execImportDialog();
 
1305
        }
 
1306
}
 
1307
 
 
1308
/**
 
1309
 * Import from freedb.org.
 
1310
 */
 
1311
void Kid3App::slotImportFreedb()
 
1312
{
 
1313
        setupImportDialog();
 
1314
        if (m_importDialog) {
 
1315
                m_importDialog->setAutoStartSubDialog(ImportDialog::ASD_Freedb);
 
1316
                execImportDialog();
 
1317
        }
 
1318
}
 
1319
 
 
1320
/**
 
1321
 * Import from MusicBrainz.
 
1322
 */
 
1323
void Kid3App::slotImportMusicBrainz()
 
1324
{
 
1325
#ifdef HAVE_TUNEPIMP
 
1326
        setupImportDialog();
 
1327
        if (m_importDialog) {
 
1328
                m_importDialog->setAutoStartSubDialog(ImportDialog::ASD_MusicBrainz);
 
1329
                execImportDialog();
 
1330
        }
 
1331
#endif
 
1332
}
 
1333
 
 
1334
/**
 
1335
 * Set data to be exported.
 
1336
 *
 
1337
 * @param src ExportDialog::SrcV1 to export ID3v1,
 
1338
 *            ExportDialog::SrcV2 to export ID3v2
 
1339
 */
 
1340
void Kid3App::setExportData(int src)
 
1341
{
 
1342
        if (m_exportDialog) {
 
1343
                ImportTrackDataVector trackDataVector;
 
1344
                TaggedFile *mp3file = view->mp3ListBox->first();
 
1345
                bool firstTrack = true;
 
1346
                while (mp3file != 0) {
 
1347
                        mp3file->readTags(false);
 
1348
                        ImportTrackData trackData(mp3file->getAbsFilename(),
 
1349
                                                                                                                                mp3file->getDuration());
 
1350
                        if (src == ExportDialog::SrcV1) {
 
1351
                                mp3file->getStandardTagsV1(&trackData);
 
1352
                        } else {
 
1353
                                mp3file->getStandardTagsV2(&trackData);
 
1354
                        }
 
1355
                        if (firstTrack) {
 
1356
                                trackDataVector.artist = trackData.artist;
 
1357
                                trackDataVector.album = trackData.album;
 
1358
                                firstTrack = false;
 
1359
                        }
 
1360
#if QT_VERSION >= 300
 
1361
                        trackDataVector.push_back(trackData);
 
1362
#else
 
1363
                        trackDataVector.append(trackData);
 
1364
#endif
 
1365
                        mp3file = view->mp3ListBox->next();
 
1366
                }
 
1367
                m_exportDialog->setExportData(trackDataVector);
 
1368
        }
 
1369
}
 
1370
 
 
1371
/**
 
1372
 * Export.
 
1373
 */
 
1374
void Kid3App::slotExport()
 
1375
{
 
1376
        m_exportDialog = new ExportDialog(0);
 
1377
        if (m_exportDialog) {
 
1378
                m_exportDialog->setSrcV1(genCfg->m_exportSrcV1);
 
1379
                m_exportDialog->setExportFormat(
 
1380
                        genCfg->m_exportFormatNames, genCfg->m_exportFormatHeaders,
 
1381
                        genCfg->m_exportFormatTracks, genCfg->m_exportFormatTrailers,
 
1382
                        genCfg->m_exportFormatIdx);
 
1383
                setExportData(genCfg->m_exportSrcV1 ?
 
1384
                                                                        ExportDialog::SrcV1 : ExportDialog::SrcV2);
 
1385
                connect(m_exportDialog, SIGNAL(exportDataRequested(int)),
 
1386
                                                this, SLOT(setExportData(int)));
 
1387
                m_exportDialog->setWindowSize(genCfg->m_exportWindowWidth,
 
1388
                                                                                                                                        genCfg->m_exportWindowHeight);
 
1389
                if (m_exportDialog->exec() == QDialog::Accepted) {
 
1390
                        genCfg->m_exportSrcV1 = m_exportDialog->getSrcV1();
 
1391
                        QString name, header, track, trailer;
 
1392
                        genCfg->m_exportFormatIdx = m_exportDialog->getExportFormat(
 
1393
                                name, header, track, trailer);
 
1394
                        genCfg->m_exportFormatNames[genCfg->m_exportFormatIdx] = name;
 
1395
                        genCfg->m_exportFormatHeaders[genCfg->m_exportFormatIdx] = header;
 
1396
                        genCfg->m_exportFormatTracks[genCfg->m_exportFormatIdx] = track;
 
1397
                        genCfg->m_exportFormatTrailers[genCfg->m_exportFormatIdx] = trailer;
 
1398
                        m_exportDialog->getWindowSize(genCfg->m_exportWindowWidth,
 
1399
                                                                                                                                                genCfg->m_exportWindowHeight);
 
1400
                }
 
1401
                delete m_exportDialog;
 
1402
                m_exportDialog = 0;
 
1403
        }
 
1404
}
 
1405
 
 
1406
/**
 
1407
 * Show or hide the ID3V1.1 controls according to the settings and
 
1408
 * set the menu entries appropriately.
 
1409
 */
 
1410
void Kid3App::updateHideV1()
 
1411
{
 
1412
        if (miscCfg && miscCfg->m_hideV1) {
 
1413
                view->idV1GroupBox->hide();
 
1414
#ifdef CONFIG_USE_KDE
 
1415
                settingsShowHideV1->setText(i18n("Show ID3v&1.1"));
 
1416
#else
 
1417
                settingsShowHideV1->setText(i18n("Show ID3v1.1"));
 
1418
                settingsShowHideV1->setMenuText(i18n("Show ID3v&1.1"));
 
1419
#endif
 
1420
 
 
1421
        } else {
 
1422
                view->idV1GroupBox->show();
 
1423
#ifdef CONFIG_USE_KDE
 
1424
                settingsShowHideV1->setText(i18n("Hide ID3v&1.1"));
 
1425
#else
 
1426
                settingsShowHideV1->setText(i18n("Hide ID3v1.1"));
 
1427
                settingsShowHideV1->setMenuText(i18n("Hide ID3v&1.1"));
 
1428
#endif
 
1429
        }
 
1430
}
 
1431
 
 
1432
/**
 
1433
 * Show or hide the ID3V2.3 controls according to the settings and
 
1434
 * set the menu entries appropriately.
 
1435
 */
 
1436
void Kid3App::updateHideV2()
 
1437
{
 
1438
        if (miscCfg && miscCfg->m_hideV2) {
 
1439
                view->idV2GroupBox->hide();
 
1440
#ifdef CONFIG_USE_KDE
 
1441
                settingsShowHideV2->setText(i18n("Show ID3v&2.3"));
 
1442
#else
 
1443
                settingsShowHideV2->setText(i18n("Show ID3v2.3"));
 
1444
                settingsShowHideV2->setMenuText(i18n("Show ID3v&2.3"));
 
1445
#endif
 
1446
 
 
1447
        } else {
 
1448
                view->idV2GroupBox->show();
 
1449
#ifdef CONFIG_USE_KDE
 
1450
                settingsShowHideV2->setText(i18n("Hide ID3v&2.3"));
 
1451
#else
 
1452
                settingsShowHideV2->setText(i18n("Hide ID3v2.3"));
 
1453
                settingsShowHideV2->setMenuText(i18n("Hide ID3v&2.3"));
 
1454
#endif
 
1455
        }
 
1456
}
 
1457
 
 
1458
/**
 
1459
 * Show or hide ID3v1.1 controls.
 
1460
 */
 
1461
void Kid3App::slotSettingsShowHideV1()
 
1462
{
 
1463
        if (miscCfg) {
 
1464
                miscCfg->m_hideV1 = !miscCfg->m_hideV1;
 
1465
        }
 
1466
        updateHideV1();
 
1467
}
 
1468
 
 
1469
/**
 
1470
 * Show or hide ID3v2.3 controls.
 
1471
 */
 
1472
void Kid3App::slotSettingsShowHideV2()
 
1473
{
 
1474
        if (miscCfg) {
 
1475
                miscCfg->m_hideV2 = !miscCfg->m_hideV2;
 
1476
        }
 
1477
        updateHideV2();
1157
1478
}
1158
1479
 
1159
1480
/**
1191
1512
}
1192
1513
 
1193
1514
/**
1194
 
 * Apply format.
 
1515
 * Apply filename format.
1195
1516
 */
1196
 
void Kid3App::slotApplyFormat(void)
 
1517
void Kid3App::slotApplyFilenameFormat(void)
1197
1518
{
1198
1519
        StandardTags st;
1199
1520
        if (view->numFilesSelected() == 1) {
1200
1521
                updateCurrentSelection();
1201
1522
        }
1202
 
        StandardTagsFilter fltV1(view->getFilterFromID3V1());
1203
 
        StandardTagsFilter fltV2(view->getFilterFromID3V2());
1204
1523
        TaggedFile *mp3file = view->mp3ListBox->first();
1205
1524
        bool no_selection = view->numFilesSelected() == 0;
1206
1525
        while (mp3file != 0) {
1210
1529
                        str = mp3file->getFilename();
1211
1530
                        fnFormatCfg->formatString(str);
1212
1531
                        mp3file->setFilename(str);
 
1532
                }
 
1533
                mp3file = view->mp3ListBox->next();
 
1534
        }
 
1535
        updateGuiControls();
 
1536
}
 
1537
 
 
1538
/**
 
1539
 * Apply ID3 format.
 
1540
 */
 
1541
void Kid3App::slotApplyId3Format(void)
 
1542
{
 
1543
        StandardTags st;
 
1544
        if (view->numFilesSelected() == 1) {
 
1545
                updateCurrentSelection();
 
1546
        }
 
1547
        StandardTagsFilter fltV1(view->getFilterFromID3V1());
 
1548
        StandardTagsFilter fltV2(view->getFilterFromID3V2());
 
1549
        TaggedFile *mp3file = view->mp3ListBox->first();
 
1550
        bool no_selection = view->numFilesSelected() == 0;
 
1551
        while (mp3file != 0) {
 
1552
                if (no_selection || mp3file->isInSelection()) {
 
1553
                        mp3file->readTags(false);
1213
1554
                        mp3file->getStandardTagsV1(&st);
1214
1555
                        id3FormatCfg->formatStandardTags(st);
1215
1556
                        mp3file->setStandardTagsV1(&st, fltV1);
1264
1605
}
1265
1606
 
1266
1607
/**
 
1608
 * Number tracks.
 
1609
 */
 
1610
void Kid3App::slotNumberTracks()
 
1611
{
 
1612
        if (!m_numberTracksDialog) {
 
1613
                m_numberTracksDialog = new NumberTracksDialog(0);
 
1614
        }
 
1615
        if (m_numberTracksDialog) {
 
1616
                if (m_numberTracksDialog->exec() == QDialog::Accepted) {
 
1617
                        int nr = m_numberTracksDialog->getStartNumber();
 
1618
                        bool destV1 = m_numberTracksDialog->getDestV1();
 
1619
 
 
1620
                        updateCurrentSelection();
 
1621
                        TaggedFile *mp3file = view->mp3ListBox->first();
 
1622
                        bool no_selection = view->numFilesSelected() == 0;
 
1623
                        while (mp3file != 0) {
 
1624
                                if (no_selection || mp3file->isInSelection()) {
 
1625
                                        mp3file->readTags(false);
 
1626
                                        if (destV1) {
 
1627
                                                int oldnr = mp3file->getTrackNumV1();
 
1628
                                                if (nr != oldnr) {
 
1629
                                                        mp3file->setTrackNumV1(nr);
 
1630
                                                }
 
1631
                                        } else {
 
1632
                                                int oldnr = mp3file->getTrackNumV2();
 
1633
                                                if (nr != oldnr) {
 
1634
                                                        mp3file->setTrackNumV2(nr);
 
1635
                                                }
 
1636
                                        }
 
1637
                                        ++nr;
 
1638
                                }
 
1639
                                mp3file = view->mp3ListBox->next();
 
1640
                        }
 
1641
                        updateGuiControls();
 
1642
                }
 
1643
        }
 
1644
}
 
1645
 
 
1646
/**
1267
1647
 * Open directory on drop.
1268
1648
 *
1269
1649
 * @param txt URL of directory or file in directory
1472
1852
                st->year = copytags->year;
1473
1853
        if (copytags->track >= 0)
1474
1854
                st->track = copytags->track;
1475
 
        if (copytags->genre >= 0)
 
1855
        if (copytags->genre >= 0) {
1476
1856
                st->genre = copytags->genre;
 
1857
                st->genreStr = copytags->genreStr;
 
1858
        }
1477
1859
}
1478
1860
 
1479
1861
/**
1489
1871
                if (mp3file->isInSelection()) {
1490
1872
                        mp3file->getStandardTagsV1(&st);
1491
1873
                        pasteTags(&st);
 
1874
                        formatStandardTagsIfEnabled(&st);
1492
1875
                        mp3file->setStandardTagsV1(&st, flt);
1493
1876
                }
1494
1877
                mp3file = view->mp3ListBox->next();
1510
1893
                if (mp3file->isInSelection()) {
1511
1894
                        mp3file->getStandardTagsV2(&st);
1512
1895
                        pasteTags(&st);
 
1896
                        formatStandardTagsIfEnabled(&st);
1513
1897
                        mp3file->setStandardTagsV2(&st, flt);
1514
1898
                }
1515
1899
                mp3file = view->mp3ListBox->next();
1539
1923
                        }
1540
1924
                        mp3file->getStandardTagsV1(&st);
1541
1925
                        mp3file->getTagsFromFilename(&st, view->formatComboBox->currentText());
 
1926
                        formatStandardTagsIfEnabled(&st);
1542
1927
                        mp3file->setStandardTagsV1(&st, flt);
1543
1928
                }
1544
1929
                mp3file = view->mp3ListBox->next();
1568
1953
                        }
1569
1954
                        mp3file->getStandardTagsV2(&st);
1570
1955
                        mp3file->getTagsFromFilename(&st, view->formatComboBox->currentText());
 
1956
                        formatStandardTagsIfEnabled(&st);
1571
1957
                        mp3file->setStandardTagsV2(&st, flt);
1572
1958
                }
1573
1959
                mp3file = view->mp3ListBox->next();
1600
1986
                        }
1601
1987
                        mp3file->getFilenameFromTags(
1602
1988
                                &st, view->formatComboBox->currentText());
 
1989
                        formatFileNameIfEnabled(mp3file);
1603
1990
                        if (!multiselect) {
1604
1991
                                view->nameLineEdit->setText(
1605
1992
                                        mp3file->getFilename());
1624
2011
        while (mp3file != 0) {
1625
2012
                if (mp3file->isInSelection()) {
1626
2013
                        mp3file->getStandardTagsV1(&st);
 
2014
                        formatStandardTagsIfEnabled(&st);
1627
2015
                        mp3file->setStandardTagsV2(&st, flt);
1628
2016
                }
1629
2017
                mp3file = view->mp3ListBox->next();
1645
2033
        while (mp3file != 0) {
1646
2034
                if (mp3file->isInSelection()) {
1647
2035
                        mp3file->getStandardTagsV2(&st);
 
2036
                        formatStandardTagsIfEnabled(&st);
1648
2037
                        mp3file->setStandardTagsV1(&st, flt);
1649
2038
                }
1650
2039
                mp3file = view->mp3ListBox->next();
1769
2158
        getSelectedFileWithFrameList(taggedFile, framelist);
1770
2159
        if (taggedFile && framelist &&
1771
2160
                        (id = framelist->selectFrameId()) != -1 &&
1772
 
                        framelist->addFrame(id)) {
 
2161
                        framelist->addFrame(id, true)) {
1773
2162
                updateAfterFrameModification(taggedFile);
 
2163
        } else if (!taggedFile && !framelist) {
 
2164
                // multiple files selected
 
2165
                TaggedFile *mp3file = view->mp3ListBox->first();
 
2166
                bool firstFile = true;
 
2167
                while (mp3file != 0) {
 
2168
                        if (mp3file->isInSelection()) {
 
2169
                                if (firstFile) {
 
2170
                                        firstFile = false;
 
2171
                                        taggedFile = mp3file;
 
2172
                                        framelist = mp3file->getFrameList();
 
2173
                                        framelist->setTags(taggedFile);
 
2174
                                        if ((id = framelist->selectFrameId()) != -1 &&
 
2175
                                                        framelist->addFrame(id, true)) {
 
2176
                                                framelist->copyFrame();
 
2177
                                        } else {
 
2178
                                                break;
 
2179
                                        }
 
2180
                                } else {
 
2181
                                        if (mp3file->getFrameList() == framelist) {
 
2182
                                                framelist->setTags(mp3file);
 
2183
                                                framelist->pasteFrame();
 
2184
                                        }
 
2185
                                }
 
2186
                        }
 
2187
                        mp3file = view->mp3ListBox->next();
 
2188
                }
 
2189
                if (taggedFile && framelist) {
 
2190
//                      framelist->setTags(taggedFile);
 
2191
                }
 
2192
                updateModificationState();
 
2193
        }
 
2194
}
 
2195
 
 
2196
/**
 
2197
 * Format a filename if format while editing is switched on.
 
2198
 *
 
2199
 * @param taggedFile file to modify
 
2200
 */
 
2201
void Kid3App::formatFileNameIfEnabled(TaggedFile* taggedFile) const
 
2202
{
 
2203
        if (fnFormatCfg->m_formatWhileEditing) {
 
2204
                QString fn(taggedFile->getFilename());
 
2205
                fnFormatCfg->formatString(fn);
 
2206
                taggedFile->setFilename(fn);
 
2207
        }
 
2208
}
 
2209
 
 
2210
/**
 
2211
 * Format tags if format while editing is switched on.
 
2212
 *
 
2213
 * @param st standard tags
 
2214
 */
 
2215
void Kid3App::formatStandardTagsIfEnabled(StandardTags* st) const
 
2216
{
 
2217
        if (id3FormatCfg->m_formatWhileEditing) {
 
2218
                id3FormatCfg->formatStandardTags(*st);
1774
2219
        }
1775
2220
}