2010-11-17 19:35:50 +01:00
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
2011-01-01 17:04:25 +01:00
// Copyright (C) 2004-2011 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"
# 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-03-28 04:26:47 +02:00
# include "Thread_DiskObserver.h"
2010-11-22 21:45:00 +01:00
# include "Dialog_LogView.h"
2010-11-26 00:29:53 +01:00
# include "Encoder_MP3.h"
# include "Encoder_Vorbis.h"
2010-12-03 23:01:17 +01:00
# include "Encoder_AAC.h"
2011-05-04 01:15:05 +02:00
# include "Encoder_AC3.h"
2010-12-14 23:53:14 +01:00
# include "Encoder_FLAC.h"
2010-12-17 01:12:12 +01:00
# include "Encoder_Wave.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>
2010-11-20 22:14:10 +01:00
2011-04-11 21:55:34 +02:00
# include <MMSystem.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
# define MAX_INSTANCES 16
//Maximum number of CPU cores for auto-detection
# define MAX_CPU_COUNT 4
////////////////////////////////////////////////////////////
2010-12-02 23:26:30 +01:00
# define CHANGE_BACKGROUND_COLOR(WIDGET, COLOR) \
{ \
QPalette palette = WIDGET - > palette ( ) ; \
palette . setColor ( QPalette : : Background , COLOR ) ; \
WIDGET - > setPalette ( palette ) ; \
}
2010-12-10 22:17:44 +01:00
# define SET_PROGRESS_TEXT(TXT) \
{ \
label_progress - > setText ( TXT ) ; \
m_systemTray - > setToolTip ( QString ( ) . sprintf ( " LameXP v%d.%02d \n %ls " , lamexp_version_major ( ) , lamexp_version_minor ( ) , QString ( TXT ) . utf16 ( ) ) ) ; \
}
2011-02-14 19:03:36 +01:00
# define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
2010-11-18 00:32:46 +01:00
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
2010-11-17 19:35:50 +01:00
2010-11-20 19:16:04 +01:00
ProcessingDialog : : ProcessingDialog ( FileListModel * fileListModel , AudioFileModel * metaInfo , SettingsModel * settings , QWidget * parent )
2010-11-20 02:14:22 +01:00
:
2010-11-20 19:16:04 +01:00
QDialog ( parent ) ,
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-03-28 04:26:47 +02:00
m_shutdownFlag ( false ) ,
m_diskObserver ( NULL )
2010-11-17 19:35:50 +01:00
{
//Init the dialog, from the .ui file
setupUi ( this ) ;
setWindowFlags ( windowFlags ( ) ^ Qt : : WindowContextHelpButtonHint ) ;
2010-11-18 22:37:35 +01:00
//Setup version info
2010-11-17 19:35:50 +01:00
label_versionInfo - > setText ( QString ( ) . sprintf ( " v%d.%02d %s (Build %d) " , lamexp_version_major ( ) , lamexp_version_minor ( ) , lamexp_version_release ( ) , lamexp_version_build ( ) ) ) ;
2010-11-18 00:32:46 +01:00
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
connect ( button_AbortProcess , SIGNAL ( clicked ( ) ) , this , SLOT ( abortEncoding ( ) ) ) ;
2010-11-17 19:35:50 +01:00
//Init progress indicator
m_progressIndicator = new QMovie ( " :/images/Working.gif " ) ;
label_headerWorking - > setMovie ( m_progressIndicator ) ;
2010-11-18 00:32:46 +01:00
progressBar - > setValue ( 0 ) ;
//Init progress model
m_progressModel = new ProgressModel ( ) ;
view_log - > setModel ( m_progressModel ) ;
view_log - > verticalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
view_log - > verticalHeader ( ) - > hide ( ) ;
view_log - > horizontalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
view_log - > horizontalHeader ( ) - > setResizeMode ( 0 , QHeaderView : : Stretch ) ;
2010-11-21 21:51:22 +01:00
connect ( m_progressModel , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( progressModelChanged ( ) ) ) ;
connect ( m_progressModel , SIGNAL ( modelReset ( ) ) , this , SLOT ( progressModelChanged ( ) ) ) ;
2010-11-26 00:29:53 +01:00
connect ( view_log , SIGNAL ( activated ( QModelIndex ) ) , this , SLOT ( logViewDoubleClicked ( QModelIndex ) ) ) ;
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 " ) ) ;
2010-11-24 21:00:59 +01:00
view_log - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( 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 ( ) ) ) ;
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
label_headerStatus - > setText ( QString ( " <b>%1</b><br>%2 " ) . arg ( tr ( " Encoding Files " ) , tr ( " Your files are being encoded, please be patient... " ) ) ) ;
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 ( ) ;
2010-11-19 21:11:54 +01:00
m_userAborted = false ;
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 )
{
2010-11-18 00:32:46 +01:00
view_log - > setModel ( NULL ) ;
2011-03-28 04:26:47 +02:00
if ( m_progressIndicator )
{
m_progressIndicator - > stop ( ) ;
}
if ( m_diskObserver )
{
m_diskObserver - > stop ( ) ;
m_diskObserver - > wait ( 15000 ) ;
}
2010-11-17 19:35:50 +01:00
LAMEXP_DELETE ( m_progressIndicator ) ;
2010-11-18 00:32:46 +01:00
LAMEXP_DELETE ( m_progressModel ) ;
2010-11-24 21:00:59 +01:00
LAMEXP_DELETE ( m_contextMenu ) ;
2010-12-10 22:17:44 +01:00
LAMEXP_DELETE ( m_systemTray ) ;
2011-03-28 04:26:47 +02:00
LAMEXP_DELETE ( m_diskObserver ) ;
2010-11-19 21:11:54 +01:00
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setOverlayIcon ( this , NULL ) ;
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarNoState ) ;
2010-11-19 21:11:54 +01:00
while ( ! m_threadList . isEmpty ( ) )
{
2010-11-20 02:14:22 +01:00
ProcessThread * thread = m_threadList . takeFirst ( ) ;
thread - > terminate ( ) ;
thread - > wait ( 15000 ) ;
delete thread ;
2010-11-19 21:11:54 +01:00
}
2010-11-18 00:32:46 +01:00
}
////////////////////////////////////////////////////////////
// EVENTS
////////////////////////////////////////////////////////////
void ProcessingDialog : : showEvent ( QShowEvent * event )
{
setCloseButtonEnabled ( false ) ;
button_closeDialog - > setEnabled ( false ) ;
button_AbortProcess - > setEnabled ( false ) ;
2010-12-10 22:17:44 +01:00
m_systemTray - > setVisible ( true ) ;
2010-11-25 16:56:32 +01:00
if ( ! SetPriorityClass ( GetCurrentProcess ( ) , ABOVE_NORMAL_PRIORITY_CLASS ) )
{
SetPriorityClass ( GetCurrentProcess ( ) , HIGH_PRIORITY_CLASS ) ;
}
2010-11-18 00:32:46 +01:00
QTimer : : singleShot ( 1000 , this , SLOT ( initEncoding ( ) ) ) ;
}
void ProcessingDialog : : closeEvent ( QCloseEvent * event )
{
2010-12-10 22:17:44 +01:00
if ( ! button_closeDialog - > isEnabled ( ) )
{
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 ( ) ;
if ( obj = = label_versionInfo )
{
if ( event - > type ( ) = = QEvent : : Enter )
{
QPalette palette = label_versionInfo - > palette ( ) ;
defaultColor = palette . color ( QPalette : : Normal , QPalette : : WindowText ) ;
palette . setColor ( QPalette : : Normal , QPalette : : WindowText , Qt : : red ) ;
label_versionInfo - > setPalette ( palette ) ;
}
else if ( event - > type ( ) = = QEvent : : Leave )
{
QPalette palette = label_versionInfo - > palette ( ) ;
palette . setColor ( QPalette : : Normal , QPalette : : WindowText , defaultColor ) ;
label_versionInfo - > setPalette ( palette ) ;
}
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 ;
}
////////////////////////////////////////////////////////////
// SLOTS
////////////////////////////////////////////////////////////
void ProcessingDialog : : initEncoding ( void )
{
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 ( ) ;
2010-11-19 21:11:54 +01:00
m_userAborted = false ;
2010-11-20 22:14:10 +01:00
m_playList . clear ( ) ;
2010-11-19 21:11:54 +01:00
2010-12-02 23:26:30 +01:00
CHANGE_BACKGROUND_COLOR ( 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 ( ) ;
button_closeDialog - > setEnabled ( false ) ;
button_AbortProcess - > setEnabled ( true ) ;
2010-11-19 21:11:54 +01:00
progressBar - > setRange ( 0 , m_pendingJobs . count ( ) ) ;
2011-03-18 01:12:17 +01:00
checkBox_shutdownComputer - > setEnabled ( true ) ;
checkBox_shutdownComputer - > setChecked ( false ) ;
2010-11-19 21:11:54 +01:00
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : initTaskbar ( ) ;
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 ( ) ) ;
connect ( m_diskObserver , SIGNAL ( messageLogged ( QString , bool ) ) , m_progressModel , SLOT ( addSystemMessage ( QString , bool ) ) , Qt : : QueuedConnection ) ;
m_diskObserver - > start ( ) ;
}
2011-02-28 01:28:27 +01:00
int maximumInstances = max ( min ( m_settings - > maximumInstances ( ) , MAX_INSTANCES ) , 0 ) ;
2011-02-25 00:22:18 +01:00
if ( maximumInstances < 1 )
{
lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features ( ) ;
2011-02-28 01:28:27 +01:00
maximumInstances = max ( min ( cpuFeatures . count , MAX_CPU_COUNT ) , 1 ) ;
2011-02-25 00:22:18 +01:00
}
2010-11-24 21:00:59 +01:00
2011-02-25 00:22:18 +01:00
int parallelThreadCount = max ( min ( maximumInstances , m_pendingJobs . count ( ) ) , 1 ) ;
2011-02-02 22:56:45 +01:00
if ( parallelThreadCount > 1 )
{
m_progressModel - > addSystemMessage ( tr ( " Multi-threading enabled: Running %1 instances in parallel! " ) . arg ( QString : : number ( parallelThreadCount ) ) ) ;
}
for ( int i = 0 ; i < parallelThreadCount ; i + + )
2010-11-24 21:00:59 +01:00
{
startNextJob ( ) ;
}
2010-11-18 00:32:46 +01:00
}
void ProcessingDialog : : abortEncoding ( void )
{
2010-11-19 21:11:54 +01:00
m_userAborted = true ;
2010-11-18 00:32:46 +01:00
button_AbortProcess - > setEnabled ( false ) ;
2011-01-02 01:09:05 +01:00
SET_PROGRESS_TEXT ( tr ( " Aborted! Waiting for running jobs to terminate... " ) ) ;
2010-12-02 23:26:30 +01:00
2010-11-19 21:11:54 +01:00
for ( int i = 0 ; i < m_threadList . count ( ) ; i + + )
2010-11-18 00:32:46 +01:00
{
2010-11-19 21:11:54 +01:00
m_threadList . at ( i ) - > abort ( ) ;
2010-11-18 00:32:46 +01:00
}
}
void ProcessingDialog : : doneEncoding ( void )
{
2010-11-19 21:11:54 +01:00
m_runningThreads - - ;
2010-11-18 00:32:46 +01:00
progressBar - > setValue ( progressBar - > value ( ) + 1 ) ;
2010-12-02 23:26:30 +01:00
if ( ! m_userAborted )
{
2011-01-02 01:09:05 +01:00
SET_PROGRESS_TEXT ( tr ( " Encoding: %1 files of %2 completed so far, please wait... " ) . arg ( QString : : number ( progressBar - > value ( ) ) , QString : : number ( progressBar - > maximum ( ) ) ) ) ;
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setTaskbarProgress ( this , progressBar - > value ( ) , progressBar - > maximum ( ) ) ;
2010-12-02 23:26:30 +01:00
}
2010-11-18 00:32:46 +01:00
2010-11-20 02:14:22 +01:00
int index = m_threadList . indexOf ( dynamic_cast < ProcessThread * > ( QWidget : : sender ( ) ) ) ;
if ( index > = 0 )
{
m_threadList . takeAt ( index ) - > deleteLater ( ) ;
}
2010-11-19 21:11:54 +01:00
if ( ! m_pendingJobs . isEmpty ( ) & & ! m_userAborted )
2010-11-18 00:32:46 +01:00
{
2010-11-19 21:11:54 +01:00
startNextJob ( ) ;
qDebug ( " Running jobs: %u " , m_runningThreads ) ;
2010-11-18 00:32:46 +01:00
return ;
}
2010-11-19 21:11:54 +01:00
if ( m_runningThreads > 0 )
{
qDebug ( " Running jobs: %u " , m_runningThreads ) ;
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 ) ;
2010-11-21 21:51:22 +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... " ) ) ;
2010-11-20 22:14:10 +01:00
QApplication : : processEvents ( ) ;
writePlayList ( ) ;
}
2010-11-21 21:51:22 +01:00
if ( m_userAborted )
{
2010-12-02 23:26:30 +01:00
CHANGE_BACKGROUND_COLOR ( frame_header , QColor ( " #FFF3BA " ) ) ;
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this , & QIcon ( " :/icons/error.png " ) ) ;
2011-01-14 19:45:14 +01:00
SET_PROGRESS_TEXT ( ( m_succeededJobs . count ( ) > 0 ) ? tr ( " Process was aborted by the user after %1 file(s)! " ) . arg ( QString : : number ( 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 " ) ) ;
2010-11-25 18:28:42 +01:00
QApplication : : processEvents ( ) ;
2010-11-29 20:36:27 +01:00
if ( m_settings - > soundsEnabled ( ) ) PlaySound ( MAKEINTRESOURCE ( IDR_WAVE_ABORTED ) , GetModuleHandle ( NULL ) , SND_RESOURCE | SND_SYNC ) ;
2010-11-21 21:51:22 +01:00
}
else
{
2010-12-10 21:24:42 +01:00
if ( m_failedJobs . count ( ) > 0 )
2010-11-21 21:51:22 +01:00
{
2010-12-02 23:26:30 +01:00
CHANGE_BACKGROUND_COLOR ( frame_header , QColor ( " #FFBABA " ) ) ;
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarErrorState ) ;
WinSevenTaskbar : : setOverlayIcon ( this , & QIcon ( " :/icons/exclamation.png " ) ) ;
2011-01-02 01:09:05 +01:00
SET_PROGRESS_TEXT ( tr ( " Error: %1 of %2 files failed. Double-click failed items for detailed information! " ) . arg ( QString : : number ( m_failedJobs . count ( ) ) , QString : : number ( m_failedJobs . count ( ) + m_succeededJobs . count ( ) ) ) ) ;
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 " ) ) ;
2010-11-25 18:28:42 +01:00
QApplication : : processEvents ( ) ;
2010-11-29 20:36:27 +01:00
if ( m_settings - > soundsEnabled ( ) ) PlaySound ( MAKEINTRESOURCE ( IDR_WAVE_ERROR ) , GetModuleHandle ( NULL ) , SND_RESOURCE | SND_SYNC ) ;
2010-11-21 21:51:22 +01:00
}
else
{
2010-12-19 00:50:22 +01:00
CHANGE_BACKGROUND_COLOR ( frame_header , QColor ( " #E0FFE2 " ) ) ;
2010-12-05 23:11:03 +01:00
WinSevenTaskbar : : setTaskbarState ( this , WinSevenTaskbar : : WinSevenTaskbarNormalState ) ;
WinSevenTaskbar : : setOverlayIcon ( this , & QIcon ( " :/icons/accept.png " ) ) ;
2011-02-21 13:22:00 +01:00
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 " ) ) ;
2010-11-25 18:28:42 +01:00
QApplication : : processEvents ( ) ;
2010-11-29 20:36:27 +01:00
if ( m_settings - > soundsEnabled ( ) ) PlaySound ( MAKEINTRESOURCE ( IDR_WAVE_SUCCESS ) , GetModuleHandle ( NULL ) , SND_RESOURCE | SND_SYNC ) ;
2010-11-21 21:51:22 +01:00
}
}
2010-11-18 00:32:46 +01:00
setCloseButtonEnabled ( true ) ;
button_closeDialog - > setEnabled ( true ) ;
button_AbortProcess - > setEnabled ( false ) ;
2011-03-18 01:12:17 +01:00
checkBox_shutdownComputer - > setEnabled ( false ) ;
2010-11-18 00:32:46 +01:00
2011-06-13 18:59:21 +02:00
m_progressModel - > restoreHiddenItems ( ) ;
2010-11-25 18:09:31 +01:00
view_log - > scrollToBottom ( ) ;
2010-11-21 21:51:22 +01:00
m_progressIndicator - > stop ( ) ;
2010-12-05 23:11:03 +01:00
progressBar - > setValue ( progressBar - > maximum ( ) ) ;
WinSevenTaskbar : : setTaskbarProgress ( this , progressBar - > value ( ) , progressBar - > maximum ( ) ) ;
2010-11-25 20:41:59 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2011-03-18 01:12:17 +01:00
if ( ! m_userAborted & & checkBox_shutdownComputer - > isChecked ( ) )
{
2011-03-18 12:37:18 +01:00
if ( shutdownComputer ( ) )
{
m_shutdownFlag = true ;
accept ( ) ;
}
2011-03-18 01:12:17 +01:00
}
2010-11-18 00:32:46 +01:00
}
2010-11-20 22:14:10 +01:00
void ProcessingDialog : : processFinished ( const QUuid & jobId , const QString & outFileName , bool success )
{
if ( success )
{
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
}
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
}
}
void ProcessingDialog : : progressModelChanged ( void )
{
view_log - > 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
{
MessageBeep ( MB_ICONWARNING ) ;
}
2010-11-22 21:45:00 +01:00
}
2010-11-24 21:00:59 +01:00
else
{
MessageBeep ( MB_ICONWARNING ) ;
}
}
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
{
QModelIndex index = view_log - > indexAt ( view_log - > mapFromGlobal ( m_contextMenu - > pos ( ) ) ) ;
logViewDoubleClicked ( index . isValid ( ) ? index : view_log - > currentIndex ( ) ) ;
2010-11-22 21:45:00 +01:00
}
2011-02-11 23:16:11 +01:00
void ProcessingDialog : : contextMenuShowFileActionTriggered ( void )
{
QModelIndex index = view_log - > indexAt ( view_log - > mapFromGlobal ( m_contextMenu - > pos ( ) ) ) ;
const QUuid & jobId = m_progressModel - > getJobId ( index . isValid ( ) ? index : view_log - > currentIndex ( ) ) ;
QString filePath = m_playList . value ( jobId , QString ( ) ) ;
if ( filePath . isEmpty ( ) )
{
MessageBeep ( MB_ICONWARNING ) ;
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 ( ) ) ;
MessageBeep ( MB_ICONERROR ) ;
}
}
2010-11-18 00:32:46 +01:00
////////////////////////////////////////////////////////////
// Private Functions
////////////////////////////////////////////////////////////
2010-11-19 21:11:54 +01:00
void ProcessingDialog : : startNextJob ( void )
{
if ( m_pendingJobs . isEmpty ( ) )
{
return ;
}
2010-11-20 19:16:04 +01:00
m_currentFile + + ;
AudioFileModel currentFile = updateMetaInfo ( m_pendingJobs . takeFirst ( ) ) ;
2010-11-20 02:14:22 +01:00
AbstractEncoder * encoder = NULL ;
2011-01-26 20:16:46 +01:00
bool nativeResampling = false ;
2010-12-14 23:53:14 +01:00
2010-11-20 02:14:22 +01:00
switch ( m_settings - > compressionEncoder ( ) )
{
case SettingsModel : : MP3Encoder :
{
MP3Encoder * mp3Encoder = new MP3Encoder ( ) ;
mp3Encoder - > setBitrate ( m_settings - > compressionBitrate ( ) ) ;
mp3Encoder - > setRCMode ( m_settings - > compressionRCMode ( ) ) ;
2011-01-21 19:14:11 +01:00
mp3Encoder - > setAlgoQuality ( m_settings - > lameAlgoQuality ( ) ) ;
2011-01-21 23:25:55 +01:00
if ( m_settings - > bitrateManagementEnabled ( ) )
{
mp3Encoder - > setBitrateLimits ( m_settings - > bitrateManagementMinRate ( ) , m_settings - > bitrateManagementMaxRate ( ) ) ;
}
2011-01-26 20:16:46 +01:00
if ( m_settings - > samplingRate ( ) > 0 )
{
mp3Encoder - > setSamplingRate ( SettingsModel : : samplingRates [ m_settings - > samplingRate ( ) ] ) ;
nativeResampling = true ;
}
2011-01-23 02:19:18 +01:00
mp3Encoder - > setChannelMode ( m_settings - > lameChannelMode ( ) ) ;
2011-02-09 23:36:17 +01:00
mp3Encoder - > setCustomParams ( m_settings - > customParametersLAME ( ) ) ;
2010-11-20 02:14:22 +01:00
encoder = mp3Encoder ;
}
break ;
2010-11-26 00:29:53 +01:00
case SettingsModel : : VorbisEncoder :
{
VorbisEncoder * vorbisEncoder = new VorbisEncoder ( ) ;
vorbisEncoder - > setBitrate ( m_settings - > compressionBitrate ( ) ) ;
vorbisEncoder - > setRCMode ( m_settings - > compressionRCMode ( ) ) ;
2011-01-21 23:25:55 +01:00
if ( m_settings - > bitrateManagementEnabled ( ) )
{
vorbisEncoder - > setBitrateLimits ( m_settings - > bitrateManagementMinRate ( ) , m_settings - > bitrateManagementMaxRate ( ) ) ;
}
2011-01-26 20:16:46 +01:00
if ( m_settings - > samplingRate ( ) > 0 )
{
vorbisEncoder - > setSamplingRate ( SettingsModel : : samplingRates [ m_settings - > samplingRate ( ) ] ) ;
nativeResampling = true ;
}
2011-02-09 23:36:17 +01:00
vorbisEncoder - > setCustomParams ( m_settings - > customParametersOggEnc ( ) ) ;
2010-11-26 00:29:53 +01:00
encoder = vorbisEncoder ;
}
break ;
2010-12-03 23:01:17 +01:00
case SettingsModel : : AACEncoder :
{
AACEncoder * aacEncoder = new AACEncoder ( ) ;
aacEncoder - > setBitrate ( m_settings - > compressionBitrate ( ) ) ;
aacEncoder - > setRCMode ( m_settings - > compressionRCMode ( ) ) ;
2011-01-23 02:19:18 +01:00
aacEncoder - > setEnable2Pass ( m_settings - > neroAACEnable2Pass ( ) ) ;
aacEncoder - > setProfile ( m_settings - > neroAACProfile ( ) ) ;
2011-02-09 23:36:17 +01:00
aacEncoder - > setCustomParams ( m_settings - > customParametersNeroAAC ( ) ) ;
2010-12-03 23:01:17 +01:00
encoder = aacEncoder ;
}
break ;
2011-05-04 01:15:05 +02:00
case SettingsModel : : AC3Encoder :
{
AC3Encoder * ac3Encoder = new AC3Encoder ( ) ;
ac3Encoder - > setBitrate ( m_settings - > compressionBitrate ( ) ) ;
ac3Encoder - > setRCMode ( m_settings - > compressionRCMode ( ) ) ;
2011-05-05 12:27:25 +02:00
ac3Encoder - > setCustomParams ( m_settings - > customParametersAften ( ) ) ;
2011-05-07 00:50:18 +02:00
ac3Encoder - > setAudioCodingMode ( m_settings - > aftenAudioCodingMode ( ) ) ;
ac3Encoder - > setDynamicRangeCompression ( m_settings - > aftenDynamicRangeCompression ( ) ) ;
ac3Encoder - > setExponentSearchSize ( m_settings - > aftenExponentSearchSize ( ) ) ;
ac3Encoder - > setFastBitAllocation ( m_settings - > aftenFastBitAllocation ( ) ) ;
2011-05-04 01:15:05 +02:00
encoder = ac3Encoder ;
}
break ;
2010-12-14 23:53:14 +01:00
case SettingsModel : : FLACEncoder :
{
FLACEncoder * flacEncoder = new FLACEncoder ( ) ;
flacEncoder - > setBitrate ( m_settings - > compressionBitrate ( ) ) ;
flacEncoder - > setRCMode ( m_settings - > compressionRCMode ( ) ) ;
2011-02-09 23:36:17 +01:00
flacEncoder - > setCustomParams ( m_settings - > customParametersFLAC ( ) ) ;
2010-12-14 23:53:14 +01:00
encoder = flacEncoder ;
}
break ;
2010-12-17 01:12:12 +01:00
case SettingsModel : : PCMEncoder :
{
WaveEncoder * waveEncoder = new WaveEncoder ( ) ;
waveEncoder - > setBitrate ( m_settings - > compressionBitrate ( ) ) ;
waveEncoder - > setRCMode ( m_settings - > compressionRCMode ( ) ) ;
encoder = waveEncoder ;
}
break ;
2010-11-20 02:14:22 +01:00
default :
throw " Unsupported encoder! " ;
}
2010-11-21 21:51:22 +01:00
2010-12-14 01:25:13 +01:00
ProcessThread * thread = new ProcessThread
(
currentFile ,
2011-02-25 22:03:39 +01:00
( m_settings - > outputToSourceDir ( ) ? QFileInfo ( currentFile . filePath ( ) ) . absolutePath ( ) : m_settings - > outputDir ( ) ) ,
( m_settings - > customTempPathEnabled ( ) ? m_settings - > customTempPath ( ) : lamexp_temp_folder2 ( ) ) ,
2010-12-14 01:25:13 +01:00
encoder ,
m_settings - > prependRelativeSourcePath ( )
) ;
2011-01-25 23:12:56 +01:00
2011-01-26 20:16:46 +01:00
if ( ( m_settings - > samplingRate ( ) > 0 ) & & ! nativeResampling )
{
2011-02-20 20:19:48 +01:00
if ( SettingsModel : : samplingRates [ m_settings - > samplingRate ( ) ] ! = currentFile . formatAudioSamplerate ( ) | | currentFile . formatAudioSamplerate ( ) = = 0 )
{
thread - > addFilter ( new ResampleFilter ( SettingsModel : : samplingRates [ m_settings - > samplingRate ( ) ] ) ) ;
}
2011-01-26 20:16:46 +01:00
}
if ( ( m_settings - > toneAdjustBass ( ) ! = 0 ) | | ( m_settings - > toneAdjustTreble ( ) ! = 0 ) )
{
thread - > addFilter ( new ToneAdjustFilter ( m_settings - > toneAdjustBass ( ) , m_settings - > toneAdjustTreble ( ) ) ) ;
}
2011-01-25 23:12:56 +01:00
if ( m_settings - > normalizationFilterEnabled ( ) )
{
thread - > addFilter ( new NormalizeFilter ( m_settings - > normalizationFilterMaxVolume ( ) ) ) ;
}
2010-11-19 21:11:54 +01:00
m_threadList . append ( thread ) ;
2010-12-10 21:24:42 +01:00
m_allJobs . append ( thread - > getId ( ) ) ;
2010-11-26 00:29:53 +01:00
2010-11-19 21:11:54 +01:00
connect ( thread , SIGNAL ( finished ( ) ) , 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 ) ;
2010-11-20 22:14:10 +01:00
connect ( thread , SIGNAL ( processStateFinished ( QUuid , QString , bool ) ) , this , SLOT ( processFinished ( QUuid , QString , bool ) ) , Qt : : QueuedConnection ) ;
2010-11-22 21:45:00 +01:00
connect ( thread , SIGNAL ( processMessageLogged ( QUuid , QString ) ) , m_progressModel , SLOT ( appendToLog ( QUuid , QString ) ) , Qt : : QueuedConnection ) ;
2010-11-26 00:29:53 +01:00
2010-11-19 21:11:54 +01:00
m_runningThreads + + ;
thread - > start ( ) ;
}
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
const static char * invalidChars = " \\ /:*? \" <>| " ;
QStringList list ;
bool useUtf8 = false ;
int counter = 1 ;
//Generate playlist name
2010-11-20 22:14:10 +01:00
QString playListName = ( m_metaInfo - > fileAlbum ( ) . isEmpty ( ) ? " Playlist " : m_metaInfo - > fileAlbum ( ) ) ;
2011-06-02 02:11:47 +02:00
if ( ! m_metaInfo - > fileArtist ( ) . isEmpty ( ) )
{
playListName = QString ( " %1 - %2 " ) . arg ( m_metaInfo - > fileArtist ( ) , playListName ) ;
}
2010-11-20 22:14:10 +01:00
2011-06-02 02:11:47 +02:00
//Clean playlist name
2010-11-20 22:14:10 +01:00
for ( int i = 0 ; invalidChars [ i ] ; i + + )
{
2011-06-02 02:11:47 +02:00
playListName = playListName . replace ( invalidChars [ i ] , ' ' ) . simplified ( ) ;
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 " ) ) ) ;
}
//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
}
2010-11-20 19:16:04 +01:00
AudioFileModel ProcessingDialog : : updateMetaInfo ( const AudioFileModel & audioFile )
{
if ( ! m_settings - > writeMetaTags ( ) )
{
2011-02-06 23:43:26 +01:00
return AudioFileModel ( audioFile , false ) ;
2010-11-20 19:16:04 +01:00
}
AudioFileModel result = audioFile ;
2011-02-06 23:43:26 +01:00
result . updateMetaInfo ( * m_metaInfo ) ;
if ( m_metaInfo - > filePosition ( ) = = UINT_MAX )
{
result . setFilePosition ( m_currentFile ) ;
}
2010-11-20 19:16:04 +01:00
return result ;
}
2010-11-18 00:32:46 +01:00
void ProcessingDialog : : setCloseButtonEnabled ( bool enabled )
{
HMENU hMenu = GetSystemMenu ( ( HWND ) winId ( ) , FALSE ) ;
EnableMenuItem ( hMenu , SC_CLOSE , MF_BYCOMMAND | ( enabled ? MF_ENABLED : MF_GRAYED ) ) ;
2010-11-17 19:35:50 +01:00
}
2010-12-10 22:17:44 +01:00
void ProcessingDialog : : systemTrayActivated ( QSystemTrayIcon : : ActivationReason reason )
{
if ( reason = = QSystemTrayIcon : : DoubleClick )
{
SetForegroundWindow ( this - > winId ( ) ) ;
}
}
2011-03-18 01:12:17 +01:00
2011-03-18 12:37:18 +01:00
bool ProcessingDialog : : shutdownComputer ( void )
2011-03-18 01:12:17 +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... " ) ) ;
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 ( ) ;
QApplication : : processEvents ( ) ;
if ( m_settings - > soundsEnabled ( ) )
{
2011-03-18 12:37:18 +01:00
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
2011-03-18 01:12:17 +01:00
PlaySound ( MAKEINTRESOURCE ( IDR_WAVE_SHUTDOWN ) , GetModuleHandle ( NULL ) , SND_RESOURCE | SND_SYNC ) ;
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 ) ;
2011-03-18 01:12:17 +01:00
QApplication : : processEvents ( ) ;
2011-03-18 12:37:18 +01:00
PlaySound ( MAKEINTRESOURCE ( ( i < iTimeout ) ? IDR_WAVE_BEEP : IDR_WAVE_BEEP_LONG ) , GetModuleHandle ( NULL ) , SND_RESOURCE | SND_SYNC ) ;
2011-03-18 01:12:17 +01:00
}
progressDialog . close ( ) ;
2011-03-18 12:37:18 +01:00
return true ;
2011-03-18 01:12:17 +01:00
}