2012-01-29 04:06:07 +01:00
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
2014-01-27 19:58:24 +01:00
// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
2012-01-29 04:06:07 +01:00
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
# include "win_addJob.h"
2013-11-14 02:29:18 +01:00
# include "uic_win_addJob.h"
2012-01-29 04:06:07 +01:00
# include "global.h"
2012-01-29 19:14:46 +01:00
# include "model_options.h"
2014-02-12 21:36:10 +01:00
# include "model_preferences.h"
# include "model_sysinfo.h"
2013-07-03 21:34:21 +02:00
# include "model_recently.h"
2014-04-16 13:49:36 +02:00
# include "encoder_factory.h"
2012-02-01 01:08:54 +01:00
# include "win_help.h"
2012-02-16 02:08:46 +01:00
# include "win_editor.h"
2012-01-29 04:06:07 +01:00
# include <QDate>
# include <QTimer>
# include <QCloseEvent>
# include <QMessageBox>
2012-01-29 15:57:23 +01:00
# include <QFileDialog>
# include <QDesktopServices>
# include <QValidator>
2012-01-29 21:31:09 +01:00
# include <QDir>
2012-01-31 22:30:21 +01:00
# include <QInputDialog>
2012-02-02 15:56:49 +01:00
# include <QSettings>
2012-02-10 18:42:16 +01:00
# include <QUrl>
2012-02-16 02:08:46 +01:00
# include <QAction>
2012-02-16 14:33:26 +01:00
# include <QClipboard>
2012-09-27 18:13:55 +02:00
# include <QToolTip>
2012-01-29 15:57:23 +01:00
2013-05-11 01:50:05 +02:00
# define ARRAY_SIZE(ARRAY) (sizeof((ARRAY)) / sizeof((ARRAY[0])))
2012-02-02 15:56:49 +01:00
# define VALID_DIR(PATH) ((!(PATH).isEmpty()) && QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
2012-02-02 18:55:55 +01:00
# define REMOVE_USAFED_ITEM \
{ \
2013-11-14 02:29:18 +01:00
for ( int i = 0 ; i < ui - > cbxTemplate - > count ( ) ; i + + ) \
2012-02-02 18:55:55 +01:00
{ \
2014-02-12 21:36:10 +01:00
const OptionsModel * temp = reinterpret_cast < const OptionsModel * > ( ui - > cbxTemplate - > itemData ( i ) . value < const void * > ( ) ) ; \
2012-02-02 18:55:55 +01:00
if ( temp = = NULL ) \
{ \
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > blockSignals ( true ) ; \
ui - > cbxTemplate - > removeItem ( i ) ; \
ui - > cbxTemplate - > blockSignals ( false ) ; \
2012-02-02 18:55:55 +01:00
break ; \
} \
} \
}
2012-02-16 14:33:26 +01:00
# define ADD_CONTEXTMENU_ACTION(WIDGET, ICON, TEXT, SLOTNAME) \
{ \
QAction * _action = new QAction ( ( ICON ) , ( TEXT ) , this ) ; \
_action - > setData ( QVariant : : fromValue < void * > ( WIDGET ) ) ; \
WIDGET - > addAction ( _action ) ; \
connect ( _action , SIGNAL ( triggered ( bool ) ) , this , SLOT ( SLOTNAME ( ) ) ) ; \
}
# define ADD_CONTEXTMENU_SEPARATOR(WIDGET) \
{ \
QAction * _action = new QAction ( this ) ; \
_action - > setSeparator ( true ) ; \
WIDGET - > addAction ( _action ) ; \
}
2014-02-11 02:33:17 +01:00
# define BLOCK_SIGNALS(FLAG) do \
{ \
ui - > cbxEncoderType - > blockSignals ( FLAG ) ; \
ui - > cbxEncoderArch - > blockSignals ( FLAG ) ; \
ui - > cbxEncoderVariant - > blockSignals ( FLAG ) ; \
ui - > cbxRateControlMode - > blockSignals ( FLAG ) ; \
ui - > spinQuantizer - > blockSignals ( FLAG ) ; \
ui - > spinBitrate - > blockSignals ( FLAG ) ; \
ui - > cbxPreset - > blockSignals ( FLAG ) ; \
ui - > cbxTuning - > blockSignals ( FLAG ) ; \
ui - > cbxProfile - > blockSignals ( FLAG ) ; \
ui - > editCustomX264Params - > blockSignals ( FLAG ) ; \
ui - > editCustomAvs2YUVParams - > blockSignals ( FLAG ) ; \
} \
while ( 0 )
2014-02-10 21:33:04 +01:00
2014-02-12 21:36:10 +01:00
Q_DECLARE_METATYPE ( const void * )
2012-01-29 15:57:23 +01:00
///////////////////////////////////////////////////////////////////////////////
// Validator
///////////////////////////////////////////////////////////////////////////////
class StringValidator : public QValidator
{
2012-01-31 20:28:40 +01:00
public :
2012-02-06 22:40:07 +01:00
StringValidator ( QLabel * notifier , QLabel * icon )
2012-02-06 17:34:25 +01:00
:
2012-02-06 22:40:07 +01:00
m_notifier ( notifier ) , m_icon ( icon )
2012-02-06 17:34:25 +01:00
{
m_notifier - > hide ( ) ;
2012-02-06 22:40:07 +01:00
m_icon - > hide ( ) ;
2012-02-06 17:34:25 +01:00
}
2012-01-31 20:28:40 +01:00
2012-02-13 00:04:39 +01:00
virtual State validate ( QString & input , int & pos ) const = 0 ;
2012-01-29 15:57:23 +01:00
virtual void fixup ( QString & input ) const
{
input = input . simplified ( ) ;
}
2012-01-31 20:28:40 +01:00
protected :
2012-02-06 22:40:07 +01:00
QLabel * const m_notifier , * const m_icon ;
2012-02-06 17:34:25 +01:00
2012-02-13 00:04:39 +01:00
bool checkParam ( const QString & input , const QString & param , const bool doubleMinus ) const
2012-02-06 17:34:25 +01:00
{
2012-02-06 22:40:07 +01:00
static const char c [ 20 ] = { ' ' , ' * ' , ' ? ' , ' < ' , ' > ' , ' / ' , ' \\ ' , ' " ' , ' \' ' , ' ! ' , ' + ' , ' # ' , ' & ' , ' % ' , ' = ' , ' , ' , ' ; ' , ' . ' , ' <EFBFBD> ' , ' ` ' } ;
2012-02-13 00:04:39 +01:00
const QString prefix = doubleMinus ? QLatin1String ( " -- " ) : QLatin1String ( " - " ) ;
2012-02-06 22:40:07 +01:00
2012-02-06 17:34:25 +01:00
bool flag = false ;
if ( param . length ( ) > 1 )
{
2012-02-13 00:04:39 +01:00
flag = flag | | input . endsWith ( QString ( " %1%2 " ) . arg ( prefix , param ) , Qt : : CaseInsensitive ) ;
2012-02-06 22:40:07 +01:00
for ( size_t i = 0 ; i < sizeof ( c ) ; i + + )
{
2012-02-13 00:04:39 +01:00
flag = flag | | input . contains ( QString ( " %1%2%3 " ) . arg ( prefix , param , QChar : : fromLatin1 ( c [ i ] ) ) , Qt : : CaseInsensitive ) ;
2012-02-06 22:40:07 +01:00
}
2012-02-06 17:34:25 +01:00
}
else
{
flag = flag | | input . startsWith ( QString ( " -%1 " ) . arg ( param ) ) ;
2012-02-06 22:40:07 +01:00
for ( size_t i = 0 ; i < sizeof ( c ) ; i + + )
{
flag = flag | | input . contains ( QString ( " %1-%2 " ) . arg ( QChar : : fromLatin1 ( c [ i ] ) , param ) , Qt : : CaseSensitive ) ;
}
2012-02-06 17:34:25 +01:00
}
2012-09-27 18:13:55 +02:00
if ( ( flag ) & & ( m_notifier ) )
{
m_notifier - > setText ( tr ( " Invalid parameter: %1 " ) . arg ( ( param . length ( ) > 1 ) ? QString ( " %1%2 " ) . arg ( prefix , param ) : QString ( " -%1 " ) . arg ( param ) ) ) ;
}
return flag ;
}
const bool & setStatus ( const bool & flag , const QString & toolName ) const
{
2012-02-06 17:34:25 +01:00
if ( flag )
{
2012-02-06 22:40:07 +01:00
if ( m_notifier )
{
if ( m_notifier - > isHidden ( ) ) m_notifier - > show ( ) ;
if ( m_icon ) { if ( m_icon - > isHidden ( ) ) m_icon - > show ( ) ; }
2012-09-27 18:13:55 +02:00
if ( QWidget * w = m_notifier - > topLevelWidget ( ) - > focusWidget ( ) )
{
QToolTip : : showText ( static_cast < QWidget * > ( w - > parent ( ) ) - > mapToGlobal ( w - > pos ( ) ) , QString ( " <nobr>%1</nobr> " ) . arg ( tr ( " <b>Warning:</b> You entered a parameter that is incomaptible with using %1 from a GUI.<br>Please note that the GUI will automatically set <i>this</i> parameter for you (if required). " ) . arg ( toolName ) ) , m_notifier , QRect ( ) ) ;
}
2012-02-06 22:40:07 +01:00
}
2012-02-06 17:34:25 +01:00
}
else
{
2012-02-06 22:40:07 +01:00
if ( m_notifier )
{
if ( m_notifier - > isVisible ( ) ) m_notifier - > hide ( ) ;
if ( m_icon ) { if ( m_icon - > isVisible ( ) ) m_icon - > hide ( ) ; }
2012-09-27 18:13:55 +02:00
QToolTip : : hideText ( ) ;
2012-02-06 22:40:07 +01:00
}
2012-02-06 17:34:25 +01:00
}
return flag ;
}
2012-01-29 15:57:23 +01:00
} ;
2012-01-29 04:06:07 +01:00
2012-02-13 00:04:39 +01:00
class StringValidatorX264 : public StringValidator
{
public :
StringValidatorX264 ( QLabel * notifier , QLabel * icon ) : StringValidator ( notifier , icon ) { }
virtual State validate ( QString & input , int & pos ) const
{
2012-09-22 14:58:51 +02:00
static const char * p [ ] = { " B " , " o " , " h " , " p " , " q " , /*"fps", "frames",*/ " preset " , " tune " , " profile " ,
2012-02-13 00:04:39 +01:00
" stdin " , " crf " , " bitrate " , " qp " , " pass " , " stats " , " output " , " help " , " quiet " , NULL } ;
bool invalid = false ;
for ( size_t i = 0 ; p [ i ] & & ( ! invalid ) ; i + + )
{
invalid = invalid | | checkParam ( input , QString : : fromLatin1 ( p [ i ] ) , true ) ;
}
2012-09-27 18:13:55 +02:00
return setStatus ( invalid , " x264 " ) ? QValidator : : Intermediate : QValidator : : Acceptable ;
2012-02-13 00:04:39 +01:00
}
} ;
class StringValidatorAvs2YUV : public StringValidator
{
public :
StringValidatorAvs2YUV ( QLabel * notifier , QLabel * icon ) : StringValidator ( notifier , icon ) { }
virtual State validate ( QString & input , int & pos ) const
{
2012-02-16 02:08:46 +01:00
static const char * p [ ] = { " o " , " frames " , " seek " , " raw " , " hfyu " , " slave " , NULL } ;
2012-02-13 00:04:39 +01:00
bool invalid = false ;
for ( size_t i = 0 ; p [ i ] & & ( ! invalid ) ; i + + )
{
invalid = invalid | | checkParam ( input , QString : : fromLatin1 ( p [ i ] ) , false ) ;
}
2012-09-27 18:13:55 +02:00
return setStatus ( invalid , " Avs2YUV " ) ? QValidator : : Intermediate : QValidator : : Acceptable ;
2012-02-13 00:04:39 +01:00
}
} ;
2012-01-29 04:06:07 +01:00
///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor
///////////////////////////////////////////////////////////////////////////////
2014-02-12 21:36:10 +01:00
AddJobDialog : : AddJobDialog ( QWidget * parent , OptionsModel * const options , RecentlyUsed * const recentlyUsed , const SysinfoModel * const sysinfo , const PreferencesModel * const preferences )
2012-01-29 04:06:07 +01:00
:
2012-01-29 19:14:46 +01:00
QDialog ( parent ) ,
2012-02-02 15:56:49 +01:00
m_options ( options ) ,
2013-11-14 02:29:18 +01:00
m_recentlyUsed ( recentlyUsed ) ,
2014-02-12 21:36:10 +01:00
m_sysinfo ( sysinfo ) ,
m_preferences ( preferences ) ,
2014-02-15 00:40:15 +01:00
m_defaults ( new OptionsModel ( sysinfo ) ) ,
2013-11-14 02:29:18 +01:00
ui ( new Ui : : AddJobDialog ( ) )
2012-01-29 04:06:07 +01:00
{
//Init the dialog, from the .ui file
2013-11-14 02:29:18 +01:00
ui - > setupUi ( this ) ;
2012-01-29 19:14:46 +01:00
setWindowFlags ( windowFlags ( ) & ( ~ Qt : : WindowContextHelpButtonHint ) ) ;
2012-01-29 04:06:07 +01:00
//Fix dialog size
2013-11-14 02:29:18 +01:00
ui - > buttonSaveTemplate - > setMaximumHeight ( 20 ) ;
ui - > buttonDeleteTemplate - > setMaximumHeight ( 20 ) ;
2012-01-29 04:06:07 +01:00
resize ( width ( ) , minimumHeight ( ) ) ;
setMinimumSize ( size ( ) ) ;
setMaximumHeight ( height ( ) ) ;
2013-05-08 00:04:40 +02:00
//Hide optional controls
2013-11-14 02:29:18 +01:00
ui - > checkBoxApplyToAll - > setVisible ( false ) ;
2013-05-08 00:04:40 +02:00
2014-02-10 21:33:04 +01:00
//Monitor combobox changes
connect ( ui - > cbxEncoderType , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( encoderIndexChanged ( int ) ) ) ;
2014-02-12 21:36:10 +01:00
connect ( ui - > cbxEncoderVariant , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( variantIndexChanged ( int ) ) ) ;
connect ( ui - > cbxRateControlMode , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( modeIndexChanged ( int ) ) ) ;
2012-01-29 15:57:23 +01:00
//Activate buttons
2013-11-14 02:29:18 +01:00
connect ( ui - > buttonBrowseSource , SIGNAL ( clicked ( ) ) , this , SLOT ( browseButtonClicked ( ) ) ) ;
connect ( ui - > buttonBrowseOutput , SIGNAL ( clicked ( ) ) , this , SLOT ( browseButtonClicked ( ) ) ) ;
connect ( ui - > buttonSaveTemplate , SIGNAL ( clicked ( ) ) , this , SLOT ( saveTemplateButtonClicked ( ) ) ) ;
connect ( ui - > buttonDeleteTemplate , SIGNAL ( clicked ( ) ) , this , SLOT ( deleteTemplateButtonClicked ( ) ) ) ;
2012-01-29 15:57:23 +01:00
//Setup validator
2013-11-14 02:29:18 +01:00
ui - > editCustomX264Params - > installEventFilter ( this ) ;
ui - > editCustomX264Params - > setValidator ( new StringValidatorX264 ( ui - > labelNotificationX264 , ui - > iconNotificationX264 ) ) ;
ui - > editCustomX264Params - > clear ( ) ;
ui - > editCustomAvs2YUVParams - > installEventFilter ( this ) ;
ui - > editCustomAvs2YUVParams - > setValidator ( new StringValidatorAvs2YUV ( ui - > labelNotificationAvs2YUV , ui - > iconNotificationAvs2YUV ) ) ;
ui - > editCustomAvs2YUVParams - > clear ( ) ;
2012-01-31 00:13:32 +01:00
//Install event filter
2013-11-14 02:29:18 +01:00
ui - > labelHelpScreenX264 - > installEventFilter ( this ) ;
ui - > labelHelpScreenAvs2YUV - > installEventFilter ( this ) ;
2012-01-31 03:03:17 +01:00
//Monitor for options changes
2014-02-11 02:33:17 +01:00
connect ( ui - > cbxEncoderType , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > cbxEncoderArch , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > cbxEncoderVariant , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
2013-11-14 02:29:18 +01:00
connect ( ui - > cbxRateControlMode , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > spinQuantizer , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > spinBitrate , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > cbxPreset , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > cbxTuning , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > cbxProfile , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > editCustomX264Params , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( ui - > editCustomAvs2YUVParams , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
2012-01-31 03:03:17 +01:00
2012-02-16 02:08:46 +01:00
//Create context menus
2013-11-14 02:29:18 +01:00
ADD_CONTEXTMENU_ACTION ( ui - > editCustomX264Params , QIcon ( " :/buttons/page_edit.png " ) , tr ( " Open the Text-Editor " ) , editorActionTriggered ) ;
ADD_CONTEXTMENU_ACTION ( ui - > editCustomAvs2YUVParams , QIcon ( " :/buttons/page_edit.png " ) , tr ( " Open the Text-Editor " ) , editorActionTriggered ) ;
ADD_CONTEXTMENU_SEPARATOR ( ui - > editCustomX264Params ) ;
ADD_CONTEXTMENU_SEPARATOR ( ui - > editCustomAvs2YUVParams ) ;
ADD_CONTEXTMENU_ACTION ( ui - > editCustomX264Params , QIcon ( " :/buttons/page_copy.png " ) , tr ( " Copy to Clipboard " ) , copyActionTriggered ) ;
ADD_CONTEXTMENU_ACTION ( ui - > editCustomAvs2YUVParams , QIcon ( " :/buttons/page_copy.png " ) , tr ( " Copy to Clipboard " ) , copyActionTriggered ) ;
ADD_CONTEXTMENU_ACTION ( ui - > editCustomX264Params , QIcon ( " :/buttons/page_paste.png " ) , tr ( " Paste from Clipboard " ) , pasteActionTriggered ) ;
ADD_CONTEXTMENU_ACTION ( ui - > editCustomAvs2YUVParams , QIcon ( " :/buttons/page_paste.png " ) , tr ( " Paste from Clipboard " ) , pasteActionTriggered ) ;
2012-02-16 02:08:46 +01:00
2012-01-31 22:30:21 +01:00
//Setup template selector
loadTemplateList ( ) ;
2013-11-14 02:29:18 +01:00
connect ( ui - > cbxTemplate , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( templateSelected ( ) ) ) ;
2012-01-29 04:06:07 +01:00
}
AddJobDialog : : ~ AddJobDialog ( void )
{
2012-02-02 15:56:49 +01:00
//Free templates
2013-11-14 02:29:18 +01:00
for ( int i = 0 ; i < ui - > cbxTemplate - > model ( ) - > rowCount ( ) ; i + + )
2012-01-31 22:30:21 +01:00
{
2013-11-14 02:29:18 +01:00
if ( ui - > cbxTemplate - > itemText ( i ) . startsWith ( " < " ) | | ui - > cbxTemplate - > itemText ( i ) . endsWith ( " > " ) )
2012-01-31 22:30:21 +01:00
{
continue ;
}
2014-02-14 23:32:36 +01:00
const OptionsModel * item = reinterpret_cast < const OptionsModel * > ( ui - > cbxTemplate - > itemData ( i ) . value < const void * > ( ) ) ;
ui - > cbxTemplate - > setItemData ( i , QVariant : : fromValue < const void * > ( NULL ) ) ;
2012-01-31 22:30:21 +01:00
X264_DELETE ( item ) ;
}
2012-04-30 16:56:01 +02:00
//Free validators
2013-11-14 02:29:18 +01:00
if ( const QValidator * tmp = ui - > editCustomX264Params - > validator ( ) )
2012-04-30 16:56:01 +02:00
{
2013-11-14 02:29:18 +01:00
ui - > editCustomX264Params - > setValidator ( NULL ) ;
2012-04-30 16:56:01 +02:00
X264_DELETE ( tmp ) ;
}
2013-11-14 02:29:18 +01:00
if ( const QValidator * tmp = ui - > editCustomAvs2YUVParams - > validator ( ) )
2012-04-30 16:56:01 +02:00
{
2013-11-14 02:29:18 +01:00
ui - > editCustomAvs2YUVParams - > setValidator ( NULL ) ;
2012-04-30 16:56:01 +02:00
X264_DELETE ( tmp ) ;
}
2012-01-31 03:03:17 +01:00
X264_DELETE ( m_defaults ) ;
2013-11-14 02:29:18 +01:00
delete ui ;
2012-01-29 04:06:07 +01:00
}
2012-01-29 15:57:23 +01:00
///////////////////////////////////////////////////////////////////////////////
// Events
///////////////////////////////////////////////////////////////////////////////
2012-01-29 04:06:07 +01:00
void AddJobDialog : : showEvent ( QShowEvent * event )
{
QDialog : : showEvent ( event ) ;
2012-01-31 03:03:17 +01:00
templateSelected ( ) ;
2012-02-02 15:56:49 +01:00
2013-11-14 02:29:18 +01:00
if ( ( ! ui - > editSource - > text ( ) . isEmpty ( ) ) & & ui - > editOutput - > text ( ) . isEmpty ( ) )
2012-02-02 15:56:49 +01:00
{
2014-02-14 00:01:00 +01:00
QString outPath = generateOutputFileName ( QDir : : fromNativeSeparators ( ui - > editSource - > text ( ) ) , m_recentlyUsed - > outputDirectory ( ) , m_recentlyUsed - > filterIndex ( ) , m_preferences - > getSaveToSourcePath ( ) ) ;
2013-11-14 02:29:18 +01:00
ui - > editOutput - > setText ( QDir : : toNativeSeparators ( outPath ) ) ;
ui - > buttonAccept - > setFocus ( ) ;
2012-02-02 15:56:49 +01:00
}
2012-02-06 17:34:25 +01:00
2013-11-14 02:29:18 +01:00
ui - > labelNotificationX264 - > hide ( ) ;
ui - > iconNotificationX264 - > hide ( ) ;
ui - > labelNotificationAvs2YUV - > hide ( ) ;
ui - > iconNotificationAvs2YUV - > hide ( ) ;
2012-12-01 15:54:07 +01:00
//Enable drag&drop support for this window, required for Qt v4.8.4+
setAcceptDrops ( true ) ;
2012-01-29 04:06:07 +01:00
}
2012-01-31 00:13:32 +01:00
bool AddJobDialog : : eventFilter ( QObject * o , QEvent * e )
{
2013-11-14 02:29:18 +01:00
if ( ( o = = ui - > labelHelpScreenX264 ) & & ( e - > type ( ) = = QEvent : : MouseButtonPress ) )
2012-01-31 00:13:32 +01:00
{
2014-02-15 00:40:15 +01:00
OptionsModel options ( m_sysinfo ) ; saveOptions ( & options ) ;
2014-02-12 21:36:10 +01:00
HelpDialog * helpScreen = new HelpDialog ( this , false , m_sysinfo , & options , m_preferences ) ;
2012-02-12 15:58:28 +01:00
helpScreen - > exec ( ) ;
X264_DELETE ( helpScreen ) ;
}
2013-11-14 02:29:18 +01:00
else if ( ( o = = ui - > labelHelpScreenAvs2YUV ) & & ( e - > type ( ) = = QEvent : : MouseButtonPress ) )
2012-02-12 15:58:28 +01:00
{
2014-02-12 21:36:10 +01:00
HelpDialog * helpScreen = new HelpDialog ( this , false , m_sysinfo , m_defaults , m_preferences ) ;
2012-02-01 01:08:54 +01:00
helpScreen - > exec ( ) ;
X264_DELETE ( helpScreen ) ;
2012-01-31 20:28:40 +01:00
}
2013-11-14 02:29:18 +01:00
else if ( ( o = = ui - > editCustomX264Params ) & & ( e - > type ( ) = = QEvent : : FocusOut ) )
2012-01-31 20:28:40 +01:00
{
2013-11-14 02:29:18 +01:00
ui - > editCustomX264Params - > setText ( ui - > editCustomX264Params - > text ( ) . simplified ( ) ) ;
2012-01-31 00:13:32 +01:00
}
2013-11-14 02:29:18 +01:00
else if ( ( o = = ui - > editCustomAvs2YUVParams ) & & ( e - > type ( ) = = QEvent : : FocusOut ) )
2012-02-12 15:58:28 +01:00
{
2013-11-14 02:29:18 +01:00
ui - > editCustomAvs2YUVParams - > setText ( ui - > editCustomAvs2YUVParams - > text ( ) . simplified ( ) ) ;
2012-02-12 15:58:28 +01:00
}
2012-01-31 00:13:32 +01:00
return false ;
}
2012-02-10 18:42:16 +01:00
void AddJobDialog : : dragEnterEvent ( QDragEnterEvent * event )
{
2012-12-01 15:54:07 +01:00
bool accept [ 2 ] = { false , false } ;
foreach ( const QString & fmt , event - > mimeData ( ) - > formats ( ) )
{
accept [ 0 ] = accept [ 0 ] | | fmt . contains ( " text/uri-list " , Qt : : CaseInsensitive ) ;
accept [ 1 ] = accept [ 1 ] | | fmt . contains ( " FileNameW " , Qt : : CaseInsensitive ) ;
}
if ( accept [ 0 ] & & accept [ 1 ] )
2012-02-10 18:42:16 +01:00
{
event - > acceptProposedAction ( ) ;
}
}
void AddJobDialog : : dropEvent ( QDropEvent * event )
{
QString droppedFile ;
QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
if ( urls . count ( ) > 1 )
{
QDragEnterEvent dragEvent ( event - > pos ( ) , event - > proposedAction ( ) , event - > mimeData ( ) , Qt : : NoButton , Qt : : NoModifier ) ;
if ( qApp - > notify ( parent ( ) , & dragEvent ) )
{
qApp - > notify ( parent ( ) , event ) ;
reject ( ) ; return ;
}
}
while ( ( ! urls . isEmpty ( ) ) & & droppedFile . isEmpty ( ) )
{
QUrl currentUrl = urls . takeFirst ( ) ;
QFileInfo file ( currentUrl . toLocalFile ( ) ) ;
if ( file . exists ( ) & & file . isFile ( ) )
{
qDebug ( " AddJobDialog::dropEvent: %s " , file . canonicalFilePath ( ) . toUtf8 ( ) . constData ( ) ) ;
droppedFile = file . canonicalFilePath ( ) ;
}
}
if ( ! droppedFile . isEmpty ( ) )
{
2014-02-14 00:01:00 +01:00
const QString outFileName = generateOutputFileName ( droppedFile , currentOutputPath ( ) , currentOutputIndx ( ) , m_preferences - > getSaveToSourcePath ( ) ) ;
2013-11-14 02:29:18 +01:00
ui - > editSource - > setText ( QDir : : toNativeSeparators ( droppedFile ) ) ;
ui - > editOutput - > setText ( QDir : : toNativeSeparators ( outFileName ) ) ;
2012-02-10 18:42:16 +01:00
}
}
2012-01-29 15:57:23 +01:00
///////////////////////////////////////////////////////////////////////////////
// Slots
///////////////////////////////////////////////////////////////////////////////
2014-02-10 21:33:04 +01:00
void AddJobDialog : : encoderIndexChanged ( int index )
{
2014-02-12 21:36:10 +01:00
const bool isX265 = ( index > 0 ) ;
const bool noProf = isX265 | | ( ui - > cbxEncoderVariant - > currentIndex ( ) > 0 ) ;
2014-02-10 21:33:04 +01:00
ui - > cbxEncoderVariant - > setItemText ( 1 , isX265 ? tr ( " 16-Bit " ) : tr ( " 10-Bit " ) ) ;
2014-02-12 21:36:10 +01:00
ui - > labelProfile - > setEnabled ( ! noProf ) ;
ui - > cbxProfile - > setEnabled ( ! noProf ) ;
if ( noProf ) ui - > cbxProfile - > setCurrentIndex ( 0 ) ;
2014-04-16 14:57:32 +02:00
variantIndexChanged ( ui - > cbxEncoderVariant - > currentIndex ( ) ) ;
2014-02-12 21:36:10 +01:00
}
void AddJobDialog : : variantIndexChanged ( int index )
{
const bool noProf = ( index > 0 ) | | ( ui - > cbxEncoderType - > currentIndex ( ) > 0 ) ;
ui - > labelProfile - > setEnabled ( ! noProf ) ;
ui - > cbxProfile - > setEnabled ( ! noProf ) ;
if ( noProf ) ui - > cbxProfile - > setCurrentIndex ( 0 ) ;
2014-04-16 14:57:32 +02:00
modeIndexChanged ( ui - > cbxRateControlMode - > currentIndex ( ) ) ;
2014-02-10 21:33:04 +01:00
}
2012-01-29 04:06:07 +01:00
void AddJobDialog : : modeIndexChanged ( int index )
{
2014-04-16 14:57:32 +02:00
ui - > spinQuantizer - > setEnabled ( index = = OptionsModel : : RCMode_CRF | | index = = OptionsModel : : RCMode_CQ ) ;
ui - > spinBitrate - > setEnabled ( index = = OptionsModel : : RCMode_ABR | | index = = OptionsModel : : RCMode_2Pass ) ;
2012-01-29 04:06:07 +01:00
}
2012-01-29 15:57:23 +01:00
void AddJobDialog : : accept ( void )
{
2014-02-21 17:52:16 +01:00
//Check x265 support
if ( ( ui - > cbxEncoderType - > currentIndex ( ) = = OptionsModel : : EncType_X265 ) & & ( ! m_sysinfo - > has256Support ( ) ) )
2014-02-15 00:13:22 +01:00
{
2014-02-21 17:52:16 +01:00
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> " ) ) ;
2014-02-15 00:13:22 +01:00
ui - > cbxEncoderType - > setCurrentIndex ( OptionsModel : : EncType_X264 ) ;
return ;
}
2014-02-11 02:33:17 +01:00
//Check 64-Bit support
2014-02-12 21:36:10 +01:00
if ( ( ui - > cbxEncoderArch - > currentIndex ( ) = = OptionsModel : : EncArch_x64 ) & & ( ! m_sysinfo - > hasX64Support ( ) ) )
2014-02-11 02:33:17 +01:00
{
2014-02-21 17:52:16 +01:00
QMessageBox : : warning ( this , tr ( " 64-Bit unsupported! " ) , tr ( " <nobr>Sorry, this computer does <b>not</b> support 64-Bit encoders!</nobr> " ) ) ;
2014-02-11 02:33:17 +01:00
ui - > cbxEncoderArch - > setCurrentIndex ( OptionsModel : : EncArch_x32 ) ;
return ;
}
2013-05-08 22:46:25 +02:00
//Selection complete?
2013-11-14 02:29:18 +01:00
if ( ui - > editSource - > text ( ) . trimmed ( ) . isEmpty ( ) )
2012-01-29 15:57:23 +01:00
{
2014-02-21 17:52:16 +01:00
QMessageBox : : warning ( this , tr ( " Not Found! " ) , tr ( " <nobr>Please select a valid source file first!<(nobr> " ) ) ;
2012-01-29 15:57:23 +01:00
return ;
}
2013-11-14 02:29:18 +01:00
if ( ui - > editOutput - > text ( ) . trimmed ( ) . isEmpty ( ) )
2012-02-02 15:56:49 +01:00
{
2012-02-06 17:34:25 +01:00
QMessageBox : : warning ( this , tr ( " Not Selected! " ) , tr ( " <nobr>Please select a valid output file first!</nobr> " ) ) ;
2012-02-02 15:56:49 +01:00
return ;
}
2013-05-08 22:46:25 +02:00
//Does source exist?
QFileInfo sourceFile = QFileInfo ( this - > sourceFile ( ) ) ;
2012-01-29 15:57:23 +01:00
if ( ! ( sourceFile . exists ( ) & & sourceFile . isFile ( ) ) )
{
2012-02-06 17:34:25 +01:00
QMessageBox : : warning ( this , tr ( " Not Found! " ) , tr ( " <nobr>The selected source file could not be found!</nobr> " ) ) ;
2012-01-29 15:57:23 +01:00
return ;
}
2014-04-11 15:33:02 +02:00
//Get encoder info
2014-04-16 13:49:36 +02:00
const AbstractEncoderInfo & encoderInfo = EncoderFactory : : getEncoderInfo ( ui - > cbxEncoderType - > currentIndex ( ) ) ;
2014-04-11 15:33:02 +02:00
2014-04-15 22:12:02 +02:00
//Is selected RC mode supported?
if ( ! encoderInfo . isRCModeSupported ( ui - > cbxRateControlMode - > currentIndex ( ) ) )
{
QMessageBox : : warning ( this , tr ( " Bad RC Mode! " ) , tr ( " <nobr>The selected RC mode is not supported by the selected encoder!</nobr> " ) ) ;
for ( int i = 0 ; i < ui - > cbxRateControlMode - > count ( ) ; i + + )
{
if ( encoderInfo . isRCModeSupported ( i ) )
{
ui - > cbxRateControlMode - > setCurrentIndex ( i ) ;
break ;
}
}
return ;
}
2014-04-11 15:33:02 +02:00
//Is the type of the source file supported? (as far as we can tell)
if ( sourceFile . suffix ( ) . compare ( " AVS " , Qt : : CaseInsensitive ) = = 0 )
2014-02-21 17:52:16 +01:00
{
2014-04-11 15:33:02 +02:00
if ( ! m_sysinfo - > hasAVSSupport ( ) )
2014-02-21 17:52:16 +01:00
{
2014-04-11 15:33:02 +02:00
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 )
{
return ;
}
2014-02-21 17:52:16 +01:00
}
}
2014-04-11 15:33:02 +02:00
else if ( ( sourceFile . suffix ( ) . compare ( " VPY " , Qt : : CaseInsensitive ) = = 0 ) | | ( sourceFile . suffix ( ) . compare ( " PY " , Qt : : CaseInsensitive ) = = 0 ) )
2014-02-21 17:52:16 +01:00
{
2014-04-11 15:33:02 +02:00
if ( ! m_sysinfo - > hasVPSSupport ( ) )
2014-02-21 17:52:16 +01:00
{
2014-04-11 15:33:02 +02:00
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 )
{
return ;
}
}
}
else
{
const QStringList inputFormats = encoderInfo . supportedInputFormats ( ) ;
if ( ! inputFormats . contains ( sourceFile . suffix ( ) , Qt : : CaseInsensitive ) )
{
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 ( " Ingnore (at your own risk!) " ) ) ! = 1 )
{
return ;
}
2014-02-21 17:52:16 +01:00
}
}
2014-02-21 23:57:03 +01:00
2014-04-11 15:33:02 +02:00
2014-02-22 20:32:46 +01:00
//Is output file extension supported by encoder?
2014-04-11 15:33:02 +02:00
const QStringList outputFormats = encoderInfo . supportedOutputFormats ( ) ;
2013-05-08 22:46:25 +02:00
QFileInfo outputFile = QFileInfo ( this - > outputFile ( ) ) ;
2014-04-11 15:33:02 +02:00
if ( ! outputFormats . contains ( outputFile . suffix ( ) , Qt : : CaseInsensitive ) )
2014-02-21 23:57:03 +01:00
{
2014-04-11 15:33:02 +02:00
QMessageBox : : warning ( this , tr ( " Unsupported output format " ) , tr ( " <nobr>Sorry, the selected encoder does not support the selected output format!</nobr> " ) ) ;
ui - > editOutput - > setText ( QDir : : toNativeSeparators ( QString ( " %1/%2.%3 " ) . arg ( outputFile . absolutePath ( ) , outputFile . completeBaseName ( ) , outputFormats . first ( ) ) ) ) ;
2014-02-21 23:57:03 +01:00
return ;
}
//Does output file already exist?
2012-01-29 15:57:23 +01:00
if ( outputFile . exists ( ) & & outputFile . isFile ( ) )
{
2012-02-06 17:34:25 +01:00
int ret = QMessageBox : : question ( this , tr ( " Already Exists! " ) , tr ( " <nobr>Output file already exists! Overwrite?</nobr> " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ;
if ( ret ! = QMessageBox : : Yes ) return ;
2012-01-29 15:57:23 +01:00
}
if ( outputFile . exists ( ) & & ( ! outputFile . isFile ( ) ) )
{
2012-02-10 18:42:16 +01:00
QMessageBox : : warning ( this , tr ( " Not a File! " ) , tr ( " <nobr>Selected output file does not appear to be a valid file!</nobr> " ) ) ;
2012-01-29 15:57:23 +01:00
return ;
}
2013-05-08 22:46:25 +02:00
2013-05-11 01:50:05 +02:00
//Is destination dir writable?
QFileInfo outputDir = QFileInfo ( outputFile . absolutePath ( ) ) ;
if ( ! ( outputDir . exists ( ) & & outputDir . isDir ( ) & & outputDir . isWritable ( ) ) )
{
QMessageBox : : warning ( this , tr ( " Not Writable! " ) , tr ( " <nobr>Output directory does not exist or is not writable!</nobr> " ) ) ;
return ;
}
2013-05-08 22:46:25 +02:00
//Custom parameters okay?
2013-11-14 02:29:18 +01:00
if ( ! ui - > editCustomX264Params - > hasAcceptableInput ( ) )
2012-02-06 17:34:25 +01:00
{
int ret = QMessageBox : : warning ( this , tr ( " Invalid Params " ) , tr ( " <nobr>Your custom parameters are invalid and will be discarded!</nobr> " ) , QMessageBox : : Ignore | QMessageBox : : Cancel , QMessageBox : : Cancel ) ;
if ( ret ! = QMessageBox : : Ignore ) return ;
}
2012-01-29 15:57:23 +01:00
2013-05-08 22:46:25 +02:00
//Update recently used
2013-07-03 21:34:21 +02:00
m_recentlyUsed - > setFilterIndex ( currentOutputIndx ( ) ) ;
m_recentlyUsed - > setSourceDirectory ( currentSourcePath ( ) ) ;
m_recentlyUsed - > setOutputDirectory ( currentOutputPath ( ) ) ;
RecentlyUsed : : saveRecentlyUsed ( m_recentlyUsed ) ;
2012-02-02 15:56:49 +01:00
2013-05-08 22:46:25 +02:00
//Save options
2012-01-29 19:14:46 +01:00
saveOptions ( m_options ) ;
2012-01-29 15:57:23 +01:00
QDialog : : accept ( ) ;
}
void AddJobDialog : : browseButtonClicked ( void )
{
2013-11-14 02:29:18 +01:00
if ( QObject : : sender ( ) = = ui - > buttonBrowseSource )
2012-01-29 15:57:23 +01:00
{
2013-05-11 01:50:05 +02:00
QString filePath = QFileDialog : : getOpenFileName ( this , tr ( " Open Source File " ) , currentSourcePath ( true ) , getInputFilterLst ( ) , NULL , QFileDialog : : DontUseNativeDialog ) ;
2012-01-29 15:57:23 +01:00
if ( ! ( filePath . isNull ( ) | | filePath . isEmpty ( ) ) )
{
2014-02-14 00:01:00 +01:00
QString destFile = generateOutputFileName ( filePath , currentOutputPath ( ) , currentOutputIndx ( ) , m_preferences - > getSaveToSourcePath ( ) ) ;
2013-11-14 02:29:18 +01:00
ui - > editSource - > setText ( QDir : : toNativeSeparators ( filePath ) ) ;
ui - > editOutput - > setText ( QDir : : toNativeSeparators ( destFile ) ) ;
2012-01-29 15:57:23 +01:00
}
}
2013-11-14 02:29:18 +01:00
else if ( QObject : : sender ( ) = = ui - > buttonBrowseOutput )
2012-01-29 15:57:23 +01:00
{
2013-05-11 01:50:05 +02:00
QString selectedType = getFilterStr ( currentOutputIndx ( ) ) ;
QString filePath = QFileDialog : : getSaveFileName ( this , tr ( " Choose Output File " ) , currentOutputPath ( true ) , getFilterLst ( ) , & selectedType , QFileDialog : : DontUseNativeDialog | QFileDialog : : DontConfirmOverwrite ) ;
2012-02-04 22:44:19 +01:00
2012-02-05 02:49:08 +01:00
if ( ! ( filePath . isNull ( ) | | filePath . isEmpty ( ) ) )
{
2013-05-08 22:46:25 +02:00
if ( getFilterIdx ( QFileInfo ( filePath ) . suffix ( ) ) < 0 )
2012-02-05 02:49:08 +01:00
{
2013-05-11 01:50:05 +02:00
int tempIndex = - 1 ;
QRegExp regExp ( " \\ ( \\ * \\ .( \\ w+) \ \ ) " ) ;
if ( regExp . lastIndexIn ( selectedType ) > = 0 )
{
tempIndex = getFilterIdx ( regExp . cap ( 1 ) ) ;
}
if ( tempIndex < 0 )
{
2013-07-03 21:34:21 +02:00
tempIndex = m_recentlyUsed - > filterIndex ( ) ;
2013-05-11 01:50:05 +02:00
}
filePath = QString ( " %1.%2 " ) . arg ( filePath , getFilterExt ( tempIndex ) ) ;
2012-02-05 02:49:08 +01:00
}
2013-11-14 02:29:18 +01:00
ui - > editOutput - > setText ( QDir : : toNativeSeparators ( filePath ) ) ;
2012-01-29 15:57:23 +01:00
}
}
}
2012-01-29 19:14:46 +01:00
2012-01-31 03:03:17 +01:00
void AddJobDialog : : configurationChanged ( void )
{
2014-02-12 21:36:10 +01:00
const OptionsModel * options = reinterpret_cast < const OptionsModel * > ( ui - > cbxTemplate - > itemData ( ui - > cbxTemplate - > currentIndex ( ) ) . value < const void * > ( ) ) ;
2012-01-31 03:03:17 +01:00
if ( options )
{
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > blockSignals ( true ) ;
2014-02-12 21:36:10 +01:00
ui - > cbxTemplate - > insertItem ( 0 , tr ( " <Unsaved Configuration> " ) , QVariant : : fromValue < const void * > ( NULL ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > setCurrentIndex ( 0 ) ;
ui - > cbxTemplate - > blockSignals ( false ) ;
2012-01-31 03:03:17 +01:00
}
}
void AddJobDialog : : templateSelected ( void )
{
2014-02-12 21:36:10 +01:00
const OptionsModel * options = reinterpret_cast < const OptionsModel * > ( ui - > cbxTemplate - > itemData ( ui - > cbxTemplate - > currentIndex ( ) ) . value < const void * > ( ) ) ;
2012-01-31 03:03:17 +01:00
if ( options )
{
qDebug ( " Loading options! " ) ;
2012-02-02 18:55:55 +01:00
REMOVE_USAFED_ITEM ;
2012-01-31 03:03:17 +01:00
restoreOptions ( options ) ;
}
2014-02-10 21:33:04 +01:00
//Force updates
2014-02-14 23:58:39 +01:00
encoderIndexChanged ( ui - > cbxEncoderType - > currentIndex ( ) ) ;
variantIndexChanged ( ui - > cbxEncoderVariant - > currentIndex ( ) ) ;
2013-11-14 02:29:18 +01:00
modeIndexChanged ( ui - > cbxRateControlMode - > currentIndex ( ) ) ;
2012-01-31 03:03:17 +01:00
}
2012-01-31 22:30:21 +01:00
void AddJobDialog : : saveTemplateButtonClicked ( void )
{
qDebug ( " Saving template " ) ;
QString name = tr ( " New Template " ) ;
2012-02-04 19:09:27 +01:00
int n = 2 ;
while ( OptionsModel : : templateExists ( name ) )
{
name = tr ( " New Template (%1) " ) . arg ( QString : : number ( n + + ) ) ;
}
2012-01-31 22:30:21 +01:00
2014-02-15 00:40:15 +01:00
OptionsModel * options = new OptionsModel ( m_sysinfo ) ;
2012-02-02 18:55:55 +01:00
saveOptions ( options ) ;
if ( options - > equals ( m_defaults ) )
{
2012-02-04 19:09:27 +01:00
QMessageBox : : warning ( this , tr ( " Oups " ) , tr ( " <nobr>It makes no sense to save the default settings!</nobr> " ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > blockSignals ( true ) ;
ui - > cbxTemplate - > setCurrentIndex ( 0 ) ;
ui - > cbxTemplate - > blockSignals ( false ) ;
2012-02-02 18:55:55 +01:00
REMOVE_USAFED_ITEM ;
X264_DELETE ( options ) ;
return ;
}
2013-11-14 02:29:18 +01:00
for ( int i = 0 ; i < ui - > cbxTemplate - > count ( ) ; i + + )
2012-02-02 18:55:55 +01:00
{
2013-11-14 02:29:18 +01:00
const QString tempName = ui - > cbxTemplate - > itemText ( i ) ;
2012-02-13 16:44:50 +01:00
if ( tempName . contains ( ' < ' ) | | tempName . contains ( ' > ' ) )
{
continue ;
}
2014-02-14 23:32:36 +01:00
const OptionsModel * test = reinterpret_cast < const OptionsModel * > ( ui - > cbxTemplate - > itemData ( i ) . value < const void * > ( ) ) ;
2012-02-02 18:55:55 +01:00
if ( test ! = NULL )
{
if ( options - > equals ( test ) )
{
2012-02-04 19:09:27 +01:00
QMessageBox : : warning ( this , tr ( " Oups " ) , tr ( " <nobr>There already is a template for the current settings!</nobr> " ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > blockSignals ( true ) ;
ui - > cbxTemplate - > setCurrentIndex ( i ) ;
ui - > cbxTemplate - > blockSignals ( false ) ;
2012-02-02 18:55:55 +01:00
REMOVE_USAFED_ITEM ;
X264_DELETE ( options ) ;
return ;
}
}
}
2012-01-31 22:30:21 +01:00
forever
{
bool ok = false ;
2012-02-04 19:09:27 +01:00
name = QInputDialog : : getText ( this , tr ( " Save Template " ) , tr ( " Please enter the name of the template: " ) . leftJustified ( 144 , ' ' ) , QLineEdit : : Normal , name , & ok ) . simplified ( ) ;
2012-02-02 18:55:55 +01:00
if ( ! ok )
{
X264_DELETE ( options ) ;
return ;
}
if ( name . contains ( ' < ' ) | | name . contains ( ' > ' ) | | name . contains ( ' \\ ' ) | | name . contains ( ' / ' ) | | name . contains ( ' " ' ) )
2012-01-31 22:30:21 +01:00
{
2012-02-04 19:09:27 +01:00
QMessageBox : : warning ( this , tr ( " Invalid Name " ) , tr ( " <nobr>Sorry, the name you have entered is invalid!</nobr> " ) ) ;
2012-02-02 18:55:55 +01:00
while ( name . contains ( ' < ' ) ) name . remove ( ' < ' ) ;
while ( name . contains ( ' > ' ) ) name . remove ( ' > ' ) ;
while ( name . contains ( ' \\ ' ) ) name . remove ( ' \\ ' ) ;
while ( name . contains ( ' / ' ) ) name . remove ( ' / ' ) ;
while ( name . contains ( ' " ' ) ) name . remove ( ' " ' ) ;
name = name . simplified ( ) ;
2012-01-31 22:30:21 +01:00
continue ;
}
if ( OptionsModel : : templateExists ( name ) )
{
2012-02-04 19:09:27 +01:00
int ret = QMessageBox : : warning ( this , tr ( " Already Exists " ) , tr ( " <nobr>A template of that name already exists! Overwrite?</nobr> " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ;
if ( ret ! = QMessageBox : : Yes )
{
continue ;
}
2012-01-31 22:30:21 +01:00
}
break ;
}
if ( ! OptionsModel : : saveTemplate ( options , name ) )
{
2012-02-02 18:55:55 +01:00
QMessageBox : : critical ( this , tr ( " Save Failed " ) , tr ( " Sorry, the template could not be saved! " ) ) ;
2012-01-31 22:30:21 +01:00
X264_DELETE ( options ) ;
return ;
}
2013-11-14 02:29:18 +01:00
int index = ui - > cbxTemplate - > model ( ) - > rowCount ( ) ;
ui - > cbxTemplate - > blockSignals ( true ) ;
for ( int i = 0 ; i < ui - > cbxTemplate - > count ( ) ; i + + )
2012-02-04 19:09:27 +01:00
{
2013-11-14 02:29:18 +01:00
if ( ui - > cbxTemplate - > itemText ( i ) . compare ( name , Qt : : CaseInsensitive ) = = 0 )
2012-02-04 19:09:27 +01:00
{
index = - 1 ; //Do not append new template
2014-02-14 23:32:36 +01:00
const OptionsModel * oldItem = reinterpret_cast < const OptionsModel * > ( ui - > cbxTemplate - > itemData ( i ) . value < const void * > ( ) ) ;
ui - > cbxTemplate - > setItemData ( i , QVariant : : fromValue < const void * > ( options ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > setCurrentIndex ( i ) ;
2012-02-04 19:09:27 +01:00
X264_DELETE ( oldItem ) ;
}
}
if ( index > = 0 )
{
2014-02-14 23:32:36 +01:00
ui - > cbxTemplate - > insertItem ( index , name , QVariant : : fromValue < const void * > ( options ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > setCurrentIndex ( index ) ;
2012-02-04 19:09:27 +01:00
}
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > blockSignals ( false ) ;
2012-02-02 18:55:55 +01:00
REMOVE_USAFED_ITEM ;
2012-01-31 22:30:21 +01:00
}
void AddJobDialog : : deleteTemplateButtonClicked ( void )
{
2013-11-14 02:29:18 +01:00
const int index = ui - > cbxTemplate - > currentIndex ( ) ;
QString name = ui - > cbxTemplate - > itemText ( index ) ;
2012-01-31 22:30:21 +01:00
2012-02-04 19:09:27 +01:00
if ( name . contains ( ' < ' ) | | name . contains ( ' > ' ) | | name . contains ( ' \\ ' ) | | name . contains ( ' / ' ) )
2012-01-31 22:30:21 +01:00
{
QMessageBox : : warning ( this , tr ( " Invalid Item " ) , tr ( " Sorry, the selected item cannot be deleted! " ) ) ;
return ;
}
2012-02-04 19:09:27 +01:00
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 ) ;
if ( ret ! = QMessageBox : : Yes )
{
return ;
}
2012-01-31 22:30:21 +01:00
OptionsModel : : deleteTemplate ( name ) ;
2014-02-14 23:32:36 +01:00
const OptionsModel * item = reinterpret_cast < const OptionsModel * > ( ui - > cbxTemplate - > itemData ( index ) . value < const void * > ( ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > removeItem ( index ) ;
2012-01-31 22:30:21 +01:00
X264_DELETE ( item ) ;
}
2012-02-16 02:08:46 +01:00
void AddJobDialog : : editorActionTriggered ( void )
{
if ( QAction * action = dynamic_cast < QAction * > ( QObject : : sender ( ) ) )
{
QLineEdit * lineEdit = reinterpret_cast < QLineEdit * > ( action - > data ( ) . value < void * > ( ) ) ;
EditorDialog * editor = new EditorDialog ( this ) ;
editor - > setEditText ( lineEdit - > text ( ) ) ;
if ( editor - > exec ( ) = = QDialog : : Accepted )
{
lineEdit - > setText ( editor - > getEditText ( ) ) ;
}
X264_DELETE ( editor ) ;
}
}
2012-02-16 14:33:26 +01:00
void AddJobDialog : : copyActionTriggered ( void )
{
if ( QAction * action = dynamic_cast < QAction * > ( QObject : : sender ( ) ) )
{
QClipboard * clipboard = QApplication : : clipboard ( ) ;
QLineEdit * lineEdit = reinterpret_cast < QLineEdit * > ( action - > data ( ) . value < void * > ( ) ) ;
QString text = lineEdit - > hasSelectedText ( ) ? lineEdit - > selectedText ( ) : lineEdit - > text ( ) ;
clipboard - > setText ( text ) ;
}
}
void AddJobDialog : : pasteActionTriggered ( void )
{
if ( QAction * action = dynamic_cast < QAction * > ( QObject : : sender ( ) ) )
{
QClipboard * clipboard = QApplication : : clipboard ( ) ;
QLineEdit * lineEdit = reinterpret_cast < QLineEdit * > ( action - > data ( ) . value < void * > ( ) ) ;
QString text = clipboard - > text ( ) ;
if ( ! text . isEmpty ( ) ) lineEdit - > setText ( text ) ;
}
}
2012-01-29 21:31:09 +01:00
///////////////////////////////////////////////////////////////////////////////
// Public functions
///////////////////////////////////////////////////////////////////////////////
QString AddJobDialog : : sourceFile ( void )
{
2013-11-14 02:29:18 +01:00
return QDir : : fromNativeSeparators ( ui - > editSource - > text ( ) ) ;
2012-01-29 21:31:09 +01:00
}
QString AddJobDialog : : outputFile ( void )
{
2013-11-14 02:29:18 +01:00
return QDir : : fromNativeSeparators ( ui - > editOutput - > text ( ) ) ;
}
bool AddJobDialog : : runImmediately ( void )
{
return ui - > checkBoxRun - > isChecked ( ) ;
}
bool AddJobDialog : : applyToAll ( void )
{
return ui - > checkBoxApplyToAll - > isChecked ( ) ;
}
void AddJobDialog : : setRunImmediately ( bool run )
{
ui - > checkBoxRun - > setChecked ( run ) ;
}
void AddJobDialog : : setSourceFile ( const QString & path )
{
ui - > editSource - > setText ( QDir : : toNativeSeparators ( path ) ) ;
}
void AddJobDialog : : setOutputFile ( const QString & path )
{
ui - > editOutput - > setText ( QDir : : toNativeSeparators ( path ) ) ; }
void AddJobDialog : : setSourceEditable ( const bool editable )
{
ui - > buttonBrowseSource - > setEnabled ( editable ) ;
}
void AddJobDialog : : setApplyToAllVisible ( const bool visible )
{
ui - > checkBoxApplyToAll - > setVisible ( visible ) ;
2012-01-29 21:31:09 +01:00
}
2012-01-29 19:14:46 +01:00
///////////////////////////////////////////////////////////////////////////////
// Private functions
///////////////////////////////////////////////////////////////////////////////
2012-01-31 22:30:21 +01:00
void AddJobDialog : : loadTemplateList ( void )
{
2014-02-12 21:36:10 +01:00
ui - > cbxTemplate - > addItem ( tr ( " <Default> " ) , QVariant : : fromValue < const void * > ( m_defaults ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > setCurrentIndex ( 0 ) ;
2012-01-31 22:30:21 +01:00
2014-02-15 00:40:15 +01:00
QMap < QString , OptionsModel * > templates = OptionsModel : : loadAllTemplates ( m_sysinfo ) ;
2012-01-31 22:30:21 +01:00
QStringList templateNames = templates . keys ( ) ;
templateNames . sort ( ) ;
2014-02-11 02:33:17 +01:00
for ( QStringList : : ConstIterator current = templateNames . constBegin ( ) ; current ! = templateNames . constEnd ( ) ; current + + )
2012-01-31 22:30:21 +01:00
{
2014-02-11 02:33:17 +01:00
OptionsModel * currentTemplate = templates . take ( * current ) ;
2014-02-12 21:36:10 +01:00
ui - > cbxTemplate - > addItem ( * current , QVariant : : fromValue < const void * > ( currentTemplate ) ) ;
2014-02-11 02:33:17 +01:00
if ( currentTemplate - > equals ( m_options ) )
2012-01-31 22:30:21 +01:00
{
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > setCurrentIndex ( ui - > cbxTemplate - > count ( ) - 1 ) ;
2012-01-31 22:30:21 +01:00
}
}
2013-11-14 02:29:18 +01:00
if ( ( ui - > cbxTemplate - > currentIndex ( ) = = 0 ) & & ( ! m_options - > equals ( m_defaults ) ) )
2012-01-31 22:30:21 +01:00
{
2014-02-11 02:33:17 +01:00
qWarning ( " Not the default -> recently used! " ) ;
2014-02-12 21:36:10 +01:00
ui - > cbxTemplate - > insertItem ( 1 , tr ( " <Recently Used> " ) , QVariant : : fromValue < const void * > ( m_options ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxTemplate - > setCurrentIndex ( 1 ) ;
2012-01-31 22:30:21 +01:00
}
}
2012-01-29 19:14:46 +01:00
void AddJobDialog : : updateComboBox ( QComboBox * cbox , const QString & text )
{
2014-02-10 21:33:04 +01:00
int index = - 1 ;
if ( QAbstractItemModel * model = cbox - > model ( ) )
2012-01-29 19:14:46 +01:00
{
2014-02-10 21:33:04 +01:00
for ( int i = 0 ; i < cbox - > model ( ) - > rowCount ( ) ; i + + )
2012-01-29 19:14:46 +01:00
{
2014-02-10 21:33:04 +01:00
if ( model - > data ( model - > index ( i , 0 , QModelIndex ( ) ) ) . toString ( ) . compare ( text , Qt : : CaseInsensitive ) = = 0 )
{
index = i ;
break ;
}
2012-01-29 19:14:46 +01:00
}
}
2014-02-10 21:33:04 +01:00
cbox - > setCurrentIndex ( index ) ;
2012-01-29 19:14:46 +01:00
}
2014-02-12 21:36:10 +01:00
void AddJobDialog : : restoreOptions ( const OptionsModel * options )
2012-01-29 19:14:46 +01:00
{
2014-02-11 02:33:17 +01:00
BLOCK_SIGNALS ( true ) ;
2013-11-14 02:29:18 +01:00
2014-02-11 02:33:17 +01:00
ui - > cbxEncoderType - > setCurrentIndex ( options - > encType ( ) ) ;
ui - > cbxEncoderArch - > setCurrentIndex ( options - > encArch ( ) ) ;
ui - > cbxEncoderVariant - > setCurrentIndex ( options - > encVariant ( ) ) ;
2013-11-14 02:29:18 +01:00
ui - > cbxRateControlMode - > setCurrentIndex ( options - > rcMode ( ) ) ;
ui - > spinQuantizer - > setValue ( options - > quantizer ( ) ) ;
ui - > spinBitrate - > setValue ( options - > bitrate ( ) ) ;
updateComboBox ( ui - > cbxPreset , options - > preset ( ) ) ;
updateComboBox ( ui - > cbxTuning , options - > tune ( ) ) ;
updateComboBox ( ui - > cbxProfile , options - > profile ( ) ) ;
2014-02-10 21:33:04 +01:00
ui - > editCustomX264Params - > setText ( options - > customEncParams ( ) ) ;
2013-11-14 02:29:18 +01:00
ui - > editCustomAvs2YUVParams - > setText ( options - > customAvs2YUV ( ) ) ;
2014-02-11 02:33:17 +01:00
BLOCK_SIGNALS ( false ) ;
2012-01-29 19:14:46 +01:00
}
void AddJobDialog : : saveOptions ( OptionsModel * options )
{
2014-02-11 02:33:17 +01:00
options - > setEncType ( static_cast < OptionsModel : : EncType > ( ui - > cbxEncoderType - > currentIndex ( ) ) ) ;
options - > setEncArch ( static_cast < OptionsModel : : EncArch > ( ui - > cbxEncoderArch - > currentIndex ( ) ) ) ;
2014-02-10 21:33:04 +01:00
options - > setEncVariant ( static_cast < OptionsModel : : EncVariant > ( ui - > cbxEncoderVariant - > currentIndex ( ) ) ) ;
2013-11-14 02:29:18 +01:00
options - > setRCMode ( static_cast < OptionsModel : : RCMode > ( ui - > cbxRateControlMode - > currentIndex ( ) ) ) ;
options - > setQuantizer ( ui - > spinQuantizer - > value ( ) ) ;
options - > setBitrate ( ui - > spinBitrate - > value ( ) ) ;
options - > setPreset ( ui - > cbxPreset - > model ( ) - > data ( ui - > cbxPreset - > model ( ) - > index ( ui - > cbxPreset - > currentIndex ( ) , 0 ) ) . toString ( ) ) ;
options - > setTune ( ui - > cbxTuning - > model ( ) - > data ( ui - > cbxTuning - > model ( ) - > index ( ui - > cbxTuning - > currentIndex ( ) , 0 ) ) . toString ( ) ) ;
options - > setProfile ( ui - > cbxProfile - > model ( ) - > data ( ui - > cbxProfile - > model ( ) - > index ( ui - > cbxProfile - > currentIndex ( ) , 0 ) ) . toString ( ) ) ;
2014-02-10 21:33:04 +01:00
options - > setCustomEncParams ( ui - > editCustomX264Params - > hasAcceptableInput ( ) ? ui - > editCustomX264Params - > text ( ) . simplified ( ) : QString ( ) ) ;
2013-11-14 02:29:18 +01:00
options - > setCustomAvs2YUV ( ui - > editCustomAvs2YUVParams - > hasAcceptableInput ( ) ? ui - > editCustomAvs2YUVParams - > text ( ) . simplified ( ) : QString ( ) ) ;
2012-01-29 19:14:46 +01:00
}
2012-01-30 17:50:19 +01:00
2013-05-11 01:50:05 +02:00
QString AddJobDialog : : currentSourcePath ( const bool bWithName )
2012-02-02 15:56:49 +01:00
{
2013-07-03 21:34:21 +02:00
QString path = m_recentlyUsed - > sourceDirectory ( ) ;
2013-05-11 01:50:05 +02:00
QString currentSourceFile = this - > sourceFile ( ) ;
if ( ! currentSourceFile . isEmpty ( ) )
{
QString currentSourceDir = QFileInfo ( currentSourceFile ) . absolutePath ( ) ;
if ( VALID_DIR ( currentSourceDir ) )
{
path = currentSourceDir ;
}
if ( bWithName )
{
path . append ( " / " ) . append ( QFileInfo ( currentSourceFile ) . fileName ( ) ) ;
}
}
return path ;
}
2012-02-02 15:56:49 +01:00
2013-05-11 01:50:05 +02:00
QString AddJobDialog : : currentOutputPath ( const bool bWithName )
{
2013-07-03 21:34:21 +02:00
QString path = m_recentlyUsed - > outputDirectory ( ) ;
2013-05-11 01:50:05 +02:00
QString currentOutputFile = this - > outputFile ( ) ;
if ( ! currentOutputFile . isEmpty ( ) )
2012-02-02 15:56:49 +01:00
{
2013-05-11 01:50:05 +02:00
QString currentOutputDir = QFileInfo ( currentOutputFile ) . absolutePath ( ) ;
if ( VALID_DIR ( currentOutputDir ) )
{
path = currentOutputDir ;
}
if ( bWithName )
2012-02-02 15:56:49 +01:00
{
2013-05-11 01:50:05 +02:00
path . append ( " / " ) . append ( QFileInfo ( currentOutputFile ) . fileName ( ) ) ;
2012-02-02 15:56:49 +01:00
}
}
2013-05-11 01:50:05 +02:00
return path ;
2012-02-02 15:56:49 +01:00
}
2012-02-22 23:53:16 +01:00
2013-05-11 01:50:05 +02:00
int AddJobDialog : : currentOutputIndx ( void )
2012-02-22 23:53:16 +01:00
{
2014-02-21 23:57:03 +01:00
if ( ui - > cbxEncoderType - > currentIndex ( ) = = OptionsModel : : EncType_X265 )
{
return ARRAY_SIZE ( X264_FILE_TYPE_FILTERS ) - 1 ;
}
2013-05-11 01:50:05 +02:00
2014-02-21 23:57:03 +01:00
int index = m_recentlyUsed - > filterIndex ( ) ;
const QString currentOutputFile = this - > outputFile ( ) ;
2013-05-11 01:50:05 +02:00
if ( ! currentOutputFile . isEmpty ( ) )
2012-02-22 23:53:16 +01:00
{
2013-05-11 01:50:05 +02:00
const QString currentOutputExtn = QFileInfo ( currentOutputFile ) . suffix ( ) ;
const int tempIndex = getFilterIdx ( currentOutputExtn ) ;
if ( tempIndex > = 0 )
2012-02-22 23:53:16 +01:00
{
2013-05-11 01:50:05 +02:00
index = tempIndex ;
2012-02-22 23:53:16 +01:00
}
}
2013-05-11 01:50:05 +02:00
return index ;
2012-02-22 23:53:16 +01:00
}
2013-05-08 00:04:40 +02:00
///////////////////////////////////////////////////////////////////////////////
// Static functions
///////////////////////////////////////////////////////////////////////////////
QString AddJobDialog : : generateOutputFileName ( const QString & sourceFilePath , const QString & destinationDirectory , const int filterIndex , const bool saveToSourceDir )
{
QString name = QFileInfo ( sourceFilePath ) . completeBaseName ( ) ;
QString path = saveToSourceDir ? QFileInfo ( sourceFilePath ) . canonicalPath ( ) : destinationDirectory ;
QString fext = getFilterExt ( filterIndex ) ;
if ( ! VALID_DIR ( path ) )
{
2013-05-08 22:46:25 +02:00
RecentlyUsed defaults ;
2013-07-03 21:34:21 +02:00
path = defaults . outputDirectory ( ) ;
2013-05-08 00:04:40 +02:00
}
QString outPath = QString ( " %1/%2.%3 " ) . arg ( path , name , fext ) ;
2013-05-08 22:46:25 +02:00
int n = 2 ;
while ( QFileInfo ( outPath ) . exists ( ) )
2013-05-08 00:04:40 +02:00
{
2013-05-08 22:46:25 +02:00
outPath = QString ( " %1/%2 (%3).%4 " ) . arg ( path , name , QString : : number ( n + + ) , fext ) ;
2013-05-08 00:04:40 +02:00
}
2013-05-08 22:46:25 +02:00
return outPath ;
2013-05-08 00:04:40 +02:00
}
/* ------------------------------------------------------------------------- */
QString AddJobDialog : : getFilterExt ( const int filterIndex )
2012-02-22 23:53:16 +01:00
{
2013-07-03 21:34:21 +02:00
const int count = ARRAY_SIZE ( X264_FILE_TYPE_FILTERS ) ;
2012-02-22 23:53:16 +01:00
2013-05-08 00:04:40 +02:00
if ( ( filterIndex > = 0 ) & & ( filterIndex < count ) )
2012-02-22 23:53:16 +01:00
{
2013-07-03 21:34:21 +02:00
return QString : : fromLatin1 ( X264_FILE_TYPE_FILTERS [ filterIndex ] . pcExt ) ;
2012-02-22 23:53:16 +01:00
}
2013-07-03 21:34:21 +02:00
return QString : : fromLatin1 ( X264_FILE_TYPE_FILTERS [ 0 ] . pcExt ) ;
2013-05-08 00:04:40 +02:00
}
int AddJobDialog : : getFilterIdx ( const QString & fileExt )
{
2013-07-03 21:34:21 +02:00
const int count = ARRAY_SIZE ( X264_FILE_TYPE_FILTERS ) ;
2013-05-11 01:50:05 +02:00
for ( int i = 0 ; i < count ; i + + )
2013-05-08 00:04:40 +02:00
{
2013-07-03 21:34:21 +02:00
if ( fileExt . compare ( QString : : fromLatin1 ( X264_FILE_TYPE_FILTERS [ i ] . pcExt ) , Qt : : CaseInsensitive ) = = 0 )
2013-05-08 00:04:40 +02:00
{
return i ;
}
}
return - 1 ;
2012-02-22 23:53:16 +01:00
}
2013-05-08 22:46:25 +02:00
QString AddJobDialog : : getFilterStr ( const int filterIndex )
{
2013-07-03 21:34:21 +02:00
const int count = ARRAY_SIZE ( X264_FILE_TYPE_FILTERS ) ;
2013-05-08 22:46:25 +02:00
if ( ( filterIndex > = 0 ) & & ( filterIndex < count ) )
{
2013-07-03 21:34:21 +02:00
return QString ( " %1 (*.%2) " ).arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcExt)) ;
2013-05-08 22:46:25 +02:00
}
2013-07-03 21:34:21 +02:00
return QString ( " %1 (*.%2) " ).arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcExt)) ;
2013-05-08 22:46:25 +02:00
}
QString AddJobDialog : : getFilterLst ( void )
{
QStringList filters ;
2013-07-03 21:34:21 +02:00
const int count = ARRAY_SIZE ( X264_FILE_TYPE_FILTERS ) ;
2013-05-08 22:46:25 +02:00
2013-05-11 01:50:05 +02:00
for ( int i = 0 ; i < count ; i + + )
2013-05-08 22:46:25 +02:00
{
2013-07-03 21:34:21 +02:00
filters < < QString ( " %1 (*.%2) " ) . arg ( QString : : fromLatin1 ( X264_FILE_TYPE_FILTERS [ i ] . pcStr ) , QString : : fromLatin1 ( X264_FILE_TYPE_FILTERS [ i ] . pcExt ) ) ;
2013-05-08 22:46:25 +02:00
}
return filters . join ( " ;; " ) ;
}
QString AddJobDialog : : getInputFilterLst ( void )
{
static const struct
{
const char * name ;
const char * fext ;
}
s_filters [ ] =
{
{ " Avisynth Scripts " , " avs " } ,
2013-08-02 20:44:47 +02:00
{ " VapourSynth Scripts " , " vpy " } ,
2013-05-08 22:46:25 +02:00
{ " Matroska Files " , " mkv " } ,
{ " MPEG-4 Part 14 Container " , " mp4 " } ,
{ " Audio Video Interleaved " , " avi " } ,
{ " Flash Video " , " flv " } ,
{ " YUV4MPEG2 Stream " , " y4m " } ,
{ " Uncompresses YUV Data " , " yuv " } ,
} ;
2013-05-23 22:28:57 +02:00
const int count = ARRAY_SIZE ( s_filters ) ;
2013-05-08 22:46:25 +02:00
2013-05-11 01:50:05 +02:00
QString allTypes ;
for ( size_t index = 0 ; index < count ; index + + )
2013-05-08 22:46:25 +02:00
{
2013-05-11 01:50:05 +02:00
allTypes + = QString ( ( index > 0 ) ? " *.%1 " : " *.%1 " ) . arg ( QString : : fromLatin1 ( s_filters [ index ] . fext ) ) ;
}
QStringList filters ;
filters < < QString ( " All supported files (%1) " ) . arg ( allTypes ) ;
2013-05-08 22:46:25 +02:00
2013-05-11 01:50:05 +02:00
for ( size_t index = 0 ; index < count ; index + + )
2013-05-08 22:46:25 +02:00
{
2013-05-11 01:50:05 +02:00
filters < < QString ( " %1 (*.%2) " ) . arg ( QString : : fromLatin1 ( s_filters [ index ] . name ) , QString : : fromLatin1 ( s_filters [ index ] . fext ) ) ;
2013-05-08 22:46:25 +02:00
}
2013-05-11 01:50:05 +02:00
filters < < QString ( " All files (*.*) " ) ;
return filters . join ( " ;; " ) ;
2013-05-08 22:46:25 +02:00
}