Skip to content

Commit

Permalink
Library: show scan summary popup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Jul 29, 2024
1 parent da82030 commit db2e6fa
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions src/coreservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TrackCollectionManager;
class Library;
class SkinControls;
class ControlPushButton;
struct LibraryScanResultSummary;

namespace mixxx {

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/library/library_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 numVerifiedDirs;
int numScannedDirs;
int numVerifiedTracks;
int numNewTracks;
int numMovedTracks;
int numMissingTracks;
};
20 changes: 15 additions & 5 deletions src/library/scanner/libraryscanner.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -429,29 +430,38 @@ void LibraryScanner::slotFinishUnhashedScan() {
}

const QString durationString = m_scannerGlobal->timerElapsed().formatMillisWithUnit();
const int numUnchangedDirs = static_cast<int>(m_scannerGlobal->verifiedDirectories().size());
const int numChangedAddedDirs = m_scannerGlobal->numScannedDirectories();
const int numVerifiedDirs = static_cast<int>(m_scannerGlobal->verifiedDirectories().size());
const int numScannedDirs = m_scannerGlobal->numScannedDirectories();
const int numVerifiedTracks = static_cast<int>(m_scannerGlobal->verifiedTracks().size());
const int numNewTracks = m_scannerGlobal->addedTracks().size() - m_numRelocatedTracks;
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);
qInfo(" %d changed/added directories", numChangedAddedDirs);
qInfo(" %d unchanged directories", numVerifiedDirs);
qInfo(" %d scanned directories", numScannedDirs);
qInfo(" %d tracks verified from changed/added directories", numVerifiedTracks);
qInfo(" %d new tracks", numNewTracks);
qInfo(" %d moved tracks", m_numRelocatedTracks);
qInfo(" %d missing tracks", numMissingTracks);
qInfo() << "-------------------------------------------------------";

LibraryScanResultSummary result;
result.durationString = durationString;
result.numVerifiedDirs = numVerifiedDirs;
result.numScannedDirs = numScannedDirs;
result.numVerifiedTracks = numVerifiedTracks;
result.numNewTracks = numNewTracks;
result.numMovedTracks = m_numRelocatedTracks;
result.numMissingTracks = numMissingTracks;

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

emit scanFinished();
emit scanSummary(result);
}

void LibraryScanner::scan() {
Expand Down
2 changes: 2 additions & 0 deletions src/library/scanner/libraryscanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class ScannerTask;
class LibraryScannerDlg;
class QString;
struct LibraryScanResultSummary;

class LibraryScanner : public QThread {
FRIEND_TEST(LibraryScannerTest, ScannerRoundtrip);
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/library/trackcollectionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <utility>

#include "library/externaltrackcollection.h"
#include "library/library_decl.h"
#include "library/library_prefs.h"
#include "library/scanner/libraryscanner.h"
#include "library/trackcollection.h"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/library/trackcollectionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -95,6 +96,7 @@ class TrackCollectionManager: public QObject,
signals:
void libraryScanStarted();
void libraryScanFinished();
void libraryScanSummary(const LibraryScanResultSummary& result);

public slots:
void startLibraryScan();
Expand Down
31 changes: 31 additions & 0 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -117,6 +118,12 @@ MixxxMainWindow::MixxxMainWindow(std::shared_ptr<mixxx::CoreServices> pCoreServi
CmdlineArgs::Instance().getStartInFullscreen() || fullscreenPref);
}
#endif // __LINUX__

connect(m_pCoreServices.get(),
&mixxx::CoreServices::libraryScanSummary,
this,
&MixxxMainWindow::slotLibraryScanSummaryDlg);

createMenuBar();
m_pMenuBar->hide();

Expand Down Expand Up @@ -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.numNewTracks + result.numMovedTracks + result.numMissingTracks) == 0) {
summary += tr("No changes were detected.");
} else {
summary += tr("%1 verified directories").arg(result.numVerifiedDirs) +
QStringLiteral("\n") +
tr("%1 scanned directories").arg(result.numScannedDirs) +
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<DlgKeywheel>(this, m_pCoreServices->getSettings());
Expand Down
5 changes: 4 additions & 1 deletion src/mixxxmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class GuiTick;
class LaunchImage;
class VisualsManager;
class WMainMenuBar;
struct LibraryScanResultSummary;

namespace mixxx {

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit db2e6fa

Please sign in to comment.