Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/library/trackcollectionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "sources/soundsourceproxy.h"
#include "track/track.h"
#include "util/assert.h"
#include "util/cmdlineargs.h"
#include "util/db/dbconnectionpooled.h"
#include "util/logger.h"

Expand Down Expand Up @@ -43,9 +44,11 @@ TrackCollectionManager::TrackCollectionManager(
m_pInternalCollection(createInternalTrackCollection(this, pConfig, deleteTrackForTestingFn)) {
const QSqlDatabase dbConnection = mixxx::DbConnectionPooled(pDbConnectionPool);

// TODO(XXX): Add a checkbox in the library preferences for checking
// and repairing the database on the next restart of the application.
if (pConfig->getValue(kRepairDatabaseOnNextRestartConfigKey, false)) {
// The database repair can be triggered via "Repair Database"
// in the options menu, as well as using the command line option
// "--repair-database".
if (CmdlineArgs::Instance().getRepairDatabase() ||
pConfig->getValue(kRepairDatabaseOnNextRestartConfigKey, false)) {
m_pInternalCollection->repairDatabase(dbConnection);
// Reset config value
pConfig->setValue(kRepairDatabaseOnNextRestartConfigKey, false);
Expand Down
27 changes: 27 additions & 0 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,11 @@ void MixxxMainWindow::connectMenuBar() {
this,
&MixxxMainWindow::slotOptionsPreferences,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::repairDatabase,
this,
&MixxxMainWindow::slotOptionsRepairDatabase,
Qt::UniqueConnection);
connect(m_pMenuBar,
&WMainMenuBar::loadTrackToDeck,
this,
Expand Down Expand Up @@ -1134,6 +1139,28 @@ void MixxxMainWindow::slotOptionsPreferences() {
m_pPrefDlg->activateWindow();
}

void MixxxMainWindow::slotOptionsRepairDatabase() {
QMessageBox::StandardButton btn = QMessageBox::warning(
this,
VersionStore::applicationName(),
tr("Repairing the database requires a restart of Mixxx.\n"
"Do you want to exit out of Mixxx and run the database repair on the next launch?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (btn == QMessageBox::Yes) {
// TODO(cr7pt0gr4ph7): Implement an external restart handler that
// automatically restarts Mixxx here. Basically just a small
// cmdline application that, when invoked, forwards everything to the
// main Mixxx executable, but also listens for a a special restart flag.

// Set flag and exit out of Mixxx
m_pCoreServices->getSettings()->setValue(
mixxx::library::prefs::kRepairDatabaseOnNextRestartConfigKey,
true);
close();
}
}

void MixxxMainWindow::slotNoVinylControlInputConfigured() {
if (m_noVinylInputDialog && m_noVinylInputDialog->isVisible()) {
// Don't show redundant dialogs.
Expand Down
2 changes: 2 additions & 0 deletions src/mixxxmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class MixxxMainWindow : public QMainWindow {
void slotFileLoadSongPlayer(int deck);
/// show the preferences dialog
void slotOptionsPreferences();
/// set up a database repair for next start
void slotOptionsRepairDatabase();
/// show the about dialog
void slotHelpAbout();
/// show popup with library scan results
Expand Down
11 changes: 11 additions & 0 deletions src/util/cmdlineargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ CmdlineArgs::CmdlineArgs()
m_qml(false),
#endif
m_safeMode(false),
m_repairDatabase(false),
m_useLegacyVuMeter(false),
m_useLegacySpinny(false),
m_debugAssertBreak(false),
Expand Down Expand Up @@ -199,6 +200,12 @@ bool CmdlineArgs::parse(const QStringList& arguments, CmdlineArgs::ParseMode mod
: QString());
parser.addOption(rescanLibrary);

const QCommandLineOption repairDatabase(QStringLiteral("repair-database"),
forUserFeedback ? QCoreApplication::translate("CmdlineArgs",
"Run a database cleanup when Mixxx is launched.")
: QString());
parser.addOption(repairDatabase);

// An option with a value
const QCommandLineOption settingsPath(QStringLiteral("settings-path"),
forUserFeedback ? QCoreApplication::translate("CmdlineArgs",
Expand Down Expand Up @@ -446,6 +453,10 @@ bool CmdlineArgs::parse(const QStringList& arguments, CmdlineArgs::ParseMode mod
m_rescanLibrary = true;
}

if (parser.isSet(repairDatabase)) {
m_repairDatabase = true;
}

if (parser.isSet(settingsPath)) {
m_settingsPath = parser.value(settingsPath);
if (!m_settingsPath.endsWith("/")) {
Expand Down
4 changes: 4 additions & 0 deletions src/util/cmdlineargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class CmdlineArgs final {
}
#endif
bool getSafeMode() const { return m_safeMode; }
bool getRepairDatabase() const {
return m_repairDatabase;
}
bool useColors() const {
return m_useColors;
}
Expand Down Expand Up @@ -112,6 +115,7 @@ class CmdlineArgs final {
bool m_awareOfRisk;
#endif
bool m_safeMode;
bool m_repairDatabase;
bool m_useLegacyVuMeter;
bool m_useLegacySpinny;
bool m_debugAssertBreak;
Expand Down
8 changes: 8 additions & 0 deletions src/widget/wmainmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@ void WMainMenuBar::initialize() {

pOptionsMenu->addSeparator();

QString repairDatabaseTitle = tr("Repair Database");
QString repairDatabaseText = tr("Restart Mixxx & repair database inconsistencies");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QString repairDatabaseText = tr("Restart Mixxx & repair database inconsistencies");
QString repairDatabaseText = tr("Repair database inconsistencies on next launch");

to not imply that Mixxx quits and restarts by itself.
I know this is more clear in the message box in MixxxMainWindow::slotOptionsRepairDatabase(), but with the "Restart .." title I'd hesitate to click this because it sounds like it would restart immediately

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, it does quit right away.
Guess this is desired behavior, because why feel the urge to cleanup the db and not do it right away..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should quit right away because that's needed for the DB cleanup. Either you want to repair the database, or you don't. Ideally it would also restart Mixxx, but that would require an external wrapper application AFAICT, and is probably best left to a separate PR.

auto* pOptionsRepairDatabase = new QAction(repairDatabaseTitle, this);
pOptionsRepairDatabase->setStatusTip(repairDatabaseText);
pOptionsRepairDatabase->setWhatsThis(buildWhatsThis(repairDatabaseTitle, repairDatabaseText));
connect(pOptionsRepairDatabase, &QAction::triggered, this, &WMainMenuBar::repairDatabase);
pOptionsMenu->addAction(pOptionsRepairDatabase);

QString preferencesTitle = tr("&Preferences");
QString preferencesText = tr("Change Mixxx settings (e.g. playback, MIDI, controls)");
auto* pOptionsPreferences = new QAction(preferencesTitle, this);
Expand Down
1 change: 1 addition & 0 deletions src/widget/wmainmenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class WMainMenuBar : public QMenuBar {
void createPlaylist();
void loadTrackToDeck(int deck);
void reloadSkin();
void repairDatabase();
void rescanLibrary();
#ifdef __ENGINEPRIME__
void exportLibrary();
Expand Down
Loading