1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-18 20:40:43 +01:00

Adjust the ui and clean up code.

The selection of a destination folder is now done by pressing the button 'Select...'.
The last selected folders along with the option 'Alongside the originals' are
available in the box 'destination'.

The methods TranscodeDialog::TrimPath and TranscodeDialog::GetOutputFileName are now
const.

Minor formatting fixes.
This commit is contained in:
Mattias Andersson 2014-01-11 18:59:54 +01:00
parent 294023cf2d
commit 9647636ab7
3 changed files with 69 additions and 50 deletions

View File

@ -36,6 +36,7 @@
const char* TranscodeDialog::kSettingsGroup = "Transcoder";
const int TranscodeDialog::kProgressInterval = 500;
const int TranscodeDialog::kMaxDestinationItems = 10;
static bool ComparePresetsByName(const TranscoderPreset& left,
const TranscoderPreset& right) {
@ -96,12 +97,6 @@ TranscodeDialog::TranscodeDialog(QWidget *parent)
cancel_button_->hide();
ui_->progress_group->hide();
// Add a destination.
QIcon icon = IconLoader::Load("folder");
QVariant data = QVariant::fromValue(QDir::homePath());
QString text = TrimPath(data.toString());
ui_->destination->addItem(icon, text, data);
// Connect stuff
connect(ui_->add, SIGNAL(clicked()), SLOT(Add()));
connect(ui_->remove, SIGNAL(clicked()), SLOT(Remove()));
@ -110,8 +105,8 @@ TranscodeDialog::TranscodeDialog(QWidget *parent)
connect(close_button_, SIGNAL(clicked()), SLOT(hide()));
connect(ui_->details, SIGNAL(clicked()), log_dialog_, SLOT(show()));
connect(ui_->options, SIGNAL(clicked()), SLOT(Options()));
connect(ui_->destination, SIGNAL(activated(int)),
SLOT(SetDestination(int)));
connect(ui_->select, SIGNAL(clicked()), SLOT(AddDestination()));
connect(transcoder_, SIGNAL(JobComplete(QString,bool)), SLOT(JobComplete(QString,bool)));
connect(transcoder_, SIGNAL(LogLine(QString)), SLOT(LogLine(QString)));
@ -147,7 +142,7 @@ void TranscodeDialog::Start() {
// Add jobs to the transcoder
for (int i=0 ; i<file_model->rowCount() ; ++i) {
QString filename = file_model->index(i, 0).data(Qt::UserRole).toString();
QString outfilename = SetOutputFileName(filename, preset);
QString outfilename = GetOutputFileName(filename, preset);
transcoder_->AddJob(filename, preset, outfilename);
}
@ -276,35 +271,47 @@ void TranscodeDialog::Options() {
}
}
void TranscodeDialog::SetDestination(int index) {
if (!ui_->destination->itemData(index).isNull()) {
QString dir = QFileDialog::getExistingDirectory(
this, tr("Choose folder"),
ui_->destination->itemData(index).toString());
// Do not update the QComboBox if the user canceled the dialog.
if (!dir.isEmpty()) {
QVariant data = QVariant::fromValue(dir);
QString text = TrimPath(dir);
ui_->destination->setItemText(index, text);
ui_->destination->setItemData(index, data);
// Adds a folder to the destination box.
void TranscodeDialog::AddDestination() {
int index = ui_->destination->currentIndex();
QString initial_dir = (!ui_->destination->itemData(index).isNull() ?
ui_->destination->itemData(index).toString() :
QDir::homePath());
QString dir = QFileDialog::getExistingDirectory(
this, tr("Add folder"), initial_dir);
if (!dir.isEmpty()) {
// Keep only a finite number of items in the box.
while (ui_->destination->count() >= kMaxDestinationItems) {
ui_->destination->removeItem(1); // The oldest folder item.
}
QIcon icon = IconLoader::Load("folder");
QVariant data = QVariant::fromValue(dir);
// Do not insert duplicates.
int duplicate_index = ui_->destination->findData(data);
if (duplicate_index == -1) {
ui_->destination->addItem(icon, dir, data);
ui_->destination->setCurrentIndex(ui_->destination->count() - 1);
} else {
ui_->destination->setCurrentIndex(duplicate_index);
}
}
}
// Returns the rightmost non-empty part of 'path'.
QString TranscodeDialog::TrimPath(const QString& path) {
QString TranscodeDialog::TrimPath(const QString& path) const {
return path.section('/', -1, -1, QString::SectionSkipEmpty);
}
QString TranscodeDialog::SetOutputFileName(const QString& input,
const TranscoderPreset &preset) {
QString TranscodeDialog::GetOutputFileName(const QString& input,
const TranscoderPreset &preset) const {
QString path = ui_->destination->itemData(
ui_->destination->currentIndex()).toString();
if (path.isEmpty()) {
// Keep the original path.
return input.section('.', 0, -2) + '.' + preset.extension_;
}
else {
} else {
QString file_name = TrimPath(input);
file_name = file_name.section('.', 0, -2);
return path + '/' + file_name + '.' + preset.extension_;

View File

@ -36,6 +36,7 @@ class TranscodeDialog : public QDialog {
static const char* kSettingsGroup;
static const int kProgressInterval;
static const int kMaxDestinationItems;
void SetFilenames(const QStringList& filenames);
@ -51,15 +52,15 @@ class TranscodeDialog : public QDialog {
void LogLine(const QString& message);
void AllJobsComplete();
void Options();
void SetDestination(int index);
void AddDestination();
private:
void SetWorking(bool working);
void UpdateStatusText();
void UpdateProgress();
QString TrimPath(const QString& path);
QString SetOutputFileName(const QString& input,
const TranscoderPreset& preset);
QString TrimPath(const QString& path) const;
QString GetOutputFileName(const QString& input,
const TranscoderPreset& preset) const;
private:
Ui_TranscodeDialog* ui_;

View File

@ -98,7 +98,7 @@
<property name="title">
<string>Output options</string>
</property>
<layout class="QFormLayout" name="formLayout">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -107,25 +107,21 @@
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="format">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="options">
<property name="text">
<string>Options...</string>
</property>
</widget>
</item>
</layout>
<widget class="QComboBox" name="format">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="options">
<property name="text">
<string>Options...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
@ -136,6 +132,15 @@
</item>
<item row="1" column="1">
<widget class="QComboBox" name="destination">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Alongside the originals</string>
@ -143,6 +148,13 @@
</item>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="select">
<property name="text">
<string>Select...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -196,7 +208,6 @@
<tabstop>add</tabstop>
<tabstop>remove</tabstop>
<tabstop>format</tabstop>
<tabstop>destination</tabstop>
<tabstop>button_box</tabstop>
</tabstops>
<resources/>