2010-11-17 19:35:50 +01:00
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
2013-02-08 23:50:51 +01:00
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
2010-11-17 19:35:50 +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 "Dialog_Processing.h"
2012-12-08 00:21:10 +01:00
//UIC includes
# include "../tmp/UIC_ProcessingDialog.h"
2010-11-17 19:35:50 +01:00
# include "Global.h"
2010-11-26 00:29:53 +01:00
# include "Resource.h"
2010-11-19 21:11:54 +01:00
# include "Model_FileList.h"
2010-11-18 00:32:46 +01:00
# include "Model_Progress.h"
2010-11-20 02:14:22 +01:00
# include "Model_Settings.h"
2010-11-18 00:32:46 +01:00
# include "Thread_Process.h"
2011-10-29 16:26:09 +02:00
# include "Thread_CPUObserver.h"
# include "Thread_RAMObserver.h"
2011-03-28 04:26:47 +02:00
# include "Thread_DiskObserver.h"
2010-11-22 21:45:00 +01:00
# include "Dialog_LogView.h"
2013-01-18 01:08:58 +01:00
# include "Registry_Decoder.h"
2013-10-02 16:39:26 +02:00
# include "Registry_Encoder.h"
2011-08-05 21:52:43 +02:00
# include "Filter_Downmix.h"
2011-01-25 23:12:56 +01:00
# include "Filter_Normalize.h"
2011-01-26 20:16:46 +01:00
# include "Filter_Resample.h"
# include "Filter_ToneAdjust.h"
2010-12-05 23:11:03 +01:00
# include "WinSevenTaskbar.h"
2010-11-17 19:35:50 +01:00
# include <QApplication>
# include <QRect>
# include <QDesktopWidget>
# include <QMovie>
2010-11-18 00:32:46 +01:00
# include <QMessageBox>
# include <QTimer>
# include <QCloseEvent>
# include <QDesktopServices>
# include <QUrl>
2010-11-20 22:14:10 +01:00
# include <QUuid>
# include <QFileInfo>
2010-11-21 21:51:22 +01:00
# include <QDir>
2010-11-24 21:00:59 +01:00
# include <QMenu>
2010-12-10 22:17:44 +01:00
# include <QSystemTrayIcon>
2011-02-11 23:16:11 +01:00
# include <QProcess>
2011-03-18 01:12:17 +01:00
# include <QProgressDialog>
2012-11-15 18:06:04 +01:00
# include <QResizeEvent>
2011-11-28 00:35:43 +01:00
# include <QTime>
2013-10-09 03:14:38 +02:00
# include <QThreadPool>
2010-11-20 22:14:10 +01:00
2011-11-26 02:47:48 +01:00
# include <math.h>
2011-11-26 17:25:33 +01:00
# include <float.h>
2010-11-18 00:32:46 +01:00
2011-02-14 19:03:36 +01:00
////////////////////////////////////////////////////////////
2011-02-28 01:28:27 +01:00
//Maximum number of parallel instances
2011-11-08 15:12:31 +01:00
# define MAX_INSTANCES 16U
2011-02-28 01:28:27 +01:00
2011-11-26 15:30:24 +01:00
//Function to calculate the number of instances
static int cores2instances ( int cores ) ;
2011-11-26 02:47:48 +01:00
2011-02-28 01:28:27 +01:00
////////////////////////////////////////////////////////////
2012-07-29 19:09:15 +02:00
# define CHANGE_BACKGROUND_COLOR(WIDGET, COLOR) do \
2010-12-02 23:26:30 +01:00
{ \
QPalette palette = WIDGET - > palette ( ) ; \
palette . setColor ( QPalette : : Background , COLOR ) ; \
WIDGET - > setPalette ( palette ) ; \
2012-07-29 19:09:15 +02:00
} \
while ( 0 )
2010-12-02 23:26:30 +01:00
2012-07-29 19:09:15 +02:00
# define SET_PROGRESS_TEXT(TXT) do \
2010-12-10 22:17:44 +01:00
{ \
2012-12-08 00:21:10 +01:00
ui - > label_progress - > setText ( TXT ) ; \
2010-12-10 22:17:44 +01:00
m_systemTray - > setToolTip ( QString ( ) . sprintf ( " LameXP v%d.%02d \n %ls " , lamexp_version_major ( ) , lamexp_version_minor ( ) , QString ( TXT ) . utf16 ( ) ) ) ; \
2012-07-29 19:09:15 +02:00
} \
while ( 0 )
2010-12-10 22:17:44 +01:00
2012-07-29 19:09:15 +02:00
# define SET_FONT_BOLD(WIDGET,BOLD) do \
{ \
QFont _font = WIDGET - > font ( ) ; \
_font . setBold ( BOLD ) ; WIDGET - > setFont ( _font ) ; \
} \
while ( 0 )
2012-11-15 18:06:04 +01:00
# 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 )
2012-07-29 19:09:15 +02:00
# define UPDATE_MIN_WIDTH(WIDGET) do \
{ \
if ( WIDGET - > width ( ) > WIDGET - > minimumWidth ( ) ) WIDGET - > setMinimumWidth ( WIDGET - > width ( ) ) ; \
} \
while ( 0 )
2011-02-14 19:03:36 +01:00
2013-07-07 23:49:29 +02:00
# define IS_VBR(RC_MODE) ((RC_MODE) == SettingsModel::VBRMode)
2012-11-17 19:26:55 +01:00
////////////////////////////////////////////////////////////
//Dummy class for UserData
class IntUserData : public QObjectUserData
{
public :
IntUserData ( int value ) : m_value ( value ) { /*NOP*/ }
int value ( void ) { return m_value ; }
void setValue ( int value ) { m_value = value ; }
private :
int m_value ;
} ;
2010-11-18 00:32:46 +01:00
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
2010-11-17 19:35:50 +01:00
2013-10-13 00:21:37 +02:00
ProcessingDialog : : ProcessingDialog ( FileListModel * fileListModel , const AudioFileModel_MetaInfo * metaInfo , SettingsModel * settings , QWidget * parent )
2010-11-20 02:14:22 +01:00
:
2010-11-20 19:16:04 +01:00
QDialog ( parent ) ,
2012-12-08 00:21:10 +01:00
ui ( new Ui : : ProcessingDialog ) ,
2010-12-12 19:25:06 +01:00
m_systemTray ( new QSystemTrayIcon ( QIcon ( " :/icons/cd_go.png " ) , this ) ) ,
2010-11-20 19:16:04 +01:00
m_settings ( settings ) ,
2011-03-18 01:12:17 +01:00
m_metaInfo ( metaInfo ) ,
2011-10-22 01:13:28 +02:00
m_shutdownFlag ( shutdownFlag_None ) ,
2013-10-09 03:14:38 +02:00
m_threadPool ( NULL ) ,
2011-10-29 16:26:09 +02:00
m_diskObserver ( NULL ) ,
m_cpuObserver ( NULL ) ,
2012-04-11 00:44:40 +02:00
m_ramObserver ( NULL ) ,
2012-11-11 18:33:55 +01:00
m_progressViewFilter ( - 1 ) ,
2012-04-11 00:44:40 +02:00
m_firstShow ( true )
2010-11-17 19:35:50 +01:00
{
//Init the dialog, from the .ui file
2012-12-08 00:21:10 +01:00
ui - > setupUi ( this ) ;
2010-11-17 19:35:50 +01:00
setWindowFlags ( windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ) ;
2010-11-18 22:37:35 +01:00
2011-12-24 20:04:49 +01:00
//Update header icon
2012-12-08 00:21:10 +01:00
ui - > label_headerIcon - > setPixmap ( lamexp_app_icon ( ) . pixmap ( ui - > label_headerIcon - > size ( ) ) ) ;
2011-12-24 20:04:49 +01:00
2010-11-18 22:37:35 +01:00
//Setup version info
2012-12-08 00:21:10 +01:00
ui - > label_versionInfo - > setText ( QString ( ) . sprintf ( " v%d.%02d %s (Build %d) " , lamexp_version_major ( ) , lamexp_version_minor ( ) , lamexp_version_release ( ) , lamexp_version_build ( ) ) ) ;
ui - > label_versionInfo - > installEventFilter ( this ) ;
2010-11-17 19:35:50 +01:00
2010-11-18 22:37:35 +01:00
//Register meta type
qRegisterMetaType < QUuid > ( " QUuid " ) ;
2010-11-17 19:35:50 +01:00
//Center window in screen
QRect desktopRect = QApplication : : desktop ( ) - > screenGeometry ( ) ;
QRect thisRect = this - > geometry ( ) ;
move ( ( desktopRect . width ( ) - thisRect . width ( ) ) / 2 , ( desktopRect . height ( ) - thisRect . height ( ) ) / 2 ) ;
setMinimumSize ( thisRect . width ( ) , thisRect . height ( ) ) ;
2010-11-18 00:32:46 +01:00
//Enable buttons
2012-12-08 00:21:10 +01:00
connect ( ui - > button_AbortProcess , SIGNAL ( clicked ( ) ) , this , SLOT ( abortEncoding ( ) ) ) ;
2010-11-18 00:32:46 +01:00
2010-11-17 19:35:50 +01:00
//Init progress indicator
m_progressIndicator = new QMovie ( " :/images/Working.gif " ) ;
2011-11-16 22:53:18 +01:00
m_progressIndicator - > setCacheMode ( QMovie : : CacheAll ) ;
m_progressIndicator - > setSpeed ( 50 ) ;
2012-12-08 00:21:10 +01:00
ui - > label_headerWorking - > setMovie ( m_progressIndicator ) ;
ui - > progressBar - > setValue ( 0 ) ;
2010-11-18 00:32:46 +01:00
//Init progress model
m_progressModel = new ProgressModel ( ) ;
2012-12-08 00:21:10 +01:00
ui - > view_log - > setModel ( m_progressModel ) ;
ui - > view_log - > verticalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
ui - > view_log - > verticalHeader ( ) - > hide ( ) ;
ui - > view_log - > horizontalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
ui - > view_log - > horizontalHeader ( ) - > setResizeMode ( 0 , QHeaderView : : Stretch ) ;
ui - > view_log - > viewport ( ) - > installEventFilter ( this ) ;
2010-11-21 21:51:22 +01:00
connect ( m_progressModel , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( progressModelChanged ( ) ) ) ;
2012-11-11 18:33:55 +01:00
connect ( m_progressModel , SIGNAL ( rowsMoved ( QModelIndex , int , int , QModelIndex , int ) ) , this , SLOT ( progressModelChanged ( ) ) ) ;
connect ( m_progressModel , SIGNAL ( rowsRemoved ( QModelIndex , int , int ) ) , this , SLOT ( progressModelChanged ( ) ) ) ;
2010-11-21 21:51:22 +01:00
connect ( m_progressModel , SIGNAL ( modelReset ( ) ) , this , SLOT ( progressModelChanged ( ) ) ) ;
2012-12-08 00:21:10 +01:00
connect ( ui - > view_log , SIGNAL ( activated ( QModelIndex ) ) , this , SLOT ( logViewDoubleClicked ( QModelIndex ) ) ) ;
connect ( ui - > view_log - > horizontalHeader ( ) , SIGNAL ( sectionResized ( int , int , int ) ) , this , SLOT ( logViewSectionSizeChanged ( int , int , int ) ) ) ;
2010-11-18 00:32:46 +01:00
2010-11-24 21:00:59 +01:00
//Create context menu
m_contextMenu = new QMenu ( ) ;
2011-02-11 23:16:11 +01:00
QAction * contextMenuDetailsAction = m_contextMenu - > addAction ( QIcon ( " :/icons/zoom.png " ) , tr ( " Show details for selected job " ) ) ;
QAction * contextMenuShowFileAction = m_contextMenu - > addAction ( QIcon ( " :/icons/folder_go.png " ) , tr ( " Browse Output File Location " ) ) ;
2012-11-11 18:33:55 +01:00
m_contextMenu - > addSeparator ( ) ;
//Create "filter" context menu
m_progressViewFilterGroup = new QActionGroup ( this ) ;
QAction * contextMenuFilterAction [ 5 ] = { NULL , NULL , NULL , NULL , NULL } ;
if ( QMenu * filterMenu = m_contextMenu - > addMenu ( QIcon ( " :/icons/filter.png " ) , tr ( " Filter Log Items " ) ) )
{
2012-11-17 19:26:55 +01:00
contextMenuFilterAction [ 0 ] = filterMenu - > addAction ( m_progressModel - > getIcon ( ProgressModel : : JobRunning ) , tr ( " Show Running Only " ) ) ;
contextMenuFilterAction [ 1 ] = filterMenu - > addAction ( m_progressModel - > getIcon ( ProgressModel : : JobComplete ) , tr ( " Show Succeeded Only " ) ) ;
contextMenuFilterAction [ 2 ] = filterMenu - > addAction ( m_progressModel - > getIcon ( ProgressModel : : JobFailed ) , tr ( " Show Failed Only " ) ) ;
contextMenuFilterAction [ 3 ] = filterMenu - > addAction ( m_progressModel - > getIcon ( ProgressModel : : JobSkipped ) , tr ( " Show Skipped Only " ) ) ;
contextMenuFilterAction [ 4 ] = filterMenu - > addAction ( m_progressModel - > getIcon ( ProgressModel : : JobState ( - 1 ) ) , tr ( " Show All Items " ) ) ;
2012-11-11 19:36:31 +01:00
if ( QAction * act = contextMenuFilterAction [ 0 ] ) { m_progressViewFilterGroup - > addAction ( act ) ; act - > setCheckable ( true ) ; act - > setData ( ProgressModel : : JobRunning ) ; }
if ( QAction * act = contextMenuFilterAction [ 1 ] ) { m_progressViewFilterGroup - > addAction ( act ) ; act - > setCheckable ( true ) ; act - > setData ( ProgressModel : : JobComplete ) ; }
if ( QAction * act = contextMenuFilterAction [ 2 ] ) { m_progressViewFilterGroup - > addAction ( act ) ; act - > setCheckable ( true ) ; act - > setData ( ProgressModel : : JobFailed ) ; }
if ( QAction * act = contextMenuFilterAction [ 3 ] ) { m_progressViewFilterGroup - > addAction ( act ) ; act - > setCheckable ( true ) ; act - > setData ( ProgressModel : : JobSkipped ) ; }
if ( QAction * act = contextMenuFilterAction [ 4 ] ) { m_progressViewFilterGroup - > addAction ( act ) ; act - > setCheckable ( true ) ; act - > setData ( - 1 ) ; act - > setChecked ( true ) ; }
2012-11-11 18:33:55 +01:00
}
2012-11-15 18:06:04 +01:00
//Create info label
2012-12-08 00:21:10 +01:00
if ( m_filterInfoLabel = new QLabel ( ui - > view_log ) )
2012-11-15 18:06:04 +01:00
{
m_filterInfoLabel - > setFrameShape ( QFrame : : NoFrame ) ;
2012-11-17 19:26:55 +01:00
m_filterInfoLabel - > setAlignment ( Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
m_filterInfoLabel - > setUserData ( 0 , new IntUserData ( - 1 ) ) ;
2012-11-15 18:06:04 +01:00
SET_FONT_BOLD ( m_filterInfoLabel , true ) ;
SET_TEXT_COLOR ( m_filterInfoLabel , Qt : : darkGray ) ;
m_filterInfoLabel - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( m_filterInfoLabel , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenuTriggered ( QPoint ) ) ) ;
m_filterInfoLabel - > hide ( ) ;
}
2012-12-08 00:21:10 +01:00
if ( m_filterInfoLabelIcon = new QLabel ( ui - > view_log ) )
2012-11-17 19:26:55 +01:00
{
m_filterInfoLabelIcon - > setFrameShape ( QFrame : : NoFrame ) ;
m_filterInfoLabelIcon - > setAlignment ( Qt : : AlignHCenter | Qt : : AlignTop ) ;
m_filterInfoLabelIcon - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
const QIcon & ico = m_progressModel - > getIcon ( ProgressModel : : JobState ( - 1 ) ) ;
m_filterInfoLabelIcon - > setPixmap ( ico . pixmap ( 16 , 16 ) ) ;
connect ( m_filterInfoLabelIcon , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenuTriggered ( QPoint ) ) ) ;
m_filterInfoLabelIcon - > hide ( ) ;
}
2012-11-15 18:06:04 +01:00
2012-11-11 18:33:55 +01:00
//Connect context menu
2012-12-08 00:21:10 +01:00
ui - > view_log - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( ui - > view_log , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( contextMenuTriggered ( QPoint ) ) ) ;
2011-02-11 23:16:11 +01:00
connect ( contextMenuDetailsAction , SIGNAL ( triggered ( bool ) ) , this , SLOT ( contextMenuDetailsActionTriggered ( ) ) ) ;
connect ( contextMenuShowFileAction , SIGNAL ( triggered ( bool ) ) , this , SLOT ( contextMenuShowFileActionTriggered ( ) ) ) ;
2012-11-11 19:36:31 +01:00
for ( size_t i = 0 ; i < 5 ; i + + )
2012-11-11 18:33:55 +01:00
{
if ( contextMenuFilterAction [ i ] ) connect ( contextMenuFilterAction [ i ] , SIGNAL ( triggered ( bool ) ) , this , SLOT ( contextMenuFilterActionTriggered ( ) ) ) ;
}
2011-02-14 19:03:36 +01:00
SET_FONT_BOLD ( contextMenuDetailsAction , true ) ;
2010-11-19 21:11:54 +01:00
//Enque jobs
if ( fileListModel )
{
for ( int i = 0 ; i < fileListModel - > rowCount ( ) ; i + + )
{
m_pendingJobs . append ( fileListModel - > getFile ( fileListModel - > index ( i , 0 ) ) ) ;
}
}
2011-01-01 19:28:19 +01:00
//Translate
2012-12-08 00:21:10 +01:00
ui - > label_headerStatus - > setText ( QString ( " <b>%1</b><br>%2 " ) . arg ( tr ( " Encoding Files " ) , tr ( " Your files are being encoded, please be patient... " ) ) ) ;
2011-01-01 19:28:19 +01:00
2010-12-10 22:17:44 +01:00
//Enable system tray icon
connect ( m_systemTray , SIGNAL ( activated ( QSystemTrayIcon : : ActivationReason ) ) , this , SLOT ( systemTrayActivated ( QSystemTrayIcon : : ActivationReason ) ) ) ;
2010-11-19 21:11:54 +01:00
//Init other vars
m_runningThreads = 0 ;
2010-11-20 19:16:04 +01:00
m_currentFile = 0 ;
2010-12-10 21:24:42 +01:00
m_allJobs . clear ( ) ;
m_succeededJobs . clear ( ) ;
m_failedJobs . clear ( ) ;
2012-11-11 18:33:55 +01:00
m_skippedJobs . clear ( ) ;
2010-11-19 21:11:54 +01:00
m_userAborted = false ;
2011-12-29 14:42:20 +01:00
m_forcedAbort = false ;
2011-11-28 00:35:43 +01:00
m_timerStart = 0 I64 ;
2010-11-17 19:35:50 +01:00
}
2010-11-18 00:32:46 +01:00
////////////////////////////////////////////////////////////
// Destructor
////////////////////////////////////////////////////////////
2010-11-17 19:35:50 +01:00
ProcessingDialog : : ~ ProcessingDialog ( void )
{
2012-12-08 00:21:10 +01:00
ui - > view_log - > setModel ( NULL ) ;
2011-03-28 04:26:47 +02:00
if ( m_progressIndicator )
{
m_progressIndicator - > stop ( ) ;
}
if ( m_diskObserver )
{
m_diskObserver - > stop ( ) ;
2011-10-29 16:26:09 +02:00
if ( ! m_diskObserver - > wait ( 15000 ) )
{
m_diskObserver - > terminate ( ) ;
m_diskObserver - > wait ( ) ;
}
}
if ( m_cpuObserver )
{
m_cpuObserver - > stop ( ) ;
if ( ! m_cpuObserver - > wait ( 15000 ) )
{
m_cpuObserver - > terminate ( ) ;
m_cpuObserver - > wait ( ) ;
}
}
if ( m_ramObserver )
{
m_ramObserver - > stop ( ) ;
if ( ! m_ramObserver - > wait ( 15000 ) )
{
m_ramObserver - > terminate ( ) ;
m_ramObserver - > wait ( ) ;
}
2011-03-28 04:26:47 +02:00
}
2013-10-09 03:14:38 +02:00
if ( m_threadPool )
2012-11-17 19:26:55 +01:00
{
2013-10-09 03:14:38 +02:00
if ( ! m_threadPool - > waitForDone ( 100 ) )
{
emit abortRunningTasks ( ) ;
m_threadPool - > waitForDone ( ) ;
}
2012-11-17 19:26:55 +01:00
}
2010-11-17 19:35:50 +01:00
LAMEXP_DELETE ( m_progressIndicator ) ;
2010-12-10 22:17:44 +01:00
LAMEXP_DELETE ( m_systemTray ) ;
2011-03-28 04:26:47 +02:00
LAMEXP_DELETE ( m_diskObserver ) ;
2011-10-29 16:26:09 +02:00
LAMEXP_DELETE ( m_cpuObserver ) ;
LAMEXP_DELETE ( m_ramObserver ) ;
2012-11-11 18:33:55 +01:00
LAMEXP_DELETE ( m_progressViewFilterGroup ) ;
2012-11-17 19:26:55 +01:00
LAMEXP_DELETE ( m_filterInfoLabel ) ;
LAMEXP_DELETE ( m_filterInfoLabelIcon ) ;
LAMEXP_DELETE ( m_contextMenu ) ;
LAMEXP_DELETE ( m_progressModel ) ;
2013-10-09 03:14:38 +02:00
LAMEXP_DELETE ( m_threadPool ) ;
2012-11-17 19:26:55 +01:00
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setOverlayIcon ( this , NULL ) ;
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarNoState ) ;
2012-12-08 00:21:10 +01:00
LAMEXP_DELETE ( ui ) ;
2010-11-18 00:32:46 +01:00
}
////////////////////////////////////////////////////////////
// EVENTS
////////////////////////////////////////////////////////////
void ProcessingDialog : : showEvent ( QShowEvent * event )
{
2012-04-11 00:44:40 +02:00
QDialog : : showEvent ( event ) ;
2011-10-30 21:41:00 +01:00
2012-04-11 00:44:40 +02:00
if ( m_firstShow )
2010-11-25 16:56:32 +01:00
{
2012-04-11 00:44:40 +02:00
static const char * NA = " N/A " ;
2013-10-07 00:01:15 +02:00
lamexp_enable_close_button ( this , false ) ;
2012-12-08 00:21:10 +01:00
ui - > button_closeDialog - > setEnabled ( false ) ;
ui - > button_AbortProcess - > setEnabled ( false ) ;
2012-04-11 00:44:40 +02:00
m_systemTray - > setVisible ( true ) ;
2013-10-07 00:01:15 +02:00
lamexp_change_process_priority ( 1 ) ;
2010-11-25 16:56:32 +01:00
2012-12-08 00:21:10 +01:00
ui - > label_cpu - > setText ( NA ) ;
ui - > label_disk - > setText ( NA ) ;
ui - > label_ram - > setText ( NA ) ;
2011-10-29 16:26:09 +02:00
2012-04-11 00:44:40 +02:00
QTimer : : singleShot ( 1000 , this , SLOT ( initEncoding ( ) ) ) ;
m_firstShow = false ;
}
2012-11-15 18:06:04 +01:00
//Force update geometry
resizeEvent ( NULL ) ;
2010-11-18 00:32:46 +01:00
}
void ProcessingDialog : : closeEvent ( QCloseEvent * event )
{
2012-12-08 00:21:10 +01:00
if ( ! ui - > button_closeDialog - > isEnabled ( ) )
2010-12-10 22:17:44 +01:00
{
event - > ignore ( ) ;
}
else
{
m_systemTray - > setVisible ( false ) ;
}
2010-11-18 00:32:46 +01:00
}
bool ProcessingDialog : : eventFilter ( QObject * obj , QEvent * event )
{
static QColor defaultColor = QColor ( ) ;
2012-12-08 00:21:10 +01:00
if ( obj = = ui - > label_versionInfo )
2010-11-18 00:32:46 +01:00
{
if ( event - > type ( ) = = QEvent : : Enter )
{
2012-12-08 00:21:10 +01:00
QPalette palette = ui - > label_versionInfo - > palette ( ) ;
2010-11-18 00:32:46 +01:00
defaultColor = palette . color ( QPalette : : Normal , QPalette : : WindowText ) ;
palette . setColor ( QPalette : : Normal , QPalette : : WindowText , Qt : : red ) ;
2012-12-08 00:21:10 +01:00
ui - > label_versionInfo - > setPalette ( palette ) ;
2010-11-18 00:32:46 +01:00
}
else if ( event - > type ( ) = = QEvent : : Leave )
{
2012-12-08 00:21:10 +01:00
QPalette palette = ui - > label_versionInfo - > palette ( ) ;
2010-11-18 00:32:46 +01:00
palette . setColor ( QPalette : : Normal , QPalette : : WindowText , defaultColor ) ;
2012-12-08 00:21:10 +01:00
ui - > label_versionInfo - > setPalette ( palette ) ;
2010-11-18 00:32:46 +01:00
}
else if ( event - > type ( ) = = QEvent : : MouseButtonPress )
{
2011-02-28 01:28:27 +01:00
QUrl url ( lamexp_website_url ( ) ) ;
2010-11-18 00:32:46 +01:00
QDesktopServices : : openUrl ( url ) ;
}
}
return false ;
}
2011-12-29 14:42:20 +01:00
bool ProcessingDialog : : event ( QEvent * e )
{
switch ( e - > type ( ) )
{
case lamexp_event_queryendsession :
qWarning ( " System is shutting down, preparing to abort... " ) ;
if ( ! m_userAborted ) abortEncoding ( true ) ;
return true ;
case lamexp_event_endsession :
qWarning ( " System is shutting down, encoding will be aborted now... " ) ;
if ( isVisible ( ) )
{
while ( ! close ( ) )
{
if ( ! m_userAborted ) abortEncoding ( true ) ;
2013-10-12 20:34:59 +02:00
qApp - > processEvents ( QEventLoop : : WaitForMoreEvents | QEventLoop : : ExcludeUserInputEvents ) ;
2011-12-29 14:42:20 +01:00
}
}
m_pendingJobs . clear ( ) ;
return true ;
default :
return QDialog : : event ( e ) ;
}
}
2012-11-15 18:06:04 +01:00
/*
* Window was resized
*/
void ProcessingDialog : : resizeEvent ( QResizeEvent * event )
{
if ( event ) QDialog : : resizeEvent ( event ) ;
2012-12-08 00:21:10 +01:00
if ( QWidget * port = ui - > view_log - > viewport ( ) )
2012-11-15 18:06:04 +01:00
{
QRect geom = port - > geometry ( ) ;
2012-11-17 19:26:55 +01:00
m_filterInfoLabel - > setGeometry ( geom . left ( ) + 16 , geom . top ( ) + 16 , geom . width ( ) - 32 , 48 ) ;
m_filterInfoLabelIcon - > setGeometry ( geom . left ( ) + 16 , geom . top ( ) + 64 , geom . width ( ) - 32 , geom . height ( ) - 80 ) ;
2012-11-15 18:06:04 +01:00
}
}
2011-11-07 17:13:41 +01:00
bool ProcessingDialog : : winEvent ( MSG * message , long * result )
{
return WinSevenTaskbar : : handleWinEvent ( message , result ) ;
}
2010-11-18 00:32:46 +01:00
////////////////////////////////////////////////////////////
// SLOTS
////////////////////////////////////////////////////////////
void ProcessingDialog : : initEncoding ( void )
{
2012-04-13 16:37:47 +02:00
qDebug ( " Initializing encoding process... " ) ;
2012-04-11 00:44:40 +02:00
2010-11-19 21:11:54 +01:00
m_runningThreads = 0 ;
2010-11-20 19:16:04 +01:00
m_currentFile = 0 ;
2010-12-10 21:24:42 +01:00
m_allJobs . clear ( ) ;
m_succeededJobs . clear ( ) ;
m_failedJobs . clear ( ) ;
2012-11-11 18:33:55 +01:00
m_skippedJobs . clear ( ) ;
2010-11-19 21:11:54 +01:00
m_userAborted = false ;
2011-12-29 14:42:20 +01:00
m_forcedAbort = false ;
2010-11-20 22:14:10 +01:00
m_playList . clear ( ) ;
2013-01-18 01:08:58 +01:00
DecoderRegistry : : configureDecoders ( m_settings ) ;
2012-12-08 00:21:10 +01:00
CHANGE_BACKGROUND_COLOR ( ui - > frame_header , QColor ( Qt : : white ) ) ;
2011-01-02 01:09:05 +01:00
SET_PROGRESS_TEXT ( tr ( " Encoding files, please wait... " ) ) ;
2010-11-18 00:32:46 +01:00
m_progressIndicator - > start ( ) ;
2012-12-08 00:21:10 +01:00
ui - > button_closeDialog - > setEnabled ( false ) ;
ui - > button_AbortProcess - > setEnabled ( true ) ;
ui - > progressBar - > setRange ( 0 , m_pendingJobs . count ( ) ) ;
ui - > checkBox_shutdownComputer - > setEnabled ( true ) ;
ui - > checkBox_shutdownComputer - > setChecked ( false ) ;
2010-11-19 21:11:54 +01:00
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarNormalState ) ;
WinSevenTaskbar : : setTaskbarProgress ( this , 0 , m_pendingJobs . count ( ) ) ;
WinSevenTaskbar : : setOverlayIcon ( this , & QIcon ( " :/icons/control_play_blue.png " ) ) ;
2011-03-28 04:26:47 +02:00
if ( ! m_diskObserver )
{
m_diskObserver = new DiskObserverThread ( m_settings - > customTempPathEnabled ( ) ? m_settings - > customTempPath ( ) : lamexp_temp_folder2 ( ) ) ;
2011-11-28 00:35:43 +01:00
connect ( m_diskObserver , SIGNAL ( messageLogged ( QString , int ) ) , m_progressModel , SLOT ( addSystemMessage ( QString , int ) ) , Qt : : QueuedConnection ) ;
2011-10-29 16:26:09 +02:00
connect ( m_diskObserver , SIGNAL ( freeSpaceChanged ( quint64 ) ) , this , SLOT ( diskUsageHasChanged ( quint64 ) ) , Qt : : QueuedConnection ) ;
2011-03-28 04:26:47 +02:00
m_diskObserver - > start ( ) ;
}
2011-10-29 16:26:09 +02:00
if ( ! m_cpuObserver )
{
m_cpuObserver = new CPUObserverThread ( ) ;
connect ( m_cpuObserver , SIGNAL ( currentUsageChanged ( double ) ) , this , SLOT ( cpuUsageHasChanged ( double ) ) , Qt : : QueuedConnection ) ;
m_cpuObserver - > start ( ) ;
}
if ( ! m_ramObserver )
{
m_ramObserver = new RAMObserverThread ( ) ;
connect ( m_ramObserver , SIGNAL ( currentUsageChanged ( double ) ) , this , SLOT ( ramUsageHasChanged ( double ) ) , Qt : : QueuedConnection ) ;
m_ramObserver - > start ( ) ;
}
2010-11-24 21:00:59 +01:00
2013-10-09 03:14:38 +02:00
if ( ! m_threadPool )
2011-02-02 22:56:45 +01:00
{
2013-10-09 03:14:38 +02:00
unsigned int maximumInstances = qBound ( 0U , m_settings - > maximumInstances ( ) , MAX_INSTANCES ) ;
if ( maximumInstances < 1 )
{
lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features ( lamexp_arguments ( ) ) ;
maximumInstances = cores2instances ( qBound ( 1 , cpuFeatures . count , 64 ) ) ;
}
maximumInstances = qBound ( 1U , maximumInstances , static_cast < unsigned int > ( m_pendingJobs . count ( ) ) ) ;
if ( maximumInstances > 1 )
{
m_progressModel - > addSystemMessage ( tr ( " Multi-threading enabled: Running %1 instances in parallel! " ) . arg ( QString : : number ( maximumInstances ) ) ) ;
}
m_threadPool = new QThreadPool ( ) ;
m_threadPool - > setMaxThreadCount ( maximumInstances ) ;
2011-02-02 22:56:45 +01:00
}
2013-10-09 03:14:38 +02:00
for ( int i = 0 ; i < m_threadPool - > maxThreadCount ( ) ; i + + )
2010-11-24 21:00:59 +01:00
{
startNextJob ( ) ;
2013-10-09 03:14:38 +02:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2013-10-11 20:43:31 +02:00
QThread : : yieldCurrentThread ( ) ;
2010-11-24 21:00:59 +01:00
}
2011-11-28 00:35:43 +01:00
2013-10-07 00:01:15 +02:00
m_timerStart = lamexp_perfcounter_value ( ) ;
2010-11-18 00:32:46 +01:00
}
2013-10-12 20:34:59 +02:00
void ProcessingDialog : : startNextJob ( void )
{
if ( m_pendingJobs . isEmpty ( ) )
{
qWarning ( " No more files left, unable to start another job! " ) ;
return ;
}
m_currentFile + + ;
m_runningThreads + + ;
AudioFileModel currentFile = updateMetaInfo ( m_pendingJobs . takeFirst ( ) ) ;
bool nativeResampling = false ;
//Create encoder instance
AbstractEncoder * encoder = EncoderRegistry : : createInstance ( m_settings - > compressionEncoder ( ) , m_settings , & nativeResampling ) ;
//Create processing thread
ProcessThread * thread = new ProcessThread
(
currentFile ,
( m_settings - > outputToSourceDir ( ) ? QFileInfo ( currentFile . filePath ( ) ) . absolutePath ( ) : m_settings - > outputDir ( ) ) ,
( m_settings - > customTempPathEnabled ( ) ? m_settings - > customTempPath ( ) : lamexp_temp_folder2 ( ) ) ,
encoder ,
m_settings - > prependRelativeSourcePath ( ) & & ( ! m_settings - > outputToSourceDir ( ) )
) ;
//Add audio filters
if ( m_settings - > forceStereoDownmix ( ) )
{
thread - > addFilter ( new DownmixFilter ( ) ) ;
}
if ( ( m_settings - > samplingRate ( ) > 0 ) & & ! nativeResampling )
{
2013-10-12 22:55:41 +02:00
if ( SettingsModel : : samplingRates [ m_settings - > samplingRate ( ) ] ! = currentFile . techInfo ( ) . audioSamplerate ( ) | | currentFile . techInfo ( ) . audioSamplerate ( ) = = 0 )
2013-10-12 20:34:59 +02:00
{
thread - > addFilter ( new ResampleFilter ( SettingsModel : : samplingRates [ m_settings - > samplingRate ( ) ] ) ) ;
}
}
if ( ( m_settings - > toneAdjustBass ( ) ! = 0 ) | | ( m_settings - > toneAdjustTreble ( ) ! = 0 ) )
{
thread - > addFilter ( new ToneAdjustFilter ( m_settings - > toneAdjustBass ( ) , m_settings - > toneAdjustTreble ( ) ) ) ;
}
if ( m_settings - > normalizationFilterEnabled ( ) )
{
thread - > addFilter ( new NormalizeFilter ( m_settings - > normalizationFilterMaxVolume ( ) , m_settings - > normalizationFilterEQMode ( ) ) ) ;
}
if ( m_settings - > renameOutputFilesEnabled ( ) & & ( ! m_settings - > renameOutputFilesPattern ( ) . simplified ( ) . isEmpty ( ) ) )
{
thread - > setRenamePattern ( m_settings - > renameOutputFilesPattern ( ) ) ;
}
if ( m_settings - > overwriteMode ( ) ! = SettingsModel : : Overwrite_KeepBoth )
{
thread - > setOverwriteMode ( ( m_settings - > overwriteMode ( ) = = SettingsModel : : Overwrite_SkipFile ) , ( m_settings - > overwriteMode ( ) = = SettingsModel : : Overwrite_Replaces ) ) ;
}
m_allJobs . append ( thread - > getId ( ) ) ;
//Connect thread signals
connect ( thread , SIGNAL ( processFinished ( ) ) , this , SLOT ( doneEncoding ( ) ) , Qt : : QueuedConnection ) ;
connect ( thread , SIGNAL ( processStateInitialized ( QUuid , QString , QString , int ) ) , m_progressModel , SLOT ( addJob ( QUuid , QString , QString , int ) ) , Qt : : QueuedConnection ) ;
connect ( thread , SIGNAL ( processStateChanged ( QUuid , QString , int ) ) , m_progressModel , SLOT ( updateJob ( QUuid , QString , int ) ) , Qt : : QueuedConnection ) ;
connect ( thread , SIGNAL ( processStateFinished ( QUuid , QString , int ) ) , this , SLOT ( processFinished ( QUuid , QString , int ) ) , Qt : : QueuedConnection ) ;
connect ( thread , SIGNAL ( processMessageLogged ( QUuid , QString ) ) , m_progressModel , SLOT ( appendToLog ( QUuid , QString ) ) , Qt : : QueuedConnection ) ;
connect ( this , SIGNAL ( abortRunningTasks ( ) ) , thread , SLOT ( abort ( ) ) , Qt : : DirectConnection ) ;
//Initialize thread object
if ( ! thread - > init ( ) )
{
qFatal ( " Fatal Error: Thread initialization has failed! " ) ;
}
//Update GUI
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
//Give it a go!
if ( ! thread - > start ( m_threadPool ) )
{
qWarning ( " Job failed to start or file was skipped! " ) ;
}
}
2011-12-29 14:42:20 +01:00
void ProcessingDialog : : abortEncoding ( bool force )
2010-11-18 00:32:46 +01:00
{
2010-11-19 21:11:54 +01:00
m_userAborted = true ;
2011-12-29 14:42:20 +01:00
if ( force ) m_forcedAbort = true ;
2012-12-08 00:21:10 +01:00
ui - > button_AbortProcess - > setEnabled ( false ) ;
2011-01-02 01:09:05 +01:00
SET_PROGRESS_TEXT ( tr ( " Aborted! Waiting for running jobs to terminate... " ) ) ;
2013-10-09 03:14:38 +02:00
emit abortRunningTasks ( ) ;
2010-11-18 00:32:46 +01:00
}
void ProcessingDialog : : doneEncoding ( void )
{
2010-11-19 21:11:54 +01:00
m_runningThreads - - ;
2012-12-08 00:21:10 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > value ( ) + 1 ) ;
2010-12-02 23:26:30 +01:00
if ( ! m_userAborted )
{
2013-01-23 23:39:30 +01:00
SET_PROGRESS_TEXT ( tr ( " Encoding: %n file(s) of %1 completed so far, please wait... " , " " , ui - > progressBar - > value ( ) ) . arg ( QString : : number ( ui - > progressBar - > maximum ( ) ) ) ) ;
2012-12-08 00:21:10 +01:00
WinSevenTaskbar : : setTaskbarProgress ( this , ui - > progressBar - > value ( ) , ui - > progressBar - > maximum ( ) ) ;
2010-12-02 23:26:30 +01:00
}
2010-11-18 00:32:46 +01:00
2013-10-09 03:14:38 +02:00
if ( ( ! m_pendingJobs . isEmpty ( ) ) & & ( ! m_userAborted ) )
2010-11-18 00:32:46 +01:00
{
2013-10-12 20:34:59 +02:00
QTimer : : singleShot ( 0 , this , SLOT ( startNextJob ( ) ) ) ;
qDebug ( " %d files left, starting next job... " , m_pendingJobs . count ( ) ) ;
2010-11-18 00:32:46 +01:00
return ;
}
2010-11-19 21:11:54 +01:00
if ( m_runningThreads > 0 )
{
2013-10-12 20:34:59 +02:00
qDebug ( " No files left, but still have %u running jobs. " , m_runningThreads ) ;
2010-11-19 21:11:54 +01:00
return ;
}
2010-11-25 20:41:59 +01:00
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
2010-11-19 21:11:54 +01:00
qDebug ( " Running jobs: %u " , m_runningThreads ) ;
2011-12-29 14:42:20 +01:00
if ( ! m_userAborted & & m_settings - > createPlaylist ( ) & & ! m_settings - > outputToSourceDir ( ) )
2010-11-20 22:14:10 +01:00
{
2011-01-13 08:57:34 +01:00
SET_PROGRESS_TEXT ( tr ( " Creating the playlist file, please wait... " ) ) ;
2013-10-12 20:34:59 +02:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2010-11-20 22:14:10 +01:00
writePlayList ( ) ;
}
2011-12-29 14:42:20 +01:00
if ( m_userAborted )
2010-11-21 21:51:22 +01:00
{
2012-12-08 00:21:10 +01:00
CHANGE_BACKGROUND_COLOR ( ui - > frame_header , QColor ( " #FFF3BA " ) ) ;
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this , & QIcon ( " :/icons/error.png " ) ) ;
2013-01-23 23:25:31 +01:00
SET_PROGRESS_TEXT ( ( m_succeededJobs . count ( ) > 0 ) ? tr ( " Process was aborted by the user after %n file(s)! " , " " , m_succeededJobs . count ( ) ) : tr ( " Process was aborted prematurely by the user! " ) ) ;
2011-01-02 01:09:05 +01:00
m_systemTray - > showMessage ( tr ( " LameXP - Aborted " ) , tr ( " Process was aborted by the user. " ) , QSystemTrayIcon : : Warning ) ;
2010-12-12 19:25:06 +01:00
m_systemTray - > setIcon ( QIcon ( " :/icons/cd_delete.png " ) ) ;
2013-10-12 20:34:59 +02:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2013-10-09 03:14:38 +02:00
if ( m_settings - > soundsEnabled ( ) & & ( ! m_forcedAbort ) )
2011-12-27 05:04:53 +01:00
{
2013-10-07 00:01:15 +02:00
lamexp_play_sound ( IDR_WAVE_ABORTED , false ) ;
2011-12-27 05:04:53 +01:00
}
2010-11-21 21:51:22 +01:00
}
else
{
2013-10-07 00:01:15 +02:00
const __int64 counter = lamexp_perfcounter_value ( ) ;
const __int64 frequency = lamexp_perfcounter_frequ ( ) ;
if ( ( counter > = 0 I64 ) & & ( frequency > = 0 ) )
2011-11-28 00:35:43 +01:00
{
2013-10-07 00:01:15 +02:00
if ( ( m_timerStart > = 0 I64 ) & & ( m_timerStart < counter ) )
2011-11-28 00:35:43 +01:00
{
2013-10-07 00:01:15 +02:00
double timeElapsed = static_cast < double > ( counter - m_timerStart ) / static_cast < double > ( frequency ) ;
2011-11-28 00:35:43 +01:00
m_progressModel - > addSystemMessage ( tr ( " Process finished after %1. " ) . arg ( time2text ( timeElapsed ) ) , ProgressModel : : SysMsg_Performance ) ;
}
}
2010-12-10 21:24:42 +01:00
if ( m_failedJobs . count ( ) > 0 )
2010-11-21 21:51:22 +01:00
{
2012-12-08 00:21:10 +01:00
CHANGE_BACKGROUND_COLOR ( ui - > frame_header , QColor ( " #FFBABA " ) ) ;
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this , & QIcon ( " :/icons/exclamation.png " ) ) ;
2012-11-11 18:33:55 +01:00
if ( m_skippedJobs . count ( ) > 0 )
{
2013-01-28 22:22:49 +01:00
SET_PROGRESS_TEXT ( tr ( " Error: %1 of %n file(s) failed (%2). Double-click failed items for detailed information! " , " " , m_failedJobs . count ( ) + m_succeededJobs . count ( ) + m_skippedJobs . count ( ) ) . arg ( QString : : number ( m_failedJobs . count ( ) ) , tr ( " %n file(s) skipped " , " " , m_skippedJobs . count ( ) ) ) ) ;
2012-11-11 18:33:55 +01:00
}
else
{
2013-01-28 22:22:49 +01:00
SET_PROGRESS_TEXT ( tr ( " Error: %1 of %n file(s) failed. Double-click failed items for detailed information! " , " " , m_failedJobs . count ( ) + m_succeededJobs . count ( ) ) . arg ( QString : : number ( m_failedJobs . count ( ) ) ) ) ;
2012-11-11 18:33:55 +01:00
}
2011-01-02 01:09:05 +01:00
m_systemTray - > showMessage ( tr ( " LameXP - Error " ) , tr ( " At least one file has failed! " ) , QSystemTrayIcon : : Critical ) ;
2010-12-12 19:25:06 +01:00
m_systemTray - > setIcon ( QIcon ( " :/icons/cd_delete.png " ) ) ;
2013-10-12 20:34:59 +02:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2013-10-07 00:01:15 +02:00
if ( m_settings - > soundsEnabled ( ) ) lamexp_play_sound ( IDR_WAVE_ERROR , false ) ;
2010-11-21 21:51:22 +01:00
}
else
{
2012-12-08 00:21:10 +01:00
CHANGE_BACKGROUND_COLOR ( ui - > frame_header , QColor ( " #E0FFE2 " ) ) ;
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarNormalState ) ;
WinSevenTaskbar : : setOverlayIcon ( this , & QIcon ( " :/icons/accept.png " ) ) ;
2012-11-11 18:33:55 +01:00
if ( m_skippedJobs . count ( ) > 0 )
{
2013-01-28 22:22:49 +01:00
SET_PROGRESS_TEXT ( tr ( " All files completed successfully. Skipped %n file(s). " , " " , m_skippedJobs . count ( ) ) ) ;
2012-11-11 18:33:55 +01:00
}
else
{
SET_PROGRESS_TEXT ( tr ( " All files completed successfully. " ) ) ;
}
2011-01-02 01:09:05 +01:00
m_systemTray - > showMessage ( tr ( " LameXP - Done " ) , tr ( " All files completed successfully. " ) , QSystemTrayIcon : : Information ) ;
2010-12-12 19:25:06 +01:00
m_systemTray - > setIcon ( QIcon ( " :/icons/cd_add.png " ) ) ;
2013-10-12 20:34:59 +02:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2013-10-07 00:01:15 +02:00
if ( m_settings - > soundsEnabled ( ) ) lamexp_play_sound ( IDR_WAVE_SUCCESS , false ) ;
2010-11-21 21:51:22 +01:00
}
}
2013-10-07 00:01:15 +02:00
lamexp_enable_close_button ( this , true ) ;
2012-12-08 00:21:10 +01:00
ui - > button_closeDialog - > setEnabled ( true ) ;
ui - > button_AbortProcess - > setEnabled ( false ) ;
ui - > checkBox_shutdownComputer - > setEnabled ( false ) ;
2010-11-18 00:32:46 +01:00
2011-06-13 18:59:21 +02:00
m_progressModel - > restoreHiddenItems ( ) ;
2012-12-08 00:21:10 +01:00
ui - > view_log - > scrollToBottom ( ) ;
2010-11-21 21:51:22 +01:00
m_progressIndicator - > stop ( ) ;
2012-12-08 00:21:10 +01:00
ui - > progressBar - > setValue ( ui - > progressBar - > maximum ( ) ) ;
WinSevenTaskbar : : setTaskbarProgress ( this , ui - > progressBar - > value ( ) , ui - > progressBar - > maximum ( ) ) ;
2010-11-25 20:41:59 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2011-03-18 01:12:17 +01:00
2012-12-08 00:21:10 +01:00
if ( ! m_userAborted & & ui - > checkBox_shutdownComputer - > isChecked ( ) )
2011-03-18 01:12:17 +01:00
{
2011-03-18 12:37:18 +01:00
if ( shutdownComputer ( ) )
{
2011-10-22 01:13:28 +02:00
m_shutdownFlag = m_settings - > hibernateComputer ( ) ? shutdownFlag_Hibernate : shutdownFlag_TurnPowerOff ;
2011-03-18 12:37:18 +01:00
accept ( ) ;
}
2011-03-18 01:12:17 +01:00
}
2010-11-18 00:32:46 +01:00
}
2012-11-11 18:33:55 +01:00
void ProcessingDialog : : processFinished ( const QUuid & jobId , const QString & outFileName , int success )
2010-11-20 22:14:10 +01:00
{
2012-11-11 18:33:55 +01:00
if ( success > 0 )
2010-11-20 22:14:10 +01:00
{
2010-12-10 21:24:42 +01:00
m_playList . insert ( jobId , outFileName ) ;
m_succeededJobs . append ( jobId ) ;
2010-11-20 22:14:10 +01:00
}
2012-11-11 18:33:55 +01:00
else if ( success < 0 )
{
m_playList . insert ( jobId , outFileName ) ;
m_skippedJobs . append ( jobId ) ;
}
2010-11-21 21:51:22 +01:00
else
{
2010-12-10 21:24:42 +01:00
m_failedJobs . append ( jobId ) ;
2010-11-21 21:51:22 +01:00
}
2012-11-11 18:33:55 +01:00
//Update filter as soon as a job finished!
if ( m_progressViewFilter > = 0 )
{
QTimer : : singleShot ( 0 , this , SLOT ( progressViewFilterChanged ( ) ) ) ;
}
2010-11-21 21:51:22 +01:00
}
void ProcessingDialog : : progressModelChanged ( void )
{
2012-11-11 18:33:55 +01:00
//Update filter as soon as the model changes!
if ( m_progressViewFilter > = 0 )
{
QTimer : : singleShot ( 0 , this , SLOT ( progressViewFilterChanged ( ) ) ) ;
}
2012-12-08 00:21:10 +01:00
QTimer : : singleShot ( 0 , ui - > view_log , SLOT ( scrollToBottom ( ) ) ) ;
2010-11-20 22:14:10 +01:00
}
2010-11-22 21:45:00 +01:00
void ProcessingDialog : : logViewDoubleClicked ( const QModelIndex & index )
{
if ( m_runningThreads = = 0 )
{
const QStringList & logFile = m_progressModel - > getLogFile ( index ) ;
2011-02-02 22:56:45 +01:00
if ( ! logFile . isEmpty ( ) )
{
LogViewDialog * logView = new LogViewDialog ( this ) ;
logView - > setWindowTitle ( QString ( " LameXP - [%1] " ) . arg ( m_progressModel - > data ( index , Qt : : DisplayRole ) . toString ( ) ) ) ;
logView - > exec ( logFile ) ;
LAMEXP_DELETE ( logView ) ;
}
else
{
2011-12-26 21:02:55 +01:00
QMessageBox : : information ( this , windowTitle ( ) , m_progressModel - > data ( m_progressModel - > index ( index . row ( ) , 0 ) ) . toString ( ) ) ;
2011-02-02 22:56:45 +01:00
}
2010-11-22 21:45:00 +01:00
}
2010-11-24 21:00:59 +01:00
else
{
2013-10-07 00:01:15 +02:00
lamexp_beep ( lamexp_beep_warning ) ;
2010-11-24 21:00:59 +01:00
}
}
2011-08-23 17:01:11 +02:00
void ProcessingDialog : : logViewSectionSizeChanged ( int logicalIndex , int oldSize , int newSize )
{
if ( logicalIndex = = 1 )
{
2012-12-08 00:21:10 +01:00
if ( QHeaderView * hdr = ui - > view_log - > horizontalHeader ( ) )
2011-08-23 17:01:11 +02:00
{
2011-11-08 15:12:31 +01:00
hdr - > setMinimumSectionSize ( qMax ( hdr - > minimumSectionSize ( ) , hdr - > sectionSize ( 1 ) ) ) ;
2011-08-23 17:01:11 +02:00
}
}
}
2010-11-24 21:00:59 +01:00
void ProcessingDialog : : contextMenuTriggered ( const QPoint & pos )
{
2011-02-14 19:03:36 +01:00
QAbstractScrollArea * scrollArea = dynamic_cast < QAbstractScrollArea * > ( QObject : : sender ( ) ) ;
QWidget * sender = scrollArea ? scrollArea - > viewport ( ) : dynamic_cast < QWidget * > ( QObject : : sender ( ) ) ;
if ( pos . x ( ) < = sender - > width ( ) & & pos . y ( ) < = sender - > height ( ) & & pos . x ( ) > = 0 & & pos . y ( ) > = 0 )
2010-12-22 23:45:36 +01:00
{
2011-02-14 19:03:36 +01:00
m_contextMenu - > popup ( sender - > mapToGlobal ( pos ) ) ;
2010-12-22 23:45:36 +01:00
}
2010-11-24 21:00:59 +01:00
}
2011-02-11 23:16:11 +01:00
void ProcessingDialog : : contextMenuDetailsActionTriggered ( void )
2010-11-24 21:00:59 +01:00
{
2012-12-08 00:21:10 +01:00
QModelIndex index = ui - > view_log - > indexAt ( ui - > view_log - > viewport ( ) - > mapFromGlobal ( m_contextMenu - > pos ( ) ) ) ;
logViewDoubleClicked ( index . isValid ( ) ? index : ui - > view_log - > currentIndex ( ) ) ;
2010-11-22 21:45:00 +01:00
}
2011-02-11 23:16:11 +01:00
void ProcessingDialog : : contextMenuShowFileActionTriggered ( void )
{
2012-12-08 00:21:10 +01:00
QModelIndex index = ui - > view_log - > indexAt ( ui - > view_log - > viewport ( ) - > mapFromGlobal ( m_contextMenu - > pos ( ) ) ) ;
const QUuid & jobId = m_progressModel - > getJobId ( index . isValid ( ) ? index : ui - > view_log - > currentIndex ( ) ) ;
2011-02-11 23:16:11 +01:00
QString filePath = m_playList . value ( jobId , QString ( ) ) ;
if ( filePath . isEmpty ( ) )
{
2013-10-07 00:01:15 +02:00
lamexp_beep ( lamexp_beep_warning ) ;
2011-02-11 23:16:11 +01:00
return ;
}
if ( QFileInfo ( filePath ) . exists ( ) )
{
QString systemRootPath ;
QDir systemRoot ( lamexp_known_folder ( lamexp_folder_systemfolder ) ) ;
if ( systemRoot . exists ( ) & & systemRoot . cdUp ( ) )
{
systemRootPath = systemRoot . canonicalPath ( ) ;
}
if ( ! systemRootPath . isEmpty ( ) )
{
QFileInfo explorer ( QString ( " %1/explorer.exe " ) . arg ( systemRootPath ) ) ;
if ( explorer . exists ( ) & & explorer . isFile ( ) )
{
QProcess : : execute ( explorer . canonicalFilePath ( ) , QStringList ( ) < < " /select, " < < QDir : : toNativeSeparators ( QFileInfo ( filePath ) . canonicalFilePath ( ) ) ) ;
return ;
}
}
else
{
qWarning ( " SystemRoot directory could not be detected! " ) ;
}
}
else
{
qWarning ( " File not found: %s " , filePath . toLatin1 ( ) . constData ( ) ) ;
2013-10-07 00:01:15 +02:00
lamexp_beep ( lamexp_beep_error ) ;
2011-02-11 23:16:11 +01:00
}
}
2012-11-11 18:33:55 +01:00
void ProcessingDialog : : contextMenuFilterActionTriggered ( void )
{
if ( QAction * action = dynamic_cast < QAction * > ( QObject : : sender ( ) ) )
{
if ( action - > data ( ) . type ( ) = = QVariant : : Int )
{
m_progressViewFilter = action - > data ( ) . toInt ( ) ;
progressViewFilterChanged ( ) ;
QTimer : : singleShot ( 0 , this , SLOT ( progressViewFilterChanged ( ) ) ) ;
2012-12-08 00:21:10 +01:00
QTimer : : singleShot ( 0 , ui - > view_log , SLOT ( scrollToBottom ( ) ) ) ;
2012-11-11 18:33:55 +01:00
action - > setChecked ( true ) ;
}
}
}
2012-11-15 18:06:04 +01:00
/*
* Filter progress items
*/
2012-11-11 18:33:55 +01:00
void ProcessingDialog : : progressViewFilterChanged ( void )
{
2012-11-17 19:26:55 +01:00
bool matchFound = false ;
2012-11-11 18:33:55 +01:00
2012-12-08 00:21:10 +01:00
for ( int i = 0 ; i < ui - > view_log - > model ( ) - > rowCount ( ) ; i + + )
2012-11-11 18:33:55 +01:00
{
QModelIndex index = ( m_progressViewFilter > = 0 ) ? m_progressModel - > index ( i , 0 ) : QModelIndex ( ) ;
const bool bHide = index . isValid ( ) ? ( m_progressModel - > getJobState ( index ) ! = m_progressViewFilter ) : false ;
2012-12-08 00:21:10 +01:00
ui - > view_log - > setRowHidden ( i , bHide ) ; matchFound = matchFound | | ( ! bHide ) ;
2012-11-11 18:33:55 +01:00
}
2012-11-17 19:26:55 +01:00
if ( ( m_progressViewFilter > = 0 ) & & ( ! matchFound ) )
2012-11-11 18:33:55 +01:00
{
2012-11-17 19:26:55 +01:00
if ( m_filterInfoLabel - > isHidden ( ) | | ( dynamic_cast < IntUserData * > ( m_filterInfoLabel - > userData ( 0 ) ) - > value ( ) ! = m_progressViewFilter ) )
2012-11-11 18:33:55 +01:00
{
2012-11-17 19:26:55 +01:00
dynamic_cast < IntUserData * > ( m_filterInfoLabel - > userData ( 0 ) ) - > setValue ( m_progressViewFilter ) ;
m_filterInfoLabel - > setText ( QString ( " <p>» %1 «</p> " ) . arg ( tr ( " None of the items matches the current filtering rules " ) ) ) ;
2012-11-15 18:06:04 +01:00
m_filterInfoLabel - > show ( ) ;
2012-11-17 19:26:55 +01:00
m_filterInfoLabelIcon - > setPixmap ( m_progressModel - > getIcon ( static_cast < ProgressModel : : JobState > ( m_progressViewFilter ) ) . pixmap ( 16 , 16 , QIcon : : Disabled ) ) ;
m_filterInfoLabelIcon - > show ( ) ;
2012-11-15 18:06:04 +01:00
resizeEvent ( NULL ) ;
2012-11-11 18:33:55 +01:00
}
}
2012-11-15 18:06:04 +01:00
else if ( ! m_filterInfoLabel - > isHidden ( ) )
{
m_filterInfoLabel - > hide ( ) ;
2012-11-17 19:26:55 +01:00
m_filterInfoLabelIcon - > hide ( ) ;
2012-11-15 18:06:04 +01:00
}
2012-11-11 18:33:55 +01:00
}
2010-11-18 00:32:46 +01:00
////////////////////////////////////////////////////////////
// Private Functions
////////////////////////////////////////////////////////////
2010-11-20 22:14:10 +01:00
void ProcessingDialog : : writePlayList ( void )
{
2010-12-10 21:24:42 +01:00
if ( m_succeededJobs . count ( ) < = 0 | | m_allJobs . count ( ) < = 0 )
{
qWarning ( " WritePlayList: Nothing to do! " ) ;
return ;
}
2011-06-02 02:11:47 +02:00
//Init local variables
QStringList list ;
2011-09-06 18:47:13 +02:00
QRegExp regExp1 ( " \\ [ \\ d \\ d \\ ][^/ \\ \\ ]+$ " , Qt : : CaseInsensitive ) ;
QRegExp regExp2 ( " \\ ( \\ d \\ d \\ ) [ ^ / \ \ \ \ ] + $ " , Qt::CaseInsensitive) ;
QRegExp regExp3 ( " \\ d \\ d[^/ \\ \\ ]+$ " , Qt : : CaseInsensitive ) ;
bool usePrefix [ 3 ] = { true , true , true } ;
2011-06-02 02:11:47 +02:00
bool useUtf8 = false ;
int counter = 1 ;
//Generate playlist name
2013-10-13 00:21:37 +02:00
QString playListName = ( m_metaInfo - > album ( ) . isEmpty ( ) ? " Playlist " : m_metaInfo - > album ( ) ) ;
if ( ! m_metaInfo - > artist ( ) . isEmpty ( ) )
2011-06-02 02:11:47 +02:00
{
2013-10-13 00:21:37 +02:00
playListName = QString ( " %1 - %2 " ) . arg ( m_metaInfo - > artist ( ) , playListName ) ;
2011-06-02 02:11:47 +02:00
}
2010-11-20 22:14:10 +01:00
2011-06-02 02:11:47 +02:00
//Clean playlist name
2011-09-06 18:47:13 +02:00
playListName = lamexp_clean_filename ( playListName ) ;
2010-11-20 22:14:10 +01:00
2011-06-02 02:11:47 +02:00
//Create list of audio files
for ( int i = 0 ; i < m_allJobs . count ( ) ; i + + )
{
if ( ! m_succeededJobs . contains ( m_allJobs . at ( i ) ) ) continue ;
list < < QDir : : toNativeSeparators ( QDir ( m_settings - > outputDir ( ) ) . relativeFilePath ( m_playList . value ( m_allJobs . at ( i ) , " N/A " ) ) ) ;
}
2011-09-06 18:47:13 +02:00
//Use prefix?
for ( int i = 0 ; i < list . count ( ) ; i + + )
{
if ( regExp1 . indexIn ( list . at ( i ) ) < 0 ) usePrefix [ 0 ] = false ;
if ( regExp2 . indexIn ( list . at ( i ) ) < 0 ) usePrefix [ 1 ] = false ;
if ( regExp3 . indexIn ( list . at ( i ) ) < 0 ) usePrefix [ 2 ] = false ;
}
if ( usePrefix [ 0 ] | | usePrefix [ 1 ] | | usePrefix [ 2 ] )
{
playListName . prepend ( usePrefix [ 0 ] ? " [00] " : ( usePrefix [ 1 ] ? " (00) " : " 00 " ) ) ;
}
2011-06-02 02:11:47 +02:00
//Do we need an UTF-8 playlist?
for ( int i = 0 ; i < list . count ( ) ; i + + )
{
if ( wcscmp ( QWCHAR ( QString : : fromLatin1 ( list . at ( i ) . toLatin1 ( ) . constData ( ) ) ) , QWCHAR ( list . at ( i ) ) ) )
{
useUtf8 = true ;
break ;
}
}
//Generate playlist output file
QString playListFile = QString ( " %1/%2.%3 " ) . arg ( m_settings - > outputDir ( ) , playListName , ( useUtf8 ? " m3u8 " : " m3u " ) ) ;
2010-11-20 22:14:10 +01:00
while ( QFileInfo ( playListFile ) . exists ( ) )
{
2011-06-02 02:11:47 +02:00
playListFile = QString ( " %1/%2 (%3).%4 " ) . arg ( m_settings - > outputDir ( ) , playListName , QString : : number ( + + counter ) , ( useUtf8 ? " m3u8 " : " m3u " ) ) ;
2010-11-20 22:14:10 +01:00
}
2010-12-10 21:24:42 +01:00
2011-06-02 02:11:47 +02:00
//Now write playlist to output file
2010-11-20 22:14:10 +01:00
QFile playList ( playListFile ) ;
if ( playList . open ( QIODevice : : WriteOnly ) )
{
2011-06-02 02:11:47 +02:00
if ( useUtf8 )
{
playList . write ( " \xef \xbb \xbf " ) ;
}
2010-11-20 22:14:10 +01:00
playList . write ( " #EXTM3U \r \n " ) ;
2011-06-02 02:11:47 +02:00
while ( ! list . isEmpty ( ) )
2010-11-20 22:14:10 +01:00
{
2011-06-02 02:11:47 +02:00
playList . write ( useUtf8 ? list . takeFirst ( ) . toUtf8 ( ) . constData ( ) : list . takeFirst ( ) . toLatin1 ( ) . constData ( ) ) ;
2010-11-20 22:14:10 +01:00
playList . write ( " \r \n " ) ;
}
playList . close ( ) ;
}
2010-11-21 21:51:22 +01:00
else
{
2011-01-02 01:09:05 +01:00
QMessageBox : : warning ( this , tr ( " Playlist creation failed " ) , QString ( " %1<br><nobr>%2</nobr> " ) . arg ( tr ( " The playlist file could not be created: " ) , playListFile ) ) ;
2010-11-21 21:51:22 +01:00
}
2010-11-20 22:14:10 +01:00
}
2013-10-12 22:55:41 +02:00
AudioFileModel ProcessingDialog : : updateMetaInfo ( AudioFileModel & audioFile )
2010-11-20 19:16:04 +01:00
{
if ( ! m_settings - > writeMetaTags ( ) )
{
2013-10-12 22:55:41 +02:00
audioFile . metaInfo ( ) . reset ( ) ;
return audioFile ;
2010-11-20 19:16:04 +01:00
}
2013-10-13 20:50:12 +02:00
audioFile . metaInfo ( ) . update ( * m_metaInfo , true ) ;
2011-02-06 23:43:26 +01:00
2013-10-12 22:55:41 +02:00
if ( audioFile . metaInfo ( ) . position ( ) = = UINT_MAX )
2011-02-06 23:43:26 +01:00
{
2013-10-12 22:55:41 +02:00
audioFile . metaInfo ( ) . setPosition ( m_currentFile ) ;
2011-02-06 23:43:26 +01:00
}
2010-11-20 19:16:04 +01:00
2013-10-12 22:55:41 +02:00
return audioFile ;
2010-11-20 19:16:04 +01:00
}
2010-12-10 22:17:44 +01:00
void ProcessingDialog : : systemTrayActivated ( QSystemTrayIcon : : ActivationReason reason )
{
if ( reason = = QSystemTrayIcon : : DoubleClick )
{
2013-10-07 00:01:15 +02:00
lamexp_bring_to_front ( this ) ;
2010-12-10 22:17:44 +01:00
}
}
2011-03-18 01:12:17 +01:00
2011-10-29 16:26:09 +02:00
void ProcessingDialog : : cpuUsageHasChanged ( const double val )
{
2012-12-08 00:21:10 +01:00
ui - > label_cpu - > setText ( QString ( ) . sprintf ( " %d%% " , qRound ( val * 100.0 ) ) ) ;
UPDATE_MIN_WIDTH ( ui - > label_cpu ) ;
2011-10-29 16:26:09 +02:00
}
void ProcessingDialog : : ramUsageHasChanged ( const double val )
{
2012-12-08 00:21:10 +01:00
ui - > label_ram - > setText ( QString ( ) . sprintf ( " %d%% " , qRound ( val * 100.0 ) ) ) ;
UPDATE_MIN_WIDTH ( ui - > label_ram ) ;
2011-10-29 16:26:09 +02:00
}
void ProcessingDialog : : diskUsageHasChanged ( const quint64 val )
{
int postfix = 0 ;
const char * postfixStr [ 6 ] = { " B " , " KB " , " MB " , " GB " , " TB " , " PB " } ;
double space = static_cast < double > ( val ) ;
while ( ( space > = 1000.0 ) & & ( postfix < 5 ) )
{
space = space / 1024.0 ;
postfix + + ;
}
2012-12-08 00:21:10 +01:00
ui - > label_disk - > setText ( QString ( ) . sprintf ( " %3.1f %s " , space , postfixStr [ postfix ] ) ) ;
UPDATE_MIN_WIDTH ( ui - > label_disk ) ;
2011-10-29 16:26:09 +02:00
}
2011-03-18 12:37:18 +01:00
bool ProcessingDialog : : shutdownComputer ( void )
2011-03-18 01:12:17 +01:00
{
2011-10-23 18:05:27 +02:00
const int iTimeout = m_settings - > hibernateComputer ( ) ? 10 : 30 ;
2011-03-18 01:12:17 +01:00
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... " ) ) ;
2011-03-18 12:37:18 +01:00
qWarning ( " Initiating shutdown sequence! " ) ;
2011-03-18 01:12:17 +01:00
QProgressDialog progressDialog ( text . arg ( iTimeout ) , tr ( " Cancel Shutdown " ) , 0 , iTimeout + 1 , this , flags ) ;
2011-03-28 21:58:01 +02:00
QPushButton * cancelButton = new QPushButton ( tr ( " Cancel Shutdown " ) , & progressDialog ) ;
cancelButton - > setIcon ( QIcon ( " :/icons/power_on.png " ) ) ;
2011-03-18 01:12:17 +01:00
progressDialog . setModal ( true ) ;
progressDialog . setAutoClose ( false ) ;
progressDialog . setAutoReset ( false ) ;
2011-03-28 21:58:01 +02:00
progressDialog . setWindowIcon ( QIcon ( " :/icons/power_off.png " ) ) ;
progressDialog . setCancelButton ( cancelButton ) ;
2011-03-18 01:12:17 +01:00
progressDialog . show ( ) ;
2013-10-12 20:34:59 +02:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2011-03-18 01:12:17 +01:00
if ( m_settings - > soundsEnabled ( ) )
{
2011-03-18 12:37:18 +01:00
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
2013-10-07 00:01:15 +02:00
lamexp_play_sound ( IDR_WAVE_SHUTDOWN , false ) ;
2011-03-18 12:37:18 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2011-03-18 01:12:17 +01:00
}
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 ( ) ;
2011-03-18 12:37:18 +01:00
if ( progressDialog . wasCanceled ( ) )
{
progressDialog . close ( ) ;
return false ;
}
2011-03-18 01:12:17 +01:00
progressDialog . setValue ( i + 1 ) ;
progressDialog . setLabelText ( text . arg ( iTimeout - i ) ) ;
2011-03-28 21:58:01 +02:00
if ( iTimeout - i = = 3 ) progressDialog . setCancelButton ( NULL ) ;
2013-10-12 20:34:59 +02:00
qApp - > processEvents ( QEventLoop : : ExcludeUserInputEvents ) ;
2013-10-07 00:01:15 +02:00
lamexp_play_sound ( ( ( i < iTimeout ) ? IDR_WAVE_BEEP : IDR_WAVE_BEEP_LONG ) , false ) ;
2011-03-18 01:12:17 +01:00
}
progressDialog . close ( ) ;
2011-03-18 12:37:18 +01:00
return true ;
2011-11-26 15:30:24 +01:00
}
2011-11-28 00:35:43 +01:00
QString ProcessingDialog : : time2text ( const double timeVal ) const
{
double intPart = 0 ;
double frcPart = modf ( timeVal , & intPart ) ;
QTime time = QTime ( ) . addSecs ( qRound ( intPart ) ) . addMSecs ( qRound ( frcPart * 1000.0 ) ) ;
2013-01-23 23:25:31 +01:00
QString a , b ;
2011-11-28 00:35:43 +01:00
if ( time . hour ( ) > 0 )
{
2013-01-23 23:25:31 +01:00
a = tr ( " %n hour(s) " , " " , time . hour ( ) ) ;
b = tr ( " %n minute(s) " , " " , time . minute ( ) ) ;
2011-11-28 00:35:43 +01:00
}
else if ( time . minute ( ) > 0 )
{
2013-01-23 23:25:31 +01:00
a = tr ( " %n minute(s) " , " " , time . minute ( ) ) ;
b = tr ( " %n second(s) " , " " , time . second ( ) ) ;
2011-11-28 00:35:43 +01:00
}
else
{
2013-01-23 23:25:31 +01:00
a = tr ( " %n second(s) " , " " , time . second ( ) ) ;
b = tr ( " %n millisecond(s) " , " " , time . msec ( ) ) ;
2011-11-28 00:35:43 +01:00
}
2013-01-23 23:25:31 +01:00
return QString ( " %1, %2 " ) . arg ( a , b ) ;
2011-11-28 00:35:43 +01:00
}
2011-11-26 15:30:24 +01:00
////////////////////////////////////////////////////////////
// HELPER FUNCTIONS
////////////////////////////////////////////////////////////
static int cores2instances ( int cores )
{
2011-11-27 02:06:03 +01:00
//This function is a "cubic spline" with sampling points at:
//(1,1); (2,2); (4,4); (8,6); (16,8); (32,11); (64,16)
2011-11-26 17:25:33 +01:00
static const double LUT [ 8 ] [ 5 ] =
{
2011-11-27 02:06:03 +01:00
{ 1.0 , 0.014353554 , - 0.043060662 , 1.028707108 , 0.000000000 } ,
{ 2.0 , - 0.028707108 , 0.215303309 , 0.511979167 , 0.344485294 } ,
{ 4.0 , 0.010016468 , - 0.249379596 , 2.370710784 , - 2.133823529 } ,
{ 8.0 , 0.000282437 , - 0.015762868 , 0.501776961 , 2.850000000 } ,
{ 16.0 , 0.000033270 , - 0.003802849 , 0.310416667 , 3.870588235 } ,
{ 32.0 , 0.000006343 , - 0.001217831 , 0.227696078 , 4.752941176 } ,
{ 64.0 , 0.000000000 , 0.000000000 , 0.000000000 , 16.000000000 } ,
{ DBL_MAX , 0.0 , 0.0 , 0.0 , 0.0 }
2011-11-26 17:25:33 +01:00
} ;
double x = abs ( static_cast < double > ( cores ) ) , y = 1.0 ;
for ( size_t i = 0 ; i < 7 ; i + + )
2011-11-26 15:30:24 +01:00
{
2011-11-26 17:25:33 +01:00
if ( ( x > = LUT [ i ] [ 0 ] ) & & ( x < LUT [ i + 1 ] [ 0 ] ) )
2011-11-26 15:30:24 +01:00
{
2011-11-28 15:38:45 +01:00
y = ( ( ( ( ( LUT [ i ] [ 1 ] * x ) + LUT [ i ] [ 2 ] ) * x ) + LUT [ i ] [ 3 ] ) * x ) + LUT [ i ] [ 4 ] ;
2011-11-26 17:25:33 +01:00
break ;
2011-11-26 15:30:24 +01:00
}
}
return qRound ( y ) ;
}