diff --git a/src/coreservices.cpp b/src/coreservices.cpp index 3ecaae55feaf..b0c707f10b03 100644 --- a/src/coreservices.cpp +++ b/src/coreservices.cpp @@ -19,6 +19,7 @@ #endif #include "library/coverartcache.h" #include "library/library.h" +#include "library/library_decl.h" #include "library/library_prefs.h" #include "library/trackcollection.h" #include "library/trackcollectionmanager.h" @@ -442,6 +443,12 @@ void CoreServices::initialize(QApplication* pApp) { pConfig->set(ConfigKey("[Library]", "SupportedFileExtensions"), supportedFileSuffixes.join(",")); + // Forward the scanner signal so MixxxMainWindow can display a summary popup. + connect(m_pTrackCollectionManager.get(), + &TrackCollectionManager::libraryScanSummary, + this, + &CoreServices::libraryScanSummary, + Qt::UniqueConnection); // Scan the library directory. Do this after the skinloader has // loaded a skin, see issue #6625 if (rescan || musicDirAdded || m_pSettingsManager->shouldRescanLibrary()) { diff --git a/src/coreservices.h b/src/coreservices.h index d0c1a2499378..f0f78baf4184 100644 --- a/src/coreservices.h +++ b/src/coreservices.h @@ -22,6 +22,7 @@ class TrackCollectionManager; class Library; class SkinControls; class ControlPushButton; +struct LibraryScanResultSummary; namespace mixxx { @@ -105,6 +106,7 @@ class CoreServices : public QObject { signals: void initializationProgressUpdate(int progress, const QString& serviceName); + void libraryScanSummary(const LibraryScanResultSummary& result); public slots: void slotOptionsKeyboard(bool toggle); diff --git a/src/library/library_decl.h b/src/library/library_decl.h index 17b9d34b1f2d..62d50cf6f305 100644 --- a/src/library/library_decl.h +++ b/src/library/library_decl.h @@ -19,3 +19,13 @@ enum class FocusWidget { Count // Used for setting the number of PushButton states of // m_pFocusedWidget in librarycontrol.cpp }; + +struct LibraryScanResultSummary { + QString durationString; + int numUnchangedDirs; + int numChangedAddedDirs; + int numVerifiedTracks; + int numNewTracks; + int numMovedTracks; + int numMissingTracks; +}; diff --git a/src/library/scanner/libraryscanner.cpp b/src/library/scanner/libraryscanner.cpp index 4051e3a8bd7a..9acc139dd635 100644 --- a/src/library/scanner/libraryscanner.cpp +++ b/src/library/scanner/libraryscanner.cpp @@ -1,6 +1,7 @@ #include "library/scanner/libraryscanner.h" #include "library/coverartutils.h" +#include "library/library_decl.h" #include "library/queryutil.h" #include "library/scanner/libraryscannerdlg.h" #include "library/scanner/recursivescandirectorytask.h" @@ -439,7 +440,6 @@ void LibraryScanner::slotFinishUnhashedScan() { const int numMissingTracks = m_numPreviousExistingTrackLocations + numNewTracks - m_trackDao.getAllExistingTrackLocations().size(); - // TODO Use this information to display a scan summary popup. qInfo() << "----------------------------------------------"; qInfo("Library scan finished after %s", durationString.toLocal8Bit().constData()); qInfo(" %d unchanged directories", numUnchangedDirs); @@ -450,11 +450,21 @@ void LibraryScanner::slotFinishUnhashedScan() { qInfo(" %d missing tracks", numMissingTracks); qInfo() << "----------------------------------------------"; + LibraryScanResultSummary result; + result.durationString = durationString; + result.numUnchangedDirs = numUnchangedDirs; + result.numChangedAddedDirs = numChangedAddedDirs; + result.numVerifiedTracks = numVerifiedTracks; + result.numNewTracks = numNewTracks; + result.numMovedTracks = numMovedTracks; + result.numMissingTracks = numMissingTracks; + m_scannerGlobal.clear(); changeScannerState(FINISHED); // now we may accept new scan commands emit scanFinished(); + emit scanSummary(result); } void LibraryScanner::scan() { diff --git a/src/library/scanner/libraryscanner.h b/src/library/scanner/libraryscanner.h index 4c7ee69de189..c8c34b29dd78 100644 --- a/src/library/scanner/libraryscanner.h +++ b/src/library/scanner/libraryscanner.h @@ -21,6 +21,7 @@ class ScannerTask; class LibraryScannerDlg; class QString; +struct LibraryScanResultSummary; class LibraryScanner : public QThread { FRIEND_TEST(LibraryScannerTest, ScannerRoundtrip); @@ -42,6 +43,7 @@ class LibraryScanner : public QThread { signals: void scanStarted(); void scanFinished(); + void scanSummary(const LibraryScanResultSummary& result); void progressHashing(const QString&); void progressLoading(const QString& path); void progressCoverArt(const QString& file); diff --git a/src/library/trackcollectionmanager.cpp b/src/library/trackcollectionmanager.cpp index 397b87bac746..d67652b75935 100644 --- a/src/library/trackcollectionmanager.cpp +++ b/src/library/trackcollectionmanager.cpp @@ -3,6 +3,7 @@ #include #include "library/externaltrackcollection.h" +#include "library/library_decl.h" #include "library/library_prefs.h" #include "library/scanner/libraryscanner.h" #include "library/trackcollection.h" @@ -84,6 +85,11 @@ TrackCollectionManager::TrackCollectionManager( this, &TrackCollectionManager::libraryScanFinished, /*signal-to-signal*/ Qt::DirectConnection); + connect(m_pScanner.get(), + &LibraryScanner::scanSummary, + this, + &TrackCollectionManager::libraryScanSummary, + /*signal-to-signal*/ Qt::DirectConnection); // Handle signals // NOTE: The receiver's thread context `this` is required to enforce diff --git a/src/library/trackcollectionmanager.h b/src/library/trackcollectionmanager.h index edf48753e052..56f91c92b89b 100644 --- a/src/library/trackcollectionmanager.h +++ b/src/library/trackcollectionmanager.h @@ -16,6 +16,7 @@ class LibraryScanner; class TrackCollection; class ExternalTrackCollection; class RelocatedTrack; +struct LibraryScanResultSummary; // Manages Mixxx's internal database of tracks as well as external track collections. // @@ -95,6 +96,7 @@ class TrackCollectionManager: public QObject, signals: void libraryScanStarted(); void libraryScanFinished(); + void libraryScanSummary(const LibraryScanResultSummary& result); public slots: void startLibraryScan(); diff --git a/src/mixxxmainwindow.cpp b/src/mixxxmainwindow.cpp index c5b44237bf97..36bd64a4aee6 100644 --- a/src/mixxxmainwindow.cpp +++ b/src/mixxxmainwindow.cpp @@ -33,6 +33,7 @@ #endif #include "control/controlindicatortimer.h" #include "library/library.h" +#include "library/library_decl.h" #include "library/library_prefs.h" #ifdef __ENGINEPRIME__ #include "library/export/libraryexporter.h" @@ -117,6 +118,12 @@ MixxxMainWindow::MixxxMainWindow(std::shared_ptr pCoreServi CmdlineArgs::Instance().getStartInFullscreen() || fullscreenPref); } #endif // __LINUX__ + + connect(m_pCoreServices.get(), + &mixxx::CoreServices::libraryScanSummary, + this, + &MixxxMainWindow::slotLibraryScanSummaryDlg); + createMenuBar(); m_pMenuBar->hide(); @@ -1139,6 +1146,30 @@ void MixxxMainWindow::slotHelpAbout() { about->show(); } +void MixxxMainWindow::slotLibraryScanSummaryDlg(const LibraryScanResultSummary& result) { + QString summary = + tr("Scan took %1.").arg(result.durationString) + QStringLiteral("\n\n"); + if (result.numChangedAddedDirs == 0) { + summary += tr("No changes were detected."); + } else { + summary += tr("%1 unchanged directories").arg(result.numUnchangedDirs) + + QStringLiteral("\n") + + tr("%1 changed or added directories").arg(result.numChangedAddedDirs) + + QStringLiteral("\n") + + tr("%1 verified tracks").arg(result.numVerifiedTracks) + + QStringLiteral("\n") + + tr("%1 new tracks found").arg(result.numNewTracks) + + QStringLiteral("\n") + + tr("%1 moved tracks detected").arg(result.numMovedTracks) + + QStringLiteral("\n") + + tr("%1 are missing").arg(result.numMissingTracks); + } + QMessageBox* msg = new QMessageBox(); + msg->setWindowTitle(tr("Library scan finished")); + msg->setText(summary); + msg->show(); +} + void MixxxMainWindow::slotShowKeywheel(bool toggle) { if (!m_pKeywheel) { m_pKeywheel = make_parented(this, m_pCoreServices->getSettings()); diff --git a/src/mixxxmainwindow.h b/src/mixxxmainwindow.h index 1c673578ce37..38e079d824a3 100644 --- a/src/mixxxmainwindow.h +++ b/src/mixxxmainwindow.h @@ -17,6 +17,7 @@ class GuiTick; class LaunchImage; class VisualsManager; class WMainMenuBar; +struct LibraryScanResultSummary; namespace mixxx { @@ -63,7 +64,9 @@ class MixxxMainWindow : public QMainWindow { void slotOptionsPreferences(); /// show the about dialog void slotHelpAbout(); - // show keywheel + /// show popup with library scan results + void slotLibraryScanSummaryDlg(const LibraryScanResultSummary& result); + /// show keywheel void slotShowKeywheel(bool toggle); /// toggle full screen mode void slotViewFullScreen(bool toggle);