diff options
author | RJ Ryan <rryan@mixxx.org> | 2014-10-21 15:58:06 -0400 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2014-10-21 15:58:06 -0400 |
commit | eb265df04e7bd0bdefbce8354326c552eb6ffb10 (patch) | |
tree | ba78f36e8e1a8686a48ef166e64415aabf0e0e7c /src/widget | |
parent | 5d2fa92af0f2fc0923546dfa2cdfa0e4991b1395 (diff) |
Some NULL-safety changes.
Diffstat (limited to 'src/widget')
-rw-r--r-- | src/widget/wcoverart.cpp | 33 | ||||
-rw-r--r-- | src/widget/wcoverart.h | 1 | ||||
-rw-r--r-- | src/widget/wcoverartmenu.cpp | 25 | ||||
-rw-r--r-- | src/widget/wtracktableview.cpp | 7 |
4 files changed, 47 insertions, 19 deletions
diff --git a/src/widget/wcoverart.cpp b/src/widget/wcoverart.cpp index 082746b258..599f888501 100644 --- a/src/widget/wcoverart.cpp +++ b/src/widget/wcoverart.cpp @@ -13,17 +13,19 @@ WCoverArt::WCoverArt(QWidget* parent, TrackCollection* pTrackCollection) : QWidget(parent), WBaseWidget(this), - m_pCoverCache(CoverArtCache::instance()), m_bEnableWidget(true), m_pMenu(new WCoverArtMenu(this)), - m_loadedCover(m_pCoverCache->getDefaultCoverArt()), - m_loadedCoverScaled(scaledCoverArt(m_loadedCover)), m_trackDAO(pTrackCollection->getTrackDAO()), m_pDlgFullSize(new DlgCoverArtFullSize()) { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - connect(m_pCoverCache, SIGNAL(pixmapFound(int, QPixmap)), - this, SLOT(slotPixmapFound(int, QPixmap)), Qt::DirectConnection); + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache != NULL) { + connect(pCache, SIGNAL(pixmapFound(int, QPixmap)), + this, SLOT(slotPixmapFound(int, QPixmap)), Qt::DirectConnection); + m_loadedCover = pCache->getDefaultCoverArt(); + m_loadedCoverScaled = scaledCoverArt(m_loadedCover); + } connect(m_pMenu, SIGNAL(coverLocationUpdated(const QString&, const QString&, QPixmap)), this, @@ -64,7 +66,9 @@ void WCoverArt::slotCoverLocationUpdated(const QString& newLoc, QPixmap px) { Q_UNUSED(oldLoc); Q_UNUSED(px); - if (!m_pCoverCache->changeCoverArt(m_lastRequestedCover.trackId, newLoc)) { + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache != NULL && !pCache->changeCoverArt( + m_lastRequestedCover.trackId, newLoc)) { // parent must be NULL - it ensures the use of the default style. QMessageBox::warning(NULL, tr("Change Cover Art"), tr("Could not change the cover art.")); @@ -82,8 +86,11 @@ void WCoverArt::slotEnableWidget(bool enable) { void WCoverArt::slotResetWidget() { m_lastRequestedCover = CoverInfo(); - m_loadedCover = m_pCoverCache->getDefaultCoverArt(); - m_loadedCoverScaled = scaledCoverArt(m_loadedCover); + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache != NULL) { + m_loadedCover = pCache->getDefaultCoverArt(); + m_loadedCoverScaled = scaledCoverArt(m_loadedCover); + } update(); } @@ -103,7 +110,10 @@ void WCoverArt::slotLoadCoverArt(CoverInfo info, bool cachedOnly) { return; } m_lastRequestedCover = info; - m_pCoverCache->requestPixmap(info, QSize(0,0), cachedOnly); + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache != NULL) { + pCache->requestPixmap(info, QSize(0,0), cachedOnly); + } } QPixmap WCoverArt::scaledCoverArt(QPixmap normal) { @@ -135,7 +145,10 @@ void WCoverArt::resizeEvent(QResizeEvent*) { setMaximumHeight(h); } if (m_lastRequestedCover.trackId < 1) { - m_loadedCover = m_pCoverCache->getDefaultCoverArt(); + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache != NULL) { + m_loadedCover = pCache->getDefaultCoverArt(); + } } m_loadedCoverScaled = scaledCoverArt(m_loadedCover); } diff --git a/src/widget/wcoverart.h b/src/widget/wcoverart.h index 6e0fa12f42..98ef4b3f7b 100644 --- a/src/widget/wcoverart.h +++ b/src/widget/wcoverart.h @@ -42,7 +42,6 @@ class WCoverArt : public QWidget, public WBaseWidget { private: QPixmap scaledCoverArt(QPixmap normal); - CoverArtCache* m_pCoverCache; bool m_bEnableWidget; WCoverArtMenu* m_pMenu; QPixmap m_loadedCover; diff --git a/src/widget/wcoverartmenu.cpp b/src/widget/wcoverartmenu.cpp index 6cab7e5acd..dc8be5eb94 100644 --- a/src/widget/wcoverartmenu.cpp +++ b/src/widget/wcoverartmenu.cpp @@ -51,12 +51,16 @@ void WCoverArtMenu::slotChange() { return; } + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache == NULL) { + return; + } + // get initial directory (trackdir or coverdir) QString initialDir; QString trackPath = m_pTrack->getDirectory(); if (m_coverInfo.coverLocation.isEmpty() || - m_coverInfo.coverLocation == CoverArtCache::instance() - ->getDefaultCoverLocation()) { + m_coverInfo.coverLocation == pCache->getDefaultCoverLocation()) { initialDir = trackPath; } else { initialDir = m_coverInfo.coverLocation; @@ -111,14 +115,19 @@ void WCoverArtMenu::slotReload() { if (m_coverInfo.trackId < 1) { return; } + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache == NULL) { + return; + } + CoverArtDAO::CoverArtInfo info; info.trackId = m_pTrack->getId(); 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); + CoverArtCache::FutureResult res = pCache->searchImage( + info, QSize(0,0), false); QPixmap px; px.convertFromImage(res.img); emit(coverLocationUpdated(res.coverLocation, m_coverInfo.coverLocation, px)); @@ -128,7 +137,11 @@ void WCoverArtMenu::slotUnset() { if (m_coverInfo.trackId < 1) { return; } - QString newLoc = CoverArtCache::instance()->getDefaultCoverLocation(); - QPixmap px = CoverArtCache::instance()->getDefaultCoverArt(); + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache == NULL) { + return; + } + QString newLoc = pCache->getDefaultCoverLocation(); + QPixmap px = pCache->getDefaultCoverArt(); emit(coverLocationUpdated(newLoc, m_coverInfo.coverLocation, px)); } diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index 100c5518f2..d3a759db18 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -96,8 +96,11 @@ WTrackTableView::WTrackTableView(QWidget * parent, connect(this, SIGNAL(scrollValueChanged(int)), this, SLOT(slotScrollValueChanged(int))); - connect(CoverArtCache::instance(), SIGNAL(requestRepaint()), - this, SLOT(update())); + CoverArtCache* pCache = CoverArtCache::instance(); + if (pCache != NULL) { + connect(pCache, SIGNAL(requestRepaint()), + this, SLOT(update())); + } } WTrackTableView::~WTrackTableView() { |