1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_MainWindow.h"
27 #include "Dialog_WorkingBanner.h"
28 #include "Dialog_MetaInfo.h"
29 #include "Dialog_About.h"
30 #include "Dialog_Update.h"
31 #include "Dialog_DropBox.h"
32 #include "Dialog_CueImport.h"
33 #include "Thread_FileAnalyzer.h"
34 #include "Thread_MessageHandler.h"
35 #include "Model_MetaInfo.h"
36 #include "Model_Settings.h"
37 #include "Model_FileList.h"
38 #include "Model_FileSystem.h"
39 #include "WinSevenTaskbar.h"
40 #include "Registry_Decoder.h"
41 #include "ShellIntegration.h"
44 #include <QMessageBox>
46 #include <QDesktopWidget>
48 #include <QFileDialog>
49 #include <QInputDialog>
50 #include <QFileSystemModel>
51 #include <QDesktopServices>
53 #include <QPlastiqueStyle>
54 #include <QCleanlooksStyle>
55 #include <QWindowsVistaStyle>
56 #include <QWindowsStyle>
58 #include <QDragEnterEvent>
59 #include <QWindowsMime>
62 #include <QProcessEnvironment>
63 #include <QCryptographicHash>
64 #include <QTranslator>
72 #define ABORT_IF_BUSY if(m_banner->isVisible() || m_delayedFileTimer->isActive()) { MessageBeep(MB_ICONEXCLAMATION); return; }
73 #define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); }
74 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
75 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(URL)
76 #define TEMP_HIDE_DROPBOX(CMD) { bool __dropBoxVisible = m_dropBox->isVisible(); if(__dropBoxVisible) m_dropBox->hide(); {CMD}; if(__dropBoxVisible) m_dropBox->show(); }
77 #define USE_NATIVE_FILE_DIALOG (lamexp_themes_enabled() || ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) < QSysInfo::WV_XP))
78 #define NOBR(STR) QString("<nobr>%1</nobr>").arg(STR).replace("-", "−")
80 ////////////////////////////////////////////////////////////
82 ////////////////////////////////////////////////////////////
84 MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settingsModel, QWidget *parent)
87 m_fileListModel(fileListModel),
89 m_settings(settingsModel),
90 m_neroEncoderAvailable(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")),
91 m_fhgEncoderAvailable(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll") && lamexp_check_tool("nsutil.dll") && lamexp_check_tool("libmp4v2.dll")),
93 m_firstTimeShown(true),
94 m_OutputFolderViewInitialized(false)
96 //Init the dialog, from the .ui file
98 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint);
100 //Register meta types
101 qRegisterMetaType<AudioFileModel>("AudioFileModel");
103 //Enabled main buttons
104 connect(buttonAbout, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
105 connect(buttonStart, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
106 connect(buttonQuit, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
109 tabWidget->setCurrentIndex(0);
110 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
113 sourceFileView->setModel(m_fileListModel);
114 sourceFileView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
115 sourceFileView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
116 sourceFileView->setContextMenuPolicy(Qt::CustomContextMenu);
117 sourceFileView->viewport()->installEventFilter(this);
118 m_dropNoteLabel = new QLabel(sourceFileView);
119 m_dropNoteLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
120 SET_FONT_BOLD(m_dropNoteLabel, true);
121 SET_TEXT_COLOR(m_dropNoteLabel, Qt::darkGray);
122 m_sourceFilesContextMenu = new QMenu();
123 m_showDetailsContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/zoom.png"), "N/A");
124 m_previewContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/sound.png"), "N/A");
125 m_findFileContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/folder_go.png"), "N/A");
126 SET_FONT_BOLD(m_showDetailsContextAction, true);
127 connect(buttonAddFiles, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
128 connect(buttonRemoveFile, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
129 connect(buttonClearFiles, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
130 connect(buttonFileUp, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
131 connect(buttonFileDown, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
132 connect(buttonShowDetails, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
133 connect(m_fileListModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(sourceModelChanged()));
134 connect(m_fileListModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(sourceModelChanged()));
135 connect(m_fileListModel, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
136 connect(sourceFileView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(sourceFilesContextMenu(QPoint)));
137 connect(sourceFileView->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
138 connect(sourceFileView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
139 connect(m_showDetailsContextAction, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
140 connect(m_previewContextAction, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
141 connect(m_findFileContextAction, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
144 m_fileSystemModel = new QFileSystemModelEx();
145 m_fileSystemModel->installEventFilter(this);
146 outputFolderView->setModel(m_fileSystemModel);
147 outputFolderView->header()->setStretchLastSection(true);
148 outputFolderView->header()->hideSection(1);
149 outputFolderView->header()->hideSection(2);
150 outputFolderView->header()->hideSection(3);
151 outputFolderView->setHeaderHidden(true);
152 outputFolderView->setAnimated(false);
153 outputFolderView->setMouseTracking(false);
154 outputFolderView->setContextMenuPolicy(Qt::CustomContextMenu);
155 outputFolderView->installEventFilter(this);
156 outputFoldersFovoritesLabel->installEventFilter(this);
157 while(saveToSourceFolderCheckBox->isChecked() != m_settings->outputToSourceDir()) saveToSourceFolderCheckBox->click();
158 prependRelativePathCheckBox->setChecked(m_settings->prependRelativeSourcePath());
159 connect(outputFolderView, SIGNAL(clicked(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
160 connect(outputFolderView, SIGNAL(activated(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
161 connect(outputFolderView, SIGNAL(pressed(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
162 connect(outputFolderView, SIGNAL(entered(QModelIndex)), this, SLOT(outputFolderViewMoved(QModelIndex)));
163 connect(buttonMakeFolder, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
164 connect(buttonGotoHome, SIGNAL(clicked()), SLOT(gotoHomeFolderButtonClicked()));
165 connect(buttonGotoDesktop, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
166 connect(buttonGotoMusic, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
167 connect(saveToSourceFolderCheckBox, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
168 connect(prependRelativePathCheckBox, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
169 m_outputFolderContextMenu = new QMenu();
170 m_showFolderContextAction = m_outputFolderContextMenu->addAction(QIcon(":/icons/zoom.png"), "N/A");
171 m_outputFolderFavoritesMenu = new QMenu();
172 m_addFavoriteFolderAction = m_outputFolderFavoritesMenu->addAction(QIcon(":/icons/add.png"), "N/A");
173 m_outputFolderFavoritesMenu->insertSeparator(m_addFavoriteFolderAction);
174 connect(outputFolderView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(outputFolderContextMenu(QPoint)));
175 connect(m_showFolderContextAction, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
176 connect(m_addFavoriteFolderAction, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
177 outputFolderLabel->installEventFilter(this);
178 outputFolderView->setCurrentIndex(m_fileSystemModel->index(m_settings->outputDir()));
179 outputFolderViewClicked(outputFolderView->currentIndex());
182 //Setup "Meta Data" tab
183 m_metaInfoModel = new MetaInfoModel(m_metaData, 6);
184 m_metaInfoModel->clearData();
185 m_metaInfoModel->setData(m_metaInfoModel->index(4, 1), m_settings->metaInfoPosition());
186 metaDataView->setModel(m_metaInfoModel);
187 metaDataView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
188 metaDataView->verticalHeader()->hide();
189 metaDataView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
190 while(writeMetaDataCheckBox->isChecked() != m_settings->writeMetaTags()) writeMetaDataCheckBox->click();
191 generatePlaylistCheckBox->setChecked(m_settings->createPlaylist());
192 connect(buttonEditMeta, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
193 connect(buttonClearMeta, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
194 connect(writeMetaDataCheckBox, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
195 connect(generatePlaylistCheckBox, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
197 //Setup "Compression" tab
198 m_encoderButtonGroup = new QButtonGroup(this);
199 m_encoderButtonGroup->addButton(radioButtonEncoderMP3, SettingsModel::MP3Encoder);
200 m_encoderButtonGroup->addButton(radioButtonEncoderVorbis, SettingsModel::VorbisEncoder);
201 m_encoderButtonGroup->addButton(radioButtonEncoderAAC, SettingsModel::AACEncoder);
202 m_encoderButtonGroup->addButton(radioButtonEncoderAC3, SettingsModel::AC3Encoder);
203 m_encoderButtonGroup->addButton(radioButtonEncoderFLAC, SettingsModel::FLACEncoder);
204 m_encoderButtonGroup->addButton(radioButtonEncoderPCM, SettingsModel::PCMEncoder);
205 m_modeButtonGroup = new QButtonGroup(this);
206 m_modeButtonGroup->addButton(radioButtonModeQuality, SettingsModel::VBRMode);
207 m_modeButtonGroup->addButton(radioButtonModeAverageBitrate, SettingsModel::ABRMode);
208 m_modeButtonGroup->addButton(radioButtonConstBitrate, SettingsModel::CBRMode);
209 radioButtonEncoderAAC->setEnabled(m_neroEncoderAvailable || m_fhgEncoderAvailable);
210 radioButtonEncoderMP3->setChecked(m_settings->compressionEncoder() == SettingsModel::MP3Encoder);
211 radioButtonEncoderVorbis->setChecked(m_settings->compressionEncoder() == SettingsModel::VorbisEncoder);
212 radioButtonEncoderAAC->setChecked((m_settings->compressionEncoder() == SettingsModel::AACEncoder) && (m_neroEncoderAvailable || m_fhgEncoderAvailable));
213 radioButtonEncoderAC3->setChecked(m_settings->compressionEncoder() == SettingsModel::AC3Encoder);
214 radioButtonEncoderFLAC->setChecked(m_settings->compressionEncoder() == SettingsModel::FLACEncoder);
215 radioButtonEncoderPCM->setChecked(m_settings->compressionEncoder() == SettingsModel::PCMEncoder);
216 radioButtonModeQuality->setChecked(m_settings->compressionRCMode() == SettingsModel::VBRMode);
217 radioButtonModeAverageBitrate->setChecked(m_settings->compressionRCMode() == SettingsModel::ABRMode);
218 radioButtonConstBitrate->setChecked(m_settings->compressionRCMode() == SettingsModel::CBRMode);
219 sliderBitrate->setValue(m_settings->compressionBitrate());
220 connect(m_encoderButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
221 connect(m_modeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
222 connect(sliderBitrate, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
223 updateEncoder(m_encoderButtonGroup->checkedId());
225 //Setup "Advanced Options" tab
226 sliderLameAlgoQuality->setValue(m_settings->lameAlgoQuality());
227 if(m_settings->maximumInstances() > 0) sliderMaxInstances->setValue(m_settings->maximumInstances());
228 spinBoxBitrateManagementMin->setValue(m_settings->bitrateManagementMinRate());
229 spinBoxBitrateManagementMax->setValue(m_settings->bitrateManagementMaxRate());
230 spinBoxNormalizationFilter->setValue(static_cast<double>(m_settings->normalizationFilterMaxVolume()) / 100.0);
231 spinBoxToneAdjustBass->setValue(static_cast<double>(m_settings->toneAdjustBass()) / 100.0);
232 spinBoxToneAdjustTreble->setValue(static_cast<double>(m_settings->toneAdjustTreble()) / 100.0);
233 spinBoxAftenSearchSize->setValue(m_settings->aftenExponentSearchSize());
234 comboBoxMP3ChannelMode->setCurrentIndex(m_settings->lameChannelMode());
235 comboBoxSamplingRate->setCurrentIndex(m_settings->samplingRate());
236 comboBoxAACProfile->setCurrentIndex(m_settings->aacEncProfile());
237 comboBoxAftenCodingMode->setCurrentIndex(m_settings->aftenAudioCodingMode());
238 comboBoxAftenDRCMode->setCurrentIndex(m_settings->aftenDynamicRangeCompression());
239 while(checkBoxBitrateManagement->isChecked() != m_settings->bitrateManagementEnabled()) checkBoxBitrateManagement->click();
240 while(checkBoxNeroAAC2PassMode->isChecked() != m_settings->neroAACEnable2Pass()) checkBoxNeroAAC2PassMode->click();
241 while(checkBoxAftenFastAllocation->isChecked() != m_settings->aftenFastBitAllocation()) checkBoxAftenFastAllocation->click();
242 while(checkBoxNormalizationFilter->isChecked() != m_settings->normalizationFilterEnabled()) checkBoxNormalizationFilter->click();
243 while(checkBoxAutoDetectInstances->isChecked() != (m_settings->maximumInstances() < 1)) checkBoxAutoDetectInstances->click();
244 while(checkBoxUseSystemTempFolder->isChecked() == m_settings->customTempPathEnabled()) checkBoxUseSystemTempFolder->click();
245 while(checkBoxRenameOutput->isChecked() != m_settings->renameOutputFilesEnabled()) checkBoxRenameOutput->click();
246 while(checkBoxForceStereoDownmix->isChecked() != m_settings->forceStereoDownmix()) checkBoxForceStereoDownmix->click();
247 checkBoxNeroAAC2PassMode->setEnabled(!m_fhgEncoderAvailable);
248 lineEditCustomParamLAME->setText(m_settings->customParametersLAME());
249 lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEnc());
250 lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEnc());
251 lineEditCustomParamFLAC->setText(m_settings->customParametersFLAC());
252 lineEditCustomParamAften->setText(m_settings->customParametersAften());
253 lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPath()));
254 lineEditRenamePattern->setText(m_settings->renameOutputFilesPattern());
255 connect(sliderLameAlgoQuality, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
256 connect(checkBoxBitrateManagement, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
257 connect(spinBoxBitrateManagementMin, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
258 connect(spinBoxBitrateManagementMax, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
259 connect(comboBoxMP3ChannelMode, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
260 connect(comboBoxSamplingRate, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
261 connect(checkBoxNeroAAC2PassMode, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
262 connect(comboBoxAACProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
263 connect(checkBoxNormalizationFilter, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
264 connect(comboBoxAftenCodingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
265 connect(comboBoxAftenDRCMode, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
266 connect(spinBoxAftenSearchSize, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
267 connect(checkBoxAftenFastAllocation, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
268 connect(spinBoxNormalizationFilter, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
269 connect(spinBoxToneAdjustBass, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
270 connect(spinBoxToneAdjustTreble, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
271 connect(buttonToneAdjustReset, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
272 connect(lineEditCustomParamLAME, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
273 connect(lineEditCustomParamOggEnc, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
274 connect(lineEditCustomParamNeroAAC, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
275 connect(lineEditCustomParamFLAC, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
276 connect(lineEditCustomParamAften, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
277 connect(sliderMaxInstances, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
278 connect(checkBoxAutoDetectInstances, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
279 connect(buttonBrowseCustomTempFolder, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
280 connect(lineEditCustomTempFolder, SIGNAL(textChanged(QString)), this, SLOT(customTempFolderChanged(QString)));
281 connect(checkBoxUseSystemTempFolder, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
282 connect(buttonResetAdvancedOptions, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
283 connect(checkBoxRenameOutput, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
284 connect(lineEditRenamePattern, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
285 connect(lineEditRenamePattern, SIGNAL(textChanged(QString)), this, SLOT(renameOutputPatternChanged(QString)));
286 connect(labelShowRenameMacros, SIGNAL(linkActivated(QString)), this, SLOT(showRenameMacros(QString)));
287 connect(checkBoxForceStereoDownmix, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
288 updateLameAlgoQuality(sliderLameAlgoQuality->value());
289 updateMaximumInstances(sliderMaxInstances->value());
290 toneAdjustTrebleChanged(spinBoxToneAdjustTreble->value());
291 toneAdjustBassChanged(spinBoxToneAdjustBass->value());
292 customParamsChanged();
294 //Activate file menu actions
295 actionOpenFolder->setData(QVariant::fromValue<bool>(false));
296 actionOpenFolderRecursively->setData(QVariant::fromValue<bool>(true));
297 connect(actionOpenFolder, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
298 connect(actionOpenFolderRecursively, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
300 //Activate view menu actions
301 m_tabActionGroup = new QActionGroup(this);
302 m_tabActionGroup->addAction(actionSourceFiles);
303 m_tabActionGroup->addAction(actionOutputDirectory);
304 m_tabActionGroup->addAction(actionCompression);
305 m_tabActionGroup->addAction(actionMetaData);
306 m_tabActionGroup->addAction(actionAdvancedOptions);
307 actionSourceFiles->setData(0);
308 actionOutputDirectory->setData(1);
309 actionMetaData->setData(2);
310 actionCompression->setData(3);
311 actionAdvancedOptions->setData(4);
312 actionSourceFiles->setChecked(true);
313 connect(m_tabActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(tabActionActivated(QAction*)));
315 //Activate style menu actions
316 m_styleActionGroup = new QActionGroup(this);
317 m_styleActionGroup->addAction(actionStylePlastique);
318 m_styleActionGroup->addAction(actionStyleCleanlooks);
319 m_styleActionGroup->addAction(actionStyleWindowsVista);
320 m_styleActionGroup->addAction(actionStyleWindowsXP);
321 m_styleActionGroup->addAction(actionStyleWindowsClassic);
322 actionStylePlastique->setData(0);
323 actionStyleCleanlooks->setData(1);
324 actionStyleWindowsVista->setData(2);
325 actionStyleWindowsXP->setData(3);
326 actionStyleWindowsClassic->setData(4);
327 actionStylePlastique->setChecked(true);
328 actionStyleWindowsXP->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_XP && lamexp_themes_enabled());
329 actionStyleWindowsVista->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_VISTA && lamexp_themes_enabled());
330 connect(m_styleActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(styleActionActivated(QAction*)));
331 styleActionActivated(NULL);
333 //Populate the language menu
334 m_languageActionGroup = new QActionGroup(this);
335 QStringList translations = lamexp_query_translations();
336 while(!translations.isEmpty())
338 QString langId = translations.takeFirst();
339 QAction *currentLanguage = new QAction(this);
340 currentLanguage->setData(langId);
341 currentLanguage->setText(lamexp_translation_name(langId));
342 currentLanguage->setIcon(QIcon(QString(":/flags/%1.png").arg(langId)));
343 currentLanguage->setCheckable(true);
344 m_languageActionGroup->addAction(currentLanguage);
345 menuLanguage->insertAction(actionLoadTranslationFromFile, currentLanguage);
347 menuLanguage->insertSeparator(actionLoadTranslationFromFile);
348 connect(actionLoadTranslationFromFile, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
349 connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*)));
351 //Activate tools menu actions
352 actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
353 actionDisableSounds->setChecked(!m_settings->soundsEnabled());
354 actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
355 actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
356 actionDisableShellIntegration->setChecked(!m_settings->shellIntegrationEnabled());
357 actionDisableShellIntegration->setDisabled(lamexp_portable_mode() && actionDisableShellIntegration->isChecked());
358 actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta() || lamexp_version_demo());
359 actionCheckForBetaUpdates->setEnabled(!lamexp_version_demo());
360 connect(actionDisableUpdateReminder, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
361 connect(actionDisableSounds, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
362 connect(actionDisableNeroAacNotifications, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
363 connect(actionDisableSlowStartupNotifications, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
364 connect(actionDisableShellIntegration, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
365 connect(actionShowDropBoxWidget, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
366 connect(actionCheckForBetaUpdates, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
367 connect(actionImportCueSheet, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
369 //Activate help menu actions
370 actionVisitHomepage->setData(QString::fromLatin1(lamexp_website_url()));
371 actionVisitSupport->setData(QString::fromLatin1(lamexp_support_url()));
372 actionDocumentFAQ->setData(QString("%1/FAQ.html").arg(QApplication::applicationDirPath()));
373 actionDocumentChangelog->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
374 actionDocumentTranslate->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
375 connect(actionCheckUpdates, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
376 connect(actionVisitHomepage, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
377 connect(actionVisitSupport, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
378 connect(actionDocumentFAQ, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
379 connect(actionDocumentChangelog, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
380 connect(actionDocumentTranslate, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
382 //Center window in screen
383 QRect desktopRect = QApplication::desktop()->screenGeometry();
384 QRect thisRect = this->geometry();
385 move((desktopRect.width() - thisRect.width()) / 2, (desktopRect.height() - thisRect.height()) / 2);
386 setMinimumSize(thisRect.width(), thisRect.height());
389 m_banner = new WorkingBanner(this);
391 //Create DropBox widget
392 m_dropBox = new DropBox(this, m_fileListModel, m_settings);
393 connect(m_fileListModel, SIGNAL(modelReset()), m_dropBox, SLOT(modelChanged()));
394 connect(m_fileListModel, SIGNAL(rowsInserted(QModelIndex,int,int)), m_dropBox, SLOT(modelChanged()));
395 connect(m_fileListModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), m_dropBox, SLOT(modelChanged()));
397 //Create message handler thread
398 m_messageHandler = new MessageHandlerThread();
399 m_delayedFileList = new QStringList();
400 m_delayedFileTimer = new QTimer();
401 m_delayedFileTimer->setSingleShot(true);
402 m_delayedFileTimer->setInterval(5000);
403 connect(m_messageHandler, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection);
404 connect(m_messageHandler, SIGNAL(fileReceived(QString)), this, SLOT(addFileDelayed(QString)), Qt::QueuedConnection);
405 connect(m_messageHandler, SIGNAL(folderReceived(QString, bool)), this, SLOT(addFolderDelayed(QString, bool)), Qt::QueuedConnection);
406 connect(m_messageHandler, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection);
407 connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
408 m_messageHandler->start();
410 //Load translation file
411 QList<QAction*> languageActions = m_languageActionGroup->actions();
412 while(!languageActions.isEmpty())
414 QAction *currentLanguage = languageActions.takeFirst();
415 if(currentLanguage->data().toString().compare(m_settings->currentLanguage(), Qt::CaseInsensitive) == 0)
417 currentLanguage->setChecked(true);
418 languageActionActivated(currentLanguage);
422 //Re-translate (make sure we translate once)
423 QEvent languageChangeEvent(QEvent::LanguageChange);
424 changeEvent(&languageChangeEvent);
427 this->setAcceptDrops(true);
430 ////////////////////////////////////////////////////////////
432 ////////////////////////////////////////////////////////////
434 MainWindow::~MainWindow(void)
436 //Stop message handler thread
437 if(m_messageHandler && m_messageHandler->isRunning())
439 m_messageHandler->stop();
440 if(!m_messageHandler->wait(10000))
442 m_messageHandler->terminate();
443 m_messageHandler->wait();
448 sourceFileView->setModel(NULL);
449 metaDataView->setModel(NULL);
452 LAMEXP_DELETE(m_tabActionGroup);
453 LAMEXP_DELETE(m_styleActionGroup);
454 LAMEXP_DELETE(m_languageActionGroup);
455 LAMEXP_DELETE(m_banner);
456 LAMEXP_DELETE(m_fileSystemModel);
457 LAMEXP_DELETE(m_messageHandler);
458 LAMEXP_DELETE(m_delayedFileList);
459 LAMEXP_DELETE(m_delayedFileTimer);
460 LAMEXP_DELETE(m_metaInfoModel);
461 LAMEXP_DELETE(m_encoderButtonGroup);
462 LAMEXP_DELETE(m_encoderButtonGroup);
463 LAMEXP_DELETE(m_sourceFilesContextMenu);
464 LAMEXP_DELETE(m_outputFolderFavoritesMenu);
465 LAMEXP_DELETE(m_dropBox);
468 ////////////////////////////////////////////////////////////
470 ////////////////////////////////////////////////////////////
473 * Add file to source list
475 void MainWindow::addFiles(const QStringList &files)
482 tabWidget->setCurrentIndex(0);
484 FileAnalyzer *analyzer = new FileAnalyzer(files);
485 connect(analyzer, SIGNAL(fileSelected(QString)), m_banner, SLOT(setText(QString)), Qt::QueuedConnection);
486 connect(analyzer, SIGNAL(fileAnalyzed(AudioFileModel)), m_fileListModel, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection);
487 connect(m_banner, SIGNAL(userAbort()), analyzer, SLOT(abortProcess()), Qt::DirectConnection);
489 m_banner->show(tr("Adding file(s), please wait..."), analyzer);
491 if(analyzer->filesDenied())
493 QMessageBox::warning(this, tr("Access Denied"), QString("<nobr>%1<br>%2</nobr>").arg(tr("%1 file(s) have been rejected, because read access was not granted!").arg(analyzer->filesDenied()), tr("This usually means the file is locked by another process.")));
495 if(analyzer->filesDummyCDDA())
497 QMessageBox::warning(this, tr("CDDA Files"), QString("<nobr>%1<br><br>%2<br>%3</nobr>").arg(tr("%1 file(s) have been rejected, because they are dummy CDDA files!").arg(analyzer->filesDummyCDDA()), tr("Sorry, LameXP cannot extract audio tracks from an Audio−CD at present."), tr("We recommend using %1 for that purpose.").arg("<a href=\"http://www.exactaudiocopy.de/\">Exact Audio Copy</a>")));
499 if(analyzer->filesCueSheet())
501 QMessageBox::warning(this, tr("Cue Sheet"), QString("<nobr>%1<br>%2</nobr>").arg(tr("%1 file(s) have been rejected, because they appear to be Cue Sheet images!").arg(analyzer->filesCueSheet()), tr("Please use LameXP's Cue Sheet wizard for importing Cue Sheet files.")));
503 if(analyzer->filesRejected())
505 QMessageBox::warning(this, tr("Files Rejected"), QString("<nobr>%1<br>%2</nobr>").arg(tr("%1 file(s) have been rejected, because the file format could not be recognized!").arg(analyzer->filesRejected()), tr("This usually means the file is damaged or the file format is not supported.")));
508 LAMEXP_DELETE(analyzer);
509 sourceFileView->scrollToBottom();
514 * Add folder to source list
516 void MainWindow::addFolder(const QString &path, bool recursive, bool delayed)
518 QFileInfoList folderInfoList;
519 folderInfoList << QFileInfo(path);
520 QStringList fileList;
522 m_banner->show(tr("Scanning folder(s) for files, please wait..."));
524 QApplication::processEvents();
525 GetAsyncKeyState(VK_ESCAPE);
527 while(!folderInfoList.isEmpty())
529 if(GetAsyncKeyState(VK_ESCAPE) & 0x0001)
531 MessageBeep(MB_ICONERROR);
532 qWarning("Operation cancelled by user!");
537 QDir currentDir(folderInfoList.takeFirst().canonicalFilePath());
538 QFileInfoList fileInfoList = currentDir.entryInfoList(QDir::Files | QDir::NoSymLinks);
540 while(!fileInfoList.isEmpty())
542 fileList << fileInfoList.takeFirst().canonicalFilePath();
545 QApplication::processEvents();
549 folderInfoList.append(currentDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks));
550 QApplication::processEvents();
555 QApplication::processEvents();
557 if(!fileList.isEmpty())
561 addFilesDelayed(fileList);
573 bool MainWindow::checkForUpdates(void)
575 bool bReadyToInstall = false;
577 UpdateDialog *updateDialog = new UpdateDialog(m_settings, this);
578 updateDialog->exec();
580 if(updateDialog->getSuccess())
582 m_settings->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate));
583 bReadyToInstall = updateDialog->updateReadyToInstall();
586 LAMEXP_DELETE(updateDialog);
587 return bReadyToInstall;
590 void MainWindow::refreshFavorites(void)
592 QList<QAction*> folderList = m_outputFolderFavoritesMenu->actions();
593 QStringList favorites = m_settings->favoriteOutputFolders().split("|", QString::SkipEmptyParts);
594 while(favorites.count() > 6) favorites.removeFirst();
596 while(!folderList.isEmpty())
598 QAction *currentItem = folderList.takeFirst();
599 if(currentItem->isSeparator()) break;
600 m_outputFolderFavoritesMenu->removeAction(currentItem);
601 LAMEXP_DELETE(currentItem);
604 QAction *lastItem = m_outputFolderFavoritesMenu->actions().first();
606 while(!favorites.isEmpty())
608 QString path = favorites.takeLast();
609 if(QDir(path).exists())
611 QAction *action = new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path), this);
612 action->setData(path);
613 m_outputFolderFavoritesMenu->insertAction(lastItem, action);
614 connect(action, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
620 ////////////////////////////////////////////////////////////
622 ////////////////////////////////////////////////////////////
625 * Window is about to be shown
627 void MainWindow::showEvent(QShowEvent *event)
630 m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height());
631 sourceModelChanged();
633 if(!event->spontaneous())
635 tabWidget->setCurrentIndex(0);
640 m_firstTimeShown = false;
641 QTimer::singleShot(0, this, SLOT(windowShown()));
645 if(m_settings->dropBoxWidgetEnabled())
647 m_dropBox->setVisible(true);
653 * Re-translate the UI
655 void MainWindow::changeEvent(QEvent *e)
657 if(e->type() == QEvent::LanguageChange)
659 int comboBoxIndex[5];
661 //Backup combobox indices, as retranslateUi() resets
662 comboBoxIndex[0] = comboBoxMP3ChannelMode->currentIndex();
663 comboBoxIndex[1] = comboBoxSamplingRate->currentIndex();
664 comboBoxIndex[2] = comboBoxAACProfile->currentIndex();
665 comboBoxIndex[3] = comboBoxAftenCodingMode->currentIndex();
666 comboBoxIndex[4] = comboBoxAftenDRCMode->currentIndex();
668 //Re-translate from UIC
669 Ui::MainWindow::retranslateUi(this);
671 //Restore combobox indices
672 comboBoxMP3ChannelMode->setCurrentIndex(comboBoxIndex[0]);
673 comboBoxSamplingRate->setCurrentIndex(comboBoxIndex[1]);
674 comboBoxAACProfile->setCurrentIndex(comboBoxIndex[2]);
675 comboBoxAftenCodingMode->setCurrentIndex(comboBoxIndex[3]);
676 comboBoxAftenDRCMode->setCurrentIndex(comboBoxIndex[4]);
678 //Update the window title
681 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
683 else if(lamexp_version_demo())
685 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
688 //Manually re-translate widgets that UIC doesn't handle
689 m_dropNoteLabel->setText(QString("» %1 «").arg(tr("You can drop in audio files here!")));
690 m_showDetailsContextAction->setText(tr("Show Details"));
691 m_previewContextAction->setText(tr("Open File in External Application"));
692 m_findFileContextAction->setText(tr("Browse File Location"));
693 m_showFolderContextAction->setText(tr("Browse Selected Folder"));
694 m_addFavoriteFolderAction->setText(tr("Bookmark Current Output Folder"));
697 m_metaInfoModel->clearData();
698 m_metaInfoModel->setData(m_metaInfoModel->index(4, 1), m_settings->metaInfoPosition());
699 updateEncoder(m_settings->compressionEncoder());
700 updateLameAlgoQuality(sliderLameAlgoQuality->value());
701 updateMaximumInstances(sliderMaxInstances->value());
702 renameOutputPatternChanged(lineEditRenamePattern->text());
704 //Re-install shell integration
705 if(m_settings->shellIntegrationEnabled())
707 ShellIntegration::install();
710 //Force resize, if needed
711 tabPageChanged(tabWidget->currentIndex());
716 * File dragged over window
718 void MainWindow::dragEnterEvent(QDragEnterEvent *event)
720 QStringList formats = event->mimeData()->formats();
722 if(formats.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive) && formats.contains("text/uri-list", Qt::CaseInsensitive))
724 event->acceptProposedAction();
729 * File dropped onto window
731 void MainWindow::dropEvent(QDropEvent *event)
735 QStringList droppedFiles;
736 QList<QUrl> urls = event->mimeData()->urls();
738 while(!urls.isEmpty())
740 QUrl currentUrl = urls.takeFirst();
741 QFileInfo file(currentUrl.toLocalFile());
748 qDebug64("Dropped File: %1", file.canonicalFilePath());
749 droppedFiles << file.canonicalFilePath();
754 qDebug64("Dropped Folder: %1", file.canonicalFilePath());
755 QList<QFileInfo> list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Files | QDir::NoSymLinks);
758 for(int j = 0; j < list.count(); j++)
760 droppedFiles << list.at(j).canonicalFilePath();
765 list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
766 for(int j = 0; j < list.count(); j++)
768 qDebug64("Descending to Folder: %1", list.at(j).canonicalFilePath());
769 urls.prepend(QUrl::fromLocalFile(list.at(j).canonicalFilePath()));
775 if(!droppedFiles.isEmpty())
777 addFilesDelayed(droppedFiles, true);
782 * Window tries to close
784 void MainWindow::closeEvent(QCloseEvent *event)
786 if(m_banner->isVisible() || m_delayedFileTimer->isActive())
788 MessageBeep(MB_ICONEXCLAMATION);
801 void MainWindow::resizeEvent(QResizeEvent *event)
803 QMainWindow::resizeEvent(event);
804 m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height());
810 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
812 if(obj == m_fileSystemModel)
814 if(QApplication::overrideCursor() == NULL)
816 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
817 QTimer::singleShot(250, this, SLOT(restoreCursor()));
820 else if(obj == outputFolderView)
822 switch(event->type())
826 case QEvent::KeyPress:
827 case QEvent::KeyRelease:
828 case QEvent::FocusIn:
829 case QEvent::FocusOut:
830 case QEvent::TouchEnd:
831 outputFolderViewClicked(outputFolderView->currentIndex());
835 else if(obj == outputFolderLabel)
837 switch(event->type())
839 case QEvent::MouseButtonPress:
840 if(dynamic_cast<QMouseEvent*>(event)->button() == Qt::LeftButton)
842 QDesktopServices::openUrl(QString("file:///%1").arg(outputFolderLabel->text()));
846 outputFolderLabel->setForegroundRole(QPalette::Link);
849 outputFolderLabel->setForegroundRole(QPalette::WindowText);
853 else if(obj == outputFoldersFovoritesLabel)
855 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
856 QPoint pos = (mouseEvent != NULL) ? mouseEvent->pos() : QPoint();
857 QWidget *sender = dynamic_cast<QLabel*>(obj);
859 switch(event->type())
862 outputFoldersFovoritesLabel->setFrameShadow(QFrame::Raised);
864 case QEvent::MouseButtonPress:
865 outputFoldersFovoritesLabel->setFrameShadow(QFrame::Sunken);
867 case QEvent::MouseButtonRelease:
868 outputFoldersFovoritesLabel->setFrameShadow(QFrame::Raised);
869 if(sender && mouseEvent)
871 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0 && mouseEvent->button() != Qt::MidButton)
873 m_outputFolderFavoritesMenu->popup(sender->mapToGlobal(pos));
878 outputFoldersFovoritesLabel->setFrameShadow(QFrame::Plain);
886 ////////////////////////////////////////////////////////////
888 ////////////////////////////////////////////////////////////
890 // =========================================================
892 // =========================================================
897 void MainWindow::windowShown(void)
899 QStringList arguments = QApplication::arguments();
902 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 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)
1573 QString selectedCueFile;
1575 if(USE_NATIVE_FILE_DIALOG)
1577 selectedCueFile = QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1581 QFileDialog dialog(this, tr("Open Cue Sheet"));
1582 dialog.setFileMode(QFileDialog::ExistingFile);
1583 dialog.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1584 dialog.setDirectory(m_settings->mostRecentInputPath());
1587 selectedCueFile = dialog.selectedFiles().first();
1591 if(!selectedCueFile.isEmpty())
1593 m_settings->mostRecentInputPath(QFileInfo(selectedCueFile).canonicalPath());
1594 CueImportDialog *cueImporter = new CueImportDialog(this, m_fileListModel, selectedCueFile);
1595 cueImporter->exec();
1596 LAMEXP_DELETE(cueImporter);
1602 * Show the "drop box" widget
1604 void MainWindow::showDropBoxWidgetActionTriggered(bool checked)
1606 m_settings->dropBoxWidgetEnabled(true);
1608 if(!m_dropBox->isVisible())
1613 lamexp_blink_window(m_dropBox);
1617 * Check for beta (pre-release) updates
1619 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked)
1621 bool checkUpdatesNow = false;
1625 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))
1627 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")))
1629 checkUpdatesNow = true;
1631 m_settings->autoUpdateCheckBeta(true);
1635 m_settings->autoUpdateCheckBeta(false);
1640 QMessageBox::information(this, tr("Beta Updates"), tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on."));
1641 m_settings->autoUpdateCheckBeta(false);
1644 actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta());
1648 if(checkForUpdates())
1650 QApplication::quit();
1656 * Disable shell integration action
1658 void MainWindow::disableShellIntegrationActionTriggered(bool checked)
1662 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))
1664 ShellIntegration::remove();
1665 QMessageBox::information(this, tr("Shell Integration"), tr("The LameXP shell integration has been disabled."));
1666 m_settings->shellIntegrationEnabled(false);
1670 m_settings->shellIntegrationEnabled(true);
1675 ShellIntegration::install();
1676 QMessageBox::information(this, tr("Shell Integration"), tr("The LameXP shell integration has been re-enabled."));
1677 m_settings->shellIntegrationEnabled(true);
1680 actionDisableShellIntegration->setChecked(!m_settings->shellIntegrationEnabled());
1682 if(lamexp_portable_mode() && actionDisableShellIntegration->isChecked())
1684 actionDisableShellIntegration->setEnabled(false);
1688 // =========================================================
1690 // =========================================================
1693 * Visit homepage action
1695 void MainWindow::visitHomepageActionActivated(void)
1697 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
1699 if(action->data().isValid() && (action->data().type() == QVariant::String))
1701 QDesktopServices::openUrl(QUrl(action->data().toString()));
1709 void MainWindow::documentActionActivated(void)
1711 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
1713 if(action->data().isValid() && (action->data().type() == QVariant::String))
1715 QFileInfo document(action->data().toString());
1716 QFileInfo resource(QString(":/doc/%1.html").arg(document.baseName()));
1717 if(document.exists() && document.isFile() && (document.size() == resource.size()))
1719 QDesktopServices::openUrl(QUrl::fromLocalFile(document.canonicalFilePath()));
1723 QFile source(resource.filePath());
1724 QFile output(QString("%1/%2.%3.html").arg(lamexp_temp_folder2(), document.baseName(), lamexp_rand_str().left(8)));
1725 if(source.open(QIODevice::ReadOnly) && output.open(QIODevice::ReadWrite))
1727 output.write(source.readAll());
1728 action->setData(output.fileName());
1731 QDesktopServices::openUrl(QUrl::fromLocalFile(output.fileName()));
1739 * Check for updates action
1741 void MainWindow::checkUpdatesActionActivated(void)
1748 bFlag = checkForUpdates();
1753 QApplication::quit();
1757 // =========================================================
1758 // Source file slots
1759 // =========================================================
1762 * Add file(s) button
1764 void MainWindow::addFilesButtonClicked(void)
1770 if(USE_NATIVE_FILE_DIALOG)
1772 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
1773 QStringList selectedFiles = QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings->mostRecentInputPath(), fileTypeFilters.join(";;"));
1774 if(!selectedFiles.isEmpty())
1776 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
1777 addFiles(selectedFiles);
1782 QFileDialog dialog(this, tr("Add file(s)"));
1783 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
1784 dialog.setFileMode(QFileDialog::ExistingFiles);
1785 dialog.setNameFilter(fileTypeFilters.join(";;"));
1786 dialog.setDirectory(m_settings->mostRecentInputPath());
1789 QStringList selectedFiles = dialog.selectedFiles();
1790 if(!selectedFiles.isEmpty())
1792 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
1793 addFiles(selectedFiles);
1801 * Open folder action
1803 void MainWindow::openFolderActionActivated(void)
1806 QString selectedFolder;
1808 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
1812 if(USE_NATIVE_FILE_DIALOG)
1814 selectedFolder = QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings->mostRecentInputPath());
1818 QFileDialog dialog(this, tr("Add Folder"));
1819 dialog.setFileMode(QFileDialog::DirectoryOnly);
1820 dialog.setDirectory(m_settings->mostRecentInputPath());
1823 selectedFolder = dialog.selectedFiles().first();
1827 if(!selectedFolder.isEmpty())
1829 m_settings->mostRecentInputPath(QDir(selectedFolder).canonicalPath());
1830 addFolder(selectedFolder, action->data().toBool());
1837 * Remove file button
1839 void MainWindow::removeFileButtonClicked(void)
1841 if(sourceFileView->currentIndex().isValid())
1843 int iRow = sourceFileView->currentIndex().row();
1844 m_fileListModel->removeFile(sourceFileView->currentIndex());
1845 sourceFileView->selectRow(iRow < m_fileListModel->rowCount() ? iRow : m_fileListModel->rowCount()-1);
1850 * Clear files button
1852 void MainWindow::clearFilesButtonClicked(void)
1854 m_fileListModel->clearFiles();
1858 * Move file up button
1860 void MainWindow::fileUpButtonClicked(void)
1862 if(sourceFileView->currentIndex().isValid())
1864 int iRow = sourceFileView->currentIndex().row() - 1;
1865 m_fileListModel->moveFile(sourceFileView->currentIndex(), -1);
1866 sourceFileView->selectRow(iRow >= 0 ? iRow : 0);
1871 * Move file down button
1873 void MainWindow::fileDownButtonClicked(void)
1875 if(sourceFileView->currentIndex().isValid())
1877 int iRow = sourceFileView->currentIndex().row() + 1;
1878 m_fileListModel->moveFile(sourceFileView->currentIndex(), 1);
1879 sourceFileView->selectRow(iRow < m_fileListModel->rowCount() ? iRow : m_fileListModel->rowCount()-1);
1884 * Show details button
1886 void MainWindow::showDetailsButtonClicked(void)
1891 MetaInfoDialog *metaInfoDialog = new MetaInfoDialog(this);
1892 QModelIndex index = sourceFileView->currentIndex();
1894 while(index.isValid())
1898 index = m_fileListModel->index(index.row() + 1, index.column());
1899 sourceFileView->selectRow(index.row());
1903 index = m_fileListModel->index(index.row() - 1, index.column());
1904 sourceFileView->selectRow(index.row());
1907 AudioFileModel &file = (*m_fileListModel)[index];
1910 iResult = metaInfoDialog->exec(file, index.row() > 0, index.row() < m_fileListModel->rowCount() - 1);
1913 if(iResult == INT_MAX)
1915 m_metaInfoModel->assignInfoFrom(file);
1916 tabWidget->setCurrentIndex(tabWidget->indexOf(tabMetaData));
1923 LAMEXP_DELETE(metaInfoDialog);
1927 * Show context menu for source files
1929 void MainWindow::sourceFilesContextMenu(const QPoint &pos)
1931 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
1932 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
1936 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
1938 m_sourceFilesContextMenu->popup(sender->mapToGlobal(pos));
1944 * Scrollbar of source files moved
1946 void MainWindow::sourceFilesScrollbarMoved(int)
1948 sourceFileView->resizeColumnToContents(0);
1952 * Open selected file in external player
1954 void MainWindow::previewContextActionTriggered(void)
1956 const static char *appNames[3] = {"smplayer_portable.exe", "smplayer.exe", "mplayer.exe"};
1957 const static wchar_t *registryKey = L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{DB9E4EAB-2717-499F-8D56-4CC8A644AB60}";
1959 QModelIndex index = sourceFileView->currentIndex();
1960 if(!index.isValid())
1965 QString mplayerPath;
1966 HKEY registryKeyHandle;
1968 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryKey, 0, KEY_READ, ®istryKeyHandle) == ERROR_SUCCESS)
1970 wchar_t Buffer[4096];
1971 DWORD BuffSize = sizeof(wchar_t*) * 4096;
1972 if(RegQueryValueExW(registryKeyHandle, L"InstallLocation", 0, 0, reinterpret_cast<BYTE*>(Buffer), &BuffSize) == ERROR_SUCCESS)
1974 mplayerPath = QString::fromUtf16(reinterpret_cast<const unsigned short*>(Buffer));
1978 if(!mplayerPath.isEmpty())
1980 QDir mplayerDir(mplayerPath);
1981 if(mplayerDir.exists())
1983 for(int i = 0; i < 3; i++)
1985 if(mplayerDir.exists(appNames[i]))
1987 QProcess::startDetached(mplayerDir.absoluteFilePath(appNames[i]), QStringList() << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
1994 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel->getFile(index).filePath()));
1998 * Find selected file in explorer
2000 void MainWindow::findFileContextActionTriggered(void)
2002 QModelIndex index = sourceFileView->currentIndex();
2005 QString systemRootPath;
2007 QDir systemRoot(lamexp_known_folder(lamexp_folder_systemfolder));
2008 if(systemRoot.exists() && systemRoot.cdUp())
2010 systemRootPath = systemRoot.canonicalPath();
2013 if(!systemRootPath.isEmpty())
2015 QFileInfo explorer(QString("%1/explorer.exe").arg(systemRootPath));
2016 if(explorer.exists() && explorer.isFile())
2018 QProcess::execute(explorer.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
2024 qWarning("SystemRoot directory could not be detected!");
2030 * Add all pending files
2032 void MainWindow::handleDelayedFiles(void)
2034 m_delayedFileTimer->stop();
2036 if(m_delayedFileList->isEmpty())
2041 if(m_banner->isVisible())
2043 m_delayedFileTimer->start(5000);
2047 QStringList selectedFiles;
2048 tabWidget->setCurrentIndex(0);
2050 while(!m_delayedFileList->isEmpty())
2052 QFileInfo currentFile = QFileInfo(m_delayedFileList->takeFirst());
2053 if(!currentFile.exists() || !currentFile.isFile())
2057 selectedFiles << currentFile.canonicalFilePath();
2060 addFiles(selectedFiles);
2064 * Show or hide Drag'n'Drop notice after model reset
2066 void MainWindow::sourceModelChanged(void)
2068 m_dropNoteLabel->setVisible(m_fileListModel->rowCount() <= 0);
2071 // =========================================================
2072 // Output folder slots
2073 // =========================================================
2076 * Output folder changed (mouse clicked)
2078 void MainWindow::outputFolderViewClicked(const QModelIndex &index)
2080 if(outputFolderView->currentIndex() != index)
2082 outputFolderView->setCurrentIndex(index);
2084 QString selectedDir = m_fileSystemModel->filePath(index);
2085 if(selectedDir.length() < 3) selectedDir.append(QDir::separator());
2086 outputFolderLabel->setText(QDir::toNativeSeparators(selectedDir));
2087 m_settings->outputDir(selectedDir);
2091 * Output folder changed (mouse moved)
2093 void MainWindow::outputFolderViewMoved(const QModelIndex &index)
2095 if(QApplication::mouseButtons() & Qt::LeftButton)
2097 outputFolderViewClicked(index);
2102 * Goto desktop button
2104 void MainWindow::gotoDesktopButtonClicked(void)
2106 QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
2108 if(!desktopPath.isEmpty() && QDir(desktopPath).exists())
2110 outputFolderView->setCurrentIndex(m_fileSystemModel->index(desktopPath));
2111 outputFolderViewClicked(outputFolderView->currentIndex());
2112 outputFolderView->setFocus();
2116 buttonGotoDesktop->setEnabled(false);
2121 * Goto home folder button
2123 void MainWindow::gotoHomeFolderButtonClicked(void)
2125 QString homePath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
2127 if(!homePath.isEmpty() && QDir(homePath).exists())
2129 outputFolderView->setCurrentIndex(m_fileSystemModel->index(homePath));
2130 outputFolderViewClicked(outputFolderView->currentIndex());
2131 outputFolderView->setFocus();
2135 buttonGotoHome->setEnabled(false);
2140 * Goto music folder button
2142 void MainWindow::gotoMusicFolderButtonClicked(void)
2144 QString musicPath = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
2146 if(!musicPath.isEmpty() && QDir(musicPath).exists())
2148 outputFolderView->setCurrentIndex(m_fileSystemModel->index(musicPath));
2149 outputFolderViewClicked(outputFolderView->currentIndex());
2150 outputFolderView->setFocus();
2154 buttonGotoMusic->setEnabled(false);
2159 * Goto music favorite output folder
2161 void MainWindow::gotoFavoriteFolder(void)
2163 QAction *item = dynamic_cast<QAction*>(QObject::sender());
2167 QDir path(item->data().toString());
2170 outputFolderView->setCurrentIndex(m_fileSystemModel->index(path.canonicalPath()));
2171 outputFolderViewClicked(outputFolderView->currentIndex());
2172 outputFolderView->setFocus();
2176 MessageBeep(MB_ICONERROR);
2177 m_outputFolderFavoritesMenu->removeAction(item);
2178 item->deleteLater();
2184 * Make folder button
2186 void MainWindow::makeFolderButtonClicked(void)
2190 QDir basePath(m_fileSystemModel->fileInfo(outputFolderView->currentIndex()).absoluteFilePath());
2191 QString suggestedName = tr("New Folder");
2193 if(!m_metaData->fileArtist().isEmpty() && !m_metaData->fileAlbum().isEmpty())
2195 suggestedName = QString("%1 - %2").arg(m_metaData->fileArtist(), m_metaData->fileAlbum());
2197 else if(!m_metaData->fileArtist().isEmpty())
2199 suggestedName = m_metaData->fileArtist();
2201 else if(!m_metaData->fileAlbum().isEmpty())
2203 suggestedName = m_metaData->fileAlbum();
2207 for(int i = 0; i < m_fileListModel->rowCount(); i++)
2209 AudioFileModel audioFile = m_fileListModel->getFile(m_fileListModel->index(i, 0));
2210 if(!audioFile.fileAlbum().isEmpty() || !audioFile.fileArtist().isEmpty())
2212 if(!audioFile.fileArtist().isEmpty() && !audioFile.fileAlbum().isEmpty())
2214 suggestedName = QString("%1 - %2").arg(audioFile.fileArtist(), audioFile.fileAlbum());
2216 else if(!audioFile.fileArtist().isEmpty())
2218 suggestedName = audioFile.fileArtist();
2220 else if(!audioFile.fileAlbum().isEmpty())
2222 suggestedName = audioFile.fileAlbum();
2229 suggestedName = lamexp_clean_filename(suggestedName);
2233 bool bApplied = false;
2234 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();
2238 folderName = lamexp_clean_filepath(folderName.simplified());
2240 if(folderName.isEmpty())
2242 MessageBeep(MB_ICONERROR);
2247 QString newFolder = folderName;
2249 while(basePath.exists(newFolder))
2251 newFolder = QString(folderName).append(QString().sprintf(" (%d)", ++i));
2254 if(basePath.mkpath(newFolder))
2256 QDir createdDir = basePath;
2257 if(createdDir.cd(newFolder))
2259 outputFolderView->setCurrentIndex(m_fileSystemModel->index(createdDir.canonicalPath()));
2260 outputFolderViewClicked(outputFolderView->currentIndex());
2261 outputFolderView->setFocus();
2266 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!")));
2274 * Output to source dir changed
2276 void MainWindow::saveToSourceFolderChanged(void)
2278 m_settings->outputToSourceDir(saveToSourceFolderCheckBox->isChecked());
2282 * Prepend relative source file path to output file name changed
2284 void MainWindow::prependRelativePathChanged(void)
2286 m_settings->prependRelativeSourcePath(prependRelativePathCheckBox->isChecked());
2290 * Show context menu for output folder
2292 void MainWindow::outputFolderContextMenu(const QPoint &pos)
2294 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
2295 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
2297 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
2299 m_outputFolderContextMenu->popup(sender->mapToGlobal(pos));
2304 * Show selected folder in explorer
2306 void MainWindow::showFolderContextActionTriggered(void)
2308 QDesktopServices::openUrl(QUrl::fromLocalFile(m_fileSystemModel->filePath(outputFolderView->currentIndex())));
2312 * Add current folder to favorites
2314 void MainWindow::addFavoriteFolderActionTriggered(void)
2316 QString path = m_fileSystemModel->filePath(outputFolderView->currentIndex());
2317 QStringList favorites = m_settings->favoriteOutputFolders().split("|", QString::SkipEmptyParts);
2319 if(!favorites.contains(path, Qt::CaseInsensitive))
2321 favorites.append(path);
2322 while(favorites.count() > 6) favorites.removeFirst();
2326 MessageBeep(MB_ICONWARNING);
2329 m_settings->favoriteOutputFolders(favorites.join("|"));
2334 * Initialize file system model
2336 void MainWindow::initOutputFolderModel(void)
2338 QModelIndex previousIndex = outputFolderView->currentIndex();
2339 m_fileSystemModel->setRootPath(m_fileSystemModel->rootPath());
2340 QApplication::processEvents();
2341 outputFolderView->reset();
2342 outputFolderView->setCurrentIndex(previousIndex);
2343 m_OutputFolderViewInitialized = true;
2346 // =========================================================
2347 // Metadata tab slots
2348 // =========================================================
2351 * Edit meta button clicked
2353 void MainWindow::editMetaButtonClicked(void)
2357 const QModelIndex index = metaDataView->currentIndex();
2361 m_metaInfoModel->editItem(index, this);
2363 if(index.row() == 4)
2365 m_settings->metaInfoPosition(m_metaData->filePosition());
2371 * Reset meta button clicked
2373 void MainWindow::clearMetaButtonClicked(void)
2376 m_metaInfoModel->clearData();
2380 * Meta tags enabled changed
2382 void MainWindow::metaTagsEnabledChanged(void)
2384 m_settings->writeMetaTags(writeMetaDataCheckBox->isChecked());
2388 * Playlist enabled changed
2390 void MainWindow::playlistEnabledChanged(void)
2392 m_settings->createPlaylist(generatePlaylistCheckBox->isChecked());
2395 // =========================================================
2396 // Compression tab slots
2397 // =========================================================
2402 void MainWindow::updateEncoder(int id)
2404 m_settings->compressionEncoder(id);
2406 switch(m_settings->compressionEncoder())
2408 case SettingsModel::VorbisEncoder:
2409 radioButtonModeQuality->setEnabled(true);
2410 radioButtonModeAverageBitrate->setEnabled(true);
2411 radioButtonConstBitrate->setEnabled(false);
2412 if(radioButtonConstBitrate->isChecked()) radioButtonModeQuality->setChecked(true);
2413 sliderBitrate->setEnabled(true);
2415 case SettingsModel::AC3Encoder:
2416 radioButtonModeQuality->setEnabled(true);
2417 radioButtonModeQuality->setChecked(true);
2418 radioButtonModeAverageBitrate->setEnabled(false);
2419 radioButtonConstBitrate->setEnabled(true);
2420 sliderBitrate->setEnabled(true);
2422 case SettingsModel::FLACEncoder:
2423 radioButtonModeQuality->setEnabled(false);
2424 radioButtonModeQuality->setChecked(true);
2425 radioButtonModeAverageBitrate->setEnabled(false);
2426 radioButtonConstBitrate->setEnabled(false);
2427 sliderBitrate->setEnabled(true);
2429 case SettingsModel::PCMEncoder:
2430 radioButtonModeQuality->setEnabled(false);
2431 radioButtonModeQuality->setChecked(true);
2432 radioButtonModeAverageBitrate->setEnabled(false);
2433 radioButtonConstBitrate->setEnabled(false);
2434 sliderBitrate->setEnabled(false);
2436 case SettingsModel::AACEncoder:
2437 radioButtonModeQuality->setEnabled(true);
2438 radioButtonModeAverageBitrate->setEnabled(!m_fhgEncoderAvailable);
2439 if(m_fhgEncoderAvailable && radioButtonModeAverageBitrate->isChecked()) radioButtonConstBitrate->setChecked(true);
2440 radioButtonConstBitrate->setEnabled(true);
2441 sliderBitrate->setEnabled(true);
2444 radioButtonModeQuality->setEnabled(true);
2445 radioButtonModeAverageBitrate->setEnabled(true);
2446 radioButtonConstBitrate->setEnabled(true);
2447 sliderBitrate->setEnabled(true);
2451 updateRCMode(m_modeButtonGroup->checkedId());
2455 * Update rate-control mode
2457 void MainWindow::updateRCMode(int id)
2459 m_settings->compressionRCMode(id);
2461 switch(m_settings->compressionEncoder())
2463 case SettingsModel::MP3Encoder:
2464 switch(m_settings->compressionRCMode())
2466 case SettingsModel::VBRMode:
2467 sliderBitrate->setMinimum(0);
2468 sliderBitrate->setMaximum(9);
2471 sliderBitrate->setMinimum(0);
2472 sliderBitrate->setMaximum(13);
2476 case SettingsModel::VorbisEncoder:
2477 switch(m_settings->compressionRCMode())
2479 case SettingsModel::VBRMode:
2480 sliderBitrate->setMinimum(-2);
2481 sliderBitrate->setMaximum(10);
2484 sliderBitrate->setMinimum(4);
2485 sliderBitrate->setMaximum(63);
2489 case SettingsModel::AC3Encoder:
2490 switch(m_settings->compressionRCMode())
2492 case SettingsModel::VBRMode:
2493 sliderBitrate->setMinimum(0);
2494 sliderBitrate->setMaximum(16);
2497 sliderBitrate->setMinimum(0);
2498 sliderBitrate->setMaximum(18);
2502 case SettingsModel::AACEncoder:
2503 switch(m_settings->compressionRCMode())
2505 case SettingsModel::VBRMode:
2506 sliderBitrate->setMinimum(0);
2507 sliderBitrate->setMaximum(20);
2510 sliderBitrate->setMinimum(4);
2511 sliderBitrate->setMaximum(63);
2515 case SettingsModel::FLACEncoder:
2516 sliderBitrate->setMinimum(0);
2517 sliderBitrate->setMaximum(8);
2519 case SettingsModel::PCMEncoder:
2520 sliderBitrate->setMinimum(0);
2521 sliderBitrate->setMaximum(2);
2522 sliderBitrate->setValue(1);
2525 sliderBitrate->setMinimum(0);
2526 sliderBitrate->setMaximum(0);
2530 updateBitrate(sliderBitrate->value());
2536 void MainWindow::updateBitrate(int value)
2538 m_settings->compressionBitrate(value);
2540 switch(m_settings->compressionRCMode())
2542 case SettingsModel::VBRMode:
2543 switch(m_settings->compressionEncoder())
2545 case SettingsModel::MP3Encoder:
2546 labelBitrate->setText(tr("Quality Level %1").arg(9 - value));
2548 case SettingsModel::VorbisEncoder:
2549 labelBitrate->setText(tr("Quality Level %1").arg(value));
2551 case SettingsModel::AACEncoder:
2552 labelBitrate->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", static_cast<double>(value * 5) / 100.0)));
2554 case SettingsModel::FLACEncoder:
2555 labelBitrate->setText(tr("Compression %1").arg(value));
2557 case SettingsModel::AC3Encoder:
2558 labelBitrate->setText(tr("Quality Level %1").arg(min(1024, max(0, value * 64))));
2560 case SettingsModel::PCMEncoder:
2561 labelBitrate->setText(tr("Uncompressed"));
2564 labelBitrate->setText(QString::number(value));
2568 case SettingsModel::ABRMode:
2569 switch(m_settings->compressionEncoder())
2571 case SettingsModel::MP3Encoder:
2572 labelBitrate->setText(QString("≈ %1 kbps").arg(SettingsModel::mp3Bitrates[value]));
2574 case SettingsModel::FLACEncoder:
2575 labelBitrate->setText(tr("Compression %1").arg(value));
2577 case SettingsModel::AC3Encoder:
2578 labelBitrate->setText(QString("≈ %1 kbps").arg(SettingsModel::ac3Bitrates[value]));
2580 case SettingsModel::PCMEncoder:
2581 labelBitrate->setText(tr("Uncompressed"));
2584 labelBitrate->setText(QString("≈ %1 kbps").arg(min(500, value * 8)));
2589 switch(m_settings->compressionEncoder())
2591 case SettingsModel::MP3Encoder:
2592 labelBitrate->setText(QString("%1 kbps").arg(SettingsModel::mp3Bitrates[value]));
2594 case SettingsModel::FLACEncoder:
2595 labelBitrate->setText(tr("Compression %1").arg(value));
2597 case SettingsModel::AC3Encoder:
2598 labelBitrate->setText(QString("%1 kbps").arg(SettingsModel::ac3Bitrates[value]));
2600 case SettingsModel::PCMEncoder:
2601 labelBitrate->setText(tr("Uncompressed"));
2604 labelBitrate->setText(QString("%1 kbps").arg(min(500, value * 8)));
2611 // =========================================================
2612 // Advanced option slots
2613 // =========================================================
2616 * Lame algorithm quality changed
2618 void MainWindow::updateLameAlgoQuality(int value)
2625 text = tr("Best Quality (Very Slow)");
2628 text = tr("High Quality (Recommended)");
2631 text = tr("Average Quality (Default)");
2634 text = tr("Low Quality (Fast)");
2637 text = tr("Poor Quality (Very Fast)");
2643 m_settings->lameAlgoQuality(value);
2644 labelLameAlgoQuality->setText(text);
2647 bool warning = (value == 0), notice = (value == 4);
2648 labelLameAlgoQualityWarning->setVisible(warning);
2649 labelLameAlgoQualityWarningIcon->setVisible(warning);
2650 labelLameAlgoQualityNotice->setVisible(notice);
2651 labelLameAlgoQualityNoticeIcon->setVisible(notice);
2652 labelLameAlgoQualitySpacer->setVisible(warning || notice);
2656 * Bitrate management endabled/disabled
2658 void MainWindow::bitrateManagementEnabledChanged(bool checked)
2660 m_settings->bitrateManagementEnabled(checked);
2664 * Minimum bitrate has changed
2666 void MainWindow::bitrateManagementMinChanged(int value)
2668 if(value > spinBoxBitrateManagementMax->value())
2670 spinBoxBitrateManagementMin->setValue(spinBoxBitrateManagementMax->value());
2671 m_settings->bitrateManagementMinRate(spinBoxBitrateManagementMax->value());
2675 m_settings->bitrateManagementMinRate(value);
2680 * Maximum bitrate has changed
2682 void MainWindow::bitrateManagementMaxChanged(int value)
2684 if(value < spinBoxBitrateManagementMin->value())
2686 spinBoxBitrateManagementMax->setValue(spinBoxBitrateManagementMin->value());
2687 m_settings->bitrateManagementMaxRate(spinBoxBitrateManagementMin->value());
2691 m_settings->bitrateManagementMaxRate(value);
2696 * Channel mode has changed
2698 void MainWindow::channelModeChanged(int value)
2700 if(value >= 0) m_settings->lameChannelMode(value);
2704 * Sampling rate has changed
2706 void MainWindow::samplingRateChanged(int value)
2708 if(value >= 0) m_settings->samplingRate(value);
2712 * Nero AAC 2-Pass mode changed
2714 void MainWindow::neroAAC2PassChanged(bool checked)
2716 m_settings->neroAACEnable2Pass(checked);
2720 * Nero AAC profile mode changed
2722 void MainWindow::neroAACProfileChanged(int value)
2724 if(value >= 0) m_settings->aacEncProfile(value);
2728 * Aften audio coding mode changed
2730 void MainWindow::aftenCodingModeChanged(int value)
2732 if(value >= 0) m_settings->aftenAudioCodingMode(value);
2736 * Aften DRC mode changed
2738 void MainWindow::aftenDRCModeChanged(int value)
2740 if(value >= 0) m_settings->aftenDynamicRangeCompression(value);
2744 * Aften exponent search size changed
2746 void MainWindow::aftenSearchSizeChanged(int value)
2748 if(value >= 0) m_settings->aftenExponentSearchSize(value);
2752 * Aften fast bit allocation changed
2754 void MainWindow::aftenFastAllocationChanged(bool checked)
2756 m_settings->aftenFastBitAllocation(checked);
2760 * Normalization filter enabled changed
2762 void MainWindow::normalizationEnabledChanged(bool checked)
2764 m_settings->normalizationFilterEnabled(checked);
2768 * Normalization max. volume changed
2770 void MainWindow::normalizationMaxVolumeChanged(double value)
2772 m_settings->normalizationFilterMaxVolume(static_cast<int>(value * 100.0));
2776 * Tone adjustment has changed (Bass)
2778 void MainWindow::toneAdjustBassChanged(double value)
2780 m_settings->toneAdjustBass(static_cast<int>(value * 100.0));
2781 spinBoxToneAdjustBass->setPrefix((value > 0) ? "+" : QString());
2785 * Tone adjustment has changed (Treble)
2787 void MainWindow::toneAdjustTrebleChanged(double value)
2789 m_settings->toneAdjustTreble(static_cast<int>(value * 100.0));
2790 spinBoxToneAdjustTreble->setPrefix((value > 0) ? "+" : QString());
2794 * Tone adjustment has been reset
2796 void MainWindow::toneAdjustTrebleReset(void)
2798 spinBoxToneAdjustBass->setValue(m_settings->toneAdjustBassDefault());
2799 spinBoxToneAdjustTreble->setValue(m_settings->toneAdjustTrebleDefault());
2800 toneAdjustBassChanged(spinBoxToneAdjustBass->value());
2801 toneAdjustTrebleChanged(spinBoxToneAdjustTreble->value());
2805 * Custom encoder parameters changed
2807 void MainWindow::customParamsChanged(void)
2809 lineEditCustomParamLAME->setText(lineEditCustomParamLAME->text().simplified());
2810 lineEditCustomParamOggEnc->setText(lineEditCustomParamOggEnc->text().simplified());
2811 lineEditCustomParamNeroAAC->setText(lineEditCustomParamNeroAAC->text().simplified());
2812 lineEditCustomParamFLAC->setText(lineEditCustomParamFLAC->text().simplified());
2813 lineEditCustomParamAften->setText(lineEditCustomParamAften->text().simplified());
2815 bool customParamsUsed = false;
2816 if(!lineEditCustomParamLAME->text().isEmpty()) customParamsUsed = true;
2817 if(!lineEditCustomParamOggEnc->text().isEmpty()) customParamsUsed = true;
2818 if(!lineEditCustomParamNeroAAC->text().isEmpty()) customParamsUsed = true;
2819 if(!lineEditCustomParamFLAC->text().isEmpty()) customParamsUsed = true;
2820 if(!lineEditCustomParamAften->text().isEmpty()) customParamsUsed = true;
2822 labelCustomParamsIcon->setVisible(customParamsUsed);
2823 labelCustomParamsText->setVisible(customParamsUsed);
2824 labelCustomParamsSpacer->setVisible(customParamsUsed);
2826 m_settings->customParametersLAME(lineEditCustomParamLAME->text());
2827 m_settings->customParametersOggEnc(lineEditCustomParamOggEnc->text());
2828 m_settings->customParametersAacEnc(lineEditCustomParamNeroAAC->text());
2829 m_settings->customParametersFLAC(lineEditCustomParamFLAC->text());
2830 m_settings->customParametersAften(lineEditCustomParamAften->text());
2835 * Rename output files enabled changed
2837 void MainWindow::renameOutputEnabledChanged(bool checked)
2839 m_settings->renameOutputFilesEnabled(checked);
2843 * Rename output files patterm changed
2845 void MainWindow::renameOutputPatternChanged(void)
2847 QString temp = lineEditRenamePattern->text().simplified();
2848 lineEditRenamePattern->setText(temp.isEmpty() ? m_settings->renameOutputFilesPatternDefault() : temp);
2849 m_settings->renameOutputFilesPattern(lineEditRenamePattern->text());
2853 * Rename output files patterm changed
2855 void MainWindow::renameOutputPatternChanged(const QString &text)
2857 QString pattern(text.simplified());
2859 pattern.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive);
2860 pattern.replace("<TrackNo>", "04", Qt::CaseInsensitive);
2861 pattern.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive);
2862 pattern.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive);
2863 pattern.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive);
2864 pattern.replace("<Year>", "2001", Qt::CaseInsensitive);
2865 pattern.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive);
2867 if(pattern.compare(lamexp_clean_filename(pattern)))
2869 if(lineEditRenamePattern->palette().color(QPalette::Text) != Qt::red)
2871 MessageBeep(MB_ICONERROR);
2872 SET_TEXT_COLOR(lineEditRenamePattern, Qt::red);
2877 if(lineEditRenamePattern->palette().color(QPalette::Text) != Qt::black)
2879 MessageBeep(MB_ICONINFORMATION);
2880 SET_TEXT_COLOR(lineEditRenamePattern, Qt::black);
2884 labelRanameExample->setText(lamexp_clean_filename(pattern));
2888 * Show list of rename macros
2890 void MainWindow::showRenameMacros(const QString &text)
2892 if(text.compare("reset", Qt::CaseInsensitive) == 0)
2894 lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
2898 const QString format = QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
2900 QString message = QString("<table>");
2901 message += QString(format).arg("BaseName", tr("File name without extension"));
2902 message += QString(format).arg("TrackNo", tr("Track number with leading zero"));
2903 message += QString(format).arg("Title", tr("Track title"));
2904 message += QString(format).arg("Artist", tr("Artist name"));
2905 message += QString(format).arg("Album", tr("Album name"));
2906 message += QString(format).arg("Year", tr("Year with (at least) four digits"));
2907 message += QString(format).arg("Comment", tr("Comment"));
2908 message += "</table><br><br>";
2909 message += QString("%1<br>").arg(tr("Characters forbidden in file names:"));
2910 message += "<b><tt>\\ / : * ? < > |<br>";
2912 QMessageBox::information(this, tr("Rename Macros"), message, tr("Discard"));
2915 void MainWindow::forceStereoDownmixEnabledChanged(bool checked)
2917 m_settings->forceStereoDownmix(checked);
2921 * Maximum number of instances changed
2923 void MainWindow::updateMaximumInstances(int value)
2925 labelMaxInstances->setText(tr("%1 Instance(s)").arg(QString::number(value)));
2926 m_settings->maximumInstances(checkBoxAutoDetectInstances->isChecked() ? NULL : value);
2930 * Auto-detect number of instances
2932 void MainWindow::autoDetectInstancesChanged(bool checked)
2934 m_settings->maximumInstances(checked ? NULL : sliderMaxInstances->value());
2938 * Browse for custom TEMP folder button clicked
2940 void MainWindow::browseCustomTempFolderButtonClicked(void)
2942 QString newTempFolder;
2944 if(USE_NATIVE_FILE_DIALOG)
2946 newTempFolder = QFileDialog::getExistingDirectory(this, QString(), m_settings->customTempPath());
2950 QFileDialog dialog(this);
2951 dialog.setFileMode(QFileDialog::DirectoryOnly);
2952 dialog.setDirectory(m_settings->customTempPath());
2955 newTempFolder = dialog.selectedFiles().first();
2959 if(!newTempFolder.isEmpty())
2961 QFile writeTest(QString("%1/~%2.tmp").arg(newTempFolder, lamexp_rand_str()));
2962 if(writeTest.open(QIODevice::ReadWrite))
2965 lineEditCustomTempFolder->setText(QDir::toNativeSeparators(newTempFolder));
2969 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
2975 * Custom TEMP folder changed
2977 void MainWindow::customTempFolderChanged(const QString &text)
2979 m_settings->customTempPath(QDir::fromNativeSeparators(text));
2983 * Use custom TEMP folder option changed
2985 void MainWindow::useCustomTempFolderChanged(bool checked)
2987 m_settings->customTempPathEnabled(!checked);
2991 * Reset all advanced options to their defaults
2993 void MainWindow::resetAdvancedOptionsButtonClicked(void)
2995 sliderLameAlgoQuality->setValue(m_settings->lameAlgoQualityDefault());
2996 spinBoxBitrateManagementMin->setValue(m_settings->bitrateManagementMinRateDefault());
2997 spinBoxBitrateManagementMax->setValue(m_settings->bitrateManagementMaxRateDefault());
2998 spinBoxNormalizationFilter->setValue(static_cast<double>(m_settings->normalizationFilterMaxVolumeDefault()) / 100.0);
2999 spinBoxToneAdjustBass->setValue(static_cast<double>(m_settings->toneAdjustBassDefault()) / 100.0);
3000 spinBoxToneAdjustTreble->setValue(static_cast<double>(m_settings->toneAdjustTrebleDefault()) / 100.0);
3001 spinBoxAftenSearchSize->setValue(m_settings->aftenExponentSearchSizeDefault());
3002 comboBoxMP3ChannelMode->setCurrentIndex(m_settings->lameChannelModeDefault());
3003 comboBoxSamplingRate->setCurrentIndex(m_settings->samplingRateDefault());
3004 comboBoxAACProfile->setCurrentIndex(m_settings->aacEncProfileDefault());
3005 comboBoxAftenCodingMode->setCurrentIndex(m_settings->aftenAudioCodingModeDefault());
3006 comboBoxAftenDRCMode->setCurrentIndex(m_settings->aftenDynamicRangeCompressionDefault());
3007 while(checkBoxBitrateManagement->isChecked() != m_settings->bitrateManagementEnabledDefault()) checkBoxBitrateManagement->click();
3008 while(checkBoxNeroAAC2PassMode->isChecked() != m_settings->neroAACEnable2PassDefault()) checkBoxNeroAAC2PassMode->click();
3009 while(checkBoxNormalizationFilter->isChecked() != m_settings->normalizationFilterEnabledDefault()) checkBoxNormalizationFilter->click();
3010 while(checkBoxAutoDetectInstances->isChecked() != (m_settings->maximumInstancesDefault() < 1)) checkBoxAutoDetectInstances->click();
3011 while(checkBoxUseSystemTempFolder->isChecked() == m_settings->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder->click();
3012 while(checkBoxAftenFastAllocation->isChecked() != m_settings->aftenFastBitAllocationDefault()) checkBoxAftenFastAllocation->click();
3013 while(checkBoxRenameOutput->isChecked() != m_settings->renameOutputFilesEnabledDefault()) checkBoxRenameOutput->click();
3014 while(checkBoxForceStereoDownmix->isChecked() != m_settings->forceStereoDownmixDefault()) checkBoxForceStereoDownmix->click();
3015 lineEditCustomParamLAME->setText(m_settings->customParametersLAMEDefault());
3016 lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEncDefault());
3017 lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEncDefault());
3018 lineEditCustomParamFLAC->setText(m_settings->customParametersFLACDefault());
3019 lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPathDefault()));
3020 lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
3021 customParamsChanged();
3022 scrollArea->verticalScrollBar()->setValue(0);
3025 // =========================================================
3026 // Multi-instance handling slots
3027 // =========================================================
3030 * Other instance detected
3032 void MainWindow::notifyOtherInstance(void)
3034 if(!m_banner->isVisible())
3036 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);
3042 * Add file from another instance
3044 void MainWindow::addFileDelayed(const QString &filePath, bool tryASAP)
3046 if(tryASAP && !m_delayedFileTimer->isActive())
3048 qDebug("Received file: %s", filePath.toUtf8().constData());
3049 m_delayedFileList->append(filePath);
3050 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3053 m_delayedFileTimer->stop();
3054 qDebug("Received file: %s", filePath.toUtf8().constData());
3055 m_delayedFileList->append(filePath);
3056 m_delayedFileTimer->start(5000);
3060 * Add files from another instance
3062 void MainWindow::addFilesDelayed(const QStringList &filePaths, bool tryASAP)
3064 if(tryASAP && !m_delayedFileTimer->isActive())
3066 qDebug("Received %d file(s).", filePaths.count());
3067 m_delayedFileList->append(filePaths);
3068 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3072 m_delayedFileTimer->stop();
3073 qDebug("Received %d file(s).", filePaths.count());
3074 m_delayedFileList->append(filePaths);
3075 m_delayedFileTimer->start(5000);
3080 * Add folder from another instance
3082 void MainWindow::addFolderDelayed(const QString &folderPath, bool recursive)
3084 if(!m_banner->isVisible())
3086 addFolder(folderPath, recursive, true);
3090 // =========================================================
3092 // =========================================================
3095 * Restore the override cursor
3097 void MainWindow::restoreCursor(void)
3099 QApplication::restoreOverrideCursor();