1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_MainWindow.h"
27 #include "Dialog_WorkingBanner.h"
28 #include "Dialog_MetaInfo.h"
29 #include "Dialog_About.h"
30 #include "Dialog_Update.h"
31 #include "Dialog_DropBox.h"
32 #include "Dialog_CueImport.h"
33 #include "Thread_FileAnalyzer.h"
34 #include "Thread_MessageHandler.h"
35 #include "Model_MetaInfo.h"
36 #include "Model_Settings.h"
37 #include "Model_FileList.h"
38 #include "Model_FileSystem.h"
39 #include "WinSevenTaskbar.h"
40 #include "Registry_Decoder.h"
41 #include "ShellIntegration.h"
44 #include <QMessageBox>
46 #include <QDesktopWidget>
48 #include <QFileDialog>
49 #include <QInputDialog>
50 #include <QFileSystemModel>
51 #include <QDesktopServices>
53 #include <QPlastiqueStyle>
54 #include <QCleanlooksStyle>
55 #include <QWindowsVistaStyle>
56 #include <QWindowsStyle>
58 #include <QDragEnterEvent>
59 #include <QWindowsMime>
62 #include <QProcessEnvironment>
63 #include <QCryptographicHash>
64 #include <QTranslator>
72 #define ABORT_IF_BUSY if(m_banner->isVisible() || m_delayedFileTimer->isActive()) { MessageBeep(MB_ICONEXCLAMATION); return; }
73 #define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); }
74 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
75 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(URL)
76 #define TEMP_HIDE_DROPBOX(CMD) { bool __dropBoxVisible = m_dropBox->isVisible(); if(__dropBoxVisible) m_dropBox->hide(); {CMD}; if(__dropBoxVisible) m_dropBox->show(); }
77 #define USE_NATIVE_FILE_DIALOG (lamexp_themes_enabled() || ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) < QSysInfo::WV_XP))
78 #define NOBR(STR) QString("<nobr>%1</nobr>").arg(STR).replace("-", "−")
80 ////////////////////////////////////////////////////////////
82 ////////////////////////////////////////////////////////////
84 MainWindow::MainWindow(FileListModel
*fileListModel
, AudioFileModel
*metaInfo
, SettingsModel
*settingsModel
, QWidget
*parent
)
87 m_fileListModel(fileListModel
),
89 m_settings(settingsModel
),
90 m_neroEncoderAvailable(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")),
91 m_fhgEncoderAvailable(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll") && lamexp_check_tool("nsutil.dll") && lamexp_check_tool("libmp4v2.dll")),
93 m_firstTimeShown(true),
94 m_OutputFolderViewInitialized(false)
96 //Init the dialog, from the .ui file
98 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint
);
100 //Register meta types
101 qRegisterMetaType
<AudioFileModel
>("AudioFileModel");
103 //Enabled main buttons
104 connect(buttonAbout
, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
105 connect(buttonStart
, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
106 connect(buttonQuit
, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
109 tabWidget
->setCurrentIndex(0);
110 connect(tabWidget
, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
113 sourceFileView
->setModel(m_fileListModel
);
114 sourceFileView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
115 sourceFileView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
116 sourceFileView
->setContextMenuPolicy(Qt::CustomContextMenu
);
117 sourceFileView
->viewport()->installEventFilter(this);
118 m_dropNoteLabel
= new QLabel(sourceFileView
);
119 m_dropNoteLabel
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
120 SET_FONT_BOLD(m_dropNoteLabel
, true);
121 SET_TEXT_COLOR(m_dropNoteLabel
, Qt::darkGray
);
122 m_sourceFilesContextMenu
= new QMenu();
123 m_showDetailsContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
124 m_previewContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/sound.png"), "N/A");
125 m_findFileContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_go.png"), "N/A");
126 SET_FONT_BOLD(m_showDetailsContextAction
, true);
127 connect(buttonAddFiles
, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
128 connect(buttonRemoveFile
, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
129 connect(buttonClearFiles
, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
130 connect(buttonFileUp
, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
131 connect(buttonFileDown
, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
132 connect(buttonShowDetails
, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
133 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
134 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
135 connect(m_fileListModel
, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
136 connect(sourceFileView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(sourceFilesContextMenu(QPoint
)));
137 connect(sourceFileView
->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
138 connect(sourceFileView
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
139 connect(m_showDetailsContextAction
, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
140 connect(m_previewContextAction
, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
141 connect(m_findFileContextAction
, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
144 m_fileSystemModel
= new QFileSystemModelEx();
145 m_fileSystemModel
->installEventFilter(this);
146 outputFolderView
->setModel(m_fileSystemModel
);
147 outputFolderView
->header()->setStretchLastSection(true);
148 outputFolderView
->header()->hideSection(1);
149 outputFolderView
->header()->hideSection(2);
150 outputFolderView
->header()->hideSection(3);
151 outputFolderView
->setHeaderHidden(true);
152 outputFolderView
->setAnimated(false);
153 outputFolderView
->setMouseTracking(false);
154 outputFolderView
->setContextMenuPolicy(Qt::CustomContextMenu
);
155 outputFolderView
->installEventFilter(this);
156 outputFoldersFovoritesLabel
->installEventFilter(this);
157 while(saveToSourceFolderCheckBox
->isChecked() != m_settings
->outputToSourceDir()) saveToSourceFolderCheckBox
->click();
158 prependRelativePathCheckBox
->setChecked(m_settings
->prependRelativeSourcePath());
159 connect(outputFolderView
, SIGNAL(clicked(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
160 connect(outputFolderView
, SIGNAL(activated(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
161 connect(outputFolderView
, SIGNAL(pressed(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
162 connect(outputFolderView
, SIGNAL(entered(QModelIndex
)), this, SLOT(outputFolderViewMoved(QModelIndex
)));
163 connect(buttonMakeFolder
, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
164 connect(buttonGotoHome
, SIGNAL(clicked()), SLOT(gotoHomeFolderButtonClicked()));
165 connect(buttonGotoDesktop
, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
166 connect(buttonGotoMusic
, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
167 connect(saveToSourceFolderCheckBox
, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
168 connect(prependRelativePathCheckBox
, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
169 m_outputFolderContextMenu
= new QMenu();
170 m_showFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
171 m_outputFolderFavoritesMenu
= new QMenu();
172 m_addFavoriteFolderAction
= m_outputFolderFavoritesMenu
->addAction(QIcon(":/icons/add.png"), "N/A");
173 m_outputFolderFavoritesMenu
->insertSeparator(m_addFavoriteFolderAction
);
174 connect(outputFolderView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(outputFolderContextMenu(QPoint
)));
175 connect(m_showFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
176 connect(m_addFavoriteFolderAction
, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
177 outputFolderLabel
->installEventFilter(this);
178 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(m_settings
->outputDir()));
179 outputFolderViewClicked(outputFolderView
->currentIndex());
182 //Setup "Meta Data" tab
183 m_metaInfoModel
= new MetaInfoModel(m_metaData
, 6);
184 m_metaInfoModel
->clearData();
185 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
186 metaDataView
->setModel(m_metaInfoModel
);
187 metaDataView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
188 metaDataView
->verticalHeader()->hide();
189 metaDataView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
190 while(writeMetaDataCheckBox
->isChecked() != m_settings
->writeMetaTags()) writeMetaDataCheckBox
->click();
191 generatePlaylistCheckBox
->setChecked(m_settings
->createPlaylist());
192 connect(buttonEditMeta
, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
193 connect(buttonClearMeta
, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
194 connect(writeMetaDataCheckBox
, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
195 connect(generatePlaylistCheckBox
, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
197 //Setup "Compression" tab
198 m_encoderButtonGroup
= new QButtonGroup(this);
199 m_encoderButtonGroup
->addButton(radioButtonEncoderMP3
, SettingsModel::MP3Encoder
);
200 m_encoderButtonGroup
->addButton(radioButtonEncoderVorbis
, SettingsModel::VorbisEncoder
);
201 m_encoderButtonGroup
->addButton(radioButtonEncoderAAC
, SettingsModel::AACEncoder
);
202 m_encoderButtonGroup
->addButton(radioButtonEncoderAC3
, SettingsModel::AC3Encoder
);
203 m_encoderButtonGroup
->addButton(radioButtonEncoderFLAC
, SettingsModel::FLACEncoder
);
204 m_encoderButtonGroup
->addButton(radioButtonEncoderPCM
, SettingsModel::PCMEncoder
);
205 m_modeButtonGroup
= new QButtonGroup(this);
206 m_modeButtonGroup
->addButton(radioButtonModeQuality
, SettingsModel::VBRMode
);
207 m_modeButtonGroup
->addButton(radioButtonModeAverageBitrate
, SettingsModel::ABRMode
);
208 m_modeButtonGroup
->addButton(radioButtonConstBitrate
, SettingsModel::CBRMode
);
209 radioButtonEncoderAAC
->setEnabled(m_neroEncoderAvailable
|| m_fhgEncoderAvailable
);
210 radioButtonEncoderMP3
->setChecked(m_settings
->compressionEncoder() == SettingsModel::MP3Encoder
);
211 radioButtonEncoderVorbis
->setChecked(m_settings
->compressionEncoder() == SettingsModel::VorbisEncoder
);
212 radioButtonEncoderAAC
->setChecked((m_settings
->compressionEncoder() == SettingsModel::AACEncoder
) && (m_neroEncoderAvailable
|| m_fhgEncoderAvailable
));
213 radioButtonEncoderAC3
->setChecked(m_settings
->compressionEncoder() == SettingsModel::AC3Encoder
);
214 radioButtonEncoderFLAC
->setChecked(m_settings
->compressionEncoder() == SettingsModel::FLACEncoder
);
215 radioButtonEncoderPCM
->setChecked(m_settings
->compressionEncoder() == SettingsModel::PCMEncoder
);
216 radioButtonModeQuality
->setChecked(m_settings
->compressionRCMode() == SettingsModel::VBRMode
);
217 radioButtonModeAverageBitrate
->setChecked(m_settings
->compressionRCMode() == SettingsModel::ABRMode
);
218 radioButtonConstBitrate
->setChecked(m_settings
->compressionRCMode() == SettingsModel::CBRMode
);
219 sliderBitrate
->setValue(m_settings
->compressionBitrate());
220 connect(m_encoderButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
221 connect(m_modeButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
222 connect(sliderBitrate
, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
223 updateEncoder(m_encoderButtonGroup
->checkedId());
225 //Setup "Advanced Options" tab
226 sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQuality());
227 if(m_settings
->maximumInstances() > 0) sliderMaxInstances
->setValue(m_settings
->maximumInstances());
228 spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRate());
229 spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRate());
230 spinBoxNormalizationFilter
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolume()) / 100.0);
231 spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBass()) / 100.0);
232 spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTreble()) / 100.0);
233 spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSize());
234 comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelMode());
235 comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRate());
236 comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfile());
237 comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingMode());
238 comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompression());
239 while(checkBoxBitrateManagement
->isChecked() != m_settings
->bitrateManagementEnabled()) checkBoxBitrateManagement
->click();
240 while(checkBoxNeroAAC2PassMode
->isChecked() != m_settings
->neroAACEnable2Pass()) checkBoxNeroAAC2PassMode
->click();
241 while(checkBoxAftenFastAllocation
->isChecked() != m_settings
->aftenFastBitAllocation()) checkBoxAftenFastAllocation
->click();
242 while(checkBoxNormalizationFilter
->isChecked() != m_settings
->normalizationFilterEnabled()) checkBoxNormalizationFilter
->click();
243 while(checkBoxAutoDetectInstances
->isChecked() != (m_settings
->maximumInstances() < 1)) checkBoxAutoDetectInstances
->click();
244 while(checkBoxUseSystemTempFolder
->isChecked() == m_settings
->customTempPathEnabled()) checkBoxUseSystemTempFolder
->click();
245 while(checkBoxRenameOutput
->isChecked() != m_settings
->renameOutputFilesEnabled()) checkBoxRenameOutput
->click();
246 while(checkBoxForceStereoDownmix
->isChecked() != m_settings
->forceStereoDownmix()) checkBoxForceStereoDownmix
->click();
247 checkBoxNeroAAC2PassMode
->setEnabled(!m_fhgEncoderAvailable
);
248 lineEditCustomParamLAME
->setText(m_settings
->customParametersLAME());
249 lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEnc());
250 lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEnc());
251 lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLAC());
252 lineEditCustomParamAften
->setText(m_settings
->customParametersAften());
253 lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPath()));
254 lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPattern());
255 connect(sliderLameAlgoQuality
, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
256 connect(checkBoxBitrateManagement
, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
257 connect(spinBoxBitrateManagementMin
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
258 connect(spinBoxBitrateManagementMax
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
259 connect(comboBoxMP3ChannelMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
260 connect(comboBoxSamplingRate
, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
261 connect(checkBoxNeroAAC2PassMode
, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
262 connect(comboBoxAACProfile
, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
263 connect(checkBoxNormalizationFilter
, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
264 connect(comboBoxAftenCodingMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
265 connect(comboBoxAftenDRCMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
266 connect(spinBoxAftenSearchSize
, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
267 connect(checkBoxAftenFastAllocation
, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
268 connect(spinBoxNormalizationFilter
, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
269 connect(spinBoxToneAdjustBass
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
270 connect(spinBoxToneAdjustTreble
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
271 connect(buttonToneAdjustReset
, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
272 connect(lineEditCustomParamLAME
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
273 connect(lineEditCustomParamOggEnc
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
274 connect(lineEditCustomParamNeroAAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
275 connect(lineEditCustomParamFLAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
276 connect(lineEditCustomParamAften
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
277 connect(sliderMaxInstances
, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
278 connect(checkBoxAutoDetectInstances
, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
279 connect(buttonBrowseCustomTempFolder
, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
280 connect(lineEditCustomTempFolder
, SIGNAL(textChanged(QString
)), this, SLOT(customTempFolderChanged(QString
)));
281 connect(checkBoxUseSystemTempFolder
, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
282 connect(buttonResetAdvancedOptions
, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
283 connect(checkBoxRenameOutput
, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
284 connect(lineEditRenamePattern
, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
285 connect(lineEditRenamePattern
, SIGNAL(textChanged(QString
)), this, SLOT(renameOutputPatternChanged(QString
)));
286 connect(labelShowRenameMacros
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
287 connect(checkBoxForceStereoDownmix
, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
288 updateLameAlgoQuality(sliderLameAlgoQuality
->value());
289 updateMaximumInstances(sliderMaxInstances
->value());
290 toneAdjustTrebleChanged(spinBoxToneAdjustTreble
->value());
291 toneAdjustBassChanged(spinBoxToneAdjustBass
->value());
292 customParamsChanged();
294 //Activate file menu actions
295 actionOpenFolder
->setData(QVariant::fromValue
<bool>(false));
296 actionOpenFolderRecursively
->setData(QVariant::fromValue
<bool>(true));
297 connect(actionOpenFolder
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
298 connect(actionOpenFolderRecursively
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
300 //Activate view menu actions
301 m_tabActionGroup
= new QActionGroup(this);
302 m_tabActionGroup
->addAction(actionSourceFiles
);
303 m_tabActionGroup
->addAction(actionOutputDirectory
);
304 m_tabActionGroup
->addAction(actionCompression
);
305 m_tabActionGroup
->addAction(actionMetaData
);
306 m_tabActionGroup
->addAction(actionAdvancedOptions
);
307 actionSourceFiles
->setData(0);
308 actionOutputDirectory
->setData(1);
309 actionMetaData
->setData(2);
310 actionCompression
->setData(3);
311 actionAdvancedOptions
->setData(4);
312 actionSourceFiles
->setChecked(true);
313 connect(m_tabActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(tabActionActivated(QAction
*)));
315 //Activate style menu actions
316 m_styleActionGroup
= new QActionGroup(this);
317 m_styleActionGroup
->addAction(actionStylePlastique
);
318 m_styleActionGroup
->addAction(actionStyleCleanlooks
);
319 m_styleActionGroup
->addAction(actionStyleWindowsVista
);
320 m_styleActionGroup
->addAction(actionStyleWindowsXP
);
321 m_styleActionGroup
->addAction(actionStyleWindowsClassic
);
322 actionStylePlastique
->setData(0);
323 actionStyleCleanlooks
->setData(1);
324 actionStyleWindowsVista
->setData(2);
325 actionStyleWindowsXP
->setData(3);
326 actionStyleWindowsClassic
->setData(4);
327 actionStylePlastique
->setChecked(true);
328 actionStyleWindowsXP
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_XP
&& lamexp_themes_enabled());
329 actionStyleWindowsVista
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_VISTA
&& lamexp_themes_enabled());
330 connect(m_styleActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(styleActionActivated(QAction
*)));
331 styleActionActivated(NULL
);
333 //Populate the language menu
334 m_languageActionGroup
= new QActionGroup(this);
335 QStringList translations
= lamexp_query_translations();
336 while(!translations
.isEmpty())
338 QString langId
= translations
.takeFirst();
339 QAction
*currentLanguage
= new QAction(this);
340 currentLanguage
->setData(langId
);
341 currentLanguage
->setText(lamexp_translation_name(langId
));
342 currentLanguage
->setIcon(QIcon(QString(":/flags/%1.png").arg(langId
)));
343 currentLanguage
->setCheckable(true);
344 m_languageActionGroup
->addAction(currentLanguage
);
345 menuLanguage
->insertAction(actionLoadTranslationFromFile
, currentLanguage
);
347 menuLanguage
->insertSeparator(actionLoadTranslationFromFile
);
348 connect(actionLoadTranslationFromFile
, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
349 connect(m_languageActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(languageActionActivated(QAction
*)));
351 //Activate tools menu actions
352 actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
353 actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
354 actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
355 actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
356 actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
357 actionDisableShellIntegration
->setDisabled(lamexp_portable_mode() && actionDisableShellIntegration
->isChecked());
358 actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta() || lamexp_version_demo());
359 actionCheckForBetaUpdates
->setEnabled(!lamexp_version_demo());
360 connect(actionDisableUpdateReminder
, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
361 connect(actionDisableSounds
, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
362 connect(actionDisableNeroAacNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
363 connect(actionDisableSlowStartupNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
364 connect(actionDisableShellIntegration
, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
365 connect(actionShowDropBoxWidget
, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
366 connect(actionCheckForBetaUpdates
, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
367 connect(actionImportCueSheet
, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
369 //Activate help menu actions
370 actionVisitHomepage
->setData(QString::fromLatin1(lamexp_website_url()));
371 actionVisitSupport
->setData(QString::fromLatin1(lamexp_support_url()));
372 actionDocumentFAQ
->setData(QString("%1/FAQ.html").arg(QApplication::applicationDirPath()));
373 actionDocumentChangelog
->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
374 actionDocumentTranslate
->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
375 connect(actionCheckUpdates
, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
376 connect(actionVisitHomepage
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
377 connect(actionVisitSupport
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
378 connect(actionDocumentFAQ
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
379 connect(actionDocumentChangelog
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
380 connect(actionDocumentTranslate
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
382 //Center window in screen
383 QRect desktopRect
= QApplication::desktop()->screenGeometry();
384 QRect thisRect
= this->geometry();
385 move((desktopRect
.width() - thisRect
.width()) / 2, (desktopRect
.height() - thisRect
.height()) / 2);
386 setMinimumSize(thisRect
.width(), thisRect
.height());
389 m_banner
= new WorkingBanner(this);
391 //Create DropBox widget
392 m_dropBox
= new DropBox(this, m_fileListModel
, m_settings
);
393 connect(m_fileListModel
, SIGNAL(modelReset()), m_dropBox
, SLOT(modelChanged()));
394 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), m_dropBox
, SLOT(modelChanged()));
395 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), m_dropBox
, SLOT(modelChanged()));
397 //Create message handler thread
398 m_messageHandler
= new MessageHandlerThread();
399 m_delayedFileList
= new QStringList();
400 m_delayedFileTimer
= new QTimer();
401 m_delayedFileTimer
->setSingleShot(true);
402 m_delayedFileTimer
->setInterval(5000);
403 connect(m_messageHandler
, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection
);
404 connect(m_messageHandler
, SIGNAL(fileReceived(QString
)), this, SLOT(addFileDelayed(QString
)), Qt::QueuedConnection
);
405 connect(m_messageHandler
, SIGNAL(folderReceived(QString
, bool)), this, SLOT(addFolderDelayed(QString
, bool)), Qt::QueuedConnection
);
406 connect(m_messageHandler
, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection
);
407 connect(m_delayedFileTimer
, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
408 m_messageHandler
->start();
410 //Load translation file
411 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
412 while(!languageActions
.isEmpty())
414 QAction
*currentLanguage
= languageActions
.takeFirst();
415 if(currentLanguage
->data().toString().compare(m_settings
->currentLanguage(), Qt::CaseInsensitive
) == 0)
417 currentLanguage
->setChecked(true);
418 languageActionActivated(currentLanguage
);
422 //Re-translate (make sure we translate once)
423 QEvent
languageChangeEvent(QEvent::LanguageChange
);
424 changeEvent(&languageChangeEvent
);
427 this->setAcceptDrops(true);
430 ////////////////////////////////////////////////////////////
432 ////////////////////////////////////////////////////////////
434 MainWindow::~MainWindow(void)
436 //Stop message handler thread
437 if(m_messageHandler
&& m_messageHandler
->isRunning())
439 m_messageHandler
->stop();
440 if(!m_messageHandler
->wait(10000))
442 m_messageHandler
->terminate();
443 m_messageHandler
->wait();
448 sourceFileView
->setModel(NULL
);
449 metaDataView
->setModel(NULL
);
452 LAMEXP_DELETE(m_tabActionGroup
);
453 LAMEXP_DELETE(m_styleActionGroup
);
454 LAMEXP_DELETE(m_languageActionGroup
);
455 LAMEXP_DELETE(m_banner
);
456 LAMEXP_DELETE(m_fileSystemModel
);
457 LAMEXP_DELETE(m_messageHandler
);
458 LAMEXP_DELETE(m_delayedFileList
);
459 LAMEXP_DELETE(m_delayedFileTimer
);
460 LAMEXP_DELETE(m_metaInfoModel
);
461 LAMEXP_DELETE(m_encoderButtonGroup
);
462 LAMEXP_DELETE(m_encoderButtonGroup
);
463 LAMEXP_DELETE(m_sourceFilesContextMenu
);
464 LAMEXP_DELETE(m_outputFolderFavoritesMenu
);
465 LAMEXP_DELETE(m_dropBox
);
468 ////////////////////////////////////////////////////////////
470 ////////////////////////////////////////////////////////////
473 * Add file to source list
475 void MainWindow::addFiles(const QStringList
&files
)
482 tabWidget
->setCurrentIndex(0);
484 FileAnalyzer
*analyzer
= new FileAnalyzer(files
);
485 connect(analyzer
, SIGNAL(fileSelected(QString
)), m_banner
, SLOT(setText(QString
)), Qt::QueuedConnection
);
486 connect(analyzer
, SIGNAL(fileAnalyzed(AudioFileModel
)), m_fileListModel
, SLOT(addFile(AudioFileModel
)), Qt::QueuedConnection
);
487 connect(m_banner
, SIGNAL(userAbort()), analyzer
, SLOT(abortProcess()), Qt::DirectConnection
);
489 m_banner
->show(tr("Adding file(s), please wait..."), analyzer
);
491 if(analyzer
->filesDenied())
493 QMessageBox::warning(this, tr("Access Denied"), QString("<nobr>%1<br>%2</nobr>").arg(tr("%1 file(s) have been rejected, because read access was not granted!").arg(analyzer
->filesDenied()), tr("This usually means the file is locked by another process.")));
495 if(analyzer
->filesDummyCDDA())
497 QMessageBox::warning(this, tr("CDDA Files"), QString("<nobr>%1<br><br>%2<br>%3</nobr>").arg(tr("%1 file(s) have been rejected, because they are dummy CDDA files!").arg(analyzer
->filesDummyCDDA()), tr("Sorry, LameXP cannot extract audio tracks from an Audio−CD at present."), tr("We recommend using %1 for that purpose.").arg("<a href=\"http://www.exactaudiocopy.de/\">Exact Audio Copy</a>")));
499 if(analyzer
->filesCueSheet())
501 QMessageBox::warning(this, tr("Cue Sheet"), QString("<nobr>%1<br>%2</nobr>").arg(tr("%1 file(s) have been rejected, because they appear to be Cue Sheet images!").arg(analyzer
->filesCueSheet()), tr("Please use LameXP's Cue Sheet wizard for importing Cue Sheet files.")));
503 if(analyzer
->filesRejected())
505 QMessageBox::warning(this, tr("Files Rejected"), QString("<nobr>%1<br>%2</nobr>").arg(tr("%1 file(s) have been rejected, because the file format could not be recognized!").arg(analyzer
->filesRejected()), tr("This usually means the file is damaged or the file format is not supported.")));
508 LAMEXP_DELETE(analyzer
);
509 sourceFileView
->scrollToBottom();
514 * Add folder to source list
516 void MainWindow::addFolder(const QString
&path
, bool recursive
, bool delayed
)
518 QFileInfoList folderInfoList
;
519 folderInfoList
<< QFileInfo(path
);
520 QStringList fileList
;
522 m_banner
->show(tr("Scanning folder(s) for files, please wait..."));
524 QApplication::processEvents();
525 GetAsyncKeyState(VK_ESCAPE
);
527 while(!folderInfoList
.isEmpty())
529 if(GetAsyncKeyState(VK_ESCAPE
) & 0x0001)
531 MessageBeep(MB_ICONERROR
);
532 qWarning("Operation cancelled by user!");
537 QDir
currentDir(folderInfoList
.takeFirst().canonicalFilePath());
538 QFileInfoList fileInfoList
= currentDir
.entryInfoList(QDir::Files
| QDir::NoSymLinks
);
540 while(!fileInfoList
.isEmpty())
542 fileList
<< fileInfoList
.takeFirst().canonicalFilePath();
545 QApplication::processEvents();
549 folderInfoList
.append(currentDir
.entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
));
550 QApplication::processEvents();
555 QApplication::processEvents();
557 if(!fileList
.isEmpty())
561 addFilesDelayed(fileList
);
573 bool MainWindow::checkForUpdates(void)
575 bool bReadyToInstall
= false;
577 UpdateDialog
*updateDialog
= new UpdateDialog(m_settings
, this);
578 updateDialog
->exec();
580 if(updateDialog
->getSuccess())
582 m_settings
->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate
));
583 bReadyToInstall
= updateDialog
->updateReadyToInstall();
586 LAMEXP_DELETE(updateDialog
);
587 return bReadyToInstall
;
590 void MainWindow::refreshFavorites(void)
592 QList
<QAction
*> folderList
= m_outputFolderFavoritesMenu
->actions();
593 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
594 while(favorites
.count() > 6) favorites
.removeFirst();
596 while(!folderList
.isEmpty())
598 QAction
*currentItem
= folderList
.takeFirst();
599 if(currentItem
->isSeparator()) break;
600 m_outputFolderFavoritesMenu
->removeAction(currentItem
);
601 LAMEXP_DELETE(currentItem
);
604 QAction
*lastItem
= m_outputFolderFavoritesMenu
->actions().first();
606 while(!favorites
.isEmpty())
608 QString path
= favorites
.takeLast();
609 if(QDir(path
).exists())
611 QAction
*action
= new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path
), this);
612 action
->setData(path
);
613 m_outputFolderFavoritesMenu
->insertAction(lastItem
, action
);
614 connect(action
, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
620 ////////////////////////////////////////////////////////////
622 ////////////////////////////////////////////////////////////
625 * Window is about to be shown
627 void MainWindow::showEvent(QShowEvent
*event
)
630 m_dropNoteLabel
->setGeometry(0, 0, sourceFileView
->width(), sourceFileView
->height());
631 sourceModelChanged();
633 if(!event
->spontaneous())
635 tabWidget
->setCurrentIndex(0);
640 m_firstTimeShown
= false;
641 QTimer::singleShot(0, this, SLOT(windowShown()));
645 if(m_settings
->dropBoxWidgetEnabled())
647 m_dropBox
->setVisible(true);
653 * Re-translate the UI
655 void MainWindow::changeEvent(QEvent
*e
)
657 if(e
->type() == QEvent::LanguageChange
)
659 int comboBoxIndex
[5];
661 //Backup combobox indices, as retranslateUi() resets
662 comboBoxIndex
[0] = comboBoxMP3ChannelMode
->currentIndex();
663 comboBoxIndex
[1] = comboBoxSamplingRate
->currentIndex();
664 comboBoxIndex
[2] = comboBoxAACProfile
->currentIndex();
665 comboBoxIndex
[3] = comboBoxAftenCodingMode
->currentIndex();
666 comboBoxIndex
[4] = comboBoxAftenDRCMode
->currentIndex();
668 //Re-translate from UIC
669 Ui::MainWindow::retranslateUi(this);
671 //Restore combobox indices
672 comboBoxMP3ChannelMode
->setCurrentIndex(comboBoxIndex
[0]);
673 comboBoxSamplingRate
->setCurrentIndex(comboBoxIndex
[1]);
674 comboBoxAACProfile
->setCurrentIndex(comboBoxIndex
[2]);
675 comboBoxAftenCodingMode
->setCurrentIndex(comboBoxIndex
[3]);
676 comboBoxAftenDRCMode
->setCurrentIndex(comboBoxIndex
[4]);
678 //Update the window title
681 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
683 else if(lamexp_version_demo())
685 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
688 //Manually re-translate widgets that UIC doesn't handle
689 m_dropNoteLabel
->setText(QString("» %1 «").arg(tr("You can drop in audio files here!")));
690 m_showDetailsContextAction
->setText(tr("Show Details"));
691 m_previewContextAction
->setText(tr("Open File in External Application"));
692 m_findFileContextAction
->setText(tr("Browse File Location"));
693 m_showFolderContextAction
->setText(tr("Browse Selected Folder"));
694 m_addFavoriteFolderAction
->setText(tr("Bookmark Current Output Folder"));
697 m_metaInfoModel
->clearData();
698 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
699 updateEncoder(m_settings
->compressionEncoder());
700 updateLameAlgoQuality(sliderLameAlgoQuality
->value());
701 updateMaximumInstances(sliderMaxInstances
->value());
702 renameOutputPatternChanged(lineEditRenamePattern
->text());
704 //Re-install shell integration
705 if(m_settings
->shellIntegrationEnabled())
707 ShellIntegration::install();
710 //Force resize, if needed
711 tabPageChanged(tabWidget
->currentIndex());
716 * File dragged over window
718 void MainWindow::dragEnterEvent(QDragEnterEvent
*event
)
720 QStringList formats
= event
->mimeData()->formats();
722 if(formats
.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive
) && formats
.contains("text/uri-list", Qt::CaseInsensitive
))
724 event
->acceptProposedAction();
729 * File dropped onto window
731 void MainWindow::dropEvent(QDropEvent
*event
)
735 QStringList droppedFiles
;
736 QList
<QUrl
> urls
= event
->mimeData()->urls();
738 while(!urls
.isEmpty())
740 QUrl currentUrl
= urls
.takeFirst();
741 QFileInfo
file(currentUrl
.toLocalFile());
748 qDebug64("Dropped File: %1", file
.canonicalFilePath());
749 droppedFiles
<< file
.canonicalFilePath();
754 qDebug64("Dropped Folder: %1", file
.canonicalFilePath());
755 QList
<QFileInfo
> list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Files
| QDir::NoSymLinks
);
758 for(int j
= 0; j
< list
.count(); j
++)
760 droppedFiles
<< list
.at(j
).canonicalFilePath();
765 list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
);
766 for(int j
= 0; j
< list
.count(); j
++)
768 qDebug64("Descending to Folder: %1", list
.at(j
).canonicalFilePath());
769 urls
.prepend(QUrl::fromLocalFile(list
.at(j
).canonicalFilePath()));
775 if(!droppedFiles
.isEmpty())
777 addFilesDelayed(droppedFiles
, true);
782 * Window tries to close
784 void MainWindow::closeEvent(QCloseEvent
*event
)
786 if(m_banner
->isVisible() || m_delayedFileTimer
->isActive())
788 MessageBeep(MB_ICONEXCLAMATION
);
801 void MainWindow::resizeEvent(QResizeEvent
*event
)
803 QMainWindow::resizeEvent(event
);
804 m_dropNoteLabel
->setGeometry(0, 0, sourceFileView
->width(), sourceFileView
->height());
810 bool MainWindow::eventFilter(QObject
*obj
, QEvent
*event
)
812 if(obj
== m_fileSystemModel
)
814 if(QApplication::overrideCursor() == NULL
)
816 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
817 QTimer::singleShot(250, this, SLOT(restoreCursor()));
820 else if(obj
== outputFolderView
)
822 switch(event
->type())
826 case QEvent::KeyPress
:
827 case QEvent::KeyRelease
:
828 case QEvent::FocusIn
:
829 case QEvent::FocusOut
:
830 case QEvent::TouchEnd
:
831 outputFolderViewClicked(outputFolderView
->currentIndex());
835 else if(obj
== outputFolderLabel
)
837 switch(event
->type())
839 case QEvent::MouseButtonPress
:
840 if(dynamic_cast<QMouseEvent
*>(event
)->button() == Qt::LeftButton
)
842 QDesktopServices::openUrl(QString("file:///%1").arg(outputFolderLabel
->text()));
846 outputFolderLabel
->setForegroundRole(QPalette::Link
);
849 outputFolderLabel
->setForegroundRole(QPalette::WindowText
);
853 else if(obj
== outputFoldersFovoritesLabel
)
855 QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
);
856 QPoint pos
= (mouseEvent
!= NULL
) ? mouseEvent
->pos() : QPoint();
857 QWidget
*sender
= dynamic_cast<QLabel
*>(obj
);
859 switch(event
->type())
862 outputFoldersFovoritesLabel
->setFrameShadow(QFrame::Raised
);
864 case QEvent::MouseButtonPress
:
865 outputFoldersFovoritesLabel
->setFrameShadow(QFrame::Sunken
);
867 case QEvent::MouseButtonRelease
:
868 outputFoldersFovoritesLabel
->setFrameShadow(QFrame::Raised
);
869 if(sender
&& mouseEvent
)
871 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
)
873 m_outputFolderFavoritesMenu
->popup(sender
->mapToGlobal(pos
));
878 outputFoldersFovoritesLabel
->setFrameShadow(QFrame::Plain
);
886 ////////////////////////////////////////////////////////////
888 ////////////////////////////////////////////////////////////
890 // =========================================================
892 // =========================================================
897 void MainWindow::windowShown(void)
899 QStringList arguments
= QApplication::arguments();
902 if(m_settings
->licenseAccepted() <= 0)
906 if(m_settings
->licenseAccepted() == 0)
908 AboutDialog
*about
= new AboutDialog(m_settings
, this, true);
909 iAccepted
= about
->exec();
910 LAMEXP_DELETE(about
);
915 m_settings
->licenseAccepted(-1);
916 QApplication::processEvents();
917 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
918 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
919 if(!QProcess::startDetached(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()), QStringList()))
921 MoveFileEx(QWCHAR(QDir::toNativeSeparators(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath())), NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
| MOVEFILE_REPLACE_EXISTING
);
923 QApplication::quit();
927 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WOOHOO
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
928 m_settings
->licenseAccepted(1);
931 QMessageBox::information(this, "We want you!", QString("<nobr>We are still looking for LameXP translators!<br><br>If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:<br><tt>" + LINK("http://mulder.brhack.net/public/doc/lamexp_translate.html") + "</tt></nobr><br>"));
935 //Check for expiration
936 if(lamexp_version_demo())
938 if(QDate::currentDate() >= lamexp_version_expires())
940 qWarning("Binary has expired !!!");
941 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
942 if(QMessageBox::warning(this, tr("LameXP - Expired"), QString("<nobr>%1<br>%2</nobr>").arg(tr("This demo (pre-release) version of LameXP has expired at %1.").arg(lamexp_version_expires().toString(Qt::ISODate
)), tr("LameXP is free software and release versions won't expire.")), tr("Check for Updates"), tr("Exit Program")) == 0)
946 QApplication::quit();
951 //Slow startup indicator
952 if(m_settings
->slowStartup() && m_settings
->antivirNotificationsEnabled())
955 message
+= NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP."));
956 message
+= NOBR(tr("Please refer to the %1 document for details and solutions!")).arg("<a href=\"http://lamexp.git.sourceforge.net/git/gitweb.cgi?p=lamexp/lamexp;a=blob_plain;f=doc/FAQ.html;hb=HEAD#df406578\">F.A.Q.</a>");
957 if(QMessageBox::warning(this, tr("Slow Startup"), message
, tr("Discard"), tr("Don't Show Again")) == 1)
959 m_settings
->antivirNotificationsEnabled(false);
960 actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
965 if(QDate::currentDate() >= lamexp_version_date().addYears(1))
967 qWarning("Binary is more than a year old, time to update!");
968 if(QMessageBox::warning(this, tr("Urgent Update"), NOBR(tr("Your version of LameXP is more than a year old. Time for an update!")), tr("Check for Updates"), tr("Exit Program")) == 0)
970 if(checkForUpdates())
972 QApplication::quit();
978 QApplication::quit();
982 else if(m_settings
->autoUpdateEnabled())
984 QDate lastUpdateCheck
= QDate::fromString(m_settings
->autoUpdateLastCheck(), Qt::ISODate
);
985 if(!lastUpdateCheck
.isValid() || QDate::currentDate() >= lastUpdateCheck
.addDays(14))
987 if(QMessageBox::information(this, tr("Update Reminder"), QString("<nobr>%1</nobr>").arg(lastUpdateCheck
.isValid() ? tr("Your last update check was more than 14 days ago. Check for updates now?") : tr("Your did not check for LameXP updates yet. Check for updates now?")).replace("-", "−"), tr("Check for Updates"), tr("Postpone")) == 0)
989 if(checkForUpdates())
991 QApplication::quit();
998 //Check for AAC support
999 if(m_neroEncoderAvailable
)
1001 if(m_settings
->neroAacNotificationsEnabled())
1003 if(lamexp_tool_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1005 QString messageText
;
1006 messageText
+= NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1007 messageText
+= NOBR(tr("The current version available is %1 (or later), but you still have version %2 installed.").arg(lamexp_version2string("?.?.?.?", lamexp_toolver_neroaac(), tr("n/a")), lamexp_version2string("?.?.?.?", lamexp_tool_version("neroAacEnc.exe"), tr("n/a")))).append("<br><br>");
1008 messageText
+= NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1009 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br>";
1010 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText
);
1016 if(m_settings
->neroAacNotificationsEnabled() && (!m_fhgEncoderAvailable
))
1018 QString appPath
= QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1019 if(appPath
.isEmpty()) appPath
= QCoreApplication::applicationDirPath();
1020 QString messageText
;
1021 messageText
+= NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1022 messageText
+= NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1023 messageText
+= NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1024 messageText
+= QString("<nobr><tt><a href=\"file:///%1\">%2</a></tt></nobr><br><br>").arg(QDir::toNativeSeparators(appPath
), QDir::toNativeSeparators(appPath
).replace("-", "−"));
1025 messageText
+= NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1026 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br>";
1027 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText
, tr("Discard"), tr("Don't Show Again")) == 1)
1029 m_settings
->neroAacNotificationsEnabled(false);
1030 actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1035 //Add files from the command-line
1036 for(int i
= 0; i
< arguments
.count() - 1; i
++)
1038 QStringList addedFiles
;
1039 if(!arguments
[i
].compare("--add", Qt::CaseInsensitive
))
1041 QFileInfo
currentFile(arguments
[++i
].trimmed());
1042 qDebug("Adding file from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1043 addedFiles
.append(currentFile
.absoluteFilePath());
1045 if(!addedFiles
.isEmpty())
1047 addFilesDelayed(addedFiles
);
1051 //Add folders from the command-line
1052 for(int i
= 0; i
< arguments
.count() - 1; i
++)
1054 if(!arguments
[i
].compare("--add-folder", Qt::CaseInsensitive
))
1056 QFileInfo
currentFile(arguments
[++i
].trimmed());
1057 qDebug("Adding folder from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1058 addFolder(currentFile
.absoluteFilePath(), false, true);
1060 if(!arguments
[i
].compare("--add-recursive", Qt::CaseInsensitive
))
1062 QFileInfo
currentFile(arguments
[++i
].trimmed());
1063 qDebug("Adding folder recursively from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1064 addFolder(currentFile
.absoluteFilePath(), true, true);
1068 //Enable shell integration
1069 if(m_settings
->shellIntegrationEnabled())
1071 ShellIntegration::install();
1074 //Make DropBox visible
1075 if(m_settings
->dropBoxWidgetEnabled())
1077 m_dropBox
->setVisible(true);
1081 // =========================================================
1082 // Main button solots
1083 // =========================================================
1088 void MainWindow::encodeButtonClicked(void)
1090 static const __int64 oneGigabyte
= 1073741824i64
;
1091 static const __int64 minimumFreeDiskspaceMultiplier
= 2i64
;
1092 static const char *writeTestBuffer
= "LAMEXP_WRITE_TEST";
1096 if(m_fileListModel
->rowCount() < 1)
1098 QMessageBox::warning(this, tr("LameXP"), QString("<nobr>%1</nobr>").arg(tr("You must add at least one file to the list before proceeding!")));
1099 tabWidget
->setCurrentIndex(0);
1103 QString tempFolder
= m_settings
->customTempPathEnabled() ? m_settings
->customTempPath() : lamexp_temp_folder2();
1104 if(!QFileInfo(tempFolder
).exists() || !QFileInfo(tempFolder
).isDir())
1106 if(QMessageBox::warning(this, tr("Not Found"), QString("<nobr>%1</nobr><br><nobr>%2</nobr>").arg(tr("Your currently selected TEMP folder does not exist anymore:"), QDir::toNativeSeparators(tempFolder
)), tr("Restore Default"), tr("Cancel")) == 0)
1108 while(checkBoxUseSystemTempFolder
->isChecked() == m_settings
->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder
->click();
1113 qint64 currentFreeDiskspace
= lamexp_free_diskspace(tempFolder
);
1114 if(currentFreeDiskspace
< (oneGigabyte
* minimumFreeDiskspaceMultiplier
))
1116 QStringList tempFolderParts
= tempFolder
.split("/", QString::SkipEmptyParts
, Qt::CaseInsensitive
);
1117 tempFolderParts
.takeLast();
1118 if(m_settings
->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1119 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), QString("<nobr>%1</nobr><br><nobr>%2</nobr><br><br>%3").arg(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier
)), tr("It is highly recommend to free up more diskspace before proceeding with the encode!"), tr("Your TEMP folder is located at:")).append("<br><nobr><i><a href=\"file:///%3\">%3</a></i></nobr><br>").arg(tempFolderParts
.join("\\")), tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1122 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(lamexp_known_folder(lamexp_folder_systemfolder
)), QStringList() << "/D" << tempFolderParts
.first());
1127 QMessageBox::warning(this, tr("Low Diskspace"), tr("You are proceeding with low diskspace. Problems might occur!"));
1132 switch(m_settings
->compressionEncoder())
1134 case SettingsModel::MP3Encoder
:
1135 case SettingsModel::VorbisEncoder
:
1136 case SettingsModel::AACEncoder
:
1137 case SettingsModel::AC3Encoder
:
1138 case SettingsModel::FLACEncoder
:
1139 case SettingsModel::PCMEncoder
:
1142 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1143 tabWidget
->setCurrentIndex(3);
1147 if(!m_settings
->outputToSourceDir())
1149 QFile
writeTest(QString("%1/~%2.txt").arg(m_settings
->outputDir(), lamexp_rand_str()));
1150 if(!(writeTest
.open(QIODevice::ReadWrite
) && (writeTest
.write(writeTestBuffer
) == strlen(writeTestBuffer
))))
1152 QMessageBox::warning(this, tr("LameXP"), QString("%1<br><nobr>%2</nobr><br><br>%3").arg(tr("Cannot write to the selected output directory."), m_settings
->outputDir(), tr("Please choose a different directory!")));
1153 tabWidget
->setCurrentIndex(1);
1170 void MainWindow::aboutButtonClicked(void)
1176 AboutDialog
*aboutBox
= new AboutDialog(m_settings
, this);
1178 LAMEXP_DELETE(aboutBox
);
1185 void MainWindow::closeButtonClicked(void)
1191 // =========================================================
1193 // =========================================================
1198 void MainWindow::tabPageChanged(int idx
)
1200 QList
<QAction
*> actions
= m_tabActionGroup
->actions();
1201 for(int i
= 0; i
< actions
.count(); i
++)
1204 int actionIndex
= actions
.at(i
)->data().toInt(&ok
);
1205 if(ok
&& actionIndex
== idx
)
1207 actions
.at(i
)->setChecked(true);
1211 int initialWidth
= this->width();
1212 int maximumWidth
= QApplication::desktop()->width();
1214 if(this->isVisible())
1216 while(tabWidget
->width() < tabWidget
->sizeHint().width())
1218 int previousWidth
= this->width();
1219 this->resize(this->width() + 1, this->height());
1220 if(this->frameGeometry().width() >= maximumWidth
) break;
1221 if(this->width() <= previousWidth
) break;
1225 if(idx
== tabWidget
->indexOf(tabOptions
) && scrollArea
->widget() && this->isVisible())
1227 for(int i
= 0; i
< 2; i
++)
1229 QApplication::processEvents();
1230 while(scrollArea
->viewport()->width() < scrollArea
->widget()->width())
1232 int previousWidth
= this->width();
1233 this->resize(this->width() + 1, this->height());
1234 if(this->frameGeometry().width() >= maximumWidth
) break;
1235 if(this->width() <= previousWidth
) break;
1239 else if(idx
== tabWidget
->indexOf(tabSourceFiles
))
1241 m_dropNoteLabel
->setGeometry(0, 0, sourceFileView
->width(), sourceFileView
->height());
1243 else if(idx
== tabWidget
->indexOf(tabOutputDir
))
1245 if(!m_OutputFolderViewInitialized
)
1247 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
1251 if(initialWidth
< this->width())
1253 QPoint prevPos
= this->pos();
1254 int delta
= (this->width() - initialWidth
) >> 2;
1255 move(prevPos
.x() - delta
, prevPos
.y());
1260 * Tab action triggered
1262 void MainWindow::tabActionActivated(QAction
*action
)
1264 if(action
&& action
->data().isValid())
1267 int index
= action
->data().toInt(&ok
);
1270 tabWidget
->setCurrentIndex(index
);
1275 // =========================================================
1277 // =========================================================
1280 * Style action triggered
1282 void MainWindow::styleActionActivated(QAction
*action
)
1284 //Change style setting
1285 if(action
&& action
->data().isValid())
1288 int actionIndex
= action
->data().toInt(&ok
);
1291 m_settings
->interfaceStyle(actionIndex
);
1295 //Set up the new style
1296 switch(m_settings
->interfaceStyle())
1299 if(actionStyleCleanlooks
->isEnabled())
1301 actionStyleCleanlooks
->setChecked(true);
1302 QApplication::setStyle(new QCleanlooksStyle());
1306 if(actionStyleWindowsVista
->isEnabled())
1308 actionStyleWindowsVista
->setChecked(true);
1309 QApplication::setStyle(new QWindowsVistaStyle());
1313 if(actionStyleWindowsXP
->isEnabled())
1315 actionStyleWindowsXP
->setChecked(true);
1316 QApplication::setStyle(new QWindowsXPStyle());
1320 if(actionStyleWindowsClassic
->isEnabled())
1322 actionStyleWindowsClassic
->setChecked(true);
1323 QApplication::setStyle(new QWindowsStyle());
1327 actionStylePlastique
->setChecked(true);
1328 QApplication::setStyle(new QPlastiqueStyle());
1332 //Force re-translate after style change
1333 changeEvent(new QEvent(QEvent::LanguageChange
));
1337 * Language action triggered
1339 void MainWindow::languageActionActivated(QAction
*action
)
1341 if(action
->data().type() == QVariant::String
)
1343 QString langId
= action
->data().toString();
1345 if(lamexp_install_translator(langId
))
1347 action
->setChecked(true);
1348 m_settings
->currentLanguage(langId
);
1354 * Load language from file action triggered
1356 void MainWindow::languageFromFileActionActivated(bool checked
)
1358 QFileDialog
dialog(this, tr("Load Translation"));
1359 dialog
.setFileMode(QFileDialog::ExistingFile
);
1360 dialog
.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
1364 QStringList selectedFiles
= dialog
.selectedFiles();
1365 if(lamexp_install_translator_from_file(selectedFiles
.first()))
1367 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
1368 while(!actions
.isEmpty())
1370 actions
.takeFirst()->setChecked(false);
1375 languageActionActivated(m_languageActionGroup
->actions().first());
1380 // =========================================================
1382 // =========================================================
1385 * Disable update reminder action
1387 void MainWindow::disableUpdateReminderActionTriggered(bool checked
)
1391 if(0 == QMessageBox::question(this, tr("Disable Update Reminder"), tr("Do you really want to disable the update reminder?"), tr("Yes"), tr("No"), QString(), 1))
1393 QMessageBox::information(this, tr("Update Reminder"), QString("%1<br>%2").arg(tr("The update reminder has been disabled."), tr("Please remember to check for updates at regular intervals!")));
1394 m_settings
->autoUpdateEnabled(false);
1398 m_settings
->autoUpdateEnabled(true);
1403 QMessageBox::information(this, tr("Update Reminder"), tr("The update reminder has been re-enabled."));
1404 m_settings
->autoUpdateEnabled(true);
1407 actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
1411 * Disable sound effects action
1413 void MainWindow::disableSoundsActionTriggered(bool checked
)
1417 if(0 == QMessageBox::question(this, tr("Disable Sound Effects"), tr("Do you really want to disable all sound effects?"), tr("Yes"), tr("No"), QString(), 1))
1419 QMessageBox::information(this, tr("Sound Effects"), tr("All sound effects have been disabled."));
1420 m_settings
->soundsEnabled(false);
1424 m_settings
->soundsEnabled(true);
1429 QMessageBox::information(this, tr("Sound Effects"), tr("The sound effects have been re-enabled."));
1430 m_settings
->soundsEnabled(true);
1433 actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
1437 * Disable Nero AAC encoder action
1439 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked
)
1443 if(0 == QMessageBox::question(this, tr("Nero AAC Notifications"), tr("Do you really want to disable all Nero AAC Encoder notifications?"), tr("Yes"), tr("No"), QString(), 1))
1445 QMessageBox::information(this, tr("Nero AAC Notifications"), tr("All Nero AAC Encoder notifications have been disabled."));
1446 m_settings
->neroAacNotificationsEnabled(false);
1450 m_settings
->neroAacNotificationsEnabled(true);
1455 QMessageBox::information(this, tr("Nero AAC Notifications"), tr("The Nero AAC Encoder notifications have been re-enabled."));
1456 m_settings
->neroAacNotificationsEnabled(true);
1459 actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1463 * Disable WMA Decoder component action
1465 //void MainWindow::disableWmaDecoderNotificationsActionTriggered(bool checked)
1469 // if(0 == QMessageBox::question(this, tr("WMA Decoder Notifications"), tr("Do you really want to disable all WMA Decoder notifications?"), tr("Yes"), tr("No"), QString(), 1))
1471 // QMessageBox::information(this, tr("WMA Decoder Notifications"), tr("All WMA Decoder notifications have been disabled."));
1472 // m_settings->wmaDecoderNotificationsEnabled(false);
1476 // m_settings->wmaDecoderNotificationsEnabled(true);
1481 // QMessageBox::information(this, tr("WMA Decoder Notifications"), tr("The WMA Decoder notifications have been re-enabled."));
1482 // m_settings->wmaDecoderNotificationsEnabled(true);
1485 // actionDisableWmaDecoderNotifications->setChecked(!m_settings->wmaDecoderNotificationsEnabled());
1489 * Disable slow startup action
1491 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked
)
1495 if(0 == QMessageBox::question(this, tr("Slow Startup Notifications"), tr("Do you really want to disable the slow startup notifications?"), tr("Yes"), tr("No"), QString(), 1))
1497 QMessageBox::information(this, tr("Slow Startup Notifications"), tr("The slow startup notifications have been disabled."));
1498 m_settings
->antivirNotificationsEnabled(false);
1502 m_settings
->antivirNotificationsEnabled(true);
1507 QMessageBox::information(this, tr("Slow Startup Notifications"), tr("The slow startup notifications have been re-enabled."));
1508 m_settings
->antivirNotificationsEnabled(true);
1511 actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
1515 * Download and install WMA Decoder component
1517 //void MainWindow::installWMADecoderActionTriggered(bool checked)
1519 // if(QMessageBox::question(this, tr("Install WMA Decoder"), tr("Do you want to download and install the WMA File Decoder component now?"), tr("Download && Install"), tr("Cancel")) == 0)
1521 // if(installWMADecoder())
1523 // QApplication::quit();
1530 * Import a Cue Sheet file
1532 void MainWindow::importCueSheetActionTriggered(bool checked
)
1538 QString selectedCueFile
;
1540 if(USE_NATIVE_FILE_DIALOG
)
1542 selectedCueFile
= QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings
->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1546 QFileDialog
dialog(this, tr("Open Cue Sheet"));
1547 dialog
.setFileMode(QFileDialog::ExistingFile
);
1548 dialog
.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1549 dialog
.setDirectory(m_settings
->mostRecentInputPath());
1552 selectedCueFile
= dialog
.selectedFiles().first();
1556 if(!selectedCueFile
.isEmpty())
1558 m_settings
->mostRecentInputPath(QFileInfo(selectedCueFile
).canonicalPath());
1559 CueImportDialog
*cueImporter
= new CueImportDialog(this, m_fileListModel
, selectedCueFile
);
1560 cueImporter
->exec();
1561 LAMEXP_DELETE(cueImporter
);
1567 * Show the "drop box" widget
1569 void MainWindow::showDropBoxWidgetActionTriggered(bool checked
)
1571 m_settings
->dropBoxWidgetEnabled(true);
1573 if(!m_dropBox
->isVisible())
1578 lamexp_blink_window(m_dropBox
);
1582 * Check for beta (pre-release) updates
1584 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked
)
1586 bool checkUpdatesNow
= false;
1590 if(0 == QMessageBox::question(this, tr("Beta Updates"), tr("Do you really want LameXP to check for Beta (pre-release) updates?"), tr("Yes"), tr("No"), QString(), 1))
1592 if(0 == QMessageBox::information(this, tr("Beta Updates"), tr("LameXP will check for Beta (pre-release) updates from now on."), tr("Check Now"), tr("Discard")))
1594 checkUpdatesNow
= true;
1596 m_settings
->autoUpdateCheckBeta(true);
1600 m_settings
->autoUpdateCheckBeta(false);
1605 QMessageBox::information(this, tr("Beta Updates"), tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on."));
1606 m_settings
->autoUpdateCheckBeta(false);
1609 actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta());
1613 if(checkForUpdates())
1615 QApplication::quit();
1621 * Disable shell integration action
1623 void MainWindow::disableShellIntegrationActionTriggered(bool checked
)
1627 if(0 == QMessageBox::question(this, tr("Shell Integration"), tr("Do you really want to disable the LameXP shell integration?"), tr("Yes"), tr("No"), QString(), 1))
1629 ShellIntegration::remove();
1630 QMessageBox::information(this, tr("Shell Integration"), tr("The LameXP shell integration has been disabled."));
1631 m_settings
->shellIntegrationEnabled(false);
1635 m_settings
->shellIntegrationEnabled(true);
1640 ShellIntegration::install();
1641 QMessageBox::information(this, tr("Shell Integration"), tr("The LameXP shell integration has been re-enabled."));
1642 m_settings
->shellIntegrationEnabled(true);
1645 actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
1647 if(lamexp_portable_mode() && actionDisableShellIntegration
->isChecked())
1649 actionDisableShellIntegration
->setEnabled(false);
1653 // =========================================================
1655 // =========================================================
1658 * Visit homepage action
1660 void MainWindow::visitHomepageActionActivated(void)
1662 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
1664 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
1666 QDesktopServices::openUrl(QUrl(action
->data().toString()));
1674 void MainWindow::documentActionActivated(void)
1676 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
1678 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
1680 QFileInfo
document(action
->data().toString());
1681 QFileInfo
resource(QString(":/doc/%1.html").arg(document
.baseName()));
1682 if(document
.exists() && document
.isFile() && (document
.size() == resource
.size()))
1684 QDesktopServices::openUrl(QUrl::fromLocalFile(document
.canonicalFilePath()));
1688 QFile
source(resource
.filePath());
1689 QFile
output(QString("%1/%2.%3.html").arg(lamexp_temp_folder2(), document
.baseName(), lamexp_rand_str().left(8)));
1690 if(source
.open(QIODevice::ReadOnly
) && output
.open(QIODevice::ReadWrite
))
1692 output
.write(source
.readAll());
1693 action
->setData(output
.fileName());
1696 QDesktopServices::openUrl(QUrl::fromLocalFile(output
.fileName()));
1704 * Check for updates action
1706 void MainWindow::checkUpdatesActionActivated(void)
1713 bFlag
= checkForUpdates();
1718 QApplication::quit();
1722 // =========================================================
1723 // Source file slots
1724 // =========================================================
1727 * Add file(s) button
1729 void MainWindow::addFilesButtonClicked(void)
1735 if(USE_NATIVE_FILE_DIALOG
)
1737 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
1738 QStringList selectedFiles
= QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings
->mostRecentInputPath(), fileTypeFilters
.join(";;"));
1739 if(!selectedFiles
.isEmpty())
1741 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
1742 addFiles(selectedFiles
);
1747 QFileDialog
dialog(this, tr("Add file(s)"));
1748 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
1749 dialog
.setFileMode(QFileDialog::ExistingFiles
);
1750 dialog
.setNameFilter(fileTypeFilters
.join(";;"));
1751 dialog
.setDirectory(m_settings
->mostRecentInputPath());
1754 QStringList selectedFiles
= dialog
.selectedFiles();
1755 if(!selectedFiles
.isEmpty())
1757 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
1758 addFiles(selectedFiles
);
1766 * Open folder action
1768 void MainWindow::openFolderActionActivated(void)
1771 QString selectedFolder
;
1773 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
1777 if(USE_NATIVE_FILE_DIALOG
)
1779 selectedFolder
= QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings
->mostRecentInputPath());
1783 QFileDialog
dialog(this, tr("Add Folder"));
1784 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
1785 dialog
.setDirectory(m_settings
->mostRecentInputPath());
1788 selectedFolder
= dialog
.selectedFiles().first();
1792 if(!selectedFolder
.isEmpty())
1794 m_settings
->mostRecentInputPath(QDir(selectedFolder
).canonicalPath());
1795 addFolder(selectedFolder
, action
->data().toBool());
1802 * Remove file button
1804 void MainWindow::removeFileButtonClicked(void)
1806 if(sourceFileView
->currentIndex().isValid())
1808 int iRow
= sourceFileView
->currentIndex().row();
1809 m_fileListModel
->removeFile(sourceFileView
->currentIndex());
1810 sourceFileView
->selectRow(iRow
< m_fileListModel
->rowCount() ? iRow
: m_fileListModel
->rowCount()-1);
1815 * Clear files button
1817 void MainWindow::clearFilesButtonClicked(void)
1819 m_fileListModel
->clearFiles();
1823 * Move file up button
1825 void MainWindow::fileUpButtonClicked(void)
1827 if(sourceFileView
->currentIndex().isValid())
1829 int iRow
= sourceFileView
->currentIndex().row() - 1;
1830 m_fileListModel
->moveFile(sourceFileView
->currentIndex(), -1);
1831 sourceFileView
->selectRow(iRow
>= 0 ? iRow
: 0);
1836 * Move file down button
1838 void MainWindow::fileDownButtonClicked(void)
1840 if(sourceFileView
->currentIndex().isValid())
1842 int iRow
= sourceFileView
->currentIndex().row() + 1;
1843 m_fileListModel
->moveFile(sourceFileView
->currentIndex(), 1);
1844 sourceFileView
->selectRow(iRow
< m_fileListModel
->rowCount() ? iRow
: m_fileListModel
->rowCount()-1);
1849 * Show details button
1851 void MainWindow::showDetailsButtonClicked(void)
1856 MetaInfoDialog
*metaInfoDialog
= new MetaInfoDialog(this);
1857 QModelIndex index
= sourceFileView
->currentIndex();
1859 while(index
.isValid())
1863 index
= m_fileListModel
->index(index
.row() + 1, index
.column());
1864 sourceFileView
->selectRow(index
.row());
1868 index
= m_fileListModel
->index(index
.row() - 1, index
.column());
1869 sourceFileView
->selectRow(index
.row());
1872 AudioFileModel
&file
= (*m_fileListModel
)[index
];
1875 iResult
= metaInfoDialog
->exec(file
, index
.row() > 0, index
.row() < m_fileListModel
->rowCount() - 1);
1878 if(iResult
== INT_MAX
)
1880 m_metaInfoModel
->assignInfoFrom(file
);
1881 tabWidget
->setCurrentIndex(tabWidget
->indexOf(tabMetaData
));
1888 LAMEXP_DELETE(metaInfoDialog
);
1892 * Show context menu for source files
1894 void MainWindow::sourceFilesContextMenu(const QPoint
&pos
)
1896 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
1897 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
1901 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
1903 m_sourceFilesContextMenu
->popup(sender
->mapToGlobal(pos
));
1909 * Scrollbar of source files moved
1911 void MainWindow::sourceFilesScrollbarMoved(int)
1913 sourceFileView
->resizeColumnToContents(0);
1917 * Open selected file in external player
1919 void MainWindow::previewContextActionTriggered(void)
1921 const static char *appNames
[3] = {"smplayer_portable.exe", "smplayer.exe", "mplayer.exe"};
1922 const static wchar_t *registryKey
= L
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{DB9E4EAB-2717-499F-8D56-4CC8A644AB60}";
1924 QModelIndex index
= sourceFileView
->currentIndex();
1925 if(!index
.isValid())
1930 QString mplayerPath
;
1931 HKEY registryKeyHandle
;
1933 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, registryKey
, 0, KEY_READ
, ®istryKeyHandle
) == ERROR_SUCCESS
)
1935 wchar_t Buffer
[4096];
1936 DWORD BuffSize
= sizeof(wchar_t*) * 4096;
1937 if(RegQueryValueExW(registryKeyHandle
, L
"InstallLocation", 0, 0, reinterpret_cast<BYTE
*>(Buffer
), &BuffSize
) == ERROR_SUCCESS
)
1939 mplayerPath
= QString::fromUtf16(reinterpret_cast<const unsigned short*>(Buffer
));
1943 if(!mplayerPath
.isEmpty())
1945 QDir
mplayerDir(mplayerPath
);
1946 if(mplayerDir
.exists())
1948 for(int i
= 0; i
< 3; i
++)
1950 if(mplayerDir
.exists(appNames
[i
]))
1952 QProcess::startDetached(mplayerDir
.absoluteFilePath(appNames
[i
]), QStringList() << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
1959 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel
->getFile(index
).filePath()));
1963 * Find selected file in explorer
1965 void MainWindow::findFileContextActionTriggered(void)
1967 QModelIndex index
= sourceFileView
->currentIndex();
1970 QString systemRootPath
;
1972 QDir
systemRoot(lamexp_known_folder(lamexp_folder_systemfolder
));
1973 if(systemRoot
.exists() && systemRoot
.cdUp())
1975 systemRootPath
= systemRoot
.canonicalPath();
1978 if(!systemRootPath
.isEmpty())
1980 QFileInfo
explorer(QString("%1/explorer.exe").arg(systemRootPath
));
1981 if(explorer
.exists() && explorer
.isFile())
1983 QProcess::execute(explorer
.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
1989 qWarning("SystemRoot directory could not be detected!");
1995 * Add all pending files
1997 void MainWindow::handleDelayedFiles(void)
1999 m_delayedFileTimer
->stop();
2001 if(m_delayedFileList
->isEmpty())
2006 if(m_banner
->isVisible())
2008 m_delayedFileTimer
->start(5000);
2012 QStringList selectedFiles
;
2013 tabWidget
->setCurrentIndex(0);
2015 while(!m_delayedFileList
->isEmpty())
2017 QFileInfo currentFile
= QFileInfo(m_delayedFileList
->takeFirst());
2018 if(!currentFile
.exists() || !currentFile
.isFile())
2022 selectedFiles
<< currentFile
.canonicalFilePath();
2025 addFiles(selectedFiles
);
2029 * Show or hide Drag'n'Drop notice after model reset
2031 void MainWindow::sourceModelChanged(void)
2033 m_dropNoteLabel
->setVisible(m_fileListModel
->rowCount() <= 0);
2036 // =========================================================
2037 // Output folder slots
2038 // =========================================================
2041 * Output folder changed (mouse clicked)
2043 void MainWindow::outputFolderViewClicked(const QModelIndex
&index
)
2045 if(outputFolderView
->currentIndex() != index
)
2047 outputFolderView
->setCurrentIndex(index
);
2049 QString selectedDir
= m_fileSystemModel
->filePath(index
);
2050 if(selectedDir
.length() < 3) selectedDir
.append(QDir::separator());
2051 outputFolderLabel
->setText(QDir::toNativeSeparators(selectedDir
));
2052 m_settings
->outputDir(selectedDir
);
2056 * Output folder changed (mouse moved)
2058 void MainWindow::outputFolderViewMoved(const QModelIndex
&index
)
2060 if(QApplication::mouseButtons() & Qt::LeftButton
)
2062 outputFolderViewClicked(index
);
2067 * Goto desktop button
2069 void MainWindow::gotoDesktopButtonClicked(void)
2071 QString desktopPath
= QDesktopServices::storageLocation(QDesktopServices::DesktopLocation
);
2073 if(!desktopPath
.isEmpty() && QDir(desktopPath
).exists())
2075 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(desktopPath
));
2076 outputFolderViewClicked(outputFolderView
->currentIndex());
2077 outputFolderView
->setFocus();
2081 buttonGotoDesktop
->setEnabled(false);
2086 * Goto home folder button
2088 void MainWindow::gotoHomeFolderButtonClicked(void)
2090 QString homePath
= QDesktopServices::storageLocation(QDesktopServices::HomeLocation
);
2092 if(!homePath
.isEmpty() && QDir(homePath
).exists())
2094 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(homePath
));
2095 outputFolderViewClicked(outputFolderView
->currentIndex());
2096 outputFolderView
->setFocus();
2100 buttonGotoHome
->setEnabled(false);
2105 * Goto music folder button
2107 void MainWindow::gotoMusicFolderButtonClicked(void)
2109 QString musicPath
= QDesktopServices::storageLocation(QDesktopServices::MusicLocation
);
2111 if(!musicPath
.isEmpty() && QDir(musicPath
).exists())
2113 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(musicPath
));
2114 outputFolderViewClicked(outputFolderView
->currentIndex());
2115 outputFolderView
->setFocus();
2119 buttonGotoMusic
->setEnabled(false);
2124 * Goto music favorite output folder
2126 void MainWindow::gotoFavoriteFolder(void)
2128 QAction
*item
= dynamic_cast<QAction
*>(QObject::sender());
2132 QDir
path(item
->data().toString());
2135 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(path
.canonicalPath()));
2136 outputFolderViewClicked(outputFolderView
->currentIndex());
2137 outputFolderView
->setFocus();
2141 MessageBeep(MB_ICONERROR
);
2142 m_outputFolderFavoritesMenu
->removeAction(item
);
2143 item
->deleteLater();
2149 * Make folder button
2151 void MainWindow::makeFolderButtonClicked(void)
2155 QDir
basePath(m_fileSystemModel
->fileInfo(outputFolderView
->currentIndex()).absoluteFilePath());
2156 QString suggestedName
= tr("New Folder");
2158 if(!m_metaData
->fileArtist().isEmpty() && !m_metaData
->fileAlbum().isEmpty())
2160 suggestedName
= QString("%1 - %2").arg(m_metaData
->fileArtist(), m_metaData
->fileAlbum());
2162 else if(!m_metaData
->fileArtist().isEmpty())
2164 suggestedName
= m_metaData
->fileArtist();
2166 else if(!m_metaData
->fileAlbum().isEmpty())
2168 suggestedName
= m_metaData
->fileAlbum();
2172 for(int i
= 0; i
< m_fileListModel
->rowCount(); i
++)
2174 AudioFileModel audioFile
= m_fileListModel
->getFile(m_fileListModel
->index(i
, 0));
2175 if(!audioFile
.fileAlbum().isEmpty() || !audioFile
.fileArtist().isEmpty())
2177 if(!audioFile
.fileArtist().isEmpty() && !audioFile
.fileAlbum().isEmpty())
2179 suggestedName
= QString("%1 - %2").arg(audioFile
.fileArtist(), audioFile
.fileAlbum());
2181 else if(!audioFile
.fileArtist().isEmpty())
2183 suggestedName
= audioFile
.fileArtist();
2185 else if(!audioFile
.fileAlbum().isEmpty())
2187 suggestedName
= audioFile
.fileAlbum();
2194 suggestedName
= lamexp_clean_filename(suggestedName
);
2198 bool bApplied
= false;
2199 QString folderName
= QInputDialog::getText(this, tr("New Folder"), tr("Enter the name of the new folder:").leftJustified(96, ' '), QLineEdit::Normal
, suggestedName
, &bApplied
, Qt::WindowStaysOnTopHint
).simplified();
2203 folderName
= lamexp_clean_filepath(folderName
.simplified());
2205 if(folderName
.isEmpty())
2207 MessageBeep(MB_ICONERROR
);
2212 QString newFolder
= folderName
;
2214 while(basePath
.exists(newFolder
))
2216 newFolder
= QString(folderName
).append(QString().sprintf(" (%d)", ++i
));
2219 if(basePath
.mkpath(newFolder
))
2221 QDir createdDir
= basePath
;
2222 if(createdDir
.cd(newFolder
))
2224 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(createdDir
.canonicalPath()));
2225 outputFolderViewClicked(outputFolderView
->currentIndex());
2226 outputFolderView
->setFocus();
2231 QMessageBox::warning(this, tr("Failed to create folder"), QString("%1<br><nobr>%2</nobr><br><br>%3").arg(tr("The new folder could not be created:"), basePath
.absoluteFilePath(newFolder
), tr("Drive is read-only or insufficient access rights!")));
2239 * Output to source dir changed
2241 void MainWindow::saveToSourceFolderChanged(void)
2243 m_settings
->outputToSourceDir(saveToSourceFolderCheckBox
->isChecked());
2247 * Prepend relative source file path to output file name changed
2249 void MainWindow::prependRelativePathChanged(void)
2251 m_settings
->prependRelativeSourcePath(prependRelativePathCheckBox
->isChecked());
2255 * Show context menu for output folder
2257 void MainWindow::outputFolderContextMenu(const QPoint
&pos
)
2259 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
2260 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
2262 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
2264 m_outputFolderContextMenu
->popup(sender
->mapToGlobal(pos
));
2269 * Show selected folder in explorer
2271 void MainWindow::showFolderContextActionTriggered(void)
2273 QDesktopServices::openUrl(QUrl::fromLocalFile(m_fileSystemModel
->filePath(outputFolderView
->currentIndex())));
2277 * Add current folder to favorites
2279 void MainWindow::addFavoriteFolderActionTriggered(void)
2281 QString path
= m_fileSystemModel
->filePath(outputFolderView
->currentIndex());
2282 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
2284 if(!favorites
.contains(path
, Qt::CaseInsensitive
))
2286 favorites
.append(path
);
2287 while(favorites
.count() > 6) favorites
.removeFirst();
2291 MessageBeep(MB_ICONWARNING
);
2294 m_settings
->favoriteOutputFolders(favorites
.join("|"));
2299 * Initialize file system model
2301 void MainWindow::initOutputFolderModel(void)
2303 QModelIndex previousIndex
= outputFolderView
->currentIndex();
2304 m_fileSystemModel
->setRootPath(m_fileSystemModel
->rootPath());
2305 QApplication::processEvents();
2306 outputFolderView
->reset();
2307 outputFolderView
->setCurrentIndex(previousIndex
);
2308 m_OutputFolderViewInitialized
= true;
2311 // =========================================================
2312 // Metadata tab slots
2313 // =========================================================
2316 * Edit meta button clicked
2318 void MainWindow::editMetaButtonClicked(void)
2322 const QModelIndex index
= metaDataView
->currentIndex();
2326 m_metaInfoModel
->editItem(index
, this);
2328 if(index
.row() == 4)
2330 m_settings
->metaInfoPosition(m_metaData
->filePosition());
2336 * Reset meta button clicked
2338 void MainWindow::clearMetaButtonClicked(void)
2341 m_metaInfoModel
->clearData();
2345 * Meta tags enabled changed
2347 void MainWindow::metaTagsEnabledChanged(void)
2349 m_settings
->writeMetaTags(writeMetaDataCheckBox
->isChecked());
2353 * Playlist enabled changed
2355 void MainWindow::playlistEnabledChanged(void)
2357 m_settings
->createPlaylist(generatePlaylistCheckBox
->isChecked());
2360 // =========================================================
2361 // Compression tab slots
2362 // =========================================================
2367 void MainWindow::updateEncoder(int id
)
2369 m_settings
->compressionEncoder(id
);
2371 switch(m_settings
->compressionEncoder())
2373 case SettingsModel::VorbisEncoder
:
2374 radioButtonModeQuality
->setEnabled(true);
2375 radioButtonModeAverageBitrate
->setEnabled(true);
2376 radioButtonConstBitrate
->setEnabled(false);
2377 if(radioButtonConstBitrate
->isChecked()) radioButtonModeQuality
->setChecked(true);
2378 sliderBitrate
->setEnabled(true);
2380 case SettingsModel::AC3Encoder
:
2381 radioButtonModeQuality
->setEnabled(true);
2382 radioButtonModeQuality
->setChecked(true);
2383 radioButtonModeAverageBitrate
->setEnabled(false);
2384 radioButtonConstBitrate
->setEnabled(true);
2385 sliderBitrate
->setEnabled(true);
2387 case SettingsModel::FLACEncoder
:
2388 radioButtonModeQuality
->setEnabled(false);
2389 radioButtonModeQuality
->setChecked(true);
2390 radioButtonModeAverageBitrate
->setEnabled(false);
2391 radioButtonConstBitrate
->setEnabled(false);
2392 sliderBitrate
->setEnabled(true);
2394 case SettingsModel::PCMEncoder
:
2395 radioButtonModeQuality
->setEnabled(false);
2396 radioButtonModeQuality
->setChecked(true);
2397 radioButtonModeAverageBitrate
->setEnabled(false);
2398 radioButtonConstBitrate
->setEnabled(false);
2399 sliderBitrate
->setEnabled(false);
2401 case SettingsModel::AACEncoder
:
2402 radioButtonModeQuality
->setEnabled(true);
2403 radioButtonModeAverageBitrate
->setEnabled(!m_fhgEncoderAvailable
);
2404 if(m_fhgEncoderAvailable
&& radioButtonModeAverageBitrate
->isChecked()) radioButtonConstBitrate
->setChecked(true);
2405 radioButtonConstBitrate
->setEnabled(true);
2406 sliderBitrate
->setEnabled(true);
2409 radioButtonModeQuality
->setEnabled(true);
2410 radioButtonModeAverageBitrate
->setEnabled(true);
2411 radioButtonConstBitrate
->setEnabled(true);
2412 sliderBitrate
->setEnabled(true);
2416 updateRCMode(m_modeButtonGroup
->checkedId());
2420 * Update rate-control mode
2422 void MainWindow::updateRCMode(int id
)
2424 m_settings
->compressionRCMode(id
);
2426 switch(m_settings
->compressionEncoder())
2428 case SettingsModel::MP3Encoder
:
2429 switch(m_settings
->compressionRCMode())
2431 case SettingsModel::VBRMode
:
2432 sliderBitrate
->setMinimum(0);
2433 sliderBitrate
->setMaximum(9);
2436 sliderBitrate
->setMinimum(0);
2437 sliderBitrate
->setMaximum(13);
2441 case SettingsModel::VorbisEncoder
:
2442 switch(m_settings
->compressionRCMode())
2444 case SettingsModel::VBRMode
:
2445 sliderBitrate
->setMinimum(-2);
2446 sliderBitrate
->setMaximum(10);
2449 sliderBitrate
->setMinimum(4);
2450 sliderBitrate
->setMaximum(63);
2454 case SettingsModel::AC3Encoder
:
2455 switch(m_settings
->compressionRCMode())
2457 case SettingsModel::VBRMode
:
2458 sliderBitrate
->setMinimum(0);
2459 sliderBitrate
->setMaximum(16);
2462 sliderBitrate
->setMinimum(0);
2463 sliderBitrate
->setMaximum(18);
2467 case SettingsModel::AACEncoder
:
2468 switch(m_settings
->compressionRCMode())
2470 case SettingsModel::VBRMode
:
2471 sliderBitrate
->setMinimum(0);
2472 sliderBitrate
->setMaximum(20);
2475 sliderBitrate
->setMinimum(4);
2476 sliderBitrate
->setMaximum(63);
2480 case SettingsModel::FLACEncoder
:
2481 sliderBitrate
->setMinimum(0);
2482 sliderBitrate
->setMaximum(8);
2484 case SettingsModel::PCMEncoder
:
2485 sliderBitrate
->setMinimum(0);
2486 sliderBitrate
->setMaximum(2);
2487 sliderBitrate
->setValue(1);
2490 sliderBitrate
->setMinimum(0);
2491 sliderBitrate
->setMaximum(0);
2495 updateBitrate(sliderBitrate
->value());
2501 void MainWindow::updateBitrate(int value
)
2503 m_settings
->compressionBitrate(value
);
2505 switch(m_settings
->compressionRCMode())
2507 case SettingsModel::VBRMode
:
2508 switch(m_settings
->compressionEncoder())
2510 case SettingsModel::MP3Encoder
:
2511 labelBitrate
->setText(tr("Quality Level %1").arg(9 - value
));
2513 case SettingsModel::VorbisEncoder
:
2514 labelBitrate
->setText(tr("Quality Level %1").arg(value
));
2516 case SettingsModel::AACEncoder
:
2517 labelBitrate
->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", static_cast<double>(value
* 5) / 100.0)));
2519 case SettingsModel::FLACEncoder
:
2520 labelBitrate
->setText(tr("Compression %1").arg(value
));
2522 case SettingsModel::AC3Encoder
:
2523 labelBitrate
->setText(tr("Quality Level %1").arg(min(1024, max(0, value
* 64))));
2525 case SettingsModel::PCMEncoder
:
2526 labelBitrate
->setText(tr("Uncompressed"));
2529 labelBitrate
->setText(QString::number(value
));
2533 case SettingsModel::ABRMode
:
2534 switch(m_settings
->compressionEncoder())
2536 case SettingsModel::MP3Encoder
:
2537 labelBitrate
->setText(QString("≈ %1 kbps").arg(SettingsModel::mp3Bitrates
[value
]));
2539 case SettingsModel::FLACEncoder
:
2540 labelBitrate
->setText(tr("Compression %1").arg(value
));
2542 case SettingsModel::AC3Encoder
:
2543 labelBitrate
->setText(QString("≈ %1 kbps").arg(SettingsModel::ac3Bitrates
[value
]));
2545 case SettingsModel::PCMEncoder
:
2546 labelBitrate
->setText(tr("Uncompressed"));
2549 labelBitrate
->setText(QString("≈ %1 kbps").arg(min(500, value
* 8)));
2554 switch(m_settings
->compressionEncoder())
2556 case SettingsModel::MP3Encoder
:
2557 labelBitrate
->setText(QString("%1 kbps").arg(SettingsModel::mp3Bitrates
[value
]));
2559 case SettingsModel::FLACEncoder
:
2560 labelBitrate
->setText(tr("Compression %1").arg(value
));
2562 case SettingsModel::AC3Encoder
:
2563 labelBitrate
->setText(QString("%1 kbps").arg(SettingsModel::ac3Bitrates
[value
]));
2565 case SettingsModel::PCMEncoder
:
2566 labelBitrate
->setText(tr("Uncompressed"));
2569 labelBitrate
->setText(QString("%1 kbps").arg(min(500, value
* 8)));
2576 // =========================================================
2577 // Advanced option slots
2578 // =========================================================
2581 * Lame algorithm quality changed
2583 void MainWindow::updateLameAlgoQuality(int value
)
2590 text
= tr("Best Quality (Very Slow)");
2593 text
= tr("High Quality (Recommended)");
2596 text
= tr("Average Quality (Default)");
2599 text
= tr("Low Quality (Fast)");
2602 text
= tr("Poor Quality (Very Fast)");
2608 m_settings
->lameAlgoQuality(value
);
2609 labelLameAlgoQuality
->setText(text
);
2612 bool warning
= (value
== 0), notice
= (value
== 4);
2613 labelLameAlgoQualityWarning
->setVisible(warning
);
2614 labelLameAlgoQualityWarningIcon
->setVisible(warning
);
2615 labelLameAlgoQualityNotice
->setVisible(notice
);
2616 labelLameAlgoQualityNoticeIcon
->setVisible(notice
);
2617 labelLameAlgoQualitySpacer
->setVisible(warning
|| notice
);
2621 * Bitrate management endabled/disabled
2623 void MainWindow::bitrateManagementEnabledChanged(bool checked
)
2625 m_settings
->bitrateManagementEnabled(checked
);
2629 * Minimum bitrate has changed
2631 void MainWindow::bitrateManagementMinChanged(int value
)
2633 if(value
> spinBoxBitrateManagementMax
->value())
2635 spinBoxBitrateManagementMin
->setValue(spinBoxBitrateManagementMax
->value());
2636 m_settings
->bitrateManagementMinRate(spinBoxBitrateManagementMax
->value());
2640 m_settings
->bitrateManagementMinRate(value
);
2645 * Maximum bitrate has changed
2647 void MainWindow::bitrateManagementMaxChanged(int value
)
2649 if(value
< spinBoxBitrateManagementMin
->value())
2651 spinBoxBitrateManagementMax
->setValue(spinBoxBitrateManagementMin
->value());
2652 m_settings
->bitrateManagementMaxRate(spinBoxBitrateManagementMin
->value());
2656 m_settings
->bitrateManagementMaxRate(value
);
2661 * Channel mode has changed
2663 void MainWindow::channelModeChanged(int value
)
2665 if(value
>= 0) m_settings
->lameChannelMode(value
);
2669 * Sampling rate has changed
2671 void MainWindow::samplingRateChanged(int value
)
2673 if(value
>= 0) m_settings
->samplingRate(value
);
2677 * Nero AAC 2-Pass mode changed
2679 void MainWindow::neroAAC2PassChanged(bool checked
)
2681 m_settings
->neroAACEnable2Pass(checked
);
2685 * Nero AAC profile mode changed
2687 void MainWindow::neroAACProfileChanged(int value
)
2689 if(value
>= 0) m_settings
->aacEncProfile(value
);
2693 * Aften audio coding mode changed
2695 void MainWindow::aftenCodingModeChanged(int value
)
2697 if(value
>= 0) m_settings
->aftenAudioCodingMode(value
);
2701 * Aften DRC mode changed
2703 void MainWindow::aftenDRCModeChanged(int value
)
2705 if(value
>= 0) m_settings
->aftenDynamicRangeCompression(value
);
2709 * Aften exponent search size changed
2711 void MainWindow::aftenSearchSizeChanged(int value
)
2713 if(value
>= 0) m_settings
->aftenExponentSearchSize(value
);
2717 * Aften fast bit allocation changed
2719 void MainWindow::aftenFastAllocationChanged(bool checked
)
2721 m_settings
->aftenFastBitAllocation(checked
);
2725 * Normalization filter enabled changed
2727 void MainWindow::normalizationEnabledChanged(bool checked
)
2729 m_settings
->normalizationFilterEnabled(checked
);
2733 * Normalization max. volume changed
2735 void MainWindow::normalizationMaxVolumeChanged(double value
)
2737 m_settings
->normalizationFilterMaxVolume(static_cast<int>(value
* 100.0));
2741 * Tone adjustment has changed (Bass)
2743 void MainWindow::toneAdjustBassChanged(double value
)
2745 m_settings
->toneAdjustBass(static_cast<int>(value
* 100.0));
2746 spinBoxToneAdjustBass
->setPrefix((value
> 0) ? "+" : QString());
2750 * Tone adjustment has changed (Treble)
2752 void MainWindow::toneAdjustTrebleChanged(double value
)
2754 m_settings
->toneAdjustTreble(static_cast<int>(value
* 100.0));
2755 spinBoxToneAdjustTreble
->setPrefix((value
> 0) ? "+" : QString());
2759 * Tone adjustment has been reset
2761 void MainWindow::toneAdjustTrebleReset(void)
2763 spinBoxToneAdjustBass
->setValue(m_settings
->toneAdjustBassDefault());
2764 spinBoxToneAdjustTreble
->setValue(m_settings
->toneAdjustTrebleDefault());
2765 toneAdjustBassChanged(spinBoxToneAdjustBass
->value());
2766 toneAdjustTrebleChanged(spinBoxToneAdjustTreble
->value());
2770 * Custom encoder parameters changed
2772 void MainWindow::customParamsChanged(void)
2774 lineEditCustomParamLAME
->setText(lineEditCustomParamLAME
->text().simplified());
2775 lineEditCustomParamOggEnc
->setText(lineEditCustomParamOggEnc
->text().simplified());
2776 lineEditCustomParamNeroAAC
->setText(lineEditCustomParamNeroAAC
->text().simplified());
2777 lineEditCustomParamFLAC
->setText(lineEditCustomParamFLAC
->text().simplified());
2778 lineEditCustomParamAften
->setText(lineEditCustomParamAften
->text().simplified());
2780 bool customParamsUsed
= false;
2781 if(!lineEditCustomParamLAME
->text().isEmpty()) customParamsUsed
= true;
2782 if(!lineEditCustomParamOggEnc
->text().isEmpty()) customParamsUsed
= true;
2783 if(!lineEditCustomParamNeroAAC
->text().isEmpty()) customParamsUsed
= true;
2784 if(!lineEditCustomParamFLAC
->text().isEmpty()) customParamsUsed
= true;
2785 if(!lineEditCustomParamAften
->text().isEmpty()) customParamsUsed
= true;
2787 labelCustomParamsIcon
->setVisible(customParamsUsed
);
2788 labelCustomParamsText
->setVisible(customParamsUsed
);
2789 labelCustomParamsSpacer
->setVisible(customParamsUsed
);
2791 m_settings
->customParametersLAME(lineEditCustomParamLAME
->text());
2792 m_settings
->customParametersOggEnc(lineEditCustomParamOggEnc
->text());
2793 m_settings
->customParametersAacEnc(lineEditCustomParamNeroAAC
->text());
2794 m_settings
->customParametersFLAC(lineEditCustomParamFLAC
->text());
2795 m_settings
->customParametersAften(lineEditCustomParamAften
->text());
2800 * Rename output files enabled changed
2802 void MainWindow::renameOutputEnabledChanged(bool checked
)
2804 m_settings
->renameOutputFilesEnabled(checked
);
2808 * Rename output files patterm changed
2810 void MainWindow::renameOutputPatternChanged(void)
2812 QString temp
= lineEditRenamePattern
->text().simplified();
2813 lineEditRenamePattern
->setText(temp
.isEmpty() ? m_settings
->renameOutputFilesPatternDefault() : temp
);
2814 m_settings
->renameOutputFilesPattern(lineEditRenamePattern
->text());
2818 * Rename output files patterm changed
2820 void MainWindow::renameOutputPatternChanged(const QString
&text
)
2822 QString
pattern(text
.simplified());
2824 pattern
.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive
);
2825 pattern
.replace("<TrackNo>", "04", Qt::CaseInsensitive
);
2826 pattern
.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive
);
2827 pattern
.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive
);
2828 pattern
.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive
);
2829 pattern
.replace("<Year>", "2001", Qt::CaseInsensitive
);
2830 pattern
.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive
);
2832 if(pattern
.compare(lamexp_clean_filename(pattern
)))
2834 if(lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::red
)
2836 MessageBeep(MB_ICONERROR
);
2837 SET_TEXT_COLOR(lineEditRenamePattern
, Qt::red
);
2842 if(lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::black
)
2844 MessageBeep(MB_ICONINFORMATION
);
2845 SET_TEXT_COLOR(lineEditRenamePattern
, Qt::black
);
2849 labelRanameExample
->setText(lamexp_clean_filename(pattern
));
2853 * Show list of rename macros
2855 void MainWindow::showRenameMacros(const QString
&text
)
2857 if(text
.compare("reset", Qt::CaseInsensitive
) == 0)
2859 lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPatternDefault());
2863 const QString format
= QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
2865 QString message
= QString("<table>");
2866 message
+= QString(format
).arg("BaseName", tr("File name without extension"));
2867 message
+= QString(format
).arg("TrackNo", tr("Track number with leading zero"));
2868 message
+= QString(format
).arg("Title", tr("Track title"));
2869 message
+= QString(format
).arg("Artist", tr("Artist name"));
2870 message
+= QString(format
).arg("Album", tr("Album name"));
2871 message
+= QString(format
).arg("Year", tr("Year with (at least) four digits"));
2872 message
+= QString(format
).arg("Comment", tr("Comment"));
2873 message
+= "</table><br><br>";
2874 message
+= QString("%1<br>").arg(tr("Characters forbidden in file names:"));
2875 message
+= "<b><tt>\\ / : * ? < > |<br>";
2877 QMessageBox::information(this, tr("Rename Macros"), message
, tr("Discard"));
2880 void MainWindow::forceStereoDownmixEnabledChanged(bool checked
)
2882 m_settings
->forceStereoDownmix(checked
);
2886 * Maximum number of instances changed
2888 void MainWindow::updateMaximumInstances(int value
)
2890 labelMaxInstances
->setText(tr("%1 Instance(s)").arg(QString::number(value
)));
2891 m_settings
->maximumInstances(checkBoxAutoDetectInstances
->isChecked() ? NULL
: value
);
2895 * Auto-detect number of instances
2897 void MainWindow::autoDetectInstancesChanged(bool checked
)
2899 m_settings
->maximumInstances(checked
? NULL
: sliderMaxInstances
->value());
2903 * Browse for custom TEMP folder button clicked
2905 void MainWindow::browseCustomTempFolderButtonClicked(void)
2907 QString newTempFolder
;
2909 if(USE_NATIVE_FILE_DIALOG
)
2911 newTempFolder
= QFileDialog::getExistingDirectory(this, QString(), m_settings
->customTempPath());
2915 QFileDialog
dialog(this);
2916 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
2917 dialog
.setDirectory(m_settings
->customTempPath());
2920 newTempFolder
= dialog
.selectedFiles().first();
2924 if(!newTempFolder
.isEmpty())
2926 QFile
writeTest(QString("%1/~%2.tmp").arg(newTempFolder
, lamexp_rand_str()));
2927 if(writeTest
.open(QIODevice::ReadWrite
))
2930 lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(newTempFolder
));
2934 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
2940 * Custom TEMP folder changed
2942 void MainWindow::customTempFolderChanged(const QString
&text
)
2944 m_settings
->customTempPath(QDir::fromNativeSeparators(text
));
2948 * Use custom TEMP folder option changed
2950 void MainWindow::useCustomTempFolderChanged(bool checked
)
2952 m_settings
->customTempPathEnabled(!checked
);
2956 * Reset all advanced options to their defaults
2958 void MainWindow::resetAdvancedOptionsButtonClicked(void)
2960 sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQualityDefault());
2961 spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRateDefault());
2962 spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRateDefault());
2963 spinBoxNormalizationFilter
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolumeDefault()) / 100.0);
2964 spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBassDefault()) / 100.0);
2965 spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTrebleDefault()) / 100.0);
2966 spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSizeDefault());
2967 comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelModeDefault());
2968 comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRateDefault());
2969 comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfileDefault());
2970 comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingModeDefault());
2971 comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompressionDefault());
2972 while(checkBoxBitrateManagement
->isChecked() != m_settings
->bitrateManagementEnabledDefault()) checkBoxBitrateManagement
->click();
2973 while(checkBoxNeroAAC2PassMode
->isChecked() != m_settings
->neroAACEnable2PassDefault()) checkBoxNeroAAC2PassMode
->click();
2974 while(checkBoxNormalizationFilter
->isChecked() != m_settings
->normalizationFilterEnabledDefault()) checkBoxNormalizationFilter
->click();
2975 while(checkBoxAutoDetectInstances
->isChecked() != (m_settings
->maximumInstancesDefault() < 1)) checkBoxAutoDetectInstances
->click();
2976 while(checkBoxUseSystemTempFolder
->isChecked() == m_settings
->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder
->click();
2977 while(checkBoxAftenFastAllocation
->isChecked() != m_settings
->aftenFastBitAllocationDefault()) checkBoxAftenFastAllocation
->click();
2978 while(checkBoxRenameOutput
->isChecked() != m_settings
->renameOutputFilesEnabledDefault()) checkBoxRenameOutput
->click();
2979 while(checkBoxForceStereoDownmix
->isChecked() != m_settings
->forceStereoDownmixDefault()) checkBoxForceStereoDownmix
->click();
2980 lineEditCustomParamLAME
->setText(m_settings
->customParametersLAMEDefault());
2981 lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEncDefault());
2982 lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEncDefault());
2983 lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLACDefault());
2984 lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPathDefault()));
2985 lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPatternDefault());
2986 customParamsChanged();
2987 scrollArea
->verticalScrollBar()->setValue(0);
2990 // =========================================================
2991 // Multi-instance handling slots
2992 // =========================================================
2995 * Other instance detected
2997 void MainWindow::notifyOtherInstance(void)
2999 if(!m_banner
->isVisible())
3001 QMessageBox
msgBox(QMessageBox::Warning
, tr("Already Running"), tr("LameXP is already running, please use the running instance!"), QMessageBox::NoButton
, this, Qt::Dialog
| Qt::MSWindowsFixedSizeDialogHint
| Qt::WindowStaysOnTopHint
);
3007 * Add file from another instance
3009 void MainWindow::addFileDelayed(const QString
&filePath
, bool tryASAP
)
3011 if(tryASAP
&& !m_delayedFileTimer
->isActive())
3013 qDebug("Received file: %s", filePath
.toUtf8().constData());
3014 m_delayedFileList
->append(filePath
);
3015 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3018 m_delayedFileTimer
->stop();
3019 qDebug("Received file: %s", filePath
.toUtf8().constData());
3020 m_delayedFileList
->append(filePath
);
3021 m_delayedFileTimer
->start(5000);
3025 * Add files from another instance
3027 void MainWindow::addFilesDelayed(const QStringList
&filePaths
, bool tryASAP
)
3029 if(tryASAP
&& !m_delayedFileTimer
->isActive())
3031 qDebug("Received %d file(s).", filePaths
.count());
3032 m_delayedFileList
->append(filePaths
);
3033 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3037 m_delayedFileTimer
->stop();
3038 qDebug("Received %d file(s).", filePaths
.count());
3039 m_delayedFileList
->append(filePaths
);
3040 m_delayedFileTimer
->start(5000);
3045 * Add folder from another instance
3047 void MainWindow::addFolderDelayed(const QString
&folderPath
, bool recursive
)
3049 if(!m_banner
->isVisible())
3051 addFolder(folderPath
, recursive
, true);
3055 // =========================================================
3057 // =========================================================
3060 * Restore the override cursor
3062 void MainWindow::restoreCursor(void)
3064 QApplication::restoreOverrideCursor();