RipCDDialog: Added file name preview

This commit is contained in:
Lukas Prediger 2021-08-23 17:18:49 +03:00
parent 77f09e1152
commit bd8881707b
No known key found for this signature in database
GPG Key ID: DF7C5DA2E98A3428
3 changed files with 47 additions and 5 deletions

View File

@ -50,6 +50,7 @@ const int kCheckboxColumn = 0;
const int kTrackNumberColumn = 1; const int kTrackNumberColumn = 1;
const int kTrackTitleColumn = 2; const int kTrackTitleColumn = 2;
const int kTrackDurationColumn = 3; const int kTrackDurationColumn = 3;
const int kTrackFilenamePreviewColumn = 4;
} // namespace } // namespace
const char* RipCDDialog::kSettingsGroup = "Transcoder"; const char* RipCDDialog::kSettingsGroup = "Transcoder";
@ -74,7 +75,11 @@ RipCDDialog::RipCDDialog(DeviceManager* device_manager, QWidget* parent)
ui_->tableWidget->horizontalHeader()->setSectionResizeMode( ui_->tableWidget->horizontalHeader()->setSectionResizeMode(
kTrackNumberColumn, QHeaderView::ResizeToContents); kTrackNumberColumn, QHeaderView::ResizeToContents);
ui_->tableWidget->horizontalHeader()->setSectionResizeMode( ui_->tableWidget->horizontalHeader()->setSectionResizeMode(
kTrackTitleColumn, QHeaderView::Stretch); kTrackDurationColumn, QHeaderView::ResizeToContents);
ui_->tableWidget->horizontalHeader()->setSectionResizeMode(
kTrackTitleColumn, QHeaderView::ResizeToContents);
ui_->tableWidget->horizontalHeader()->setSectionResizeMode(
kTrackFilenamePreviewColumn, QHeaderView::Stretch);
// Add a rip button // Add a rip button
rip_button_ = ui_->button_box->addButton(tr("Start ripping"), rip_button_ = ui_->button_box->addButton(tr("Start ripping"),
@ -104,6 +109,8 @@ RipCDDialog::RipCDDialog(DeviceManager* device_manager, QWidget* parent)
connect(ui_->naming_group, SIGNAL(FormatStringChanged()), connect(ui_->naming_group, SIGNAL(FormatStringChanged()),
SLOT(FormatStringUpdated())); SLOT(FormatStringUpdated()));
connect(ui_->naming_group, SIGNAL(OptionChanged()),
SLOT(FormatStringUpdated()));
setWindowTitle(tr("Rip CD")); setWindowTitle(tr("Rip CD"));
AddDestinationDirectory(QDir::homePath()); AddDestinationDirectory(QDir::homePath());
@ -130,6 +137,9 @@ RipCDDialog::RipCDDialog(DeviceManager* device_manager, QWidget* parent)
break; break;
} }
} }
connect(ui_->format, SIGNAL(currentIndexChanged(int)),
SLOT(UpdateFileNamePreviews));
} }
RipCDDialog::~RipCDDialog() {} RipCDDialog::~RipCDDialog() {}
@ -372,6 +382,7 @@ void RipCDDialog::UpdateTrackListTable() {
connect(line_edit_track_title, &QLineEdit::textChanged, connect(line_edit_track_title, &QLineEdit::textChanged,
[this, current_row](const QString& text) { [this, current_row](const QString& text) {
songs_[current_row].set_title(text); songs_[current_row].set_title(text);
UpdateFileNamePreviews();
}); });
ui_->tableWidget->setCellWidget(current_row, kTrackTitleColumn, ui_->tableWidget->setCellWidget(current_row, kTrackTitleColumn,
line_edit_track_title); line_edit_track_title);
@ -379,6 +390,25 @@ void RipCDDialog::UpdateTrackListTable() {
new QLabel(song.PrettyLength())); new QLabel(song.PrettyLength()));
current_row++; current_row++;
} }
UpdateFileNamePreviews();
}
void RipCDDialog::UpdateFileNamePreviews() {
OrganiseFormat format = ui_->naming_group->format();
TranscoderPreset preset = ui_->format->itemData(ui_->format->currentIndex())
.value<TranscoderPreset>();
int current_row = 0;
for (const Song& song : songs_) {
if (format.IsValid())
ui_->tableWidget->setCellWidget(
current_row, kTrackFilenamePreviewColumn,
new QLabel(format.GetFilenameForSong(song, preset)));
else
ui_->tableWidget->setCellWidget(current_row, kTrackFilenamePreviewColumn,
new QLabel(tr("Invalid format")));
current_row++;
}
} }
void RipCDDialog::AddAlbumMetadataFromMusicBrainz(const SongList& songs) { void RipCDDialog::AddAlbumMetadataFromMusicBrainz(const SongList& songs) {
@ -412,7 +442,10 @@ void RipCDDialog::ResetDialog() {
ui_->discLineEdit->clear(); ui_->discLineEdit->clear();
} }
void RipCDDialog::FormatStringUpdated() { EnableIfPossible(); } void RipCDDialog::FormatStringUpdated() {
UpdateFileNamePreviews();
EnableIfPossible();
}
void RipCDDialog::EnableIfPossible() { void RipCDDialog::EnableIfPossible() {
rip_button_->setEnabled(!songs_.isEmpty() && rip_button_->setEnabled(!songs_.isEmpty() &&

View File

@ -65,6 +65,7 @@ class RipCDDialog : public QDialog {
void AddAlbumMetadataFromMusicBrainz(const SongList& songs); void AddAlbumMetadataFromMusicBrainz(const SongList& songs);
void DiscChanged(); void DiscChanged();
void FormatStringUpdated(); void FormatStringUpdated();
void UpdateFileNamePreviews();
private: private:
static const char* kSettingsGroup; static const char* kSettingsGroup;

View File

@ -9,7 +9,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>522</width> <width>600</width>
<height>800</height> <height>800</height>
</rect> </rect>
</property> </property>
@ -119,13 +119,16 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="columnCount"> <property name="columnCount">
<number>4</number> <number>5</number>
</property> </property>
<attribute name="horizontalHeaderVisible"> <attribute name="horizontalHeaderVisible">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<attribute name="horizontalHeaderMinimumSectionSize"> <attribute name="horizontalHeaderMinimumSectionSize">
<number>10</number> <number>4</number>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>20</number>
</attribute> </attribute>
<attribute name="verticalHeaderVisible"> <attribute name="verticalHeaderVisible">
<bool>false</bool> <bool>false</bool>
@ -153,6 +156,11 @@
<string>Duration</string> <string>Duration</string>
</property> </property>
</column> </column>
<column>
<property name="text">
<string>Filename Preview</string>
</property>
</column>
</widget> </widget>
</item> </item>
</layout> </layout>