1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_MainWindow.h"
25 #include "../tmp/UIC_MainWindow.h"
30 #include "Dialog_WorkingBanner.h"
31 #include "Dialog_MetaInfo.h"
32 #include "Dialog_About.h"
33 #include "Dialog_Update.h"
34 #include "Dialog_DropBox.h"
35 #include "Dialog_CueImport.h"
36 #include "Dialog_LogView.h"
37 #include "Thread_FileAnalyzer.h"
38 #include "Thread_FileAnalyzer_ST.h"
39 #include "Thread_MessageHandler.h"
40 #include "Model_MetaInfo.h"
41 #include "Model_Settings.h"
42 #include "Model_FileList.h"
43 #include "Model_FileSystem.h"
44 #include "WinSevenTaskbar.h"
45 #include "Registry_Decoder.h"
46 #include "ShellIntegration.h"
47 #include "CustomEventFilter.h"
50 #include <QMessageBox>
52 #include <QDesktopWidget>
54 #include <QFileDialog>
55 #include <QInputDialog>
56 #include <QFileSystemModel>
57 #include <QDesktopServices>
59 #include <QPlastiqueStyle>
60 #include <QCleanlooksStyle>
61 #include <QWindowsVistaStyle>
62 #include <QWindowsStyle>
64 #include <QDragEnterEvent>
68 #include <QProcessEnvironment>
69 #include <QCryptographicHash>
70 #include <QTranslator>
78 ////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////
82 #define ABORT_IF_BUSY do \
84 if(m_banner->isVisible() || m_delayedFileTimer->isActive()) \
86 MessageBeep(MB_ICONEXCLAMATION); \
92 #define SET_TEXT_COLOR(WIDGET, COLOR) do \
94 QPalette _palette = WIDGET->palette(); \
95 _palette.setColor(QPalette::WindowText, (COLOR)); \
96 _palette.setColor(QPalette::Text, (COLOR)); \
97 WIDGET->setPalette(_palette); \
101 #define SET_FONT_BOLD(WIDGET,BOLD) do \
103 QFont _font = WIDGET->font(); \
104 _font.setBold(BOLD); \
105 WIDGET->setFont(_font); \
109 #define TEMP_HIDE_DROPBOX(CMD) do \
111 bool _dropBoxVisible = m_dropBox->isVisible(); \
112 if(_dropBoxVisible) m_dropBox->hide(); \
113 do { CMD } while(0); \
114 if(_dropBoxVisible) m_dropBox->show(); \
118 #define SET_MODEL(VIEW, MODEL) do \
120 QItemSelectionModel *_tmp = (VIEW)->selectionModel(); \
121 (VIEW)->setModel(MODEL); \
122 LAMEXP_DELETE(_tmp); \
126 #define SET_CHECKBOX_STATE(CHCKBX, STATE) do \
128 if((CHCKBX)->isChecked() != (STATE)) \
132 if((CHCKBX)->isChecked() != (STATE)) \
134 qWarning("Warning: Failed to set checkbox " #CHCKBX " state!"); \
139 #define TRIM_STRING_RIGHT(STR) do \
141 while((STR.length() > 0) && STR[STR.length()-1].isSpace()) STR.chop(1); \
145 #define MAKE_TRANSPARENT(WIDGET, FLAG) do \
147 QPalette _p = (WIDGET)->palette(); \
148 _p.setColor(QPalette::Background, Qt::transparent); \
149 (WIDGET)->setPalette(FLAG ? _p : QPalette()); \
153 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "−"))
154 #define FSLINK(PATH) QString("<a href=\"file:///%1\">%2</a>").arg(PATH).arg(QString(PATH).replace("-", "−"))
155 #define USE_NATIVE_FILE_DIALOG (lamexp_themes_enabled() || ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) < QSysInfo::WV_XP))
156 #define CENTER_CURRENT_OUTPUT_FOLDER_DELAYED QTimer::singleShot(125, this, SLOT(centerOutputFolderModel()))
158 static const DWORD IDM_ABOUTBOX
= 0xEFF0;
160 ////////////////////////////////////////////////////////////
162 ////////////////////////////////////////////////////////////
164 MainWindow::MainWindow(FileListModel
*fileListModel
, AudioFileModel
*metaInfo
, SettingsModel
*settingsModel
, QWidget
*parent
)
167 ui(new Ui::MainWindow
),
168 m_fileListModel(fileListModel
),
169 m_metaData(metaInfo
),
170 m_settings(settingsModel
),
171 m_fileSystemModel(NULL
),
172 m_neroEncoderAvailable(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")),
173 m_fhgEncoderAvailable(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll") && lamexp_check_tool("nsutil.dll") && lamexp_check_tool("libmp4v2.dll")),
174 m_qaacEncoderAvailable(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll")),
176 m_firstTimeShown(true),
177 m_outputFolderViewCentering(false),
178 m_outputFolderViewInitCounter(0)
180 //Init the dialog, from the .ui file
182 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint
);
184 //Register meta types
185 qRegisterMetaType
<AudioFileModel
>("AudioFileModel");
187 //Enabled main buttons
188 connect(ui
->buttonAbout
, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
189 connect(ui
->buttonStart
, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
190 connect(ui
->buttonQuit
, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
193 ui
->tabWidget
->setCurrentIndex(0);
194 connect(ui
->tabWidget
, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
197 if(HMENU hMenu
= ::GetSystemMenu(winId(), FALSE
))
199 AppendMenuW(hMenu
, MF_SEPARATOR
, 0, 0);
200 AppendMenuW(hMenu
, MF_STRING
, IDM_ABOUTBOX
, L
"About...");
203 //--------------------------------
204 // Setup "Source" tab
205 //--------------------------------
207 ui
->sourceFileView
->setModel(m_fileListModel
);
208 ui
->sourceFileView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
209 ui
->sourceFileView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
210 ui
->sourceFileView
->setContextMenuPolicy(Qt::CustomContextMenu
);
211 ui
->sourceFileView
->viewport()->installEventFilter(this);
212 m_dropNoteLabel
= new QLabel(ui
->sourceFileView
);
213 m_dropNoteLabel
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
214 SET_FONT_BOLD(m_dropNoteLabel
, true);
215 SET_TEXT_COLOR(m_dropNoteLabel
, Qt::darkGray
);
216 m_sourceFilesContextMenu
= new QMenu();
217 m_showDetailsContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
218 m_previewContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/sound.png"), "N/A");
219 m_findFileContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_go.png"), "N/A");
220 m_sourceFilesContextMenu
->addSeparator();
221 m_exportCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/table_save.png"), "N/A");
222 m_importCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_table.png"), "N/A");
223 SET_FONT_BOLD(m_showDetailsContextAction
, true);
224 connect(ui
->buttonAddFiles
, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
225 connect(ui
->buttonRemoveFile
, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
226 connect(ui
->buttonClearFiles
, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
227 connect(ui
->buttonFileUp
, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
228 connect(ui
->buttonFileDown
, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
229 connect(ui
->buttonShowDetails
, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
230 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
231 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
232 connect(m_fileListModel
, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
233 connect(ui
->sourceFileView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(sourceFilesContextMenu(QPoint
)));
234 connect(ui
->sourceFileView
->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
235 connect(ui
->sourceFileView
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
236 connect(m_showDetailsContextAction
, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
237 connect(m_previewContextAction
, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
238 connect(m_findFileContextAction
, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
239 connect(m_exportCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(exportCsvContextActionTriggered()));
240 connect(m_importCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(importCsvContextActionTriggered()));
242 //--------------------------------
243 // Setup "Output" tab
244 //--------------------------------
246 ui
->outputFolderView
->setHeaderHidden(true);
247 ui
->outputFolderView
->setAnimated(false);
248 ui
->outputFolderView
->setMouseTracking(false);
249 ui
->outputFolderView
->setContextMenuPolicy(Qt::CustomContextMenu
);
250 ui
->outputFolderView
->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn
);
252 m_evenFilterOutputFolderMouse
= new CustomEventFilter
;
253 ui
->outputFoldersGoUpLabel
->installEventFilter(m_evenFilterOutputFolderMouse
);
254 ui
->outputFoldersEditorLabel
->installEventFilter(m_evenFilterOutputFolderMouse
);
255 ui
->outputFoldersFovoritesLabel
->installEventFilter(m_evenFilterOutputFolderMouse
);
256 ui
->outputFolderLabel
->installEventFilter(m_evenFilterOutputFolderMouse
);
258 m_evenFilterOutputFolderView
= new CustomEventFilter
;
259 ui
->outputFolderView
->installEventFilter(m_evenFilterOutputFolderView
);
261 SET_CHECKBOX_STATE(ui
->saveToSourceFolderCheckBox
, m_settings
->outputToSourceDir());
262 ui
->prependRelativePathCheckBox
->setChecked(m_settings
->prependRelativeSourcePath());
264 connect(ui
->outputFolderView
, SIGNAL(clicked(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
265 connect(ui
->outputFolderView
, SIGNAL(activated(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
266 connect(ui
->outputFolderView
, SIGNAL(pressed(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
267 connect(ui
->outputFolderView
, SIGNAL(entered(QModelIndex
)), this, SLOT(outputFolderViewMoved(QModelIndex
)));
268 connect(ui
->outputFolderView
, SIGNAL(expanded(QModelIndex
)), this, SLOT(outputFolderItemExpanded(QModelIndex
)));
269 connect(ui
->buttonMakeFolder
, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
270 connect(ui
->buttonGotoHome
, SIGNAL(clicked()), SLOT(gotoHomeFolderButtonClicked()));
271 connect(ui
->buttonGotoDesktop
, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
272 connect(ui
->buttonGotoMusic
, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
273 connect(ui
->saveToSourceFolderCheckBox
, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
274 connect(ui
->prependRelativePathCheckBox
, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
275 connect(ui
->outputFolderEdit
, SIGNAL(editingFinished()), this, SLOT(outputFolderEditFinished()));
276 connect(m_evenFilterOutputFolderMouse
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(outputFolderMouseEventOccurred(QWidget
*, QEvent
*)));
277 connect(m_evenFilterOutputFolderView
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(outputFolderViewEventOccurred(QWidget
*, QEvent
*)));
279 if(m_outputFolderContextMenu
= new QMenu())
281 m_showFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
282 m_goUpFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/folder_up.png"), "N/A");
283 m_outputFolderContextMenu
->addSeparator();
284 m_refreshFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/arrow_refresh.png"), "N/A");
285 m_outputFolderContextMenu
->setDefaultAction(m_showFolderContextAction
);
286 connect(ui
->outputFolderView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(outputFolderContextMenu(QPoint
)));
287 connect(m_showFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
288 connect(m_refreshFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(refreshFolderContextActionTriggered()));
289 connect(m_goUpFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(goUpFolderContextActionTriggered()));
292 if(m_outputFolderFavoritesMenu
= new QMenu())
294 m_addFavoriteFolderAction
= m_outputFolderFavoritesMenu
->addAction(QIcon(":/icons/add.png"), "N/A");
295 m_outputFolderFavoritesMenu
->insertSeparator(m_addFavoriteFolderAction
);
296 connect(m_addFavoriteFolderAction
, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
299 ui
->outputFolderEdit
->setVisible(false);
300 if(m_outputFolderNoteBox
= new QLabel(ui
->outputFolderView
))
302 m_outputFolderNoteBox
->setAutoFillBackground(true);
303 m_outputFolderNoteBox
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
304 m_outputFolderNoteBox
->setFrameShape(QFrame::StyledPanel
);
305 SET_FONT_BOLD(m_outputFolderNoteBox
, true);
306 m_outputFolderNoteBox
->hide();
310 outputFolderViewClicked(QModelIndex());
313 //--------------------------------
314 // Setup "Meta Data" tab
315 //--------------------------------
317 m_metaInfoModel
= new MetaInfoModel(m_metaData
, 6);
318 m_metaInfoModel
->clearData();
319 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
320 ui
->metaDataView
->setModel(m_metaInfoModel
);
321 ui
->metaDataView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
322 ui
->metaDataView
->verticalHeader()->hide();
323 ui
->metaDataView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
324 SET_CHECKBOX_STATE(ui
->writeMetaDataCheckBox
, m_settings
->writeMetaTags());
325 ui
->generatePlaylistCheckBox
->setChecked(m_settings
->createPlaylist());
326 connect(ui
->buttonEditMeta
, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
327 connect(ui
->buttonClearMeta
, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
328 connect(ui
->writeMetaDataCheckBox
, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
329 connect(ui
->generatePlaylistCheckBox
, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
331 //--------------------------------
332 //Setup "Compression" tab
333 //--------------------------------
335 m_encoderButtonGroup
= new QButtonGroup(this);
336 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderMP3
, SettingsModel::MP3Encoder
);
337 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderVorbis
, SettingsModel::VorbisEncoder
);
338 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAAC
, SettingsModel::AACEncoder
);
339 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAC3
, SettingsModel::AC3Encoder
);
340 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderFLAC
, SettingsModel::FLACEncoder
);
341 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderOpus
, SettingsModel::OpusEncoder
);
342 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderDCA
, SettingsModel::DCAEncoder
);
343 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderPCM
, SettingsModel::PCMEncoder
);
345 m_modeButtonGroup
= new QButtonGroup(this);
346 m_modeButtonGroup
->addButton(ui
->radioButtonModeQuality
, SettingsModel::VBRMode
);
347 m_modeButtonGroup
->addButton(ui
->radioButtonModeAverageBitrate
, SettingsModel::ABRMode
);
348 m_modeButtonGroup
->addButton(ui
->radioButtonConstBitrate
, SettingsModel::CBRMode
);
350 ui
->radioButtonEncoderAAC
->setEnabled(m_neroEncoderAvailable
|| m_fhgEncoderAvailable
|| m_qaacEncoderAvailable
);
351 ui
->radioButtonEncoderMP3
->setChecked(m_settings
->compressionEncoder() == SettingsModel::MP3Encoder
);
352 ui
->radioButtonEncoderVorbis
->setChecked(m_settings
->compressionEncoder() == SettingsModel::VorbisEncoder
);
353 ui
->radioButtonEncoderAAC
->setChecked((m_settings
->compressionEncoder() == SettingsModel::AACEncoder
) && (m_neroEncoderAvailable
|| m_fhgEncoderAvailable
|| m_qaacEncoderAvailable
));
354 ui
->radioButtonEncoderAC3
->setChecked(m_settings
->compressionEncoder() == SettingsModel::AC3Encoder
);
355 ui
->radioButtonEncoderFLAC
->setChecked(m_settings
->compressionEncoder() == SettingsModel::FLACEncoder
);
356 ui
->radioButtonEncoderOpus
->setChecked(m_settings
->compressionEncoder() == SettingsModel::OpusEncoder
);
357 ui
->radioButtonEncoderDCA
->setChecked(m_settings
->compressionEncoder() == SettingsModel::DCAEncoder
);
358 ui
->radioButtonEncoderPCM
->setChecked(m_settings
->compressionEncoder() == SettingsModel::PCMEncoder
);
359 ui
->radioButtonModeQuality
->setChecked(m_settings
->compressionRCMode() == SettingsModel::VBRMode
);
360 ui
->radioButtonModeAverageBitrate
->setChecked(m_settings
->compressionRCMode() == SettingsModel::ABRMode
);
361 ui
->radioButtonConstBitrate
->setChecked(m_settings
->compressionRCMode() == SettingsModel::CBRMode
);
362 ui
->sliderBitrate
->setValue(m_settings
->compressionBitrate());
364 m_evenFilterCompressionTab
= new CustomEventFilter();
365 ui
->labelCompressionHelp
->installEventFilter(m_evenFilterCompressionTab
);
367 connect(m_encoderButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
368 connect(m_modeButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
369 connect(m_evenFilterCompressionTab
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(compressionTabEventOccurred(QWidget
*, QEvent
*)));
370 connect(ui
->sliderBitrate
, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
372 updateEncoder(m_encoderButtonGroup
->checkedId());
374 //--------------------------------
375 //Setup "Advanced Options" tab
376 //--------------------------------
378 ui
->sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQuality());
379 if(m_settings
->maximumInstances() > 0) ui
->sliderMaxInstances
->setValue(m_settings
->maximumInstances());
381 ui
->spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRate());
382 ui
->spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRate());
383 ui
->spinBoxNormalizationFilter
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolume()) / 100.0);
384 ui
->spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBass()) / 100.0);
385 ui
->spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTreble()) / 100.0);
386 ui
->spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSize());
387 ui
->spinBoxOpusComplexity
->setValue(m_settings
->opusComplexity());
389 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelMode());
390 ui
->comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRate());
391 ui
->comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfile());
392 ui
->comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingMode());
393 ui
->comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompression());
394 ui
->comboBoxNormalizationMode
->setCurrentIndex(m_settings
->normalizationFilterEqualizationMode());
395 //comboBoxOpusOptimize->setCurrentIndex(m_settings->opusOptimizeFor());
396 ui
->comboBoxOpusFramesize
->setCurrentIndex(m_settings
->opusFramesize());
398 SET_CHECKBOX_STATE(ui
->checkBoxBitrateManagement
, m_settings
->bitrateManagementEnabled());
399 SET_CHECKBOX_STATE(ui
->checkBoxNeroAAC2PassMode
, m_settings
->neroAACEnable2Pass());
400 SET_CHECKBOX_STATE(ui
->checkBoxAftenFastAllocation
, m_settings
->aftenFastBitAllocation());
401 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilter
, m_settings
->normalizationFilterEnabled());
402 SET_CHECKBOX_STATE(ui
->checkBoxAutoDetectInstances
, (m_settings
->maximumInstances() < 1));
403 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, !m_settings
->customTempPathEnabled());
404 SET_CHECKBOX_STATE(ui
->checkBoxRenameOutput
, m_settings
->renameOutputFilesEnabled());
405 SET_CHECKBOX_STATE(ui
->checkBoxForceStereoDownmix
, m_settings
->forceStereoDownmix());
406 ui
->checkBoxNeroAAC2PassMode
->setEnabled(!(m_fhgEncoderAvailable
|| m_qaacEncoderAvailable
));
408 ui
->lineEditCustomParamLAME
->setText(m_settings
->customParametersLAME());
409 ui
->lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEnc());
410 ui
->lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEnc());
411 ui
->lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLAC());
412 ui
->lineEditCustomParamAften
->setText(m_settings
->customParametersAften());
413 ui
->lineEditCustomParamOpus
->setText(m_settings
->customParametersOpus());
414 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPath()));
415 ui
->lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPattern());
417 m_evenFilterCustumParamsHelp
= new CustomEventFilter();
418 ui
->helpCustomParamLAME
->installEventFilter(m_evenFilterCustumParamsHelp
);
419 ui
->helpCustomParamOggEnc
->installEventFilter(m_evenFilterCustumParamsHelp
);
420 ui
->helpCustomParamNeroAAC
->installEventFilter(m_evenFilterCustumParamsHelp
);
421 ui
->helpCustomParamFLAC
->installEventFilter(m_evenFilterCustumParamsHelp
);
422 ui
->helpCustomParamAften
->installEventFilter(m_evenFilterCustumParamsHelp
);
423 ui
->helpCustomParamOpus
->installEventFilter(m_evenFilterCustumParamsHelp
);
425 m_overwriteButtonGroup
= new QButtonGroup(this);
426 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeKeepBoth
, SettingsModel::Overwrite_KeepBoth
);
427 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeSkipFile
, SettingsModel::Overwrite_SkipFile
);
428 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeReplaces
, SettingsModel::Overwrite_Replaces
);
430 ui
->radioButtonOverwriteModeKeepBoth
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_KeepBoth
);
431 ui
->radioButtonOverwriteModeSkipFile
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_SkipFile
);
432 ui
->radioButtonOverwriteModeReplaces
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_Replaces
);
434 connect(ui
->sliderLameAlgoQuality
, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
435 connect(ui
->checkBoxBitrateManagement
, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
436 connect(ui
->spinBoxBitrateManagementMin
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
437 connect(ui
->spinBoxBitrateManagementMax
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
438 connect(ui
->comboBoxMP3ChannelMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
439 connect(ui
->comboBoxSamplingRate
, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
440 connect(ui
->checkBoxNeroAAC2PassMode
, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
441 connect(ui
->comboBoxAACProfile
, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
442 connect(ui
->checkBoxNormalizationFilter
, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
443 connect(ui
->comboBoxAftenCodingMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
444 connect(ui
->comboBoxAftenDRCMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
445 connect(ui
->spinBoxAftenSearchSize
, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
446 connect(ui
->checkBoxAftenFastAllocation
, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
447 connect(ui
->spinBoxNormalizationFilter
, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
448 connect(ui
->comboBoxNormalizationMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(normalizationModeChanged(int)));
449 connect(ui
->spinBoxToneAdjustBass
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
450 connect(ui
->spinBoxToneAdjustTreble
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
451 connect(ui
->buttonToneAdjustReset
, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
452 connect(ui
->lineEditCustomParamLAME
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
453 connect(ui
->lineEditCustomParamOggEnc
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
454 connect(ui
->lineEditCustomParamNeroAAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
455 connect(ui
->lineEditCustomParamFLAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
456 connect(ui
->lineEditCustomParamAften
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
457 connect(ui
->lineEditCustomParamOpus
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
458 connect(ui
->sliderMaxInstances
, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
459 connect(ui
->checkBoxAutoDetectInstances
, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
460 connect(ui
->buttonBrowseCustomTempFolder
, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
461 connect(ui
->lineEditCustomTempFolder
, SIGNAL(textChanged(QString
)), this, SLOT(customTempFolderChanged(QString
)));
462 connect(ui
->checkBoxUseSystemTempFolder
, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
463 connect(ui
->buttonResetAdvancedOptions
, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
464 connect(ui
->checkBoxRenameOutput
, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
465 connect(ui
->lineEditRenamePattern
, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
466 connect(ui
->lineEditRenamePattern
, SIGNAL(textChanged(QString
)), this, SLOT(renameOutputPatternChanged(QString
)));
467 connect(ui
->labelShowRenameMacros
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
468 connect(ui
->checkBoxForceStereoDownmix
, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
469 connect(ui
->comboBoxOpusFramesize
, SIGNAL(currentIndexChanged(int)), this, SLOT(opusSettingsChanged()));
470 connect(ui
->spinBoxOpusComplexity
, SIGNAL(valueChanged(int)), this, SLOT(opusSettingsChanged()));
471 //connect(comboBoxOpusOptimize, SIGNAL(currentIndexChanged(int)), SLOT(opusSettingsChanged()));
472 //connect(checkBoxOpusExpAnalysis, SIGNAL(clicked(bool)), this, SLOT(opusSettingsChanged()));
473 connect(m_overwriteButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(overwriteModeChanged(int)));
474 connect(m_evenFilterCustumParamsHelp
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(customParamsHelpRequested(QWidget
*, QEvent
*)));
476 //--------------------------------
477 // Force initial GUI update
478 //--------------------------------
480 updateLameAlgoQuality(ui
->sliderLameAlgoQuality
->value());
481 updateMaximumInstances(ui
->sliderMaxInstances
->value());
482 toneAdjustTrebleChanged(ui
->spinBoxToneAdjustTreble
->value());
483 toneAdjustBassChanged(ui
->spinBoxToneAdjustBass
->value());
484 customParamsChanged();
486 //--------------------------------
487 // Initialize actions
488 //--------------------------------
490 //Activate file menu actions
491 ui
->actionOpenFolder
->setData(QVariant::fromValue
<bool>(false));
492 ui
->actionOpenFolderRecursively
->setData(QVariant::fromValue
<bool>(true));
493 connect(ui
->actionOpenFolder
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
494 connect(ui
->actionOpenFolderRecursively
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
496 //Activate view menu actions
497 m_tabActionGroup
= new QActionGroup(this);
498 m_tabActionGroup
->addAction(ui
->actionSourceFiles
);
499 m_tabActionGroup
->addAction(ui
->actionOutputDirectory
);
500 m_tabActionGroup
->addAction(ui
->actionCompression
);
501 m_tabActionGroup
->addAction(ui
->actionMetaData
);
502 m_tabActionGroup
->addAction(ui
->actionAdvancedOptions
);
503 ui
->actionSourceFiles
->setData(0);
504 ui
->actionOutputDirectory
->setData(1);
505 ui
->actionMetaData
->setData(2);
506 ui
->actionCompression
->setData(3);
507 ui
->actionAdvancedOptions
->setData(4);
508 ui
->actionSourceFiles
->setChecked(true);
509 connect(m_tabActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(tabActionActivated(QAction
*)));
511 //Activate style menu actions
512 m_styleActionGroup
= new QActionGroup(this);
513 m_styleActionGroup
->addAction(ui
->actionStylePlastique
);
514 m_styleActionGroup
->addAction(ui
->actionStyleCleanlooks
);
515 m_styleActionGroup
->addAction(ui
->actionStyleWindowsVista
);
516 m_styleActionGroup
->addAction(ui
->actionStyleWindowsXP
);
517 m_styleActionGroup
->addAction(ui
->actionStyleWindowsClassic
);
518 ui
->actionStylePlastique
->setData(0);
519 ui
->actionStyleCleanlooks
->setData(1);
520 ui
->actionStyleWindowsVista
->setData(2);
521 ui
->actionStyleWindowsXP
->setData(3);
522 ui
->actionStyleWindowsClassic
->setData(4);
523 ui
->actionStylePlastique
->setChecked(true);
524 ui
->actionStyleWindowsXP
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_XP
&& lamexp_themes_enabled());
525 ui
->actionStyleWindowsVista
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_VISTA
&& lamexp_themes_enabled());
526 connect(m_styleActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(styleActionActivated(QAction
*)));
527 styleActionActivated(NULL
);
529 //Populate the language menu
530 m_languageActionGroup
= new QActionGroup(this);
531 QStringList translations
= lamexp_query_translations();
532 while(!translations
.isEmpty())
534 QString langId
= translations
.takeFirst();
535 QAction
*currentLanguage
= new QAction(this);
536 currentLanguage
->setData(langId
);
537 currentLanguage
->setText(lamexp_translation_name(langId
));
538 currentLanguage
->setIcon(QIcon(QString(":/flags/%1.png").arg(langId
)));
539 currentLanguage
->setCheckable(true);
540 currentLanguage
->setChecked(false);
541 m_languageActionGroup
->addAction(currentLanguage
);
542 ui
->menuLanguage
->insertAction(ui
->actionLoadTranslationFromFile
, currentLanguage
);
544 ui
->menuLanguage
->insertSeparator(ui
->actionLoadTranslationFromFile
);
545 connect(ui
->actionLoadTranslationFromFile
, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
546 connect(m_languageActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(languageActionActivated(QAction
*)));
547 ui
->actionLoadTranslationFromFile
->setChecked(false);
549 //Activate tools menu actions
550 ui
->actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
551 ui
->actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
552 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
553 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
554 ui
->actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
555 ui
->actionDisableShellIntegration
->setDisabled(lamexp_portable_mode() && ui
->actionDisableShellIntegration
->isChecked());
556 ui
->actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta() || lamexp_version_demo());
557 ui
->actionCheckForBetaUpdates
->setEnabled(!lamexp_version_demo());
558 ui
->actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
559 ui
->actionHibernateComputer
->setEnabled(lamexp_is_hibernation_supported());
560 connect(ui
->actionDisableUpdateReminder
, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
561 connect(ui
->actionDisableSounds
, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
562 connect(ui
->actionDisableNeroAacNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
563 connect(ui
->actionDisableSlowStartupNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
564 connect(ui
->actionDisableShellIntegration
, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
565 connect(ui
->actionShowDropBoxWidget
, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
566 connect(ui
->actionHibernateComputer
, SIGNAL(triggered(bool)), this, SLOT(hibernateComputerActionTriggered(bool)));
567 connect(ui
->actionCheckForBetaUpdates
, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
568 connect(ui
->actionImportCueSheet
, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
570 //Activate help menu actions
571 ui
->actionVisitHomepage
->setData(QString::fromLatin1(lamexp_website_url()));
572 ui
->actionVisitSupport
->setData(QString::fromLatin1(lamexp_support_url()));
573 ui
->actionDocumentFAQ
->setData(QString("%1/FAQ.html").arg(QApplication::applicationDirPath()));
574 ui
->actionDocumentChangelog
->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
575 ui
->actionDocumentTranslate
->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
576 connect(ui
->actionCheckUpdates
, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
577 connect(ui
->actionVisitHomepage
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
578 connect(ui
->actionVisitSupport
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
579 connect(ui
->actionDocumentFAQ
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
580 connect(ui
->actionDocumentChangelog
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
581 connect(ui
->actionDocumentTranslate
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
583 //--------------------------------
584 // Prepare to show window
585 //--------------------------------
587 //Center window in screen
588 QRect desktopRect
= QApplication::desktop()->screenGeometry();
589 QRect thisRect
= this->geometry();
590 move((desktopRect
.width() - thisRect
.width()) / 2, (desktopRect
.height() - thisRect
.height()) / 2);
591 setMinimumSize(thisRect
.width(), thisRect
.height());
594 m_banner
= new WorkingBanner(this);
596 //Create DropBox widget
597 m_dropBox
= new DropBox(this, m_fileListModel
, m_settings
);
598 connect(m_fileListModel
, SIGNAL(modelReset()), m_dropBox
, SLOT(modelChanged()));
599 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), m_dropBox
, SLOT(modelChanged()));
600 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), m_dropBox
, SLOT(modelChanged()));
601 connect(m_fileListModel
, SIGNAL(rowAppended()), m_dropBox
, SLOT(modelChanged()));
603 //Create message handler thread
604 m_messageHandler
= new MessageHandlerThread();
605 m_delayedFileList
= new QStringList();
606 m_delayedFileTimer
= new QTimer();
607 m_delayedFileTimer
->setSingleShot(true);
608 m_delayedFileTimer
->setInterval(5000);
609 connect(m_messageHandler
, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection
);
610 connect(m_messageHandler
, SIGNAL(fileReceived(QString
)), this, SLOT(addFileDelayed(QString
)), Qt::QueuedConnection
);
611 connect(m_messageHandler
, SIGNAL(folderReceived(QString
, bool)), this, SLOT(addFolderDelayed(QString
, bool)), Qt::QueuedConnection
);
612 connect(m_messageHandler
, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection
);
613 connect(m_delayedFileTimer
, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
614 m_messageHandler
->start();
617 initializeTranslation();
619 //Re-translate (make sure we translate once)
620 QEvent
languageChangeEvent(QEvent::LanguageChange
);
621 changeEvent(&languageChangeEvent
);
624 this->setAcceptDrops(true);
627 ////////////////////////////////////////////////////////////
629 ////////////////////////////////////////////////////////////
631 MainWindow::~MainWindow(void)
633 //Stop message handler thread
634 if(m_messageHandler
&& m_messageHandler
->isRunning())
636 m_messageHandler
->stop();
637 if(!m_messageHandler
->wait(2500))
639 m_messageHandler
->terminate();
640 m_messageHandler
->wait();
645 SET_MODEL(ui
->sourceFileView
, NULL
);
646 SET_MODEL(ui
->outputFolderView
, NULL
);
647 SET_MODEL(ui
->metaDataView
, NULL
);
650 LAMEXP_DELETE(m_tabActionGroup
);
651 LAMEXP_DELETE(m_styleActionGroup
);
652 LAMEXP_DELETE(m_languageActionGroup
);
653 LAMEXP_DELETE(m_banner
);
654 LAMEXP_DELETE(m_fileSystemModel
);
655 LAMEXP_DELETE(m_messageHandler
);
656 LAMEXP_DELETE(m_delayedFileList
);
657 LAMEXP_DELETE(m_delayedFileTimer
);
658 LAMEXP_DELETE(m_metaInfoModel
);
659 LAMEXP_DELETE(m_encoderButtonGroup
);
660 LAMEXP_DELETE(m_modeButtonGroup
);
661 LAMEXP_DELETE(m_overwriteButtonGroup
);
662 LAMEXP_DELETE(m_sourceFilesContextMenu
);
663 LAMEXP_DELETE(m_outputFolderFavoritesMenu
);
664 LAMEXP_DELETE(m_outputFolderContextMenu
);
665 LAMEXP_DELETE(m_dropBox
);
666 LAMEXP_DELETE(m_evenFilterCustumParamsHelp
);
667 LAMEXP_DELETE(m_evenFilterOutputFolderMouse
);
668 LAMEXP_DELETE(m_evenFilterOutputFolderView
);
669 LAMEXP_DELETE(m_evenFilterCompressionTab
);
671 //Un-initialize the dialog
675 ////////////////////////////////////////////////////////////
677 ////////////////////////////////////////////////////////////
680 * Add file to source list
682 void MainWindow::addFiles(const QStringList
&files
)
689 ui
->tabWidget
->setCurrentIndex(0);
691 FileAnalyzer
*analyzer
= new FileAnalyzer(files
);
692 connect(analyzer
, SIGNAL(fileSelected(QString
)), m_banner
, SLOT(setText(QString
)), Qt::QueuedConnection
);
693 connect(analyzer
, SIGNAL(progressValChanged(unsigned int)), m_banner
, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection
);
694 connect(analyzer
, SIGNAL(progressMaxChanged(unsigned int)), m_banner
, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection
);
695 connect(analyzer
, SIGNAL(fileAnalyzed(AudioFileModel
)), m_fileListModel
, SLOT(addFile(AudioFileModel
)), Qt::QueuedConnection
);
696 connect(m_banner
, SIGNAL(userAbort()), analyzer
, SLOT(abortProcess()), Qt::DirectConnection
);
700 m_fileListModel
->setBlockUpdates(true);
701 QTime startTime
= QTime::currentTime();
702 m_banner
->show(tr("Adding file(s), please wait..."), analyzer
);
706 /* ignore any exceptions that may occur */
709 m_fileListModel
->setBlockUpdates(false);
710 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
711 ui
->sourceFileView
->update();
712 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
713 ui
->sourceFileView
->scrollToBottom();
714 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
716 if(analyzer
->filesDenied())
718 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."))));
720 if(analyzer
->filesDummyCDDA())
722 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>"))));
724 if(analyzer
->filesCueSheet())
726 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."))));
728 if(analyzer
->filesRejected())
730 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."))));
733 LAMEXP_DELETE(analyzer
);
738 * Add folder to source list
740 void MainWindow::addFolder(const QString
&path
, bool recursive
, bool delayed
)
742 QFileInfoList folderInfoList
;
743 folderInfoList
<< QFileInfo(path
);
744 QStringList fileList
;
746 m_banner
->show(tr("Scanning folder(s) for files, please wait..."));
748 QApplication::processEvents();
749 GetAsyncKeyState(VK_ESCAPE
);
751 while(!folderInfoList
.isEmpty())
753 if(GetAsyncKeyState(VK_ESCAPE
) & 0x0001)
755 MessageBeep(MB_ICONERROR
);
756 qWarning("Operation cancelled by user!");
761 QDir
currentDir(folderInfoList
.takeFirst().canonicalFilePath());
762 QFileInfoList fileInfoList
= currentDir
.entryInfoList(QDir::Files
| QDir::NoSymLinks
);
764 while(!fileInfoList
.isEmpty())
766 fileList
<< fileInfoList
.takeFirst().canonicalFilePath();
769 QApplication::processEvents();
773 folderInfoList
.append(currentDir
.entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
));
774 QApplication::processEvents();
779 QApplication::processEvents();
781 if(!fileList
.isEmpty())
785 addFilesDelayed(fileList
);
797 bool MainWindow::checkForUpdates(void)
799 bool bReadyToInstall
= false;
801 UpdateDialog
*updateDialog
= new UpdateDialog(m_settings
, this);
802 updateDialog
->exec();
804 if(updateDialog
->getSuccess())
806 m_settings
->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate
));
807 bReadyToInstall
= updateDialog
->updateReadyToInstall();
810 LAMEXP_DELETE(updateDialog
);
811 return bReadyToInstall
;
815 * Refresh list of favorites
817 void MainWindow::refreshFavorites(void)
819 QList
<QAction
*> folderList
= m_outputFolderFavoritesMenu
->actions();
820 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
821 while(favorites
.count() > 6) favorites
.removeFirst();
823 while(!folderList
.isEmpty())
825 QAction
*currentItem
= folderList
.takeFirst();
826 if(currentItem
->isSeparator()) break;
827 m_outputFolderFavoritesMenu
->removeAction(currentItem
);
828 LAMEXP_DELETE(currentItem
);
831 QAction
*lastItem
= m_outputFolderFavoritesMenu
->actions().first();
833 while(!favorites
.isEmpty())
835 QString path
= favorites
.takeLast();
836 if(QDir(path
).exists())
838 QAction
*action
= new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path
), this);
839 action
->setData(path
);
840 m_outputFolderFavoritesMenu
->insertAction(lastItem
, action
);
841 connect(action
, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
848 * Initilaize translation
850 void MainWindow::initializeTranslation(void)
852 bool translationLoaded
= false;
854 //Try to load "external" translation file
855 if(!m_settings
->currentLanguageFile().isEmpty())
857 const QString qmFilePath
= QFileInfo(m_settings
->currentLanguageFile()).canonicalFilePath();
858 if((!qmFilePath
.isEmpty()) && QFileInfo(qmFilePath
).exists() && QFileInfo(qmFilePath
).isFile() && (QFileInfo(qmFilePath
).suffix().compare("qm", Qt::CaseInsensitive
) == 0))
860 if(lamexp_install_translator_from_file(qmFilePath
))
862 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
863 while(!actions
.isEmpty()) actions
.takeFirst()->setChecked(false);
864 ui
->actionLoadTranslationFromFile
->setChecked(true);
865 translationLoaded
= true;
870 //Try to load "built-in" translation file
871 if(!translationLoaded
)
873 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
874 while(!languageActions
.isEmpty())
876 QAction
*currentLanguage
= languageActions
.takeFirst();
877 if(currentLanguage
->data().toString().compare(m_settings
->currentLanguage(), Qt::CaseInsensitive
) == 0)
879 currentLanguage
->setChecked(true);
880 languageActionActivated(currentLanguage
);
881 translationLoaded
= true;
886 //Fallback to default translation
887 if(!translationLoaded
)
889 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
890 while(!languageActions
.isEmpty())
892 QAction
*currentLanguage
= languageActions
.takeFirst();
893 if(currentLanguage
->data().toString().compare(LAMEXP_DEFAULT_LANGID
, Qt::CaseInsensitive
) == 0)
895 currentLanguage
->setChecked(true);
896 languageActionActivated(currentLanguage
);
897 translationLoaded
= true;
902 //Make sure we loaded some translation
903 if(!translationLoaded
)
905 qFatal("Failed to load any translation, this is NOT supposed to happen!");
909 ////////////////////////////////////////////////////////////
911 ////////////////////////////////////////////////////////////
914 * Window is about to be shown
916 void MainWindow::showEvent(QShowEvent
*event
)
919 m_dropNoteLabel
->setGeometry(0, 0, ui
->sourceFileView
->width(), ui
->sourceFileView
->height());
920 sourceModelChanged();
922 if(!event
->spontaneous())
924 ui
->tabWidget
->setCurrentIndex(0);
929 m_firstTimeShown
= false;
930 QTimer::singleShot(0, this, SLOT(windowShown()));
934 if(m_settings
->dropBoxWidgetEnabled())
936 m_dropBox
->setVisible(true);
942 * Re-translate the UI
944 void MainWindow::changeEvent(QEvent
*e
)
946 if(e
->type() == QEvent::LanguageChange
)
948 int comboBoxIndex
[8];
950 //Backup combobox indices, as retranslateUi() resets
951 comboBoxIndex
[0] = ui
->comboBoxMP3ChannelMode
->currentIndex();
952 comboBoxIndex
[1] = ui
->comboBoxSamplingRate
->currentIndex();
953 comboBoxIndex
[2] = ui
->comboBoxAACProfile
->currentIndex();
954 comboBoxIndex
[3] = ui
->comboBoxAftenCodingMode
->currentIndex();
955 comboBoxIndex
[4] = ui
->comboBoxAftenDRCMode
->currentIndex();
956 comboBoxIndex
[5] = ui
->comboBoxNormalizationMode
->currentIndex();
957 comboBoxIndex
[6] = 0; //comboBoxOpusOptimize->currentIndex();
958 comboBoxIndex
[7] = ui
->comboBoxOpusFramesize
->currentIndex();
960 //Re-translate from UIC
961 ui
->retranslateUi(this);
963 //Restore combobox indices
964 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(comboBoxIndex
[0]);
965 ui
->comboBoxSamplingRate
->setCurrentIndex(comboBoxIndex
[1]);
966 ui
->comboBoxAACProfile
->setCurrentIndex(comboBoxIndex
[2]);
967 ui
->comboBoxAftenCodingMode
->setCurrentIndex(comboBoxIndex
[3]);
968 ui
->comboBoxAftenDRCMode
->setCurrentIndex(comboBoxIndex
[4]);
969 ui
->comboBoxNormalizationMode
->setCurrentIndex(comboBoxIndex
[5]);
970 //comboBoxOpusOptimize->setCurrentIndex(comboBoxIndex[6]);
971 ui
->comboBoxOpusFramesize
->setCurrentIndex(comboBoxIndex
[7]);
973 //Update the window title
976 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
978 else if(lamexp_version_demo())
980 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
983 //Manually re-translate widgets that UIC doesn't handle
984 m_dropNoteLabel
->setText(QString("» %1 «").arg(tr("You can drop in audio files here!")));
985 m_outputFolderNoteBox
->setText(tr("Initializing directory outline, please be patient..."));
986 m_showDetailsContextAction
->setText(tr("Show Details"));
987 m_previewContextAction
->setText(tr("Open File in External Application"));
988 m_findFileContextAction
->setText(tr("Browse File Location"));
989 m_showFolderContextAction
->setText(tr("Browse Selected Folder"));
990 m_refreshFolderContextAction
->setText(tr("Refresh Directory Outline"));
991 m_goUpFolderContextAction
->setText(tr("Go To Parent Directory"));
992 m_addFavoriteFolderAction
->setText(tr("Bookmark Current Output Folder"));
993 m_exportCsvContextAction
->setText(tr("Export Meta Tags to CSV File"));
994 m_importCsvContextAction
->setText(tr("Import Meta Tags from CSV File"));
997 m_metaInfoModel
->clearData();
998 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
999 updateEncoder(m_settings
->compressionEncoder());
1000 updateLameAlgoQuality(ui
->sliderLameAlgoQuality
->value());
1001 updateMaximumInstances(ui
->sliderMaxInstances
->value());
1002 renameOutputPatternChanged(ui
->lineEditRenamePattern
->text());
1004 //Re-install shell integration
1005 if(m_settings
->shellIntegrationEnabled())
1007 ShellIntegration::install();
1010 //Translate system menu
1011 if(HMENU hMenu
= ::GetSystemMenu(winId(), FALSE
))
1013 ModifyMenu(hMenu
, IDM_ABOUTBOX
, MF_STRING
| MF_BYCOMMAND
, IDM_ABOUTBOX
, QWCHAR(ui
->buttonAbout
->text()));
1016 //Force resize, if needed
1017 tabPageChanged(ui
->tabWidget
->currentIndex());
1022 * File dragged over window
1024 void MainWindow::dragEnterEvent(QDragEnterEvent
*event
)
1026 QStringList formats
= event
->mimeData()->formats();
1028 if(formats
.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive
) && formats
.contains("text/uri-list", Qt::CaseInsensitive
))
1030 event
->acceptProposedAction();
1035 * File dropped onto window
1037 void MainWindow::dropEvent(QDropEvent
*event
)
1041 QStringList droppedFiles
;
1042 QList
<QUrl
> urls
= event
->mimeData()->urls();
1044 while(!urls
.isEmpty())
1046 QUrl currentUrl
= urls
.takeFirst();
1047 QFileInfo
file(currentUrl
.toLocalFile());
1054 qDebug("Dropped File: %s", file
.canonicalFilePath().toUtf8().constData());
1055 droppedFiles
<< file
.canonicalFilePath();
1060 qDebug("Dropped Folder: %s", file
.canonicalFilePath().toUtf8().constData());
1061 QList
<QFileInfo
> list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Files
| QDir::NoSymLinks
);
1062 if(list
.count() > 0)
1064 for(int j
= 0; j
< list
.count(); j
++)
1066 droppedFiles
<< list
.at(j
).canonicalFilePath();
1071 list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
);
1072 for(int j
= 0; j
< list
.count(); j
++)
1074 qDebug("Descending to Folder: %s", list
.at(j
).canonicalFilePath().toUtf8().constData());
1075 urls
.prepend(QUrl::fromLocalFile(list
.at(j
).canonicalFilePath()));
1081 if(!droppedFiles
.isEmpty())
1083 addFilesDelayed(droppedFiles
, true);
1088 * Window tries to close
1090 void MainWindow::closeEvent(QCloseEvent
*event
)
1092 if(m_banner
->isVisible() || m_delayedFileTimer
->isActive())
1094 MessageBeep(MB_ICONEXCLAMATION
);
1105 * Window was resized
1107 void MainWindow::resizeEvent(QResizeEvent
*event
)
1109 if(event
) QMainWindow::resizeEvent(event
);
1110 m_dropNoteLabel
->setGeometry(0, 0, ui
->sourceFileView
->width(), ui
->sourceFileView
->height());
1112 if(QWidget
*port
= ui
->outputFolderView
->viewport())
1114 m_outputFolderNoteBox
->setGeometry(16, (port
->height() - 64) / 2, port
->width() - 32, 64);
1119 * Key press event filter
1121 void MainWindow::keyPressEvent(QKeyEvent
*e
)
1123 if(e
->key() == Qt::Key_Delete
)
1125 if(ui
->sourceFileView
->isVisible())
1127 QTimer::singleShot(0, this, SLOT(removeFileButtonClicked()));
1132 if(e
->modifiers().testFlag(Qt::ControlModifier
) && (e
->key() == Qt::Key_F5
))
1134 initializeTranslation();
1135 MessageBeep(MB_ICONINFORMATION
);
1139 if(e
->key() == Qt::Key_F5
)
1141 if(ui
->outputFolderView
->isVisible())
1143 QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
1148 QMainWindow::keyPressEvent(e
);
1154 bool MainWindow::eventFilter(QObject
*obj
, QEvent
*event
)
1156 if(obj
== m_fileSystemModel
)
1158 if(QApplication::overrideCursor() == NULL
)
1160 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
1161 QTimer::singleShot(250, this, SLOT(restoreCursor()));
1165 return QMainWindow::eventFilter(obj
, event
);
1168 bool MainWindow::event(QEvent
*e
)
1172 case lamexp_event_queryendsession
:
1173 qWarning("System is shutting down, main window prepares to close...");
1174 if(m_banner
->isVisible()) m_banner
->close();
1175 if(m_delayedFileTimer
->isActive()) m_delayedFileTimer
->stop();
1177 case lamexp_event_endsession
:
1178 qWarning("System is shutting down, main window will close now...");
1183 QApplication::processEvents(QEventLoop::WaitForMoreEvents
& QEventLoop::ExcludeUserInputEvents
);
1186 m_fileListModel
->clearFiles();
1188 case QEvent::MouseButtonPress
:
1189 if(ui
->outputFolderEdit
->isVisible())
1191 QTimer::singleShot(0, this, SLOT(outputFolderEditFinished()));
1194 return QMainWindow::event(e
);
1198 bool MainWindow::winEvent(MSG
*message
, long *result
)
1200 if((message
->message
== WM_SYSCOMMAND
) && ((message
->wParam
& 0xFFF0) == IDM_ABOUTBOX
))
1202 QTimer::singleShot(0, ui
->buttonAbout
, SLOT(click()));
1206 return WinSevenTaskbar::handleWinEvent(message
, result
);
1209 ////////////////////////////////////////////////////////////
1211 ////////////////////////////////////////////////////////////
1213 // =========================================================
1214 // Show window slots
1215 // =========================================================
1220 void MainWindow::windowShown(void)
1222 const QStringList
&arguments
= lamexp_arguments(); //QApplication::arguments();
1225 bool firstRun
= false;
1226 for(int i
= 0; i
< arguments
.count(); i
++)
1228 /*QMessageBox::information(this, QString::number(i), arguments[i]);*/
1229 if(!arguments
[i
].compare("--first-run", Qt::CaseInsensitive
)) firstRun
= true;
1233 if((m_settings
->licenseAccepted() <= 0) || firstRun
)
1235 int iAccepted
= m_settings
->licenseAccepted();
1237 if((iAccepted
== 0) || firstRun
)
1239 AboutDialog
*about
= new AboutDialog(m_settings
, this, true);
1240 iAccepted
= about
->exec();
1241 if(iAccepted
<= 0) iAccepted
= -2;
1242 LAMEXP_DELETE(about
);
1247 m_settings
->licenseAccepted(++iAccepted
);
1248 m_settings
->syncNow();
1249 QApplication::processEvents();
1250 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1251 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
1252 QFileInfo uninstallerInfo
= QFileInfo(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()));
1253 if(uninstallerInfo
.exists())
1255 QString uninstallerDir
= uninstallerInfo
.canonicalPath();
1256 QString uninstallerPath
= uninstallerInfo
.canonicalFilePath();
1257 for(int i
= 0; i
< 3; i
++)
1259 HINSTANCE res
= ShellExecuteW(reinterpret_cast<HWND
>(this->winId()), L
"open", QWCHAR(QDir::toNativeSeparators(uninstallerPath
)), L
"/Force", QWCHAR(QDir::toNativeSeparators(uninstallerDir
)), SW_SHOWNORMAL
);
1260 if(reinterpret_cast<int>(res
) > 32) break;
1263 QApplication::quit();
1267 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WOOHOO
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1268 m_settings
->licenseAccepted(1);
1269 m_settings
->syncNow();
1270 if(lamexp_version_demo()) showAnnounceBox();
1273 //Check for expiration
1274 if(lamexp_version_demo())
1276 if(QDate::currentDate() >= lamexp_version_expires())
1278 qWarning("Binary has expired !!!");
1279 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1280 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)
1284 QApplication::quit();
1289 //Slow startup indicator
1290 if(m_settings
->slowStartup() && m_settings
->antivirNotificationsEnabled())
1293 message
+= NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
1294 message
+= NOBR(tr("Please refer to the %1 document for details and solutions!")).arg("<a href=\"http://lamexp.sourceforge.net/doc/FAQ.html#df406578\">F.A.Q.</a>").append("<br>");
1295 if(QMessageBox::warning(this, tr("Slow Startup"), message
, tr("Discard"), tr("Don't Show Again")) == 1)
1297 m_settings
->antivirNotificationsEnabled(false);
1298 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
1303 if(QDate::currentDate() >= lamexp_version_date().addYears(1))
1305 qWarning("Binary is more than a year old, time to update!");
1306 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"));
1310 if(checkForUpdates())
1312 QApplication::quit();
1317 QApplication::quit();
1320 QEventLoop loop
; QTimer::singleShot(7000, &loop
, SLOT(quit()));
1321 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WAITING
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_ASYNC
);
1322 m_banner
->show(tr("Skipping update check this time, please be patient..."), &loop
);
1326 else if(m_settings
->autoUpdateEnabled())
1328 QDate lastUpdateCheck
= QDate::fromString(m_settings
->autoUpdateLastCheck(), Qt::ISODate
);
1329 if(!firstRun
&& (!lastUpdateCheck
.isValid() || QDate::currentDate() >= lastUpdateCheck
.addDays(14)))
1331 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)
1333 if(checkForUpdates())
1335 QApplication::quit();
1342 //Check for AAC support
1343 if(m_neroEncoderAvailable
)
1345 if(m_settings
->neroAacNotificationsEnabled())
1347 if(lamexp_tool_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1349 QString messageText
;
1350 messageText
+= NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1351 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>");
1352 messageText
+= NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1353 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br><br>";
1354 messageText
+= NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
1355 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText
);
1361 if(m_settings
->neroAacNotificationsEnabled() && (!(m_fhgEncoderAvailable
|| m_qaacEncoderAvailable
)))
1363 QString appPath
= QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1364 if(appPath
.isEmpty()) appPath
= QCoreApplication::applicationDirPath();
1365 QString messageText
;
1366 messageText
+= NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1367 messageText
+= NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1368 messageText
+= NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1369 messageText
+= QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath
)));
1370 messageText
+= NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1371 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br>";
1372 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText
, tr("Discard"), tr("Don't Show Again")) == 1)
1374 m_settings
->neroAacNotificationsEnabled(false);
1375 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1380 //Add files from the command-line
1381 for(int i
= 0; i
< arguments
.count() - 1; i
++)
1383 QStringList addedFiles
;
1384 if(!arguments
[i
].compare("--add", Qt::CaseInsensitive
))
1386 QFileInfo
currentFile(arguments
[++i
].trimmed());
1387 qDebug("Adding file from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1388 addedFiles
.append(currentFile
.absoluteFilePath());
1390 if(!addedFiles
.isEmpty())
1392 addFilesDelayed(addedFiles
);
1396 //Add folders from the command-line
1397 for(int i
= 0; i
< arguments
.count() - 1; i
++)
1399 if(!arguments
[i
].compare("--add-folder", Qt::CaseInsensitive
))
1401 QFileInfo
currentFile(arguments
[++i
].trimmed());
1402 qDebug("Adding folder from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1403 addFolder(currentFile
.absoluteFilePath(), false, true);
1405 if(!arguments
[i
].compare("--add-recursive", Qt::CaseInsensitive
))
1407 QFileInfo
currentFile(arguments
[++i
].trimmed());
1408 qDebug("Adding folder recursively from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1409 addFolder(currentFile
.absoluteFilePath(), true, true);
1413 //Enable shell integration
1414 if(m_settings
->shellIntegrationEnabled())
1416 ShellIntegration::install();
1419 //Make DropBox visible
1420 if(m_settings
->dropBoxWidgetEnabled())
1422 m_dropBox
->setVisible(true);
1429 void MainWindow::showAnnounceBox(void)
1431 const unsigned int timeout
= 8U;
1433 const QString announceText
= QString("%1<br><br>%2<br><nobr><tt>%3</tt></nobr><br>").arg
1435 NOBR("We are still looking for LameXP translators!"),
1436 NOBR("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:"),
1437 LINK("http://lamexp.sourceforge.net/doc/Translate.html")
1440 QMessageBox
*announceBox
= new QMessageBox(QMessageBox::Warning
, "We want you!", announceText
, QMessageBox::NoButton
, this);
1441 announceBox
->setWindowFlags(Qt::Window
| Qt::WindowTitleHint
| Qt::CustomizeWindowHint
);
1442 announceBox
->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1444 QTimer
*timers
[timeout
+1];
1445 QPushButton
*buttons
[timeout
+1];
1447 for(unsigned int i
= 0; i
<= timeout
; i
++)
1449 QString text
= (i
> 0) ? QString("%1 (%2)").arg(tr("Discard"), QString::number(i
)) : tr("Discard");
1450 buttons
[i
] = announceBox
->addButton(text
, (i
> 0) ? QMessageBox::NoRole
: QMessageBox::AcceptRole
);
1453 for(unsigned int i
= 0; i
<= timeout
; i
++)
1455 buttons
[i
]->setEnabled(i
== 0);
1456 buttons
[i
]->setVisible(i
== timeout
);
1459 for(unsigned int i
= 0; i
< timeout
; i
++)
1461 timers
[i
] = new QTimer(this);
1462 timers
[i
]->setSingleShot(true);
1463 timers
[i
]->setInterval(1000);
1464 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
+1], SLOT(hide()));
1465 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
], SLOT(show()));
1468 connect(timers
[i
], SIGNAL(timeout()), timers
[i
-1], SLOT(start()));
1472 timers
[timeout
-1]->start();
1473 announceBox
->exec();
1475 for(unsigned int i
= 0; i
< timeout
; i
++)
1478 LAMEXP_DELETE(timers
[i
]);
1481 LAMEXP_DELETE(announceBox
);
1484 // =========================================================
1485 // Main button solots
1486 // =========================================================
1491 void MainWindow::encodeButtonClicked(void)
1493 static const unsigned __int64 oneGigabyte
= 1073741824ui
64;
1494 static const unsigned __int64 minimumFreeDiskspaceMultiplier
= 2ui
64;
1495 static const char *writeTestBuffer
= "LAMEXP_WRITE_TEST";
1499 if(m_fileListModel
->rowCount() < 1)
1501 QMessageBox::warning(this, tr("LameXP"), NOBR(tr("You must add at least one file to the list before proceeding!")));
1502 ui
->tabWidget
->setCurrentIndex(0);
1506 QString tempFolder
= m_settings
->customTempPathEnabled() ? m_settings
->customTempPath() : lamexp_temp_folder2();
1507 if(!QFileInfo(tempFolder
).exists() || !QFileInfo(tempFolder
).isDir())
1509 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)
1511 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, m_settings
->customTempPathEnabledDefault());
1517 unsigned __int64 currentFreeDiskspace
= lamexp_free_diskspace(tempFolder
, &ok
);
1519 if(ok
&& (currentFreeDiskspace
< (oneGigabyte
* minimumFreeDiskspaceMultiplier
)))
1521 QStringList tempFolderParts
= tempFolder
.split("/", QString::SkipEmptyParts
, Qt::CaseInsensitive
);
1522 tempFolderParts
.takeLast();
1523 if(m_settings
->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1524 QString lowDiskspaceMsg
= QString("%1<br>%2<br><br>%3<br>%4<br>").arg
1526 NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier
))),
1527 NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")),
1528 NOBR(tr("Your TEMP folder is located at:")),
1529 QString("<nobr><tt>%1</tt></nobr>").arg(FSLINK(tempFolderParts
.join("\\")))
1531 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg
, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1534 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(lamexp_known_folder(lamexp_folder_systemfolder
)), QStringList() << "/D" << tempFolderParts
.first());
1539 QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!")));
1544 switch(m_settings
->compressionEncoder())
1546 case SettingsModel::MP3Encoder
:
1547 case SettingsModel::VorbisEncoder
:
1548 case SettingsModel::AACEncoder
:
1549 case SettingsModel::AC3Encoder
:
1550 case SettingsModel::FLACEncoder
:
1551 case SettingsModel::OpusEncoder
:
1552 case SettingsModel::DCAEncoder
:
1553 case SettingsModel::PCMEncoder
:
1556 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1557 ui
->tabWidget
->setCurrentIndex(3);
1561 if(!m_settings
->outputToSourceDir())
1563 QFile
writeTest(QString("%1/~%2.txt").arg(m_settings
->outputDir(), lamexp_rand_str()));
1564 if(!(writeTest
.open(QIODevice::ReadWrite
) && (writeTest
.write(writeTestBuffer
) == strlen(writeTestBuffer
))))
1566 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!")));
1567 ui
->tabWidget
->setCurrentIndex(1);
1584 void MainWindow::aboutButtonClicked(void)
1590 AboutDialog
*aboutBox
= new AboutDialog(m_settings
, this);
1592 LAMEXP_DELETE(aboutBox
);
1599 void MainWindow::closeButtonClicked(void)
1605 // =========================================================
1607 // =========================================================
1612 void MainWindow::tabPageChanged(int idx
)
1616 QList
<QAction
*> actions
= m_tabActionGroup
->actions();
1617 for(int i
= 0; i
< actions
.count(); i
++)
1620 int actionIndex
= actions
.at(i
)->data().toInt(&ok
);
1621 if(ok
&& actionIndex
== idx
)
1623 actions
.at(i
)->setChecked(true);
1627 int initialWidth
= this->width();
1628 int maximumWidth
= QApplication::desktop()->availableGeometry().width();
1630 //Make sure all tab headers are fully visible
1631 if(this->isVisible())
1633 int delta
= ui
->tabWidget
->sizeHint().width() - ui
->tabWidget
->width();
1636 this->resize(qMin(this->width() + delta
, maximumWidth
), this->height());
1640 //Tab specific operations
1641 if(idx
== ui
->tabWidget
->indexOf(ui
->tabOptions
) && ui
->scrollArea
->widget() && this->isVisible())
1643 ui
->scrollArea
->widget()->updateGeometry();
1644 ui
->scrollArea
->viewport()->updateGeometry();
1645 qApp
->processEvents();
1646 int delta
= ui
->scrollArea
->widget()->width() - ui
->scrollArea
->viewport()->width();
1649 this->resize(qMin(this->width() + delta
, maximumWidth
), this->height());
1652 else if(idx
== ui
->tabWidget
->indexOf(ui
->tabSourceFiles
))
1654 m_dropNoteLabel
->setGeometry(0, 0, ui
->sourceFileView
->width(), ui
->sourceFileView
->height());
1656 else if(idx
== ui
->tabWidget
->indexOf(ui
->tabOutputDir
))
1658 if(!m_fileSystemModel
)
1660 QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
1664 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
1668 //Center window around previous position
1669 if(initialWidth
< this->width())
1671 QPoint prevPos
= this->pos();
1672 int delta
= (this->width() - initialWidth
) >> 2;
1673 move(prevPos
.x() - delta
, prevPos
.y());
1678 * Tab action triggered
1680 void MainWindow::tabActionActivated(QAction
*action
)
1682 if(action
&& action
->data().isValid())
1685 int index
= action
->data().toInt(&ok
);
1688 ui
->tabWidget
->setCurrentIndex(index
);
1693 // =========================================================
1695 // =========================================================
1698 * Style action triggered
1700 void MainWindow::styleActionActivated(QAction
*action
)
1702 //Change style setting
1703 if(action
&& action
->data().isValid())
1706 int actionIndex
= action
->data().toInt(&ok
);
1709 m_settings
->interfaceStyle(actionIndex
);
1713 //Set up the new style
1714 switch(m_settings
->interfaceStyle())
1717 if(ui
->actionStyleCleanlooks
->isEnabled())
1719 ui
->actionStyleCleanlooks
->setChecked(true);
1720 QApplication::setStyle(new QCleanlooksStyle());
1724 if(ui
->actionStyleWindowsVista
->isEnabled())
1726 ui
->actionStyleWindowsVista
->setChecked(true);
1727 QApplication::setStyle(new QWindowsVistaStyle());
1731 if(ui
->actionStyleWindowsXP
->isEnabled())
1733 ui
->actionStyleWindowsXP
->setChecked(true);
1734 QApplication::setStyle(new QWindowsXPStyle());
1738 if(ui
->actionStyleWindowsClassic
->isEnabled())
1740 ui
->actionStyleWindowsClassic
->setChecked(true);
1741 QApplication::setStyle(new QWindowsStyle());
1745 ui
->actionStylePlastique
->setChecked(true);
1746 QApplication::setStyle(new QPlastiqueStyle());
1750 //Force re-translate after style change
1751 if(QEvent
*e
= new QEvent(QEvent::LanguageChange
))
1758 const type_info
&styleType
= typeid(*qApp
->style());
1759 const bool bTransparent
= ((typeid(QWindowsVistaStyle
) == styleType
) || (typeid(QWindowsXPStyle
) == styleType
));
1760 MAKE_TRANSPARENT(ui
->scrollArea
, bTransparent
);
1764 * Language action triggered
1766 void MainWindow::languageActionActivated(QAction
*action
)
1768 if(action
->data().type() == QVariant::String
)
1770 QString langId
= action
->data().toString();
1772 if(lamexp_install_translator(langId
))
1774 action
->setChecked(true);
1775 ui
->actionLoadTranslationFromFile
->setChecked(false);
1776 m_settings
->currentLanguage(langId
);
1777 m_settings
->currentLanguageFile(QString());
1783 * Load language from file action triggered
1785 void MainWindow::languageFromFileActionActivated(bool checked
)
1787 QFileDialog
dialog(this, tr("Load Translation"));
1788 dialog
.setFileMode(QFileDialog::ExistingFile
);
1789 dialog
.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
1793 QStringList selectedFiles
= dialog
.selectedFiles();
1794 const QString qmFile
= QFileInfo(selectedFiles
.first()).canonicalFilePath();
1795 if(lamexp_install_translator_from_file(qmFile
))
1797 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
1798 while(!actions
.isEmpty())
1800 actions
.takeFirst()->setChecked(false);
1802 ui
->actionLoadTranslationFromFile
->setChecked(true);
1803 m_settings
->currentLanguageFile(qmFile
);
1807 languageActionActivated(m_languageActionGroup
->actions().first());
1812 // =========================================================
1814 // =========================================================
1817 * Disable update reminder action
1819 void MainWindow::disableUpdateReminderActionTriggered(bool checked
)
1823 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))
1825 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!"))));
1826 m_settings
->autoUpdateEnabled(false);
1830 m_settings
->autoUpdateEnabled(true);
1835 QMessageBox::information(this, tr("Update Reminder"), NOBR(tr("The update reminder has been re-enabled.")));
1836 m_settings
->autoUpdateEnabled(true);
1839 ui
->actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
1843 * Disable sound effects action
1845 void MainWindow::disableSoundsActionTriggered(bool checked
)
1849 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))
1851 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("All sound effects have been disabled.")));
1852 m_settings
->soundsEnabled(false);
1856 m_settings
->soundsEnabled(true);
1861 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("The sound effects have been re-enabled.")));
1862 m_settings
->soundsEnabled(true);
1865 ui
->actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
1869 * Disable Nero AAC encoder action
1871 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked
)
1875 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))
1877 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("All Nero AAC Encoder notifications have been disabled.")));
1878 m_settings
->neroAacNotificationsEnabled(false);
1882 m_settings
->neroAacNotificationsEnabled(true);
1887 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("The Nero AAC Encoder notifications have been re-enabled.")));
1888 m_settings
->neroAacNotificationsEnabled(true);
1891 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1895 * Disable slow startup action
1897 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked
)
1901 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))
1903 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been disabled.")));
1904 m_settings
->antivirNotificationsEnabled(false);
1908 m_settings
->antivirNotificationsEnabled(true);
1913 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been re-enabled.")));
1914 m_settings
->antivirNotificationsEnabled(true);
1917 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
1921 * Import a Cue Sheet file
1923 void MainWindow::importCueSheetActionTriggered(bool checked
)
1932 QString selectedCueFile
;
1934 if(USE_NATIVE_FILE_DIALOG
)
1936 selectedCueFile
= QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings
->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1940 QFileDialog
dialog(this, tr("Open Cue Sheet"));
1941 dialog
.setFileMode(QFileDialog::ExistingFile
);
1942 dialog
.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1943 dialog
.setDirectory(m_settings
->mostRecentInputPath());
1946 selectedCueFile
= dialog
.selectedFiles().first();
1950 if(!selectedCueFile
.isEmpty())
1952 m_settings
->mostRecentInputPath(QFileInfo(selectedCueFile
).canonicalPath());
1953 CueImportDialog
*cueImporter
= new CueImportDialog(this, m_fileListModel
, selectedCueFile
);
1954 result
= cueImporter
->exec();
1955 LAMEXP_DELETE(cueImporter
);
1958 if(result
!= (-1)) break;
1964 * Show the "drop box" widget
1966 void MainWindow::showDropBoxWidgetActionTriggered(bool checked
)
1968 m_settings
->dropBoxWidgetEnabled(true);
1970 if(!m_dropBox
->isVisible())
1975 lamexp_blink_window(m_dropBox
);
1979 * Check for beta (pre-release) updates
1981 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked
)
1983 bool checkUpdatesNow
= false;
1987 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))
1989 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")))
1991 checkUpdatesNow
= true;
1993 m_settings
->autoUpdateCheckBeta(true);
1997 m_settings
->autoUpdateCheckBeta(false);
2002 QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on.")));
2003 m_settings
->autoUpdateCheckBeta(false);
2006 ui
->actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta());
2010 if(checkForUpdates())
2012 QApplication::quit();
2018 * Hibernate computer action
2020 void MainWindow::hibernateComputerActionTriggered(bool checked
)
2024 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))
2026 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will hibernate the computer on shutdown from now on.")));
2027 m_settings
->hibernateComputer(true);
2031 m_settings
->hibernateComputer(false);
2036 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will <i>not</i> hibernate the computer on shutdown from now on.")));
2037 m_settings
->hibernateComputer(false);
2040 ui
->actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
2044 * Disable shell integration action
2046 void MainWindow::disableShellIntegrationActionTriggered(bool checked
)
2050 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))
2052 ShellIntegration::remove();
2053 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been disabled.")));
2054 m_settings
->shellIntegrationEnabled(false);
2058 m_settings
->shellIntegrationEnabled(true);
2063 ShellIntegration::install();
2064 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been re-enabled.")));
2065 m_settings
->shellIntegrationEnabled(true);
2068 ui
->actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
2070 if(lamexp_portable_mode() && ui
->actionDisableShellIntegration
->isChecked())
2072 ui
->actionDisableShellIntegration
->setEnabled(false);
2076 // =========================================================
2078 // =========================================================
2081 * Visit homepage action
2083 void MainWindow::visitHomepageActionActivated(void)
2085 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2087 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
2089 QDesktopServices::openUrl(QUrl(action
->data().toString()));
2097 void MainWindow::documentActionActivated(void)
2099 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2101 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
2103 QFileInfo
document(action
->data().toString());
2104 QFileInfo
resource(QString(":/doc/%1.html").arg(document
.baseName()));
2105 if(document
.exists() && document
.isFile() && (document
.size() == resource
.size()))
2107 QDesktopServices::openUrl(QUrl::fromLocalFile(document
.canonicalFilePath()));
2111 QFile
source(resource
.filePath());
2112 QFile
output(QString("%1/%2.%3.html").arg(lamexp_temp_folder2(), document
.baseName(), lamexp_rand_str().left(8)));
2113 if(source
.open(QIODevice::ReadOnly
) && output
.open(QIODevice::ReadWrite
))
2115 output
.write(source
.readAll());
2116 action
->setData(output
.fileName());
2119 QDesktopServices::openUrl(QUrl::fromLocalFile(output
.fileName()));
2127 * Check for updates action
2129 void MainWindow::checkUpdatesActionActivated(void)
2136 bFlag
= checkForUpdates();
2141 QApplication::quit();
2145 // =========================================================
2146 // Source file slots
2147 // =========================================================
2150 * Add file(s) button
2152 void MainWindow::addFilesButtonClicked(void)
2158 if(USE_NATIVE_FILE_DIALOG
)
2160 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2161 QStringList selectedFiles
= QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings
->mostRecentInputPath(), fileTypeFilters
.join(";;"));
2162 if(!selectedFiles
.isEmpty())
2164 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2165 addFiles(selectedFiles
);
2170 QFileDialog
dialog(this, tr("Add file(s)"));
2171 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2172 dialog
.setFileMode(QFileDialog::ExistingFiles
);
2173 dialog
.setNameFilter(fileTypeFilters
.join(";;"));
2174 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2177 QStringList selectedFiles
= dialog
.selectedFiles();
2178 if(!selectedFiles
.isEmpty())
2180 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2181 addFiles(selectedFiles
);
2189 * Open folder action
2191 void MainWindow::openFolderActionActivated(void)
2194 QString selectedFolder
;
2196 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2200 if(USE_NATIVE_FILE_DIALOG
)
2202 selectedFolder
= QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings
->mostRecentInputPath());
2206 QFileDialog
dialog(this, tr("Add Folder"));
2207 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
2208 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2211 selectedFolder
= dialog
.selectedFiles().first();
2215 if(!selectedFolder
.isEmpty())
2217 m_settings
->mostRecentInputPath(QDir(selectedFolder
).canonicalPath());
2218 addFolder(selectedFolder
, action
->data().toBool());
2225 * Remove file button
2227 void MainWindow::removeFileButtonClicked(void)
2229 if(ui
->sourceFileView
->currentIndex().isValid())
2231 int iRow
= ui
->sourceFileView
->currentIndex().row();
2232 m_fileListModel
->removeFile(ui
->sourceFileView
->currentIndex());
2233 ui
->sourceFileView
->selectRow(iRow
< m_fileListModel
->rowCount() ? iRow
: m_fileListModel
->rowCount()-1);
2238 * Clear files button
2240 void MainWindow::clearFilesButtonClicked(void)
2242 m_fileListModel
->clearFiles();
2246 * Move file up button
2248 void MainWindow::fileUpButtonClicked(void)
2250 if(ui
->sourceFileView
->currentIndex().isValid())
2252 int iRow
= ui
->sourceFileView
->currentIndex().row() - 1;
2253 m_fileListModel
->moveFile(ui
->sourceFileView
->currentIndex(), -1);
2254 ui
->sourceFileView
->selectRow(iRow
>= 0 ? iRow
: 0);
2259 * Move file down button
2261 void MainWindow::fileDownButtonClicked(void)
2263 if(ui
->sourceFileView
->currentIndex().isValid())
2265 int iRow
= ui
->sourceFileView
->currentIndex().row() + 1;
2266 m_fileListModel
->moveFile(ui
->sourceFileView
->currentIndex(), 1);
2267 ui
->sourceFileView
->selectRow(iRow
< m_fileListModel
->rowCount() ? iRow
: m_fileListModel
->rowCount()-1);
2272 * Show details button
2274 void MainWindow::showDetailsButtonClicked(void)
2279 MetaInfoDialog
*metaInfoDialog
= new MetaInfoDialog(this);
2280 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2282 while(index
.isValid())
2286 index
= m_fileListModel
->index(index
.row() + 1, index
.column());
2287 ui
->sourceFileView
->selectRow(index
.row());
2291 index
= m_fileListModel
->index(index
.row() - 1, index
.column());
2292 ui
->sourceFileView
->selectRow(index
.row());
2295 AudioFileModel
&file
= (*m_fileListModel
)[index
];
2298 iResult
= metaInfoDialog
->exec(file
, index
.row() > 0, index
.row() < m_fileListModel
->rowCount() - 1);
2301 if(iResult
== INT_MAX
)
2303 m_metaInfoModel
->assignInfoFrom(file
);
2304 ui
->tabWidget
->setCurrentIndex(ui
->tabWidget
->indexOf(ui
->tabMetaData
));
2311 LAMEXP_DELETE(metaInfoDialog
);
2312 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2313 sourceFilesScrollbarMoved(0);
2317 * Show context menu for source files
2319 void MainWindow::sourceFilesContextMenu(const QPoint
&pos
)
2321 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
2322 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
2326 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
2328 m_sourceFilesContextMenu
->popup(sender
->mapToGlobal(pos
));
2334 * Scrollbar of source files moved
2336 void MainWindow::sourceFilesScrollbarMoved(int)
2338 ui
->sourceFileView
->resizeColumnToContents(0);
2342 * Open selected file in external player
2344 void MainWindow::previewContextActionTriggered(void)
2346 const static char *appNames
[3] = {"smplayer_portable.exe", "smplayer.exe", "mplayer.exe"};
2347 const static wchar_t *registryKey
= L
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{DB9E4EAB-2717-499F-8D56-4CC8A644AB60}";
2349 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2350 if(!index
.isValid())
2355 QString mplayerPath
;
2356 HKEY registryKeyHandle
;
2358 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, registryKey
, 0, KEY_READ
, ®istryKeyHandle
) == ERROR_SUCCESS
)
2360 wchar_t Buffer
[4096];
2361 DWORD BuffSize
= sizeof(wchar_t*) * 4096;
2362 if(RegQueryValueExW(registryKeyHandle
, L
"InstallLocation", 0, 0, reinterpret_cast<BYTE
*>(Buffer
), &BuffSize
) == ERROR_SUCCESS
)
2364 mplayerPath
= QString::fromUtf16(reinterpret_cast<const unsigned short*>(Buffer
));
2368 if(!mplayerPath
.isEmpty())
2370 QDir
mplayerDir(mplayerPath
);
2371 if(mplayerDir
.exists())
2373 for(int i
= 0; i
< 3; i
++)
2375 if(mplayerDir
.exists(appNames
[i
]))
2377 QProcess::startDetached(mplayerDir
.absoluteFilePath(appNames
[i
]), QStringList() << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
2384 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel
->getFile(index
).filePath()));
2388 * Find selected file in explorer
2390 void MainWindow::findFileContextActionTriggered(void)
2392 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2395 QString systemRootPath
;
2397 QDir
systemRoot(lamexp_known_folder(lamexp_folder_systemfolder
));
2398 if(systemRoot
.exists() && systemRoot
.cdUp())
2400 systemRootPath
= systemRoot
.canonicalPath();
2403 if(!systemRootPath
.isEmpty())
2405 QFileInfo
explorer(QString("%1/explorer.exe").arg(systemRootPath
));
2406 if(explorer
.exists() && explorer
.isFile())
2408 QProcess::execute(explorer
.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
2414 qWarning("SystemRoot directory could not be detected!");
2420 * Add all pending files
2422 void MainWindow::handleDelayedFiles(void)
2424 m_delayedFileTimer
->stop();
2426 if(m_delayedFileList
->isEmpty())
2431 if(m_banner
->isVisible())
2433 m_delayedFileTimer
->start(5000);
2437 QStringList selectedFiles
;
2438 ui
->tabWidget
->setCurrentIndex(0);
2440 while(!m_delayedFileList
->isEmpty())
2442 QFileInfo currentFile
= QFileInfo(m_delayedFileList
->takeFirst());
2443 if(!currentFile
.exists() || !currentFile
.isFile())
2447 selectedFiles
<< currentFile
.canonicalFilePath();
2450 addFiles(selectedFiles
);
2454 * Export Meta tags to CSV file
2456 void MainWindow::exportCsvContextActionTriggered(void)
2460 QString selectedCsvFile
;
2462 if(USE_NATIVE_FILE_DIALOG
)
2464 selectedCsvFile
= QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2468 QFileDialog
dialog(this, tr("Save CSV file"));
2469 dialog
.setFileMode(QFileDialog::AnyFile
);
2470 dialog
.setAcceptMode(QFileDialog::AcceptSave
);
2471 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2472 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2475 selectedCsvFile
= dialog
.selectedFiles().first();
2479 if(!selectedCsvFile
.isEmpty())
2481 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2482 switch(m_fileListModel
->exportToCsv(selectedCsvFile
))
2484 case FileListModel::CsvError_NoTags
:
2485 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, there are no meta tags that can be exported!")));
2487 case FileListModel::CsvError_FileOpen
:
2488 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to open CSV file for writing!")));
2490 case FileListModel::CsvError_FileWrite
:
2491 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to write to the CSV file!")));
2493 case FileListModel::CsvError_OK
:
2494 QMessageBox::information(this, tr("CSV Export"), NOBR(tr("The CSV files was created successfully!")));
2497 qWarning("exportToCsv: Unknown return code!");
2505 * Import Meta tags from CSV file
2507 void MainWindow::importCsvContextActionTriggered(void)
2511 QString selectedCsvFile
;
2513 if(USE_NATIVE_FILE_DIALOG
)
2515 selectedCsvFile
= QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2519 QFileDialog
dialog(this, tr("Open CSV file"));
2520 dialog
.setFileMode(QFileDialog::ExistingFile
);
2521 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2522 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2525 selectedCsvFile
= dialog
.selectedFiles().first();
2529 if(!selectedCsvFile
.isEmpty())
2531 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2532 switch(m_fileListModel
->importFromCsv(this, selectedCsvFile
))
2534 case FileListModel::CsvError_FileOpen
:
2535 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to open CSV file for reading!")));
2537 case FileListModel::CsvError_FileRead
:
2538 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to read from the CSV file!")));
2540 case FileListModel::CsvError_NoTags
:
2541 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, the CSV file does not contain any known fields!")));
2543 case FileListModel::CsvError_Incomplete
:
2544 QMessageBox::warning(this, tr("CSV Import"), NOBR(tr("CSV file is incomplete. Not all files were updated!")));
2546 case FileListModel::CsvError_OK
:
2547 QMessageBox::information(this, tr("CSV Import"), NOBR(tr("The CSV files was imported successfully!")));
2549 case FileListModel::CsvError_Aborted
:
2550 /* User aborted, ignore! */
2553 qWarning("exportToCsv: Unknown return code!");
2560 * Show or hide Drag'n'Drop notice after model reset
2562 void MainWindow::sourceModelChanged(void)
2564 m_dropNoteLabel
->setVisible(m_fileListModel
->rowCount() <= 0);
2567 // =========================================================
2568 // Output folder slots
2569 // =========================================================
2572 * Output folder changed (mouse clicked)
2574 void MainWindow::outputFolderViewClicked(const QModelIndex
&index
)
2576 if(index
.isValid() && (ui
->outputFolderView
->currentIndex() != index
))
2578 ui
->outputFolderView
->setCurrentIndex(index
);
2581 if(m_fileSystemModel
&& index
.isValid())
2583 QString selectedDir
= m_fileSystemModel
->filePath(index
);
2584 if(selectedDir
.length() < 3) selectedDir
.append(QDir::separator());
2585 ui
->outputFolderLabel
->setText(QDir::toNativeSeparators(selectedDir
));
2586 ui
->outputFolderLabel
->setToolTip(ui
->outputFolderLabel
->text());
2587 m_settings
->outputDir(selectedDir
);
2591 ui
->outputFolderLabel
->setText(QDir::toNativeSeparators(m_settings
->outputDir()));
2592 ui
->outputFolderLabel
->setToolTip(ui
->outputFolderLabel
->text());
2597 * Output folder changed (mouse moved)
2599 void MainWindow::outputFolderViewMoved(const QModelIndex
&index
)
2601 if(QApplication::mouseButtons() & Qt::LeftButton
)
2603 outputFolderViewClicked(index
);
2608 * Goto desktop button
2610 void MainWindow::gotoDesktopButtonClicked(void)
2612 if(!m_fileSystemModel
)
2614 qWarning("File system model not initialized yet!");
2618 QString desktopPath
= QDesktopServices::storageLocation(QDesktopServices::DesktopLocation
);
2620 if(!desktopPath
.isEmpty() && QDir(desktopPath
).exists())
2622 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(desktopPath
));
2623 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2624 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2628 ui
->buttonGotoDesktop
->setEnabled(false);
2633 * Goto home folder button
2635 void MainWindow::gotoHomeFolderButtonClicked(void)
2637 if(!m_fileSystemModel
)
2639 qWarning("File system model not initialized yet!");
2643 QString homePath
= QDesktopServices::storageLocation(QDesktopServices::HomeLocation
);
2645 if(!homePath
.isEmpty() && QDir(homePath
).exists())
2647 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(homePath
));
2648 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2649 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2653 ui
->buttonGotoHome
->setEnabled(false);
2658 * Goto music folder button
2660 void MainWindow::gotoMusicFolderButtonClicked(void)
2662 if(!m_fileSystemModel
)
2664 qWarning("File system model not initialized yet!");
2668 QString musicPath
= QDesktopServices::storageLocation(QDesktopServices::MusicLocation
);
2670 if(!musicPath
.isEmpty() && QDir(musicPath
).exists())
2672 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(musicPath
));
2673 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2674 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2678 ui
->buttonGotoMusic
->setEnabled(false);
2683 * Goto music favorite output folder
2685 void MainWindow::gotoFavoriteFolder(void)
2687 if(!m_fileSystemModel
)
2689 qWarning("File system model not initialized yet!");
2693 QAction
*item
= dynamic_cast<QAction
*>(QObject::sender());
2697 QDir
path(item
->data().toString());
2700 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(path
.canonicalPath()));
2701 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2702 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2706 MessageBeep(MB_ICONERROR
);
2707 m_outputFolderFavoritesMenu
->removeAction(item
);
2708 item
->deleteLater();
2714 * Make folder button
2716 void MainWindow::makeFolderButtonClicked(void)
2720 if(!m_fileSystemModel
)
2722 qWarning("File system model not initialized yet!");
2726 QDir
basePath(m_fileSystemModel
->fileInfo(ui
->outputFolderView
->currentIndex()).absoluteFilePath());
2727 QString suggestedName
= tr("New Folder");
2729 if(!m_metaData
->fileArtist().isEmpty() && !m_metaData
->fileAlbum().isEmpty())
2731 suggestedName
= QString("%1 - %2").arg(m_metaData
->fileArtist(), m_metaData
->fileAlbum());
2733 else if(!m_metaData
->fileArtist().isEmpty())
2735 suggestedName
= m_metaData
->fileArtist();
2737 else if(!m_metaData
->fileAlbum().isEmpty())
2739 suggestedName
= m_metaData
->fileAlbum();
2743 for(int i
= 0; i
< m_fileListModel
->rowCount(); i
++)
2745 AudioFileModel audioFile
= m_fileListModel
->getFile(m_fileListModel
->index(i
, 0));
2746 if(!audioFile
.fileAlbum().isEmpty() || !audioFile
.fileArtist().isEmpty())
2748 if(!audioFile
.fileArtist().isEmpty() && !audioFile
.fileAlbum().isEmpty())
2750 suggestedName
= QString("%1 - %2").arg(audioFile
.fileArtist(), audioFile
.fileAlbum());
2752 else if(!audioFile
.fileArtist().isEmpty())
2754 suggestedName
= audioFile
.fileArtist();
2756 else if(!audioFile
.fileAlbum().isEmpty())
2758 suggestedName
= audioFile
.fileAlbum();
2765 suggestedName
= lamexp_clean_filename(suggestedName
);
2769 bool bApplied
= false;
2770 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();
2774 folderName
= lamexp_clean_filepath(folderName
.simplified());
2776 if(folderName
.isEmpty())
2778 MessageBeep(MB_ICONERROR
);
2783 QString newFolder
= folderName
;
2785 while(basePath
.exists(newFolder
))
2787 newFolder
= QString(folderName
).append(QString().sprintf(" (%d)", ++i
));
2790 if(basePath
.mkpath(newFolder
))
2792 QDir createdDir
= basePath
;
2793 if(createdDir
.cd(newFolder
))
2795 QModelIndex newIndex
= m_fileSystemModel
->index(createdDir
.canonicalPath());
2796 ui
->outputFolderView
->setCurrentIndex(newIndex
);
2797 outputFolderViewClicked(newIndex
);
2798 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2803 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!")));
2811 * Output to source dir changed
2813 void MainWindow::saveToSourceFolderChanged(void)
2815 m_settings
->outputToSourceDir(ui
->saveToSourceFolderCheckBox
->isChecked());
2819 * Prepend relative source file path to output file name changed
2821 void MainWindow::prependRelativePathChanged(void)
2823 m_settings
->prependRelativeSourcePath(ui
->prependRelativePathCheckBox
->isChecked());
2827 * Show context menu for output folder
2829 void MainWindow::outputFolderContextMenu(const QPoint
&pos
)
2831 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
2832 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
2834 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
2836 m_outputFolderContextMenu
->popup(sender
->mapToGlobal(pos
));
2841 * Show selected folder in explorer
2843 void MainWindow::showFolderContextActionTriggered(void)
2845 if(!m_fileSystemModel
)
2847 qWarning("File system model not initialized yet!");
2851 QString path
= QDir::toNativeSeparators(m_fileSystemModel
->filePath(ui
->outputFolderView
->currentIndex()));
2852 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
2853 ShellExecuteW(reinterpret_cast<HWND
>(this->winId()), L
"explore", QWCHAR(path
), NULL
, NULL
, SW_SHOW
);
2857 * Refresh the directory outline
2859 void MainWindow::refreshFolderContextActionTriggered(void)
2861 //force re-initialization
2862 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
2866 * Go one directory up
2868 void MainWindow::goUpFolderContextActionTriggered(void)
2870 QModelIndex current
= ui
->outputFolderView
->currentIndex();
2871 if(current
.isValid())
2873 QModelIndex parent
= current
.parent();
2874 if(parent
.isValid())
2877 ui
->outputFolderView
->setCurrentIndex(parent
);
2878 outputFolderViewClicked(parent
);
2882 MessageBeep(MB_ICONWARNING
);
2884 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2889 * Add current folder to favorites
2891 void MainWindow::addFavoriteFolderActionTriggered(void)
2893 QString path
= m_fileSystemModel
->filePath(ui
->outputFolderView
->currentIndex());
2894 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
2896 if(!favorites
.contains(path
, Qt::CaseInsensitive
))
2898 favorites
.append(path
);
2899 while(favorites
.count() > 6) favorites
.removeFirst();
2903 MessageBeep(MB_ICONWARNING
);
2906 m_settings
->favoriteOutputFolders(favorites
.join("|"));
2911 * Output folder edit finished
2913 void MainWindow::outputFolderEditFinished(void)
2915 if(ui
->outputFolderEdit
->isHidden())
2917 return; //Not currently in edit mode!
2922 QString text
= QDir::fromNativeSeparators(ui
->outputFolderEdit
->text().trimmed());
2923 while(text
.startsWith('"') || text
.startsWith('/')) text
= text
.right(text
.length() - 1).trimmed();
2924 while(text
.endsWith('"') || text
.endsWith('/')) text
= text
.left(text
.length() - 1).trimmed();
2926 static const char *str
= "?*<>|\"";
2927 for(size_t i
= 0; str
[i
]; i
++) text
.replace(str
[i
], "_");
2929 if(!((text
.length() >= 2) && text
.at(0).isLetter() && text
.at(1) == QChar(':')))
2931 text
= QString("%1/%2").arg(QDir::fromNativeSeparators(ui
->outputFolderLabel
->text()), text
);
2934 if(text
.length() == 2) text
+= "/"; /* "X:" => "X:/" */
2936 while(text
.length() > 2)
2938 QFileInfo
info(text
);
2939 if(info
.exists() && info
.isDir())
2941 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalFilePath()).absoluteFilePath());
2945 ui
->outputFolderView
->setCurrentIndex(index
);
2946 outputFolderViewClicked(index
);
2950 else if(info
.exists() && info
.isFile())
2952 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalPath()).absoluteFilePath());
2956 ui
->outputFolderView
->setCurrentIndex(index
);
2957 outputFolderViewClicked(index
);
2962 text
= text
.left(text
.length() - 1).trimmed();
2965 ui
->outputFolderEdit
->setVisible(false);
2966 ui
->outputFolderLabel
->setVisible(true);
2967 ui
->outputFolderView
->setEnabled(true);
2969 if(!ok
) MessageBeep(MB_ICONERROR
);
2970 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2974 * Initialize file system model
2976 void MainWindow::initOutputFolderModel(void)
2978 if(m_outputFolderNoteBox
->isHidden())
2980 m_outputFolderNoteBox
->show();
2981 m_outputFolderNoteBox
->repaint();
2982 m_outputFolderViewInitCounter
= 4;
2984 if(m_fileSystemModel
)
2986 SET_MODEL(ui
->outputFolderView
, NULL
);
2987 LAMEXP_DELETE(m_fileSystemModel
);
2988 ui
->outputFolderView
->repaint();
2991 if(m_fileSystemModel
= new QFileSystemModelEx())
2993 m_fileSystemModel
->installEventFilter(this);
2994 connect(m_fileSystemModel
, SIGNAL(directoryLoaded(QString
)), this, SLOT(outputFolderDirectoryLoaded(QString
)));
2995 connect(m_fileSystemModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(outputFolderRowsInserted(QModelIndex
,int,int)));
2997 SET_MODEL(ui
->outputFolderView
, m_fileSystemModel
);
2998 ui
->outputFolderView
->header()->setStretchLastSection(true);
2999 ui
->outputFolderView
->header()->hideSection(1);
3000 ui
->outputFolderView
->header()->hideSection(2);
3001 ui
->outputFolderView
->header()->hideSection(3);
3003 m_fileSystemModel
->setRootPath("");
3004 QModelIndex index
= m_fileSystemModel
->index(m_settings
->outputDir());
3005 if(index
.isValid()) ui
->outputFolderView
->setCurrentIndex(index
);
3006 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3009 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3010 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3015 * Initialize file system model (do NOT call this one directly!)
3017 void MainWindow::initOutputFolderModel_doAsync(void)
3019 if(m_outputFolderViewInitCounter
> 0)
3021 m_outputFolderViewInitCounter
--;
3022 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3026 QTimer::singleShot(125, m_outputFolderNoteBox
, SLOT(hide()));
3027 ui
->outputFolderView
->setFocus();
3032 * Center current folder in view
3034 void MainWindow::centerOutputFolderModel(void)
3036 if(ui
->outputFolderView
->isVisible())
3038 centerOutputFolderModel_doAsync();
3039 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel_doAsync()));
3044 * Center current folder in view (do NOT call this one directly!)
3046 void MainWindow::centerOutputFolderModel_doAsync(void)
3048 if(ui
->outputFolderView
->isVisible())
3050 m_outputFolderViewCentering
= true;
3051 const QModelIndex index
= ui
->outputFolderView
->currentIndex();
3052 ui
->outputFolderView
->scrollTo(index
, QAbstractItemView::PositionAtCenter
);
3053 ui
->outputFolderView
->setFocus();
3058 * File system model asynchronously loaded a dir
3060 void MainWindow::outputFolderDirectoryLoaded(const QString
&path
)
3062 if(m_outputFolderViewCentering
)
3064 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3069 * File system model inserted new items
3071 void MainWindow::outputFolderRowsInserted(const QModelIndex
&parent
, int start
, int end
)
3073 if(m_outputFolderViewCentering
)
3075 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3080 * Directory view item was expanded by user
3082 void MainWindow::outputFolderItemExpanded(const QModelIndex
&item
)
3084 //We need to stop centering as soon as the user has expanded an item manually!
3085 m_outputFolderViewCentering
= false;
3089 * View event for output folder control occurred
3091 void MainWindow::outputFolderViewEventOccurred(QWidget
*sender
, QEvent
*event
)
3093 switch(event
->type())
3097 case QEvent::KeyPress
:
3098 case QEvent::KeyRelease
:
3099 case QEvent::FocusIn
:
3100 case QEvent::FocusOut
:
3101 case QEvent::TouchEnd
:
3102 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3108 * Mouse event for output folder control occurred
3110 void MainWindow::outputFolderMouseEventOccurred(QWidget
*sender
, QEvent
*event
)
3112 QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
);
3113 QPoint pos
= (mouseEvent
) ? mouseEvent
->pos() : QPoint();
3115 if(sender
== ui
->outputFolderLabel
)
3117 switch(event
->type())
3119 case QEvent::MouseButtonPress
:
3120 if(mouseEvent
&& (mouseEvent
->button() == Qt::LeftButton
))
3122 QString path
= ui
->outputFolderLabel
->text();
3123 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
3124 ShellExecuteW(reinterpret_cast<HWND
>(this->winId()), L
"explore", QWCHAR(path
), NULL
, NULL
, SW_SHOW
);
3128 ui
->outputFolderLabel
->setForegroundRole(QPalette::Link
);
3131 ui
->outputFolderLabel
->setForegroundRole(QPalette::WindowText
);
3136 if((sender
== ui
->outputFoldersFovoritesLabel
) || (sender
== ui
->outputFoldersEditorLabel
) || (sender
== ui
->outputFoldersGoUpLabel
))
3138 const type_info
&styleType
= typeid(*qApp
->style());
3139 if((typeid(QPlastiqueStyle
) == styleType
) || (typeid(QWindowsStyle
) == styleType
))
3141 switch(event
->type())
3144 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Raised
: QFrame::Plain
);
3146 case QEvent::MouseButtonPress
:
3147 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Sunken
: QFrame::Plain
);
3149 case QEvent::MouseButtonRelease
:
3150 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Raised
: QFrame::Plain
);
3153 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Plain
: QFrame::Plain
);
3159 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(QFrame::Plain
);
3162 if((event
->type() == QEvent::MouseButtonRelease
) && ui
->outputFolderView
->isEnabled() && (mouseEvent
))
3164 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
)
3166 if(sender
== ui
->outputFoldersFovoritesLabel
)
3168 m_outputFolderFavoritesMenu
->popup(sender
->mapToGlobal(pos
));
3170 else if(sender
== ui
->outputFoldersEditorLabel
)
3172 ui
->outputFolderView
->setEnabled(false);
3173 ui
->outputFolderLabel
->setVisible(false);
3174 ui
->outputFolderEdit
->setVisible(true);
3175 ui
->outputFolderEdit
->setText(ui
->outputFolderLabel
->text());
3176 ui
->outputFolderEdit
->selectAll();
3177 ui
->outputFolderEdit
->setFocus();
3179 else if(sender
== ui
->outputFoldersGoUpLabel
)
3181 QTimer::singleShot(0, this, SLOT(goUpFolderContextActionTriggered()));
3185 throw "Oups, this is not supposed to happen!";
3192 // =========================================================
3193 // Metadata tab slots
3194 // =========================================================
3197 * Edit meta button clicked
3199 void MainWindow::editMetaButtonClicked(void)
3203 const QModelIndex index
= ui
->metaDataView
->currentIndex();
3207 m_metaInfoModel
->editItem(index
, this);
3209 if(index
.row() == 4)
3211 m_settings
->metaInfoPosition(m_metaData
->filePosition());
3217 * Reset meta button clicked
3219 void MainWindow::clearMetaButtonClicked(void)
3222 m_metaInfoModel
->clearData();
3226 * Meta tags enabled changed
3228 void MainWindow::metaTagsEnabledChanged(void)
3230 m_settings
->writeMetaTags(ui
->writeMetaDataCheckBox
->isChecked());
3234 * Playlist enabled changed
3236 void MainWindow::playlistEnabledChanged(void)
3238 m_settings
->createPlaylist(ui
->generatePlaylistCheckBox
->isChecked());
3241 // =========================================================
3242 // Compression tab slots
3243 // =========================================================
3248 void MainWindow::updateEncoder(int id
)
3250 m_settings
->compressionEncoder(id
);
3252 switch(m_settings
->compressionEncoder())
3254 case SettingsModel::VorbisEncoder
:
3255 ui
->radioButtonModeQuality
->setEnabled(true);
3256 ui
->radioButtonModeAverageBitrate
->setEnabled(true);
3257 ui
->radioButtonConstBitrate
->setEnabled(false);
3258 if(ui
->radioButtonConstBitrate
->isChecked()) ui
->radioButtonModeQuality
->setChecked(true);
3259 ui
->sliderBitrate
->setEnabled(true);
3261 case SettingsModel::AC3Encoder
:
3262 ui
->radioButtonModeQuality
->setEnabled(true);
3263 ui
->radioButtonModeQuality
->setChecked(true);
3264 ui
->radioButtonModeAverageBitrate
->setEnabled(false);
3265 ui
->radioButtonConstBitrate
->setEnabled(true);
3266 ui
->sliderBitrate
->setEnabled(true);
3268 case SettingsModel::FLACEncoder
:
3269 ui
->radioButtonModeQuality
->setEnabled(false);
3270 ui
->radioButtonModeQuality
->setChecked(true);
3271 ui
->radioButtonModeAverageBitrate
->setEnabled(false);
3272 ui
->radioButtonConstBitrate
->setEnabled(false);
3273 ui
->sliderBitrate
->setEnabled(true);
3275 case SettingsModel::PCMEncoder
:
3276 ui
->radioButtonModeQuality
->setEnabled(false);
3277 ui
->radioButtonModeQuality
->setChecked(true);
3278 ui
->radioButtonModeAverageBitrate
->setEnabled(false);
3279 ui
->radioButtonConstBitrate
->setEnabled(false);
3280 ui
->sliderBitrate
->setEnabled(false);
3282 case SettingsModel::AACEncoder
:
3283 ui
->radioButtonModeQuality
->setEnabled(true);
3284 ui
->radioButtonModeAverageBitrate
->setEnabled(!m_fhgEncoderAvailable
);
3285 if(m_fhgEncoderAvailable
&& ui
->radioButtonModeAverageBitrate
->isChecked()) ui
->radioButtonConstBitrate
->setChecked(true);
3286 ui
->radioButtonConstBitrate
->setEnabled(true);
3287 ui
->sliderBitrate
->setEnabled(true);
3289 case SettingsModel::DCAEncoder
:
3290 ui
->radioButtonModeQuality
->setEnabled(false);
3291 ui
->radioButtonModeAverageBitrate
->setEnabled(false);
3292 ui
->radioButtonConstBitrate
->setEnabled(true);
3293 ui
->radioButtonConstBitrate
->setChecked(true);
3294 ui
->sliderBitrate
->setEnabled(true);
3297 ui
->radioButtonModeQuality
->setEnabled(true);
3298 ui
->radioButtonModeAverageBitrate
->setEnabled(true);
3299 ui
->radioButtonConstBitrate
->setEnabled(true);
3300 ui
->sliderBitrate
->setEnabled(true);
3304 if(m_settings
->compressionEncoder() == SettingsModel::AACEncoder
)
3306 const QString encoderName
= m_qaacEncoderAvailable
? tr("QAAC (Apple)") : (m_fhgEncoderAvailable
? tr("FHG AAC (Winamp)") : (m_neroEncoderAvailable
? tr("Nero AAC") : tr("Not available!")));
3307 ui
->labelEncoderInfo
->setVisible(true);
3308 ui
->labelEncoderInfo
->setText(tr("Current AAC Encoder: %1").arg(encoderName
));
3312 ui
->labelEncoderInfo
->setVisible(false);
3315 updateRCMode(m_modeButtonGroup
->checkedId());
3319 * Update rate-control mode
3321 void MainWindow::updateRCMode(int id
)
3323 m_settings
->compressionRCMode(id
);
3325 switch(m_settings
->compressionEncoder())
3327 case SettingsModel::MP3Encoder
:
3328 switch(m_settings
->compressionRCMode())
3330 case SettingsModel::VBRMode
:
3331 ui
->sliderBitrate
->setMinimum(0);
3332 ui
->sliderBitrate
->setMaximum(9);
3335 ui
->sliderBitrate
->setMinimum(0);
3336 ui
->sliderBitrate
->setMaximum(13);
3340 case SettingsModel::VorbisEncoder
:
3341 switch(m_settings
->compressionRCMode())
3343 case SettingsModel::VBRMode
:
3344 ui
->sliderBitrate
->setMinimum(-2);
3345 ui
->sliderBitrate
->setMaximum(10);
3348 ui
->sliderBitrate
->setMinimum(4);
3349 ui
->sliderBitrate
->setMaximum(63);
3353 case SettingsModel::AC3Encoder
:
3354 switch(m_settings
->compressionRCMode())
3356 case SettingsModel::VBRMode
:
3357 ui
->sliderBitrate
->setMinimum(0);
3358 ui
->sliderBitrate
->setMaximum(16);
3361 ui
->sliderBitrate
->setMinimum(0);
3362 ui
->sliderBitrate
->setMaximum(18);
3366 case SettingsModel::AACEncoder
:
3367 switch(m_settings
->compressionRCMode())
3369 case SettingsModel::VBRMode
:
3370 ui
->sliderBitrate
->setMinimum(0);
3371 ui
->sliderBitrate
->setMaximum(20);
3374 ui
->sliderBitrate
->setMinimum(4);
3375 ui
->sliderBitrate
->setMaximum(63);
3379 case SettingsModel::FLACEncoder
:
3380 ui
->sliderBitrate
->setMinimum(0);
3381 ui
->sliderBitrate
->setMaximum(8);
3383 case SettingsModel::OpusEncoder
:
3384 ui
->sliderBitrate
->setMinimum(1);
3385 ui
->sliderBitrate
->setMaximum(32);
3387 case SettingsModel::DCAEncoder
:
3388 ui
->sliderBitrate
->setMinimum(1);
3389 ui
->sliderBitrate
->setMaximum(128);
3391 case SettingsModel::PCMEncoder
:
3392 ui
->sliderBitrate
->setMinimum(0);
3393 ui
->sliderBitrate
->setMaximum(2);
3394 ui
->sliderBitrate
->setValue(1);
3397 ui
->sliderBitrate
->setMinimum(0);
3398 ui
->sliderBitrate
->setMaximum(0);
3402 updateBitrate(ui
->sliderBitrate
->value());
3408 void MainWindow::updateBitrate(int value
)
3410 m_settings
->compressionBitrate(value
);
3412 switch(m_settings
->compressionRCMode())
3414 case SettingsModel::VBRMode
:
3415 switch(m_settings
->compressionEncoder())
3417 case SettingsModel::MP3Encoder
:
3418 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(9 - value
));
3420 case SettingsModel::VorbisEncoder
:
3421 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(value
));
3423 case SettingsModel::AACEncoder
:
3424 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", static_cast<double>(value
* 5) / 100.0)));
3426 case SettingsModel::FLACEncoder
:
3427 ui
->labelBitrate
->setText(tr("Compression %1").arg(value
));
3429 case SettingsModel::OpusEncoder
:
3430 ui
->labelBitrate
->setText(QString("≈ %1 kbps").arg(qMin(500, value
* 8)));
3432 case SettingsModel::AC3Encoder
:
3433 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(qMin(1024, qMax(0, value
* 64))));
3435 case SettingsModel::PCMEncoder
:
3436 ui
->labelBitrate
->setText(tr("Uncompressed"));
3439 ui
->labelBitrate
->setText(QString::number(value
));
3443 case SettingsModel::ABRMode
:
3444 switch(m_settings
->compressionEncoder())
3446 case SettingsModel::MP3Encoder
:
3447 ui
->labelBitrate
->setText(QString("≈ %1 kbps").arg(SettingsModel::mp3Bitrates
[value
]));
3449 case SettingsModel::FLACEncoder
:
3450 ui
->labelBitrate
->setText(tr("Compression %1").arg(value
));
3452 case SettingsModel::AC3Encoder
:
3453 ui
->labelBitrate
->setText(QString("≈ %1 kbps").arg(SettingsModel::ac3Bitrates
[value
]));
3455 case SettingsModel::PCMEncoder
:
3456 ui
->labelBitrate
->setText(tr("Uncompressed"));
3459 ui
->labelBitrate
->setText(QString("≈ %1 kbps").arg(qMin(500, value
* 8)));
3464 switch(m_settings
->compressionEncoder())
3466 case SettingsModel::MP3Encoder
:
3467 ui
->labelBitrate
->setText(QString("%1 kbps").arg(SettingsModel::mp3Bitrates
[value
]));
3469 case SettingsModel::FLACEncoder
:
3470 ui
->labelBitrate
->setText(tr("Compression %1").arg(value
));
3472 case SettingsModel::AC3Encoder
:
3473 ui
->labelBitrate
->setText(QString("%1 kbps").arg(SettingsModel::ac3Bitrates
[value
]));
3475 case SettingsModel::DCAEncoder
:
3476 ui
->labelBitrate
->setText(QString("%1 kbps").arg(value
* 32));
3478 case SettingsModel::PCMEncoder
:
3479 ui
->labelBitrate
->setText(tr("Uncompressed"));
3482 ui
->labelBitrate
->setText(QString("%1 kbps").arg(qMin(500, value
* 8)));
3490 * Event for compression tab occurred
3492 void MainWindow::compressionTabEventOccurred(QWidget
*sender
, QEvent
*event
)
3494 static const QUrl
helpUrl("http://lamexp.sourceforge.net/doc/FAQ.html#054010d9");
3496 if((sender
== ui
->labelCompressionHelp
) && (event
->type() == QEvent::MouseButtonPress
))
3498 QDesktopServices::openUrl(helpUrl
);
3502 // =========================================================
3503 // Advanced option slots
3504 // =========================================================
3507 * Lame algorithm quality changed
3509 void MainWindow::updateLameAlgoQuality(int value
)
3516 text
= tr("Best Quality (Very Slow)");
3519 text
= tr("High Quality (Recommended)");
3522 text
= tr("Average Quality (Default)");
3525 text
= tr("Low Quality (Fast)");
3528 text
= tr("Poor Quality (Very Fast)");
3534 m_settings
->lameAlgoQuality(value
);
3535 ui
->labelLameAlgoQuality
->setText(text
);
3538 bool warning
= (value
== 0), notice
= (value
== 4);
3539 ui
->labelLameAlgoQualityWarning
->setVisible(warning
);
3540 ui
->labelLameAlgoQualityWarningIcon
->setVisible(warning
);
3541 ui
->labelLameAlgoQualityNotice
->setVisible(notice
);
3542 ui
->labelLameAlgoQualityNoticeIcon
->setVisible(notice
);
3543 ui
->labelLameAlgoQualitySpacer
->setVisible(warning
|| notice
);
3547 * Bitrate management endabled/disabled
3549 void MainWindow::bitrateManagementEnabledChanged(bool checked
)
3551 m_settings
->bitrateManagementEnabled(checked
);
3555 * Minimum bitrate has changed
3557 void MainWindow::bitrateManagementMinChanged(int value
)
3559 if(value
> ui
->spinBoxBitrateManagementMax
->value())
3561 ui
->spinBoxBitrateManagementMin
->setValue(ui
->spinBoxBitrateManagementMax
->value());
3562 m_settings
->bitrateManagementMinRate(ui
->spinBoxBitrateManagementMax
->value());
3566 m_settings
->bitrateManagementMinRate(value
);
3571 * Maximum bitrate has changed
3573 void MainWindow::bitrateManagementMaxChanged(int value
)
3575 if(value
< ui
->spinBoxBitrateManagementMin
->value())
3577 ui
->spinBoxBitrateManagementMax
->setValue(ui
->spinBoxBitrateManagementMin
->value());
3578 m_settings
->bitrateManagementMaxRate(ui
->spinBoxBitrateManagementMin
->value());
3582 m_settings
->bitrateManagementMaxRate(value
);
3587 * Channel mode has changed
3589 void MainWindow::channelModeChanged(int value
)
3591 if(value
>= 0) m_settings
->lameChannelMode(value
);
3595 * Sampling rate has changed
3597 void MainWindow::samplingRateChanged(int value
)
3599 if(value
>= 0) m_settings
->samplingRate(value
);
3603 * Nero AAC 2-Pass mode changed
3605 void MainWindow::neroAAC2PassChanged(bool checked
)
3607 m_settings
->neroAACEnable2Pass(checked
);
3611 * Nero AAC profile mode changed
3613 void MainWindow::neroAACProfileChanged(int value
)
3615 if(value
>= 0) m_settings
->aacEncProfile(value
);
3619 * Aften audio coding mode changed
3621 void MainWindow::aftenCodingModeChanged(int value
)
3623 if(value
>= 0) m_settings
->aftenAudioCodingMode(value
);
3627 * Aften DRC mode changed
3629 void MainWindow::aftenDRCModeChanged(int value
)
3631 if(value
>= 0) m_settings
->aftenDynamicRangeCompression(value
);
3635 * Aften exponent search size changed
3637 void MainWindow::aftenSearchSizeChanged(int value
)
3639 if(value
>= 0) m_settings
->aftenExponentSearchSize(value
);
3643 * Aften fast bit allocation changed
3645 void MainWindow::aftenFastAllocationChanged(bool checked
)
3647 m_settings
->aftenFastBitAllocation(checked
);
3652 * Opus encoder settings changed
3654 void MainWindow::opusSettingsChanged(void)
3656 m_settings
->opusFramesize(ui
->comboBoxOpusFramesize
->currentIndex());
3657 m_settings
->opusComplexity(ui
->spinBoxOpusComplexity
->value());
3658 //m_settings->opusOptimizeFor(comboBoxOpusOptimize->currentIndex());
3662 * Normalization filter enabled changed
3664 void MainWindow::normalizationEnabledChanged(bool checked
)
3666 m_settings
->normalizationFilterEnabled(checked
);
3670 * Normalization max. volume changed
3672 void MainWindow::normalizationMaxVolumeChanged(double value
)
3674 m_settings
->normalizationFilterMaxVolume(static_cast<int>(value
* 100.0));
3678 * Normalization equalization mode changed
3680 void MainWindow::normalizationModeChanged(int mode
)
3682 m_settings
->normalizationFilterEqualizationMode(mode
);
3686 * Tone adjustment has changed (Bass)
3688 void MainWindow::toneAdjustBassChanged(double value
)
3690 m_settings
->toneAdjustBass(static_cast<int>(value
* 100.0));
3691 ui
->spinBoxToneAdjustBass
->setPrefix((value
> 0) ? "+" : QString());
3695 * Tone adjustment has changed (Treble)
3697 void MainWindow::toneAdjustTrebleChanged(double value
)
3699 m_settings
->toneAdjustTreble(static_cast<int>(value
* 100.0));
3700 ui
->spinBoxToneAdjustTreble
->setPrefix((value
> 0) ? "+" : QString());
3704 * Tone adjustment has been reset
3706 void MainWindow::toneAdjustTrebleReset(void)
3708 ui
->spinBoxToneAdjustBass
->setValue(m_settings
->toneAdjustBassDefault());
3709 ui
->spinBoxToneAdjustTreble
->setValue(m_settings
->toneAdjustTrebleDefault());
3710 toneAdjustBassChanged(ui
->spinBoxToneAdjustBass
->value());
3711 toneAdjustTrebleChanged(ui
->spinBoxToneAdjustTreble
->value());
3715 * Custom encoder parameters changed
3717 void MainWindow::customParamsChanged(void)
3719 ui
->lineEditCustomParamLAME
->setText(ui
->lineEditCustomParamLAME
->text().simplified());
3720 ui
->lineEditCustomParamOggEnc
->setText(ui
->lineEditCustomParamOggEnc
->text().simplified());
3721 ui
->lineEditCustomParamNeroAAC
->setText(ui
->lineEditCustomParamNeroAAC
->text().simplified());
3722 ui
->lineEditCustomParamFLAC
->setText(ui
->lineEditCustomParamFLAC
->text().simplified());
3723 ui
->lineEditCustomParamAften
->setText(ui
->lineEditCustomParamAften
->text().simplified());
3724 ui
->lineEditCustomParamOpus
->setText(ui
->lineEditCustomParamOpus
->text().simplified());
3726 bool customParamsUsed
= false;
3727 if(!ui
->lineEditCustomParamLAME
->text().isEmpty()) customParamsUsed
= true;
3728 if(!ui
->lineEditCustomParamOggEnc
->text().isEmpty()) customParamsUsed
= true;
3729 if(!ui
->lineEditCustomParamNeroAAC
->text().isEmpty()) customParamsUsed
= true;
3730 if(!ui
->lineEditCustomParamFLAC
->text().isEmpty()) customParamsUsed
= true;
3731 if(!ui
->lineEditCustomParamAften
->text().isEmpty()) customParamsUsed
= true;
3732 if(!ui
->lineEditCustomParamOpus
->text().isEmpty()) customParamsUsed
= true;
3734 ui
->labelCustomParamsIcon
->setVisible(customParamsUsed
);
3735 ui
->labelCustomParamsText
->setVisible(customParamsUsed
);
3736 ui
->labelCustomParamsSpacer
->setVisible(customParamsUsed
);
3738 m_settings
->customParametersLAME(ui
->lineEditCustomParamLAME
->text());
3739 m_settings
->customParametersOggEnc(ui
->lineEditCustomParamOggEnc
->text());
3740 m_settings
->customParametersAacEnc(ui
->lineEditCustomParamNeroAAC
->text());
3741 m_settings
->customParametersFLAC(ui
->lineEditCustomParamFLAC
->text());
3742 m_settings
->customParametersAften(ui
->lineEditCustomParamAften
->text());
3743 m_settings
->customParametersOpus(ui
->lineEditCustomParamOpus
->text());
3747 * Rename output files enabled changed
3749 void MainWindow::renameOutputEnabledChanged(bool checked
)
3751 m_settings
->renameOutputFilesEnabled(checked
);
3755 * Rename output files patterm changed
3757 void MainWindow::renameOutputPatternChanged(void)
3759 QString temp
= ui
->lineEditRenamePattern
->text().simplified();
3760 ui
->lineEditRenamePattern
->setText(temp
.isEmpty() ? m_settings
->renameOutputFilesPatternDefault() : temp
);
3761 m_settings
->renameOutputFilesPattern(ui
->lineEditRenamePattern
->text());
3765 * Rename output files patterm changed
3767 void MainWindow::renameOutputPatternChanged(const QString
&text
)
3769 QString
pattern(text
.simplified());
3771 pattern
.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive
);
3772 pattern
.replace("<TrackNo>", "04", Qt::CaseInsensitive
);
3773 pattern
.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive
);
3774 pattern
.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive
);
3775 pattern
.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive
);
3776 pattern
.replace("<Year>", "2001", Qt::CaseInsensitive
);
3777 pattern
.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive
);
3779 if(pattern
.compare(lamexp_clean_filename(pattern
)))
3781 if(ui
->lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::red
)
3783 MessageBeep(MB_ICONERROR
);
3784 SET_TEXT_COLOR(ui
->lineEditRenamePattern
, Qt::red
);
3789 if(ui
->lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::black
)
3791 MessageBeep(MB_ICONINFORMATION
);
3792 SET_TEXT_COLOR(ui
->lineEditRenamePattern
, Qt::black
);
3796 ui
->labelRanameExample
->setText(lamexp_clean_filename(pattern
));
3800 * Show list of rename macros
3802 void MainWindow::showRenameMacros(const QString
&text
)
3804 if(text
.compare("reset", Qt::CaseInsensitive
) == 0)
3806 ui
->lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPatternDefault());
3810 const QString format
= QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
3812 QString message
= QString("<table>");
3813 message
+= QString(format
).arg("BaseName", tr("File name without extension"));
3814 message
+= QString(format
).arg("TrackNo", tr("Track number with leading zero"));
3815 message
+= QString(format
).arg("Title", tr("Track title"));
3816 message
+= QString(format
).arg("Artist", tr("Artist name"));
3817 message
+= QString(format
).arg("Album", tr("Album name"));
3818 message
+= QString(format
).arg("Year", tr("Year with (at least) four digits"));
3819 message
+= QString(format
).arg("Comment", tr("Comment"));
3820 message
+= "</table><br><br>";
3821 message
+= QString("%1<br>").arg(tr("Characters forbidden in file names:"));
3822 message
+= "<b><tt>\\ / : * ? < > |<br>";
3824 QMessageBox::information(this, tr("Rename Macros"), message
, tr("Discard"));
3827 void MainWindow::forceStereoDownmixEnabledChanged(bool checked
)
3829 m_settings
->forceStereoDownmix(checked
);
3833 * Maximum number of instances changed
3835 void MainWindow::updateMaximumInstances(int value
)
3837 ui
->labelMaxInstances
->setText(tr("%1 Instance(s)").arg(QString::number(value
)));
3838 m_settings
->maximumInstances(ui
->checkBoxAutoDetectInstances
->isChecked() ? NULL
: value
);
3842 * Auto-detect number of instances
3844 void MainWindow::autoDetectInstancesChanged(bool checked
)
3846 m_settings
->maximumInstances(checked
? NULL
: ui
->sliderMaxInstances
->value());
3850 * Browse for custom TEMP folder button clicked
3852 void MainWindow::browseCustomTempFolderButtonClicked(void)
3854 QString newTempFolder
;
3856 if(USE_NATIVE_FILE_DIALOG
)
3858 newTempFolder
= QFileDialog::getExistingDirectory(this, QString(), m_settings
->customTempPath());
3862 QFileDialog
dialog(this);
3863 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
3864 dialog
.setDirectory(m_settings
->customTempPath());
3867 newTempFolder
= dialog
.selectedFiles().first();
3871 if(!newTempFolder
.isEmpty())
3873 QFile
writeTest(QString("%1/~%2.tmp").arg(newTempFolder
, lamexp_rand_str()));
3874 if(writeTest
.open(QIODevice::ReadWrite
))
3877 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(newTempFolder
));
3881 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
3887 * Custom TEMP folder changed
3889 void MainWindow::customTempFolderChanged(const QString
&text
)
3891 m_settings
->customTempPath(QDir::fromNativeSeparators(text
));
3895 * Use custom TEMP folder option changed
3897 void MainWindow::useCustomTempFolderChanged(bool checked
)
3899 m_settings
->customTempPathEnabled(!checked
);
3903 * Help for custom parameters was requested
3905 void MainWindow::customParamsHelpRequested(QWidget
*obj
, QEvent
*event
)
3907 if(event
->type() != QEvent::MouseButtonRelease
)
3912 if(QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
))
3914 QPoint pos
= mouseEvent
->pos();
3915 if(!(pos
.x() <= obj
->width() && pos
.y() <= obj
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
))
3921 if(obj
== ui
->helpCustomParamLAME
) showCustomParamsHelpScreen("lame.exe", "--longhelp");
3922 else if(obj
== ui
->helpCustomParamOggEnc
) showCustomParamsHelpScreen("oggenc2.exe", "--help");
3923 else if(obj
== ui
->helpCustomParamNeroAAC
)
3925 if(m_qaacEncoderAvailable
) showCustomParamsHelpScreen("qaac.exe", "--help");
3926 else if(m_fhgEncoderAvailable
) showCustomParamsHelpScreen("fhgaacenc.exe", "");
3927 else if(m_neroEncoderAvailable
) showCustomParamsHelpScreen("neroAacEnc.exe", "-help");
3928 else MessageBeep(MB_ICONERROR
);
3930 else if(obj
== ui
->helpCustomParamFLAC
) showCustomParamsHelpScreen("flac.exe", "--help");
3931 else if(obj
== ui
->helpCustomParamAften
) showCustomParamsHelpScreen("aften.exe", "-h");
3932 else if(obj
== ui
->helpCustomParamOpus
) showCustomParamsHelpScreen("opusenc_std.exe", "--help");
3933 else MessageBeep(MB_ICONERROR
);
3937 * Show help for custom parameters
3939 void MainWindow::showCustomParamsHelpScreen(const QString
&toolName
, const QString
&command
)
3941 const QString binary
= lamexp_lookup_tool(toolName
);
3942 if(binary
.isEmpty())
3944 MessageBeep(MB_ICONERROR
);
3945 qWarning("customParamsHelpRequested: Binary could not be found!");
3949 QProcess
*process
= new QProcess();
3950 process
->setProcessChannelMode(QProcess::MergedChannels
);
3951 process
->setReadChannel(QProcess::StandardOutput
);
3952 process
->start(binary
, command
.isEmpty() ? QStringList() : QStringList() << command
);
3953 qApp
->setOverrideCursor(QCursor(Qt::WaitCursor
));
3955 if(process
->waitForStarted(15000))
3957 qApp
->processEvents();
3958 process
->waitForFinished(15000);
3961 if(process
->state() != QProcess::NotRunning
)
3964 process
->waitForFinished(-1);
3967 qApp
->restoreOverrideCursor();
3968 QStringList output
; bool spaceFlag
= true;
3970 while(process
->canReadLine())
3972 QString temp
= QString::fromUtf8(process
->readLine());
3973 TRIM_STRING_RIGHT(temp
);
3976 if(!spaceFlag
) { output
<< temp
; spaceFlag
= true; }
3980 output
<< temp
; spaceFlag
= false;
3984 LAMEXP_DELETE(process
);
3986 if(output
.count() < 1)
3988 qWarning("Empty output, cannot show help screen!");
3989 MessageBeep(MB_ICONERROR
);
3992 LogViewDialog
*dialog
= new LogViewDialog(this);
3993 TEMP_HIDE_DROPBOX( dialog
->exec(output
); );
3994 LAMEXP_DELETE(dialog
);
3997 void MainWindow::overwriteModeChanged(int id
)
3999 if((id
== SettingsModel::Overwrite_Replaces
) && (m_settings
->overwriteMode() != SettingsModel::Overwrite_Replaces
))
4001 if(QMessageBox::warning(this, tr("Overwrite Mode"), tr("Warning: This mode may overwrite existing files with no way to revert!"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
4003 ui
->radioButtonOverwriteModeKeepBoth
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_KeepBoth
);
4004 ui
->radioButtonOverwriteModeSkipFile
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_SkipFile
);
4009 m_settings
->overwriteMode(id
);
4013 * Reset all advanced options to their defaults
4015 void MainWindow::resetAdvancedOptionsButtonClicked(void)
4017 ui
->sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQualityDefault());
4018 ui
->spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRateDefault());
4019 ui
->spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRateDefault());
4020 ui
->spinBoxNormalizationFilter
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolumeDefault()) / 100.0);
4021 ui
->spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBassDefault()) / 100.0);
4022 ui
->spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTrebleDefault()) / 100.0);
4023 ui
->spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSizeDefault());
4024 ui
->spinBoxOpusComplexity
->setValue(m_settings
->opusComplexityDefault());
4025 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelModeDefault());
4026 ui
->comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRateDefault());
4027 ui
->comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfileDefault());
4028 ui
->comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingModeDefault());
4029 ui
->comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompressionDefault());
4030 ui
->comboBoxNormalizationMode
->setCurrentIndex(m_settings
->normalizationFilterEqualizationModeDefault());
4031 //comboBoxOpusOptimize->setCurrentIndex(m_settings->opusOptimizeForDefault());
4032 ui
->comboBoxOpusFramesize
->setCurrentIndex(m_settings
->opusFramesizeDefault());
4033 SET_CHECKBOX_STATE(ui
->checkBoxBitrateManagement
, m_settings
->bitrateManagementEnabledDefault());
4034 SET_CHECKBOX_STATE(ui
->checkBoxNeroAAC2PassMode
, m_settings
->neroAACEnable2PassDefault());
4035 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilter
, m_settings
->normalizationFilterEnabledDefault());
4036 SET_CHECKBOX_STATE(ui
->checkBoxAutoDetectInstances
, (m_settings
->maximumInstancesDefault() < 1));
4037 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, !m_settings
->customTempPathEnabledDefault());
4038 SET_CHECKBOX_STATE(ui
->checkBoxAftenFastAllocation
, m_settings
->aftenFastBitAllocationDefault());
4039 SET_CHECKBOX_STATE(ui
->checkBoxRenameOutput
, m_settings
->renameOutputFilesEnabledDefault());
4040 SET_CHECKBOX_STATE(ui
->checkBoxForceStereoDownmix
, m_settings
->forceStereoDownmixDefault());
4041 ui
->lineEditCustomParamLAME
->setText(m_settings
->customParametersLAMEDefault());
4042 ui
->lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEncDefault());
4043 ui
->lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEncDefault());
4044 ui
->lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLACDefault());
4045 ui
->lineEditCustomParamOpus
->setText(m_settings
->customParametersFLACDefault());
4046 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPathDefault()));
4047 ui
->lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPatternDefault());
4048 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_KeepBoth
) ui
->radioButtonOverwriteModeKeepBoth
->click();
4049 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_SkipFile
) ui
->radioButtonOverwriteModeSkipFile
->click();
4050 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_Replaces
) ui
->radioButtonOverwriteModeReplaces
->click();
4051 customParamsChanged();
4052 ui
->scrollArea
->verticalScrollBar()->setValue(0);
4055 // =========================================================
4056 // Multi-instance handling slots
4057 // =========================================================
4060 * Other instance detected
4062 void MainWindow::notifyOtherInstance(void)
4064 if(!m_banner
->isVisible())
4066 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
);
4072 * Add file from another instance
4074 void MainWindow::addFileDelayed(const QString
&filePath
, bool tryASAP
)
4076 if(tryASAP
&& !m_delayedFileTimer
->isActive())
4078 qDebug("Received file: %s", filePath
.toUtf8().constData());
4079 m_delayedFileList
->append(filePath
);
4080 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4083 m_delayedFileTimer
->stop();
4084 qDebug("Received file: %s", filePath
.toUtf8().constData());
4085 m_delayedFileList
->append(filePath
);
4086 m_delayedFileTimer
->start(5000);
4090 * Add files from another instance
4092 void MainWindow::addFilesDelayed(const QStringList
&filePaths
, bool tryASAP
)
4094 if(tryASAP
&& !m_delayedFileTimer
->isActive())
4096 qDebug("Received %d file(s).", filePaths
.count());
4097 m_delayedFileList
->append(filePaths
);
4098 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4102 m_delayedFileTimer
->stop();
4103 qDebug("Received %d file(s).", filePaths
.count());
4104 m_delayedFileList
->append(filePaths
);
4105 m_delayedFileTimer
->start(5000);
4110 * Add folder from another instance
4112 void MainWindow::addFolderDelayed(const QString
&folderPath
, bool recursive
)
4114 if(!m_banner
->isVisible())
4116 addFolder(folderPath
, recursive
, true);
4120 // =========================================================
4122 // =========================================================
4125 * Restore the override cursor
4127 void MainWindow::restoreCursor(void)
4129 QApplication::restoreOverrideCursor();