2012-01-29 04:06:07 +01:00
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
# include "win_addJob.h"
# include "global.h"
2012-01-29 19:14:46 +01:00
# include "model_options.h"
2012-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-01-29 15:57:23 +01:00
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 \
{ \
for ( int i = 0 ; i < cbxTemplate - > count ( ) ; i + + ) \
{ \
OptionsModel * temp = reinterpret_cast < OptionsModel * > ( cbxTemplate - > itemData ( i ) . value < void * > ( ) ) ; \
if ( temp = = NULL ) \
{ \
cbxTemplate - > blockSignals ( true ) ; \
cbxTemplate - > removeItem ( i ) ; \
cbxTemplate - > blockSignals ( false ) ; \
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 ) ; \
}
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
}
if ( flag )
{
2012-02-06 22:40:07 +01:00
if ( m_notifier )
{
2012-02-13 00:04:39 +01:00
m_notifier - > setText ( tr ( " Invalid parameter: %1 " ) . arg ( ( param . length ( ) > 1 ) ? QString ( " %1%2 " ) . arg ( prefix , param ) : QString ( " -%1 " ) . arg ( param ) ) ) ;
2012-02-06 22:40:07 +01:00
if ( m_notifier - > isHidden ( ) ) m_notifier - > show ( ) ;
if ( m_icon ) { if ( m_icon - > isHidden ( ) ) m_icon - > show ( ) ; }
}
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-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
{
static const char * p [ ] = { " B " , " o " , " h " , " p " , " q " , " fps " , " frames " , " preset " , " tune " , " profile " ,
" 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 ) ;
}
return invalid ? QValidator : : Intermediate : QValidator : : Acceptable ;
}
} ;
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 ) ;
}
return invalid ? QValidator : : Intermediate : QValidator : : Acceptable ;
}
} ;
2012-01-29 04:06:07 +01:00
///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor
///////////////////////////////////////////////////////////////////////////////
2012-03-29 15:20:26 +02:00
AddJobDialog : : AddJobDialog ( QWidget * parent , OptionsModel * options , bool x64supported , bool use10BitEncoding )
2012-01-29 04:06:07 +01:00
:
2012-01-29 19:14:46 +01:00
QDialog ( parent ) ,
2012-01-31 03:03:17 +01:00
m_defaults ( new OptionsModel ( ) ) ,
2012-02-02 15:56:49 +01:00
m_options ( options ) ,
2012-02-03 12:31:51 +01:00
m_x64supported ( x64supported ) ,
2012-03-29 15:20:26 +02:00
m_use10BitEncoding ( use10BitEncoding ) ,
2012-02-22 23:53:16 +01:00
m_initialDir_src ( QDir : : fromNativeSeparators ( QDesktopServices : : storageLocation ( QDesktopServices : : MoviesLocation ) ) ) ,
m_initialDir_out ( QDir : : fromNativeSeparators ( QDesktopServices : : storageLocation ( QDesktopServices : : MoviesLocation ) ) ) ,
m_lastFilterIndex ( 0 )
2012-01-29 04:06:07 +01:00
{
//Init the dialog, from the .ui file
setupUi ( this ) ;
2012-01-29 19:14:46 +01:00
setWindowFlags ( windowFlags ( ) & ( ~ Qt : : WindowContextHelpButtonHint ) ) ;
2012-01-29 04:06:07 +01:00
//Fix dialog size
2012-01-31 03:03:17 +01:00
buttonSaveTemplate - > setMaximumHeight ( 20 ) ;
buttonDeleteTemplate - > setMaximumHeight ( 20 ) ;
2012-01-29 04:06:07 +01:00
resize ( width ( ) , minimumHeight ( ) ) ;
setMinimumSize ( size ( ) ) ;
setMaximumHeight ( height ( ) ) ;
2012-02-22 23:53:16 +01:00
//Setup file type filter
m_types . clear ( ) ;
m_types < < tr ( " Matroska Files (*.mkv) " ) ;
m_types < < tr ( " MPEG-4 Part 14 Container (*.mp4) " ) ;
m_types < < tr ( " H.264 Elementary Stream (*.264) " ) ;
2012-01-31 03:03:17 +01:00
//Monitor RC mode combobox
2012-01-29 04:06:07 +01:00
connect ( cbxRateControlMode , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( modeIndexChanged ( int ) ) ) ;
2012-01-29 15:57:23 +01:00
//Activate buttons
connect ( buttonBrowseSource , SIGNAL ( clicked ( ) ) , this , SLOT ( browseButtonClicked ( ) ) ) ;
connect ( buttonBrowseOutput , SIGNAL ( clicked ( ) ) , this , SLOT ( browseButtonClicked ( ) ) ) ;
2012-01-31 22:30:21 +01:00
connect ( buttonSaveTemplate , SIGNAL ( clicked ( ) ) , this , SLOT ( saveTemplateButtonClicked ( ) ) ) ;
connect ( buttonDeleteTemplate , SIGNAL ( clicked ( ) ) , this , SLOT ( deleteTemplateButtonClicked ( ) ) ) ;
2012-01-29 15:57:23 +01:00
//Setup validator
2012-02-13 00:04:39 +01:00
editCustomX264Params - > installEventFilter ( this ) ;
editCustomX264Params - > setValidator ( new StringValidatorX264 ( labelNotificationX264 , iconNotificationX264 ) ) ;
editCustomX264Params - > clear ( ) ;
editCustomAvs2YUVParams - > installEventFilter ( this ) ;
editCustomAvs2YUVParams - > setValidator ( new StringValidatorAvs2YUV ( labelNotificationAvs2YUV , iconNotificationAvs2YUV ) ) ;
editCustomAvs2YUVParams - > clear ( ) ;
2012-01-31 00:13:32 +01:00
//Install event filter
2012-02-12 15:58:28 +01:00
labelHelpScreenX264 - > installEventFilter ( this ) ;
labelHelpScreenAvs2YUV - > installEventFilter ( this ) ;
2012-01-31 03:03:17 +01:00
//Monitor for options changes
connect ( cbxRateControlMode , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
2012-02-04 15:56:38 +01:00
connect ( spinQuantizer , SIGNAL ( valueChanged ( double ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
2012-01-31 03:03:17 +01:00
connect ( spinBitrate , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( cbxPreset , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( cbxTuning , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( cbxProfile , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
2012-02-13 00:04:39 +01:00
connect ( editCustomX264Params , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( configurationChanged ( ) ) ) ;
connect ( 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
2012-02-16 14:33:26 +01:00
ADD_CONTEXTMENU_ACTION ( editCustomX264Params , QIcon ( " :/buttons/page_edit.png " ) , tr ( " Open the Text-Editor " ) , editorActionTriggered ) ;
ADD_CONTEXTMENU_ACTION ( editCustomAvs2YUVParams , QIcon ( " :/buttons/page_edit.png " ) , tr ( " Open the Text-Editor " ) , editorActionTriggered ) ;
ADD_CONTEXTMENU_SEPARATOR ( editCustomX264Params ) ;
ADD_CONTEXTMENU_SEPARATOR ( editCustomAvs2YUVParams ) ;
ADD_CONTEXTMENU_ACTION ( editCustomX264Params , QIcon ( " :/buttons/page_copy.png " ) , tr ( " Copy to Clipboard " ) , copyActionTriggered ) ;
ADD_CONTEXTMENU_ACTION ( editCustomAvs2YUVParams , QIcon ( " :/buttons/page_copy.png " ) , tr ( " Copy to Clipboard " ) , copyActionTriggered ) ;
ADD_CONTEXTMENU_ACTION ( editCustomX264Params , QIcon ( " :/buttons/page_paste.png " ) , tr ( " Paste from Clipboard " ) , pasteActionTriggered ) ;
ADD_CONTEXTMENU_ACTION ( 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 ( ) ;
2012-01-31 03:03:17 +01:00
connect ( cbxTemplate , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( templateSelected ( ) ) ) ;
2012-02-02 15:56:49 +01:00
//Load directories
2012-02-10 18:42:16 +01:00
const QString appDir = x264_data_path ( ) ;
2012-02-02 15:56:49 +01:00
QSettings settings ( QString ( " %1/last.ini " ) . arg ( appDir ) , QSettings : : IniFormat ) ;
2012-02-22 23:53:16 +01:00
m_initialDir_src = settings . value ( " path/directory_openFrom " , m_initialDir_src ) . toString ( ) ;
m_initialDir_out = settings . value ( " path/directory_saveTo " , m_initialDir_out ) . toString ( ) ;
m_lastFilterIndex = settings . value ( " path/filterIndex " , m_lastFilterIndex ) . toInt ( ) ;
2012-01-29 04:06:07 +01:00
}
AddJobDialog : : ~ AddJobDialog ( void )
{
2012-02-02 15:56:49 +01:00
//Free templates
2012-01-31 22:30:21 +01:00
for ( int i = 0 ; i < cbxTemplate - > model ( ) - > rowCount ( ) ; i + + )
{
if ( cbxTemplate - > itemText ( i ) . startsWith ( " < " ) | | cbxTemplate - > itemText ( i ) . endsWith ( " > " ) )
{
continue ;
}
OptionsModel * item = reinterpret_cast < OptionsModel * > ( cbxTemplate - > itemData ( i ) . value < void * > ( ) ) ;
cbxTemplate - > setItemData ( i , QVariant : : fromValue < void * > ( NULL ) ) ;
X264_DELETE ( item ) ;
}
2012-01-31 03:03:17 +01:00
X264_DELETE ( m_defaults ) ;
2012-01-29 04:06:07 +01:00
}
2012-01-29 15:57:23 +01:00
///////////////////////////////////////////////////////////////////////////////
// Events
///////////////////////////////////////////////////////////////////////////////
2012-01-29 04:06:07 +01:00
void AddJobDialog : : showEvent ( QShowEvent * event )
{
QDialog : : showEvent ( event ) ;
2012-01-31 03:03:17 +01:00
templateSelected ( ) ;
2012-02-02 15:56:49 +01:00
2012-02-22 23:53:16 +01:00
if ( ! editSource - > text ( ) . isEmpty ( ) ) m_initialDir_src = QFileInfo ( QDir : : fromNativeSeparators ( editSource - > text ( ) ) ) . path ( ) ;
if ( ! editOutput - > text ( ) . isEmpty ( ) ) m_initialDir_out = QFileInfo ( QDir : : fromNativeSeparators ( editOutput - > text ( ) ) ) . path ( ) ;
2012-02-03 00:53:14 +01:00
if ( ( ! editSource - > text ( ) . isEmpty ( ) ) & & editOutput - > text ( ) . isEmpty ( ) )
2012-02-02 15:56:49 +01:00
{
generateOutputFileName ( QDir : : fromNativeSeparators ( editSource - > text ( ) ) ) ;
2012-02-02 22:53:40 +01:00
buttonAccept - > setFocus ( ) ;
2012-02-02 15:56:49 +01:00
}
2012-02-06 17:34:25 +01:00
2012-02-13 00:04:39 +01:00
labelNotificationX264 - > hide ( ) ;
iconNotificationX264 - > hide ( ) ;
labelNotificationAvs2YUV - > hide ( ) ;
iconNotificationAvs2YUV - > hide ( ) ;
2012-01-29 04:06:07 +01:00
}
2012-01-31 00:13:32 +01:00
bool AddJobDialog : : eventFilter ( QObject * o , QEvent * e )
{
2012-02-12 15:58:28 +01:00
if ( ( o = = labelHelpScreenX264 ) & & ( e - > type ( ) = = QEvent : : MouseButtonPress ) )
2012-01-31 00:13:32 +01:00
{
2012-03-29 15:20:26 +02:00
HelpDialog * helpScreen = new HelpDialog ( this , false , m_x64supported , m_use10BitEncoding ) ;
2012-02-12 15:58:28 +01:00
helpScreen - > exec ( ) ;
X264_DELETE ( helpScreen ) ;
}
else if ( ( o = = labelHelpScreenAvs2YUV ) & & ( e - > type ( ) = = QEvent : : MouseButtonPress ) )
{
2012-03-29 15:20:26 +02:00
HelpDialog * helpScreen = new HelpDialog ( this , true , m_x64supported , m_use10BitEncoding ) ;
2012-02-01 01:08:54 +01:00
helpScreen - > exec ( ) ;
X264_DELETE ( helpScreen ) ;
2012-01-31 20:28:40 +01:00
}
2012-02-13 00:04:39 +01:00
else if ( ( o = = editCustomX264Params ) & & ( e - > type ( ) = = QEvent : : FocusOut ) )
2012-01-31 20:28:40 +01:00
{
2012-02-13 00:04:39 +01:00
editCustomX264Params - > setText ( editCustomX264Params - > text ( ) . simplified ( ) ) ;
2012-01-31 00:13:32 +01:00
}
2012-02-12 15:58:28 +01:00
else if ( ( o = = editCustomAvs2YUVParams ) & & ( e - > type ( ) = = QEvent : : FocusOut ) )
{
editCustomAvs2YUVParams - > setText ( editCustomAvs2YUVParams - > text ( ) . simplified ( ) ) ;
}
2012-01-31 00:13:32 +01:00
return false ;
}
2012-02-10 18:42:16 +01:00
void AddJobDialog : : dragEnterEvent ( QDragEnterEvent * event )
{
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
if ( formats . contains ( " application/x-qt-windows-mime;value= \" FileNameW \" " , Qt : : CaseInsensitive ) & & formats . contains ( " text/uri-list " , Qt : : CaseInsensitive ) )
{
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 ( ) )
{
editSource - > setText ( QDir : : toNativeSeparators ( droppedFile ) ) ;
generateOutputFileName ( droppedFile ) ;
}
}
2012-01-29 15:57:23 +01:00
///////////////////////////////////////////////////////////////////////////////
// Slots
///////////////////////////////////////////////////////////////////////////////
2012-01-29 04:06:07 +01:00
void AddJobDialog : : modeIndexChanged ( int index )
{
spinQuantizer - > setEnabled ( index = = 0 | | index = = 1 ) ;
spinBitrate - > setEnabled ( index = = 2 | | index = = 3 ) ;
}
2012-01-29 15:57:23 +01:00
void AddJobDialog : : accept ( void )
{
if ( editSource - > text ( ) . trimmed ( ) . isEmpty ( ) )
{
QMessageBox : : warning ( this , tr ( " Not Found! " ) , tr ( " Please select a valid source file first! " ) ) ;
return ;
}
2012-02-02 15:56:49 +01:00
if ( editOutput - > text ( ) . trimmed ( ) . isEmpty ( ) )
{
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 ;
}
2012-01-29 15:57:23 +01:00
QFileInfo sourceFile = QFileInfo ( editSource - > text ( ) ) ;
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 ;
}
QFileInfo outputDir = QFileInfo ( QFileInfo ( editOutput - > text ( ) ) . path ( ) ) ;
if ( ! ( outputDir . exists ( ) & & outputDir . isDir ( ) & & outputDir . isWritable ( ) ) )
{
2012-02-06 17:34:25 +01:00
QMessageBox : : warning ( this , tr ( " Not Writable! " ) , tr ( " <nobr>Output directory does not exist or is not writable!</nobr> " ) ) ;
2012-01-29 15:57:23 +01:00
return ;
}
QFileInfo outputFile = QFileInfo ( editOutput - > text ( ) ) ;
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 ;
}
2012-02-13 00:04:39 +01:00
if ( ! 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
2012-02-02 15:56:49 +01:00
//Save directories
2012-02-10 18:42:16 +01:00
const QString appDir = x264_data_path ( ) ;
2012-02-02 15:56:49 +01:00
QSettings settings ( QString ( " %1/last.ini " ) . arg ( appDir ) , QSettings : : IniFormat ) ;
if ( settings . isWritable ( ) )
{
2012-02-22 23:53:16 +01:00
settings . setValue ( " path/directory_saveTo " , m_initialDir_out ) ;
settings . setValue ( " path/directory_openFrom " , m_initialDir_src ) ;
settings . setValue ( " path/filterIndex " , m_lastFilterIndex ) ;
2012-02-02 15:56:49 +01:00
settings . sync ( ) ;
}
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 )
{
if ( QObject : : sender ( ) = = buttonBrowseSource )
{
2012-02-22 23:53:16 +01:00
QString initDir = VALID_DIR ( m_initialDir_src ) ? m_initialDir_src : QDesktopServices : : storageLocation ( QDesktopServices : : MoviesLocation ) ;
2012-02-05 02:49:08 +01:00
if ( ! editSource - > text ( ) . isEmpty ( ) ) initDir = QString ( " %1/%2 " ) . arg ( initDir , QFileInfo ( QDir : : fromNativeSeparators ( editSource - > text ( ) ) ) . fileName ( ) ) ;
QString filePath = QFileDialog : : getOpenFileName ( this , tr ( " Open Source File " ) , initDir , makeFileFilter ( ) , NULL , QFileDialog : : DontUseNativeDialog ) ;
2012-01-29 15:57:23 +01:00
if ( ! ( filePath . isNull ( ) | | filePath . isEmpty ( ) ) )
{
2012-01-29 21:31:09 +01:00
editSource - > setText ( QDir : : toNativeSeparators ( filePath ) ) ;
2012-02-02 15:56:49 +01:00
generateOutputFileName ( filePath ) ;
2012-02-22 23:53:16 +01:00
m_initialDir_src = QFileInfo ( filePath ) . path ( ) ;
2012-01-29 15:57:23 +01:00
}
}
else if ( QObject : : sender ( ) = = buttonBrowseOutput )
{
2012-02-22 23:53:16 +01:00
QString initDir = VALID_DIR ( m_initialDir_out ) ? m_initialDir_out : QDesktopServices : : storageLocation ( QDesktopServices : : MoviesLocation ) ;
2012-02-05 02:49:08 +01:00
if ( ! editOutput - > text ( ) . isEmpty ( ) ) initDir = QString ( " %1/%2 " ) . arg ( initDir , QFileInfo ( QDir : : fromNativeSeparators ( editOutput - > text ( ) ) ) . completeBaseName ( ) ) ;
2012-02-22 23:53:16 +01:00
int filterIdx = getFilterIndex ( QFileInfo ( QDir : : fromNativeSeparators ( editOutput - > text ( ) ) ) . suffix ( ) ) ;
QString selectedType = m_types . at ( ( filterIdx > = 0 ) ? filterIdx : m_lastFilterIndex ) ;
2012-01-29 15:57:23 +01:00
2012-02-22 23:53:16 +01:00
QString filePath = QFileDialog : : getSaveFileName ( this , tr ( " Choose Output File " ) , initDir , m_types . join ( " ;; " ) , & 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 ( ) ) )
{
2012-02-22 23:53:16 +01:00
if ( getFilterIndex ( QFileInfo ( filePath ) . suffix ( ) ) < 0 )
2012-02-05 02:49:08 +01:00
{
2012-02-22 23:53:16 +01:00
filterIdx = m_types . indexOf ( selectedType ) ;
if ( filterIdx > = 0 )
2012-02-05 02:49:08 +01:00
{
2012-02-22 23:53:16 +01:00
filePath = QString ( " %1.%2 " ) . arg ( filePath , getFilterExt ( filterIdx ) ) ;
2012-02-05 02:49:08 +01:00
}
}
2012-01-29 21:31:09 +01:00
editOutput - > setText ( QDir : : toNativeSeparators ( filePath ) ) ;
2012-02-22 23:53:16 +01:00
m_lastFilterIndex = getFilterIndex ( QFileInfo ( filePath ) . suffix ( ) ) ;
m_initialDir_out = QFileInfo ( filePath ) . path ( ) ;
2012-01-29 15:57:23 +01:00
}
}
}
2012-01-29 19:14:46 +01:00
2012-01-31 03:03:17 +01:00
void AddJobDialog : : configurationChanged ( void )
{
OptionsModel * options = reinterpret_cast < OptionsModel * > ( cbxTemplate - > itemData ( cbxTemplate - > currentIndex ( ) ) . value < void * > ( ) ) ;
if ( options )
{
cbxTemplate - > blockSignals ( true ) ;
cbxTemplate - > insertItem ( 0 , tr ( " <Unsaved Configuration> " ) , QVariant : : fromValue < void * > ( NULL ) ) ;
cbxTemplate - > setCurrentIndex ( 0 ) ;
cbxTemplate - > blockSignals ( false ) ;
}
}
void AddJobDialog : : templateSelected ( void )
{
OptionsModel * options = reinterpret_cast < OptionsModel * > ( cbxTemplate - > itemData ( cbxTemplate - > currentIndex ( ) ) . value < void * > ( ) ) ;
if ( options )
{
qDebug ( " Loading options! " ) ;
2012-02-02 18:55:55 +01:00
REMOVE_USAFED_ITEM ;
2012-01-31 03:03:17 +01:00
restoreOptions ( options ) ;
}
modeIndexChanged ( cbxRateControlMode - > currentIndex ( ) ) ;
}
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
2012-02-02 18:55:55 +01:00
OptionsModel * options = new OptionsModel ( ) ;
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> " ) ) ;
2012-02-02 18:55:55 +01:00
cbxTemplate - > blockSignals ( true ) ;
cbxTemplate - > setCurrentIndex ( 0 ) ;
cbxTemplate - > blockSignals ( false ) ;
REMOVE_USAFED_ITEM ;
X264_DELETE ( options ) ;
return ;
}
for ( int i = 0 ; i < cbxTemplate - > count ( ) ; i + + )
{
2012-02-13 16:44:50 +01:00
const QString tempName = cbxTemplate - > itemText ( i ) ;
if ( tempName . contains ( ' < ' ) | | tempName . contains ( ' > ' ) )
{
continue ;
}
2012-02-02 18:55:55 +01:00
OptionsModel * test = reinterpret_cast < OptionsModel * > ( cbxTemplate - > itemData ( i ) . value < void * > ( ) ) ;
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> " ) ) ;
2012-02-02 18:55:55 +01:00
cbxTemplate - > blockSignals ( true ) ;
cbxTemplate - > setCurrentIndex ( i ) ;
cbxTemplate - > blockSignals ( false ) ;
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 ;
}
int index = cbxTemplate - > model ( ) - > rowCount ( ) ;
cbxTemplate - > blockSignals ( true ) ;
2012-02-04 19:09:27 +01:00
for ( int i = 0 ; i < cbxTemplate - > count ( ) ; i + + )
{
if ( cbxTemplate - > itemText ( i ) . compare ( name , Qt : : CaseInsensitive ) = = 0 )
{
index = - 1 ; //Do not append new template
OptionsModel * oldItem = reinterpret_cast < OptionsModel * > ( cbxTemplate - > itemData ( i ) . value < void * > ( ) ) ;
cbxTemplate - > setItemData ( i , QVariant : : fromValue < void * > ( options ) ) ;
cbxTemplate - > setCurrentIndex ( i ) ;
X264_DELETE ( oldItem ) ;
}
}
if ( index > = 0 )
{
cbxTemplate - > insertItem ( index , name , QVariant : : fromValue < void * > ( options ) ) ;
cbxTemplate - > setCurrentIndex ( index ) ;
}
2012-01-31 22:30:21 +01:00
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 )
{
const int index = cbxTemplate - > currentIndex ( ) ;
QString name = cbxTemplate - > itemText ( index ) ;
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 ) ;
OptionsModel * item = reinterpret_cast < OptionsModel * > ( cbxTemplate - > itemData ( index ) . value < void * > ( ) ) ;
cbxTemplate - > removeItem ( index ) ;
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 )
{
return QDir : : fromNativeSeparators ( editSource - > text ( ) ) ;
}
QString AddJobDialog : : outputFile ( void )
{
return QDir : : fromNativeSeparators ( editOutput - > text ( ) ) ;
}
2012-01-29 19:14:46 +01:00
///////////////////////////////////////////////////////////////////////////////
// Private functions
///////////////////////////////////////////////////////////////////////////////
2012-01-31 22:30:21 +01:00
void AddJobDialog : : loadTemplateList ( void )
{
cbxTemplate - > addItem ( tr ( " <Default> " ) , QVariant : : fromValue < void * > ( m_defaults ) ) ;
cbxTemplate - > setCurrentIndex ( 0 ) ;
QMap < QString , OptionsModel * > templates = OptionsModel : : loadAllTemplates ( ) ;
QStringList templateNames = templates . keys ( ) ;
templateNames . sort ( ) ;
while ( ! templateNames . isEmpty ( ) )
{
QString current = templateNames . takeFirst ( ) ;
cbxTemplate - > addItem ( current , QVariant : : fromValue < void * > ( templates . value ( current ) ) ) ;
if ( templates . value ( current ) - > equals ( m_options ) )
{
cbxTemplate - > setCurrentIndex ( cbxTemplate - > count ( ) - 1 ) ;
}
}
if ( ( cbxTemplate - > currentIndex ( ) = = 0 ) & & ( ! m_options - > equals ( m_defaults ) ) )
{
cbxTemplate - > insertItem ( 1 , tr ( " <Recently Used> " ) , QVariant : : fromValue < void * > ( m_options ) ) ;
cbxTemplate - > setCurrentIndex ( 1 ) ;
}
}
2012-01-29 19:14:46 +01:00
void AddJobDialog : : updateComboBox ( QComboBox * cbox , const QString & text )
{
for ( int i = 0 ; i < cbox - > model ( ) - > rowCount ( ) ; i + + )
{
if ( cbox - > model ( ) - > data ( cbox - > model ( ) - > index ( i , 0 , QModelIndex ( ) ) ) . toString ( ) . compare ( text , Qt : : CaseInsensitive ) = = 0 )
{
cbox - > setCurrentIndex ( i ) ;
break ;
}
}
}
void AddJobDialog : : restoreOptions ( OptionsModel * options )
{
2012-01-31 03:03:17 +01:00
cbxRateControlMode - > blockSignals ( true ) ;
spinQuantizer - > blockSignals ( true ) ;
spinBitrate - > blockSignals ( true ) ;
cbxPreset - > blockSignals ( true ) ;
cbxTuning - > blockSignals ( true ) ;
cbxProfile - > blockSignals ( true ) ;
2012-02-13 00:04:39 +01:00
editCustomX264Params - > blockSignals ( true ) ;
editCustomAvs2YUVParams - > blockSignals ( true ) ;
2012-01-31 03:03:17 +01:00
2012-01-29 19:14:46 +01:00
cbxRateControlMode - > setCurrentIndex ( options - > rcMode ( ) ) ;
spinQuantizer - > setValue ( options - > quantizer ( ) ) ;
spinBitrate - > setValue ( options - > bitrate ( ) ) ;
updateComboBox ( cbxPreset , options - > preset ( ) ) ;
updateComboBox ( cbxTuning , options - > tune ( ) ) ;
updateComboBox ( cbxProfile , options - > profile ( ) ) ;
2012-02-13 00:04:39 +01:00
editCustomX264Params - > setText ( options - > customX264 ( ) ) ;
2012-02-12 15:58:28 +01:00
editCustomAvs2YUVParams - > setText ( options - > customAvs2YUV ( ) ) ;
2012-01-31 03:03:17 +01:00
cbxRateControlMode - > blockSignals ( false ) ;
spinQuantizer - > blockSignals ( false ) ;
spinBitrate - > blockSignals ( false ) ;
cbxPreset - > blockSignals ( false ) ;
cbxTuning - > blockSignals ( false ) ;
cbxProfile - > blockSignals ( false ) ;
2012-02-13 00:04:39 +01:00
editCustomX264Params - > blockSignals ( false ) ;
editCustomAvs2YUVParams - > blockSignals ( false ) ;
2012-01-29 19:14:46 +01:00
}
void AddJobDialog : : saveOptions ( OptionsModel * options )
{
options - > setRCMode ( static_cast < OptionsModel : : RCMode > ( cbxRateControlMode - > currentIndex ( ) ) ) ;
options - > setQuantizer ( spinQuantizer - > value ( ) ) ;
options - > setBitrate ( spinBitrate - > value ( ) ) ;
options - > setPreset ( cbxPreset - > model ( ) - > data ( cbxPreset - > model ( ) - > index ( cbxPreset - > currentIndex ( ) , 0 ) ) . toString ( ) ) ;
options - > setTune ( cbxTuning - > model ( ) - > data ( cbxTuning - > model ( ) - > index ( cbxTuning - > currentIndex ( ) , 0 ) ) . toString ( ) ) ;
options - > setProfile ( cbxProfile - > model ( ) - > data ( cbxProfile - > model ( ) - > index ( cbxProfile - > currentIndex ( ) , 0 ) ) . toString ( ) ) ;
2012-02-13 00:04:39 +01:00
options - > setCustomX264 ( editCustomX264Params - > hasAcceptableInput ( ) ? editCustomX264Params - > text ( ) . simplified ( ) : QString ( ) ) ;
options - > setCustomAvs2YUV ( editCustomAvs2YUVParams - > hasAcceptableInput ( ) ? editCustomAvs2YUVParams - > text ( ) . simplified ( ) : QString ( ) ) ;
2012-01-29 19:14:46 +01:00
}
2012-01-30 17:50:19 +01:00
QString AddJobDialog : : makeFileFilter ( void )
{
2012-02-05 02:49:08 +01:00
static const struct
{
const char * name ;
const char * fext ;
}
s_filters [ ] =
{
{ " Avisynth Scripts " , " avs " } ,
{ " Matroska Files " , " mkv " } ,
{ " MPEG-4 Part 14 Container " , " mp4 " } ,
{ " Audio Video Interleaved " , " avi " } ,
{ " Flash Video " , " flv " } ,
{ " YUV4MPEG2 Stream " , " y4m " } ,
{ " Uncompresses YUV Data " , " yuv " } ,
{ NULL , NULL }
} ;
2012-01-30 17:50:19 +01:00
QString filters ( " All supported files ( " ) ;
2012-02-05 02:49:08 +01:00
for ( size_t index = 0 ; s_filters [ index ] . name & & s_filters [ index ] . fext ; index + + )
2012-01-30 17:50:19 +01:00
{
2012-02-05 02:49:08 +01:00
filters + = QString ( ( index > 0 ) ? " *.%1 " : " *.%1 " ) . arg ( QString : : fromLatin1 ( s_filters [ index ] . fext ) ) ;
2012-01-30 17:50:19 +01:00
}
filters + = QString ( " );; " ) ;
2012-02-05 02:49:08 +01:00
for ( size_t index = 0 ; s_filters [ index ] . name & & s_filters [ index ] . fext ; index + + )
2012-01-30 17:50:19 +01:00
{
2012-02-05 02:49:08 +01:00
filters + = QString ( " %1 (*.%2);; " ) . arg ( QString : : fromLatin1 ( s_filters [ index ] . name ) , QString : : fromLatin1 ( s_filters [ index ] . fext ) ) ;
2012-01-30 17:50:19 +01:00
}
filters + = QString ( " All files (*.*) " ) ;
return filters ;
}
2012-02-02 15:56:49 +01:00
void AddJobDialog : : generateOutputFileName ( const QString & filePath )
{
QString name = QFileInfo ( filePath ) . completeBaseName ( ) ;
2012-02-22 23:53:16 +01:00
QString path = VALID_DIR ( m_initialDir_out ) ? m_initialDir_out : QFileInfo ( filePath ) . path ( ) ;
QString fext = getFilterExt ( m_lastFilterIndex ) ;
2012-02-02 15:56:49 +01:00
2012-02-22 23:53:16 +01:00
QString outPath = QString ( " %1/%2.%3 " ) . arg ( path , name , fext ) ;
2012-02-02 15:56:49 +01:00
if ( QFileInfo ( outPath ) . exists ( ) )
{
int i = 2 ;
while ( QFileInfo ( outPath ) . exists ( ) )
{
2012-02-22 23:53:16 +01:00
outPath = QString ( " %1/%2 (%3).%4 " ) . arg ( path , name , QString : : number ( i + + ) , fext ) ;
2012-02-02 15:56:49 +01:00
}
}
editOutput - > setText ( QDir : : toNativeSeparators ( outPath ) ) ;
}
2012-02-22 23:53:16 +01:00
int AddJobDialog : : getFilterIndex ( const QString & fileExt )
{
if ( ! fileExt . isEmpty ( ) )
{
QRegExp ext ( " \\ ( \\ * \\ .(.+) \ \ ) " ) ;
for ( int i = 0 ; i < m_types . count ( ) ; i + + )
{
if ( ext . lastIndexIn ( m_types . at ( i ) ) > = 0 )
{
if ( fileExt . compare ( ext . cap ( 1 ) , Qt : : CaseInsensitive ) = = 0 )
{
return i ;
}
}
}
}
return - 1 ;
}
QString AddJobDialog : : getFilterExt ( int filterIdx )
{
int index = qBound ( 0 , filterIdx , m_types . count ( ) - 1 ) ;
QRegExp ext ( " \\ ( \\ * \\ .(.+) \ \ ) " ) ;
if ( ext . lastIndexIn ( m_types . at ( index ) ) > = 0 )
{
return ext . cap ( 1 ) . toLower ( ) ;
}
return QString : : fromLatin1 ( " mkv " ) ;
}