OSDN Git Service

6b33c7ac5236e1170f4605bebc732b50e004f009
[x264-launcher/x264-launcher.git] / src / win_addJob.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2022 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "win_addJob.h"
23 #include "UIC_win_addJob.h"
24
25 //Internal
26 #include "global.h"
27 #include "model_options.h"
28 #include "model_preferences.h"
29 #include "model_sysinfo.h"
30 #include "model_recently.h"
31 #include "encoder_factory.h"
32 #include "mediainfo.h"
33 #include "string_validator.h"
34 #include "win_help.h"
35 #include "win_editor.h"
36
37 //MUtils
38 #include <MUtils/Global.h>
39 #include <MUtils/OSSupport.h>
40 #include <MUtils/Exception.h>
41
42 //Qt
43 #include <QDate>
44 #include <QTimer>
45 #include <QCloseEvent>
46 #include <QMessageBox>
47 #include <QFileDialog>
48 #include <QDesktopServices>
49 #include <QValidator>
50 #include <QDir>
51 #include <QInputDialog>
52 #include <QSettings>
53 #include <QUrl>
54 #include <QAction>
55 #include <QClipboard>
56 #include <QToolTip>
57
58 #include <memory>
59
60 #define ARRAY_SIZE(ARRAY) (sizeof((ARRAY))/sizeof((ARRAY[0])))
61 #define VALID_DIR(PATH) ((!(PATH).isEmpty()) && QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
62 #define SHFL(X) ((*reinterpret_cast<int*>(&(X))) <<= 1)
63
64 #define REMOVE_USAFED_ITEM \
65 { \
66         for(int i = 0; i < ui->cbxTemplate->count(); i++) \
67         { \
68                 const OptionsModel* temp = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>()); \
69                 if(temp == NULL) \
70                 { \
71                         ui->cbxTemplate->blockSignals(true); \
72                         ui->cbxTemplate->removeItem(i); \
73                         ui->cbxTemplate->blockSignals(false); \
74                         break; \
75                 } \
76         } \
77 }
78
79 #define ADD_CONTEXTMENU_ACTION(WIDGET, ICON, TEXT, SLOTNAME) \
80 { \
81         QAction *_action = new QAction((ICON), (TEXT), this); \
82         _action->setData(QVariant::fromValue<void*>(WIDGET)); \
83         WIDGET->addAction(_action); \
84         connect(_action, SIGNAL(triggered(bool)), this, SLOT(SLOTNAME())); \
85 }
86
87 #define ADD_CONTEXTMENU_SEPARATOR(WIDGET) \
88 { \
89         QAction *_action = new QAction(this); \
90         _action->setSeparator(true); \
91         WIDGET->addAction(_action); \
92
93
94 Q_DECLARE_METATYPE(const void*)
95
96 ///////////////////////////////////////////////////////////////////////////////
97 // Disable Monitoring RAII
98 ///////////////////////////////////////////////////////////////////////////////
99
100 class DisableHelperRAII
101 {
102 public:
103         DisableHelperRAII(bool *const flag) : m_flag(flag)
104         {
105                 *m_flag = false;
106         }
107
108         ~DisableHelperRAII(void)
109         {
110                 *m_flag = true;
111         }
112
113 private:
114         bool *const m_flag;
115 };
116
117 ///////////////////////////////////////////////////////////////////////////////
118 // Constructor & Destructor
119 ///////////////////////////////////////////////////////////////////////////////
120
121 AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *const options, RecentlyUsed *const recentlyUsed, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences)
122 :
123         QDialog(parent),
124         m_options(options),
125         m_recentlyUsed(recentlyUsed),
126         m_sysinfo(sysinfo),
127         m_preferences(preferences),
128         m_defaults(new OptionsModel(sysinfo)),
129         ui(new Ui::AddJobDialog()),
130         m_monitorConfigChanges(false)
131 {
132         //Init the dialog, from the .ui file
133         ui->setupUi(this);
134         setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
135
136         //Fix dialog size
137         ui->buttonSaveTemplate->setMaximumHeight(20);
138         ui->buttonDeleteTemplate->setMaximumHeight(20);
139         resize(width(), minimumHeight());
140         setMinimumSize(size());
141         setMaximumHeight(height());
142
143         //Init encoder combobox
144         ui->cbxEncoderType->addItem(tr("x264 (AVC)"),  OptionsModel::EncType_X264);
145         ui->cbxEncoderType->addItem(tr("x265 (HEVC)"), OptionsModel::EncType_X265);
146         ui->cbxEncoderType->addItem(tr("NVEncC"),      OptionsModel::EncType_NVEnc);
147
148         //Init combobox items
149         ui->cbxTuning ->addItem(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED));
150         ui->cbxProfile->addItem(QString::fromLatin1(OptionsModel::PROFILE_UNRESTRICTED));
151
152         //Hide optional controls
153         ui->checkBoxApplyToAll->setVisible(false);
154
155         //Monitor combobox changes
156         connect(ui->cbxEncoderType,     SIGNAL(currentIndexChanged(int)), this, SLOT(encoderIndexChanged(int)));
157         connect(ui->cbxEncoderVariant,  SIGNAL(currentIndexChanged(int)), this, SLOT(variantIndexChanged(int)));
158         connect(ui->cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(modeIndexChanged(int)));
159
160         //Activate buttons
161         connect(ui->buttonBrowseSource,   SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
162         connect(ui->buttonBrowseOutput,   SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
163         connect(ui->buttonSaveTemplate,   SIGNAL(clicked()), this, SLOT(saveTemplateButtonClicked()));
164         connect(ui->buttonDeleteTemplate, SIGNAL(clicked()), this, SLOT(deleteTemplateButtonClicked()));
165
166         //Setup validator
167         ui->editCustomX264Params->installEventFilter(this);
168         ui->editCustomX264Params->setValidator(new StringValidatorEncoder(ui->labelNotificationX264, ui->iconNotificationX264));
169         ui->editCustomX264Params->clear();
170         ui->editCustomAvs2YUVParams->installEventFilter(this);
171         ui->editCustomAvs2YUVParams->setValidator(new StringValidatorSource(ui->labelNotificationAvs2YUV, ui->iconNotificationAvs2YUV));
172         ui->editCustomAvs2YUVParams->clear();
173
174         //Install event filter
175         ui->labelHelpScreenX264->installEventFilter(this);
176         ui->labelHelpScreenAvs2YUV->installEventFilter(this);
177
178         //Monitor for options changes
179         connect(ui->cbxEncoderType, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
180         connect(ui->cbxEncoderArch, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
181         connect(ui->cbxEncoderVariant, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
182         connect(ui->cbxRateControlMode, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
183         connect(ui->spinQuantizer, SIGNAL(valueChanged(double)), this, SLOT(configurationChanged()));
184         connect(ui->spinBitrate, SIGNAL(valueChanged(int)), this, SLOT(configurationChanged()));
185         connect(ui->cbxPreset, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
186         connect(ui->cbxTuning, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
187         connect(ui->cbxProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(configurationChanged()));
188         connect(ui->editCustomX264Params, SIGNAL(textChanged(QString)), this, SLOT(configurationChanged()));
189         connect(ui->editCustomAvs2YUVParams, SIGNAL(textChanged(QString)), this, SLOT(configurationChanged()));
190
191         //Create context menus
192         ADD_CONTEXTMENU_ACTION(ui->editCustomX264Params, QIcon(":/buttons/page_edit.png"), tr("Open the Text-Editor"), editorActionTriggered);
193         ADD_CONTEXTMENU_ACTION(ui->editCustomAvs2YUVParams, QIcon(":/buttons/page_edit.png"), tr("Open the Text-Editor"), editorActionTriggered);
194         ADD_CONTEXTMENU_SEPARATOR(ui->editCustomX264Params);
195         ADD_CONTEXTMENU_SEPARATOR(ui->editCustomAvs2YUVParams);
196         ADD_CONTEXTMENU_ACTION(ui->editCustomX264Params, QIcon(":/buttons/page_copy.png"), tr("Copy to Clipboard"), copyActionTriggered);
197         ADD_CONTEXTMENU_ACTION(ui->editCustomAvs2YUVParams, QIcon(":/buttons/page_copy.png"), tr("Copy to Clipboard"), copyActionTriggered);
198         ADD_CONTEXTMENU_ACTION(ui->editCustomX264Params, QIcon(":/buttons/page_paste.png"), tr("Paste from Clipboard"), pasteActionTriggered);
199         ADD_CONTEXTMENU_ACTION(ui->editCustomAvs2YUVParams, QIcon(":/buttons/page_paste.png"), tr("Paste from Clipboard"), pasteActionTriggered);
200
201         //Setup template selector
202         loadTemplateList();
203         connect(ui->cbxTemplate, SIGNAL(currentIndexChanged(int)), this, SLOT(templateSelected()));
204
205         //Force initial UI update
206         encoderIndexChanged(ui->cbxEncoderType->currentIndex());
207         m_monitorConfigChanges = true;
208 }
209
210 AddJobDialog::~AddJobDialog(void)
211 {
212         //Free templates
213         for(int i = 0; i < ui->cbxTemplate->model()->rowCount(); i++)
214         {
215                 if(ui->cbxTemplate->itemText(i).startsWith("<") || ui->cbxTemplate->itemText(i).endsWith(">"))
216                 {
217                         continue;
218                 }
219                 const OptionsModel *item = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>());
220                 ui->cbxTemplate->setItemData(i, QVariant::fromValue<const void*>(NULL));
221                 MUTILS_DELETE(item);
222         }
223
224         //Free validators
225         if(const QValidator *tmp = ui->editCustomX264Params->validator())
226         {
227                 ui->editCustomX264Params->setValidator(NULL);
228                 MUTILS_DELETE(tmp);
229         }
230         if(const QValidator *tmp = ui->editCustomAvs2YUVParams->validator())
231         {
232                 ui->editCustomAvs2YUVParams->setValidator(NULL);
233                 MUTILS_DELETE(tmp);
234         }
235
236         MUTILS_DELETE(m_defaults);
237         delete ui;
238 }
239
240 ///////////////////////////////////////////////////////////////////////////////
241 // Events
242 ///////////////////////////////////////////////////////////////////////////////
243
244 void AddJobDialog::showEvent(QShowEvent *event)
245 {
246         QDialog::showEvent(event);
247         templateSelected();
248
249         if((!ui->editSource->text().isEmpty()) && ui->editOutput->text().isEmpty())
250         {
251                 QString outPath = generateOutputFileName(QDir::fromNativeSeparators(ui->editSource->text()), m_recentlyUsed->outputDirectory(), m_recentlyUsed->filterIndex(), m_preferences->getSaveToSourcePath());
252                 ui->editOutput->setText(QDir::toNativeSeparators(outPath));
253                 ui->buttonAccept->setFocus();
254         }
255
256         ui->labelNotificationX264->hide();
257         ui->iconNotificationX264->hide();
258         ui->labelNotificationAvs2YUV->hide();
259         ui->iconNotificationAvs2YUV->hide();
260
261         //Enable drag&drop support for this window, required for Qt v4.8.4+
262         setAcceptDrops(true);
263 }
264
265 bool AddJobDialog::eventFilter(QObject *o, QEvent *e)
266 {
267         if((o == ui->labelHelpScreenX264) && (e->type() == QEvent::MouseButtonPress))
268         {
269                 OptionsModel options(m_sysinfo); saveOptions(&options);
270                 QScopedPointer<HelpDialog> helpScreen(new HelpDialog(this, false, m_sysinfo, &options, m_preferences));
271                 helpScreen->exec();
272         }
273         else if((o == ui->labelHelpScreenAvs2YUV) && (e->type() == QEvent::MouseButtonPress))
274         {
275                 OptionsModel options(m_sysinfo); saveOptions(&options);
276                 QScopedPointer<HelpDialog> helpScreen(new HelpDialog(this, true, m_sysinfo, &options, m_preferences));
277                 helpScreen->exec();
278         }
279         else if((o == ui->editCustomX264Params) && (e->type() == QEvent::FocusOut))
280         {
281                 ui->editCustomX264Params->setText(ui->editCustomX264Params->text().simplified());
282         }
283         else if((o == ui->editCustomAvs2YUVParams) && (e->type() == QEvent::FocusOut))
284         {
285                 ui->editCustomAvs2YUVParams->setText(ui->editCustomAvs2YUVParams->text().simplified());
286         }
287         return false;
288 }
289
290 void AddJobDialog::dragEnterEvent(QDragEnterEvent *event)
291 {
292         bool accept[2] = {false, false};
293
294         foreach(const QString &fmt, event->mimeData()->formats())
295         {
296                 accept[0] = accept[0] || fmt.contains("text/uri-list", Qt::CaseInsensitive);
297                 accept[1] = accept[1] || fmt.contains("FileNameW", Qt::CaseInsensitive);
298         }
299
300         if(accept[0] && accept[1])
301         {
302                 event->acceptProposedAction();
303         }
304 }
305
306 void AddJobDialog::dropEvent(QDropEvent *event)
307 {
308         QString droppedFile;
309         QList<QUrl> urls = event->mimeData()->urls();
310
311         if(urls.count() > 1)
312         {
313                 QDragEnterEvent dragEvent(event->pos(), event->proposedAction(), event->mimeData(), Qt::NoButton, Qt::NoModifier);
314                 if(qApp->notify(parent(), &dragEvent))
315                 {
316                         qApp->notify(parent(), event);
317                         reject(); return;
318                 }
319         }
320
321         while((!urls.isEmpty()) && droppedFile.isEmpty())
322         {
323                 QUrl currentUrl = urls.takeFirst();
324                 QFileInfo file(currentUrl.toLocalFile());
325                 if(file.exists() && file.isFile())
326                 {
327                         qDebug("AddJobDialog::dropEvent: %s", file.canonicalFilePath().toUtf8().constData());
328                         droppedFile = file.canonicalFilePath();
329                 }
330         }
331         
332         if(!droppedFile.isEmpty())
333         {
334                 const QString outFileName = generateOutputFileName(droppedFile, currentOutputPath(), currentOutputIndx(), m_preferences->getSaveToSourcePath());
335                 ui->editSource->setText(QDir::toNativeSeparators(droppedFile));
336                 ui->editOutput->setText(QDir::toNativeSeparators(outFileName));
337         }
338 }
339
340 ///////////////////////////////////////////////////////////////////////////////
341 // Slots
342 ///////////////////////////////////////////////////////////////////////////////
343
344 void AddJobDialog::encoderIndexChanged(int index)
345 {
346         const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
347         const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
348
349         //Update encoder architectures
350         const QList<AbstractEncoderInfo::ArchId> archs = encoderInfo.getArchitectures();
351         ui->cbxEncoderArch->clear();
352         for (quint32 archIdx = 0; archIdx < quint32(archs.count()); ++archIdx)
353         {
354                 ui->cbxEncoderArch->addItem(archs[archIdx].first, archIdx);
355         }
356
357         //Update encoder variants
358         const QStringList variants = encoderInfo.getVariants();
359         ui->cbxEncoderVariant->clear();
360         for(quint32 varntIdx = 0; varntIdx < quint32(variants.count()); ++varntIdx)
361         {
362                 ui->cbxEncoderVariant->addItem(variants[varntIdx], varntIdx);
363         }
364
365         //Update encoder RC modes
366         const QList<AbstractEncoderInfo::RCMode> rcModes = encoderInfo.getRCModes();
367         ui->cbxRateControlMode->clear();
368         for (quint32 rcIndex = 0; rcIndex < quint32(rcModes.count()); ++rcIndex)
369         {
370                 ui->cbxRateControlMode->addItem(rcModes[rcIndex].first, rcIndex);
371         }
372
373         //Update presets
374         const QStringList presets = encoderInfo.getPresets();
375         if(presets.empty())
376         {
377                 ui->cbxPreset->setEnabled(false);
378                 ui->cbxPreset->setCurrentIndex(0);
379         }
380         else
381         {
382                 ui->cbxPreset->setEnabled(true);
383                 ui->cbxPreset->clear();
384                 ui->cbxPreset->addItem(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED));
385                 ui->cbxPreset->addItems(presets);
386         }
387
388         //Update tunings
389         const QStringList tunings = encoderInfo.getTunings();
390         if(tunings.empty())
391         {
392                 ui->cbxTuning->setEnabled(false);
393                 ui->cbxTuning->setCurrentIndex(0);
394         }
395         else
396         {
397                 ui->cbxTuning->setEnabled(true);
398                 ui->cbxTuning->clear();
399                 ui->cbxTuning->addItem(QString::fromLatin1(OptionsModel::SETTING_UNSPECIFIED));
400                 ui->cbxTuning->addItems(tunings);
401         }
402
403         variantIndexChanged(ui->cbxEncoderVariant->currentIndex());
404 }
405
406 void AddJobDialog::variantIndexChanged(int index)
407 {
408         const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
409         const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
410
411         //Update encoder profiles
412         const QStringList profiles = encoderInfo.getProfiles(ui->cbxEncoderVariant->itemData(index).toUInt());
413         if(profiles.empty())
414         {
415                 ui->cbxProfile->setEnabled(false);
416                 ui->cbxProfile->setCurrentIndex(0);
417         }
418         else
419         {
420                 ui->cbxProfile->setEnabled(true);
421                 ui->cbxProfile->clear();
422                 ui->cbxProfile->addItem(QString::fromLatin1(OptionsModel::PROFILE_UNRESTRICTED));
423                 ui->cbxProfile->addItems(profiles);
424         }
425         
426         modeIndexChanged(ui->cbxRateControlMode->currentIndex());
427 }
428
429 void AddJobDialog::modeIndexChanged(int index)
430 {
431         const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
432         const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
433
434         //Update bitrate/quantizer boxes
435         const AbstractEncoderInfo::RCType rcType = encoderInfo.rcModeToType(ui->cbxRateControlMode->itemData(index).toUInt());
436         ui->spinQuantizer->setEnabled(rcType == AbstractEncoderInfo::RC_TYPE_QUANTIZER);
437         ui->spinBitrate  ->setEnabled(rcType != AbstractEncoderInfo::RC_TYPE_QUANTIZER);
438 }
439
440 void AddJobDialog::accept(void)
441 {
442         //Get encoder info
443         const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
444         const AbstractEncoderInfo &encoderInfo = EncoderFactory::getEncoderInfo(encType);
445
446         //Check 64-Bit support
447         if (encoderInfo.archToType(ui->cbxEncoderArch->itemData(ui->cbxEncoderArch->currentIndex()).toUInt()) == AbstractEncoderInfo::ARCH_TYPE_X64)
448         {
449                 if (!m_sysinfo->getCPUFeatures(SysinfoModel::CPUFeatures_X64))
450                 {
451                         QMessageBox::warning(this, tr("64-Bit unsupported!"), tr("<nobr>Sorry, this computer does <b>not</b> support 64-Bit encoders!</nobr>"));
452                         ui->cbxEncoderArch->setCurrentIndex(AbstractEncoderInfo::ARCH_TYPE_X86);
453                         return;
454                 }
455         }
456         
457         //Selection complete?
458         if(ui->editSource->text().trimmed().isEmpty())
459         {
460                 QMessageBox::warning(this, tr("Not Found!"), tr("<nobr>Please select a valid source file first!<(nobr>"));
461                 return;
462         }
463         if(ui->editOutput->text().trimmed().isEmpty())
464         {
465                 QMessageBox::warning(this, tr("Not Selected!"), tr("<nobr>Please select a valid output file first!</nobr>"));
466                 return;
467         }
468
469         //Does source exist?
470         QFileInfo sourceFile = QFileInfo(this->sourceFile());
471         if(!(sourceFile.exists() && sourceFile.isFile()))
472         {
473                 QMessageBox::warning(this, tr("Not Found!"), tr("<nobr>The selected source file could not be found!</nobr>"));
474                 return;
475         }
476
477         //Is the type of the source file supported?
478         const int sourceType = MediaInfo::analyze(sourceFile.canonicalFilePath());
479         if(sourceType == MediaInfo::FILETYPE_AVISYNTH)
480         {
481                 if(!m_sysinfo->hasAvisynth())
482                 {
483                         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)
484                         {
485                                 return;
486                         }
487                 }
488         }
489         else if(sourceType == MediaInfo::FILETYPE_VAPOURSYNTH)
490         {
491                 if(!m_sysinfo->hasVapourSynth())
492                 {
493                         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)
494                         {
495                                 return;
496                         }
497                 }
498         }
499         else if(!encoderInfo.isInputTypeSupported(sourceType))
500         {
501                 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)
502                 {
503                         return;
504                 }
505         }
506         
507         //Is output file extension supported by encoder?
508         const QStringList outputFormats = encoderInfo.supportedOutputFormats();
509         QFileInfo outputFile = QFileInfo(this->outputFile());
510         if(!outputFormats.contains(outputFile.suffix(), Qt::CaseInsensitive))
511         {
512                 QMessageBox::warning(this, tr("Unsupported output format"), tr("<nobr>Sorry, the selected encoder does not support the selected output format!</nobr>"));
513                 ui->editOutput->setText(QDir::toNativeSeparators(QString("%1/%2.%3").arg(outputFile.absolutePath(), outputFile.completeBaseName(), outputFormats.first())));
514                 return;
515         }
516
517         //Does output file already exist?
518         if(outputFile.exists() && outputFile.isFile())
519         {
520                 int ret = QMessageBox::question(this, tr("Already Exists!"), tr("<nobr>Output file already exists! Overwrite?</nobr>"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
521                 if(ret != QMessageBox::Yes) return;
522         }
523         if(outputFile.exists() && (!outputFile.isFile()))
524         {
525                 QMessageBox::warning(this, tr("Not a File!"), tr("<nobr>Selected output file does not appear to be a valid file!</nobr>"));
526                 return;
527         }
528
529         //Is destination dir writable?
530         QFileInfo outputDir = QFileInfo(outputFile.absolutePath());
531         if(!(outputDir.exists() && outputDir.isDir() && outputDir.isWritable()))
532         {
533                 QMessageBox::warning(this, tr("Not Writable!"), tr("<nobr>Output directory does not exist or is not writable!</nobr>"));
534                 return;
535         }
536
537         //Custom parameters okay?
538         if(!ui->editCustomX264Params->hasAcceptableInput())
539         {
540                 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);
541                 if(ret != QMessageBox::Ignore) return;
542         }
543
544         //Update recently used
545         m_recentlyUsed->setFilterIndex(currentOutputIndx());
546         m_recentlyUsed->setSourceDirectory(currentSourcePath());
547         m_recentlyUsed->setOutputDirectory(currentOutputPath());
548         RecentlyUsed::saveRecentlyUsed(m_recentlyUsed);
549
550         //Save options
551         saveOptions(m_options);
552         QDialog::accept();
553 }
554
555 void AddJobDialog::browseButtonClicked(void)
556 {
557         if(QObject::sender() == ui->buttonBrowseSource)
558         {
559                 QString filePath = QFileDialog::getOpenFileName(this, tr("Open Source File"), currentSourcePath(true), getInputFilterLst(), NULL, QFileDialog::DontUseNativeDialog);
560                 if(!(filePath.isNull() || filePath.isEmpty()))
561                 {
562                         QString destFile = generateOutputFileName(filePath, currentOutputPath(), currentOutputIndx(), m_preferences->getSaveToSourcePath());
563                         ui->editSource->setText(QDir::toNativeSeparators(filePath));
564                         ui->editOutput->setText(QDir::toNativeSeparators(destFile));
565                 }
566         }
567         else if(QObject::sender() == ui->buttonBrowseOutput)
568         {
569                 QString selectedType = getFilterStr(currentOutputIndx());
570                 QString filePath = QFileDialog::getSaveFileName(this, tr("Choose Output File"), currentOutputPath(true), getFilterLst(), &selectedType, QFileDialog::DontUseNativeDialog | QFileDialog::DontConfirmOverwrite);
571
572                 if(!(filePath.isNull() || filePath.isEmpty()))
573                 {
574                         if(getFilterIdx(QFileInfo(filePath).suffix()) < 0)
575                         {
576                                 int tempIndex = -1;
577                                 QRegExp regExp("\\(\\*\\.(\\w+)\\)");
578                                 if(regExp.lastIndexIn(selectedType) >= 0)
579                                 {
580                                         tempIndex = getFilterIdx(regExp.cap(1));
581                                 }
582                                 if(tempIndex < 0)
583                                 {
584                                         tempIndex = m_recentlyUsed->filterIndex();
585                                 }
586                                 filePath = QString("%1.%2").arg(filePath, getFilterExt(tempIndex));
587                         }
588                         ui->editOutput->setText(QDir::toNativeSeparators(filePath));
589                 }
590         }
591 }
592
593 void AddJobDialog::configurationChanged(void)
594 {
595         if(!m_monitorConfigChanges)
596         {
597                 return;
598         }
599
600         const OptionsModel* options = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(ui->cbxTemplate->currentIndex()).value<const void*>());
601         if(options)
602         {
603                 ui->cbxTemplate->blockSignals(true);
604                 ui->cbxTemplate->insertItem(0, tr("<Modified Configuration>"), QVariant::fromValue<const void*>(NULL));
605                 ui->cbxTemplate->setCurrentIndex(0);
606                 ui->cbxTemplate->blockSignals(false);
607         }
608 }
609
610 void AddJobDialog::templateSelected(void)
611 {
612         const OptionsModel* options = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(ui->cbxTemplate->currentIndex()).value<const void*>());
613         if(options)
614         {
615                 qDebug("Loading options!");
616                 m_lastTemplateName = ui->cbxTemplate->itemText(ui->cbxTemplate->currentIndex());
617                 REMOVE_USAFED_ITEM;
618                 restoreOptions(options);
619         }
620 }
621
622 void AddJobDialog::saveTemplateButtonClicked(void)
623 {
624         qDebug("Saving template");
625
626         QString name = m_lastTemplateName;
627         if(name.isEmpty() || name.contains('<') || name.contains('>'))
628         {
629                 name = tr("New Template");
630                 int n = 1;
631                 while(OptionsModel::templateExists(name))
632                 {
633                         name = tr("New Template (%1)").arg(QString::number(++n));
634                 }
635         }
636
637         QScopedPointer<OptionsModel> options(new OptionsModel(m_sysinfo));
638         saveOptions(options.data());
639
640         if(options->equals(m_defaults))
641         {
642                 QMessageBox::warning (this, tr("Oups"), tr("<nobr>It makes no sense to save the default settings!</nobr>"));
643                 ui->cbxTemplate->blockSignals(true);
644                 ui->cbxTemplate->setCurrentIndex(0);
645                 ui->cbxTemplate->blockSignals(false);
646                 REMOVE_USAFED_ITEM;
647                 return;
648         }
649
650         for(int i = 0; i < ui->cbxTemplate->count(); i++)
651         {
652                 const QString tempName = ui->cbxTemplate->itemText(i);
653                 if(tempName.contains('<') || tempName.contains('>'))
654                 {
655                         continue;
656                 }
657                 const OptionsModel* test = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>());
658                 if(test != NULL)
659                 {
660                         if(options->equals(test))
661                         {
662                                 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)));
663                                 ui->cbxTemplate->blockSignals(true);
664                                 ui->cbxTemplate->setCurrentIndex(i);
665                                 ui->cbxTemplate->blockSignals(false);
666                                 REMOVE_USAFED_ITEM;
667                                 return;
668                         }
669                 }
670         }
671
672         forever
673         {
674                 bool ok = false;
675                 
676                 QStringList items;
677                 items << name;
678                 for(int i = 0; i < ui->cbxTemplate->count(); i++)
679                 {
680                         const QString tempName = ui->cbxTemplate->itemText(i);
681                         if(!(tempName.contains('<') || tempName.contains('>')))
682                         {
683                                 items << tempName;
684                         }
685                 }
686                 
687                 name = QInputDialog::getItem(this, tr("Save Template"), tr("Please enter the name of the template:").leftJustified(144, ' '), items, 0, true, &ok).simplified();
688                 if(!ok)
689                 {
690                         return;
691                 }
692                 if(name.isEmpty())
693                 {
694                         continue;
695                 }
696                 if(name.contains('<') || name.contains('>') || name.contains('\\') || name.contains('/') || name.contains('"'))
697                 {
698                         QMessageBox::warning (this, tr("Invalid Name"), tr("<nobr>Sorry, the name you have entered is invalid!</nobr>"));
699                         while(name.contains('<')) name.remove('<');
700                         while(name.contains('>')) name.remove('>');
701                         while(name.contains('\\')) name.remove('\\');
702                         while(name.contains('/')) name.remove('/');
703                         while(name.contains('"')) name.remove('"');
704                         name = name.simplified();
705                         continue;
706                 }
707                 if(OptionsModel::templateExists(name))
708                 {
709                         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);
710                         if(ret != QMessageBox::Yes)
711                         {
712                                 continue;
713                         }
714                 }
715                 break;
716         }
717         
718         if(!OptionsModel::saveTemplate(options.data(), name))
719         {
720                 QMessageBox::critical(this, tr("Save Failed"), tr("Sorry, the template could not be saved!"));
721                 return;
722         }
723         
724         ui->cbxTemplate->blockSignals(true);
725         for(int i = 0; i < ui->cbxTemplate->count(); i++)
726         {
727                 if(ui->cbxTemplate->itemText(i).compare(name, Qt::CaseInsensitive) == 0)
728                 {
729                         QScopedPointer<const OptionsModel> oldItem(reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(i).value<const void*>()));
730                         ui->cbxTemplate->setItemData(i, QVariant::fromValue<const void*>(options.take()));
731                         ui->cbxTemplate->setCurrentIndex(i);
732                 }
733         }
734         if(!options.isNull())
735         {
736                 const int index = ui->cbxTemplate->model()->rowCount();
737                 ui->cbxTemplate->insertItem(index, name, QVariant::fromValue<const void*>(options.take()));
738                 ui->cbxTemplate->setCurrentIndex(index);
739         }
740         ui->cbxTemplate->blockSignals(false);
741
742         m_lastTemplateName = name;
743         REMOVE_USAFED_ITEM;
744 }
745
746 void AddJobDialog::deleteTemplateButtonClicked(void)
747 {
748         const int index = ui->cbxTemplate->currentIndex();
749         QString name = ui->cbxTemplate->itemText(index);
750
751         if(name.contains('<') || name.contains('>') || name.contains('\\') || name.contains('/'))
752         {
753                 QMessageBox::warning (this, tr("Invalid Item"), tr("Sorry, the selected item cannot be deleted!"));
754                 return;
755         }
756
757         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);
758         if(ret != QMessageBox::Yes)
759         {
760                 return;
761         }
762         
763         OptionsModel::deleteTemplate(name);
764         const OptionsModel *item = reinterpret_cast<const OptionsModel*>(ui->cbxTemplate->itemData(index).value<const void*>());
765         ui->cbxTemplate->removeItem(index);
766         MUTILS_DELETE(item);
767 }
768
769 void AddJobDialog::editorActionTriggered(void)
770 {
771
772         if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
773         {
774                 QLineEdit *lineEdit = reinterpret_cast<QLineEdit*>(action->data().value<void*>());
775                 
776                 EditorDialog *editor = new EditorDialog(this);
777                 editor->setEditText(lineEdit->text());
778
779                 if(editor->exec() == QDialog::Accepted)
780                 {
781                         lineEdit->setText(editor->getEditText());
782                 }
783
784                 MUTILS_DELETE(editor);
785         }
786 }
787
788 void AddJobDialog::copyActionTriggered(void)
789 {
790         if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
791         {
792                 QClipboard *clipboard = QApplication::clipboard();
793                 QLineEdit *lineEdit = reinterpret_cast<QLineEdit*>(action->data().value<void*>());
794                 QString text = lineEdit->hasSelectedText() ? lineEdit->selectedText() : lineEdit->text();
795                 clipboard->setText(text);
796         }
797 }
798
799 void AddJobDialog::pasteActionTriggered(void)
800 {
801         if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
802         {
803                 QClipboard *clipboard = QApplication::clipboard();
804                 QLineEdit *lineEdit = reinterpret_cast<QLineEdit*>(action->data().value<void*>());
805                 QString text = clipboard->text();
806                 if(!text.isEmpty()) lineEdit->setText(text);
807         }
808 }
809
810 ///////////////////////////////////////////////////////////////////////////////
811 // Public functions
812 ///////////////////////////////////////////////////////////////////////////////
813
814 QString AddJobDialog::sourceFile(void)
815 {
816         return QDir::fromNativeSeparators(ui->editSource->text());
817 }
818
819 QString AddJobDialog::outputFile(void)
820 {
821         return QDir::fromNativeSeparators(ui->editOutput->text());
822 }
823
824 bool AddJobDialog::runImmediately(void)
825 {
826         return ui->checkBoxRun->isChecked();
827 }
828
829 bool AddJobDialog::applyToAll(void)
830 {
831         return ui->checkBoxApplyToAll->isChecked();
832 }
833
834 void AddJobDialog::setRunImmediately(bool run)
835 {
836         ui->checkBoxRun->setChecked(run);
837 }
838
839 void AddJobDialog::setSourceFile(const QString &path)
840 {
841         ui->editSource->setText(QDir::toNativeSeparators(path));
842 }
843
844 void AddJobDialog::setOutputFile(const QString &path)
845 {
846         ui->editOutput->setText(QDir::toNativeSeparators(path));}
847
848 void AddJobDialog::setSourceEditable(const bool editable)
849 {
850         ui->buttonBrowseSource->setEnabled(editable);
851 }
852
853 void AddJobDialog::setApplyToAllVisible(const bool visible)
854 {
855         ui->checkBoxApplyToAll->setVisible(visible);
856 }
857
858 ///////////////////////////////////////////////////////////////////////////////
859 // Private functions
860 ///////////////////////////////////////////////////////////////////////////////
861
862 void AddJobDialog::loadTemplateList(void)
863 {
864         ui->cbxTemplate->addItem(tr("<Default>"), QVariant::fromValue<const void*>(m_defaults));
865         ui->cbxTemplate->setCurrentIndex(0);
866
867         QMap<QString, OptionsModel*> templates = OptionsModel::loadAllTemplates(m_sysinfo);
868         QStringList templateNames = templates.keys();
869         templateNames.sort();
870
871         for(QStringList::ConstIterator current = templateNames.constBegin(); current != templateNames.constEnd(); current++)
872         {
873                 OptionsModel *currentTemplate = templates.take(*current);
874                 ui->cbxTemplate->addItem(*current, QVariant::fromValue<const void*>(currentTemplate));
875                 if(currentTemplate->equals(m_options))
876                 {
877                         ui->cbxTemplate->setCurrentIndex(ui->cbxTemplate->count() - 1);
878                 }
879         }
880
881         if((ui->cbxTemplate->currentIndex() == 0) && (!m_options->equals(m_defaults)))
882         {
883                 qWarning("Not the default -> recently used!");
884                 ui->cbxTemplate->insertItem(1, tr("<Recently Used>"), QVariant::fromValue<const void*>(m_options));
885                 ui->cbxTemplate->setCurrentIndex(1);
886         }
887 }
888
889 void AddJobDialog::updateComboBox(QComboBox *const cbox, const QString &text)
890 {
891         int index = 0;
892         if(QAbstractItemModel *model = cbox->model())
893         {
894                 for(int i = 0; i < cbox->model()->rowCount(); i++)
895                 {
896                         if(model->data(model->index(i, 0, QModelIndex())).toString().compare(text, Qt::CaseInsensitive) == 0)
897                         {
898                                 index = i;
899                                 break;
900                         }
901                 }
902         }
903         cbox->setCurrentIndex(index);
904 }
905
906 void AddJobDialog::updateComboBox(QComboBox *const cbox, const int &data)
907 {
908         int index = 0;
909         if (QAbstractItemModel *model = cbox->model())
910         {
911                 for (int i = 0; i < cbox->model()->rowCount(); i++)
912                 {
913                         if (cbox->itemData(i).toInt() == data)
914                         {
915                                 index = i;
916                                 break;
917                         }
918                 }
919         }
920         cbox->setCurrentIndex(index);
921 }
922
923 void AddJobDialog::updateComboBox(QComboBox *const cbox, const quint32 &data)
924 {
925         int index = 0;
926         if(QAbstractItemModel *model = cbox->model())
927         {
928                 for(int i = 0; i < cbox->model()->rowCount(); i++)
929                 {
930                         if(cbox->itemData(i).toUInt() == data)
931                         {
932                                 index = i;
933                                 break;
934                         }
935                 }
936         }
937         cbox->setCurrentIndex(index);
938 }
939
940 void AddJobDialog::restoreOptions(const OptionsModel *options)
941 {
942         DisableHelperRAII disable(&m_monitorConfigChanges);
943
944         updateComboBox(ui->cbxEncoderType,     options->encType());
945         updateComboBox(ui->cbxEncoderArch,     options->encArch());
946         updateComboBox(ui->cbxEncoderVariant,  options->encVariant());
947         updateComboBox(ui->cbxRateControlMode, options->rcMode());
948
949         ui->spinQuantizer->setValue(options->quantizer());
950         ui->spinBitrate  ->setValue(options->bitrate());
951
952         updateComboBox(ui->cbxPreset,  options->preset());
953         updateComboBox(ui->cbxTuning,  options->tune());
954         updateComboBox(ui->cbxProfile, options->profile());
955
956         ui->editCustomX264Params   ->setText(options->customEncParams());
957         ui->editCustomAvs2YUVParams->setText(options->customAvs2YUV());
958 }
959
960 void AddJobDialog::saveOptions(OptionsModel *options)
961 {
962         options->setEncType(static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt()));
963
964         options->setEncArch   (ui->cbxEncoderArch    ->itemData(ui->cbxEncoderArch    ->currentIndex()).toUInt());
965         options->setEncVariant(ui->cbxEncoderVariant ->itemData(ui->cbxEncoderVariant ->currentIndex()).toUInt());
966         options->setRCMode    (ui->cbxRateControlMode->itemData(ui->cbxRateControlMode->currentIndex()).toUInt());
967         
968         options->setQuantizer(ui->spinQuantizer->value());
969         options->setBitrate  (ui->spinBitrate  ->value());
970         
971         options->setPreset (ui->cbxPreset ->model()->data(ui->cbxPreset ->model()->index(ui->cbxPreset ->currentIndex(), 0)).toString());
972         options->setTune   (ui->cbxTuning ->model()->data(ui->cbxTuning ->model()->index(ui->cbxTuning ->currentIndex(), 0)).toString());
973         options->setProfile(ui->cbxProfile->model()->data(ui->cbxProfile->model()->index(ui->cbxProfile->currentIndex(), 0)).toString());
974
975         options->setCustomEncParams(ui->editCustomX264Params->hasAcceptableInput() ? ui->editCustomX264Params->text().simplified()     : QString());
976         options->setCustomAvs2YUV(ui->editCustomAvs2YUVParams->hasAcceptableInput() ? ui->editCustomAvs2YUVParams->text().simplified() : QString());
977 }
978
979 QString AddJobDialog::currentSourcePath(const bool bWithName)
980 {
981         QString path = m_recentlyUsed->sourceDirectory();
982         QString currentSourceFile = this->sourceFile();
983         
984         if(!currentSourceFile.isEmpty())
985         {
986                 QString currentSourceDir = QFileInfo(currentSourceFile).absolutePath();
987                 if(VALID_DIR(currentSourceDir))
988                 {
989                         path = currentSourceDir;
990                 }
991                 if(bWithName)
992                 {
993                         path.append("/").append(QFileInfo(currentSourceFile).fileName());
994                 }
995         }
996
997         return path;
998 }
999
1000 QString AddJobDialog::currentOutputPath(const bool bWithName)
1001 {
1002         QString path = m_recentlyUsed->outputDirectory();
1003         QString currentOutputFile = this->outputFile();
1004         
1005         if(!currentOutputFile.isEmpty())
1006         {
1007                 QString currentOutputDir = QFileInfo(currentOutputFile).absolutePath();
1008                 if(VALID_DIR(currentOutputDir))
1009                 {
1010                         path = currentOutputDir;
1011                 }
1012                 if(bWithName)
1013                 {
1014                         path.append("/").append(QFileInfo(currentOutputFile).fileName());
1015                 }
1016         }
1017
1018         return path;
1019 }
1020
1021 int AddJobDialog::currentOutputIndx(void)
1022 {
1023         const OptionsModel::EncType encType = static_cast<OptionsModel::EncType>(ui->cbxEncoderType->itemData(ui->cbxEncoderType->currentIndex()).toInt());
1024         if(encType == OptionsModel::EncType_X265)
1025         {
1026                 return ARRAY_SIZE(X264_FILE_TYPE_FILTERS) - 1;
1027         }
1028         
1029         int index = m_recentlyUsed->filterIndex();
1030         const QString currentOutputFile = this->outputFile();
1031
1032         if(!currentOutputFile.isEmpty())
1033         {
1034                 const QString currentOutputExtn = QFileInfo(currentOutputFile).suffix();
1035                 const int tempIndex = getFilterIdx(currentOutputExtn);
1036                 if(tempIndex >= 0)
1037                 {
1038                         index = tempIndex;
1039                 }
1040         }
1041
1042         return index;
1043 }
1044
1045 ///////////////////////////////////////////////////////////////////////////////
1046 // Static functions
1047 ///////////////////////////////////////////////////////////////////////////////
1048
1049 QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, const QString &destinationDirectory, const int filterIndex, const bool saveToSourceDir)
1050 {
1051         QString name = QFileInfo(sourceFilePath).completeBaseName();
1052         QString path = saveToSourceDir ? QFileInfo(sourceFilePath).canonicalPath() : destinationDirectory;
1053         QString fext = getFilterExt(filterIndex);
1054         
1055         if(!VALID_DIR(path))
1056         {
1057                 RecentlyUsed defaults;
1058                 path = defaults.outputDirectory();
1059         }
1060
1061         QString outPath = QString("%1/%2.%3").arg(path, name, fext);
1062
1063         int n = 2;
1064         while(QFileInfo(outPath).exists())
1065         {
1066                 outPath = QString("%1/%2 (%3).%4").arg(path, name, QString::number(n++), fext);
1067         }
1068
1069         return outPath;
1070 }
1071
1072 /* ------------------------------------------------------------------------- */
1073
1074 QString AddJobDialog::getFilterExt(const int filterIndex)
1075 {
1076         const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
1077
1078         if((filterIndex >= 0) && (filterIndex < count))
1079         {
1080                 return QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcExt);
1081         }
1082
1083         return QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcExt);
1084 }
1085
1086 int AddJobDialog::getFilterIdx(const QString &fileExt)
1087 {
1088         const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
1089
1090         for(int i = 0; i < count; i++)
1091         {
1092                 if(fileExt.compare(QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcExt), Qt::CaseInsensitive) == 0)
1093                 {
1094                         return i;
1095                 }
1096         }
1097
1098         return -1;
1099 }
1100
1101 QString AddJobDialog::getFilterStr(const int filterIndex)
1102 {
1103         const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
1104
1105         if((filterIndex >= 0) && (filterIndex < count))
1106         {
1107                 return QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcExt));
1108         }
1109
1110         return QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcExt));
1111 }
1112
1113 QString AddJobDialog::getFilterLst(void)
1114 {
1115         QStringList filters;
1116         const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
1117         
1118         for(int i = 0; i < count; i++)
1119         {
1120                 filters << QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcExt));
1121         }
1122
1123         return filters.join(";;");
1124 }
1125
1126 QString AddJobDialog::getInputFilterLst(void)
1127 {
1128         static const struct
1129         {
1130                 const char *name;
1131                 const char *fext;
1132         }
1133         s_filters[] =
1134         {
1135                 {"Avisynth Scripts", "avs"},
1136                 {"VapourSynth Scripts", "vpy"},
1137                 {"Matroska Files", "mkv"},
1138                 {"MPEG-4 Part 14 Container", "mp4"},
1139                 {"Audio Video Interleaved", "avi"},
1140                 {"Flash Video", "flv"},
1141                 {"YUV4MPEG2 Stream", "y4m"},
1142                 {"Uncompresses YUV Data", "yuv"},
1143         };
1144
1145         const int count = ARRAY_SIZE(s_filters);
1146
1147         QString allTypes;
1148         for(size_t index = 0; index < count; index++)
1149         {
1150
1151                 allTypes += QString((index > 0) ? " *.%1" : "*.%1").arg(QString::fromLatin1(s_filters[index].fext));
1152         }
1153         
1154         QStringList filters;
1155         filters << QString("All supported files (%1)").arg(allTypes);
1156
1157         for(size_t index = 0; index < count; index++)
1158         {
1159                 filters << QString("%1 (*.%2)").arg(QString::fromLatin1(s_filters[index].name), QString::fromLatin1(s_filters[index].fext));
1160         }
1161                 
1162         filters << QString("All files (*.*)");
1163         return filters.join(";;");
1164 }
1165
1166