1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 11:35:24 +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 char* TranscodeDialog::kSettingsGroup = "Transcoder";
const int TranscodeDialog::kProgressInterval = 500; const int TranscodeDialog::kProgressInterval = 500;
const int TranscodeDialog::kMaxDestinationItems = 10;
static bool ComparePresetsByName(const TranscoderPreset& left, static bool ComparePresetsByName(const TranscoderPreset& left,
const TranscoderPreset& right) { const TranscoderPreset& right) {
@ -96,12 +97,6 @@ TranscodeDialog::TranscodeDialog(QWidget *parent)
cancel_button_->hide(); cancel_button_->hide();
ui_->progress_group->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 stuff
connect(ui_->add, SIGNAL(clicked()), SLOT(Add())); connect(ui_->add, SIGNAL(clicked()), SLOT(Add()));
connect(ui_->remove, SIGNAL(clicked()), SLOT(Remove())); connect(ui_->remove, SIGNAL(clicked()), SLOT(Remove()));
@ -110,8 +105,8 @@ TranscodeDialog::TranscodeDialog(QWidget *parent)
connect(close_button_, SIGNAL(clicked()), SLOT(hide())); connect(close_button_, SIGNAL(clicked()), SLOT(hide()));
connect(ui_->details, SIGNAL(clicked()), log_dialog_, SLOT(show())); connect(ui_->details, SIGNAL(clicked()), log_dialog_, SLOT(show()));
connect(ui_->options, SIGNAL(clicked()), SLOT(Options())); connect(ui_->options, SIGNAL(clicked()), SLOT(Options()));
connect(ui_->destination, SIGNAL(activated(int)), connect(ui_->select, SIGNAL(clicked()), SLOT(AddDestination()));
SLOT(SetDestination(int)));
connect(transcoder_, SIGNAL(JobComplete(QString,bool)), SLOT(JobComplete(QString,bool))); connect(transcoder_, SIGNAL(JobComplete(QString,bool)), SLOT(JobComplete(QString,bool)));
connect(transcoder_, SIGNAL(LogLine(QString)), SLOT(LogLine(QString))); connect(transcoder_, SIGNAL(LogLine(QString)), SLOT(LogLine(QString)));
@ -147,7 +142,7 @@ void TranscodeDialog::Start() {
// Add jobs to the transcoder // Add jobs to the transcoder
for (int i=0 ; i<file_model->rowCount() ; ++i) { for (int i=0 ; i<file_model->rowCount() ; ++i) {
QString filename = file_model->index(i, 0).data(Qt::UserRole).toString(); 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); transcoder_->AddJob(filename, preset, outfilename);
} }
@ -276,35 +271,47 @@ void TranscodeDialog::Options() {
} }
} }
void TranscodeDialog::SetDestination(int index) { // Adds a folder to the destination box.
if (!ui_->destination->itemData(index).isNull()) { void TranscodeDialog::AddDestination() {
QString dir = QFileDialog::getExistingDirectory( int index = ui_->destination->currentIndex();
this, tr("Choose folder"), QString initial_dir = (!ui_->destination->itemData(index).isNull() ?
ui_->destination->itemData(index).toString()); ui_->destination->itemData(index).toString() :
// Do not update the QComboBox if the user canceled the dialog. QDir::homePath());
if (!dir.isEmpty()) { QString dir = QFileDialog::getExistingDirectory(
QVariant data = QVariant::fromValue(dir); this, tr("Add folder"), initial_dir);
QString text = TrimPath(dir);
ui_->destination->setItemText(index, text); if (!dir.isEmpty()) {
ui_->destination->setItemData(index, data); // 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'. // 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); return path.section('/', -1, -1, QString::SectionSkipEmpty);
} }
QString TranscodeDialog::SetOutputFileName(const QString& input, QString TranscodeDialog::GetOutputFileName(const QString& input,
const TranscoderPreset &preset) { const TranscoderPreset &preset) const {
QString path = ui_->destination->itemData( QString path = ui_->destination->itemData(
ui_->destination->currentIndex()).toString(); ui_->destination->currentIndex()).toString();
if (path.isEmpty()) { if (path.isEmpty()) {
// Keep the original path. // Keep the original path.
return input.section('.', 0, -2) + '.' + preset.extension_; return input.section('.', 0, -2) + '.' + preset.extension_;
} } else {
else {
QString file_name = TrimPath(input); QString file_name = TrimPath(input);
file_name = file_name.section('.', 0, -2); file_name = file_name.section('.', 0, -2);
return path + '/' + file_name + '.' + preset.extension_; return path + '/' + file_name + '.' + preset.extension_;

View File

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

View File

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