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

Stop browse thread before deleting the library #11593

Merged
merged 3 commits into from
Jun 5, 2023
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
4 changes: 4 additions & 0 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,7 @@ QStringList BrowseFeature::getDefaultQuickLinks() const {
qDebug() << "Default quick links:" << result;
return result;
}

void BrowseFeature::releaseBrowseThread() {
m_browseModel.releaseBrowseThread();
}
2 changes: 2 additions & 0 deletions src/library/browse/browsefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class BrowseFeature : public LibraryFeature {

TreeItemModel* getChildModel();

void releaseBrowseThread();

public slots:
void slotAddQuickLink();
void slotRemoveQuickLink();
Expand Down
13 changes: 11 additions & 2 deletions src/library/browse/browsetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ const QList<int>& BrowseTableModel::searchColumns() const {
}

void BrowseTableModel::setPath(const MDir& path) {
m_current_directory = path;
m_pBrowseThread->executePopulation(m_current_directory, this);
if (m_pBrowseThread) {
m_current_directory = path;
m_pBrowseThread->executePopulation(m_current_directory, this);
}
}

TrackPointer BrowseTableModel::getTrack(const QModelIndex& index) const {
Expand Down Expand Up @@ -471,3 +473,10 @@ QAbstractItemDelegate* BrowseTableModel::delegateForColumn(const int i, QObject*
}
return nullptr;
}

void BrowseTableModel::releaseBrowseThread() {
// The shared browse thread is stopped in the destructor
// if this is the last reference. All references must be reset before
// the library is destructed.
m_pBrowseThread.reset();
}
1 change: 1 addition & 0 deletions src/library/browse/browsetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo
bool isColumnSortable(int column) const override;
TrackModel::SortColumnId sortColumnIdFromColumnIndex(int index) const override;
int columnIndexFromSortColumnId(TrackModel::SortColumnId sortColumn) const override;
void releaseBrowseThread();

public slots:
void slotClear(BrowseTableModel*);
Expand Down
14 changes: 7 additions & 7 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ Library::Library(
m_pCrateFeature = new CrateFeature(this, m_pConfig);
addFeature(m_pCrateFeature);

BrowseFeature* browseFeature = new BrowseFeature(
this, m_pConfig, pRecordingManager);
connect(browseFeature,
m_pBrowseFeature = new BrowseFeature(
this, m_pConfig, pRecordingManager);
connect(m_pBrowseFeature,
&BrowseFeature::scanLibrary,
m_pTrackCollectionManager,
&TrackCollectionManager::startLibraryScan);
connect(m_pTrackCollectionManager,
&TrackCollectionManager::libraryScanStarted,
browseFeature,
m_pBrowseFeature,
&BrowseFeature::slotLibraryScanStarted);
connect(m_pTrackCollectionManager,
&TrackCollectionManager::libraryScanFinished,
browseFeature,
m_pBrowseFeature,
&BrowseFeature::slotLibraryScanFinished);
addFeature(browseFeature);
addFeature(m_pBrowseFeature);

addFeature(new RecordingFeature(this, m_pConfig, pRecordingManager));
addFeature(new SetlogFeature(this, UserSettingsPointer(m_pConfig)));
Expand Down Expand Up @@ -218,8 +218,8 @@ TrackCollectionManager* Library::trackCollections() const {
void Library::stopPendingTasks() {
if (m_pAnalysisFeature) {
m_pAnalysisFeature->stopAnalysis();
m_pAnalysisFeature = nullptr;
}
m_pBrowseFeature->releaseBrowseThread();
}

void Library::bindSearchboxWidget(WSearchLineEdit* pSearchboxWidget) {
Expand Down
2 changes: 2 additions & 0 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "util/parented_ptr.h"

class AnalysisFeature;
class BrowseFeature;
class ControlObject;
class CrateFeature;
class ExternalTrackCollection;
Expand Down Expand Up @@ -142,6 +143,7 @@ class Library: public QObject {
PlaylistFeature* m_pPlaylistFeature;
CrateFeature* m_pCrateFeature;
AnalysisFeature* m_pAnalysisFeature;
BrowseFeature* m_pBrowseFeature;
QFont m_trackTableFont;
int m_iTrackTableRowHeight;
bool m_editMetadataSelectedClick;
Expand Down