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 qDebug("Dropped File: %s", file.canonicalFilePath().toUtf8().constData());
749 droppedFiles << file.canonicalFilePath();
754 qDebug("Dropped Folder: %s", file.canonicalFilePath().toUtf8().constData());
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 qDebug("Descending to Folder: %s", list.at(j).canonicalFilePath().toUtf8().constData());
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 bool firstRun = false;
903 for(int i = 0; i < arguments.count(); i++)
905 if(!arguments[i].compare("--first-run", Qt::CaseInsensitive)) firstRun = true;
909 if((m_settings->licenseAccepted() <= 0) || firstRun)
913 if((m_settings->licenseAccepted() == 0) || firstRun)
915 AboutDialog *about = new AboutDialog(m_settings, this, true);
916 iAccepted = about->exec();
917 LAMEXP_DELETE(about);
922 m_settings->licenseAccepted(-1);
923 QApplication::processEvents();
924 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
925 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
926 if(!QProcess::startDetached(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()), QStringList()))
928 MoveFileEx(QWCHAR(QDir::toNativeSeparators(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath())), NULL, MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING);
930 QApplication::quit();
934 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WOOHOO), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
935 m_settings->licenseAccepted(1);
936 if(lamexp_version_demo()) showAnnounceBox();
939 //Check for expiration
940 if(lamexp_version_demo())
942 if(QDate::currentDate() >= lamexp_version_expires())
944 qWarning("Binary has expired !!!");
945 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
946 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)
950 QApplication::quit();
955 //Slow startup indicator
956 if(m_settings->slowStartup() && m_settings->antivirNotificationsEnabled())
959 message += NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
960 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>").append("<br>");
961 if(QMessageBox::warning(this, tr("Slow Startup"), message, tr("Discard"), tr("Don't Show Again")) == 1)
963 m_settings->antivirNotificationsEnabled(false);
964 actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
969 if(QDate::currentDate() >= lamexp_version_date().addYears(1))
971 qWarning("Binary is more than a year old, time to update!");
972 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)
974 if(checkForUpdates())
976 QApplication::quit();
982 QApplication::quit();
986 else if(m_settings->autoUpdateEnabled())
988 QDate lastUpdateCheck = QDate::fromString(m_settings->autoUpdateLastCheck(), Qt::ISODate);
989 if(!firstRun && (!lastUpdateCheck.isValid() || QDate::currentDate() >= lastUpdateCheck.addDays(14)))
991 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)
993 if(checkForUpdates())
995 QApplication::quit();
1002 //Check for AAC support
1003 if(m_neroEncoderAvailable)
1005 if(m_settings->neroAacNotificationsEnabled())
1007 if(lamexp_tool_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1009 QString messageText;
1010 messageText += NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1011 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>");
1012 messageText += NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1013 messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br>";
1014 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText);
1020 if(m_settings->neroAacNotificationsEnabled() && (!m_fhgEncoderAvailable))
1022 QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1023 if(appPath.isEmpty()) appPath = QCoreApplication::applicationDirPath();
1024 QString messageText;
1025 messageText += NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1026 messageText += NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1027 messageText += NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1028 messageText += QString("<nobr><tt><a href=\"file:///%1\">%2</a></tt></nobr><br><br>").arg(QDir::toNativeSeparators(appPath), QDir::toNativeSeparators(appPath).replace("-", "−"));
1029 messageText += NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1030 messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br>";
1031 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText, tr("Discard"), tr("Don't Show Again")) == 1)
1033 m_settings->neroAacNotificationsEnabled(false);
1034 actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
1039 //Add files from the command-line
1040 for(int i = 0; i < arguments.count() - 1; i++)
1042 QStringList addedFiles;
1043 if(!arguments[i].compare("--add", Qt::CaseInsensitive))
1045 QFileInfo currentFile(arguments[++i].trimmed());
1046 qDebug("Adding file from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1047 addedFiles.append(currentFile.absoluteFilePath());
1049 if(!addedFiles.isEmpty())
1051 addFilesDelayed(addedFiles);
1055 //Add folders from the command-line
1056 for(int i = 0; i < arguments.count() - 1; i++)
1058 if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
1060 QFileInfo currentFile(arguments[++i].trimmed());
1061 qDebug("Adding folder from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1062 addFolder(currentFile.absoluteFilePath(), false, true);
1064 if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
1066 QFileInfo currentFile(arguments[++i].trimmed());
1067 qDebug("Adding folder recursively from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1068 addFolder(currentFile.absoluteFilePath(), true, true);
1072 //Enable shell integration
1073 if(m_settings->shellIntegrationEnabled())
1075 ShellIntegration::install();
1078 //Make DropBox visible
1079 if(m_settings->dropBoxWidgetEnabled())
1081 m_dropBox->setVisible(true);
1088 void MainWindow::showAnnounceBox(void)
1090 QString announceText("<nobr>We are still looking for LameXP translators!<br><br>");
1091 announceText.append("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:<br>");
1092 announceText.append("<tt>" + LINK("http://mulder.brhack.net/public/doc/lamexp_translate.html") + "</tt></nobr><br>");
1094 QMessageBox *announceBox = new QMessageBox(QMessageBox::Warning, "We want you!", announceText, QMessageBox::NoButton, this);
1095 announceBox->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
1096 announceBox->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1097 QPushButton *button1 = announceBox->addButton(tr("Discard"), QMessageBox::AcceptRole);
1098 QPushButton *button2 = announceBox->addButton(tr("Discard"), QMessageBox::NoRole);
1099 button1->setVisible(false);
1100 button2->setEnabled(false);
1102 QTimer *announceTimer = new QTimer(this);
1103 announceTimer->setSingleShot(true);
1104 announceTimer->setInterval(8000);
1105 connect(announceTimer, SIGNAL(timeout()), button1, SLOT(show()));
1106 connect(announceTimer, SIGNAL(timeout()), button2, SLOT(hide()));
1108 announceTimer->start();
1109 while(announceTimer->isActive()) announceBox->exec();
1110 announceTimer->stop();
1112 LAMEXP_DELETE(announceTimer);
1113 LAMEXP_DELETE(announceBox);
1116 // =========================================================
1117 // Main button solots
1118 // =========================================================
1123 void MainWindow::encodeButtonClicked(void)
1125 static const __int64 oneGigabyte = 1073741824i64;
1126 static const __int64 minimumFreeDiskspaceMultiplier = 2i64;
1127 static const char *writeTestBuffer = "LAMEXP_WRITE_TEST";
1131 if(m_fileListModel->rowCount() < 1)
1133 QMessageBox::warning(this, tr("LameXP"), QString("<nobr>%1</nobr>").arg(tr("You must add at least one file to the list before proceeding!")));
1134 tabWidget->setCurrentIndex(0);
1138 QString tempFolder = m_settings->customTempPathEnabled() ? m_settings->customTempPath() : lamexp_temp_folder2();
1139 if(!QFileInfo(tempFolder).exists() || !QFileInfo(tempFolder).isDir())
1141 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)
1143 while(checkBoxUseSystemTempFolder->isChecked() == m_settings->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder->click();
1148 qint64 currentFreeDiskspace = lamexp_free_diskspace(tempFolder);
1149 if(currentFreeDiskspace < (oneGigabyte * minimumFreeDiskspaceMultiplier))
1151 QStringList tempFolderParts = tempFolder.split("/", QString::SkipEmptyParts, Qt::CaseInsensitive);
1152 tempFolderParts.takeLast();
1153 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1154 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")))
1157 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(lamexp_known_folder(lamexp_folder_systemfolder)), QStringList() << "/D" << tempFolderParts.first());
1162 QMessageBox::warning(this, tr("Low Diskspace"), tr("You are proceeding with low diskspace. Problems might occur!"));
1167 switch(m_settings->compressionEncoder())
1169 case SettingsModel::MP3Encoder:
1170 case SettingsModel::VorbisEncoder:
1171 case SettingsModel::AACEncoder:
1172 case SettingsModel::AC3Encoder:
1173 case SettingsModel::FLACEncoder:
1174 case SettingsModel::PCMEncoder:
1177 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1178 tabWidget->setCurrentIndex(3);
1182 if(!m_settings->outputToSourceDir())
1184 QFile writeTest(QString("%1/~%2.txt").arg(m_settings->outputDir(), lamexp_rand_str()));
1185 if(!(writeTest.open(QIODevice::ReadWrite) && (writeTest.write(writeTestBuffer) == strlen(writeTestBuffer))))
1187 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!")));
1188 tabWidget->setCurrentIndex(1);
1205 void MainWindow::aboutButtonClicked(void)
1211 AboutDialog *aboutBox = new AboutDialog(m_settings, this);
1213 LAMEXP_DELETE(aboutBox);
1220 void MainWindow::closeButtonClicked(void)
1226 // =========================================================
1228 // =========================================================
1233 void MainWindow::tabPageChanged(int idx)
1235 QList<QAction*> actions = m_tabActionGroup->actions();
1236 for(int i = 0; i < actions.count(); i++)
1239 int actionIndex = actions.at(i)->data().toInt(&ok);
1240 if(ok && actionIndex == idx)
1242 actions.at(i)->setChecked(true);
1246 int initialWidth = this->width();
1247 int maximumWidth = QApplication::desktop()->width();
1249 if(this->isVisible())
1251 while(tabWidget->width() < tabWidget->sizeHint().width())
1253 int previousWidth = this->width();
1254 this->resize(this->width() + 1, this->height());
1255 if(this->frameGeometry().width() >= maximumWidth) break;
1256 if(this->width() <= previousWidth) break;
1260 if(idx == tabWidget->indexOf(tabOptions) && scrollArea->widget() && this->isVisible())
1262 for(int i = 0; i < 2; i++)
1264 QApplication::processEvents();
1265 while(scrollArea->viewport()->width() < scrollArea->widget()->width())
1267 int previousWidth = this->width();
1268 this->resize(this->width() + 1, this->height());
1269 if(this->frameGeometry().width() >= maximumWidth) break;
1270 if(this->width() <= previousWidth) break;
1274 else if(idx == tabWidget->indexOf(tabSourceFiles))
1276 m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height());
1278 else if(idx == tabWidget->indexOf(tabOutputDir))
1280 if(!m_OutputFolderViewInitialized)
1282 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
1286 if(initialWidth < this->width())
1288 QPoint prevPos = this->pos();
1289 int delta = (this->width() - initialWidth) >> 2;
1290 move(prevPos.x() - delta, prevPos.y());
1295 * Tab action triggered
1297 void MainWindow::tabActionActivated(QAction *action)
1299 if(action && action->data().isValid())
1302 int index = action->data().toInt(&ok);
1305 tabWidget->setCurrentIndex(index);
1310 // =========================================================
1312 // =========================================================
1315 * Style action triggered
1317 void MainWindow::styleActionActivated(QAction *action)
1319 //Change style setting
1320 if(action && action->data().isValid())
1323 int actionIndex = action->data().toInt(&ok);
1326 m_settings->interfaceStyle(actionIndex);
1330 //Set up the new style
1331 switch(m_settings->interfaceStyle())
1334 if(actionStyleCleanlooks->isEnabled())
1336 actionStyleCleanlooks->setChecked(true);
1337 QApplication::setStyle(new QCleanlooksStyle());
1341 if(actionStyleWindowsVista->isEnabled())
1343 actionStyleWindowsVista->setChecked(true);
1344 QApplication::setStyle(new QWindowsVistaStyle());
1348 if(actionStyleWindowsXP->isEnabled())
1350 actionStyleWindowsXP->setChecked(true);
1351 QApplication::setStyle(new QWindowsXPStyle());
1355 if(actionStyleWindowsClassic->isEnabled())
1357 actionStyleWindowsClassic->setChecked(true);
1358 QApplication::setStyle(new QWindowsStyle());
1362 actionStylePlastique->setChecked(true);
1363 QApplication::setStyle(new QPlastiqueStyle());
1367 //Force re-translate after style change
1368 changeEvent(new QEvent(QEvent::LanguageChange));
1372 * Language action triggered
1374 void MainWindow::languageActionActivated(QAction *action)
1376 if(action->data().type() == QVariant::String)
1378 QString langId = action->data().toString();
1380 if(lamexp_install_translator(langId))
1382 action->setChecked(true);
1383 m_settings->currentLanguage(langId);
1389 * Load language from file action triggered
1391 void MainWindow::languageFromFileActionActivated(bool checked)
1393 QFileDialog dialog(this, tr("Load Translation"));
1394 dialog.setFileMode(QFileDialog::ExistingFile);
1395 dialog.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
1399 QStringList selectedFiles = dialog.selectedFiles();
1400 if(lamexp_install_translator_from_file(selectedFiles.first()))
1402 QList<QAction*> actions = m_languageActionGroup->actions();
1403 while(!actions.isEmpty())
1405 actions.takeFirst()->setChecked(false);
1410 languageActionActivated(m_languageActionGroup->actions().first());
1415 // =========================================================
1417 // =========================================================
1420 * Disable update reminder action
1422 void MainWindow::disableUpdateReminderActionTriggered(bool checked)
1426 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))
1428 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!")));
1429 m_settings->autoUpdateEnabled(false);
1433 m_settings->autoUpdateEnabled(true);
1438 QMessageBox::information(this, tr("Update Reminder"), tr("The update reminder has been re-enabled."));
1439 m_settings->autoUpdateEnabled(true);
1442 actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
1446 * Disable sound effects action
1448 void MainWindow::disableSoundsActionTriggered(bool checked)
1452 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))
1454 QMessageBox::information(this, tr("Sound Effects"), tr("All sound effects have been disabled."));
1455 m_settings->soundsEnabled(false);
1459 m_settings->soundsEnabled(true);
1464 QMessageBox::information(this, tr("Sound Effects"), tr("The sound effects have been re-enabled."));
1465 m_settings->soundsEnabled(true);
1468 actionDisableSounds->setChecked(!m_settings->soundsEnabled());
1472 * Disable Nero AAC encoder action
1474 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked)
1478 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))
1480 QMessageBox::information(this, tr("Nero AAC Notifications"), tr("All Nero AAC Encoder notifications have been disabled."));
1481 m_settings->neroAacNotificationsEnabled(false);
1485 m_settings->neroAacNotificationsEnabled(true);
1490 QMessageBox::information(this, tr("Nero AAC Notifications"), tr("The Nero AAC Encoder notifications have been re-enabled."));
1491 m_settings->neroAacNotificationsEnabled(true);
1494 actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
1498 * Disable WMA Decoder component action
1500 //void MainWindow::disableWmaDecoderNotificationsActionTriggered(bool checked)
1504 // 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))
1506 // QMessageBox::information(this, tr("WMA Decoder Notifications"), tr("All WMA Decoder notifications have been disabled."));
1507 // m_settings->wmaDecoderNotificationsEnabled(false);
1511 // m_settings->wmaDecoderNotificationsEnabled(true);
1516 // QMessageBox::information(this, tr("WMA Decoder Notifications"), tr("The WMA Decoder notifications have been re-enabled."));
1517 // m_settings->wmaDecoderNotificationsEnabled(true);
1520 // actionDisableWmaDecoderNotifications->setChecked(!m_settings->wmaDecoderNotificationsEnabled());
1524 * Disable slow startup action
1526 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked)
1530 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))
1532 QMessageBox::information(this, tr("Slow Startup Notifications"), tr("The slow startup notifications have been disabled."));
1533 m_settings->antivirNotificationsEnabled(false);
1537 m_settings->antivirNotificationsEnabled(true);
1542 QMessageBox::information(this, tr("Slow Startup Notifications"), tr("The slow startup notifications have been re-enabled."));
1543 m_settings->antivirNotificationsEnabled(true);
1546 actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
1550 * Download and install WMA Decoder component
1552 //void MainWindow::installWMADecoderActionTriggered(bool checked)
1554 // 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)
1556 // if(installWMADecoder())
1558 // QApplication::quit();
1565 * Import a Cue Sheet file
1567 void MainWindow::importCueSheetActionTriggered(bool checked)
1576 QString selectedCueFile;
1578 if(USE_NATIVE_FILE_DIALOG)
1580 selectedCueFile = QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1584 QFileDialog dialog(this, tr("Open Cue Sheet"));
1585 dialog.setFileMode(QFileDialog::ExistingFile);
1586 dialog.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1587 dialog.setDirectory(m_settings->mostRecentInputPath());
1590 selectedCueFile = dialog.selectedFiles().first();
1594 if(!selectedCueFile.isEmpty())
1596 m_settings->mostRecentInputPath(QFileInfo(selectedCueFile).canonicalPath());
1597 CueImportDialog *cueImporter = new CueImportDialog(this, m_fileListModel, selectedCueFile);
1598 result = cueImporter->exec();
1599 LAMEXP_DELETE(cueImporter);
1602 if(result != (-1)) break;
1608 * Show the "drop box" widget
1610 void MainWindow::showDropBoxWidgetActionTriggered(bool checked)
1612 m_settings->dropBoxWidgetEnabled(true);
1614 if(!m_dropBox->isVisible())
1619 lamexp_blink_window(m_dropBox);
1623 * Check for beta (pre-release) updates
1625 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked)
1627 bool checkUpdatesNow = false;
1631 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))
1633 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")))
1635 checkUpdatesNow = true;
1637 m_settings->autoUpdateCheckBeta(true);
1641 m_settings->autoUpdateCheckBeta(false);
1646 QMessageBox::information(this, tr("Beta Updates"), tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on."));
1647 m_settings->autoUpdateCheckBeta(false);
1650 actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta());
1654 if(checkForUpdates())
1656 QApplication::quit();
1662 * Disable shell integration action
1664 void MainWindow::disableShellIntegrationActionTriggered(bool checked)
1668 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))
1670 ShellIntegration::remove();
1671 QMessageBox::information(this, tr("Shell Integration"), tr("The LameXP shell integration has been disabled."));
1672 m_settings->shellIntegrationEnabled(false);
1676 m_settings->shellIntegrationEnabled(true);
1681 ShellIntegration::install();
1682 QMessageBox::information(this, tr("Shell Integration"), tr("The LameXP shell integration has been re-enabled."));
1683 m_settings->shellIntegrationEnabled(true);
1686 actionDisableShellIntegration->setChecked(!m_settings->shellIntegrationEnabled());
1688 if(lamexp_portable_mode() && actionDisableShellIntegration->isChecked())
1690 actionDisableShellIntegration->setEnabled(false);
1694 // =========================================================
1696 // =========================================================
1699 * Visit homepage action
1701 void MainWindow::visitHomepageActionActivated(void)
1703 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
1705 if(action->data().isValid() && (action->data().type() == QVariant::String))
1707 QDesktopServices::openUrl(QUrl(action->data().toString()));
1715 void MainWindow::documentActionActivated(void)
1717 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
1719 if(action->data().isValid() && (action->data().type() == QVariant::String))
1721 QFileInfo document(action->data().toString());
1722 QFileInfo resource(QString(":/doc/%1.html").arg(document.baseName()));
1723 if(document.exists() && document.isFile() && (document.size() == resource.size()))
1725 QDesktopServices::openUrl(QUrl::fromLocalFile(document.canonicalFilePath()));
1729 QFile source(resource.filePath());
1730 QFile output(QString("%1/%2.%3.html").arg(lamexp_temp_folder2(), document.baseName(), lamexp_rand_str().left(8)));
1731 if(source.open(QIODevice::ReadOnly) && output.open(QIODevice::ReadWrite))
1733 output.write(source.readAll());
1734 action->setData(output.fileName());
1737 QDesktopServices::openUrl(QUrl::fromLocalFile(output.fileName()));
1745 * Check for updates action
1747 void MainWindow::checkUpdatesActionActivated(void)
1754 bFlag = checkForUpdates();
1759 QApplication::quit();
1763 // =========================================================
1764 // Source file slots
1765 // =========================================================
1768 * Add file(s) button
1770 void MainWindow::addFilesButtonClicked(void)
1776 if(USE_NATIVE_FILE_DIALOG)
1778 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
1779 QStringList selectedFiles = QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings->mostRecentInputPath(), fileTypeFilters.join(";;"));
1780 if(!selectedFiles.isEmpty())
1782 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
1783 addFiles(selectedFiles);
1788 QFileDialog dialog(this, tr("Add file(s)"));
1789 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
1790 dialog.setFileMode(QFileDialog::ExistingFiles);
1791 dialog.setNameFilter(fileTypeFilters.join(";;"));
1792 dialog.setDirectory(m_settings->mostRecentInputPath());
1795 QStringList selectedFiles = dialog.selectedFiles();
1796 if(!selectedFiles.isEmpty())
1798 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
1799 addFiles(selectedFiles);
1807 * Open folder action
1809 void MainWindow::openFolderActionActivated(void)
1812 QString selectedFolder;
1814 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
1818 if(USE_NATIVE_FILE_DIALOG)
1820 selectedFolder = QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings->mostRecentInputPath());
1824 QFileDialog dialog(this, tr("Add Folder"));
1825 dialog.setFileMode(QFileDialog::DirectoryOnly);
1826 dialog.setDirectory(m_settings->mostRecentInputPath());
1829 selectedFolder = dialog.selectedFiles().first();
1833 if(!selectedFolder.isEmpty())
1835 m_settings->mostRecentInputPath(QDir(selectedFolder).canonicalPath());
1836 addFolder(selectedFolder, action->data().toBool());
1843 * Remove file button
1845 void MainWindow::removeFileButtonClicked(void)
1847 if(sourceFileView->currentIndex().isValid())
1849 int iRow = sourceFileView->currentIndex().row();
1850 m_fileListModel->removeFile(sourceFileView->currentIndex());
1851 sourceFileView->selectRow(iRow < m_fileListModel->rowCount() ? iRow : m_fileListModel->rowCount()-1);
1856 * Clear files button
1858 void MainWindow::clearFilesButtonClicked(void)
1860 m_fileListModel->clearFiles();
1864 * Move file up button
1866 void MainWindow::fileUpButtonClicked(void)
1868 if(sourceFileView->currentIndex().isValid())
1870 int iRow = sourceFileView->currentIndex().row() - 1;
1871 m_fileListModel->moveFile(sourceFileView->currentIndex(), -1);
1872 sourceFileView->selectRow(iRow >= 0 ? iRow : 0);
1877 * Move file down button
1879 void MainWindow::fileDownButtonClicked(void)
1881 if(sourceFileView->currentIndex().isValid())
1883 int iRow = sourceFileView->currentIndex().row() + 1;
1884 m_fileListModel->moveFile(sourceFileView->currentIndex(), 1);
1885 sourceFileView->selectRow(iRow < m_fileListModel->rowCount() ? iRow : m_fileListModel->rowCount()-1);
1890 * Show details button
1892 void MainWindow::showDetailsButtonClicked(void)
1897 MetaInfoDialog *metaInfoDialog = new MetaInfoDialog(this);
1898 QModelIndex index = sourceFileView->currentIndex();
1900 while(index.isValid())
1904 index = m_fileListModel->index(index.row() + 1, index.column());
1905 sourceFileView->selectRow(index.row());
1909 index = m_fileListModel->index(index.row() - 1, index.column());
1910 sourceFileView->selectRow(index.row());
1913 AudioFileModel &file = (*m_fileListModel)[index];
1916 iResult = metaInfoDialog->exec(file, index.row() > 0, index.row() < m_fileListModel->rowCount() - 1);
1919 if(iResult == INT_MAX)
1921 m_metaInfoModel->assignInfoFrom(file);
1922 tabWidget->setCurrentIndex(tabWidget->indexOf(tabMetaData));
1929 LAMEXP_DELETE(metaInfoDialog);
1933 * Show context menu for source files
1935 void MainWindow::sourceFilesContextMenu(const QPoint &pos)
1937 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
1938 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
1942 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
1944 m_sourceFilesContextMenu->popup(sender->mapToGlobal(pos));
1950 * Scrollbar of source files moved
1952 void MainWindow::sourceFilesScrollbarMoved(int)
1954 sourceFileView->resizeColumnToContents(0);
1958 * Open selected file in external player
1960 void MainWindow::previewContextActionTriggered(void)
1962 const static char *appNames[3] = {"smplayer_portable.exe", "smplayer.exe", "mplayer.exe"};
1963 const static wchar_t *registryKey = L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{DB9E4EAB-2717-499F-8D56-4CC8A644AB60}";
1965 QModelIndex index = sourceFileView->currentIndex();
1966 if(!index.isValid())
1971 QString mplayerPath;
1972 HKEY registryKeyHandle;
1974 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryKey, 0, KEY_READ, ®istryKeyHandle) == ERROR_SUCCESS)
1976 wchar_t Buffer[4096];
1977 DWORD BuffSize = sizeof(wchar_t*) * 4096;
1978 if(RegQueryValueExW(registryKeyHandle, L"InstallLocation", 0, 0, reinterpret_cast<BYTE*>(Buffer), &BuffSize) == ERROR_SUCCESS)
1980 mplayerPath = QString::fromUtf16(reinterpret_cast<const unsigned short*>(Buffer));
1984 if(!mplayerPath.isEmpty())
1986 QDir mplayerDir(mplayerPath);
1987 if(mplayerDir.exists())
1989 for(int i = 0; i < 3; i++)
1991 if(mplayerDir.exists(appNames[i]))
1993 QProcess::startDetached(mplayerDir.absoluteFilePath(appNames[i]), QStringList() << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
2000 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel->getFile(index).filePath()));
2004 * Find selected file in explorer
2006 void MainWindow::findFileContextActionTriggered(void)
2008 QModelIndex index = sourceFileView->currentIndex();
2011 QString systemRootPath;
2013 QDir systemRoot(lamexp_known_folder(lamexp_folder_systemfolder));
2014 if(systemRoot.exists() && systemRoot.cdUp())
2016 systemRootPath = systemRoot.canonicalPath();
2019 if(!systemRootPath.isEmpty())
2021 QFileInfo explorer(QString("%1/explorer.exe").arg(systemRootPath));
2022 if(explorer.exists() && explorer.isFile())
2024 QProcess::execute(explorer.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
2030 qWarning("SystemRoot directory could not be detected!");
2036 * Add all pending files
2038 void MainWindow::handleDelayedFiles(void)
2040 m_delayedFileTimer->stop();
2042 if(m_delayedFileList->isEmpty())
2047 if(m_banner->isVisible())
2049 m_delayedFileTimer->start(5000);
2053 QStringList selectedFiles;
2054 tabWidget->setCurrentIndex(0);
2056 while(!m_delayedFileList->isEmpty())
2058 QFileInfo currentFile = QFileInfo(m_delayedFileList->takeFirst());
2059 if(!currentFile.exists() || !currentFile.isFile())
2063 selectedFiles << currentFile.canonicalFilePath();
2066 addFiles(selectedFiles);
2070 * Show or hide Drag'n'Drop notice after model reset
2072 void MainWindow::sourceModelChanged(void)
2074 m_dropNoteLabel->setVisible(m_fileListModel->rowCount() <= 0);
2077 // =========================================================
2078 // Output folder slots
2079 // =========================================================
2082 * Output folder changed (mouse clicked)
2084 void MainWindow::outputFolderViewClicked(const QModelIndex &index)
2086 if(outputFolderView->currentIndex() != index)
2088 outputFolderView->setCurrentIndex(index);
2090 QString selectedDir = m_fileSystemModel->filePath(index);
2091 if(selectedDir.length() < 3) selectedDir.append(QDir::separator());
2092 outputFolderLabel->setText(QDir::toNativeSeparators(selectedDir));
2093 m_settings->outputDir(selectedDir);
2097 * Output folder changed (mouse moved)
2099 void MainWindow::outputFolderViewMoved(const QModelIndex &index)
2101 if(QApplication::mouseButtons() & Qt::LeftButton)
2103 outputFolderViewClicked(index);
2108 * Goto desktop button
2110 void MainWindow::gotoDesktopButtonClicked(void)
2112 QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
2114 if(!desktopPath.isEmpty() && QDir(desktopPath).exists())
2116 outputFolderView->setCurrentIndex(m_fileSystemModel->index(desktopPath));
2117 outputFolderViewClicked(outputFolderView->currentIndex());
2118 outputFolderView->setFocus();
2122 buttonGotoDesktop->setEnabled(false);
2127 * Goto home folder button
2129 void MainWindow::gotoHomeFolderButtonClicked(void)
2131 QString homePath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
2133 if(!homePath.isEmpty() && QDir(homePath).exists())
2135 outputFolderView->setCurrentIndex(m_fileSystemModel->index(homePath));
2136 outputFolderViewClicked(outputFolderView->currentIndex());
2137 outputFolderView->setFocus();
2141 buttonGotoHome->setEnabled(false);
2146 * Goto music folder button
2148 void MainWindow::gotoMusicFolderButtonClicked(void)
2150 QString musicPath = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
2152 if(!musicPath.isEmpty() && QDir(musicPath).exists())
2154 outputFolderView->setCurrentIndex(m_fileSystemModel->index(musicPath));
2155 outputFolderViewClicked(outputFolderView->currentIndex());
2156 outputFolderView->setFocus();
2160 buttonGotoMusic->setEnabled(false);
2165 * Goto music favorite output folder
2167 void MainWindow::gotoFavoriteFolder(void)
2169 QAction *item = dynamic_cast<QAction*>(QObject::sender());
2173 QDir path(item->data().toString());
2176 outputFolderView->setCurrentIndex(m_fileSystemModel->index(path.canonicalPath()));
2177 outputFolderViewClicked(outputFolderView->currentIndex());
2178 outputFolderView->setFocus();
2182 MessageBeep(MB_ICONERROR);
2183 m_outputFolderFavoritesMenu->removeAction(item);
2184 item->deleteLater();
2190 * Make folder button
2192 void MainWindow::makeFolderButtonClicked(void)
2196 QDir basePath(m_fileSystemModel->fileInfo(outputFolderView->currentIndex()).absoluteFilePath());
2197 QString suggestedName = tr("New Folder");
2199 if(!m_metaData->fileArtist().isEmpty() && !m_metaData->fileAlbum().isEmpty())
2201 suggestedName = QString("%1 - %2").arg(m_metaData->fileArtist(), m_metaData->fileAlbum());
2203 else if(!m_metaData->fileArtist().isEmpty())
2205 suggestedName = m_metaData->fileArtist();
2207 else if(!m_metaData->fileAlbum().isEmpty())
2209 suggestedName = m_metaData->fileAlbum();
2213 for(int i = 0; i < m_fileListModel->rowCount(); i++)
2215 AudioFileModel audioFile = m_fileListModel->getFile(m_fileListModel->index(i, 0));
2216 if(!audioFile.fileAlbum().isEmpty() || !audioFile.fileArtist().isEmpty())
2218 if(!audioFile.fileArtist().isEmpty() && !audioFile.fileAlbum().isEmpty())
2220 suggestedName = QString("%1 - %2").arg(audioFile.fileArtist(), audioFile.fileAlbum());
2222 else if(!audioFile.fileArtist().isEmpty())
2224 suggestedName = audioFile.fileArtist();
2226 else if(!audioFile.fileAlbum().isEmpty())
2228 suggestedName = audioFile.fileAlbum();
2235 suggestedName = lamexp_clean_filename(suggestedName);
2239 bool bApplied = false;
2240 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();
2244 folderName = lamexp_clean_filepath(folderName.simplified());
2246 if(folderName.isEmpty())
2248 MessageBeep(MB_ICONERROR);
2253 QString newFolder = folderName;
2255 while(basePath.exists(newFolder))
2257 newFolder = QString(folderName).append(QString().sprintf(" (%d)", ++i));
2260 if(basePath.mkpath(newFolder))
2262 QDir createdDir = basePath;
2263 if(createdDir.cd(newFolder))
2265 outputFolderView->setCurrentIndex(m_fileSystemModel->index(createdDir.canonicalPath()));
2266 outputFolderViewClicked(outputFolderView->currentIndex());
2267 outputFolderView->setFocus();
2272 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!")));
2280 * Output to source dir changed
2282 void MainWindow::saveToSourceFolderChanged(void)
2284 m_settings->outputToSourceDir(saveToSourceFolderCheckBox->isChecked());
2288 * Prepend relative source file path to output file name changed
2290 void MainWindow::prependRelativePathChanged(void)
2292 m_settings->prependRelativeSourcePath(prependRelativePathCheckBox->isChecked());
2296 * Show context menu for output folder
2298 void MainWindow::outputFolderContextMenu(const QPoint &pos)
2300 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
2301 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
2303 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
2305 m_outputFolderContextMenu->popup(sender->mapToGlobal(pos));
2310 * Show selected folder in explorer
2312 void MainWindow::showFolderContextActionTriggered(void)
2314 QDesktopServices::openUrl(QUrl::fromLocalFile(m_fileSystemModel->filePath(outputFolderView->currentIndex())));
2318 * Add current folder to favorites
2320 void MainWindow::addFavoriteFolderActionTriggered(void)
2322 QString path = m_fileSystemModel->filePath(outputFolderView->currentIndex());
2323 QStringList favorites = m_settings->favoriteOutputFolders().split("|", QString::SkipEmptyParts);
2325 if(!favorites.contains(path, Qt::CaseInsensitive))
2327 favorites.append(path);
2328 while(favorites.count() > 6) favorites.removeFirst();
2332 MessageBeep(MB_ICONWARNING);
2335 m_settings->favoriteOutputFolders(favorites.join("|"));
2340 * Initialize file system model
2342 void MainWindow::initOutputFolderModel(void)
2344 QModelIndex previousIndex = outputFolderView->currentIndex();
2345 m_fileSystemModel->setRootPath(m_fileSystemModel->rootPath());
2346 QApplication::processEvents();
2347 outputFolderView->reset();
2348 outputFolderView->setCurrentIndex(previousIndex);
2349 m_OutputFolderViewInitialized = true;
2352 // =========================================================
2353 // Metadata tab slots
2354 // =========================================================
2357 * Edit meta button clicked
2359 void MainWindow::editMetaButtonClicked(void)
2363 const QModelIndex index = metaDataView->currentIndex();
2367 m_metaInfoModel->editItem(index, this);
2369 if(index.row() == 4)
2371 m_settings->metaInfoPosition(m_metaData->filePosition());
2377 * Reset meta button clicked
2379 void MainWindow::clearMetaButtonClicked(void)
2382 m_metaInfoModel->clearData();
2386 * Meta tags enabled changed
2388 void MainWindow::metaTagsEnabledChanged(void)
2390 m_settings->writeMetaTags(writeMetaDataCheckBox->isChecked());
2394 * Playlist enabled changed
2396 void MainWindow::playlistEnabledChanged(void)
2398 m_settings->createPlaylist(generatePlaylistCheckBox->isChecked());
2401 // =========================================================
2402 // Compression tab slots
2403 // =========================================================
2408 void MainWindow::updateEncoder(int id)
2410 m_settings->compressionEncoder(id);
2412 switch(m_settings->compressionEncoder())
2414 case SettingsModel::VorbisEncoder:
2415 radioButtonModeQuality->setEnabled(true);
2416 radioButtonModeAverageBitrate->setEnabled(true);
2417 radioButtonConstBitrate->setEnabled(false);
2418 if(radioButtonConstBitrate->isChecked()) radioButtonModeQuality->setChecked(true);
2419 sliderBitrate->setEnabled(true);
2421 case SettingsModel::AC3Encoder:
2422 radioButtonModeQuality->setEnabled(true);
2423 radioButtonModeQuality->setChecked(true);
2424 radioButtonModeAverageBitrate->setEnabled(false);
2425 radioButtonConstBitrate->setEnabled(true);
2426 sliderBitrate->setEnabled(true);
2428 case SettingsModel::FLACEncoder:
2429 radioButtonModeQuality->setEnabled(false);
2430 radioButtonModeQuality->setChecked(true);
2431 radioButtonModeAverageBitrate->setEnabled(false);
2432 radioButtonConstBitrate->setEnabled(false);
2433 sliderBitrate->setEnabled(true);
2435 case SettingsModel::PCMEncoder:
2436 radioButtonModeQuality->setEnabled(false);
2437 radioButtonModeQuality->setChecked(true);
2438 radioButtonModeAverageBitrate->setEnabled(false);
2439 radioButtonConstBitrate->setEnabled(false);
2440 sliderBitrate->setEnabled(false);
2442 case SettingsModel::AACEncoder:
2443 radioButtonModeQuality->setEnabled(true);
2444 radioButtonModeAverageBitrate->setEnabled(!m_fhgEncoderAvailable);
2445 if(m_fhgEncoderAvailable && radioButtonModeAverageBitrate->isChecked()) radioButtonConstBitrate->setChecked(true);
2446 radioButtonConstBitrate->setEnabled(true);
2447 sliderBitrate->setEnabled(true);
2450 radioButtonModeQuality->setEnabled(true);
2451 radioButtonModeAverageBitrate->setEnabled(true);
2452 radioButtonConstBitrate->setEnabled(true);
2453 sliderBitrate->setEnabled(true);
2457 updateRCMode(m_modeButtonGroup->checkedId());
2461 * Update rate-control mode
2463 void MainWindow::updateRCMode(int id)
2465 m_settings->compressionRCMode(id);
2467 switch(m_settings->compressionEncoder())
2469 case SettingsModel::MP3Encoder:
2470 switch(m_settings->compressionRCMode())
2472 case SettingsModel::VBRMode:
2473 sliderBitrate->setMinimum(0);
2474 sliderBitrate->setMaximum(9);
2477 sliderBitrate->setMinimum(0);
2478 sliderBitrate->setMaximum(13);
2482 case SettingsModel::VorbisEncoder:
2483 switch(m_settings->compressionRCMode())
2485 case SettingsModel::VBRMode:
2486 sliderBitrate->setMinimum(-2);
2487 sliderBitrate->setMaximum(10);
2490 sliderBitrate->setMinimum(4);
2491 sliderBitrate->setMaximum(63);
2495 case SettingsModel::AC3Encoder:
2496 switch(m_settings->compressionRCMode())
2498 case SettingsModel::VBRMode:
2499 sliderBitrate->setMinimum(0);
2500 sliderBitrate->setMaximum(16);
2503 sliderBitrate->setMinimum(0);
2504 sliderBitrate->setMaximum(18);
2508 case SettingsModel::AACEncoder:
2509 switch(m_settings->compressionRCMode())
2511 case SettingsModel::VBRMode:
2512 sliderBitrate->setMinimum(0);
2513 sliderBitrate->setMaximum(20);
2516 sliderBitrate->setMinimum(4);
2517 sliderBitrate->setMaximum(63);
2521 case SettingsModel::FLACEncoder:
2522 sliderBitrate->setMinimum(0);
2523 sliderBitrate->setMaximum(8);
2525 case SettingsModel::PCMEncoder:
2526 sliderBitrate->setMinimum(0);
2527 sliderBitrate->setMaximum(2);
2528 sliderBitrate->setValue(1);
2531 sliderBitrate->setMinimum(0);
2532 sliderBitrate->setMaximum(0);
2536 updateBitrate(sliderBitrate->value());
2542 void MainWindow::updateBitrate(int value)
2544 m_settings->compressionBitrate(value);
2546 switch(m_settings->compressionRCMode())
2548 case SettingsModel::VBRMode:
2549 switch(m_settings->compressionEncoder())
2551 case SettingsModel::MP3Encoder:
2552 labelBitrate->setText(tr("Quality Level %1").arg(9 - value));
2554 case SettingsModel::VorbisEncoder:
2555 labelBitrate->setText(tr("Quality Level %1").arg(value));
2557 case SettingsModel::AACEncoder:
2558 labelBitrate->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", static_cast<double>(value * 5) / 100.0)));
2560 case SettingsModel::FLACEncoder:
2561 labelBitrate->setText(tr("Compression %1").arg(value));
2563 case SettingsModel::AC3Encoder:
2564 labelBitrate->setText(tr("Quality Level %1").arg(min(1024, max(0, value * 64))));
2566 case SettingsModel::PCMEncoder:
2567 labelBitrate->setText(tr("Uncompressed"));
2570 labelBitrate->setText(QString::number(value));
2574 case SettingsModel::ABRMode:
2575 switch(m_settings->compressionEncoder())
2577 case SettingsModel::MP3Encoder:
2578 labelBitrate->setText(QString("≈ %1 kbps").arg(SettingsModel::mp3Bitrates[value]));
2580 case SettingsModel::FLACEncoder:
2581 labelBitrate->setText(tr("Compression %1").arg(value));
2583 case SettingsModel::AC3Encoder:
2584 labelBitrate->setText(QString("≈ %1 kbps").arg(SettingsModel::ac3Bitrates[value]));
2586 case SettingsModel::PCMEncoder:
2587 labelBitrate->setText(tr("Uncompressed"));
2590 labelBitrate->setText(QString("≈ %1 kbps").arg(min(500, value * 8)));
2595 switch(m_settings->compressionEncoder())
2597 case SettingsModel::MP3Encoder:
2598 labelBitrate->setText(QString("%1 kbps").arg(SettingsModel::mp3Bitrates[value]));
2600 case SettingsModel::FLACEncoder:
2601 labelBitrate->setText(tr("Compression %1").arg(value));
2603 case SettingsModel::AC3Encoder:
2604 labelBitrate->setText(QString("%1 kbps").arg(SettingsModel::ac3Bitrates[value]));
2606 case SettingsModel::PCMEncoder:
2607 labelBitrate->setText(tr("Uncompressed"));
2610 labelBitrate->setText(QString("%1 kbps").arg(min(500, value * 8)));
2617 // =========================================================
2618 // Advanced option slots
2619 // =========================================================
2622 * Lame algorithm quality changed
2624 void MainWindow::updateLameAlgoQuality(int value)
2631 text = tr("Best Quality (Very Slow)");
2634 text = tr("High Quality (Recommended)");
2637 text = tr("Average Quality (Default)");
2640 text = tr("Low Quality (Fast)");
2643 text = tr("Poor Quality (Very Fast)");
2649 m_settings->lameAlgoQuality(value);
2650 labelLameAlgoQuality->setText(text);
2653 bool warning = (value == 0), notice = (value == 4);
2654 labelLameAlgoQualityWarning->setVisible(warning);
2655 labelLameAlgoQualityWarningIcon->setVisible(warning);
2656 labelLameAlgoQualityNotice->setVisible(notice);
2657 labelLameAlgoQualityNoticeIcon->setVisible(notice);
2658 labelLameAlgoQualitySpacer->setVisible(warning || notice);
2662 * Bitrate management endabled/disabled
2664 void MainWindow::bitrateManagementEnabledChanged(bool checked)
2666 m_settings->bitrateManagementEnabled(checked);
2670 * Minimum bitrate has changed
2672 void MainWindow::bitrateManagementMinChanged(int value)
2674 if(value > spinBoxBitrateManagementMax->value())
2676 spinBoxBitrateManagementMin->setValue(spinBoxBitrateManagementMax->value());
2677 m_settings->bitrateManagementMinRate(spinBoxBitrateManagementMax->value());
2681 m_settings->bitrateManagementMinRate(value);
2686 * Maximum bitrate has changed
2688 void MainWindow::bitrateManagementMaxChanged(int value)
2690 if(value < spinBoxBitrateManagementMin->value())
2692 spinBoxBitrateManagementMax->setValue(spinBoxBitrateManagementMin->value());
2693 m_settings->bitrateManagementMaxRate(spinBoxBitrateManagementMin->value());
2697 m_settings->bitrateManagementMaxRate(value);
2702 * Channel mode has changed
2704 void MainWindow::channelModeChanged(int value)
2706 if(value >= 0) m_settings->lameChannelMode(value);
2710 * Sampling rate has changed
2712 void MainWindow::samplingRateChanged(int value)
2714 if(value >= 0) m_settings->samplingRate(value);
2718 * Nero AAC 2-Pass mode changed
2720 void MainWindow::neroAAC2PassChanged(bool checked)
2722 m_settings->neroAACEnable2Pass(checked);
2726 * Nero AAC profile mode changed
2728 void MainWindow::neroAACProfileChanged(int value)
2730 if(value >= 0) m_settings->aacEncProfile(value);
2734 * Aften audio coding mode changed
2736 void MainWindow::aftenCodingModeChanged(int value)
2738 if(value >= 0) m_settings->aftenAudioCodingMode(value);
2742 * Aften DRC mode changed
2744 void MainWindow::aftenDRCModeChanged(int value)
2746 if(value >= 0) m_settings->aftenDynamicRangeCompression(value);
2750 * Aften exponent search size changed
2752 void MainWindow::aftenSearchSizeChanged(int value)
2754 if(value >= 0) m_settings->aftenExponentSearchSize(value);
2758 * Aften fast bit allocation changed
2760 void MainWindow::aftenFastAllocationChanged(bool checked)
2762 m_settings->aftenFastBitAllocation(checked);
2766 * Normalization filter enabled changed
2768 void MainWindow::normalizationEnabledChanged(bool checked)
2770 m_settings->normalizationFilterEnabled(checked);
2774 * Normalization max. volume changed
2776 void MainWindow::normalizationMaxVolumeChanged(double value)
2778 m_settings->normalizationFilterMaxVolume(static_cast<int>(value * 100.0));
2782 * Tone adjustment has changed (Bass)
2784 void MainWindow::toneAdjustBassChanged(double value)
2786 m_settings->toneAdjustBass(static_cast<int>(value * 100.0));
2787 spinBoxToneAdjustBass->setPrefix((value > 0) ? "+" : QString());
2791 * Tone adjustment has changed (Treble)
2793 void MainWindow::toneAdjustTrebleChanged(double value)
2795 m_settings->toneAdjustTreble(static_cast<int>(value * 100.0));
2796 spinBoxToneAdjustTreble->setPrefix((value > 0) ? "+" : QString());
2800 * Tone adjustment has been reset
2802 void MainWindow::toneAdjustTrebleReset(void)
2804 spinBoxToneAdjustBass->setValue(m_settings->toneAdjustBassDefault());
2805 spinBoxToneAdjustTreble->setValue(m_settings->toneAdjustTrebleDefault());
2806 toneAdjustBassChanged(spinBoxToneAdjustBass->value());
2807 toneAdjustTrebleChanged(spinBoxToneAdjustTreble->value());
2811 * Custom encoder parameters changed
2813 void MainWindow::customParamsChanged(void)
2815 lineEditCustomParamLAME->setText(lineEditCustomParamLAME->text().simplified());
2816 lineEditCustomParamOggEnc->setText(lineEditCustomParamOggEnc->text().simplified());
2817 lineEditCustomParamNeroAAC->setText(lineEditCustomParamNeroAAC->text().simplified());
2818 lineEditCustomParamFLAC->setText(lineEditCustomParamFLAC->text().simplified());
2819 lineEditCustomParamAften->setText(lineEditCustomParamAften->text().simplified());
2821 bool customParamsUsed = false;
2822 if(!lineEditCustomParamLAME->text().isEmpty()) customParamsUsed = true;
2823 if(!lineEditCustomParamOggEnc->text().isEmpty()) customParamsUsed = true;
2824 if(!lineEditCustomParamNeroAAC->text().isEmpty()) customParamsUsed = true;
2825 if(!lineEditCustomParamFLAC->text().isEmpty()) customParamsUsed = true;
2826 if(!lineEditCustomParamAften->text().isEmpty()) customParamsUsed = true;
2828 labelCustomParamsIcon->setVisible(customParamsUsed);
2829 labelCustomParamsText->setVisible(customParamsUsed);
2830 labelCustomParamsSpacer->setVisible(customParamsUsed);
2832 m_settings->customParametersLAME(lineEditCustomParamLAME->text());
2833 m_settings->customParametersOggEnc(lineEditCustomParamOggEnc->text());
2834 m_settings->customParametersAacEnc(lineEditCustomParamNeroAAC->text());
2835 m_settings->customParametersFLAC(lineEditCustomParamFLAC->text());
2836 m_settings->customParametersAften(lineEditCustomParamAften->text());
2841 * Rename output files enabled changed
2843 void MainWindow::renameOutputEnabledChanged(bool checked)
2845 m_settings->renameOutputFilesEnabled(checked);
2849 * Rename output files patterm changed
2851 void MainWindow::renameOutputPatternChanged(void)
2853 QString temp = lineEditRenamePattern->text().simplified();
2854 lineEditRenamePattern->setText(temp.isEmpty() ? m_settings->renameOutputFilesPatternDefault() : temp);
2855 m_settings->renameOutputFilesPattern(lineEditRenamePattern->text());
2859 * Rename output files patterm changed
2861 void MainWindow::renameOutputPatternChanged(const QString &text)
2863 QString pattern(text.simplified());
2865 pattern.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive);
2866 pattern.replace("<TrackNo>", "04", Qt::CaseInsensitive);
2867 pattern.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive);
2868 pattern.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive);
2869 pattern.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive);
2870 pattern.replace("<Year>", "2001", Qt::CaseInsensitive);
2871 pattern.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive);
2873 if(pattern.compare(lamexp_clean_filename(pattern)))
2875 if(lineEditRenamePattern->palette().color(QPalette::Text) != Qt::red)
2877 MessageBeep(MB_ICONERROR);
2878 SET_TEXT_COLOR(lineEditRenamePattern, Qt::red);
2883 if(lineEditRenamePattern->palette().color(QPalette::Text) != Qt::black)
2885 MessageBeep(MB_ICONINFORMATION);
2886 SET_TEXT_COLOR(lineEditRenamePattern, Qt::black);
2890 labelRanameExample->setText(lamexp_clean_filename(pattern));
2894 * Show list of rename macros
2896 void MainWindow::showRenameMacros(const QString &text)
2898 if(text.compare("reset", Qt::CaseInsensitive) == 0)
2900 lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
2904 const QString format = QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
2906 QString message = QString("<table>");
2907 message += QString(format).arg("BaseName", tr("File name without extension"));
2908 message += QString(format).arg("TrackNo", tr("Track number with leading zero"));
2909 message += QString(format).arg("Title", tr("Track title"));
2910 message += QString(format).arg("Artist", tr("Artist name"));
2911 message += QString(format).arg("Album", tr("Album name"));
2912 message += QString(format).arg("Year", tr("Year with (at least) four digits"));
2913 message += QString(format).arg("Comment", tr("Comment"));
2914 message += "</table><br><br>";
2915 message += QString("%1<br>").arg(tr("Characters forbidden in file names:"));
2916 message += "<b><tt>\\ / : * ? < > |<br>";
2918 QMessageBox::information(this, tr("Rename Macros"), message, tr("Discard"));
2921 void MainWindow::forceStereoDownmixEnabledChanged(bool checked)
2923 m_settings->forceStereoDownmix(checked);
2927 * Maximum number of instances changed
2929 void MainWindow::updateMaximumInstances(int value)
2931 labelMaxInstances->setText(tr("%1 Instance(s)").arg(QString::number(value)));
2932 m_settings->maximumInstances(checkBoxAutoDetectInstances->isChecked() ? NULL : value);
2936 * Auto-detect number of instances
2938 void MainWindow::autoDetectInstancesChanged(bool checked)
2940 m_settings->maximumInstances(checked ? NULL : sliderMaxInstances->value());
2944 * Browse for custom TEMP folder button clicked
2946 void MainWindow::browseCustomTempFolderButtonClicked(void)
2948 QString newTempFolder;
2950 if(USE_NATIVE_FILE_DIALOG)
2952 newTempFolder = QFileDialog::getExistingDirectory(this, QString(), m_settings->customTempPath());
2956 QFileDialog dialog(this);
2957 dialog.setFileMode(QFileDialog::DirectoryOnly);
2958 dialog.setDirectory(m_settings->customTempPath());
2961 newTempFolder = dialog.selectedFiles().first();
2965 if(!newTempFolder.isEmpty())
2967 QFile writeTest(QString("%1/~%2.tmp").arg(newTempFolder, lamexp_rand_str()));
2968 if(writeTest.open(QIODevice::ReadWrite))
2971 lineEditCustomTempFolder->setText(QDir::toNativeSeparators(newTempFolder));
2975 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
2981 * Custom TEMP folder changed
2983 void MainWindow::customTempFolderChanged(const QString &text)
2985 m_settings->customTempPath(QDir::fromNativeSeparators(text));
2989 * Use custom TEMP folder option changed
2991 void MainWindow::useCustomTempFolderChanged(bool checked)
2993 m_settings->customTempPathEnabled(!checked);
2997 * Reset all advanced options to their defaults
2999 void MainWindow::resetAdvancedOptionsButtonClicked(void)
3001 sliderLameAlgoQuality->setValue(m_settings->lameAlgoQualityDefault());
3002 spinBoxBitrateManagementMin->setValue(m_settings->bitrateManagementMinRateDefault());
3003 spinBoxBitrateManagementMax->setValue(m_settings->bitrateManagementMaxRateDefault());
3004 spinBoxNormalizationFilter->setValue(static_cast<double>(m_settings->normalizationFilterMaxVolumeDefault()) / 100.0);
3005 spinBoxToneAdjustBass->setValue(static_cast<double>(m_settings->toneAdjustBassDefault()) / 100.0);
3006 spinBoxToneAdjustTreble->setValue(static_cast<double>(m_settings->toneAdjustTrebleDefault()) / 100.0);
3007 spinBoxAftenSearchSize->setValue(m_settings->aftenExponentSearchSizeDefault());
3008 comboBoxMP3ChannelMode->setCurrentIndex(m_settings->lameChannelModeDefault());
3009 comboBoxSamplingRate->setCurrentIndex(m_settings->samplingRateDefault());
3010 comboBoxAACProfile->setCurrentIndex(m_settings->aacEncProfileDefault());
3011 comboBoxAftenCodingMode->setCurrentIndex(m_settings->aftenAudioCodingModeDefault());
3012 comboBoxAftenDRCMode->setCurrentIndex(m_settings->aftenDynamicRangeCompressionDefault());
3013 while(checkBoxBitrateManagement->isChecked() != m_settings->bitrateManagementEnabledDefault()) checkBoxBitrateManagement->click();
3014 while(checkBoxNeroAAC2PassMode->isChecked() != m_settings->neroAACEnable2PassDefault()) checkBoxNeroAAC2PassMode->click();
3015 while(checkBoxNormalizationFilter->isChecked() != m_settings->normalizationFilterEnabledDefault()) checkBoxNormalizationFilter->click();
3016 while(checkBoxAutoDetectInstances->isChecked() != (m_settings->maximumInstancesDefault() < 1)) checkBoxAutoDetectInstances->click();
3017 while(checkBoxUseSystemTempFolder->isChecked() == m_settings->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder->click();
3018 while(checkBoxAftenFastAllocation->isChecked() != m_settings->aftenFastBitAllocationDefault()) checkBoxAftenFastAllocation->click();
3019 while(checkBoxRenameOutput->isChecked() != m_settings->renameOutputFilesEnabledDefault()) checkBoxRenameOutput->click();
3020 while(checkBoxForceStereoDownmix->isChecked() != m_settings->forceStereoDownmixDefault()) checkBoxForceStereoDownmix->click();
3021 lineEditCustomParamLAME->setText(m_settings->customParametersLAMEDefault());
3022 lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEncDefault());
3023 lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEncDefault());
3024 lineEditCustomParamFLAC->setText(m_settings->customParametersFLACDefault());
3025 lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPathDefault()));
3026 lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
3027 customParamsChanged();
3028 scrollArea->verticalScrollBar()->setValue(0);
3031 // =========================================================
3032 // Multi-instance handling slots
3033 // =========================================================
3036 * Other instance detected
3038 void MainWindow::notifyOtherInstance(void)
3040 if(!m_banner->isVisible())
3042 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);
3048 * Add file from another instance
3050 void MainWindow::addFileDelayed(const QString &filePath, bool tryASAP)
3052 if(tryASAP && !m_delayedFileTimer->isActive())
3054 qDebug("Received file: %s", filePath.toUtf8().constData());
3055 m_delayedFileList->append(filePath);
3056 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3059 m_delayedFileTimer->stop();
3060 qDebug("Received file: %s", filePath.toUtf8().constData());
3061 m_delayedFileList->append(filePath);
3062 m_delayedFileTimer->start(5000);
3066 * Add files from another instance
3068 void MainWindow::addFilesDelayed(const QStringList &filePaths, bool tryASAP)
3070 if(tryASAP && !m_delayedFileTimer->isActive())
3072 qDebug("Received %d file(s).", filePaths.count());
3073 m_delayedFileList->append(filePaths);
3074 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3078 m_delayedFileTimer->stop();
3079 qDebug("Received %d file(s).", filePaths.count());
3080 m_delayedFileList->append(filePaths);
3081 m_delayedFileTimer->start(5000);
3086 * Add folder from another instance
3088 void MainWindow::addFolderDelayed(const QString &folderPath, bool recursive)
3090 if(!m_banner->isVisible())
3092 addFolder(folderPath, recursive, true);
3096 // =========================================================
3098 // =========================================================
3101 * Restore the override cursor
3103 void MainWindow::restoreCursor(void)
3105 QApplication::restoreOverrideCursor();