Skip to content

Commit

Permalink
Library scan: don't show report dialog when auto-scan detected no cha…
Browse files Browse the repository at this point in the history
…nges
  • Loading branch information
ronso0 committed Aug 29, 2024
1 parent f8d7fd9 commit c2554f2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void CoreServices::initialize(QApplication* pApp) {
// Scan the library directory. Do this after the skinloader has
// loaded a skin, see issue #6625
if (rescan || musicDirAdded || m_pSettingsManager->shouldRescanLibrary()) {
m_pTrackCollectionManager->startLibraryScanNoReport();
m_pTrackCollectionManager->startLibraryAutoScan();
}

// This has to be done before m_pSoundManager->setupDevices()
Expand Down
1 change: 1 addition & 0 deletions src/library/library_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum class FocusWidget {

struct LibraryScanResultSummary {
QString durationString;
bool autoscan;
int numNewTracks;
int numMovedTracks;
int numMissingTracks;
Expand Down
11 changes: 5 additions & 6 deletions src/library/scanner/libraryscanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ LibraryScanner::LibraryScanner(
m_trackDao(m_cueDao, m_playlistDao, m_analysisDao, m_libraryHashDao, pConfig),
m_stateSema(1), // only one transaction is possible at a time
m_state(IDLE),
m_emitSummaryReport(true) {
m_manualScan(true) {
// Move LibraryScanner to its own thread so that our signals/slots will
// queue to our event loop.
moveToThread(this);
Expand Down Expand Up @@ -473,20 +473,19 @@ void LibraryScanner::slotFinishUnhashedScan() {
result.numMissingTracks = numMissingTracks;
result.numRediscoveredTracks = numRediscoveredTracks;
result.tracksTotal = tracksTotal;
result.autoscan = m_manualScan;

m_scannerGlobal.clear();
changeScannerState(FINISHED);
// now we may accept new scan commands

emit scanFinished();
if (m_emitSummaryReport) {
emit scanSummary(result);
}
emit scanSummary(result);
}

void LibraryScanner::scan(bool requestSummaryReport) {
void LibraryScanner::scan(bool autoscan) {
if (changeScannerState(STARTING)) {
m_emitSummaryReport = requestSummaryReport;
m_manualScan = autoscan;
emit startScan();
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/library/scanner/libraryscanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class LibraryScanner : public QThread {
public slots:
// Call from any thread to start a scan. Does nothing if a scan is already
// in progress.
// Optionally omit summary report. Purpose is to not show the summary dialog
// during startup when being called by CoreServices::initialize.
void scan(bool requestSummaryReport = true);
// The autoscan flag is used for the summary report. Receivers of scanSummary()
// can use this to decide whether to show the summary dialog, for example hide
// it for the automatic scan during startup.
void scan(bool autoscan = false);

// Call from any thread to cancel the scan.
void slotCancel();
Expand Down Expand Up @@ -129,5 +130,5 @@ class LibraryScanner : public QThread {
QList<mixxx::FileInfo> m_libraryRootDirs;
QScopedPointer<LibraryScannerDlg> m_pProgressDlg;

bool m_emitSummaryReport;
bool m_manualScan;
};
4 changes: 2 additions & 2 deletions src/library/trackcollectionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ TrackCollectionManager::~TrackCollectionManager() {
GlobalTrackCache::destroyInstance();
}

void TrackCollectionManager::startLibraryScanNoReport() {
void TrackCollectionManager::startLibraryAutoScan() {
VERIFY_OR_DEBUG_ASSERT(m_pScanner) {
return;
}
m_pScanner->scan(false);
m_pScanner->scan(true);
}

void TrackCollectionManager::startLibraryScan() {
Expand Down
2 changes: 1 addition & 1 deletion src/library/trackcollectionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TrackCollectionManager: public QObject,
};
SaveTrackResult saveTrack(const TrackPointer& pTrack) const;
// Same as startLibraryScan() but don't emit the scan summary.
void startLibraryScanNoReport();
void startLibraryAutoScan();

signals:
void libraryScanStarted();
Expand Down
12 changes: 9 additions & 3 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,17 @@ void MixxxMainWindow::slotHelpAbout() {
}

void MixxxMainWindow::slotLibraryScanSummaryDlg(const LibraryScanResultSummary& result) {
// Don't show the report dialog when the sacn is run during startup and no
// noteworthy changes have been detected.
if (result.autoscan &&
result.numNewMissingTracks == 0 &&
result.numRediscoveredTracks == 0) {
return;
}

QString summary =
tr("Scan took %1.").arg(result.durationString) + QStringLiteral("<br><br>");
if (result.numNewTracks == 0 &&
result.numMovedTracks == 0 &&
result.numNewMissingTracks == 0) {
if (result.numNewTracks == 0 && result.numMovedTracks == 0 && result.numNewMissingTracks == 0) {
summary += tr("No changes detected.") +
QStringLiteral("<br><b>") +
tr("%1 tracks in total").arg(result.tracksTotal) +
Expand Down

0 comments on commit c2554f2

Please sign in to comment.