Skip to content

Commit

Permalink
Merge pull request #4223 from uklotzde/library_prefs
Browse files Browse the repository at this point in the history
Access ConfigObjects by predefined constants instead of plain strings
  • Loading branch information
daschuer authored Aug 21, 2021
2 parents 6ad1449 + 2458444 commit 7bb2f29
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 65 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/library/externaltrackcollection.cpp
src/library/hiddentablemodel.cpp
src/library/itunes/itunesfeature.cpp
src/library/library_prefs.cpp
src/library/library.cpp
src/library/librarycontrol.cpp
src/library/libraryfeature.cpp
Expand Down
33 changes: 16 additions & 17 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#endif
#include "library/externaltrackcollection.h"
#include "library/itunes/itunesfeature.h"
#include "library/library_preferences.h"
#include "library/library_prefs.h"
#include "library/librarycontrol.h"
#include "library/libraryfeature.h"
#include "library/librarytablemodel.h"
Expand Down Expand Up @@ -52,8 +52,7 @@ const mixxx::Logger kLogger("Library");

} // anonymous namespace

//static
const QString Library::kConfigGroup("[Library]");
using namespace mixxx::library::prefs;

// This is the name which we use to register the WTrackTableView with the
// WLibrary
Expand All @@ -79,7 +78,7 @@ Library::Library(
m_pPlaylistFeature(nullptr),
m_pCrateFeature(nullptr),
m_pAnalysisFeature(nullptr) {
qRegisterMetaType<Library::RemovalType>("Library::RemovalType");
qRegisterMetaType<LibraryRemovalType>("LibraryRemovalType");

m_pKeyNotation.reset(new ControlObject(ConfigKey(kConfigGroup, "key_notation")));

Expand Down Expand Up @@ -249,8 +248,8 @@ Library::Library(
}

m_editMetadataSelectedClick = m_pConfig->getValue(
ConfigKey(kConfigGroup, "EditMetadataSelectedClick"),
PREF_LIBRARY_EDIT_METADATA_DEFAULT);
kEditMetadataSelectedClickConfigKey,
kEditMetadataSelectedClickDefault);
}

Library::~Library() {
Expand Down Expand Up @@ -510,26 +509,26 @@ void Library::slotRequestAddDir(const QString& dir) {
}
// set at least one directory in the config file so that it will be possible
// to downgrade from 1.12
if (m_pConfig->getValueString(PREF_LEGACY_LIBRARY_DIR).length() < 1) {
m_pConfig->set(PREF_LEGACY_LIBRARY_DIR, dir);
if (m_pConfig->getValueString(kLegacyDirectoryConfigKey).length() < 1) {
m_pConfig->set(kLegacyDirectoryConfigKey, dir);
}
}

void Library::slotRequestRemoveDir(const QString& dir, RemovalType removalType) {
void Library::slotRequestRemoveDir(const QString& dir, LibraryRemovalType removalType) {
// Remove the directory from the directory list.
if (!m_pTrackCollectionManager->removeDirectory(mixxx::FileInfo(dir))) {
return;
}

switch (removalType) {
case RemovalType::KeepTracks:
case LibraryRemovalType::KeepTracks:
break;
case RemovalType::HideTracks:
case LibraryRemovalType::HideTracks:
// Mark all tracks in this directory as deleted but DON'T purge them
// in case the user re-adds them manually.
m_pTrackCollectionManager->hideAllTracks(dir);
break;
case RemovalType::PurgeTracks:
case LibraryRemovalType::PurgeTracks:
// The user requested that we purge all metadata.
m_pTrackCollectionManager->purgeAllTracks(dir);
break;
Expand All @@ -539,17 +538,17 @@ void Library::slotRequestRemoveDir(const QString& dir, RemovalType removalType)

// Also update the config file if necessary so that downgrading is still
// possible.
QString confDir = m_pConfig->getValueString(PREF_LEGACY_LIBRARY_DIR);
QString confDir = m_pConfig->getValueString(kLegacyDirectoryConfigKey);

if (QDir(dir) == QDir(confDir)) {
const QList<mixxx::FileInfo> dirList =
m_pTrackCollectionManager->internalCollection()->loadRootDirs();
if (dirList.isEmpty()) {
// Save empty string so that an old version of mixxx knows it has to
// ask for a new directory.
m_pConfig->set(PREF_LEGACY_LIBRARY_DIR, QString());
m_pConfig->set(kLegacyDirectoryConfigKey, QString());
} else {
m_pConfig->set(PREF_LEGACY_LIBRARY_DIR, dirList.first().location());
m_pConfig->set(kLegacyDirectoryConfigKey, dirList.first().location());
}
}
}
Expand All @@ -559,9 +558,9 @@ void Library::slotRequestRelocateDir(const QString& oldDir, const QString& newDi

// also update the config file if necessary so that downgrading is still
// possible
QString conDir = m_pConfig->getValueString(PREF_LEGACY_LIBRARY_DIR);
QString conDir = m_pConfig->getValueString(kLegacyDirectoryConfigKey);
if (oldDir == conDir) {
m_pConfig->set(PREF_LEGACY_LIBRARY_DIR, newDir);
m_pConfig->set(kLegacyDirectoryConfigKey, newDir);
}
}

Expand Down
11 changes: 2 additions & 9 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QPointer>

#include "analyzer/analyzerprogress.h"
#include "library/library_decl.h"
#ifdef __ENGINEPRIME__
#include "library/trackset/crate/crateid.h"
#endif
Expand Down Expand Up @@ -48,8 +49,6 @@ class Library: public QObject {
Q_OBJECT

public:
static const QString kConfigGroup;

Library(QObject* parent,
UserSettingsPointer pConfig,
mixxx::DbConnectionPoolPtr pDbConnectionPool,
Expand Down Expand Up @@ -91,12 +90,6 @@ class Library: public QObject {

//static Library* buildDefaultLibrary();

enum class RemovalType {
KeepTracks,
HideTracks,
PurgeTracks
};

static const int kDefaultRowHeightPx;

void setFont(const QFont& font);
Expand All @@ -121,7 +114,7 @@ class Library: public QObject {
void slotCreatePlaylist();
void slotCreateCrate();
void slotRequestAddDir(const QString& directory);
void slotRequestRemoveDir(const QString& directory, Library::RemovalType removalType);
void slotRequestRemoveDir(const QString& directory, LibraryRemovalType removalType);
void slotRequestRelocateDir(const QString& previousDirectory, const QString& newDirectory);
void onSkinLoadFinished();

Expand Down
9 changes: 9 additions & 0 deletions src/library/library_decl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

class Library;

enum class LibraryRemovalType {
KeepTracks,
HideTracks,
PurgeTracks
};
5 changes: 0 additions & 5 deletions src/library/library_preferences.h

This file was deleted.

29 changes: 29 additions & 0 deletions src/library/library_prefs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "library/library_prefs.h"

// Don't use nested namespaces here to ensure that both the
// definition and declaration of the constants match! Typos
// or missing definitions/declarations will then be detected
// reliably at compile time.

const ConfigKey mixxx::library::prefs::kLegacyDirectoryConfigKey =
ConfigKey(
QStringLiteral("[Playlist]"),
QStringLiteral("Directory"));

const QString mixxx::library::prefs::kConfigGroup =
QStringLiteral("[Library]");

const ConfigKey mixxx::library::prefs::kEditMetadataSelectedClickConfigKey =
ConfigKey(
mixxx::library::prefs::kConfigGroup,
"EditMetadataSelectedClick");

const ConfigKey mixxx::library::prefs::kSearchDebouncingTimeoutMillisConfigKey =
ConfigKey(
mixxx::library::prefs::kConfigGroup,
QStringLiteral("SearchDebouncingTimeoutMillis"));

const ConfigKey mixxx::library::prefs::kSyncTrackMetadataExportConfigKey =
ConfigKey(
mixxx::library::prefs::kConfigGroup,
QStringLiteral("SyncTrackMetadataExport"));
27 changes: 27 additions & 0 deletions src/library/library_prefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "preferences/configobject.h"

namespace mixxx {

namespace library {

namespace prefs {

extern const ConfigKey kLegacyDirectoryConfigKey;

extern const QString kConfigGroup;

extern const ConfigKey kSearchDebouncingTimeoutMillisConfigKey;

extern const ConfigKey kEditMetadataSelectedClickConfigKey;

const bool kEditMetadataSelectedClickDefault = false;

extern const ConfigKey kSyncTrackMetadataExportConfigKey;

} // namespace prefs

} // namespace library

} // namespace mixxx
7 changes: 6 additions & 1 deletion src/library/trackcollectionmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "library/trackcollectionmanager.h"

#include "library/externaltrackcollection.h"
#include "library/library_prefs.h"
#include "library/scanner/libraryscanner.h"
#include "library/trackcollection.h"
#include "moc_trackcollectionmanager.cpp"
Expand Down Expand Up @@ -281,7 +282,11 @@ void TrackCollectionManager::exportTrackMetadata(
// last synchronized. Exporting metadata will update this time
// stamp on the track object!
if (pTrack->isMarkedForMetadataExport() ||
(pTrack->isDirty() && m_pConfig && m_pConfig->getValueString(ConfigKey("[Library]","SyncTrackMetadataExport")).toInt() == 1)) {
(pTrack->isDirty() &&
m_pConfig &&
m_pConfig->getValueString(
mixxx::library::prefs::kSyncTrackMetadataExportConfigKey)
.toInt() == 1)) {
switch (mode) {
case TrackMetadataExportMode::Immediate:
// Export track metadata now by saving as file tags.
Expand Down
15 changes: 7 additions & 8 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "controllers/keyboard/keyboardeventfilter.h"
#include "database/mixxxdb.h"
#include "library/library.h"
#include "library/library_preferences.h"
#include "library/library_prefs.h"
#ifdef __ENGINEPRIME__
#include "library/export/libraryexporter.h"
#endif
Expand Down Expand Up @@ -800,13 +800,12 @@ void MixxxMainWindow::slotFileLoadSongPlayer(int deck) {

UserSettingsPointer pConfig = m_pCoreServices->getSettings();
QString trackPath =
QFileDialog::getOpenFileName(
this,
loadTrackText,
pConfig->getValueString(PREF_LEGACY_LIBRARY_DIR),
QString("Audio (%1)")
.arg(SoundSourceProxy::getSupportedFileNamePatterns().join(" ")));

QFileDialog::getOpenFileName(
this,
loadTrackText,
pConfig->getValueString(mixxx::library::prefs::kLegacyDirectoryConfigKey),
QString("Audio (%1)")
.arg(SoundSourceProxy::getSupportedFileNamePatterns().join(" ")));

if (!trackPath.isNull()) {
// The user has picked a file via a file dialog. This means the system
Expand Down
38 changes: 20 additions & 18 deletions src/preferences/dialog/dlgpreflibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
#include <QUrl>

#include "library/dlgtrackmetadataexport.h"
#include "library/library.h"
#include "library/library_prefs.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "moc_dlgpreflibrary.cpp"
#include "sources/soundsourceproxy.h"
#include "widget/wsearchlineedit.h"

namespace {
const ConfigKey kSearchDebouncingTimeoutMillisKey =
ConfigKey("[Library]", "SearchDebouncingTimeoutMillis");
} // namespace
using namespace mixxx::library::prefs;

DlgPrefLibrary::DlgPrefLibrary(
QWidget* pParent,
Expand Down Expand Up @@ -82,7 +81,7 @@ DlgPrefLibrary::DlgPrefLibrary(
searchDebouncingTimeoutSpinBox->setMaximum(WSearchLineEdit::kMaxDebouncingTimeoutMillis);
const auto searchDebouncingTimeoutMillis =
m_pConfig->getValue(
ConfigKey("[Library]","SearchDebouncingTimeoutMillis"),
kSearchDebouncingTimeoutMillisConfigKey,
WSearchLineEdit::kDefaultDebouncingTimeoutMillis);
searchDebouncingTimeoutSpinBox->setValue(searchDebouncingTimeoutMillis);
connect(searchDebouncingTimeoutSpinBox,
Expand Down Expand Up @@ -120,6 +119,8 @@ DlgPrefLibrary::DlgPrefLibrary(
slotUpdate();
}

DlgPrefLibrary::~DlgPrefLibrary() = default;

void DlgPrefLibrary::slotShow() {
m_bAddedDirectory = false;
}
Expand Down Expand Up @@ -185,7 +186,7 @@ void DlgPrefLibrary::slotResetToDefaults() {
checkBox_show_traktor->setChecked(true);
checkBox_show_rekordbox->setChecked(true);
radioButton_dbclick_bottom->setChecked(false);
checkBoxEditMetadataSelectedClicked->setChecked(PREF_LIBRARY_EDIT_METADATA_DEFAULT);
checkBoxEditMetadataSelectedClicked->setChecked(kEditMetadataSelectedClickDefault);
radioButton_dbclick_top->setChecked(false);
radioButton_dbclick_deck->setChecked(true);
spinBoxRowHeight->setValue(Library::kDefaultRowHeightPx);
Expand All @@ -196,8 +197,8 @@ void DlgPrefLibrary::slotUpdate() {
initializeDirList();
checkBox_library_scan->setChecked(m_pConfig->getValue(
ConfigKey("[Library]","RescanOnStartup"), false));
checkBox_SyncTrackMetadataExport->setChecked(m_pConfig->getValue(
ConfigKey("[Library]","SyncTrackMetadataExport"), false));
checkBox_SyncTrackMetadataExport->setChecked(
m_pConfig->getValue(kSyncTrackMetadataExportConfigKey, false));
checkBox_SeratoMetadataExport->setChecked(m_pConfig->getValue(
ConfigKey("[Library]", "SeratoMetadataExport"), false));
checkBox_use_relative_path->setChecked(m_pConfig->getValue(
Expand Down Expand Up @@ -233,8 +234,8 @@ void DlgPrefLibrary::slotUpdate() {
}

bool editMetadataSelectedClick = m_pConfig->getValue(
ConfigKey("[Library]","EditMetadataSelectedClick"),
PREF_LIBRARY_EDIT_METADATA_DEFAULT);
kEditMetadataSelectedClickConfigKey,
kEditMetadataSelectedClickDefault);
checkBoxEditMetadataSelectedClicked->setChecked(editMetadataSelectedClick);
m_pLibrary->setEditMedatataSelectedClick(editMetadataSelectedClick);

Expand Down Expand Up @@ -301,16 +302,16 @@ void DlgPrefLibrary::slotRemoveDir() {
return;
}

Library::RemovalType removalType;
LibraryRemovalType removalType;
if (removeMsgBox.clickedButton() == hideAllButton) {
removalType = Library::RemovalType::HideTracks;
removalType = LibraryRemovalType::HideTracks;
} else if (removeMsgBox.clickedButton() == deleteAllButton) {
removalType = Library::RemovalType::PurgeTracks;
removalType = LibraryRemovalType::PurgeTracks;
} else {
// Only used in DEBUG_ASSERT
Q_UNUSED(leaveUnchangedButton);
DEBUG_ASSERT(removeMsgBox.clickedButton() == leaveUnchangedButton);
removalType = Library::RemovalType::KeepTracks;
removalType = LibraryRemovalType::KeepTracks;
}

emit requestRemoveDir(fd, removalType);
Expand Down Expand Up @@ -363,8 +364,9 @@ void DlgPrefLibrary::slotSeratoMetadataExportClicked(bool checked) {
void DlgPrefLibrary::slotApply() {
m_pConfig->set(ConfigKey("[Library]","RescanOnStartup"),
ConfigValue((int)checkBox_library_scan->isChecked()));
m_pConfig->set(ConfigKey("[Library]","SyncTrackMetadataExport"),
ConfigValue((int)checkBox_SyncTrackMetadataExport->isChecked()));
m_pConfig->set(
kSyncTrackMetadataExportConfigKey,
ConfigValue{checkBox_SyncTrackMetadataExport->isChecked()});
m_pConfig->set(ConfigKey("[Library]", "SeratoMetadataExport"),
ConfigValue(static_cast<int>(checkBox_SeratoMetadataExport->isChecked())));
m_pConfig->set(ConfigKey("[Library]","UseRelativePathOnExport"),
Expand Down Expand Up @@ -394,7 +396,7 @@ void DlgPrefLibrary::slotApply() {
m_pConfig->set(ConfigKey("[Library]","TrackLoadAction"),
ConfigValue(dbclick_status));

m_pConfig->set(ConfigKey("[Library]", "EditMetadataSelectedClick"),
m_pConfig->set(kEditMetadataSelectedClickConfigKey,
ConfigValue(checkBoxEditMetadataSelectedClicked->checkState()));
m_pLibrary->setEditMedatataSelectedClick(
checkBoxEditMetadataSelectedClicked->checkState());
Expand Down Expand Up @@ -445,7 +447,7 @@ void DlgPrefLibrary::slotSelectFont() {

void DlgPrefLibrary::slotSearchDebouncingTimeoutMillisChanged(int searchDebouncingTimeoutMillis) {
m_pConfig->setValue(
kSearchDebouncingTimeoutMillisKey,
kSearchDebouncingTimeoutMillisConfigKey,
searchDebouncingTimeoutMillis);
WSearchLineEdit::setDebouncingTimeoutMillis(searchDebouncingTimeoutMillis);
}
Expand Down
Loading

0 comments on commit 7bb2f29

Please sign in to comment.