///////////////////////////////////////////////////////////////////////////////
// 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 <QDir>
#include <QInputDialog>
#include <QSettings>
+#include <QUrl>
+#include <QAction>
+#include <QClipboard>
+#include <QToolTip>
-static const struct
-{
- const char *name;
- const char *fext;
-}
-g_filters[] =
-{
- {"Avisynth Scripts", "avs"},
- {"Matroska Files", "mkv"},
- {"MPEG-4 Part 14 Container", "mp4"},
- {"Audio Video Interleaved", "avi"},
- {"Flash Video", "flv"},
- {NULL, NULL}
-};
+#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; \
} \
} \
}
+#define ADD_CONTEXTMENU_ACTION(WIDGET, ICON, TEXT, SLOTNAME) \
+{ \
+ QAction *_action = new QAction((ICON), (TEXT), this); \
+ _action->setData(QVariant::fromValue<void*>(WIDGET)); \
+ WIDGET->addAction(_action); \
+ connect(_action, SIGNAL(triggered(bool)), this, SLOT(SLOTNAME())); \
+}
+
+#define ADD_CONTEXTMENU_SEPARATOR(WIDGET) \
+{ \
+ QAction *_action = new QAction(this); \
+ _action->setSeparator(true); \
+ WIDGET->addAction(_action); \
+}
+
+Q_DECLARE_METATYPE(const void*)
+
///////////////////////////////////////////////////////////////////////////////
-// Validator
+// Disable Monitoring RAII
///////////////////////////////////////////////////////////////////////////////
-class StringValidator : public QValidator
+class DisableHelperRAII
{
public:
- StringValidator(QLabel *notifier) : m_notifier(notifier) { m_notifier->hide(); }
-
- virtual State validate(QString &input, int &pos) const
+ DisableHelperRAII(bool *const flag) : m_flag(flag)
{
- bool invalid = false;
-
- invalid = invalid || (input.contains(" -B") || input.startsWith("-B"));
- invalid = invalid || (input.contains(" -o") || input.startsWith("-o"));
- invalid = invalid || (input.contains(" -h") || input.startsWith("-h"));
- invalid = invalid || (input.contains(" -p") || input.startsWith("-p"));
-
- invalid = invalid || input.contains("--fps", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--frames", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--preset", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--tune", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--profile", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--stdin", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--crf", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--bitrate", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--qp", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--pass", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--stats", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--output", Qt::CaseInsensitive);
- invalid = invalid || input.contains("--help", Qt::CaseInsensitive);
-
- if(invalid)
- {
- MessageBeep(MB_ICONWARNING);
- if(m_notifier->isHidden())
- {
- m_notifier->show();
- QTimer::singleShot(1000, m_notifier, SLOT(hide()));
- }
- }
-
- return invalid ? QValidator::Invalid : QValidator::Acceptable;
+ *m_flag = false;
}
- virtual void fixup(QString &input) const
+ ~DisableHelperRAII(void)
{
- input = input.simplified();
+ *m_flag = true;
}
-protected:
- QLabel *const m_notifier;
+private:
+ bool *const m_flag;
};
///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor
///////////////////////////////////////////////////////////////////////////////
-AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *options, bool x64supported)
+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),
- initialDir_src(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation)),
- initialDir_out(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation))
-
+ 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());
- //Monitor RC mode combobox
- connect(cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(modeIndexChanged(int)));
+ //Init encoder combobox
+ ui->cbxEncoderType->addItem(tr("x264 (AVC)"), OptionsModel::EncType_X264);
+ ui->cbxEncoderType->addItem(tr("x265 (HEVC)"), OptionsModel::EncType_X265);
+ ui->cbxEncoderType->addItem(tr("NVEncC"), OptionsModel::EncType_NVEnc);
+
+ //Init combobox items
+ ui->cbxTuning ->addItem(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED));
+ ui->cbxProfile->addItem(QString::fromLatin1(OptionsModel::PROFILE_UNRESTRICTED));
+
+ //Hide optional controls
+ ui->checkBoxApplyToAll->setVisible(false);
+
+ //Monitor combobox changes
+ connect(ui->cbxEncoderType, SIGNAL(currentIndexChanged(int)), this, SLOT(encoderIndexChanged(int)));
+ connect(ui->cbxEncoderVariant, SIGNAL(currentIndexChanged(int)), this, SLOT(variantIndexChanged(int)));
+ connect(ui->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
- editCustomParams->installEventFilter(this);
- editCustomParams->setValidator(new StringValidator(labelNotification));
- editCustomParams->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
- labelHelpScreen->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(int)), 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(editCustomParams, 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(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()));
- //Load directories
- const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- QSettings settings(QString("%1/last.ini").arg(appDir), QSettings::IniFormat);
- initialDir_src = settings.value("path/directory_openFrom", initialDir_src).toString();
- initialDir_out = settings.value("path/directory_saveTo", initialDir_out).toString();
+ //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);
}
-
- X264_DELETE(m_defaults);
+
+ //Free validators
+ if(const QValidator *tmp = ui->editCustomX264Params->validator())
+ {
+ ui->editCustomX264Params->setValidator(NULL);
+ MUTILS_DELETE(tmp);
+ }
+ if(const QValidator *tmp = ui->editCustomAvs2YUVParams->validator())
+ {
+ ui->editCustomAvs2YUVParams->setValidator(NULL);
+ MUTILS_DELETE(tmp);
+ }
+
+ MUTILS_DELETE(m_defaults);
+ delete ui;
}
///////////////////////////////////////////////////////////////////////////////
QDialog::showEvent(event);
templateSelected();
- if(!editSource->text().isEmpty()) initialDir_src = QFileInfo(QDir::fromNativeSeparators(editSource->text())).path();
- if(!editOutput->text().isEmpty()) initialDir_out = QFileInfo(QDir::fromNativeSeparators(editOutput->text())).path();
-
- if((!editSource->text().isEmpty()) && editOutput->text().isEmpty())
+ if((!ui->editSource->text().isEmpty()) && ui->editOutput->text().isEmpty())
{
- generateOutputFileName(QDir::fromNativeSeparators(editSource->text()));
- 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();
}
+
+ 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 == labelHelpScreen) && (e->type() == QEvent::MouseButtonPress))
+ if((o == ui->labelHelpScreenX264) && (e->type() == QEvent::MouseButtonPress))
+ {
+ OptionsModel options(m_sysinfo); saveOptions(&options);
+ QScopedPointer<HelpDialog> helpScreen(new HelpDialog(this, false, m_sysinfo, &options, m_preferences));
+ helpScreen->exec();
+ }
+ else if((o == ui->labelHelpScreenAvs2YUV) && (e->type() == QEvent::MouseButtonPress))
{
- HelpDialog *helpScreen = new HelpDialog(this, m_x64supported);
+ 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 == editCustomParams) && (e->type() == QEvent::FocusOut))
+ else if((o == ui->editCustomX264Params) && (e->type() == QEvent::FocusOut))
{
- editCustomParams->setText(editCustomParams->text().simplified());
+ ui->editCustomX264Params->setText(ui->editCustomX264Params->text().simplified());
+ }
+ else if((o == ui->editCustomAvs2YUVParams) && (e->type() == QEvent::FocusOut))
+ {
+ ui->editCustomAvs2YUVParams->setText(ui->editCustomAvs2YUVParams->text().simplified());
}
return false;
}
+void AddJobDialog::dragEnterEvent(QDragEnterEvent *event)
+{
+ bool accept[2] = {false, false};
+
+ foreach(const QString &fmt, event->mimeData()->formats())
+ {
+ accept[0] = accept[0] || fmt.contains("text/uri-list", Qt::CaseInsensitive);
+ accept[1] = accept[1] || fmt.contains("FileNameW", Qt::CaseInsensitive);
+ }
+
+ if(accept[0] && accept[1])
+ {
+ event->acceptProposedAction();
+ }
+}
+
+void AddJobDialog::dropEvent(QDropEvent *event)
+{
+ QString droppedFile;
+ QList<QUrl> urls = event->mimeData()->urls();
+
+ if(urls.count() > 1)
+ {
+ QDragEnterEvent dragEvent(event->pos(), event->proposedAction(), event->mimeData(), Qt::NoButton, Qt::NoModifier);
+ if(qApp->notify(parent(), &dragEvent))
+ {
+ qApp->notify(parent(), event);
+ reject(); return;
+ }
+ }
+
+ while((!urls.isEmpty()) && droppedFile.isEmpty())
+ {
+ QUrl currentUrl = urls.takeFirst();
+ QFileInfo file(currentUrl.toLocalFile());
+ if(file.exists() && file.isFile())
+ {
+ qDebug("AddJobDialog::dropEvent: %s", file.canonicalFilePath().toUtf8().constData());
+ droppedFile = file.canonicalFilePath();
+ }
+ }
+
+ if(!droppedFile.isEmpty())
+ {
+ 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)
{
- if(editSource->text().trimmed().isEmpty())
+ //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)
{
- QMessageBox::warning(this, tr("Not Found!"), tr("Please select a valid source file first!"));
- return;
+ if (!m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64))
+ {
+ QMessageBox::warning(this, tr("64-Bit unsupported!"), tr("<nobr>Sorry, this computer does <b>not</b> support 64-Bit encoders!</nobr>"));
+ ui->cbxEncoderArch->setCurrentIndex(AbstractEncoderInfo::ARCH_TYPE_X86);
+ return;
+ }
}
- if(editOutput->text().trimmed().isEmpty())
+ //Selection complete?
+ if(ui->editSource->text().trimmed().isEmpty())
{
- QMessageBox::warning(this, tr("Not Selected!"), tr("Please select a valid output file first!"));
+ QMessageBox::warning(this, tr("Not Found!"), tr("<nobr>Please select a valid source file first!<(nobr>"));
return;
}
-
- QFileInfo sourceFile = QFileInfo(editSource->text());
- if(!(sourceFile.exists() && sourceFile.isFile()))
+ if(ui->editOutput->text().trimmed().isEmpty())
{
- QMessageBox::warning(this, tr("Not Found!"), tr("The selected source file could not be found!"));
+ QMessageBox::warning(this, tr("Not Selected!"), tr("<nobr>Please select a valid output file first!</nobr>"));
return;
}
- QFileInfo outputDir = QFileInfo(QFileInfo(editOutput->text()).path());
- if(!(outputDir.exists() && outputDir.isDir() && outputDir.isWritable()))
+ //Does source exist?
+ QFileInfo sourceFile = QFileInfo(this->sourceFile());
+ if(!(sourceFile.exists() && sourceFile.isFile()))
{
- QMessageBox::warning(this, tr("Not Writable!"), tr("Output directory does not exist or is not writable!"));
+ QMessageBox::warning(this, tr("Not Found!"), tr("<nobr>The selected source file could not be found!</nobr>"));
return;
}
- QFileInfo outputFile = QFileInfo(editOutput->text());
- if(outputFile.exists() && outputFile.isFile())
+ //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::question(this, tr("Already Exists!"), tr("Output file already exists! Overwrite?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
+ 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);
+ if(ret != QMessageBox::Yes) return;
+ }
if(outputFile.exists() && (!outputFile.isFile()))
{
- QMessageBox::warning(this, tr("Not a File!"), tr("Selected output files does not appear to be a file!"));
+ QMessageBox::warning(this, tr("Not a File!"), tr("<nobr>Selected output file does not appear to be a valid file!</nobr>"));
+ 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;
}
- //Save directories
- const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- QSettings settings(QString("%1/last.ini").arg(appDir), QSettings::IniFormat);
- if(settings.isWritable())
+ //Custom parameters okay?
+ if(!ui->editCustomX264Params->hasAcceptableInput())
{
- settings.setValue("path/directory_openFrom", initialDir_src);
- settings.setValue("path/directory_saveTo", initialDir_out);
- settings.sync();
+ 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->setFilterIndex(currentOutputIndx());
+ m_recentlyUsed->setSourceDirectory(currentSourcePath());
+ m_recentlyUsed->setOutputDirectory(currentOutputPath());
+ RecentlyUsed::saveRecentlyUsed(m_recentlyUsed);
+
+ //Save options
saveOptions(m_options);
QDialog::accept();
}
void AddJobDialog::browseButtonClicked(void)
{
- if(QObject::sender() == buttonBrowseSource)
+ if(QObject::sender() == ui->buttonBrowseSource)
{
- QString filePath = QFileDialog::getOpenFileName(this, tr("Open Source File"), VALID_DIR(initialDir_src) ? initialDir_src : QDesktopServices::storageLocation(QDesktopServices::MoviesLocation), makeFileFilter(), 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));
- generateOutputFileName(filePath);
- initialDir_src = QFileInfo(filePath).path();
+ 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 filters;
- filters += tr("Matroska Files (*.mkv)").append(";;");
- filters += tr("MPEG-4 Part 14 Container (*.mp4)").append(";;");
- filters += tr("H.264 Elementary Stream (*.264)");
-
- QString filePath = QFileDialog::getSaveFileName(this, tr("Choose Output File"), VALID_DIR(initialDir_out) ? initialDir_out : QDesktopServices::storageLocation(QDesktopServices::MoviesLocation), filters, NULL, 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()))
{
- QString suffix = QFileInfo(filePath).suffix();
- if(suffix.compare("mkv", Qt::CaseInsensitive) && suffix.compare("mp4", Qt::CaseInsensitive) && suffix.compare("264", Qt::CaseInsensitive))
+ if(getFilterIdx(QFileInfo(filePath).suffix()) < 0)
{
- filePath = QString("%1.mkv").arg(filePath);
+ 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));
- initialDir_out = QFileInfo(filePath).path();
+ 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");
- OptionsModel *options = new OptionsModel();
- saveOptions(options);
+ QString name = m_lastTemplateName;
+ if(name.isEmpty() || name.contains('<') || name.contains('>'))
+ {
+ name = tr("New Template");
+ int n = 1;
+ while(OptionsModel::templateExists(name))
+ {
+ name = tr("New Template (%1)").arg(QString::number(++n));
+ }
+ }
+
+ QScopedPointer<OptionsModel> options(new OptionsModel(m_sysinfo));
+ saveOptions(options.data());
if(options->equals(m_defaults))
{
- QMessageBox::warning (this, tr("Default"), tr("It makes no sense to save the defaults!"));
- cbxTemplate->blockSignals(true);
- cbxTemplate->setCurrentIndex(0);
- cbxTemplate->blockSignals(false);
+ QMessageBox::warning (this, tr("Oups"), tr("<nobr>It makes no sense to save the default settings!</nobr>"));
+ 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++)
{
- OptionsModel* test = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>());
+ const QString tempName = ui->cbxTemplate->itemText(i);
+ if(tempName.contains('<') || tempName.contains('>'))
+ {
+ continue;
+ }
+ 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!"));
- 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(160, ' '), 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("Sorry, the name you have entered is invalid!"));
+ QMessageBox::warning (this, tr("Invalid Name"), tr("<nobr>Sorry, the name you have entered is invalid!</nobr>"));
while(name.contains('<')) name.remove('<');
while(name.contains('>')) name.remove('>');
while(name.contains('\\')) name.remove('\\');
}
if(OptionsModel::templateExists(name))
{
- QMessageBox::warning (this, tr("Already Exists"), tr("Sorry, a template of that name already exists!"));
- continue;
+ int ret = QMessageBox::warning (this, tr("Already Exists"), tr("<nobr>A template of that name already exists! Overwrite?</nobr>"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ if(ret != QMessageBox::Yes)
+ {
+ continue;
+ }
}
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);
- cbxTemplate->insertItem(index, name, QVariant::fromValue<void*>(options));
- cbxTemplate->setCurrentIndex(index);
- cbxTemplate->blockSignals(false);
+ ui->cbxTemplate->blockSignals(true);
+ for(int i = 0; i < ui->cbxTemplate->count(); i++)
+ {
+ if(ui->cbxTemplate->itemText(i).compare(name, Qt::CaseInsensitive) == 0)
+ {
+ 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(!options.isNull())
+ {
+ const int index = ui->cbxTemplate->model()->rowCount();
+ ui->cbxTemplate->insertItem(index, name, QVariant::fromValue<const void*>(options.take()));
+ ui->cbxTemplate->setCurrentIndex(index);
+ }
+ ui->cbxTemplate->blockSignals(false);
+ m_lastTemplateName = name;
REMOVE_USAFED_ITEM;
}
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('>'))
+ if(name.contains('<') || name.contains('>') || name.contains('\\') || name.contains('/'))
{
QMessageBox::warning (this, tr("Invalid Item"), tr("Sorry, the selected item cannot be deleted!"));
return;
}
+ 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)
+{
+
+ if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
+ {
+ QLineEdit *lineEdit = reinterpret_cast<QLineEdit*>(action->data().value<void*>());
+
+ EditorDialog *editor = new EditorDialog(this);
+ editor->setEditText(lineEdit->text());
+
+ if(editor->exec() == QDialog::Accepted)
+ {
+ lineEdit->setText(editor->getEditText());
+ }
+
+ MUTILS_DELETE(editor);
+ }
+}
+
+void AddJobDialog::copyActionTriggered(void)
+{
+ if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
+ {
+ QClipboard *clipboard = QApplication::clipboard();
+ QLineEdit *lineEdit = reinterpret_cast<QLineEdit*>(action->data().value<void*>());
+ QString text = lineEdit->hasSelectedText() ? lineEdit->selectedText() : lineEdit->text();
+ clipboard->setText(text);
+ }
+}
+
+void AddJobDialog::pasteActionTriggered(void)
+{
+ if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
+ {
+ QClipboard *clipboard = QApplication::clipboard();
+ QLineEdit *lineEdit = reinterpret_cast<QLineEdit*>(action->data().value<void*>());
+ QString text = clipboard->text();
+ if(!text.isEmpty()) lineEdit->setText(text);
+ }
}
///////////////////////////////////////////////////////////////////////////////
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);
- editCustomParams->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());
- editCustomParams->setText(options->custom());
+ 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);
- editCustomParams->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->setCustom(editCustomParams->text().simplified());
+ 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::makeFileFilter(void)
+QString AddJobDialog::currentSourcePath(const bool bWithName)
{
- QString filters("All supported files (");
+ QString path = m_recentlyUsed->sourceDirectory();
+ QString currentSourceFile = this->sourceFile();
+
+ if(!currentSourceFile.isEmpty())
+ {
+ QString currentSourceDir = QFileInfo(currentSourceFile).absolutePath();
+ if(VALID_DIR(currentSourceDir))
+ {
+ path = currentSourceDir;
+ }
+ if(bWithName)
+ {
+ path.append("/").append(QFileInfo(currentSourceFile).fileName());
+ }
+ }
+
+ return path;
+}
- for(size_t index = 0; g_filters[index].name && g_filters[index].fext; index++)
+QString AddJobDialog::currentOutputPath(const bool bWithName)
+{
+ QString path = m_recentlyUsed->outputDirectory();
+ QString currentOutputFile = this->outputFile();
+
+ if(!currentOutputFile.isEmpty())
{
- filters += QString((index > 0) ? " *.%1" : "*.%1").arg(QString::fromLatin1(g_filters[index].fext));
+ QString currentOutputDir = QFileInfo(currentOutputFile).absolutePath();
+ if(VALID_DIR(currentOutputDir))
+ {
+ path = currentOutputDir;
+ }
+ if(bWithName)
+ {
+ path.append("/").append(QFileInfo(currentOutputFile).fileName());
+ }
}
- filters += QString(");;");
+ return path;
+}
- for(size_t index = 0; g_filters[index].name && g_filters[index].fext; index++)
+int AddJobDialog::currentOutputIndx(void)
+{
+ const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
+ if(encType == OptionsModel::EncType_X265)
{
- filters += QString("%1 (*.%2);;").arg(QString::fromLatin1(g_filters[index].name), QString::fromLatin1(g_filters[index].fext));
+ return ARRAY_SIZE(X264_FILE_TYPE_FILTERS) - 1;
}
-
- filters += QString("All files (*.*)");
- return filters;
+
+ int index = m_recentlyUsed->filterIndex();
+ const QString currentOutputFile = this->outputFile();
+
+ if(!currentOutputFile.isEmpty())
+ {
+ 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();
+ QString path = saveToSourceDir ? QFileInfo(sourceFilePath).canonicalPath() : destinationDirectory;
+ QString fext = getFilterExt(filterIndex);
+
+ if(!VALID_DIR(path))
+ {
+ RecentlyUsed defaults;
+ path = defaults.outputDirectory();
+ }
+
+ QString outPath = QString("%1/%2.%3").arg(path, name, fext);
+
+ int n = 2;
+ while(QFileInfo(outPath).exists())
+ {
+ outPath = QString("%1/%2 (%3).%4").arg(path, name, QString::number(n++), fext);
+ }
+
+ return outPath;
+}
+
+/* ------------------------------------------------------------------------- */
+
+QString AddJobDialog::getFilterExt(const int filterIndex)
+{
+ const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
+
+ if((filterIndex >= 0) && (filterIndex < count))
+ {
+ return QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcExt);
+ }
+
+ return QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcExt);
}
-void AddJobDialog::generateOutputFileName(const QString &filePath)
+int AddJobDialog::getFilterIdx(const QString &fileExt)
{
- QString name = QFileInfo(filePath).completeBaseName();
- QString path = VALID_DIR(initialDir_out) ? initialDir_out : QFileInfo(filePath).path();
-
- QString outPath = QString("%1/%2.mkv").arg(path, name);
+ const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
- if(QFileInfo(outPath).exists())
+ for(int i = 0; i < count; i++)
{
- int i = 2;
- while(QFileInfo(outPath).exists())
+ if(fileExt.compare(QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcExt), Qt::CaseInsensitive) == 0)
{
- outPath = QString("%1/%2 (%3).mkv").arg(path, name, QString::number(i++));
+ return i;
}
}
- editOutput->setText(QDir::toNativeSeparators(outPath));
+ return -1;
+}
+
+QString AddJobDialog::getFilterStr(const int filterIndex)
+{
+ const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
+
+ if((filterIndex >= 0) && (filterIndex < count))
+ {
+ 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(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; i < count; i++)
+ {
+ filters << QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcExt));
+ }
+
+ return filters.join(";;");
+}
+
+QString AddJobDialog::getInputFilterLst(void)
+{
+ static const struct
+ {
+ const char *name;
+ const char *fext;
+ }
+ 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"},
+ };
+
+ const int count = ARRAY_SIZE(s_filters);
+
+ QString allTypes;
+ for(size_t index = 0; index < count; index++)
+ {
+
+ 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; index < count; index++)
+ {
+ filters << QString("%1 (*.%2)").arg(QString::fromLatin1(s_filters[index].name), QString::fromLatin1(s_filters[index].fext));
+ }
+
+ filters << QString("All files (*.*)");
+ return filters.join(";;");
+}
+
+