Skip to content

Commit

Permalink
Library: offer rescan & update directory list only if directories cha…
Browse files Browse the repository at this point in the history
…nged
  • Loading branch information
ronso0 committed Apr 19, 2024
1 parent a6dfbd0 commit 3889305
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 44 deletions.
11 changes: 5 additions & 6 deletions src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void CoreServices::initialize(QApplication* pApp) {
// the uninitialized singleton instance!
m_pPlayerManager->bindToLibrary(m_pLibrary.get());

bool hasChanged_MusicDir = false;
bool musicDirAdded = false;

if (m_pTrackCollectionManager->internalCollection()->loadRootDirs().isEmpty()) {
// TODO(XXX) this needs to be smarter, we can't distinguish between an empty
Expand All @@ -371,10 +371,9 @@ void CoreServices::initialize(QApplication* pApp) {
tr("Choose music library directory"),
QStandardPaths::writableLocation(
QStandardPaths::MusicLocation));
if (!fd.isEmpty()) {
// adds Folder to database.
m_pLibrary->slotRequestAddDir(fd);
hasChanged_MusicDir = true;
// request to add directory to database.
if (!fd.isEmpty() && m_pLibrary->requestAddDir(fd)) {
musicDirAdded = true;
}
}

Expand Down Expand Up @@ -425,7 +424,7 @@ void CoreServices::initialize(QApplication* pApp) {

// Scan the library directory. Do this after the skinloader has
// loaded a skin, see issue #6625
if (rescan || hasChanged_MusicDir || m_pSettingsManager->shouldRescanLibrary()) {
if (rescan || musicDirAdded || m_pSettingsManager->shouldRescanLibrary()) {
m_pTrackCollectionManager->startLibraryScan();
}

Expand Down
8 changes: 3 additions & 5 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ BrowseFeature::BrowseFeature(
m_proxyModel(&m_browseModel, true),
m_pSidebarModel(new FolderTreeModel(this)),
m_pLastRightClickedItem(nullptr) {
connect(this,
&BrowseFeature::requestAddDir,
pLibrary,
&Library::slotRequestAddDir);
connect(&m_browseModel,
&BrowseTableModel::restoreModelState,
this,
Expand Down Expand Up @@ -178,7 +174,9 @@ void BrowseFeature::slotAddToLibrary() {
return;
}
QString spath = m_pLastRightClickedItem->getData().toString();
emit requestAddDir(spath);
if (!m_pLibrary->requestAddDir(spath)) {
return;
}

QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Warning);
Expand Down
20 changes: 13 additions & 7 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ void Library::onSkinLoadFinished() {
m_pSidebarModel->activateDefaultSelection();
}

void Library::slotRequestAddDir(const QString& dir) {
bool Library::requestAddDir(const QString& dir) {
// We only call this method if the user has picked a new directory via a
// file dialog. This means the system sandboxer (if we are sandboxed) has
// granted us permission to this folder. Create a security bookmark while we
Expand Down Expand Up @@ -613,17 +613,20 @@ void Library::slotRequestAddDir(const QString& dir) {
"Aborting the operation to avoid library inconsistencies");
break;
default:
return;
return false;
}
if (!error.isEmpty()) {
QMessageBox::information(nullptr,
tr("Can't add Directory to Library"),
tr("Could not add <b>%1</b> to your library.\n\n%2")
.arg(directory.absolutePath(), error));
return false;
}

return true;
}

void Library::slotRequestRemoveDir(const QString& dir, LibraryRemovalType removalType) {
bool Library::requestRemoveDir(const QString& dir, LibraryRemovalType removalType) {
// Remove the directory from the directory list.
DirectoryDAO::RemoveResult result =
m_pTrackCollectionManager->removeDirectory(mixxx::FileInfo(dir));
Expand All @@ -638,7 +641,7 @@ void Library::slotRequestRemoveDir(const QString& dir, LibraryRemovalType remova
default:
DEBUG_ASSERT(!"unreachable");
}
return;
return false;
}

switch (removalType) {
Expand All @@ -656,13 +659,15 @@ void Library::slotRequestRemoveDir(const QString& dir, LibraryRemovalType remova
default:
DEBUG_ASSERT(!"unreachable");
}

return true;
}

void Library::slotRequestRelocateDir(const QString& oldDir, const QString& newDir) {
bool Library::requestRelocateDir(const QString& oldDir, const QString& newDir) {
DirectoryDAO::RelocateResult result =
m_pTrackCollectionManager->relocateDirectory(oldDir, newDir);
if (result == DirectoryDAO::RelocateResult::Ok) {
return;
return true;
}

QString error;
Expand All @@ -676,14 +681,15 @@ void Library::slotRequestRelocateDir(const QString& oldDir, const QString& newDi
"This directory can not be read.");
break;
default:
return;
DEBUG_ASSERT(!"unreachable");
}
if (!error.isEmpty()) {
QMessageBox::information(nullptr,
tr("Relink Directory"),
tr("Could not relink <b>%1</b> to <b>%2</b>.\n\n%3")
.arg(oldDir, newDir, error));
}
return false;
}

void Library::setFont(const QFont& font) {
Expand Down
7 changes: 4 additions & 3 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class Library: public QObject {
/// and shows the results by switching the view.
void searchTracksInCollection(const QString& query);

bool requestAddDir(const QString& directory);
bool requestRemoveDir(const QString& directory, LibraryRemovalType removalType);
bool requestRelocateDir(const QString& previousDirectory, const QString& newDirectory);

#ifdef __ENGINEPRIME__
std::unique_ptr<mixxx::LibraryExporter> makeLibraryExporter(QWidget* parent);
#endif
Expand All @@ -111,9 +115,6 @@ class Library: public QObject {
void slotRefreshLibraryModels();
void slotCreatePlaylist();
void slotCreateCrate();
void slotRequestAddDir(const QString& directory);
void slotRequestRemoveDir(const QString& directory, LibraryRemovalType removalType);
void slotRequestRelocateDir(const QString& previousDirectory, const QString& newDirectory);
void onSkinLoadFinished();

signals:
Expand Down
39 changes: 17 additions & 22 deletions src/preferences/dialog/dlgpreflibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ DlgPrefLibrary::DlgPrefLibrary(
m_iOriginalTrackTableRowHeight(Library::kDefaultRowHeightPx) {
setupUi(this);

connect(this,
&DlgPrefLibrary::requestAddDir,
m_pLibrary.get(),
&Library::slotRequestAddDir);
connect(this,
&DlgPrefLibrary::requestRemoveDir,
m_pLibrary.get(),
&Library::slotRequestRemoveDir);
connect(this,
&DlgPrefLibrary::requestRelocateDir,
m_pLibrary.get(),
&Library::slotRequestRelocateDir);
connect(PushButtonAddDir,
&QPushButton::clicked,
this,
Expand Down Expand Up @@ -171,7 +159,13 @@ QUrl DlgPrefLibrary::helpUrl() const {
return QUrl(MIXXX_MANUAL_LIBRARY_URL);
}

void DlgPrefLibrary::populateDirList() {
//<<<<<<< HEAD
//void DlgPrefLibrary::populateDirList() {
//||||||| parent of 19606101db (Library: offer rescan & update directory list only if directories changed)
//void DlgPrefLibrary::initializeDirList() {
//=======
void DlgPrefLibrary::updateDirList() {
//>>>>>>> 19606101db (Library: offer rescan & update directory list only if directories changed)
// save which index was selected
const QString selected = dirList->currentIndex().data().toString();
// clear and fill model
Expand Down Expand Up @@ -240,7 +234,7 @@ void DlgPrefLibrary::slotResetToDefaults() {
}

void DlgPrefLibrary::slotUpdate() {
populateDirList();
updateDirList();
checkBox_library_scan->setChecked(m_pConfig->getValue(
kRescanOnStartupConfigKey, false));

Expand Down Expand Up @@ -354,9 +348,10 @@ void DlgPrefLibrary::slotAddDir() {
this, tr("Choose a music directory"),
QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
if (!fd.isEmpty()) {
emit requestAddDir(fd);
slotUpdate();
m_bAddedDirectory = true;
if (m_pLibrary->requestAddDir(fd)) {
updateDirList();
m_bAddedDirectory = true;
}
}
}

Expand Down Expand Up @@ -412,8 +407,9 @@ void DlgPrefLibrary::slotRemoveDir() {
removalType = LibraryRemovalType::KeepTracks;
}

emit requestRemoveDir(fd, removalType);
slotUpdate();
if (m_pLibrary->requestRemoveDir(fd, removalType)) {
updateDirList();
}
}

void DlgPrefLibrary::slotRelocateDir() {
Expand All @@ -434,9 +430,8 @@ void DlgPrefLibrary::slotRelocateDir() {
QString fd = QFileDialog::getExistingDirectory(
this, tr("Relink music directory to new location"), startDir);

if (!fd.isEmpty()) {
emit requestRelocateDir(currentFd, fd);
slotUpdate();
if (!fd.isEmpty() && m_pLibrary->requestRelocateDir(currentFd, fd)) {
updateDirList();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/preferences/dialog/dlgpreflibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DlgPrefLibrary : public DlgPreferencePage, public Ui::DlgPrefLibraryDlg {
void slotSeratoMetadataExportClicked(bool);

private:
void populateDirList();
void updateDirList();
void setLibraryFont(const QFont& font);
void updateSearchLineEditHistoryOptions();
void setSeratoMetadataEnabled(bool shouldSyncTrackMetadata);
Expand Down

0 comments on commit 3889305

Please sign in to comment.