summaryrefslogtreecommitdiffstats
path: root/src/widget
diff options
context:
space:
mode:
authorRJ Ryan <rryan@mixxx.org>2014-10-27 22:05:51 -0400
committerRJ Ryan <rryan@mixxx.org>2014-10-27 22:05:51 -0400
commit9bbbea5160ae7690e2abed21fae48c1189cd0c82 (patch)
tree61571b5bbe3f27d731199e7a61c804cd6a4294c4 /src/widget
parente9aa413ed74a8551b150cd8f95bd27a387fb562a (diff)
Improve connection between WCoverArtMenu, WCoverArtLabel, WCoverArt, and DlgTrackInfo.
* Remove copying of changed cover art into the folder (temporarily?). * Mark all user-generated change events as USER_SELECTED. * Remove reliance on CoverInfo::trackId in a couple places.
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/wcoverart.cpp21
-rw-r--r--src/widget/wcoverart.h4
-rw-r--r--src/widget/wcoverartlabel.cpp25
-rw-r--r--src/widget/wcoverartlabel.h6
-rw-r--r--src/widget/wcoverartmenu.cpp104
-rw-r--r--src/widget/wcoverartmenu.h17
6 files changed, 72 insertions, 105 deletions
diff --git a/src/widget/wcoverart.cpp b/src/widget/wcoverart.cpp
index 7548ef9ea3..521f381b2c 100644
--- a/src/widget/wcoverart.cpp
+++ b/src/widget/wcoverart.cpp
@@ -31,10 +31,8 @@ WCoverArt::WCoverArt(QWidget* parent,
connect(pCache, SIGNAL(pixmapFound(int, QPixmap)),
this, SLOT(slotPixmapFound(int, QPixmap)));
}
- connect(m_pMenu,
- SIGNAL(coverLocationUpdated(const QString&, const QString&, QPixmap)),
- this,
- SLOT(slotCoverLocationUpdated(const QString&, const QString&, QPixmap)));
+ connect(m_pMenu, SIGNAL(coverArtSelected(const CoverArt&)),
+ this, SLOT(slotCoverArtSelected(const CoverArt&)));
}
WCoverArt::~WCoverArt() {
@@ -77,22 +75,13 @@ void WCoverArt::setup(QDomNode node, const SkinContext& context) {
m_defaultCoverScaled = scaledCoverArt(m_defaultCover);
}
-void WCoverArt::slotCoverLocationUpdated(const QString& newLoc,
- const QString& oldLoc,
- QPixmap newCover) {
- Q_UNUSED(oldLoc);
- Q_UNUSED(newCover);
-
+void WCoverArt::slotCoverArtSelected(const CoverArt& art) {
if (m_loadedTrack.isNull()) {
return;
}
-
- CoverArt art;
- art.info.coverLocation = newLoc;
- art.info.source = CoverInfo::USER_SELECTED;
- art.info.type = CoverInfo::FILE;
- // TODO(rryan): hash
m_loadedTrack->setCoverArt(art);
+ // TODO(rryan): listen to TIO signal instead
+ slotLoadTrack(m_loadedTrack);
}
void WCoverArt::slotEnable(bool enable) {
diff --git a/src/widget/wcoverart.h b/src/widget/wcoverart.h
index 1b1a9f4ee1..d071b3ee1b 100644
--- a/src/widget/wcoverart.h
+++ b/src/widget/wcoverart.h
@@ -33,9 +33,7 @@ class WCoverArt : public QWidget, public WBaseWidget {
private slots:
void slotPixmapFound(int trackId, QPixmap pixmap);
- void slotCoverLocationUpdated(const QString& newLoc,
- const QString& oldLoc,
- QPixmap px);
+ void slotCoverArtSelected(const CoverArt& art);
protected:
void paintEvent(QPaintEvent*);
diff --git a/src/widget/wcoverartlabel.cpp b/src/widget/wcoverartlabel.cpp
index b026ae09f7..e5bc937ad6 100644
--- a/src/widget/wcoverartlabel.cpp
+++ b/src/widget/wcoverartlabel.cpp
@@ -1,3 +1,5 @@
+#include <QtDebug>
+
#include "widget/wcoverartlabel.h"
#include "library/coverartutils.h"
@@ -6,8 +8,6 @@ static const QSize s_labelDisplaySize = QSize(100, 100);
WCoverArtLabel::WCoverArtLabel(QWidget* parent)
: QLabel(parent),
- m_pTrack(TrackPointer()),
- m_coverInfo(CoverInfo()),
m_pCoverMenu(new WCoverArtMenu(this)),
m_pDlgFullSize(new DlgCoverArtFullSize()),
m_defaultCover(CoverArtUtils::defaultCoverLocation()) {
@@ -17,10 +17,8 @@ WCoverArtLabel::WCoverArtLabel(QWidget* parent)
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(slotCoverMenu(QPoint)));
- connect(m_pCoverMenu,
- SIGNAL(coverLocationUpdated(const QString&, const QString&, QPixmap)),
- this,
- SIGNAL(coverLocationUpdated(const QString&, const QString&, QPixmap)));
+ connect(m_pCoverMenu, SIGNAL(coverArtSelected(const CoverArt&)),
+ this, SIGNAL(coverArtSelected(const CoverArt&)));
m_defaultCover = m_defaultCover.scaled(s_labelDisplaySize,
Qt::KeepAspectRatio,
@@ -33,9 +31,17 @@ WCoverArtLabel::~WCoverArtLabel() {
delete m_pDlgFullSize;
}
-void WCoverArtLabel::setCoverArt(TrackPointer track, CoverInfo info, QPixmap px) {
- m_pTrack = track;
+void WCoverArtLabel::setCoverArt(TrackPointer pTrack, const CoverInfo& info, QPixmap px) {
+ qDebug() << "WCoverArtLabel::setCoverArt" << info << px.size();
+
+ // Clear the WCoverArtMenu to release the TrackPointer it holds (we may as
+ // well have a WCoverArtMenu::setCoverArt method to match this one but the
+ // existing pattern is passing them in through show() so that's what we
+ // do)..
+ m_pCoverMenu->clear();
+
m_coverInfo = info;
+ m_pTrack = pTrack;
if (px.isNull()) {
setPixmap(m_defaultCover);
@@ -51,9 +57,6 @@ void WCoverArtLabel::setCoverArt(TrackPointer track, CoverInfo info, QPixmap px)
}
void WCoverArtLabel::slotCoverMenu(const QPoint& pos) {
- if (m_pTrack == NULL) {
- return;
- }
m_pCoverMenu->show(mapToGlobal(pos), m_coverInfo, m_pTrack);
}
diff --git a/src/widget/wcoverartlabel.h b/src/widget/wcoverartlabel.h
index 82e7f2e20a..ac1f062f2b 100644
--- a/src/widget/wcoverartlabel.h
+++ b/src/widget/wcoverartlabel.h
@@ -15,12 +15,10 @@ class WCoverArtLabel : public QLabel {
WCoverArtLabel(QWidget* parent = 0);
virtual ~WCoverArtLabel();
- void setCoverArt(TrackPointer track, CoverInfo info, QPixmap px);
+ void setCoverArt(TrackPointer pTrack, const CoverInfo& info, QPixmap px);
signals:
- void coverLocationUpdated(const QString& newLocation,
- const QString& oldLocation,
- QPixmap newCover);
+ void coverArtSelected(const CoverArt& art);
protected:
void leaveEvent(QEvent*);
diff --git a/src/widget/wcoverartmenu.cpp b/src/widget/wcoverartmenu.cpp
index 875abe8514..ab6643cb37 100644
--- a/src/widget/wcoverartmenu.cpp
+++ b/src/widget/wcoverartmenu.cpp
@@ -1,5 +1,5 @@
#include <QFileDialog>
-#include <QStringBuilder>
+#include <QFileInfo>
#include "widget/wcoverartmenu.h"
#include "library/coverartutils.h"
@@ -7,7 +7,6 @@
WCoverArtMenu::WCoverArtMenu(QWidget *parent)
: QMenu(parent) {
createActions();
- addActions();
}
WCoverArtMenu::~WCoverArtMenu() {
@@ -20,43 +19,48 @@ void WCoverArtMenu::createActions() {
m_pChange = new QAction(tr("Choose new cover",
"change cover art location"), this);
connect(m_pChange, SIGNAL(triggered()), this, SLOT(slotChange()));
+ addAction(m_pChange);
m_pUnset = new QAction(tr("Unset cover",
"unset cover art - load default"), this);
connect(m_pUnset, SIGNAL(triggered()), this, SLOT(slotUnset()));
+ addAction(m_pUnset);
m_pReload = new QAction(tr("Reload from track/folder",
"reload just cover art, using the search algorithm"), this);
connect(m_pReload, SIGNAL(triggered()), this, SLOT(slotReload()));
+ addAction(m_pReload);
}
-void WCoverArtMenu::addActions() {
- addAction(m_pChange);
- addAction(m_pUnset);
- addAction(m_pReload);
+void WCoverArtMenu::clear() {
+ m_coverInfo = CoverInfo();
+ m_pTrack.clear();
}
void WCoverArtMenu::show(QPoint pos, CoverInfo info, TrackPointer pTrack) {
- if (info.trackId < 1) {
- return;
- }
m_coverInfo = info;
m_pTrack = pTrack;
popup(pos);
}
void WCoverArtMenu::slotChange() {
- if (m_coverInfo.trackId < 1 || m_pTrack.isNull()) {
- return;
- }
-
// get initial directory (trackdir or coverdir)
QString initialDir;
- QString trackPath = m_pTrack->getDirectory();
- if (m_coverInfo.coverLocation.isEmpty()) {
- initialDir = trackPath;
- } else {
- initialDir = m_coverInfo.coverLocation;
+
+ QFileInfo track;
+ if (m_pTrack) {
+ track = m_pTrack->getFileInfo();
+ } else if (!m_coverInfo.trackLocation.isEmpty()) {
+ track = QFileInfo(m_coverInfo.trackLocation);
+ }
+
+ // If the cover is from file metadata then use the directory the track is
+ // in.
+ if (m_coverInfo.type == CoverInfo::METADATA) {
+ initialDir = track.absolutePath();
+ } else if (m_coverInfo.type == CoverInfo::FILE) {
+ QFileInfo file(track.dir(), m_coverInfo.coverLocation);
+ initialDir = file.absolutePath();
}
QStringList extensions = CoverArtUtils::supportedCoverArtExtensions();
@@ -69,58 +73,36 @@ void WCoverArtMenu::slotChange() {
// open file dialog
QString selectedCover = QFileDialog::getOpenFileName(
this, tr("Change Cover Art"), initialDir, supportedText);
-
if (selectedCover.isEmpty()) {
return;
}
- // if the cover comes from an external dir,
- // we copy it to the track directory.
- QString newCover;
- QFileInfo fileInfo(selectedCover);
- QString coverPath = fileInfo.absolutePath();
- if (trackPath == coverPath) {
- newCover = selectedCover;
- } else {
- QDir trackDir(trackPath);
- QString ext = fileInfo.suffix();
- QString mixxxCoverFile = trackDir.filePath("mixxx-cover." % ext);
- QStringList filepaths;
- filepaths << trackDir.filePath("cover." % ext)
- << trackDir.filePath("album." % ext)
- << mixxxCoverFile;
-
- foreach (QString filepath, filepaths) {
- if (QFile::copy(selectedCover, filepath)) {
- newCover = filepath;
- break;
- }
- }
-
- if (newCover.isEmpty()) {
- // overwrites "mixxx-cover"
- QFile::remove(mixxxCoverFile);
- if (QFile::copy(selectedCover, mixxxCoverFile)) {
- newCover = mixxxCoverFile;
- }
- }
- }
+ // TODO(rryan): Ask if user wants to copy the file.
- QPixmap px(newCover);
- emit(coverLocationUpdated(newCover, m_coverInfo.coverLocation, px));
+ CoverArt art;
+ art.image = QImage(selectedCover);
+ if (art.image.isNull()) {
+ // TODO(rryan): feedback
+ return;
+ }
+ art.info.type = CoverInfo::FILE;
+ art.info.source = CoverInfo::USER_SELECTED;
+ art.info.coverLocation = selectedCover;
+ art.info.hash = CoverArtUtils::calculateHash(art.image);
+ qDebug() << "WCoverArtMenu::slotChange emit" << art;
+ emit(coverArtSelected(art));
}
void WCoverArtMenu::slotReload() {
- if (m_coverInfo.trackId < 1 || m_pTrack.isNull()) {
- return;
- }
- // TODO(rryan): implement, need to signal to parent
+ CoverArt art = CoverArtUtils::guessCoverArt(m_pTrack);
+ qDebug() << "WCoverArtMenu::slotReload emit" << art;
+ emit(coverArtSelected(art));
}
void WCoverArtMenu::slotUnset() {
- if (m_coverInfo.trackId < 1) {
- return;
- }
- QPixmap px;
- emit(coverLocationUpdated(QString(), m_coverInfo.coverLocation, QPixmap()));
+ CoverArt art;
+ art.info.type = CoverInfo::NONE;
+ art.info.source = CoverInfo::USER_SELECTED;
+ qDebug() << "WCoverArtMenu::slotUnset emit" << art;
+ emit(coverArtSelected(art));
}
diff --git a/src/widget/wcoverartmenu.h b/src/widget/wcoverartmenu.h
index c882551f5e..d9356d1c1f 100644
--- a/src/widget/wcoverartmenu.h
+++ b/src/widget/wcoverartmenu.h
@@ -9,24 +9,22 @@
#include "trackinfoobject.h"
#include "library/coverart.h"
+// This class implements a context-menu with all CoverArt user actions. Callers
+// MUST use the method show(...) to open the menu. do NOT use exec() or
+// popup(). This class does not change the database -- it emits a
+// coverArtSelected signal when the user performs an action. It is up to the
+// parent to decide how to handle the action.
class WCoverArtMenu : public QMenu {
Q_OBJECT
public:
- // This class implements a context-menu with all CoverArt actions. Callers
- // MUST use the method show(...) to open the menu. do NOT use exec() or
- // popup(). This class does NOT CHANGE the database. When the cover is
- // changed through any of the offered options the 'coverLocationUpdated'
- // signal will be emitted and the widget using this menu can decide when and
- // if the new cover should be saved.
WCoverArtMenu(QWidget *parent = 0);
virtual ~WCoverArtMenu();
void show(QPoint pos, CoverInfo info, TrackPointer pTrack);
+ void clear();
signals:
- void coverLocationUpdated(const QString& newLocation,
- const QString& oldLocation,
- QPixmap newCover);
+ void coverArtSelected(const CoverArt& art);
private slots:
void slotChange();
@@ -35,7 +33,6 @@ class WCoverArtMenu : public QMenu {
private:
void createActions();
- void addActions();
QAction* m_pChange;
QAction* m_pReload;