Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrackDAO: Load a single track by URL #4475

Merged
merged 1 commit into from
Oct 23, 2021
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
9 changes: 9 additions & 0 deletions src/library/dao/trackdao.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ class TrackDAO : public QObject, public virtual DAO, public virtual GlobalTrackC
/// access as a friend.
static bool getTrackHeaderParsedInternal(const mixxx::TrackRecord& trackRecord);

/// Lookup and load a track by URL.
///
/// Only local file URLs are supported.
///
/// Returns `nullptr` if no track matches the given URL.
TrackPointer getTrackByUrl(const QUrl& url) const {
return getTrackByRef(TrackRef::fromUrl(url));
}

signals:
// Forwarded from Track object
void trackDirty(TrackId trackId);
Expand Down
8 changes: 8 additions & 0 deletions src/track/trackref.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class TrackRef final {
std::move(id));
}

/// Convert a local file URL into a TrackRef.
static TrackRef fromUrl(
const QUrl& url,
TrackId id = TrackId()) {
const auto fileInfo = mixxx::FileInfo::fromQUrl(url);
return TrackRef::fromFileInfo(fileInfo, id);
}

// Default constructor
TrackRef() {
DEBUG_ASSERT(verifyConsistency());
Expand Down