OSDN Git Service

Bump NVEncC binaries to version 5.01 + added more supported profiles by new NVEncC...
[x264-launcher/x264-launcher.git] / src / win_addJob.cpp
index a0315b6..ccd9eb1 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // 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
+       DisableHelperRAII(bool *const flag) : m_flag(flag)
        {
-               input = input.simplified();
+               *m_flag = false;
        }
 
-protected:
-       QLabel *const m_notifier, *const m_icon;
-
-       bool checkParam(const QString &input, const QString &param, const bool doubleMinus) const
+       ~DisableHelperRAII(void)
        {
-               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;
+               *m_flag = true;
        }
 
-       const bool &setStatus(const bool &flag, const QString &toolName) const
-       {
-               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;
-       }
-};
-
-class StringValidatorX264 : public StringValidator
-{
-public:
-       StringValidatorX264(QLabel *notifier, QLabel *icon) : StringValidator(notifier, icon) {}
-
-       virtual State validate(QString &input, int &pos) const
-       {
-               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;
-       }
-};
-
-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;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -308,17 +246,17 @@ void AddJobDialog::showEvent(QShowEvent *event)
        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);
@@ -326,25 +264,25 @@ void AddJobDialog::showEvent(QShowEvent *event)
 
 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;
 }
@@ -393,9 +331,9 @@ void AddJobDialog::dropEvent(QDropEvent *event)
        
        if(!droppedFile.isEmpty())
        {
-               const QString outFileName = generateOutputFileName(droppedFile, currentOutputPath(), currentOutputIndx(), m_saveToSourceFolder);
-               editSource->setText(QDir::toNativeSeparators(droppedFile));
-               editOutput->setText(QDir::toNativeSeparators(outFileName));
+               const QString outFileName = generateOutputFileName(droppedFile, currentOutputPath(), currentOutputIndx(), m_preferences->getSaveToSourcePath());
+               ui->editSource->setText(QDir::toNativeSeparators(droppedFile));
+               ui->editOutput->setText(QDir::toNativeSeparators(outFileName));
        }
 }
 
@@ -403,21 +341,126 @@ void AddJobDialog::dropEvent(QDropEvent *event)
 // 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;
@@ -431,8 +474,47 @@ void AddJobDialog::accept(void)
                return;
        }
 
-       //Does output file already exist?
+       //Is the type of the source file supported?
+       const int sourceType = MediaInfo::analyze(sourceFile.canonicalFilePath());
+       if(sourceType == MediaInfo::FILETYPE_AVISYNTH)
+       {
+               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?
        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);
@@ -453,17 +535,17 @@ void AddJobDialog::accept(void)
        }
 
        //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->filterIndex = currentOutputIndx();
-       m_recentlyUsed->sourceDirectory = currentSourcePath();
-       m_recentlyUsed->outputDirectory = currentOutputPath();
-       saveRecentlyUsed(m_recentlyUsed);
+       m_recentlyUsed->setFilterIndex(currentOutputIndx());
+       m_recentlyUsed->setSourceDirectory(currentSourcePath());
+       m_recentlyUsed->setOutputDirectory(currentOutputPath());
+       RecentlyUsed::saveRecentlyUsed(m_recentlyUsed);
 
        //Save options
        saveOptions(m_options);
@@ -472,17 +554,17 @@ void AddJobDialog::accept(void)
 
 void AddJobDialog::browseButtonClicked(void)
 {
-       if(QObject::sender() == buttonBrowseSource)
+       if(QObject::sender() == ui->buttonBrowseSource)
        {
                QString filePath = QFileDialog::getOpenFileName(this, tr("Open Source File"), currentSourcePath(true), getInputFilterLst(), NULL, QFileDialog::DontUseNativeDialog);
                if(!(filePath.isNull() || filePath.isEmpty()))
                {
-                       QString destFile = generateOutputFileName(filePath, currentOutputPath(), currentOutputIndx(), m_saveToSourceFolder);
-                       editSource->setText(QDir::toNativeSeparators(filePath));
-                       editOutput->setText(QDir::toNativeSeparators(destFile));
+                       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 selectedType = getFilterStr(currentOutputIndx());
                QString filePath = QFileDialog::getSaveFileName(this, tr("Choose Output File"), currentOutputPath(true), getFilterLst(), &selectedType, QFileDialog::DontUseNativeDialog | QFileDialog::DontConfirmOverwrite);
@@ -499,83 +581,89 @@ void AddJobDialog::browseButtonClicked(void)
                                }
                                if(tempIndex < 0)
                                {
-                                       tempIndex = m_recentlyUsed->filterIndex;
+                                       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;
                        }
                }
@@ -584,12 +672,27 @@ void AddJobDialog::saveTemplateButtonClicked(void)
        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>"));
@@ -612,40 +715,38 @@ void AddJobDialog::saveTemplateButtonClicked(void)
                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('/'))
        {
@@ -653,17 +754,16 @@ void AddJobDialog::deleteTemplateButtonClicked(void)
                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)
@@ -681,7 +781,7 @@ void AddJobDialog::editorActionTriggered(void)
                        lineEdit->setText(editor->getEditText());
                }
 
-               X264_DELETE(editor);
+               MUTILS_DELETE(editor);
        }
 }
 
@@ -713,12 +813,46 @@ void AddJobDialog::pasteActionTriggered(void)
 
 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);
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -727,88 +861,124 @@ QString AddJobDialog::outputFile(void)
 
 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((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);
+       }
+}
 
-               if(templates.value(current)->equals(m_options))
+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);
-
-       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());
-
-       cbxRateControlMode->blockSignals(false);
-       spinQuantizer->blockSignals(false);
-       spinBitrate->blockSignals(false);
-       cbxPreset->blockSignals(false);
-       cbxTuning->blockSignals(false);
-       cbxProfile->blockSignals(false);
-       editCustomX264Params->blockSignals(false);
-       editCustomAvs2YUVParams->blockSignals(false);
+       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->spinQuantizer->setValue(options->quantizer());
+       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());
 }
 
 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());
 }
 
 QString AddJobDialog::currentSourcePath(const bool bWithName)
 {
-       QString path = m_recentlyUsed->sourceDirectory;
+       QString path = m_recentlyUsed->sourceDirectory();
        QString currentSourceFile = this->sourceFile();
        
        if(!currentSourceFile.isEmpty())
@@ -829,7 +999,7 @@ QString AddJobDialog::currentSourcePath(const bool bWithName)
 
 QString AddJobDialog::currentOutputPath(const bool bWithName)
 {
-       QString path = m_recentlyUsed->outputDirectory;
+       QString path = m_recentlyUsed->outputDirectory();
        QString currentOutputFile = this->outputFile();
        
        if(!currentOutputFile.isEmpty())
@@ -850,9 +1020,15 @@ QString AddJobDialog::currentOutputPath(const bool bWithName)
 
 int AddJobDialog::currentOutputIndx(void)
 {
-       int index = m_recentlyUsed->filterIndex;
-       QString currentOutputFile = this->outputFile();
+       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;
+       }
        
+       int index = m_recentlyUsed->filterIndex();
+       const QString currentOutputFile = this->outputFile();
+
        if(!currentOutputFile.isEmpty())
        {
                const QString currentOutputExtn = QFileInfo(currentOutputFile).suffix();
@@ -870,58 +1046,6 @@ int AddJobDialog::currentOutputIndx(void)
 // 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";
-
-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"},
-};
-
-/* ------------------------------------------------------------------------- */
-
-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)
-{
-       RecentlyUsed defaults;
-       initRecentlyUsed(&defaults);
-       
-       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();
-
-       if(!VALID_DIR(recentlyUsed->sourceDirectory)) recentlyUsed->sourceDirectory = defaults.sourceDirectory;
-       if(!VALID_DIR(recentlyUsed->outputDirectory)) recentlyUsed->outputDirectory = defaults.outputDirectory;
-       recentlyUsed->filterIndex = qBound(0, recentlyUsed->filterIndex, int(ARRAY_SIZE(FILE_TYPE_FILTERS)-1));
-}
-
-void AddJobDialog::saveRecentlyUsed(RecentlyUsed *recentlyUsed)
-{
-       QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
-       if(settings.isWritable())
-       {
-               settings.setValue(KEY_SOURCE_DIR, recentlyUsed->sourceDirectory);
-               settings.setValue(KEY_OUTPUT_DIR, recentlyUsed->outputDirectory);
-               settings.setValue(KEY_FILTER_IDX, recentlyUsed->filterIndex);
-               settings.sync();
-       }
-}
-
 QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, const QString &destinationDirectory, const int filterIndex, const bool saveToSourceDir)
 {
        QString name = QFileInfo(sourceFilePath).completeBaseName();
@@ -931,8 +1055,7 @@ QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, cons
        if(!VALID_DIR(path))
        {
                RecentlyUsed defaults;
-               initRecentlyUsed(&defaults);
-               path = defaults.outputDirectory;
+               path = defaults.outputDirectory();
        }
 
        QString outPath = QString("%1/%2.%3").arg(path, name, fext);
@@ -950,23 +1073,23 @@ QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, cons
 
 QString AddJobDialog::getFilterExt(const int filterIndex)
 {
-       const int count = ARRAY_SIZE(FILE_TYPE_FILTERS);
+       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)
 {
-       const int count = ARRAY_SIZE(FILE_TYPE_FILTERS);
+       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;
                }
@@ -977,24 +1100,24 @@ int AddJobDialog::getFilterIdx(const QString &fileExt)
 
 QString AddJobDialog::getFilterStr(const int filterIndex)
 {
-       const int count = ARRAY_SIZE(FILE_TYPE_FILTERS);
+       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(FILE_TYPE_FILTERS);
+       const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
        
        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(";;");
@@ -1010,6 +1133,7 @@ QString AddJobDialog::getInputFilterLst(void)
        s_filters[] =
        {
                {"Avisynth Scripts", "avs"},
+               {"VapourSynth Scripts", "vpy"},
                {"Matroska Files", "mkv"},
                {"MPEG-4 Part 14 Container", "mp4"},
                {"Audio Video Interleaved", "avi"},
@@ -1018,7 +1142,7 @@ QString AddJobDialog::getInputFilterLst(void)
                {"Uncompresses YUV Data", "yuv"},
        };
 
-       const int count = ARRAY_SIZE(FILE_TYPE_FILTERS);
+       const int count = ARRAY_SIZE(s_filters);
 
        QString allTypes;
        for(size_t index = 0; index < count; index++)
@@ -1038,3 +1162,5 @@ QString AddJobDialog::getInputFilterLst(void)
        filters << QString("All files (*.*)");
        return filters.join(";;");
 }
+
+