2012-01-28 16:40:14 +01:00
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
2016-01-01 23:59:55 +01:00
// Copyright (C) 2004-2016 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"
2015-02-01 16:33:31 +01:00
# include "UIC_win_main.h"
2012-01-28 18:55:40 +01:00
2015-02-01 16:33:31 +01:00
//Internal
2013-11-14 02:29:18 +01:00
# include "global.h"
2014-02-01 19:19:06 +01:00
# include "cli.h"
2014-01-27 21:54:24 +01:00
# include "ipc.h"
2013-11-14 02:29:18 +01:00
# include "model_status.h"
2014-02-12 19:34:14 +01:00
# include "model_sysinfo.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"
2015-03-14 14:01:50 +01:00
# include "thread_binaries.h"
2013-08-07 15:34:02 +02:00
# include "thread_vapoursynth.h"
2013-07-03 21:52:19 +02:00
# include "thread_encode.h"
2015-02-01 21:05:17 +01:00
# include "thread_ipc_recv.h"
2014-04-20 17:38:55 +02:00
# include "input_filter.h"
2013-07-03 21:34:21 +02:00
# include "win_addJob.h"
2014-02-26 03:58:19 +01:00
# include "win_about.h"
2013-07-03 21:34:21 +02:00
# 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
2015-02-01 16:33:31 +01:00
//MUtils
# include <MUtils/OSSupport.h>
# include <MUtils/CPUFeatures.h>
2015-02-01 21:05:17 +01:00
# include <MUtils/IPCChannel.h>
2015-02-02 22:11:06 +01:00
# include <MUtils/GUI.h>
# include <MUtils/Sound.h>
# include <MUtils/Exception.h>
2015-02-08 21:14:21 +01:00
# include <MUtils/Taskbar7.h>
# include <MUtils/Version.h>
2015-02-01 16:33:31 +01:00
//Qt
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>
2014-05-14 17:13:42 +02:00
# include <QSystemTrayIcon>
2015-03-14 14:01:50 +01:00
# include <QMovie>
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
2014-05-03 15:11:29 +02:00
//Constants
2014-08-13 16:14:57 +02:00
static const char * tpl_last = " <LAST_USED> " ;
2014-05-03 15:11:29 +02:00
static const char * home_url = " http://muldersoft.com/ " ;
2014-04-20 19:40:59 +02:00
static const char * update_url = " https://github.com/lordmulder/Simple-x264-Launcher/releases/latest " ;
2014-05-03 15:11:29 +02:00
static const char * avs_dl_url = " http://sourceforge.net/projects/avisynth2/files/AviSynth%202.5/ " ;
static const char * python_url = " https://www.python.org/downloads/ " ;
2014-08-13 16:14:57 +02:00
static const char * vsynth_url = " http://www.vapoursynth.com/ " ;
static const int vsynth_rev = 24 ;
2012-01-30 17:50:19 +01:00
2014-05-03 15:11:29 +02:00
//Macros
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)
2014-05-03 15:11:29 +02:00
# define LINK(URL) (QString("<a href=\"%1\">%1< / a>").arg((URL)))
2014-05-18 21:59:26 +02:00
# define INIT_ERROR_EXIT() do { close(); qApp->exit(-1); return; } while(0)
2014-02-21 19:28:17 +01:00
# define SETUP_WEBLINK(OBJ, URL) do { (OBJ)->setData(QVariant(QUrl(URL))); connect((OBJ), SIGNAL(triggered()), this, SLOT(showWebLink())); } while(0)
2014-05-18 21:59:26 +02:00
# define APP_IS_READY (m_initialized && (!m_fileTimer->isActive()) && (QApplication::activeModalWidget() == NULL))
2015-12-20 13:59:42 +01:00
# define ENSURE_APP_IS_READY() do { if(!APP_IS_READY) { MUtils::Sound::beep(MUtils::Sound::BEEP_WRN); qWarning("Cannot perfrom this action at this time!"); return; } } while(0)
2015-02-02 22:11:06 +01:00
# define X264_STRCMP(X,Y) ((X).compare((Y), Qt::CaseInsensitive) == 0)
2014-02-21 19:28:17 +01:00
2012-01-28 16:40:14 +01:00
///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor
///////////////////////////////////////////////////////////////////////////////
2012-02-10 18:42:16 +01:00
/*
* Constructor
*/
2015-02-01 21:05:17 +01:00
MainWindow : : MainWindow ( const MUtils : : CPUFetaures : : cpu_info_t & cpuFeatures , MUtils : : IPCChannel * const ipcChannel )
2012-01-29 01:19:50 +01:00
:
2015-02-01 21:05:17 +01:00
m_ipcChannel ( ipcChannel ) ,
2014-02-12 19:34:14 +01:00
m_sysinfo ( NULL ) ,
2012-02-10 18:42:16 +01:00
m_options ( NULL ) ,
m_jobList ( NULL ) ,
2014-01-28 02:09:43 +01:00
m_pendingFiles ( new QStringList ( ) ) ,
2013-07-03 21:34:21 +02:00
m_preferences ( NULL ) ,
m_recentlyUsed ( NULL ) ,
2014-05-18 21:59:26 +02:00
m_initialized ( false ) ,
2013-11-14 02:29:18 +01:00
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
2014-02-12 19:34:14 +01:00
//Create and initialize the sysinfo object
2015-02-01 21:05:17 +01:00
m_sysinfo . reset ( new SysinfoModel ( ) ) ;
2014-02-12 19:34:14 +01:00
m_sysinfo - > setAppPath ( QApplication : : applicationDirPath ( ) ) ;
2015-02-28 17:12:35 +01:00
m_sysinfo - > setCPUFeatures ( SysinfoModel : : CPUFeatures_MMX , cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_MMX ) ;
m_sysinfo - > setCPUFeatures ( SysinfoModel : : CPUFeatures_SSE , cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_SSE ) ;
m_sysinfo - > setCPUFeatures ( SysinfoModel : : CPUFeatures_X64 , cpuFeatures . x64 & & ( cpuFeatures . features & MUtils : : CPUFetaures : : FLAG_SSE2 ) ) ; //X64 implies SSE2
2014-02-12 19:34:14 +01:00
2012-02-03 00:53:14 +01:00
//Load preferences
2015-02-01 21:05:17 +01:00
m_preferences . reset ( new PreferencesModel ( ) ) ;
PreferencesModel : : loadPreferences ( m_preferences . data ( ) ) ;
2012-02-03 00:53:14 +01:00
2013-05-08 22:46:25 +02:00
//Load recently used
2015-02-01 21:05:17 +01:00
m_recentlyUsed . reset ( new RecentlyUsed ( ) ) ;
RecentlyUsed : : loadRecentlyUsed ( m_recentlyUsed . data ( ) ) ;
2013-05-08 22:46:25 +02:00
2012-02-09 02:06:29 +01:00
//Create options object
2015-02-01 21:05:17 +01:00
m_options . reset ( new OptionsModel ( m_sysinfo . data ( ) ) ) ;
OptionsModel : : loadTemplate ( m_options . data ( ) , QString : : fromLatin1 ( tpl_last ) ) ;
2012-02-09 02:06:29 +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
2015-02-08 21:14:21 +01:00
ui - > labelBuildDate - > setText ( tr ( " Built on %1 at %2 " ) . arg ( MUtils : : Version : : app_build_date ( ) . toString ( Qt : : ISODate ) , MUtils : : Version : : app_build_time ( ) . toString ( Qt : : ISODate ) ) ) ;
2014-02-21 17:52:16 +01:00
2015-02-02 22:11:06 +01:00
if ( MUTILS_DEBUG )
2012-02-05 04:41:42 +01:00
{
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
2015-02-01 21:05:17 +01:00
m_jobList . reset ( new JobListModel ( m_preferences . data ( ) ) ) ;
connect ( m_jobList . data ( ) , SIGNAL ( dataChanged ( QModelIndex , QModelIndex ) ) , this , SLOT ( jobChangedData ( QModelIndex , QModelIndex ) ) ) ;
ui - > jobsView - > setModel ( m_jobList . data ( ) ) ;
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 ) ;
2015-10-24 18:28:45 +02:00
ui - > jobsView - > horizontalHeader ( ) - > setResizeMode ( 1 , QHeaderView : : ResizeToContents ) ;
ui - > jobsView - > horizontalHeader ( ) - > setResizeMode ( 2 , QHeaderView : : ResizeToContents ) ;
ui - > jobsView - > horizontalHeader ( ) - > setMinimumSectionSize ( 96 ) ;
2013-11-14 02:29:18 +01:00
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
2014-04-20 17:38:55 +02:00
//Setup key listener
2015-02-01 21:05:17 +01:00
m_inputFilter_jobList . reset ( new InputEventFilter ( ui - > jobsView ) ) ;
2014-04-20 17:38:55 +02:00
m_inputFilter_jobList - > addKeyFilter ( Qt : : ControlModifier | Qt : : Key_Up , 1 ) ;
m_inputFilter_jobList - > addKeyFilter ( Qt : : ControlModifier | Qt : : Key_Down , 2 ) ;
2015-02-01 21:05:17 +01:00
connect ( m_inputFilter_jobList . data ( ) , SIGNAL ( keyPressed ( int ) ) , this , SLOT ( jobListKeyPressed ( int ) ) ) ;
2014-04-20 17:38:55 +02:00
//Setup mouse listener
2015-02-01 21:05:17 +01:00
m_inputFilter_version . reset ( new InputEventFilter ( ui - > labelBuildDate ) ) ;
2014-04-20 17:38:55 +02:00
m_inputFilter_version - > addMouseFilter ( Qt : : LeftButton , 0 ) ;
m_inputFilter_version - > addMouseFilter ( Qt : : RightButton , 0 ) ;
2015-02-01 21:05:17 +01:00
connect ( m_inputFilter_version . data ( ) , SIGNAL ( mouseClicked ( int ) ) , this , SLOT ( versionLabelMouseClicked ( int ) ) ) ;
2014-04-20 17:38:55 +02: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 ) ;
2015-03-23 21:22:11 +01:00
QAction * actionSaveToLog = new QAction ( QIcon ( " :/buttons/disk.png " ) , tr ( " Save to File... " ) , ui - > logView ) ;
QAction * actionSeparator = new QAction ( ui - > logView ) ;
QAction * actionWordwraps = new QAction ( QIcon ( " :/buttons/text_wrapping.png " ) , tr ( " Enable Line-Wrapping " ) , ui - > logView ) ;
actionSeparator - > setSeparator ( true ) ;
actionWordwraps - > setCheckable ( true ) ;
2012-02-02 22:53:40 +01:00
actionClipboard - > setEnabled ( false ) ;
2015-03-23 21:22:11 +01:00
actionSaveToLog - > setEnabled ( false ) ;
actionWordwraps - > setEnabled ( false ) ;
2013-11-14 02:29:18 +01:00
ui - > logView - > addAction ( actionClipboard ) ;
2015-03-23 21:22:11 +01:00
ui - > logView - > addAction ( actionSaveToLog ) ;
ui - > logView - > addAction ( actionSeparator ) ;
ui - > logView - > addAction ( actionWordwraps ) ;
2012-01-31 00:13:32 +01:00
connect ( actionClipboard , SIGNAL ( triggered ( bool ) ) , this , SLOT ( copyLogToClipboard ( bool ) ) ) ;
2015-03-23 21:22:11 +01:00
connect ( actionSaveToLog , SIGNAL ( triggered ( bool ) ) , this , SLOT ( saveLogToLocalFile ( bool ) ) ) ;
connect ( actionWordwraps , SIGNAL ( triggered ( bool ) ) , this , SLOT ( toggleLineWrapping ( 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
2014-04-20 17:38:55 +02: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 ( ) ) ) ;
connect ( ui - > actionJob_MoveUp , SIGNAL ( triggered ( ) ) , this , SLOT ( moveButtonPressed ( ) ) ) ;
connect ( ui - > actionJob_MoveDown , SIGNAL ( triggered ( ) ) , this , SLOT ( moveButtonPressed ( ) ) ) ;
2012-01-28 23:24:41 +01:00
//Enable menu
2015-12-20 13:59:42 +01:00
connect ( ui - > actionOpen , SIGNAL ( triggered ( ) ) , this , SLOT ( openActionTriggered ( ) ) ) ;
connect ( ui - > actionCleanup_Finished , SIGNAL ( triggered ( ) ) , this , SLOT ( cleanupActionTriggered ( ) ) ) ;
connect ( ui - > actionCleanup_Enqueued , SIGNAL ( triggered ( ) ) , this , SLOT ( cleanupActionTriggered ( ) ) ) ;
connect ( ui - > actionAbout , SIGNAL ( triggered ( ) ) , this , SLOT ( showAbout ( ) ) ) ;
connect ( ui - > actionPreferences , SIGNAL ( triggered ( ) ) , this , SLOT ( showPreferences ( ) ) ) ;
connect ( ui - > actionCheckForUpdates , SIGNAL ( triggered ( ) ) , this , SLOT ( checkUpdates ( ) ) ) ;
ui - > actionCleanup_Finished - > setData ( QVariant ( bool ( 0 ) ) ) ;
ui - > actionCleanup_Enqueued - > setData ( QVariant ( bool ( 1 ) ) ) ;
2012-01-29 19:14:46 +01:00
2014-02-21 19:28:17 +01:00
//Setup web-links
SETUP_WEBLINK ( ui - > actionWebMulder , home_url ) ;
2014-04-11 14:44:01 +02:00
SETUP_WEBLINK ( ui - > actionWebX264 , " http://www.videolan.org/developers/x264.html " ) ;
SETUP_WEBLINK ( ui - > actionWebX265 , " http://www.videolan.org/developers/x265.html " ) ;
2016-06-12 14:31:31 +02:00
SETUP_WEBLINK ( ui - > actionWebX264Komisar , " http://komisar.gin.by/ " ) ;
SETUP_WEBLINK ( ui - > actionWebX264VideoLAN , " http://download.videolan.org/pub/x264/binaries/ " ) ;
SETUP_WEBLINK ( ui - > actionWebX264FreeCodecs , " http://www.free-codecs.com/x264_video_codec_download.htm " ) ;
SETUP_WEBLINK ( ui - > actionWebX265Fllear , " http://x265.ru/en/builds/ " ) ;
SETUP_WEBLINK ( ui - > actionWebX265LigH , " https://www.mediafire.com/?6lfp2jlygogwa " ) ;
SETUP_WEBLINK ( ui - > actionWebX265Snowfag , " http://builds.x265.eu/ " ) ;
SETUP_WEBLINK ( ui - > actionWebX265FreeCodecs , " http://www.free-codecs.com/x265_hevc_encoder_download.htm " ) ;
SETUP_WEBLINK ( ui - > actionWebAvisynth32 , " https://sourceforge.net/projects/avisynth2/files/AviSynth%202.6/ " ) ;
SETUP_WEBLINK ( ui - > actionWebAvisynth64 , " http://forum.doom9.org/showthread.php?t=152800 " ) ;
2014-02-21 19:28:17 +01:00
SETUP_WEBLINK ( ui - > actionWebAvisynthPlus , " http://www.avs-plus.net/ " ) ;
SETUP_WEBLINK ( ui - > actionWebVapourSynth , " http://www.vapoursynth.com/ " ) ;
SETUP_WEBLINK ( ui - > actionWebVapourSynthDocs , " http://www.vapoursynth.com/doc/ " ) ;
2015-03-14 14:01:50 +01:00
SETUP_WEBLINK ( ui - > actionOnlineDocX264 , " http://en.wikibooks.org/wiki/MeGUI/x264_Settings " ) ; //http://mewiki.project357.com/wiki/X264_Settings
2014-05-05 15:05:37 +02:00
SETUP_WEBLINK ( ui - > actionOnlineDocX265 , " http://x265.readthedocs.org/en/default/ " ) ;
2014-02-21 19:28:17 +01:00
SETUP_WEBLINK ( ui - > actionWebBluRay , " http://www.x264bluray.com/ " ) ;
SETUP_WEBLINK ( ui - > actionWebAvsWiki , " http://avisynth.nl/index.php/Main_Page#Usage " ) ;
SETUP_WEBLINK ( ui - > actionWebSupport , " http://forum.doom9.org/showthread.php?t=144140 " ) ;
SETUP_WEBLINK ( ui - > actionWebSecret , " http://www.youtube.com/watch_popup?v=AXIeHY-OYNI " ) ;
2012-01-31 00:13:32 +01:00
//Create floating label
2015-03-14 14:01:50 +01:00
m_label [ 0 ] . reset ( new QLabel ( ui - > jobsView - > viewport ( ) ) ) ;
m_label [ 1 ] . reset ( new QLabel ( ui - > logView - > viewport ( ) ) ) ;
if ( ! m_label [ 0 ] . isNull ( ) )
{
m_label [ 0 ] - > setText ( tr ( " No job created yet. Please click the 'Add New Job' button! " ) ) ;
m_label [ 0 ] - > setAlignment ( Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
SET_TEXT_COLOR ( m_label [ 0 ] , Qt : : darkGray ) ;
SET_FONT_BOLD ( m_label [ 0 ] , true ) ;
m_label [ 0 ] - > setVisible ( true ) ;
m_label [ 0 ] - > setContextMenuPolicy ( Qt : : ActionsContextMenu ) ;
m_label [ 0 ] - > addActions ( ui - > jobsView - > actions ( ) ) ;
}
if ( ! m_label [ 1 ] . isNull ( ) )
{
m_animation . reset ( new QMovie ( " :/images/spinner.gif " ) ) ;
m_label [ 1 ] - > setAlignment ( Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
if ( ! m_animation . isNull ( ) )
{
m_label [ 1 ] - > setMovie ( m_animation . data ( ) ) ;
m_animation - > start ( ) ;
}
}
2013-11-14 02:29:18 +01:00
connect ( ui - > splitter , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( updateLabelPos ( ) ) ) ;
2012-02-07 21:48:25 +01:00
updateLabelPos ( ) ;
2014-05-03 16:46:08 +02:00
2014-05-14 17:13:42 +02:00
//Init system tray icon
2015-02-01 21:05:17 +01:00
m_sysTray . reset ( new QSystemTrayIcon ( this ) ) ;
2014-05-14 17:13:42 +02:00
m_sysTray - > setToolTip ( this - > windowTitle ( ) ) ;
m_sysTray - > setIcon ( this - > windowIcon ( ) ) ;
2015-02-01 21:05:17 +01:00
connect ( m_sysTray . data ( ) , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) , this , SLOT ( sysTrayActived ( ) ) ) ;
2014-05-14 17:13:42 +02:00
2015-02-08 21:14:21 +01:00
//Init taskbar progress
m_taskbar . reset ( new MUtils : : Taskbar7 ( this ) ) ;
2014-05-03 16:46:08 +02:00
//Create corner widget
QLabel * checkUp = new QLabel ( ui - > menubar ) ;
checkUp - > setText ( QString ( " <nobr><img src= \" :/buttons/exclamation_small.png \" > <b style= \" color:darkred \" >%1</b> </nobr> " ) . arg ( tr ( " Check for Updates " ) ) ) ;
checkUp - > setFixedHeight ( ui - > menubar - > height ( ) ) ;
checkUp - > setCursor ( QCursor ( Qt : : PointingHandCursor ) ) ;
2015-02-01 21:05:17 +01:00
m_inputFilter_checkUp . reset ( new InputEventFilter ( checkUp ) ) ;
2014-05-03 16:46:08 +02:00
m_inputFilter_checkUp - > addMouseFilter ( Qt : : LeftButton , 0 ) ;
m_inputFilter_checkUp - > addMouseFilter ( Qt : : RightButton , 0 ) ;
2015-02-01 21:05:17 +01:00
connect ( m_inputFilter_checkUp . data ( ) , SIGNAL ( mouseClicked ( int ) ) , this , SLOT ( checkUpdates ( ) ) ) ;
2014-05-03 16:46:08 +02:00
checkUp - > hide ( ) ;
ui - > menubar - > setCornerWidget ( checkUp ) ;
2014-05-18 21:59:26 +02:00
//Create timer
2015-02-01 21:05:17 +01:00
m_fileTimer . reset ( new QTimer ( this ) ) ;
connect ( m_fileTimer . data ( ) , SIGNAL ( timeout ( ) ) , this , SLOT ( handlePendingFiles ( ) ) ) ;
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 )
{
2015-02-01 21:05:17 +01:00
OptionsModel : : saveTemplate ( m_options . data ( ) , QString : : fromLatin1 ( tpl_last ) ) ;
2012-02-09 02:06:29 +01:00
2015-02-01 21:05:17 +01:00
if ( ! m_ipcThread . isNull ( ) )
{
m_ipcThread - > stop ( ) ;
if ( ! m_ipcThread - > wait ( 5000 ) )
{
m_ipcThread - > terminate ( ) ;
m_ipcThread - > wait ( ) ;
}
}
2014-02-12 19:34:14 +01:00
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
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-01-28 02:09:43 +01:00
2012-02-10 18:42:16 +01:00
qDebug ( " MainWindow::addButtonPressed " ) ;
2014-02-14 00:01:00 +01:00
bool runImmediately = ( countRunningJobs ( ) < ( m_preferences - > getAutoRunNextJob ( ) ? m_preferences - > getMaxRunningJobCount ( ) : 1 ) ) ;
2013-05-08 00:04:40 +02:00
QString sourceFileName , outputFileName ;
2014-01-28 02:09:43 +01:00
2015-02-01 21:05:17 +01:00
if ( createJob ( sourceFileName , outputFileName , m_options . data ( ) , runImmediately ) )
2012-01-29 04:06:07 +01:00
{
2015-02-01 21:05:17 +01:00
appendJob ( sourceFileName , outputFileName , m_options . data ( ) , 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 ( )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2015-12-20 13:59:42 +01:00
qWarning ( " openActionTriggered() " ) ;
2014-01-28 02:09:43 +01:00
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
{
2014-02-14 00:01:00 +01:00
bool runImmediately = ( countRunningJobs ( ) < ( m_preferences - > getAutoRunNextJob ( ) ? m_preferences - > getMaxRunningJobCount ( ) : 1 ) ) ;
2013-05-11 01:50:05 +02:00
QString sourceFileName ( fileList . first ( ) ) , outputFileName ;
2015-02-01 21:05:17 +01:00
if ( createJob ( sourceFileName , outputFileName , m_options . data ( ) , runImmediately ) )
2013-05-11 01:50:05 +02:00
{
2015-02-01 21:05:17 +01:00
appendJob ( sourceFileName , outputFileName , m_options . data ( ) , runImmediately ) ;
2013-05-11 01:50:05 +02:00
}
}
}
}
2015-12-20 13:59:42 +01:00
/*
* The " clean-up " action was invoked
*/
void MainWindow : : cleanupActionTriggered ( void )
{
ENSURE_APP_IS_READY ( ) ;
QAction * const sender = dynamic_cast < QAction * > ( QObject : : sender ( ) ) ;
if ( sender )
{
const QVariant data = sender - > data ( ) ;
if ( data . isValid ( ) & & ( data . type ( ) = = QVariant : : Bool ) )
{
const bool mode = data . toBool ( ) ;
const int rows = m_jobList - > rowCount ( QModelIndex ( ) ) ;
QList < int > jobIndices ;
for ( int i = 0 ; i < rows ; i + + )
{
const JobStatus status = m_jobList - > getJobStatus ( m_jobList - > index ( i , 0 , QModelIndex ( ) ) ) ;
if ( mode & & ( status = = JobStatus_Enqueued ) )
{
jobIndices . append ( i ) ;
}
else if ( ( ! mode ) & & ( ( status = = JobStatus_Completed ) | | ( status = = JobStatus_Aborted ) | | ( status = = JobStatus_Failed ) ) )
{
jobIndices . append ( i ) ;
}
}
if ( ! jobIndices . isEmpty ( ) )
{
QListIterator < int > iter ( jobIndices ) ;
iter . toBack ( ) ;
while ( iter . hasPrevious ( ) )
{
m_jobList - > deleteJob ( m_jobList - > index ( iter . previous ( ) , 0 , QModelIndex ( ) ) ) ;
}
}
else
{
MUtils : : Sound : : beep ( MUtils : : Sound : : BEEP_WRN ) ;
}
}
}
}
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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-02-26 00:54:33 +01:00
if ( QMessageBox : : question ( this , tr ( " Abort Job? " ) , tr ( " <nobr>Do you really want to <b>abort</b> the selected job now?</nobr> " ) , tr ( " Back " ) , tr ( " Abort Job " ) ) = = 1 )
{
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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2013-11-14 02:29:18 +01:00
m_jobList - > deleteJob ( ui - > jobsView - > currentIndex ( ) ) ;
2015-03-14 14:01:50 +01:00
m_label [ 0 ] - > setVisible ( m_jobList - > rowCount ( QModelIndex ( ) ) = = 0 ) ;
2012-02-02 22:53:40 +01:00
}
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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-01-28 02:09:43 +01:00
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! " ) ) ;
}
}
2014-04-20 17:38:55 +02:00
/*
* The " browse " button was clicked
*/
void MainWindow : : moveButtonPressed ( void )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-04-20 17:38:55 +02:00
if ( sender ( ) = = ui - > actionJob_MoveUp )
{
qDebug ( " Move job %d (direction: UP) " , ui - > jobsView - > currentIndex ( ) . row ( ) ) ;
if ( ! m_jobList - > moveJob ( ui - > jobsView - > currentIndex ( ) , JobListModel : : MOVE_UP ) )
{
2015-02-02 22:11:06 +01:00
MUtils : : Sound : : beep ( MUtils : : Sound : : BEEP_ERR ) ;
2014-04-20 17:38:55 +02:00
}
ui - > jobsView - > scrollTo ( ui - > jobsView - > currentIndex ( ) , QAbstractItemView : : PositionAtCenter ) ;
}
else if ( sender ( ) = = ui - > actionJob_MoveDown )
{
qDebug ( " Move job %d (direction: DOWN) " , ui - > jobsView - > currentIndex ( ) . row ( ) ) ;
if ( ! m_jobList - > moveJob ( ui - > jobsView - > currentIndex ( ) , JobListModel : : MOVE_DOWN ) )
{
2015-02-02 22:11:06 +01:00
MUtils : : Sound : : beep ( MUtils : : Sound : : BEEP_ERR ) ;
2014-04-20 17:38:55 +02:00
}
ui - > jobsView - > scrollTo ( ui - > jobsView - > currentIndex ( ) , QAbstractItemView : : PositionAtCenter ) ;
}
else
{
qWarning ( " [moveButtonPressed] Error: Unknown sender! " ) ;
}
}
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 )
{
2014-05-18 21:59:26 +02:00
if ( ! APP_IS_READY )
2014-05-14 17:13:42 +02:00
{
2015-02-02 22:11:06 +01:00
MUtils : : Sound : : beep ( MUtils : : Sound : : BEEP_WRN ) ;
2014-05-14 17:13:42 +02:00
qWarning ( " Cannot perfrom this action at this time! " ) ;
ui - > buttonPauseJob - > setChecked ( ! checked ) ;
}
2014-01-29 16:23:55 +01:00
2012-02-02 02:13:02 +01:00
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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-01-28 02:09:43 +01:00
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
{
2014-02-14 00:01:00 +01:00
bool runImmediately = ( countRunningJobs ( ) < ( m_preferences - > getAutoRunNextJob ( ) ? m_preferences - > getMaxRunningJobCount ( ) : 1 ) ) ;
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 ) ;
}
2015-02-02 22:11:06 +01:00
MUTILS_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 ) ) ) ;
2015-03-23 21:22:11 +01:00
foreach ( QAction * action , ui - > logView - > actions ( ) )
{
action - > setEnabled ( true ) ;
}
2013-11-14 02:29:18 +01:00
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 ) ;
2015-03-23 21:22:11 +01:00
foreach ( QAction * action , ui - > logView - > actions ( ) )
{
action - > setEnabled ( false ) ;
}
2013-11-14 02:29:18 +01:00
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
{
2014-02-14 00:01:00 +01:00
if ( m_preferences - > getAutoRunNextJob ( ) ) QTimer : : singleShot ( 0 , this , SLOT ( launchNextJob ( ) ) ) ;
if ( m_preferences - > getSaveLogFiles ( ) ) 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 ( ) ) ) ) ;
2015-02-08 21:14:21 +01:00
if ( ! m_taskbar . isNull ( ) )
{
m_taskbar - > setTaskbarProgress ( 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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-01-28 02:09:43 +01:00
2014-02-26 15:34:56 +01:00
if ( AboutDialog * aboutDialog = new AboutDialog ( this ) )
2012-02-02 17:20:42 +01:00
{
2014-02-26 15:34:56 +01:00
aboutDialog - > exec ( ) ;
2015-02-02 22:11:06 +01:00
MUTILS_DELETE ( aboutDialog ) ;
2012-02-02 17:20:42 +01:00
}
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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-02-21 19:28:17 +01:00
if ( QObject * obj = QObject : : sender ( ) )
{
if ( QAction * action = dynamic_cast < QAction * > ( obj ) )
{
if ( action - > data ( ) . type ( ) = = QVariant : : Url )
{
QDesktopServices : : openUrl ( action - > data ( ) . toUrl ( ) ) ;
}
}
}
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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-01-28 02:09:43 +01:00
2015-02-01 21:05:17 +01:00
PreferencesDialog * preferences = new PreferencesDialog ( this , m_preferences . data ( ) , m_sysinfo . data ( ) ) ;
2012-02-03 00:53:14 +01:00
preferences - > exec ( ) ;
2014-01-28 02:09:43 +01:00
2015-02-02 22:11:06 +01:00
MUTILS_DELETE ( preferences ) ;
2012-02-03 00:53:14 +01:00
}
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 )
{
2014-04-20 19:40:59 +02:00
qDebug ( " Launching next job... " ) ;
2012-01-29 00:57:47 +01:00
2014-02-14 00:01:00 +01:00
if ( countRunningJobs ( ) > = m_preferences - > getMaxRunningJobCount ( ) )
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
}
2014-04-20 19:40:59 +02:00
const int rows = m_jobList - > rowCount ( QModelIndex ( ) ) ;
2012-02-04 01:12:21 +01:00
for ( int i = 0 ; i < rows ; i + + )
2012-01-29 00:57:47 +01:00
{
2014-04-20 19:40:59 +02:00
const QModelIndex currentIndex = m_jobList - > index ( i , 0 , QModelIndex ( ) ) ;
if ( m_jobList - > getJobStatus ( currentIndex ) = = JobStatus_Enqueued )
2012-01-29 00:57:47 +01:00
{
2014-04-20 19:40:59 +02:00
if ( m_jobList - > startJob ( currentIndex ) )
2012-02-03 00:53:14 +01:00
{
2014-04-20 19:40:59 +02:00
ui - > jobsView - > selectRow ( currentIndex . row ( ) ) ;
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
2014-04-20 19:40:59 +02:00
qWarning ( " No enqueued jobs left to be started! " ) ;
if ( m_preferences - > getShutdownComputer ( ) )
{
QTimer : : singleShot ( 0 , this , SLOT ( shutdownComputer ( ) ) ) ;
}
2012-02-04 01:12:21 +01:00
}
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 ( ' : ' , " - " ) ) ;
2015-03-23 22:05:58 +01:00
if ( ! log - > saveToLocalFile ( logFilePath ) )
2012-04-30 19:26:41 +02:00
{
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 )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2014-01-29 16:23:55 +01:00
2012-02-04 01:12:21 +01:00
if ( countPendingJobs ( ) > 0 )
{
qDebug ( " Still have pending jobs, won't shutdown yet! " ) ;
return ;
}
2014-01-29 16:23:55 +01:00
2012-02-04 01:12:21 +01:00
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 ) ;
2015-02-02 22:11:06 +01:00
MUtils : : Sound : : play_sound ( " shutdown " , 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 ( ) ;
2015-02-02 22:11:06 +01:00
MUtils : : Sound : : play_sound ( ( ( i < iTimeout ) ? " beep " : " beep2 " ) , false ) ;
2012-02-04 01:12:21 +01:00
}
qWarning ( " Shutting down !!! " ) ;
2015-02-02 22:11:06 +01:00
if ( MUtils : : OS : : shutdown_computer ( " Simple x264 Launcher: All jobs completed, shutting down! " , 10 , true , false ) )
2012-02-04 01:12:21 +01:00
{
qApp - > closeAllWindows ( ) ;
2012-01-29 00:57:47 +01:00
}
2014-01-29 16:23:55 +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 )
{
2014-05-18 21:59:26 +02:00
if ( m_initialized )
2014-01-28 02:09:43 +01:00
{
qWarning ( " Already initialized -> skipping! " ) ;
return ;
}
2012-02-07 21:48:25 +01:00
updateLabelPos ( ) ;
2015-02-01 16:33:31 +01:00
const MUtils : : OS : : ArgumentMap & arguments = MUtils : : OS : : arguments ( ) ;
2015-03-14 14:01:50 +01:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2014-04-20 20:47:43 +02:00
2014-02-21 17:52:16 +01:00
//---------------------------------------
// Check required binaries
//---------------------------------------
qDebug ( " [Validating binaries] " ) ;
2015-03-14 14:01:50 +01:00
if ( ! BinariesCheckThread : : check ( m_sysinfo . data ( ) ) )
2012-01-29 21:31:09 +01:00
{
2015-08-02 19:16:37 +02:00
QMessageBox : : critical ( this , tr ( " Invalid File! " ) , tr ( " <nobr>At least one tool is missing or is not a valid Win32/Win64 binary.<br>Please re-install the program in order to fix the problem!</nobr> " ) . replace ( " - " , " − " ) ) ;
qFatal ( " At least one tool is missing or is not a valid Win32/Win64 binary! " ) ;
2012-02-10 01:58:45 +01:00
}
2014-02-21 17:52:16 +01:00
qDebug ( " " ) ;
//---------------------------------------
// Check for portable mode
//---------------------------------------
2012-02-10 01:58:45 +01:00
2015-02-08 21:14:21 +01:00
if ( x264_is_portable ( ) )
2012-02-10 01:58:45 +01:00
{
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
}
2015-03-14 14:01:50 +01:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2014-02-21 17:52:16 +01:00
//---------------------------------------
// Check CPU capabilities
//---------------------------------------
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)
2015-02-28 17:12:35 +01:00
if ( ! m_sysinfo - > getCPUFeatures ( SysinfoModel : : CPUFeatures_MMX ) )
2012-02-07 21:48:25 +01:00
{
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
}
2015-02-28 17:12:35 +01:00
else if ( ! m_sysinfo - > getCPUFeatures ( SysinfoModel : : CPUFeatures_SSE ) )
2012-02-07 21:48:25 +01:00
{
2015-02-28 17:12:35 +01:00
qWarning ( " WARNING: System does not support SSE (v1), x264/x265 probably 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/x265 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!)
2015-02-01 16:33:31 +01:00
if ( arguments . contains ( CLI_PARAM_SKIP_VERSION_CHECK ) )
2013-07-07 16:11:47 +02:00
{
2015-01-05 20:53:01 +01:00
qWarning ( " Version checks are disabled now, you have been warned! \n " ) ;
2014-02-14 00:01:00 +01:00
m_preferences - > setSkipVersionTest ( true ) ;
2013-07-07 16:11:47 +02:00
}
2013-08-04 18:44:53 +02:00
//Don't abort encoding process on timeout (not recommended!)
2015-02-01 16:33:31 +01:00
if ( arguments . contains ( CLI_PARAM_NO_DEADLOCK ) )
2013-08-04 18:44:53 +02:00
{
qWarning ( " Deadlock detection disabled, you have been warned! \n " ) ;
2014-02-14 00:01:00 +01:00
m_preferences - > setAbortOnTimeout ( false ) ;
2013-08-04 18:44:53 +02:00
}
2015-03-14 14:01:50 +01:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2014-02-21 17:52:16 +01:00
//---------------------------------------
// Check Avisynth support
//---------------------------------------
2015-02-01 16:33:31 +01:00
if ( ! arguments . contains ( CLI_PARAM_SKIP_AVS_CHECK ) )
2012-01-30 17:50:19 +01:00
{
2012-04-30 16:56:01 +02:00
qDebug ( " [Check for Avisynth support] " ) ;
2015-03-01 22:00:05 +01:00
if ( ! AvisynthCheckThread : : detect ( m_sysinfo . data ( ) ) )
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
}
2015-03-01 22:00:05 +01:00
else if ( ( ! m_sysinfo - > hasAvisynth ( ) ) & & ( ! m_preferences - > getDisableWarnings ( ) ) )
2014-02-12 19:34:14 +01:00
{
2015-03-01 22:00:05 +01:00
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 ( avs_dl_url ) ) ;
int val = QMessageBox : : warning ( this , tr ( " Avisynth Missing " ) , QString ( " <nobr>%1</nobr> " ) . arg ( text ) . replace ( " - " , " − " ) , tr ( " Close " ) , tr ( " Disable this Warning " ) ) ;
if ( val = = 1 )
2013-08-08 23:18:31 +02:00
{
2015-03-01 22:00:05 +01:00
m_preferences - > setDisableWarnings ( true ) ;
PreferencesModel : : savePreferences ( m_preferences . data ( ) ) ;
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
2014-02-21 17:52:16 +01:00
//---------------------------------------
// Check VapurSynth support
//---------------------------------------
2015-02-01 16:33:31 +01:00
if ( ! arguments . contains ( CLI_PARAM_SKIP_VPS_CHECK ) )
2013-08-02 18:09:12 +02:00
{
2013-08-11 20:13:51 +02:00
qDebug ( " [Check for VapourSynth support] " ) ;
2015-03-01 22:00:05 +01:00
if ( ! VapourSynthCheckThread : : detect ( m_sysinfo . data ( ) ) )
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. " ) ;
2014-02-21 17:52:16 +01:00
const 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
}
2015-03-01 22:00:05 +01:00
else if ( ( ! m_sysinfo - > hasVapourSynth ( ) ) & & ( ! m_preferences - > getDisableWarnings ( ) ) )
2014-02-12 19:34:14 +01:00
{
2015-03-01 22:00:05 +01: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 (<b>r%1</b> or later) for Windows: " ) . arg ( QString : : number ( vsynth_rev ) ) . append ( " <br> " ) . append ( LINK ( vsynth_url ) ) . append ( " <br><br> " ) ;
text + = tr ( " Note that Python v3.4 is a prerequisite for installing VapourSynth: " ) . append ( " <br> " ) . append ( LINK ( python_url ) ) . append ( " <br> " ) ;
const int val = QMessageBox : : warning ( this , tr ( " VapourSynth Missing " ) , QString ( " <nobr>%1</nobr> " ) . arg ( text ) . replace ( " - " , " − " ) , tr ( " Close " ) , tr ( " Disable this Warning " ) ) ;
if ( val = = 1 )
2013-08-08 23:18:31 +02:00
{
2015-03-01 22:00:05 +01:00
m_preferences - > setDisableWarnings ( true ) ;
PreferencesModel : : savePreferences ( m_preferences . data ( ) ) ;
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
}
2015-02-01 21:05:17 +01:00
2015-03-14 14:01:50 +01:00
//---------------------------------------
// Create the IPC listener thread
//---------------------------------------
if ( m_ipcChannel )
{
m_ipcThread . reset ( new IPCThread_Recv ( m_ipcChannel ) ) ;
connect ( m_ipcThread . data ( ) , SIGNAL ( receivedCommand ( int , QStringList , quint32 ) ) , this , SLOT ( handleCommand ( int , QStringList , quint32 ) ) , Qt : : QueuedConnection ) ;
m_ipcThread - > start ( ) ;
}
2014-05-03 16:46:08 +02:00
//---------------------------------------
// Finish initialization
//---------------------------------------
//Set Window title
2015-02-28 17:12:35 +01:00
setWindowTitle ( QString ( " %1 (%2) " ) . arg ( windowTitle ( ) , m_sysinfo - > getCPUFeatures ( SysinfoModel : : CPUFeatures_X64 ) ? " 64-Bit " : " 32-Bit " ) ) ;
2014-05-03 16:46:08 +02:00
//Enable drag&drop support for this window, required for Qt v4.8.4+
setAcceptDrops ( true ) ;
2014-05-18 21:59:26 +02:00
//Update flag
m_initialized = true ;
2014-05-03 16:46:08 +02:00
2015-03-14 14:01:50 +01:00
//Hide the spinner animation
if ( ! m_label [ 1 ] . isNull ( ) )
{
if ( ! m_animation . isNull ( ) )
{
m_animation - > stop ( ) ;
}
m_label [ 1 ] - > setVisible ( false ) ;
}
2014-02-21 17:52:16 +01:00
//---------------------------------------
// Check for Expiration
//---------------------------------------
2013-12-14 22:30:19 +01:00
2015-02-08 21:14:21 +01:00
if ( MUtils : : Version : : app_build_date ( ) . addMonths ( 6 ) < MUtils : : OS : : current_date ( ) )
2012-02-02 02:13:02 +01:00
{
2014-05-03 16:46:08 +02:00
if ( QWidget * cornerWidget = ui - > menubar - > cornerWidget ( ) ) cornerWidget - > show ( ) ;
2013-12-14 22:30:19 +01:00
QString text ;
2014-04-20 20:47:43 +02:00
text + = QString ( " <nobr><tt>%1</tt></nobr><br><br> " ) . arg ( tr ( " Your version of Simple x264 Launcher is more than 6 months old! " ) . replace ( ' - ' , " − " ) ) ;
text + = QString ( " <nobr><tt>%1<br><a href= \" %2 \" >%3</a><br><br> " ) . arg ( tr ( " You can download the most recent version from the official web-site now: " ) . replace ( ' - ' , " − " ) , QString : : fromLatin1 ( update_url ) , QString : : fromLatin1 ( update_url ) . replace ( " - " , " − " ) ) ;
text + = QString ( " <nobr><tt>%1</tt></nobr><br> " ) . arg ( tr ( " Alternatively, click 'Check for Updates' to run the auto-update utility. " ) . replace ( ' - ' , " − " ) ) ;
2012-02-02 02:13:02 +01:00
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 ) ;
2013-12-14 22:30:19 +01:00
msgBox . setText ( text ) ;
QPushButton * btn1 = msgBox . addButton ( tr ( " Check for Updates " ) , QMessageBox : : AcceptRole ) ;
QPushButton * btn2 = msgBox . addButton ( tr ( " Discard " ) , QMessageBox : : NoRole ) ;
QPushButton * btn3 = msgBox . addButton ( btn2 - > text ( ) , QMessageBox : : RejectRole ) ;
btn2 - > setEnabled ( false ) ;
btn3 - > setVisible ( false ) ;
QTimer : : singleShot ( 7500 , btn2 , SLOT ( hide ( ) ) ) ;
QTimer : : singleShot ( 7500 , btn3 , SLOT ( show ( ) ) ) ;
if ( msgBox . exec ( ) = = 0 )
{
QTimer : : singleShot ( 0 , this , SLOT ( checkUpdates ( ) ) ) ;
return ;
}
}
2014-05-03 16:46:08 +02:00
else if ( ! parseCommandLineArgs ( ) )
2013-12-14 22:30:19 +01:00
{
2014-01-28 02:09:43 +01:00
//Update reminder
2015-02-01 16:33:31 +01:00
if ( arguments . contains ( CLI_PARAM_FIRST_RUN ) )
2014-04-20 20:47:43 +02:00
{
qWarning ( " First run -> resetting update check now! " ) ;
m_recentlyUsed - > setLastUpdateCheck ( 0 ) ;
2015-02-01 21:05:17 +01:00
RecentlyUsed : : saveRecentlyUsed ( m_recentlyUsed . data ( ) ) ;
2014-04-20 20:47:43 +02:00
}
2015-02-02 22:11:06 +01:00
else if ( m_recentlyUsed - > lastUpdateCheck ( ) + 14 < MUtils : : OS : : current_date ( ) . toJulianDay ( ) )
2013-12-14 22:30:19 +01:00
{
2014-05-03 16:46:08 +02:00
if ( QWidget * cornerWidget = ui - > menubar - > cornerWidget ( ) ) cornerWidget - > show ( ) ;
if ( ! m_preferences - > getNoUpdateReminder ( ) )
2014-01-28 02:09:43 +01:00
{
2014-05-03 16:46:08 +02:00
if ( QMessageBox : : warning ( this , tr ( " Update Notification " ) , QString ( " <nobr>%1</nobr> " ) . arg ( tr ( " Your last update check was more than 14 days ago. Check for updates now? " ) ) , tr ( " Check for Updates " ) , tr ( " Discard " ) ) = = 0 )
{
QTimer : : singleShot ( 0 , this , SLOT ( checkUpdates ( ) ) ) ;
return ;
}
2014-01-28 02:09:43 +01:00
}
2013-12-14 22:30:19 +01:00
}
2012-02-02 02:13:02 +01:00
}
2014-04-18 14:41:20 +02:00
//Load queued jobs
2015-02-01 21:05:17 +01:00
if ( m_jobList - > loadQueuedJobs ( m_sysinfo . data ( ) ) > 0 )
2014-04-18 14:41:20 +02:00
{
2015-03-14 14:01:50 +01:00
m_label [ 0 ] - > setVisible ( m_jobList - > rowCount ( QModelIndex ( ) ) = = 0 ) ;
2014-04-20 17:38:55 +02:00
m_jobList - > clearQueuedJobs ( ) ;
2014-04-18 14:41:20 +02:00
}
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
{
2015-03-14 14:01:50 +01:00
for ( int i = 0 ; i < 2 ; i + + )
{
//const QWidget *const viewPort = ui->jobsView->viewport();
const QWidget * const viewPort = dynamic_cast < QWidget * > ( m_label [ i ] - > parent ( ) ) ;
if ( viewPort )
{
m_label [ i ] - > 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 )
{
2014-04-20 20:47:43 +02:00
qDebug ( " Coyping logfile to clipboard... " ) ;
2012-01-31 00:13:32 +01:00
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 ( ) ;
2015-02-02 22:11:06 +01:00
MUtils : : Sound : : beep ( MUtils : : Sound : : BEEP_NFO ) ;
2012-01-31 00:13:32 +01:00
}
}
2015-03-23 21:22:11 +01:00
/*
* Save log to local file
*/
void MainWindow : : saveLogToLocalFile ( bool checked )
{
ENSURE_APP_IS_READY ( ) ;
const QModelIndex index = ui - > jobsView - > currentIndex ( ) ;
const QString initialName = index . isValid ( ) ? QFileInfo ( m_jobList - > getJobOutputFile ( index ) ) . completeBaseName ( ) : tr ( " Logfile " ) ;
const QString fileName = QFileDialog : : getSaveFileName ( this , tr ( " Save Log File " ) , initialName , tr ( " Log File (*.log) " ) ) ;
if ( ! fileName . isEmpty ( ) )
{
if ( LogFileModel * log = dynamic_cast < LogFileModel * > ( ui - > logView - > model ( ) ) )
{
if ( ! log - > saveToLocalFile ( fileName ) )
{
QMessageBox : : warning ( this , this - > windowTitle ( ) , tr ( " Error: Log file could not be saved! " ) ) ;
}
}
}
}
/*
* Toggle line - wrapping
*/
void MainWindow : : toggleLineWrapping ( bool checked )
{
ui - > logView - > setWordWrap ( checked ) ;
}
2012-02-10 18:42:16 +01:00
/*
* Process the dropped files
*/
2014-01-28 02:09:43 +01:00
void MainWindow : : handlePendingFiles ( void )
2012-02-10 18:42:16 +01:00
{
2014-05-18 21:59:26 +02:00
qDebug ( " MainWindow::handlePendingFiles " ) ;
if ( ! m_pendingFiles - > isEmpty ( ) )
2012-02-10 18:42:16 +01:00
{
2014-05-18 21:59:26 +02:00
QStringList pendingFiles ( * m_pendingFiles ) ;
m_pendingFiles - > clear ( ) ;
createJobMultiple ( pendingFiles ) ;
2012-02-10 18:42:16 +01:00
}
2014-05-18 21:59:26 +02:00
qDebug ( " Leave from MainWindow::handlePendingFiles! " ) ;
2012-02-10 18:42:16 +01:00
}
2014-04-20 19:40:59 +02:00
/*
* Handle incoming IPC command
*/
2014-02-01 15:34:11 +01:00
void MainWindow : : handleCommand ( const int & command , const QStringList & args , const quint32 & flags )
2012-02-21 00:37:31 +01:00
{
2014-05-18 21:59:26 +02:00
if ( ! ( m_initialized & & ( QApplication : : activeModalWidget ( ) = = NULL ) ) )
2014-01-28 02:09:43 +01:00
{
qWarning ( " Cannot accapt commands at this time -> discarding! " ) ;
2014-01-28 02:16:12 +01:00
return ;
2014-01-28 02:09:43 +01:00
}
2014-05-14 17:13:42 +02:00
if ( ( ! isVisible ( ) ) | | m_sysTray - > isVisible ( ) )
{
sysTrayActived ( ) ;
}
2015-02-02 22:11:06 +01:00
MUtils : : GUI : : bring_to_front ( this ) ;
2014-01-27 21:54:24 +01:00
2014-01-28 02:09:43 +01:00
# ifdef IPC_LOGGING
qDebug ( " \n ---------- IPC ---------- " ) ;
qDebug ( " CommandId: %d " , command ) ;
for ( QStringList : : ConstIterator iter = args . constBegin ( ) ; iter ! = args . constEnd ( ) ; iter + + )
2014-01-27 21:54:24 +01:00
{
2014-01-28 02:09:43 +01:00
qDebug ( " Arguments: %s " , iter - > toUtf8 ( ) . constData ( ) ) ;
2014-01-27 21:54:24 +01:00
}
2014-02-01 15:34:11 +01:00
qDebug ( " The Flags: 0x%08X " , flags ) ;
2014-01-28 02:09:43 +01:00
qDebug ( " ---------- IPC ---------- \n " ) ;
# endif //IPC_LOGGING
2014-01-27 21:54:24 +01:00
switch ( command )
{
2014-01-29 23:59:03 +01:00
case IPC_OPCODE_PING :
2014-01-27 21:54:24 +01:00
qDebug ( " Received a PING request from another instance! " ) ;
2015-02-02 22:11:06 +01:00
MUtils : : GUI : : blink_window ( this , 5 , 125 ) ;
2014-01-27 21:54:24 +01:00
break ;
2014-01-29 23:59:03 +01:00
case IPC_OPCODE_ADD_FILE :
2014-01-27 21:54:24 +01:00
if ( ! args . isEmpty ( ) )
{
if ( QFileInfo ( args [ 0 ] ) . exists ( ) & & QFileInfo ( args [ 0 ] ) . isFile ( ) )
{
2014-01-28 02:09:43 +01:00
* m_pendingFiles < < QFileInfo ( args [ 0 ] ) . canonicalFilePath ( ) ;
2014-05-18 21:59:26 +02:00
if ( ! m_fileTimer - > isActive ( ) )
2014-01-28 02:09:43 +01:00
{
2014-05-18 21:59:26 +02:00
m_fileTimer - > setSingleShot ( true ) ;
m_fileTimer - > start ( 5000 ) ;
2014-01-28 02:09:43 +01:00
}
2014-01-27 21:54:24 +01:00
}
else
{
qWarning ( " File '%s' not found! " , args [ 0 ] . toUtf8 ( ) . constData ( ) ) ;
}
}
break ;
2014-01-29 23:59:03 +01:00
case IPC_OPCODE_ADD_JOB :
2014-01-27 21:54:24 +01:00
if ( args . size ( ) > = 3 )
{
if ( QFileInfo ( args [ 0 ] ) . exists ( ) & & QFileInfo ( args [ 0 ] ) . isFile ( ) )
{
2015-02-01 21:05:17 +01:00
OptionsModel options ( m_sysinfo . data ( ) ) ;
2014-02-14 00:01:00 +01:00
bool runImmediately = ( countRunningJobs ( ) < ( m_preferences - > getAutoRunNextJob ( ) ? m_preferences - > getMaxRunningJobCount ( ) : 1 ) ) ;
2014-01-27 21:54:24 +01:00
if ( ! ( args [ 2 ] . isEmpty ( ) | | X264_STRCMP ( args [ 2 ] , " - " ) ) )
{
if ( ! OptionsModel : : loadTemplate ( & options , args [ 2 ] . trimmed ( ) ) )
{
qWarning ( " Template '%s' could not be found -> using defaults! " , args [ 2 ] . trimmed ( ) . toUtf8 ( ) . constData ( ) ) ;
}
}
2014-02-01 15:34:11 +01:00
if ( ( flags & IPC_FLAG_FORCE_START ) & & ( ! ( flags & IPC_FLAG_FORCE_ENQUEUE ) ) ) runImmediately = true ;
if ( ( flags & IPC_FLAG_FORCE_ENQUEUE ) & & ( ! ( flags & IPC_FLAG_FORCE_START ) ) ) runImmediately = false ;
appendJob ( args [ 0 ] , args [ 1 ] , & options , runImmediately ) ;
2014-01-27 21:54:24 +01:00
}
else
{
qWarning ( " Source file '%s' not found! " , args [ 0 ] . toUtf8 ( ) . constData ( ) ) ;
}
}
break ;
default :
2015-02-02 22:11:06 +01:00
MUTILS_THROW ( " Unknown command received! " ) ;
2014-01-27 21:54:24 +01:00
}
2012-02-21 00:37:31 +01:00
}
2014-04-20 19:40:59 +02:00
/*
* Check for new updates
*/
2013-11-22 17:01:13 +01:00
void MainWindow : : checkUpdates ( void )
{
2014-05-18 21:59:26 +02:00
ENSURE_APP_IS_READY ( ) ;
2013-11-22 17:01:13 +01:00
if ( countRunningJobs ( ) > 0 )
{
QMessageBox : : warning ( this , tr ( " Jobs Are Running " ) , tr ( " Sorry, can not update while there still are running jobs! " ) ) ;
return ;
}
2015-02-01 21:05:17 +01:00
UpdaterDialog * updater = new UpdaterDialog ( this , m_sysinfo . data ( ) , update_url ) ;
2013-12-11 15:50:26 +01:00
const int ret = updater - > exec ( ) ;
2013-12-14 22:30:19 +01:00
if ( updater - > getSuccess ( ) )
{
2015-02-02 22:11:06 +01:00
m_recentlyUsed - > setLastUpdateCheck ( MUtils : : OS : : current_date ( ) . toJulianDay ( ) ) ;
2015-02-01 21:05:17 +01:00
RecentlyUsed : : saveRecentlyUsed ( m_recentlyUsed . data ( ) ) ;
2014-05-03 16:46:08 +02:00
if ( QWidget * cornerWidget = ui - > menubar - > cornerWidget ( ) ) cornerWidget - > hide ( ) ;
2013-12-14 22:30:19 +01:00
}
if ( ret = = UpdaterDialog : : READY_TO_INSTALL_UPDATE )
2013-12-11 15:50:26 +01:00
{
2013-12-14 22:30:19 +01:00
qWarning ( " Exitting program to install update... " ) ;
2013-12-11 15:50:26 +01:00
close ( ) ;
2013-12-13 15:25:36 +01:00
QApplication : : quit ( ) ;
2013-12-11 15:50:26 +01:00
}
2015-02-02 22:11:06 +01:00
MUTILS_DELETE ( updater ) ;
2013-11-22 17:01:13 +01:00
}
2014-04-20 19:40:59 +02:00
/*
* Handle mouse event for version label
*/
2014-04-20 17:38:55 +02:00
void MainWindow : : versionLabelMouseClicked ( const int & tag )
{
if ( tag = = 0 )
{
QTimer : : singleShot ( 0 , this , SLOT ( showAbout ( ) ) ) ;
}
}
2014-04-20 19:40:59 +02:00
/*
* Handle key event for job list
*/
2014-04-20 17:38:55 +02:00
void MainWindow : : jobListKeyPressed ( const int & tag )
{
switch ( tag )
{
case 1 :
ui - > actionJob_MoveUp - > trigger ( ) ;
break ;
case 2 :
ui - > actionJob_MoveDown - > trigger ( ) ;
break ;
}
}
2014-05-14 17:13:42 +02:00
/*
* System tray was activated
*/
void MainWindow : : sysTrayActived ( void )
{
m_sysTray - > hide ( ) ;
showNormal ( ) ;
2015-02-02 22:11:06 +01:00
MUtils : : GUI : : bring_to_front ( this ) ;
2014-05-14 17:13:42 +02:00
}
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 ) ;
2014-05-18 21:59:26 +02:00
if ( ! m_initialized )
2012-01-29 21:31:09 +01:00
{
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
{
2014-05-18 21:59:26 +02:00
if ( ! APP_IS_READY )
2013-11-08 17:39:16 +01:00
{
2014-01-29 23:59:03 +01:00
e - > ignore ( ) ;
2014-01-28 02:09:43 +01:00
qWarning ( " Cannot close window at this time! " ) ;
2013-11-08 17:39:16 +01:00
return ;
}
2014-04-18 14:41:20 +02:00
//Make sure we have no running jobs left!
2014-05-18 21:59:26 +02:00
if ( countRunningJobs ( ) > 0 )
2012-01-29 15:57:23 +01:00
{
2014-05-18 21:59:26 +02:00
e - > ignore ( ) ;
if ( ! m_preferences - > getNoSystrayWarning ( ) )
2012-02-02 22:53:40 +01:00
{
2014-05-18 21:59:26 +02:00
if ( QMessageBox : : warning ( this , tr ( " Jobs Are Running " ) , tr ( " <nobr>You still have running jobs, application will be minimized to notification area!<nobr> " ) , tr ( " OK " ) , tr ( " Don't Show Again " ) ) = = 1 )
2014-05-14 17:13:42 +02:00
{
2014-05-18 21:59:26 +02:00
m_preferences - > setNoSystrayWarning ( true ) ;
2015-02-01 21:05:17 +01:00
PreferencesModel : : savePreferences ( m_preferences . data ( ) ) ;
2014-05-14 17:13:42 +02:00
}
2012-02-02 22:53:40 +01:00
}
2014-05-18 21:59:26 +02:00
hide ( ) ;
m_sysTray - > show ( ) ;
return ;
}
2014-04-18 14:41:20 +02:00
2014-05-18 21:59:26 +02:00
//Save pending jobs for next time, if desired by user
if ( countPendingJobs ( ) > 0 )
{
int ret = QMessageBox : : question ( this , tr ( " Jobs Are Pending " ) , tr ( " You still have pending jobs. How do you want to proceed? " ) , tr ( " Save Pending Jobs " ) , tr ( " Discard " ) ) ;
if ( ret = = 0 )
2014-01-28 02:09:43 +01:00
{
2014-05-18 21:59:26 +02:00
m_jobList - > saveQueuedJobs ( ) ;
}
else
{
if ( QMessageBox : : warning ( this , tr ( " Jobs Are Pending " ) , tr ( " Do you really want to discard all pending jobs? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ! = QMessageBox : : Yes )
2014-04-18 14:41:20 +02:00
{
2014-05-18 21:59:26 +02:00
e - > ignore ( ) ;
return ;
2014-01-28 02:09:43 +01:00
}
}
2012-02-02 22:53:40 +01:00
}
2014-04-18 14:41:20 +02:00
//Delete remaining jobs
2012-02-02 22:53:40 +01:00
while ( m_jobList - > rowCount ( QModelIndex ( ) ) > 0 )
{
2014-04-18 14:41:20 +02:00
if ( ( m_jobList - > rowCount ( QModelIndex ( ) ) % 10 ) = = 0 )
{
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
}
2012-02-02 22:53:40 +01:00
if ( ! m_jobList - > deleteJob ( m_jobList - > index ( 0 , 0 , QModelIndex ( ) ) ) )
{
e - > ignore ( ) ;
2014-04-18 14:41:20 +02:00
QMessageBox : : warning ( this , tr ( " Failed To Exit " ) , tr ( " Warning: At least one job could not be deleted! " ) ) ;
2012-02-02 22:53:40 +01:00
}
}
2014-01-29 16:23:55 +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-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 )
{
2014-05-18 21:59:26 +02:00
if ( ! ( m_initialized & & ( QApplication : : activeModalWidget ( ) = = NULL ) ) )
2014-01-28 02:16:12 +01:00
{
2014-04-22 01:59:12 +02:00
qWarning ( " Cannot accept dropped files at this time -> discarding! " ) ;
2014-01-28 02:16:12 +01:00
return ;
}
2012-02-02 13:52:52 +01:00
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
{
2014-01-28 02:09:43 +01:00
m_pendingFiles - > append ( droppedFiles ) ;
m_pendingFiles - > sort ( ) ;
2014-05-18 21:59:26 +02:00
if ( ! m_fileTimer - > isActive ( ) )
2014-01-28 02:16:12 +01:00
{
2014-05-18 21:59:26 +02:00
m_fileTimer - > setSingleShot ( true ) ;
m_fileTimer - > start ( 5000 ) ;
2014-01-28 02:16:12 +01:00
}
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 ;
2015-02-01 21:05:17 +01:00
AddJobDialog * addDialog = new AddJobDialog ( this , options , m_recentlyUsed . data ( ) , m_sysinfo . data ( ) , m_preferences . data ( ) ) ;
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 ;
}
2015-02-02 22:11:06 +01:00
MUTILS_DELETE ( addDialog ) ;
2013-05-08 00:04:40 +02:00
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
{
2014-02-14 00:01:00 +01:00
runImmediately = ( countRunningJobs ( ) < ( m_preferences - > getAutoRunNextJob ( ) ? m_preferences - > getMaxRunningJobCount ( ) : 1 ) ) ;
2013-05-11 01:50:05 +02:00
QString sourceFileName ( * iter ) , outputFileName ;
2015-02-01 21:05:17 +01:00
if ( createJob ( sourceFileName , outputFileName , m_options . data ( ) , runImmediately , false , counter + + , filePathIn . count ( ) , & applyToAll ) )
2013-05-11 01:50:05 +02:00
{
2015-02-01 21:05:17 +01:00
if ( appendJob ( sourceFileName , outputFileName , m_options . data ( ) , runImmediately ) )
2013-05-11 01:50:05 +02:00
{
continue ;
}
}
return false ;
}
//Add remaining files
while ( applyToAll & & ( iter ! = filePathIn . constEnd ( ) ) )
{
2014-02-14 00:01:00 +01:00
const bool runImmediatelyTmp = runImmediately & & ( countRunningJobs ( ) < ( m_preferences - > getAutoRunNextJob ( ) ? m_preferences - > getMaxRunningJobCount ( ) : 1 ) ) ;
2013-05-11 01:50:05 +02:00
const QString sourceFileName = * iter ;
2014-02-14 00:01:00 +01:00
const QString outputFileName = AddJobDialog : : generateOutputFileName ( sourceFileName , m_recentlyUsed - > outputDirectory ( ) , m_recentlyUsed - > filterIndex ( ) , m_preferences - > getSaveToSourcePath ( ) ) ;
2015-02-01 21:05:17 +01:00
if ( ! appendJob ( sourceFileName , outputFileName , m_options . data ( ) , runImmediatelyTmp ) )
2013-05-11 01:50:05 +02:00
{
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 ;
2015-02-01 21:05:17 +01:00
EncodeThread * thrd = new EncodeThread ( sourceFileName , outputFileName , options , m_sysinfo . data ( ) , m_preferences . data ( ) ) ;
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 ;
}
2015-03-14 14:01:50 +01:00
m_label [ 0 ] - > setVisible ( m_jobList - > rowCount ( QModelIndex ( ) ) = = 0 ) ;
2013-05-08 00:04:40 +02:00
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 ) ;
2014-04-20 17:38:55 +02:00
ui - > actionJob_MoveUp - > setEnabled ( status ! = JobStatus_Undefined ) ;
ui - > actionJob_MoveDown - > setEnabled ( status ! = JobStatus_Undefined ) ;
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) " ) ;
2015-02-08 21:14:21 +01:00
if ( m_taskbar . isNull ( ) )
{
return ; /*taskbar object not created yet*/
}
2012-02-08 00:29:47 +01:00
switch ( status )
{
2013-07-03 21:52:19 +02:00
case JobStatus_Undefined :
2015-02-08 21:14:21 +01:00
m_taskbar - > setTaskbarState ( MUtils : : Taskbar7 : : TASKBAR_STATE_NONE ) ;
2012-02-08 00:29:47 +01:00
break ;
2013-07-03 21:52:19 +02:00
case JobStatus_Aborting :
case JobStatus_Starting :
case JobStatus_Pausing :
case JobStatus_Resuming :
2015-02-08 21:14:21 +01:00
m_taskbar - > setTaskbarState ( MUtils : : Taskbar7 : : TASKBAR_STATE_INTERMEDIATE ) ;
2012-02-08 00:29:47 +01:00
break ;
2013-07-03 21:52:19 +02:00
case JobStatus_Aborted :
case JobStatus_Failed :
2015-02-08 21:14:21 +01:00
m_taskbar - > setTaskbarState ( MUtils : : Taskbar7 : : TASKBAR_STATE_ERROR ) ;
2012-02-08 00:29:47 +01:00
break ;
2013-07-03 21:52:19 +02:00
case JobStatus_Paused :
2015-02-08 21:14:21 +01:00
m_taskbar - > setTaskbarState ( MUtils : : Taskbar7 : : TASKBAR_STATE_PAUSED ) ;
2012-02-08 00:29:47 +01:00
break ;
default :
2015-02-08 21:14:21 +01:00
m_taskbar - > setTaskbarState ( MUtils : : Taskbar7 : : TASKBAR_STATE_NORMAL ) ;
2012-02-08 00:29:47 +01:00
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 :
2015-02-08 21:14:21 +01:00
m_taskbar - > setTaskbarProgress ( ui - > progressBar - > value ( ) , ui - > progressBar - > maximum ( ) ) ;
2012-02-08 00:29:47 +01:00
break ;
}
2015-02-08 21:14:21 +01:00
m_taskbar - > setOverlayIcon ( icon . isNull ( ) ? NULL : & icon ) ;
2012-02-08 00:29:47 +01:00
}
2014-01-20 22:02:53 +01:00
/*
* Parse command - line arguments
*/
2014-01-28 02:09:43 +01:00
bool MainWindow : : parseCommandLineArgs ( void )
2014-01-20 22:02:53 +01:00
{
2015-02-01 16:33:31 +01:00
const MUtils : : OS : : ArgumentMap & args = MUtils : : OS : : arguments ( ) ;
quint32 flags = 0 ;
bool commandSent = false ;
2014-01-27 20:34:59 +01:00
2015-02-01 16:33:31 +01:00
//Handle flags
if ( args . contains ( CLI_PARAM_FORCE_START ) )
{
flags = ( ( flags | IPC_FLAG_FORCE_START ) & ( ~ IPC_FLAG_FORCE_ENQUEUE ) ) ;
}
if ( args . contains ( CLI_PARAM_FORCE_ENQUEUE ) )
{
flags = ( ( flags | IPC_FLAG_FORCE_ENQUEUE ) & ( ~ IPC_FLAG_FORCE_START ) ) ;
}
2014-02-01 19:19:06 +01:00
//Process all command-line arguments
2015-02-01 16:33:31 +01:00
if ( args . contains ( CLI_PARAM_ADD_FILE ) )
{
foreach ( const QString & fileName , args . values ( CLI_PARAM_ADD_FILE ) )
{
handleCommand ( IPC_OPCODE_ADD_FILE , QStringList ( ) < < fileName , flags ) ;
}
commandSent = true ;
}
if ( args . contains ( CLI_PARAM_ADD_JOB ) )
2014-01-20 22:02:53 +01:00
{
2015-02-01 16:33:31 +01:00
foreach ( const QString & options , args . values ( CLI_PARAM_ADD_JOB ) )
2014-01-20 22:02:53 +01:00
{
2015-02-01 16:33:31 +01:00
const QStringList optionValues = options . split ( ' | ' , QString : : SkipEmptyParts ) ;
if ( optionValues . count ( ) = = 3 )
{
handleCommand ( IPC_OPCODE_ADD_JOB , optionValues , flags ) ;
}
else
{
qWarning ( " Invalid number of arguments for parameter \" --%s \" detected! " , CLI_PARAM_ADD_JOB ) ;
}
2014-01-20 22:02:53 +01:00
}
2015-02-01 16:33:31 +01:00
commandSent = true ;
2014-01-20 22:02:53 +01:00
}
2014-01-28 02:09:43 +01:00
2015-02-01 16:33:31 +01:00
return commandSent ;
2014-01-20 22:02:53 +01:00
}