Skip to content

Commit

Permalink
[Preview/Conflicts] Merge remote-tracking branch 'origin/ready-for-me…
Browse files Browse the repository at this point in the history
…rge/trigger-repair-database' into 'staging'
  • Loading branch information
cr7pt0gr4ph7 committed Oct 17, 2024
2 parents cc7a5f5 + cea2987 commit 5c6ecab
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/library/library_prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,10 @@ const ConfigKey mixxx::library::prefs::kTagFetcherApplyCoverConfigKey =
ConfigKey{
mixxx::library::prefs::kConfigGroup,
QStringLiteral("TagFetcherApplyCover")};

const QString kTrackCollectionConfigGroup = QStringLiteral("[TrackCollection]");

const ConfigKey mixxx::library::prefs::kRepairDatabaseOnNextRestart =
ConfigKey{
kTrackCollectionConfigGroup,
QStringLiteral("RepairDatabaseOnNextRestart")};
2 changes: 2 additions & 0 deletions src/library/library_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ extern const ConfigKey kTagFetcherApplyTagsConfigKey;

extern const ConfigKey kTagFetcherApplyCoverConfigKey;

extern const ConfigKey kRepairDatabaseOnNextRestart;

} // namespace prefs

} // namespace library
Expand Down
15 changes: 7 additions & 8 deletions src/library/trackcollectionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
#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"

namespace {

const mixxx::Logger kLogger("TrackCollectionManager");

const QString kConfigGroup = QStringLiteral("[TrackCollection]");

const ConfigKey kConfigKeyRepairDatabaseOnNextRestart(kConfigGroup, "RepairDatabaseOnNextRestart");

inline
parented_ptr<TrackCollection> createInternalTrackCollection(
TrackCollectionManager* parent,
Expand All @@ -44,12 +41,14 @@ 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(kConfigKeyRepairDatabaseOnNextRestart, 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(mixxx::library::prefs::kRepairDatabaseOnNextRestart, false)) {
m_pInternalCollection->repairDatabase(dbConnection);
// Reset config value
pConfig->setValue(kConfigKeyRepairDatabaseOnNextRestart, false);
pConfig->setValue(mixxx::library::prefs::kRepairDatabaseOnNextRestart, false);
}

m_pInternalCollection->connectDatabase(dbConnection);
Expand Down
30 changes: 30 additions & 0 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,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 @@ -1088,6 +1093,31 @@ void MixxxMainWindow::slotOptionsPreferences() {
m_pPrefDlg->activateWindow();
}

void MixxxMainWindow::slotOptionsRepairDatabase() {
const QString kConfigGroup = QStringLiteral("[TrackCollection]");
const ConfigKey kConfigKeyRepairDatabaseOnNextRestart(
kConfigGroup, "RepairDatabaseOnNextRestart");

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::kRepairDatabaseOnNextRestart, true);
close();
}
}

void MixxxMainWindow::slotNoVinylControlInputConfigured() {
QMessageBox::StandardButton btn = QMessageBox::warning(
this,
Expand Down
2 changes: 2 additions & 0 deletions src/mixxxmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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 keywheel
Expand Down
11 changes: 11 additions & 0 deletions src/util/cmdlineargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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 @@ -194,6 +195,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 @@ -402,6 +409,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 @@ -52,6 +52,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 @@ -101,6 +104,7 @@ class CmdlineArgs final {
bool m_qml;
#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 @@ -501,6 +501,14 @@ void WMainMenuBar::initialize() {

pOptionsMenu->addSeparator();

QString repairDatabaseTitle = tr("Repair Database");
QString repairDatabaseText = tr("Restart Mixxx & repair database inconsistencies");
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 @@ -63,6 +63,7 @@ class WMainMenuBar : public QMenuBar {
void createPlaylist();
void loadTrackToDeck(int deck);
void reloadSkin();
void repairDatabase();
void rescanLibrary();
#ifdef __ENGINEPRIME__
void exportLibrary();
Expand Down

0 comments on commit 5c6ecab

Please sign in to comment.