2012-01-28 16:40:14 +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_main.h"
2012-01-28 18:55:40 +01:00
2012-01-28 16:40:14 +01:00
# include "global.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"
2012-01-29 04:06:07 +01:00
# include "win_addJob.h"
2012-02-03 00:53:14 +01:00
# include "win_preferences.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-01-29 15:57:23 +01:00
2012-02-04 01:12:21 +01:00
# include <Mmsystem.h>
2012-01-28 16:40:14 +01:00
2012-02-02 22:53:40 +01:00
const char * home_url = " http://mulder.brhack.net/ " ;
2012-01-30 17:50:19 +01:00
2012-01-31 00:13:32 +01:00
# define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
# define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); }
2012-01-28 16:40:14 +01:00
///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor
///////////////////////////////////////////////////////////////////////////////
2012-01-29 01:19:50 +01:00
MainWindow : : MainWindow ( bool x64supported )
:
2012-01-29 21:31:09 +01:00
m_x64supported ( x64supported ) ,
m_appDir ( QApplication : : applicationDirPath ( ) ) ,
m_firstShow ( true )
2012-01-28 16:40:14 +01:00
{
//Init the dialog, from the .ui file
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 " ) ;
qRegisterMetaType < EncodeThread : : JobStatus > ( " EncodeThread::JobStatus " ) ;
2012-02-03 00:53:14 +01:00
//Load preferences
memset ( & m_preferences , 0 , sizeof ( PreferencesDialog : : Preferences ) ) ;
PreferencesDialog : : loadPreferences ( & m_preferences ) ;
2012-01-28 18:55:40 +01:00
//Freeze minimum size
setMinimumSize ( size ( ) ) ;
2012-01-31 00:13:32 +01:00
splitter - > setSizes ( QList < int > ( ) < < 16 < < 196 ) ;
2012-01-28 18:55:40 +01:00
2012-01-29 01:19:50 +01:00
//Update title
2012-01-29 21:31:09 +01:00
labelBuildDate - > setText ( tr ( " Built on %1 at %2 " ) . arg ( x264_version_date ( ) . toString ( Qt : : ISODate ) , QString : : fromLatin1 ( x264_version_time ( ) ) ) ) ;
2012-01-31 20:28:40 +01:00
labelBuildDate - > installEventFilter ( this ) ;
2012-01-30 17:50:19 +01:00
setWindowTitle ( QString ( " %1 (%2 Mode) " ) . arg ( windowTitle ( ) , m_x64supported ? " 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
m_jobList = new JobListModel ( ) ;
2012-01-28 23:24:41 +01:00
connect ( m_jobList , SIGNAL ( dataChanged ( QModelIndex , QModelIndex ) ) , this , SLOT ( jobChangedData ( QModelIndex , QModelIndex ) ) ) ;
2012-01-28 18:55:40 +01:00
jobsView - > setModel ( m_jobList ) ;
2012-01-31 00:13:32 +01:00
2012-01-28 18:55:40 +01:00
//Setup view
2012-01-28 23:24:41 +01:00
jobsView - > horizontalHeader ( ) - > setSectionHidden ( 3 , true ) ;
2012-01-28 18:55:40 +01:00
jobsView - > horizontalHeader ( ) - > setResizeMode ( 0 , QHeaderView : : Stretch ) ;
jobsView - > horizontalHeader ( ) - > setResizeMode ( 1 , QHeaderView : : Fixed ) ;
jobsView - > horizontalHeader ( ) - > setResizeMode ( 2 , QHeaderView : : Fixed ) ;
jobsView - > horizontalHeader ( ) - > resizeSection ( 1 , 150 ) ;
jobsView - > horizontalHeader ( ) - > resizeSection ( 2 , 90 ) ;
jobsView - > verticalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
2012-01-28 19:59:04 +01:00
connect ( 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
QAction * actionClipboard = new QAction ( QIcon ( " :/buttons/page_paste.png " ) , tr ( " Copy to Clipboard " ) , logView ) ;
2012-02-02 22:53:40 +01:00
actionClipboard - > setEnabled ( false ) ;
2012-01-31 00:13:32 +01:00
logView - > addAction ( actionClipboard ) ;
connect ( actionClipboard , SIGNAL ( triggered ( bool ) ) , this , SLOT ( copyLogToClipboard ( bool ) ) ) ;
jobsView - > addActions ( menuJob - > actions ( ) ) ;
2012-01-28 18:55:40 +01:00
//Enable buttons
connect ( buttonAddJob , SIGNAL ( clicked ( ) ) , this , SLOT ( addButtonPressed ( ) ) ) ;
2012-01-28 23:24:41 +01:00
connect ( buttonStartJob , SIGNAL ( clicked ( ) ) , this , SLOT ( startButtonPressed ( ) ) ) ;
connect ( buttonAbortJob , SIGNAL ( clicked ( ) ) , this , SLOT ( abortButtonPressed ( ) ) ) ;
2012-02-02 02:13:02 +01:00
connect ( buttonPauseJob , SIGNAL ( toggled ( bool ) ) , this , SLOT ( pauseButtonPressed ( bool ) ) ) ;
2012-02-02 22:53:40 +01:00
connect ( actionJob_Delete , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteButtonPressed ( ) ) ) ;
connect ( actionJob_Browse , SIGNAL ( triggered ( ) ) , this , SLOT ( browseButtonPressed ( ) ) ) ;
2012-01-28 23:24:41 +01:00
//Enable menu
connect ( actionAbout , SIGNAL ( triggered ( ) ) , this , SLOT ( showAbout ( ) ) ) ;
2012-01-29 15:57:23 +01:00
connect ( actionWebMulder , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( actionWebX264 , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( actionWebKomisar , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( actionWebJarod , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
connect ( actionWebWiki , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
2012-01-30 17:50:19 +01:00
connect ( actionWebBluRay , SIGNAL ( triggered ( ) ) , this , SLOT ( showWebLink ( ) ) ) ;
2012-02-03 00:53:14 +01:00
connect ( actionPreferences , SIGNAL ( triggered ( ) ) , this , SLOT ( showPreferences ( ) ) ) ;
2012-01-29 19:14:46 +01:00
2012-01-31 00:13:32 +01:00
//Create floating label
m_label = new QLabel ( jobsView ) ;
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 ) ;
m_label - > addActions ( jobsView - > actions ( ) ) ;
connect ( splitter , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( updateLabel ( ) ) ) ;
updateLabel ( ) ;
2012-01-29 19:14:46 +01:00
//Create options object
m_options = new OptionsModel ( ) ;
2012-01-28 16:40:14 +01:00
}
MainWindow : : ~ MainWindow ( void )
{
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-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-01-28 16:40:14 +01:00
}
2012-01-28 18:55:40 +01:00
///////////////////////////////////////////////////////////////////////////////
// Slots
///////////////////////////////////////////////////////////////////////////////
2012-02-04 15:56:38 +01:00
void MainWindow : : addButtonPressed ( const QString & filePath , int fileNo , int fileTotal , bool * ok )
2012-01-28 18:55:40 +01:00
{
2012-02-02 18:55:55 +01:00
if ( ok ) * ok = false ;
2012-02-03 12:31:51 +01:00
AddJobDialog * addDialog = new AddJobDialog ( this , m_options , m_x64supported ) ;
2012-02-04 01:12:21 +01:00
addDialog - > setRunImmediately ( countRunningJobs ( ) < ( m_preferences . autoRunNextJob ? m_preferences . maxRunningJobCount : 1 ) ) ;
2012-02-04 15:56:38 +01:00
if ( ( fileNo > = 0 ) & & ( fileTotal > 1 ) ) addDialog - > setWindowTitle ( addDialog - > windowTitle ( ) . append ( tr ( " (File %1 of %2) " ) . arg ( QString : : number ( fileNo + 1 ) , QString : : number ( fileTotal ) ) ) ) ;
2012-02-02 13:52:52 +01:00
if ( ! filePath . isEmpty ( ) ) addDialog - > setSourceFile ( filePath ) ;
2012-02-04 01:12:21 +01:00
2012-01-29 04:06:07 +01:00
int result = addDialog - > exec ( ) ;
if ( result = = QDialog : : Accepted )
{
2012-01-29 15:57:23 +01:00
EncodeThread * thrd = new EncodeThread
(
addDialog - > sourceFile ( ) ,
2012-01-29 19:14:46 +01:00
addDialog - > outputFile ( ) ,
2012-01-29 21:31:09 +01:00
m_options ,
2012-01-30 17:50:19 +01:00
QString ( " %1/toolset " ) . arg ( m_appDir ) ,
2012-02-05 02:49:08 +01:00
m_x64supported ,
m_x64supported & & m_preferences . useAvisyth64Bit
2012-01-29 15:57:23 +01:00
) ;
2012-01-29 04:06:07 +01:00
QModelIndex newIndex = m_jobList - > insertJob ( thrd ) ;
2012-01-29 15:57:23 +01:00
2012-02-02 18:55:55 +01:00
if ( newIndex . isValid ( ) )
2012-01-29 15:57:23 +01:00
{
2012-02-02 18:55:55 +01:00
if ( addDialog - > runImmediately ( ) )
{
jobsView - > selectRow ( newIndex . row ( ) ) ;
QApplication : : processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
m_jobList - > startJob ( newIndex ) ;
}
2012-01-31 00:13:32 +01:00
2012-02-02 18:55:55 +01:00
if ( ok ) * ok = true ;
}
2012-01-29 04:06:07 +01:00
}
2012-02-02 22:53:40 +01:00
m_label - > setVisible ( m_jobList - > rowCount ( QModelIndex ( ) ) = = 0 ) ;
2012-01-29 04:06:07 +01:00
X264_DELETE ( addDialog ) ;
2012-01-28 23:24:41 +01:00
}
2012-01-28 19:59:04 +01:00
2012-01-28 23:24:41 +01:00
void MainWindow : : startButtonPressed ( void )
{
m_jobList - > startJob ( jobsView - > currentIndex ( ) ) ;
2012-01-28 19:59:04 +01:00
}
2012-01-28 23:24:41 +01:00
void MainWindow : : abortButtonPressed ( void )
{
m_jobList - > abortJob ( jobsView - > currentIndex ( ) ) ;
}
2012-01-29 00:57:47 +01:00
2012-02-02 22:53:40 +01:00
void MainWindow : : deleteButtonPressed ( void )
{
m_jobList - > deleteJob ( jobsView - > currentIndex ( ) ) ;
m_label - > setVisible ( m_jobList - > rowCount ( QModelIndex ( ) ) = = 0 ) ;
}
void MainWindow : : browseButtonPressed ( void )
{
QString outputFile = m_jobList - > getJobOutputFile ( jobsView - > currentIndex ( ) ) ;
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-02 02:13:02 +01:00
void MainWindow : : pauseButtonPressed ( bool checked )
{
if ( checked )
{
m_jobList - > pauseJob ( jobsView - > currentIndex ( ) ) ;
}
else
{
m_jobList - > resumeJob ( jobsView - > currentIndex ( ) ) ;
}
}
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
if ( logView - > model ( ) )
{
disconnect ( logView - > model ( ) , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( jobLogExtended ( QModelIndex , int , int ) ) ) ;
}
2012-02-02 22:53:40 +01:00
if ( current . isValid ( ) )
{
logView - > setModel ( m_jobList - > getLogFile ( current ) ) ;
connect ( logView - > model ( ) , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( jobLogExtended ( QModelIndex , int , int ) ) ) ;
logView - > actions ( ) . first ( ) - > setEnabled ( true ) ;
QTimer : : singleShot ( 0 , logView , SLOT ( scrollToBottom ( ) ) ) ;
2012-01-28 23:24:41 +01:00
2012-02-02 22:53:40 +01:00
progressBar - > setValue ( m_jobList - > getJobProgress ( current ) ) ;
editDetails - > setText ( m_jobList - > data ( m_jobList - > index ( current . row ( ) , 3 , QModelIndex ( ) ) , Qt : : DisplayRole ) . toString ( ) ) ;
updateButtons ( m_jobList - > getJobStatus ( current ) ) ;
}
else
{
logView - > setModel ( NULL ) ;
logView - > actions ( ) . first ( ) - > setEnabled ( false ) ;
progressBar - > setValue ( 0 ) ;
editDetails - > clear ( ) ;
updateButtons ( EncodeThread : : JobStatus_Undefined ) ;
}
2012-01-31 00:13:32 +01:00
progressBar - > repaint ( ) ;
2012-01-28 23:24:41 +01:00
}
void MainWindow : : jobChangedData ( const QModelIndex & topLeft , const QModelIndex & bottomRight )
{
int selected = jobsView - > currentIndex ( ) . row ( ) ;
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 + + )
{
2012-02-04 01:12:21 +01:00
EncodeThread : : 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-04 01:12:21 +01:00
if ( ( status = = EncodeThread : : JobStatus_Completed ) | | ( status = = EncodeThread : : JobStatus_Failed ) )
2012-01-29 00:57:47 +01:00
{
2012-02-04 01:12:21 +01:00
if ( m_preferences . autoRunNextJob ) QTimer : : singleShot ( 0 , this , SLOT ( launchNextJob ( ) ) ) ;
if ( m_preferences . shutdownComputer ) QTimer : : singleShot ( 0 , this , SLOT ( shutdownComputer ( ) ) ) ;
2012-01-28 23:24:41 +01:00
}
}
}
2012-02-03 15:28:00 +01:00
else 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 )
{
progressBar - > setValue ( m_jobList - > getJobProgress ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) ) ) ;
break ;
}
}
}
2012-02-03 15:28:00 +01:00
else 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 )
{
editDetails - > setText ( m_jobList - > data ( m_jobList - > index ( i , 3 , QModelIndex ( ) ) , Qt : : DisplayRole ) . toString ( ) ) ;
break ;
}
}
}
}
void MainWindow : : jobLogExtended ( const QModelIndex & parent , int start , int end )
{
QTimer : : singleShot ( 0 , logView , SLOT ( scrollToBottom ( ) ) ) ;
}
void MainWindow : : showAbout ( void )
{
QString text ;
2012-01-29 00:57:47 +01:00
text + = QString ( ) . sprintf ( " <nobr><tt>Simple x264 Launcher v%u.%02u - use 64-Bit x264 with 32-Bit Avisynth<br> " , x264_version_major ( ) , x264_version_minor ( ) ) ;
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-02 17:20:42 +01:00
forever
{
2012-02-04 01:12:21 +01:00
int ret = QMessageBox : : information ( this , tr ( " About... " ) , text . replace ( " - " , " − " ) , tr ( " About x264 " ) , tr ( " About Qt " ) , tr ( " Close " ) , 0 , 2 ) ;
2012-02-02 17:20:42 +01:00
switch ( ret )
{
case 0 :
{
QString text2 ;
2012-02-02 22:53:40 +01:00
text2 + = tr ( " <nobr><tt>x264 - the best H.264/AVC encoder. Copyright (c) 2003-2012 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-02 22:53:40 +01:00
text2 + = tr ( " Please visit <a href= \" %1 \" >%1</a> for obtaining a <u>commercial</u> x264 license!<br></tt></nobr> " ) . arg ( " http://x264licensing.com/ " ) ;
2012-02-02 17:20:42 +01:00
QMessageBox : : information ( this , tr ( " About x264 " ) , text2 . replace ( " - " , " − " ) , tr ( " Close " ) ) ;
}
break ;
case 1 :
QMessageBox : : aboutQt ( this ) ;
break ;
default :
return ;
}
}
2012-01-29 00:57:47 +01:00
}
2012-01-29 15:57:23 +01:00
void MainWindow : : showWebLink ( void )
{
if ( QObject : : sender ( ) = = actionWebMulder ) QDesktopServices : : openUrl ( QUrl ( home_url ) ) ;
if ( QObject : : sender ( ) = = actionWebX264 ) QDesktopServices : : openUrl ( QUrl ( " http://www.x264.com/ " ) ) ;
if ( QObject : : sender ( ) = = actionWebKomisar ) QDesktopServices : : openUrl ( QUrl ( " http://komisar.gin.by/ " ) ) ;
if ( QObject : : sender ( ) = = actionWebJarod ) QDesktopServices : : openUrl ( QUrl ( " http://www.x264.nl/ " ) ) ;
if ( QObject : : sender ( ) = = actionWebWiki ) QDesktopServices : : openUrl ( QUrl ( " http://mewiki.project357.com/wiki/X264_Settings " ) ) ;
2012-01-30 17:50:19 +01:00
if ( QObject : : sender ( ) = = actionWebBluRay ) QDesktopServices : : openUrl ( QUrl ( " http://www.x264bluray.com/ " ) ) ;
2012-01-29 15:57:23 +01:00
}
2012-02-03 00:53:14 +01:00
void MainWindow : : showPreferences ( void )
{
2012-02-05 02:49:08 +01:00
PreferencesDialog * preferences = new PreferencesDialog ( this , & m_preferences , m_x64supported ) ;
2012-02-03 00:53:14 +01:00
preferences - > exec ( ) ;
X264_DELETE ( preferences ) ;
}
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 ( ) ) ;
2012-02-04 01:12:21 +01: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
}
2012-02-04 01:12:21 +01:00
int startIdx = jobsView - > currentIndex ( ) . isValid ( ) ? qBound ( 0 , jobsView - > currentIndex ( ) . row ( ) , rows - 1 ) : 0 ;
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 ;
EncodeThread : : JobStatus status = m_jobList - > getJobStatus ( m_jobList - > index ( currentIdx , 0 , QModelIndex ( ) ) ) ;
if ( status = = EncodeThread : : 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
{
2012-02-04 01:12:21 +01:00
jobsView - > selectRow ( currentIdx ) ;
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! " ) ;
}
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 ) ;
PlaySound ( MAKEINTRESOURCE ( IDR_WAVE1 ) , GetModuleHandle ( NULL ) , SND_RESOURCE | SND_SYNC ) ;
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 ( ) ;
PlaySound ( MAKEINTRESOURCE ( ( i < iTimeout ) ? IDR_WAVE2 : IDR_WAVE3 ) , GetModuleHandle ( NULL ) , SND_RESOURCE | SND_SYNC ) ;
}
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-01-29 21:31:09 +01:00
void MainWindow : : init ( void )
{
2012-02-05 02:49:08 +01:00
static const char * binFiles = " x264.exe:x264_x64.exe:avs2yuv.exe: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
updateLabel ( ) ;
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 ) )
{
2012-02-02 04:12:58 +01:00
bool binaryTypeOkay = false ;
DWORD binaryType ;
if ( GetBinaryType ( QWCHAR ( file - > fileName ( ) ) , & binaryType ) )
{
binaryTypeOkay = ( binaryType = = SCS_32BIT_BINARY | | binaryType = = SCS_64BIT_BINARY ) ;
}
if ( ! binaryTypeOkay )
{
2012-02-02 13:52:52 +01:00
QMessageBox : : critical ( this , tr ( " Invalid File! " ) , tr ( " <nobr>At least on required tool is not a valid Win32 or Win64 binary:<br>%1<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 ( ) ) ;
close ( ) ; qApp - > exit ( - 1 ) ; return ;
}
2012-01-29 21:31:09 +01:00
m_toolsList < < file ;
}
else
{
X264_DELETE ( file ) ;
QMessageBox : : critical ( this , tr ( " File Not Found! " ) , tr ( " <nobr>At least on required tool could not be found:<br>%1<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 ( " - " , " − " ) ) ;
qFatal ( QString ( " Binary not found: %1/toolset/%2 " ) . arg ( m_appDir , current ) . toLatin1 ( ) . constData ( ) ) ;
2012-01-30 17:50:19 +01:00
close ( ) ; qApp - > exit ( - 1 ) ; return ;
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 ) ;
if ( rnd ! = val ) { close ( ) ; qApp - > exit ( - 1 ) ; return ; }
}
//Check for Avisynth support
bool avsAvailable = false ;
QLibrary * avsLib = new QLibrary ( " avisynth.dll " ) ;
if ( avsLib - > load ( ) )
{
avsAvailable = ( avsLib - > resolve ( " avs_create_script_environment " ) ! = NULL ) ;
}
if ( ! avsAvailable )
{
avsLib - > unload ( ) ; X264_DELETE ( avsLib ) ;
int val = QMessageBox : : warning ( this , tr ( " Avisynth Missing " ) , tr ( " <nobr>It appears that Avisynth is not currently installed on your computer.<br>Thus Avisynth input will not be working at all!<br><br>Please download and install Avisynth:<br><a href= \" http://sourceforge.net/projects/avisynth2/files/AviSynth%202.5/ \" >http://sourceforge.net/projects/avisynth2/files/AviSynth 2.5/</a></nobr> " ) . replace ( " - " , " − " ) , tr ( " Quit " ) , tr ( " Ignore " ) ) ;
if ( val ! = 1 ) { close ( ) ; qApp - > exit ( - 1 ) ; return ; }
}
2012-02-02 02:13:02 +01:00
//Check for expiration
if ( x264_version_date ( ) . addMonths ( 6 ) < QDate : : currentDate ( ) )
{
QMessageBox msgBox ( this ) ;
msgBox . setIcon ( QMessageBox : : Information ) ;
msgBox . setWindowTitle ( tr ( " Update Notification " ) ) ;
msgBox . setWindowFlags ( Qt : : Window | Qt : : WindowTitleHint | Qt : : CustomizeWindowHint ) ;
msgBox . setText ( tr ( " <nobr><tt>Oups, this version of 'Simple x264 Launcher' is more than 6 months old.<br><br>Please check the official web-site at <a href= \" %1 \" >%1</a> for updates!<br></tt></nobr> " ) . replace ( " - " , " − " ) . arg ( home_url ) ) ;
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 ;
}
if ( QFileInfo ( current ) . exists ( ) & & QFileInfo ( current ) . isFile ( ) )
{
files < < QFileInfo ( current ) . canonicalFilePath ( ) ;
}
}
if ( int totalFiles = files . count ( ) )
{
bool ok = true ; int n = 0 ;
while ( ( ! files . isEmpty ( ) ) & & ok )
{
QString currentFile = files . takeFirst ( ) ;
qDebug ( " Adding file: %s " , currentFile . toUtf8 ( ) . constData ( ) ) ;
addButtonPressed ( currentFile , n + + , totalFiles , & ok ) ;
}
}
2012-01-29 21:31:09 +01:00
}
2012-01-31 00:13:32 +01:00
void MainWindow : : updateLabel ( void )
{
m_label - > setGeometry ( 0 , 0 , jobsView - > width ( ) , jobsView - > height ( ) ) ;
}
void MainWindow : : copyLogToClipboard ( bool checked )
{
qDebug ( " copyLogToClipboard " ) ;
if ( LogFileModel * log = dynamic_cast < LogFileModel * > ( logView - > model ( ) ) )
{
log - > copyToClipboard ( ) ;
MessageBeep ( MB_ICONINFORMATION ) ;
}
}
2012-01-28 23:24:41 +01:00
///////////////////////////////////////////////////////////////////////////////
// Event functions
///////////////////////////////////////////////////////////////////////////////
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-01-28 23:24:41 +01:00
void MainWindow : : closeEvent ( QCloseEvent * e )
2012-01-29 15:57:23 +01:00
{
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-01-31 00:13:32 +01:00
void MainWindow : : resizeEvent ( QResizeEvent * e )
{
QMainWindow : : resizeEvent ( e ) ;
updateLabel ( ) ;
}
2012-01-31 20:28:40 +01:00
bool MainWindow : : eventFilter ( QObject * o , QEvent * e )
{
if ( ( o = = labelBuildDate ) & & ( e - > type ( ) = = QEvent : : MouseButtonPress ) )
{
QTimer : : singleShot ( 0 , this , SLOT ( showAbout ( ) ) ) ;
return true ;
}
return false ;
}
2012-02-02 13:52:52 +01:00
/*
* File dragged over window
*/
void MainWindow : : 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 ( ) ;
}
}
/*
* 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 ( ) )
{
qDebug ( " Dropped File: %s " , file . canonicalFilePath ( ) . toUtf8 ( ) . constData ( ) ) ;
droppedFiles < < file . canonicalFilePath ( ) ;
}
}
droppedFiles . sort ( ) ;
2012-02-04 15:56:38 +01:00
int totalFiles = droppedFiles . count ( ) ;
2012-02-02 18:55:55 +01:00
2012-02-04 15:56:38 +01:00
bool ok = true ; int n = 0 ;
2012-02-02 18:55:55 +01:00
while ( ( ! droppedFiles . isEmpty ( ) ) & & ok )
2012-02-02 13:52:52 +01:00
{
QString currentFile = droppedFiles . takeFirst ( ) ;
qDebug ( " Adding file: %s " , currentFile . toUtf8 ( ) . constData ( ) ) ;
2012-02-04 15:56:38 +01:00
addButtonPressed ( currentFile , n + + , totalFiles , & ok ) ;
2012-02-02 13:52:52 +01:00
}
}
2012-01-29 15:57:23 +01:00
///////////////////////////////////////////////////////////////////////////////
// Private functions
///////////////////////////////////////////////////////////////////////////////
2012-02-02 22:53:40 +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 + + )
{
EncodeThread : : JobStatus status = m_jobList - > getJobStatus ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) ) ;
if ( status ! = EncodeThread : : JobStatus_Completed & & status ! = EncodeThread : : JobStatus_Aborted & & status ! = EncodeThread : : JobStatus_Failed )
{
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-02 22:53:40 +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 + + )
{
EncodeThread : : JobStatus status = m_jobList - > getJobStatus ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) ) ;
if ( status ! = EncodeThread : : JobStatus_Completed & & status ! = EncodeThread : : JobStatus_Aborted & & status ! = EncodeThread : : JobStatus_Failed & & status ! = EncodeThread : : JobStatus_Enqueued )
{
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-01-28 23:24:41 +01:00
void MainWindow : : updateButtons ( EncodeThread : : JobStatus status )
{
qDebug ( " MainWindow::updateButtons(void) " ) ;
buttonStartJob - > setEnabled ( status = = EncodeThread : : JobStatus_Enqueued ) ;
2012-02-02 02:13:02 +01:00
buttonAbortJob - > setEnabled ( status = = EncodeThread : : JobStatus_Indexing | | status = = EncodeThread : : JobStatus_Running | | status = = EncodeThread : : JobStatus_Running_Pass1 | | status = = EncodeThread : : JobStatus_Running_Pass2 | | status = = EncodeThread : : JobStatus_Paused ) ;
buttonPauseJob - > setEnabled ( status = = EncodeThread : : JobStatus_Indexing | | status = = EncodeThread : : JobStatus_Running | | status = = EncodeThread : : JobStatus_Paused | | status = = EncodeThread : : JobStatus_Running_Pass1 | | status = = EncodeThread : : JobStatus_Running_Pass2 ) ;
buttonPauseJob - > setChecked ( status = = EncodeThread : : JobStatus_Paused | | status = = EncodeThread : : JobStatus_Pausing ) ;
2012-01-31 00:13:32 +01:00
2012-02-02 22:53:40 +01:00
actionJob_Delete - > setEnabled ( status = = EncodeThread : : JobStatus_Completed | | status = = EncodeThread : : JobStatus_Aborted | | status = = EncodeThread : : JobStatus_Failed | | status = = EncodeThread : : JobStatus_Enqueued ) ;
actionJob_Browse - > setEnabled ( status = = EncodeThread : : JobStatus_Completed ) ;
2012-01-31 00:13:32 +01:00
actionJob_Start - > setEnabled ( buttonStartJob - > isEnabled ( ) ) ;
actionJob_Abort - > setEnabled ( buttonAbortJob - > isEnabled ( ) ) ;
2012-02-02 02:13:02 +01:00
actionJob_Pause - > setEnabled ( buttonPauseJob - > isEnabled ( ) ) ;
actionJob_Pause - > setChecked ( buttonPauseJob - > isChecked ( ) ) ;
editDetails - > setEnabled ( status ! = EncodeThread : : JobStatus_Paused ) ;
2012-01-28 18:55:40 +01:00
}