///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
-// Copyright (C) 2004-2012 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"
+//Internal
#include "global.h"
#include "model_options.h"
+#include "model_preferences.h"
+#include "model_sysinfo.h"
+#include "model_recently.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 \
{ \
- for(int i = 0; i < cbxTemplate->count(); i++) \
+ for(int i = 0; i < ui->cbxTemplate->count(); i++) \
{ \
- OptionsModel* temp = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>()); \
+ const OptionsModel* temp = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>()); \
if(temp == NULL) \
{ \
- cbxTemplate->blockSignals(true); \
- cbxTemplate->removeItem(i); \
- cbxTemplate->blockSignals(false); \
+ ui->cbxTemplate->blockSignals(true); \
+ ui->cbxTemplate->removeItem(i); \
+ ui->cbxTemplate->blockSignals(false); \
break; \
} \
} \
WIDGET->addAction(_action); \
}
+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;
};
///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor
///////////////////////////////////////////////////////////////////////////////
-AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *options, RecentlyUsed *recentlyUsed, bool x64supported, bool use10BitEncoding, bool saveToSourceFolder)
+AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *const options, RecentlyUsed *const recentlyUsed, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences)
:
QDialog(parent),
- m_defaults(new OptionsModel()),
m_options(options),
- m_x64supported(x64supported),
- m_use10BitEncoding(use10BitEncoding),
- m_saveToSourceFolder(saveToSourceFolder),
- m_recentlyUsed(recentlyUsed)
+ m_recentlyUsed(recentlyUsed),
+ m_sysinfo(sysinfo),
+ m_preferences(preferences),
+ m_defaults(new OptionsModel(sysinfo)),
+ ui(new Ui::AddJobDialog()),
+ m_monitorConfigChanges(false)
{
//Init the dialog, from the .ui file
- setupUi(this);
+ ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
-
+
//Fix dialog size
- buttonSaveTemplate->setMaximumHeight(20);
- buttonDeleteTemplate->setMaximumHeight(20);
+ ui->buttonSaveTemplate->setMaximumHeight(20);
+ ui->buttonDeleteTemplate->setMaximumHeight(20);
resize(width(), minimumHeight());
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
- checkBoxApplyToAll->setVisible(false);
+ ui->checkBoxApplyToAll->setVisible(false);
- //Monitor RC mode combobox
- connect(cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(modeIndexChanged(int)));
+ //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->cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(modeIndexChanged(int)));
//Activate buttons
- connect(buttonBrowseSource, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
- connect(buttonBrowseOutput, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
- connect(buttonSaveTemplate, SIGNAL(clicked()), this, SLOT(saveTemplateButtonClicked()));
- connect(buttonDeleteTemplate, SIGNAL(clicked()), this, SLOT(deleteTemplateButtonClicked()));
+ 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
- editCustomX264Params->installEventFilter(this);
- editCustomX264Params->setValidator(new StringValidatorX264(labelNotificationX264, iconNotificationX264));
- editCustomX264Params->clear();
- editCustomAvs2YUVParams->installEventFilter(this);
- editCustomAvs2YUVParams->setValidator(new StringValidatorAvs2YUV(labelNotificationAvs2YUV, iconNotificationAvs2YUV));
- editCustomAvs2YUVParams->clear();
+ ui->editCustomX264Params->installEventFilter(this);
+ ui->editCustomX264Params->setValidator(new StringValidatorEncoder(ui->labelNotificationX264, ui->iconNotificationX264));
+ ui->editCustomX264Params->clear();
+ ui->editCustomAvs2YUVParams->installEventFilter(this);
+ ui->editCustomAvs2YUVParams->setValidator(new StringValidatorSource(ui->labelNotificationAvs2YUV, ui->iconNotificationAvs2YUV));
+ ui->editCustomAvs2YUVParams->clear();
//Install event filter
- labelHelpScreenX264->installEventFilter(this);
- labelHelpScreenAvs2YUV->installEventFilter(this);
+ ui->labelHelpScreenX264->installEventFilter(this);
+ ui->labelHelpScreenAvs2YUV->installEventFilter(this);
//Monitor for options changes
- connect(cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
- connect(spinQuantizer, SIGNAL(valueChanged(double)), this, SLOT(configurationChanged()));
- connect(spinBitrate, SIGNAL(valueChanged(int)), this, SLOT(configurationChanged()));
- connect(cbxPreset, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
- connect(cbxTuning, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
- connect(cbxProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
- connect(editCustomX264Params, SIGNAL(textChanged(QString)), this, SLOT(configurationChanged()));
- connect(editCustomAvs2YUVParams, SIGNAL(textChanged(QString)), this, SLOT(configurationChanged()));
+ connect(ui->cbxEncoderType, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
+ connect(ui->cbxEncoderArch, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
+ connect(ui->cbxEncoderVariant, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
+ connect(ui->cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
+ connect(ui->spinQuantizer, SIGNAL(valueChanged(double)), this, SLOT(configurationChanged()));
+ connect(ui->spinBitrate, SIGNAL(valueChanged(int)), this, SLOT(configurationChanged()));
+ connect(ui->cbxPreset, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
+ connect(ui->cbxTuning, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
+ connect(ui->cbxProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
+ connect(ui->editCustomX264Params, SIGNAL(textChanged(QString)), this, SLOT(configurationChanged()));
+ connect(ui->editCustomAvs2YUVParams, SIGNAL(textChanged(QString)), this, SLOT(configurationChanged()));
//Create context menus
- ADD_CONTEXTMENU_ACTION(editCustomX264Params, QIcon(":/buttons/page_edit.png"), tr("Open the Text-Editor"), editorActionTriggered);
- ADD_CONTEXTMENU_ACTION(editCustomAvs2YUVParams, QIcon(":/buttons/page_edit.png"), tr("Open the Text-Editor"), editorActionTriggered);
- ADD_CONTEXTMENU_SEPARATOR(editCustomX264Params);
- ADD_CONTEXTMENU_SEPARATOR(editCustomAvs2YUVParams);
- ADD_CONTEXTMENU_ACTION(editCustomX264Params, QIcon(":/buttons/page_copy.png"), tr("Copy to Clipboard"), copyActionTriggered);
- ADD_CONTEXTMENU_ACTION(editCustomAvs2YUVParams, QIcon(":/buttons/page_copy.png"), tr("Copy to Clipboard"), copyActionTriggered);
- ADD_CONTEXTMENU_ACTION(editCustomX264Params, QIcon(":/buttons/page_paste.png"), tr("Paste from Clipboard"), pasteActionTriggered);
- ADD_CONTEXTMENU_ACTION(editCustomAvs2YUVParams, QIcon(":/buttons/page_paste.png"), tr("Paste from Clipboard"), pasteActionTriggered);
+ ADD_CONTEXTMENU_ACTION(ui->editCustomX264Params, QIcon(":/buttons/page_edit.png"), tr("Open the Text-Editor"), editorActionTriggered);
+ ADD_CONTEXTMENU_ACTION(ui->editCustomAvs2YUVParams, QIcon(":/buttons/page_edit.png"), tr("Open the Text-Editor"), editorActionTriggered);
+ ADD_CONTEXTMENU_SEPARATOR(ui->editCustomX264Params);
+ ADD_CONTEXTMENU_SEPARATOR(ui->editCustomAvs2YUVParams);
+ ADD_CONTEXTMENU_ACTION(ui->editCustomX264Params, QIcon(":/buttons/page_copy.png"), tr("Copy to Clipboard"), copyActionTriggered);
+ ADD_CONTEXTMENU_ACTION(ui->editCustomAvs2YUVParams, QIcon(":/buttons/page_copy.png"), tr("Copy to Clipboard"), copyActionTriggered);
+ ADD_CONTEXTMENU_ACTION(ui->editCustomX264Params, QIcon(":/buttons/page_paste.png"), tr("Paste from Clipboard"), pasteActionTriggered);
+ ADD_CONTEXTMENU_ACTION(ui->editCustomAvs2YUVParams, QIcon(":/buttons/page_paste.png"), tr("Paste from Clipboard"), pasteActionTriggered);
//Setup template selector
loadTemplateList();
- connect(cbxTemplate, SIGNAL(currentIndexChanged(int)), this, SLOT(templateSelected()));
+ connect(ui->cbxTemplate, SIGNAL(currentIndexChanged(int)), this, SLOT(templateSelected()));
+
+ //Force initial UI update
+ encoderIndexChanged(ui->cbxEncoderType->currentIndex());
+ m_monitorConfigChanges = true;
}
AddJobDialog::~AddJobDialog(void)
{
//Free templates
- for(int i = 0; i < cbxTemplate->model()->rowCount(); i++)
+ for(int i = 0; i < ui->cbxTemplate->model()->rowCount(); i++)
{
- if(cbxTemplate->itemText(i).startsWith("<") || cbxTemplate->itemText(i).endsWith(">"))
+ if(ui->cbxTemplate->itemText(i).startsWith("<") || ui->cbxTemplate->itemText(i).endsWith(">"))
{
continue;
}
- OptionsModel *item = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>());
- cbxTemplate->setItemData(i, QVariant::fromValue<void*>(NULL));
- X264_DELETE(item);
+ const OptionsModel *item = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>());
+ ui->cbxTemplate->setItemData(i, QVariant::fromValue<const void*>(NULL));
+ MUTILS_DELETE(item);
}
//Free validators
- if(const QValidator *tmp = editCustomX264Params->validator())
+ if(const QValidator *tmp = ui->editCustomX264Params->validator())
{
- editCustomX264Params->setValidator(NULL);
- X264_DELETE(tmp);
+ ui->editCustomX264Params->setValidator(NULL);
+ MUTILS_DELETE(tmp);
}
- if(const QValidator *tmp = editCustomAvs2YUVParams->validator())
+ if(const QValidator *tmp = ui->editCustomAvs2YUVParams->validator())
{
- editCustomAvs2YUVParams->setValidator(NULL);
- X264_DELETE(tmp);
+ ui->editCustomAvs2YUVParams->setValidator(NULL);
+ MUTILS_DELETE(tmp);
}
- X264_DELETE(m_defaults);
+ MUTILS_DELETE(m_defaults);
+ delete ui;
}
///////////////////////////////////////////////////////////////////////////////
QDialog::showEvent(event);
templateSelected();
- if((!editSource->text().isEmpty()) && editOutput->text().isEmpty())
+ if((!ui->editSource->text().isEmpty()) && ui->editOutput->text().isEmpty())
{
- QString outPath = generateOutputFileName(QDir::fromNativeSeparators(editSource->text()), m_recentlyUsed->outputDirectory, m_recentlyUsed->filterIndex, m_saveToSourceFolder);
- editOutput->setText(QDir::toNativeSeparators(outPath));
- buttonAccept->setFocus();
+ QString outPath = generateOutputFileName(QDir::fromNativeSeparators(ui->editSource->text()), m_recentlyUsed->outputDirectory(), m_recentlyUsed->filterIndex(), m_preferences->getSaveToSourcePath());
+ ui->editOutput->setText(QDir::toNativeSeparators(outPath));
+ ui->buttonAccept->setFocus();
}
- labelNotificationX264->hide();
- iconNotificationX264->hide();
- labelNotificationAvs2YUV->hide();
- iconNotificationAvs2YUV->hide();
+ ui->labelNotificationX264->hide();
+ ui->iconNotificationX264->hide();
+ ui->labelNotificationAvs2YUV->hide();
+ ui->iconNotificationAvs2YUV->hide();
//Enable drag&drop support for this window, required for Qt v4.8.4+
setAcceptDrops(true);
bool AddJobDialog::eventFilter(QObject *o, QEvent *e)
{
- if((o == labelHelpScreenX264) && (e->type() == QEvent::MouseButtonPress))
+ if((o == ui->labelHelpScreenX264) && (e->type() == QEvent::MouseButtonPress))
{
- HelpDialog *helpScreen = new HelpDialog(this, false, m_x64supported, m_use10BitEncoding);
+ OptionsModel options(m_sysinfo); saveOptions(&options);
+ QScopedPointer<HelpDialog> helpScreen(new HelpDialog(this, false, m_sysinfo, &options, m_preferences));
helpScreen->exec();
- X264_DELETE(helpScreen);
}
- else if((o == labelHelpScreenAvs2YUV) && (e->type() == QEvent::MouseButtonPress))
+ else if((o == ui->labelHelpScreenAvs2YUV) && (e->type() == QEvent::MouseButtonPress))
{
- HelpDialog *helpScreen = new HelpDialog(this, true, m_x64supported, m_use10BitEncoding);
+ 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 == editCustomX264Params) && (e->type() == QEvent::FocusOut))
+ else if((o == ui->editCustomX264Params) && (e->type() == QEvent::FocusOut))
{
- editCustomX264Params->setText(editCustomX264Params->text().simplified());
+ ui->editCustomX264Params->setText(ui->editCustomX264Params->text().simplified());
}
- else if((o == editCustomAvs2YUVParams) && (e->type() == QEvent::FocusOut))
+ else if((o == ui->editCustomAvs2YUVParams) && (e->type() == QEvent::FocusOut))
{
- editCustomAvs2YUVParams->setText(editCustomAvs2YUVParams->text().simplified());
+ ui->editCustomAvs2YUVParams->setText(ui->editCustomAvs2YUVParams->text().simplified());
}
return false;
}
if(!droppedFile.isEmpty())
{
- editSource->setText(QDir::toNativeSeparators(droppedFile));
- generateOutputFileName(droppedFile, m_recentlyUsed->outputDirectory, m_recentlyUsed->filterIndex, m_saveToSourceFolder);
+ const QString outFileName = generateOutputFileName(droppedFile, currentOutputPath(), currentOutputIndx(), m_preferences->getSaveToSourcePath());
+ ui->editSource->setText(QDir::toNativeSeparators(droppedFile));
+ ui->editOutput->setText(QDir::toNativeSeparators(outFileName));
}
}
// Slots
///////////////////////////////////////////////////////////////////////////////
+void AddJobDialog::encoderIndexChanged(int index)
+{
+ 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);
+ }
+
+ //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 OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
+ const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
+
+ //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)
{
- spinQuantizer->setEnabled(index == 0 || index == 1);
- 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)
{
+ //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 (encoderInfo.archToType(ui->cbxEncoderArch->itemData(ui->cbxEncoderArch->currentIndex()).toUInt()) == AbstractEncoderInfo::ARCH_TYPE_X64)
+ {
+ 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?
- if(editSource->text().trimmed().isEmpty())
+ if(ui->editSource->text().trimmed().isEmpty())
{
- QMessageBox::warning(this, tr("Not Found!"), tr("Please select a valid source file first!"));
+ QMessageBox::warning(this, tr("Not Found!"), tr("<nobr>Please select a valid source file first!<(nobr>"));
return;
}
- if(editOutput->text().trimmed().isEmpty())
+ if(ui->editOutput->text().trimmed().isEmpty())
{
QMessageBox::warning(this, tr("Not Selected!"), tr("<nobr>Please select a valid output file first!</nobr>"));
return;
return;
}
- //Is destination dir writable?
- QFileInfo outputDir = QFileInfo(QFileInfo(this->outputFile()).absolutePath());
- if(!(outputDir.exists() && outputDir.isDir() && outputDir.isWritable()))
+ //Is the type of the source file supported?
+ const int sourceType = MediaInfo::analyze(sourceFile.canonicalFilePath());
+ if(sourceType == MediaInfo::FILETYPE_AVISYNTH)
{
- QMessageBox::warning(this, tr("Not Writable!"), tr("<nobr>Output directory does not exist or is not writable!</nobr>"));
+ if(!m_sysinfo->hasAvisynth())
+ {
+ 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(sourceType == MediaInfo::FILETYPE_VAPOURSYNTH)
+ {
+ 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("Ignore (at your own risk!)")) != 1)
+ {
+ return;
+ }
+ }
+ }
+ else if(!encoderInfo.isInputTypeSupported(sourceType))
+ {
+ 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)
+ {
+ return;
+ }
+ }
+
+ //Is output file extension supported by encoder?
+ const QStringList outputFormats = encoderInfo.supportedOutputFormats();
+ QFileInfo outputFile = QFileInfo(this->outputFile());
+ if(!outputFormats.contains(outputFile.suffix(), Qt::CaseInsensitive))
+ {
+ QMessageBox::warning(this, tr("Unsupported output format"), tr("<nobr>Sorry, the selected encoder does not support the selected output format!</nobr>"));
+ ui->editOutput->setText(QDir::toNativeSeparators(QString("%1/%2.%3").arg(outputFile.absolutePath(), outputFile.completeBaseName(), outputFormats.first())));
return;
}
//Does output file already exist?
- QFileInfo outputFile = QFileInfo(this->outputFile());
if(outputFile.exists() && outputFile.isFile())
{
int ret = QMessageBox::question(this, tr("Already Exists!"), tr("<nobr>Output file already exists! Overwrite?</nobr>"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
return;
}
+ //Is destination dir writable?
+ QFileInfo outputDir = QFileInfo(outputFile.absolutePath());
+ if(!(outputDir.exists() && outputDir.isDir() && outputDir.isWritable()))
+ {
+ QMessageBox::warning(this, tr("Not Writable!"), tr("<nobr>Output directory does not exist or is not writable!</nobr>"));
+ return;
+ }
+
//Custom parameters okay?
- if(!editCustomX264Params->hasAcceptableInput())
+ if(!ui->editCustomX264Params->hasAcceptableInput())
{
int ret = QMessageBox::warning(this, tr("Invalid Params"), tr("<nobr>Your custom parameters are invalid and will be discarded!</nobr>"), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel);
if(ret != QMessageBox::Ignore) return;
}
//Update recently used
- m_recentlyUsed->sourceDirectory = sourceFile.canonicalPath();
- m_recentlyUsed->outputDirectory = outputFile.canonicalPath();
- m_recentlyUsed->filterIndex = qMax(0, getFilterIdx(outputFile.suffix()));
- saveRecentlyUsed(m_recentlyUsed);
+ m_recentlyUsed->setFilterIndex(currentOutputIndx());
+ m_recentlyUsed->setSourceDirectory(currentSourcePath());
+ m_recentlyUsed->setOutputDirectory(currentOutputPath());
+ RecentlyUsed::saveRecentlyUsed(m_recentlyUsed);
//Save options
saveOptions(m_options);
void AddJobDialog::browseButtonClicked(void)
{
- if(QObject::sender() == buttonBrowseSource)
+ if(QObject::sender() == ui->buttonBrowseSource)
{
- QString initDir = m_recentlyUsed->sourceDirectory;
- if(!editSource->text().isEmpty())
- {
- QString tempDir = QFileInfo(QDir::fromNativeSeparators(editSource->text())).canonicalPath();
- if(VALID_DIR(tempDir)) initDir = tempDir;
- }
-
- QString filePath = QFileDialog::getOpenFileName(this, tr("Open Source File"), initDir, getInputFilterLst(), NULL, QFileDialog::DontUseNativeDialog);
+ QString filePath = QFileDialog::getOpenFileName(this, tr("Open Source File"), currentSourcePath(true), getInputFilterLst(), NULL, QFileDialog::DontUseNativeDialog);
if(!(filePath.isNull() || filePath.isEmpty()))
{
- editSource->setText(QDir::toNativeSeparators(filePath));
- QString destPath = generateOutputFileName(filePath, m_recentlyUsed->outputDirectory, m_recentlyUsed->filterIndex, m_saveToSourceFolder);
- editOutput->setText(QDir::toNativeSeparators(destPath));
+ QString destFile = generateOutputFileName(filePath, currentOutputPath(), currentOutputIndx(), m_preferences->getSaveToSourcePath());
+ ui->editSource->setText(QDir::toNativeSeparators(filePath));
+ ui->editOutput->setText(QDir::toNativeSeparators(destFile));
}
}
- else if(QObject::sender() == buttonBrowseOutput)
+ else if(QObject::sender() == ui->buttonBrowseOutput)
{
- QString initDir = m_recentlyUsed->outputDirectory;
- if(!editOutput->text().isEmpty())
- {
- QString tempDir = QFileInfo(QDir::fromNativeSeparators(editOutput->text())).canonicalPath();
- if(VALID_DIR(tempDir)) initDir = tempDir;
- }
-
- QString selectedType = getFilterStr(m_recentlyUsed->filterIndex);
- QString filePath = QFileDialog::getSaveFileName(this, tr("Choose Output File"), initDir, getFilterLst(), &selectedType, QFileDialog::DontUseNativeDialog | QFileDialog::DontConfirmOverwrite);
+ QString selectedType = getFilterStr(currentOutputIndx());
+ QString filePath = QFileDialog::getSaveFileName(this, tr("Choose Output File"), currentOutputPath(true), getFilterLst(), &selectedType, QFileDialog::DontUseNativeDialog | QFileDialog::DontConfirmOverwrite);
if(!(filePath.isNull() || filePath.isEmpty()))
{
if(getFilterIdx(QFileInfo(filePath).suffix()) < 0)
{
- filePath = QString("%1.%2").arg(filePath, getFilterExt(m_recentlyUsed->filterIndex));
+ int tempIndex = -1;
+ QRegExp regExp("\\(\\*\\.(\\w+)\\)");
+ if(regExp.lastIndexIn(selectedType) >= 0)
+ {
+ tempIndex = getFilterIdx(regExp.cap(1));
+ }
+ if(tempIndex < 0)
+ {
+ tempIndex = m_recentlyUsed->filterIndex();
+ }
+ filePath = QString("%1.%2").arg(filePath, getFilterExt(tempIndex));
}
- editOutput->setText(QDir::toNativeSeparators(filePath));
+ ui->editOutput->setText(QDir::toNativeSeparators(filePath));
}
}
}
void AddJobDialog::configurationChanged(void)
{
- OptionsModel* options = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(cbxTemplate->currentIndex()).value<void*>());
+ if(!m_monitorConfigChanges)
+ {
+ return;
+ }
+
+ const OptionsModel* options = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(ui->cbxTemplate->currentIndex()).value<const void*>());
if(options)
{
- cbxTemplate->blockSignals(true);
- cbxTemplate->insertItem(0, tr("<Unsaved Configuration>"), QVariant::fromValue<void*>(NULL));
- cbxTemplate->setCurrentIndex(0);
- cbxTemplate->blockSignals(false);
+ ui->cbxTemplate->blockSignals(true);
+ ui->cbxTemplate->insertItem(0, tr("<Modified Configuration>"), QVariant::fromValue<const void*>(NULL));
+ ui->cbxTemplate->setCurrentIndex(0);
+ ui->cbxTemplate->blockSignals(false);
}
}
void AddJobDialog::templateSelected(void)
{
- OptionsModel* options = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(cbxTemplate->currentIndex()).value<void*>());
+ const OptionsModel* options = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(ui->cbxTemplate->currentIndex()).value<const void*>());
if(options)
{
qDebug("Loading options!");
+ m_lastTemplateName = ui->cbxTemplate->itemText(ui->cbxTemplate->currentIndex());
REMOVE_USAFED_ITEM;
restoreOptions(options);
}
-
- modeIndexChanged(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();
- saveOptions(options);
+ QScopedPointer<OptionsModel> options(new OptionsModel(m_sysinfo));
+ saveOptions(options.data());
if(options->equals(m_defaults))
{
QMessageBox::warning (this, tr("Oups"), tr("<nobr>It makes no sense to save the default settings!</nobr>"));
- cbxTemplate->blockSignals(true);
- cbxTemplate->setCurrentIndex(0);
- cbxTemplate->blockSignals(false);
+ ui->cbxTemplate->blockSignals(true);
+ ui->cbxTemplate->setCurrentIndex(0);
+ ui->cbxTemplate->blockSignals(false);
REMOVE_USAFED_ITEM;
- X264_DELETE(options);
return;
}
- for(int i = 0; i < cbxTemplate->count(); i++)
+ for(int i = 0; i < ui->cbxTemplate->count(); i++)
{
- const QString tempName = cbxTemplate->itemText(i);
+ const QString tempName = ui->cbxTemplate->itemText(i);
if(tempName.contains('<') || tempName.contains('>'))
{
continue;
}
- OptionsModel* test = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>());
+ const OptionsModel* test = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>());
if(test != NULL)
{
if(options->equals(test))
{
- QMessageBox::warning (this, tr("Oups"), tr("<nobr>There already is a template for the current settings!</nobr>"));
- cbxTemplate->blockSignals(true);
- cbxTemplate->setCurrentIndex(i);
- cbxTemplate->blockSignals(false);
+ 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 = cbxTemplate->model()->rowCount();
- cbxTemplate->blockSignals(true);
- for(int i = 0; i < cbxTemplate->count(); i++)
+ ui->cbxTemplate->blockSignals(true);
+ for(int i = 0; i < ui->cbxTemplate->count(); i++)
{
- if(cbxTemplate->itemText(i).compare(name, Qt::CaseInsensitive) == 0)
+ if(ui->cbxTemplate->itemText(i).compare(name, Qt::CaseInsensitive) == 0)
{
- index = -1; //Do not append new template
- OptionsModel *oldItem = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>());
- cbxTemplate->setItemData(i, QVariant::fromValue<void*>(options));
- cbxTemplate->setCurrentIndex(i);
- X264_DELETE(oldItem);
+ 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);
}
}
- if(index >= 0)
+ if(!options.isNull())
{
- cbxTemplate->insertItem(index, name, QVariant::fromValue<void*>(options));
- cbxTemplate->setCurrentIndex(index);
+ const int index = ui->cbxTemplate->model()->rowCount();
+ ui->cbxTemplate->insertItem(index, name, QVariant::fromValue<const void*>(options.take()));
+ ui->cbxTemplate->setCurrentIndex(index);
}
- cbxTemplate->blockSignals(false);
+ ui->cbxTemplate->blockSignals(false);
+ m_lastTemplateName = name;
REMOVE_USAFED_ITEM;
}
void AddJobDialog::deleteTemplateButtonClicked(void)
{
- const int index = cbxTemplate->currentIndex();
- QString name = cbxTemplate->itemText(index);
+ const int index = ui->cbxTemplate->currentIndex();
+ QString name = ui->cbxTemplate->itemText(index);
if(name.contains('<') || name.contains('>') || name.contains('\\') || name.contains('/'))
{
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);
- OptionsModel *item = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(index).value<void*>());
- cbxTemplate->removeItem(index);
- X264_DELETE(item);
+ const OptionsModel *item = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(index).value<const void*>());
+ ui->cbxTemplate->removeItem(index);
+ MUTILS_DELETE(item);
}
void AddJobDialog::editorActionTriggered(void)
lineEdit->setText(editor->getEditText());
}
- X264_DELETE(editor);
+ MUTILS_DELETE(editor);
}
}
QString AddJobDialog::sourceFile(void)
{
- return QDir::fromNativeSeparators(editSource->text());
+ return QDir::fromNativeSeparators(ui->editSource->text());
}
QString AddJobDialog::outputFile(void)
{
- return QDir::fromNativeSeparators(editOutput->text());
+ return QDir::fromNativeSeparators(ui->editOutput->text());
+}
+
+bool AddJobDialog::runImmediately(void)
+{
+ return ui->checkBoxRun->isChecked();
+}
+
+bool AddJobDialog::applyToAll(void)
+{
+ return ui->checkBoxApplyToAll->isChecked();
+}
+
+void AddJobDialog::setRunImmediately(bool run)
+{
+ ui->checkBoxRun->setChecked(run);
+}
+
+void AddJobDialog::setSourceFile(const QString &path)
+{
+ ui->editSource->setText(QDir::toNativeSeparators(path));
+}
+
+void AddJobDialog::setOutputFile(const QString &path)
+{
+ ui->editOutput->setText(QDir::toNativeSeparators(path));}
+
+void AddJobDialog::setSourceEditable(const bool editable)
+{
+ ui->buttonBrowseSource->setEnabled(editable);
+}
+
+void AddJobDialog::setApplyToAllVisible(const bool visible)
+{
+ ui->checkBoxApplyToAll->setVisible(visible);
}
///////////////////////////////////////////////////////////////////////////////
void AddJobDialog::loadTemplateList(void)
{
- cbxTemplate->addItem(tr("<Default>"), QVariant::fromValue<void*>(m_defaults));
- cbxTemplate->setCurrentIndex(0);
+ ui->cbxTemplate->addItem(tr("<Default>"), QVariant::fromValue<const void*>(m_defaults));
+ ui->cbxTemplate->setCurrentIndex(0);
- QMap<QString, OptionsModel*> templates = OptionsModel::loadAllTemplates();
+ QMap<QString, OptionsModel*> templates = OptionsModel::loadAllTemplates(m_sysinfo);
QStringList templateNames = templates.keys();
templateNames.sort();
- while(!templateNames.isEmpty())
+ for(QStringList::ConstIterator current = templateNames.constBegin(); current != templateNames.constEnd(); current++)
{
- QString current = templateNames.takeFirst();
- cbxTemplate->addItem(current, QVariant::fromValue<void*>(templates.value(current)));
+ OptionsModel *currentTemplate = templates.take(*current);
+ ui->cbxTemplate->addItem(*current, QVariant::fromValue<const void*>(currentTemplate));
+ if(currentTemplate->equals(m_options))
+ {
+ ui->cbxTemplate->setCurrentIndex(ui->cbxTemplate->count() - 1);
+ }
+ }
- if(templates.value(current)->equals(m_options))
+ if((ui->cbxTemplate->currentIndex() == 0) && (!m_options->equals(m_defaults)))
+ {
+ qWarning("Not the default -> recently used!");
+ ui->cbxTemplate->insertItem(1, tr("<Recently Used>"), QVariant::fromValue<const void*>(m_options));
+ ui->cbxTemplate->setCurrentIndex(1);
+ }
+}
+
+void AddJobDialog::updateComboBox(QComboBox *const cbox, const QString &text)
+{
+ int index = 0;
+ if(QAbstractItemModel *model = cbox->model())
+ {
+ for(int i = 0; i < cbox->model()->rowCount(); i++)
{
- cbxTemplate->setCurrentIndex(cbxTemplate->count() - 1);
+ if(model->data(model->index(i, 0, QModelIndex())).toString().compare(text, Qt::CaseInsensitive) == 0)
+ {
+ index = i;
+ break;
+ }
}
}
+ cbox->setCurrentIndex(index);
+}
- if((cbxTemplate->currentIndex() == 0) && (!m_options->equals(m_defaults)))
+void AddJobDialog::updateComboBox(QComboBox *const cbox, const int &data)
+{
+ int index = 0;
+ if (QAbstractItemModel *model = cbox->model())
{
- cbxTemplate->insertItem(1, tr("<Recently Used>"), QVariant::fromValue<void*>(m_options));
- cbxTemplate->setCurrentIndex(1);
+ 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 *cbox, const QString &text)
+void AddJobDialog::updateComboBox(QComboBox *const cbox, const quint32 &data)
{
- for(int i = 0; i < cbox->model()->rowCount(); i++)
+ int index = 0;
+ if(QAbstractItemModel *model = cbox->model())
{
- if(cbox->model()->data(cbox->model()->index(i, 0, QModelIndex())).toString().compare(text, Qt::CaseInsensitive) == 0)
+ for(int i = 0; i < cbox->model()->rowCount(); i++)
{
- cbox->setCurrentIndex(i);
- break;
+ if(cbox->itemData(i).toUInt() == data)
+ {
+ index = i;
+ break;
+ }
}
}
+ cbox->setCurrentIndex(index);
}
-void AddJobDialog::restoreOptions(OptionsModel *options)
+void AddJobDialog::restoreOptions(const OptionsModel *options)
{
- cbxRateControlMode->blockSignals(true);
- spinQuantizer->blockSignals(true);
- spinBitrate->blockSignals(true);
- cbxPreset->blockSignals(true);
- cbxTuning->blockSignals(true);
- cbxProfile->blockSignals(true);
- editCustomX264Params->blockSignals(true);
- editCustomAvs2YUVParams->blockSignals(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());
- cbxRateControlMode->setCurrentIndex(options->rcMode());
- spinQuantizer->setValue(options->quantizer());
- spinBitrate->setValue(options->bitrate());
- updateComboBox(cbxPreset, options->preset());
- updateComboBox(cbxTuning, options->tune());
- updateComboBox(cbxProfile, options->profile());
- editCustomX264Params->setText(options->customX264());
- editCustomAvs2YUVParams->setText(options->customAvs2YUV());
+ ui->spinQuantizer->setValue(options->quantizer());
+ ui->spinBitrate ->setValue(options->bitrate());
- cbxRateControlMode->blockSignals(false);
- spinQuantizer->blockSignals(false);
- spinBitrate->blockSignals(false);
- cbxPreset->blockSignals(false);
- cbxTuning->blockSignals(false);
- cbxProfile->blockSignals(false);
- editCustomX264Params->blockSignals(false);
- editCustomAvs2YUVParams->blockSignals(false);
+ 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());
}
void AddJobDialog::saveOptions(OptionsModel *options)
{
- options->setRCMode(static_cast<OptionsModel::RCMode>(cbxRateControlMode->currentIndex()));
- options->setQuantizer(spinQuantizer->value());
- options->setBitrate(spinBitrate->value());
- options->setPreset(cbxPreset->model()->data(cbxPreset->model()->index(cbxPreset->currentIndex(), 0)).toString());
- options->setTune(cbxTuning->model()->data(cbxTuning->model()->index(cbxTuning->currentIndex(), 0)).toString());
- options->setProfile(cbxProfile->model()->data(cbxProfile->model()->index(cbxProfile->currentIndex(), 0)).toString());
- options->setCustomX264(editCustomX264Params->hasAcceptableInput() ? editCustomX264Params->text().simplified() : QString());
- options->setCustomAvs2YUV(editCustomAvs2YUVParams->hasAcceptableInput() ? editCustomAvs2YUVParams->text().simplified() : QString());
+ 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->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->setCustomAvs2YUV(ui->editCustomAvs2YUVParams->hasAcceptableInput() ? ui->editCustomAvs2YUVParams->text().simplified() : QString());
}
-/*
-void AddJobDialog::generateOutputFileName(const QString &filePath)
+QString AddJobDialog::currentSourcePath(const bool bWithName)
{
- QString name = QFileInfo(filePath).completeBaseName();
- QString path = m_saveToSourceFolder ? QFileInfo(filePath).canonicalPath() : (VALID_DIR(m_initialDir_out) ? m_initialDir_out : QFileInfo(filePath).path());
- QString fext = getFilterExt(m_lastFilterIndex);
-
- QString outPath = QString("%1/%2.%3").arg(path, name, fext);
-
- if(QFileInfo(outPath).exists())
+ QString path = m_recentlyUsed->sourceDirectory();
+ QString currentSourceFile = this->sourceFile();
+
+ if(!currentSourceFile.isEmpty())
{
- int i = 2;
- while(QFileInfo(outPath).exists())
+ QString currentSourceDir = QFileInfo(currentSourceFile).absolutePath();
+ if(VALID_DIR(currentSourceDir))
{
- outPath = QString("%1/%2 (%3).%4").arg(path, name, QString::number(i++), fext);
+ path = currentSourceDir;
+ }
+ if(bWithName)
+ {
+ path.append("/").append(QFileInfo(currentSourceFile).fileName());
}
}
- editOutput->setText(QDir::toNativeSeparators(outPath));
+ return path;
}
-int AddJobDialog::getFilterIndex(const QString &fileExt)
+QString AddJobDialog::currentOutputPath(const bool bWithName)
{
- if(!fileExt.isEmpty())
+ QString path = m_recentlyUsed->outputDirectory();
+ QString currentOutputFile = this->outputFile();
+
+ if(!currentOutputFile.isEmpty())
{
- QRegExp ext("\\(\\*\\.(.+)\\)");
- for(int i = 0; i < m_types.count(); i++)
+ QString currentOutputDir = QFileInfo(currentOutputFile).absolutePath();
+ if(VALID_DIR(currentOutputDir))
{
- if(ext.lastIndexIn(m_types.at(i)) >= 0)
- {
- if(fileExt.compare(ext.cap(1), Qt::CaseInsensitive) == 0)
- {
- return i;
- }
- }
+ path = currentOutputDir;
+ }
+ if(bWithName)
+ {
+ path.append("/").append(QFileInfo(currentOutputFile).fileName());
}
}
- return -1;
+ return path;
}
-*/
-///////////////////////////////////////////////////////////////////////////////
-// Static functions
-///////////////////////////////////////////////////////////////////////////////
-
-static const char *KEY_FILTER_IDX = "path/filterIndex";
-static const char *KEY_SOURCE_DIR = "path/directory_openFrom";
-static const char *KEY_OUTPUT_DIR = "path/directory_saveTo";
-
-void AddJobDialog::initRecentlyUsed(RecentlyUsed *recentlyUsed)
-{
- recentlyUsed->sourceDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
- recentlyUsed->outputDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
- recentlyUsed->filterIndex = 0;
-}
-
-void AddJobDialog::loadRecentlyUsed(RecentlyUsed *recentlyUsed)
+int AddJobDialog::currentOutputIndx(void)
{
- RecentlyUsed defaults;
- initRecentlyUsed(&defaults);
+ 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;
+ }
- QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
- recentlyUsed->sourceDirectory = settings.value(KEY_SOURCE_DIR, defaults.sourceDirectory).toString();
- recentlyUsed->outputDirectory = settings.value(KEY_OUTPUT_DIR, defaults.outputDirectory).toString();
- recentlyUsed->filterIndex = settings.value(KEY_FILTER_IDX, defaults.filterIndex).toInt();
+ int index = m_recentlyUsed->filterIndex();
+ const QString currentOutputFile = this->outputFile();
- if(!VALID_DIR(recentlyUsed->sourceDirectory)) recentlyUsed->sourceDirectory = defaults.sourceDirectory;
- if(!VALID_DIR(recentlyUsed->outputDirectory)) recentlyUsed->outputDirectory = defaults.outputDirectory;
-}
-
-void AddJobDialog::saveRecentlyUsed(RecentlyUsed *recentlyUsed)
-{
- QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
- if(settings.isWritable())
+ if(!currentOutputFile.isEmpty())
{
- settings.setValue(KEY_SOURCE_DIR, recentlyUsed->sourceDirectory);
- settings.setValue(KEY_OUTPUT_DIR, recentlyUsed->outputDirectory);
- settings.setValue(KEY_FILTER_IDX, recentlyUsed->filterIndex);
- settings.sync();
+ const QString currentOutputExtn = QFileInfo(currentOutputFile).suffix();
+ const int tempIndex = getFilterIdx(currentOutputExtn);
+ if(tempIndex >= 0)
+ {
+ index = tempIndex;
+ }
}
+
+ return index;
}
+///////////////////////////////////////////////////////////////////////////////
+// Static functions
+///////////////////////////////////////////////////////////////////////////////
+
QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, const QString &destinationDirectory, const int filterIndex, const bool saveToSourceDir)
{
QString name = QFileInfo(sourceFilePath).completeBaseName();
if(!VALID_DIR(path))
{
RecentlyUsed defaults;
- initRecentlyUsed(&defaults);
- path = defaults.outputDirectory;
+ path = defaults.outputDirectory();
}
QString outPath = QString("%1/%2.%3").arg(path, name, fext);
/* ------------------------------------------------------------------------- */
-static const struct
-{
- const char *pcExt;
- const char *pcStr;
-}
-FILE_TYPE_FILTERS[] =
-{
- { "mkv", "Matroska Files" },
- { "mp4", "MPEG-4 Part 14 Container" },
- { "264", "H.264 Elementary Stream"},
- { NULL, NULL }
-};
-
QString AddJobDialog::getFilterExt(const int filterIndex)
{
- int count = 0;
- while((FILE_TYPE_FILTERS[count].pcExt) && (FILE_TYPE_FILTERS[count].pcStr)) count++;
+ const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
if((filterIndex >= 0) && (filterIndex < count))
{
- return QString::fromLatin1(FILE_TYPE_FILTERS[filterIndex].pcExt);
+ return QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcExt);
}
- return QString::fromLatin1(FILE_TYPE_FILTERS[0].pcExt);
+ return QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcExt);
}
int AddJobDialog::getFilterIdx(const QString &fileExt)
{
- for(int i = 0; (FILE_TYPE_FILTERS[i].pcExt && FILE_TYPE_FILTERS[i].pcStr); i++)
+ const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
+
+ for(int i = 0; i < count; i++)
{
- if(fileExt.compare(QString::fromLatin1(FILE_TYPE_FILTERS[i].pcExt), Qt::CaseInsensitive) == 0)
+ if(fileExt.compare(QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcExt), Qt::CaseInsensitive) == 0)
{
return i;
}
QString AddJobDialog::getFilterStr(const int filterIndex)
{
- int count = 0;
- while((FILE_TYPE_FILTERS[count].pcExt) && (FILE_TYPE_FILTERS[count].pcStr)) count++;
+ const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
if((filterIndex >= 0) && (filterIndex < count))
{
- return QString("%1 (*.%2)").arg(QString::fromLatin1(FILE_TYPE_FILTERS[filterIndex].pcStr), QString::fromLatin1(FILE_TYPE_FILTERS[filterIndex].pcExt));
+ return QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcExt));
}
- return QString("%1 (*.%2)").arg(QString::fromLatin1(FILE_TYPE_FILTERS[0].pcStr), QString::fromLatin1(FILE_TYPE_FILTERS[0].pcExt));
+ return QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcExt));
}
QString AddJobDialog::getFilterLst(void)
{
QStringList filters;
+ const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
- for(int i = 0; (FILE_TYPE_FILTERS[i].pcExt && FILE_TYPE_FILTERS[i].pcStr); i++)
+ for(int i = 0; i < count; i++)
{
- filters << QString("%1 (*.%2)").arg(QString::fromLatin1(FILE_TYPE_FILTERS[i].pcStr), QString::fromLatin1(FILE_TYPE_FILTERS[i].pcExt));
+ filters << QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcExt));
}
return filters.join(";;");
s_filters[] =
{
{"Avisynth Scripts", "avs"},
+ {"VapourSynth Scripts", "vpy"},
{"Matroska Files", "mkv"},
{"MPEG-4 Part 14 Container", "mp4"},
{"Audio Video Interleaved", "avi"},
{"Flash Video", "flv"},
{"YUV4MPEG2 Stream", "y4m"},
{"Uncompresses YUV Data", "yuv"},
- {NULL, NULL}
};
- QString filters("All supported files (");
+ const int count = ARRAY_SIZE(s_filters);
- for(size_t index = 0; (s_filters[index].name && s_filters[index].fext); index++)
+ QString allTypes;
+ for(size_t index = 0; index < count; index++)
{
- filters += QString((index > 0) ? " *.%1" : "*.%1").arg(QString::fromLatin1(s_filters[index].fext));
- }
- filters += QString(");;");
+ allTypes += QString((index > 0) ? " *.%1" : "*.%1").arg(QString::fromLatin1(s_filters[index].fext));
+ }
+
+ QStringList filters;
+ filters << QString("All supported files (%1)").arg(allTypes);
- for(size_t index = 0; s_filters[index].name && s_filters[index].fext; index++)
+ for(size_t index = 0; index < count; index++)
{
- filters += QString("%1 (*.%2);;").arg(QString::fromLatin1(s_filters[index].name), QString::fromLatin1(s_filters[index].fext));
+ filters << QString("%1 (*.%2)").arg(QString::fromLatin1(s_filters[index].name), QString::fromLatin1(s_filters[index].fext));
}
- filters += QString("All files (*.*)");
- return filters;
+ filters << QString("All files (*.*)");
+ return filters.join(";;");
}
+
+