2010-11-06 23:04:47 +01:00
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
// Copyright (C) 2004-2010 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
# include "Dialog_MainWindow.h"
//LameXP includes
# include "Global.h"
# include "Resource.h"
# include "Dialog_WorkingBanner.h"
# include "Dialog_MetaInfo.h"
2010-11-11 19:37:16 +01:00
# include "Dialog_About.h"
2010-11-27 19:41:58 +01:00
# include "Dialog_Update.h"
2010-11-06 23:04:47 +01:00
# include "Thread_FileAnalyzer.h"
2010-11-08 19:29:36 +01:00
# include "Thread_MessageHandler.h"
2010-11-10 19:44:51 +01:00
# include "Model_MetaInfo.h"
2010-11-12 19:02:01 +01:00
# include "Model_Settings.h"
2010-11-19 21:11:54 +01:00
# include "Model_FileList.h"
2010-11-25 01:23:48 +01:00
# include "Model_FileSystem.h"
2010-12-05 23:11:03 +01:00
# include "WinSevenTaskbar.h"
2010-11-06 23:04:47 +01:00
//Qt includes
# include <QMessageBox>
# include <QTimer>
# include <QDesktopWidget>
# include <QDate>
# include <QFileDialog>
# include <QInputDialog>
# include <QFileSystemModel>
# include <QDesktopServices>
# include <QUrl>
2010-11-08 00:24:54 +01:00
# include <QPlastiqueStyle>
# include <QCleanlooksStyle>
# include <QWindowsVistaStyle>
# include <QWindowsStyle>
2010-11-11 19:37:16 +01:00
# include <QSysInfo>
2010-11-12 23:31:04 +01:00
# include <QDragEnterEvent>
# include <QWindowsMime>
2010-11-15 21:07:58 +01:00
# include <QProcess>
2010-11-21 21:51:41 +01:00
# include <QUuid>
2010-11-25 20:41:59 +01:00
# include <QProcessEnvironment>
2010-11-06 23:04:47 +01:00
//Win32 includes
# include <Windows.h>
2010-11-10 19:44:51 +01:00
//Helper macros
2010-11-20 22:14:10 +01:00
# define ABORT_IF_BUSY if(m_banner->isVisible() || m_delayedFileTimer->isActive()) { MessageBeep(MB_ICONEXCLAMATION); return; }
# define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, COLOR); WIDGET->setPalette(_palette); }
# define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
2010-11-11 22:58:02 +01:00
# define LINK(URL) QString("<a href=\"%1\">%2< / a>").arg(URL).arg(URL)
2010-11-11 19:37:16 +01:00
2010-11-12 21:02:14 +01:00
//Helper class
class Index : public QObjectUserData
{
public :
Index ( int index ) { m_index = index ; }
int value ( void ) { return m_index ; }
private :
int m_index ;
} ;
2010-11-06 23:04:47 +01:00
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
2010-11-19 21:11:54 +01:00
MainWindow : : MainWindow ( FileListModel * fileListModel , AudioFileModel * metaInfo , SettingsModel * settingsModel , QWidget * parent )
:
QMainWindow ( parent ) ,
m_fileListModel ( fileListModel ) ,
m_metaData ( metaInfo ) ,
m_settings ( settingsModel ) ,
2010-11-20 22:14:10 +01:00
m_accepted ( false ) ,
m_firstTimeShown ( true )
2010-11-06 23:04:47 +01:00
{
//Init the dialog, from the .ui file
setupUi ( this ) ;
2010-11-15 04:42:06 +01:00
setWindowFlags ( windowFlags ( ) ^ Qt : : WindowMaximizeButtonHint ) ;
2010-11-06 23:04:47 +01:00
//Register meta types
qRegisterMetaType < AudioFileModel > ( " AudioFileModel " ) ;
//Update window title
if ( lamexp_version_demo ( ) )
{
setWindowTitle ( windowTitle ( ) . append ( " [DEMO VERSION] " ) ) ;
}
//Enabled main buttons
connect ( buttonAbout , SIGNAL ( clicked ( ) ) , this , SLOT ( aboutButtonClicked ( ) ) ) ;
connect ( buttonStart , SIGNAL ( clicked ( ) ) , this , SLOT ( encodeButtonClicked ( ) ) ) ;
2010-11-19 21:11:54 +01:00
connect ( buttonQuit , SIGNAL ( clicked ( ) ) , this , SLOT ( closeButtonClicked ( ) ) ) ;
2010-11-06 23:04:47 +01:00
//Setup tab widget
tabWidget - > setCurrentIndex ( 0 ) ;
connect ( tabWidget , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( tabPageChanged ( int ) ) ) ;
//Setup "Source" tab
sourceFileView - > setModel ( m_fileListModel ) ;
sourceFileView - > verticalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
sourceFileView - > horizontalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
2010-11-25 20:41:59 +01:00
sourceFileView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2010-11-20 02:14:22 +01:00
m_dropNoteLabel = new QLabel ( sourceFileView ) ;
m_dropNoteLabel - > setAlignment ( Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
m_dropNoteLabel - > setText ( " <EFBFBD> You can drop in audio files here! <20> " ) ;
2010-11-20 22:14:10 +01:00
SET_FONT_BOLD ( m_dropNoteLabel , true ) ;
SET_TEXT_COLOR ( m_dropNoteLabel , Qt : : darkGray ) ;
2010-11-25 20:41:59 +01:00
m_sourceFilesContextMenu = new QMenu ( ) ;
QAction * showDetailsContextAction = m_sourceFilesContextMenu - > addAction ( QIcon ( " :/icons/zoom.png " ) , " Show Details " ) ;
QAction * previewContextAction = m_sourceFilesContextMenu - > addAction ( QIcon ( " :/icons/sound.png " ) , " Open File in External Application " ) ;
QAction * findFileContextAction = m_sourceFilesContextMenu - > addAction ( QIcon ( " :/icons/folder_go.png " ) , " Browse File Location " ) ;
SET_FONT_BOLD ( showDetailsContextAction , true ) ;
2010-11-06 23:04:47 +01:00
connect ( buttonAddFiles , SIGNAL ( clicked ( ) ) , this , SLOT ( addFilesButtonClicked ( ) ) ) ;
connect ( buttonRemoveFile , SIGNAL ( clicked ( ) ) , this , SLOT ( removeFileButtonClicked ( ) ) ) ;
connect ( buttonClearFiles , SIGNAL ( clicked ( ) ) , this , SLOT ( clearFilesButtonClicked ( ) ) ) ;
connect ( buttonFileUp , SIGNAL ( clicked ( ) ) , this , SLOT ( fileUpButtonClicked ( ) ) ) ;
connect ( buttonFileDown , SIGNAL ( clicked ( ) ) , this , SLOT ( fileDownButtonClicked ( ) ) ) ;
2010-11-10 19:44:51 +01:00
connect ( buttonShowDetails , SIGNAL ( clicked ( ) ) , this , SLOT ( showDetailsButtonClicked ( ) ) ) ;
2010-11-21 21:51:41 +01:00
connect ( m_fileListModel , SIGNAL ( rowsInserted ( QModelIndex , int , int ) ) , this , SLOT ( sourceModelChanged ( ) ) ) ;
connect ( m_fileListModel , SIGNAL ( rowsRemoved ( QModelIndex , int , int ) ) , this , SLOT ( sourceModelChanged ( ) ) ) ;
connect ( m_fileListModel , SIGNAL ( modelReset ( ) ) , this , SLOT ( sourceModelChanged ( ) ) ) ;
2010-11-25 20:41:59 +01:00
connect ( sourceFileView , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( sourceFilesContextMenu ( QPoint ) ) ) ;
connect ( showDetailsContextAction , SIGNAL ( triggered ( bool ) ) , this , SLOT ( showDetailsButtonClicked ( ) ) ) ;
connect ( previewContextAction , SIGNAL ( triggered ( bool ) ) , this , SLOT ( previewContextActionTriggered ( ) ) ) ;
connect ( findFileContextAction , SIGNAL ( triggered ( bool ) ) , this , SLOT ( findFileContextActionTriggered ( ) ) ) ;
2010-11-06 23:04:47 +01:00
//Setup "Output" tab
2010-11-25 01:23:48 +01:00
m_fileSystemModel = new QFileSystemModelEx ( ) ;
2010-11-06 23:04:47 +01:00
m_fileSystemModel - > setRootPath ( m_fileSystemModel - > rootPath ( ) ) ;
2010-11-24 21:00:59 +01:00
m_fileSystemModel - > installEventFilter ( this ) ;
2010-11-06 23:04:47 +01:00
outputFolderView - > setModel ( m_fileSystemModel ) ;
outputFolderView - > header ( ) - > setStretchLastSection ( true ) ;
outputFolderView - > header ( ) - > hideSection ( 1 ) ;
outputFolderView - > header ( ) - > hideSection ( 2 ) ;
outputFolderView - > header ( ) - > hideSection ( 3 ) ;
outputFolderView - > setHeaderHidden ( true ) ;
outputFolderView - > setAnimated ( true ) ;
2010-11-25 20:41:59 +01:00
outputFolderView - > installEventFilter ( this ) ;
outputFolderView - > setMouseTracking ( false ) ;
2010-12-05 23:11:03 +01:00
outputFolderView - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
2010-11-21 21:51:41 +01:00
while ( saveToSourceFolderCheckBox - > isChecked ( ) ! = m_settings - > outputToSourceDir ( ) ) saveToSourceFolderCheckBox - > click ( ) ;
2010-11-06 23:04:47 +01:00
connect ( outputFolderView , SIGNAL ( clicked ( QModelIndex ) ) , this , SLOT ( outputFolderViewClicked ( QModelIndex ) ) ) ;
2010-11-25 20:41:59 +01:00
connect ( outputFolderView , SIGNAL ( activated ( QModelIndex ) ) , this , SLOT ( outputFolderViewClicked ( QModelIndex ) ) ) ;
connect ( outputFolderView , SIGNAL ( entered ( QModelIndex ) ) , this , SLOT ( outputFolderViewClicked ( QModelIndex ) ) ) ;
2010-11-20 02:14:22 +01:00
outputFolderView - > setCurrentIndex ( m_fileSystemModel - > index ( m_settings - > outputDir ( ) ) ) ;
2010-11-06 23:04:47 +01:00
outputFolderViewClicked ( outputFolderView - > currentIndex ( ) ) ;
connect ( buttonMakeFolder , SIGNAL ( clicked ( ) ) , this , SLOT ( makeFolderButtonClicked ( ) ) ) ;
connect ( buttonGotoHome , SIGNAL ( clicked ( ) ) , SLOT ( gotoHomeFolderButtonClicked ( ) ) ) ;
connect ( buttonGotoDesktop , SIGNAL ( clicked ( ) ) , this , SLOT ( gotoDesktopButtonClicked ( ) ) ) ;
connect ( buttonGotoMusic , SIGNAL ( clicked ( ) ) , this , SLOT ( gotoMusicFolderButtonClicked ( ) ) ) ;
2010-11-21 21:51:41 +01:00
connect ( saveToSourceFolderCheckBox , SIGNAL ( clicked ( ) ) , this , SLOT ( saveToSourceFolderChanged ( ) ) ) ;
2010-12-05 23:11:03 +01:00
m_outputFolderContextMenu = new QMenu ( ) ;
QAction * showFolderContextAction = m_outputFolderContextMenu - > addAction ( QIcon ( " :/icons/zoom.png " ) , " Browse Selected Folder " ) ;
connect ( outputFolderView , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( outputFolderContextMenu ( QPoint ) ) ) ;
connect ( showFolderContextAction , SIGNAL ( triggered ( bool ) ) , this , SLOT ( showFolderContextActionTriggered ( ) ) ) ;
2010-11-06 23:04:47 +01:00
2010-11-10 19:44:51 +01:00
//Setup "Meta Data" tab
m_metaInfoModel = new MetaInfoModel ( m_metaData , 6 ) ;
m_metaInfoModel - > clearData ( ) ;
metaDataView - > setModel ( m_metaInfoModel ) ;
metaDataView - > verticalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
metaDataView - > verticalHeader ( ) - > hide ( ) ;
metaDataView - > horizontalHeader ( ) - > setResizeMode ( QHeaderView : : ResizeToContents ) ;
2010-11-20 19:16:04 +01:00
while ( writeMetaDataCheckBox - > isChecked ( ) ! = m_settings - > writeMetaTags ( ) ) writeMetaDataCheckBox - > click ( ) ;
2010-11-21 21:51:41 +01:00
generatePlaylistCheckBox - > setChecked ( m_settings - > createPlaylist ( ) ) ;
2010-11-10 19:44:51 +01:00
connect ( buttonEditMeta , SIGNAL ( clicked ( ) ) , this , SLOT ( editMetaButtonClicked ( ) ) ) ;
connect ( buttonClearMeta , SIGNAL ( clicked ( ) ) , this , SLOT ( clearMetaButtonClicked ( ) ) ) ;
2010-11-20 19:16:04 +01:00
connect ( writeMetaDataCheckBox , SIGNAL ( clicked ( ) ) , this , SLOT ( metaTagsEnabledChanged ( ) ) ) ;
2010-11-20 22:14:10 +01:00
connect ( generatePlaylistCheckBox , SIGNAL ( clicked ( ) ) , this , SLOT ( playlistEnabledChanged ( ) ) ) ;
2010-11-11 22:58:02 +01:00
//Setup "Compression" tab
2010-11-15 04:42:06 +01:00
m_encoderButtonGroup = new QButtonGroup ( this ) ;
m_encoderButtonGroup - > addButton ( radioButtonEncoderMP3 , SettingsModel : : MP3Encoder ) ;
m_encoderButtonGroup - > addButton ( radioButtonEncoderVorbis , SettingsModel : : VorbisEncoder ) ;
m_encoderButtonGroup - > addButton ( radioButtonEncoderAAC , SettingsModel : : AACEncoder ) ;
m_encoderButtonGroup - > addButton ( radioButtonEncoderFLAC , SettingsModel : : FLACEncoder ) ;
m_encoderButtonGroup - > addButton ( radioButtonEncoderPCM , SettingsModel : : PCMEncoder ) ;
m_modeButtonGroup = new QButtonGroup ( this ) ;
m_modeButtonGroup - > addButton ( radioButtonModeQuality , SettingsModel : : VBRMode ) ;
m_modeButtonGroup - > addButton ( radioButtonModeAverageBitrate , SettingsModel : : ABRMode ) ;
m_modeButtonGroup - > addButton ( radioButtonConstBitrate , SettingsModel : : CBRMode ) ;
radioButtonEncoderMP3 - > setChecked ( m_settings - > compressionEncoder ( ) = = SettingsModel : : MP3Encoder ) ;
radioButtonEncoderVorbis - > setChecked ( m_settings - > compressionEncoder ( ) = = SettingsModel : : VorbisEncoder ) ;
radioButtonEncoderAAC - > setChecked ( m_settings - > compressionEncoder ( ) = = SettingsModel : : AACEncoder ) ;
radioButtonEncoderFLAC - > setChecked ( m_settings - > compressionEncoder ( ) = = SettingsModel : : FLACEncoder ) ;
radioButtonEncoderPCM - > setChecked ( m_settings - > compressionEncoder ( ) = = SettingsModel : : PCMEncoder ) ;
radioButtonModeQuality - > setChecked ( m_settings - > compressionRCMode ( ) = = SettingsModel : : VBRMode ) ;
radioButtonModeAverageBitrate - > setChecked ( m_settings - > compressionRCMode ( ) = = SettingsModel : : ABRMode ) ;
radioButtonConstBitrate - > setChecked ( m_settings - > compressionRCMode ( ) = = SettingsModel : : CBRMode ) ;
sliderBitrate - > setValue ( m_settings - > compressionBitrate ( ) ) ;
connect ( m_encoderButtonGroup , SIGNAL ( buttonClicked ( int ) ) , this , SLOT ( updateEncoder ( int ) ) ) ;
connect ( m_modeButtonGroup , SIGNAL ( buttonClicked ( int ) ) , this , SLOT ( updateRCMode ( int ) ) ) ;
2010-11-11 22:58:02 +01:00
connect ( sliderBitrate , SIGNAL ( valueChanged ( int ) ) , this , SLOT ( updateBitrate ( int ) ) ) ;
2010-11-15 04:42:06 +01:00
updateEncoder ( m_encoderButtonGroup - > checkedId ( ) ) ;
2010-11-11 22:58:02 +01:00
2010-11-06 23:04:47 +01:00
//Activate file menu actions
connect ( actionOpenFolder , SIGNAL ( triggered ( ) ) , this , SLOT ( openFolderActionActivated ( ) ) ) ;
//Activate view menu actions
m_tabActionGroup = new QActionGroup ( this ) ;
m_tabActionGroup - > addAction ( actionSourceFiles ) ;
m_tabActionGroup - > addAction ( actionOutputDirectory ) ;
m_tabActionGroup - > addAction ( actionCompression ) ;
m_tabActionGroup - > addAction ( actionMetaData ) ;
m_tabActionGroup - > addAction ( actionAdvancedOptions ) ;
2010-11-12 21:02:14 +01:00
actionSourceFiles - > setUserData ( 0 , new Index ( 0 ) ) ;
actionOutputDirectory - > setUserData ( 0 , new Index ( 1 ) ) ;
actionMetaData - > setUserData ( 0 , new Index ( 2 ) ) ;
actionCompression - > setUserData ( 0 , new Index ( 3 ) ) ;
actionAdvancedOptions - > setUserData ( 0 , new Index ( 4 ) ) ;
2010-11-06 23:04:47 +01:00
actionSourceFiles - > setChecked ( true ) ;
connect ( m_tabActionGroup , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( tabActionActivated ( QAction * ) ) ) ;
2010-11-08 00:24:54 +01:00
//Activate style menu actions
m_styleActionGroup = new QActionGroup ( this ) ;
m_styleActionGroup - > addAction ( actionStylePlastique ) ;
m_styleActionGroup - > addAction ( actionStyleCleanlooks ) ;
2010-11-08 21:47:35 +01:00
m_styleActionGroup - > addAction ( actionStyleWindowsVista ) ;
m_styleActionGroup - > addAction ( actionStyleWindowsXP ) ;
m_styleActionGroup - > addAction ( actionStyleWindowsClassic ) ;
2010-11-12 21:02:14 +01:00
actionStylePlastique - > setUserData ( 0 , new Index ( 0 ) ) ;
actionStyleCleanlooks - > setUserData ( 0 , new Index ( 1 ) ) ;
actionStyleWindowsVista - > setUserData ( 0 , new Index ( 2 ) ) ;
actionStyleWindowsXP - > setUserData ( 0 , new Index ( 3 ) ) ;
actionStyleWindowsClassic - > setUserData ( 0 , new Index ( 4 ) ) ;
2010-11-08 00:24:54 +01:00
actionStylePlastique - > setChecked ( true ) ;
2010-11-11 19:37:16 +01:00
actionStyleWindowsXP - > setEnabled ( ( QSysInfo : : windowsVersion ( ) & QSysInfo : : WV_NT_based ) > = QSysInfo : : WV_XP ) ;
actionStyleWindowsVista - > setEnabled ( ( QSysInfo : : windowsVersion ( ) & QSysInfo : : WV_NT_based ) > = QSysInfo : : WV_VISTA ) ;
2010-11-08 00:24:54 +01:00
connect ( m_styleActionGroup , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( styleActionActivated ( QAction * ) ) ) ;
2010-11-12 21:02:14 +01:00
styleActionActivated ( NULL ) ;
2010-11-08 00:24:54 +01:00
2010-11-29 20:36:27 +01:00
//Activate tools menu actions
actionDisableUpdateReminder - > setChecked ( ! m_settings - > autoUpdateEnabled ( ) ) ;
actionDisableSounds - > setChecked ( ! m_settings - > soundsEnabled ( ) ) ;
connect ( actionDisableUpdateReminder , SIGNAL ( triggered ( bool ) ) , this , SLOT ( disableUpdateReminderActionTriggered ( bool ) ) ) ;
connect ( actionDisableSounds , SIGNAL ( triggered ( bool ) ) , this , SLOT ( disableSoundsActionTriggered ( bool ) ) ) ;
2010-12-12 01:49:07 +01:00
connect ( actionInstallWMADecoder , SIGNAL ( triggered ( bool ) ) , this , SLOT ( installWMADecoderActionTriggered ( bool ) ) ) ;
2010-11-29 20:36:27 +01:00
2010-11-06 23:04:47 +01:00
//Activate help menu actions
connect ( actionCheckUpdates , SIGNAL ( triggered ( ) ) , this , SLOT ( checkUpdatesActionActivated ( ) ) ) ;
connect ( actionVisitHomepage , SIGNAL ( triggered ( ) ) , this , SLOT ( visitHomepageActionActivated ( ) ) ) ;
//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 ( ) ) ;
//Create banner
m_banner = new WorkingBanner ( this ) ;
2010-11-08 19:29:36 +01:00
//Create message handler thread
m_messageHandler = new MessageHandlerThread ( ) ;
2010-11-08 21:47:35 +01:00
m_delayedFileList = new QStringList ( ) ;
m_delayedFileTimer = new QTimer ( ) ;
connect ( m_messageHandler , SIGNAL ( otherInstanceDetected ( ) ) , this , SLOT ( notifyOtherInstance ( ) ) , Qt : : QueuedConnection ) ;
connect ( m_messageHandler , SIGNAL ( fileReceived ( QString ) ) , this , SLOT ( addFileDelayed ( QString ) ) , Qt : : QueuedConnection ) ;
2010-11-09 22:06:11 +01:00
connect ( m_messageHandler , SIGNAL ( killSignalReceived ( ) ) , this , SLOT ( close ( ) ) , Qt : : QueuedConnection ) ;
2010-11-08 21:47:35 +01:00
connect ( m_delayedFileTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( handleDelayedFiles ( ) ) ) ;
2010-11-08 19:29:36 +01:00
m_messageHandler - > start ( ) ;
2010-11-12 23:31:04 +01:00
//Enable Drag & Drop
this - > setAcceptDrops ( true ) ;
2010-11-06 23:04:47 +01:00
}
////////////////////////////////////////////////////////////
// Destructor
////////////////////////////////////////////////////////////
MainWindow : : ~ MainWindow ( void )
{
2010-11-09 22:06:11 +01:00
//Stop message handler thread
if ( m_messageHandler & & m_messageHandler - > isRunning ( ) )
2010-11-08 21:47:35 +01:00
{
m_messageHandler - > stop ( ) ;
2010-11-09 22:06:11 +01:00
if ( ! m_messageHandler - > wait ( 10000 ) )
{
m_messageHandler - > terminate ( ) ;
m_messageHandler - > wait ( ) ;
}
2010-11-08 21:47:35 +01:00
}
2010-11-10 19:44:51 +01:00
//Unset models
sourceFileView - > setModel ( NULL ) ;
metaDataView - > setModel ( NULL ) ;
2010-11-09 22:06:11 +01:00
//Free memory
2010-11-06 23:04:47 +01:00
LAMEXP_DELETE ( m_tabActionGroup ) ;
2010-11-08 00:24:54 +01:00
LAMEXP_DELETE ( m_styleActionGroup ) ;
2010-11-06 23:04:47 +01:00
LAMEXP_DELETE ( m_banner ) ;
2010-11-07 16:32:54 +01:00
LAMEXP_DELETE ( m_fileSystemModel ) ;
2010-11-08 21:47:35 +01:00
LAMEXP_DELETE ( m_messageHandler ) ;
LAMEXP_DELETE ( m_delayedFileList ) ;
LAMEXP_DELETE ( m_delayedFileTimer ) ;
2010-11-10 19:44:51 +01:00
LAMEXP_DELETE ( m_metaInfoModel ) ;
2010-11-15 04:42:06 +01:00
LAMEXP_DELETE ( m_encoderButtonGroup ) ;
2010-11-20 02:14:22 +01:00
LAMEXP_DELETE ( m_encoderButtonGroup ) ;
2010-11-25 20:41:59 +01:00
LAMEXP_DELETE ( m_sourceFilesContextMenu ) ;
2010-11-06 23:04:47 +01:00
}
////////////////////////////////////////////////////////////
2010-11-11 19:37:16 +01:00
// PRIVATE FUNCTIONS
2010-11-06 23:04:47 +01:00
////////////////////////////////////////////////////////////
2010-11-11 19:37:16 +01:00
void MainWindow : : addFiles ( const QStringList & files )
{
if ( files . isEmpty ( ) )
{
return ;
}
tabWidget - > setCurrentIndex ( 0 ) ;
FileAnalyzer * analyzer = new FileAnalyzer ( files ) ;
connect ( analyzer , SIGNAL ( fileSelected ( QString ) ) , m_banner , SLOT ( setText ( QString ) ) , Qt : : QueuedConnection ) ;
connect ( analyzer , SIGNAL ( fileAnalyzed ( AudioFileModel ) ) , m_fileListModel , SLOT ( addFile ( AudioFileModel ) ) , Qt : : QueuedConnection ) ;
m_banner - > show ( " Adding file(s), please wait... " , analyzer ) ;
if ( analyzer - > filesDenied ( ) )
{
QMessageBox : : warning ( this , " Access Denied " , QString ( " <nobr>%1 file(s) have been rejected, because read access was not granted!<br>This usually means the file is locked by another process.</nobr> " ) . arg ( analyzer - > filesDenied ( ) ) ) ;
}
if ( analyzer - > filesRejected ( ) )
{
QMessageBox : : warning ( this , " Files Rejected " , QString ( " <nobr>%1 file(s) have been rejected, because the file format could not be recognized!<br>This usually means the file is damaged or the file format is not supported.</nobr> " ) . arg ( analyzer - > filesRejected ( ) ) ) ;
}
LAMEXP_DELETE ( analyzer ) ;
sourceFileView - > scrollToBottom ( ) ;
m_banner - > close ( ) ;
}
2010-11-06 23:04:47 +01:00
2010-11-08 19:29:36 +01:00
////////////////////////////////////////////////////////////
// EVENTS
////////////////////////////////////////////////////////////
void MainWindow : : showEvent ( QShowEvent * event )
{
2010-11-19 21:11:54 +01:00
m_accepted = false ;
2010-11-20 02:14:22 +01:00
m_dropNoteLabel - > setGeometry ( 0 , 0 , sourceFileView - > width ( ) , sourceFileView - > height ( ) ) ;
2010-11-21 21:51:41 +01:00
sourceModelChanged ( ) ;
2010-11-20 22:14:10 +01:00
tabWidget - > setCurrentIndex ( 0 ) ;
if ( m_firstTimeShown )
{
m_firstTimeShown = false ;
QTimer : : singleShot ( 0 , this , SLOT ( windowShown ( ) ) ) ;
}
2010-11-08 19:29:36 +01:00
}
2010-11-12 23:31:04 +01:00
void MainWindow : : dragEnterEvent ( QDragEnterEvent * event )
{
QStringList formats = event - > mimeData ( ) - > formats ( ) ;
2010-11-13 02:11:15 +01:00
if ( formats . contains ( " application/x-qt-windows-mime;value= \" FileNameW \" " , Qt : : CaseInsensitive ) & & formats . contains ( " text/uri-list " , Qt : : CaseInsensitive ) )
2010-11-12 23:31:04 +01:00
{
2010-11-13 02:11:15 +01:00
event - > acceptProposedAction ( ) ;
2010-11-12 23:31:04 +01:00
}
}
void MainWindow : : dropEvent ( QDropEvent * event )
{
ABORT_IF_BUSY ;
QStringList droppedFiles ;
const QList < QUrl > urls = event - > mimeData ( ) - > urls ( ) ;
for ( int i = 0 ; i < urls . count ( ) ; i + + )
{
2010-11-13 02:11:15 +01:00
QFileInfo file ( urls . at ( i ) . toLocalFile ( ) ) ;
if ( ! file . exists ( ) )
{
continue ;
}
if ( file . isFile ( ) )
{
droppedFiles < < file . canonicalFilePath ( ) ;
continue ;
}
if ( file . isDir ( ) )
{
QList < QFileInfo > list = QDir ( file . canonicalFilePath ( ) ) . entryInfoList ( QDir : : Files ) ;
for ( int j = 0 ; j < list . count ( ) ; j + + )
{
2010-11-15 22:07:46 +01:00
droppedFiles < < list . at ( j ) . canonicalFilePath ( ) ;
2010-11-13 02:11:15 +01:00
}
}
2010-11-12 23:31:04 +01:00
}
addFiles ( droppedFiles ) ;
}
2010-11-19 21:11:54 +01:00
void MainWindow : : closeEvent ( QCloseEvent * event )
{
if ( m_banner - > isVisible ( ) | | m_delayedFileTimer - > isActive ( ) )
{
MessageBeep ( MB_ICONEXCLAMATION ) ;
event - > ignore ( ) ;
}
}
2010-11-20 02:14:22 +01:00
void MainWindow : : resizeEvent ( QResizeEvent * event )
{
QMainWindow : : resizeEvent ( event ) ;
m_dropNoteLabel - > setGeometry ( 0 , 0 , sourceFileView - > width ( ) , sourceFileView - > height ( ) ) ;
}
2010-11-24 21:00:59 +01:00
bool MainWindow : : eventFilter ( QObject * obj , QEvent * event )
{
2010-11-25 01:23:48 +01:00
if ( obj = = m_fileSystemModel & & QApplication : : overrideCursor ( ) = = NULL )
2010-11-24 21:00:59 +01:00
{
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
2010-11-25 01:23:48 +01:00
QTimer : : singleShot ( 250 , this , SLOT ( restoreCursor ( ) ) ) ;
2010-11-24 21:00:59 +01:00
}
2010-11-25 20:41:59 +01:00
else if ( obj = = outputFolderView & & ( event - > type ( ) = = QEvent : : KeyRelease | | event - > type ( ) = = QEvent : : KeyPress ) )
{
outputFolderViewClicked ( outputFolderView - > currentIndex ( ) ) ;
}
2010-11-24 21:00:59 +01:00
return false ;
}
2010-11-06 23:04:47 +01:00
////////////////////////////////////////////////////////////
// Slots
////////////////////////////////////////////////////////////
2010-11-08 19:29:36 +01:00
/*
* Window shown
*/
void MainWindow : : windowShown ( void )
{
QStringList arguments = QApplication : : arguments ( ) ;
2010-11-29 20:36:27 +01:00
//Check license
2010-11-12 19:02:01 +01:00
if ( m_settings - > licenseAccepted ( ) < = 0 )
2010-11-12 15:58:53 +01:00
{
2010-11-12 19:02:01 +01:00
int iAccepted = - 1 ;
if ( m_settings - > licenseAccepted ( ) = = 0 )
{
2010-11-29 20:36:27 +01:00
AboutDialog * about = new AboutDialog ( m_settings , this , true ) ;
2010-11-12 19:02:01 +01:00
iAccepted = about - > exec ( ) ;
LAMEXP_DELETE ( about ) ;
}
if ( iAccepted < = 0 )
{
2010-11-15 04:42:06 +01:00
m_settings - > licenseAccepted ( - 1 ) ;
2010-11-12 19:02:01 +01:00
QMessageBox : : critical ( this , " License Declined " , " You have declined the license. Consequently the application will exit now! " ) ;
QApplication : : quit ( ) ;
return ;
}
2010-11-15 04:42:06 +01:00
m_settings - > licenseAccepted ( 1 ) ;
2010-11-12 15:58:53 +01:00
}
2010-11-29 20:36:27 +01:00
//Check for expiration
if ( lamexp_version_demo ( ) )
{
QDate expireDate = lamexp_version_date ( ) . addDays ( 14 ) ;
if ( QDate : : currentDate ( ) > = expireDate )
{
qWarning ( " Binary has expired !!! " ) ;
if ( QMessageBox : : warning ( this , " LameXP - Expired " , QString ( " This demo (pre-release) version of LameXP has expired at %1. \n LameXP is free software and release versions won't expire. " ) . arg ( expireDate . toString ( Qt : : ISODate ) ) , " Check for Updates " , " Exit Program " ) = = 0 )
{
checkUpdatesActionActivated ( ) ;
}
QApplication : : quit ( ) ;
return ;
}
}
//Update reminder
if ( QDate : : currentDate ( ) > = lamexp_version_date ( ) . addYears ( 1 ) )
{
qWarning ( " Binary is more than a year old, time to update! " ) ;
if ( QMessageBox : : warning ( this , " Urgent Update " , " Your version of LameXP is more than a year old. Time for an update! " , " Check for Updates " , " Exit Program " ) = = 0 )
{
checkUpdatesActionActivated ( ) ;
}
else
{
QApplication : : quit ( ) ;
return ;
}
}
else if ( m_settings - > autoUpdateEnabled ( ) )
{
QDate lastUpdateCheck = QDate : : fromString ( m_settings - > autoUpdateLastCheck ( ) , Qt : : ISODate ) ;
if ( ! lastUpdateCheck . isValid ( ) | | QDate : : currentDate ( ) > = lastUpdateCheck . addDays ( 14 ) )
{
2010-12-03 23:01:17 +01:00
if ( QMessageBox : : information ( this , " Update Reminer " , ( lastUpdateCheck . isValid ( ) ? " Your last update check was more than 14 days ago. Check for updates now? " : " Your did not check for LameXP updates yet. Check for updates now? " ) , " Check for Updates " , " Defer " ) = = 0 )
2010-11-29 20:36:27 +01:00
{
checkUpdatesActionActivated ( ) ;
}
}
}
2010-11-11 22:58:02 +01:00
//Check for AAC support
2010-11-15 22:07:46 +01:00
if ( lamexp_check_tool ( " neroAacEnc.exe " ) & & lamexp_check_tool ( " neroAacDec.exe " ) & & lamexp_check_tool ( " neroAacTag.exe " ) )
2010-11-11 22:58:02 +01:00
{
2010-11-12 15:58:53 +01:00
if ( lamexp_tool_version ( " neroAacEnc.exe " ) < lamexp_toolver_neroaac ( ) )
{
QString messageText ;
messageText + = " <nobr>LameXP detected that your version of the Nero AAC encoder is outdated!<br> " ;
messageText + = " The current version available is " + lamexp_version2string ( " ?.?.?.? " , lamexp_toolver_neroaac ( ) ) + " (or later), but you still have version " + lamexp_version2string ( " ?.?.?.? " , lamexp_tool_version ( " neroAacEnc.exe " ) ) + " installed.<br><br> " ;
messageText + = " You can download the latest version of the Nero AAC encoder from the Nero website at:<br> " ;
messageText + = " <b> " + LINK ( AboutDialog : : neroAacUrl ) + " </b><br></nobr> " ;
QMessageBox : : information ( this , " AAC Encoder Outdated " , messageText ) ;
}
2010-11-11 22:58:02 +01:00
}
else
{
2010-11-15 22:07:46 +01:00
radioButtonEncoderAAC - > setEnabled ( false ) ;
2010-11-11 22:58:02 +01:00
QString messageText ;
messageText + = " <nobr>The Nero AAC encoder could not be found. AAC encoding support will be disabled.<br> " ;
messageText + = " Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!<br><br> " ;
2010-12-08 18:29:31 +01:00
messageText + = " Your LameXP directory is as follows:<br> " ;
messageText + = " <i><nobr> " + QDir : : toNativeSeparators ( QCoreApplication : : applicationDirPath ( ) ) + " </nobr></i><br><br> " ;
2010-11-12 15:58:53 +01:00
messageText + = " You can download the Nero AAC encoder for free from the official Nero website at:<br> " ;
2010-11-11 22:58:02 +01:00
messageText + = " <b> " + LINK ( AboutDialog : : neroAacUrl ) + " </b><br></nobr> " ;
QMessageBox : : information ( this , " AAC Support Disabled " , messageText ) ;
}
//Add files from the command-line
2010-11-08 19:29:36 +01:00
for ( int i = 0 ; i < arguments . count ( ) - 1 ; i + + )
{
if ( ! arguments [ i ] . compare ( " --add " , Qt : : CaseInsensitive ) )
{
QFileInfo currentFile ( arguments [ + + i ] . trimmed ( ) ) ;
2010-11-13 02:11:15 +01:00
qDebug ( " Adding file from CLI: %s " , currentFile . canonicalFilePath ( ) . toUtf8 ( ) . constData ( ) ) ;
m_delayedFileList - > append ( currentFile . canonicalFilePath ( ) ) ;
2010-11-08 19:29:36 +01:00
}
}
2010-11-08 21:47:35 +01:00
if ( ! m_delayedFileList - > isEmpty ( ) & & ! m_delayedFileTimer - > isActive ( ) )
2010-11-08 19:29:36 +01:00
{
2010-11-08 21:47:35 +01:00
m_delayedFileTimer - > start ( 5000 ) ;
2010-11-08 19:29:36 +01:00
}
}
2010-11-06 23:04:47 +01:00
/*
* About button
*/
void MainWindow : : aboutButtonClicked ( void )
{
2010-11-10 19:44:51 +01:00
ABORT_IF_BUSY ;
2010-11-29 20:36:27 +01:00
AboutDialog * aboutBox = new AboutDialog ( m_settings , this ) ;
2010-11-11 19:37:16 +01:00
aboutBox - > exec ( ) ;
2010-11-07 23:06:30 +01:00
LAMEXP_DELETE ( aboutBox ) ;
2010-11-06 23:04:47 +01:00
}
/*
* Encode button
*/
void MainWindow : : encodeButtonClicked ( void )
{
2010-11-10 19:44:51 +01:00
ABORT_IF_BUSY ;
2010-11-15 21:07:58 +01:00
2010-11-20 02:14:22 +01:00
if ( m_fileListModel - > rowCount ( ) < 1 )
{
QMessageBox : : warning ( this , " LameXP " , " You must add at least one file to the list before proceeding! " ) ;
tabWidget - > setCurrentIndex ( 0 ) ;
return ;
}
2010-12-03 23:01:17 +01:00
if ( m_settings - > compressionEncoder ( ) ! = SettingsModel : : MP3Encoder & & m_settings - > compressionEncoder ( ) ! = SettingsModel : : VorbisEncoder & & m_settings - > compressionEncoder ( ) ! = SettingsModel : : AACEncoder )
2010-11-15 21:07:58 +01:00
{
2010-12-03 23:01:17 +01:00
QMessageBox : : warning ( this , " LameXP " , " Sorry, only MP3, Vorbis and AAC encoding is supported at the moment.<br>Support for more encoders to be added in later versions! " ) ;
2010-11-15 21:07:58 +01:00
tabWidget - > setCurrentIndex ( 3 ) ;
return ;
}
2010-11-21 21:51:41 +01:00
if ( ! m_settings - > outputToSourceDir ( ) )
{
QFile writeTest ( QString ( " %1/~%2.txt " ) . arg ( m_settings - > outputDir ( ) , QUuid : : createUuid ( ) . toString ( ) ) ) ;
if ( ! writeTest . open ( QIODevice : : ReadWrite ) )
{
QMessageBox : : warning ( this , " LameXP " , QString ( " Cannot write to the selected output directory.<br><nobr>%1</nobr><br><br>Please choose a different directory! " ) . arg ( m_settings - > outputDir ( ) ) ) ;
tabWidget - > setCurrentIndex ( 1 ) ;
return ;
}
else
{
writeTest . close ( ) ;
writeTest . remove ( ) ;
}
}
2010-11-15 21:07:58 +01:00
2010-11-19 21:11:54 +01:00
m_accepted = true ;
close ( ) ;
}
2010-11-15 21:07:58 +01:00
2010-11-19 21:11:54 +01:00
/*
* Close button
*/
void MainWindow : : closeButtonClicked ( void )
{
ABORT_IF_BUSY ;
close ( ) ;
2010-11-06 23:04:47 +01:00
}
/*
* Add file ( s ) button
*/
void MainWindow : : addFilesButtonClicked ( void )
{
2010-11-10 19:44:51 +01:00
ABORT_IF_BUSY ;
2010-11-06 23:04:47 +01:00
QStringList selectedFiles = QFileDialog : : getOpenFileNames ( this , " Add file(s) " , QString ( ) , " All supported files (*.*) " ) ;
2010-11-11 19:37:16 +01:00
addFiles ( selectedFiles ) ;
2010-11-06 23:04:47 +01:00
}
/*
* Open folder action
*/
void MainWindow : : openFolderActionActivated ( void )
{
2010-11-10 19:44:51 +01:00
ABORT_IF_BUSY ;
2010-11-06 23:04:47 +01:00
QString selectedFolder = QFileDialog : : getExistingDirectory ( this , " Add folder " , QDesktopServices : : storageLocation ( QDesktopServices : : MusicLocation ) ) ;
if ( ! selectedFolder . isEmpty ( ) )
{
QDir sourceDir ( selectedFolder ) ;
QFileInfoList fileInfoList = sourceDir . entryInfoList ( QDir : : Files ) ;
QStringList fileList ;
while ( ! fileInfoList . isEmpty ( ) )
{
2010-11-13 02:11:15 +01:00
fileList < < fileInfoList . takeFirst ( ) . canonicalFilePath ( ) ;
2010-11-06 23:04:47 +01:00
}
2010-11-11 19:37:16 +01:00
addFiles ( fileList ) ;
2010-11-06 23:04:47 +01:00
}
}
/*
* Remove file button
*/
void MainWindow : : removeFileButtonClicked ( void )
{
if ( sourceFileView - > currentIndex ( ) . isValid ( ) )
{
int iRow = sourceFileView - > currentIndex ( ) . row ( ) ;
m_fileListModel - > removeFile ( sourceFileView - > currentIndex ( ) ) ;
sourceFileView - > selectRow ( iRow < m_fileListModel - > rowCount ( ) ? iRow : m_fileListModel - > rowCount ( ) - 1 ) ;
}
}
/*
* Clear files button
*/
void MainWindow : : clearFilesButtonClicked ( void )
{
m_fileListModel - > clearFiles ( ) ;
}
/*
* Move file up button
*/
void MainWindow : : fileUpButtonClicked ( void )
{
if ( sourceFileView - > currentIndex ( ) . isValid ( ) )
{
int iRow = sourceFileView - > currentIndex ( ) . row ( ) - 1 ;
m_fileListModel - > moveFile ( sourceFileView - > currentIndex ( ) , - 1 ) ;
sourceFileView - > selectRow ( iRow > = 0 ? iRow : 0 ) ;
}
}
/*
* Move file down button
*/
void MainWindow : : fileDownButtonClicked ( void )
{
if ( sourceFileView - > currentIndex ( ) . isValid ( ) )
{
int iRow = sourceFileView - > currentIndex ( ) . row ( ) + 1 ;
m_fileListModel - > moveFile ( sourceFileView - > currentIndex ( ) , 1 ) ;
sourceFileView - > selectRow ( iRow < m_fileListModel - > rowCount ( ) ? iRow : m_fileListModel - > rowCount ( ) - 1 ) ;
}
}
/*
2010-11-10 19:44:51 +01:00
* Show details button
2010-11-06 23:04:47 +01:00
*/
2010-11-10 19:44:51 +01:00
void MainWindow : : showDetailsButtonClicked ( void )
2010-11-06 23:04:47 +01:00
{
2010-11-10 19:44:51 +01:00
ABORT_IF_BUSY ;
2010-11-06 23:04:47 +01:00
int iResult = 0 ;
MetaInfoDialog * metaInfoDialog = new MetaInfoDialog ( this ) ;
QModelIndex index = sourceFileView - > currentIndex ( ) ;
while ( index . isValid ( ) )
{
if ( iResult > 0 )
{
index = m_fileListModel - > index ( index . row ( ) + 1 , index . column ( ) ) ;
sourceFileView - > selectRow ( index . row ( ) ) ;
}
if ( iResult < 0 )
{
index = m_fileListModel - > index ( index . row ( ) - 1 , index . column ( ) ) ;
sourceFileView - > selectRow ( index . row ( ) ) ;
}
2010-11-08 02:06:01 +01:00
AudioFileModel & file = ( * m_fileListModel ) [ index ] ;
2010-11-06 23:04:47 +01:00
iResult = metaInfoDialog - > exec ( file , index . row ( ) > 0 , index . row ( ) < m_fileListModel - > rowCount ( ) - 1 ) ;
if ( ! iResult ) break ;
}
LAMEXP_DELETE ( metaInfoDialog ) ;
}
/*
* Tab page changed
*/
void MainWindow : : tabPageChanged ( int idx )
{
2010-11-12 21:02:14 +01:00
QList < QAction * > actions = m_tabActionGroup - > actions ( ) ;
for ( int i = 0 ; i < actions . count ( ) ; i + + )
2010-11-06 23:04:47 +01:00
{
2010-11-12 21:02:14 +01:00
if ( actions . at ( i ) - > userData ( 0 ) & & dynamic_cast < Index * > ( actions . at ( i ) - > userData ( 0 ) ) - > value ( ) = = idx )
{
actions . at ( i ) - > setChecked ( true ) ;
}
2010-11-06 23:04:47 +01:00
}
}
/*
* Tab action triggered
*/
void MainWindow : : tabActionActivated ( QAction * action )
{
2010-11-12 21:02:14 +01:00
if ( action & & action - > userData ( 0 ) )
2010-11-06 23:04:47 +01:00
{
2010-11-12 21:02:14 +01:00
int index = dynamic_cast < Index * > ( action - > userData ( 0 ) ) - > value ( ) ;
tabWidget - > setCurrentIndex ( index ) ;
2010-11-06 23:04:47 +01:00
}
}
2010-11-08 00:24:54 +01:00
/*
* Style action triggered
*/
void MainWindow : : styleActionActivated ( QAction * action )
{
2010-11-12 21:02:14 +01:00
if ( action & & action - > userData ( 0 ) )
{
2010-11-15 04:42:06 +01:00
m_settings - > interfaceStyle ( dynamic_cast < Index * > ( action - > userData ( 0 ) ) - > value ( ) ) ;
2010-11-12 21:02:14 +01:00
}
switch ( m_settings - > interfaceStyle ( ) )
{
case 1 :
actionStyleCleanlooks - > setChecked ( true ) ;
QApplication : : setStyle ( new QCleanlooksStyle ( ) ) ;
break ;
case 2 :
actionStyleWindowsVista - > setChecked ( true ) ;
QApplication : : setStyle ( new QWindowsVistaStyle ( ) ) ;
break ;
case 3 :
actionStyleWindowsXP - > setChecked ( true ) ;
QApplication : : setStyle ( new QWindowsXPStyle ( ) ) ;
break ;
case 4 :
actionStyleWindowsClassic - > setChecked ( true ) ;
QApplication : : setStyle ( new QWindowsStyle ( ) ) ;
break ;
default :
actionStylePlastique - > setChecked ( true ) ;
QApplication : : setStyle ( new QPlastiqueStyle ( ) ) ;
break ;
}
2010-11-08 00:24:54 +01:00
}
2010-11-06 23:04:47 +01:00
/*
* Output folder changed
*/
void MainWindow : : outputFolderViewClicked ( const QModelIndex & index )
{
QString selectedDir = m_fileSystemModel - > filePath ( index ) ;
if ( selectedDir . length ( ) < 3 ) selectedDir . append ( QDir : : separator ( ) ) ;
outputFolderLabel - > setText ( selectedDir ) ;
2010-11-20 02:14:22 +01:00
m_settings - > outputDir ( selectedDir ) ;
2010-11-06 23:04:47 +01:00
}
/*
* Goto desktop button
*/
void MainWindow : : gotoDesktopButtonClicked ( void )
{
outputFolderView - > setCurrentIndex ( m_fileSystemModel - > index ( QDesktopServices : : storageLocation ( QDesktopServices : : DesktopLocation ) ) ) ;
outputFolderViewClicked ( outputFolderView - > currentIndex ( ) ) ;
outputFolderView - > setFocus ( ) ;
}
/*
* Goto home folder button
*/
void MainWindow : : gotoHomeFolderButtonClicked ( void )
{
outputFolderView - > setCurrentIndex ( m_fileSystemModel - > index ( QDesktopServices : : storageLocation ( QDesktopServices : : HomeLocation ) ) ) ;
outputFolderViewClicked ( outputFolderView - > currentIndex ( ) ) ;
outputFolderView - > setFocus ( ) ;
}
/*
* Goto music folder button
*/
void MainWindow : : gotoMusicFolderButtonClicked ( void )
{
outputFolderView - > setCurrentIndex ( m_fileSystemModel - > index ( QDesktopServices : : storageLocation ( QDesktopServices : : MusicLocation ) ) ) ;
outputFolderViewClicked ( outputFolderView - > currentIndex ( ) ) ;
outputFolderView - > setFocus ( ) ;
}
/*
* Make folder button
*/
void MainWindow : : makeFolderButtonClicked ( void )
{
2010-11-10 19:44:51 +01:00
ABORT_IF_BUSY ;
2010-11-25 01:23:48 +01:00
QDir basePath ( m_fileSystemModel - > fileInfo ( outputFolderView - > currentIndex ( ) ) . absoluteFilePath ( ) ) ;
2010-12-10 22:57:48 +01:00
QString suggestedName = " New Folder " ;
2010-11-06 23:04:47 +01:00
2010-12-10 22:57:48 +01:00
if ( ! m_metaData - > fileArtist ( ) . isEmpty ( ) & & ! m_metaData - > fileAlbum ( ) . isEmpty ( ) )
{
suggestedName = QString ( " %1 - %2 " ) . arg ( m_metaData - > fileArtist ( ) , m_metaData - > fileAlbum ( ) ) ;
}
else if ( ! m_metaData - > fileArtist ( ) . isEmpty ( ) )
{
suggestedName = m_metaData - > fileArtist ( ) ;
}
else if ( ! m_metaData - > fileAlbum ( ) . isEmpty ( ) )
{
suggestedName = m_metaData - > fileAlbum ( ) ;
}
else
{
for ( int i = 0 ; i < m_fileListModel - > rowCount ( ) ; i + + )
2010-11-06 23:04:47 +01:00
{
2010-12-10 22:57:48 +01:00
AudioFileModel audioFile = m_fileListModel - > getFile ( m_fileListModel - > index ( i , 0 ) ) ;
if ( ! audioFile . fileAlbum ( ) . isEmpty ( ) | | ! audioFile . fileArtist ( ) . isEmpty ( ) )
2010-11-06 23:04:47 +01:00
{
2010-12-10 22:57:48 +01:00
if ( ! audioFile . fileArtist ( ) . isEmpty ( ) & & ! audioFile . fileAlbum ( ) . isEmpty ( ) )
{
suggestedName = QString ( " %1 - %2 " ) . arg ( audioFile . fileArtist ( ) , audioFile . fileAlbum ( ) ) ;
}
else if ( ! audioFile . fileArtist ( ) . isEmpty ( ) )
{
suggestedName = audioFile . fileArtist ( ) ;
}
else if ( ! audioFile . fileAlbum ( ) . isEmpty ( ) )
{
suggestedName = audioFile . fileAlbum ( ) ;
}
break ;
2010-11-06 23:04:47 +01:00
}
}
2010-12-10 22:57:48 +01:00
}
while ( true )
{
bool bApplied = false ;
QString folderName = QInputDialog : : getText ( this , " New Folder " , QString ( " Enter the name of the new folder: " ) . leftJustified ( 96 , ' ' ) , QLineEdit : : Normal , suggestedName , & bApplied , Qt : : WindowStaysOnTopHint ) . simplified ( ) ;
if ( bApplied )
2010-11-06 23:04:47 +01:00
{
2010-12-10 22:57:48 +01:00
folderName . remove ( " : " , Qt : : CaseInsensitive ) ;
folderName . remove ( " / " , Qt : : CaseInsensitive ) ;
folderName . remove ( " \\ " , Qt : : CaseInsensitive ) ;
folderName . remove ( " ? " , Qt : : CaseInsensitive ) ;
folderName . remove ( " * " , Qt : : CaseInsensitive ) ;
folderName . remove ( " < " , Qt : : CaseInsensitive ) ;
folderName . remove ( " > " , Qt : : CaseInsensitive ) ;
folderName = folderName . simplified ( ) ;
if ( folderName . isEmpty ( ) )
{
MessageBeep ( MB_ICONERROR ) ;
continue ;
}
int i = 1 ;
QString newFolder = folderName ;
while ( basePath . exists ( newFolder ) )
{
newFolder = QString ( folderName ) . append ( QString ( ) . sprintf ( " (%d) " , + + i ) ) ;
}
if ( basePath . mkdir ( newFolder ) )
{
QDir createdDir = basePath ;
if ( createdDir . cd ( newFolder ) )
{
outputFolderView - > setCurrentIndex ( m_fileSystemModel - > index ( createdDir . canonicalPath ( ) ) ) ;
outputFolderViewClicked ( outputFolderView - > currentIndex ( ) ) ;
outputFolderView - > setFocus ( ) ;
}
}
else
{
QMessageBox : : warning ( this , " Failed to create folder " , QString ( " The new folder could not be created:<br><nobr>%1</nobr><br><br>Drive is read-only or insufficient access rights! " ) . arg ( basePath . absoluteFilePath ( newFolder ) ) ) ;
}
2010-11-06 23:04:47 +01:00
}
2010-12-10 22:57:48 +01:00
break ;
2010-11-06 23:04:47 +01:00
}
}
2010-11-10 19:44:51 +01:00
/*
* Edit meta button clicked
*/
void MainWindow : : editMetaButtonClicked ( void )
{
ABORT_IF_BUSY ;
m_metaInfoModel - > editItem ( metaDataView - > currentIndex ( ) , this ) ;
}
/*
* Reset meta button clicked
*/
void MainWindow : : clearMetaButtonClicked ( void )
{
ABORT_IF_BUSY ;
m_metaInfoModel - > clearData ( ) ;
}
2010-11-06 23:04:47 +01:00
/*
* Visit homepage action
*/
void MainWindow : : visitHomepageActionActivated ( void )
{
QDesktopServices : : openUrl ( QUrl ( " http://mulder.dummwiedeutsch.de/ " ) ) ;
}
/*
* Check for updates action
*/
void MainWindow : : checkUpdatesActionActivated ( void )
{
2010-11-10 19:44:51 +01:00
ABORT_IF_BUSY ;
2010-11-29 20:36:27 +01:00
UpdateDialog * updateDialog = new UpdateDialog ( m_settings , this ) ;
2010-11-27 19:41:58 +01:00
updateDialog - > exec ( ) ;
2010-11-29 20:36:27 +01:00
if ( updateDialog - > getSuccess ( ) )
{
m_settings - > autoUpdateLastCheck ( QDate : : currentDate ( ) . toString ( Qt : : ISODate ) ) ;
}
2010-11-27 19:41:58 +01:00
2010-11-29 20:36:27 +01:00
LAMEXP_DELETE ( updateDialog ) ;
2010-11-06 23:04:47 +01:00
}
2010-11-08 21:47:35 +01:00
/*
* Other instance detected
*/
void MainWindow : : notifyOtherInstance ( void )
{
if ( ! m_banner - > isVisible ( ) )
{
QMessageBox msgBox ( QMessageBox : : Warning , " Already running " , " LameXP is already running, please use the running instance! " , QMessageBox : : NoButton , this , Qt : : Dialog | Qt : : MSWindowsFixedSizeDialogHint | Qt : : WindowStaysOnTopHint ) ;
msgBox . exec ( ) ;
}
}
/*
* Add file from another instance
*/
void MainWindow : : addFileDelayed ( const QString & filePath )
{
m_delayedFileTimer - > stop ( ) ;
qDebug ( " Received file: %s " , filePath . toUtf8 ( ) . constData ( ) ) ;
m_delayedFileList - > append ( filePath ) ;
m_delayedFileTimer - > start ( 5000 ) ;
}
/*
* Add all pending files
*/
void MainWindow : : handleDelayedFiles ( void )
{
if ( m_banner - > isVisible ( ) )
{
return ;
}
m_delayedFileTimer - > stop ( ) ;
if ( m_delayedFileList - > isEmpty ( ) )
{
return ;
}
QStringList selectedFiles ;
2010-11-10 00:59:50 +01:00
tabWidget - > setCurrentIndex ( 0 ) ;
2010-11-08 21:47:35 +01:00
while ( ! m_delayedFileList - > isEmpty ( ) )
{
2010-11-13 02:11:15 +01:00
QFileInfo currentFile = QFileInfo ( m_delayedFileList - > takeFirst ( ) ) ;
if ( ! currentFile . exists ( ) )
{
continue ;
}
if ( currentFile . isFile ( ) )
{
selectedFiles < < currentFile . canonicalFilePath ( ) ;
continue ;
}
if ( currentFile . isDir ( ) )
{
QList < QFileInfo > list = QDir ( currentFile . canonicalFilePath ( ) ) . entryInfoList ( QDir : : Files ) ;
for ( int j = 0 ; j < list . count ( ) ; j + + )
{
2010-11-15 22:07:46 +01:00
selectedFiles < < list . at ( j ) . canonicalFilePath ( ) ;
2010-11-13 02:11:15 +01:00
}
}
2010-11-08 21:47:35 +01:00
}
2010-11-11 19:37:16 +01:00
addFiles ( selectedFiles ) ;
2010-11-08 21:47:35 +01:00
}
2010-11-11 22:58:02 +01:00
2010-11-15 04:42:06 +01:00
/*
* Update encoder
*/
void MainWindow : : updateEncoder ( int id )
{
m_settings - > compressionEncoder ( id ) ;
switch ( m_settings - > compressionEncoder ( ) )
{
case SettingsModel : : VorbisEncoder :
radioButtonModeQuality - > setEnabled ( true ) ;
radioButtonModeAverageBitrate - > setEnabled ( true ) ;
radioButtonConstBitrate - > setEnabled ( false ) ;
if ( radioButtonConstBitrate - > isChecked ( ) ) radioButtonModeQuality - > setChecked ( true ) ;
sliderBitrate - > setEnabled ( true ) ;
break ;
case SettingsModel : : FLACEncoder :
radioButtonModeQuality - > setEnabled ( false ) ;
radioButtonModeQuality - > setChecked ( true ) ;
radioButtonModeAverageBitrate - > setEnabled ( false ) ;
radioButtonConstBitrate - > setEnabled ( false ) ;
sliderBitrate - > setEnabled ( true ) ;
break ;
case SettingsModel : : PCMEncoder :
radioButtonModeQuality - > setEnabled ( false ) ;
radioButtonModeQuality - > setChecked ( true ) ;
radioButtonModeAverageBitrate - > setEnabled ( false ) ;
radioButtonConstBitrate - > setEnabled ( false ) ;
sliderBitrate - > setEnabled ( false ) ;
break ;
default :
radioButtonModeQuality - > setEnabled ( true ) ;
radioButtonModeAverageBitrate - > setEnabled ( true ) ;
radioButtonConstBitrate - > setEnabled ( true ) ;
sliderBitrate - > setEnabled ( true ) ;
break ;
}
updateRCMode ( m_modeButtonGroup - > checkedId ( ) ) ;
}
/*
* Update rate - control mode
*/
void MainWindow : : updateRCMode ( int id )
{
m_settings - > compressionRCMode ( id ) ;
switch ( m_settings - > compressionEncoder ( ) )
{
case SettingsModel : : MP3Encoder :
switch ( m_settings - > compressionRCMode ( ) )
{
case SettingsModel : : VBRMode :
sliderBitrate - > setMinimum ( 0 ) ;
sliderBitrate - > setMaximum ( 9 ) ;
break ;
default :
2010-11-15 21:07:58 +01:00
sliderBitrate - > setMinimum ( 0 ) ;
sliderBitrate - > setMaximum ( 13 ) ;
2010-11-15 04:42:06 +01:00
break ;
}
break ;
case SettingsModel : : VorbisEncoder :
switch ( m_settings - > compressionRCMode ( ) )
{
case SettingsModel : : VBRMode :
sliderBitrate - > setMinimum ( - 2 ) ;
sliderBitrate - > setMaximum ( 10 ) ;
break ;
default :
sliderBitrate - > setMinimum ( 4 ) ;
sliderBitrate - > setMaximum ( 63 ) ;
break ;
}
break ;
case SettingsModel : : AACEncoder :
switch ( m_settings - > compressionRCMode ( ) )
{
case SettingsModel : : VBRMode :
sliderBitrate - > setMinimum ( 0 ) ;
sliderBitrate - > setMaximum ( 20 ) ;
break ;
default :
sliderBitrate - > setMinimum ( 4 ) ;
sliderBitrate - > setMaximum ( 63 ) ;
break ;
}
break ;
case SettingsModel : : FLACEncoder :
sliderBitrate - > setMinimum ( 0 ) ;
sliderBitrate - > setMaximum ( 8 ) ;
break ;
case SettingsModel : : PCMEncoder :
sliderBitrate - > setMinimum ( 0 ) ;
sliderBitrate - > setMaximum ( 2 ) ;
sliderBitrate - > setValue ( 1 ) ;
break ;
default :
sliderBitrate - > setMinimum ( 0 ) ;
sliderBitrate - > setMaximum ( 0 ) ;
break ;
}
updateBitrate ( sliderBitrate - > value ( ) ) ;
}
2010-11-11 22:58:02 +01:00
/*
* Update bitrate
*/
void MainWindow : : updateBitrate ( int value )
{
2010-11-15 04:42:06 +01:00
m_settings - > compressionBitrate ( value ) ;
switch ( m_settings - > compressionRCMode ( ) )
{
case SettingsModel : : VBRMode :
switch ( m_settings - > compressionEncoder ( ) )
{
case SettingsModel : : MP3Encoder :
labelBitrate - > setText ( QString ( " Quality Level %1 " ) . arg ( 9 - value ) ) ;
break ;
case SettingsModel : : VorbisEncoder :
labelBitrate - > setText ( QString ( " Quality Level %1 " ) . arg ( value ) ) ;
break ;
case SettingsModel : : AACEncoder :
labelBitrate - > setText ( QString ( " Quality Level %1 " ) . arg ( QString ( ) . sprintf ( " %.2f " , static_cast < double > ( value * 5 ) / 100.0 ) ) ) ;
break ;
case SettingsModel : : FLACEncoder :
labelBitrate - > setText ( QString ( " Compression %1 " ) . arg ( value ) ) ;
break ;
case SettingsModel : : PCMEncoder :
labelBitrate - > setText ( " Uncompressed " ) ;
break ;
default :
labelBitrate - > setText ( QString : : number ( value ) ) ;
break ;
}
break ;
case SettingsModel : : ABRMode :
switch ( m_settings - > compressionEncoder ( ) )
{
case SettingsModel : : MP3Encoder :
2010-11-15 21:07:58 +01:00
labelBitrate - > setText ( QString ( " ≈ %1 kbps " ) . arg ( SettingsModel : : mp3Bitrates [ value ] ) ) ;
2010-11-15 04:42:06 +01:00
break ;
case SettingsModel : : FLACEncoder :
labelBitrate - > setText ( QString ( " Compression %1 " ) . arg ( value ) ) ;
break ;
case SettingsModel : : PCMEncoder :
labelBitrate - > setText ( " Uncompressed " ) ;
break ;
default :
labelBitrate - > setText ( QString ( " ≈ %1 kbps " ) . arg ( min ( 500 , value * 8 ) ) ) ;
break ;
}
break ;
default :
switch ( m_settings - > compressionEncoder ( ) )
{
case SettingsModel : : MP3Encoder :
2010-11-15 21:07:58 +01:00
labelBitrate - > setText ( QString ( " %1 kbps " ) . arg ( SettingsModel : : mp3Bitrates [ value ] ) ) ;
2010-11-15 04:42:06 +01:00
break ;
case SettingsModel : : FLACEncoder :
labelBitrate - > setText ( QString ( " Compression %1 " ) . arg ( value ) ) ;
break ;
case SettingsModel : : PCMEncoder :
labelBitrate - > setText ( " Uncompressed " ) ;
break ;
default :
labelBitrate - > setText ( QString ( " %1 kbps " ) . arg ( min ( 500 , value * 8 ) ) ) ;
break ;
}
break ;
}
2010-11-11 22:58:02 +01:00
}
2010-11-20 02:14:22 +01:00
/*
* Model reset
*/
2010-11-21 21:51:41 +01:00
void MainWindow : : sourceModelChanged ( void )
2010-11-20 02:14:22 +01:00
{
m_dropNoteLabel - > setVisible ( m_fileListModel - > rowCount ( ) < = 0 ) ;
}
2010-11-20 19:16:04 +01:00
/*
* Meta tags enabled changed
*/
void MainWindow : : metaTagsEnabledChanged ( void )
{
m_settings - > writeMetaTags ( writeMetaDataCheckBox - > isChecked ( ) ) ;
}
2010-11-20 22:14:10 +01:00
/*
* Playlist enabled changed
*/
void MainWindow : : playlistEnabledChanged ( void )
{
m_settings - > createPlaylist ( generatePlaylistCheckBox - > isChecked ( ) ) ;
}
2010-11-21 21:51:41 +01:00
/*
* Output to source dir changed
*/
void MainWindow : : saveToSourceFolderChanged ( void )
{
m_settings - > outputToSourceDir ( saveToSourceFolderCheckBox - > isChecked ( ) ) ;
}
2010-11-24 21:00:59 +01:00
/*
* Restore the override cursor
*/
void MainWindow : : restoreCursor ( void )
{
QApplication : : restoreOverrideCursor ( ) ;
}
2010-11-25 20:41:59 +01:00
/*
* Show context menu for source files
*/
void MainWindow : : sourceFilesContextMenu ( const QPoint & pos )
{
m_sourceFilesContextMenu - > popup ( sourceFileView - > mapToGlobal ( pos ) ) ;
}
/*
* Open selected file in external player
*/
void MainWindow : : previewContextActionTriggered ( void )
{
2010-11-26 00:29:53 +01:00
const static char * appNames [ 3 ] = { " smplayer_portable.exe " , " smplayer.exe " , " mplayer.exe " } ;
const static wchar_t * registryKey = L " SOFTWARE \\ Wow6432Node \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall \\ {DB9E4EAB-2717-499F-8D56-4CC8A644AB60} " ;
2010-11-25 20:41:59 +01:00
QModelIndex index = sourceFileView - > currentIndex ( ) ;
2010-11-26 00:29:53 +01:00
if ( ! index . isValid ( ) )
2010-11-25 20:41:59 +01:00
{
2010-11-26 00:29:53 +01:00
return ;
}
QString mplayerPath ;
HKEY registryKeyHandle ;
if ( RegOpenKeyExW ( HKEY_LOCAL_MACHINE , registryKey , 0 , KEY_READ , & registryKeyHandle ) = = ERROR_SUCCESS )
{
wchar_t Buffer [ 4096 ] ;
DWORD BuffSize = sizeof ( wchar_t * ) * 4096 ;
if ( RegQueryValueExW ( registryKeyHandle , L " InstallLocation " , 0 , 0 , reinterpret_cast < BYTE * > ( Buffer ) , & BuffSize ) = = ERROR_SUCCESS )
{
mplayerPath = QString : : fromUtf16 ( reinterpret_cast < const unsigned short * > ( Buffer ) ) ;
}
2010-11-25 20:41:59 +01:00
}
2010-11-26 00:29:53 +01:00
if ( ! mplayerPath . isEmpty ( ) )
{
QDir mplayerDir ( mplayerPath ) ;
if ( mplayerDir . exists ( ) )
{
for ( int i = 0 ; i < 3 ; i + + )
{
if ( mplayerDir . exists ( appNames [ i ] ) )
{
QProcess : : startDetached ( mplayerDir . absoluteFilePath ( appNames [ i ] ) , QStringList ( ) < < QDir : : toNativeSeparators ( m_fileListModel - > getFile ( index ) . filePath ( ) ) ) ;
return ;
}
}
}
}
QDesktopServices : : openUrl ( QString ( " file:/// " ) . append ( m_fileListModel - > getFile ( index ) . filePath ( ) ) ) ;
2010-11-25 20:41:59 +01:00
}
/*
* Find selected file in explorer
*/
void MainWindow : : findFileContextActionTriggered ( void )
{
QModelIndex index = sourceFileView - > currentIndex ( ) ;
if ( index . isValid ( ) )
{
QProcessEnvironment procEnv = QProcessEnvironment : : systemEnvironment ( ) ;
QString systemRootPath = procEnv . value ( " SystemRoot " , procEnv . value ( " windir " ) ) ;
if ( ! systemRootPath . isEmpty ( ) )
{
QFileInfo explorer ( QString ( " %1/explorer.exe " ) . arg ( systemRootPath ) ) ;
if ( explorer . exists ( ) & & explorer . isFile ( ) )
{
QProcess : : execute ( explorer . canonicalFilePath ( ) , QStringList ( ) < < " /select, " < < QDir : : toNativeSeparators ( m_fileListModel - > getFile ( index ) . filePath ( ) ) ) ;
return ;
}
}
qWarning ( " SystemRoot directory could not be detected! " ) ;
QProcess : : execute ( " explorer.exe " , QStringList ( ) < < " /select, " < < QDir : : toNativeSeparators ( m_fileListModel - > getFile ( index ) . filePath ( ) ) ) ;
}
}
2010-11-29 20:36:27 +01:00
2010-12-05 23:11:03 +01:00
/*
* Show context menu for output folder
*/
void MainWindow : : outputFolderContextMenu ( const QPoint & pos )
{
m_outputFolderContextMenu - > popup ( outputFolderView - > mapToGlobal ( pos ) ) ;
}
/*
* Show selected folder in explorer
*/
void MainWindow : : showFolderContextActionTriggered ( void )
{
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( m_fileSystemModel - > filePath ( outputFolderView - > currentIndex ( ) ) ) ) ;
}
2010-11-29 20:36:27 +01:00
/*
* Disable update reminder action
*/
void MainWindow : : disableUpdateReminderActionTriggered ( bool checked )
{
if ( checked )
{
if ( QMessageBox : : Yes = = QMessageBox : : question ( this , " Disable Update Reminder " , " Do you really want to disable the update reminder? " , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) )
{
QMessageBox : : information ( this , " Update Reminder " , " The update reminder has been disabled.<br>Please remember to check for updates at regular intervals! " ) ;
m_settings - > autoUpdateEnabled ( false ) ;
}
else
{
m_settings - > autoUpdateEnabled ( true ) ;
}
}
else
{
QMessageBox : : information ( this , " Update Reminder " , " The update reminder has been re-enabled. " ) ;
m_settings - > autoUpdateEnabled ( true ) ;
}
actionDisableUpdateReminder - > setChecked ( ! m_settings - > autoUpdateEnabled ( ) ) ;
}
/*
* Disable sound effects action
*/
void MainWindow : : disableSoundsActionTriggered ( bool checked )
{
if ( checked )
{
if ( QMessageBox : : Yes = = QMessageBox : : question ( this , " Disable Sound Effects " , " Do you really want to disable all sound effects? " , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) )
{
QMessageBox : : information ( this , " Sound Effects " , " All sound effects have been disabled. " ) ;
m_settings - > soundsEnabled ( false ) ;
}
else
{
m_settings - > soundsEnabled ( true ) ;
}
}
else
{
QMessageBox : : information ( this , " Sound Effects " , " The sound effects have been re-enabled. " ) ;
m_settings - > soundsEnabled ( true ) ;
}
actionDisableSounds - > setChecked ( ! m_settings - > soundsEnabled ( ) ) ;
}
2010-12-12 01:49:07 +01:00
void MainWindow : : installWMADecoderActionTriggered ( bool checked )
{
static const char * download_url = " http://www.nch.com.au/components/wmawav.exe " ;
if ( QMessageBox : : question ( this , " Install WMA Decoder " , " Do you want to download and install the WMA File Deocder now? " , " Download && Install " , " Cancel " ) ! = 0 )
{
return ;
}
QString binaryWGet = lamexp_lookup_tool ( " wget.exe " ) ;
QString binaryElevator = lamexp_lookup_tool ( " elevator.exe " ) ;
if ( binaryWGet . isEmpty ( ) | | binaryElevator . isEmpty ( ) )
{
throw " Required binary is not available! " ;
}
QString setupFile = QString ( " %1/%2.exe " ) . arg ( lamexp_temp_folder ( ) , lamexp_rand_str ( ) ) ;
QProcess process ;
process . setWorkingDirectory ( QFileInfo ( setupFile ) . absolutePath ( ) ) ;
QEventLoop loop ;
connect ( & process , SIGNAL ( error ( QProcess : : ProcessError ) ) , & loop , SLOT ( quit ( ) ) ) ;
connect ( & process , SIGNAL ( finished ( int , QProcess : : ExitStatus ) ) , & loop , SLOT ( quit ( ) ) ) ;
process . start ( binaryWGet , QStringList ( ) < < " -O " < < QFileInfo ( setupFile ) . fileName ( ) < < download_url ) ;
m_banner - > show ( " Downloading WMA Decoder Setup, please wait... " , & loop ) ;
if ( process . exitCode ( ) ! = 0 | | QFileInfo ( setupFile ) . size ( ) < 10240 )
{
QFile : : remove ( setupFile ) ;
QMessageBox : : critical ( this , " Download Failed " , " Failed to download the WMA Decoder. Check your internet connection! " ) ;
return ;
}
QApplication : : setOverrideCursor ( Qt : : WaitCursor ) ;
process . start ( binaryElevator , QStringList ( ) < < QString ( " /exec=%1 " ) . arg ( setupFile ) ) ;
loop . exec ( QEventLoop : : ExcludeUserInputEvents ) ;
QFile : : remove ( setupFile ) ;
QApplication : : restoreOverrideCursor ( ) ;
QMessageBox : : information ( this , " WMA Decoder " , " The WMA Decoder has been installed. Please restart LameXP now! " ) ;
}