diff --git a/src/coreservices.cpp b/src/coreservices.cpp index 3a66ab5decc5..e1b57089f90a 100644 --- a/src/coreservices.cpp +++ b/src/coreservices.cpp @@ -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 @@ -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; } } @@ -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(); } diff --git a/src/library/browse/browsefeature.cpp b/src/library/browse/browsefeature.cpp index 180c67008d0b..f0ee679d29f0 100644 --- a/src/library/browse/browsefeature.cpp +++ b/src/library/browse/browsefeature.cpp @@ -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, @@ -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); diff --git a/src/library/library.cpp b/src/library/library.cpp index 7830255076cb..103bb706b396 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -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 @@ -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 %1 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)); @@ -638,7 +641,7 @@ void Library::slotRequestRemoveDir(const QString& dir, LibraryRemovalType remova default: DEBUG_ASSERT(!"unreachable"); } - return; + return false; } switch (removalType) { @@ -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; @@ -676,7 +681,7 @@ 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, @@ -684,6 +689,7 @@ void Library::slotRequestRelocateDir(const QString& oldDir, const QString& newDi tr("Could not relink %1 to %2.\n\n%3") .arg(oldDir, newDir, error)); } + return false; } void Library::setFont(const QFont& font) { diff --git a/src/library/library.h b/src/library/library.h index 3cd08cc23e55..de00a24aa71b 100644 --- a/src/library/library.h +++ b/src/library/library.h @@ -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 makeLibraryExporter(QWidget* parent); #endif @@ -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: diff --git a/src/preferences/dialog/dlgpreflibrary.cpp b/src/preferences/dialog/dlgpreflibrary.cpp index efb1966877fc..49beb6e749de 100644 --- a/src/preferences/dialog/dlgpreflibrary.cpp +++ b/src/preferences/dialog/dlgpreflibrary.cpp @@ -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, @@ -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 @@ -240,7 +234,7 @@ void DlgPrefLibrary::slotResetToDefaults() { } void DlgPrefLibrary::slotUpdate() { - populateDirList(); + updateDirList(); checkBox_library_scan->setChecked(m_pConfig->getValue( kRescanOnStartupConfigKey, false)); @@ -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; + } } } @@ -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() { @@ -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(); } } diff --git a/src/preferences/dialog/dlgpreflibrary.h b/src/preferences/dialog/dlgpreflibrary.h index d817d6af0141..b5146299b865 100644 --- a/src/preferences/dialog/dlgpreflibrary.h +++ b/src/preferences/dialog/dlgpreflibrary.h @@ -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);