1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_MainWindow.h"
27 #include "Dialog_WorkingBanner.h"
28 #include "Dialog_MetaInfo.h"
29 #include "Dialog_About.h"
30 #include "Dialog_Update.h"
31 #include "Dialog_DropBox.h"
32 #include "Dialog_CueImport.h"
33 #include "Thread_FileAnalyzer.h"
34 #include "Thread_MessageHandler.h"
35 #include "Model_MetaInfo.h"
36 #include "Model_Settings.h"
37 #include "Model_FileList.h"
38 #include "Model_FileSystem.h"
39 #include "WinSevenTaskbar.h"
40 #include "Registry_Decoder.h"
41 #include "ShellIntegration.h"
44 #include <QMessageBox>
46 #include <QDesktopWidget>
48 #include <QFileDialog>
49 #include <QInputDialog>
50 #include <QFileSystemModel>
51 #include <QDesktopServices>
53 #include <QPlastiqueStyle>
54 #include <QCleanlooksStyle>
55 #include <QWindowsVistaStyle>
56 #include <QWindowsStyle>
58 #include <QDragEnterEvent>
62 #include <QProcessEnvironment>
63 #include <QCryptographicHash>
64 #include <QTranslator>
73 #define ABORT_IF_BUSY if(m_banner->isVisible() || m_delayedFileTimer->isActive()) { MessageBeep(MB_ICONEXCLAMATION); return; }
74 #define SET_TEXT_COLOR(WIDGET,COLOR) { QPalette _palette = WIDGET->palette(); _palette.setColor(QPalette::WindowText, (COLOR)); _palette.setColor(QPalette::Text, (COLOR)); WIDGET->setPalette(_palette); }
75 #define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
76 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "−"))
77 #define FSLINK(PATH) QString("<a href=\"file:///%1\">%2</a>").arg(PATH).arg(QString(PATH).replace("-", "−"))
78 #define TEMP_HIDE_DROPBOX(CMD) { bool __dropBoxVisible = m_dropBox->isVisible(); if(__dropBoxVisible) m_dropBox->hide(); {CMD}; if(__dropBoxVisible) m_dropBox->show(); }
79 #define USE_NATIVE_FILE_DIALOG (lamexp_themes_enabled() || ((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based) < QSysInfo::WV_XP))
80 #define CENTER_CURRENT_OUTPUT_FOLDER_DELAYED QTimer::singleShot(125, this, SLOT(centerOutputFolderModel()))
81 #define SET_MODEL(VIEW, MODEL) { QItemSelectionModel *_tmp = (VIEW)->selectionModel(); (VIEW)->setModel(MODEL); LAMEXP_DELETE(_tmp); }
83 ////////////////////////////////////////////////////////////
85 ////////////////////////////////////////////////////////////
87 MainWindow::MainWindow(FileListModel
*fileListModel
, AudioFileModel
*metaInfo
, SettingsModel
*settingsModel
, QWidget
*parent
)
90 m_fileListModel(fileListModel
),
92 m_settings(settingsModel
),
93 m_fileSystemModel(NULL
),
94 m_neroEncoderAvailable(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe")),
95 m_fhgEncoderAvailable(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll") && lamexp_check_tool("nsutil.dll") && lamexp_check_tool("libmp4v2.dll")),
96 m_qaacEncoderAvailable(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll")),
98 m_firstTimeShown(true),
99 m_outputFolderViewCentering(false),
100 m_outputFolderViewInitCounter(0)
102 //Init the dialog, from the .ui file
104 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint
);
106 //Register meta types
107 qRegisterMetaType
<AudioFileModel
>("AudioFileModel");
109 //Enabled main buttons
110 connect(buttonAbout
, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
111 connect(buttonStart
, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
112 connect(buttonQuit
, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
115 tabWidget
->setCurrentIndex(0);
116 connect(tabWidget
, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
119 sourceFileView
->setModel(m_fileListModel
);
120 sourceFileView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
121 sourceFileView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
122 sourceFileView
->setContextMenuPolicy(Qt::CustomContextMenu
);
123 sourceFileView
->viewport()->installEventFilter(this);
124 m_dropNoteLabel
= new QLabel(sourceFileView
);
125 m_dropNoteLabel
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
126 SET_FONT_BOLD(m_dropNoteLabel
, true);
127 SET_TEXT_COLOR(m_dropNoteLabel
, Qt::darkGray
);
128 m_sourceFilesContextMenu
= new QMenu();
129 m_showDetailsContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
130 m_previewContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/sound.png"), "N/A");
131 m_findFileContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_go.png"), "N/A");
132 m_sourceFilesContextMenu
->addSeparator();
133 m_exportCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/table_save.png"), "N/A");
134 m_importCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_table.png"), "N/A");
135 SET_FONT_BOLD(m_showDetailsContextAction
, true);
136 connect(buttonAddFiles
, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
137 connect(buttonRemoveFile
, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
138 connect(buttonClearFiles
, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
139 connect(buttonFileUp
, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
140 connect(buttonFileDown
, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
141 connect(buttonShowDetails
, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
142 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
143 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
144 connect(m_fileListModel
, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
145 connect(sourceFileView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(sourceFilesContextMenu(QPoint
)));
146 connect(sourceFileView
->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
147 connect(sourceFileView
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
148 connect(m_showDetailsContextAction
, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
149 connect(m_previewContextAction
, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
150 connect(m_findFileContextAction
, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
151 connect(m_exportCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(exportCsvContextActionTriggered()));
152 connect(m_importCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(importCsvContextActionTriggered()));
155 outputFolderView
->setHeaderHidden(true);
156 outputFolderView
->setAnimated(false);
157 outputFolderView
->setMouseTracking(false);
158 outputFolderView
->setContextMenuPolicy(Qt::CustomContextMenu
);
159 outputFolderView
->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn
);
160 outputFolderView
->installEventFilter(this);
161 outputFoldersEditorLabel
->installEventFilter(this);
162 outputFoldersFovoritesLabel
->installEventFilter(this);
163 while(saveToSourceFolderCheckBox
->isChecked() != m_settings
->outputToSourceDir()) saveToSourceFolderCheckBox
->click();
164 prependRelativePathCheckBox
->setChecked(m_settings
->prependRelativeSourcePath());
165 connect(outputFolderView
, SIGNAL(clicked(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
166 connect(outputFolderView
, SIGNAL(activated(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
167 connect(outputFolderView
, SIGNAL(pressed(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
168 connect(outputFolderView
, SIGNAL(entered(QModelIndex
)), this, SLOT(outputFolderViewMoved(QModelIndex
)));
169 connect(outputFolderView
, SIGNAL(expanded(QModelIndex
)), this, SLOT(outputFolderItemExpanded(QModelIndex
)));
170 connect(buttonMakeFolder
, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
171 connect(buttonGotoHome
, SIGNAL(clicked()), SLOT(gotoHomeFolderButtonClicked()));
172 connect(buttonGotoDesktop
, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
173 connect(buttonGotoMusic
, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
174 connect(saveToSourceFolderCheckBox
, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
175 connect(prependRelativePathCheckBox
, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
176 connect(outputFolderEdit
, SIGNAL(editingFinished()), this, SLOT(outputFolderEditFinished()));
177 if(m_outputFolderContextMenu
= new QMenu())
179 m_showFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
180 m_refreshFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/arrow_refresh.png"), "N/A");
181 m_outputFolderContextMenu
->setDefaultAction(m_showFolderContextAction
);
182 connect(outputFolderView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(outputFolderContextMenu(QPoint
)));
183 connect(m_showFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
184 connect(m_refreshFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(refreshFolderContextActionTriggered()));
186 if(m_outputFolderFavoritesMenu
= new QMenu())
188 m_addFavoriteFolderAction
= m_outputFolderFavoritesMenu
->addAction(QIcon(":/icons/add.png"), "N/A");
189 m_outputFolderFavoritesMenu
->insertSeparator(m_addFavoriteFolderAction
);
190 connect(m_addFavoriteFolderAction
, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
192 outputFolderEdit
->setVisible(false);
193 outputFolderLabel
->installEventFilter(this);
194 if(m_outputFolderNoteBox
= new QLabel(outputFolderView
))
196 m_outputFolderNoteBox
->setAutoFillBackground(true);
197 m_outputFolderNoteBox
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
198 m_outputFolderNoteBox
->setFrameShape(QFrame::StyledPanel
);
199 SET_FONT_BOLD(m_outputFolderNoteBox
, true);
200 m_outputFolderNoteBox
->hide();
203 outputFolderViewClicked(QModelIndex());
206 //Setup "Meta Data" tab
207 m_metaInfoModel
= new MetaInfoModel(m_metaData
, 6);
208 m_metaInfoModel
->clearData();
209 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
210 metaDataView
->setModel(m_metaInfoModel
);
211 metaDataView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
212 metaDataView
->verticalHeader()->hide();
213 metaDataView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
214 while(writeMetaDataCheckBox
->isChecked() != m_settings
->writeMetaTags()) writeMetaDataCheckBox
->click();
215 generatePlaylistCheckBox
->setChecked(m_settings
->createPlaylist());
216 connect(buttonEditMeta
, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
217 connect(buttonClearMeta
, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
218 connect(writeMetaDataCheckBox
, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
219 connect(generatePlaylistCheckBox
, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
221 //Setup "Compression" tab
222 m_encoderButtonGroup
= new QButtonGroup(this);
223 m_encoderButtonGroup
->addButton(radioButtonEncoderMP3
, SettingsModel::MP3Encoder
);
224 m_encoderButtonGroup
->addButton(radioButtonEncoderVorbis
, SettingsModel::VorbisEncoder
);
225 m_encoderButtonGroup
->addButton(radioButtonEncoderAAC
, SettingsModel::AACEncoder
);
226 m_encoderButtonGroup
->addButton(radioButtonEncoderAC3
, SettingsModel::AC3Encoder
);
227 m_encoderButtonGroup
->addButton(radioButtonEncoderFLAC
, SettingsModel::FLACEncoder
);
228 m_encoderButtonGroup
->addButton(radioButtonEncoderDCA
, SettingsModel::DCAEncoder
);
229 m_encoderButtonGroup
->addButton(radioButtonEncoderPCM
, SettingsModel::PCMEncoder
);
230 m_modeButtonGroup
= new QButtonGroup(this);
231 m_modeButtonGroup
->addButton(radioButtonModeQuality
, SettingsModel::VBRMode
);
232 m_modeButtonGroup
->addButton(radioButtonModeAverageBitrate
, SettingsModel::ABRMode
);
233 m_modeButtonGroup
->addButton(radioButtonConstBitrate
, SettingsModel::CBRMode
);
234 radioButtonEncoderAAC
->setEnabled(m_neroEncoderAvailable
|| m_fhgEncoderAvailable
|| m_qaacEncoderAvailable
);
235 radioButtonEncoderMP3
->setChecked(m_settings
->compressionEncoder() == SettingsModel::MP3Encoder
);
236 radioButtonEncoderVorbis
->setChecked(m_settings
->compressionEncoder() == SettingsModel::VorbisEncoder
);
237 radioButtonEncoderAAC
->setChecked((m_settings
->compressionEncoder() == SettingsModel::AACEncoder
) && (m_neroEncoderAvailable
|| m_fhgEncoderAvailable
|| m_qaacEncoderAvailable
));
238 radioButtonEncoderAC3
->setChecked(m_settings
->compressionEncoder() == SettingsModel::AC3Encoder
);
239 radioButtonEncoderFLAC
->setChecked(m_settings
->compressionEncoder() == SettingsModel::FLACEncoder
);
240 radioButtonEncoderDCA
->setChecked(m_settings
->compressionEncoder() == SettingsModel::DCAEncoder
);
241 radioButtonEncoderPCM
->setChecked(m_settings
->compressionEncoder() == SettingsModel::PCMEncoder
);
242 radioButtonModeQuality
->setChecked(m_settings
->compressionRCMode() == SettingsModel::VBRMode
);
243 radioButtonModeAverageBitrate
->setChecked(m_settings
->compressionRCMode() == SettingsModel::ABRMode
);
244 radioButtonConstBitrate
->setChecked(m_settings
->compressionRCMode() == SettingsModel::CBRMode
);
245 sliderBitrate
->setValue(m_settings
->compressionBitrate());
246 connect(m_encoderButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
247 connect(m_modeButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
248 connect(sliderBitrate
, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
249 updateEncoder(m_encoderButtonGroup
->checkedId());
251 //Setup "Advanced Options" tab
252 sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQuality());
253 if(m_settings
->maximumInstances() > 0) sliderMaxInstances
->setValue(m_settings
->maximumInstances());
254 spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRate());
255 spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRate());
256 spinBoxNormalizationFilter
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolume()) / 100.0);
257 spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBass()) / 100.0);
258 spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTreble()) / 100.0);
259 spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSize());
260 comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelMode());
261 comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRate());
262 comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfile());
263 comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingMode());
264 comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompression());
265 comboBoxNormalizationMode
->setCurrentIndex(m_settings
->normalizationFilterEqualizationMode());
266 while(checkBoxBitrateManagement
->isChecked() != m_settings
->bitrateManagementEnabled()) checkBoxBitrateManagement
->click();
267 while(checkBoxNeroAAC2PassMode
->isChecked() != m_settings
->neroAACEnable2Pass()) checkBoxNeroAAC2PassMode
->click();
268 while(checkBoxAftenFastAllocation
->isChecked() != m_settings
->aftenFastBitAllocation()) checkBoxAftenFastAllocation
->click();
269 while(checkBoxNormalizationFilter
->isChecked() != m_settings
->normalizationFilterEnabled()) checkBoxNormalizationFilter
->click();
270 while(checkBoxAutoDetectInstances
->isChecked() != (m_settings
->maximumInstances() < 1)) checkBoxAutoDetectInstances
->click();
271 while(checkBoxUseSystemTempFolder
->isChecked() == m_settings
->customTempPathEnabled()) checkBoxUseSystemTempFolder
->click();
272 while(checkBoxRenameOutput
->isChecked() != m_settings
->renameOutputFilesEnabled()) checkBoxRenameOutput
->click();
273 while(checkBoxForceStereoDownmix
->isChecked() != m_settings
->forceStereoDownmix()) checkBoxForceStereoDownmix
->click();
274 checkBoxNeroAAC2PassMode
->setEnabled(!(m_fhgEncoderAvailable
|| m_qaacEncoderAvailable
));
275 lineEditCustomParamLAME
->setText(m_settings
->customParametersLAME());
276 lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEnc());
277 lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEnc());
278 lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLAC());
279 lineEditCustomParamAften
->setText(m_settings
->customParametersAften());
280 lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPath()));
281 lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPattern());
282 connect(sliderLameAlgoQuality
, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
283 connect(checkBoxBitrateManagement
, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
284 connect(spinBoxBitrateManagementMin
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
285 connect(spinBoxBitrateManagementMax
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
286 connect(comboBoxMP3ChannelMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
287 connect(comboBoxSamplingRate
, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
288 connect(checkBoxNeroAAC2PassMode
, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
289 connect(comboBoxAACProfile
, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
290 connect(checkBoxNormalizationFilter
, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
291 connect(comboBoxAftenCodingMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
292 connect(comboBoxAftenDRCMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
293 connect(spinBoxAftenSearchSize
, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
294 connect(checkBoxAftenFastAllocation
, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
295 connect(spinBoxNormalizationFilter
, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
296 connect(comboBoxNormalizationMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(normalizationModeChanged(int)));
297 connect(spinBoxToneAdjustBass
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
298 connect(spinBoxToneAdjustTreble
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
299 connect(buttonToneAdjustReset
, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
300 connect(lineEditCustomParamLAME
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
301 connect(lineEditCustomParamOggEnc
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
302 connect(lineEditCustomParamNeroAAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
303 connect(lineEditCustomParamFLAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
304 connect(lineEditCustomParamAften
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
305 connect(sliderMaxInstances
, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
306 connect(checkBoxAutoDetectInstances
, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
307 connect(buttonBrowseCustomTempFolder
, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
308 connect(lineEditCustomTempFolder
, SIGNAL(textChanged(QString
)), this, SLOT(customTempFolderChanged(QString
)));
309 connect(checkBoxUseSystemTempFolder
, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
310 connect(buttonResetAdvancedOptions
, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
311 connect(checkBoxRenameOutput
, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
312 connect(lineEditRenamePattern
, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
313 connect(lineEditRenamePattern
, SIGNAL(textChanged(QString
)), this, SLOT(renameOutputPatternChanged(QString
)));
314 connect(labelShowRenameMacros
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
315 connect(checkBoxForceStereoDownmix
, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
316 updateLameAlgoQuality(sliderLameAlgoQuality
->value());
317 updateMaximumInstances(sliderMaxInstances
->value());
318 toneAdjustTrebleChanged(spinBoxToneAdjustTreble
->value());
319 toneAdjustBassChanged(spinBoxToneAdjustBass
->value());
320 customParamsChanged();
322 //Activate file menu actions
323 actionOpenFolder
->setData(QVariant::fromValue
<bool>(false));
324 actionOpenFolderRecursively
->setData(QVariant::fromValue
<bool>(true));
325 connect(actionOpenFolder
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
326 connect(actionOpenFolderRecursively
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
328 //Activate view menu actions
329 m_tabActionGroup
= new QActionGroup(this);
330 m_tabActionGroup
->addAction(actionSourceFiles
);
331 m_tabActionGroup
->addAction(actionOutputDirectory
);
332 m_tabActionGroup
->addAction(actionCompression
);
333 m_tabActionGroup
->addAction(actionMetaData
);
334 m_tabActionGroup
->addAction(actionAdvancedOptions
);
335 actionSourceFiles
->setData(0);
336 actionOutputDirectory
->setData(1);
337 actionMetaData
->setData(2);
338 actionCompression
->setData(3);
339 actionAdvancedOptions
->setData(4);
340 actionSourceFiles
->setChecked(true);
341 connect(m_tabActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(tabActionActivated(QAction
*)));
343 //Activate style menu actions
344 m_styleActionGroup
= new QActionGroup(this);
345 m_styleActionGroup
->addAction(actionStylePlastique
);
346 m_styleActionGroup
->addAction(actionStyleCleanlooks
);
347 m_styleActionGroup
->addAction(actionStyleWindowsVista
);
348 m_styleActionGroup
->addAction(actionStyleWindowsXP
);
349 m_styleActionGroup
->addAction(actionStyleWindowsClassic
);
350 actionStylePlastique
->setData(0);
351 actionStyleCleanlooks
->setData(1);
352 actionStyleWindowsVista
->setData(2);
353 actionStyleWindowsXP
->setData(3);
354 actionStyleWindowsClassic
->setData(4);
355 actionStylePlastique
->setChecked(true);
356 actionStyleWindowsXP
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_XP
&& lamexp_themes_enabled());
357 actionStyleWindowsVista
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_VISTA
&& lamexp_themes_enabled());
358 connect(m_styleActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(styleActionActivated(QAction
*)));
359 styleActionActivated(NULL
);
361 //Populate the language menu
362 m_languageActionGroup
= new QActionGroup(this);
363 QStringList translations
= lamexp_query_translations();
364 while(!translations
.isEmpty())
366 QString langId
= translations
.takeFirst();
367 QAction
*currentLanguage
= new QAction(this);
368 currentLanguage
->setData(langId
);
369 currentLanguage
->setText(lamexp_translation_name(langId
));
370 currentLanguage
->setIcon(QIcon(QString(":/flags/%1.png").arg(langId
)));
371 currentLanguage
->setCheckable(true);
372 m_languageActionGroup
->addAction(currentLanguage
);
373 menuLanguage
->insertAction(actionLoadTranslationFromFile
, currentLanguage
);
375 menuLanguage
->insertSeparator(actionLoadTranslationFromFile
);
376 connect(actionLoadTranslationFromFile
, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
377 connect(m_languageActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(languageActionActivated(QAction
*)));
379 //Activate tools menu actions
380 actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
381 actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
382 actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
383 actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
384 actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
385 actionDisableShellIntegration
->setDisabled(lamexp_portable_mode() && actionDisableShellIntegration
->isChecked());
386 actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta() || lamexp_version_demo());
387 actionCheckForBetaUpdates
->setEnabled(!lamexp_version_demo());
388 actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
389 actionHibernateComputer
->setEnabled(lamexp_is_hibernation_supported());
390 connect(actionDisableUpdateReminder
, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
391 connect(actionDisableSounds
, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
392 connect(actionDisableNeroAacNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
393 connect(actionDisableSlowStartupNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
394 connect(actionDisableShellIntegration
, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
395 connect(actionShowDropBoxWidget
, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
396 connect(actionHibernateComputer
, SIGNAL(triggered(bool)), this, SLOT(hibernateComputerActionTriggered(bool)));
397 connect(actionCheckForBetaUpdates
, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
398 connect(actionImportCueSheet
, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
400 //Activate help menu actions
401 actionVisitHomepage
->setData(QString::fromLatin1(lamexp_website_url()));
402 actionVisitSupport
->setData(QString::fromLatin1(lamexp_support_url()));
403 actionDocumentFAQ
->setData(QString("%1/FAQ.html").arg(QApplication::applicationDirPath()));
404 actionDocumentChangelog
->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
405 actionDocumentTranslate
->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
406 connect(actionCheckUpdates
, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
407 connect(actionVisitHomepage
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
408 connect(actionVisitSupport
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
409 connect(actionDocumentFAQ
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
410 connect(actionDocumentChangelog
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
411 connect(actionDocumentTranslate
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
413 //Center window in screen
414 QRect desktopRect
= QApplication::desktop()->screenGeometry();
415 QRect thisRect
= this->geometry();
416 move((desktopRect
.width() - thisRect
.width()) / 2, (desktopRect
.height() - thisRect
.height()) / 2);
417 setMinimumSize(thisRect
.width(), thisRect
.height());
420 m_banner
= new WorkingBanner(this);
422 //Create DropBox widget
423 m_dropBox
= new DropBox(this, m_fileListModel
, m_settings
);
424 connect(m_fileListModel
, SIGNAL(modelReset()), m_dropBox
, SLOT(modelChanged()));
425 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), m_dropBox
, SLOT(modelChanged()));
426 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), m_dropBox
, SLOT(modelChanged()));
427 connect(m_fileListModel
, SIGNAL(rowAppended()), m_dropBox
, SLOT(modelChanged()));
429 //Create message handler thread
430 m_messageHandler
= new MessageHandlerThread();
431 m_delayedFileList
= new QStringList();
432 m_delayedFileTimer
= new QTimer();
433 m_delayedFileTimer
->setSingleShot(true);
434 m_delayedFileTimer
->setInterval(5000);
435 connect(m_messageHandler
, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection
);
436 connect(m_messageHandler
, SIGNAL(fileReceived(QString
)), this, SLOT(addFileDelayed(QString
)), Qt::QueuedConnection
);
437 connect(m_messageHandler
, SIGNAL(folderReceived(QString
, bool)), this, SLOT(addFolderDelayed(QString
, bool)), Qt::QueuedConnection
);
438 connect(m_messageHandler
, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection
);
439 connect(m_delayedFileTimer
, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
440 m_messageHandler
->start();
442 //Load translation file
443 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
444 while(!languageActions
.isEmpty())
446 QAction
*currentLanguage
= languageActions
.takeFirst();
447 if(currentLanguage
->data().toString().compare(m_settings
->currentLanguage(), Qt::CaseInsensitive
) == 0)
449 currentLanguage
->setChecked(true);
450 languageActionActivated(currentLanguage
);
454 //Re-translate (make sure we translate once)
455 QEvent
languageChangeEvent(QEvent::LanguageChange
);
456 changeEvent(&languageChangeEvent
);
459 this->setAcceptDrops(true);
462 ////////////////////////////////////////////////////////////
464 ////////////////////////////////////////////////////////////
466 MainWindow::~MainWindow(void)
468 //Stop message handler thread
469 if(m_messageHandler
&& m_messageHandler
->isRunning())
471 m_messageHandler
->stop();
472 if(!m_messageHandler
->wait(2500))
474 m_messageHandler
->terminate();
475 m_messageHandler
->wait();
480 SET_MODEL(sourceFileView
, NULL
);
481 SET_MODEL(outputFolderView
, NULL
);
482 SET_MODEL(metaDataView
, NULL
);
485 LAMEXP_DELETE(m_tabActionGroup
);
486 LAMEXP_DELETE(m_styleActionGroup
);
487 LAMEXP_DELETE(m_languageActionGroup
);
488 LAMEXP_DELETE(m_banner
);
489 LAMEXP_DELETE(m_fileSystemModel
);
490 LAMEXP_DELETE(m_messageHandler
);
491 LAMEXP_DELETE(m_delayedFileList
);
492 LAMEXP_DELETE(m_delayedFileTimer
);
493 LAMEXP_DELETE(m_metaInfoModel
);
494 LAMEXP_DELETE(m_encoderButtonGroup
);
495 LAMEXP_DELETE(m_encoderButtonGroup
);
496 LAMEXP_DELETE(m_sourceFilesContextMenu
);
497 LAMEXP_DELETE(m_outputFolderFavoritesMenu
);
498 LAMEXP_DELETE(m_outputFolderContextMenu
);
499 LAMEXP_DELETE(m_dropBox
);
502 ////////////////////////////////////////////////////////////
504 ////////////////////////////////////////////////////////////
507 * Add file to source list
509 void MainWindow::addFiles(const QStringList
&files
)
516 tabWidget
->setCurrentIndex(0);
518 FileAnalyzer
*analyzer
= new FileAnalyzer(files
);
519 connect(analyzer
, SIGNAL(fileSelected(QString
)), m_banner
, SLOT(setText(QString
)), Qt::QueuedConnection
);
520 connect(analyzer
, SIGNAL(progressValChanged(unsigned int)), m_banner
, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection
);
521 connect(analyzer
, SIGNAL(progressMaxChanged(unsigned int)), m_banner
, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection
);
522 connect(analyzer
, SIGNAL(fileAnalyzed(AudioFileModel
)), m_fileListModel
, SLOT(addFile(AudioFileModel
)), Qt::QueuedConnection
);
523 connect(m_banner
, SIGNAL(userAbort()), analyzer
, SLOT(abortProcess()), Qt::DirectConnection
);
527 m_fileListModel
->setBlockUpdates(true);
528 m_banner
->show(tr("Adding file(s), please wait..."), analyzer
);
532 /* ignore any exceptions that may occur */
535 m_fileListModel
->setBlockUpdates(false);
536 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
537 sourceFileView
->update();
538 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
539 sourceFileView
->scrollToBottom();
540 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
542 if(analyzer
->filesDenied())
544 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."))));
546 if(analyzer
->filesDummyCDDA())
548 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>"))));
550 if(analyzer
->filesCueSheet())
552 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."))));
554 if(analyzer
->filesRejected())
556 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."))));
559 LAMEXP_DELETE(analyzer
);
564 * Add folder to source list
566 void MainWindow::addFolder(const QString
&path
, bool recursive
, bool delayed
)
568 QFileInfoList folderInfoList
;
569 folderInfoList
<< QFileInfo(path
);
570 QStringList fileList
;
572 m_banner
->show(tr("Scanning folder(s) for files, please wait..."));
574 QApplication::processEvents();
575 GetAsyncKeyState(VK_ESCAPE
);
577 while(!folderInfoList
.isEmpty())
579 if(GetAsyncKeyState(VK_ESCAPE
) & 0x0001)
581 MessageBeep(MB_ICONERROR
);
582 qWarning("Operation cancelled by user!");
587 QDir
currentDir(folderInfoList
.takeFirst().canonicalFilePath());
588 QFileInfoList fileInfoList
= currentDir
.entryInfoList(QDir::Files
| QDir::NoSymLinks
);
590 while(!fileInfoList
.isEmpty())
592 fileList
<< fileInfoList
.takeFirst().canonicalFilePath();
595 QApplication::processEvents();
599 folderInfoList
.append(currentDir
.entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
));
600 QApplication::processEvents();
605 QApplication::processEvents();
607 if(!fileList
.isEmpty())
611 addFilesDelayed(fileList
);
623 bool MainWindow::checkForUpdates(void)
625 bool bReadyToInstall
= false;
627 UpdateDialog
*updateDialog
= new UpdateDialog(m_settings
, this);
628 updateDialog
->exec();
630 if(updateDialog
->getSuccess())
632 m_settings
->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate
));
633 bReadyToInstall
= updateDialog
->updateReadyToInstall();
636 LAMEXP_DELETE(updateDialog
);
637 return bReadyToInstall
;
640 void MainWindow::refreshFavorites(void)
642 QList
<QAction
*> folderList
= m_outputFolderFavoritesMenu
->actions();
643 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
644 while(favorites
.count() > 6) favorites
.removeFirst();
646 while(!folderList
.isEmpty())
648 QAction
*currentItem
= folderList
.takeFirst();
649 if(currentItem
->isSeparator()) break;
650 m_outputFolderFavoritesMenu
->removeAction(currentItem
);
651 LAMEXP_DELETE(currentItem
);
654 QAction
*lastItem
= m_outputFolderFavoritesMenu
->actions().first();
656 while(!favorites
.isEmpty())
658 QString path
= favorites
.takeLast();
659 if(QDir(path
).exists())
661 QAction
*action
= new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path
), this);
662 action
->setData(path
);
663 m_outputFolderFavoritesMenu
->insertAction(lastItem
, action
);
664 connect(action
, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
670 ////////////////////////////////////////////////////////////
672 ////////////////////////////////////////////////////////////
675 * Window is about to be shown
677 void MainWindow::showEvent(QShowEvent
*event
)
680 m_dropNoteLabel
->setGeometry(0, 0, sourceFileView
->width(), sourceFileView
->height());
681 sourceModelChanged();
683 if(!event
->spontaneous())
685 tabWidget
->setCurrentIndex(0);
690 m_firstTimeShown
= false;
691 QTimer::singleShot(0, this, SLOT(windowShown()));
695 if(m_settings
->dropBoxWidgetEnabled())
697 m_dropBox
->setVisible(true);
703 * Re-translate the UI
705 void MainWindow::changeEvent(QEvent
*e
)
707 if(e
->type() == QEvent::LanguageChange
)
709 int comboBoxIndex
[6];
711 //Backup combobox indices, as retranslateUi() resets
712 comboBoxIndex
[0] = comboBoxMP3ChannelMode
->currentIndex();
713 comboBoxIndex
[1] = comboBoxSamplingRate
->currentIndex();
714 comboBoxIndex
[2] = comboBoxAACProfile
->currentIndex();
715 comboBoxIndex
[3] = comboBoxAftenCodingMode
->currentIndex();
716 comboBoxIndex
[4] = comboBoxAftenDRCMode
->currentIndex();
717 comboBoxIndex
[5] = comboBoxNormalizationMode
->currentIndex();
719 //Re-translate from UIC
720 Ui::MainWindow::retranslateUi(this);
722 //Restore combobox indices
723 comboBoxMP3ChannelMode
->setCurrentIndex(comboBoxIndex
[0]);
724 comboBoxSamplingRate
->setCurrentIndex(comboBoxIndex
[1]);
725 comboBoxAACProfile
->setCurrentIndex(comboBoxIndex
[2]);
726 comboBoxAftenCodingMode
->setCurrentIndex(comboBoxIndex
[3]);
727 comboBoxAftenDRCMode
->setCurrentIndex(comboBoxIndex
[4]);
728 comboBoxNormalizationMode
->setCurrentIndex(comboBoxIndex
[5]);
730 //Update the window title
733 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
735 else if(lamexp_version_demo())
737 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
740 //Manually re-translate widgets that UIC doesn't handle
741 m_dropNoteLabel
->setText(QString("» %1 «").arg(tr("You can drop in audio files here!")));
742 m_outputFolderNoteBox
->setText(tr("Initializing directory outline, please be patient..."));
743 m_showDetailsContextAction
->setText(tr("Show Details"));
744 m_previewContextAction
->setText(tr("Open File in External Application"));
745 m_findFileContextAction
->setText(tr("Browse File Location"));
746 m_showFolderContextAction
->setText(tr("Browse Selected Folder"));
747 m_refreshFolderContextAction
->setText(tr("Refresh Directory Outline"));
748 m_addFavoriteFolderAction
->setText(tr("Bookmark Current Output Folder"));
749 m_exportCsvContextAction
->setText(tr("Export Meta Tags to CSV File"));
750 m_importCsvContextAction
->setText(tr("Import Meta Tags from CSV File"));
753 m_metaInfoModel
->clearData();
754 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
755 updateEncoder(m_settings
->compressionEncoder());
756 updateLameAlgoQuality(sliderLameAlgoQuality
->value());
757 updateMaximumInstances(sliderMaxInstances
->value());
758 renameOutputPatternChanged(lineEditRenamePattern
->text());
760 //Re-install shell integration
761 if(m_settings
->shellIntegrationEnabled())
763 ShellIntegration::install();
766 //Force resize, if needed
767 tabPageChanged(tabWidget
->currentIndex());
772 * File dragged over window
774 void MainWindow::dragEnterEvent(QDragEnterEvent
*event
)
776 QStringList formats
= event
->mimeData()->formats();
778 if(formats
.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive
) && formats
.contains("text/uri-list", Qt::CaseInsensitive
))
780 event
->acceptProposedAction();
785 * File dropped onto window
787 void MainWindow::dropEvent(QDropEvent
*event
)
791 QStringList droppedFiles
;
792 QList
<QUrl
> urls
= event
->mimeData()->urls();
794 while(!urls
.isEmpty())
796 QUrl currentUrl
= urls
.takeFirst();
797 QFileInfo
file(currentUrl
.toLocalFile());
804 qDebug("Dropped File: %s", file
.canonicalFilePath().toUtf8().constData());
805 droppedFiles
<< file
.canonicalFilePath();
810 qDebug("Dropped Folder: %s", file
.canonicalFilePath().toUtf8().constData());
811 QList
<QFileInfo
> list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Files
| QDir::NoSymLinks
);
814 for(int j
= 0; j
< list
.count(); j
++)
816 droppedFiles
<< list
.at(j
).canonicalFilePath();
821 list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
);
822 for(int j
= 0; j
< list
.count(); j
++)
824 qDebug("Descending to Folder: %s", list
.at(j
).canonicalFilePath().toUtf8().constData());
825 urls
.prepend(QUrl::fromLocalFile(list
.at(j
).canonicalFilePath()));
831 if(!droppedFiles
.isEmpty())
833 addFilesDelayed(droppedFiles
, true);
838 * Window tries to close
840 void MainWindow::closeEvent(QCloseEvent
*event
)
842 if(m_banner
->isVisible() || m_delayedFileTimer
->isActive())
844 MessageBeep(MB_ICONEXCLAMATION
);
857 void MainWindow::resizeEvent(QResizeEvent
*event
)
859 if(event
) QMainWindow::resizeEvent(event
);
860 m_dropNoteLabel
->setGeometry(0, 0, sourceFileView
->width(), sourceFileView
->height());
862 if(QWidget
*port
= outputFolderView
->viewport())
864 m_outputFolderNoteBox
->setGeometry(16, (port
->height() - 64) / 2, port
->width() - 32, 64);
869 * Key press event filter
871 void MainWindow::keyPressEvent(QKeyEvent
*e
)
873 if(e
->key() == Qt::Key_F5
)
875 if(outputFolderView
->isVisible())
877 QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
882 if(e
->key() == Qt::Key_Delete
)
884 if(sourceFileView
->isVisible())
886 QTimer::singleShot(0, this, SLOT(removeFileButtonClicked()));
891 QMainWindow::keyPressEvent(e
);
897 bool MainWindow::eventFilter(QObject
*obj
, QEvent
*event
)
899 if(obj
== m_fileSystemModel
)
901 if(QApplication::overrideCursor() == NULL
)
903 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
904 QTimer::singleShot(250, this, SLOT(restoreCursor()));
907 else if(obj
== outputFolderView
)
909 switch(event
->type())
913 case QEvent::KeyPress
:
914 case QEvent::KeyRelease
:
915 case QEvent::FocusIn
:
916 case QEvent::FocusOut
:
917 case QEvent::TouchEnd
:
918 outputFolderViewClicked(outputFolderView
->currentIndex());
922 else if(obj
== outputFolderLabel
)
924 switch(event
->type())
926 case QEvent::MouseButtonPress
:
927 if(dynamic_cast<QMouseEvent
*>(event
)->button() == Qt::LeftButton
)
929 QString path
= outputFolderLabel
->text();
930 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
931 ShellExecuteW(reinterpret_cast<HWND
>(this->winId()), L
"explore", QWCHAR(path
), NULL
, NULL
, SW_SHOW
);
935 outputFolderLabel
->setForegroundRole(QPalette::Link
);
938 outputFolderLabel
->setForegroundRole(QPalette::WindowText
);
942 else if(obj
== outputFoldersFovoritesLabel
)
944 QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
);
945 QPoint pos
= (mouseEvent
!= NULL
) ? mouseEvent
->pos() : QPoint();
946 QWidget
*sender
= dynamic_cast<QLabel
*>(obj
);
948 switch(event
->type())
951 outputFoldersFovoritesLabel
->setFrameShadow(QFrame::Raised
);
953 case QEvent::MouseButtonPress
:
954 outputFoldersFovoritesLabel
->setFrameShadow(QFrame::Sunken
);
956 case QEvent::MouseButtonRelease
:
957 outputFoldersFovoritesLabel
->setFrameShadow(QFrame::Raised
);
958 if(sender
&& mouseEvent
)
960 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
)
962 if(outputFolderView
->isEnabled())
964 m_outputFolderFavoritesMenu
->popup(sender
->mapToGlobal(pos
));
970 outputFoldersFovoritesLabel
->setFrameShadow(QFrame::Plain
);
974 else if(obj
== outputFoldersEditorLabel
)
976 QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
);
977 QPoint pos
= (mouseEvent
!= NULL
) ? mouseEvent
->pos() : QPoint();
978 QWidget
*sender
= dynamic_cast<QLabel
*>(obj
);
980 switch(event
->type())
983 outputFoldersEditorLabel
->setFrameShadow(QFrame::Raised
);
985 case QEvent::MouseButtonPress
:
986 outputFoldersEditorLabel
->setFrameShadow(QFrame::Sunken
);
988 case QEvent::MouseButtonRelease
:
989 outputFoldersEditorLabel
->setFrameShadow(QFrame::Raised
);
990 if(sender
&& mouseEvent
)
992 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
)
994 if(outputFolderView
->isEnabled())
996 outputFolderView
->setEnabled(false);
997 outputFolderLabel
->setVisible(false);
998 outputFolderEdit
->setVisible(true);
999 outputFolderEdit
->setText(outputFolderLabel
->text());
1000 outputFolderEdit
->selectAll();
1001 outputFolderEdit
->setFocus();
1007 outputFoldersEditorLabel
->setFrameShadow(QFrame::Plain
);
1012 return QMainWindow::eventFilter(obj
, event
);
1015 bool MainWindow::event(QEvent
*e
)
1019 case lamexp_event_queryendsession
:
1020 qWarning("System is shutting down, main window prepares to close...");
1021 if(m_banner
->isVisible()) m_banner
->close();
1022 if(m_delayedFileTimer
->isActive()) m_delayedFileTimer
->stop();
1024 case lamexp_event_endsession
:
1025 qWarning("System is shutting down, main window will close now...");
1030 QApplication::processEvents(QEventLoop::WaitForMoreEvents
& QEventLoop::ExcludeUserInputEvents
);
1033 m_fileListModel
->clearFiles();
1035 case QEvent::MouseButtonPress
:
1036 if(outputFolderEdit
->isVisible())
1038 QTimer::singleShot(0, this, SLOT(outputFolderEditFinished()));
1041 return QMainWindow::event(e
);
1045 bool MainWindow::winEvent(MSG
*message
, long *result
)
1047 return WinSevenTaskbar::handleWinEvent(message
, result
);
1050 ////////////////////////////////////////////////////////////
1052 ////////////////////////////////////////////////////////////
1054 // =========================================================
1055 // Show window slots
1056 // =========================================================
1061 void MainWindow::windowShown(void)
1063 QStringList arguments
= QApplication::arguments();
1066 bool firstRun
= false;
1067 for(int i
= 0; i
< arguments
.count(); i
++)
1069 if(!arguments
[i
].compare("--first-run", Qt::CaseInsensitive
)) firstRun
= true;
1073 if((m_settings
->licenseAccepted() <= 0) || firstRun
)
1077 if((m_settings
->licenseAccepted() == 0) || firstRun
)
1079 AboutDialog
*about
= new AboutDialog(m_settings
, this, true);
1080 iAccepted
= about
->exec();
1081 LAMEXP_DELETE(about
);
1086 m_settings
->licenseAccepted(-1);
1087 QApplication::processEvents();
1088 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1089 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
1090 QFileInfo uninstallerInfo
= QFileInfo(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()));
1091 if(uninstallerInfo
.exists())
1093 QString uninstallerDir
= uninstallerInfo
.canonicalPath();
1094 QString uninstallerPath
= uninstallerInfo
.canonicalFilePath();
1095 for(int i
= 0; i
< 3; i
++)
1097 HINSTANCE res
= ShellExecuteW(reinterpret_cast<HWND
>(this->winId()), L
"open", QWCHAR(QDir::toNativeSeparators(uninstallerPath
)), L
"/Force", QWCHAR(QDir::toNativeSeparators(uninstallerDir
)), SW_SHOWNORMAL
);
1098 if(reinterpret_cast<int>(res
) > 32) break;
1103 MoveFileEx(QWCHAR(QDir::toNativeSeparators(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath())), NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
| MOVEFILE_REPLACE_EXISTING
);
1105 QApplication::quit();
1109 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WOOHOO
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1110 m_settings
->licenseAccepted(1);
1111 if(lamexp_version_demo()) showAnnounceBox();
1114 //Check for expiration
1115 if(lamexp_version_demo())
1117 if(QDate::currentDate() >= lamexp_version_expires())
1119 qWarning("Binary has expired !!!");
1120 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1121 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)
1125 QApplication::quit();
1130 //Slow startup indicator
1131 if(m_settings
->slowStartup() && m_settings
->antivirNotificationsEnabled())
1134 message
+= NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
1135 message
+= NOBR(tr("Please refer to the %1 document for details and solutions!")).arg("<a href=\"http://lamexp.git.sourceforge.net/git/gitweb.cgi?p=lamexp/lamexp;a=blob_plain;f=doc/FAQ.html;hb=HEAD#df406578\">F.A.Q.</a>").append("<br>");
1136 if(QMessageBox::warning(this, tr("Slow Startup"), message
, tr("Discard"), tr("Don't Show Again")) == 1)
1138 m_settings
->antivirNotificationsEnabled(false);
1139 actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
1144 if(QDate::currentDate() >= lamexp_version_date().addYears(1))
1146 qWarning("Binary is more than a year old, time to update!");
1147 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"));
1151 if(checkForUpdates())
1153 QApplication::quit();
1158 QApplication::quit();
1161 QEventLoop loop
; QTimer::singleShot(7000, &loop
, SLOT(quit()));
1162 PlaySound(MAKEINTRESOURCE(IDR_WAVE_WAITING
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_ASYNC
);
1163 m_banner
->show(tr("Skipping update check this time, please be patient..."), &loop
);
1167 else if(m_settings
->autoUpdateEnabled())
1169 QDate lastUpdateCheck
= QDate::fromString(m_settings
->autoUpdateLastCheck(), Qt::ISODate
);
1170 if(!firstRun
&& (!lastUpdateCheck
.isValid() || QDate::currentDate() >= lastUpdateCheck
.addDays(14)))
1172 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)
1174 if(checkForUpdates())
1176 QApplication::quit();
1183 //Check for AAC support
1184 if(m_neroEncoderAvailable
)
1186 if(m_settings
->neroAacNotificationsEnabled())
1188 if(lamexp_tool_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1190 QString messageText
;
1191 messageText
+= NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1192 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>");
1193 messageText
+= NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1194 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br><br>";
1195 messageText
+= NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
1196 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText
);
1202 if(m_settings
->neroAacNotificationsEnabled() && (!(m_fhgEncoderAvailable
|| m_qaacEncoderAvailable
)))
1204 QString appPath
= QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1205 if(appPath
.isEmpty()) appPath
= QCoreApplication::applicationDirPath();
1206 QString messageText
;
1207 messageText
+= NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1208 messageText
+= NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1209 messageText
+= NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1210 messageText
+= QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath
)));
1211 messageText
+= NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1212 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br>";
1213 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText
, tr("Discard"), tr("Don't Show Again")) == 1)
1215 m_settings
->neroAacNotificationsEnabled(false);
1216 actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1221 //Add files from the command-line
1222 for(int i
= 0; i
< arguments
.count() - 1; i
++)
1224 QStringList addedFiles
;
1225 if(!arguments
[i
].compare("--add", Qt::CaseInsensitive
))
1227 QFileInfo
currentFile(arguments
[++i
].trimmed());
1228 qDebug("Adding file from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1229 addedFiles
.append(currentFile
.absoluteFilePath());
1231 if(!addedFiles
.isEmpty())
1233 addFilesDelayed(addedFiles
);
1237 //Add folders from the command-line
1238 for(int i
= 0; i
< arguments
.count() - 1; i
++)
1240 if(!arguments
[i
].compare("--add-folder", Qt::CaseInsensitive
))
1242 QFileInfo
currentFile(arguments
[++i
].trimmed());
1243 qDebug("Adding folder from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1244 addFolder(currentFile
.absoluteFilePath(), false, true);
1246 if(!arguments
[i
].compare("--add-recursive", Qt::CaseInsensitive
))
1248 QFileInfo
currentFile(arguments
[++i
].trimmed());
1249 qDebug("Adding folder recursively from CLI: %s", currentFile
.absoluteFilePath().toUtf8().constData());
1250 addFolder(currentFile
.absoluteFilePath(), true, true);
1254 //Enable shell integration
1255 if(m_settings
->shellIntegrationEnabled())
1257 ShellIntegration::install();
1260 //Make DropBox visible
1261 if(m_settings
->dropBoxWidgetEnabled())
1263 m_dropBox
->setVisible(true);
1270 void MainWindow::showAnnounceBox(void)
1272 const unsigned int timeout
= 8U;
1274 const QString announceText
= QString("%1<br><br>%2<br><nobr><tt>%3</tt></nobr><br>").arg
1276 NOBR("We are still looking for LameXP translators!"),
1277 NOBR("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:"),
1278 LINK("http://mulder.brhack.net/public/doc/lamexp_translate.html")
1281 QMessageBox
*announceBox
= new QMessageBox(QMessageBox::Warning
, "We want you!", announceText
, QMessageBox::NoButton
, this);
1282 announceBox
->setWindowFlags(Qt::Window
| Qt::WindowTitleHint
| Qt::CustomizeWindowHint
);
1283 announceBox
->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1285 QTimer
*timers
[timeout
+1];
1286 QPushButton
*buttons
[timeout
+1];
1288 for(unsigned int i
= 0; i
<= timeout
; i
++)
1290 QString text
= (i
> 0) ? QString("%1 (%2)").arg(tr("Discard"), QString::number(i
)) : tr("Discard");
1291 buttons
[i
] = announceBox
->addButton(text
, (i
> 0) ? QMessageBox::NoRole
: QMessageBox::AcceptRole
);
1294 for(unsigned int i
= 0; i
<= timeout
; i
++)
1296 buttons
[i
]->setEnabled(i
== 0);
1297 buttons
[i
]->setVisible(i
== timeout
);
1300 for(unsigned int i
= 0; i
< timeout
; i
++)
1302 timers
[i
] = new QTimer(this);
1303 timers
[i
]->setSingleShot(true);
1304 timers
[i
]->setInterval(1000);
1305 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
+1], SLOT(hide()));
1306 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
], SLOT(show()));
1309 connect(timers
[i
], SIGNAL(timeout()), timers
[i
-1], SLOT(start()));
1313 timers
[timeout
-1]->start();
1314 announceBox
->exec();
1316 for(unsigned int i
= 0; i
< timeout
; i
++)
1319 LAMEXP_DELETE(timers
[i
]);
1322 LAMEXP_DELETE(announceBox
);
1325 // =========================================================
1326 // Main button solots
1327 // =========================================================
1332 void MainWindow::encodeButtonClicked(void)
1334 static const unsigned __int64 oneGigabyte
= 1073741824ui
64;
1335 static const unsigned __int64 minimumFreeDiskspaceMultiplier
= 2ui
64;
1336 static const char *writeTestBuffer
= "LAMEXP_WRITE_TEST";
1340 if(m_fileListModel
->rowCount() < 1)
1342 QMessageBox::warning(this, tr("LameXP"), NOBR(tr("You must add at least one file to the list before proceeding!")));
1343 tabWidget
->setCurrentIndex(0);
1347 QString tempFolder
= m_settings
->customTempPathEnabled() ? m_settings
->customTempPath() : lamexp_temp_folder2();
1348 if(!QFileInfo(tempFolder
).exists() || !QFileInfo(tempFolder
).isDir())
1350 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)
1352 while(checkBoxUseSystemTempFolder
->isChecked() == m_settings
->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder
->click();
1358 unsigned __int64 currentFreeDiskspace
= lamexp_free_diskspace(tempFolder
, &ok
);
1360 if(ok
&& (currentFreeDiskspace
< (oneGigabyte
* minimumFreeDiskspaceMultiplier
)))
1362 QStringList tempFolderParts
= tempFolder
.split("/", QString::SkipEmptyParts
, Qt::CaseInsensitive
);
1363 tempFolderParts
.takeLast();
1364 if(m_settings
->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY
), GetModuleHandle(NULL
), SND_RESOURCE
| SND_SYNC
);
1365 QString lowDiskspaceMsg
= QString("%1<br>%2<br><br>%3<br>%4<br>").arg
1367 NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier
))),
1368 NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")),
1369 NOBR(tr("Your TEMP folder is located at:")),
1370 QString("<nobr><tt>%1</tt></nobr>").arg(FSLINK(tempFolderParts
.join("\\")))
1372 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg
, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1375 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(lamexp_known_folder(lamexp_folder_systemfolder
)), QStringList() << "/D" << tempFolderParts
.first());
1380 QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!")));
1385 switch(m_settings
->compressionEncoder())
1387 case SettingsModel::MP3Encoder
:
1388 case SettingsModel::VorbisEncoder
:
1389 case SettingsModel::AACEncoder
:
1390 case SettingsModel::AC3Encoder
:
1391 case SettingsModel::FLACEncoder
:
1392 case SettingsModel::DCAEncoder
:
1393 case SettingsModel::PCMEncoder
:
1396 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1397 tabWidget
->setCurrentIndex(3);
1401 if(!m_settings
->outputToSourceDir())
1403 QFile
writeTest(QString("%1/~%2.txt").arg(m_settings
->outputDir(), lamexp_rand_str()));
1404 if(!(writeTest
.open(QIODevice::ReadWrite
) && (writeTest
.write(writeTestBuffer
) == strlen(writeTestBuffer
))))
1406 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!")));
1407 tabWidget
->setCurrentIndex(1);
1424 void MainWindow::aboutButtonClicked(void)
1430 AboutDialog
*aboutBox
= new AboutDialog(m_settings
, this);
1432 LAMEXP_DELETE(aboutBox
);
1439 void MainWindow::closeButtonClicked(void)
1445 // =========================================================
1447 // =========================================================
1452 void MainWindow::tabPageChanged(int idx
)
1456 QList
<QAction
*> actions
= m_tabActionGroup
->actions();
1457 for(int i
= 0; i
< actions
.count(); i
++)
1460 int actionIndex
= actions
.at(i
)->data().toInt(&ok
);
1461 if(ok
&& actionIndex
== idx
)
1463 actions
.at(i
)->setChecked(true);
1467 int initialWidth
= this->width();
1468 int maximumWidth
= QApplication::desktop()->width();
1470 if(this->isVisible())
1472 while(tabWidget
->width() < tabWidget
->sizeHint().width())
1474 int previousWidth
= this->width();
1475 this->resize(this->width() + 1, this->height());
1476 if(this->frameGeometry().width() >= maximumWidth
) break;
1477 if(this->width() <= previousWidth
) break;
1481 if(idx
== tabWidget
->indexOf(tabOptions
) && scrollArea
->widget() && this->isVisible())
1483 for(int i
= 0; i
< 2; i
++)
1485 QApplication::processEvents();
1486 while(scrollArea
->viewport()->width() < scrollArea
->widget()->width())
1488 int previousWidth
= this->width();
1489 this->resize(this->width() + 1, this->height());
1490 if(this->frameGeometry().width() >= maximumWidth
) break;
1491 if(this->width() <= previousWidth
) break;
1495 else if(idx
== tabWidget
->indexOf(tabSourceFiles
))
1497 m_dropNoteLabel
->setGeometry(0, 0, sourceFileView
->width(), sourceFileView
->height());
1499 else if(idx
== tabWidget
->indexOf(tabOutputDir
))
1501 if(!m_fileSystemModel
)
1503 QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
1507 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
1511 if(initialWidth
< this->width())
1513 QPoint prevPos
= this->pos();
1514 int delta
= (this->width() - initialWidth
) >> 2;
1515 move(prevPos
.x() - delta
, prevPos
.y());
1520 * Tab action triggered
1522 void MainWindow::tabActionActivated(QAction
*action
)
1524 if(action
&& action
->data().isValid())
1527 int index
= action
->data().toInt(&ok
);
1530 tabWidget
->setCurrentIndex(index
);
1535 // =========================================================
1537 // =========================================================
1540 * Style action triggered
1542 void MainWindow::styleActionActivated(QAction
*action
)
1544 //Change style setting
1545 if(action
&& action
->data().isValid())
1548 int actionIndex
= action
->data().toInt(&ok
);
1551 m_settings
->interfaceStyle(actionIndex
);
1555 //Set up the new style
1556 switch(m_settings
->interfaceStyle())
1559 if(actionStyleCleanlooks
->isEnabled())
1561 actionStyleCleanlooks
->setChecked(true);
1562 QApplication::setStyle(new QCleanlooksStyle());
1566 if(actionStyleWindowsVista
->isEnabled())
1568 actionStyleWindowsVista
->setChecked(true);
1569 QApplication::setStyle(new QWindowsVistaStyle());
1573 if(actionStyleWindowsXP
->isEnabled())
1575 actionStyleWindowsXP
->setChecked(true);
1576 QApplication::setStyle(new QWindowsXPStyle());
1580 if(actionStyleWindowsClassic
->isEnabled())
1582 actionStyleWindowsClassic
->setChecked(true);
1583 QApplication::setStyle(new QWindowsStyle());
1587 actionStylePlastique
->setChecked(true);
1588 QApplication::setStyle(new QPlastiqueStyle());
1592 //Force re-translate after style change
1593 if(QEvent
*e
= new QEvent(QEvent::LanguageChange
))
1601 * Language action triggered
1603 void MainWindow::languageActionActivated(QAction
*action
)
1605 if(action
->data().type() == QVariant::String
)
1607 QString langId
= action
->data().toString();
1609 if(lamexp_install_translator(langId
))
1611 action
->setChecked(true);
1612 m_settings
->currentLanguage(langId
);
1618 * Load language from file action triggered
1620 void MainWindow::languageFromFileActionActivated(bool checked
)
1622 QFileDialog
dialog(this, tr("Load Translation"));
1623 dialog
.setFileMode(QFileDialog::ExistingFile
);
1624 dialog
.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
1628 QStringList selectedFiles
= dialog
.selectedFiles();
1629 if(lamexp_install_translator_from_file(selectedFiles
.first()))
1631 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
1632 while(!actions
.isEmpty())
1634 actions
.takeFirst()->setChecked(false);
1639 languageActionActivated(m_languageActionGroup
->actions().first());
1644 // =========================================================
1646 // =========================================================
1649 * Disable update reminder action
1651 void MainWindow::disableUpdateReminderActionTriggered(bool checked
)
1655 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))
1657 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!"))));
1658 m_settings
->autoUpdateEnabled(false);
1662 m_settings
->autoUpdateEnabled(true);
1667 QMessageBox::information(this, tr("Update Reminder"), NOBR(tr("The update reminder has been re-enabled.")));
1668 m_settings
->autoUpdateEnabled(true);
1671 actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
1675 * Disable sound effects action
1677 void MainWindow::disableSoundsActionTriggered(bool checked
)
1681 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))
1683 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("All sound effects have been disabled.")));
1684 m_settings
->soundsEnabled(false);
1688 m_settings
->soundsEnabled(true);
1693 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("The sound effects have been re-enabled.")));
1694 m_settings
->soundsEnabled(true);
1697 actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
1701 * Disable Nero AAC encoder action
1703 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked
)
1707 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))
1709 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("All Nero AAC Encoder notifications have been disabled.")));
1710 m_settings
->neroAacNotificationsEnabled(false);
1714 m_settings
->neroAacNotificationsEnabled(true);
1719 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("The Nero AAC Encoder notifications have been re-enabled.")));
1720 m_settings
->neroAacNotificationsEnabled(true);
1723 actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1727 * Disable slow startup action
1729 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked
)
1733 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))
1735 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been disabled.")));
1736 m_settings
->antivirNotificationsEnabled(false);
1740 m_settings
->antivirNotificationsEnabled(true);
1745 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been re-enabled.")));
1746 m_settings
->antivirNotificationsEnabled(true);
1749 actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
1753 * Import a Cue Sheet file
1755 void MainWindow::importCueSheetActionTriggered(bool checked
)
1764 QString selectedCueFile
;
1766 if(USE_NATIVE_FILE_DIALOG
)
1768 selectedCueFile
= QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings
->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1772 QFileDialog
dialog(this, tr("Open Cue Sheet"));
1773 dialog
.setFileMode(QFileDialog::ExistingFile
);
1774 dialog
.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
1775 dialog
.setDirectory(m_settings
->mostRecentInputPath());
1778 selectedCueFile
= dialog
.selectedFiles().first();
1782 if(!selectedCueFile
.isEmpty())
1784 m_settings
->mostRecentInputPath(QFileInfo(selectedCueFile
).canonicalPath());
1785 CueImportDialog
*cueImporter
= new CueImportDialog(this, m_fileListModel
, selectedCueFile
);
1786 result
= cueImporter
->exec();
1787 LAMEXP_DELETE(cueImporter
);
1790 if(result
!= (-1)) break;
1796 * Show the "drop box" widget
1798 void MainWindow::showDropBoxWidgetActionTriggered(bool checked
)
1800 m_settings
->dropBoxWidgetEnabled(true);
1802 if(!m_dropBox
->isVisible())
1807 lamexp_blink_window(m_dropBox
);
1811 * Check for beta (pre-release) updates
1813 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked
)
1815 bool checkUpdatesNow
= false;
1819 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))
1821 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")))
1823 checkUpdatesNow
= true;
1825 m_settings
->autoUpdateCheckBeta(true);
1829 m_settings
->autoUpdateCheckBeta(false);
1834 QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on.")));
1835 m_settings
->autoUpdateCheckBeta(false);
1838 actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta());
1842 if(checkForUpdates())
1844 QApplication::quit();
1850 * Hibernate computer action
1852 void MainWindow::hibernateComputerActionTriggered(bool checked
)
1856 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))
1858 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will hibernate the computer on shutdown from now on.")));
1859 m_settings
->hibernateComputer(true);
1863 m_settings
->hibernateComputer(false);
1868 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will <i>not</i> hibernate the computer on shutdown from now on.")));
1869 m_settings
->hibernateComputer(false);
1872 actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
1876 * Disable shell integration action
1878 void MainWindow::disableShellIntegrationActionTriggered(bool checked
)
1882 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))
1884 ShellIntegration::remove();
1885 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been disabled.")));
1886 m_settings
->shellIntegrationEnabled(false);
1890 m_settings
->shellIntegrationEnabled(true);
1895 ShellIntegration::install();
1896 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been re-enabled.")));
1897 m_settings
->shellIntegrationEnabled(true);
1900 actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
1902 if(lamexp_portable_mode() && actionDisableShellIntegration
->isChecked())
1904 actionDisableShellIntegration
->setEnabled(false);
1908 // =========================================================
1910 // =========================================================
1913 * Visit homepage action
1915 void MainWindow::visitHomepageActionActivated(void)
1917 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
1919 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
1921 QDesktopServices::openUrl(QUrl(action
->data().toString()));
1929 void MainWindow::documentActionActivated(void)
1931 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
1933 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
1935 QFileInfo
document(action
->data().toString());
1936 QFileInfo
resource(QString(":/doc/%1.html").arg(document
.baseName()));
1937 if(document
.exists() && document
.isFile() && (document
.size() == resource
.size()))
1939 QDesktopServices::openUrl(QUrl::fromLocalFile(document
.canonicalFilePath()));
1943 QFile
source(resource
.filePath());
1944 QFile
output(QString("%1/%2.%3.html").arg(lamexp_temp_folder2(), document
.baseName(), lamexp_rand_str().left(8)));
1945 if(source
.open(QIODevice::ReadOnly
) && output
.open(QIODevice::ReadWrite
))
1947 output
.write(source
.readAll());
1948 action
->setData(output
.fileName());
1951 QDesktopServices::openUrl(QUrl::fromLocalFile(output
.fileName()));
1959 * Check for updates action
1961 void MainWindow::checkUpdatesActionActivated(void)
1968 bFlag
= checkForUpdates();
1973 QApplication::quit();
1977 // =========================================================
1978 // Source file slots
1979 // =========================================================
1982 * Add file(s) button
1984 void MainWindow::addFilesButtonClicked(void)
1990 if(USE_NATIVE_FILE_DIALOG
)
1992 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
1993 QStringList selectedFiles
= QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings
->mostRecentInputPath(), fileTypeFilters
.join(";;"));
1994 if(!selectedFiles
.isEmpty())
1996 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
1997 addFiles(selectedFiles
);
2002 QFileDialog
dialog(this, tr("Add file(s)"));
2003 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2004 dialog
.setFileMode(QFileDialog::ExistingFiles
);
2005 dialog
.setNameFilter(fileTypeFilters
.join(";;"));
2006 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2009 QStringList selectedFiles
= dialog
.selectedFiles();
2010 if(!selectedFiles
.isEmpty())
2012 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2013 addFiles(selectedFiles
);
2021 * Open folder action
2023 void MainWindow::openFolderActionActivated(void)
2026 QString selectedFolder
;
2028 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2032 if(USE_NATIVE_FILE_DIALOG
)
2034 selectedFolder
= QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings
->mostRecentInputPath());
2038 QFileDialog
dialog(this, tr("Add Folder"));
2039 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
2040 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2043 selectedFolder
= dialog
.selectedFiles().first();
2047 if(!selectedFolder
.isEmpty())
2049 m_settings
->mostRecentInputPath(QDir(selectedFolder
).canonicalPath());
2050 addFolder(selectedFolder
, action
->data().toBool());
2057 * Remove file button
2059 void MainWindow::removeFileButtonClicked(void)
2061 if(sourceFileView
->currentIndex().isValid())
2063 int iRow
= sourceFileView
->currentIndex().row();
2064 m_fileListModel
->removeFile(sourceFileView
->currentIndex());
2065 sourceFileView
->selectRow(iRow
< m_fileListModel
->rowCount() ? iRow
: m_fileListModel
->rowCount()-1);
2070 * Clear files button
2072 void MainWindow::clearFilesButtonClicked(void)
2074 m_fileListModel
->clearFiles();
2078 * Move file up button
2080 void MainWindow::fileUpButtonClicked(void)
2082 if(sourceFileView
->currentIndex().isValid())
2084 int iRow
= sourceFileView
->currentIndex().row() - 1;
2085 m_fileListModel
->moveFile(sourceFileView
->currentIndex(), -1);
2086 sourceFileView
->selectRow(iRow
>= 0 ? iRow
: 0);
2091 * Move file down button
2093 void MainWindow::fileDownButtonClicked(void)
2095 if(sourceFileView
->currentIndex().isValid())
2097 int iRow
= sourceFileView
->currentIndex().row() + 1;
2098 m_fileListModel
->moveFile(sourceFileView
->currentIndex(), 1);
2099 sourceFileView
->selectRow(iRow
< m_fileListModel
->rowCount() ? iRow
: m_fileListModel
->rowCount()-1);
2104 * Show details button
2106 void MainWindow::showDetailsButtonClicked(void)
2111 MetaInfoDialog
*metaInfoDialog
= new MetaInfoDialog(this);
2112 QModelIndex index
= sourceFileView
->currentIndex();
2114 while(index
.isValid())
2118 index
= m_fileListModel
->index(index
.row() + 1, index
.column());
2119 sourceFileView
->selectRow(index
.row());
2123 index
= m_fileListModel
->index(index
.row() - 1, index
.column());
2124 sourceFileView
->selectRow(index
.row());
2127 AudioFileModel
&file
= (*m_fileListModel
)[index
];
2130 iResult
= metaInfoDialog
->exec(file
, index
.row() > 0, index
.row() < m_fileListModel
->rowCount() - 1);
2133 if(iResult
== INT_MAX
)
2135 m_metaInfoModel
->assignInfoFrom(file
);
2136 tabWidget
->setCurrentIndex(tabWidget
->indexOf(tabMetaData
));
2143 LAMEXP_DELETE(metaInfoDialog
);
2144 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2145 sourceFilesScrollbarMoved(0);
2149 * Show context menu for source files
2151 void MainWindow::sourceFilesContextMenu(const QPoint
&pos
)
2153 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
2154 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
2158 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
2160 m_sourceFilesContextMenu
->popup(sender
->mapToGlobal(pos
));
2166 * Scrollbar of source files moved
2168 void MainWindow::sourceFilesScrollbarMoved(int)
2170 sourceFileView
->resizeColumnToContents(0);
2174 * Open selected file in external player
2176 void MainWindow::previewContextActionTriggered(void)
2178 const static char *appNames
[3] = {"smplayer_portable.exe", "smplayer.exe", "mplayer.exe"};
2179 const static wchar_t *registryKey
= L
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{DB9E4EAB-2717-499F-8D56-4CC8A644AB60}";
2181 QModelIndex index
= sourceFileView
->currentIndex();
2182 if(!index
.isValid())
2187 QString mplayerPath
;
2188 HKEY registryKeyHandle
;
2190 if(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, registryKey
, 0, KEY_READ
, ®istryKeyHandle
) == ERROR_SUCCESS
)
2192 wchar_t Buffer
[4096];
2193 DWORD BuffSize
= sizeof(wchar_t*) * 4096;
2194 if(RegQueryValueExW(registryKeyHandle
, L
"InstallLocation", 0, 0, reinterpret_cast<BYTE
*>(Buffer
), &BuffSize
) == ERROR_SUCCESS
)
2196 mplayerPath
= QString::fromUtf16(reinterpret_cast<const unsigned short*>(Buffer
));
2200 if(!mplayerPath
.isEmpty())
2202 QDir
mplayerDir(mplayerPath
);
2203 if(mplayerDir
.exists())
2205 for(int i
= 0; i
< 3; i
++)
2207 if(mplayerDir
.exists(appNames
[i
]))
2209 QProcess::startDetached(mplayerDir
.absoluteFilePath(appNames
[i
]), QStringList() << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
2216 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel
->getFile(index
).filePath()));
2220 * Find selected file in explorer
2222 void MainWindow::findFileContextActionTriggered(void)
2224 QModelIndex index
= sourceFileView
->currentIndex();
2227 QString systemRootPath
;
2229 QDir
systemRoot(lamexp_known_folder(lamexp_folder_systemfolder
));
2230 if(systemRoot
.exists() && systemRoot
.cdUp())
2232 systemRootPath
= systemRoot
.canonicalPath();
2235 if(!systemRootPath
.isEmpty())
2237 QFileInfo
explorer(QString("%1/explorer.exe").arg(systemRootPath
));
2238 if(explorer
.exists() && explorer
.isFile())
2240 QProcess::execute(explorer
.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
2246 qWarning("SystemRoot directory could not be detected!");
2252 * Add all pending files
2254 void MainWindow::handleDelayedFiles(void)
2256 m_delayedFileTimer
->stop();
2258 if(m_delayedFileList
->isEmpty())
2263 if(m_banner
->isVisible())
2265 m_delayedFileTimer
->start(5000);
2269 QStringList selectedFiles
;
2270 tabWidget
->setCurrentIndex(0);
2272 while(!m_delayedFileList
->isEmpty())
2274 QFileInfo currentFile
= QFileInfo(m_delayedFileList
->takeFirst());
2275 if(!currentFile
.exists() || !currentFile
.isFile())
2279 selectedFiles
<< currentFile
.canonicalFilePath();
2282 addFiles(selectedFiles
);
2286 * Export Meta tags to CSV file
2288 void MainWindow::exportCsvContextActionTriggered(void)
2292 QString selectedCsvFile
;
2294 if(USE_NATIVE_FILE_DIALOG
)
2296 selectedCsvFile
= QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2300 QFileDialog
dialog(this, tr("Save CSV file"));
2301 dialog
.setFileMode(QFileDialog::AnyFile
);
2302 dialog
.setAcceptMode(QFileDialog::AcceptSave
);
2303 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2304 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2307 selectedCsvFile
= dialog
.selectedFiles().first();
2311 if(!selectedCsvFile
.isEmpty())
2313 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2314 switch(m_fileListModel
->exportToCsv(selectedCsvFile
))
2316 case FileListModel::CsvError_NoTags
:
2317 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, there are no meta tags that can be exported!")));
2319 case FileListModel::CsvError_FileOpen
:
2320 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to open CSV file for writing!")));
2322 case FileListModel::CsvError_FileWrite
:
2323 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to write to the CSV file!")));
2325 case FileListModel::CsvError_OK
:
2326 QMessageBox::information(this, tr("CSV Export"), NOBR(tr("The CSV files was created successfully!")));
2329 qWarning("exportToCsv: Unknown return code!");
2337 * Import Meta tags from CSV file
2339 void MainWindow::importCsvContextActionTriggered(void)
2343 QString selectedCsvFile
;
2345 if(USE_NATIVE_FILE_DIALOG
)
2347 selectedCsvFile
= QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2351 QFileDialog
dialog(this, tr("Open CSV file"));
2352 dialog
.setFileMode(QFileDialog::ExistingFile
);
2353 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2354 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2357 selectedCsvFile
= dialog
.selectedFiles().first();
2361 if(!selectedCsvFile
.isEmpty())
2363 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2364 switch(m_fileListModel
->importFromCsv(this, selectedCsvFile
))
2366 case FileListModel::CsvError_FileOpen
:
2367 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to open CSV file for reading!")));
2369 case FileListModel::CsvError_FileRead
:
2370 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to read from the CSV file!")));
2372 case FileListModel::CsvError_NoTags
:
2373 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, the CSV file does not contain any known fields!")));
2375 case FileListModel::CsvError_Incomplete
:
2376 QMessageBox::warning(this, tr("CSV Import"), NOBR(tr("CSV file is incomplete. Not all files were updated!")));
2378 case FileListModel::CsvError_OK
:
2379 QMessageBox::information(this, tr("CSV Import"), NOBR(tr("The CSV files was imported successfully!")));
2381 case FileListModel::CsvError_Aborted
:
2382 /* User aborted, ignore! */
2385 qWarning("exportToCsv: Unknown return code!");
2392 * Show or hide Drag'n'Drop notice after model reset
2394 void MainWindow::sourceModelChanged(void)
2396 m_dropNoteLabel
->setVisible(m_fileListModel
->rowCount() <= 0);
2399 // =========================================================
2400 // Output folder slots
2401 // =========================================================
2404 * Output folder changed (mouse clicked)
2406 void MainWindow::outputFolderViewClicked(const QModelIndex
&index
)
2408 if(index
.isValid() && (outputFolderView
->currentIndex() != index
))
2410 outputFolderView
->setCurrentIndex(index
);
2413 if(m_fileSystemModel
&& index
.isValid())
2415 QString selectedDir
= m_fileSystemModel
->filePath(index
);
2416 if(selectedDir
.length() < 3) selectedDir
.append(QDir::separator());
2417 outputFolderLabel
->setText(QDir::toNativeSeparators(selectedDir
));
2418 m_settings
->outputDir(selectedDir
);
2422 outputFolderLabel
->setText(QDir::toNativeSeparators(m_settings
->outputDir()));
2427 * Output folder changed (mouse moved)
2429 void MainWindow::outputFolderViewMoved(const QModelIndex
&index
)
2431 if(QApplication::mouseButtons() & Qt::LeftButton
)
2433 outputFolderViewClicked(index
);
2438 * Goto desktop button
2440 void MainWindow::gotoDesktopButtonClicked(void)
2442 if(!m_fileSystemModel
)
2444 qWarning("File system model not initialized yet!");
2448 QString desktopPath
= QDesktopServices::storageLocation(QDesktopServices::DesktopLocation
);
2450 if(!desktopPath
.isEmpty() && QDir(desktopPath
).exists())
2452 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(desktopPath
));
2453 outputFolderViewClicked(outputFolderView
->currentIndex());
2454 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2458 buttonGotoDesktop
->setEnabled(false);
2463 * Goto home folder button
2465 void MainWindow::gotoHomeFolderButtonClicked(void)
2467 if(!m_fileSystemModel
)
2469 qWarning("File system model not initialized yet!");
2473 QString homePath
= QDesktopServices::storageLocation(QDesktopServices::HomeLocation
);
2475 if(!homePath
.isEmpty() && QDir(homePath
).exists())
2477 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(homePath
));
2478 outputFolderViewClicked(outputFolderView
->currentIndex());
2479 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2483 buttonGotoHome
->setEnabled(false);
2488 * Goto music folder button
2490 void MainWindow::gotoMusicFolderButtonClicked(void)
2492 if(!m_fileSystemModel
)
2494 qWarning("File system model not initialized yet!");
2498 QString musicPath
= QDesktopServices::storageLocation(QDesktopServices::MusicLocation
);
2500 if(!musicPath
.isEmpty() && QDir(musicPath
).exists())
2502 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(musicPath
));
2503 outputFolderViewClicked(outputFolderView
->currentIndex());
2504 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2508 buttonGotoMusic
->setEnabled(false);
2513 * Goto music favorite output folder
2515 void MainWindow::gotoFavoriteFolder(void)
2517 if(!m_fileSystemModel
)
2519 qWarning("File system model not initialized yet!");
2523 QAction
*item
= dynamic_cast<QAction
*>(QObject::sender());
2527 QDir
path(item
->data().toString());
2530 outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(path
.canonicalPath()));
2531 outputFolderViewClicked(outputFolderView
->currentIndex());
2532 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2536 MessageBeep(MB_ICONERROR
);
2537 m_outputFolderFavoritesMenu
->removeAction(item
);
2538 item
->deleteLater();
2544 * Make folder button
2546 void MainWindow::makeFolderButtonClicked(void)
2550 if(!m_fileSystemModel
)
2552 qWarning("File system model not initialized yet!");
2556 QDir
basePath(m_fileSystemModel
->fileInfo(outputFolderView
->currentIndex()).absoluteFilePath());
2557 QString suggestedName
= tr("New Folder");
2559 if(!m_metaData
->fileArtist().isEmpty() && !m_metaData
->fileAlbum().isEmpty())
2561 suggestedName
= QString("%1 - %2").arg(m_metaData
->fileArtist(), m_metaData
->fileAlbum());
2563 else if(!m_metaData
->fileArtist().isEmpty())
2565 suggestedName
= m_metaData
->fileArtist();
2567 else if(!m_metaData
->fileAlbum().isEmpty())
2569 suggestedName
= m_metaData
->fileAlbum();
2573 for(int i
= 0; i
< m_fileListModel
->rowCount(); i
++)
2575 AudioFileModel audioFile
= m_fileListModel
->getFile(m_fileListModel
->index(i
, 0));
2576 if(!audioFile
.fileAlbum().isEmpty() || !audioFile
.fileArtist().isEmpty())
2578 if(!audioFile
.fileArtist().isEmpty() && !audioFile
.fileAlbum().isEmpty())
2580 suggestedName
= QString("%1 - %2").arg(audioFile
.fileArtist(), audioFile
.fileAlbum());
2582 else if(!audioFile
.fileArtist().isEmpty())
2584 suggestedName
= audioFile
.fileArtist();
2586 else if(!audioFile
.fileAlbum().isEmpty())
2588 suggestedName
= audioFile
.fileAlbum();
2595 suggestedName
= lamexp_clean_filename(suggestedName
);
2599 bool bApplied
= false;
2600 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();
2604 folderName
= lamexp_clean_filepath(folderName
.simplified());
2606 if(folderName
.isEmpty())
2608 MessageBeep(MB_ICONERROR
);
2613 QString newFolder
= folderName
;
2615 while(basePath
.exists(newFolder
))
2617 newFolder
= QString(folderName
).append(QString().sprintf(" (%d)", ++i
));
2620 if(basePath
.mkpath(newFolder
))
2622 QDir createdDir
= basePath
;
2623 if(createdDir
.cd(newFolder
))
2625 QModelIndex newIndex
= m_fileSystemModel
->index(createdDir
.canonicalPath());
2626 outputFolderView
->setCurrentIndex(newIndex
);
2627 outputFolderViewClicked(newIndex
);
2628 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2633 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!")));
2641 * Output to source dir changed
2643 void MainWindow::saveToSourceFolderChanged(void)
2645 m_settings
->outputToSourceDir(saveToSourceFolderCheckBox
->isChecked());
2649 * Prepend relative source file path to output file name changed
2651 void MainWindow::prependRelativePathChanged(void)
2653 m_settings
->prependRelativeSourcePath(prependRelativePathCheckBox
->isChecked());
2657 * Show context menu for output folder
2659 void MainWindow::outputFolderContextMenu(const QPoint
&pos
)
2661 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
2662 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
2664 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
2666 m_outputFolderContextMenu
->popup(sender
->mapToGlobal(pos
));
2671 * Show selected folder in explorer
2673 void MainWindow::showFolderContextActionTriggered(void)
2675 if(!m_fileSystemModel
)
2677 qWarning("File system model not initialized yet!");
2681 QString path
= QDir::toNativeSeparators(m_fileSystemModel
->filePath(outputFolderView
->currentIndex()));
2682 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
2683 ShellExecuteW(reinterpret_cast<HWND
>(this->winId()), L
"explore", QWCHAR(path
), NULL
, NULL
, SW_SHOW
);
2687 * Refresh the directory outline
2689 void MainWindow::refreshFolderContextActionTriggered(void)
2691 //force re-initialization
2692 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
2696 * Add current folder to favorites
2698 void MainWindow::addFavoriteFolderActionTriggered(void)
2700 QString path
= m_fileSystemModel
->filePath(outputFolderView
->currentIndex());
2701 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
2703 if(!favorites
.contains(path
, Qt::CaseInsensitive
))
2705 favorites
.append(path
);
2706 while(favorites
.count() > 6) favorites
.removeFirst();
2710 MessageBeep(MB_ICONWARNING
);
2713 m_settings
->favoriteOutputFolders(favorites
.join("|"));
2718 * Output folder edit finished
2720 void MainWindow::outputFolderEditFinished(void)
2722 if(outputFolderEdit
->isHidden())
2724 return; //Not currently in edit mode!
2729 QString text
= QDir::fromNativeSeparators(outputFolderEdit
->text().trimmed());
2730 while(text
.startsWith('"') || text
.startsWith('/')) text
= text
.right(text
.length() - 1).trimmed();
2731 while(text
.endsWith('"') || text
.endsWith('/')) text
= text
.left(text
.length() - 1).trimmed();
2733 static const char *str
= "?*<>|\"";
2734 for(size_t i
= 0; str
[i
]; i
++) text
.replace(str
[i
], "_");
2736 if(!((text
.length() >= 2) && text
.at(0).isLetter() && text
.at(1) == QChar(':')))
2738 text
= QString("%1/%2").arg(QDir::fromNativeSeparators(outputFolderLabel
->text()), text
);
2741 if(text
.length() == 2) text
+= "/"; /* "X:" => "X:/" */
2743 while(text
.length() > 2)
2745 QFileInfo
info(text
);
2746 if(info
.exists() && info
.isDir())
2748 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalFilePath()).absoluteFilePath());
2752 outputFolderView
->setCurrentIndex(index
);
2753 outputFolderViewClicked(index
);
2757 else if(info
.exists() && info
.isFile())
2759 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalPath()).absoluteFilePath());
2763 outputFolderView
->setCurrentIndex(index
);
2764 outputFolderViewClicked(index
);
2769 text
= text
.left(text
.length() - 1).trimmed();
2772 outputFolderEdit
->setVisible(false);
2773 outputFolderLabel
->setVisible(true);
2774 outputFolderView
->setEnabled(true);
2776 if(!ok
) MessageBeep(MB_ICONERROR
);
2777 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2781 * Initialize file system model
2783 void MainWindow::initOutputFolderModel(void)
2785 if(m_outputFolderNoteBox
->isHidden())
2787 m_outputFolderNoteBox
->show();
2788 m_outputFolderNoteBox
->repaint();
2789 m_outputFolderViewInitCounter
= 4;
2791 if(m_fileSystemModel
)
2793 SET_MODEL(outputFolderView
, NULL
);
2794 LAMEXP_DELETE(m_fileSystemModel
);
2795 outputFolderView
->repaint();
2798 if(m_fileSystemModel
= new QFileSystemModelEx())
2800 m_fileSystemModel
->installEventFilter(this);
2801 connect(m_fileSystemModel
, SIGNAL(directoryLoaded(QString
)), this, SLOT(outputFolderDirectoryLoaded(QString
)));
2802 connect(m_fileSystemModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(outputFolderRowsInserted(QModelIndex
,int,int)));
2804 SET_MODEL(outputFolderView
, m_fileSystemModel
);
2805 outputFolderView
->header()->setStretchLastSection(true);
2806 outputFolderView
->header()->hideSection(1);
2807 outputFolderView
->header()->hideSection(2);
2808 outputFolderView
->header()->hideSection(3);
2810 m_fileSystemModel
->setRootPath("");
2811 QModelIndex index
= m_fileSystemModel
->index(m_settings
->outputDir());
2812 if(index
.isValid()) outputFolderView
->setCurrentIndex(index
);
2813 outputFolderViewClicked(outputFolderView
->currentIndex());
2816 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2817 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
2822 * Initialize file system model (do NOT call this one directly!)
2824 void MainWindow::initOutputFolderModel_doAsync(void)
2826 if(m_outputFolderViewInitCounter
> 0)
2828 m_outputFolderViewInitCounter
--;
2829 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
2833 QTimer::singleShot(125, m_outputFolderNoteBox
, SLOT(hide()));
2834 outputFolderView
->setFocus();
2839 * Center current folder in view
2841 void MainWindow::centerOutputFolderModel(void)
2843 if(outputFolderView
->isVisible())
2845 centerOutputFolderModel_doAsync();
2846 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel_doAsync()));
2851 * Center current folder in view (do NOT call this one directly!)
2853 void MainWindow::centerOutputFolderModel_doAsync(void)
2855 if(outputFolderView
->isVisible())
2857 m_outputFolderViewCentering
= true;
2858 const QModelIndex index
= outputFolderView
->currentIndex();
2859 outputFolderView
->scrollTo(index
, QAbstractItemView::PositionAtCenter
);
2860 outputFolderView
->setFocus();
2865 * File system model asynchronously loaded a dir
2867 void MainWindow::outputFolderDirectoryLoaded(const QString
&path
)
2869 if(m_outputFolderViewCentering
)
2871 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2876 * File system model inserted new items
2878 void MainWindow::outputFolderRowsInserted(const QModelIndex
&parent
, int start
, int end
)
2880 if(m_outputFolderViewCentering
)
2882 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2887 * Directory view item was expanded by user
2889 void MainWindow::outputFolderItemExpanded(const QModelIndex
&item
)
2891 //We need to stop centering as soon as the user has expanded an item manually!
2892 m_outputFolderViewCentering
= false;
2895 // =========================================================
2896 // Metadata tab slots
2897 // =========================================================
2900 * Edit meta button clicked
2902 void MainWindow::editMetaButtonClicked(void)
2906 const QModelIndex index
= metaDataView
->currentIndex();
2910 m_metaInfoModel
->editItem(index
, this);
2912 if(index
.row() == 4)
2914 m_settings
->metaInfoPosition(m_metaData
->filePosition());
2920 * Reset meta button clicked
2922 void MainWindow::clearMetaButtonClicked(void)
2925 m_metaInfoModel
->clearData();
2929 * Meta tags enabled changed
2931 void MainWindow::metaTagsEnabledChanged(void)
2933 m_settings
->writeMetaTags(writeMetaDataCheckBox
->isChecked());
2937 * Playlist enabled changed
2939 void MainWindow::playlistEnabledChanged(void)
2941 m_settings
->createPlaylist(generatePlaylistCheckBox
->isChecked());
2944 // =========================================================
2945 // Compression tab slots
2946 // =========================================================
2951 void MainWindow::updateEncoder(int id
)
2953 m_settings
->compressionEncoder(id
);
2955 switch(m_settings
->compressionEncoder())
2957 case SettingsModel::VorbisEncoder
:
2958 radioButtonModeQuality
->setEnabled(true);
2959 radioButtonModeAverageBitrate
->setEnabled(true);
2960 radioButtonConstBitrate
->setEnabled(false);
2961 if(radioButtonConstBitrate
->isChecked()) radioButtonModeQuality
->setChecked(true);
2962 sliderBitrate
->setEnabled(true);
2964 case SettingsModel::AC3Encoder
:
2965 radioButtonModeQuality
->setEnabled(true);
2966 radioButtonModeQuality
->setChecked(true);
2967 radioButtonModeAverageBitrate
->setEnabled(false);
2968 radioButtonConstBitrate
->setEnabled(true);
2969 sliderBitrate
->setEnabled(true);
2971 case SettingsModel::FLACEncoder
:
2972 radioButtonModeQuality
->setEnabled(false);
2973 radioButtonModeQuality
->setChecked(true);
2974 radioButtonModeAverageBitrate
->setEnabled(false);
2975 radioButtonConstBitrate
->setEnabled(false);
2976 sliderBitrate
->setEnabled(true);
2978 case SettingsModel::PCMEncoder
:
2979 radioButtonModeQuality
->setEnabled(false);
2980 radioButtonModeQuality
->setChecked(true);
2981 radioButtonModeAverageBitrate
->setEnabled(false);
2982 radioButtonConstBitrate
->setEnabled(false);
2983 sliderBitrate
->setEnabled(false);
2985 case SettingsModel::AACEncoder
:
2986 radioButtonModeQuality
->setEnabled(true);
2987 radioButtonModeAverageBitrate
->setEnabled(!m_fhgEncoderAvailable
);
2988 if(m_fhgEncoderAvailable
&& radioButtonModeAverageBitrate
->isChecked()) radioButtonConstBitrate
->setChecked(true);
2989 radioButtonConstBitrate
->setEnabled(true);
2990 sliderBitrate
->setEnabled(true);
2992 case SettingsModel::DCAEncoder
:
2993 radioButtonModeQuality
->setEnabled(false);
2994 radioButtonModeAverageBitrate
->setEnabled(false);
2995 radioButtonConstBitrate
->setEnabled(true);
2996 radioButtonConstBitrate
->setChecked(true);
2997 sliderBitrate
->setEnabled(true);
3000 radioButtonModeQuality
->setEnabled(true);
3001 radioButtonModeAverageBitrate
->setEnabled(true);
3002 radioButtonConstBitrate
->setEnabled(true);
3003 sliderBitrate
->setEnabled(true);
3007 if(m_settings
->compressionEncoder() == SettingsModel::AACEncoder
)
3009 const QString encoderName
= m_qaacEncoderAvailable
? tr("QAAC (Apple)") : (m_fhgEncoderAvailable
? tr("FHG AAC (Winamp)") : (m_neroEncoderAvailable
? tr("Nero AAC") : tr("Not available!")));
3010 labelEncoderInfo
->setVisible(true);
3011 labelEncoderInfo
->setText(tr("Current AAC Encoder: %1").arg(encoderName
));
3015 labelEncoderInfo
->setVisible(false);
3018 updateRCMode(m_modeButtonGroup
->checkedId());
3022 * Update rate-control mode
3024 void MainWindow::updateRCMode(int id
)
3026 m_settings
->compressionRCMode(id
);
3028 switch(m_settings
->compressionEncoder())
3030 case SettingsModel::MP3Encoder
:
3031 switch(m_settings
->compressionRCMode())
3033 case SettingsModel::VBRMode
:
3034 sliderBitrate
->setMinimum(0);
3035 sliderBitrate
->setMaximum(9);
3038 sliderBitrate
->setMinimum(0);
3039 sliderBitrate
->setMaximum(13);
3043 case SettingsModel::VorbisEncoder
:
3044 switch(m_settings
->compressionRCMode())
3046 case SettingsModel::VBRMode
:
3047 sliderBitrate
->setMinimum(-2);
3048 sliderBitrate
->setMaximum(10);
3051 sliderBitrate
->setMinimum(4);
3052 sliderBitrate
->setMaximum(63);
3056 case SettingsModel::AC3Encoder
:
3057 switch(m_settings
->compressionRCMode())
3059 case SettingsModel::VBRMode
:
3060 sliderBitrate
->setMinimum(0);
3061 sliderBitrate
->setMaximum(16);
3064 sliderBitrate
->setMinimum(0);
3065 sliderBitrate
->setMaximum(18);
3069 case SettingsModel::AACEncoder
:
3070 switch(m_settings
->compressionRCMode())
3072 case SettingsModel::VBRMode
:
3073 sliderBitrate
->setMinimum(0);
3074 sliderBitrate
->setMaximum(20);
3077 sliderBitrate
->setMinimum(4);
3078 sliderBitrate
->setMaximum(63);
3082 case SettingsModel::FLACEncoder
:
3083 sliderBitrate
->setMinimum(0);
3084 sliderBitrate
->setMaximum(8);
3086 case SettingsModel::DCAEncoder
:
3087 sliderBitrate
->setMinimum(1);
3088 sliderBitrate
->setMaximum(128);
3090 case SettingsModel::PCMEncoder
:
3091 sliderBitrate
->setMinimum(0);
3092 sliderBitrate
->setMaximum(2);
3093 sliderBitrate
->setValue(1);
3096 sliderBitrate
->setMinimum(0);
3097 sliderBitrate
->setMaximum(0);
3101 updateBitrate(sliderBitrate
->value());
3107 void MainWindow::updateBitrate(int value
)
3109 m_settings
->compressionBitrate(value
);
3111 switch(m_settings
->compressionRCMode())
3113 case SettingsModel::VBRMode
:
3114 switch(m_settings
->compressionEncoder())
3116 case SettingsModel::MP3Encoder
:
3117 labelBitrate
->setText(tr("Quality Level %1").arg(9 - value
));
3119 case SettingsModel::VorbisEncoder
:
3120 labelBitrate
->setText(tr("Quality Level %1").arg(value
));
3122 case SettingsModel::AACEncoder
:
3123 labelBitrate
->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", static_cast<double>(value
* 5) / 100.0)));
3125 case SettingsModel::FLACEncoder
:
3126 labelBitrate
->setText(tr("Compression %1").arg(value
));
3128 case SettingsModel::AC3Encoder
:
3129 labelBitrate
->setText(tr("Quality Level %1").arg(qMin(1024, qMax(0, value
* 64))));
3131 case SettingsModel::PCMEncoder
:
3132 labelBitrate
->setText(tr("Uncompressed"));
3135 labelBitrate
->setText(QString::number(value
));
3139 case SettingsModel::ABRMode
:
3140 switch(m_settings
->compressionEncoder())
3142 case SettingsModel::MP3Encoder
:
3143 labelBitrate
->setText(QString("≈ %1 kbps").arg(SettingsModel::mp3Bitrates
[value
]));
3145 case SettingsModel::FLACEncoder
:
3146 labelBitrate
->setText(tr("Compression %1").arg(value
));
3148 case SettingsModel::AC3Encoder
:
3149 labelBitrate
->setText(QString("≈ %1 kbps").arg(SettingsModel::ac3Bitrates
[value
]));
3151 case SettingsModel::PCMEncoder
:
3152 labelBitrate
->setText(tr("Uncompressed"));
3155 labelBitrate
->setText(QString("≈ %1 kbps").arg(qMin(500, value
* 8)));
3160 switch(m_settings
->compressionEncoder())
3162 case SettingsModel::MP3Encoder
:
3163 labelBitrate
->setText(QString("%1 kbps").arg(SettingsModel::mp3Bitrates
[value
]));
3165 case SettingsModel::FLACEncoder
:
3166 labelBitrate
->setText(tr("Compression %1").arg(value
));
3168 case SettingsModel::AC3Encoder
:
3169 labelBitrate
->setText(QString("%1 kbps").arg(SettingsModel::ac3Bitrates
[value
]));
3171 case SettingsModel::DCAEncoder
:
3172 labelBitrate
->setText(QString("%1 kbps").arg(value
* 32));
3174 case SettingsModel::PCMEncoder
:
3175 labelBitrate
->setText(tr("Uncompressed"));
3178 labelBitrate
->setText(QString("%1 kbps").arg(qMin(500, value
* 8)));
3185 // =========================================================
3186 // Advanced option slots
3187 // =========================================================
3190 * Lame algorithm quality changed
3192 void MainWindow::updateLameAlgoQuality(int value
)
3199 text
= tr("Best Quality (Very Slow)");
3202 text
= tr("High Quality (Recommended)");
3205 text
= tr("Average Quality (Default)");
3208 text
= tr("Low Quality (Fast)");
3211 text
= tr("Poor Quality (Very Fast)");
3217 m_settings
->lameAlgoQuality(value
);
3218 labelLameAlgoQuality
->setText(text
);
3221 bool warning
= (value
== 0), notice
= (value
== 4);
3222 labelLameAlgoQualityWarning
->setVisible(warning
);
3223 labelLameAlgoQualityWarningIcon
->setVisible(warning
);
3224 labelLameAlgoQualityNotice
->setVisible(notice
);
3225 labelLameAlgoQualityNoticeIcon
->setVisible(notice
);
3226 labelLameAlgoQualitySpacer
->setVisible(warning
|| notice
);
3230 * Bitrate management endabled/disabled
3232 void MainWindow::bitrateManagementEnabledChanged(bool checked
)
3234 m_settings
->bitrateManagementEnabled(checked
);
3238 * Minimum bitrate has changed
3240 void MainWindow::bitrateManagementMinChanged(int value
)
3242 if(value
> spinBoxBitrateManagementMax
->value())
3244 spinBoxBitrateManagementMin
->setValue(spinBoxBitrateManagementMax
->value());
3245 m_settings
->bitrateManagementMinRate(spinBoxBitrateManagementMax
->value());
3249 m_settings
->bitrateManagementMinRate(value
);
3254 * Maximum bitrate has changed
3256 void MainWindow::bitrateManagementMaxChanged(int value
)
3258 if(value
< spinBoxBitrateManagementMin
->value())
3260 spinBoxBitrateManagementMax
->setValue(spinBoxBitrateManagementMin
->value());
3261 m_settings
->bitrateManagementMaxRate(spinBoxBitrateManagementMin
->value());
3265 m_settings
->bitrateManagementMaxRate(value
);
3270 * Channel mode has changed
3272 void MainWindow::channelModeChanged(int value
)
3274 if(value
>= 0) m_settings
->lameChannelMode(value
);
3278 * Sampling rate has changed
3280 void MainWindow::samplingRateChanged(int value
)
3282 if(value
>= 0) m_settings
->samplingRate(value
);
3286 * Nero AAC 2-Pass mode changed
3288 void MainWindow::neroAAC2PassChanged(bool checked
)
3290 m_settings
->neroAACEnable2Pass(checked
);
3294 * Nero AAC profile mode changed
3296 void MainWindow::neroAACProfileChanged(int value
)
3298 if(value
>= 0) m_settings
->aacEncProfile(value
);
3302 * Aften audio coding mode changed
3304 void MainWindow::aftenCodingModeChanged(int value
)
3306 if(value
>= 0) m_settings
->aftenAudioCodingMode(value
);
3310 * Aften DRC mode changed
3312 void MainWindow::aftenDRCModeChanged(int value
)
3314 if(value
>= 0) m_settings
->aftenDynamicRangeCompression(value
);
3318 * Aften exponent search size changed
3320 void MainWindow::aftenSearchSizeChanged(int value
)
3322 if(value
>= 0) m_settings
->aftenExponentSearchSize(value
);
3326 * Aften fast bit allocation changed
3328 void MainWindow::aftenFastAllocationChanged(bool checked
)
3330 m_settings
->aftenFastBitAllocation(checked
);
3334 * Normalization filter enabled changed
3336 void MainWindow::normalizationEnabledChanged(bool checked
)
3338 m_settings
->normalizationFilterEnabled(checked
);
3342 * Normalization max. volume changed
3344 void MainWindow::normalizationMaxVolumeChanged(double value
)
3346 m_settings
->normalizationFilterMaxVolume(static_cast<int>(value
* 100.0));
3350 * Normalization equalization mode changed
3352 void MainWindow::normalizationModeChanged(int mode
)
3354 m_settings
->normalizationFilterEqualizationMode(mode
);
3358 * Tone adjustment has changed (Bass)
3360 void MainWindow::toneAdjustBassChanged(double value
)
3362 m_settings
->toneAdjustBass(static_cast<int>(value
* 100.0));
3363 spinBoxToneAdjustBass
->setPrefix((value
> 0) ? "+" : QString());
3367 * Tone adjustment has changed (Treble)
3369 void MainWindow::toneAdjustTrebleChanged(double value
)
3371 m_settings
->toneAdjustTreble(static_cast<int>(value
* 100.0));
3372 spinBoxToneAdjustTreble
->setPrefix((value
> 0) ? "+" : QString());
3376 * Tone adjustment has been reset
3378 void MainWindow::toneAdjustTrebleReset(void)
3380 spinBoxToneAdjustBass
->setValue(m_settings
->toneAdjustBassDefault());
3381 spinBoxToneAdjustTreble
->setValue(m_settings
->toneAdjustTrebleDefault());
3382 toneAdjustBassChanged(spinBoxToneAdjustBass
->value());
3383 toneAdjustTrebleChanged(spinBoxToneAdjustTreble
->value());
3387 * Custom encoder parameters changed
3389 void MainWindow::customParamsChanged(void)
3391 lineEditCustomParamLAME
->setText(lineEditCustomParamLAME
->text().simplified());
3392 lineEditCustomParamOggEnc
->setText(lineEditCustomParamOggEnc
->text().simplified());
3393 lineEditCustomParamNeroAAC
->setText(lineEditCustomParamNeroAAC
->text().simplified());
3394 lineEditCustomParamFLAC
->setText(lineEditCustomParamFLAC
->text().simplified());
3395 lineEditCustomParamAften
->setText(lineEditCustomParamAften
->text().simplified());
3397 bool customParamsUsed
= false;
3398 if(!lineEditCustomParamLAME
->text().isEmpty()) customParamsUsed
= true;
3399 if(!lineEditCustomParamOggEnc
->text().isEmpty()) customParamsUsed
= true;
3400 if(!lineEditCustomParamNeroAAC
->text().isEmpty()) customParamsUsed
= true;
3401 if(!lineEditCustomParamFLAC
->text().isEmpty()) customParamsUsed
= true;
3402 if(!lineEditCustomParamAften
->text().isEmpty()) customParamsUsed
= true;
3404 labelCustomParamsIcon
->setVisible(customParamsUsed
);
3405 labelCustomParamsText
->setVisible(customParamsUsed
);
3406 labelCustomParamsSpacer
->setVisible(customParamsUsed
);
3408 m_settings
->customParametersLAME(lineEditCustomParamLAME
->text());
3409 m_settings
->customParametersOggEnc(lineEditCustomParamOggEnc
->text());
3410 m_settings
->customParametersAacEnc(lineEditCustomParamNeroAAC
->text());
3411 m_settings
->customParametersFLAC(lineEditCustomParamFLAC
->text());
3412 m_settings
->customParametersAften(lineEditCustomParamAften
->text());
3417 * Rename output files enabled changed
3419 void MainWindow::renameOutputEnabledChanged(bool checked
)
3421 m_settings
->renameOutputFilesEnabled(checked
);
3425 * Rename output files patterm changed
3427 void MainWindow::renameOutputPatternChanged(void)
3429 QString temp
= lineEditRenamePattern
->text().simplified();
3430 lineEditRenamePattern
->setText(temp
.isEmpty() ? m_settings
->renameOutputFilesPatternDefault() : temp
);
3431 m_settings
->renameOutputFilesPattern(lineEditRenamePattern
->text());
3435 * Rename output files patterm changed
3437 void MainWindow::renameOutputPatternChanged(const QString
&text
)
3439 QString
pattern(text
.simplified());
3441 pattern
.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive
);
3442 pattern
.replace("<TrackNo>", "04", Qt::CaseInsensitive
);
3443 pattern
.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive
);
3444 pattern
.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive
);
3445 pattern
.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive
);
3446 pattern
.replace("<Year>", "2001", Qt::CaseInsensitive
);
3447 pattern
.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive
);
3449 if(pattern
.compare(lamexp_clean_filename(pattern
)))
3451 if(lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::red
)
3453 MessageBeep(MB_ICONERROR
);
3454 SET_TEXT_COLOR(lineEditRenamePattern
, Qt::red
);
3459 if(lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::black
)
3461 MessageBeep(MB_ICONINFORMATION
);
3462 SET_TEXT_COLOR(lineEditRenamePattern
, Qt::black
);
3466 labelRanameExample
->setText(lamexp_clean_filename(pattern
));
3470 * Show list of rename macros
3472 void MainWindow::showRenameMacros(const QString
&text
)
3474 if(text
.compare("reset", Qt::CaseInsensitive
) == 0)
3476 lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPatternDefault());
3480 const QString format
= QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
3482 QString message
= QString("<table>");
3483 message
+= QString(format
).arg("BaseName", tr("File name without extension"));
3484 message
+= QString(format
).arg("TrackNo", tr("Track number with leading zero"));
3485 message
+= QString(format
).arg("Title", tr("Track title"));
3486 message
+= QString(format
).arg("Artist", tr("Artist name"));
3487 message
+= QString(format
).arg("Album", tr("Album name"));
3488 message
+= QString(format
).arg("Year", tr("Year with (at least) four digits"));
3489 message
+= QString(format
).arg("Comment", tr("Comment"));
3490 message
+= "</table><br><br>";
3491 message
+= QString("%1<br>").arg(tr("Characters forbidden in file names:"));
3492 message
+= "<b><tt>\\ / : * ? < > |<br>";
3494 QMessageBox::information(this, tr("Rename Macros"), message
, tr("Discard"));
3497 void MainWindow::forceStereoDownmixEnabledChanged(bool checked
)
3499 m_settings
->forceStereoDownmix(checked
);
3503 * Maximum number of instances changed
3505 void MainWindow::updateMaximumInstances(int value
)
3507 labelMaxInstances
->setText(tr("%1 Instance(s)").arg(QString::number(value
)));
3508 m_settings
->maximumInstances(checkBoxAutoDetectInstances
->isChecked() ? NULL
: value
);
3512 * Auto-detect number of instances
3514 void MainWindow::autoDetectInstancesChanged(bool checked
)
3516 m_settings
->maximumInstances(checked
? NULL
: sliderMaxInstances
->value());
3520 * Browse for custom TEMP folder button clicked
3522 void MainWindow::browseCustomTempFolderButtonClicked(void)
3524 QString newTempFolder
;
3526 if(USE_NATIVE_FILE_DIALOG
)
3528 newTempFolder
= QFileDialog::getExistingDirectory(this, QString(), m_settings
->customTempPath());
3532 QFileDialog
dialog(this);
3533 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
3534 dialog
.setDirectory(m_settings
->customTempPath());
3537 newTempFolder
= dialog
.selectedFiles().first();
3541 if(!newTempFolder
.isEmpty())
3543 QFile
writeTest(QString("%1/~%2.tmp").arg(newTempFolder
, lamexp_rand_str()));
3544 if(writeTest
.open(QIODevice::ReadWrite
))
3547 lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(newTempFolder
));
3551 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
3557 * Custom TEMP folder changed
3559 void MainWindow::customTempFolderChanged(const QString
&text
)
3561 m_settings
->customTempPath(QDir::fromNativeSeparators(text
));
3565 * Use custom TEMP folder option changed
3567 void MainWindow::useCustomTempFolderChanged(bool checked
)
3569 m_settings
->customTempPathEnabled(!checked
);
3573 * Reset all advanced options to their defaults
3575 void MainWindow::resetAdvancedOptionsButtonClicked(void)
3577 sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQualityDefault());
3578 spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRateDefault());
3579 spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRateDefault());
3580 spinBoxNormalizationFilter
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolumeDefault()) / 100.0);
3581 spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBassDefault()) / 100.0);
3582 spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTrebleDefault()) / 100.0);
3583 spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSizeDefault());
3584 comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelModeDefault());
3585 comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRateDefault());
3586 comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfileDefault());
3587 comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingModeDefault());
3588 comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompressionDefault());
3589 comboBoxNormalizationMode
->setCurrentIndex(m_settings
->normalizationFilterEqualizationModeDefault());
3590 while(checkBoxBitrateManagement
->isChecked() != m_settings
->bitrateManagementEnabledDefault()) checkBoxBitrateManagement
->click();
3591 while(checkBoxNeroAAC2PassMode
->isChecked() != m_settings
->neroAACEnable2PassDefault()) checkBoxNeroAAC2PassMode
->click();
3592 while(checkBoxNormalizationFilter
->isChecked() != m_settings
->normalizationFilterEnabledDefault()) checkBoxNormalizationFilter
->click();
3593 while(checkBoxAutoDetectInstances
->isChecked() != (m_settings
->maximumInstancesDefault() < 1)) checkBoxAutoDetectInstances
->click();
3594 while(checkBoxUseSystemTempFolder
->isChecked() == m_settings
->customTempPathEnabledDefault()) checkBoxUseSystemTempFolder
->click();
3595 while(checkBoxAftenFastAllocation
->isChecked() != m_settings
->aftenFastBitAllocationDefault()) checkBoxAftenFastAllocation
->click();
3596 while(checkBoxRenameOutput
->isChecked() != m_settings
->renameOutputFilesEnabledDefault()) checkBoxRenameOutput
->click();
3597 while(checkBoxForceStereoDownmix
->isChecked() != m_settings
->forceStereoDownmixDefault()) checkBoxForceStereoDownmix
->click();
3598 lineEditCustomParamLAME
->setText(m_settings
->customParametersLAMEDefault());
3599 lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEncDefault());
3600 lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEncDefault());
3601 lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLACDefault());
3602 lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPathDefault()));
3603 lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPatternDefault());
3604 customParamsChanged();
3605 scrollArea
->verticalScrollBar()->setValue(0);
3608 // =========================================================
3609 // Multi-instance handling slots
3610 // =========================================================
3613 * Other instance detected
3615 void MainWindow::notifyOtherInstance(void)
3617 if(!m_banner
->isVisible())
3619 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
);
3625 * Add file from another instance
3627 void MainWindow::addFileDelayed(const QString
&filePath
, bool tryASAP
)
3629 if(tryASAP
&& !m_delayedFileTimer
->isActive())
3631 qDebug("Received file: %s", filePath
.toUtf8().constData());
3632 m_delayedFileList
->append(filePath
);
3633 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3636 m_delayedFileTimer
->stop();
3637 qDebug("Received file: %s", filePath
.toUtf8().constData());
3638 m_delayedFileList
->append(filePath
);
3639 m_delayedFileTimer
->start(5000);
3643 * Add files from another instance
3645 void MainWindow::addFilesDelayed(const QStringList
&filePaths
, bool tryASAP
)
3647 if(tryASAP
&& !m_delayedFileTimer
->isActive())
3649 qDebug("Received %d file(s).", filePaths
.count());
3650 m_delayedFileList
->append(filePaths
);
3651 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
3655 m_delayedFileTimer
->stop();
3656 qDebug("Received %d file(s).", filePaths
.count());
3657 m_delayedFileList
->append(filePaths
);
3658 m_delayedFileTimer
->start(5000);
3663 * Add folder from another instance
3665 void MainWindow::addFolderDelayed(const QString
&folderPath
, bool recursive
)
3667 if(!m_banner
->isVisible())
3669 addFolder(folderPath
, recursive
, true);
3673 // =========================================================
3675 // =========================================================
3678 * Restore the override cursor
3680 void MainWindow::restoreCursor(void)
3682 QApplication::restoreOverrideCursor();