Skip to content

Commit 8ee4974

Browse files
committed
Merge pull request #1 from cardinot/coverArtSupport_2
Cover art support 2
2 parents 056d5c4 + 71dfb45 commit 8ee4974

15 files changed

+419
-156
lines changed
File renamed without changes.
1.87 KB
Loading
1.57 KB
Loading

res/images/library/ic_cover_unset.png

481 Bytes
Loading

res/mixxx.qrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
<file>images/library/ic_library_cover_hide.png</file>
107107
<file>images/library/ic_library_cover_show.png</file>
108108
<file>images/library/ic_library_zoom_in.png</file>
109-
<file>images/library/vinyl-record.png</file>
109+
<file>images/library/default_cover.png</file>
110+
<file>images/library/ic_cover_change.png</file>
111+
<file>images/library/ic_cover_reload.png</file>
112+
<file>images/library/ic_cover_unset.png</file>
110113
</qresource>
111114
</RCC>

src/dlgtrackinfo.cpp

+162-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// dlgtrackinfo.cpp
22
// Created 11/10/2009 by RJ Ryan ([email protected])
33

4+
#include <QDesktopServices>
5+
#include <QFileDialog>
6+
#include <QMenu>
47
#include <QtDebug>
58

69
#include "dlgtrackinfo.h"
10+
#include "library/coverartcache.h"
711
#include "library/dao/cue.h"
812
#include "trackinfoobject.h"
913

@@ -62,10 +66,41 @@ void DlgTrackInfo::init(){
6266
this, SLOT(slotBpmTap()));
6367
connect(btnReloadFromFile, SIGNAL(clicked()),
6468
this, SLOT(reloadTrackMetadata()));
69+
connect(btnOpenFileBrowser, SIGNAL(clicked()),
70+
this, SLOT(slotOpenInFileBrowser()));
6571
m_bpmTapTimer.start();
6672
for (int i = 0; i < kFilterLength; ++i) {
6773
m_bpmTapFilter[i] = 0.0f;
6874
}
75+
76+
connect(CoverArtCache::instance(), SIGNAL(pixmapFound(int, QPixmap)),
77+
this, SLOT(slotPixmapFound(int, QPixmap)), Qt::DirectConnection);
78+
79+
// Cover art actions
80+
// change cover art location
81+
QAction* changeCover = new QAction(
82+
QIcon(":/images/library/ic_cover_change.png"),
83+
tr("&Change"), this);
84+
connect(changeCover, SIGNAL(triggered()),
85+
this, SLOT(slotChangeCoverArt()));
86+
// unset cover art - load default
87+
QAction* unsetCover = new QAction(
88+
QIcon(":/images/library/ic_cover_unset.png"),
89+
tr("&Unset"), this);
90+
connect(unsetCover, SIGNAL(triggered()),
91+
this, SLOT(slotUnsetCoverArt()));
92+
// reload just cover art using the search algorithm (in CoverArtCache)
93+
QAction* reloadCover = new QAction(
94+
QIcon(":/images/library/ic_cover_reload.png"),
95+
tr("&Reload"), this);
96+
connect(reloadCover, SIGNAL(triggered()),
97+
this, SLOT(slotReloadCover()));
98+
// Cover art popup menu
99+
QMenu* coverMenu = new QMenu(this);
100+
coverMenu->addAction(changeCover);
101+
coverMenu->addAction(unsetCover);
102+
coverMenu->addAction(reloadCover);
103+
coverArt->setMenu(coverMenu);
69104
}
70105

71106
void DlgTrackInfo::OK() {
@@ -119,7 +154,7 @@ void DlgTrackInfo::cueDelete() {
119154
}
120155

121156
void DlgTrackInfo::populateFields(TrackPointer pTrack) {
122-
setWindowTitle(pTrack->getTitle());
157+
setWindowTitle(pTrack->getArtist() % " - " % pTrack->getTitle());
123158

124159
// Editable fields
125160
txtTrackName->setText(pTrack->getTitle());
@@ -160,6 +195,124 @@ void DlgTrackInfo::loadTrack(TrackPointer pTrack) {
160195

161196
populateFields(m_pLoadedTrack);
162197
populateCues(m_pLoadedTrack);
198+
199+
// Load Default Cover Art
200+
coverArt->setIcon(scaledCoverArt(CoverArtCache::instance()->getDefaultCoverArt()));
201+
m_sLoadedCoverLocation.clear();
202+
}
203+
204+
QPixmap DlgTrackInfo::scaledCoverArt(QPixmap original) {
205+
return original.scaled(110, 110,
206+
Qt::KeepAspectRatio,
207+
Qt::SmoothTransformation);
208+
}
209+
210+
void DlgTrackInfo::slotPixmapFound(int trackId, QPixmap pixmap) {
211+
if (m_pLoadedTrack == NULL)
212+
return;
213+
214+
if (m_pLoadedTrack->getId() == trackId) {
215+
coverArt->setIcon(scaledCoverArt(pixmap));
216+
update();
217+
}
218+
}
219+
220+
void DlgTrackInfo::slotLoadCoverArt(const QString& coverLocation,
221+
const QString& md5Hash,
222+
int trackId) {
223+
m_sLoadedCoverLocation = coverLocation;
224+
CoverArtCache::instance()->requestPixmap(trackId,
225+
m_sLoadedCoverLocation,
226+
md5Hash);
227+
}
228+
229+
void DlgTrackInfo::slotUnsetCoverArt() {
230+
if (m_pLoadedTrack == NULL) {
231+
return;
232+
}
233+
bool res = CoverArtCache::instance()->changeCoverArt(
234+
m_pLoadedTrack->getId(),
235+
CoverArtCache::instance()->getDefaultCoverLocation());
236+
if (!res) {
237+
QMessageBox::warning(this, tr("Unset Cover Art"),
238+
tr("Could not unset the cover art!"));
239+
}
240+
}
241+
242+
void DlgTrackInfo::slotChangeCoverArt() {
243+
if (m_pLoadedTrack == NULL) {
244+
return;
245+
}
246+
247+
// get initial directory (trackdir or coverdir)
248+
QString initialDir;
249+
QString trackPath = m_pLoadedTrack->getDirectory();
250+
if (m_sLoadedCoverLocation.isEmpty() ||
251+
m_sLoadedCoverLocation == CoverArtCache::instance()
252+
->getDefaultCoverLocation()) {
253+
initialDir = trackPath;
254+
} else {
255+
initialDir = m_sLoadedCoverLocation;
256+
}
257+
258+
// open file dialog
259+
QString selectedCover = QFileDialog::getOpenFileName(
260+
this, tr("Change Cover Art"), initialDir,
261+
tr("Image Files (*.png *.jpg *.jpeg *.bmp)"));
262+
263+
if (selectedCover.isEmpty()) {
264+
return;
265+
}
266+
267+
// if the cover comes from an external dir,
268+
// we copy it to the track directory.
269+
QString newCover;
270+
QFileInfo coverInfo(selectedCover);
271+
QString coverPath = coverInfo.absolutePath();
272+
if (trackPath != coverPath) {
273+
QString ext = coverInfo.suffix();
274+
QStringList filepaths;
275+
filepaths << trackPath % "/cover." % ext
276+
<< trackPath % "/album." % ext
277+
<< trackPath % "/mixxx-cover." % ext;
278+
279+
foreach (QString filepath, filepaths) {
280+
if (QFile::copy(selectedCover, filepath)) {
281+
newCover = filepath;
282+
break;
283+
}
284+
}
285+
286+
if (newCover.isEmpty()) {
287+
// overwrites "mixxx-cover"
288+
QFile::remove(filepaths.last());
289+
if (QFile::copy(selectedCover, filepaths.last())) {
290+
newCover = filepaths.last();
291+
}
292+
}
293+
} else {
294+
newCover = selectedCover;
295+
}
296+
297+
bool res = CoverArtCache::instance()->changeCoverArt(
298+
m_pLoadedTrack->getId(), newCover);
299+
if (res) {
300+
m_sLoadedCoverLocation = newCover;
301+
} else {
302+
QMessageBox::warning(this, tr("Change Cover Art"),
303+
tr("Could not change the cover art!"));
304+
}
305+
}
306+
307+
void DlgTrackInfo::slotOpenInFileBrowser() {
308+
if (m_pLoadedTrack == NULL) {
309+
return;
310+
}
311+
QDir directory(m_pLoadedTrack->getDirectory());
312+
if (!directory.exists()) {
313+
directory = QDir::home();
314+
}
315+
QDesktopServices::openUrl(QUrl::fromLocalFile(directory.absolutePath()));
163316
}
164317

165318
void DlgTrackInfo::populateCues(TrackPointer pTrack) {
@@ -223,6 +376,7 @@ void DlgTrackInfo::populateCues(TrackPointer pTrack) {
223376
row += 1;
224377
}
225378
cueTable->setSortingEnabled(true);
379+
cueTable->horizontalHeader()->setStretchLastSection(true);
226380
}
227381

228382
void DlgTrackInfo::saveTrack() {
@@ -377,6 +531,13 @@ void DlgTrackInfo::reloadTrackMetadata() {
377531
}
378532
}
379533

534+
void DlgTrackInfo::slotReloadCover() {
535+
if (m_pLoadedTrack) {
536+
m_sLoadedCoverLocation.clear();
537+
CoverArtCache::instance()->requestPixmap(m_pLoadedTrack->getId());
538+
}
539+
}
540+
380541
void DlgTrackInfo::fetchTag() {
381542
m_DlgTagFetcher.init(m_pLoadedTrack);
382543
m_DlgTagFetcher.show();

src/dlgtrackinfo.h

+16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
2626
// Not thread safe. Only invoke via AutoConnection or QueuedConnection, not
2727
// directly!
2828
void loadTrack(TrackPointer pTrack);
29+
void slotLoadCoverArt(const QString& coverLocation,
30+
const QString& md5Hash,
31+
int trackId);
2932

3033
signals:
3134
void next();
@@ -50,6 +53,12 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
5053
void slotBpmTap();
5154

5255
void reloadTrackMetadata();
56+
void slotOpenInFileBrowser();
57+
58+
void slotPixmapFound(int trackId, QPixmap pixmap);
59+
void slotChangeCoverArt();
60+
void slotUnsetCoverArt();
61+
void slotReloadCover();
5362

5463
private:
5564
void populateFields(TrackPointer pTrack);
@@ -58,16 +67,23 @@ class DlgTrackInfo : public QDialog, public Ui::DlgTrackInfo {
5867
void unloadTrack(bool save);
5968
void clear();
6069
void init();
70+
QPixmap scaledCoverArt(QPixmap original);
6171

6272
QHash<int, Cue*> m_cueMap;
6373
TrackPointer m_pLoadedTrack;
74+
QString m_sLoadedCoverLocation;
6475

6576
CSAMPLE m_bpmTapFilter[kFilterLength];
6677
QTime m_bpmTapTimer;
6778

6879
QMutex m_mutex;
6980
DlgTagFetcher& m_DlgTagFetcher;
7081

82+
enum reloadCoverCases {
83+
LOAD,
84+
CHANGE,
85+
UNSET
86+
};
7187
};
7288

7389
#endif /* DLGTRACKINFO_H */

0 commit comments

Comments
 (0)