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"
27 #include "Dialog_WorkingBanner.h"
28 #include "Dialog_MetaInfo.h"
29 #include "Dialog_About.h"
30 #include "Dialog_Update.h"
31 #include "Dialog_DropBox.h"
32 #include "Dialog_CueImport.h"
33 #include "Thread_FileAnalyzer.h"
34 #include "Thread_FileAnalyzer_ST.h"
35 #include "Thread_MessageHandler.h"
36 #include "Model_MetaInfo.h"
37 #include "Model_Settings.h"
38 #include "Model_FileList.h"
39 #include "Model_FileSystem.h"
40 #include "WinSevenTaskbar.h"
41 #include "Registry_Decoder.h"
42 #include "ShellIntegration.h"
45 #include <QMessageBox>
47 #include <QDesktopWidget>
49 #include <QFileDialog>
50 #include <QInputDialog>
51 #include <QFileSystemModel>
52 #include <QDesktopServices>
54 #include <QPlastiqueStyle>
55 #include <QCleanlooksStyle>
56 #include <QWindowsVistaStyle>
57 #include <QWindowsStyle>
59 #include <QDragEnterEvent>
63 #include <QProcessEnvironment>
64 #include <QCryptographicHash>
65 #include <QTranslator>
74 #define ABORT_IF_BUSY if(m_banner->isVisible() || m_delayedFileTimer->isActive()) { MessageBeep(MB_ICONEXCLAMATION); return; }
75 #define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); }
76 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
77 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "−"))
78 #define FSLINK(PATH) QString("<a href=\"file:///%1\">%2</a>").arg(PATH).arg(QString(PATH).replace("-", "−"))
79 #define TEMP_HIDE_DROPBOX(CMD) { bool __dropBoxVisible = m_dropBox->isVisible(); if(__dropBoxVisible) m_dropBox->hide(); {CMD}; if(__dropBoxVisible) m_dropBox->show(); }
80 #define USE_NATIVE_FILE_DIALOG (lamexp_themes_enabled() || ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) < QSysInfo::WV_XP))
81 #define CENTER_CURRENT_OUTPUT_FOLDER_DELAYED QTimer::singleShot(125, this, SLOT(centerOutputFolderModel()))
82 #define SET_MODEL(VIEW, MODEL) { QItemSelectionModel *_tmp = (VIEW)->selectionModel(); (VIEW)->setModel(MODEL); LAMEXP_DELETE(_tmp); }
84 ////////////////////////////////////////////////////////////
86 ////////////////////////////////////////////////////////////
88 MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settingsModel, QWidget *parent)
91 m_fileListModel(fileListModel),
93 m_settings(settingsModel),
94 m_fileSystemModel(NULL),
95 m_neroEncoderAvailable(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")),
96 m_fhgEncoderAvailable(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll") && lamexp_check_tool("nsutil.dll") && lamexp_check_tool("libmp4v2.dll")),
97 m_qaacEncoderAvailable(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll")),
99 m_firstTimeShown(true),
100 m_outputFolderViewCentering(false),
101 m_outputFolderViewInitCounter(0)
103 //Init the dialog, from the .ui file
105 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint);
107 //Register meta types
108 qRegisterMetaType<AudioFileModel>("AudioFileModel");
110 //Enabled main buttons
111 connect(buttonAbout, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
112 connect(buttonStart, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
113 connect(buttonQuit, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
116 tabWidget->setCurrentIndex(0);
117 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
120 sourceFileView->setModel(m_fileListModel);
121 sourceFileView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
122 sourceFileView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
123 sourceFileView->setContextMenuPolicy(Qt::CustomContextMenu);
124 sourceFileView->viewport()->installEventFilter(this);
125 m_dropNoteLabel = new QLabel(sourceFileView);
126 m_dropNoteLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
127 SET_FONT_BOLD(m_dropNoteLabel, true);
128 SET_TEXT_COLOR(m_dropNoteLabel, Qt::darkGray);
129 m_sourceFilesContextMenu = new QMenu();
130 m_showDetailsContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/zoom.png"), "N/A");
131 m_previewContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/sound.png"), "N/A");
132 m_findFileContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/folder_go.png"), "N/A");
133 m_sourceFilesContextMenu->addSeparator();
134 m_exportCsvContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/table_save.png"), "N/A");
135 m_importCsvContextAction = m_sourceFilesContextMenu->addAction(QIcon(":/icons/folder_table.png"), "N/A");
136 SET_FONT_BOLD(m_showDetailsContextAction, true);
137 connect(buttonAddFiles, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
138 connect(buttonRemoveFile, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
139 connect(buttonClearFiles, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
140 connect(buttonFileUp, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
141 connect(buttonFileDown, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
142 connect(buttonShowDetails, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
143 connect(m_fileListModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(sourceModelChanged()));
144 connect(m_fileListModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(sourceModelChanged()));
145 connect(m_fileListModel, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
146 connect(sourceFileView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(sourceFilesContextMenu(QPoint)));
147 connect(sourceFileView->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
148 connect(sourceFileView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
149 connect(m_showDetailsContextAction, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
150 connect(m_previewContextAction, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
151 connect(m_findFileContextAction, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
152 connect(m_exportCsvContextAction, SIGNAL(triggered(bool)), this, SLOT(exportCsvContextActionTriggered()));
153 connect(m_importCsvContextAction, SIGNAL(triggered(bool)), this, SLOT(importCsvContextActionTriggered()));
156 outputFolderView->setHeaderHidden(true);
157 outputFolderView->setAnimated(false);
158 outputFolderView->setMouseTracking(false);
159 outputFolderView->setContextMenuPolicy(Qt::CustomContextMenu);
160 outputFolderView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
161 outputFolderView->installEventFilter(this);
162 outputFoldersEditorLabel->installEventFilter(this);
163 outputFoldersFovoritesLabel->installEventFilter(this);
164 while(saveToSourceFolderCheckBox->isChecked() != m_settings->outputToSourceDir()) saveToSourceFolderCheckBox->click();
165 prependRelativePathCheckBox->setChecked(m_settings->prependRelativeSourcePath());
166 connect(outputFolderView, SIGNAL(clicked(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
167 connect(outputFolderView, SIGNAL(activated(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
168 connect(outputFolderView, SIGNAL(pressed(QModelIndex)), this, SLOT(outputFolderViewClicked(QModelIndex)));
169 connect(outputFolderView, SIGNAL(entered(QModelIndex)), this, SLOT(outputFolderViewMoved(QModelIndex)));
170 connect(outputFolderView, SIGNAL(expanded(QModelIndex)), this, SLOT(outputFolderItemExpanded(QModelIndex)));
171 connect(buttonMakeFolder, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
172 connect(buttonGotoHome, SIGNAL(clicked()), SLOT(gotoHomeFolderButtonClicked()));
173 connect(buttonGotoDesktop, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
174 connect(buttonGotoMusic, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
175 connect(saveToSourceFolderCheckBox, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
176 connect(prependRelativePathCheckBox, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
177 connect(outputFolderEdit, SIGNAL(editingFinished()), this, SLOT(outputFolderEditFinished()));
178 if(m_outputFolderContextMenu = new QMenu())
180 m_showFolderContextAction = m_outputFolderContextMenu->addAction(QIcon(":/icons/zoom.png"), "N/A");
181 m_refreshFolderContextAction = m_outputFolderContextMenu->addAction(QIcon(":/icons/arrow_refresh.png"), "N/A");
182 m_outputFolderContextMenu->setDefaultAction(m_showFolderContextAction);
183 connect(outputFolderView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(outputFolderContextMenu(QPoint)));
184 connect(m_showFolderContextAction, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
185 connect(m_refreshFolderContextAction, SIGNAL(triggered(bool)), this, SLOT(refreshFolderContextActionTriggered()));
187 if(m_outputFolderFavoritesMenu = new QMenu())
189 m_addFavoriteFolderAction = m_outputFolderFavoritesMenu->addAction(QIcon(":/icons/add.png"), "N/A");
190 m_outputFolderFavoritesMenu->insertSeparator(m_addFavoriteFolderAction);
191 connect(m_addFavoriteFolderAction, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
193 outputFolderEdit->setVisible(false);
194 outputFolderLabel->installEventFilter(this);
195 if(m_outputFolderNoteBox = new QLabel(outputFolderView))
197 m_outputFolderNoteBox->setAutoFillBackground(true);
198 m_outputFolderNoteBox->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
199 m_outputFolderNoteBox->setFrameShape(QFrame::StyledPanel);
200 SET_FONT_BOLD(m_outputFolderNoteBox, true);
201 m_outputFolderNoteBox->hide();
204 outputFolderViewClicked(QModelIndex());
207 //Setup "Meta Data" tab
208 m_metaInfoModel = new MetaInfoModel(m_metaData, 6);
209 m_metaInfoModel->clearData();
210 m_metaInfoModel->setData(m_metaInfoModel->index(4, 1), m_settings->metaInfoPosition());
211 metaDataView->setModel(m_metaInfoModel);
212 metaDataView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
213 metaDataView->verticalHeader()->hide();
214 metaDataView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
215 while(writeMetaDataCheckBox->isChecked() != m_settings->writeMetaTags()) writeMetaDataCheckBox->click();
216 generatePlaylistCheckBox->setChecked(m_settings->createPlaylist());
217 connect(buttonEditMeta, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
218 connect(buttonClearMeta, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
219 connect(writeMetaDataCheckBox, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
220 connect(generatePlaylistCheckBox, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
222 //Setup "Compression" tab
223 m_encoderButtonGroup = new QButtonGroup(this);
224 m_encoderButtonGroup->addButton(radioButtonEncoderMP3, SettingsModel::MP3Encoder);
225 m_encoderButtonGroup->addButton(radioButtonEncoderVorbis, SettingsModel::VorbisEncoder);
226 m_encoderButtonGroup->addButton(radioButtonEncoderAAC, SettingsModel::AACEncoder);
227 m_encoderButtonGroup->addButton(radioButtonEncoderAC3, SettingsModel::AC3Encoder);
228 m_encoderButtonGroup->addButton(radioButtonEncoderFLAC, SettingsModel::FLACEncoder);
229 m_encoderButtonGroup->addButton(radioButtonEncoderDCA, SettingsModel::DCAEncoder);
230 m_encoderButtonGroup->addButton(radioButtonEncoderPCM, SettingsModel::PCMEncoder);
231 m_modeButtonGroup = new QButtonGroup(this);
232 m_modeButtonGroup->addButton(radioButtonModeQuality, SettingsModel::VBRMode);
233 m_modeButtonGroup->addButton(radioButtonModeAverageBitrate, SettingsModel::ABRMode);
234 m_modeButtonGroup->addButton(radioButtonConstBitrate, SettingsModel::CBRMode);
235 radioButtonEncoderAAC->setEnabled(m_neroEncoderAvailable || m_fhgEncoderAvailable || m_qaacEncoderAvailable);
236 radioButtonEncoderMP3->setChecked(m_settings->compressionEncoder() == SettingsModel::MP3Encoder);
237 radioButtonEncoderVorbis->setChecked(m_settings->compressionEncoder() == SettingsModel::VorbisEncoder);
238 radioButtonEncoderAAC->setChecked((m_settings->compressionEncoder() == SettingsModel::AACEncoder) && (m_neroEncoderAvailable || m_fhgEncoderAvailable || m_qaacEncoderAvailable));
239 radioButtonEncoderAC3->setChecked(m_settings->compressionEncoder() == SettingsModel::AC3Encoder);
240 radioButtonEncoderFLAC->setChecked(m_settings->compressionEncoder() == SettingsModel::FLACEncoder);
241 radioButtonEncoderDCA->setChecked(m_settings->compressionEncoder() == SettingsModel::DCAEncoder);
242 radioButtonEncoderPCM->setChecked(m_settings->compressionEncoder() == SettingsModel::PCMEncoder);
243 radioButtonModeQuality->setChecked(m_settings->compressionRCMode() == SettingsModel::VBRMode);
244 radioButtonModeAverageBitrate->setChecked(m_settings->compressionRCMode() == SettingsModel::ABRMode);
245 radioButtonConstBitrate->setChecked(m_settings->compressionRCMode() == SettingsModel::CBRMode);
246 sliderBitrate->setValue(m_settings->compressionBitrate());
247 connect(m_encoderButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
248 connect(m_modeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
249 connect(sliderBitrate, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
250 updateEncoder(m_encoderButtonGroup->checkedId());
252 //Setup "Advanced Options" tab
253 sliderLameAlgoQuality->setValue(m_settings->lameAlgoQuality());
254 if(m_settings->maximumInstances() > 0) sliderMaxInstances->setValue(m_settings->maximumInstances());
255 spinBoxBitrateManagementMin->setValue(m_settings->bitrateManagementMinRate());
256 spinBoxBitrateManagementMax->setValue(m_settings->bitrateManagementMaxRate());
257 spinBoxNormalizationFilter->setValue(static_cast<double>(m_settings->normalizationFilterMaxVolume()) / 100.0);
258 spinBoxToneAdjustBass->setValue(static_cast<double>(m_settings->toneAdjustBass()) / 100.0);
259 spinBoxToneAdjustTreble->setValue(static_cast<double>(m_settings->toneAdjustTreble()) / 100.0);
260 spinBoxAftenSearchSize->setValue(m_settings->aftenExponentSearchSize());
261 comboBoxMP3ChannelMode->setCurrentIndex(m_settings->lameChannelMode());
262 comboBoxSamplingRate->setCurrentIndex(m_settings->samplingRate());
263 comboBoxAACProfile->setCurrentIndex(m_settings->aacEncProfile());
264 comboBoxAftenCodingMode->setCurrentIndex(m_settings->aftenAudioCodingMode());
265 comboBoxAftenDRCMode->setCurrentIndex(m_settings->aftenDynamicRangeCompression());
266 comboBoxNormalizationMode->setCurrentIndex(m_settings->normalizationFilterEqualizationMode());
267 while(checkBoxBitrateManagement->isChecked() != m_settings->bitrateManagementEnabled()) checkBoxBitrateManagement->click();
268 while(checkBoxNeroAAC2PassMode->isChecked() != m_settings->neroAACEnable2Pass()) checkBoxNeroAAC2PassMode->click();
269 while(checkBoxAftenFastAllocation->isChecked() != m_settings->aftenFastBitAllocation()) checkBoxAftenFastAllocation->click();
270 while(checkBoxNormalizationFilter->isChecked() != m_settings->normalizationFilterEnabled()) checkBoxNormalizationFilter->click();
271 while(checkBoxAutoDetectInstances->isChecked() != (m_settings->maximumInstances() < 1)) checkBoxAutoDetectInstances->click();
272 while(checkBoxUseSystemTempFolder->isChecked() == m_settings->customTempPathEnabled()) checkBoxUseSystemTempFolder->click();
273 while(checkBoxRenameOutput->isChecked() != m_settings->renameOutputFilesEnabled()) checkBoxRenameOutput->click();
274 while(checkBoxForceStereoDownmix->isChecked() != m_settings->forceStereoDownmix()) checkBoxForceStereoDownmix->click();
275 checkBoxNeroAAC2PassMode->setEnabled(!(m_fhgEncoderAvailable || m_qaacEncoderAvailable));
276 lineEditCustomParamLAME->setText(m_settings->customParametersLAME());
277 lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEnc());
278 lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEnc());
279 lineEditCustomParamFLAC->setText(m_settings->customParametersFLAC());
280 lineEditCustomParamAften->setText(m_settings->customParametersAften());
281 lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPath()));
282 lineEditRenamePattern->setText(m_settings->renameOutputFilesPattern());
283 connect(sliderLameAlgoQuality, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
284 connect(checkBoxBitrateManagement, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
285 connect(spinBoxBitrateManagementMin, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
286 connect(spinBoxBitrateManagementMax, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
287 connect(comboBoxMP3ChannelMode, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
288 connect(comboBoxSamplingRate, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
289 connect(checkBoxNeroAAC2PassMode, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
290 connect(comboBoxAACProfile, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
291 connect(checkBoxNormalizationFilter, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
292 connect(comboBoxAftenCodingMode, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
293 connect(comboBoxAftenDRCMode, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
294 connect(spinBoxAftenSearchSize, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
295 connect(checkBoxAftenFastAllocation, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
296 connect(spinBoxNormalizationFilter, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
297 connect(comboBoxNormalizationMode, SIGNAL(currentIndexChanged(int)), this, SLOT(normalizationModeChanged(int)));
298 connect(spinBoxToneAdjustBass, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
299 connect(spinBoxToneAdjustTreble, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
300 connect(buttonToneAdjustReset, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
301 connect(lineEditCustomParamLAME, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
302 connect(lineEditCustomParamOggEnc, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
303 connect(lineEditCustomParamNeroAAC, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
304 connect(lineEditCustomParamFLAC, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
305 connect(lineEditCustomParamAften, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
306 connect(sliderMaxInstances, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
307 connect(checkBoxAutoDetectInstances, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
308 connect(buttonBrowseCustomTempFolder, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
309 connect(lineEditCustomTempFolder, SIGNAL(textChanged(QString)), this, SLOT(customTempFolderChanged(QString)));
310 connect(checkBoxUseSystemTempFolder, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
311 connect(buttonResetAdvancedOptions, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
312 connect(checkBoxRenameOutput, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
313 connect(lineEditRenamePattern, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
314 connect(lineEditRenamePattern, SIGNAL(textChanged(QString)), this, SLOT(renameOutputPatternChanged(QString)));
315 connect(labelShowRenameMacros, SIGNAL(linkActivated(QString)), this, SLOT(showRenameMacros(QString)));
316 connect(checkBoxForceStereoDownmix, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
317 updateLameAlgoQuality(sliderLameAlgoQuality->value());
318 updateMaximumInstances(sliderMaxInstances->value());
319 toneAdjustTrebleChanged(spinBoxToneAdjustTreble->value());
320 toneAdjustBassChanged(spinBoxToneAdjustBass->value());
321 customParamsChanged();
323 //Activate file menu actions
324 actionOpenFolder->setData(QVariant::fromValue<bool>(false));
325 actionOpenFolderRecursively->setData(QVariant::fromValue<bool>(true));
326 connect(actionOpenFolder, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
327 connect(actionOpenFolderRecursively, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
329 //Activate view menu actions
330 m_tabActionGroup = new QActionGroup(this);
331 m_tabActionGroup->addAction(actionSourceFiles);
332 m_tabActionGroup->addAction(actionOutputDirectory);
333 m_tabActionGroup->addAction(actionCompression);
334 m_tabActionGroup->addAction(actionMetaData);
335 m_tabActionGroup->addAction(actionAdvancedOptions);
336 actionSourceFiles->setData(0);
337 actionOutputDirectory->setData(1);
338 actionMetaData->setData(2);
339 actionCompression->setData(3);
340 actionAdvancedOptions->setData(4);
341 actionSourceFiles->setChecked(true);
342 connect(m_tabActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(tabActionActivated(QAction*)));
344 //Activate style menu actions
345 m_styleActionGroup = new QActionGroup(this);
346 m_styleActionGroup->addAction(actionStylePlastique);
347 m_styleActionGroup->addAction(actionStyleCleanlooks);
348 m_styleActionGroup->addAction(actionStyleWindowsVista);
349 m_styleActionGroup->addAction(actionStyleWindowsXP);
350 m_styleActionGroup->addAction(actionStyleWindowsClassic);
351 actionStylePlastique->setData(0);
352 actionStyleCleanlooks->setData(1);
353 actionStyleWindowsVista->setData(2);
354 actionStyleWindowsXP->setData(3);
355 actionStyleWindowsClassic->setData(4);
356 actionStylePlastique->setChecked(true);
357 actionStyleWindowsXP->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_XP && lamexp_themes_enabled());
358 actionStyleWindowsVista->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) >= QSysInfo::WV_VISTA && lamexp_themes_enabled());
359 connect(m_styleActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(styleActionActivated(QAction*)));
360 styleActionActivated(NULL);
362 //Populate the language menu
363 m_languageActionGroup = new QActionGroup(this);
364 QStringList translations = lamexp_query_translations();
365 while(!translations.isEmpty())
367 QString langId = translations.takeFirst();
368 QAction *currentLanguage = new QAction(this);
369 currentLanguage->setData(langId);
370 currentLanguage->setText(lamexp_translation_name(langId));
371 currentLanguage->setIcon(QIcon(QString(":/flags/%1.png").arg(langId)));
372 currentLanguage->setCheckable(true);
373 m_languageActionGroup->addAction(currentLanguage);
374 menuLanguage->insertAction(actionLoadTranslationFromFile, currentLanguage);
376 menuLanguage->insertSeparator(actionLoadTranslationFromFile);
377 connect(actionLoadTranslationFromFile, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
378 connect(m_languageActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(languageActionActivated(QAction*)));
380 //Activate tools menu actions
381 actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
382 actionDisableSounds->setChecked(!m_settings->soundsEnabled());
383 actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
384 actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
385 actionDisableShellIntegration->setChecked(!m_settings->shellIntegrationEnabled());
386 actionDisableShellIntegration->setDisabled(lamexp_portable_mode() && actionDisableShellIntegration->isChecked());
387 actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta() || lamexp_version_demo());
388 actionCheckForBetaUpdates->setEnabled(!lamexp_version_demo());
389 actionHibernateComputer->setChecked(m_settings->hibernateComputer());
390 actionHibernateComputer->setEnabled(lamexp_is_hibernation_supported());
391 connect(actionDisableUpdateReminder, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
392 connect(actionDisableSounds, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
393 connect(actionDisableNeroAacNotifications, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
394 connect(actionDisableSlowStartupNotifications, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
395 connect(actionDisableShellIntegration, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
396 connect(actionShowDropBoxWidget, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
397 connect(actionHibernateComputer, SIGNAL(triggered(bool)), this, SLOT(hibernateComputerActionTriggered(bool)));
398 connect(actionCheckForBetaUpdates, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
399 connect(actionImportCueSheet, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
401 //Activate help menu actions
402 actionVisitHomepage->setData(QString::fromLatin1(lamexp_website_url()));
403 actionVisitSupport->setData(QString::fromLatin1(lamexp_support_url()));
404 actionDocumentFAQ->setData(QString("%1/FAQ.html").arg(QApplication::applicationDirPath()));
405 actionDocumentChangelog->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
406 actionDocumentTranslate->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
407 connect(actionCheckUpdates, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
408 connect(actionVisitHomepage, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
409 connect(actionVisitSupport, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
410 connect(actionDocumentFAQ, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
411 connect(actionDocumentChangelog, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
412 connect(actionDocumentTranslate, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
414 //Center window in screen
415 QRect desktopRect = QApplication::desktop()->screenGeometry();
416 QRect thisRect = this->geometry();
417 move((desktopRect.width() - thisRect.width()) / 2, (desktopRect.height() - thisRect.height()) / 2);
418 setMinimumSize(thisRect.width(), thisRect.height());
421 m_banner = new WorkingBanner(this);
423 //Create DropBox widget
424 m_dropBox = new DropBox(this, m_fileListModel, m_settings);
425 connect(m_fileListModel, SIGNAL(modelReset()), m_dropBox, SLOT(modelChanged()));
426 connect(m_fileListModel, SIGNAL(rowsInserted(QModelIndex,int,int)), m_dropBox, SLOT(modelChanged()));
427 connect(m_fileListModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), m_dropBox, SLOT(modelChanged()));
428 connect(m_fileListModel, SIGNAL(rowAppended()), m_dropBox, SLOT(modelChanged()));
430 //Create message handler thread
431 m_messageHandler = new MessageHandlerThread();
432 m_delayedFileList = new QStringList();
433 m_delayedFileTimer = new QTimer();
434 m_delayedFileTimer->setSingleShot(true);
435 m_delayedFileTimer->setInterval(5000);
436 connect(m_messageHandler, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection);
437 connect(m_messageHandler, SIGNAL(fileReceived(QString)), this, SLOT(addFileDelayed(QString)), Qt::QueuedConnection);
438 connect(m_messageHandler, SIGNAL(folderReceived(QString, bool)), this, SLOT(addFolderDelayed(QString, bool)), Qt::QueuedConnection);
439 connect(m_messageHandler, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection);
440 connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
441 m_messageHandler->start();
443 //Load translation file
444 QList<QAction*> languageActions = m_languageActionGroup->actions();
445 while(!languageActions.isEmpty())
447 QAction *currentLanguage = languageActions.takeFirst();
448 if(currentLanguage->data().toString().compare(m_settings->currentLanguage(), Qt::CaseInsensitive) == 0)
450 currentLanguage->setChecked(true);
451 languageActionActivated(currentLanguage);
455 //Re-translate (make sure we translate once)
456 QEvent languageChangeEvent(QEvent::LanguageChange);
457 changeEvent(&languageChangeEvent);
460 this->setAcceptDrops(true);
463 ////////////////////////////////////////////////////////////
465 ////////////////////////////////////////////////////////////
467 MainWindow::~MainWindow(void)
469 //Stop message handler thread
470 if(m_messageHandler && m_messageHandler->isRunning())
472 m_messageHandler->stop();
473 if(!m_messageHandler->wait(2500))
475 m_messageHandler->terminate();
476 m_messageHandler->wait();
481 SET_MODEL(sourceFileView, NULL);
482 SET_MODEL(outputFolderView, NULL);
483 SET_MODEL(metaDataView, NULL);
486 LAMEXP_DELETE(m_tabActionGroup);
487 LAMEXP_DELETE(m_styleActionGroup);
488 LAMEXP_DELETE(m_languageActionGroup);
489 LAMEXP_DELETE(m_banner);
490 LAMEXP_DELETE(m_fileSystemModel);
491 LAMEXP_DELETE(m_messageHandler);
492 LAMEXP_DELETE(m_delayedFileList);
493 LAMEXP_DELETE(m_delayedFileTimer);
494 LAMEXP_DELETE(m_metaInfoModel);
495 LAMEXP_DELETE(m_encoderButtonGroup);
496 LAMEXP_DELETE(m_encoderButtonGroup);
497 LAMEXP_DELETE(m_sourceFilesContextMenu);
498 LAMEXP_DELETE(m_outputFolderFavoritesMenu);
499 LAMEXP_DELETE(m_outputFolderContextMenu);
500 LAMEXP_DELETE(m_dropBox);
503 ////////////////////////////////////////////////////////////
505 ////////////////////////////////////////////////////////////
508 * Add file to source list
510 void MainWindow::addFiles(const QStringList &files)
517 tabWidget->setCurrentIndex(0);
519 int timeMT = 0, timeST = 0;
523 FileAnalyzer_ST *analyzerPre = new FileAnalyzer_ST(files);
524 connect(analyzerPre, SIGNAL(fileSelected(QString)), m_banner, SLOT(setText(QString)), Qt::QueuedConnection);
525 connect(analyzerPre, SIGNAL(progressValChanged(unsigned int)), m_banner, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection);
526 connect(analyzerPre, SIGNAL(progressMaxChanged(unsigned int)), m_banner, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection);
527 connect(analyzerPre, SIGNAL(fileAnalyzed(AudioFileModel)), m_fileListModel, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection);
528 connect(m_banner, SIGNAL(userAbort()), analyzerPre, SLOT(abortProcess()), Qt::DirectConnection);
532 m_fileListModel->setBlockUpdates(true);
533 m_banner->show(tr("Adding file(s), please wait..."), analyzerPre);
537 /* ignore any exceptions that may occur */
542 FileAnalyzer *analyzer = new FileAnalyzer(files);
543 connect(analyzer, SIGNAL(fileSelected(QString)), m_banner, SLOT(setText(QString)), Qt::QueuedConnection);
544 connect(analyzer, SIGNAL(progressValChanged(unsigned int)), m_banner, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection);
545 connect(analyzer, SIGNAL(progressMaxChanged(unsigned int)), m_banner, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection);
546 connect(analyzer, SIGNAL(fileAnalyzed(AudioFileModel)), m_fileListModel, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection);
547 connect(m_banner, SIGNAL(userAbort()), analyzer, SLOT(abortProcess()), Qt::DirectConnection);
551 m_fileListModel->setBlockUpdates(true);
552 QTime startTime = QTime::currentTime();
553 m_banner->show(tr("Adding file(s), please wait..."), analyzer);
554 timeMT = startTime.secsTo(QTime::currentTime());
558 /* ignore any exceptions that may occur */
563 FileAnalyzer_ST *analyzerST = new FileAnalyzer_ST(files);
564 connect(analyzerST, SIGNAL(fileSelected(QString)), m_banner, SLOT(setText(QString)), Qt::QueuedConnection);
565 connect(analyzerST, SIGNAL(progressValChanged(unsigned int)), m_banner, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection);
566 connect(analyzerST, SIGNAL(progressMaxChanged(unsigned int)), m_banner, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection);
567 connect(analyzerST, SIGNAL(fileAnalyzed(AudioFileModel)), m_fileListModel, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection);
568 connect(m_banner, SIGNAL(userAbort()), analyzerST, SLOT(abortProcess()), Qt::DirectConnection);
572 m_fileListModel->setBlockUpdates(true);
573 QTime startTime = QTime::currentTime();
574 m_banner->show(tr("Adding file(s), please wait..."), analyzerST);
575 timeST = startTime.secsTo(QTime::currentTime());
579 /* ignore any exceptions that may occur */
584 if(timeST > 0 && timeMT > 0)
586 double speedUp = static_cast<double>(timeST) / static_cast<double>(timeMT);
587 qWarning("ST: %d, MT: %d", timeST, timeMT);
588 QMessageBox::information(this, "Speed Up", QString().sprintf("Announcement: The new multi-threaded file analyzer is %.1fx faster !!!", speedUp), QMessageBox::Ok);
592 QMessageBox::information(this, "Speed Up", "Couldn't compare the the new multi-threaded file analyzer this time!", QMessageBox::Ok);
597 m_fileListModel->setBlockUpdates(false);
598 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
599 sourceFileView->update();
600 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
601 sourceFileView->scrollToBottom();
602 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
604 if(analyzer->filesDenied())
606 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."))));
608 if(analyzer->filesDummyCDDA())
610 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>"))));
612 if(analyzer->filesCueSheet())
614 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."))));
616 if(analyzer->filesRejected())
618 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."))));
621 LAMEXP_DELETE(analyzer);
622 LAMEXP_DELETE(analyzerST);
623 LAMEXP_DELETE(analyzerPre);
629 * Add folder to source list
631 void MainWindow::addFolder(const QString &path, bool recursive, bool delayed)
633 QFileInfoList folderInfoList;
634 folderInfoList << QFileInfo(path);
635 QStringList fileList;
637 m_banner->show(tr("Scanning folder(s) for files, please wait..."));
639 QApplication::processEvents();
640 GetAsyncKeyState(VK_ESCAPE);
642 while(!folderInfoList.isEmpty())
644 if(GetAsyncKeyState(VK_ESCAPE) & 0x0001)
646 MessageBeep(MB_ICONERROR);
647 qWarning("Operation cancelled by user!");
652 QDir currentDir(folderInfoList.takeFirst().canonicalFilePath());
653 QFileInfoList fileInfoList = currentDir.entryInfoList(QDir::Files | QDir::NoSymLinks);
655 while(!fileInfoList.isEmpty())
657 fileList << fileInfoList.takeFirst().canonicalFilePath();
660 QApplication::processEvents();
664 folderInfoList.append(currentDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks));
665 QApplication::processEvents();
670 QApplication::processEvents();
672 if(!fileList.isEmpty())
676 addFilesDelayed(fileList);
688 bool MainWindow::checkForUpdates(void)
690 bool bReadyToInstall = false;
692 UpdateDialog *updateDialog = new UpdateDialog(m_settings, this);
693 updateDialog->exec();
695 if(updateDialog->getSuccess())
697 m_settings->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate));
698 bReadyToInstall = updateDialog->updateReadyToInstall();
701 LAMEXP_DELETE(updateDialog);
702 return bReadyToInstall;
705 void MainWindow::refreshFavorites(void)
707 QList<QAction*> folderList = m_outputFolderFavoritesMenu->actions();
708 QStringList favorites = m_settings->favoriteOutputFolders().split("|", QString::SkipEmptyParts);
709 while(favorites.count() > 6) favorites.removeFirst();
711 while(!folderList.isEmpty())
713 QAction *currentItem = folderList.takeFirst();
714 if(currentItem->isSeparator()) break;
715 m_outputFolderFavoritesMenu->removeAction(currentItem);
716 LAMEXP_DELETE(currentItem);
719 QAction *lastItem = m_outputFolderFavoritesMenu->actions().first();
721 while(!favorites.isEmpty())
723 QString path = favorites.takeLast();
724 if(QDir(path).exists())
726 QAction *action = new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path), this);
727 action->setData(path);
728 m_outputFolderFavoritesMenu->insertAction(lastItem, action);
729 connect(action, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
735 ////////////////////////////////////////////////////////////
737 ////////////////////////////////////////////////////////////
740 * Window is about to be shown
742 void MainWindow::showEvent(QShowEvent *event)
745 m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height());
746 sourceModelChanged();
748 if(!event->spontaneous())
750 tabWidget->setCurrentIndex(0);
755 m_firstTimeShown = false;
756 QTimer::singleShot(0, this, SLOT(windowShown()));
760 if(m_settings->dropBoxWidgetEnabled())
762 m_dropBox->setVisible(true);
768 * Re-translate the UI
770 void MainWindow::changeEvent(QEvent *e)
772 if(e->type() == QEvent::LanguageChange)
774 int comboBoxIndex[6];
776 //Backup combobox indices, as retranslateUi() resets
777 comboBoxIndex[0] = comboBoxMP3ChannelMode->currentIndex();
778 comboBoxIndex[1] = comboBoxSamplingRate->currentIndex();
779 comboBoxIndex[2] = comboBoxAACProfile->currentIndex();
780 comboBoxIndex[3] = comboBoxAftenCodingMode->currentIndex();
781 comboBoxIndex[4] = comboBoxAftenDRCMode->currentIndex();
782 comboBoxIndex[5] = comboBoxNormalizationMode->currentIndex();
784 //Re-translate from UIC
785 Ui::MainWindow::retranslateUi(this);
787 //Restore combobox indices
788 comboBoxMP3ChannelMode->setCurrentIndex(comboBoxIndex[0]);
789 comboBoxSamplingRate->setCurrentIndex(comboBoxIndex[1]);
790 comboBoxAACProfile->setCurrentIndex(comboBoxIndex[2]);
791 comboBoxAftenCodingMode->setCurrentIndex(comboBoxIndex[3]);
792 comboBoxAftenDRCMode->setCurrentIndex(comboBoxIndex[4]);
793 comboBoxNormalizationMode->setCurrentIndex(comboBoxIndex[5]);
795 //Update the window title
798 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
800 else if(lamexp_version_demo())
802 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
805 //Manually re-translate widgets that UIC doesn't handle
806 m_dropNoteLabel->setText(QString("» %1 «").arg(tr("You can drop in audio files here!")));
807 m_outputFolderNoteBox->setText(tr("Initializing directory outline, please be patient..."));
808 m_showDetailsContextAction->setText(tr("Show Details"));
809 m_previewContextAction->setText(tr("Open File in External Application"));
810 m_findFileContextAction->setText(tr("Browse File Location"));
811 m_showFolderContextAction->setText(tr("Browse Selected Folder"));
812 m_refreshFolderContextAction->setText(tr("Refresh Directory Outline"));
813 m_addFavoriteFolderAction->setText(tr("Bookmark Current Output Folder"));
814 m_exportCsvContextAction->setText(tr("Export Meta Tags to CSV File"));
815 m_importCsvContextAction->setText(tr("Import Meta Tags from CSV File"));
818 m_metaInfoModel->clearData();
819 m_metaInfoModel->setData(m_metaInfoModel->index(4, 1), m_settings->metaInfoPosition());
820 updateEncoder(m_settings->compressionEncoder());
821 updateLameAlgoQuality(sliderLameAlgoQuality->value());
822 updateMaximumInstances(sliderMaxInstances->value());
823 renameOutputPatternChanged(lineEditRenamePattern->text());
825 //Re-install shell integration
826 if(m_settings->shellIntegrationEnabled())
828 ShellIntegration::install();
831 //Force resize, if needed
832 tabPageChanged(tabWidget->currentIndex());
837 * File dragged over window
839 void MainWindow::dragEnterEvent(QDragEnterEvent *event)
841 QStringList formats = event->mimeData()->formats();
843 if(formats.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive) && formats.contains("text/uri-list", Qt::CaseInsensitive))
845 event->acceptProposedAction();
850 * File dropped onto window
852 void MainWindow::dropEvent(QDropEvent *event)
856 QStringList droppedFiles;
857 QList<QUrl> urls = event->mimeData()->urls();
859 while(!urls.isEmpty())
861 QUrl currentUrl = urls.takeFirst();
862 QFileInfo file(currentUrl.toLocalFile());
869 qDebug("Dropped File: %s", file.canonicalFilePath().toUtf8().constData());
870 droppedFiles << file.canonicalFilePath();
875 qDebug("Dropped Folder: %s", file.canonicalFilePath().toUtf8().constData());
876 QList<QFileInfo> list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Files | QDir::NoSymLinks);
879 for(int j = 0; j < list.count(); j++)
881 droppedFiles << list.at(j).canonicalFilePath();
886 list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
887 for(int j = 0; j < list.count(); j++)
889 qDebug("Descending to Folder: %s", list.at(j).canonicalFilePath().toUtf8().constData());
890 urls.prepend(QUrl::fromLocalFile(list.at(j).canonicalFilePath()));
896 if(!droppedFiles.isEmpty())
898 addFilesDelayed(droppedFiles, true);
903 * Window tries to close
905 void MainWindow::closeEvent(QCloseEvent *event)
907 if(m_banner->isVisible() || m_delayedFileTimer->isActive())
909 MessageBeep(MB_ICONEXCLAMATION);
922 void MainWindow::resizeEvent(QResizeEvent *event)
924 if(event) QMainWindow::resizeEvent(event);
925 m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height());
927 if(QWidget *port = outputFolderView->viewport())
929 m_outputFolderNoteBox->setGeometry(16, (port->height() - 64) / 2, port->width() - 32, 64);
934 * Key press event filter
936 void MainWindow::keyPressEvent(QKeyEvent *e)
938 if(e->key() == Qt::Key_F5)
940 if(outputFolderView->isVisible())
942 QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
947 if(e->key() == Qt::Key_Delete)
949 if(sourceFileView->isVisible())
951 QTimer::singleShot(0, this, SLOT(removeFileButtonClicked()));
956 QMainWindow::keyPressEvent(e);
962 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
964 if(obj == m_fileSystemModel)
966 if(QApplication::overrideCursor() == NULL)
968 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
969 QTimer::singleShot(250, this, SLOT(restoreCursor()));
972 else if(obj == outputFolderView)
974 switch(event->type())
978 case QEvent::KeyPress:
979 case QEvent::KeyRelease:
980 case QEvent::FocusIn:
981 case QEvent::FocusOut:
982 case QEvent::TouchEnd:
983 outputFolderViewClicked(outputFolderView->currentIndex());
987 else if(obj == outputFolderLabel)
989 switch(event->type())
991 case QEvent::MouseButtonPress:
992 if(dynamic_cast<QMouseEvent*>(event)->button() == Qt::LeftButton)
994 QString path = outputFolderLabel->text();
995 if(!path.endsWith(QDir::separator())) path.append(QDir::separator());
996 ShellExecuteW(reinterpret_cast<HWND>(this->winId()), L"explore", QWCHAR(path), NULL, NULL, SW_SHOW);
1000 outputFolderLabel->setForegroundRole(QPalette::Link);
1003 outputFolderLabel->setForegroundRole(QPalette::WindowText);
1007 else if(obj == outputFoldersFovoritesLabel)
1009 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
1010 QPoint pos = (mouseEvent != NULL) ? mouseEvent->pos() : QPoint();
1011 QWidget *sender = dynamic_cast<QLabel*>(obj);
1013 switch(event->type())
1016 outputFoldersFovoritesLabel->setFrameShadow(QFrame::Raised);
1018 case QEvent::MouseButtonPress:
1019 outputFoldersFovoritesLabel->setFrameShadow(QFrame::Sunken);
1021 case QEvent::MouseButtonRelease:
1022 outputFoldersFovoritesLabel->setFrameShadow(QFrame::Raised);
1023 if(sender && mouseEvent)
1025 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0 && mouseEvent->button() != Qt::MidButton)
1027 if(outputFolderView->isEnabled())
1029 m_outputFolderFavoritesMenu->popup(sender->mapToGlobal(pos));
1035 outputFoldersFovoritesLabel->setFrameShadow(QFrame::Plain);
1039 else if(obj == outputFoldersEditorLabel)
1041 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
1042 QPoint pos = (mouseEvent != NULL) ? mouseEvent->pos() : QPoint();
1043 QWidget *sender = dynamic_cast<QLabel*>(obj);
1045 switch(event->type())
1048 outputFoldersEditorLabel->setFrameShadow(QFrame::Raised);
1050 case QEvent::MouseButtonPress:
1051 outputFoldersEditorLabel->setFrameShadow(QFrame::Sunken);
1053 case QEvent::MouseButtonRelease:
1054 outputFoldersEditorLabel->setFrameShadow(QFrame::Raised);
1055 if(sender && mouseEvent)
1057 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0 && mouseEvent->button() != Qt::MidButton)
1059 if(outputFolderView->isEnabled())
1061 outputFolderView->setEnabled(false);
1062 outputFolderLabel->setVisible(false);
1063 outputFolderEdit->setVisible(true);
1064 outputFolderEdit->setText(outputFolderLabel->text());
1065 outputFolderEdit->selectAll();
1066 outputFolderEdit->setFocus();
1072 outputFoldersEditorLabel->setFrameShadow(QFrame::Plain);
1077 return QMainWindow::eventFilter(obj, event);
1080 bool MainWindow::event(QEvent *e)
1084 case lamexp_event_queryendsession:
1085 qWarning("System is shutting down, main window prepares to close...");
1086 if(m_banner->isVisible()) m_banner->close();
1087 if(m_delayedFileTimer->isActive()) m_delayedFileTimer->stop();
1089 case lamexp_event_endsession:
1090 qWarning("System is shutting down, main window will close now...");
1095 QApplication::processEvents(QEventLoop::WaitForMoreEvents & QEventLoop::ExcludeUserInputEvents);
1098 m_fileListModel->clearFiles();
1100 case QEvent::MouseButtonPress:
1101 if(outputFolderEdit->isVisible())
1103 QTimer::singleShot(0, this, SLOT(outputFolderEditFinished()));
1106 return QMainWindow::event(e);
1110 bool MainWindow::winEvent(MSG *message, long *result)
1112 return WinSevenTaskbar::handleWinEvent(message, result);
1115 ////////////////////////////////////////////////////////////
1117 ////////////////////////////////////////////////////////////
1119 // =========================================================
1120 // Show window slots
1121 // =========================================================
1126 void MainWindow::windowShown(void)
1128 QStringList arguments = QApplication::arguments();
1131 bool firstRun = false;
1132 for(int i = 0; i < arguments.count(); i++)
1134 if(!arguments[i].compare("--first-run", Qt::CaseInsensitive)) firstRun = true;
1138 if((m_settings->licenseAccepted() <= 0) || firstRun)
1142 if((m_settings->licenseAccepted() == 0) || firstRun)
1144 AboutDialog *about = new AboutDialog(m_settings, this, true);
1145 iAccepted = about->exec();
1146 LAMEXP_DELETE(about);
1151 m_settings->licenseAccepted(-1);
1152 QApplication::processEvents();
1153 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1154 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
1155 QFileInfo uninstallerInfo = QFileInfo(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()));
1156 if(uninstallerInfo.exists())
1158 QString uninstallerDir = uninstallerInfo.canonicalPath();
1159 QString uninstallerPath = uninstallerInfo.canonicalFilePath();
1160 for(int i = 0; i < 3; i++)
1162 HINSTANCE res = ShellExecuteW(reinterpret_cast<HWND>(this->winId()), L"open", QWCHAR(QDir::toNativeSeparators(uninstallerPath)), L"/Force", QWCHAR(QDir::toNativeSeparators(uninstallerDir)), SW_SHOWNORMAL);
1163 if(reinterpret_cast<int>(res) > 32) break;
1168 MoveFileEx(QWCHAR(QDir::toNativeSeparators(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath())), NULL, MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING);
1170 QApplication::quit();
1174 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WOOHOO), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1175 m_settings->licenseAccepted(1);
1176 if(lamexp_version_demo()) showAnnounceBox();
1179 //Check for expiration
1180 if(lamexp_version_demo())
1182 if(QDate::currentDate() >= lamexp_version_expires())
1184 qWarning("Binary has expired !!!");
1185 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1186 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)
1190 QApplication::quit();
1195 //Slow startup indicator
1196 if(m_settings->slowStartup() && m_settings->antivirNotificationsEnabled())
1199 message += NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
1200 message += NOBR(tr("Please refer to the %1 document for details and solutions!")).arg("<a href=\"http://lamexp.git.sourceforge.net/git/gitweb.cgi?p=lamexp/lamexp;a=blob_plain;f=doc/FAQ.html;hb=HEAD#df406578\">F.A.Q.</a>").append("<br>");
1201 if(QMessageBox::warning(this, tr("Slow Startup"), message, tr("Discard"), tr("Don't Show Again")) == 1)
1203 m_settings->antivirNotificationsEnabled(false);
1204 actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
1209 if(QDate::currentDate() >= lamexp_version_date().addYears(1))
1211 qWarning("Binary is more than a year old, time to update!");
1212 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"));
1216 if(checkForUpdates())
1218 QApplication::quit();
1223 QApplication::quit();
1226 QEventLoop loop; QTimer::singleShot(7000, &loop, SLOT(quit()));
1227 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WAITING), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
1228 m_banner->show(tr("Skipping update check this time, please be patient..."), &loop);
1232 else if(m_settings->autoUpdateEnabled())
1234 QDate lastUpdateCheck = QDate::fromString(m_settings->autoUpdateLastCheck(), Qt::ISODate);
1235 if(!firstRun && (!lastUpdateCheck.isValid() || QDate::currentDate() >= lastUpdateCheck.addDays(14)))
1237 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)
1239 if(checkForUpdates())
1241 QApplication::quit();
1248 //Check for AAC support
1249 if(m_neroEncoderAvailable)
1251 if(m_settings->neroAacNotificationsEnabled())
1253 if(lamexp_tool_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1255 QString messageText;
1256 messageText += NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1257 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>");
1258 messageText += NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1259 messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br><br>";
1260 messageText += NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
1261 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText);
1267 if(m_settings->neroAacNotificationsEnabled() && (!(m_fhgEncoderAvailable || m_qaacEncoderAvailable)))
1269 QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1270 if(appPath.isEmpty()) appPath = QCoreApplication::applicationDirPath();
1271 QString messageText;
1272 messageText += NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1273 messageText += NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1274 messageText += NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1275 messageText += QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath)));
1276 messageText += NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1277 messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br>";
1278 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText, tr("Discard"), tr("Don't Show Again")) == 1)
1280 m_settings->neroAacNotificationsEnabled(false);
1281 actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
1286 //Add files from the command-line
1287 for(int i = 0; i < arguments.count() - 1; i++)
1289 QStringList addedFiles;
1290 if(!arguments[i].compare("--add", Qt::CaseInsensitive))
1292 QFileInfo currentFile(arguments[++i].trimmed());
1293 qDebug("Adding file from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1294 addedFiles.append(currentFile.absoluteFilePath());
1296 if(!addedFiles.isEmpty())
1298 addFilesDelayed(addedFiles);
1302 //Add folders from the command-line
1303 for(int i = 0; i < arguments.count() - 1; i++)
1305 if(!arguments[i].compare("--add-folder", Qt::CaseInsensitive))
1307 QFileInfo currentFile(arguments[++i].trimmed());
1308 qDebug("Adding folder from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1309 addFolder(currentFile.absoluteFilePath(), false, true);
1311 if(!arguments[i].compare("--add-recursive", Qt::CaseInsensitive))
1313 QFileInfo currentFile(arguments[++i].trimmed());
1314 qDebug("Adding folder recursively from CLI: %s", currentFile.absoluteFilePath().toUtf8().constData());
1315 addFolder(currentFile.absoluteFilePath(), true, true);
1319 //Enable shell integration
1320 if(m_settings->shellIntegrationEnabled())
1322 ShellIntegration::install();
1325 //Make DropBox visible
1326 if(m_settings->dropBoxWidgetEnabled())
1328 m_dropBox->setVisible(true);
1335 void MainWindow::showAnnounceBox(void)
1337 const unsigned int timeout = 8U;
1339 const QString announceText = QString("%1<br><br>%2<br><nobr><tt>%3</tt></nobr><br>").arg
1341 NOBR("We are still looking for LameXP translators!"),
1342 NOBR("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:"),
1343 LINK("http://mulder.brhack.net/public/doc/lamexp_translate.html")
1346 QMessageBox *announceBox = new QMessageBox(QMessageBox::Warning, "We want you!", announceText, QMessageBox::NoButton, this);
1347 announceBox->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
1348 announceBox->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1350 QTimer *timers[timeout+1];
1351 QPushButton *buttons[timeout+1];
1353 for(unsigned int i = 0; i <= timeout; i++)
1355 QString text = (i > 0) ? QString("%1 (%2)").arg(tr("Discard"), QString::number(i)) : tr("Discard");
1356 buttons[i] = announceBox->addButton(text, (i > 0) ? QMessageBox::NoRole : QMessageBox::AcceptRole);
1359 for(unsigned int i = 0; i <= timeout; i++)
1361 buttons[i]->setEnabled(i == 0);
1362 buttons[i]->setVisible(i == timeout);
1365 for(unsigned int i = 0; i < timeout; i++)
1367 timers[i] = new QTimer(this);
1368 timers[i]->setSingleShot(true);
1369 timers[i]->setInterval(1000);
1370 connect(timers[i], SIGNAL(timeout()), buttons[i+1], SLOT(hide()));
1371 connect(timers[i], SIGNAL(timeout()), buttons[i], SLOT(show()));
1374 connect(timers[i], SIGNAL(timeout()), timers[i-1], SLOT(start()));
1378 timers[timeout-1]->start();
1379 announceBox->exec();
1381 for(unsigned int i = 0; i < timeout; i++)
1384 LAMEXP_DELETE(timers[i]);
1387 LAMEXP_DELETE(announceBox);
1390 // =========================================================
1391 // Main button solots
1392 // =========================================================
1397 void MainWindow::encodeButtonClicked(void)
1399 static const unsigned __int64 oneGigabyte = 1073741824ui64;
1400 static const unsigned __int64 minimumFreeDiskspaceMultiplier = 2ui64;
1401 static const char *writeTestBuffer = "LAMEXP_WRITE_TEST";
1405 if(m_fileListModel->rowCount() < 1)
1407 QMessageBox::warning(this, tr("LameXP"), NOBR(tr("You must add at least one file to the list before proceeding!")));
1408 tabWidget->setCurrentIndex(0);
1412 QString tempFolder = m_settings->customTempPathEnabled() ? m_settings->customTempPath() : lamexp_temp_folder2();
1413 if(!QFileInfo(tempFolder).exists() || !QFileInfo(tempFolder).isDir())
1415 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)
1417 while(checkBoxUseSystemTempFolder->isChecked() == m_settings->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder->click();
1423 unsigned __int64 currentFreeDiskspace = lamexp_free_diskspace(tempFolder, &ok);
1425 if(ok && (currentFreeDiskspace < (oneGigabyte * minimumFreeDiskspaceMultiplier)))
1427 QStringList tempFolderParts = tempFolder.split("/", QString::SkipEmptyParts, Qt::CaseInsensitive);
1428 tempFolderParts.takeLast();
1429 if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
1430 QString lowDiskspaceMsg = QString("%1<br>%2<br><br>%3<br>%4<br>").arg
1432 NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier))),
1433 NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")),
1434 NOBR(tr("Your TEMP folder is located at:")),
1435 QString("<nobr><tt>%1</tt></nobr>").arg(FSLINK(tempFolderParts.join("\\")))
1437 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1440 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(lamexp_known_folder(lamexp_folder_systemfolder)), QStringList() << "/D" << tempFolderParts.first());
1445 QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!")));
1450 switch(m_settings->compressionEncoder())
1452 case SettingsModel::MP3Encoder:
1453 case SettingsModel::VorbisEncoder:
1454 case SettingsModel::AACEncoder:
1455 case SettingsModel::AC3Encoder:
1456 case SettingsModel::FLACEncoder:
1457 case SettingsModel::DCAEncoder:
1458 case SettingsModel::PCMEncoder:
1461 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1462 tabWidget->setCurrentIndex(3);
1466 if(!m_settings->outputToSourceDir())
1468 QFile writeTest(QString("%1/~%2.txt").arg(m_settings->outputDir(), lamexp_rand_str()));
1469 if(!(writeTest.open(QIODevice::ReadWrite) && (writeTest.write(writeTestBuffer) == strlen(writeTestBuffer))))
1471 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!")));
1472 tabWidget->setCurrentIndex(1);
1489 void MainWindow::aboutButtonClicked(void)
1495 AboutDialog *aboutBox = new AboutDialog(m_settings, this);
1497 LAMEXP_DELETE(aboutBox);
1504 void MainWindow::closeButtonClicked(void)
1510 // =========================================================
1512 // =========================================================
1517 void MainWindow::tabPageChanged(int idx)
1521 QList<QAction*> actions = m_tabActionGroup->actions();
1522 for(int i = 0; i < actions.count(); i++)
1525 int actionIndex = actions.at(i)->data().toInt(&ok);
1526 if(ok && actionIndex == idx)
1528 actions.at(i)->setChecked(true);
1532 int initialWidth = this->width();
1533 int maximumWidth = QApplication::desktop()->width();
1535 if(this->isVisible())
1537 while(tabWidget->width() < tabWidget->sizeHint().width())
1539 int previousWidth = this->width();
1540 this->resize(this->width() + 1, this->height());
1541 if(this->frameGeometry().width() >= maximumWidth) break;
1542 if(this->width() <= previousWidth) break;
1546 if(idx == tabWidget->indexOf(tabOptions) && scrollArea->widget() && this->isVisible())
1548 for(int i = 0; i < 2; i++)
1550 QApplication::processEvents();
1551 while(scrollArea->viewport()->width() < scrollArea->widget()->width())
1553 int previousWidth = this->width();
1554 this->resize(this->width() + 1, this->height());
1555 if(this->frameGeometry().width() >= maximumWidth) break;
1556 if(this->width() <= previousWidth) break;
1560 else if(idx == tabWidget->indexOf(tabSourceFiles))
1562 m_dropNoteLabel->setGeometry(0, 0, sourceFileView->width(), sourceFileView->height());
1564 else if(idx == tabWidget->indexOf(tabOutputDir))
1566 if(!m_fileSystemModel)
1568 QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
1572 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
1576 if(initialWidth < this->width())
1578 QPoint prevPos = this->pos();
1579 int delta = (this->width() - initialWidth) >> 2;
1580 move(prevPos.x() - delta, prevPos.y());
1585 * Tab action triggered
1587 void MainWindow::tabActionActivated(QAction *action)
1589 if(action && action->data().isValid())
1592 int index = action->data().toInt(&ok);
1595 tabWidget->setCurrentIndex(index);
1600 // =========================================================
1602 // =========================================================
1605 * Style action triggered
1607 void MainWindow::styleActionActivated(QAction *action)
1609 //Change style setting
1610 if(action && action->data().isValid())
1613 int actionIndex = action->data().toInt(&ok);
1616 m_settings->interfaceStyle(actionIndex);
1620 //Set up the new style
1621 switch(m_settings->interfaceStyle())
1624 if(actionStyleCleanlooks->isEnabled())
1626 actionStyleCleanlooks->setChecked(true);
1627 QApplication::setStyle(new QCleanlooksStyle());
1631 if(actionStyleWindowsVista->isEnabled())
1633 actionStyleWindowsVista->setChecked(true);
1634 QApplication::setStyle(new QWindowsVistaStyle());
1638 if(actionStyleWindowsXP->isEnabled())
1640 actionStyleWindowsXP->setChecked(true);
1641 QApplication::setStyle(new QWindowsXPStyle());
1645 if(actionStyleWindowsClassic->isEnabled())
1647 actionStyleWindowsClassic->setChecked(true);
1648 QApplication::setStyle(new QWindowsStyle());
1652 actionStylePlastique->setChecked(true);
1653 QApplication::setStyle(new QPlastiqueStyle());
1657 //Force re-translate after style change
1658 if(QEvent *e = new QEvent(QEvent::LanguageChange))
1666 * Language action triggered
1668 void MainWindow::languageActionActivated(QAction *action)
1670 if(action->data().type() == QVariant::String)
1672 QString langId = action->data().toString();
1674 if(lamexp_install_translator(langId))
1676 action->setChecked(true);
1677 m_settings->currentLanguage(langId);
1683 * Load language from file action triggered
1685 void MainWindow::languageFromFileActionActivated(bool checked)
1687 QFileDialog dialog(this, tr("Load Translation"));
1688 dialog.setFileMode(QFileDialog::ExistingFile);
1689 dialog.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
1693 QStringList selectedFiles = dialog.selectedFiles();
1694 if(lamexp_install_translator_from_file(selectedFiles.first()))
1696 QList<QAction*> actions = m_languageActionGroup->actions();
1697 while(!actions.isEmpty())
1699 actions.takeFirst()->setChecked(false);
1704 languageActionActivated(m_languageActionGroup->actions().first());
1709 // =========================================================
1711 // =========================================================
1714 * Disable update reminder action
1716 void MainWindow::disableUpdateReminderActionTriggered(bool checked)
1720 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))
1722 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!"))));
1723 m_settings->autoUpdateEnabled(false);
1727 m_settings->autoUpdateEnabled(true);
1732 QMessageBox::information(this, tr("Update Reminder"), NOBR(tr("The update reminder has been re-enabled.")));
1733 m_settings->autoUpdateEnabled(true);
1736 actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
1740 * Disable sound effects action
1742 void MainWindow::disableSoundsActionTriggered(bool checked)
1746 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))
1748 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("All sound effects have been disabled.")));
1749 m_settings->soundsEnabled(false);
1753 m_settings->soundsEnabled(true);
1758 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("The sound effects have been re-enabled.")));
1759 m_settings->soundsEnabled(true);
1762 actionDisableSounds->setChecked(!m_settings->soundsEnabled());
1766 * Disable Nero AAC encoder action
1768 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked)
1772 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))
1774 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("All Nero AAC Encoder notifications have been disabled.")));
1775 m_settings->neroAacNotificationsEnabled(false);
1779 m_settings->neroAacNotificationsEnabled(true);
1784 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("The Nero AAC Encoder notifications have been re-enabled.")));
1785 m_settings->neroAacNotificationsEnabled(true);
1788 actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
1792 * Disable slow startup action
1794 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked)
1798 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))
1800 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been disabled.")));
1801 m_settings->antivirNotificationsEnabled(false);
1805 m_settings->antivirNotificationsEnabled(true);
1810 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been re-enabled.")));
1811 m_settings->antivirNotificationsEnabled(true);
1814 actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
1818 * Import a Cue Sheet file
1820 void MainWindow::importCueSheetActionTriggered(bool checked)
1829 QString selectedCueFile;
1831 if(USE_NATIVE_FILE_DIALOG)
1833 selectedCueFile = QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1837 QFileDialog dialog(this, tr("Open Cue Sheet"));
1838 dialog.setFileMode(QFileDialog::ExistingFile);
1839 dialog.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1840 dialog.setDirectory(m_settings->mostRecentInputPath());
1843 selectedCueFile = dialog.selectedFiles().first();
1847 if(!selectedCueFile.isEmpty())
1849 m_settings->mostRecentInputPath(QFileInfo(selectedCueFile).canonicalPath());
1850 CueImportDialog *cueImporter = new CueImportDialog(this, m_fileListModel, selectedCueFile);
1851 result = cueImporter->exec();
1852 LAMEXP_DELETE(cueImporter);
1855 if(result != (-1)) break;
1861 * Show the "drop box" widget
1863 void MainWindow::showDropBoxWidgetActionTriggered(bool checked)
1865 m_settings->dropBoxWidgetEnabled(true);
1867 if(!m_dropBox->isVisible())
1872 lamexp_blink_window(m_dropBox);
1876 * Check for beta (pre-release) updates
1878 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked)
1880 bool checkUpdatesNow = false;
1884 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))
1886 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")))
1888 checkUpdatesNow = true;
1890 m_settings->autoUpdateCheckBeta(true);
1894 m_settings->autoUpdateCheckBeta(false);
1899 QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on.")));
1900 m_settings->autoUpdateCheckBeta(false);
1903 actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta());
1907 if(checkForUpdates())
1909 QApplication::quit();
1915 * Hibernate computer action
1917 void MainWindow::hibernateComputerActionTriggered(bool checked)
1921 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))
1923 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will hibernate the computer on shutdown from now on.")));
1924 m_settings->hibernateComputer(true);
1928 m_settings->hibernateComputer(false);
1933 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will <i>not</i> hibernate the computer on shutdown from now on.")));
1934 m_settings->hibernateComputer(false);
1937 actionHibernateComputer->setChecked(m_settings->hibernateComputer());
1941 * Disable shell integration action
1943 void MainWindow::disableShellIntegrationActionTriggered(bool checked)
1947 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))
1949 ShellIntegration::remove();
1950 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been disabled.")));
1951 m_settings->shellIntegrationEnabled(false);
1955 m_settings->shellIntegrationEnabled(true);
1960 ShellIntegration::install();
1961 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been re-enabled.")));
1962 m_settings->shellIntegrationEnabled(true);
1965 actionDisableShellIntegration->setChecked(!m_settings->shellIntegrationEnabled());
1967 if(lamexp_portable_mode() && actionDisableShellIntegration->isChecked())
1969 actionDisableShellIntegration->setEnabled(false);
1973 // =========================================================
1975 // =========================================================
1978 * Visit homepage action
1980 void MainWindow::visitHomepageActionActivated(void)
1982 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
1984 if(action->data().isValid() && (action->data().type() == QVariant::String))
1986 QDesktopServices::openUrl(QUrl(action->data().toString()));
1994 void MainWindow::documentActionActivated(void)
1996 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
1998 if(action->data().isValid() && (action->data().type() == QVariant::String))
2000 QFileInfo document(action->data().toString());
2001 QFileInfo resource(QString(":/doc/%1.html").arg(document.baseName()));
2002 if(document.exists() && document.isFile() && (document.size() == resource.size()))
2004 QDesktopServices::openUrl(QUrl::fromLocalFile(document.canonicalFilePath()));
2008 QFile source(resource.filePath());
2009 QFile output(QString("%1/%2.%3.html").arg(lamexp_temp_folder2(), document.baseName(), lamexp_rand_str().left(8)));
2010 if(source.open(QIODevice::ReadOnly) && output.open(QIODevice::ReadWrite))
2012 output.write(source.readAll());
2013 action->setData(output.fileName());
2016 QDesktopServices::openUrl(QUrl::fromLocalFile(output.fileName()));
2024 * Check for updates action
2026 void MainWindow::checkUpdatesActionActivated(void)
2033 bFlag = checkForUpdates();
2038 QApplication::quit();
2042 // =========================================================
2043 // Source file slots
2044 // =========================================================
2047 * Add file(s) button
2049 void MainWindow::addFilesButtonClicked(void)
2055 if(USE_NATIVE_FILE_DIALOG)
2057 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
2058 QStringList selectedFiles = QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings->mostRecentInputPath(), fileTypeFilters.join(";;"));
2059 if(!selectedFiles.isEmpty())
2061 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
2062 addFiles(selectedFiles);
2067 QFileDialog dialog(this, tr("Add file(s)"));
2068 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
2069 dialog.setFileMode(QFileDialog::ExistingFiles);
2070 dialog.setNameFilter(fileTypeFilters.join(";;"));
2071 dialog.setDirectory(m_settings->mostRecentInputPath());
2074 QStringList selectedFiles = dialog.selectedFiles();
2075 if(!selectedFiles.isEmpty())
2077 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
2078 addFiles(selectedFiles);
2086 * Open folder action
2088 void MainWindow::openFolderActionActivated(void)
2091 QString selectedFolder;
2093 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
2097 if(USE_NATIVE_FILE_DIALOG)
2099 selectedFolder = QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings->mostRecentInputPath());
2103 QFileDialog dialog(this, tr("Add Folder"));
2104 dialog.setFileMode(QFileDialog::DirectoryOnly);
2105 dialog.setDirectory(m_settings->mostRecentInputPath());
2108 selectedFolder = dialog.selectedFiles().first();
2112 if(!selectedFolder.isEmpty())
2114 m_settings->mostRecentInputPath(QDir(selectedFolder).canonicalPath());
2115 addFolder(selectedFolder, action->data().toBool());
2122 * Remove file button
2124 void MainWindow::removeFileButtonClicked(void)
2126 if(sourceFileView->currentIndex().isValid())
2128 int iRow = sourceFileView->currentIndex().row();
2129 m_fileListModel->removeFile(sourceFileView->currentIndex());
2130 sourceFileView->selectRow(iRow < m_fileListModel->rowCount() ? iRow : m_fileListModel->rowCount()-1);
2135 * Clear files button
2137 void MainWindow::clearFilesButtonClicked(void)
2139 m_fileListModel->clearFiles();
2143 * Move file up button
2145 void MainWindow::fileUpButtonClicked(void)
2147 if(sourceFileView->currentIndex().isValid())
2149 int iRow = sourceFileView->currentIndex().row() - 1;
2150 m_fileListModel->moveFile(sourceFileView->currentIndex(), -1);
2151 sourceFileView->selectRow(iRow >= 0 ? iRow : 0);
2156 * Move file down button
2158 void MainWindow::fileDownButtonClicked(void)
2160 if(sourceFileView->currentIndex().isValid())
2162 int iRow = sourceFileView->currentIndex().row() + 1;
2163 m_fileListModel->moveFile(sourceFileView->currentIndex(), 1);
2164 sourceFileView->selectRow(iRow < m_fileListModel->rowCount() ? iRow : m_fileListModel->rowCount()-1);
2169 * Show details button
2171 void MainWindow::showDetailsButtonClicked(void)
2176 MetaInfoDialog *metaInfoDialog = new MetaInfoDialog(this);
2177 QModelIndex index = sourceFileView->currentIndex();
2179 while(index.isValid())
2183 index = m_fileListModel->index(index.row() + 1, index.column());
2184 sourceFileView->selectRow(index.row());
2188 index = m_fileListModel->index(index.row() - 1, index.column());
2189 sourceFileView->selectRow(index.row());
2192 AudioFileModel &file = (*m_fileListModel)[index];
2195 iResult = metaInfoDialog->exec(file, index.row() > 0, index.row() < m_fileListModel->rowCount() - 1);
2198 if(iResult == INT_MAX)
2200 m_metaInfoModel->assignInfoFrom(file);
2201 tabWidget->setCurrentIndex(tabWidget->indexOf(tabMetaData));
2208 LAMEXP_DELETE(metaInfoDialog);
2209 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2210 sourceFilesScrollbarMoved(0);
2214 * Show context menu for source files
2216 void MainWindow::sourceFilesContextMenu(const QPoint &pos)
2218 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
2219 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
2223 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
2225 m_sourceFilesContextMenu->popup(sender->mapToGlobal(pos));
2231 * Scrollbar of source files moved
2233 void MainWindow::sourceFilesScrollbarMoved(int)
2235 sourceFileView->resizeColumnToContents(0);
2239 * Open selected file in external player
2241 void MainWindow::previewContextActionTriggered(void)
2243 const static char *appNames[3] = {"smplayer_portable.exe", "smplayer.exe", "mplayer.exe"};
2244 const static wchar_t *registryKey = L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{DB9E4EAB-2717-499F-8D56-4CC8A644AB60}";
2246 QModelIndex index = sourceFileView->currentIndex();
2247 if(!index.isValid())
2252 QString mplayerPath;
2253 HKEY registryKeyHandle;
2255 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryKey, 0, KEY_READ, ®istryKeyHandle) == ERROR_SUCCESS)
2257 wchar_t Buffer[4096];
2258 DWORD BuffSize = sizeof(wchar_t*) * 4096;
2259 if(RegQueryValueExW(registryKeyHandle, L"InstallLocation", 0, 0, reinterpret_cast<BYTE*>(Buffer), &BuffSize) == ERROR_SUCCESS)
2261 mplayerPath = QString::fromUtf16(reinterpret_cast<const unsigned short*>(Buffer));
2265 if(!mplayerPath.isEmpty())
2267 QDir mplayerDir(mplayerPath);
2268 if(mplayerDir.exists())
2270 for(int i = 0; i < 3; i++)
2272 if(mplayerDir.exists(appNames[i]))
2274 QProcess::startDetached(mplayerDir.absoluteFilePath(appNames[i]), QStringList() << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
2281 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel->getFile(index).filePath()));
2285 * Find selected file in explorer
2287 void MainWindow::findFileContextActionTriggered(void)
2289 QModelIndex index = sourceFileView->currentIndex();
2292 QString systemRootPath;
2294 QDir systemRoot(lamexp_known_folder(lamexp_folder_systemfolder));
2295 if(systemRoot.exists() && systemRoot.cdUp())
2297 systemRootPath = systemRoot.canonicalPath();
2300 if(!systemRootPath.isEmpty())
2302 QFileInfo explorer(QString("%1/explorer.exe").arg(systemRootPath));
2303 if(explorer.exists() && explorer.isFile())
2305 QProcess::execute(explorer.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
2311 qWarning("SystemRoot directory could not be detected!");
2317 * Add all pending files
2319 void MainWindow::handleDelayedFiles(void)
2321 m_delayedFileTimer->stop();
2323 if(m_delayedFileList->isEmpty())
2328 if(m_banner->isVisible())
2330 m_delayedFileTimer->start(5000);
2334 QStringList selectedFiles;
2335 tabWidget->setCurrentIndex(0);
2337 while(!m_delayedFileList->isEmpty())
2339 QFileInfo currentFile = QFileInfo(m_delayedFileList->takeFirst());
2340 if(!currentFile.exists() || !currentFile.isFile())
2344 selectedFiles << currentFile.canonicalFilePath();
2347 addFiles(selectedFiles);
2351 * Export Meta tags to CSV file
2353 void MainWindow::exportCsvContextActionTriggered(void)
2357 QString selectedCsvFile;
2359 if(USE_NATIVE_FILE_DIALOG)
2361 selectedCsvFile = QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2365 QFileDialog dialog(this, tr("Save CSV file"));
2366 dialog.setFileMode(QFileDialog::AnyFile);
2367 dialog.setAcceptMode(QFileDialog::AcceptSave);
2368 dialog.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2369 dialog.setDirectory(m_settings->mostRecentInputPath());
2372 selectedCsvFile = dialog.selectedFiles().first();
2376 if(!selectedCsvFile.isEmpty())
2378 m_settings->mostRecentInputPath(QFileInfo(selectedCsvFile).canonicalPath());
2379 switch(m_fileListModel->exportToCsv(selectedCsvFile))
2381 case FileListModel::CsvError_NoTags:
2382 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, there are no meta tags that can be exported!")));
2384 case FileListModel::CsvError_FileOpen:
2385 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to open CSV file for writing!")));
2387 case FileListModel::CsvError_FileWrite:
2388 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to write to the CSV file!")));
2390 case FileListModel::CsvError_OK:
2391 QMessageBox::information(this, tr("CSV Export"), NOBR(tr("The CSV files was created successfully!")));
2394 qWarning("exportToCsv: Unknown return code!");
2402 * Import Meta tags from CSV file
2404 void MainWindow::importCsvContextActionTriggered(void)
2408 QString selectedCsvFile;
2410 if(USE_NATIVE_FILE_DIALOG)
2412 selectedCsvFile = QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2416 QFileDialog dialog(this, tr("Open CSV file"));
2417 dialog.setFileMode(QFileDialog::ExistingFile);
2418 dialog.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2419 dialog.setDirectory(m_settings->mostRecentInputPath());
2422 selectedCsvFile = dialog.selectedFiles().first();
2426 if(!selectedCsvFile.isEmpty())
2428 m_settings->mostRecentInputPath(QFileInfo(selectedCsvFile).canonicalPath());
2429 switch(m_fileListModel->importFromCsv(this, selectedCsvFile))
2431 case FileListModel::CsvError_FileOpen:
2432 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to open CSV file for reading!")));
2434 case FileListModel::CsvError_FileRead:
2435 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to read from the CSV file!")));
2437 case FileListModel::CsvError_NoTags:
2438 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, the CSV file does not contain any known fields!")));
2440 case FileListModel::CsvError_Incomplete:
2441 QMessageBox::warning(this, tr("CSV Import"), NOBR(tr("CSV file is incomplete. Not all files were updated!")));
2443 case FileListModel::CsvError_OK:
2444 QMessageBox::information(this, tr("CSV Import"), NOBR(tr("The CSV files was imported successfully!")));
2446 case FileListModel::CsvError_Aborted:
2447 /* User aborted, ignore! */
2450 qWarning("exportToCsv: Unknown return code!");
2457 * Show or hide Drag'n'Drop notice after model reset
2459 void MainWindow::sourceModelChanged(void)
2461 m_dropNoteLabel->setVisible(m_fileListModel->rowCount() <= 0);
2464 // =========================================================
2465 // Output folder slots
2466 // =========================================================
2469 * Output folder changed (mouse clicked)
2471 void MainWindow::outputFolderViewClicked(const QModelIndex &index)
2473 if(index.isValid() && (outputFolderView->currentIndex() != index))
2475 outputFolderView->setCurrentIndex(index);
2478 if(m_fileSystemModel && index.isValid())
2480 QString selectedDir = m_fileSystemModel->filePath(index);
2481 if(selectedDir.length() < 3) selectedDir.append(QDir::separator());
2482 outputFolderLabel->setText(QDir::toNativeSeparators(selectedDir));
2483 m_settings->outputDir(selectedDir);
2487 outputFolderLabel->setText(QDir::toNativeSeparators(m_settings->outputDir()));
2492 * Output folder changed (mouse moved)
2494 void MainWindow::outputFolderViewMoved(const QModelIndex &index)
2496 if(QApplication::mouseButtons() & Qt::LeftButton)
2498 outputFolderViewClicked(index);
2503 * Goto desktop button
2505 void MainWindow::gotoDesktopButtonClicked(void)
2507 if(!m_fileSystemModel)
2509 qWarning("File system model not initialized yet!");
2513 QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
2515 if(!desktopPath.isEmpty() && QDir(desktopPath).exists())
2517 outputFolderView->setCurrentIndex(m_fileSystemModel->index(desktopPath));
2518 outputFolderViewClicked(outputFolderView->currentIndex());
2519 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2523 buttonGotoDesktop->setEnabled(false);
2528 * Goto home folder button
2530 void MainWindow::gotoHomeFolderButtonClicked(void)
2532 if(!m_fileSystemModel)
2534 qWarning("File system model not initialized yet!");
2538 QString homePath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
2540 if(!homePath.isEmpty() && QDir(homePath).exists())
2542 outputFolderView->setCurrentIndex(m_fileSystemModel->index(homePath));
2543 outputFolderViewClicked(outputFolderView->currentIndex());
2544 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2548 buttonGotoHome->setEnabled(false);
2553 * Goto music folder button
2555 void MainWindow::gotoMusicFolderButtonClicked(void)
2557 if(!m_fileSystemModel)
2559 qWarning("File system model not initialized yet!");
2563 QString musicPath = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
2565 if(!musicPath.isEmpty() && QDir(musicPath).exists())
2567 outputFolderView->setCurrentIndex(m_fileSystemModel->index(musicPath));
2568 outputFolderViewClicked(outputFolderView->currentIndex());
2569 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2573 buttonGotoMusic->setEnabled(false);
2578 * Goto music favorite output folder
2580 void MainWindow::gotoFavoriteFolder(void)
2582 if(!m_fileSystemModel)
2584 qWarning("File system model not initialized yet!");
2588 QAction *item = dynamic_cast<QAction*>(QObject::sender());
2592 QDir path(item->data().toString());
2595 outputFolderView->setCurrentIndex(m_fileSystemModel->index(path.canonicalPath()));
2596 outputFolderViewClicked(outputFolderView->currentIndex());
2597 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2601 MessageBeep(MB_ICONERROR);
2602 m_outputFolderFavoritesMenu->removeAction(item);
2603 item->deleteLater();
2609 * Make folder button
2611 void MainWindow::makeFolderButtonClicked(void)
2615 if(!m_fileSystemModel)
2617 qWarning("File system model not initialized yet!");
2621 QDir basePath(m_fileSystemModel->fileInfo(outputFolderView->currentIndex()).absoluteFilePath());
2622 QString suggestedName = tr("New Folder");
2624 if(!m_metaData->fileArtist().isEmpty() && !m_metaData->fileAlbum().isEmpty())
2626 suggestedName = QString("%1 - %2").arg(m_metaData->fileArtist(), m_metaData->fileAlbum());
2628 else if(!m_metaData->fileArtist().isEmpty())
2630 suggestedName = m_metaData->fileArtist();
2632 else if(!m_metaData->fileAlbum().isEmpty())
2634 suggestedName = m_metaData->fileAlbum();
2638 for(int i = 0; i < m_fileListModel->rowCount(); i++)
2640 AudioFileModel audioFile = m_fileListModel->getFile(m_fileListModel->index(i, 0));
2641 if(!audioFile.fileAlbum().isEmpty() || !audioFile.fileArtist().isEmpty())
2643 if(!audioFile.fileArtist().isEmpty() && !audioFile.fileAlbum().isEmpty())
2645 suggestedName = QString("%1 - %2").arg(audioFile.fileArtist(), audioFile.fileAlbum());
2647 else if(!audioFile.fileArtist().isEmpty())
2649 suggestedName = audioFile.fileArtist();
2651 else if(!audioFile.fileAlbum().isEmpty())
2653 suggestedName = audioFile.fileAlbum();
2660 suggestedName = lamexp_clean_filename(suggestedName);
2664 bool bApplied = false;
2665 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();
2669 folderName = lamexp_clean_filepath(folderName.simplified());
2671 if(folderName.isEmpty())
2673 MessageBeep(MB_ICONERROR);
2678 QString newFolder = folderName;
2680 while(basePath.exists(newFolder))
2682 newFolder = QString(folderName).append(QString().sprintf(" (%d)", ++i));
2685 if(basePath.mkpath(newFolder))
2687 QDir createdDir = basePath;
2688 if(createdDir.cd(newFolder))
2690 QModelIndex newIndex = m_fileSystemModel->index(createdDir.canonicalPath());
2691 outputFolderView->setCurrentIndex(newIndex);
2692 outputFolderViewClicked(newIndex);
2693 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2698 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!")));
2706 * Output to source dir changed
2708 void MainWindow::saveToSourceFolderChanged(void)
2710 m_settings->outputToSourceDir(saveToSourceFolderCheckBox->isChecked());
2714 * Prepend relative source file path to output file name changed
2716 void MainWindow::prependRelativePathChanged(void)
2718 m_settings->prependRelativeSourcePath(prependRelativePathCheckBox->isChecked());
2722 * Show context menu for output folder
2724 void MainWindow::outputFolderContextMenu(const QPoint &pos)
2726 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
2727 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
2729 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
2731 m_outputFolderContextMenu->popup(sender->mapToGlobal(pos));
2736 * Show selected folder in explorer
2738 void MainWindow::showFolderContextActionTriggered(void)
2740 if(!m_fileSystemModel)
2742 qWarning("File system model not initialized yet!");
2746 QString path = QDir::toNativeSeparators(m_fileSystemModel->filePath(outputFolderView->currentIndex()));
2747 if(!path.endsWith(QDir::separator())) path.append(QDir::separator());
2748 ShellExecuteW(reinterpret_cast<HWND>(this->winId()), L"explore", QWCHAR(path), NULL, NULL, SW_SHOW);
2752 * Refresh the directory outline
2754 void MainWindow::refreshFolderContextActionTriggered(void)
2756 //force re-initialization
2757 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
2761 * Add current folder to favorites
2763 void MainWindow::addFavoriteFolderActionTriggered(void)
2765 QString path = m_fileSystemModel->filePath(outputFolderView->currentIndex());
2766 QStringList favorites = m_settings->favoriteOutputFolders().split("|", QString::SkipEmptyParts);
2768 if(!favorites.contains(path, Qt::CaseInsensitive))
2770 favorites.append(path);
2771 while(favorites.count() > 6) favorites.removeFirst();
2775 MessageBeep(MB_ICONWARNING);
2778 m_settings->favoriteOutputFolders(favorites.join("|"));
2783 * Output folder edit finished
2785 void MainWindow::outputFolderEditFinished(void)
2787 if(outputFolderEdit->isHidden())
2789 return; //Not currently in edit mode!
2794 QString text = QDir::fromNativeSeparators(outputFolderEdit->text().trimmed());
2795 while(text.startsWith('"') || text.startsWith('/')) text = text.right(text.length() - 1).trimmed();
2796 while(text.endsWith('"') || text.endsWith('/')) text = text.left(text.length() - 1).trimmed();
2798 static const char *str = "?*<>|\"";
2799 for(size_t i = 0; str[i]; i++) text.replace(str[i], "_");
2801 if(!((text.length() >= 2) && text.at(0).isLetter() && text.at(1) == QChar(':')))
2803 text = QString("%1/%2").arg(QDir::fromNativeSeparators(outputFolderLabel->text()), text);
2806 if(text.length() == 2) text += "/"; /* "X:" => "X:/" */
2808 while(text.length() > 2)
2810 QFileInfo info(text);
2811 if(info.exists() && info.isDir())
2813 QModelIndex index = m_fileSystemModel->index(QFileInfo(info.canonicalFilePath()).absoluteFilePath());
2817 outputFolderView->setCurrentIndex(index);
2818 outputFolderViewClicked(index);
2822 else if(info.exists() && info.isFile())
2824 QModelIndex index = m_fileSystemModel->index(QFileInfo(info.canonicalPath()).absoluteFilePath());
2828 outputFolderView->setCurrentIndex(index);
2829 outputFolderViewClicked(index);
2834 text = text.left(text.length() - 1).trimmed();
2837 outputFolderEdit->setVisible(false);
2838 outputFolderLabel->setVisible(true);
2839 outputFolderView->setEnabled(true);
2841 if(!ok) MessageBeep(MB_ICONERROR);
2842 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2846 * Initialize file system model
2848 void MainWindow::initOutputFolderModel(void)
2850 if(m_outputFolderNoteBox->isHidden())
2852 m_outputFolderNoteBox->show();
2853 m_outputFolderNoteBox->repaint();
2854 m_outputFolderViewInitCounter = 4;
2856 if(m_fileSystemModel)
2858 SET_MODEL(outputFolderView, NULL);
2859 LAMEXP_DELETE(m_fileSystemModel);
2860 outputFolderView->repaint();
2863 if(m_fileSystemModel = new QFileSystemModelEx())
2865 m_fileSystemModel->installEventFilter(this);
2866 connect(m_fileSystemModel, SIGNAL(directoryLoaded(QString)), this, SLOT(outputFolderDirectoryLoaded(QString)));
2867 connect(m_fileSystemModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(outputFolderRowsInserted(QModelIndex,int,int)));
2869 SET_MODEL(outputFolderView, m_fileSystemModel);
2870 outputFolderView->header()->setStretchLastSection(true);
2871 outputFolderView->header()->hideSection(1);
2872 outputFolderView->header()->hideSection(2);
2873 outputFolderView->header()->hideSection(3);
2875 m_fileSystemModel->setRootPath("");
2876 QModelIndex index = m_fileSystemModel->index(m_settings->outputDir());
2877 if(index.isValid()) outputFolderView->setCurrentIndex(index);
2878 outputFolderViewClicked(outputFolderView->currentIndex());
2881 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2882 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
2887 * Initialize file system model (do NOT call this one directly!)
2889 void MainWindow::initOutputFolderModel_doAsync(void)
2891 if(m_outputFolderViewInitCounter > 0)
2893 m_outputFolderViewInitCounter--;
2894 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
2898 QTimer::singleShot(125, m_outputFolderNoteBox, SLOT(hide()));
2899 outputFolderView->setFocus();
2904 * Center current folder in view
2906 void MainWindow::centerOutputFolderModel(void)
2908 if(outputFolderView->isVisible())
2910 centerOutputFolderModel_doAsync();
2911 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel_doAsync()));
2916 * Center current folder in view (do NOT call this one directly!)
2918 void MainWindow::centerOutputFolderModel_doAsync(void)
2920 if(outputFolderView->isVisible())
2922 m_outputFolderViewCentering = true;
2923 const QModelIndex index = outputFolderView->currentIndex();
2924 outputFolderView->scrollTo(index, QAbstractItemView::PositionAtCenter);
2925 outputFolderView->setFocus();
2930 * File system model asynchronously loaded a dir
2932 void MainWindow::outputFolderDirectoryLoaded(const QString &path)
2934 if(m_outputFolderViewCentering)
2936 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2941 * File system model inserted new items
2943 void MainWindow::outputFolderRowsInserted(const QModelIndex &parent, int start, int end)
2945 if(m_outputFolderViewCentering)
2947 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2952 * Directory view item was expanded by user
2954 void MainWindow::outputFolderItemExpanded(const QModelIndex &item)
2956 //We need to stop centering as soon as the user has expanded an item manually!
2957 m_outputFolderViewCentering = false;
2960 // =========================================================
2961 // Metadata tab slots
2962 // =========================================================
2965 * Edit meta button clicked
2967 void MainWindow::editMetaButtonClicked(void)
2971 const QModelIndex index = metaDataView->currentIndex();
2975 m_metaInfoModel->editItem(index, this);
2977 if(index.row() == 4)
2979 m_settings->metaInfoPosition(m_metaData->filePosition());
2985 * Reset meta button clicked
2987 void MainWindow::clearMetaButtonClicked(void)
2990 m_metaInfoModel->clearData();
2994 * Meta tags enabled changed
2996 void MainWindow::metaTagsEnabledChanged(void)
2998 m_settings->writeMetaTags(writeMetaDataCheckBox->isChecked());
3002 * Playlist enabled changed
3004 void MainWindow::playlistEnabledChanged(void)
3006 m_settings->createPlaylist(generatePlaylistCheckBox->isChecked());
3009 // =========================================================
3010 // Compression tab slots
3011 // =========================================================
3016 void MainWindow::updateEncoder(int id)
3018 m_settings->compressionEncoder(id);
3020 switch(m_settings->compressionEncoder())
3022 case SettingsModel::VorbisEncoder:
3023 radioButtonModeQuality->setEnabled(true);
3024 radioButtonModeAverageBitrate->setEnabled(true);
3025 radioButtonConstBitrate->setEnabled(false);
3026 if(radioButtonConstBitrate->isChecked()) radioButtonModeQuality->setChecked(true);
3027 sliderBitrate->setEnabled(true);
3029 case SettingsModel::AC3Encoder:
3030 radioButtonModeQuality->setEnabled(true);
3031 radioButtonModeQuality->setChecked(true);
3032 radioButtonModeAverageBitrate->setEnabled(false);
3033 radioButtonConstBitrate->setEnabled(true);
3034 sliderBitrate->setEnabled(true);
3036 case SettingsModel::FLACEncoder:
3037 radioButtonModeQuality->setEnabled(false);
3038 radioButtonModeQuality->setChecked(true);
3039 radioButtonModeAverageBitrate->setEnabled(false);
3040 radioButtonConstBitrate->setEnabled(false);
3041 sliderBitrate->setEnabled(true);
3043 case SettingsModel::PCMEncoder:
3044 radioButtonModeQuality->setEnabled(false);
3045 radioButtonModeQuality->setChecked(true);
3046 radioButtonModeAverageBitrate->setEnabled(false);
3047 radioButtonConstBitrate->setEnabled(false);
3048 sliderBitrate->setEnabled(false);
3050 case SettingsModel::AACEncoder:
3051 radioButtonModeQuality->setEnabled(true);
3052 radioButtonModeAverageBitrate->setEnabled(!m_fhgEncoderAvailable);
3053 if(m_fhgEncoderAvailable && radioButtonModeAverageBitrate->isChecked()) radioButtonConstBitrate->setChecked(true);
3054 radioButtonConstBitrate->setEnabled(true);
3055 sliderBitrate->setEnabled(true);
3057 case SettingsModel::DCAEncoder:
3058 radioButtonModeQuality->setEnabled(false);
3059 radioButtonModeAverageBitrate->setEnabled(false);
3060 radioButtonConstBitrate->setEnabled(true);
3061 radioButtonConstBitrate->setChecked(true);
3062 sliderBitrate->setEnabled(true);
3065 radioButtonModeQuality->setEnabled(true);
3066 radioButtonModeAverageBitrate->setEnabled(true);
3067 radioButtonConstBitrate->setEnabled(true);
3068 sliderBitrate->setEnabled(true);
3072 if(m_settings->compressionEncoder() == SettingsModel::AACEncoder)
3074 const QString encoderName = m_qaacEncoderAvailable ? tr("QAAC (Apple)") : (m_fhgEncoderAvailable ? tr("FHG AAC (Winamp)") : (m_neroEncoderAvailable ? tr("Nero AAC") : tr("Not available!")));
3075 labelEncoderInfo->setVisible(true);
3076 labelEncoderInfo->setText(tr("Current AAC Encoder: %1").arg(encoderName));
3080 labelEncoderInfo->setVisible(false);
3083 updateRCMode(m_modeButtonGroup->checkedId());
3087 * Update rate-control mode
3089 void MainWindow::updateRCMode(int id)
3091 m_settings->compressionRCMode(id);
3093 switch(m_settings->compressionEncoder())
3095 case SettingsModel::MP3Encoder:
3096 switch(m_settings->compressionRCMode())
3098 case SettingsModel::VBRMode:
3099 sliderBitrate->setMinimum(0);
3100 sliderBitrate->setMaximum(9);
3103 sliderBitrate->setMinimum(0);
3104 sliderBitrate->setMaximum(13);
3108 case SettingsModel::VorbisEncoder:
3109 switch(m_settings->compressionRCMode())
3111 case SettingsModel::VBRMode:
3112 sliderBitrate->setMinimum(-2);
3113 sliderBitrate->setMaximum(10);
3116 sliderBitrate->setMinimum(4);
3117 sliderBitrate->setMaximum(63);
3121 case SettingsModel::AC3Encoder:
3122 switch(m_settings->compressionRCMode())
3124 case SettingsModel::VBRMode:
3125 sliderBitrate->setMinimum(0);
3126 sliderBitrate->setMaximum(16);
3129 sliderBitrate->setMinimum(0);
3130 sliderBitrate->setMaximum(18);
3134 case SettingsModel::AACEncoder:
3135 switch(m_settings->compressionRCMode())
3137 case SettingsModel::VBRMode:
3138 sliderBitrate->setMinimum(0);
3139 sliderBitrate->setMaximum(20);
3142 sliderBitrate->setMinimum(4);
3143 sliderBitrate->setMaximum(63);
3147 case SettingsModel::FLACEncoder:
3148 sliderBitrate->setMinimum(0);
3149 sliderBitrate->setMaximum(8);
3151 case SettingsModel::DCAEncoder:
3152 sliderBitrate->setMinimum(1);
3153 sliderBitrate->setMaximum(128);
3155 case SettingsModel::PCMEncoder:
3156 sliderBitrate->setMinimum(0);
3157 sliderBitrate->setMaximum(2);
3158 sliderBitrate->setValue(1);
3161 sliderBitrate->setMinimum(0);
3162 sliderBitrate->setMaximum(0);
3166 updateBitrate(sliderBitrate->value());
3172 void MainWindow::updateBitrate(int value)
3174 m_settings->compressionBitrate(value);
3176 switch(m_settings->compressionRCMode())
3178 case SettingsModel::VBRMode:
3179 switch(m_settings->compressionEncoder())
3181 case SettingsModel::MP3Encoder:
3182 labelBitrate->setText(tr("Quality Level %1").arg(9 - value));
3184 case SettingsModel::VorbisEncoder:
3185 labelBitrate->setText(tr("Quality Level %1").arg(value));
3187 case SettingsModel::AACEncoder:
3188 labelBitrate->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", static_cast<double>(value * 5) / 100.0)));
3190 case SettingsModel::FLACEncoder:
3191 labelBitrate->setText(tr("Compression %1").arg(value));
3193 case SettingsModel::AC3Encoder:
3194 labelBitrate->setText(tr("Quality Level %1").arg(qMin(1024, qMax(0, value * 64))));
3196 case SettingsModel::PCMEncoder:
3197 labelBitrate->setText(tr("Uncompressed"));
3200 labelBitrate->setText(QString::number(value));
3204 case SettingsModel::ABRMode:
3205 switch(m_settings->compressionEncoder())
3207 case SettingsModel::MP3Encoder:
3208 labelBitrate->setText(QString("≈ %1 kbps").arg(SettingsModel::mp3Bitrates[value]));
3210 case SettingsModel::FLACEncoder:
3211 labelBitrate->setText(tr("Compression %1").arg(value));
3213 case SettingsModel::AC3Encoder:
3214 labelBitrate->setText(QString("≈ %1 kbps").arg(SettingsModel::ac3Bitrates[value]));
3216 case SettingsModel::PCMEncoder:
3217 labelBitrate->setText(tr("Uncompressed"));
3220 labelBitrate->setText(QString("≈ %1 kbps").arg(qMin(500, value * 8)));
3225 switch(m_settings->compressionEncoder())
3227 case SettingsModel::MP3Encoder:
3228 labelBitrate->setText(QString("%1 kbps").arg(SettingsModel::mp3Bitrates[value]));
3230 case SettingsModel::FLACEncoder:
3231 labelBitrate->setText(tr("Compression %1").arg(value));
3233 case SettingsModel::AC3Encoder:
3234 labelBitrate->setText(QString("%1 kbps").arg(SettingsModel::ac3Bitrates[value]));
3236 case SettingsModel::DCAEncoder:
3237 labelBitrate->setText(QString("%1 kbps").arg(value * 32));
3239 case SettingsModel::PCMEncoder:
3240 labelBitrate->setText(tr("Uncompressed"));
3243 labelBitrate->setText(QString("%1 kbps").arg(qMin(500, value * 8)));
3250 // =========================================================
3251 // Advanced option slots
3252 // =========================================================
3255 * Lame algorithm quality changed
3257 void MainWindow::updateLameAlgoQuality(int value)
3264 text = tr("Best Quality (Very Slow)");
3267 text = tr("High Quality (Recommended)");
3270 text = tr("Average Quality (Default)");
3273 text = tr("Low Quality (Fast)");
3276 text = tr("Poor Quality (Very Fast)");
3282 m_settings->lameAlgoQuality(value);
3283 labelLameAlgoQuality->setText(text);
3286 bool warning = (value == 0), notice = (value == 4);
3287 labelLameAlgoQualityWarning->setVisible(warning);
3288 labelLameAlgoQualityWarningIcon->setVisible(warning);
3289 labelLameAlgoQualityNotice->setVisible(notice);
3290 labelLameAlgoQualityNoticeIcon->setVisible(notice);
3291 labelLameAlgoQualitySpacer->setVisible(warning || notice);
3295 * Bitrate management endabled/disabled
3297 void MainWindow::bitrateManagementEnabledChanged(bool checked)
3299 m_settings->bitrateManagementEnabled(checked);
3303 * Minimum bitrate has changed
3305 void MainWindow::bitrateManagementMinChanged(int value)
3307 if(value > spinBoxBitrateManagementMax->value())
3309 spinBoxBitrateManagementMin->setValue(spinBoxBitrateManagementMax->value());
3310 m_settings->bitrateManagementMinRate(spinBoxBitrateManagementMax->value());
3314 m_settings->bitrateManagementMinRate(value);
3319 * Maximum bitrate has changed
3321 void MainWindow::bitrateManagementMaxChanged(int value)
3323 if(value < spinBoxBitrateManagementMin->value())
3325 spinBoxBitrateManagementMax->setValue(spinBoxBitrateManagementMin->value());
3326 m_settings->bitrateManagementMaxRate(spinBoxBitrateManagementMin->value());
3330 m_settings->bitrateManagementMaxRate(value);
3335 * Channel mode has changed
3337 void MainWindow::channelModeChanged(int value)
3339 if(value >= 0) m_settings->lameChannelMode(value);
3343 * Sampling rate has changed
3345 void MainWindow::samplingRateChanged(int value)
3347 if(value >= 0) m_settings->samplingRate(value);
3351 * Nero AAC 2-Pass mode changed
3353 void MainWindow::neroAAC2PassChanged(bool checked)
3355 m_settings->neroAACEnable2Pass(checked);
3359 * Nero AAC profile mode changed
3361 void MainWindow::neroAACProfileChanged(int value)
3363 if(value >= 0) m_settings->aacEncProfile(value);
3367 * Aften audio coding mode changed
3369 void MainWindow::aftenCodingModeChanged(int value)
3371 if(value >= 0) m_settings->aftenAudioCodingMode(value);
3375 * Aften DRC mode changed
3377 void MainWindow::aftenDRCModeChanged(int value)
3379 if(value >= 0) m_settings->aftenDynamicRangeCompression(value);
3383 * Aften exponent search size changed
3385 void MainWindow::aftenSearchSizeChanged(int value)
3387 if(value >= 0) m_settings->aftenExponentSearchSize(value);
3391 * Aften fast bit allocation changed
3393 void MainWindow::aftenFastAllocationChanged(bool checked)
3395 m_settings->aftenFastBitAllocation(checked);
3399 * Normalization filter enabled changed
3401 void MainWindow::normalizationEnabledChanged(bool checked)
3403 m_settings->normalizationFilterEnabled(checked);
3407 * Normalization max. volume changed
3409 void MainWindow::normalizationMaxVolumeChanged(double value)
3411 m_settings->normalizationFilterMaxVolume(static_cast<int>(value * 100.0));
3415 * Normalization equalization mode changed
3417 void MainWindow::normalizationModeChanged(int mode)
3419 m_settings->normalizationFilterEqualizationMode(mode);
3423 * Tone adjustment has changed (Bass)
3425 void MainWindow::toneAdjustBassChanged(double value)
3427 m_settings->toneAdjustBass(static_cast<int>(value * 100.0));
3428 spinBoxToneAdjustBass->setPrefix((value > 0) ? "+" : QString());
3432 * Tone adjustment has changed (Treble)
3434 void MainWindow::toneAdjustTrebleChanged(double value)
3436 m_settings->toneAdjustTreble(static_cast<int>(value * 100.0));
3437 spinBoxToneAdjustTreble->setPrefix((value > 0) ? "+" : QString());
3441 * Tone adjustment has been reset
3443 void MainWindow::toneAdjustTrebleReset(void)
3445 spinBoxToneAdjustBass->setValue(m_settings->toneAdjustBassDefault());
3446 spinBoxToneAdjustTreble->setValue(m_settings->toneAdjustTrebleDefault());
3447 toneAdjustBassChanged(spinBoxToneAdjustBass->value());
3448 toneAdjustTrebleChanged(spinBoxToneAdjustTreble->value());
3452 * Custom encoder parameters changed
3454 void MainWindow::customParamsChanged(void)
3456 lineEditCustomParamLAME->setText(lineEditCustomParamLAME->text().simplified());
3457 lineEditCustomParamOggEnc->setText(lineEditCustomParamOggEnc->text().simplified());
3458 lineEditCustomParamNeroAAC->setText(lineEditCustomParamNeroAAC->text().simplified());
3459 lineEditCustomParamFLAC->setText(lineEditCustomParamFLAC->text().simplified());
3460 lineEditCustomParamAften->setText(lineEditCustomParamAften->text().simplified());
3462 bool customParamsUsed = false;
3463 if(!lineEditCustomParamLAME->text().isEmpty()) customParamsUsed = true;
3464 if(!lineEditCustomParamOggEnc->text().isEmpty()) customParamsUsed = true;
3465 if(!lineEditCustomParamNeroAAC->text().isEmpty()) customParamsUsed = true;
3466 if(!lineEditCustomParamFLAC->text().isEmpty()) customParamsUsed = true;
3467 if(!lineEditCustomParamAften->text().isEmpty()) customParamsUsed = true;
3469 labelCustomParamsIcon->setVisible(customParamsUsed);
3470 labelCustomParamsText->setVisible(customParamsUsed);
3471 labelCustomParamsSpacer->setVisible(customParamsUsed);
3473 m_settings->customParametersLAME(lineEditCustomParamLAME->text());
3474 m_settings->customParametersOggEnc(lineEditCustomParamOggEnc->text());
3475 m_settings->customParametersAacEnc(lineEditCustomParamNeroAAC->text());
3476 m_settings->customParametersFLAC(lineEditCustomParamFLAC->text());
3477 m_settings->customParametersAften(lineEditCustomParamAften->text());
3482 * Rename output files enabled changed
3484 void MainWindow::renameOutputEnabledChanged(bool checked)
3486 m_settings->renameOutputFilesEnabled(checked);
3490 * Rename output files patterm changed
3492 void MainWindow::renameOutputPatternChanged(void)
3494 QString temp = lineEditRenamePattern->text().simplified();
3495 lineEditRenamePattern->setText(temp.isEmpty() ? m_settings->renameOutputFilesPatternDefault() : temp);
3496 m_settings->renameOutputFilesPattern(lineEditRenamePattern->text());
3500 * Rename output files patterm changed
3502 void MainWindow::renameOutputPatternChanged(const QString &text)
3504 QString pattern(text.simplified());
3506 pattern.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive);
3507 pattern.replace("<TrackNo>", "04", Qt::CaseInsensitive);
3508 pattern.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive);
3509 pattern.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive);
3510 pattern.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive);
3511 pattern.replace("<Year>", "2001", Qt::CaseInsensitive);
3512 pattern.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive);
3514 if(pattern.compare(lamexp_clean_filename(pattern)))
3516 if(lineEditRenamePattern->palette().color(QPalette::Text) != Qt::red)
3518 MessageBeep(MB_ICONERROR);
3519 SET_TEXT_COLOR(lineEditRenamePattern, Qt::red);
3524 if(lineEditRenamePattern->palette().color(QPalette::Text) != Qt::black)
3526 MessageBeep(MB_ICONINFORMATION);
3527 SET_TEXT_COLOR(lineEditRenamePattern, Qt::black);
3531 labelRanameExample->setText(lamexp_clean_filename(pattern));
3535 * Show list of rename macros
3537 void MainWindow::showRenameMacros(const QString &text)
3539 if(text.compare("reset", Qt::CaseInsensitive) == 0)
3541 lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
3545 const QString format = QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
3547 QString message = QString("<table>");
3548 message += QString(format).arg("BaseName", tr("File name without extension"));
3549 message += QString(format).arg("TrackNo", tr("Track number with leading zero"));
3550 message += QString(format).arg("Title", tr("Track title"));
3551 message += QString(format).arg("Artist", tr("Artist name"));
3552 message += QString(format).arg("Album", tr("Album name"));
3553 message += QString(format).arg("Year", tr("Year with (at least) four digits"));
3554 message += QString(format).arg("Comment", tr("Comment"));
3555 message += "</table><br><br>";
3556 message += QString("%1<br>").arg(tr("Characters forbidden in file names:"));
3557 message += "<b><tt>\\ / : * ? < > |<br>";
3559 QMessageBox::information(this, tr("Rename Macros"), message, tr("Discard"));
3562 void MainWindow::forceStereoDownmixEnabledChanged(bool checked)
3564 m_settings->forceStereoDownmix(checked);
3568 * Maximum number of instances changed
3570 void MainWindow::updateMaximumInstances(int value)
3572 labelMaxInstances->setText(tr("%1 Instance(s)").arg(QString::number(value)));
3573 m_settings->maximumInstances(checkBoxAutoDetectInstances->isChecked() ? NULL : value);
3577 * Auto-detect number of instances
3579 void MainWindow::autoDetectInstancesChanged(bool checked)
3581 m_settings->maximumInstances(checked ? NULL : sliderMaxInstances->value());
3585 * Browse for custom TEMP folder button clicked
3587 void MainWindow::browseCustomTempFolderButtonClicked(void)
3589 QString newTempFolder;
3591 if(USE_NATIVE_FILE_DIALOG)
3593 newTempFolder = QFileDialog::getExistingDirectory(this, QString(), m_settings->customTempPath());
3597 QFileDialog dialog(this);
3598 dialog.setFileMode(QFileDialog::DirectoryOnly);
3599 dialog.setDirectory(m_settings->customTempPath());
3602 newTempFolder = dialog.selectedFiles().first();
3606 if(!newTempFolder.isEmpty())
3608 QFile writeTest(QString("%1/~%2.tmp").arg(newTempFolder, lamexp_rand_str()));
3609 if(writeTest.open(QIODevice::ReadWrite))
3612 lineEditCustomTempFolder->setText(QDir::toNativeSeparators(newTempFolder));
3616 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
3622 * Custom TEMP folder changed
3624 void MainWindow::customTempFolderChanged(const QString &text)
3626 m_settings->customTempPath(QDir::fromNativeSeparators(text));
3630 * Use custom TEMP folder option changed
3632 void MainWindow::useCustomTempFolderChanged(bool checked)
3634 m_settings->customTempPathEnabled(!checked);
3638 * Reset all advanced options to their defaults
3640 void MainWindow::resetAdvancedOptionsButtonClicked(void)
3642 sliderLameAlgoQuality->setValue(m_settings->lameAlgoQualityDefault());
3643 spinBoxBitrateManagementMin->setValue(m_settings->bitrateManagementMinRateDefault());
3644 spinBoxBitrateManagementMax->setValue(m_settings->bitrateManagementMaxRateDefault());
3645 spinBoxNormalizationFilter->setValue(static_cast<double>(m_settings->normalizationFilterMaxVolumeDefault()) / 100.0);
3646 spinBoxToneAdjustBass->setValue(static_cast<double>(m_settings->toneAdjustBassDefault()) / 100.0);
3647 spinBoxToneAdjustTreble->setValue(static_cast<double>(m_settings->toneAdjustTrebleDefault()) / 100.0);
3648 spinBoxAftenSearchSize->setValue(m_settings->aftenExponentSearchSizeDefault());
3649 comboBoxMP3ChannelMode->setCurrentIndex(m_settings->lameChannelModeDefault());
3650 comboBoxSamplingRate->setCurrentIndex(m_settings->samplingRateDefault());
3651 comboBoxAACProfile->setCurrentIndex(m_settings->aacEncProfileDefault());
3652 comboBoxAftenCodingMode->setCurrentIndex(m_settings->aftenAudioCodingModeDefault());
3653 comboBoxAftenDRCMode->setCurrentIndex(m_settings->aftenDynamicRangeCompressionDefault());
3654 comboBoxNormalizationMode->setCurrentIndex(m_settings->normalizationFilterEqualizationModeDefault());
3655 while(checkBoxBitrateManagement->isChecked() != m_settings->bitrateManagementEnabledDefault()) checkBoxBitrateManagement->click();
3656 while(checkBoxNeroAAC2PassMode->isChecked() != m_settings->neroAACEnable2PassDefault()) checkBoxNeroAAC2PassMode->click();
3657 while(checkBoxNormalizationFilter->isChecked() != m_settings->normalizationFilterEnabledDefault()) checkBoxNormalizationFilter->click();
3658 while(checkBoxAutoDetectInstances->isChecked() != (m_settings->maximumInstancesDefault() < 1)) checkBoxAutoDetectInstances->click();
3659 while(checkBoxUseSystemTempFolder->isChecked() == m_settings->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder->click();
3660 while(checkBoxAftenFastAllocation->isChecked() != m_settings->aftenFastBitAllocationDefault()) checkBoxAftenFastAllocation->click();
3661 while(checkBoxRenameOutput->isChecked() != m_settings->renameOutputFilesEnabledDefault()) checkBoxRenameOutput->click();
3662 while(checkBoxForceStereoDownmix->isChecked() != m_settings->forceStereoDownmixDefault()) checkBoxForceStereoDownmix->click();
3663 lineEditCustomParamLAME->setText(m_settings->customParametersLAMEDefault());
3664 lineEditCustomParamOggEnc->setText(m_settings->customParametersOggEncDefault());
3665 lineEditCustomParamNeroAAC->setText(m_settings->customParametersAacEncDefault());
3666 lineEditCustomParamFLAC->setText(m_settings->customParametersFLACDefault());
3667 lineEditCustomTempFolder->setText(QDir::toNativeSeparators(m_settings->customTempPathDefault()));
3668 lineEditRenamePattern->setText(m_settings->renameOutputFilesPatternDefault());
3669 customParamsChanged();
3670 scrollArea->verticalScrollBar()->setValue(0);
3673 // =========================================================
3674 // Multi-instance handling slots
3675 // =========================================================
3678 * Other instance detected
3680 void MainWindow::notifyOtherInstance(void)
3682 if(!m_banner->isVisible())
3684 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);
3690 * Add file from another instance
3692 void MainWindow::addFileDelayed(const QString &filePath, bool tryASAP)
3694 if(tryASAP && !m_delayedFileTimer->isActive())
3696 qDebug("Received file: %s", filePath.toUtf8().constData());
3697 m_delayedFileList->append(filePath);
3698 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3701 m_delayedFileTimer->stop();
3702 qDebug("Received file: %s", filePath.toUtf8().constData());
3703 m_delayedFileList->append(filePath);
3704 m_delayedFileTimer->start(5000);
3708 * Add files from another instance
3710 void MainWindow::addFilesDelayed(const QStringList &filePaths, bool tryASAP)
3712 if(tryASAP && !m_delayedFileTimer->isActive())
3714 qDebug("Received %d file(s).", filePaths.count());
3715 m_delayedFileList->append(filePaths);
3716 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3720 m_delayedFileTimer->stop();
3721 qDebug("Received %d file(s).", filePaths.count());
3722 m_delayedFileList->append(filePaths);
3723 m_delayedFileTimer->start(5000);
3728 * Add folder from another instance
3730 void MainWindow::addFolderDelayed(const QString &folderPath, bool recursive)
3732 if(!m_banner->isVisible())
3734 addFolder(folderPath, recursive, true);
3738 // =========================================================
3740 // =========================================================
3743 * Restore the override cursor
3745 void MainWindow::restoreCursor(void)
3747 QApplication::restoreOverrideCursor();