Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/library/crate/cratestorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ class CrateQueryBinder {
FwdSqlQuery& m_query;
};

const QChar kSqlListSeparator(',');

// It is not possible to bind multiple values as a list to a query.
// The list of track ids has to be transformed into a single list
// string before it can be used in an SQL query.
QString joinSqlStringList(const QList<TrackId>& trackIds) {
QString joinedTrackIds;
// Reserve memory up front to prevent reallocation. Here we
// assume that all track ids fit into 6 decimal digits and
// add 1 character for the list separator.
joinedTrackIds.reserve((6 + 1) * trackIds.size());
for (const auto& trackId: trackIds) {
if (!joinedTrackIds.isEmpty()) {
joinedTrackIds += kSqlListSeparator;
}
joinedTrackIds += trackId.toString();
}
return joinedTrackIds;
}

} // anonymous namespace


Expand Down Expand Up @@ -468,6 +488,29 @@ CrateTrackSelectResult CrateStorage::selectTrackCratesSorted(TrackId trackId) co
}
}

CrateSummarySelectResult CrateStorage::selectCratesWithTrackCount(const QList<TrackId>& trackIds) const {
FwdSqlQuery query(m_database, QString(
"SELECT *, ("
" SELECT COUNT(*) FROM %1 WHERE %2.%3 = %1.%4 and %1.%5 in (%9)"
" ) AS %6, 0 as %7 FROM %2 ORDER BY %8").arg(
CRATE_TRACKS_TABLE,
CRATE_TABLE,
CRATETABLE_ID,
CRATETRACKSTABLE_CRATEID,
CRATETRACKSTABLE_TRACKID,
CRATESUMMARY_TRACK_COUNT,
CRATESUMMARY_TRACK_DURATION,
CRATETABLE_NAME,
joinSqlStringList(trackIds)));

if (query.execPrepared()) {
return CrateSummarySelectResult(std::move(query));
} else {
return CrateSummarySelectResult();
}
}



CrateTrackSelectResult CrateStorage::selectTracksSortedByCrateNameLike(const QString& crateNameLike) const {
FwdSqlQuery query(m_database, QString(
Expand Down
3 changes: 2 additions & 1 deletion src/library/crate/cratestorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ class CrateStorage: public virtual /*implements*/ SqlStorage {
CrateId crateId) const;
CrateTrackSelectResult selectTrackCratesSorted(
TrackId trackId) const;
CrateSummarySelectResult selectCratesWithTrackCount(
const QList<TrackId>& trackIds) const;
CrateTrackSelectResult selectTracksSortedByCrateNameLike(
const QString& crateNameLike) const;

Expand All @@ -284,7 +286,6 @@ class CrateStorage: public virtual /*implements*/ SqlStorage {
QSet<CrateId> collectCrateIdsOfTracks(
const QList<TrackId>& trackIds) const;


/////////////////////////////////////////////////////////////////////////
// CrateSummary view operations (read-only, const)
/////////////////////////////////////////////////////////////////////////
Expand Down
21 changes: 19 additions & 2 deletions src/library/setlogfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
#include "library/treeitem.h"
#include "mixer/playerinfo.h"
#include "mixer/playermanager.h"
#include "widget/wtracktableview.h"
#include "widget/wlibrary.h"

SetlogFeature::SetlogFeature(QObject* parent,
UserSettingsPointer pConfig,
TrackCollection* pTrackCollection)
: BasePlaylistFeature(parent, pConfig, pTrackCollection, "SETLOGHOME"),
m_playlistId(-1) {
m_playlistId(-1),
m_libraryWidget(nullptr) {
m_pPlaylistTableModel = new PlaylistTableModel(this, pTrackCollection,
"mixxx.db.model.setlog",
true); //show all tracks
Expand Down Expand Up @@ -60,6 +63,8 @@ void SetlogFeature::bindWidget(WLibrary* libraryWidget,
keyboard);
connect(&PlayerInfo::instance(), SIGNAL(currentPlayingTrackChanged(TrackPointer)),
this, SLOT(slotPlayingTrackChanged(TrackPointer)));
m_libraryWidget = libraryWidget;

}

void SetlogFeature::onRightClick(const QPoint& globalPos) {
Expand Down Expand Up @@ -268,7 +273,19 @@ void SetlogFeature::slotPlayingTrackChanged(TrackPointer currentPlayingTrack) {

if (m_pPlaylistTableModel->getPlaylist() == m_playlistId) {
// View needs a refresh
m_pPlaylistTableModel->appendTrack(currentPlayingTrackId);

WTrackTableView* view = dynamic_cast<WTrackTableView*>(m_libraryWidget->getActiveView());
if (view != nullptr) {
// We have a active view on the history. The user may have some
// important active selection. For example putting track into crates
// while the song changes trough autodj. The selection is then lost
// and dataloss occures
const QList<TrackId> trackIds = view->getSelectedTrackIds();
m_pPlaylistTableModel->appendTrack(currentPlayingTrackId);
view->setSelectedTracks(trackIds);
} else {
m_pPlaylistTableModel->appendTrack(currentPlayingTrackId);
}
} else {
// TODO(XXX): Care whether the append succeeded.
m_playlistDao.appendTrackToPlaylist(currentPlayingTrackId,
Expand Down
1 change: 1 addition & 0 deletions src/library/setlogfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class SetlogFeature : public BasePlaylistFeature {
QAction* m_pJoinWithPreviousAction;
QAction* m_pGetNewPlaylist;
int m_playlistId;
WLibrary* m_libraryWidget;
};

#endif // SETLOGFEATURE_H
19 changes: 19 additions & 0 deletions src/track/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,25 @@ void Track::removeCue(const CuePointer& pCue) {
emit(cuesUpdated());
}

void Track::removeCuesOfType(Cue::CueType type) {
QMutexLocker lock(&m_qMutex);
bool dirty = false;
QMutableListIterator<CuePointer> it(m_cuePoints);
while (it.hasNext()) {
CuePointer pCue = it.next();
// FIXME: Why does this only work for the CUE CueType?
if (pCue->getType() == type) {
disconnect(pCue.get(), 0, this, 0);
it.remove();
dirty = true;
}
}
if (dirty) {
markDirtyAndUnlock(&lock);
emit(cuesUpdated());
}
}

QList<CuePointer> Track::getCuePoints() const {
QMutexLocker lock(&m_qMutex);
return m_cuePoints;
Expand Down
1 change: 1 addition & 0 deletions src/track/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class Track : public QObject {
// Calls for managing the track's cue points
CuePointer createAndAddCue();
void removeCue(const CuePointer& pCue);
void removeCuesOfType(Cue::CueType);
QList<CuePointer> getCuePoints() const;
void setCuePoints(const QList<CuePointer>& cuePoints);

Expand Down
4 changes: 2 additions & 2 deletions src/util/parented_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ inline bool operator== (const parented_ptr<T>& lhs, const U* rhs) {
}

template<typename T, typename U>
inline bool operator== (const parented_ptr<T>& lhs, const parented_ptr<U>& rhs) const {
inline bool operator== (const parented_ptr<T>& lhs, const parented_ptr<U>& rhs) {
return lhs.get() == rhs.get();
}

Expand All @@ -115,7 +115,7 @@ inline bool operator!= (const parented_ptr<T>& lhs, const U* rhs) {
}

template<typename T, typename U>
inline bool operator!= (const parented_ptr<T>& lhs, const parented_ptr<U>& rhs) const {
inline bool operator!= (const parented_ptr<T>& lhs, const parented_ptr<U>& rhs) {
return !(lhs.get() == rhs.get());
}

Expand Down
2 changes: 1 addition & 1 deletion src/widget/wcoverartmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void WCoverArtMenu::createActions() {
connect(m_pChange, SIGNAL(triggered()), this, SLOT(slotChange()));
addAction(m_pChange);

m_pUnset = new QAction(tr("Unset cover",
m_pUnset = new QAction(tr("Clear cover",
"clears the set cover art -- does not touch files on disk"), this);
connect(m_pUnset, SIGNAL(triggered()), this, SLOT(slotUnset()));
addAction(m_pUnset);
Expand Down
Loading