Skip to content

Commit 33a4e39

Browse files
committed
Style fixes and formatting cleanup in DlgPrefLibrary
1 parent bb93d12 commit 33a4e39

1 file changed

Lines changed: 111 additions & 46 deletions

File tree

src/preferences/dialog/dlgpreflibrary.cpp

Lines changed: 111 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,27 @@ DlgPrefLibrary::DlgPrefLibrary(
111111

112112
updateSearchLineEditHistoryOptions();
113113

114+
comboBox_dateFormat->addItem(tr("Native (System Default)"),
115+
QVariant::fromValue(BaseTrackTableModel::DateFormat::Native));
116+
comboBox_dateFormat->addItem(tr("ISO 8601 (yyyy-MM-dd)"),
117+
QVariant::fromValue(BaseTrackTableModel::DateFormat::ISO8601));
118+
comboBox_dateFormat->addItem(tr("Regional Short (d/M/yy)"),
119+
QVariant::fromValue(BaseTrackTableModel::DateFormat::RegionalShort));
120+
comboBox_dateFormat->addItem(tr("Regional Long (dd.MM.yyyy)"),
121+
QVariant::fromValue(BaseTrackTableModel::DateFormat::RegionalLong));
122+
comboBox_dateFormat->addItem(tr("Custom"),
123+
QVariant::fromValue(BaseTrackTableModel::DateFormat::Custom));
124+
125+
connect(comboBox_dateFormat,
126+
&QComboBox::currentIndexChanged,
127+
this,
128+
&DlgPrefLibrary::slotDateFormatIndexChanged);
129+
130+
connect(comboBox_dateFormat,
131+
&QComboBox::editTextChanged,
132+
this,
133+
&DlgPrefLibrary::slotDateFormatChanged);
134+
114135
connect(btn_library_font, &QAbstractButton::clicked, this, &DlgPrefLibrary::slotSelectFont);
115136

116137
// TODO(XXX) this string should be extracted from the soundsources
@@ -231,7 +252,7 @@ void DlgPrefLibrary::populateDirList() {
231252
dirList->setModel(&m_dirListModel);
232253
dirList->setCurrentIndex(m_dirListModel.index(0, 0));
233254
// reselect index if it still exists
234-
for (int i=0 ; i<m_dirListModel.rowCount() ; ++i) {
255+
for (int i = 0; i < m_dirListModel.rowCount(); ++i) {
235256
const QModelIndex index = m_dirListModel.index(i, 0);
236257
if (index.data().toString() == selected) {
237258
dirList->setCurrentIndex(index);
@@ -267,6 +288,16 @@ void DlgPrefLibrary::slotResetToDefaults() {
267288
comboBox_search_bpm_fuzzy_range->setCurrentIndex(
268289
comboBox_search_bpm_fuzzy_range->findData(kDefaultFuzzyRateRangePercent));
269290

291+
int dateIndex = comboBox_dateFormat->findData(
292+
QVariant::fromValue(BaseTrackTableModel::DateFormat::Native));
293+
if (dateIndex != -1) {
294+
comboBox_dateFormat->setCurrentIndex(dateIndex);
295+
} else {
296+
// Fallback or custom default? Default is usually Native (empty string)
297+
// which should be found.
298+
comboBox_dateFormat->setCurrentIndex(0);
299+
}
300+
270301
checkBox_show_rhythmbox->setChecked(true);
271302
checkBox_show_banshee->setChecked(true);
272303
checkBox_show_itunes->setChecked(true);
@@ -297,18 +328,50 @@ void DlgPrefLibrary::slotUpdate() {
297328
kUseRelativePathOnExportConfigKey, false));
298329

299330
checkBox_show_rhythmbox->setChecked(m_pConfig->getValue(
300-
ConfigKey("[Library]","ShowRhythmboxLibrary"), true));
331+
ConfigKey("[Library]", "ShowRhythmboxLibrary"), true));
301332
checkBox_show_banshee->setChecked(m_pConfig->getValue(
302-
ConfigKey("[Library]","ShowBansheeLibrary"), true));
333+
ConfigKey("[Library]", "ShowBansheeLibrary"), true));
303334
checkBox_show_itunes->setChecked(m_pConfig->getValue(
304-
ConfigKey("[Library]","ShowITunesLibrary"), true));
335+
ConfigKey("[Library]", "ShowITunesLibrary"), true));
305336
checkBox_show_traktor->setChecked(m_pConfig->getValue(
306-
ConfigKey("[Library]","ShowTraktorLibrary"), true));
337+
ConfigKey("[Library]", "ShowTraktorLibrary"), true));
307338
checkBox_show_rekordbox->setChecked(m_pConfig->getValue(
308-
ConfigKey("[Library]","ShowRekordboxLibrary"), true));
339+
ConfigKey("[Library]", "ShowRekordboxLibrary"), true));
309340
checkBox_show_serato->setChecked(m_pConfig->getValue(
310341
ConfigKey("[Library]", "ShowSeratoLibrary"), true));
311342

343+
QString dateFormat = m_pConfig->getValue(
344+
kDateFormatConfigKey,
345+
BaseTrackTableModel::kDateFormatDefault);
346+
347+
// Determine the matching preset or custom
348+
BaseTrackTableModel::DateFormat preset = BaseTrackTableModel::DateFormat::Custom;
349+
if (dateFormat.isEmpty()) {
350+
preset = BaseTrackTableModel::DateFormat::Native;
351+
} else if (dateFormat == QStringLiteral("yyyy-MM-dd")) {
352+
preset = BaseTrackTableModel::DateFormat::ISO8601;
353+
} else if (dateFormat == QStringLiteral("d/M/yy")) {
354+
preset = BaseTrackTableModel::DateFormat::RegionalShort;
355+
} else if (dateFormat == QStringLiteral("dd.MM.yyyy")) {
356+
preset = BaseTrackTableModel::DateFormat::RegionalLong;
357+
}
358+
359+
int dateIndex = comboBox_dateFormat->findData(QVariant::fromValue(preset));
360+
if (dateIndex != -1) {
361+
comboBox_dateFormat->setCurrentIndex(dateIndex);
362+
}
363+
364+
if (preset == BaseTrackTableModel::DateFormat::Custom) {
365+
comboBox_dateFormat->setEditable(true);
366+
comboBox_dateFormat->setEditText(dateFormat);
367+
m_lastCustomDateFormat = dateFormat;
368+
} else {
369+
comboBox_dateFormat->setEditable(false);
370+
}
371+
372+
// Ensure the static member is updated on startup/load
373+
BaseTrackTableModel::setDateFormat(dateFormat);
374+
312375
switch (m_pConfig->getValue<int>(
313376
kTrackDoubleClickActionConfigKey,
314377
static_cast<int>(TrackDoubleClickAction::LoadToDeck))) {
@@ -372,12 +435,12 @@ void DlgPrefLibrary::slotUpdate() {
372435
m_pConfig->getValue(
373436
kSearchBpmFuzzyRangeConfigKey,
374437
BpmFilterNode::kRelativeRangeDefault);
375-
int index = comboBox_search_bpm_fuzzy_range->findData(static_cast<int>(searchBpmFuzzyRange));
376-
if (index == -1) {
377-
index = comboBox_search_bpm_fuzzy_range->findData(kDefaultFuzzyRateRangePercent);
438+
int bpmIndex = comboBox_search_bpm_fuzzy_range->findData(static_cast<int>(searchBpmFuzzyRange));
439+
if (bpmIndex == -1) {
440+
bpmIndex = comboBox_search_bpm_fuzzy_range->findData(kDefaultFuzzyRateRangePercent);
378441
}
379-
comboBox_search_bpm_fuzzy_range->setCurrentIndex(index);
380-
slotBpmRangeSelected(index);
442+
comboBox_search_bpm_fuzzy_range->setCurrentIndex(bpmIndex);
443+
slotBpmRangeSelected(bpmIndex);
381444

382445
const auto bpmColumnPrecision =
383446
m_pConfig->getValue(
@@ -403,9 +466,9 @@ void DlgPrefLibrary::resetLibraryFont() {
403466
}
404467

405468
void DlgPrefLibrary::slotAddDir() {
406-
QString fd = QFileDialog::getExistingDirectory(
407-
this, tr("Choose a music directory"),
408-
QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
469+
QString fd = QFileDialog::getExistingDirectory(this,
470+
tr("Choose a music directory"),
471+
QStandardPaths::writableLocation(QStandardPaths::MusicLocation));
409472
if (!fd.isEmpty()) {
410473
if (m_pLibrary->requestAddDir(fd)) {
411474
populateDirList();
@@ -423,29 +486,29 @@ void DlgPrefLibrary::slotRemoveDir() {
423486
removeMsgBox.setWindowTitle(tr("Confirm Directory Removal"));
424487

425488
removeMsgBox.setText(tr(
426-
"Mixxx will no longer watch this directory for new tracks. "
427-
"What would you like to do with the tracks from this directory and "
428-
"subdirectories?"
429-
"<ul>"
430-
"<li>Hide all tracks from this directory and subdirectories.</li>"
431-
"<li>Delete all metadata for these tracks from Mixxx permanently.</li>"
432-
"<li>Leave the tracks unchanged in your library.</li>"
433-
"</ul>"
434-
"Hiding tracks saves their metadata in case you re-add them in the "
435-
"future."));
489+
"Mixxx will no longer watch this directory for new tracks. "
490+
"What would you like to do with the tracks from this directory and "
491+
"subdirectories?"
492+
"<ul>"
493+
"<li>Hide all tracks from this directory and subdirectories.</li>"
494+
"<li>Delete all metadata for these tracks from Mixxx permanently.</li>"
495+
"<li>Leave the tracks unchanged in your library.</li>"
496+
"</ul>"
497+
"Hiding tracks saves their metadata in case you re-add them in the "
498+
"future."));
436499
removeMsgBox.setInformativeText(tr(
437-
"Metadata means all track details (artist, title, playcount, etc.) as "
438-
"well as beatgrids, hotcues, and loops. This choice only affects the "
439-
"Mixxx library. No files on disk will be changed or deleted."));
500+
"Metadata means all track details (artist, title, playcount, etc.) as "
501+
"well as beatgrids, hotcues, and loops. This choice only affects the "
502+
"Mixxx library. No files on disk will be changed or deleted."));
440503

441504
QPushButton* cancelButton =
442505
removeMsgBox.addButton(QMessageBox::Cancel);
443506
QPushButton* hideAllButton = removeMsgBox.addButton(
444-
tr("Hide Tracks"), QMessageBox::AcceptRole);
507+
tr("Hide Tracks"), QMessageBox::AcceptRole);
445508
QPushButton* deleteAllButton = removeMsgBox.addButton(
446-
tr("Delete Track Metadata"), QMessageBox::AcceptRole);
509+
tr("Delete Track Metadata"), QMessageBox::AcceptRole);
447510
QPushButton* leaveUnchangedButton = removeMsgBox.addButton(
448-
tr("Leave Tracks Unchanged"), QMessageBox::AcceptRole);
511+
tr("Leave Tracks Unchanged"), QMessageBox::AcceptRole);
449512
Q_UNUSED(leaveUnchangedButton); // Only used in DEBUG_ASSERT
450513
removeMsgBox.setDefaultButton(cancelButton);
451514
removeMsgBox.exec();
@@ -487,7 +550,7 @@ void DlgPrefLibrary::slotRelocateDir() {
487550
}
488551

489552
QString fd = QFileDialog::getExistingDirectory(
490-
this, tr("Relink music directory to new location"), startDir);
553+
this, tr("Relink music directory to new location"), startDir);
491554

492555
if (!fd.isEmpty() && m_pLibrary->requestRelocateDir(currentFd, fd)) {
493556
populateDirList();
@@ -541,16 +604,16 @@ void DlgPrefLibrary::slotApply() {
541604
ConfigValue(checkBox_enable_search_history_shortcuts->isChecked()));
542605
updateSearchLineEditHistoryOptions();
543606

544-
m_pConfig->set(ConfigKey("[Library]","ShowRhythmboxLibrary"),
545-
ConfigValue((int)checkBox_show_rhythmbox->isChecked()));
546-
m_pConfig->set(ConfigKey("[Library]","ShowBansheeLibrary"),
547-
ConfigValue((int)checkBox_show_banshee->isChecked()));
548-
m_pConfig->set(ConfigKey("[Library]","ShowITunesLibrary"),
549-
ConfigValue((int)checkBox_show_itunes->isChecked()));
550-
m_pConfig->set(ConfigKey("[Library]","ShowTraktorLibrary"),
551-
ConfigValue((int)checkBox_show_traktor->isChecked()));
552-
m_pConfig->set(ConfigKey("[Library]","ShowRekordboxLibrary"),
553-
ConfigValue((int)checkBox_show_rekordbox->isChecked()));
607+
m_pConfig->set(ConfigKey("[Library]", "ShowRhythmboxLibrary"),
608+
ConfigValue((int)checkBox_show_rhythmbox->isChecked()));
609+
m_pConfig->set(ConfigKey("[Library]", "ShowBansheeLibrary"),
610+
ConfigValue((int)checkBox_show_banshee->isChecked()));
611+
m_pConfig->set(ConfigKey("[Library]", "ShowITunesLibrary"),
612+
ConfigValue((int)checkBox_show_itunes->isChecked()));
613+
m_pConfig->set(ConfigKey("[Library]", "ShowTraktorLibrary"),
614+
ConfigValue((int)checkBox_show_traktor->isChecked()));
615+
m_pConfig->set(ConfigKey("[Library]", "ShowRekordboxLibrary"),
616+
ConfigValue((int)checkBox_show_rekordbox->isChecked()));
554617
m_pConfig->set(ConfigKey("[Library]", "ShowSeratoLibrary"),
555618
ConfigValue((int)checkBox_show_serato->isChecked()));
556619

@@ -587,14 +650,14 @@ void DlgPrefLibrary::slotApply() {
587650
QFont font = m_pLibrary->getTrackTableFont();
588651
if (m_originalTrackTableFont != font) {
589652
m_pConfig->set(ConfigKey("[Library]", "Font"),
590-
ConfigValue(font.toString()));
653+
ConfigValue(font.toString()));
591654
m_originalTrackTableFont = font;
592655
}
593656

594657
int rowHeight = spinBox_row_height->value();
595658
if (m_iOriginalTrackTableRowHeight != rowHeight) {
596-
m_pConfig->set(ConfigKey("[Library]","RowHeight"),
597-
ConfigValue(rowHeight));
659+
m_pConfig->set(ConfigKey("[Library]", "RowHeight"),
660+
ConfigValue(rowHeight));
598661
m_iOriginalTrackTableRowHeight = rowHeight;
599662
}
600663

@@ -660,8 +723,10 @@ void DlgPrefLibrary::setLibraryFont(const QFont& font) {
660723
void DlgPrefLibrary::slotSelectFont() {
661724
// False if the user cancels font selection.
662725
bool ok = false;
663-
QFont font = QFontDialog::getFont(&ok, m_pLibrary->getTrackTableFont(),
664-
this, tr("Select Library Font"));
726+
QFont font = QFontDialog::getFont(&ok,
727+
m_pLibrary->getTrackTableFont(),
728+
this,
729+
tr("Select Library Font"));
665730
if (ok) {
666731
setLibraryFont(font);
667732
}

0 commit comments

Comments
 (0)