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

Remove TrackFile class #3761

Merged
merged 9 commits into from
Apr 27, 2021
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,6 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/track/serato/markers2.cpp
src/track/serato/tags.cpp
src/track/track.cpp
src/track/trackfile.cpp
src/track/trackinfo.cpp
src/track/trackmetadata.cpp
src/track/tracknumbers.cpp
Expand Down
15 changes: 7 additions & 8 deletions src/engine/cachingreader/cachingreaderworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,16 @@ void CachingReaderWorker::loadTrack(const TrackPointer& pTrack) {
// Emit that a new track is loading, stops the current track
emit trackLoading();

const QString trackLocation = pTrack->getLocation();
if (trackLocation.isEmpty() || !pTrack->checkFileExists()) {
if (!pTrack->getFileInfo().checkFileExists()) {
kLogger.warning()
<< m_group
<< "File not found"
<< trackLocation;
<< pTrack->getFileInfo();
const auto update = ReaderStatusUpdate::trackUnloaded();
m_pReaderStatusFIFO->writeBlocking(&update, 1);
emit trackLoadFailed(pTrack,
tr("The file '%1' could not be found.")
.arg(QDir::toNativeSeparators(trackLocation)));
.arg(QDir::toNativeSeparators(pTrack->getLocation())));
return;
}

Expand All @@ -156,12 +155,12 @@ void CachingReaderWorker::loadTrack(const TrackPointer& pTrack) {
kLogger.warning()
<< m_group
<< "Failed to open file"
<< trackLocation;
<< pTrack->getFileInfo();
const auto update = ReaderStatusUpdate::trackUnloaded();
m_pReaderStatusFIFO->writeBlocking(&update, 1);
emit trackLoadFailed(pTrack,
tr("The file '%1' could not be loaded.")
.arg(QDir::toNativeSeparators(trackLocation)));
.arg(QDir::toNativeSeparators(pTrack->getLocation())));
return;
}

Expand All @@ -173,12 +172,12 @@ void CachingReaderWorker::loadTrack(const TrackPointer& pTrack) {
kLogger.warning()
<< m_group
<< "Failed to open empty file"
<< trackLocation;
<< pTrack->getFileInfo();
const auto update = ReaderStatusUpdate::trackUnloaded();
m_pReaderStatusFIFO->writeBlocking(&update, 1);
emit trackLoadFailed(pTrack,
tr("The file '%1' is empty and could not be loaded.")
.arg(QDir::toNativeSeparators(trackLocation)));
.arg(QDir::toNativeSeparators(pTrack->getLocation())));
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void AutoDJFeature::slotAddRandomTrack() {
<< randomTrackId;
continue;
}
if (!pRandomTrack->checkFileExists()) {
if (!pRandomTrack->getFileInfo().checkFileExists()) {
qWarning() << "Track does not exist:"
<< pRandomTrack->getInfo()
<< pRandomTrack->getFileInfo();
Expand Down
2 changes: 1 addition & 1 deletion src/library/autodj/autodjprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ TrackPointer AutoDJProcessor::getNextTrackFromQueue() {
m_pAutoDJTableModel->index(0, 0));

if (nextTrack) {
if (nextTrack->checkFileExists()) {
if (nextTrack->getFileInfo().checkFileExists()) {
return nextTrack;
} else {
// Remove missing song from auto DJ playlist.
Expand Down
4 changes: 3 additions & 1 deletion src/library/banshee/bansheefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ void BansheeFeature::activate() {
qDebug() << m_databaseFile << "does not exist";
}

if (!Sandbox::askForAccess(m_databaseFile) || !m_connection.open(m_databaseFile)) {
mixxx::FileInfo fileInfo(m_databaseFile);
if (!Sandbox::askForAccess(&fileInfo) ||
!m_connection.open(m_databaseFile)) {
QMessageBox::warning(
nullptr,
tr("Error loading Banshee database"),
Expand Down
6 changes: 3 additions & 3 deletions src/library/banshee/bansheeplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ TrackId BansheePlaylistModel::doGetTrackId(const TrackPointer& pTrack) const {
if (pTrack) {
for (int row = 0; row < rowCount(); ++row) {
const QUrl rowUrl(getFieldString(index(row, 0), CLM_URI));
if (TrackFile::fromUrl(rowUrl) == pTrack->getFileInfo()) {
if (mixxx::FileInfo::fromQUrl(rowUrl) == pTrack->getFileInfo()) {
return TrackId(getFieldVariant(index(row, 0), CLM_VIEW_ORDER));
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ TrackPointer BansheePlaylistModel::getTrack(const QModelIndex& index) const {

bool track_already_in_library = false;
TrackPointer pTrack = m_pTrackCollectionManager->getOrAddTrack(
TrackRef::fromFileInfo(location),
TrackRef::fromFilePath(location),
&track_already_in_library);

// If this track was not in the Mixxx library it is now added and will be
Expand Down Expand Up @@ -295,7 +295,7 @@ QString BansheePlaylistModel::getTrackLocation(const QModelIndex& index) const {
}
QUrl url(getFieldString(index, CLM_URI));

QString location = TrackFile::fromUrl(url).location();
QString location = mixxx::FileInfo::fromQUrl(url).location();
qDebug() << location << " = " << url;
if (!location.isEmpty()) {
return location;
Expand Down
2 changes: 1 addition & 1 deletion src/library/baseexternalplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TrackPointer BaseExternalPlaylistModel::getTrack(const QModelIndex& index) const

bool track_already_in_library = false;
TrackPointer pTrack = m_pTrackCollectionManager->getOrAddTrack(
TrackRef::fromFileInfo(location),
TrackRef::fromFilePath(location),
&track_already_in_library);

// If this track was not in the Mixxx library it is now added and will be
Expand Down
2 changes: 1 addition & 1 deletion src/library/baseexternaltrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TrackPointer BaseExternalTrackModel::getTrack(const QModelIndex& index) const {

bool track_already_in_library = false;
TrackPointer pTrack = m_pTrackCollectionManager->getOrAddTrack(
TrackRef::fromFileInfo(location),
TrackRef::fromFilePath(location),
&track_already_in_library);

if (pTrack) {
Expand Down
4 changes: 2 additions & 2 deletions src/library/basesqltablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ QList<TrackRef> BaseSqlTableModel::getTrackRefs(
QList<TrackRef> trackRefs;
trackRefs.reserve(indices.size());
foreach (QModelIndex index, indices) {
trackRefs.append(TrackRef::fromFileInfo(
TrackFile(getTrackLocation(index)),
trackRefs.append(TrackRef::fromFilePath(
getTrackLocation(index),
getTrackId(index)));
}
return trackRefs;
Expand Down
8 changes: 4 additions & 4 deletions src/library/basetrackcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ constexpr bool sDebug = false;
} // namespace

BaseTrackCache::BaseTrackCache(TrackCollection* pTrackCollection,
const QString& tableName,
const QString& idColumn,
const QStringList& columns,
bool isCaching)
const QString& tableName,
const QString& idColumn,
const QStringList& columns,
bool isCaching)
: m_tableName(tableName),
m_idColumn(idColumn),
m_columnCount(columns.size()),
Expand Down
2 changes: 1 addition & 1 deletion src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ QList<QUrl> BaseTrackTableModel::collectUrls(
continue;
}
visitedRows.insert(index.row());
QUrl url = TrackFile(getTrackLocation(index)).toUrl();
QUrl url = mixxx::FileInfo(getTrackLocation(index)).toQUrl();
if (url.isValid()) {
urls.append(url);
}
Expand Down
23 changes: 11 additions & 12 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,18 @@ void BrowseFeature::activateChild(const QModelIndex& index) {
} else {
// Open a security token for this path and if we do not have access, ask
// for it.
auto dir = mixxx::FileAccess(mixxx::FileInfo(path));
if (!dir.isReadable()) {
if (Sandbox::askForAccess(path)) {
auto dirInfo = mixxx::FileInfo(path);
auto dirAccess = mixxx::FileAccess(dirInfo);
if (!dirAccess.isReadable()) {
if (Sandbox::askForAccess(&dirInfo)) {
// Re-create to get a new token.
dir = mixxx::FileAccess(mixxx::FileInfo(path));
dirAccess = mixxx::FileAccess(dirInfo);
} else {
// TODO(rryan): Activate an info page about sandboxing?
return;
}
}
m_browseModel.setPath(std::move(dir));
m_browseModel.setPath(std::move(dirAccess));
}
emit showTrackModel(&m_proxyModel);
emit enableCoverArtDisplay(false);
Expand Down Expand Up @@ -485,12 +486,12 @@ QStringList BrowseFeature::getDefaultQuickLinks() const {
bool osDesktopDirIncluded = false;
bool osDocumentsDirIncluded = false;
const auto rootDirs = m_pLibrary->trackCollections()->internalCollection()->loadRootDirs();
for (const mixxx::FileInfo& fileInfo : rootDirs) {
const auto dir = fileInfo.toQDir();
for (mixxx::FileInfo fileInfo : rootDirs) {
// Skip directories we don't have permission to.
if (!Sandbox::canAccessDir(dir)) {
if (!Sandbox::canAccess(&fileInfo)) {
continue;
}
const auto dir = fileInfo.toQDir();
if (dir == osMusicDir) {
osMusicDirIncluded = true;
}
Expand All @@ -515,13 +516,11 @@ QStringList BrowseFeature::getDefaultQuickLinks() const {
result << osDownloadsDir.canonicalPath() + "/";
}

if (!osDesktopDirIncluded &&
Sandbox::canAccessDir(osDesktopDir)) {
if (!osDesktopDirIncluded && Sandbox::canAccessDir(osDesktopDir)) {
result << osDesktopDir.canonicalPath() + "/";
}

if (!osDocumentsDirIncluded &&
Sandbox::canAccessDir(osDocumentsDir)) {
if (!osDocumentsDirIncluded && Sandbox::canAccessDir(osDocumentsDir)) {
result << osDocumentsDir.canonicalPath() + "/";
}

Expand Down
5 changes: 2 additions & 3 deletions src/library/browse/browsetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "moc_browsetablemodel.cpp"
#include "track/track.h"
#include "util/compatibility.h"
#include "util/fileaccess.h"
#include "widget/wlibrarytableview.h"

BrowseTableModel::BrowseTableModel(QObject* parent,
Expand Down Expand Up @@ -191,7 +190,7 @@ void BrowseTableModel::setPath(mixxx::FileAccess path) {
}

TrackPointer BrowseTableModel::getTrack(const QModelIndex& index) const {
return getTrackByRef(TrackRef::fromFileInfo(getTrackLocation(index)));
return getTrackByRef(TrackRef::fromFilePath(getTrackLocation(index)));
}

TrackPointer BrowseTableModel::getTrackByRef(const TrackRef& trackRef) const {
Expand Down Expand Up @@ -298,7 +297,7 @@ QMimeData* BrowseTableModel::mimeData(const QModelIndexList& indexes) const {
if (index.isValid()) {
if (!rows.contains(index.row())) {
rows.push_back(index.row());
QUrl url = TrackFile(getTrackLocation(index)).toUrl();
QUrl url = mixxx::FileInfo(getTrackLocation(index)).toQUrl();
if (!url.isValid()) {
qDebug() << "ERROR invalid url" << url;
continue;
Expand Down
22 changes: 14 additions & 8 deletions src/library/browse/browsethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ void BrowseThread::populateModel() {
BrowseTableModel* thisModelObserver = m_model_observer;
m_path_mutex.unlock();

if (!thisPath.info().hasLocation()) {
// Abort if the location is inaccessible or does not exist
qWarning() << "Skipping" << thisPath.info();
return;
}

// Refresh the name filters in case we loaded new SoundSource plugins.
QStringList nameFilters(SoundSourceProxy::getSupportedFileNamePatterns());
const QStringList nameFilters = SoundSourceProxy::getSupportedFileNamePatterns();

QDirIterator fileIt(thisPath.info().location(),
nameFilters,
Expand Down Expand Up @@ -151,12 +157,12 @@ void BrowseThread::populateModel() {
item->setData("0", Qt::UserRole);
row_data.insert(COLUMN_PREVIEW, item);

const QString filepath = fileIt.next();
const auto fileAccess = mixxx::FileAccess(
mixxx::FileInfo(fileIt.next()),
thisPath.token());
{
const TrackPointer pTrack =
SoundSourceProxy::importTemporaryTrack(
filepath,
thisPath.token());
SoundSourceProxy::importTemporaryTrack(fileAccess);

item = new QStandardItem(pTrack->getFileInfo().fileName());
item->setToolTip(item->text());
Expand Down Expand Up @@ -249,15 +255,15 @@ void BrowseThread::populateModel() {
row_data.insert(COLUMN_GROUPING, item);

const auto fileLastModified =
pTrack->getFileInfo().fileLastModified();
fileAccess.info().lastModified();
item = new QStandardItem(
mixxx::displayLocalDateTime(fileLastModified));
item->setToolTip(item->text());
item->setData(fileLastModified, Qt::UserRole);
row_data.insert(COLUMN_FILE_MODIFIED_TIME, item);

const auto fileCreated =
pTrack->getFileInfo().fileCreated();
fileAccess.info().birthTime();
item = new QStandardItem(
mixxx::displayLocalDateTime(fileCreated));
item->setToolTip(item->text());
Expand All @@ -279,7 +285,7 @@ void BrowseThread::populateModel() {
if (row % 10 == 0) {
// this is a blocking operation
emit rowsAppended(rows, thisModelObserver);
qDebug() << "Append " << rows.count() << " from " << filepath;
qDebug() << "Append " << rows.count() << " from " << fileAccess.info();
rows.clear();
}
// Sleep additionally for 10ms which prevents us from GUI freezes
Expand Down
29 changes: 12 additions & 17 deletions src/library/coverart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ bool operator==(const CoverInfoRelative& lhs, const CoverInfoRelative& rhs) {
lhs.coverLocation == rhs.coverLocation;
}

bool operator!=(const CoverInfoRelative& lhs, const CoverInfoRelative& rhs) {
return !(lhs == rhs);
}

QDebug operator<<(QDebug dbg, const CoverInfoRelative& info) {
const QDebugStateSaver saver(dbg);
dbg = dbg.maybeSpace() << "CoverInfoRelative";
Expand Down Expand Up @@ -112,10 +108,11 @@ CoverInfo::LoadedImage CoverInfo::loadImage(
loadedImage.result = LoadedImage::Result::ErrorMetadataWithEmptyTrackLocation;
return loadedImage;
}
loadedImage.filePath = trackLocation;
loadedImage.location = trackLocation;
loadedImage.image = CoverArtUtils::extractEmbeddedCover(
TrackFile(trackLocation),
pTrackLocationToken);
mixxx::FileAccess(
mixxx::FileInfo(trackLocation),
pTrackLocationToken));
if (loadedImage.image.isNull()) {
// TODO: extractEmbeddedCover() should indicate if no image
// is available or if loading the embedded image failed.
Expand All @@ -126,7 +123,7 @@ CoverInfo::LoadedImage CoverInfo::loadImage(
loadedImage.result = LoadedImage::Result::Ok;
}
} else if (type == CoverInfo::FILE) {
auto coverFile = QFileInfo(coverLocation);
auto coverFile = mixxx::FileInfo(coverLocation);
if (coverFile.isRelative()) {
VERIFY_OR_DEBUG_ASSERT(!trackLocation.isEmpty()) {
// This is not expected to happen, because every track
Expand All @@ -138,23 +135,21 @@ CoverInfo::LoadedImage CoverInfo::loadImage(
return loadedImage;
}
// Compose track directory with relative path
const auto trackFile = TrackFile(trackLocation);
DEBUG_ASSERT(trackFile.asFileInfo().isAbsolute());
coverFile = QFileInfo(
trackFile.directory(),
const auto fileInfo = mixxx::FileInfo(trackLocation);
coverFile = mixxx::FileInfo(
fileInfo.locationPath(),
coverLocation);
}
DEBUG_ASSERT(coverFile.isAbsolute());
loadedImage.filePath = coverFile.filePath();
loadedImage.location = coverFile.location();
if (!coverFile.exists()) {
loadedImage.result = LoadedImage::Result::ErrorFilePathDoesNotExist;
return loadedImage;
}
SecurityTokenPointer pToken =
Sandbox::openSecurityToken(
coverFile,
&coverFile,
true);
if (loadedImage.image.load(loadedImage.filePath)) {
if (loadedImage.image.load(loadedImage.location)) {
DEBUG_ASSERT(!loadedImage.image.isNull());
loadedImage.result = LoadedImage::Result::Ok;
} else {
Expand Down Expand Up @@ -242,7 +237,7 @@ QDebug operator<<(QDebug dbg, const CoverInfo::LoadedImage& loadedImage) {
dbg = dbg.maybeSpace() << "CoverInfo::LoadedImage";
return dbg.nospace()
<< '{'
<< loadedImage.filePath
<< loadedImage.location
<< ','
<< loadedImage.image.size()
<< ','
Expand Down
Loading