Skip to content

Commit

Permalink
New logic to load covers - check if user is stoped in the row for mor…
Browse files Browse the repository at this point in the history
…e than 0.1s

It's more efficient because it ensures that we'll only call loadCoverArt after finish quick selections.
  • Loading branch information
cardinot committed Jul 5, 2014
1 parent 02d190f commit ab39f64
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
31 changes: 21 additions & 10 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ WTrackTableView::WTrackTableView(QWidget * parent,
this, SLOT(addSelectionToCrate(int)));

// control the delay to load the next cover art
m_lastCoverLoaded = -1.0;
m_lastSelection = 0.0;
m_bLastCoverLoaded = true;
m_pCOTGuiTickTime = new ControlObjectThread("[Master]", "guiTickTime");
connect(m_pCOTGuiTickTime, SIGNAL(valueChanged(double)),
this, SLOT(slotGuiTickTime(double)));
}

WTrackTableView::~WTrackTableView() {
Expand Down Expand Up @@ -134,20 +137,29 @@ void WTrackTableView::selectionChanged(const QItemSelection &selected,
const QItemSelection &deselected) {
Q_UNUSED(selected);
Q_UNUSED(deselected);
slotLoadCoverArt();

if (m_bLastCoverLoaded) {
// load default cover art
emit(loadCoverArt("", "", 0));
}
m_bLastCoverLoaded = false;
m_lastSelection = m_pCOTGuiTickTime->get();
update();
}

void WTrackTableView::slotGuiTickTime(double cpuTime) {
// if the user is stoped in the same row for more than 0.1s,
// we load the cover art once.
if (cpuTime >= m_lastSelection + 0.1 && !m_bLastCoverLoaded) {
slotLoadCoverArt();
m_bLastCoverLoaded = true;
}
}

void WTrackTableView::slotLoadCoverArt() {
QString coverLocation;
QString md5Hash;
int trackId = 0;

if (m_pCOTGuiTickTime->get() <= m_lastCoverLoaded + 0.5) {
emit(loadCoverArt(coverLocation, md5Hash, trackId)); // default cover art
update();
return;
}

const QModelIndexList indices = selectionModel()->selectedRows();
if ((indices.size() == 1) && (indices[0].isValid())) {
QModelIndex idx = indices[0];
Expand All @@ -162,7 +174,6 @@ void WTrackTableView::slotLoadCoverArt() {
trackId = trackModel->getTrackId(idx);
}
}
m_lastCoverLoaded = m_pCOTGuiTickTime->get();
emit(loadCoverArt(coverLocation, md5Hash, trackId));
update();
}
Expand Down
4 changes: 3 additions & 1 deletion src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class WTrackTableView : public WLibraryTableView {
void slotUnlockBpm();
void slotScaleBpm(int);
void slotClearBeats();
void slotGuiTickTime(double);

private:
void sendToAutoDJ(bool bTop);
Expand Down Expand Up @@ -149,7 +150,8 @@ class WTrackTableView : public WLibraryTableView {
bool m_sorting;

// Control the delay to load a cover art.
double m_lastCoverLoaded;
double m_lastSelection;
bool m_bLastCoverLoaded;
ControlObjectThread* m_pCOTGuiTickTime;
};

Expand Down

0 comments on commit ab39f64

Please sign in to comment.