86
86
#include "frametable.h"
87
87
#include "configdialog.h"
88
88
#include "importdialog.h"
89
#include "browsecoverartdialog.h"
89
90
#include "exportdialog.h"
90
91
#include "numbertracksdialog.h"
91
92
#include "filterdialog.h"
92
93
#include "rendirdialog.h"
94
#include "downloaddialog.h"
93
95
#include "filelistitem.h"
94
96
#include "dirlist.h"
95
97
#include "pictureframe.h"
242
244
Kid3App::Kid3App() :
243
m_importDialog(0), m_exportDialog(0), m_renDirDialog(0),
244
m_numberTracksDialog(0), m_filterDialog(0)
245
m_downloadToAllFilesInDir(false),
246
m_importDialog(0), m_browseCoverArtDialog(0),
247
m_exportDialog(0), m_renDirDialog(0),
248
m_numberTracksDialog(0), m_filterDialog(0), m_downloadDialog(0)
246
250
#ifdef CONFIG_USE_KDE
247
251
#if KDE_VERSION >= 0x035c00
363
374
fileSave->KCM_setStatusTip(i18n("Saves the changed files"));
364
375
fileQuit->KCM_setStatusTip(i18n("Quits the application"));
365
376
editSelectAll->KCM_setStatusTip(i18n("Select all files"));
377
#if KDE_VERSION >= 0x035c00
378
editSelectAll->setShortcut(KShortcut("Alt+Shift+A"));
366
380
editSelectAll->setShortcut(KShortcut("Alt+A"));
367
382
editDeselect->KCM_setStatusTip(i18n("Deselect all files"));
368
383
settingsShortcuts->KCM_setStatusTip(i18n("Configure Shortcuts"));
369
384
settingsToolbars->KCM_setStatusTip(i18n("Configure Toolbars"));
399
414
SLOT(slotImportMusicBrainz()), actionCollection(),
400
415
"import_musicbrainz");
417
KCM_KAction(fileBrowseCoverArt,
418
i18n("&Browse Cover Art..."), this,
419
SLOT(slotBrowseCoverArt()), actionCollection(),
402
421
KCM_KActionIcon(fileExport, KCM_ICON_document_export,
403
422
i18n("&Export..."), this,
404
423
SLOT(slotExport()), actionCollection(),
447
466
i18n("Hide Tag &2"), this,
448
467
SLOT(slotSettingsShowHideV2()), actionCollection(),
469
KCM_KActionVar(m_settingsShowHidePicture,
470
i18n("Hide &Picture"), this,
471
SLOT(slotSettingsShowHidePicture()), actionCollection(),
451
474
KCM_KActionShortcutIcon(editPreviousFile, KShortcut("Alt+Up"), KCM_ICON_go_previous,
452
475
i18n("&Previous File"), m_view,
590
613
this, SLOT(slotImportMusicBrainz()));
616
QAction* fileBrowseCoverArt = new QAction(this);
617
if (fileBrowseCoverArt) {
618
fileBrowseCoverArt->setStatusTip(i18n("Browse album cover artwork"));
619
fileBrowseCoverArt->QCM_setMenuText(i18n("&Browse Cover Art..."));
620
connect(fileBrowseCoverArt, QCM_SIGNAL_triggered,
621
this, SLOT(slotBrowseCoverArt()));
593
623
QAction* fileExport = new QAction(this);
594
624
if (fileExport) {
595
625
fileExport->setStatusTip(i18n("Export to file or clipboard"));
732
762
connect(m_settingsShowHideV2, QCM_SIGNAL_triggered,
733
763
this, SLOT(slotSettingsShowHideV2()));
765
m_settingsShowHidePicture = new QAction(this);
766
if (m_settingsShowHidePicture) {
767
m_settingsShowHidePicture->setStatusTip(i18n("Hide Picture"));
768
m_settingsShowHidePicture->QCM_setMenuText(i18n("Hide &Picture"));
769
connect(m_settingsShowHidePicture, QCM_SIGNAL_triggered,
770
this, SLOT(slotSettingsShowHidePicture()));
735
772
QAction* settingsConfigure = new QAction(this);
736
773
if (settingsConfigure) {
737
774
settingsConfigure->setStatusTip(i18n("Configure Kid3"));
774
811
#ifdef HAVE_TUNEPIMP
775
812
QCM_addAction(fileMenu, fileImportMusicBrainz);
814
QCM_addAction(fileMenu, fileBrowseCoverArt);
777
815
QCM_addAction(fileMenu, fileExport);
778
816
QCM_addAction(fileMenu, fileCreatePlaylist);
779
817
fileMenu->QCM_addSeparator();
799
837
QCM_addAction(settingsMenu, m_settingsShowHideV1);
800
838
QCM_addAction(settingsMenu, m_settingsShowHideV2);
839
QCM_addAction(settingsMenu, m_settingsShowHidePicture);
801
840
settingsMenu->QCM_addSeparator();
802
841
QCM_addAction(settingsMenu, settingsConfigure);
925
964
m_fileOpenRecent->saveEntries(m_config, "Recent Files");
967
s_miscCfg.m_windowX = x();
968
s_miscCfg.m_windowY = y();
928
969
s_miscCfg.m_windowWidth = size().width();
929
970
s_miscCfg.m_windowHeight = size().height();
1008
1050
if (s_miscCfg.m_windowWidth != -1 && s_miscCfg.m_windowHeight != -1) {
1009
1051
resize(s_miscCfg.m_windowWidth, s_miscCfg.m_windowHeight);
1053
if (s_miscCfg.m_windowX != -1 && s_miscCfg.m_windowY != -1) {
1054
move(s_miscCfg.m_windowX, s_miscCfg.m_windowY);
1012
1057
m_view->readConfig();
1816
1861
slotStatusMsg(i18n("Ready."));
1817
1862
QApplication::restoreOverrideCursor();
1864
if (destV2 && flt.isEnabled(Frame::FT_Picture) &&
1865
!m_trackDataList.getCoverArtUrl().isEmpty()) {
1866
downloadImage(m_trackDataList.getCoverArtUrl(), true);
1983
* Browse album cover artwork.
1985
void Kid3App::slotBrowseCoverArt()
1987
if (!m_browseCoverArtDialog) {
1988
m_browseCoverArtDialog = new BrowseCoverArtDialog(0);
1990
if (m_browseCoverArtDialog) {
1991
FrameCollection frames2;
1993
TaggedFile* taggedFile;
1994
if ((item = m_view->currentFile()) != 0 &&
1995
(taggedFile = item->getFile()) != 0) {
1996
taggedFile->readTags(false);
1997
FrameCollection frames1;
1998
taggedFile->getAllFramesV1(frames1);
1999
taggedFile->getAllFramesV2(frames2);
2000
frames2.merge(frames1);
2003
m_browseCoverArtDialog->readConfig();
2004
m_browseCoverArtDialog->setFrames(frames2);
2005
m_browseCoverArtDialog->exec();
1932
2009
#if defined HAVE_ID3LIB && defined HAVE_TAGLIB
1934
2011
* Read file with TagLib if it has an ID3v2.4 tag.
1981
2058
trackData.setFileExtension(taggedFile->getFileExtension());
1982
2059
trackData.setTagFormatV1(taggedFile->getTagFormatV1());
1983
2060
trackData.setTagFormatV2(taggedFile->getTagFormatV2());
2061
TaggedFile::DetailInfo info;
2062
taggedFile->getDetailInfo(info);
2063
trackData.setDetailInfo(info);
1984
2064
if (src == ExportDialog::SrcV1) {
1985
2065
taggedFile->getAllFramesV1(trackData);
2179
* Show or hide the picture according to the settings and
2180
* set the menu entries appropriately.
2182
void Kid3App::updateHidePicture()
2184
m_view->hidePicture(s_miscCfg.m_hidePicture);
2185
if (s_miscCfg.m_hidePicture) {
2186
#ifdef CONFIG_USE_KDE
2187
m_settingsShowHidePicture->setText(i18n("Show &Picture"));
2189
m_settingsShowHidePicture->setStatusTip(i18n("Show Picture"));
2190
m_settingsShowHidePicture->QCM_setMenuText(i18n("Show &Picture"));
2194
#ifdef CONFIG_USE_KDE
2195
m_settingsShowHidePicture->setText(i18n("Hide &Picture"));
2197
m_settingsShowHidePicture->setStatusTip(i18n("Hide Picture"));
2198
m_settingsShowHidePicture->QCM_setMenuText(i18n("Hide &Picture"));
2099
2204
* Show or hide ID3v1.1 controls.
2101
2206
void Kid3App::slotSettingsShowHideV1()
2222
* Show or hide picture.
2224
void Kid3App::slotSettingsShowHidePicture()
2226
s_miscCfg.m_hidePicture = !s_miscCfg.m_hidePicture;
2227
updateHidePicture();
2228
#if QT_VERSION >= 0x040000
2229
// In Qt3 the picture is displayed too small if Kid3 is started with picture
2230
// hidden, and then "Show Picture" is triggered while a file with a picture
2231
// is selected. Thus updating the controls is only done for Qt4, in Qt3 the
2232
// file has to be selected again for the picture to be shown.
2233
if (!s_miscCfg.m_hidePicture) {
2234
updateGuiControls();
2119
2242
void Kid3App::slotSettingsConfigure()
2140
2263
if (!s_miscCfg.m_markTruncations) {
2141
2264
m_view->frameTableV1()->markRows(0);
2266
if (!s_miscCfg.m_markChanges) {
2267
m_view->frameTableV1()->markChangedFrames(0);
2268
m_view->frameTableV2()->markChangedFrames(0);
2269
m_view->markChangedFilename(false);
2143
2271
setTextEncodings();
2144
2272
#if QT_VERSION < 0x040000
2145
2273
m_view->frameTableV1()->triggerUpdateGenres();
2158
2286
void Kid3App::slotApplyFilenameFormat()
2160
if (m_view->numFilesSelected() == 1) {
2161
updateCurrentSelection();
2288
updateCurrentSelection(true);
2163
2289
FileListItem* mp3file = m_view->firstFile();
2164
2290
bool no_selection = m_view->numFilesSelected() == 0;
2165
2291
while (mp3file != 0) {
2181
2307
void Kid3App::slotApplyId3Format()
2183
2309
FrameCollection frames;
2184
if (m_view->numFilesSelected() == 1) {
2185
updateCurrentSelection();
2310
updateCurrentSelection(true);
2187
2311
FrameFilter fltV1(m_view->frameTableV1()->getEnabledFrameFilter(true));
2188
2312
FrameFilter fltV2(m_view->frameTableV2()->getEnabledFrameFilter(true));
2189
2313
FileListItem* mp3file = m_view->firstFile();
2344
2468
void Kid3App::numberTracks(int nr, bool destV1, bool destV2)
2346
updateCurrentSelection();
2470
updateCurrentSelection(true);
2347
2471
FileListItem* mp3file = m_view->firstFileInDir();
2348
2472
bool no_selection = m_view->numFilesSelected() == 0;
2349
2473
while (mp3file != 0) {
2554
2676
void Kid3App::slotConvertToId3v23()
2556
2678
#if defined HAVE_TAGLIB && defined HAVE_ID3LIB
2557
if (m_view->numFilesSelected() == 1) {
2558
updateCurrentSelection();
2679
updateCurrentSelection(true);
2560
2680
FileListItem* item = m_view->firstFile();
2561
2681
while (item != 0) {
2562
2682
TaggedFile* taggedFile;
2621
2741
QString dir = url.path().QCM_trimmed();
2623
2743
if (dir.endsWith(".jpg", QCM_CaseInsensitive) ||
2744
dir.endsWith(".jpeg", QCM_CaseInsensitive) ||
2624
2745
dir.endsWith(".png", QCM_CaseInsensitive)) {
2625
2746
PictureFrame frame;
2626
2747
if (PictureFrame::setDataFromFile(frame, dir)) {
2651
2773
PictureFrame frame;
2652
2774
if (PictureFrame::setDataFromImage(frame, image)) {
2653
2775
addFrame(&frame);
2776
updateGuiControls();
2782
* Download an image file.
2784
* @param url URL of image
2785
* @param allFilesInDir true to add the image to all files in the directory
2787
void Kid3App::downloadImage(const QString& url, bool allFilesInDir)
2789
QString imgurl(BrowseCoverArtDialog::getImageUrl(url));
2790
if (!imgurl.isEmpty()) {
2791
if (!m_downloadDialog) {
2792
m_downloadDialog = new DownloadDialog(0, i18n("Download"));
2793
connect(m_downloadDialog, SIGNAL(downloadFinished(const QByteArray&, const QString&, const QString&)),
2794
this, SLOT(imageDownloaded(const QByteArray&, const QString&, const QString&)));
2796
if (m_downloadDialog) {
2797
int hostPos = imgurl.QCM_indexOf("://");
2799
int pathPos = imgurl.QCM_indexOf("/", hostPos + 3);
2800
if (pathPos > hostPos) {
2801
m_downloadToAllFilesInDir = allFilesInDir;
2802
m_downloadDialog->startDownload(
2803
imgurl.mid(hostPos + 3, pathPos - hostPos - 3),
2804
imgurl.mid(pathPos));
2805
m_downloadDialog->exec();
2813
* Handle URL on drop.
2815
* @param txt dropped URL.
2817
void Kid3App::dropUrl(const QString& txt)
2819
downloadImage(txt, false);
2823
* Add a downloaded image.
2825
* @param data HTTP response of download
2826
* @param mimeType MIME type of data
2827
* @param url URL of downloaded data
2829
void Kid3App::imageDownloaded(const QByteArray& data,
2830
const QString& mimeType, const QString& url)
2832
if (mimeType.startsWith("image")) {
2833
PictureFrame frame(data, url, PictureFrame::PT_CoverFront, mimeType);
2834
if (m_downloadToAllFilesInDir) {
2835
FileListItem* mp3file = m_view->firstFileInDir();
2836
while (mp3file != 0) {
2837
TaggedFile* taggedFile = mp3file->getFile();
2838
taggedFile->readTags(false);
2839
taggedFile->addFrameV2(frame);
2840
mp3file = m_view->nextFileInDir();
2842
m_downloadToAllFilesInDir = false;
2846
updateGuiControls();
2683
2875
* Update files of current selection.
2877
* @param onlyIfSingleFileSelected if true, the selection is only updated
2878
* if a single file is selected
2685
void Kid3App::updateCurrentSelection()
2880
void Kid3App::updateCurrentSelection(bool onlyIfSingleFileSelected)
2687
2882
int numFiles = 0;
2688
2883
FileListItem* mp3file = m_view->firstFile();
2792
2990
if (s_miscCfg.m_markTruncations) {
2793
2991
m_view->frameTableV1()->markRows(single_v2_file->getTruncationFlags());
2993
if (s_miscCfg.m_markChanges) {
2994
m_view->frameTableV1()->markChangedFrames(
2995
single_v2_file->getChangedFramesV1());
2996
m_view->frameTableV2()->markChangedFrames(
2997
single_v2_file->getChangedFramesV2());
2998
m_view->markChangedFilename(single_v2_file->isFilenameChanged());
3001
if (!s_miscCfg.m_hidePicture) {
3002
FrameCollection::const_iterator it =
3003
m_view->frameTableV2()->frames().find(Frame(Frame::FT_Picture, "", "", -1));
3004
if (it == m_view->frameTableV2()->frames().end()) {
3005
m_view->setPictureData(0);
3008
m_view->setPictureData(PictureFrame::getData(*it, data) ? &data : 0);
2797
3013
m_view->setFilenameEditEnabled(false);
2802
3018
if (s_miscCfg.m_markTruncations) {
2803
3019
m_view->frameTableV1()->markRows(0);
3021
if (s_miscCfg.m_markChanges) {
3022
m_view->frameTableV1()->markChangedFrames(0);
3023
m_view->frameTableV2()->markChangedFrames(0);
3024
m_view->markChangedFilename(false);
3026
if (!s_miscCfg.m_hidePicture) {
3027
m_view->setPictureData(0);
2806
3030
m_view->frameTableV1()->setAllCheckBoxes(num_files_selected == 1);
2807
3031
m_view->frameTableV1()->framesToTable();
2833
3057
void Kid3App::copyTagsV1()
2835
updateCurrentSelection();
3059
updateCurrentSelection(true);
2836
3060
m_copyTags = m_view->frameTableV1()->frames().copyEnabledFrames(
2837
3061
m_view->frameTableV1()->getEnabledFrameFilter(true));
2843
3067
void Kid3App::copyTagsV2()
2845
updateCurrentSelection();
3069
updateCurrentSelection(true);
2846
3070
m_copyTags = m_view->frameTableV2()->frames().copyEnabledFrames(
2847
3071
m_view->frameTableV2()->getEnabledFrameFilter(true));
2853
3077
void Kid3App::pasteTagsV1()
2855
updateCurrentSelection();
3079
updateCurrentSelection(true);
2856
3080
FrameCollection frames(m_copyTags.copyEnabledFrames(
2857
3081
m_view->frameTableV1()->getEnabledFrameFilter(true)));
2858
3082
formatFramesIfEnabled(frames);
2873
3097
void Kid3App::pasteTagsV2()
2875
updateCurrentSelection();
3099
updateCurrentSelection(true);
2876
3100
FrameCollection frames(m_copyTags.copyEnabledFrames(
2877
3101
m_view->frameTableV2()->getEnabledFrameFilter(true)));
2878
3102
formatFramesIfEnabled(frames);
2990
3214
void Kid3App::copyV1ToV2()
2992
updateCurrentSelection();
3216
updateCurrentSelection(true);
2993
3217
FrameCollection frames;
2994
3218
FrameFilter flt(m_view->frameTableV2()->getEnabledFrameFilter(true));
2995
3219
FileListItem* mp3file = m_view->firstFile();
3012
3236
void Kid3App::copyV2ToV1()
3014
updateCurrentSelection();
3238
updateCurrentSelection(true);
3015
3239
FrameCollection frames;
3016
3240
FrameFilter flt(m_view->frameTableV1()->getEnabledFrameFilter(true));
3017
3241
FileListItem* mp3file = m_view->firstFile();
3204
3428
if (m_framelist->selectFrame() &&
3205
3429
m_framelist->addFrame(true)) {
3206
3430
updateAfterFrameModification(taggedFile);
3431
if (m_framelist->isPictureFrame()) {
3432
// update preview picture
3433
updateGuiControls();
3209
3437
m_framelist->setFrame(*frame);