2012-01-29 04:06:07 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Simple x264 Launcher
|
|
|
|
// Copyright (C) 2004-2012 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
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "win_addJob.h"
|
|
|
|
|
|
|
|
#include "global.h"
|
2012-01-29 19:14:46 +01:00
|
|
|
#include "model_options.h"
|
2012-01-29 04:06:07 +01:00
|
|
|
|
|
|
|
#include <QDate>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QMessageBox>
|
2012-01-29 15:57:23 +01:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QValidator>
|
2012-01-29 21:31:09 +01:00
|
|
|
#include <QDir>
|
2012-01-29 15:57:23 +01:00
|
|
|
|
2012-01-30 17:50:19 +01:00
|
|
|
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}
|
|
|
|
};
|
|
|
|
|
2012-01-29 15:57:23 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Validator
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class StringValidator : public QValidator
|
|
|
|
{
|
|
|
|
virtual State validate(QString &input, int &pos) const
|
|
|
|
{
|
|
|
|
bool invalid = input.simplified().compare(input) && input.simplified().append(" ").compare(input) &&
|
|
|
|
input.simplified().prepend(" ").compare(input) && input.simplified().append(" ").prepend(" ").compare(input);
|
|
|
|
|
|
|
|
if(!invalid)
|
|
|
|
{
|
|
|
|
invalid = invalid || input.contains("--fps");
|
|
|
|
invalid = invalid || input.contains("--frames");
|
|
|
|
invalid = invalid || input.contains("--preset");
|
|
|
|
invalid = invalid || input.contains("--tune");
|
|
|
|
invalid = invalid || input.contains("--profile");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(invalid) MessageBeep(MB_ICONWARNING);
|
|
|
|
return invalid ? QValidator::Invalid : QValidator::Acceptable;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void fixup(QString &input) const
|
|
|
|
{
|
|
|
|
input = input.simplified();
|
|
|
|
}
|
|
|
|
};
|
2012-01-29 04:06:07 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constructor & Destructor
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-29 19:14:46 +01:00
|
|
|
AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *options)
|
2012-01-29 04:06:07 +01:00
|
|
|
:
|
2012-01-29 19:14:46 +01:00
|
|
|
QDialog(parent),
|
2012-01-31 03:03:17 +01:00
|
|
|
m_defaults(new OptionsModel()),
|
2012-01-29 19:14:46 +01:00
|
|
|
m_options(options)
|
2012-01-29 04:06:07 +01:00
|
|
|
{
|
|
|
|
//Init the dialog, from the .ui file
|
|
|
|
setupUi(this);
|
2012-01-29 19:14:46 +01:00
|
|
|
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
2012-01-29 04:06:07 +01:00
|
|
|
|
|
|
|
//Fix dialog size
|
2012-01-31 03:03:17 +01:00
|
|
|
buttonSaveTemplate->setMaximumHeight(20);
|
|
|
|
buttonDeleteTemplate->setMaximumHeight(20);
|
2012-01-29 04:06:07 +01:00
|
|
|
resize(width(), minimumHeight());
|
|
|
|
setMinimumSize(size());
|
|
|
|
setMaximumHeight(height());
|
|
|
|
|
2012-01-31 03:03:17 +01:00
|
|
|
//Monitor RC mode combobox
|
2012-01-29 04:06:07 +01:00
|
|
|
connect(cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(modeIndexChanged(int)));
|
2012-01-29 15:57:23 +01:00
|
|
|
|
|
|
|
//Activate buttons
|
|
|
|
connect(buttonBrowseSource, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
|
|
|
|
connect(buttonBrowseOutput, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
|
|
|
|
|
|
|
|
//Setup validator
|
2012-01-31 03:03:17 +01:00
|
|
|
editCustomParams->setValidator(new StringValidator());
|
|
|
|
editCustomParams->clear();
|
2012-01-31 00:13:32 +01:00
|
|
|
|
|
|
|
//Install event filter
|
|
|
|
labelHelpScreen->installEventFilter(this);
|
2012-01-31 03:03:17 +01:00
|
|
|
|
|
|
|
//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()));
|
|
|
|
|
|
|
|
//Monitor template
|
|
|
|
cbxTemplate->insertItem(0, tr("<Default>"), QVariant::fromValue<void*>(m_defaults));
|
|
|
|
cbxTemplate->setCurrentIndex(0);
|
|
|
|
if(!m_options->equals(m_defaults))
|
|
|
|
{
|
|
|
|
cbxTemplate->insertItem(1, tr("<Recently Used>"), QVariant::fromValue<void*>(m_options));
|
|
|
|
cbxTemplate->setCurrentIndex(1);
|
|
|
|
}
|
|
|
|
connect(cbxTemplate, SIGNAL(currentIndexChanged(int)), this, SLOT(templateSelected()));
|
2012-01-29 04:06:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AddJobDialog::~AddJobDialog(void)
|
|
|
|
{
|
2012-01-31 03:03:17 +01:00
|
|
|
X264_DELETE(m_defaults);
|
2012-01-29 04:06:07 +01:00
|
|
|
}
|
|
|
|
|
2012-01-29 15:57:23 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Events
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-29 04:06:07 +01:00
|
|
|
void AddJobDialog::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
QDialog::showEvent(event);
|
2012-01-31 03:03:17 +01:00
|
|
|
templateSelected();
|
2012-01-29 04:06:07 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 00:13:32 +01:00
|
|
|
bool AddJobDialog::eventFilter(QObject *o, QEvent *e)
|
|
|
|
{
|
|
|
|
if((o == labelHelpScreen) && (e->type() == QEvent::MouseButtonPress))
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("Not yet"), tr("Not implemented yet. Please use the '?' menu for now!"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-29 15:57:23 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Slots
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-29 04:06:07 +01:00
|
|
|
void AddJobDialog::modeIndexChanged(int index)
|
|
|
|
{
|
|
|
|
spinQuantizer->setEnabled(index == 0 || index == 1);
|
|
|
|
spinBitrate->setEnabled(index == 2 || index == 3);
|
|
|
|
}
|
2012-01-29 15:57:23 +01:00
|
|
|
|
|
|
|
void AddJobDialog::accept(void)
|
|
|
|
{
|
|
|
|
if(editSource->text().trimmed().isEmpty())
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Not Found!"), tr("Please select a valid source file first!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo sourceFile = QFileInfo(editSource->text());
|
|
|
|
if(!(sourceFile.exists() && sourceFile.isFile()))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Not Found!"), tr("The selected source file could not be found!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo outputDir = QFileInfo(QFileInfo(editOutput->text()).path());
|
|
|
|
if(!(outputDir.exists() && outputDir.isDir() && outputDir.isWritable()))
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Not Writable!"), tr("Output directory does not exist or is not writable!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileInfo outputFile = QFileInfo(editOutput->text());
|
|
|
|
if(outputFile.exists() && outputFile.isFile())
|
|
|
|
{
|
|
|
|
if(QMessageBox::question(this, tr("Already Exists!"), tr("Output file already exists! Overwrite?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != 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!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-29 19:14:46 +01:00
|
|
|
saveOptions(m_options);
|
2012-01-29 15:57:23 +01:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddJobDialog::browseButtonClicked(void)
|
|
|
|
{
|
|
|
|
QString initialDir = QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);
|
|
|
|
|
|
|
|
if(QObject::sender() == buttonBrowseSource)
|
|
|
|
{
|
2012-01-30 17:50:19 +01:00
|
|
|
QString filePath = QFileDialog::getOpenFileName(this, tr("Open Source File"), initialDir, makeFileFilter());
|
|
|
|
|
2012-01-29 15:57:23 +01:00
|
|
|
if(!(filePath.isNull() || filePath.isEmpty()))
|
|
|
|
{
|
2012-01-29 21:31:09 +01:00
|
|
|
editSource->setText(QDir::toNativeSeparators(filePath));
|
2012-01-29 15:57:23 +01:00
|
|
|
|
|
|
|
QString path = QFileInfo(filePath).path();
|
|
|
|
QString name = QFileInfo(filePath).completeBaseName();
|
|
|
|
|
|
|
|
QString outPath = QString("%1/%2.mkv").arg(path, name);
|
|
|
|
|
|
|
|
if(QFileInfo(outPath).exists())
|
|
|
|
{
|
|
|
|
int i = 2;
|
|
|
|
while(QFileInfo(outPath).exists())
|
|
|
|
{
|
|
|
|
outPath = QString("%1/%2 (%3).mkv").arg(path, name, QString::number(i++));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-29 21:31:09 +01:00
|
|
|
editOutput->setText(QDir::toNativeSeparators(outPath));
|
2012-01-29 15:57:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(QObject::sender() == buttonBrowseOutput)
|
|
|
|
{
|
|
|
|
QString filters;
|
|
|
|
filters += tr("Matroska Files (*.mkv)").append(";;");
|
|
|
|
filters += tr("MPEG-4 Part 14 Container (*.mp4)").append(";;");
|
2012-01-30 17:50:19 +01:00
|
|
|
filters += tr("H.264 Elementary Stream (*.264)");
|
2012-01-29 15:57:23 +01:00
|
|
|
|
|
|
|
QString filePath = QFileDialog::getSaveFileName(this, tr("Choose Output File"), initialDir, filters);
|
|
|
|
|
|
|
|
if(!(filePath.isNull() || filePath.isEmpty()))
|
|
|
|
{
|
2012-01-29 21:31:09 +01:00
|
|
|
editOutput->setText(QDir::toNativeSeparators(filePath));
|
2012-01-29 15:57:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-29 19:14:46 +01:00
|
|
|
|
2012-01-31 03:03:17 +01:00
|
|
|
void AddJobDialog::configurationChanged(void)
|
|
|
|
{
|
|
|
|
OptionsModel* options = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(cbxTemplate->currentIndex()).value<void*>());
|
|
|
|
if(options)
|
|
|
|
{
|
|
|
|
cbxTemplate->blockSignals(true);
|
|
|
|
cbxTemplate->insertItem(0, tr("<Unsaved Configuration>"), QVariant::fromValue<void*>(NULL));
|
|
|
|
cbxTemplate->setCurrentIndex(0);
|
|
|
|
cbxTemplate->blockSignals(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddJobDialog::templateSelected(void)
|
|
|
|
{
|
|
|
|
OptionsModel* options = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(cbxTemplate->currentIndex()).value<void*>());
|
|
|
|
if(options)
|
|
|
|
{
|
|
|
|
qDebug("Loading options!");
|
|
|
|
for(int i = 0; i < cbxTemplate->model()->rowCount(); i++)
|
|
|
|
{
|
|
|
|
OptionsModel* temp = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>());
|
|
|
|
if(temp == NULL)
|
|
|
|
{
|
|
|
|
cbxTemplate->blockSignals(true);
|
|
|
|
cbxTemplate->removeItem(i);
|
|
|
|
cbxTemplate->blockSignals(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
restoreOptions(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
modeIndexChanged(cbxRateControlMode->currentIndex());
|
|
|
|
}
|
|
|
|
|
2012-01-29 21:31:09 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Public functions
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
QString AddJobDialog::sourceFile(void)
|
|
|
|
{
|
|
|
|
return QDir::fromNativeSeparators(editSource->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AddJobDialog::outputFile(void)
|
|
|
|
{
|
|
|
|
return QDir::fromNativeSeparators(editOutput->text());
|
|
|
|
}
|
|
|
|
|
2012-01-29 19:14:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private functions
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void AddJobDialog::updateComboBox(QComboBox *cbox, const QString &text)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < cbox->model()->rowCount(); i++)
|
|
|
|
{
|
|
|
|
if(cbox->model()->data(cbox->model()->index(i, 0, QModelIndex())).toString().compare(text, Qt::CaseInsensitive) == 0)
|
|
|
|
{
|
|
|
|
cbox->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddJobDialog::restoreOptions(OptionsModel *options)
|
|
|
|
{
|
2012-01-31 03:03:17 +01:00
|
|
|
cbxRateControlMode->blockSignals(true);
|
|
|
|
spinQuantizer->blockSignals(true);
|
|
|
|
spinBitrate->blockSignals(true);
|
|
|
|
cbxPreset->blockSignals(true);
|
|
|
|
cbxTuning->blockSignals(true);
|
|
|
|
cbxProfile->blockSignals(true);
|
|
|
|
editCustomParams->blockSignals(true);
|
|
|
|
|
2012-01-29 19:14:46 +01:00
|
|
|
cbxRateControlMode->setCurrentIndex(options->rcMode());
|
|
|
|
spinQuantizer->setValue(options->quantizer());
|
|
|
|
spinBitrate->setValue(options->bitrate());
|
|
|
|
updateComboBox(cbxPreset, options->preset());
|
|
|
|
updateComboBox(cbxTuning, options->tune());
|
|
|
|
updateComboBox(cbxProfile, options->profile());
|
2012-01-31 03:03:17 +01:00
|
|
|
editCustomParams->setText(options->custom());
|
|
|
|
|
|
|
|
cbxRateControlMode->blockSignals(false);
|
|
|
|
spinQuantizer->blockSignals(false);
|
|
|
|
spinBitrate->blockSignals(false);
|
|
|
|
cbxPreset->blockSignals(false);
|
|
|
|
cbxTuning->blockSignals(false);
|
|
|
|
cbxProfile->blockSignals(false);
|
|
|
|
editCustomParams->blockSignals(false);
|
2012-01-29 19:14:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2012-01-31 03:03:17 +01:00
|
|
|
options->setCustom(editCustomParams->text().simplified());
|
2012-01-29 19:14:46 +01:00
|
|
|
}
|
2012-01-30 17:50:19 +01:00
|
|
|
|
|
|
|
QString AddJobDialog::makeFileFilter(void)
|
|
|
|
{
|
|
|
|
QString filters("All supported files (");
|
|
|
|
|
|
|
|
for(size_t index = 0; g_filters[index].name && g_filters[index].fext; index++)
|
|
|
|
{
|
|
|
|
filters += QString((index > 0) ? " *.%1" : "*.%1").arg(QString::fromLatin1(g_filters[index].fext));
|
|
|
|
}
|
|
|
|
|
|
|
|
filters += QString(");;");
|
|
|
|
|
|
|
|
for(size_t index = 0; g_filters[index].name && g_filters[index].fext; index++)
|
|
|
|
{
|
|
|
|
filters += QString("%1 (*.%2);;").arg(QString::fromLatin1(g_filters[index].name), QString::fromLatin1(g_filters[index].fext));
|
|
|
|
}
|
|
|
|
|
|
|
|
filters += QString("All files (*.*)");
|
|
|
|
return filters;
|
|
|
|
}
|