1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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"
25 #include "../tmp/UIC_MainWindow.h"
30 #include "Dialog_WorkingBanner.h"
31 #include "Dialog_MetaInfo.h"
32 #include "Dialog_About.h"
33 #include "Dialog_Update.h"
34 #include "Dialog_DropBox.h"
35 #include "Dialog_CueImport.h"
36 #include "Dialog_LogView.h"
37 #include "Thread_FileAnalyzer.h"
38 #include "Thread_FileAnalyzer_ST.h"
39 #include "Thread_MessageHandler.h"
40 #include "Model_MetaInfo.h"
41 #include "Model_Settings.h"
42 #include "Model_FileList.h"
43 #include "Model_FileSystem.h"
44 #include "WinSevenTaskbar.h"
45 #include "Registry_Decoder.h"
46 #include "ShellIntegration.h"
47 #include "CustomEventFilter.h"
50 #include <QMessageBox>
52 #include <QDesktopWidget>
54 #include <QFileDialog>
55 #include <QInputDialog>
56 #include <QFileSystemModel>
57 #include <QDesktopServices>
59 #include <QPlastiqueStyle>
60 #include <QCleanlooksStyle>
61 #include <QWindowsVistaStyle>
62 #include <QWindowsStyle>
64 #include <QDragEnterEvent>
68 #include <QProcessEnvironment>
69 #include <QCryptographicHash>
70 #include <QTranslator>
78 ////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////
82 #define ABORT_IF_BUSY do \
84 if(m_banner->isVisible() || m_delayedFileTimer->isActive()) \
86 MessageBeep(MB_ICONEXCLAMATION); \
92 #define SET_TEXT_COLOR(WIDGET, COLOR) do \
94 QPalette _palette = WIDGET->palette(); \
95 _palette.setColor(QPalette::WindowText, (COLOR)); \
96 _palette.setColor(QPalette::Text, (COLOR)); \
97 WIDGET->setPalette(_palette); \
101 #define SET_FONT_BOLD(WIDGET,BOLD) do \
103 QFont _font = WIDGET->font(); \
104 _font.setBold(BOLD); \
105 WIDGET->setFont(_font); \
109 #define TEMP_HIDE_DROPBOX(CMD) do \
111 bool _dropBoxVisible = m_dropBox->isVisible(); \
112 if(_dropBoxVisible) m_dropBox->hide(); \
113 do { CMD } while(0); \
114 if(_dropBoxVisible) m_dropBox->show(); \
118 #define SET_MODEL(VIEW, MODEL) do \
120 QItemSelectionModel *_tmp = (VIEW)->selectionModel(); \
121 (VIEW)->setModel(MODEL); \
122 LAMEXP_DELETE(_tmp); \
126 #define SET_CHECKBOX_STATE(CHCKBX, STATE) do \
128 if((CHCKBX)->isChecked() != (STATE)) \
132 if((CHCKBX)->isChecked() != (STATE)) \
134 qWarning("Warning: Failed to set checkbox " #CHCKBX " state!"); \
139 #define TRIM_STRING_RIGHT(STR) do \
141 while((STR.length() > 0) && STR[STR.length()-1].isSpace()) STR.chop(1); \
145 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "−"))
146 #define FSLINK(PATH) QString("<a href=\"file:///%1\">%2</a>").arg(PATH).arg(QString(PATH).replace("-", "−"))
147 #define USE_NATIVE_FILE_DIALOG (lamexp_themes_enabled() || ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) < QSysInfo::WV_XP))
148 #define CENTER_CURRENT_OUTPUT_FOLDER_DELAYED QTimer::singleShot(125, this, SLOT(centerOutputFolderModel()))
150 static const DWORD IDM_ABOUTBOX = 0xEFF0;
152 ////////////////////////////////////////////////////////////
154 ////////////////////////////////////////////////////////////
156 MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settingsModel, QWidget *parent)
159 ui(new Ui::MainWindow),
160 m_fileListModel(fileListModel),
161 m_metaData(metaInfo),
162 m_settings(settingsModel),
163 m_fileSystemModel(NULL),
164 m_neroEncoderAvailable(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")),
165 m_fhgEncoderAvailable(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll") && lamexp_check_tool("nsutil.dll") && lamexp_check_tool("libmp4v2.dll")),
166 m_qaacEncoderAvailable(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll")),
168 m_firstTimeShown(true),
169 m_outputFolderViewCentering(false),
170 m_outputFolderViewInitCounter(0)
172 //Init the dialog, from the .ui file
174 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint);
176 //Register meta types
177 qRegisterMetaType<AudioFileModel>("AudioFileModel");
179 //Enabled main buttons
180 connect(ui->buttonAbout, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
181 connect(ui->buttonStart, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
182 connect(ui->buttonQuit, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
185 ui->tabWidget->setCurrentIndex(0);
186 connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
189 if(HMENU hMenu = ::GetSystemMenu(winId(), FALSE))
191 AppendMenuW(hMenu, MF_SEPARATOR, 0, 0);
192 AppendMenuW(hMenu, MF_STRING, IDM_ABOUTBOX, L"About...");
195 //--------------------------------
196 // Setup "Source" tab
197 //--------------------------------
199 ui->sourceFileView->setModel(m_fileListModel);
200 ui->sourceFileView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
201 ui->sourceFileView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
202 ui->sourceFileView->setContextMenuPolicy(Qt::CustomContextMenu);
203 ui->sourceFileView->viewport()->installEventFilter(this);
204 m_dropNoteLabel = new QLabel(ui->sourceFileView);
205 m_dropNoteLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
206 SET_FONT_BOLD(m_dropNoteLabel, true);
207 SET_TEXT_COLOR(m_dropNoteLabel, Qt::darkGray);
208 m_sourceFilesContextMenu = new QMenu();
209 m_showDetailsContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/zoom.png"), "N/A");
210 m_previewContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/sound.png"), "N/A");
211 m_findFileContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/folder_go.png"), "N/A");
212 m_sourceFilesContextMenu->addSeparator();
213 m_exportCsvContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/table_save.png"), "N/A");
214 m_importCsvContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/folder_table.png"), "N/A");
215 SET_FONT_BOLD(m_showDetailsContextAction, true);
216 connect(ui->buttonAddFiles, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
217 connect(ui->buttonRemoveFile, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
218 connect(ui->buttonClearFiles, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
219 connect(ui->buttonFileUp, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
220 connect(ui->buttonFileDown, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
221 connect(ui->buttonShowDetails, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
222 connect(m_fileListModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(sourceModelChanged()));
223 connect(m_fileListModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(sourceModelChanged()));
224 connect(m_fileListModel, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
225 connect(ui->sourceFileView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(sourceFilesContextMenu(QPoint)));
226 connect(ui->sourceFileView->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
227 connect(ui->sourceFileView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
228 connect(m_showDetailsContextAction, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
229 connect(m_previewContextAction, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
230 connect(m_findFileContextAction, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
231 connect(m_exportCsvContextAction, SIGNAL(triggered(bool)), this, SLOT(exportCsvContextActionTriggered()));
232 connect(m_importCsvContextAction, SIGNAL(triggered(bool)), this, SLOT(importCsvContextActionTriggered()));
234 //--------------------------------
235 // Setup "Output" tab
236 //--------------------------------
238 ui->outputFolderView->setHeaderHidden(true);
239 ui->outputFolderView->setAnimated(false);
240 ui->outputFolderView->setMouseTracking(false);
241 ui->outputFolderView->setContextMenuPolicy(Qt::CustomContextMenu);
242 ui->outputFolderView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
244 m_evenFilterOutputFolderMouse = new CustomEventFilter;
245 ui->outputFoldersEditorLabel->installEventFilter(m_evenFilterOutputFolderMouse);
246 ui->outputFoldersFovoritesLabel->installEventFilter(m_evenFilterOutputFolderMouse);
247 ui->outputFolderLabel->installEventFilter(m_evenFilterOutputFolderMouse);
249 m_evenFilterOutputFolderView = new CustomEventFilter;
250 ui->outputFolderView->installEventFilter(m_evenFilterOutputFolderView);
252 SET_CHECKBOX_STATE(ui->saveToSourceFolderCheckBox, m_settings->outputToSourceDir());
253 ui->prependRelativePathCheckBox->setChecked(m_settings->prependRelativeSourcePath());
255 connect(ui->outputFolderView, SIGNAL(clicked(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
256 connect(ui->outputFolderView, SIGNAL(activated(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
257 connect(ui->outputFolderView, SIGNAL(pressed(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
258 connect(ui->outputFolderView, SIGNAL(entered(QModelIndex)), this, SLOT(outputFolderViewMoved(QModelIndex)));
259 connect(ui->outputFolderView, SIGNAL(expanded(QModelIndex)), this, SLOT(outputFolderItemExpanded(QModelIndex)));
260 connect(ui->buttonMakeFolder, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
261 connect(ui->buttonGotoHome, SIGNAL(clicked()), SLOT(gotoHomeFolderButtonClicked()));
262 connect(ui->buttonGotoDesktop, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
263 connect(ui->buttonGotoMusic, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
264 connect(ui->saveToSourceFolderCheckBox, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
265 connect(ui->prependRelativePathCheckBox, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
266 connect(ui->outputFolderEdit, SIGNAL(editingFinished()), this, SLOT(outputFolderEditFinished()));
267 connect(m_evenFilterOutputFolderMouse, SIGNAL(eventOccurred(QWidget*, QEvent*)), this, SLOT(outputFolderMouseEventOccurred(QWidget*, QEvent*)));
268 connect(m_evenFilterOutputFolderView, SIGNAL(eventOccurred(QWidget*, QEvent*)), this, SLOT(outputFolderViewEventOccurred(QWidget*, QEvent*)));
270 if(m_outputFolderContextMenu = new QMenu())
272 m_showFolderContextAction = m_outputFolderContextMenu->addAction(QIcon(":/icons/zoom.png"), "N/A");
273 m_refreshFolderContextAction = m_outputFolderContextMenu->addAction(QIcon(":/icons/arrow_refresh.png"), "N/A");
274 m_outputFolderContextMenu->setDefaultAction(m_showFolderContextAction);
275 connect(ui->outputFolderView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(outputFolderContextMenu(QPoint)));
276 connect(m_showFolderContextAction, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
277 connect(m_refreshFolderContextAction, SIGNAL(triggered(bool)), this, SLOT(refreshFolderContextActionTriggered()));
280 if(m_outputFolderFavoritesMenu = new QMenu())
282 m_addFavoriteFolderAction = m_outputFolderFavoritesMenu->addAction(QIcon(":/icons/add.png"), "N/A");
283 m_outputFolderFavoritesMenu->insertSeparator(m_addFavoriteFolderAction);
284 connect(m_addFavoriteFolderAction, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
287 ui->outputFolderEdit->setVisible(false);
288 if(m_outputFolderNoteBox = new QLabel(ui->outputFolderView))
290 m_outputFolderNoteBox->setAutoFillBackground(true);
291 m_outputFolderNoteBox->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
292 m_outputFolderNoteBox->setFrameShape(QFrame::StyledPanel);
293 SET_FONT_BOLD(m_outputFolderNoteBox, true);
294 m_outputFolderNoteBox->hide();
298 outputFolderViewClicked(QModelIndex());
301 //--------------------------------
302 // Setup "Meta Data" tab
303 //--------------------------------
305 m_metaInfoModel = new MetaInfoModel(m_metaData, 6);
306 m_metaInfoModel->clearData();
307 m_metaInfoModel->setData(m_metaInfoModel->index(4, 1), m_settings->metaInfoPosition());
308 ui->metaDataView->setModel(m_metaInfoModel);
309 ui->metaDataView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
310 ui->metaDataView->verticalHeader()->hide();
311 ui->metaDataView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
312 SET_CHECKBOX_STATE(ui->writeMetaDataCheckBox, m_settings->writeMetaTags());
313 ui->generatePlaylistCheckBox->setChecked(m_settings->createPlaylist());
314 connect(ui->buttonEditMeta, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
315 connect(ui->buttonClearMeta, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
316 connect(ui->writeMetaDataCheckBox, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
317 connect(ui->generatePlaylistCheckBox, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
319 //--------------------------------
320 //Setup "Compression" tab
321 //--------------------------------
323 m_encoderButtonGroup = new QButtonGroup(this);
324 m_encoderButtonGroup->addButton(ui->radioButtonEncoderMP3, SettingsModel::MP3Encoder);
325 m_encoderButtonGroup->addButton(ui->radioButtonEncoderVorbis, SettingsModel::VorbisEncoder);
326 m_encoderButtonGroup->addButton(ui->radioButtonEncoderAAC, SettingsModel::AACEncoder);
327 m_encoderButtonGroup->addButton(ui->radioButtonEncoderAC3, SettingsModel::AC3Encoder);
328 m_encoderButtonGroup->addButton(ui->radioButtonEncoderFLAC, SettingsModel::FLACEncoder);
329 m_encoderButtonGroup->addButton(ui->radioButtonEncoderOpus, SettingsModel::OpusEncoder);
330 m_encoderButtonGroup->addButton(ui->radioButtonEncoderDCA, SettingsModel::DCAEncoder);
331 m_encoderButtonGroup->addButton(ui->radioButtonEncoderPCM, SettingsModel::PCMEncoder);
333 m_modeButtonGroup = new QButtonGroup(this);
334 m_modeButtonGroup->addButton(ui->radioButtonModeQuality, SettingsModel::VBRMode);
335 m_modeButtonGroup->addButton(ui->radioButtonModeAverageBitrate, SettingsModel::ABRMode);
336 m_modeButtonGroup->addButton(ui->radioButtonConstBitrate, SettingsModel::CBRMode);
338 ui->radioButtonEncoderAAC->setEnabled(m_neroEncoderAvailable || m_fhgEncoderAvailable || m_qaacEncoderAvailable);
339 ui->radioButtonEncoderMP3->setChecked(m_settings->compressionEncoder() == SettingsModel::MP3Encoder);
340 ui->radioButtonEncoderVorbis->setChecked(m_settings->compressionEncoder() == SettingsModel::VorbisEncoder);
341 ui->radioButtonEncoderAAC->setChecked((m_settings->compressionEncoder() == SettingsModel::AACEncoder) && (m_neroEncoderAvailable || m_fhgEncoderAvailable || m_qaacEncoderAvailable));
342 ui->radioButtonEncoderAC3->setChecked(m_settings->compressionEncoder() == SettingsModel::AC3Encoder);
343 ui->radioButtonEncoderFLAC->setChecked(m_settings->compressionEncoder() == SettingsModel::FLACEncoder);
344 ui->radioButtonEncoderOpus->setChecked(m_settings->compressionEncoder() == SettingsModel::OpusEncoder);
345 ui->radioButtonEncoderDCA->setChecked(m_settings->compressionEncoder() == SettingsModel::DCAEncoder);
346 ui->radioButtonEncoderPCM->setChecked(m_settings->compressionEncoder() == SettingsModel::PCMEncoder);
347 ui->radioButtonModeQuality->setChecked(m_settings->compressionRCMode() == SettingsModel::VBRMode);
348 ui->radioButtonModeAverageBitrate->setChecked(m_settings->compressionRCMode() == SettingsModel::ABRMode);
349 ui->radioButtonConstBitrate->setChecked(m_settings->compressionRCMode() == SettingsModel::CBRMode);
350 ui->sliderBitrate->setValue(m_settings->compressionBitrate());
352 m_evenFilterCompressionTab = new CustomEventFilter();
353 ui->labelCompressionHelp->installEventFilter(m_evenFilterCompressionTab);
355 connect(m_encoderButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
356 connect(m_modeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
357 connect(m_evenFilterCompressionTab, SIGNAL(eventOccurred(QWidget*, QEvent*)), this, SLOT(compressionTabEventOccurred(QWidget*, QEvent*)));
358 connect(ui->sliderBitrate, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
360 updateEncoder(m_encoderButtonGroup->checkedId());
362 //--------------------------------
363 //Setup "Advanced Options" tab
364 //--------------------------------
366 ui->sliderLameAlgoQuality->setValue(m_settings->lameAlgoQuality());
367 if(m_settings->maximumInstances() > 0) ui->sliderMaxInstances->setValue(m_settings->maximumInstances());
369 ui->spinBoxBitrateManagementMin->setValue(m_settings->bitrateManagementMinRate());
370 ui->spinBoxBitrateManagementMax->setValue(m_settings->bitrateManagementMaxRate());
371 ui->spinBoxNormalizationFilter->setValue(static_cast<double>(m_settings->normalizationFilterMaxVolume()) / 100.0);
372 ui->spinBoxToneAdjustBass->setValue(static_cast<double>(m_settings->toneAdjustBass()) / 100.0);
373 ui->spinBoxToneAdjustTreble->setValue(static_cast<double>(m_settings->toneAdjustTreble()) / 100.0);
374 ui->spinBoxAftenSearchSize->setValue(m_settings->aftenExponentSearchSize());
375 ui->spinBoxOpusComplexity->setValue(m_settings->opusComplexity());
377 ui->comboBoxMP3ChannelMode->setCurrentIndex(m_settings->lameChannelMode());
378 ui->comboBoxSamplingRate->setCurrentIndex(m_settings->samplingRate());
379 ui->comboBoxAACProfile->setCurrentIndex(m_settings->aacEncProfile());
380 ui->comboBoxAftenCodingMode->setCurrentIndex(m_settings->aftenAudioCodingMode());
381 ui->comboBoxAftenDRCMode->setCurrentIndex(m_settings->aftenDynamicRangeCompression());
382 ui->comboBoxNormalizationMode->setCurrentIndex(m_settings->normalizationFilterEqualizationMode());
383 //comboBoxOpusOptimize->setCurrentIndex(m_settings->opusOptimizeFor());
384 ui->comboBoxOpusFramesize->setCurrentIndex(m_settings->opusFramesize());
386 SET_CHECKBOX_STATE(ui->checkBoxBitrateManagement, m_settings->bitrateManagementEnabled());
387 SET_CHECKBOX_STATE(ui->checkBoxNeroAAC2PassMode, m_settings->neroAACEnable2Pass());
388 SET_CHECKBOX_STATE(ui->checkBoxAftenFastAllocation, m_settings->aftenFastBitAllocation());
389 SET_CHECKBOX_STATE(ui->checkBoxNormalizationFilter, m_settings->normalizationFilterEnabled());
390 SET_CHECKBOX_STATE(ui->checkBoxAutoDetectInstances, (m_settings->maximumInstances() < 1));
391 SET_CHECKBOX_STATE(ui->checkBoxUseSystemTempFolder, !m_settings->customTempPathEnabled());
392 SET_CHECKBOX_STATE(ui->checkBoxRenameOutput, m_settings->renameOutputFilesEnabled());
393 SET_CHECKBOX_STATE(ui->checkBoxForceStereoDownmix, m_settings->forceStereoDownmix());
394 ui->checkBoxNeroAAC2PassMode->setEnabled(!(m_fhgEncoderAvailable || m_qaacEncoderAvailable));
396 ui->lineEditCustomParamLAME->setText(m_settings->customParametersLAME());
397 ui->lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEnc());
398 ui->lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEnc());
399 ui->lineEditCustomParamFLAC->setText(m_settings->customParametersFLAC());
400 ui->lineEditCustomParamAften->setText(m_settings->customParametersAften());
401 ui->lineEditCustomParamOpus->setText(m_settings->customParametersOpus());
402 ui->lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPath()));
403 ui->lineEditRenamePattern->setText(m_settings->renameOutputFilesPattern());
405 m_evenFilterCustumParamsHelp = new CustomEventFilter();
406 ui->helpCustomParamLAME->installEventFilter(m_evenFilterCustumParamsHelp);
407 ui->helpCustomParamOggEnc->installEventFilter(m_evenFilterCustumParamsHelp);
408 ui->helpCustomParamNeroAAC->installEventFilter(m_evenFilterCustumParamsHelp);
409 ui->helpCustomParamFLAC->installEventFilter(m_evenFilterCustumParamsHelp);
410 ui->helpCustomParamAften->installEventFilter(m_evenFilterCustumParamsHelp);
411 ui->helpCustomParamOpus->installEventFilter(m_evenFilterCustumParamsHelp);
413 m_overwriteButtonGroup = new QButtonGroup(this);
414 m_overwriteButtonGroup->addButton(ui->radioButtonOverwriteModeKeepBoth, SettingsModel::Overwrite_KeepBoth);
415 m_overwriteButtonGroup->addButton(ui->radioButtonOverwriteModeSkipFile, SettingsModel::Overwrite_SkipFile);
416 m_overwriteButtonGroup->addButton(ui->radioButtonOverwriteModeReplaces, SettingsModel::Overwrite_Replaces);
418 ui->radioButtonOverwriteModeKeepBoth->setChecked(m_settings->overwriteMode() == SettingsModel::Overwrite_KeepBoth);
419 ui->radioButtonOverwriteModeSkipFile->setChecked(m_settings->overwriteMode() == SettingsModel::Overwrite_SkipFile);
420 ui->radioButtonOverwriteModeReplaces->setChecked(m_settings->overwriteMode() == SettingsModel::Overwrite_Replaces);
422 connect(ui->sliderLameAlgoQuality, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
423 connect(ui->checkBoxBitrateManagement, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
424 connect(ui->spinBoxBitrateManagementMin, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
425 connect(ui->spinBoxBitrateManagementMax, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
426 connect(ui->comboBoxMP3ChannelMode, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
427 connect(ui->comboBoxSamplingRate, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
428 connect(ui->checkBoxNeroAAC2PassMode, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
429 connect(ui->comboBoxAACProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
430 connect(ui->checkBoxNormalizationFilter, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
431 connect(ui->comboBoxAftenCodingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
432 connect(ui->comboBoxAftenDRCMode, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
433 connect(ui->spinBoxAftenSearchSize, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
434 connect(ui->checkBoxAftenFastAllocation, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
435 connect(ui->spinBoxNormalizationFilter, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
436 connect(ui->comboBoxNormalizationMode, SIGNAL(currentIndexChanged(int)), this, SLOT(normalizationModeChanged(int)));
437 connect(ui->spinBoxToneAdjustBass, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
438 connect(ui->spinBoxToneAdjustTreble, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
439 connect(ui->buttonToneAdjustReset, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
440 connect(ui->lineEditCustomParamLAME, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
441 connect(ui->lineEditCustomParamOggEnc, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
442 connect(ui->lineEditCustomParamNeroAAC, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
443 connect(ui->lineEditCustomParamFLAC, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
444 connect(ui->lineEditCustomParamAften, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
445 connect(ui->lineEditCustomParamOpus, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
446 connect(ui->sliderMaxInstances, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
447 connect(ui->checkBoxAutoDetectInstances, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
448 connect(ui->buttonBrowseCustomTempFolder, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
449 connect(ui->lineEditCustomTempFolder, SIGNAL(textChanged(QString)), this, SLOT(customTempFolderChanged(QString)));
450 connect(ui->checkBoxUseSystemTempFolder, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
451 connect(ui->buttonResetAdvancedOptions, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
452 connect(ui->checkBoxRenameOutput, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
453 connect(ui->lineEditRenamePattern, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
454 connect(ui->lineEditRenamePattern, SIGNAL(textChanged(QString)), this, SLOT(renameOutputPatternChanged(QString)));
455 connect(ui->labelShowRenameMacros, SIGNAL(linkActivated(QString)), this, SLOT(showRenameMacros(QString)));
456 connect(ui->checkBoxForceStereoDownmix, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
457 connect(ui->comboBoxOpusFramesize, SIGNAL(currentIndexChanged(int)), this, SLOT(opusSettingsChanged()));
458 connect(ui->spinBoxOpusComplexity, SIGNAL(valueChanged(int)), this, SLOT(opusSettingsChanged()));
459 //connect(comboBoxOpusOptimize, SIGNAL(currentIndexChanged(int)), SLOT(opusSettingsChanged()));
460 //connect(checkBoxOpusExpAnalysis, SIGNAL(clicked(bool)), this, SLOT(opusSettingsChanged()));
461 connect(m_overwriteButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(overwriteModeChanged(int)));
462 connect(m_evenFilterCustumParamsHelp, SIGNAL(eventOccurred(QWidget*, QEvent*)), this, SLOT(customParamsHelpRequested(QWidget*, QEvent*)));
464 //--------------------------------
465 // Force initial GUI update
466 //--------------------------------
468 updateLameAlgoQuality(ui->sliderLameAlgoQuality->value());
469 updateMaximumInstances(ui->sliderMaxInstances->value());
470 toneAdjustTrebleChanged(ui->spinBoxToneAdjustTreble->value());
471 toneAdjustBassChanged(ui->spinBoxToneAdjustBass->value());
472 customParamsChanged();
474 //--------------------------------
475 // Initialize actions
476 //--------------------------------
478 //Activate file menu actions
479 ui->actionOpenFolder->setData(QVariant::fromValue<bool>(false));
480 ui->actionOpenFolderRecursively->setData(QVariant::fromValue<bool>(true));
481 connect(ui->actionOpenFolder, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
482 connect(ui->actionOpenFolderRecursively, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
484 //Activate view menu actions
485 m_tabActionGroup = new QActionGroup(this);
486 m_tabActionGroup->addAction(ui->actionSourceFiles);
487 m_tabActionGroup->addAction(ui->actionOutputDirectory);
488 m_tabActionGroup->addAction(ui->actionCompression);
489 m_tabActionGroup->addAction(ui->actionMetaData);
490 m_tabActionGroup->addAction(ui->actionAdvancedOptions);
491 ui->actionSourceFiles->setData(0);
492 ui->actionOutputDirectory->setData(1);
493 ui->actionMetaData->setData(2);
494 ui->actionCompression->setData(3);
495 ui->actionAdvancedOptions->setData(4);
496 ui->actionSourceFiles->setChecked(true);
497 connect(m_tabActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(tabActionActivated(QAction*)));
499 //Activate style menu actions
500 m_styleActionGroup = new QActionGroup(this);
501 m_styleActionGroup->addAction(ui->actionStylePlastique);
502 m_styleActionGroup->addAction(ui->actionStyleCleanlooks);
503 m_styleActionGroup->addAction(ui->actionStyleWindowsVista);
504 m_styleActionGroup->addAction(ui->actionStyleWindowsXP);
505 m_styleActionGroup->addAction(ui->actionStyleWindowsClassic);
506 ui->actionStylePlastique->setData(0);
507 ui->actionStyleCleanlooks->setData(1);
508 ui->actionStyleWindowsVista->setData(2);
509 ui->actionStyleWindowsXP->setData(3);
510 ui->actionStyleWindowsClassic->setData(4);
511 ui->actionStylePlastique->setChecked(true);
512 ui->actionStyleWindowsXP->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_XP && lamexp_themes_enabled());
513 ui->actionStyleWindowsVista->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_VISTA && lamexp_themes_enabled());
514 connect(m_styleActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(styleActionActivated(QAction*)));
515 styleActionActivated(NULL);
517 //Populate the language menu
518 m_languageActionGroup = new QActionGroup(this);
519 QStringList translations = lamexp_query_translations();
520 while(!translations.isEmpty())
522 QString langId = translations.takeFirst();
523 QAction *currentLanguage = new QAction(this);
524 currentLanguage->setData(langId);
525 currentLanguage->setText(lamexp_translation_name(langId));
526 currentLanguage->setIcon(QIcon(QString(":/flags/%1.png").arg(langId)));
527 currentLanguage->setCheckable(true);
528 currentLanguage->setChecked(false);
529 m_languageActionGroup->addAction(currentLanguage);
530 ui->menuLanguage->insertAction(ui->actionLoadTranslationFromFile, currentLanguage);
532 ui->menuLanguage->insertSeparator(ui->actionLoadTranslationFromFile);
533 connect(ui->actionLoadTranslationFromFile, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
534 connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*)));
535 ui->actionLoadTranslationFromFile->setChecked(false);
537 //Activate tools menu actions
538 ui->actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
539 ui->actionDisableSounds->setChecked(!m_settings->soundsEnabled());
540 ui->actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
541 ui->actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
542 ui->actionDisableShellIntegration->setChecked(!m_settings->shellIntegrationEnabled());
543 ui->actionDisableShellIntegration->setDisabled(lamexp_portable_mode() && ui->actionDisableShellIntegration->isChecked());
544 ui->actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta() || lamexp_version_demo());
545 ui->actionCheckForBetaUpdates->setEnabled(!lamexp_version_demo());
546 ui->actionHibernateComputer->setChecked(m_settings->hibernateComputer());
547 ui->actionHibernateComputer->setEnabled(lamexp_is_hibernation_supported());
548 connect(ui->actionDisableUpdateReminder, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
549 connect(ui->actionDisableSounds, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
550 connect(ui->actionDisableNeroAacNotifications, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
551 connect(ui->actionDisableSlowStartupNotifications, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
552 connect(ui->actionDisableShellIntegration, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
553 connect(ui->actionShowDropBoxWidget, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
554 connect(ui->actionHibernateComputer, SIGNAL(triggered(bool)), this, SLOT(hibernateComputerActionTriggered(bool)));
555 connect(ui->actionCheckForBetaUpdates, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
556 connect(ui->actionImportCueSheet, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
558 //Activate help menu actions
559 ui->actionVisitHomepage->setData(QString::fromLatin1(lamexp_website_url()));
560 ui->actionVisitSupport->setData(QString::fromLatin1(lamexp_support_url()));
561 ui->actionDocumentFAQ->setData(QString("%1/FAQ.html").arg(QApplication::applicationDirPath()));
562 ui->actionDocumentChangelog->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
563 ui->actionDocumentTranslate->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
564 connect(ui->actionCheckUpdates, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
565 connect(ui->actionVisitHomepage, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
566 connect(ui->actionVisitSupport, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
567 connect(ui->actionDocumentFAQ, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
568 connect(ui->actionDocumentChangelog, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
569 connect(ui->actionDocumentTranslate, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
571 //--------------------------------
572 // Prepare to show window
573 //--------------------------------
575 //Center window in screen
576 QRect desktopRect = QApplication::desktop()->screenGeometry();
577 QRect thisRect = this->geometry();
578 move((desktopRect.width() - thisRect.width()) / 2, (desktopRect.height() - thisRect.height()) / 2);
579 setMinimumSize(thisRect.width(), thisRect.height());
582 m_banner = new WorkingBanner(this);
584 //Create DropBox widget
585 m_dropBox = new DropBox(this, m_fileListModel, m_settings);
586 connect(m_fileListModel, SIGNAL(modelReset()), m_dropBox, SLOT(modelChanged()));
587 connect(m_fileListModel, SIGNAL(rowsInserted(QModelIndex,int,int)), m_dropBox, SLOT(modelChanged()));
588 connect(m_fileListModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), m_dropBox, SLOT(modelChanged()));
589 connect(m_fileListModel, SIGNAL(rowAppended()), m_dropBox, SLOT(modelChanged()));
591 //Create message handler thread
592 m_messageHandler = new MessageHandlerThread();
593 m_delayedFileList = new QStringList();
594 m_delayedFileTimer = new QTimer();
595 m_delayedFileTimer->setSingleShot(true);
596 m_delayedFileTimer->setInterval(5000);
597 connect(m_messageHandler, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection);
598 connect(m_messageHandler, SIGNAL(fileReceived(QString)), this, SLOT(addFileDelayed(QString)), Qt::QueuedConnection);
599 connect(m_messageHandler, SIGNAL(folderReceived(QString, bool)), this, SLOT(addFolderDelayed(QString, bool)), Qt::QueuedConnection);
600 connect(m_messageHandler, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection);
601 connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
602 m_messageHandler->start();
605 initializeTranslation();
607 //Re-translate (make sure we translate once)
608 QEvent languageChangeEvent(QEvent::LanguageChange);
609 changeEvent(&languageChangeEvent);
612 this->setAcceptDrops(true);
615 ////////////////////////////////////////////////////////////
617 ////////////////////////////////////////////////////////////
619 MainWindow::~MainWindow(void)
621 //Stop message handler thread
622 if(m_messageHandler && m_messageHandler->isRunning())
624 m_messageHandler->stop();
625 if(!m_messageHandler->wait(2500))
627 m_messageHandler->terminate();
628 m_messageHandler->wait();
633 SET_MODEL(ui->sourceFileView, NULL);
634 SET_MODEL(ui->outputFolderView, NULL);
635 SET_MODEL(ui->metaDataView, NULL);
638 LAMEXP_DELETE(m_tabActionGroup);
639 LAMEXP_DELETE(m_styleActionGroup);
640 LAMEXP_DELETE(m_languageActionGroup);
641 LAMEXP_DELETE(m_banner);
642 LAMEXP_DELETE(m_fileSystemModel);
643 LAMEXP_DELETE(m_messageHandler);
644 LAMEXP_DELETE(m_delayedFileList);
645 LAMEXP_DELETE(m_delayedFileTimer);
646 LAMEXP_DELETE(m_metaInfoModel);
647 LAMEXP_DELETE(m_encoderButtonGroup);
648 LAMEXP_DELETE(m_modeButtonGroup);
649 LAMEXP_DELETE(m_overwriteButtonGroup);
650 LAMEXP_DELETE(m_sourceFilesContextMenu);
651 LAMEXP_DELETE(m_outputFolderFavoritesMenu);
652 LAMEXP_DELETE(m_outputFolderContextMenu);
653 LAMEXP_DELETE(m_dropBox);
654 LAMEXP_DELETE(m_evenFilterCustumParamsHelp);
655 LAMEXP_DELETE(m_evenFilterOutputFolderMouse);
656 LAMEXP_DELETE(m_evenFilterOutputFolderView);
657 LAMEXP_DELETE(m_evenFilterCompressionTab);
659 //Un-initialize the dialog
663 ////////////////////////////////////////////////////////////
665 ////////////////////////////////////////////////////////////
668 * Add file to source list
670 void MainWindow::addFiles(const QStringList &files)
677 ui->tabWidget->setCurrentIndex(0);
679 FileAnalyzer *analyzer = new FileAnalyzer(files);
680 connect(analyzer, SIGNAL(fileSelected(QString)), m_banner, SLOT(setText(QString)), Qt::QueuedConnection);
681 connect(analyzer, SIGNAL(progressValChanged(unsigned int)), m_banner, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection);
682 connect(analyzer, SIGNAL(progressMaxChanged(unsigned int)), m_banner, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection);
683 connect(analyzer, SIGNAL(fileAnalyzed(AudioFileModel)), m_fileListModel, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection);
684 connect(m_banner, SIGNAL(userAbort()), analyzer, SLOT(abortProcess()), Qt::DirectConnection);
688 m_fileListModel->setBlockUpdates(true);
689 QTime startTime = QTime::currentTime();
690 m_banner->show(tr("Adding file(s), please wait..."), analyzer);
694 /* ignore any exceptions that may occur */
697 m_fileListModel->setBlockUpdates(false);
698 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
699 ui->sourceFileView->update();
700 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
701 ui->sourceFileView->scrollToBottom();
702 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
704 if(analyzer->filesDenied())
706 QMessageBox::warning(this, tr("Access Denied"), QString("%1<br>%2").arg(NOBR(tr("%1 file(s) have been rejected, because read access was not granted!").arg(analyzer->filesDenied())), NOBR(tr("This usually means the file is locked by another process."))));
708 if(analyzer->filesDummyCDDA())
710 QMessageBox::warning(this, tr("CDDA Files"), QString("%1<br><br>%2<br>%3").arg(NOBR(tr("%1 file(s) have been rejected, because they are dummy CDDA files!").arg(analyzer->filesDummyCDDA())), NOBR(tr("Sorry, LameXP cannot extract audio tracks from an Audio-CD at present.")), NOBR(tr("We recommend using %1 for that purpose.").arg("<a href=\"http://www.exactaudiocopy.de/\">Exact Audio Copy</a>"))));
712 if(analyzer->filesCueSheet())
714 QMessageBox::warning(this, tr("Cue Sheet"), QString("%1<br>%2").arg(NOBR(tr("%1 file(s) have been rejected, because they appear to be Cue Sheet images!").arg(analyzer->filesCueSheet())), NOBR(tr("Please use LameXP's Cue Sheet wizard for importing Cue Sheet files."))));
716 if(analyzer->filesRejected())
718 QMessageBox::warning(this, tr("Files Rejected"), QString("%1<br>%2").arg(NOBR(tr("%1 file(s) have been rejected, because the file format could not be recognized!").arg(analyzer->filesRejected())), NOBR(tr("This usually means the file is damaged or the file format is not supported."))));
721 LAMEXP_DELETE(analyzer);
726 * Add folder to source list
728 void MainWindow::addFolder(const QString &path, bool recursive, bool delayed)
730 QFileInfoList folderInfoList;
731 folderInfoList << QFileInfo(path);
732 QStringList fileList;
734 m_banner->show(tr("Scanning folder(s) for files, please wait..."));
736 QApplication::processEvents();
737 GetAsyncKeyState(VK_ESCAPE);
739 while(!folderInfoList.isEmpty())
741 if(GetAsyncKeyState(VK_ESCAPE) & 0x0001)
743 MessageBeep(MB_ICONERROR);
744 qWarning("Operation cancelled by user!");
749 QDir currentDir(folderInfoList.takeFirst().canonicalFilePath());
750 QFileInfoList fileInfoList = currentDir.entryInfoList(QDir::Files | QDir::NoSymLinks);
752 while(!fileInfoList.isEmpty())
754 fileList << fileInfoList.takeFirst().canonicalFilePath();
757 QApplication::processEvents();
761 folderInfoList.append(currentDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks));
762 QApplication::processEvents();
767 QApplication::processEvents();
769 if(!fileList.isEmpty())
773 addFilesDelayed(fileList);
785 bool MainWindow::checkForUpdates(void)
787 bool bReadyToInstall = false;
789 UpdateDialog *updateDialog = new UpdateDialog(m_settings, this);
790 updateDialog->exec();
792 if(updateDialog->getSuccess())
794 m_settings->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate));
795 bReadyToInstall = updateDialog->updateReadyToInstall();
798 LAMEXP_DELETE(updateDialog);
799 return bReadyToInstall;
803 * Refresh list of favorites
805 void MainWindow::refreshFavorites(void)
807 QList<QAction*> folderList = m_outputFolderFavoritesMenu->actions();
808 QStringList favorites = m_settings->favoriteOutputFolders().split("|", QString::SkipEmptyParts);
809 while(favorites.count() > 6) favorites.removeFirst();
811 while(!folderList.isEmpty())
813 QAction *currentItem = folderList.takeFirst();
814 if(currentItem->isSeparator()) break;
815 m_outputFolderFavoritesMenu->removeAction(currentItem);
816 LAMEXP_DELETE(currentItem);
819 QAction *lastItem = m_outputFolderFavoritesMenu->actions().first();
821 while(!favorites.isEmpty())
823 QString path = favorites.takeLast();
824 if(QDir(path).exists())
826 QAction *action = new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path), this);
827 action->setData(path);
828 m_outputFolderFavoritesMenu->insertAction(lastItem, action);
829 connect(action, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
836 * Initilaize translation
838 void MainWindow::initializeTranslation(void)
840 bool translationLoaded = false;
842 //Try to load "external" translation file
843 if(!m_settings->currentLanguageFile().isEmpty())
845 const QString qmFilePath = QFileInfo(m_settings->currentLanguageFile()).canonicalFilePath();
846 if((!qmFilePath.isEmpty()) && QFileInfo(qmFilePath).exists() && QFileInfo(qmFilePath).isFile() && (QFileInfo(qmFilePath).suffix().compare("qm", Qt::CaseInsensitive) == 0))
848 if(lamexp_install_translator_from_file(qmFilePath))
850 QList<QAction*> actions = m_languageActionGroup->actions();
851 while(!actions.isEmpty()) actions.takeFirst()->setChecked(false);
852 ui->actionLoadTranslationFromFile->setChecked(true);
853 translationLoaded = true;
858 //Try to load "built-in" translation file
859 if(!translationLoaded)
861 QList<QAction*> languageActions = m_languageActionGroup->actions();
862 while(!languageActions.isEmpty())
864 QAction *currentLanguage = languageActions.takeFirst();
865 if(currentLanguage->data().toString().compare(m_settings->currentLanguage(), Qt::CaseInsensitive) == 0)
867 currentLanguage->setChecked(true);
868 languageActionActivated(currentLanguage);
869 translationLoaded = true;
874 //Fallback to default translation
875 if(!translationLoaded)
877 QList<QAction*> languageActions = m_languageActionGroup->actions();
878 while(!languageActions.isEmpty())
880 QAction *currentLanguage = languageActions.takeFirst();
881 if(currentLanguage->data().toString().compare(LAMEXP_DEFAULT_LANGID, Qt::CaseInsensitive) == 0)
883 currentLanguage->setChecked(true);
884 languageActionActivated(currentLanguage);
885 translationLoaded = true;
890 //Make sure we loaded some translation
891 if(!translationLoaded)
893 qFatal("Failed to load any translation, this is NOT supposed to happen!");
897 ////////////////////////////////////////////////////////////
899 ////////////////////////////////////////////////////////////
902 * Window is about to be shown
904 void MainWindow::showEvent(QShowEvent *event)
907 m_dropNoteLabel->setGeometry(0, 0, ui->sourceFileView->width(), ui->sourceFileView->height());
908 sourceModelChanged();
910 if(!event->spontaneous())
912 ui->tabWidget->setCurrentIndex(0);
917 m_firstTimeShown = false;
918 QTimer::singleShot(0, this, SLOT(windowShown()));
922 if(m_settings->dropBoxWidgetEnabled())
924 m_dropBox->setVisible(true);
930 * Re-translate the UI
932 void MainWindow::changeEvent(QEvent *e)
934 if(e->type() == QEvent::LanguageChange)
936 int comboBoxIndex[8];
938 //Backup combobox indices, as retranslateUi() resets
939 comboBoxIndex[0] = ui->comboBoxMP3ChannelMode->currentIndex();
940 comboBoxIndex[1] = ui->comboBoxSamplingRate->currentIndex();
941 comboBoxIndex[2] = ui->comboBoxAACProfile->currentIndex();
942 comboBoxIndex[3] = ui->comboBoxAftenCodingMode->currentIndex();
943 comboBoxIndex[4] = ui->comboBoxAftenDRCMode->currentIndex();
944 comboBoxIndex[5] = ui->comboBoxNormalizationMode->currentIndex();
945 comboBoxIndex[6] = 0; //comboBoxOpusOptimize->currentIndex();
946 comboBoxIndex[7] = ui->comboBoxOpusFramesize->currentIndex();
948 //Re-translate from UIC
949 ui->retranslateUi(this);
951 //Restore combobox indices
952 ui->comboBoxMP3ChannelMode->setCurrentIndex(comboBoxIndex[0]);
953 ui->comboBoxSamplingRate->setCurrentIndex(comboBoxIndex[1]);
954 ui->comboBoxAACProfile->setCurrentIndex(comboBoxIndex[2]);
955 ui->comboBoxAftenCodingMode->setCurrentIndex(comboBoxIndex[3]);
956 ui->comboBoxAftenDRCMode->setCurrentIndex(comboBoxIndex[4]);
957 ui->comboBoxNormalizationMode->setCurrentIndex(comboBoxIndex[5]);
958 //comboBoxOpusOptimize->setCurrentIndex(comboBoxIndex[6]);
959 ui->comboBoxOpusFramesize->setCurrentIndex(comboBoxIndex[7]);
961 //Update the window title
964 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
966 else if(lamexp_version_demo())
968 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
971 //Manually re-translate widgets that UIC doesn't handle
972 m_dropNoteLabel->setText(QString("» %1 «").arg(tr("You can drop in audio files here!")));
973 m_outputFolderNoteBox->setText(tr("Initializing directory outline, please be patient..."));
974 m_showDetailsContextAction->setText(tr("Show Details"));
975 m_previewContextAction->setText(tr("Open File in External Application"));
976 m_findFileContextAction->setText(tr("Browse File Location"));
977 m_showFolderContextAction->setText(tr("Browse Selected Folder"));
978 m_refreshFolderContextAction->setText(tr("Refresh Directory Outline"));
979 m_addFavoriteFolderAction->setText(tr("Bookmark Current Output Folder"));
980 m_exportCsvContextAction->setText(tr("Export Meta Tags to CSV File"));
981 m_importCsvContextAction->setText(tr("Import Meta Tags from CSV File"));
984 m_metaInfoModel->clearData();
985 m_metaInfoModel->setData(m_metaInfoModel->index(4, 1), m_settings->metaInfoPosition());
986 updateEncoder(m_settings->compressionEncoder());
987 updateLameAlgoQuality(ui->sliderLameAlgoQuality->value());
988 updateMaximumInstances(ui->sliderMaxInstances->value());
989 renameOutputPatternChanged(ui->lineEditRenamePattern->text());
991 //Re-install shell integration
992 if(m_settings->shellIntegrationEnabled())
994 ShellIntegration::install();
997 //Translate system menu
998 if(HMENU hMenu = ::GetSystemMenu(winId(), FALSE))
1000 ModifyMenu(hMenu, IDM_ABOUTBOX, MF_STRING | MF_BYCOMMAND, IDM_ABOUTBOX, QWCHAR(ui->buttonAbout->text()));
1003 //Force resize, if needed
1004 tabPageChanged(ui->tabWidget->currentIndex());
1009 * File dragged over window
1011 void MainWindow::dragEnterEvent(QDragEnterEvent *event)
1013 QStringList formats = event->mimeData()->formats();
1015 if(formats.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive) && formats.contains("text/uri-list", Qt::CaseInsensitive))
1017 event->acceptProposedAction();
1022 * File dropped onto window
1024 void MainWindow::dropEvent(QDropEvent *event)
1028 QStringList droppedFiles;
1029 QList<QUrl> urls = event->mimeData()->urls();
1031 while(!urls.isEmpty())
1033 QUrl currentUrl = urls.takeFirst();
1034 QFileInfo file(currentUrl.toLocalFile());
1041 qDebug("Dropped File: %s", file.canonicalFilePath().toUtf8().constData());
1042 droppedFiles << file.canonicalFilePath();
1047 qDebug("Dropped Folder: %s", file.canonicalFilePath().toUtf8().constData());
1048 QList<QFileInfo> list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Files | QDir::NoSymLinks);
1049 if(list.count() > 0)
1051 for(int j = 0; j < list.count(); j++)
1053 droppedFiles << list.at(j).canonicalFilePath();
1058 list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
1059 for(int j = 0; j < list.count(); j++)
1061 qDebug("Descending to Folder: %s", list.at(j).canonicalFilePath().toUtf8().constData());
1062 urls.prepend(QUrl::fromLocalFile(list.at(j).canonicalFilePath()));
1068 if(!droppedFiles.isEmpty())
1070 addFilesDelayed(droppedFiles, true);
1075 * Window tries to close
1077 void MainWindow::closeEvent(QCloseEvent *event)
1079 if(m_banner->isVisible() || m_delayedFileTimer->isActive())
1081 MessageBeep(MB_ICONEXCLAMATION);
1092 * Window was resized
1094 void MainWindow::resizeEvent(QResizeEvent *event)
1096 if(event) QMainWindow::resizeEvent(event);
1097 m_dropNoteLabel->setGeometry(0, 0, ui->sourceFileView->width(), ui->sourceFileView->height());
1099 if(QWidget *port = ui->outputFolderView->viewport())
1101 m_outputFolderNoteBox->setGeometry(16, (port->height() - 64) / 2, port->width() - 32, 64);
1106 * Key press event filter
1108 void MainWindow::keyPressEvent(QKeyEvent *e)
1110 if(e->key() == Qt::Key_Delete)
1112 if(ui->sourceFileView->isVisible())
1114 QTimer::singleShot(0, this, SLOT(removeFileButtonClicked()));
1119 if(e->modifiers().testFlag(Qt::ControlModifier) && (e->key() == Qt::Key_F5))
1121 initializeTranslation();
1122 MessageBeep(MB_ICONINFORMATION);
1126 if(e->key() == Qt::Key_F5)
1128 if(ui->outputFolderView->isVisible())
1130 QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
1135 QMainWindow::keyPressEvent(e);
1141 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
1143 if(obj == m_fileSystemModel)
1145 if(QApplication::overrideCursor() == NULL)
1147 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1148 QTimer::singleShot(250, this, SLOT(restoreCursor()));
1152 return QMainWindow::eventFilter(obj, event);
1155 bool MainWindow::event(QEvent *e)
1159 case lamexp_event_queryendsession:
1160 qWarning("System is shutting down, main window prepares to close...");
1161 if(m_banner->isVisible()) m_banner->close();
1162 if(m_delayedFileTimer->isActive()) m_delayedFileTimer->stop();
1164 case lamexp_event_endsession:
1165 qWarning("System is shutting down, main window will close now...");
1170 QApplication::processEvents(QEventLoop::WaitForMoreEvents & QEventLoop::ExcludeUserInputEvents);
1173 m_fileListModel->clearFiles();
1175 case QEvent::MouseButtonPress:
1176 if(ui->outputFolderEdit->isVisible())
1178 QTimer::singleShot(0, this, SLOT(outputFolderEditFinished()));
1181 return QMainWindow::event(e);
1185 bool MainWindow::winEvent(MSG *message, long *result)
1187 if((message->message == WM_SYSCOMMAND) && ((message->wParam & 0xFFF0) == IDM_ABOUTBOX))
1189 QTimer::singleShot(0, ui->buttonAbout, SLOT(click()));
1193 return WinSevenTaskbar::handleWinEvent(message, result);
1196 ////////////////////////////////////////////////////////////
1198 ////////////////////////////////////////////////////////////
1200 // =========================================================
1201 // Show window slots
1202 // =========================================================
1207 void MainWindow::windowShown(void)
1209 const QStringList &arguments = lamexp_arguments(); //QApplication::arguments();
1212 bool firstRun = false;
1213 for(int i = 0; i < arguments.count(); i++)
1215 /*QMessageBox::information(this, QString::number(i), arguments[i]);*/
1216 if(!arguments[i].compare("--first-run", Qt::CaseInsensitive)) firstRun = true;
1220 if((m_settings->licenseAccepted() <= 0) || firstRun)
1222 int iAccepted = m_settings->licenseAccepted();
1224 if((iAccepted == 0) || firstRun)
1226 AboutDialog *about = new AboutDialog(m_settings, this, true);
1227 iAccepted = about->exec();
1228 if(iAccepted <= 0) iAccepted = -2;
1229 LAMEXP_DELETE(about);
1234 m_settings->licenseAccepted(++iAccepted);
1235 m_settings->syncNow();
1236 QApplication::processEvents();
1237 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1238 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
1239 QFileInfo uninstallerInfo = QFileInfo(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()));
1240 if(uninstallerInfo.exists())
1242 QString uninstallerDir = uninstallerInfo.canonicalPath();
1243 QString uninstallerPath = uninstallerInfo.canonicalFilePath();
1244 for(int i = 0; i < 3; i++)
1246 HINSTANCE res = ShellExecuteW(reinterpret_cast<HWND>(this->winId()), L"open", QWCHAR(QDir::toNativeSeparators(uninstallerPath)), L"/Force", QWCHAR(QDir::toNativeSeparators(uninstallerDir)), SW_SHOWNORMAL);
1247 if(reinterpret_cast<int>(res) > 32) break;
1250 QApplication::quit();
1254 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WOOHOO), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1255 m_settings->licenseAccepted(1);
1256 m_settings->syncNow();
1257 if(lamexp_version_demo()) showAnnounceBox();
1260 //Check for expiration
1261 if(lamexp_version_demo())
1263 if(QDate::currentDate() >= lamexp_version_expires())
1265 qWarning("Binary has expired !!!");
1266 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1267 if(QMessageBox::warning(this, tr("LameXP - Expired"), QString("%1<br>%2").arg(NOBR(tr("This demo (pre-release) version of LameXP has expired at %1.").arg(lamexp_version_expires().toString(Qt::ISODate))), NOBR(tr("LameXP is free software and release versions won't expire."))), tr("Check for Updates"), tr("Exit Program")) == 0)
1271 QApplication::quit();
1276 //Slow startup indicator
1277 if(m_settings->slowStartup() && m_settings->antivirNotificationsEnabled())
1280 message += NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
1281 message += NOBR(tr("Please refer to the %1 document for details and solutions!")).arg("<a href=\"http://lamexp.sourceforge.net/doc/FAQ.html#df406578\">F.A.Q.</a>").append("<br>");
1282 if(QMessageBox::warning(this, tr("Slow Startup"), message, tr("Discard"), tr("Don't Show Again")) == 1)
1284 m_settings->antivirNotificationsEnabled(false);
1285 ui->actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
1290 if(QDate::currentDate() >= lamexp_version_date().addYears(1))
1292 qWarning("Binary is more than a year old, time to update!");
1293 int ret = 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"), tr("Ignore"));
1297 if(checkForUpdates())
1299 QApplication::quit();
1304 QApplication::quit();
1307 QEventLoop loop; QTimer::singleShot(7000, &loop, SLOT(quit()));
1308 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WAITING), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
1309 m_banner->show(tr("Skipping update check this time, please be patient..."), &loop);
1313 else if(m_settings->autoUpdateEnabled())
1315 QDate lastUpdateCheck = QDate::fromString(m_settings->autoUpdateLastCheck(), Qt::ISODate);
1316 if(!firstRun && (!lastUpdateCheck.isValid() || QDate::currentDate() >= lastUpdateCheck.addDays(14)))
1318 if(QMessageBox::information(this, tr("Update Reminder"), NOBR(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?")), tr("Check for Updates"), tr("Postpone")) == 0)
1320 if(checkForUpdates())
1322 QApplication::quit();
1329 //Check for AAC support
1330 if(m_neroEncoderAvailable)
1332 if(m_settings->neroAacNotificationsEnabled())
1334 if(lamexp_tool_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1336 QString messageText;
1337 messageText += NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1338 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>");
1339 messageText += NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1340 messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br><br>";
1341 messageText += NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
1342 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText);
1348 if(m_settings->neroAacNotificationsEnabled() && (!(m_fhgEncoderAvailable || m_qaacEncoderAvailable)))
1350 QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1351 if(appPath.isEmpty()) appPath = QCoreApplication::applicationDirPath();
1352 QString messageText;
1353 messageText += NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1354 messageText += NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1355 messageText += NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1356 messageText += QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath)));
1357 messageText += NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1358 messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br>";
1359 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText, tr("Discard"), tr("Don't Show Again")) == 1)
1361 m_settings->neroAacNotificationsEnabled(false);
1362 ui->actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
1367 //Add files from the command-line
1368 for(int i = 0; i < arguments.count() - 1; i++)
1370 QStringList addedFiles;
1371 if(!arguments[i].compare("--add", Qt::CaseInsensitive))
1373 QFileInfo currentFile(arguments[++i].trimmed());
1374 qDebug("Adding file from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1375 addedFiles.append(currentFile.absoluteFilePath());
1377 if(!addedFiles.isEmpty())
1379 addFilesDelayed(addedFiles);
1383 //Add folders from the command-line
1384 for(int i = 0; i < arguments.count() - 1; i++)
1386 if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
1388 QFileInfo currentFile(arguments[++i].trimmed());
1389 qDebug("Adding folder from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1390 addFolder(currentFile.absoluteFilePath(), false, true);
1392 if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
1394 QFileInfo currentFile(arguments[++i].trimmed());
1395 qDebug("Adding folder recursively from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1396 addFolder(currentFile.absoluteFilePath(), true, true);
1400 //Enable shell integration
1401 if(m_settings->shellIntegrationEnabled())
1403 ShellIntegration::install();
1406 //Make DropBox visible
1407 if(m_settings->dropBoxWidgetEnabled())
1409 m_dropBox->setVisible(true);
1416 void MainWindow::showAnnounceBox(void)
1418 const unsigned int timeout = 8U;
1420 const QString announceText = QString("%1<br><br>%2<br><nobr><tt>%3</tt></nobr><br>").arg
1422 NOBR("We are still looking for LameXP translators!"),
1423 NOBR("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:"),
1424 LINK("http://lamexp.sourceforge.net/doc/Translate.html")
1427 QMessageBox *announceBox = new QMessageBox(QMessageBox::Warning, "We want you!", announceText, QMessageBox::NoButton, this);
1428 announceBox->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
1429 announceBox->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1431 QTimer *timers[timeout+1];
1432 QPushButton *buttons[timeout+1];
1434 for(unsigned int i = 0; i <= timeout; i++)
1436 QString text = (i > 0) ? QString("%1 (%2)").arg(tr("Discard"), QString::number(i)) : tr("Discard");
1437 buttons[i] = announceBox->addButton(text, (i > 0) ? QMessageBox::NoRole : QMessageBox::AcceptRole);
1440 for(unsigned int i = 0; i <= timeout; i++)
1442 buttons[i]->setEnabled(i == 0);
1443 buttons[i]->setVisible(i == timeout);
1446 for(unsigned int i = 0; i < timeout; i++)
1448 timers[i] = new QTimer(this);
1449 timers[i]->setSingleShot(true);
1450 timers[i]->setInterval(1000);
1451 connect(timers[i], SIGNAL(timeout()), buttons[i+1], SLOT(hide()));
1452 connect(timers[i], SIGNAL(timeout()), buttons[i], SLOT(show()));
1455 connect(timers[i], SIGNAL(timeout()), timers[i-1], SLOT(start()));
1459 timers[timeout-1]->start();
1460 announceBox->exec();
1462 for(unsigned int i = 0; i < timeout; i++)
1465 LAMEXP_DELETE(timers[i]);
1468 LAMEXP_DELETE(announceBox);
1471 // =========================================================
1472 // Main button solots
1473 // =========================================================
1478 void MainWindow::encodeButtonClicked(void)
1480 static const unsigned __int64 oneGigabyte = 1073741824ui64;
1481 static const unsigned __int64 minimumFreeDiskspaceMultiplier = 2ui64;
1482 static const char *writeTestBuffer = "LAMEXP_WRITE_TEST";
1486 if(m_fileListModel->rowCount() < 1)
1488 QMessageBox::warning(this, tr("LameXP"), NOBR(tr("You must add at least one file to the list before proceeding!")));
1489 ui->tabWidget->setCurrentIndex(0);
1493 QString tempFolder = m_settings->customTempPathEnabled() ? m_settings->customTempPath() : lamexp_temp_folder2();
1494 if(!QFileInfo(tempFolder).exists() || !QFileInfo(tempFolder).isDir())
1496 if(QMessageBox::warning(this, tr("Not Found"), QString("%1<br><tt>%2</tt>").arg(NOBR(tr("Your currently selected TEMP folder does not exist anymore:")), NOBR(QDir::toNativeSeparators(tempFolder))), tr("Restore Default"), tr("Cancel")) == 0)
1498 SET_CHECKBOX_STATE(ui->checkBoxUseSystemTempFolder, m_settings->customTempPathEnabledDefault());
1504 unsigned __int64 currentFreeDiskspace = lamexp_free_diskspace(tempFolder, &ok);
1506 if(ok && (currentFreeDiskspace < (oneGigabyte * minimumFreeDiskspaceMultiplier)))
1508 QStringList tempFolderParts = tempFolder.split("/", QString::SkipEmptyParts, Qt::CaseInsensitive);
1509 tempFolderParts.takeLast();
1510 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1511 QString lowDiskspaceMsg = QString("%1<br>%2<br><br>%3<br>%4<br>").arg
1513 NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier))),
1514 NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")),
1515 NOBR(tr("Your TEMP folder is located at:")),
1516 QString("<nobr><tt>%1</tt></nobr>").arg(FSLINK(tempFolderParts.join("\\")))
1518 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1521 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(lamexp_known_folder(lamexp_folder_systemfolder)), QStringList() << "/D" << tempFolderParts.first());
1526 QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!")));
1531 switch(m_settings->compressionEncoder())
1533 case SettingsModel::MP3Encoder:
1534 case SettingsModel::VorbisEncoder:
1535 case SettingsModel::AACEncoder:
1536 case SettingsModel::AC3Encoder:
1537 case SettingsModel::FLACEncoder:
1538 case SettingsModel::OpusEncoder:
1539 case SettingsModel::DCAEncoder:
1540 case SettingsModel::PCMEncoder:
1543 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1544 ui->tabWidget->setCurrentIndex(3);
1548 if(!m_settings->outputToSourceDir())
1550 QFile writeTest(QString("%1/~%2.txt").arg(m_settings->outputDir(), lamexp_rand_str()));
1551 if(!(writeTest.open(QIODevice::ReadWrite) && (writeTest.write(writeTestBuffer) == strlen(writeTestBuffer))))
1553 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!")));
1554 ui->tabWidget->setCurrentIndex(1);
1571 void MainWindow::aboutButtonClicked(void)
1577 AboutDialog *aboutBox = new AboutDialog(m_settings, this);
1579 LAMEXP_DELETE(aboutBox);
1586 void MainWindow::closeButtonClicked(void)
1592 // =========================================================
1594 // =========================================================
1599 void MainWindow::tabPageChanged(int idx)
1603 QList<QAction*> actions = m_tabActionGroup->actions();
1604 for(int i = 0; i < actions.count(); i++)
1607 int actionIndex = actions.at(i)->data().toInt(&ok);
1608 if(ok && actionIndex == idx)
1610 actions.at(i)->setChecked(true);
1614 int initialWidth = this->width();
1615 int maximumWidth = QApplication::desktop()->availableGeometry().width();
1617 //Make sure all tab headers are fully visible
1618 if(this->isVisible())
1620 int delta = ui->tabWidget->sizeHint().width() - ui->tabWidget->width();
1623 this->resize(qMin(this->width() + delta, maximumWidth), this->height());
1627 //Tab specific operations
1628 if(idx == ui->tabWidget->indexOf(ui->tabOptions) && ui->scrollArea->widget() && this->isVisible())
1630 ui->scrollArea->widget()->updateGeometry();
1631 ui->scrollArea->viewport()->updateGeometry();
1632 qApp->processEvents();
1633 int delta = ui->scrollArea->widget()->width() - ui->scrollArea->viewport()->width();
1636 this->resize(qMin(this->width() + delta, maximumWidth), this->height());
1639 else if(idx == ui->tabWidget->indexOf(ui->tabSourceFiles))
1641 m_dropNoteLabel->setGeometry(0, 0, ui->sourceFileView->width(), ui->sourceFileView->height());
1643 else if(idx == ui->tabWidget->indexOf(ui->tabOutputDir))
1645 if(!m_fileSystemModel)
1647 QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
1651 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
1655 //Center window around previous position
1656 if(initialWidth < this->width())
1658 QPoint prevPos = this->pos();
1659 int delta = (this->width() - initialWidth) >> 2;
1660 move(prevPos.x() - delta, prevPos.y());
1665 * Tab action triggered
1667 void MainWindow::tabActionActivated(QAction *action)
1669 if(action && action->data().isValid())
1672 int index = action->data().toInt(&ok);
1675 ui->tabWidget->setCurrentIndex(index);
1680 // =========================================================
1682 // =========================================================
1685 * Style action triggered
1687 void MainWindow::styleActionActivated(QAction *action)
1689 //Change style setting
1690 if(action && action->data().isValid())
1693 int actionIndex = action->data().toInt(&ok);
1696 m_settings->interfaceStyle(actionIndex);
1700 //Set up the new style
1701 switch(m_settings->interfaceStyle())
1704 if(ui->actionStyleCleanlooks->isEnabled())
1706 ui->actionStyleCleanlooks->setChecked(true);
1707 QApplication::setStyle(new QCleanlooksStyle());
1711 if(ui->actionStyleWindowsVista->isEnabled())
1713 ui->actionStyleWindowsVista->setChecked(true);
1714 QApplication::setStyle(new QWindowsVistaStyle());
1718 if(ui->actionStyleWindowsXP->isEnabled())
1720 ui->actionStyleWindowsXP->setChecked(true);
1721 QApplication::setStyle(new QWindowsXPStyle());
1725 if(ui->actionStyleWindowsClassic->isEnabled())
1727 ui->actionStyleWindowsClassic->setChecked(true);
1728 QApplication::setStyle(new QWindowsStyle());
1732 ui->actionStylePlastique->setChecked(true);
1733 QApplication::setStyle(new QPlastiqueStyle());
1737 //Force re-translate after style change
1738 if(QEvent *e = new QEvent(QEvent::LanguageChange))
1746 * Language action triggered
1748 void MainWindow::languageActionActivated(QAction *action)
1750 if(action->data().type() == QVariant::String)
1752 QString langId = action->data().toString();
1754 if(lamexp_install_translator(langId))
1756 action->setChecked(true);
1757 ui->actionLoadTranslationFromFile->setChecked(false);
1758 m_settings->currentLanguage(langId);
1759 m_settings->currentLanguageFile(QString());
1765 * Load language from file action triggered
1767 void MainWindow::languageFromFileActionActivated(bool checked)
1769 QFileDialog dialog(this, tr("Load Translation"));
1770 dialog.setFileMode(QFileDialog::ExistingFile);
1771 dialog.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
1775 QStringList selectedFiles = dialog.selectedFiles();
1776 const QString qmFile = QFileInfo(selectedFiles.first()).canonicalFilePath();
1777 if(lamexp_install_translator_from_file(qmFile))
1779 QList<QAction*> actions = m_languageActionGroup->actions();
1780 while(!actions.isEmpty())
1782 actions.takeFirst()->setChecked(false);
1784 ui->actionLoadTranslationFromFile->setChecked(true);
1785 m_settings->currentLanguageFile(qmFile);
1789 languageActionActivated(m_languageActionGroup->actions().first());
1794 // =========================================================
1796 // =========================================================
1799 * Disable update reminder action
1801 void MainWindow::disableUpdateReminderActionTriggered(bool checked)
1805 if(0 == QMessageBox::question(this, tr("Disable Update Reminder"), NOBR(tr("Do you really want to disable the update reminder?")), tr("Yes"), tr("No"), QString(), 1))
1807 QMessageBox::information(this, tr("Update Reminder"), QString("%1<br>%2").arg(NOBR(tr("The update reminder has been disabled.")), NOBR(tr("Please remember to check for updates at regular intervals!"))));
1808 m_settings->autoUpdateEnabled(false);
1812 m_settings->autoUpdateEnabled(true);
1817 QMessageBox::information(this, tr("Update Reminder"), NOBR(tr("The update reminder has been re-enabled.")));
1818 m_settings->autoUpdateEnabled(true);
1821 ui->actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
1825 * Disable sound effects action
1827 void MainWindow::disableSoundsActionTriggered(bool checked)
1831 if(0 == QMessageBox::question(this, tr("Disable Sound Effects"), NOBR(tr("Do you really want to disable all sound effects?")), tr("Yes"), tr("No"), QString(), 1))
1833 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("All sound effects have been disabled.")));
1834 m_settings->soundsEnabled(false);
1838 m_settings->soundsEnabled(true);
1843 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("The sound effects have been re-enabled.")));
1844 m_settings->soundsEnabled(true);
1847 ui->actionDisableSounds->setChecked(!m_settings->soundsEnabled());
1851 * Disable Nero AAC encoder action
1853 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked)
1857 if(0 == QMessageBox::question(this, tr("Nero AAC Notifications"), NOBR(tr("Do you really want to disable all Nero AAC Encoder notifications?")), tr("Yes"), tr("No"), QString(), 1))
1859 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("All Nero AAC Encoder notifications have been disabled.")));
1860 m_settings->neroAacNotificationsEnabled(false);
1864 m_settings->neroAacNotificationsEnabled(true);
1869 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("The Nero AAC Encoder notifications have been re-enabled.")));
1870 m_settings->neroAacNotificationsEnabled(true);
1873 ui->actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
1877 * Disable slow startup action
1879 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked)
1883 if(0 == QMessageBox::question(this, tr("Slow Startup Notifications"), NOBR(tr("Do you really want to disable the slow startup notifications?")), tr("Yes"), tr("No"), QString(), 1))
1885 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been disabled.")));
1886 m_settings->antivirNotificationsEnabled(false);
1890 m_settings->antivirNotificationsEnabled(true);
1895 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been re-enabled.")));
1896 m_settings->antivirNotificationsEnabled(true);
1899 ui->actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
1903 * Import a Cue Sheet file
1905 void MainWindow::importCueSheetActionTriggered(bool checked)
1914 QString selectedCueFile;
1916 if(USE_NATIVE_FILE_DIALOG)
1918 selectedCueFile = QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1922 QFileDialog dialog(this, tr("Open Cue Sheet"));
1923 dialog.setFileMode(QFileDialog::ExistingFile);
1924 dialog.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1925 dialog.setDirectory(m_settings->mostRecentInputPath());
1928 selectedCueFile = dialog.selectedFiles().first();
1932 if(!selectedCueFile.isEmpty())
1934 m_settings->mostRecentInputPath(QFileInfo(selectedCueFile).canonicalPath());
1935 CueImportDialog *cueImporter = new CueImportDialog(this, m_fileListModel, selectedCueFile);
1936 result = cueImporter->exec();
1937 LAMEXP_DELETE(cueImporter);
1940 if(result != (-1)) break;
1946 * Show the "drop box" widget
1948 void MainWindow::showDropBoxWidgetActionTriggered(bool checked)
1950 m_settings->dropBoxWidgetEnabled(true);
1952 if(!m_dropBox->isVisible())
1957 lamexp_blink_window(m_dropBox);
1961 * Check for beta (pre-release) updates
1963 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked)
1965 bool checkUpdatesNow = false;
1969 if(0 == QMessageBox::question(this, tr("Beta Updates"), NOBR(tr("Do you really want LameXP to check for Beta (pre-release) updates?")), tr("Yes"), tr("No"), QString(), 1))
1971 if(0 == QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will check for Beta (pre-release) updates from now on.")), tr("Check Now"), tr("Discard")))
1973 checkUpdatesNow = true;
1975 m_settings->autoUpdateCheckBeta(true);
1979 m_settings->autoUpdateCheckBeta(false);
1984 QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on.")));
1985 m_settings->autoUpdateCheckBeta(false);
1988 ui->actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta());
1992 if(checkForUpdates())
1994 QApplication::quit();
2000 * Hibernate computer action
2002 void MainWindow::hibernateComputerActionTriggered(bool checked)
2006 if(0 == QMessageBox::question(this, tr("Hibernate Computer"), NOBR(tr("Do you really want the computer to be hibernated on shutdown?")), tr("Yes"), tr("No"), QString(), 1))
2008 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will hibernate the computer on shutdown from now on.")));
2009 m_settings->hibernateComputer(true);
2013 m_settings->hibernateComputer(false);
2018 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will <i>not</i> hibernate the computer on shutdown from now on.")));
2019 m_settings->hibernateComputer(false);
2022 ui->actionHibernateComputer->setChecked(m_settings->hibernateComputer());
2026 * Disable shell integration action
2028 void MainWindow::disableShellIntegrationActionTriggered(bool checked)
2032 if(0 == QMessageBox::question(this, tr("Shell Integration"), NOBR(tr("Do you really want to disable the LameXP shell integration?")), tr("Yes"), tr("No"), QString(), 1))
2034 ShellIntegration::remove();
2035 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been disabled.")));
2036 m_settings->shellIntegrationEnabled(false);
2040 m_settings->shellIntegrationEnabled(true);
2045 ShellIntegration::install();
2046 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been re-enabled.")));
2047 m_settings->shellIntegrationEnabled(true);
2050 ui->actionDisableShellIntegration->setChecked(!m_settings->shellIntegrationEnabled());
2052 if(lamexp_portable_mode() && ui->actionDisableShellIntegration->isChecked())
2054 ui->actionDisableShellIntegration->setEnabled(false);
2058 // =========================================================
2060 // =========================================================
2063 * Visit homepage action
2065 void MainWindow::visitHomepageActionActivated(void)
2067 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
2069 if(action->data().isValid() && (action->data().type() == QVariant::String))
2071 QDesktopServices::openUrl(QUrl(action->data().toString()));
2079 void MainWindow::documentActionActivated(void)
2081 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
2083 if(action->data().isValid() && (action->data().type() == QVariant::String))
2085 QFileInfo document(action->data().toString());
2086 QFileInfo resource(QString(":/doc/%1.html").arg(document.baseName()));
2087 if(document.exists() && document.isFile() && (document.size() == resource.size()))
2089 QDesktopServices::openUrl(QUrl::fromLocalFile(document.canonicalFilePath()));
2093 QFile source(resource.filePath());
2094 QFile output(QString("%1/%2.%3.html").arg(lamexp_temp_folder2(), document.baseName(), lamexp_rand_str().left(8)));
2095 if(source.open(QIODevice::ReadOnly) && output.open(QIODevice::ReadWrite))
2097 output.write(source.readAll());
2098 action->setData(output.fileName());
2101 QDesktopServices::openUrl(QUrl::fromLocalFile(output.fileName()));
2109 * Check for updates action
2111 void MainWindow::checkUpdatesActionActivated(void)
2118 bFlag = checkForUpdates();
2123 QApplication::quit();
2127 // =========================================================
2128 // Source file slots
2129 // =========================================================
2132 * Add file(s) button
2134 void MainWindow::addFilesButtonClicked(void)
2140 if(USE_NATIVE_FILE_DIALOG)
2142 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
2143 QStringList selectedFiles = QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings->mostRecentInputPath(), fileTypeFilters.join(";;"));
2144 if(!selectedFiles.isEmpty())
2146 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
2147 addFiles(selectedFiles);
2152 QFileDialog dialog(this, tr("Add file(s)"));
2153 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
2154 dialog.setFileMode(QFileDialog::ExistingFiles);
2155 dialog.setNameFilter(fileTypeFilters.join(";;"));
2156 dialog.setDirectory(m_settings->mostRecentInputPath());
2159 QStringList selectedFiles = dialog.selectedFiles();
2160 if(!selectedFiles.isEmpty())
2162 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
2163 addFiles(selectedFiles);
2171 * Open folder action
2173 void MainWindow::openFolderActionActivated(void)
2176 QString selectedFolder;
2178 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
2182 if(USE_NATIVE_FILE_DIALOG)
2184 selectedFolder = QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings->mostRecentInputPath());
2188 QFileDialog dialog(this, tr("Add Folder"));
2189 dialog.setFileMode(QFileDialog::DirectoryOnly);
2190 dialog.setDirectory(m_settings->mostRecentInputPath());
2193 selectedFolder = dialog.selectedFiles().first();
2197 if(!selectedFolder.isEmpty())
2199 m_settings->mostRecentInputPath(QDir(selectedFolder).canonicalPath());
2200 addFolder(selectedFolder, action->data().toBool());
2207 * Remove file button
2209 void MainWindow::removeFileButtonClicked(void)
2211 if(ui->sourceFileView->currentIndex().isValid())
2213 int iRow = ui->sourceFileView->currentIndex().row();
2214 m_fileListModel->removeFile(ui->sourceFileView->currentIndex());
2215 ui->sourceFileView->selectRow(iRow < m_fileListModel->rowCount() ? iRow : m_fileListModel->rowCount()-1);
2220 * Clear files button
2222 void MainWindow::clearFilesButtonClicked(void)
2224 m_fileListModel->clearFiles();
2228 * Move file up button
2230 void MainWindow::fileUpButtonClicked(void)
2232 if(ui->sourceFileView->currentIndex().isValid())
2234 int iRow = ui->sourceFileView->currentIndex().row() - 1;
2235 m_fileListModel->moveFile(ui->sourceFileView->currentIndex(), -1);
2236 ui->sourceFileView->selectRow(iRow >= 0 ? iRow : 0);
2241 * Move file down button
2243 void MainWindow::fileDownButtonClicked(void)
2245 if(ui->sourceFileView->currentIndex().isValid())
2247 int iRow = ui->sourceFileView->currentIndex().row() + 1;
2248 m_fileListModel->moveFile(ui->sourceFileView->currentIndex(), 1);
2249 ui->sourceFileView->selectRow(iRow < m_fileListModel->rowCount() ? iRow : m_fileListModel->rowCount()-1);
2254 * Show details button
2256 void MainWindow::showDetailsButtonClicked(void)
2261 MetaInfoDialog *metaInfoDialog = new MetaInfoDialog(this);
2262 QModelIndex index = ui->sourceFileView->currentIndex();
2264 while(index.isValid())
2268 index = m_fileListModel->index(index.row() + 1, index.column());
2269 ui->sourceFileView->selectRow(index.row());
2273 index = m_fileListModel->index(index.row() - 1, index.column());
2274 ui->sourceFileView->selectRow(index.row());
2277 AudioFileModel &file = (*m_fileListModel)[index];
2280 iResult = metaInfoDialog->exec(file, index.row() > 0, index.row() < m_fileListModel->rowCount() - 1);
2283 if(iResult == INT_MAX)
2285 m_metaInfoModel->assignInfoFrom(file);
2286 ui->tabWidget->setCurrentIndex(ui->tabWidget->indexOf(ui->tabMetaData));
2293 LAMEXP_DELETE(metaInfoDialog);
2294 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2295 sourceFilesScrollbarMoved(0);
2299 * Show context menu for source files
2301 void MainWindow::sourceFilesContextMenu(const QPoint &pos)
2303 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
2304 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
2308 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
2310 m_sourceFilesContextMenu->popup(sender->mapToGlobal(pos));
2316 * Scrollbar of source files moved
2318 void MainWindow::sourceFilesScrollbarMoved(int)
2320 ui->sourceFileView->resizeColumnToContents(0);
2324 * Open selected file in external player
2326 void MainWindow::previewContextActionTriggered(void)
2328 const static char *appNames[3] = {"smplayer_portable.exe", "smplayer.exe", "mplayer.exe"};
2329 const static wchar_t *registryKey = L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{DB9E4EAB-2717-499F-8D56-4CC8A644AB60}";
2331 QModelIndex index = ui->sourceFileView->currentIndex();
2332 if(!index.isValid())
2337 QString mplayerPath;
2338 HKEY registryKeyHandle;
2340 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryKey, 0, KEY_READ, ®istryKeyHandle) == ERROR_SUCCESS)
2342 wchar_t Buffer[4096];
2343 DWORD BuffSize = sizeof(wchar_t*) * 4096;
2344 if(RegQueryValueExW(registryKeyHandle, L"InstallLocation", 0, 0, reinterpret_cast<BYTE*>(Buffer), &BuffSize) == ERROR_SUCCESS)
2346 mplayerPath = QString::fromUtf16(reinterpret_cast<const unsigned short*>(Buffer));
2350 if(!mplayerPath.isEmpty())
2352 QDir mplayerDir(mplayerPath);
2353 if(mplayerDir.exists())
2355 for(int i = 0; i < 3; i++)
2357 if(mplayerDir.exists(appNames[i]))
2359 QProcess::startDetached(mplayerDir.absoluteFilePath(appNames[i]), QStringList() << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
2366 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel->getFile(index).filePath()));
2370 * Find selected file in explorer
2372 void MainWindow::findFileContextActionTriggered(void)
2374 QModelIndex index = ui->sourceFileView->currentIndex();
2377 QString systemRootPath;
2379 QDir systemRoot(lamexp_known_folder(lamexp_folder_systemfolder));
2380 if(systemRoot.exists() && systemRoot.cdUp())
2382 systemRootPath = systemRoot.canonicalPath();
2385 if(!systemRootPath.isEmpty())
2387 QFileInfo explorer(QString("%1/explorer.exe").arg(systemRootPath));
2388 if(explorer.exists() && explorer.isFile())
2390 QProcess::execute(explorer.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
2396 qWarning("SystemRoot directory could not be detected!");
2402 * Add all pending files
2404 void MainWindow::handleDelayedFiles(void)
2406 m_delayedFileTimer->stop();
2408 if(m_delayedFileList->isEmpty())
2413 if(m_banner->isVisible())
2415 m_delayedFileTimer->start(5000);
2419 QStringList selectedFiles;
2420 ui->tabWidget->setCurrentIndex(0);
2422 while(!m_delayedFileList->isEmpty())
2424 QFileInfo currentFile = QFileInfo(m_delayedFileList->takeFirst());
2425 if(!currentFile.exists() || !currentFile.isFile())
2429 selectedFiles << currentFile.canonicalFilePath();
2432 addFiles(selectedFiles);
2436 * Export Meta tags to CSV file
2438 void MainWindow::exportCsvContextActionTriggered(void)
2442 QString selectedCsvFile;
2444 if(USE_NATIVE_FILE_DIALOG)
2446 selectedCsvFile = QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2450 QFileDialog dialog(this, tr("Save CSV file"));
2451 dialog.setFileMode(QFileDialog::AnyFile);
2452 dialog.setAcceptMode(QFileDialog::AcceptSave);
2453 dialog.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2454 dialog.setDirectory(m_settings->mostRecentInputPath());
2457 selectedCsvFile = dialog.selectedFiles().first();
2461 if(!selectedCsvFile.isEmpty())
2463 m_settings->mostRecentInputPath(QFileInfo(selectedCsvFile).canonicalPath());
2464 switch(m_fileListModel->exportToCsv(selectedCsvFile))
2466 case FileListModel::CsvError_NoTags:
2467 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, there are no meta tags that can be exported!")));
2469 case FileListModel::CsvError_FileOpen:
2470 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to open CSV file for writing!")));
2472 case FileListModel::CsvError_FileWrite:
2473 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to write to the CSV file!")));
2475 case FileListModel::CsvError_OK:
2476 QMessageBox::information(this, tr("CSV Export"), NOBR(tr("The CSV files was created successfully!")));
2479 qWarning("exportToCsv: Unknown return code!");
2487 * Import Meta tags from CSV file
2489 void MainWindow::importCsvContextActionTriggered(void)
2493 QString selectedCsvFile;
2495 if(USE_NATIVE_FILE_DIALOG)
2497 selectedCsvFile = QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2501 QFileDialog dialog(this, tr("Open CSV file"));
2502 dialog.setFileMode(QFileDialog::ExistingFile);
2503 dialog.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2504 dialog.setDirectory(m_settings->mostRecentInputPath());
2507 selectedCsvFile = dialog.selectedFiles().first();
2511 if(!selectedCsvFile.isEmpty())
2513 m_settings->mostRecentInputPath(QFileInfo(selectedCsvFile).canonicalPath());
2514 switch(m_fileListModel->importFromCsv(this, selectedCsvFile))
2516 case FileListModel::CsvError_FileOpen:
2517 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to open CSV file for reading!")));
2519 case FileListModel::CsvError_FileRead:
2520 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to read from the CSV file!")));
2522 case FileListModel::CsvError_NoTags:
2523 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, the CSV file does not contain any known fields!")));
2525 case FileListModel::CsvError_Incomplete:
2526 QMessageBox::warning(this, tr("CSV Import"), NOBR(tr("CSV file is incomplete. Not all files were updated!")));
2528 case FileListModel::CsvError_OK:
2529 QMessageBox::information(this, tr("CSV Import"), NOBR(tr("The CSV files was imported successfully!")));
2531 case FileListModel::CsvError_Aborted:
2532 /* User aborted, ignore! */
2535 qWarning("exportToCsv: Unknown return code!");
2542 * Show or hide Drag'n'Drop notice after model reset
2544 void MainWindow::sourceModelChanged(void)
2546 m_dropNoteLabel->setVisible(m_fileListModel->rowCount() <= 0);
2549 // =========================================================
2550 // Output folder slots
2551 // =========================================================
2554 * Output folder changed (mouse clicked)
2556 void MainWindow::outputFolderViewClicked(const QModelIndex &index)
2558 if(index.isValid() && (ui->outputFolderView->currentIndex() != index))
2560 ui->outputFolderView->setCurrentIndex(index);
2563 if(m_fileSystemModel && index.isValid())
2565 QString selectedDir = m_fileSystemModel->filePath(index);
2566 if(selectedDir.length() < 3) selectedDir.append(QDir::separator());
2567 ui->outputFolderLabel->setText(QDir::toNativeSeparators(selectedDir));
2568 m_settings->outputDir(selectedDir);
2572 ui->outputFolderLabel->setText(QDir::toNativeSeparators(m_settings->outputDir()));
2577 * Output folder changed (mouse moved)
2579 void MainWindow::outputFolderViewMoved(const QModelIndex &index)
2581 if(QApplication::mouseButtons() & Qt::LeftButton)
2583 outputFolderViewClicked(index);
2588 * Goto desktop button
2590 void MainWindow::gotoDesktopButtonClicked(void)
2592 if(!m_fileSystemModel)
2594 qWarning("File system model not initialized yet!");
2598 QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
2600 if(!desktopPath.isEmpty() && QDir(desktopPath).exists())
2602 ui->outputFolderView->setCurrentIndex(m_fileSystemModel->index(desktopPath));
2603 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2604 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2608 ui->buttonGotoDesktop->setEnabled(false);
2613 * Goto home folder button
2615 void MainWindow::gotoHomeFolderButtonClicked(void)
2617 if(!m_fileSystemModel)
2619 qWarning("File system model not initialized yet!");
2623 QString homePath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
2625 if(!homePath.isEmpty() && QDir(homePath).exists())
2627 ui->outputFolderView->setCurrentIndex(m_fileSystemModel->index(homePath));
2628 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2629 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2633 ui->buttonGotoHome->setEnabled(false);
2638 * Goto music folder button
2640 void MainWindow::gotoMusicFolderButtonClicked(void)
2642 if(!m_fileSystemModel)
2644 qWarning("File system model not initialized yet!");
2648 QString musicPath = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
2650 if(!musicPath.isEmpty() && QDir(musicPath).exists())
2652 ui->outputFolderView->setCurrentIndex(m_fileSystemModel->index(musicPath));
2653 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2654 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2658 ui->buttonGotoMusic->setEnabled(false);
2663 * Goto music favorite output folder
2665 void MainWindow::gotoFavoriteFolder(void)
2667 if(!m_fileSystemModel)
2669 qWarning("File system model not initialized yet!");
2673 QAction *item = dynamic_cast<QAction*>(QObject::sender());
2677 QDir path(item->data().toString());
2680 ui->outputFolderView->setCurrentIndex(m_fileSystemModel->index(path.canonicalPath()));
2681 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2682 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2686 MessageBeep(MB_ICONERROR);
2687 m_outputFolderFavoritesMenu->removeAction(item);
2688 item->deleteLater();
2694 * Make folder button
2696 void MainWindow::makeFolderButtonClicked(void)
2700 if(!m_fileSystemModel)
2702 qWarning("File system model not initialized yet!");
2706 QDir basePath(m_fileSystemModel->fileInfo(ui->outputFolderView->currentIndex()).absoluteFilePath());
2707 QString suggestedName = tr("New Folder");
2709 if(!m_metaData->fileArtist().isEmpty() && !m_metaData->fileAlbum().isEmpty())
2711 suggestedName = QString("%1 - %2").arg(m_metaData->fileArtist(), m_metaData->fileAlbum());
2713 else if(!m_metaData->fileArtist().isEmpty())
2715 suggestedName = m_metaData->fileArtist();
2717 else if(!m_metaData->fileAlbum().isEmpty())
2719 suggestedName = m_metaData->fileAlbum();
2723 for(int i = 0; i < m_fileListModel->rowCount(); i++)
2725 AudioFileModel audioFile = m_fileListModel->getFile(m_fileListModel->index(i, 0));
2726 if(!audioFile.fileAlbum().isEmpty() || !audioFile.fileArtist().isEmpty())
2728 if(!audioFile.fileArtist().isEmpty() && !audioFile.fileAlbum().isEmpty())
2730 suggestedName = QString("%1 - %2").arg(audioFile.fileArtist(), audioFile.fileAlbum());
2732 else if(!audioFile.fileArtist().isEmpty())
2734 suggestedName = audioFile.fileArtist();
2736 else if(!audioFile.fileAlbum().isEmpty())
2738 suggestedName = audioFile.fileAlbum();
2745 suggestedName = lamexp_clean_filename(suggestedName);
2749 bool bApplied = false;
2750 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();
2754 folderName = lamexp_clean_filepath(folderName.simplified());
2756 if(folderName.isEmpty())
2758 MessageBeep(MB_ICONERROR);
2763 QString newFolder = folderName;
2765 while(basePath.exists(newFolder))
2767 newFolder = QString(folderName).append(QString().sprintf(" (%d)", ++i));
2770 if(basePath.mkpath(newFolder))
2772 QDir createdDir = basePath;
2773 if(createdDir.cd(newFolder))
2775 QModelIndex newIndex = m_fileSystemModel->index(createdDir.canonicalPath());
2776 ui->outputFolderView->setCurrentIndex(newIndex);
2777 outputFolderViewClicked(newIndex);
2778 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2783 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!")));
2791 * Output to source dir changed
2793 void MainWindow::saveToSourceFolderChanged(void)
2795 m_settings->outputToSourceDir(ui->saveToSourceFolderCheckBox->isChecked());
2799 * Prepend relative source file path to output file name changed
2801 void MainWindow::prependRelativePathChanged(void)
2803 m_settings->prependRelativeSourcePath(ui->prependRelativePathCheckBox->isChecked());
2807 * Show context menu for output folder
2809 void MainWindow::outputFolderContextMenu(const QPoint &pos)
2811 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
2812 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
2814 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
2816 m_outputFolderContextMenu->popup(sender->mapToGlobal(pos));
2821 * Show selected folder in explorer
2823 void MainWindow::showFolderContextActionTriggered(void)
2825 if(!m_fileSystemModel)
2827 qWarning("File system model not initialized yet!");
2831 QString path = QDir::toNativeSeparators(m_fileSystemModel->filePath(ui->outputFolderView->currentIndex()));
2832 if(!path.endsWith(QDir::separator())) path.append(QDir::separator());
2833 ShellExecuteW(reinterpret_cast<HWND>(this->winId()), L"explore", QWCHAR(path), NULL, NULL, SW_SHOW);
2837 * Refresh the directory outline
2839 void MainWindow::refreshFolderContextActionTriggered(void)
2841 //force re-initialization
2842 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
2846 * Add current folder to favorites
2848 void MainWindow::addFavoriteFolderActionTriggered(void)
2850 QString path = m_fileSystemModel->filePath(ui->outputFolderView->currentIndex());
2851 QStringList favorites = m_settings->favoriteOutputFolders().split("|", QString::SkipEmptyParts);
2853 if(!favorites.contains(path, Qt::CaseInsensitive))
2855 favorites.append(path);
2856 while(favorites.count() > 6) favorites.removeFirst();
2860 MessageBeep(MB_ICONWARNING);
2863 m_settings->favoriteOutputFolders(favorites.join("|"));
2868 * Output folder edit finished
2870 void MainWindow::outputFolderEditFinished(void)
2872 if(ui->outputFolderEdit->isHidden())
2874 return; //Not currently in edit mode!
2879 QString text = QDir::fromNativeSeparators(ui->outputFolderEdit->text().trimmed());
2880 while(text.startsWith('"') || text.startsWith('/')) text = text.right(text.length() - 1).trimmed();
2881 while(text.endsWith('"') || text.endsWith('/')) text = text.left(text.length() - 1).trimmed();
2883 static const char *str = "?*<>|\"";
2884 for(size_t i = 0; str[i]; i++) text.replace(str[i], "_");
2886 if(!((text.length() >= 2) && text.at(0).isLetter() && text.at(1) == QChar(':')))
2888 text = QString("%1/%2").arg(QDir::fromNativeSeparators(ui->outputFolderLabel->text()), text);
2891 if(text.length() == 2) text += "/"; /* "X:" => "X:/" */
2893 while(text.length() > 2)
2895 QFileInfo info(text);
2896 if(info.exists() && info.isDir())
2898 QModelIndex index = m_fileSystemModel->index(QFileInfo(info.canonicalFilePath()).absoluteFilePath());
2902 ui->outputFolderView->setCurrentIndex(index);
2903 outputFolderViewClicked(index);
2907 else if(info.exists() && info.isFile())
2909 QModelIndex index = m_fileSystemModel->index(QFileInfo(info.canonicalPath()).absoluteFilePath());
2913 ui->outputFolderView->setCurrentIndex(index);
2914 outputFolderViewClicked(index);
2919 text = text.left(text.length() - 1).trimmed();
2922 ui->outputFolderEdit->setVisible(false);
2923 ui->outputFolderLabel->setVisible(true);
2924 ui->outputFolderView->setEnabled(true);
2926 if(!ok) MessageBeep(MB_ICONERROR);
2927 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2931 * Initialize file system model
2933 void MainWindow::initOutputFolderModel(void)
2935 if(m_outputFolderNoteBox->isHidden())
2937 m_outputFolderNoteBox->show();
2938 m_outputFolderNoteBox->repaint();
2939 m_outputFolderViewInitCounter = 4;
2941 if(m_fileSystemModel)
2943 SET_MODEL(ui->outputFolderView, NULL);
2944 LAMEXP_DELETE(m_fileSystemModel);
2945 ui->outputFolderView->repaint();
2948 if(m_fileSystemModel = new QFileSystemModelEx())
2950 m_fileSystemModel->installEventFilter(this);
2951 connect(m_fileSystemModel, SIGNAL(directoryLoaded(QString)), this, SLOT(outputFolderDirectoryLoaded(QString)));
2952 connect(m_fileSystemModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(outputFolderRowsInserted(QModelIndex,int,int)));
2954 SET_MODEL(ui->outputFolderView, m_fileSystemModel);
2955 ui->outputFolderView->header()->setStretchLastSection(true);
2956 ui->outputFolderView->header()->hideSection(1);
2957 ui->outputFolderView->header()->hideSection(2);
2958 ui->outputFolderView->header()->hideSection(3);
2960 m_fileSystemModel->setRootPath("");
2961 QModelIndex index = m_fileSystemModel->index(m_settings->outputDir());
2962 if(index.isValid()) ui->outputFolderView->setCurrentIndex(index);
2963 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2966 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2967 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
2972 * Initialize file system model (do NOT call this one directly!)
2974 void MainWindow::initOutputFolderModel_doAsync(void)
2976 if(m_outputFolderViewInitCounter > 0)
2978 m_outputFolderViewInitCounter--;
2979 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
2983 QTimer::singleShot(125, m_outputFolderNoteBox, SLOT(hide()));
2984 ui->outputFolderView->setFocus();
2989 * Center current folder in view
2991 void MainWindow::centerOutputFolderModel(void)
2993 if(ui->outputFolderView->isVisible())
2995 centerOutputFolderModel_doAsync();
2996 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel_doAsync()));
3001 * Center current folder in view (do NOT call this one directly!)
3003 void MainWindow::centerOutputFolderModel_doAsync(void)
3005 if(ui->outputFolderView->isVisible())
3007 m_outputFolderViewCentering = true;
3008 const QModelIndex index = ui->outputFolderView->currentIndex();
3009 ui->outputFolderView->scrollTo(index, QAbstractItemView::PositionAtCenter);
3010 ui->outputFolderView->setFocus();
3015 * File system model asynchronously loaded a dir
3017 void MainWindow::outputFolderDirectoryLoaded(const QString &path)
3019 if(m_outputFolderViewCentering)
3021 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
3026 * File system model inserted new items
3028 void MainWindow::outputFolderRowsInserted(const QModelIndex &parent, int start, int end)
3030 if(m_outputFolderViewCentering)
3032 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
3037 * Directory view item was expanded by user
3039 void MainWindow::outputFolderItemExpanded(const QModelIndex &item)
3041 //We need to stop centering as soon as the user has expanded an item manually!
3042 m_outputFolderViewCentering = false;
3046 * View event for output folder control occurred
3048 void MainWindow::outputFolderViewEventOccurred(QWidget *sender, QEvent *event)
3050 switch(event->type())
3054 case QEvent::KeyPress:
3055 case QEvent::KeyRelease:
3056 case QEvent::FocusIn:
3057 case QEvent::FocusOut:
3058 case QEvent::TouchEnd:
3059 outputFolderViewClicked(ui->outputFolderView->currentIndex());
3065 * Mouse event for output folder control occurred
3067 void MainWindow::outputFolderMouseEventOccurred(QWidget *sender, QEvent *event)
3069 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
3070 QPoint pos = (mouseEvent) ? mouseEvent->pos() : QPoint();
3072 if(sender == ui->outputFolderLabel)
3074 switch(event->type())
3076 case QEvent::MouseButtonPress:
3077 if(mouseEvent && (mouseEvent->button() == Qt::LeftButton))
3079 QString path = ui->outputFolderLabel->text();
3080 if(!path.endsWith(QDir::separator())) path.append(QDir::separator());
3081 ShellExecuteW(reinterpret_cast<HWND>(this->winId()), L"explore", QWCHAR(path), NULL, NULL, SW_SHOW);
3085 ui->outputFolderLabel->setForegroundRole(QPalette::Link);
3088 ui->outputFolderLabel->setForegroundRole(QPalette::WindowText);
3092 else if(sender == ui->outputFoldersFovoritesLabel)
3094 switch(event->type())
3097 ui->outputFoldersFovoritesLabel->setFrameShadow(QFrame::Raised);
3099 case QEvent::MouseButtonPress:
3100 ui->outputFoldersFovoritesLabel->setFrameShadow(QFrame::Sunken);
3102 case QEvent::MouseButtonRelease:
3103 ui->outputFoldersFovoritesLabel->setFrameShadow(QFrame::Raised);
3106 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0 && mouseEvent->button() != Qt::MidButton)
3108 if(ui->outputFolderView->isEnabled())
3110 m_outputFolderFavoritesMenu->popup(sender->mapToGlobal(pos));
3116 ui->outputFoldersFovoritesLabel->setFrameShadow(QFrame::Plain);
3120 else if(sender == ui->outputFoldersEditorLabel)
3122 switch(event->type())
3125 ui->outputFoldersEditorLabel->setFrameShadow(QFrame::Raised);
3127 case QEvent::MouseButtonPress:
3128 ui->outputFoldersEditorLabel->setFrameShadow(QFrame::Sunken);
3130 case QEvent::MouseButtonRelease:
3131 ui->outputFoldersEditorLabel->setFrameShadow(QFrame::Raised);
3134 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0 && mouseEvent->button() != Qt::MidButton)
3136 if(ui->outputFolderView->isEnabled())
3138 ui->outputFolderView->setEnabled(false);
3139 ui->outputFolderLabel->setVisible(false);
3140 ui->outputFolderEdit->setVisible(true);
3141 ui->outputFolderEdit->setText(ui->outputFolderLabel->text());
3142 ui->outputFolderEdit->selectAll();
3143 ui->outputFolderEdit->setFocus();
3149 ui->outputFoldersEditorLabel->setFrameShadow(QFrame::Plain);
3155 // =========================================================
3156 // Metadata tab slots
3157 // =========================================================
3160 * Edit meta button clicked
3162 void MainWindow::editMetaButtonClicked(void)
3166 const QModelIndex index = ui->metaDataView->currentIndex();
3170 m_metaInfoModel->editItem(index, this);
3172 if(index.row() == 4)
3174 m_settings->metaInfoPosition(m_metaData->filePosition());
3180 * Reset meta button clicked
3182 void MainWindow::clearMetaButtonClicked(void)
3185 m_metaInfoModel->clearData();
3189 * Meta tags enabled changed
3191 void MainWindow::metaTagsEnabledChanged(void)
3193 m_settings->writeMetaTags(ui->writeMetaDataCheckBox->isChecked());
3197 * Playlist enabled changed
3199 void MainWindow::playlistEnabledChanged(void)
3201 m_settings->createPlaylist(ui->generatePlaylistCheckBox->isChecked());
3204 // =========================================================
3205 // Compression tab slots
3206 // =========================================================
3211 void MainWindow::updateEncoder(int id)
3213 m_settings->compressionEncoder(id);
3215 switch(m_settings->compressionEncoder())
3217 case SettingsModel::VorbisEncoder:
3218 ui->radioButtonModeQuality->setEnabled(true);
3219 ui->radioButtonModeAverageBitrate->setEnabled(true);
3220 ui->radioButtonConstBitrate->setEnabled(false);
3221 if(ui->radioButtonConstBitrate->isChecked()) ui->radioButtonModeQuality->setChecked(true);
3222 ui->sliderBitrate->setEnabled(true);
3224 case SettingsModel::AC3Encoder:
3225 ui->radioButtonModeQuality->setEnabled(true);
3226 ui->radioButtonModeQuality->setChecked(true);
3227 ui->radioButtonModeAverageBitrate->setEnabled(false);
3228 ui->radioButtonConstBitrate->setEnabled(true);
3229 ui->sliderBitrate->setEnabled(true);
3231 case SettingsModel::FLACEncoder:
3232 ui->radioButtonModeQuality->setEnabled(false);
3233 ui->radioButtonModeQuality->setChecked(true);
3234 ui->radioButtonModeAverageBitrate->setEnabled(false);
3235 ui->radioButtonConstBitrate->setEnabled(false);
3236 ui->sliderBitrate->setEnabled(true);
3238 case SettingsModel::PCMEncoder:
3239 ui->radioButtonModeQuality->setEnabled(false);
3240 ui->radioButtonModeQuality->setChecked(true);
3241 ui->radioButtonModeAverageBitrate->setEnabled(false);
3242 ui->radioButtonConstBitrate->setEnabled(false);
3243 ui->sliderBitrate->setEnabled(false);
3245 case SettingsModel::AACEncoder:
3246 ui->radioButtonModeQuality->setEnabled(true);
3247 ui->radioButtonModeAverageBitrate->setEnabled(!m_fhgEncoderAvailable);
3248 if(m_fhgEncoderAvailable && ui->radioButtonModeAverageBitrate->isChecked()) ui->radioButtonConstBitrate->setChecked(true);
3249 ui->radioButtonConstBitrate->setEnabled(true);
3250 ui->sliderBitrate->setEnabled(true);
3252 case SettingsModel::DCAEncoder:
3253 ui->radioButtonModeQuality->setEnabled(false);
3254 ui->radioButtonModeAverageBitrate->setEnabled(false);
3255 ui->radioButtonConstBitrate->setEnabled(true);
3256 ui->radioButtonConstBitrate->setChecked(true);
3257 ui->sliderBitrate->setEnabled(true);
3260 ui->radioButtonModeQuality->setEnabled(true);
3261 ui->radioButtonModeAverageBitrate->setEnabled(true);
3262 ui->radioButtonConstBitrate->setEnabled(true);
3263 ui->sliderBitrate->setEnabled(true);
3267 if(m_settings->compressionEncoder() == SettingsModel::AACEncoder)
3269 const QString encoderName = m_qaacEncoderAvailable ? tr("QAAC (Apple)") : (m_fhgEncoderAvailable ? tr("FHG AAC (Winamp)") : (m_neroEncoderAvailable ? tr("Nero AAC") : tr("Not available!")));
3270 ui->labelEncoderInfo->setVisible(true);
3271 ui->labelEncoderInfo->setText(tr("Current AAC Encoder: %1").arg(encoderName));
3275 ui->labelEncoderInfo->setVisible(false);
3278 updateRCMode(m_modeButtonGroup->checkedId());
3282 * Update rate-control mode
3284 void MainWindow::updateRCMode(int id)
3286 m_settings->compressionRCMode(id);
3288 switch(m_settings->compressionEncoder())
3290 case SettingsModel::MP3Encoder:
3291 switch(m_settings->compressionRCMode())
3293 case SettingsModel::VBRMode:
3294 ui->sliderBitrate->setMinimum(0);
3295 ui->sliderBitrate->setMaximum(9);
3298 ui->sliderBitrate->setMinimum(0);
3299 ui->sliderBitrate->setMaximum(13);
3303 case SettingsModel::VorbisEncoder:
3304 switch(m_settings->compressionRCMode())
3306 case SettingsModel::VBRMode:
3307 ui->sliderBitrate->setMinimum(-2);
3308 ui->sliderBitrate->setMaximum(10);
3311 ui->sliderBitrate->setMinimum(4);
3312 ui->sliderBitrate->setMaximum(63);
3316 case SettingsModel::AC3Encoder:
3317 switch(m_settings->compressionRCMode())
3319 case SettingsModel::VBRMode:
3320 ui->sliderBitrate->setMinimum(0);
3321 ui->sliderBitrate->setMaximum(16);
3324 ui->sliderBitrate->setMinimum(0);
3325 ui->sliderBitrate->setMaximum(18);
3329 case SettingsModel::AACEncoder:
3330 switch(m_settings->compressionRCMode())
3332 case SettingsModel::VBRMode:
3333 ui->sliderBitrate->setMinimum(0);
3334 ui->sliderBitrate->setMaximum(20);
3337 ui->sliderBitrate->setMinimum(4);
3338 ui->sliderBitrate->setMaximum(63);
3342 case SettingsModel::FLACEncoder:
3343 ui->sliderBitrate->setMinimum(0);
3344 ui->sliderBitrate->setMaximum(8);
3346 case SettingsModel::OpusEncoder:
3347 ui->sliderBitrate->setMinimum(1);
3348 ui->sliderBitrate->setMaximum(32);
3350 case SettingsModel::DCAEncoder:
3351 ui->sliderBitrate->setMinimum(1);
3352 ui->sliderBitrate->setMaximum(128);
3354 case SettingsModel::PCMEncoder:
3355 ui->sliderBitrate->setMinimum(0);
3356 ui->sliderBitrate->setMaximum(2);
3357 ui->sliderBitrate->setValue(1);
3360 ui->sliderBitrate->setMinimum(0);
3361 ui->sliderBitrate->setMaximum(0);
3365 updateBitrate(ui->sliderBitrate->value());
3371 void MainWindow::updateBitrate(int value)
3373 m_settings->compressionBitrate(value);
3375 switch(m_settings->compressionRCMode())
3377 case SettingsModel::VBRMode:
3378 switch(m_settings->compressionEncoder())
3380 case SettingsModel::MP3Encoder:
3381 ui->labelBitrate->setText(tr("Quality Level %1").arg(9 - value));
3383 case SettingsModel::VorbisEncoder:
3384 ui->labelBitrate->setText(tr("Quality Level %1").arg(value));
3386 case SettingsModel::AACEncoder:
3387 ui->labelBitrate->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", static_cast<double>(value * 5) / 100.0)));
3389 case SettingsModel::FLACEncoder:
3390 ui->labelBitrate->setText(tr("Compression %1").arg(value));
3392 case SettingsModel::OpusEncoder:
3393 ui->labelBitrate->setText(QString("≈ %1 kbps").arg(qMin(500, value * 8)));
3395 case SettingsModel::AC3Encoder:
3396 ui->labelBitrate->setText(tr("Quality Level %1").arg(qMin(1024, qMax(0, value * 64))));
3398 case SettingsModel::PCMEncoder:
3399 ui->labelBitrate->setText(tr("Uncompressed"));
3402 ui->labelBitrate->setText(QString::number(value));
3406 case SettingsModel::ABRMode:
3407 switch(m_settings->compressionEncoder())
3409 case SettingsModel::MP3Encoder:
3410 ui->labelBitrate->setText(QString("≈ %1 kbps").arg(SettingsModel::mp3Bitrates[value]));
3412 case SettingsModel::FLACEncoder:
3413 ui->labelBitrate->setText(tr("Compression %1").arg(value));
3415 case SettingsModel::AC3Encoder:
3416 ui->labelBitrate->setText(QString("≈ %1 kbps").arg(SettingsModel::ac3Bitrates[value]));
3418 case SettingsModel::PCMEncoder:
3419 ui->labelBitrate->setText(tr("Uncompressed"));
3422 ui->labelBitrate->setText(QString("≈ %1 kbps").arg(qMin(500, value * 8)));
3427 switch(m_settings->compressionEncoder())
3429 case SettingsModel::MP3Encoder:
3430 ui->labelBitrate->setText(QString("%1 kbps").arg(SettingsModel::mp3Bitrates[value]));
3432 case SettingsModel::FLACEncoder:
3433 ui->labelBitrate->setText(tr("Compression %1").arg(value));
3435 case SettingsModel::AC3Encoder:
3436 ui->labelBitrate->setText(QString("%1 kbps").arg(SettingsModel::ac3Bitrates[value]));
3438 case SettingsModel::DCAEncoder:
3439 ui->labelBitrate->setText(QString("%1 kbps").arg(value * 32));
3441 case SettingsModel::PCMEncoder:
3442 ui->labelBitrate->setText(tr("Uncompressed"));
3445 ui->labelBitrate->setText(QString("%1 kbps").arg(qMin(500, value * 8)));
3453 * Event for compression tab occurred
3455 void MainWindow::compressionTabEventOccurred(QWidget *sender, QEvent *event)
3457 static const QUrl helpUrl("http://lamexp.sourceforge.net/doc/FAQ.html#054010d9");
3459 if((sender == ui->labelCompressionHelp) && (event->type() == QEvent::MouseButtonPress))
3461 QDesktopServices::openUrl(helpUrl);
3465 // =========================================================
3466 // Advanced option slots
3467 // =========================================================
3470 * Lame algorithm quality changed
3472 void MainWindow::updateLameAlgoQuality(int value)
3479 text = tr("Best Quality (Very Slow)");
3482 text = tr("High Quality (Recommended)");
3485 text = tr("Average Quality (Default)");
3488 text = tr("Low Quality (Fast)");
3491 text = tr("Poor Quality (Very Fast)");
3497 m_settings->lameAlgoQuality(value);
3498 ui->labelLameAlgoQuality->setText(text);
3501 bool warning = (value == 0), notice = (value == 4);
3502 ui->labelLameAlgoQualityWarning->setVisible(warning);
3503 ui->labelLameAlgoQualityWarningIcon->setVisible(warning);
3504 ui->labelLameAlgoQualityNotice->setVisible(notice);
3505 ui->labelLameAlgoQualityNoticeIcon->setVisible(notice);
3506 ui->labelLameAlgoQualitySpacer->setVisible(warning || notice);
3510 * Bitrate management endabled/disabled
3512 void MainWindow::bitrateManagementEnabledChanged(bool checked)
3514 m_settings->bitrateManagementEnabled(checked);
3518 * Minimum bitrate has changed
3520 void MainWindow::bitrateManagementMinChanged(int value)
3522 if(value > ui->spinBoxBitrateManagementMax->value())
3524 ui->spinBoxBitrateManagementMin->setValue(ui->spinBoxBitrateManagementMax->value());
3525 m_settings->bitrateManagementMinRate(ui->spinBoxBitrateManagementMax->value());
3529 m_settings->bitrateManagementMinRate(value);
3534 * Maximum bitrate has changed
3536 void MainWindow::bitrateManagementMaxChanged(int value)
3538 if(value < ui->spinBoxBitrateManagementMin->value())
3540 ui->spinBoxBitrateManagementMax->setValue(ui->spinBoxBitrateManagementMin->value());
3541 m_settings->bitrateManagementMaxRate(ui->spinBoxBitrateManagementMin->value());
3545 m_settings->bitrateManagementMaxRate(value);
3550 * Channel mode has changed
3552 void MainWindow::channelModeChanged(int value)
3554 if(value >= 0) m_settings->lameChannelMode(value);
3558 * Sampling rate has changed
3560 void MainWindow::samplingRateChanged(int value)
3562 if(value >= 0) m_settings->samplingRate(value);
3566 * Nero AAC 2-Pass mode changed
3568 void MainWindow::neroAAC2PassChanged(bool checked)
3570 m_settings->neroAACEnable2Pass(checked);
3574 * Nero AAC profile mode changed
3576 void MainWindow::neroAACProfileChanged(int value)
3578 if(value >= 0) m_settings->aacEncProfile(value);
3582 * Aften audio coding mode changed
3584 void MainWindow::aftenCodingModeChanged(int value)
3586 if(value >= 0) m_settings->aftenAudioCodingMode(value);
3590 * Aften DRC mode changed
3592 void MainWindow::aftenDRCModeChanged(int value)
3594 if(value >= 0) m_settings->aftenDynamicRangeCompression(value);
3598 * Aften exponent search size changed
3600 void MainWindow::aftenSearchSizeChanged(int value)
3602 if(value >= 0) m_settings->aftenExponentSearchSize(value);
3606 * Aften fast bit allocation changed
3608 void MainWindow::aftenFastAllocationChanged(bool checked)
3610 m_settings->aftenFastBitAllocation(checked);
3615 * Opus encoder settings changed
3617 void MainWindow::opusSettingsChanged(void)
3619 m_settings->opusFramesize(ui->comboBoxOpusFramesize->currentIndex());
3620 m_settings->opusComplexity(ui->spinBoxOpusComplexity->value());
3621 //m_settings->opusOptimizeFor(comboBoxOpusOptimize->currentIndex());
3625 * Normalization filter enabled changed
3627 void MainWindow::normalizationEnabledChanged(bool checked)
3629 m_settings->normalizationFilterEnabled(checked);
3633 * Normalization max. volume changed
3635 void MainWindow::normalizationMaxVolumeChanged(double value)
3637 m_settings->normalizationFilterMaxVolume(static_cast<int>(value * 100.0));
3641 * Normalization equalization mode changed
3643 void MainWindow::normalizationModeChanged(int mode)
3645 m_settings->normalizationFilterEqualizationMode(mode);
3649 * Tone adjustment has changed (Bass)
3651 void MainWindow::toneAdjustBassChanged(double value)
3653 m_settings->toneAdjustBass(static_cast<int>(value * 100.0));
3654 ui->spinBoxToneAdjustBass->setPrefix((value > 0) ? "+" : QString());
3658 * Tone adjustment has changed (Treble)
3660 void MainWindow::toneAdjustTrebleChanged(double value)
3662 m_settings->toneAdjustTreble(static_cast<int>(value * 100.0));
3663 ui->spinBoxToneAdjustTreble->setPrefix((value > 0) ? "+" : QString());
3667 * Tone adjustment has been reset
3669 void MainWindow::toneAdjustTrebleReset(void)
3671 ui->spinBoxToneAdjustBass->setValue(m_settings->toneAdjustBassDefault());
3672 ui->spinBoxToneAdjustTreble->setValue(m_settings->toneAdjustTrebleDefault());
3673 toneAdjustBassChanged(ui->spinBoxToneAdjustBass->value());
3674 toneAdjustTrebleChanged(ui->spinBoxToneAdjustTreble->value());
3678 * Custom encoder parameters changed
3680 void MainWindow::customParamsChanged(void)
3682 ui->lineEditCustomParamLAME->setText(ui->lineEditCustomParamLAME->text().simplified());
3683 ui->lineEditCustomParamOggEnc->setText(ui->lineEditCustomParamOggEnc->text().simplified());
3684 ui->lineEditCustomParamNeroAAC->setText(ui->lineEditCustomParamNeroAAC->text().simplified());
3685 ui->lineEditCustomParamFLAC->setText(ui->lineEditCustomParamFLAC->text().simplified());
3686 ui->lineEditCustomParamAften->setText(ui->lineEditCustomParamAften->text().simplified());
3687 ui->lineEditCustomParamOpus->setText(ui->lineEditCustomParamOpus->text().simplified());
3689 bool customParamsUsed = false;
3690 if(!ui->lineEditCustomParamLAME->text().isEmpty()) customParamsUsed = true;
3691 if(!ui->lineEditCustomParamOggEnc->text().isEmpty()) customParamsUsed = true;
3692 if(!ui->lineEditCustomParamNeroAAC->text().isEmpty()) customParamsUsed = true;
3693 if(!ui->lineEditCustomParamFLAC->text().isEmpty()) customParamsUsed = true;
3694 if(!ui->lineEditCustomParamAften->text().isEmpty()) customParamsUsed = true;
3695 if(!ui->lineEditCustomParamOpus->text().isEmpty()) customParamsUsed = true;
3697 ui->labelCustomParamsIcon->setVisible(customParamsUsed);
3698 ui->labelCustomParamsText->setVisible(customParamsUsed);
3699 ui->labelCustomParamsSpacer->setVisible(customParamsUsed);
3701 m_settings->customParametersLAME(ui->lineEditCustomParamLAME->text());
3702 m_settings->customParametersOggEnc(ui->lineEditCustomParamOggEnc->text());
3703 m_settings->customParametersAacEnc(ui->lineEditCustomParamNeroAAC->text());
3704 m_settings->customParametersFLAC(ui->lineEditCustomParamFLAC->text());
3705 m_settings->customParametersAften(ui->lineEditCustomParamAften->text());
3706 m_settings->customParametersOpus(ui->lineEditCustomParamOpus->text());
3710 * Rename output files enabled changed
3712 void MainWindow::renameOutputEnabledChanged(bool checked)
3714 m_settings->renameOutputFilesEnabled(checked);
3718 * Rename output files patterm changed
3720 void MainWindow::renameOutputPatternChanged(void)
3722 QString temp = ui->lineEditRenamePattern->text().simplified();
3723 ui->lineEditRenamePattern->setText(temp.isEmpty() ? m_settings->renameOutputFilesPatternDefault() : temp);
3724 m_settings->renameOutputFilesPattern(ui->lineEditRenamePattern->text());
3728 * Rename output files patterm changed
3730 void MainWindow::renameOutputPatternChanged(const QString &text)
3732 QString pattern(text.simplified());
3734 pattern.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive);
3735 pattern.replace("<TrackNo>", "04", Qt::CaseInsensitive);
3736 pattern.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive);
3737 pattern.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive);
3738 pattern.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive);
3739 pattern.replace("<Year>", "2001", Qt::CaseInsensitive);
3740 pattern.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive);
3742 if(pattern.compare(lamexp_clean_filename(pattern)))
3744 if(ui->lineEditRenamePattern->palette().color(QPalette::Text) != Qt::red)
3746 MessageBeep(MB_ICONERROR);
3747 SET_TEXT_COLOR(ui->lineEditRenamePattern, Qt::red);
3752 if(ui->lineEditRenamePattern->palette().color(QPalette::Text) != Qt::black)
3754 MessageBeep(MB_ICONINFORMATION);
3755 SET_TEXT_COLOR(ui->lineEditRenamePattern, Qt::black);
3759 ui->labelRanameExample->setText(lamexp_clean_filename(pattern));
3763 * Show list of rename macros
3765 void MainWindow::showRenameMacros(const QString &text)
3767 if(text.compare("reset", Qt::CaseInsensitive) == 0)
3769 ui->lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
3773 const QString format = QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
3775 QString message = QString("<table>");
3776 message += QString(format).arg("BaseName", tr("File name without extension"));
3777 message += QString(format).arg("TrackNo", tr("Track number with leading zero"));
3778 message += QString(format).arg("Title", tr("Track title"));
3779 message += QString(format).arg("Artist", tr("Artist name"));
3780 message += QString(format).arg("Album", tr("Album name"));
3781 message += QString(format).arg("Year", tr("Year with (at least) four digits"));
3782 message += QString(format).arg("Comment", tr("Comment"));
3783 message += "</table><br><br>";
3784 message += QString("%1<br>").arg(tr("Characters forbidden in file names:"));
3785 message += "<b><tt>\\ / : * ? < > |<br>";
3787 QMessageBox::information(this, tr("Rename Macros"), message, tr("Discard"));
3790 void MainWindow::forceStereoDownmixEnabledChanged(bool checked)
3792 m_settings->forceStereoDownmix(checked);
3796 * Maximum number of instances changed
3798 void MainWindow::updateMaximumInstances(int value)
3800 ui->labelMaxInstances->setText(tr("%1 Instance(s)").arg(QString::number(value)));
3801 m_settings->maximumInstances(ui->checkBoxAutoDetectInstances->isChecked() ? NULL : value);
3805 * Auto-detect number of instances
3807 void MainWindow::autoDetectInstancesChanged(bool checked)
3809 m_settings->maximumInstances(checked ? NULL : ui->sliderMaxInstances->value());
3813 * Browse for custom TEMP folder button clicked
3815 void MainWindow::browseCustomTempFolderButtonClicked(void)
3817 QString newTempFolder;
3819 if(USE_NATIVE_FILE_DIALOG)
3821 newTempFolder = QFileDialog::getExistingDirectory(this, QString(), m_settings->customTempPath());
3825 QFileDialog dialog(this);
3826 dialog.setFileMode(QFileDialog::DirectoryOnly);
3827 dialog.setDirectory(m_settings->customTempPath());
3830 newTempFolder = dialog.selectedFiles().first();
3834 if(!newTempFolder.isEmpty())
3836 QFile writeTest(QString("%1/~%2.tmp").arg(newTempFolder, lamexp_rand_str()));
3837 if(writeTest.open(QIODevice::ReadWrite))
3840 ui->lineEditCustomTempFolder->setText(QDir::toNativeSeparators(newTempFolder));
3844 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
3850 * Custom TEMP folder changed
3852 void MainWindow::customTempFolderChanged(const QString &text)
3854 m_settings->customTempPath(QDir::fromNativeSeparators(text));
3858 * Use custom TEMP folder option changed
3860 void MainWindow::useCustomTempFolderChanged(bool checked)
3862 m_settings->customTempPathEnabled(!checked);
3866 * Help for custom parameters was requested
3868 void MainWindow::customParamsHelpRequested(QWidget *obj, QEvent *event)
3870 if(event->type() != QEvent::MouseButtonRelease)
3875 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
3877 QPoint pos = mouseEvent->pos();
3878 if(!(pos.x() <= obj->width() && pos.y() <= obj->height() && pos.x() >= 0 && pos.y() >= 0 && mouseEvent->button() != Qt::MidButton))
3884 if(obj == ui->helpCustomParamLAME) showCustomParamsHelpScreen("lame.exe", "--longhelp");
3885 else if(obj == ui->helpCustomParamOggEnc) showCustomParamsHelpScreen("oggenc2.exe", "--help");
3886 else if(obj == ui->helpCustomParamNeroAAC)
3888 if(m_qaacEncoderAvailable) showCustomParamsHelpScreen("qaac.exe", "--help");
3889 else if(m_fhgEncoderAvailable) showCustomParamsHelpScreen("fhgaacenc.exe", "");
3890 else if(m_neroEncoderAvailable) showCustomParamsHelpScreen("neroAacEnc.exe", "-help");
3891 else MessageBeep(MB_ICONERROR);
3893 else if(obj == ui->helpCustomParamFLAC) showCustomParamsHelpScreen("flac.exe", "--help");
3894 else if(obj == ui->helpCustomParamAften) showCustomParamsHelpScreen("aften.exe", "-h");
3895 else if(obj == ui->helpCustomParamOpus) showCustomParamsHelpScreen("opusenc_std.exe", "--help");
3896 else MessageBeep(MB_ICONERROR);
3900 * Show help for custom parameters
3902 void MainWindow::showCustomParamsHelpScreen(const QString &toolName, const QString &command)
3904 const QString binary = lamexp_lookup_tool(toolName);
3905 if(binary.isEmpty())
3907 MessageBeep(MB_ICONERROR);
3908 qWarning("customParamsHelpRequested: Binary could not be found!");
3912 QProcess *process = new QProcess();
3913 process->setProcessChannelMode(QProcess::MergedChannels);
3914 process->setReadChannel(QProcess::StandardOutput);
3915 process->start(binary, command.isEmpty() ? QStringList() : QStringList() << command);
3916 qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
3918 if(process->waitForStarted(15000))
3920 qApp->processEvents();
3921 process->waitForFinished(15000);
3924 if(process->state() != QProcess::NotRunning)
3927 process->waitForFinished(-1);
3930 qApp->restoreOverrideCursor();
3931 QStringList output; bool spaceFlag = true;
3933 while(process->canReadLine())
3935 QString temp = QString::fromUtf8(process->readLine());
3936 TRIM_STRING_RIGHT(temp);
3939 if(!spaceFlag) { output << temp; spaceFlag = true; }
3943 output << temp; spaceFlag = false;
3947 LAMEXP_DELETE(process);
3949 if(output.count() < 1)
3951 qWarning("Empty output, cannot show help screen!");
3952 MessageBeep(MB_ICONERROR);
3955 LogViewDialog *dialog = new LogViewDialog(this);
3956 TEMP_HIDE_DROPBOX( dialog->exec(output); );
3957 LAMEXP_DELETE(dialog);
3960 void MainWindow::overwriteModeChanged(int id)
3962 if((id == SettingsModel::Overwrite_Replaces) && (m_settings->overwriteMode() != SettingsModel::Overwrite_Replaces))
3964 if(QMessageBox::warning(this, tr("Overwrite Mode"), tr("Warning: This mode may overwrite existing files with no way to revert!"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
3966 ui->radioButtonOverwriteModeKeepBoth->setChecked(m_settings->overwriteMode() == SettingsModel::Overwrite_KeepBoth);
3967 ui->radioButtonOverwriteModeSkipFile->setChecked(m_settings->overwriteMode() == SettingsModel::Overwrite_SkipFile);
3972 m_settings->overwriteMode(id);
3976 * Reset all advanced options to their defaults
3978 void MainWindow::resetAdvancedOptionsButtonClicked(void)
3980 ui->sliderLameAlgoQuality->setValue(m_settings->lameAlgoQualityDefault());
3981 ui->spinBoxBitrateManagementMin->setValue(m_settings->bitrateManagementMinRateDefault());
3982 ui->spinBoxBitrateManagementMax->setValue(m_settings->bitrateManagementMaxRateDefault());
3983 ui->spinBoxNormalizationFilter->setValue(static_cast<double>(m_settings->normalizationFilterMaxVolumeDefault()) / 100.0);
3984 ui->spinBoxToneAdjustBass->setValue(static_cast<double>(m_settings->toneAdjustBassDefault()) / 100.0);
3985 ui->spinBoxToneAdjustTreble->setValue(static_cast<double>(m_settings->toneAdjustTrebleDefault()) / 100.0);
3986 ui->spinBoxAftenSearchSize->setValue(m_settings->aftenExponentSearchSizeDefault());
3987 ui->spinBoxOpusComplexity->setValue(m_settings->opusComplexityDefault());
3988 ui->comboBoxMP3ChannelMode->setCurrentIndex(m_settings->lameChannelModeDefault());
3989 ui->comboBoxSamplingRate->setCurrentIndex(m_settings->samplingRateDefault());
3990 ui->comboBoxAACProfile->setCurrentIndex(m_settings->aacEncProfileDefault());
3991 ui->comboBoxAftenCodingMode->setCurrentIndex(m_settings->aftenAudioCodingModeDefault());
3992 ui->comboBoxAftenDRCMode->setCurrentIndex(m_settings->aftenDynamicRangeCompressionDefault());
3993 ui->comboBoxNormalizationMode->setCurrentIndex(m_settings->normalizationFilterEqualizationModeDefault());
3994 //comboBoxOpusOptimize->setCurrentIndex(m_settings->opusOptimizeForDefault());
3995 ui->comboBoxOpusFramesize->setCurrentIndex(m_settings->opusFramesizeDefault());
3996 SET_CHECKBOX_STATE(ui->checkBoxBitrateManagement, m_settings->bitrateManagementEnabledDefault());
3997 SET_CHECKBOX_STATE(ui->checkBoxNeroAAC2PassMode, m_settings->neroAACEnable2PassDefault());
3998 SET_CHECKBOX_STATE(ui->checkBoxNormalizationFilter, m_settings->normalizationFilterEnabledDefault());
3999 SET_CHECKBOX_STATE(ui->checkBoxAutoDetectInstances, (m_settings->maximumInstancesDefault() < 1));
4000 SET_CHECKBOX_STATE(ui->checkBoxUseSystemTempFolder, !m_settings->customTempPathEnabledDefault());
4001 SET_CHECKBOX_STATE(ui->checkBoxAftenFastAllocation, m_settings->aftenFastBitAllocationDefault());
4002 SET_CHECKBOX_STATE(ui->checkBoxRenameOutput, m_settings->renameOutputFilesEnabledDefault());
4003 SET_CHECKBOX_STATE(ui->checkBoxForceStereoDownmix, m_settings->forceStereoDownmixDefault());
4004 ui->lineEditCustomParamLAME->setText(m_settings->customParametersLAMEDefault());
4005 ui->lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEncDefault());
4006 ui->lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEncDefault());
4007 ui->lineEditCustomParamFLAC->setText(m_settings->customParametersFLACDefault());
4008 ui->lineEditCustomParamOpus->setText(m_settings->customParametersFLACDefault());
4009 ui->lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPathDefault()));
4010 ui->lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
4011 if(m_settings->overwriteModeDefault() == SettingsModel::Overwrite_KeepBoth) ui->radioButtonOverwriteModeKeepBoth->click();
4012 if(m_settings->overwriteModeDefault() == SettingsModel::Overwrite_SkipFile) ui->radioButtonOverwriteModeSkipFile->click();
4013 if(m_settings->overwriteModeDefault() == SettingsModel::Overwrite_Replaces) ui->radioButtonOverwriteModeReplaces->click();
4014 customParamsChanged();
4015 ui->scrollArea->verticalScrollBar()->setValue(0);
4018 // =========================================================
4019 // Multi-instance handling slots
4020 // =========================================================
4023 * Other instance detected
4025 void MainWindow::notifyOtherInstance(void)
4027 if(!m_banner->isVisible())
4029 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);
4035 * Add file from another instance
4037 void MainWindow::addFileDelayed(const QString &filePath, bool tryASAP)
4039 if(tryASAP && !m_delayedFileTimer->isActive())
4041 qDebug("Received file: %s", filePath.toUtf8().constData());
4042 m_delayedFileList->append(filePath);
4043 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4046 m_delayedFileTimer->stop();
4047 qDebug("Received file: %s", filePath.toUtf8().constData());
4048 m_delayedFileList->append(filePath);
4049 m_delayedFileTimer->start(5000);
4053 * Add files from another instance
4055 void MainWindow::addFilesDelayed(const QStringList &filePaths, bool tryASAP)
4057 if(tryASAP && !m_delayedFileTimer->isActive())
4059 qDebug("Received %d file(s).", filePaths.count());
4060 m_delayedFileList->append(filePaths);
4061 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4065 m_delayedFileTimer->stop();
4066 qDebug("Received %d file(s).", filePaths.count());
4067 m_delayedFileList->append(filePaths);
4068 m_delayedFileTimer->start(5000);
4073 * Add folder from another instance
4075 void MainWindow::addFolderDelayed(const QString &folderPath, bool recursive)
4077 if(!m_banner->isVisible())
4079 addFolder(folderPath, recursive, true);
4083 // =========================================================
4085 // =========================================================
4088 * Restore the override cursor
4090 void MainWindow::restoreCursor(void)
4092 QApplication::restoreOverrideCursor();