summaryrefslogtreecommitdiffstats
path: root/src/widget
diff options
context:
space:
mode:
authorMax Linke <kain88@mixxx.org>2014-09-08 18:13:39 +0200
committerMax Linke <kain88@mixxx.org>2014-09-11 11:57:51 +0200
commit7a95dffc427f6d3559d3ff6cb54981e3a9f7d9f3 (patch)
treeb52ad5d936fddb8de5face3fcc1c8f2782e943ce /src/widget
parent25bd8f77c214f9b5abc5be68119449ccfe79688a (diff)
Make cover in dlgtrackinfo work with cancel
We want that changes to the cover in dlgtrackinfo behave similar to changing other values of the track. This required me to rework how WCoverArtMenu works. WCoverArtMenu is now only a common menu that DOES NOT CHANGE the database instead the widget implementing the menu does this now when it sees fit. Another important change to make this work is that 'CoverArtCache::searchImage' can now be called from any class without the need use 'requestCover'. This is necessary to reload the cover from the ID3tags/folder without updating the DB. This is ok in this case because we only search for 1 cover and we will only block the UI thread for a fraction of a second. I also think this is ok in this special case because changing covers won't happen very often and a user will to this one track at a time anyway, while the normal cover display requires us to provides covers for several tracks simultaneously.
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/wcoverart.cpp27
-rw-r--r--src/widget/wcoverart.h8
-rw-r--r--src/widget/wcoverartmenu.cpp35
-rw-r--r--src/widget/wcoverartmenu.h12
4 files changed, 55 insertions, 27 deletions
diff --git a/src/widget/wcoverart.cpp b/src/widget/wcoverart.cpp
index b0297d82e9..37313d08c6 100644
--- a/src/widget/wcoverart.cpp
+++ b/src/widget/wcoverart.cpp
@@ -11,7 +11,8 @@
#include "library/coverartcache.h"
WCoverArt::WCoverArt(QWidget* parent,
- ConfigObject<ConfigValue>* pConfig)
+ ConfigObject<ConfigValue>* pConfig,
+ TrackCollection* pTrackCollection)
: QWidget(parent),
WBaseWidget(this),
m_pConfig(pConfig),
@@ -20,7 +21,8 @@ WCoverArt::WCoverArt(QWidget* parent,
m_bCoverIsVisible(false),
m_pMenu(new WCoverArtMenu(this)),
m_loadedCover(CoverArtCache::instance()->getDefaultCoverArt()),
- m_lastRequestedTrackId(-1) {
+ m_lastRequestedTrackId(-1),
+ m_trackDAO(pTrackCollection->getTrackDAO()) {
// load icon to hide cover
m_iconHide = QPixmap(":/images/library/ic_library_cover_hide.png");
m_iconHide = m_iconHide.scaled(20,
@@ -37,12 +39,29 @@ WCoverArt::WCoverArt(QWidget* parent,
connect(CoverArtCache::instance(), SIGNAL(pixmapFound(int, QPixmap)),
this, SLOT(slotPixmapFound(int, QPixmap)), Qt::DirectConnection);
+ connect(m_pMenu,
+ SIGNAL(coverLocationUpdated(const QString&, const QString&, QPixmap)),
+ this,
+ SLOT(slotCoverLocationUpdated(const QString&, const QString&, QPixmap)));
}
WCoverArt::~WCoverArt() {
delete m_pMenu;
}
+void WCoverArt::slotCoverLocationUpdated(const QString& newLoc,
+ const QString& oldLoc,
+ QPixmap px) {
+ Q_UNUSED(oldLoc);
+ Q_UNUSED(px);
+ bool res = CoverArtCache::instance()->changeCoverArt(m_lastRequestedTrackId,
+ newLoc);
+ if (!res) {
+ QMessageBox::warning(this, tr("Change Cover Art"),
+ tr("Could not change the cover art."));
+ }
+}
+
void WCoverArt::setup(QDomNode node, const SkinContext& context) {
Q_UNUSED(node);
setMouseTracking(TRUE);
@@ -175,9 +194,11 @@ void WCoverArt::mousePressEvent(QMouseEvent* event) {
m_bCoverIsVisible = false;
resize(sizeHint());
} else if (event->button() == Qt::RightButton) { // show context-menu
+ TrackPointer pTrack = m_trackDAO.getTrack(m_lastRequestedTrackId);
m_pMenu->show(event->globalPos(),
m_lastRequestedCover,
- m_lastRequestedTrackId);
+ m_lastRequestedTrackId,
+ pTrack);
}
}
diff --git a/src/widget/wcoverart.h b/src/widget/wcoverart.h
index f3c6b407a1..d4d51a3d7e 100644
--- a/src/widget/wcoverart.h
+++ b/src/widget/wcoverart.h
@@ -9,13 +9,15 @@
#include "configobject.h"
#include "skin/skincontext.h"
#include "trackinfoobject.h"
+#include "library/trackcollection.h"
#include "widget/wbasewidget.h"
#include "widget/wcoverartmenu.h"
class WCoverArt : public QWidget, public WBaseWidget {
Q_OBJECT
public:
- WCoverArt(QWidget* parent, ConfigObject<ConfigValue>* pConfig);
+ WCoverArt(QWidget* parent, ConfigObject<ConfigValue>* pConfig,
+ TrackCollection* pTrackCollection);
virtual ~WCoverArt();
void setup(QDomNode node, const SkinContext& context);
@@ -29,6 +31,9 @@ class WCoverArt : public QWidget, public WBaseWidget {
private slots:
void slotPixmapFound(int trackId, QPixmap pixmap);
+ void slotCoverLocationUpdated(const QString& newLoc,
+ const QString& oldLoc,
+ QPixmap px);
protected:
void paintEvent(QPaintEvent*);
@@ -54,6 +59,7 @@ class WCoverArt : public QWidget, public WBaseWidget {
QPixmap m_iconShow;
int m_lastRequestedTrackId;
+ TrackDAO& m_trackDAO;
QPair<QString, QString> m_lastRequestedCover;
};
diff --git a/src/widget/wcoverartmenu.cpp b/src/widget/wcoverartmenu.cpp
index 9959dea2a9..2464bb968b 100644
--- a/src/widget/wcoverartmenu.cpp
+++ b/src/widget/wcoverartmenu.cpp
@@ -5,6 +5,7 @@
#include "dlgcoverartfullsize.h"
#include "wcoverartmenu.h"
#include "library/coverartcache.h"
+#include "library/dao/coverartdao.h"
WCoverArtMenu::WCoverArtMenu(QWidget *parent)
: QMenu(parent),
@@ -114,24 +115,25 @@ void WCoverArtMenu::slotChange() {
newCover = selectedCover;
}
- bool res = CoverArtCache::instance()->changeCoverArt(m_pTrack->getId(),
- newCover);
- if (!res) {
- QMessageBox::warning(this, tr("Change Cover Art"),
- tr("Could not change the cover art!"));
- return;
- }
-
- emit(coverLocationUpdated(newCover, m_sCoverLocation));
- m_sCoverLocation = newCover;
+ QPixmap px(newCover);
+ emit(coverLocationUpdated(newCover, m_sCoverLocation, px));
}
void WCoverArtMenu::slotReload() {
if (m_iTrackId < 1) {
return;
}
- CoverArtCache::instance()->changeCoverArt(m_iTrackId);
- CoverArtCache::instance()->requestPixmap(m_iTrackId);
+ CoverArtDAO::CoverArtInfo info;
+ info.trackId = m_iTrackId;
+ info.album = m_pTrack->getAlbum();
+ info.trackDirectory = m_pTrack->getDirectory();
+ info.trackLocation = m_pTrack->getLocation();
+ info.trackBaseName = QFileInfo(m_pTrack->getFilename()).baseName();
+ CoverArtCache::FutureResult res =
+ CoverArtCache::instance()->searchImage(info, QSize(0,0), false);
+ QPixmap px;
+ px.convertFromImage(res.img);
+ emit(coverLocationUpdated(res.coverLocation, m_sCoverLocation, px));
}
void WCoverArtMenu::slotUnset() {
@@ -139,11 +141,6 @@ void WCoverArtMenu::slotUnset() {
return;
}
QString newLoc = CoverArtCache::instance()->getDefaultCoverLocation();
- if (!CoverArtCache::instance()->changeCoverArt(m_iTrackId, newLoc)) {
- QMessageBox::warning(this, tr("Unset Cover Art"),
- tr("Could not unset the cover art!"));
- return;
- }
- emit(coverLocationUpdated(newLoc, m_sCoverLocation));
- m_sCoverLocation = newLoc;
+ QPixmap px = CoverArtCache::instance()->getDefaultCoverArt();
+ emit(coverLocationUpdated(newLoc, m_sCoverLocation, px));
}
diff --git a/src/widget/wcoverartmenu.h b/src/widget/wcoverartmenu.h
index 67d6739f4b..040688248d 100644
--- a/src/widget/wcoverartmenu.h
+++ b/src/widget/wcoverartmenu.h
@@ -10,9 +10,12 @@
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 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();
@@ -21,7 +24,8 @@ class WCoverArtMenu : public QMenu {
signals:
void coverLocationUpdated(const QString& newLocation,
- const QString& oldLocation);
+ const QString& oldLocation,
+ QPixmap px);
private slots:
void slotChange();