transcoder: Move option error into its own widget

Create a TranscoderOptionsError class and ui that inherits from
TranscoderOptionsInterface. Use this to display options errors. Move
widget creation into a static method. These changes will allow use of
the same mechanism in the transcoder settings page.
This commit is contained in:
Jim Broadus 2021-02-04 10:26:31 -08:00 committed by John Maguire
parent eb7a9bfa4c
commit 8f3772b593
7 changed files with 161 additions and 53 deletions

View File

@ -319,6 +319,7 @@ set(SOURCES
transcoder/transcoder.cpp
transcoder/transcoderoptionsaac.cpp
transcoder/transcoderoptionsdialog.cpp
transcoder/transcoderoptionserror.cpp
transcoder/transcoderoptionsflac.cpp
transcoder/transcoderoptionsmp3.cpp
transcoder/transcoderoptionsopus.cpp
@ -745,6 +746,7 @@ set(UI
transcoder/transcodelogdialog.ui
transcoder/transcoderoptionsaac.ui
transcoder/transcoderoptionsdialog.ui
transcoder/transcoderoptionserror.ui
transcoder/transcoderoptionsflac.ui
transcoder/transcoderoptionsmp3.ui
transcoder/transcoderoptionsopus.ui

View File

@ -21,6 +21,7 @@
#include "core/utilities.h"
#include "transcoder.h"
#include "transcoderoptionsaac.h"
#include "transcoderoptionserror.h"
#include "transcoderoptionsflac.h"
#include "transcoderoptionsmp3.h"
#include "transcoderoptionsopus.h"
@ -34,44 +35,12 @@ TranscoderOptionsDialog::TranscoderOptionsDialog(const TranscoderPreset& preset,
: QDialog(parent), ui_(new Ui_TranscoderOptionsDialog), options_(nullptr) {
ui_->setupUi(this);
QString element =
Transcoder::GetEncoderFactoryForMimeType(preset.codec_mimetype_);
qLog(Debug) << "Options for element" << element;
if (element == "flacenc") {
options_ = new TranscoderOptionsFlac(this);
} else if (element == "faac") {
options_ = new TranscoderOptionsAAC(this);
} else if (element == "lamemp3enc") {
options_ = new TranscoderOptionsMP3(this);
} else if (element == "vorbisenc") {
options_ = new TranscoderOptionsVorbis(this);
} else if (element == "opusenc") {
options_ = new TranscoderOptionsOpus(this);
} else if (element == "speexenc") {
options_ = new TranscoderOptionsSpeex(this);
} else if (element == "ffenc_wmav2") {
options_ = new TranscoderOptionsWma(this);
} else if (element.isEmpty()) {
ui_->errorMessage->setText(tr("Could not find a suitable encoder element "
"for <b>%1</b>.")
.arg(preset.name_));
} else {
QString url = Utilities::MakeBugReportUrl(
QString("transcoder settings: Unknown encoder element: ") + element);
ui_->errorMessage->setText(tr("No settings page available for encoder "
"element <b>%1</b>. "
"Please report this issue:<br>"
"<a href=\"%2\">%2</a>")
.arg(element)
.arg(url));
}
options_ = MakeOptionsPage(preset.codec_mimetype_, this);
setWindowTitle(tr("Transcoding options - %1").arg(preset.name_));
// Show options widget if available.
// Show options widget
if (options_) {
ui_->errorMessage->setVisible(false);
options_->layout()->setContentsMargins(0, 0, 0, 0);
ui_->verticalLayout->insertWidget(0, options_);
resize(width(), minimumHeight());
@ -99,3 +68,27 @@ void TranscoderOptionsDialog::set_settings_postfix(
options_->settings_postfix_ = settings_postfix;
}
}
TranscoderOptionsInterface* TranscoderOptionsDialog::MakeOptionsPage(
const QString& mime_type, QWidget* parent) {
QString element = Transcoder::GetEncoderFactoryForMimeType(mime_type);
qLog(Debug) << "Options for element" << element;
if (element == "flacenc") {
return new TranscoderOptionsFlac(parent);
} else if (element == "faac") {
return new TranscoderOptionsAAC(parent);
} else if (element == "lamemp3enc") {
return new TranscoderOptionsMP3(parent);
} else if (element == "vorbisenc") {
return new TranscoderOptionsVorbis(parent);
} else if (element == "opusenc") {
return new TranscoderOptionsOpus(parent);
} else if (element == "speexenc") {
return new TranscoderOptionsSpeex(parent);
} else if (element == "ffenc_wmav2") {
return new TranscoderOptionsWma(parent);
} else {
return new TranscoderOptionsError(mime_type, element, parent);
}
}

View File

@ -37,6 +37,9 @@ class TranscoderOptionsDialog : public QDialog {
void set_settings_postfix(const QString& settings_postfix);
static TranscoderOptionsInterface* MakeOptionsPage(const QString& mime_type,
QWidget* parent = nullptr);
protected:
void showEvent(QShowEvent* e);

View File

@ -14,25 +14,6 @@
<string>Transcoding options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="errorMessage">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Error</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">

View File

@ -0,0 +1,51 @@
/* This file is part of Clementine.
Copyright 2021, Jim Broadus <jbroadus@gmail.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "transcoderoptionserror.h"
#include "core/utilities.h"
#include "transcoder.h"
#include "ui_transcoderoptionserror.h"
TranscoderOptionsError::TranscoderOptionsError(const QString& mime_type,
const QString& element,
QWidget* parent)
: TranscoderOptionsInterface(parent), ui_(new Ui_TranscoderOptionsError) {
ui_->setupUi(this);
if (mime_type.isEmpty()) {
// No codec for raw formats such as wav.
ui_->info->setText(tr("No settings available for this type."));
} else if (element.isEmpty()) {
// Didn't find a suitable element.
ui_->info->setText(tr("Could not find a suitable encoder element "
"for <b>%1</b>.")
.arg(mime_type));
} else {
// No settings page available for element.
QString url = Utilities::MakeBugReportUrl(
QString("transcoder settings: Unknown encoder element: ") + element);
ui_->info->setText(tr("No settings page available for encoder "
"element <b>%1</b>. "
"Please report this issue:<br>"
"<a href=\"%2\">%2</a>")
.arg(element)
.arg(url));
}
}
TranscoderOptionsError::~TranscoderOptionsError() { delete ui_; }

View File

@ -0,0 +1,38 @@
/* This file is part of Clementine.
Copyright 2021, Jim Broadus <jbroadus@gmail.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSCODEROPTIONSERROR_H
#define TRANSCODEROPTIONSERROR_H
#include "transcoderoptionsinterface.h"
class Ui_TranscoderOptionsError;
class TranscoderOptionsError : public TranscoderOptionsInterface {
public:
TranscoderOptionsError(const QString& mime_type, const QString& element,
QWidget* parent = nullptr);
~TranscoderOptionsError();
void Load(){};
void Save(){};
private:
Ui_TranscoderOptionsError* ui_;
};
#endif // TRANSCODEROPTIONSERROR_H

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TranscoderOptionsError</class>
<widget class="QWidget" name="TranscoderOptionsError">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>102</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="info">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>