///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
-// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
///////////////////////////////////////////////////////////////////////////////
#include "win_addJob.h"
-#include "uic_win_addJob.h"
+#include "UIC_win_addJob.h"
+//Internal
#include "global.h"
#include "model_options.h"
#include "model_preferences.h"
#include "model_sysinfo.h"
#include "model_recently.h"
-#include "encoder_x264.h"
-#include "encoder_x265.h"
+#include "encoder_factory.h"
+#include "mediainfo.h"
+#include "string_validator.h"
#include "win_help.h"
#include "win_editor.h"
+//MUtils
+#include <MUtils/Global.h>
+#include <MUtils/OSSupport.h>
+#include <MUtils/Exception.h>
+
+//Qt
#include <QDate>
#include <QTimer>
#include <QCloseEvent>
#include <QClipboard>
#include <QToolTip>
+#include <memory>
+
#define ARRAY_SIZE(ARRAY) (sizeof((ARRAY))/sizeof((ARRAY[0])))
#define VALID_DIR(PATH) ((!(PATH).isEmpty()) && QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
+#define SHFL(X) ((*reinterpret_cast<int*>(&(X))) <<= 1)
#define REMOVE_USAFED_ITEM \
{ \
WIDGET->addAction(_action); \
}
-#define BLOCK_SIGNALS(FLAG) do \
-{ \
- ui->cbxEncoderType->blockSignals(FLAG); \
- ui->cbxEncoderArch->blockSignals(FLAG); \
- ui->cbxEncoderVariant->blockSignals(FLAG); \
- ui->cbxRateControlMode->blockSignals(FLAG); \
- ui->spinQuantizer->blockSignals(FLAG); \
- ui->spinBitrate->blockSignals(FLAG); \
- ui->cbxPreset->blockSignals(FLAG); \
- ui->cbxTuning->blockSignals(FLAG); \
- ui->cbxProfile->blockSignals(FLAG); \
- ui->editCustomX264Params->blockSignals(FLAG); \
- ui->editCustomAvs2YUVParams->blockSignals(FLAG); \
-} \
-while(0)
-
Q_DECLARE_METATYPE(const void*)
///////////////////////////////////////////////////////////////////////////////
-// Validator
+// Disable Monitoring RAII
///////////////////////////////////////////////////////////////////////////////
-class StringValidator : public QValidator
+class DisableHelperRAII
{
public:
- StringValidator(QLabel *notifier, QLabel *icon)
- :
- m_notifier(notifier), m_icon(icon)
- {
- m_notifier->hide();
- m_icon->hide();
- }
-
- virtual State validate(QString &input, int &pos) const = 0;
-
- virtual void fixup(QString &input) const
- {
- input = input.simplified();
- }
-
-protected:
- QLabel *const m_notifier, *const m_icon;
-
- bool checkParam(const QString &input, const QString ¶m, const bool doubleMinus) const
- {
- static const char c[20] = {' ', '*', '?', '<', '>', '/', '\\', '"', '\'', '!', '+', '#', '&', '%', '=', ',', ';', '.', 'ยด', '`'};
- const QString prefix = doubleMinus ? QLatin1String("--") : QLatin1String("-");
-
- bool flag = false;
- if(param.length() > 1)
- {
- flag = flag || input.endsWith(QString("%1%2").arg(prefix, param), Qt::CaseInsensitive);
- for(size_t i = 0; i < sizeof(c); i++)
- {
- flag = flag || input.contains(QString("%1%2%3").arg(prefix, param, QChar::fromLatin1(c[i])), Qt::CaseInsensitive);
- }
- }
- else
- {
- flag = flag || input.startsWith(QString("-%1").arg(param));
- for(size_t i = 0; i < sizeof(c); i++)
- {
- flag = flag || input.contains(QString("%1-%2").arg(QChar::fromLatin1(c[i]), param), Qt::CaseSensitive);
- }
- }
- if((flag) && (m_notifier))
- {
- m_notifier->setText(tr("Invalid parameter: %1").arg((param.length() > 1) ? QString("%1%2").arg(prefix, param) : QString("-%1").arg(param)));
- }
- return flag;
- }
-
- const bool &setStatus(const bool &flag, const QString &toolName) const
+ DisableHelperRAII(bool *const flag) : m_flag(flag)
{
- if(flag)
- {
- if(m_notifier)
- {
- if(m_notifier->isHidden()) m_notifier->show();
- if(m_icon) { if(m_icon->isHidden()) m_icon->show(); }
- if(QWidget *w = m_notifier->topLevelWidget()->focusWidget())
- {
- QToolTip::showText(static_cast<QWidget*>(w->parent())->mapToGlobal(w->pos()), QString("<nobr>%1</nobr>").arg(tr("<b>Warning:</b> You entered a parameter that is incomaptible with using %1 from a GUI.<br>Please note that the GUI will automatically set <i>this</i> parameter for you (if required).").arg(toolName)), m_notifier, QRect());
- }
- }
- }
- else
- {
- if(m_notifier)
- {
- if(m_notifier->isVisible()) m_notifier->hide();
- if(m_icon) { if(m_icon->isVisible()) m_icon->hide(); }
- QToolTip::hideText();
- }
- }
- return flag;
+ *m_flag = false;
}
-};
-
-class StringValidatorX264 : public StringValidator
-{
-public:
- StringValidatorX264(QLabel *notifier, QLabel *icon) : StringValidator(notifier, icon) {}
- virtual State validate(QString &input, int &pos) const
+ ~DisableHelperRAII(void)
{
- static const char* p[] = {"B", "o", "h", "p", "q", /*"fps", "frames",*/ "preset", "tune", "profile",
- "stdin", "crf", "bitrate", "qp", "pass", "stats", "output", "help","quiet", NULL};
-
- bool invalid = false;
-
- for(size_t i = 0; p[i] && (!invalid); i++)
- {
- invalid = invalid || checkParam(input, QString::fromLatin1(p[i]), true);
- }
-
- return setStatus(invalid, "x264") ? QValidator::Intermediate : QValidator::Acceptable;
+ *m_flag = true;
}
-};
-class StringValidatorAvs2YUV : public StringValidator
-{
-public:
- StringValidatorAvs2YUV(QLabel *notifier, QLabel *icon) : StringValidator(notifier, icon) {}
-
- virtual State validate(QString &input, int &pos) const
- {
- static const char* p[] = {"o", "frames", "seek", "raw", "hfyu", "slave", NULL};
-
- bool invalid = false;
-
- for(size_t i = 0; p[i] && (!invalid); i++)
- {
- invalid = invalid || checkParam(input, QString::fromLatin1(p[i]), false);
- }
-
- return setStatus(invalid, "Avs2YUV") ? QValidator::Intermediate : QValidator::Acceptable;
- }
+private:
+ bool *const m_flag;
};
///////////////////////////////////////////////////////////////////////////////
m_sysinfo(sysinfo),
m_preferences(preferences),
m_defaults(new OptionsModel(sysinfo)),
- ui(new Ui::AddJobDialog())
+ ui(new Ui::AddJobDialog()),
+ m_monitorConfigChanges(false)
{
//Init the dialog, from the .ui file
ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
-
+
//Fix dialog size
ui->buttonSaveTemplate->setMaximumHeight(20);
ui->buttonDeleteTemplate->setMaximumHeight(20);
setMinimumSize(size());
setMaximumHeight(height());
+ //Init encoder combobox
+ ui->cbxEncoderType->addItem(tr("x264 (AVC)"), OptionsModel::EncType_X264);
+ ui->cbxEncoderType->addItem(tr("x265 (HEVC)"), OptionsModel::EncType_X265);
+ ui->cbxEncoderType->addItem(tr("NVEncC"), OptionsModel::EncType_NVEnc);
+
+ //Init combobox items
+ ui->cbxTuning ->addItem(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED));
+ ui->cbxProfile->addItem(QString::fromLatin1(OptionsModel::PROFILE_UNRESTRICTED));
+
//Hide optional controls
ui->checkBoxApplyToAll->setVisible(false);
//Monitor combobox changes
- connect(ui->cbxEncoderType, SIGNAL(currentIndexChanged(int)), this, SLOT(encoderIndexChanged(int)));
- connect(ui->cbxEncoderVariant, SIGNAL(currentIndexChanged(int)), this, SLOT(variantIndexChanged(int)));
+ connect(ui->cbxEncoderType, SIGNAL(currentIndexChanged(int)), this, SLOT(encoderIndexChanged(int)));
+ connect(ui->cbxEncoderVariant, SIGNAL(currentIndexChanged(int)), this, SLOT(variantIndexChanged(int)));
connect(ui->cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(modeIndexChanged(int)));
//Activate buttons
- connect(ui->buttonBrowseSource, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
- connect(ui->buttonBrowseOutput, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
- connect(ui->buttonSaveTemplate, SIGNAL(clicked()), this, SLOT(saveTemplateButtonClicked()));
+ connect(ui->buttonBrowseSource, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
+ connect(ui->buttonBrowseOutput, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
+ connect(ui->buttonSaveTemplate, SIGNAL(clicked()), this, SLOT(saveTemplateButtonClicked()));
connect(ui->buttonDeleteTemplate, SIGNAL(clicked()), this, SLOT(deleteTemplateButtonClicked()));
//Setup validator
ui->editCustomX264Params->installEventFilter(this);
- ui->editCustomX264Params->setValidator(new StringValidatorX264(ui->labelNotificationX264, ui->iconNotificationX264));
+ ui->editCustomX264Params->setValidator(new StringValidatorEncoder(ui->labelNotificationX264, ui->iconNotificationX264));
ui->editCustomX264Params->clear();
ui->editCustomAvs2YUVParams->installEventFilter(this);
- ui->editCustomAvs2YUVParams->setValidator(new StringValidatorAvs2YUV(ui->labelNotificationAvs2YUV, ui->iconNotificationAvs2YUV));
+ ui->editCustomAvs2YUVParams->setValidator(new StringValidatorSource(ui->labelNotificationAvs2YUV, ui->iconNotificationAvs2YUV));
ui->editCustomAvs2YUVParams->clear();
//Install event filter
//Setup template selector
loadTemplateList();
connect(ui->cbxTemplate, SIGNAL(currentIndexChanged(int)), this, SLOT(templateSelected()));
+
+ //Force initial UI update
+ encoderIndexChanged(ui->cbxEncoderType->currentIndex());
+ m_monitorConfigChanges = true;
}
AddJobDialog::~AddJobDialog(void)
}
const OptionsModel *item = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>());
ui->cbxTemplate->setItemData(i, QVariant::fromValue<const void*>(NULL));
- X264_DELETE(item);
+ MUTILS_DELETE(item);
}
//Free validators
if(const QValidator *tmp = ui->editCustomX264Params->validator())
{
ui->editCustomX264Params->setValidator(NULL);
- X264_DELETE(tmp);
+ MUTILS_DELETE(tmp);
}
if(const QValidator *tmp = ui->editCustomAvs2YUVParams->validator())
{
ui->editCustomAvs2YUVParams->setValidator(NULL);
- X264_DELETE(tmp);
+ MUTILS_DELETE(tmp);
}
- X264_DELETE(m_defaults);
+ MUTILS_DELETE(m_defaults);
delete ui;
}
if((o == ui->labelHelpScreenX264) && (e->type() == QEvent::MouseButtonPress))
{
OptionsModel options(m_sysinfo); saveOptions(&options);
- HelpDialog *helpScreen = new HelpDialog(this, false, m_sysinfo, &options, m_preferences);
+ QScopedPointer<HelpDialog> helpScreen(new HelpDialog(this, false, m_sysinfo, &options, m_preferences));
helpScreen->exec();
- X264_DELETE(helpScreen);
}
else if((o == ui->labelHelpScreenAvs2YUV) && (e->type() == QEvent::MouseButtonPress))
{
- HelpDialog *helpScreen = new HelpDialog(this, false, m_sysinfo, m_defaults, m_preferences);
+ OptionsModel options(m_sysinfo); saveOptions(&options);
+ QScopedPointer<HelpDialog> helpScreen(new HelpDialog(this, true, m_sysinfo, &options, m_preferences));
helpScreen->exec();
- X264_DELETE(helpScreen);
}
else if((o == ui->editCustomX264Params) && (e->type() == QEvent::FocusOut))
{
void AddJobDialog::encoderIndexChanged(int index)
{
- const bool isX265 = (index > 0);
- const bool noProf = isX265 || (ui->cbxEncoderVariant->currentIndex() > 0);
+ const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
+ const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
+
+ //Update encoder architectures
+ const QList<AbstractEncoderInfo::ArchId> archs = encoderInfo.getArchitectures();
+ ui->cbxEncoderArch->clear();
+ for (quint32 archIdx = 0; archIdx < quint32(archs.count()); ++archIdx)
+ {
+ ui->cbxEncoderArch->addItem(archs[archIdx].first, archIdx);
+ }
+
+ //Update encoder variants
+ const QStringList variants = encoderInfo.getVariants();
+ ui->cbxEncoderVariant->clear();
+ for(quint32 varntIdx = 0; varntIdx < quint32(variants.count()); ++varntIdx)
+ {
+ ui->cbxEncoderVariant->addItem(variants[varntIdx], varntIdx);
+ }
- ui->cbxEncoderVariant->setItemText(1, isX265 ? tr("16-Bit") : tr("10-Bit"));
- ui->labelProfile->setEnabled(!noProf);
- ui->cbxProfile->setEnabled(!noProf);
- if(noProf) ui->cbxProfile->setCurrentIndex(0);
+ //Update encoder RC modes
+ const QList<AbstractEncoderInfo::RCMode> rcModes = encoderInfo.getRCModes();
+ ui->cbxRateControlMode->clear();
+ for (quint32 rcIndex = 0; rcIndex < quint32(rcModes.count()); ++rcIndex)
+ {
+ ui->cbxRateControlMode->addItem(rcModes[rcIndex].first, rcIndex);
+ }
+
+ //Update presets
+ const QStringList presets = encoderInfo.getPresets();
+ if(presets.empty())
+ {
+ ui->cbxPreset->setEnabled(false);
+ ui->cbxPreset->setCurrentIndex(0);
+ }
+ else
+ {
+ ui->cbxPreset->setEnabled(true);
+ ui->cbxPreset->clear();
+ ui->cbxPreset->addItem(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED));
+ ui->cbxPreset->addItems(presets);
+ }
+
+ //Update tunings
+ const QStringList tunings = encoderInfo.getTunings();
+ if(tunings.empty())
+ {
+ ui->cbxTuning->setEnabled(false);
+ ui->cbxTuning->setCurrentIndex(0);
+ }
+ else
+ {
+ ui->cbxTuning->setEnabled(true);
+ ui->cbxTuning->clear();
+ ui->cbxTuning->addItem(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED));
+ ui->cbxTuning->addItems(tunings);
+ }
+
+ variantIndexChanged(ui->cbxEncoderVariant->currentIndex());
}
void AddJobDialog::variantIndexChanged(int index)
{
- const bool noProf = (index > 0) || (ui->cbxEncoderType->currentIndex() > 0);
+ const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
+ const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
- ui->labelProfile->setEnabled(!noProf);
- ui->cbxProfile->setEnabled(!noProf);
- if(noProf) ui->cbxProfile->setCurrentIndex(0);
+ //Update encoder profiles
+ const QStringList profiles = encoderInfo.getProfiles(ui->cbxEncoderVariant->itemData(index).toUInt());
+ if(profiles.empty())
+ {
+ ui->cbxProfile->setEnabled(false);
+ ui->cbxProfile->setCurrentIndex(0);
+ }
+ else
+ {
+ ui->cbxProfile->setEnabled(true);
+ ui->cbxProfile->clear();
+ ui->cbxProfile->addItem(QString::fromLatin1(OptionsModel::PROFILE_UNRESTRICTED));
+ ui->cbxProfile->addItems(profiles);
+ }
+
+ modeIndexChanged(ui->cbxRateControlMode->currentIndex());
}
void AddJobDialog::modeIndexChanged(int index)
{
- ui->spinQuantizer->setEnabled(index == 0 || index == 1);
- ui->spinBitrate->setEnabled(index == 2 || index == 3);
+ const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
+ const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
+
+ //Update bitrate/quantizer boxes
+ const AbstractEncoderInfo::RCType rcType = encoderInfo.rcModeToType(ui->cbxRateControlMode->itemData(index).toUInt());
+ ui->spinQuantizer->setEnabled(rcType == AbstractEncoderInfo::RC_TYPE_QUANTIZER);
+ ui->spinBitrate ->setEnabled(rcType != AbstractEncoderInfo::RC_TYPE_QUANTIZER);
}
void AddJobDialog::accept(void)
{
- //Check x265 support
- if((ui->cbxEncoderType->currentIndex() == OptionsModel::EncType_X265) && (!m_sysinfo->has256Support()))
- {
- QMessageBox::warning(this, tr("x265 unsupported"), tr("<nobr>Sorry, the x265 encoder is <b>not</b> currently available on this computer!<br>Please see the Readme file on how to obtain and install x265...</nobr>"));
- ui->cbxEncoderType->setCurrentIndex(OptionsModel::EncType_X264);
- return;
- }
+ //Get encoder info
+ const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
+ const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
//Check 64-Bit support
- if((ui->cbxEncoderArch->currentIndex() == OptionsModel::EncArch_x64) && (!m_sysinfo->hasX64Support()))
+ if (encoderInfo.archToType(ui->cbxEncoderArch->itemData(ui->cbxEncoderArch->currentIndex()).toUInt()) == AbstractEncoderInfo::ARCH_TYPE_X64)
{
- QMessageBox::warning(this, tr("64-Bit unsupported!"), tr("<nobr>Sorry, this computer does <b>not</b> support 64-Bit encoders!</nobr>"));
- ui->cbxEncoderArch->setCurrentIndex(OptionsModel::EncArch_x32);
- return;
+ if (!m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64))
+ {
+ QMessageBox::warning(this, tr("64-Bit unsupported!"), tr("<nobr>Sorry, this computer does <b>not</b> support 64-Bit encoders!</nobr>"));
+ ui->cbxEncoderArch->setCurrentIndex(AbstractEncoderInfo::ARCH_TYPE_X86);
+ return;
+ }
}
//Selection complete?
return;
}
- //Get encoder info
- const AbstractEncoderInfo &encoderInfo = getEncoderInfo(ui->cbxEncoderType->currentIndex());
-
- //Is selected RC mode supported?
- if(!encoderInfo.isRCModeSupported(ui->cbxRateControlMode->currentIndex()))
+ //Is the type of the source file supported?
+ const int sourceType = MediaInfo::analyze(sourceFile.canonicalFilePath());
+ if(sourceType == MediaInfo::FILETYPE_AVISYNTH)
{
- QMessageBox::warning(this, tr("Bad RC Mode!"), tr("<nobr>The selected RC mode is not supported by the selected encoder!</nobr>"));
- for(int i = 0; i < ui->cbxRateControlMode->count(); i++)
+ if(!m_sysinfo->hasAvisynth())
{
- if(encoderInfo.isRCModeSupported(i))
- {
- ui->cbxRateControlMode->setCurrentIndex(i);
- break;
- }
- }
- return;
- }
-
- //Is the type of the source file supported? (as far as we can tell)
- if(sourceFile.suffix().compare("AVS", Qt::CaseInsensitive) == 0)
- {
- if(!m_sysinfo->hasAVSSupport())
- {
- if(QMessageBox::warning(this, tr("Avisynth unsupported!"), tr("<nobr>An Avisynth script was selected as input, although Avisynth is <b>not</b> available!</nobr>"), tr("Abort"), tr("Ingnore (at your own risk!)")) != 1)
+ if(QMessageBox::warning(this, tr("Avisynth unsupported!"), tr("<nobr>An Avisynth script was selected as input, although Avisynth is <b>not</b> available!</nobr>"), tr("Abort"), tr("Ignore (at your own risk!)")) != 1)
{
return;
}
}
}
- else if((sourceFile.suffix().compare("VPY", Qt::CaseInsensitive) == 0) || (sourceFile.suffix().compare("PY", Qt::CaseInsensitive) == 0))
+ else if(sourceType == MediaInfo::FILETYPE_VAPOURSYNTH)
{
- if(!m_sysinfo->hasVPSSupport())
+ if(!m_sysinfo->hasVapourSynth())
{
- if(QMessageBox::warning(this, tr("VapurSynth unsupported!"), tr("<nobr>A VapourSynth script was selected as input, although VapourSynth is <b>not/<b> available!</nobr>"), tr("Abort"), tr("Ingnore (at your own risk!)")) != 1)
+ if(QMessageBox::warning(this, tr("VapurSynth unsupported!"), tr("<nobr>A VapourSynth script was selected as input, although VapourSynth is <b>not/<b> available!</nobr>"), tr("Abort"), tr("Ignore (at your own risk!)")) != 1)
{
return;
}
}
}
- else
+ else if(!encoderInfo.isInputTypeSupported(sourceType))
{
- const QStringList inputFormats = encoderInfo.supportedInputFormats();
- if(!inputFormats.contains(sourceFile.suffix(), Qt::CaseInsensitive))
+ if(QMessageBox::warning(this, tr("Unsupported input format"), tr("<nobr>The selected encoder does <b>not</b> support the selected input format!</nobr>"), tr("Abort"), tr("Ignore (at your own risk!)")) != 1)
{
- if(QMessageBox::warning(this, tr("Unsupported input format"), tr("<nobr>The selected encoder does <b>not</b> support the selected input format!</nobr>"), tr("Abort"), tr("Ingnore (at your own risk!)")) != 1)
- {
- return;
- }
+ return;
}
}
-
-
+
//Is output file extension supported by encoder?
const QStringList outputFormats = encoderInfo.supportedOutputFormats();
QFileInfo outputFile = QFileInfo(this->outputFile());
void AddJobDialog::configurationChanged(void)
{
+ if(!m_monitorConfigChanges)
+ {
+ return;
+ }
+
const OptionsModel* options = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(ui->cbxTemplate->currentIndex()).value<const void*>());
if(options)
{
ui->cbxTemplate->blockSignals(true);
- ui->cbxTemplate->insertItem(0, tr("<Unsaved Configuration>"), QVariant::fromValue<const void*>(NULL));
+ ui->cbxTemplate->insertItem(0, tr("<Modified Configuration>"), QVariant::fromValue<const void*>(NULL));
ui->cbxTemplate->setCurrentIndex(0);
ui->cbxTemplate->blockSignals(false);
}
if(options)
{
qDebug("Loading options!");
+ m_lastTemplateName = ui->cbxTemplate->itemText(ui->cbxTemplate->currentIndex());
REMOVE_USAFED_ITEM;
restoreOptions(options);
}
-
- //Force updates
- encoderIndexChanged(ui->cbxEncoderType->currentIndex());
- variantIndexChanged(ui->cbxEncoderVariant->currentIndex());
- modeIndexChanged(ui->cbxRateControlMode->currentIndex());
}
void AddJobDialog::saveTemplateButtonClicked(void)
{
qDebug("Saving template");
- QString name = tr("New Template");
- int n = 2;
- while(OptionsModel::templateExists(name))
+ QString name = m_lastTemplateName;
+ if(name.isEmpty() || name.contains('<') || name.contains('>'))
{
- name = tr("New Template (%1)").arg(QString::number(n++));
+ name = tr("New Template");
+ int n = 1;
+ while(OptionsModel::templateExists(name))
+ {
+ name = tr("New Template (%1)").arg(QString::number(++n));
+ }
}
- OptionsModel *options = new OptionsModel(m_sysinfo);
- saveOptions(options);
+ QScopedPointer<OptionsModel> options(new OptionsModel(m_sysinfo));
+ saveOptions(options.data());
if(options->equals(m_defaults))
{
ui->cbxTemplate->setCurrentIndex(0);
ui->cbxTemplate->blockSignals(false);
REMOVE_USAFED_ITEM;
- X264_DELETE(options);
return;
}
{
if(options->equals(test))
{
- QMessageBox::warning (this, tr("Oups"), tr("<nobr>There already is a template for the current settings!</nobr>"));
+ QMessageBox::information (this, tr("Oups"), tr("<nobr>The current settings are already saved as template:<br><b>%1</b></nobr>").arg(ui->cbxTemplate->itemText(i)));
ui->cbxTemplate->blockSignals(true);
ui->cbxTemplate->setCurrentIndex(i);
ui->cbxTemplate->blockSignals(false);
REMOVE_USAFED_ITEM;
- X264_DELETE(options);
return;
}
}
forever
{
bool ok = false;
- name = QInputDialog::getText(this, tr("Save Template"), tr("Please enter the name of the template:").leftJustified(144, ' '), QLineEdit::Normal, name, &ok).simplified();
+
+ QStringList items;
+ items << name;
+ for(int i = 0; i < ui->cbxTemplate->count(); i++)
+ {
+ const QString tempName = ui->cbxTemplate->itemText(i);
+ if(!(tempName.contains('<') || tempName.contains('>')))
+ {
+ items << tempName;
+ }
+ }
+
+ name = QInputDialog::getItem(this, tr("Save Template"), tr("Please enter the name of the template:").leftJustified(144, ' '), items, 0, true, &ok).simplified();
if(!ok)
{
- X264_DELETE(options);
return;
}
+ if(name.isEmpty())
+ {
+ continue;
+ }
if(name.contains('<') || name.contains('>') || name.contains('\\') || name.contains('/') || name.contains('"'))
{
QMessageBox::warning (this, tr("Invalid Name"), tr("<nobr>Sorry, the name you have entered is invalid!</nobr>"));
break;
}
- if(!OptionsModel::saveTemplate(options, name))
+ if(!OptionsModel::saveTemplate(options.data(), name))
{
QMessageBox::critical(this, tr("Save Failed"), tr("Sorry, the template could not be saved!"));
- X264_DELETE(options);
return;
}
- int index = ui->cbxTemplate->model()->rowCount();
ui->cbxTemplate->blockSignals(true);
for(int i = 0; i < ui->cbxTemplate->count(); i++)
{
if(ui->cbxTemplate->itemText(i).compare(name, Qt::CaseInsensitive) == 0)
{
- index = -1; //Do not append new template
- const OptionsModel *oldItem = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>());
- ui->cbxTemplate->setItemData(i, QVariant::fromValue<const void*>(options));
+ QScopedPointer<const OptionsModel> oldItem(reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>()));
+ ui->cbxTemplate->setItemData(i, QVariant::fromValue<const void*>(options.take()));
ui->cbxTemplate->setCurrentIndex(i);
- X264_DELETE(oldItem);
}
}
- if(index >= 0)
+ if(!options.isNull())
{
- ui->cbxTemplate->insertItem(index, name, QVariant::fromValue<const void*>(options));
+ const int index = ui->cbxTemplate->model()->rowCount();
+ ui->cbxTemplate->insertItem(index, name, QVariant::fromValue<const void*>(options.take()));
ui->cbxTemplate->setCurrentIndex(index);
}
ui->cbxTemplate->blockSignals(false);
+ m_lastTemplateName = name;
REMOVE_USAFED_ITEM;
}
return;
}
- int ret = QMessageBox::question (this, tr("Delete Template"), tr("<nobr>Do you really want to delete the selected template?</nobr>"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ int ret = QMessageBox::question (this, tr("Delete Template"), tr("<nobr>Do you really want to delete the selected template?<br><b>%1</b></nobr>").arg(name), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if(ret != QMessageBox::Yes)
{
return;
}
-
-
+
OptionsModel::deleteTemplate(name);
const OptionsModel *item = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(index).value<const void*>());
ui->cbxTemplate->removeItem(index);
- X264_DELETE(item);
+ MUTILS_DELETE(item);
}
void AddJobDialog::editorActionTriggered(void)
lineEdit->setText(editor->getEditText());
}
- X264_DELETE(editor);
+ MUTILS_DELETE(editor);
}
}
}
}
-void AddJobDialog::updateComboBox(QComboBox *cbox, const QString &text)
+void AddJobDialog::updateComboBox(QComboBox *const cbox, const QString &text)
{
- int index = -1;
+ int index = 0;
if(QAbstractItemModel *model = cbox->model())
{
for(int i = 0; i < cbox->model()->rowCount(); i++)
cbox->setCurrentIndex(index);
}
+void AddJobDialog::updateComboBox(QComboBox *const cbox, const int &data)
+{
+ int index = 0;
+ if (QAbstractItemModel *model = cbox->model())
+ {
+ for (int i = 0; i < cbox->model()->rowCount(); i++)
+ {
+ if (cbox->itemData(i).toInt() == data)
+ {
+ index = i;
+ break;
+ }
+ }
+ }
+ cbox->setCurrentIndex(index);
+}
+
+void AddJobDialog::updateComboBox(QComboBox *const cbox, const quint32 &data)
+{
+ int index = 0;
+ if(QAbstractItemModel *model = cbox->model())
+ {
+ for(int i = 0; i < cbox->model()->rowCount(); i++)
+ {
+ if(cbox->itemData(i).toUInt() == data)
+ {
+ index = i;
+ break;
+ }
+ }
+ }
+ cbox->setCurrentIndex(index);
+}
+
void AddJobDialog::restoreOptions(const OptionsModel *options)
{
- BLOCK_SIGNALS(true);
+ DisableHelperRAII disable(&m_monitorConfigChanges);
+
+ updateComboBox(ui->cbxEncoderType, options->encType());
+ updateComboBox(ui->cbxEncoderArch, options->encArch());
+ updateComboBox(ui->cbxEncoderVariant, options->encVariant());
+ updateComboBox(ui->cbxRateControlMode, options->rcMode());
- ui->cbxEncoderType->setCurrentIndex(options->encType());
- ui->cbxEncoderArch->setCurrentIndex(options->encArch());
- ui->cbxEncoderVariant->setCurrentIndex(options->encVariant());
- ui->cbxRateControlMode->setCurrentIndex(options->rcMode());
ui->spinQuantizer->setValue(options->quantizer());
- ui->spinBitrate->setValue(options->bitrate());
- updateComboBox(ui->cbxPreset, options->preset());
- updateComboBox(ui->cbxTuning, options->tune());
+ ui->spinBitrate ->setValue(options->bitrate());
+
+ updateComboBox(ui->cbxPreset, options->preset());
+ updateComboBox(ui->cbxTuning, options->tune());
updateComboBox(ui->cbxProfile, options->profile());
- ui->editCustomX264Params->setText(options->customEncParams());
- ui->editCustomAvs2YUVParams->setText(options->customAvs2YUV());
- BLOCK_SIGNALS(false);
+ ui->editCustomX264Params ->setText(options->customEncParams());
+ ui->editCustomAvs2YUVParams->setText(options->customAvs2YUV());
}
void AddJobDialog::saveOptions(OptionsModel *options)
{
- options->setEncType(static_cast<OptionsModel::EncType>(ui->cbxEncoderType->currentIndex()));
- options->setEncArch(static_cast<OptionsModel::EncArch>(ui->cbxEncoderArch->currentIndex()));
- options->setEncVariant(static_cast<OptionsModel::EncVariant>(ui->cbxEncoderVariant->currentIndex()));
- options->setRCMode(static_cast<OptionsModel::RCMode>(ui->cbxRateControlMode->currentIndex()));
+ options->setEncType(static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt()));
+
+ options->setEncArch (ui->cbxEncoderArch ->itemData(ui->cbxEncoderArch ->currentIndex()).toUInt());
+ options->setEncVariant(ui->cbxEncoderVariant ->itemData(ui->cbxEncoderVariant ->currentIndex()).toUInt());
+ options->setRCMode (ui->cbxRateControlMode->itemData(ui->cbxRateControlMode->currentIndex()).toUInt());
+
options->setQuantizer(ui->spinQuantizer->value());
- options->setBitrate(ui->spinBitrate->value());
- options->setPreset(ui->cbxPreset->model()->data(ui->cbxPreset->model()->index(ui->cbxPreset->currentIndex(), 0)).toString());
- options->setTune(ui->cbxTuning->model()->data(ui->cbxTuning->model()->index(ui->cbxTuning->currentIndex(), 0)).toString());
+ options->setBitrate (ui->spinBitrate ->value());
+
+ options->setPreset (ui->cbxPreset ->model()->data(ui->cbxPreset ->model()->index(ui->cbxPreset ->currentIndex(), 0)).toString());
+ options->setTune (ui->cbxTuning ->model()->data(ui->cbxTuning ->model()->index(ui->cbxTuning ->currentIndex(), 0)).toString());
options->setProfile(ui->cbxProfile->model()->data(ui->cbxProfile->model()->index(ui->cbxProfile->currentIndex(), 0)).toString());
- options->setCustomEncParams(ui->editCustomX264Params->hasAcceptableInput() ? ui->editCustomX264Params->text().simplified() : QString());
+
+ options->setCustomEncParams(ui->editCustomX264Params->hasAcceptableInput() ? ui->editCustomX264Params->text().simplified() : QString());
options->setCustomAvs2YUV(ui->editCustomAvs2YUVParams->hasAcceptableInput() ? ui->editCustomAvs2YUVParams->text().simplified() : QString());
}
int AddJobDialog::currentOutputIndx(void)
{
- if(ui->cbxEncoderType->currentIndex() == OptionsModel::EncType_X265)
+ const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
+ if(encType == OptionsModel::EncType_X265)
{
return ARRAY_SIZE(X264_FILE_TYPE_FILTERS) - 1;
}
return filters.join(";;");
}
-const AbstractEncoderInfo& AddJobDialog::getEncoderInfo(const int &encoder)
-{
- switch(encoder)
- {
- case OptionsModel::EncType_X264:
- return X264Encoder::getEncoderInfo();
- case OptionsModel::EncType_X265:
- return X265Encoder::getEncoderInfo();
- break;
- default:
- THROW("Unsupported encoder type!");
- }
-}
+