OSDN Git Service

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