2012-01-28 16:40:14 +01:00
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
2013-05-11 21:52:07 +02:00
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
2012-01-28 16:40:14 +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_main.h"
2013-11-14 02:29:18 +01:00
# include "uic_win_main.h"
2012-01-28 18:55:40 +01:00
2013-11-14 02:29:18 +01:00
# include "global.h"
# include "model_status.h"
2012-01-28 18:55:40 +01:00
# include "model_jobList.h"
2012-01-29 19:14:46 +01:00
# include "model_options.h"
2013-07-03 21:34:21 +02:00
# include "model_preferences.h"
# include "model_recently.h"
2013-04-02 23:10:58 +02:00
# include "thread_avisynth.h"
2013-08-07 15:34:02 +02:00
# include "thread_vapoursynth.h"
2013-07-03 21:52:19 +02:00
# include "thread_ipc.h"
# include "thread_encode.h"
2012-02-08 00:29:47 +01:00
# include "taskbar7.h"
2013-07-03 21:34:21 +02:00
# include "win_addJob.h"
# include "win_preferences.h"
2013-11-22 17:01:13 +01:00
# include "win_updater.h"
2012-02-04 01:12:21 +01:00
# include "resource.h"
2012-01-28 18:55:40 +01:00
# include <QDate>
2012-01-28 19:59:04 +01:00
# include <QTimer>
2012-01-28 23:24:41 +01:00
# include <QCloseEvent>
# include <QMessageBox>
2012-01-29 15:57:23 +01:00
# include <QDesktopServices>
# include <QUrl>
2012-01-29 21:31:09 +01:00
# include <QDir>
2012-01-30 17:50:19 +01:00
# include <QLibrary>
2012-02-02 22:53:40 +01:00
# include <QProcess>
2012-02-04 01:12:21 +01:00
# include <QProgressDialog>
2012-02-13 16:44:50 +01:00
# include <QScrollBar>
2012-04-30 19:26:41 +02:00
# include <QTextStream>
2013-05-08 00:04:40 +02:00
# include <QSettings>
2013-05-11 01:50:05 +02:00
# include <QFileDialog>
2012-01-29 15:57:23 +01:00
2013-11-03 18:34:20 +01:00
# include <ctime>
2012-01-28 16:40:14 +01:00
2013-05-11 01:50:05 +02:00
const char * home_url = " http://muldersoft.com/ " ;
2012-02-08 00:29:47 +01:00
const char * update_url = " http://code.google.com/p/mulder/downloads/list " ;
2012-02-09 02:06:29 +01:00
const char * tpl_last = " <LAST_USED> " ;
2012-01-30 17:50:19 +01:00
2013-11-08 17:39:16 +01:00
# define SET_FONT_BOLD(WIDGET,BOLD) do { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); } while(0)
# define SET_TEXT_COLOR(WIDGET,COLOR) do { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); } while(0)
2013-08-07 15:34:02 +02:00
# define LINK(URL) "<a href=\"" URL "\">" URL "< / a>"
2013-11-08 17:39:16 +01:00
# define INIT_ERROR_EXIT() do { m_initialized = true; close(); qApp->exit(-1); return; } while(0)
2012-01-31 00:13:32 +01:00
2013-11-03 18:34:20 +01:00
//static int exceptionFilter(_EXCEPTION_RECORD *dst, _EXCEPTION_POINTERS *src) { memcpy(dst, src->ExceptionRecord, sizeof(_EXCEPTION_RECORD)); return EXCEPTION_EXECUTE_HANDLER; }
2012-04-30 22:24:41 +02:00
2012-01-28 16:40:14 +01:00
///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor
///////////////////////////////////////////////////////////////////////////////
2012-02-10 18:42:16 +01:00
/*
* Constructor
*/
2012-02-07 21:48:25 +01:00
MainWindow : : MainWindow ( const x264_cpu_t * const cpuFeatures )
2012-01-29 01:19:50 +01:00
:
2012-02-07 21:48:25 +01:00
m_cpuFeatures ( cpuFeatures ) ,
2012-01-29 21:31:09 +01:00
m_appDir ( QApplication : : applicationDirPath ( ) ) ,
2012-02-10 18:42:16 +01:00
m_options ( NULL ) ,
m_jobList ( NULL ) ,
m_droppedFiles ( NULL ) ,
2013-07-03 21:34:21 +02:00
m_preferences ( NULL ) ,
m_recentlyUsed ( NULL ) ,
2013-07-07 16:11:47 +02:00
m_skipVersionTest ( false ) ,
2013-08-04 18:44:53 +02:00
m_abortOnTimeout ( true ) ,
2013-11-08 17:39:16 +01:00
m_firstShow ( true ) ,
2013-11-14 02:29:18 +01:00
m_initialized ( false ) ,
ui ( new Ui : : MainWindow ( ) )
2012-01-28 16:40:14 +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 : : WindowMaximizeButtonHint ) ) ;
2012-01-28 18:55:40 +01:00
//Register meta types
qRegisterMetaType < QUuid > ( " QUuid " ) ;
2012-02-21 00:37:31 +01:00
qRegisterMetaType < QUuid > ( " DWORD " ) ;
2013-07-03 23:56:41 +02:00
qRegisterMetaType < JobStatus > ( " JobStatus " ) ;
2012-01-28 18:55:40 +01:00
2012-02-03 00:53:14 +01:00
//Load preferences
2013-07-03 21:34:21 +02:00
m_preferences = new PreferencesModel ( ) ;
PreferencesModel : : loadPreferences ( m_preferences ) ;
2012-02-03 00:53:14 +01:00
2013-05-08 22:46:25 +02:00
//Load recently used
2013-07-03 21:34:21 +02:00
m_recentlyUsed = new RecentlyUsed ( ) ;
RecentlyUsed : : loadRecentlyUsed ( m_recentlyUsed ) ;
2013-05-08 22:46:25 +02:00
2012-02-09 02:06:29 +01:00
//Create options object
m_options = new OptionsModel ( ) ;
OptionsModel : : loadTemplate ( m_options , QString : : fromLatin1 ( tpl_last ) ) ;
2012-02-21 00:37:31 +01:00
//Create IPC thread object
m_ipcThread = new IPCThread ( ) ;
2013-11-03 18:34:20 +01:00
connect ( m_ipcThread , SIGNAL ( instanceCreated ( unsigned int ) ) , this , SLOT ( instanceCreated ( unsigned int ) ) , Qt : : QueuedConnection ) ;
2012-02-21 00:37:31 +01:00
2012-01-28 18:55:40 +01:00
//Freeze minimum size
setMinimumSize ( size ( ) ) ;
2013-11-14 02:29:18 +01:00
ui - > splitter - > setSizes ( QList < int > ( ) < < 16 < < 196 ) ;
2012-01-28 18:55:40 +01:00
2012-01-29 01:19:50 +01:00
//Update title
2013-11-14 02:29:18 +01:00
ui - > labelBuildDate - > setText ( tr ( " Built on %1 at %2 " ) . arg ( x264_version_date ( ) . toString ( Qt : : ISODate ) , QString : : fromLatin1 ( x264_version_time ( ) ) ) ) ;
ui - > labelBuildDate - > installEventFilter ( this ) ;
2012-02-07 21:48:25 +01:00
setWindowTitle ( QString ( " %1 (%2 Mode) " ) . arg ( windowTitle ( ) , m_cpuFeatures - > x64 ? " 64-Bit " : " 32-Bit " ) ) ;
2012-02-05 04:41:42 +01:00
if ( X264_DEBUG )
{
setWindowTitle ( QString ( " %1 | !!! DEBUG VERSION !!! " ) . arg ( windowTitle ( ) ) ) ;
setStyleSheet ( " QMenuBar, QMainWindow { background-color: yellow } " ) ;
}
else if ( x264_is_prerelease ( ) )
{
setWindowTitle ( QString ( " %1 | PRE-RELEASE VERSION " ) . arg ( windowTitle ( ) ) ) ;
}
2012-02-03 00:53:14 +01:00
2012-01-28 18:55:40 +01:00
//Create model
2013-07-03 21:34:21 +02:00
m_jobList = new JobListModel ( m_preferences ) ;
2012-01-28 23:24:41 +01:00
connect ( m_jobList , SIGNAL ( dataChanged ( QModelIndex , QModelIndex ) ) , this , SLOT ( jobChangedData ( QModelIndex , QModelIndex ) ) ) ;
2013-11-14 02:29:18 +01:00
ui - > jobsView - > setModel ( m_jobList ) ;
2012-01-31 00:13:32 +01:00
2012-01-28 18:55:40 +01:00
//Setup view
2013-11-14 02:29:18 +01:00
ui - > jobsView - > horizontalHeader ( ) - > setSectionHidden ( 3 , true ) ;
ui - > jobsView - > horizontalHeader ( ) - > setResizeMode ( 0 , QHeaderView : : Stretch ) ;
ui - > jobsView - > horizontalHeader ( ) - > setResizeMode ( 1 , QHeaderView : : Fixed ) ;
ui - > jobsView - > horizontalHeader ( ) - > setResizeMode ( 2 , QHeaderView : : Fixed ) ;
ui - > jobsView - > horizontalHeader ( ) - > resizeSection ( 1 , 150 ) ;
ui - > jobsView - > horizontalHeader ( ) - > resizeSection ( 2 , 90 ) ;
ui - > jobsView - > verticalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
connect ( ui - > jobsView - > selectionModel ( ) , SIGNAL ( currentChanged ( QModelIndex , QModelIndex ) ) , this , SLOT ( jobSelected ( QModelIndex , QModelIndex ) ) ) ;
2012-01-28 18:55:40 +01:00
2012-01-31 00:13:32 +01:00
//Create context menu
2013-11-14 02:29:18 +01:00
QAction * actionClipboard = new QAction ( QIcon ( " :/buttons/page_paste.png " ) , tr ( " Copy to Clipboard " ) , ui - > logView ) ;
2012-02-02 22:53:40 +01:00
actionClipboard - > setEnabled ( false ) ;
2013-11-14 02:29:18 +01:00
ui - > logView - > addAction ( actionClipboard ) ;
2012-01-31 00:13:32 +01:00
connect ( actionClipboard , SIGNAL ( triggered ( bool ) ) , this , SLOT ( copyLogToClipboard ( bool ) ) ) ;
2013-11-14 02:29:18 +01:00
ui - > jobsView - > addActions ( ui - > menuJob - > actions ( ) ) ;
2012-01-31 00:13:32 +01:00
2012-01-28 18:55:40 +01:00
//Enable buttons
2013-11-14 02:29:18 +01:00
connect ( ui - > buttonAddJob , SIGNAL ( clicked ( ) ) , this , SLOT ( addButtonPressed ( ) ) ) ;
connect ( ui - > buttonStartJob , SIGNAL ( clicked ( ) ) , this , SLOT ( startButtonPressed ( ) ) ) ;
connect ( ui - > buttonAbortJob , SIGNAL ( clicked ( ) ) , this , SLOT ( abortButtonPressed ( ) ) ) ;
connect ( ui - > buttonPauseJob , SIGNAL ( toggled ( bool ) ) , this , SLOT ( pauseButtonPressed ( bool ) ) ) ;
connect ( ui - > actionJob_Delete , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteButtonPressed ( ) ) ) ;
connect ( ui - > actionJob_Restart , SIGNAL ( triggered ( ) ) , this , SLOT ( restartButtonPressed ( ) ) ) ;
connect ( ui - > actionJob_Browse , SIGNAL ( triggered ( ) ) , this , SLOT ( browseButtonPressed ( ) ) ) ;
2012-01-28 23:24:41 +01:00
//Enable menu
2013-11-14 02:29:18 +01:00
connect ( ui - > actionOpen , SIGNAL ( triggered ( ) ) , this , SLOT ( openActionTriggered ( ) ) ) ;
connect ( ui - > actionAbout , SIGNAL ( triggered ( ) ) , this , SLOT ( showAbout ( ) ) ) ;
connect ( ui - > actionWebMulder , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebX264 , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebKomisar , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebVideoLAN , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebJEEB , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebAvisynth32 , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebAvisynth64 , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebVapourSynth , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebVapourSynthDocs , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebWiki , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebBluRay , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebAvsWiki , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebSecret , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionWebSupport , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( ui - > actionPreferences , SIGNAL ( triggered ( ) ) , this , SLOT ( showPreferences ( ) ) ) ;
2013-11-22 17:01:13 +01:00
connect ( ui - > actionCheckForUpdates , SIGNAL ( triggered ( ) ) , this , SLOT ( checkUpdates ( ) ) ) ;
2012-01-29 19:14:46 +01:00
2012-01-31 00:13:32 +01:00
//Create floating label
2013-11-14 02:29:18 +01:00
m_label = new QLabel ( ui - > jobsView - > viewport ( ) ) ;
2012-01-31 00:13:32 +01:00
m_label - > setText ( tr ( " No job created yet. Please click the 'Add New Job' button! " ) ) ;
m_label - > setAlignment ( Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
SET_TEXT_COLOR ( m_label , Qt : : darkGray ) ;
SET_FONT_BOLD ( m_label , true ) ;
m_label - > setVisible ( true ) ;
m_label - > setContextMenuPolicy ( Qt : : ActionsContextMenu ) ;
2013-11-14 02:29:18 +01:00
m_label - > addActions ( ui - > jobsView - > actions ( ) ) ;
connect ( ui - > splitter , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( updateLabelPos ( ) ) ) ;
2012-02-07 21:48:25 +01:00
updateLabelPos ( ) ;
2012-01-28 16:40:14 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* Destructor
*/
2012-01-28 16:40:14 +01:00
MainWindow : : ~ MainWindow ( void )
{
2012-02-09 02:06:29 +01:00
OptionsModel : : saveTemplate ( m_options , QString : : fromLatin1 ( tpl_last ) ) ;
2012-01-28 23:24:41 +01:00
X264_DELETE ( m_jobList ) ;
2012-01-29 19:14:46 +01:00
X264_DELETE ( m_options ) ;
2012-02-10 18:42:16 +01:00
X264_DELETE ( m_droppedFiles ) ;
2012-01-31 00:13:32 +01:00
X264_DELETE ( m_label ) ;
2012-01-29 21:31:09 +01:00
while ( ! m_toolsList . isEmpty ( ) )
{
QFile * temp = m_toolsList . takeFirst ( ) ;
X264_DELETE ( temp ) ;
}
2012-02-21 00:37:31 +01:00
if ( m_ipcThread - > isRunning ( ) )
{
m_ipcThread - > setAbort ( ) ;
if ( ! m_ipcThread - > wait ( 5000 ) )
{
m_ipcThread - > terminate ( ) ;
m_ipcThread - > wait ( ) ;
}
}
X264_DELETE ( m_ipcThread ) ;
2013-07-03 21:34:21 +02:00
X264_DELETE ( m_preferences ) ;
X264_DELETE ( m_recentlyUsed ) ;
2013-08-07 15:34:02 +02:00
VapourSynthCheckThread : : unload ( ) ;
AvisynthCheckThread : : unload ( ) ;
2013-11-14 02:29:18 +01:00
delete ui ;
2012-01-28 16:40:14 +01:00
}
2012-01-28 18:55:40 +01:00
///////////////////////////////////////////////////////////////////////////////
// Slots
///////////////////////////////////////////////////////////////////////////////
2012-02-10 18:42:16 +01:00
/*
* The " add " button was clicked
*/
2013-05-08 00:04:40 +02:00
void MainWindow : : addButtonPressed ( )
2012-01-28 18:55:40 +01:00
{
2012-02-10 18:42:16 +01:00
qDebug ( " MainWindow::addButtonPressed " ) ;
2013-07-03 21:34:21 +02:00
bool runImmediately = ( countRunningJobs ( ) < ( m_preferences - > autoRunNextJob ( ) ? m_preferences - > maxRunningJobCount ( ) : 1 ) ) ;
2013-05-08 00:04:40 +02:00
QString sourceFileName , outputFileName ;
2012-02-10 18:42:16 +01:00
2013-05-08 00:04:40 +02:00
if ( createJob ( sourceFileName , outputFileName , m_options , runImmediately ) )
2012-01-29 04:06:07 +01:00
{
2013-05-08 00:04:40 +02:00
appendJob ( sourceFileName , outputFileName , m_options , runImmediately ) ;
2012-02-14 23:36:44 +01:00
}
2012-01-28 23:24:41 +01:00
}
2012-01-28 19:59:04 +01:00
2013-05-11 01:50:05 +02:00
/*
* The " open " action was triggered
*/
void MainWindow : : openActionTriggered ( )
{
2013-07-03 21:34:21 +02:00
QStringList fileList = QFileDialog : : getOpenFileNames ( this , tr ( " Open Source File(s) " ) , m_recentlyUsed - > sourceDirectory ( ) , AddJobDialog : : getInputFilterLst ( ) , NULL , QFileDialog : : DontUseNativeDialog ) ;
2013-05-11 01:50:05 +02:00
if ( ! fileList . empty ( ) )
{
2013-07-03 21:34:21 +02:00
m_recentlyUsed - > setSourceDirectory ( QFileInfo ( fileList . last ( ) ) . absolutePath ( ) ) ;
2013-05-11 01:50:05 +02:00
if ( fileList . count ( ) > 1 )
{
createJobMultiple ( fileList ) ;
}
else
{
2013-07-03 21:34:21 +02:00
bool runImmediately = ( countRunningJobs ( ) < ( m_preferences - > autoRunNextJob ( ) ? m_preferences - > maxRunningJobCount ( ) : 1 ) ) ;
2013-05-11 01:50:05 +02:00
QString sourceFileName ( fileList . first ( ) ) , outputFileName ;
if ( createJob ( sourceFileName , outputFileName , m_options , runImmediately ) )
{
appendJob ( sourceFileName , outputFileName , m_options , runImmediately ) ;
}
}
}
}
2012-02-10 18:42:16 +01:00
/*
* The " start " button was clicked
*/
2012-01-28 23:24:41 +01:00
void MainWindow : : startButtonPressed ( void )
{
2013-11-14 02:29:18 +01:00
m_jobList - > startJob ( ui - > jobsView - > currentIndex ( ) ) ;
2012-01-28 19:59:04 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* The " abort " button was clicked
*/
2012-01-28 23:24:41 +01:00
void MainWindow : : abortButtonPressed ( void )
{
2013-11-14 02:29:18 +01:00
m_jobList - > abortJob ( ui - > jobsView - > currentIndex ( ) ) ;
2012-01-28 23:24:41 +01:00
}
2012-01-29 00:57:47 +01:00
2012-02-10 18:42:16 +01:00
/*
* The " delete " button was clicked
*/
2012-02-02 22:53:40 +01:00
void MainWindow : : deleteButtonPressed ( void )
{
2013-11-14 02:29:18 +01:00
m_jobList - > deleteJob ( ui - > jobsView - > currentIndex ( ) ) ;
2012-02-02 22:53:40 +01:00
m_label - > setVisible ( m_jobList - > rowCount ( QModelIndex ( ) ) = = 0 ) ;
}
2012-02-10 18:42:16 +01:00
/*
* The " browse " button was clicked
*/
2012-02-02 22:53:40 +01:00
void MainWindow : : browseButtonPressed ( void )
{
2013-11-14 02:29:18 +01:00
QString outputFile = m_jobList - > getJobOutputFile ( ui - > jobsView - > currentIndex ( ) ) ;
2012-02-02 22:53:40 +01:00
if ( ( ! outputFile . isEmpty ( ) ) & & QFileInfo ( outputFile ) . exists ( ) & & QFileInfo ( outputFile ) . isFile ( ) )
{
QProcess : : startDetached ( QString : : fromLatin1 ( " explorer.exe " ) , QStringList ( ) < < QString : : fromLatin1 ( " /select, " ) < < QDir : : toNativeSeparators ( outputFile ) , QFileInfo ( outputFile ) . path ( ) ) ;
}
else
{
QMessageBox : : warning ( this , tr ( " Not Found " ) , tr ( " Sorry, the output file could not be found! " ) ) ;
}
}
2012-02-10 18:42:16 +01:00
/*
* The " pause " button was clicked
*/
2012-02-02 02:13:02 +01:00
void MainWindow : : pauseButtonPressed ( bool checked )
{
if ( checked )
{
2013-11-14 02:29:18 +01:00
m_jobList - > pauseJob ( ui - > jobsView - > currentIndex ( ) ) ;
2012-02-02 02:13:02 +01:00
}
else
{
2013-11-14 02:29:18 +01:00
m_jobList - > resumeJob ( ui - > jobsView - > currentIndex ( ) ) ;
2012-02-02 02:13:02 +01:00
}
}
2012-02-14 23:36:44 +01:00
/*
* The " restart " button was clicked
*/
void MainWindow : : restartButtonPressed ( void )
{
2013-11-14 02:29:18 +01:00
const QModelIndex index = ui - > jobsView - > currentIndex ( ) ;
2012-02-14 23:36:44 +01:00
const OptionsModel * options = m_jobList - > getJobOptions ( index ) ;
2013-05-08 00:04:40 +02:00
QString sourceFileName = m_jobList - > getJobSourceFile ( index ) ;
QString outputFileName = m_jobList - > getJobOutputFile ( index ) ;
2012-02-14 23:36:44 +01:00
2013-05-08 00:04:40 +02:00
if ( ( options ) & & ( ! sourceFileName . isEmpty ( ) ) & & ( ! outputFileName . isEmpty ( ) ) )
2012-02-14 23:36:44 +01:00
{
2013-10-13 22:08:06 +02:00
bool runImmediately = ( countRunningJobs ( ) < ( m_preferences - > autoRunNextJob ( ) ? m_preferences - > maxRunningJobCount ( ) : 1 ) ) ; //bool runImmediately = true;
2012-02-15 00:45:42 +01:00
OptionsModel * tempOptions = new OptionsModel ( * options ) ;
2013-05-08 00:04:40 +02:00
if ( createJob ( sourceFileName , outputFileName , tempOptions , runImmediately , true ) )
{
appendJob ( sourceFileName , outputFileName , tempOptions , runImmediately ) ;
}
2012-02-15 00:45:42 +01:00
X264_DELETE ( tempOptions ) ;
2012-02-14 23:36:44 +01:00
}
}
2012-02-10 18:42:16 +01:00
/*
* Job item selected by user
*/
2012-01-28 19:59:04 +01:00
void MainWindow : : jobSelected ( const QModelIndex & current , const QModelIndex & previous )
{
qDebug ( " Job selected: %d " , current . row ( ) ) ;
2012-01-28 23:24:41 +01:00
2013-11-14 02:29:18 +01:00
if ( ui - > logView - > model ( ) )
2012-01-28 23:24:41 +01:00
{
2013-11-14 02:29:18 +01:00
disconnect ( ui - > logView - > model ( ) , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( jobLogExtended ( QModelIndex , int , int ) ) ) ;
2012-01-28 23:24:41 +01:00
}
2012-02-02 22:53:40 +01:00
if ( current . isValid ( ) )
{
2013-11-14 02:29:18 +01:00
ui - > logView - > setModel ( m_jobList - > getLogFile ( current ) ) ;
connect ( ui - > logView - > model ( ) , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( jobLogExtended ( QModelIndex , int , int ) ) ) ;
ui - > logView - > actions ( ) . first ( ) - > setEnabled ( true ) ;
QTimer : : singleShot ( 0 , ui - > logView , SLOT ( scrollToBottom ( ) ) ) ;
2012-02-08 00:29:47 +01:00
2013-11-14 02:29:18 +01:00
ui - > progressBar - > setValue ( m_jobList - > getJobProgress ( current ) ) ;
ui - > editDetails - > setText ( m_jobList - > data ( m_jobList - > index ( current . row ( ) , 3 , QModelIndex ( ) ) , Qt : : DisplayRole ) . toString ( ) ) ;
2012-02-02 22:53:40 +01:00
updateButtons ( m_jobList - > getJobStatus ( current ) ) ;
2012-02-08 00:29:47 +01:00
updateTaskbar ( m_jobList - > getJobStatus ( current ) , m_jobList - > data ( m_jobList - > index ( current . row ( ) , 0 , QModelIndex ( ) ) , Qt : : DecorationRole ) . value < QIcon > ( ) ) ;
2012-02-02 22:53:40 +01:00
}
else
{
2013-11-14 02:29:18 +01:00
ui - > logView - > setModel ( NULL ) ;
ui - > logView - > actions ( ) . first ( ) - > setEnabled ( false ) ;
ui - > progressBar - > setValue ( 0 ) ;
ui - > editDetails - > clear ( ) ;
2013-07-03 21:52:19 +02:00
updateButtons ( JobStatus_Undefined ) ;
updateTaskbar ( JobStatus_Undefined , QIcon ( ) ) ;
2012-02-02 22:53:40 +01:00
}
2012-01-31 00:13:32 +01:00
2013-11-14 02:29:18 +01:00
ui - > progressBar - > repaint ( ) ;
2012-01-28 23:24:41 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* Handle update of job info ( status , progress , details , etc )
*/
2012-01-28 23:24:41 +01:00
void MainWindow : : jobChangedData ( const QModelIndex & topLeft , const QModelIndex & bottomRight )
{
2013-11-14 02:29:18 +01:00
int selected = ui - > jobsView - > currentIndex ( ) . row ( ) ;
2012-01-28 23:24:41 +01:00
2012-02-03 15:28:00 +01:00
if ( topLeft . column ( ) < = 1 & & bottomRight . column ( ) > = 1 ) /*STATUS*/
2012-01-28 23:24:41 +01:00
{
for ( int i = topLeft . row ( ) ; i < = bottomRight . row ( ) ; i + + )
{
2013-07-03 21:52:19 +02:00
JobStatus status = m_jobList - > getJobStatus ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) ) ;
2012-01-28 23:24:41 +01:00
if ( i = = selected )
{
qDebug ( " Current job changed status! " ) ;
2012-01-29 00:57:47 +01:00
updateButtons ( status ) ;
2012-02-08 00:29:47 +01:00
updateTaskbar ( status , m_jobList - > data ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) , Qt : : DecorationRole ) . value < QIcon > ( ) ) ;
2012-01-29 00:57:47 +01:00
}
2013-07-03 21:52:19 +02:00
if ( ( status = = JobStatus_Completed ) | | ( status = = JobStatus_Failed ) )
2012-01-29 00:57:47 +01:00
{
2013-07-03 21:34:21 +02:00
if ( m_preferences - > autoRunNextJob ( ) ) QTimer : : singleShot ( 0 , this , SLOT ( launchNextJob ( ) ) ) ;
if ( m_preferences - > shutdownComputer ( ) ) QTimer : : singleShot ( 0 , this , SLOT ( shutdownComputer ( ) ) ) ;
if ( m_preferences - > saveLogFiles ( ) ) saveLogFile ( m_jobList - > index ( i , 1 , QModelIndex ( ) ) ) ;
2012-01-28 23:24:41 +01:00
}
}
}
2012-02-08 00:29:47 +01:00
if ( topLeft . column ( ) < = 2 & & bottomRight . column ( ) > = 2 ) /*PROGRESS*/
2012-01-28 23:24:41 +01:00
{
for ( int i = topLeft . row ( ) ; i < = bottomRight . row ( ) ; i + + )
{
if ( i = = selected )
{
2013-11-14 02:29:18 +01:00
ui - > progressBar - > setValue ( m_jobList - > getJobProgress ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) ) ) ;
WinSevenTaskbar : : setTaskbarProgress ( this , ui - > progressBar - > value ( ) , ui - > progressBar - > maximum ( ) ) ;
2012-01-28 23:24:41 +01:00
break ;
}
}
}
2012-02-08 00:29:47 +01:00
if ( topLeft . column ( ) < = 3 & & bottomRight . column ( ) > = 3 ) /*DETAILS*/
2012-01-28 23:24:41 +01:00
{
for ( int i = topLeft . row ( ) ; i < = bottomRight . row ( ) ; i + + )
{
if ( i = = selected )
{
2013-11-14 02:29:18 +01:00
ui - > editDetails - > setText ( m_jobList - > data ( m_jobList - > index ( i , 3 , QModelIndex ( ) ) , Qt : : DisplayRole ) . toString ( ) ) ;
2012-01-28 23:24:41 +01:00
break ;
}
}
}
}
2012-02-10 18:42:16 +01:00
/*
* Handle new log file content
*/
2012-01-28 23:24:41 +01:00
void MainWindow : : jobLogExtended ( const QModelIndex & parent , int start , int end )
{
2013-11-14 02:29:18 +01:00
QTimer : : singleShot ( 0 , ui - > logView , SLOT ( scrollToBottom ( ) ) ) ;
2012-01-28 23:24:41 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* About screen
*/
2012-01-28 23:24:41 +01:00
void MainWindow : : showAbout ( void )
{
QString text ;
2012-02-11 00:19:24 +01:00
text + = QString ( ) . sprintf ( " <nobr><tt>Simple x264 Launcher v%u.%02u.%u - use 64-Bit x264 with 32-Bit Avisynth<br> " , x264_version_major ( ) , x264_version_minor ( ) , x264_version_build ( ) ) ;
2012-01-29 00:57:47 +01:00
text + = QString ( ) . sprintf ( " Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.<br> " , qMax ( x264_version_date ( ) . year ( ) , QDate : : currentDate ( ) . year ( ) ) ) ;
text + = QString ( ) . sprintf ( " Built on %s at %s with %s for Win-%s.<br><br> " , x264_version_date ( ) . toString ( Qt : : ISODate ) . toLatin1 ( ) . constData ( ) , x264_version_time ( ) , x264_version_compiler ( ) , x264_version_arch ( ) ) ;
2012-01-28 23:24:41 +01:00
text + = QString ( ) . sprintf ( " This program is free software: you can redistribute it and/or modify<br> " ) ;
text + = QString ( ) . sprintf ( " it under the terms of the GNU General Public License <http://www.gnu.org/>.<br> " ) ;
text + = QString ( ) . sprintf ( " Note that this program is distributed with ABSOLUTELY NO WARRANTY.<br><br> " ) ;
2012-01-29 15:57:23 +01:00
text + = QString ( ) . sprintf ( " Please check the web-site at <a href= \" %s \" >%s</a> for updates !!!<br></tt></nobr> " , home_url , home_url ) ;
2012-01-29 00:57:47 +01:00
2012-02-08 00:29:47 +01:00
QMessageBox aboutBox ( this ) ;
aboutBox . setIconPixmap ( QIcon ( " :/images/movie.png " ) . pixmap ( 64 , 64 ) ) ;
aboutBox . setWindowTitle ( tr ( " About... " ) ) ;
aboutBox . setText ( text . replace ( " - " , " − " ) ) ;
aboutBox . addButton ( tr ( " About x264 " ) , QMessageBox : : NoRole ) ;
2012-02-13 16:44:50 +01:00
aboutBox . addButton ( tr ( " About AVS " ) , QMessageBox : : NoRole ) ;
2013-08-07 15:34:02 +02:00
aboutBox . addButton ( tr ( " About VPY " ) , QMessageBox : : NoRole ) ;
2012-02-08 00:29:47 +01:00
aboutBox . addButton ( tr ( " About Qt " ) , QMessageBox : : NoRole ) ;
aboutBox . setEscapeButton ( aboutBox . addButton ( tr ( " Close " ) , QMessageBox : : NoRole ) ) ;
2012-02-02 17:20:42 +01:00
forever
{
2013-11-03 18:34:20 +01:00
x264_beep ( x264_beep_info ) ;
2012-02-08 00:29:47 +01:00
switch ( aboutBox . exec ( ) )
2012-02-02 17:20:42 +01:00
{
case 0 :
{
QString text2 ;
2013-05-11 01:50:05 +02:00
text2 + = tr ( " <nobr><tt>x264 - the best H.264/AVC encoder. Copyright (c) 2003-2013 x264 project.<br> " ) ;
2012-02-02 17:20:42 +01:00
text2 + = tr ( " Free software library for encoding video streams into the H.264/MPEG-4 AVC format.<br> " ) ;
text2 + = tr ( " Released under the terms of the GNU General Public License.<br><br> " ) ;
2012-02-13 16:44:50 +01:00
text2 + = tr ( " Please visit <a href= \" %1 \" >%1</a> for obtaining a commercial x264 license.<br> " ) . arg ( " http://x264licensing.com/ " ) ;
text2 + = tr ( " Read the <a href= \" %1 \" >user's manual</a> to get started and use the <a href= \" %2 \" >support forum</a> for help!<br></tt></nobr> " ) . arg ( " http://mewiki.project357.com/wiki/X264_Settings " , " http://forum.doom9.org/forumdisplay.php?f=77 " ) ;
2012-02-08 00:29:47 +01:00
QMessageBox x264Box ( this ) ;
x264Box . setIconPixmap ( QIcon ( " :/images/x264.png " ) . pixmap ( 48 , 48 ) ) ;
x264Box . setWindowTitle ( tr ( " About x264 " ) ) ;
x264Box . setText ( text2 . replace ( " - " , " − " ) ) ;
x264Box . setEscapeButton ( x264Box . addButton ( tr ( " Close " ) , QMessageBox : : NoRole ) ) ;
2013-11-03 18:34:20 +01:00
x264_beep ( x264_beep_info ) ;
2012-02-08 00:29:47 +01:00
x264Box . exec ( ) ;
2012-02-02 17:20:42 +01:00
}
break ;
case 1 :
2012-02-13 16:44:50 +01:00
{
QString text2 ;
2012-02-13 18:52:55 +01:00
text2 + = tr ( " <nobr><tt>Avisynth - powerful video processing scripting language.<br> " ) ;
2012-02-13 16:44:50 +01:00
text2 + = tr ( " Copyright (c) 2000 Ben Rudiak-Gould and all subsequent developers.<br> " ) ;
text2 + = tr ( " Released under the terms of the GNU General Public License.<br><br> " ) ;
text2 + = tr ( " Please visit the web-site <a href= \" %1 \" >%1</a> for more information.<br> " ) . arg ( " http://avisynth.org/ " ) ;
2013-08-07 16:00:46 +02:00
text2 + = tr ( " Read the <a href= \" %1 \" >guide</a> to get started and use the <a href= \" %2 \" >support forum</a> for help!<br></tt></nobr> " ) . arg ( " http://avisynth.nl/index.php/First_script " , " http://forum.doom9.org/forumdisplay.php?f=33 " ) ;
2012-02-13 16:44:50 +01:00
QMessageBox x264Box ( this ) ;
x264Box . setIconPixmap ( QIcon ( " :/images/avisynth.png " ) . pixmap ( 48 , 67 ) ) ;
x264Box . setWindowTitle ( tr ( " About Avisynth " ) ) ;
x264Box . setText ( text2 . replace ( " - " , " − " ) ) ;
x264Box . setEscapeButton ( x264Box . addButton ( tr ( " Close " ) , QMessageBox : : NoRole ) ) ;
2013-11-03 18:34:20 +01:00
x264_beep ( x264_beep_info ) ;
2012-02-13 16:44:50 +01:00
x264Box . exec ( ) ;
}
break ;
case 2 :
2013-08-07 15:34:02 +02:00
{
QString text2 ;
text2 + = tr ( " <nobr><tt>VapourSynth - application for video manipulation based on Python.<br> " ) ;
text2 + = tr ( " Copyright (c) 2012 Fredrik Mellbin.<br> " ) ;
text2 + = tr ( " Released under the terms of the GNU Lesser General Public.<br><br> " ) ;
text2 + = tr ( " Please visit the web-site <a href= \" %1 \" >%1</a> for more information.<br> " ) . arg ( " http://www.vapoursynth.com/ " ) ;
text2 + = tr ( " Read the <a href= \" %1 \" >documentation</a> to get started and use the <a href= \" %2 \" >support forum</a> for help!<br></tt></nobr> " ) . arg ( " http://www.vapoursynth.com/doc/ " , " http://forum.doom9.org/showthread.php?t=165771 " ) ;
QMessageBox x264Box ( this ) ;
x264Box . setIconPixmap ( QIcon ( " :/images/python.png " ) . pixmap ( 48 , 48 ) ) ;
x264Box . setWindowTitle ( tr ( " About VapourSynth " ) ) ;
x264Box . setText ( text2 . replace ( " - " , " − " ) ) ;
x264Box . setEscapeButton ( x264Box . addButton ( tr ( " Close " ) , QMessageBox : : NoRole ) ) ;
2013-11-03 18:34:20 +01:00
x264_beep ( x264_beep_info ) ;
2013-08-07 15:34:02 +02:00
x264Box . exec ( ) ;
}
break ;
case 3 :
2012-02-02 17:20:42 +01:00
QMessageBox : : aboutQt ( this ) ;
break ;
default :
return ;
}
}
2012-01-29 00:57:47 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* Open web - link
*/
2012-01-29 15:57:23 +01:00
void MainWindow : : showWebLink ( void )
{
2013-11-14 02:29:18 +01:00
if ( QObject : : sender ( ) = = ui - > actionWebMulder ) QDesktopServices : : openUrl ( QUrl ( home_url ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebX264 ) QDesktopServices : : openUrl ( QUrl ( " http://www.x264.com/ " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebKomisar ) QDesktopServices : : openUrl ( QUrl ( " http://komisar.gin.by/ " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebVideoLAN ) QDesktopServices : : openUrl ( QUrl ( " http://download.videolan.org/pub/x264/binaries/ " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebJEEB ) QDesktopServices : : openUrl ( QUrl ( " http://x264.fushizen.eu/ " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebAvisynth32 ) QDesktopServices : : openUrl ( QUrl ( " http://sourceforge.net/projects/avisynth2/files/AviSynth%202.5/ " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebAvisynth64 ) QDesktopServices : : openUrl ( QUrl ( " http://code.google.com/p/avisynth64/downloads/list " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebVapourSynth ) QDesktopServices : : openUrl ( QUrl ( " http://www.vapoursynth.com/ " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebVapourSynthDocs ) QDesktopServices : : openUrl ( QUrl ( " http://www.vapoursynth.com/doc/ " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebWiki ) QDesktopServices : : openUrl ( QUrl ( " http://mewiki.project357.com/wiki/X264_Settings " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebBluRay ) QDesktopServices : : openUrl ( QUrl ( " http://www.x264bluray.com/ " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebAvsWiki ) QDesktopServices : : openUrl ( QUrl ( " http://avisynth.nl/index.php/Main_Page#Usage " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebSupport ) QDesktopServices : : openUrl ( QUrl ( " http://forum.doom9.org/showthread.php?t=144140 " ) ) ;
if ( QObject : : sender ( ) = = ui - > actionWebSecret ) QDesktopServices : : openUrl ( QUrl ( " http://www.youtube.com/watch_popup?v=AXIeHY-OYNI " ) ) ;
2012-01-29 15:57:23 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* Pereferences dialog
*/
2012-02-03 00:53:14 +01:00
void MainWindow : : showPreferences ( void )
{
2013-07-03 21:34:21 +02:00
PreferencesDialog * preferences = new PreferencesDialog ( this , m_preferences , m_cpuFeatures - > x64 ) ;
2012-02-03 00:53:14 +01:00
preferences - > exec ( ) ;
X264_DELETE ( preferences ) ;
}
2012-02-10 18:42:16 +01:00
/*
* Launch next job , after running job has finished
*/
2012-01-29 00:57:47 +01:00
void MainWindow : : launchNextJob ( void )
{
2012-02-04 01:12:21 +01:00
qDebug ( " launchNextJob(void) " ) ;
2012-01-29 00:57:47 +01:00
const int rows = m_jobList - > rowCount ( QModelIndex ( ) ) ;
2013-07-03 21:34:21 +02:00
if ( countRunningJobs ( ) > = m_preferences - > maxRunningJobCount ( ) )
2012-01-29 00:57:47 +01:00
{
2012-02-04 01:12:21 +01:00
qDebug ( " Still have too many jobs running, won't launch next one yet! " ) ;
2012-02-03 00:53:14 +01:00
return ;
2012-01-29 00:57:47 +01:00
}
2013-11-14 02:29:18 +01:00
int startIdx = ui - > jobsView - > currentIndex ( ) . isValid ( ) ? qBound ( 0 , ui - > jobsView - > currentIndex ( ) . row ( ) , rows - 1 ) : 0 ;
2012-02-04 01:12:21 +01:00
for ( int i = 0 ; i < rows ; i + + )
2012-01-29 00:57:47 +01:00
{
2012-02-04 01:12:21 +01:00
int currentIdx = ( i + startIdx ) % rows ;
2013-07-03 21:52:19 +02:00
JobStatus status = m_jobList - > getJobStatus ( m_jobList - > index ( currentIdx , 0 , QModelIndex ( ) ) ) ;
if ( status = = JobStatus_Enqueued )
2012-01-29 00:57:47 +01:00
{
2012-02-04 01:12:21 +01:00
if ( m_jobList - > startJob ( m_jobList - > index ( currentIdx , 0 , QModelIndex ( ) ) ) )
2012-02-03 00:53:14 +01:00
{
2013-11-14 02:29:18 +01:00
ui - > jobsView - > selectRow ( currentIdx ) ;
2012-02-04 01:12:21 +01:00
return ;
2012-02-03 00:53:14 +01:00
}
2012-02-03 15:28:00 +01:00
}
2012-02-04 01:12:21 +01:00
}
2012-02-03 15:28:00 +01:00
2012-02-04 01:12:21 +01:00
qWarning ( " No enqueued jobs left! " ) ;
}
2012-04-30 19:26:41 +02:00
/*
* Save log to text file
*/
void MainWindow : : saveLogFile ( const QModelIndex & index )
{
if ( index . isValid ( ) )
{
if ( LogFileModel * log = m_jobList - > getLogFile ( index ) )
{
QDir ( QString ( " %1/logs " ) . arg ( x264_data_path ( ) ) ) . mkpath ( " . " ) ;
QString logFilePath = QString ( " %1/logs/LOG.%2.%3.txt " ) . arg ( x264_data_path ( ) , QDate : : currentDate ( ) . toString ( Qt : : ISODate ) , QTime : : currentTime ( ) . toString ( Qt : : ISODate ) . replace ( ' : ' , " - " ) ) ;
QFile outFile ( logFilePath ) ;
if ( outFile . open ( QIODevice : : WriteOnly ) )
{
QTextStream outStream ( & outFile ) ;
outStream . setCodec ( " UTF-8 " ) ;
outStream . setGenerateByteOrderMark ( true ) ;
const int rows = log - > rowCount ( QModelIndex ( ) ) ;
for ( int i = 0 ; i < rows ; i + + )
{
outStream < < log - > data ( log - > index ( i , 0 , QModelIndex ( ) ) , Qt : : DisplayRole ) . toString ( ) < < QLatin1String ( " \r \n " ) ;
}
outFile . close ( ) ;
}
else
{
qWarning ( " Failed to open log file for writing: \n %s " , logFilePath . toUtf8 ( ) . constData ( ) ) ;
}
}
}
}
2012-02-10 18:42:16 +01:00
/*
* Shut down the computer ( with countdown )
*/
2012-02-04 01:12:21 +01:00
void MainWindow : : shutdownComputer ( void )
{
qDebug ( " shutdownComputer(void) " ) ;
if ( countPendingJobs ( ) > 0 )
{
qDebug ( " Still have pending jobs, won't shutdown yet! " ) ;
return ;
}
const int iTimeout = 30 ;
const Qt : : WindowFlags flags = Qt : : WindowStaysOnTopHint | Qt : : CustomizeWindowHint | Qt : : WindowTitleHint | Qt : : MSWindowsFixedSizeDialogHint | Qt : : WindowSystemMenuHint ;
const QString text = QString ( " %1%2%1 " ) . arg ( QString ( ) . fill ( ' ' , 18 ) , tr ( " Warning: Computer will shutdown in %1 seconds... " ) ) ;
qWarning ( " Initiating shutdown sequence! " ) ;
QProgressDialog progressDialog ( text . arg ( iTimeout ) , tr ( " Cancel Shutdown " ) , 0 , iTimeout + 1 , this , flags ) ;
QPushButton * cancelButton = new QPushButton ( tr ( " Cancel Shutdown " ) , & progressDialog ) ;
cancelButton - > setIcon ( QIcon ( " :/buttons/power_on.png " ) ) ;
progressDialog . setModal ( true ) ;
progressDialog . setAutoClose ( false ) ;
progressDialog . setAutoReset ( false ) ;
progressDialog . setWindowIcon ( QIcon ( " :/buttons/power_off.png " ) ) ;
progressDialog . setWindowTitle ( windowTitle ( ) ) ;
progressDialog . setCancelButton ( cancelButton ) ;
progressDialog . show ( ) ;
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
2013-11-03 18:34:20 +01:00
x264_play_sound ( IDR_WAVE1 , false ) ;
2012-02-04 01:12:21 +01:00
QApplication : : restoreOverrideCursor ( ) ;
QTimer timer ;
timer . setInterval ( 1000 ) ;
timer . start ( ) ;
QEventLoop eventLoop ( this ) ;
connect ( & timer , SIGNAL ( timeout ( ) ) , & eventLoop , SLOT ( quit ( ) ) ) ;
connect ( & progressDialog , SIGNAL ( canceled ( ) ) , & eventLoop , SLOT ( quit ( ) ) ) ;
for ( int i = 1 ; i < = iTimeout ; i + + )
{
eventLoop . exec ( ) ;
if ( progressDialog . wasCanceled ( ) )
2012-02-03 15:28:00 +01:00
{
2012-02-04 01:12:21 +01:00
progressDialog . close ( ) ;
return ;
2012-01-29 00:57:47 +01:00
}
2012-02-04 01:12:21 +01:00
progressDialog . setValue ( i + 1 ) ;
progressDialog . setLabelText ( text . arg ( iTimeout - i ) ) ;
if ( iTimeout - i = = 3 ) progressDialog . setCancelButton ( NULL ) ;
QApplication : : processEvents ( ) ;
2013-11-03 18:34:20 +01:00
x264_play_sound ( ( ( i < iTimeout ) ? IDR_WAVE2 : IDR_WAVE3 ) , false ) ;
2012-02-04 01:12:21 +01:00
}
qWarning ( " Shutting down !!! " ) ;
if ( x264_shutdown_computer ( " Simple x264 Launcher: All jobs completed, shutting down! " , 10 , true ) )
{
qApp - > closeAllWindows ( ) ;
2012-01-29 00:57:47 +01:00
}
2012-01-28 23:24:41 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* Main initialization function ( called only once ! )
*/
2012-01-29 21:31:09 +01:00
void MainWindow : : init ( void )
{
2013-05-05 14:11:34 +02:00
static const char * binFiles = " x86/x264_8bit_x86.exe:x64/x264_8bit_x64.exe:x86/x264_10bit_x86.exe:x64/x264_10bit_x64.exe:x86/avs2yuv_x86.exe:x64/avs2yuv_x64.exe " ;
2012-01-29 21:31:09 +01:00
QStringList binaries = QString : : fromLatin1 ( binFiles ) . split ( " : " , QString : : SkipEmptyParts ) ;
2012-01-31 00:13:32 +01:00
2012-02-07 21:48:25 +01:00
updateLabelPos ( ) ;
2012-01-31 00:13:32 +01:00
2012-02-21 00:37:31 +01:00
//Check for a running instance
bool firstInstance = false ;
if ( m_ipcThread - > initialize ( & firstInstance ) )
{
2012-02-21 01:59:44 +01:00
m_ipcThread - > start ( ) ;
2012-02-21 00:37:31 +01:00
if ( ! firstInstance )
{
2012-02-21 01:59:44 +01:00
if ( ! m_ipcThread - > wait ( 5000 ) )
{
QMessageBox : : warning ( this , tr ( " Not Responding " ) , tr ( " <nobr>Another instance of this application is already running, but did not respond in time.<br>If the problem persists, please kill the running instance from the task manager!</nobr> " ) , tr ( " Quit " ) ) ;
m_ipcThread - > terminate ( ) ;
m_ipcThread - > wait ( ) ;
}
2013-11-08 17:39:16 +01:00
INIT_ERROR_EXIT ( ) ;
2012-02-21 00:37:31 +01:00
}
}
2012-01-30 17:50:19 +01:00
//Check all binaries
2012-01-29 21:31:09 +01:00
while ( ! binaries . isEmpty ( ) )
{
2012-02-02 18:55:55 +01:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2012-01-29 21:31:09 +01:00
QString current = binaries . takeFirst ( ) ;
QFile * file = new QFile ( QString ( " %1/toolset/%2 " ) . arg ( m_appDir , current ) ) ;
if ( file - > open ( QIODevice : : ReadOnly ) )
{
2013-11-03 18:34:20 +01:00
if ( ! x264_is_executable ( file - > fileName ( ) ) )
2012-02-02 04:12:58 +01:00
{
2013-07-07 16:11:47 +02:00
QMessageBox : : critical ( this , tr ( " Invalid File! " ) , tr ( " <nobr>At least on required tool is not a valid Win32 or Win64 binary:<br><tt style= \" whitespace:nowrap \" >%1</tt><br><br>Please re-install the program in order to fix the problem!</nobr> " ) . arg ( QDir : : toNativeSeparators ( QString ( " %1/toolset/%2 " ) . arg ( m_appDir , current ) ) ) . replace ( " - " , " − " ) ) ;
2012-02-02 04:12:58 +01:00
qFatal ( QString ( " Binary is invalid: %1/toolset/%2 " ) . arg ( m_appDir , current ) . toLatin1 ( ) . constData ( ) ) ;
2013-11-08 17:39:16 +01:00
INIT_ERROR_EXIT ( ) ;
2012-02-02 04:12:58 +01:00
}
2012-01-29 21:31:09 +01:00
m_toolsList < < file ;
}
else
{
X264_DELETE ( file ) ;
2013-07-07 16:11:47 +02:00
QMessageBox : : critical ( this , tr ( " File Not Found! " ) , tr ( " <nobr>At least on required tool could not be found:<br><tt style= \" whitespace:nowrap \" >%1</tt><br><br>Please re-install the program in order to fix the problem!</nobr> " ) . arg ( QDir : : toNativeSeparators ( QString ( " %1/toolset/%2 " ) . arg ( m_appDir , current ) ) ) . replace ( " - " , " − " ) ) ;
2012-01-29 21:31:09 +01:00
qFatal ( QString ( " Binary not found: %1/toolset/%2 " ) . arg ( m_appDir , current ) . toLatin1 ( ) . constData ( ) ) ;
2013-11-08 17:39:16 +01:00
INIT_ERROR_EXIT ( ) ;
2012-01-29 21:31:09 +01:00
}
2012-02-10 01:58:45 +01:00
}
//Check for portable mode
if ( x264_portable ( ) )
{
bool ok = false ;
static const char * data = " Lorem ipsum dolor sit amet, consectetur adipiscing elit. " ;
2012-02-10 18:42:16 +01:00
QFile writeTest ( QString ( " %1/%2 " ) . arg ( x264_data_path ( ) , QUuid : : createUuid ( ) . toString ( ) ) ) ;
2012-02-10 01:58:45 +01:00
if ( writeTest . open ( QIODevice : : WriteOnly ) )
{
ok = ( writeTest . write ( data ) = = strlen ( data ) ) ;
writeTest . remove ( ) ;
}
if ( ! ok )
{
int val = QMessageBox : : warning ( this , tr ( " Write Test Failed " ) , tr ( " <nobr>The application was launched in portable mode, but the program path is <b>not</b> writable!</nobr> " ) , tr ( " Quit " ) , tr ( " Ignore " ) ) ;
2013-11-08 17:39:16 +01:00
if ( val ! = 1 ) INIT_ERROR_EXIT ( ) ;
2012-02-10 01:58:45 +01:00
}
2012-01-29 21:31:09 +01:00
}
2012-01-30 17:50:19 +01:00
//Pre-release popup
2012-02-02 22:53:40 +01:00
if ( x264_is_prerelease ( ) )
2012-01-30 17:50:19 +01:00
{
qsrand ( time ( NULL ) ) ; int rnd = qrand ( ) % 3 ;
int val = QMessageBox : : information ( this , tr ( " Pre-Release Version " ) , tr ( " Note: This is a pre-release version. Please do NOT use for production!<br>Click the button #%1 in order to continue...<br><br>(There will be no such message box in the final version of this application) " ) . arg ( QString : : number ( rnd + 1 ) ) , tr ( " (1) " ) , tr ( " (2) " ) , tr ( " (3) " ) , qrand ( ) % 3 ) ;
2013-11-08 17:39:16 +01:00
if ( rnd ! = val ) INIT_ERROR_EXIT ( ) ;
2012-01-30 17:50:19 +01:00
}
2012-02-07 21:48:25 +01:00
//Make sure this CPU can run x264 (requires MMX + MMXEXT/iSSE to run x264 with ASM enabled, additionally requires SSE1 for most x264 builds)
if ( ! ( m_cpuFeatures - > mmx & & m_cpuFeatures - > mmx2 ) )
{
QMessageBox : : critical ( this , tr ( " Unsupported CPU " ) , tr ( " <nobr>Sorry, but this machine is <b>not</b> physically capable of running x264 (with assembly).<br>Please get a CPU that supports at least the MMX and MMXEXT instruction sets!</nobr> " ) , tr ( " Quit " ) ) ;
qFatal ( " System does not support MMX and MMXEXT, x264 will not work !!! " ) ;
2013-11-08 17:39:16 +01:00
INIT_ERROR_EXIT ( ) ;
2012-02-07 21:48:25 +01:00
}
else if ( ! ( m_cpuFeatures - > mmx & & m_cpuFeatures - > sse ) )
{
qWarning ( " WARNING: System does not support SSE1, most x264 builds will not work !!! \n " ) ;
int val = QMessageBox : : warning ( this , tr ( " Unsupported CPU " ) , tr ( " <nobr>It appears that this machine does <b>not</b> support the SSE1 instruction set.<br>Thus most builds of x264 will <b>not</b> run on this computer at all.<br><br>Please get a CPU that supports the MMX and SSE1 instruction sets!</nobr> " ) , tr ( " Quit " ) , tr ( " Ignore " ) ) ;
2013-11-08 17:39:16 +01:00
if ( val ! = 1 ) INIT_ERROR_EXIT ( ) ;
2012-02-07 21:48:25 +01:00
}
2013-07-07 16:11:47 +02:00
//Skip version check (not recommended!)
if ( qApp - > arguments ( ) . contains ( " --skip-x264-version-check " , Qt : : CaseInsensitive ) )
{
qWarning ( " x264 version check disabled, you have been warned! \n " ) ;
m_skipVersionTest = true ;
}
2013-08-04 18:44:53 +02:00
//Don't abort encoding process on timeout (not recommended!)
if ( qApp - > arguments ( ) . contains ( " --no-deadlock-detection " , Qt : : CaseInsensitive ) )
{
qWarning ( " Deadlock detection disabled, you have been warned! \n " ) ;
m_abortOnTimeout = false ;
}
2012-01-30 17:50:19 +01:00
//Check for Avisynth support
2012-02-13 20:49:16 +01:00
if ( ! qApp - > arguments ( ) . contains ( " --skip-avisynth-check " , Qt : : CaseInsensitive ) )
2012-01-30 17:50:19 +01:00
{
2012-04-30 16:56:01 +02:00
qDebug ( " [Check for Avisynth support] " ) ;
2013-04-02 23:10:58 +02:00
volatile double avisynthVersion = 0.0 ;
const int result = AvisynthCheckThread : : detect ( & avisynthVersion ) ;
if ( result < 0 )
2012-04-30 19:26:41 +02:00
{
2013-04-02 23:10:58 +02:00
QString text = tr ( " A critical error was encountered while checking your Avisynth version. " ) . append ( " <br> " ) ;
text + = tr ( " This is most likely caused by an erroneous Avisynth Plugin, please try to clean your Plugins folder! " ) . append ( " <br> " ) ;
text + = tr ( " We suggest to move all .dll and .avsi files out of your Avisynth Plugins folder and try again. " ) ;
int val = QMessageBox : : critical ( this , tr ( " Avisynth Error " ) , QString ( " <nobr>%1</nobr> " ) . arg ( text ) . replace ( " - " , " − " ) , tr ( " Quit " ) , tr ( " Ignore " ) ) ;
2013-11-08 17:39:16 +01:00
if ( val ! = 1 ) INIT_ERROR_EXIT ( ) ;
2012-04-30 19:26:41 +02:00
}
2013-04-02 23:10:58 +02:00
if ( ( ! result ) | | ( avisynthVersion < 2.5 ) )
2012-02-13 20:49:16 +01:00
{
2013-08-08 23:18:31 +02:00
if ( ! m_preferences - > disableWarnings ( ) )
{
QString text = tr ( " It appears that Avisynth is <b>not</b> currently installed on your computer.<br>Therefore Avisynth (.avs) input will <b>not</b> be working at all! " ) . append ( " <br><br> " ) ;
text + = tr ( " Please download and install Avisynth: " ) . append ( " <br> " ) . append ( LINK ( " http://sourceforge.net/projects/avisynth2/files/AviSynth%202.5/ " ) ) ;
int val = QMessageBox : : warning ( this , tr ( " Avisynth Missing " ) , QString ( " <nobr>%1</nobr> " ) . arg ( text ) . replace ( " - " , " − " ) , tr ( " Quit " ) , tr ( " Ignore " ) ) ;
2013-11-08 17:39:16 +01:00
if ( val ! = 1 ) INIT_ERROR_EXIT ( ) ;
2013-08-08 23:18:31 +02:00
}
2012-02-13 18:52:55 +01:00
}
2013-11-08 17:39:16 +01:00
qDebug ( " " ) ;
2012-01-30 17:50:19 +01:00
}
2012-02-02 02:13:02 +01:00
2013-08-11 20:13:51 +02:00
//Check for VapourSynth support
2013-08-02 18:09:12 +02:00
if ( ! qApp - > arguments ( ) . contains ( " --skip-vapoursynth-check " , Qt : : CaseInsensitive ) )
{
2013-08-11 20:13:51 +02:00
qDebug ( " [Check for VapourSynth support] " ) ;
2013-08-07 15:34:02 +02:00
volatile double avisynthVersion = 0.0 ;
const int result = VapourSynthCheckThread : : detect ( m_vapoursynthPath ) ;
if ( result < 0 )
2013-08-02 18:09:12 +02:00
{
2013-08-11 20:13:51 +02:00
QString text = tr ( " A critical error was encountered while checking your VapourSynth installation. " ) . append ( " <br> " ) ;
text + = tr ( " This is most likely caused by an erroneous VapourSynth Plugin, please try to clean your Filters folder! " ) . append ( " <br> " ) ;
text + = tr ( " We suggest to move all .dll files out of your VapourSynth Filters folder and try again. " ) ;
int val = QMessageBox : : critical ( this , tr ( " VapourSynth Error " ) , QString ( " <nobr>%1</nobr> " ) . arg ( text ) . replace ( " - " , " − " ) , tr ( " Quit " ) , tr ( " Ignore " ) ) ;
2013-11-08 17:39:16 +01:00
if ( val ! = 1 ) INIT_ERROR_EXIT ( ) ;
2013-08-07 15:34:02 +02:00
}
if ( ( ! result ) | | ( m_vapoursynthPath . isEmpty ( ) ) )
{
2013-08-08 23:18:31 +02:00
if ( ! m_preferences - > disableWarnings ( ) )
{
2013-08-11 20:13:51 +02:00
QString text = tr ( " It appears that VapourSynth is <b>not</b> currently installed on your computer.<br>Therefore VapourSynth (.vpy) input will <b>not</b> be working at all! " ) . append ( " <br><br> " ) ;
text + = tr ( " Please download and install VapourSynth for Windows (R19 or later): " ) . append ( " <br> " ) . append ( LINK ( " http://www.vapoursynth.com/ " ) ) . append ( " <br><br> " ) ;
text + = tr ( " Note that Python 3.3 (x86) is a prerequisite for installing VapourSynth: " ) . append ( " <br> " ) . append ( LINK ( " http://www.python.org/getit/ " ) ) . append ( " <br> " ) ;
int val = QMessageBox : : warning ( this , tr ( " VapourSynth Missing " ) , QString ( " <nobr>%1</nobr> " ) . arg ( text ) . replace ( " - " , " − " ) , tr ( " Quit " ) , tr ( " Ignore " ) ) ;
2013-11-08 17:39:16 +01:00
if ( val ! = 1 ) INIT_ERROR_EXIT ( ) ;
2013-08-08 23:18:31 +02:00
}
2013-08-02 18:09:12 +02:00
}
2013-11-08 17:39:16 +01:00
qDebug ( " " ) ;
2013-08-02 18:09:12 +02:00
}
2012-02-02 02:13:02 +01:00
//Check for expiration
if ( x264_version_date ( ) . addMonths ( 6 ) < QDate : : currentDate ( ) )
{
QMessageBox msgBox ( this ) ;
2012-02-08 00:29:47 +01:00
msgBox . setIconPixmap ( QIcon ( " :/images/update.png " ) . pixmap ( 56 , 56 ) ) ;
2012-02-02 02:13:02 +01:00
msgBox . setWindowTitle ( tr ( " Update Notification " ) ) ;
msgBox . setWindowFlags ( Qt : : Window | Qt : : WindowTitleHint | Qt : : CustomizeWindowHint ) ;
2012-02-08 00:29:47 +01:00
msgBox . setText ( tr ( " <nobr><tt>Your version of 'Simple x264 Launcher' is more than 6 months old!<br><br>Please download the most recent version from the official web-site at:<br><a href= \" %1 \" >%1</a><br></tt></nobr> " ) . replace ( " - " , " − " ) . arg ( update_url ) ) ;
2012-02-02 02:13:02 +01:00
QPushButton * btn1 = msgBox . addButton ( tr ( " Discard " ) , QMessageBox : : NoRole ) ;
QPushButton * btn2 = msgBox . addButton ( tr ( " Discard " ) , QMessageBox : : AcceptRole ) ;
btn1 - > setEnabled ( false ) ;
btn2 - > setVisible ( false ) ;
QTimer : : singleShot ( 5000 , btn1 , SLOT ( hide ( ) ) ) ;
QTimer : : singleShot ( 5000 , btn2 , SLOT ( show ( ) ) ) ;
msgBox . exec ( ) ;
}
2012-02-05 04:41:42 +01:00
//Add files from command-line
bool bAddFile = false ;
QStringList files , args = qApp - > arguments ( ) ;
while ( ! args . isEmpty ( ) )
{
QString current = args . takeFirst ( ) ;
if ( ! bAddFile )
{
bAddFile = ( current . compare ( " --add " , Qt : : CaseInsensitive ) = = 0 ) ;
continue ;
}
2012-02-07 21:48:25 +01:00
if ( ( ! current . startsWith ( " -- " ) ) & & QFileInfo ( current ) . exists ( ) & & QFileInfo ( current ) . isFile ( ) )
2012-02-05 04:41:42 +01:00
{
files < < QFileInfo ( current ) . canonicalFilePath ( ) ;
}
}
2013-05-11 01:50:05 +02:00
if ( files . count ( ) > 0 )
2012-02-05 04:41:42 +01:00
{
2013-05-11 01:50:05 +02:00
createJobMultiple ( files ) ;
2012-02-05 04:41:42 +01:00
}
2012-12-01 15:54:07 +01:00
//Enable drag&drop support for this window, required for Qt v4.8.4+
setAcceptDrops ( true ) ;
2013-11-08 17:39:16 +01:00
//Update initialized flag
m_initialized = true ;
2013-11-29 18:10:11 +01:00
//FIXME
2013-11-29 20:27:45 +01:00
QTimer : : singleShot ( 333 , this , SLOT ( checkUpdates ( ) ) ) ;
2012-01-29 21:31:09 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* Update the label position
*/
2012-02-07 21:48:25 +01:00
void MainWindow : : updateLabelPos ( void )
2012-01-31 00:13:32 +01:00
{
2013-11-14 02:29:18 +01:00
const QWidget * const viewPort = ui - > jobsView - > viewport ( ) ;
2012-02-07 21:48:25 +01:00
m_label - > setGeometry ( 0 , 0 , viewPort - > width ( ) , viewPort - > height ( ) ) ;
2012-01-31 00:13:32 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* Copy the complete log to the clipboard
*/
2012-01-31 00:13:32 +01:00
void MainWindow : : copyLogToClipboard ( bool checked )
{
qDebug ( " copyLogToClipboard " ) ;
2013-11-14 02:29:18 +01:00
if ( LogFileModel * log = dynamic_cast < LogFileModel * > ( ui - > logView - > model ( ) ) )
2012-01-31 00:13:32 +01:00
{
log - > copyToClipboard ( ) ;
2013-11-03 18:34:20 +01:00
x264_beep ( x264_beep_info ) ;
2012-01-31 00:13:32 +01:00
}
}
2012-02-10 18:42:16 +01:00
/*
* Process the dropped files
*/
void MainWindow : : handleDroppedFiles ( void )
{
qDebug ( " MainWindow::handleDroppedFiles " ) ;
if ( m_droppedFiles )
{
QStringList droppedFiles ( * m_droppedFiles ) ;
m_droppedFiles - > clear ( ) ;
2013-05-11 01:50:05 +02:00
createJobMultiple ( droppedFiles ) ;
2012-02-10 18:42:16 +01:00
}
qDebug ( " Leave from MainWindow::handleDroppedFiles! " ) ;
}
2013-11-03 18:34:20 +01:00
void MainWindow : : instanceCreated ( unsigned int pid )
2012-02-21 00:37:31 +01:00
{
2012-02-21 01:59:44 +01:00
qDebug ( " Notification from other instance (PID=0x%X) received! " , pid ) ;
2012-02-21 00:37:31 +01:00
2013-11-03 18:34:20 +01:00
x264_blink_window ( this , 5 , 125 ) ;
x264_bring_to_front ( this ) ;
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
x264_blink_window ( this , 5 , 125 ) ;
2012-02-21 00:37:31 +01:00
}
2013-11-22 17:01:13 +01:00
void MainWindow : : checkUpdates ( void )
{
if ( ! m_initialized )
{
return ;
}
if ( countRunningJobs ( ) > 0 )
{
QMessageBox : : warning ( this , tr ( " Jobs Are Running " ) , tr ( " Sorry, can not update while there still are running jobs! " ) ) ;
return ;
}
UpdaterDialog * updater = new UpdaterDialog ( this ) ;
updater - > exec ( ) ;
X264_DELETE ( updater ) ;
}
2012-01-28 23:24:41 +01:00
///////////////////////////////////////////////////////////////////////////////
// Event functions
///////////////////////////////////////////////////////////////////////////////
2012-02-10 18:42:16 +01:00
/*
* Window shown event
*/
2012-01-29 21:31:09 +01:00
void MainWindow : : showEvent ( QShowEvent * e )
{
QMainWindow : : showEvent ( e ) ;
if ( m_firstShow )
{
m_firstShow = false ;
QTimer : : singleShot ( 0 , this , SLOT ( init ( ) ) ) ;
}
}
2012-02-10 18:42:16 +01:00
/*
* Window close event
*/
2012-01-28 23:24:41 +01:00
void MainWindow : : closeEvent ( QCloseEvent * e )
2012-01-29 15:57:23 +01:00
{
2013-11-08 17:39:16 +01:00
if ( ! m_initialized )
{
e - > ignore ( ) ;
return ;
}
2012-02-03 15:28:00 +01:00
if ( countRunningJobs ( ) > 0 )
2012-01-29 15:57:23 +01:00
{
e - > ignore ( ) ;
2012-02-02 22:53:40 +01:00
QMessageBox : : warning ( this , tr ( " Jobs Are Running " ) , tr ( " Sorry, can not exit while there still are running jobs! " ) ) ;
2012-01-29 15:57:23 +01:00
return ;
}
2012-02-02 22:53:40 +01:00
2012-02-03 15:28:00 +01:00
if ( countPendingJobs ( ) > 0 )
2012-02-02 22:53:40 +01:00
{
int ret = QMessageBox : : question ( this , tr ( " Jobs Are Pending " ) , tr ( " Do you really want to quit and discard the pending jobs? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ;
if ( ret ! = QMessageBox : : Yes )
{
e - > ignore ( ) ;
return ;
}
}
while ( m_jobList - > rowCount ( QModelIndex ( ) ) > 0 )
{
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
if ( ! m_jobList - > deleteJob ( m_jobList - > index ( 0 , 0 , QModelIndex ( ) ) ) )
{
e - > ignore ( ) ;
QMessageBox : : warning ( this , tr ( " Failed To Exit " ) , tr ( " Sorry, at least one job could not be deleted! " ) ) ;
return ;
}
}
2012-01-29 15:57:23 +01:00
2012-02-02 22:53:40 +01:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2012-01-29 15:57:23 +01:00
QMainWindow : : closeEvent ( e ) ;
}
2012-02-10 18:42:16 +01:00
/*
* Window resize event
*/
2012-01-31 00:13:32 +01:00
void MainWindow : : resizeEvent ( QResizeEvent * e )
{
QMainWindow : : resizeEvent ( e ) ;
2012-02-07 21:48:25 +01:00
updateLabelPos ( ) ;
2012-01-31 00:13:32 +01:00
}
2012-02-08 00:29:47 +01:00
/*
* Event filter
*/
2012-01-31 20:28:40 +01:00
bool MainWindow : : eventFilter ( QObject * o , QEvent * e )
{
2013-11-14 02:29:18 +01:00
if ( ( o = = ui - > labelBuildDate ) & & ( e - > type ( ) = = QEvent : : MouseButtonPress ) )
2012-01-31 20:28:40 +01:00
{
QTimer : : singleShot ( 0 , this , SLOT ( showAbout ( ) ) ) ;
return true ;
}
return false ;
}
2012-02-08 00:29:47 +01:00
/*
* Win32 message filter
*/
bool MainWindow : : winEvent ( MSG * message , long * result )
{
return WinSevenTaskbar : : handleWinEvent ( message , result ) ;
}
2012-02-02 13:52:52 +01:00
/*
* File dragged over window
*/
void MainWindow : : 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-02 13:52:52 +01:00
{
event - > acceptProposedAction ( ) ;
}
}
/*
* File dropped onto window
*/
void MainWindow : : dropEvent ( QDropEvent * event )
{
QStringList droppedFiles ;
QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
while ( ! urls . isEmpty ( ) )
{
QUrl currentUrl = urls . takeFirst ( ) ;
QFileInfo file ( currentUrl . toLocalFile ( ) ) ;
if ( file . exists ( ) & & file . isFile ( ) )
{
2012-02-10 18:42:16 +01:00
qDebug ( " MainWindow::dropEvent: %s " , file . canonicalFilePath ( ) . toUtf8 ( ) . constData ( ) ) ;
2012-02-02 13:52:52 +01:00
droppedFiles < < file . canonicalFilePath ( ) ;
}
}
2012-02-10 18:42:16 +01:00
if ( droppedFiles . count ( ) > 0 )
2012-02-02 13:52:52 +01:00
{
2012-02-10 18:42:16 +01:00
if ( ! m_droppedFiles )
{
m_droppedFiles = new QStringList ( ) ;
}
m_droppedFiles - > append ( droppedFiles ) ;
m_droppedFiles - > sort ( ) ;
QTimer : : singleShot ( 0 , this , SLOT ( handleDroppedFiles ( ) ) ) ;
2012-02-02 13:52:52 +01:00
}
}
2012-01-29 15:57:23 +01:00
///////////////////////////////////////////////////////////////////////////////
// Private functions
///////////////////////////////////////////////////////////////////////////////
2013-05-08 00:04:40 +02:00
/*
* Creates a new job
*/
bool MainWindow : : createJob ( QString & sourceFileName , QString & outputFileName , OptionsModel * options , bool & runImmediately , const bool restart , int fileNo , int fileTotal , bool * applyToAll )
{
bool okay = false ;
2013-07-03 21:34:21 +02:00
AddJobDialog * addDialog = new AddJobDialog ( this , options , m_recentlyUsed , m_cpuFeatures - > x64 , m_preferences - > use10BitEncoding ( ) , m_preferences - > saveToSourcePath ( ) ) ;
2013-05-08 00:04:40 +02:00
addDialog - > setRunImmediately ( runImmediately ) ;
if ( ! sourceFileName . isEmpty ( ) ) addDialog - > setSourceFile ( sourceFileName ) ;
if ( ! outputFileName . isEmpty ( ) ) addDialog - > setOutputFile ( outputFileName ) ;
if ( restart ) addDialog - > setWindowTitle ( tr ( " Restart Job " ) ) ;
const bool multiFile = ( fileNo > = 0 ) & & ( fileTotal > 1 ) ;
if ( multiFile )
{
addDialog - > setSourceEditable ( false ) ;
addDialog - > setWindowTitle ( addDialog - > windowTitle ( ) . append ( tr ( " (File %1 of %2) " ) . arg ( QString : : number ( fileNo + 1 ) , QString : : number ( fileTotal ) ) ) ) ;
addDialog - > setApplyToAllVisible ( applyToAll ) ;
}
if ( addDialog - > exec ( ) = = QDialog : : Accepted )
{
sourceFileName = addDialog - > sourceFile ( ) ;
outputFileName = addDialog - > outputFile ( ) ;
runImmediately = addDialog - > runImmediately ( ) ;
if ( applyToAll )
{
* applyToAll = addDialog - > applyToAll ( ) ;
}
okay = true ;
}
X264_DELETE ( addDialog ) ;
return okay ;
}
2013-05-11 01:50:05 +02:00
/*
* Creates a new job from * multiple * files
*/
bool MainWindow : : createJobMultiple ( const QStringList & filePathIn )
{
QStringList : : ConstIterator iter ;
bool applyToAll = false , runImmediately = false ;
int counter = 0 ;
//Add files individually
2013-05-11 21:52:07 +02:00
for ( iter = filePathIn . constBegin ( ) ; ( iter ! = filePathIn . constEnd ( ) ) & & ( ! applyToAll ) ; iter + + )
2013-05-11 01:50:05 +02:00
{
2013-07-03 21:34:21 +02:00
runImmediately = ( countRunningJobs ( ) < ( m_preferences - > autoRunNextJob ( ) ? m_preferences - > maxRunningJobCount ( ) : 1 ) ) ;
2013-05-11 01:50:05 +02:00
QString sourceFileName ( * iter ) , outputFileName ;
if ( createJob ( sourceFileName , outputFileName , m_options , runImmediately , false , counter + + , filePathIn . count ( ) , & applyToAll ) )
{
if ( appendJob ( sourceFileName , outputFileName , m_options , runImmediately ) )
{
continue ;
}
}
return false ;
}
//Add remaining files
while ( applyToAll & & ( iter ! = filePathIn . constEnd ( ) ) )
{
2013-07-03 21:34:21 +02:00
const bool runImmediatelyTmp = runImmediately & & ( countRunningJobs ( ) < ( m_preferences - > autoRunNextJob ( ) ? m_preferences - > maxRunningJobCount ( ) : 1 ) ) ;
2013-05-11 01:50:05 +02:00
const QString sourceFileName = * iter ;
2013-07-03 21:34:21 +02:00
const QString outputFileName = AddJobDialog : : generateOutputFileName ( sourceFileName , m_recentlyUsed - > outputDirectory ( ) , m_recentlyUsed - > filterIndex ( ) , m_preferences - > saveToSourcePath ( ) ) ;
2013-05-11 01:50:05 +02:00
if ( ! appendJob ( sourceFileName , outputFileName , m_options , runImmediatelyTmp ) )
{
return false ;
}
iter + + ;
}
return true ;
}
2013-05-08 00:04:40 +02:00
/*
* Append a new job
*/
bool MainWindow : : appendJob ( const QString & sourceFileName , const QString & outputFileName , OptionsModel * options , const bool runImmediately )
{
bool okay = false ;
EncodeThread * thrd = new EncodeThread
(
sourceFileName ,
outputFileName ,
options ,
QString ( " %1/toolset " ) . arg ( m_appDir ) ,
2013-08-02 20:44:47 +02:00
m_vapoursynthPath ,
2013-05-08 00:04:40 +02:00
m_cpuFeatures - > x64 ,
2013-07-03 21:34:21 +02:00
m_preferences - > use10BitEncoding ( ) ,
m_cpuFeatures - > x64 & & m_preferences - > useAvisyth64Bit ( ) ,
2013-07-07 16:11:47 +02:00
m_skipVersionTest ,
2013-08-04 18:44:53 +02:00
m_preferences - > processPriority ( ) ,
m_abortOnTimeout
2013-05-08 00:04:40 +02:00
) ;
QModelIndex newIndex = m_jobList - > insertJob ( thrd ) ;
if ( newIndex . isValid ( ) )
{
if ( runImmediately )
{
2013-11-14 02:29:18 +01:00
ui - > jobsView - > selectRow ( newIndex . row ( ) ) ;
2013-05-08 00:04:40 +02:00
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
m_jobList - > startJob ( newIndex ) ;
}
okay = true ;
}
m_label - > setVisible ( m_jobList - > rowCount ( QModelIndex ( ) ) = = 0 ) ;
return okay ;
}
2012-02-10 18:42:16 +01:00
/*
* Jobs that are not completed ( or failed , or aborted ) yet
*/
2012-02-03 15:28:00 +01:00
unsigned int MainWindow : : countPendingJobs ( void )
2012-01-28 23:24:41 +01:00
{
2012-02-03 15:28:00 +01:00
unsigned int count = 0 ;
2012-01-28 23:24:41 +01:00
const int rows = m_jobList - > rowCount ( QModelIndex ( ) ) ;
2012-01-29 15:57:23 +01:00
2012-01-28 23:24:41 +01:00
for ( int i = 0 ; i < rows ; i + + )
{
2013-07-03 21:52:19 +02:00
JobStatus status = m_jobList - > getJobStatus ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) ) ;
if ( status ! = JobStatus_Completed & & status ! = JobStatus_Aborted & & status ! = JobStatus_Failed )
2012-01-28 23:24:41 +01:00
{
2012-02-03 15:28:00 +01:00
count + + ;
2012-01-28 23:24:41 +01:00
}
}
2012-02-03 15:28:00 +01:00
return count ;
2012-01-29 15:57:23 +01:00
}
2012-01-28 23:24:41 +01:00
2012-02-10 18:42:16 +01:00
/*
* Jobs that are still active , i . e . not terminated or enqueued
*/
2012-02-03 15:28:00 +01:00
unsigned int MainWindow : : countRunningJobs ( void )
2012-02-02 22:53:40 +01:00
{
2012-02-03 15:28:00 +01:00
unsigned int count = 0 ;
2012-02-02 22:53:40 +01:00
const int rows = m_jobList - > rowCount ( QModelIndex ( ) ) ;
for ( int i = 0 ; i < rows ; i + + )
{
2013-07-03 21:52:19 +02:00
JobStatus status = m_jobList - > getJobStatus ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) ) ;
if ( status ! = JobStatus_Completed & & status ! = JobStatus_Aborted & & status ! = JobStatus_Failed & & status ! = JobStatus_Enqueued )
2012-02-02 22:53:40 +01:00
{
2012-02-03 15:28:00 +01:00
count + + ;
2012-02-02 22:53:40 +01:00
}
}
2012-02-03 15:28:00 +01:00
return count ;
2012-02-02 22:53:40 +01:00
}
2012-02-10 18:42:16 +01:00
/*
* Update all buttons with respect to current job status
*/
2013-07-03 21:52:19 +02:00
void MainWindow : : updateButtons ( JobStatus status )
2012-01-28 23:24:41 +01:00
{
qDebug ( " MainWindow::updateButtons(void) " ) ;
2013-11-14 02:29:18 +01:00
ui - > buttonStartJob - > setEnabled ( status = = JobStatus_Enqueued ) ;
ui - > buttonAbortJob - > setEnabled ( status = = JobStatus_Indexing | | status = = JobStatus_Running | | status = = JobStatus_Running_Pass1 | | status = = JobStatus_Running_Pass2 | | status = = JobStatus_Paused ) ;
ui - > buttonPauseJob - > setEnabled ( status = = JobStatus_Indexing | | status = = JobStatus_Running | | status = = JobStatus_Paused | | status = = JobStatus_Running_Pass1 | | status = = JobStatus_Running_Pass2 ) ;
ui - > buttonPauseJob - > setChecked ( status = = JobStatus_Paused | | status = = JobStatus_Pausing ) ;
2012-01-31 00:13:32 +01:00
2013-11-14 02:29:18 +01:00
ui - > actionJob_Delete - > setEnabled ( status = = JobStatus_Completed | | status = = JobStatus_Aborted | | status = = JobStatus_Failed | | status = = JobStatus_Enqueued ) ;
ui - > actionJob_Restart - > setEnabled ( status = = JobStatus_Completed | | status = = JobStatus_Aborted | | status = = JobStatus_Failed | | status = = JobStatus_Enqueued ) ;
ui - > actionJob_Browse - > setEnabled ( status = = JobStatus_Completed ) ;
2012-02-02 22:53:40 +01:00
2013-11-14 02:29:18 +01:00
ui - > actionJob_Start - > setEnabled ( ui - > buttonStartJob - > isEnabled ( ) ) ;
ui - > actionJob_Abort - > setEnabled ( ui - > buttonAbortJob - > isEnabled ( ) ) ;
ui - > actionJob_Pause - > setEnabled ( ui - > buttonPauseJob - > isEnabled ( ) ) ;
ui - > actionJob_Pause - > setChecked ( ui - > buttonPauseJob - > isChecked ( ) ) ;
2012-02-02 02:13:02 +01:00
2013-11-14 02:29:18 +01:00
ui - > editDetails - > setEnabled ( status ! = JobStatus_Paused ) ;
2012-01-28 18:55:40 +01:00
}
2012-02-08 00:29:47 +01:00
2012-02-10 18:42:16 +01:00
/*
* Update the taskbar with current job status
*/
2013-07-03 21:52:19 +02:00
void MainWindow : : updateTaskbar ( JobStatus status , const QIcon & icon )
2012-02-08 00:29:47 +01:00
{
qDebug ( " MainWindow::updateTaskbar(void) " ) ;
switch ( status )
{
2013-07-03 21:52:19 +02:00
case JobStatus_Undefined :
2012-02-08 00:29:47 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarNoState ) ;
break ;
2013-07-03 21:52:19 +02:00
case JobStatus_Aborting :
case JobStatus_Starting :
case JobStatus_Pausing :
case JobStatus_Resuming :
2012-02-08 00:29:47 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarIndeterminateState ) ;
break ;
2013-07-03 21:52:19 +02:00
case JobStatus_Aborted :
case JobStatus_Failed :
2012-02-08 00:29:47 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
break ;
2013-07-03 21:52:19 +02:00
case JobStatus_Paused :
2012-02-08 00:29:47 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarPausedState ) ;
break ;
default :
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarNormalState ) ;
break ;
}
switch ( status )
{
2013-07-03 21:52:19 +02:00
case JobStatus_Aborting :
case JobStatus_Starting :
case JobStatus_Pausing :
case JobStatus_Resuming :
2012-02-08 00:29:47 +01:00
break ;
default :
2013-11-14 02:29:18 +01:00
WinSevenTaskbar : : setTaskbarProgress ( this , ui - > progressBar - > value ( ) , ui - > progressBar - > maximum ( ) ) ;
2012-02-08 00:29:47 +01:00
break ;
}
WinSevenTaskbar : : setOverlayIcon ( this , icon . isNull ( ) ? NULL : & icon ) ;
}