1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 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, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Dialog_MainWindow.h"
26 #include "UIC_MainWindow.h"
30 #include "Dialog_WorkingBanner.h"
31 #include "Dialog_MetaInfo.h"
32 #include "Dialog_About.h"
33 #include "Dialog_Update.h"
34 #include "Dialog_DropBox.h"
35 #include "Dialog_CueImport.h"
36 #include "Dialog_LogView.h"
37 #include "Thread_FileAnalyzer.h"
38 #include "Thread_MessageHandler.h"
39 #include "Model_MetaInfo.h"
40 #include "Model_Settings.h"
41 #include "Model_FileList.h"
42 #include "Model_FileSystem.h"
43 #include "Registry_Encoder.h"
44 #include "Registry_Decoder.h"
45 #include "Encoder_Abstract.h"
46 #include "ShellIntegration.h"
47 #include "CustomEventFilter.h"
50 #include <MUtils/Global.h>
51 #include <MUtils/OSSupport.h>
52 #include <MUtils/GUI.h>
53 #include <MUtils/Exception.h>
54 #include <MUtils/Sound.h>
55 #include <MUtils/Translation.h>
56 #include <MUtils/Version.h>
59 #include <QMessageBox>
61 #include <QDesktopWidget>
63 #include <QFileDialog>
64 #include <QInputDialog>
65 #include <QFileSystemModel>
66 #include <QDesktopServices>
68 #include <QPlastiqueStyle>
69 #include <QCleanlooksStyle>
70 #include <QWindowsVistaStyle>
71 #include <QWindowsStyle>
73 #include <QDragEnterEvent>
77 #include <QProcessEnvironment>
78 #include <QCryptographicHash>
79 #include <QTranslator>
83 ////////////////////////////////////////////////////////////
85 ////////////////////////////////////////////////////////////
87 #define BANNER_VISIBLE ((m_banner != NULL) && m_banner->isVisible())
89 #define INIT_BANNER() do \
91 if(m_banner == NULL) \
93 m_banner = new WorkingBanner(this); \
98 #define SHOW_BANNER(TXT) do \
101 m_banner->show((TXT)); \
105 #define SHOW_BANNER_ARG(TXT, ARG) do \
108 m_banner->show((TXT), (ARG)); \
113 #define SHOW_BANNER_CONDITIONALLY(FLAG, TEST, TXT) do \
115 if((!(FLAG)) && ((TEST))) \
118 m_banner->show((TXT)); \
124 #define ABORT_IF_BUSY do \
126 if(BANNER_VISIBLE || m_delayedFileTimer->isActive() || (QApplication::activeModalWidget() != NULL)) \
128 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN); \
134 #define SET_TEXT_COLOR(WIDGET, COLOR) do \
136 QPalette _palette = WIDGET->palette(); \
137 _palette.setColor(QPalette::WindowText, (COLOR)); \
138 _palette.setColor(QPalette::Text, (COLOR)); \
139 WIDGET->setPalette(_palette); \
143 #define SET_FONT_BOLD(WIDGET,BOLD) do \
145 QFont _font = WIDGET->font(); \
146 _font.setBold(BOLD); \
147 WIDGET->setFont(_font); \
151 #define TEMP_HIDE_DROPBOX(CMD) do \
153 bool _dropBoxVisible = m_dropBox->isVisible(); \
154 if(_dropBoxVisible) m_dropBox->hide(); \
155 do { CMD } while(0); \
156 if(_dropBoxVisible) m_dropBox->show(); \
160 #define SET_MODEL(VIEW, MODEL) do \
162 QItemSelectionModel *_tmp = (VIEW)->selectionModel(); \
163 (VIEW)->setModel(MODEL); \
164 MUTILS_DELETE(_tmp); \
168 #define SET_CHECKBOX_STATE(CHCKBX, STATE) do \
170 const bool isDisabled = (!(CHCKBX)->isEnabled()); \
173 (CHCKBX)->setEnabled(true); \
175 if((CHCKBX)->isChecked() != (STATE)) \
179 if((CHCKBX)->isChecked() != (STATE)) \
181 qWarning("Warning: Failed to set checkbox " #CHCKBX " state!"); \
185 (CHCKBX)->setEnabled(false); \
190 #define TRIM_STRING_RIGHT(STR) do \
192 while((STR.length() > 0) && STR[STR.length()-1].isSpace()) STR.chop(1); \
196 #define MAKE_TRANSPARENT(WIDGET, FLAG) do \
198 QPalette _p = (WIDGET)->palette(); \
199 _p.setColor(QPalette::Background, Qt::transparent); \
200 (WIDGET)->setPalette(FLAG ? _p : QPalette()); \
204 #define WITH_BLOCKED_SIGNALS(WIDGET, CMD, ...) do \
206 const bool _flag = (WIDGET)->blockSignals(true); \
207 (WIDGET)->CMD(__VA_ARGS__); \
208 if(!(_flag)) { (WIDGET)->blockSignals(false); } \
212 #define PLAY_SOUND_OPTIONAL(NAME, ASYNC) do \
214 if(m_settings->soundsEnabled()) MUtils::Sound::play_sound((NAME), (ASYNC)); \
218 #define SHOW_CORNER_WIDGET(FLAG) do \
220 if(QWidget *cornerWidget = ui->menubar->cornerWidget()) \
222 cornerWidget->setVisible((FLAG)); \
227 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "−"))
228 #define FSLINK(PATH) QString("<a href=\"file:///%1\">%2</a>").arg(PATH).arg(QString(PATH).replace("-", "−"))
229 #define CENTER_CURRENT_OUTPUT_FOLDER_DELAYED QTimer::singleShot(125, this, SLOT(centerOutputFolderModel()))
231 static const unsigned int IDM_ABOUTBOX
= 0xEFF0;
232 static const char *g_hydrogen_audio_url
= "http://wiki.hydrogenaud.io/index.php?title=Main_Page";
233 static const char *g_documents_base_url
= "http://lamexp.sourceforge.net/doc";
235 ////////////////////////////////////////////////////////////
237 ////////////////////////////////////////////////////////////
239 MainWindow::MainWindow(MUtils::IPCChannel
*const ipcChannel
, FileListModel
*const fileListModel
, AudioFileModel_MetaInfo
*const metaInfo
, SettingsModel
*const settingsModel
, QWidget
*const parent
)
242 ui(new Ui::MainWindow
),
243 m_fileListModel(fileListModel
),
244 m_metaData(metaInfo
),
245 m_settings(settingsModel
),
246 m_fileSystemModel(NULL
),
249 m_firstTimeShown(true),
250 m_outputFolderViewCentering(false),
251 m_outputFolderViewInitCounter(0)
253 //Init the dialog, from the .ui file
255 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint
);
258 MUtils::GUI::set_window_icon(this, lamexp_app_icon(), true);
260 //Register meta types
261 qRegisterMetaType
<AudioFileModel
>("AudioFileModel");
263 //Enabled main buttons
264 connect(ui
->buttonAbout
, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
265 connect(ui
->buttonStart
, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
266 connect(ui
->buttonQuit
, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
269 ui
->tabWidget
->setCurrentIndex(0);
270 connect(ui
->tabWidget
, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
273 MUtils::GUI::sysmenu_append(this, IDM_ABOUTBOX
, "About...");
275 //Setup corner widget
276 QLabel
*cornerWidget
= new QLabel(ui
->menubar
);
277 m_evenFilterCornerWidget
= new CustomEventFilter
;
278 cornerWidget
->setText("N/A");
279 cornerWidget
->setFixedHeight(ui
->menubar
->height());
280 cornerWidget
->setCursor(QCursor(Qt::PointingHandCursor
));
281 cornerWidget
->hide();
282 cornerWidget
->installEventFilter(m_evenFilterCornerWidget
);
283 connect(m_evenFilterCornerWidget
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(cornerWidgetEventOccurred(QWidget
*, QEvent
*)));
284 ui
->menubar
->setCornerWidget(cornerWidget
);
286 //--------------------------------
287 // Setup "Source" tab
288 //--------------------------------
290 ui
->sourceFileView
->setModel(m_fileListModel
);
291 ui
->sourceFileView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
292 ui
->sourceFileView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
293 ui
->sourceFileView
->setContextMenuPolicy(Qt::CustomContextMenu
);
294 ui
->sourceFileView
->viewport()->installEventFilter(this);
295 m_dropNoteLabel
= new QLabel(ui
->sourceFileView
);
296 m_dropNoteLabel
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
297 SET_FONT_BOLD(m_dropNoteLabel
, true);
298 SET_TEXT_COLOR(m_dropNoteLabel
, Qt::darkGray
);
299 m_sourceFilesContextMenu
= new QMenu();
300 m_showDetailsContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
301 m_previewContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/sound.png"), "N/A");
302 m_findFileContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_go.png"), "N/A");
303 m_sourceFilesContextMenu
->addSeparator();
304 m_exportCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/table_save.png"), "N/A");
305 m_importCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_table.png"), "N/A");
306 SET_FONT_BOLD(m_showDetailsContextAction
, true);
308 connect(ui
->buttonAddFiles
, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
309 connect(ui
->buttonRemoveFile
, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
310 connect(ui
->buttonClearFiles
, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
311 connect(ui
->buttonFileUp
, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
312 connect(ui
->buttonFileDown
, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
313 connect(ui
->buttonShowDetails
, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
314 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
315 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
316 connect(m_fileListModel
, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
317 connect(ui
->sourceFileView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(sourceFilesContextMenu(QPoint
)));
318 connect(ui
->sourceFileView
->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
319 connect(ui
->sourceFileView
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
320 connect(m_showDetailsContextAction
, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
321 connect(m_previewContextAction
, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
322 connect(m_findFileContextAction
, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
323 connect(m_exportCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(exportCsvContextActionTriggered()));
324 connect(m_importCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(importCsvContextActionTriggered()));
326 //--------------------------------
327 // Setup "Output" tab
328 //--------------------------------
330 ui
->outputFolderView
->setHeaderHidden(true);
331 ui
->outputFolderView
->setAnimated(false);
332 ui
->outputFolderView
->setMouseTracking(false);
333 ui
->outputFolderView
->setContextMenuPolicy(Qt::CustomContextMenu
);
334 ui
->outputFolderView
->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn
);
336 m_evenFilterOutputFolderMouse
= new CustomEventFilter
;
337 ui
->outputFoldersGoUpLabel
->installEventFilter(m_evenFilterOutputFolderMouse
);
338 ui
->outputFoldersEditorLabel
->installEventFilter(m_evenFilterOutputFolderMouse
);
339 ui
->outputFoldersFovoritesLabel
->installEventFilter(m_evenFilterOutputFolderMouse
);
340 ui
->outputFolderLabel
->installEventFilter(m_evenFilterOutputFolderMouse
);
342 m_evenFilterOutputFolderView
= new CustomEventFilter
;
343 ui
->outputFolderView
->installEventFilter(m_evenFilterOutputFolderView
);
345 SET_CHECKBOX_STATE(ui
->saveToSourceFolderCheckBox
, m_settings
->outputToSourceDir());
346 ui
->prependRelativePathCheckBox
->setChecked(m_settings
->prependRelativeSourcePath());
348 connect(ui
->outputFolderView
, SIGNAL(clicked(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
349 connect(ui
->outputFolderView
, SIGNAL(activated(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
350 connect(ui
->outputFolderView
, SIGNAL(pressed(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
351 connect(ui
->outputFolderView
, SIGNAL(entered(QModelIndex
)), this, SLOT(outputFolderViewMoved(QModelIndex
)));
352 connect(ui
->outputFolderView
, SIGNAL(expanded(QModelIndex
)), this, SLOT(outputFolderItemExpanded(QModelIndex
)));
353 connect(ui
->buttonMakeFolder
, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
354 connect(ui
->buttonGotoHome
, SIGNAL(clicked()), SLOT(gotoHomeFolderButtonClicked()));
355 connect(ui
->buttonGotoDesktop
, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
356 connect(ui
->buttonGotoMusic
, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
357 connect(ui
->saveToSourceFolderCheckBox
, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
358 connect(ui
->prependRelativePathCheckBox
, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
359 connect(ui
->outputFolderEdit
, SIGNAL(editingFinished()), this, SLOT(outputFolderEditFinished()));
360 connect(m_evenFilterOutputFolderMouse
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(outputFolderMouseEventOccurred(QWidget
*, QEvent
*)));
361 connect(m_evenFilterOutputFolderView
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(outputFolderViewEventOccurred(QWidget
*, QEvent
*)));
363 if(m_outputFolderContextMenu
= new QMenu())
365 m_showFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
366 m_goUpFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/folder_up.png"), "N/A");
367 m_outputFolderContextMenu
->addSeparator();
368 m_refreshFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/arrow_refresh.png"), "N/A");
369 m_outputFolderContextMenu
->setDefaultAction(m_showFolderContextAction
);
370 connect(ui
->outputFolderView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(outputFolderContextMenu(QPoint
)));
371 connect(m_showFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
372 connect(m_refreshFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(refreshFolderContextActionTriggered()));
373 connect(m_goUpFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(goUpFolderContextActionTriggered()));
376 if(m_outputFolderFavoritesMenu
= new QMenu())
378 m_addFavoriteFolderAction
= m_outputFolderFavoritesMenu
->addAction(QIcon(":/icons/add.png"), "N/A");
379 m_outputFolderFavoritesMenu
->insertSeparator(m_addFavoriteFolderAction
);
380 connect(m_addFavoriteFolderAction
, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
383 ui
->outputFolderEdit
->setVisible(false);
384 if(m_outputFolderNoteBox
= new QLabel(ui
->outputFolderView
))
386 m_outputFolderNoteBox
->setAutoFillBackground(true);
387 m_outputFolderNoteBox
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
388 m_outputFolderNoteBox
->setFrameShape(QFrame::StyledPanel
);
389 SET_FONT_BOLD(m_outputFolderNoteBox
, true);
390 m_outputFolderNoteBox
->hide();
394 outputFolderViewClicked(QModelIndex());
397 //--------------------------------
398 // Setup "Meta Data" tab
399 //--------------------------------
401 m_metaInfoModel
= new MetaInfoModel(m_metaData
);
402 m_metaInfoModel
->clearData();
403 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
404 ui
->metaDataView
->setModel(m_metaInfoModel
);
405 ui
->metaDataView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
406 ui
->metaDataView
->verticalHeader()->hide();
407 ui
->metaDataView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
408 SET_CHECKBOX_STATE(ui
->writeMetaDataCheckBox
, m_settings
->writeMetaTags());
409 ui
->generatePlaylistCheckBox
->setChecked(m_settings
->createPlaylist());
410 connect(ui
->buttonEditMeta
, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
411 connect(ui
->buttonClearMeta
, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
412 connect(ui
->writeMetaDataCheckBox
, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
413 connect(ui
->generatePlaylistCheckBox
, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
415 //--------------------------------
416 //Setup "Compression" tab
417 //--------------------------------
419 m_encoderButtonGroup
= new QButtonGroup(this);
420 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderMP3
, SettingsModel::MP3Encoder
);
421 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderVorbis
, SettingsModel::VorbisEncoder
);
422 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAAC
, SettingsModel::AACEncoder
);
423 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAC3
, SettingsModel::AC3Encoder
);
424 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderFLAC
, SettingsModel::FLACEncoder
);
425 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAPE
, SettingsModel::MACEncoder
);
426 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderOpus
, SettingsModel::OpusEncoder
);
427 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderDCA
, SettingsModel::DCAEncoder
);
428 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderPCM
, SettingsModel::PCMEncoder
);
430 const int aacEncoder
= EncoderRegistry::getAacEncoder();
431 ui
->radioButtonEncoderAAC
->setEnabled(aacEncoder
> SettingsModel::AAC_ENCODER_NONE
);
433 m_modeButtonGroup
= new QButtonGroup(this);
434 m_modeButtonGroup
->addButton(ui
->radioButtonModeQuality
, SettingsModel::VBRMode
);
435 m_modeButtonGroup
->addButton(ui
->radioButtonModeAverageBitrate
, SettingsModel::ABRMode
);
436 m_modeButtonGroup
->addButton(ui
->radioButtonConstBitrate
, SettingsModel::CBRMode
);
438 ui
->radioButtonEncoderMP3
->setChecked(true);
439 foreach(QAbstractButton
*currentButton
, m_encoderButtonGroup
->buttons())
441 if(currentButton
->isEnabled() && (m_encoderButtonGroup
->id(currentButton
) == m_settings
->compressionEncoder()))
443 currentButton
->setChecked(true);
448 m_evenFilterCompressionTab
= new CustomEventFilter();
449 ui
->labelCompressionHelp
->installEventFilter(m_evenFilterCompressionTab
);
450 ui
->labelResetEncoders
->installEventFilter(m_evenFilterCompressionTab
);
452 connect(m_encoderButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
453 connect(m_modeButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
454 connect(m_evenFilterCompressionTab
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(compressionTabEventOccurred(QWidget
*, QEvent
*)));
455 connect(ui
->sliderBitrate
, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
457 updateEncoder(m_encoderButtonGroup
->checkedId());
459 //--------------------------------
460 //Setup "Advanced Options" tab
461 //--------------------------------
463 ui
->sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQuality());
464 if(m_settings
->maximumInstances() > 0) ui
->sliderMaxInstances
->setValue(m_settings
->maximumInstances());
466 ui
->spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRate());
467 ui
->spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRate());
468 ui
->spinBoxNormalizationFilterPeak
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolume()) / 100.0);
469 ui
->spinBoxNormalizationFilterSize
->setValue(m_settings
->normalizationFilterSize());
470 ui
->spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBass()) / 100.0);
471 ui
->spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTreble()) / 100.0);
472 ui
->spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSize());
473 ui
->spinBoxOpusComplexity
->setValue(m_settings
->opusComplexity());
475 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelMode());
476 ui
->comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRate());
477 ui
->comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfile());
478 ui
->comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingMode());
479 ui
->comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompression());
480 ui
->comboBoxOpusFramesize
->setCurrentIndex(m_settings
->opusFramesize());
482 SET_CHECKBOX_STATE(ui
->checkBoxBitrateManagement
, m_settings
->bitrateManagementEnabled());
483 SET_CHECKBOX_STATE(ui
->checkBoxNeroAAC2PassMode
, m_settings
->neroAACEnable2Pass());
484 SET_CHECKBOX_STATE(ui
->checkBoxAftenFastAllocation
, m_settings
->aftenFastBitAllocation());
485 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterEnabled
, m_settings
->normalizationFilterEnabled());
486 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterDynamic
, m_settings
->normalizationFilterDynamic());
487 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterCoupled
, m_settings
->normalizationFilterCoupled());
488 SET_CHECKBOX_STATE(ui
->checkBoxAutoDetectInstances
, (m_settings
->maximumInstances() < 1));
489 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabled()));
490 SET_CHECKBOX_STATE(ui
->checkBoxRename_Rename
, m_settings
->renameOutputFilesEnabled());
491 SET_CHECKBOX_STATE(ui
->checkBoxForceStereoDownmix
, m_settings
->forceStereoDownmix());
492 SET_CHECKBOX_STATE(ui
->checkBoxOpusDisableResample
, m_settings
->opusDisableResample());
494 ui
->checkBoxNeroAAC2PassMode
->setEnabled(aacEncoder
== SettingsModel::AAC_ENCODER_NERO
);
496 ui
->lineEditCustomParamLAME
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::MP3Encoder
));
497 ui
->lineEditCustomParamOggEnc
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::VorbisEncoder
));
498 ui
->lineEditCustomParamNeroAAC
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::AACEncoder
));
499 ui
->lineEditCustomParamFLAC
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::FLACEncoder
));
500 ui
->lineEditCustomParamAften
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::AC3Encoder
));
501 ui
->lineEditCustomParamOpus
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::OpusEncoder
));
502 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPath()));
503 ui
->lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPattern());
505 m_evenFilterCustumParamsHelp
= new CustomEventFilter();
506 ui
->helpCustomParamLAME
->installEventFilter(m_evenFilterCustumParamsHelp
);
507 ui
->helpCustomParamOggEnc
->installEventFilter(m_evenFilterCustumParamsHelp
);
508 ui
->helpCustomParamNeroAAC
->installEventFilter(m_evenFilterCustumParamsHelp
);
509 ui
->helpCustomParamFLAC
->installEventFilter(m_evenFilterCustumParamsHelp
);
510 ui
->helpCustomParamAften
->installEventFilter(m_evenFilterCustumParamsHelp
);
511 ui
->helpCustomParamOpus
->installEventFilter(m_evenFilterCustumParamsHelp
);
513 m_overwriteButtonGroup
= new QButtonGroup(this);
514 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeKeepBoth
, SettingsModel::Overwrite_KeepBoth
);
515 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeSkipFile
, SettingsModel::Overwrite_SkipFile
);
516 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeReplaces
, SettingsModel::Overwrite_Replaces
);
518 ui
->radioButtonOverwriteModeKeepBoth
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_KeepBoth
);
519 ui
->radioButtonOverwriteModeSkipFile
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_SkipFile
);
520 ui
->radioButtonOverwriteModeReplaces
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_Replaces
);
522 connect(ui
->sliderLameAlgoQuality
, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
523 connect(ui
->checkBoxBitrateManagement
, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
524 connect(ui
->spinBoxBitrateManagementMin
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
525 connect(ui
->spinBoxBitrateManagementMax
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
526 connect(ui
->comboBoxMP3ChannelMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
527 connect(ui
->comboBoxSamplingRate
, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
528 connect(ui
->checkBoxNeroAAC2PassMode
, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
529 connect(ui
->comboBoxAACProfile
, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
530 connect(ui
->checkBoxNormalizationFilterEnabled
, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
531 connect(ui
->checkBoxNormalizationFilterDynamic
, SIGNAL(clicked(bool)), this, SLOT(normalizationDynamicChanged(bool)));
532 connect(ui
->checkBoxNormalizationFilterCoupled
, SIGNAL(clicked(bool)), this, SLOT(normalizationCoupledChanged(bool)));
533 connect(ui
->comboBoxAftenCodingMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
534 connect(ui
->comboBoxAftenDRCMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
535 connect(ui
->spinBoxAftenSearchSize
, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
536 connect(ui
->checkBoxAftenFastAllocation
, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
537 connect(ui
->spinBoxNormalizationFilterPeak
, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
538 connect(ui
->spinBoxNormalizationFilterSize
, SIGNAL(valueChanged(int)), this, SLOT(normalizationFilterSizeChanged(int)));
539 connect(ui
->spinBoxNormalizationFilterSize
, SIGNAL(editingFinished()), this, SLOT(normalizationFilterSizeFinished()));
540 connect(ui
->spinBoxToneAdjustBass
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
541 connect(ui
->spinBoxToneAdjustTreble
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
542 connect(ui
->buttonToneAdjustReset
, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
543 connect(ui
->lineEditCustomParamLAME
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
544 connect(ui
->lineEditCustomParamOggEnc
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
545 connect(ui
->lineEditCustomParamNeroAAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
546 connect(ui
->lineEditCustomParamFLAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
547 connect(ui
->lineEditCustomParamAften
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
548 connect(ui
->lineEditCustomParamOpus
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
549 connect(ui
->sliderMaxInstances
, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
550 connect(ui
->checkBoxAutoDetectInstances
, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
551 connect(ui
->buttonBrowseCustomTempFolder
, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
552 connect(ui
->lineEditCustomTempFolder
, SIGNAL(textChanged(QString
)), this, SLOT(customTempFolderChanged(QString
)));
553 connect(ui
->checkBoxUseSystemTempFolder
, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
554 connect(ui
->buttonResetAdvancedOptions
, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
555 connect(ui
->checkBoxRename_Rename
, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
556 connect(ui
->checkBoxRename_RegExp
, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
557 connect(ui
->lineEditRenamePattern
, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
558 connect(ui
->lineEditRenamePattern
, SIGNAL(textChanged(QString
)), this, SLOT(renameOutputPatternChanged(QString
)));
559 connect(ui
->labelShowRenameMacros
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
560 connect(ui
->labelShowRegExpHelp
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
561 connect(ui
->checkBoxForceStereoDownmix
, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
562 connect(ui
->comboBoxOpusFramesize
, SIGNAL(currentIndexChanged(int)), this, SLOT(opusSettingsChanged()));
563 connect(ui
->spinBoxOpusComplexity
, SIGNAL(valueChanged(int)), this, SLOT(opusSettingsChanged()));
564 connect(ui
->checkBoxOpusDisableResample
, SIGNAL(clicked(bool)), this, SLOT(opusSettingsChanged()));
565 connect(ui
->buttonRename_Rename
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
566 connect(ui
->buttonRename_RegExp
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
567 connect(ui
->buttonRename_FileEx
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
568 connect(m_overwriteButtonGroup
, SIGNAL(buttonClicked(int)), this, SLOT(overwriteModeChanged(int)));
569 connect(m_evenFilterCustumParamsHelp
, SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(customParamsHelpRequested(QWidget
*, QEvent
*)));
571 //--------------------------------
572 // Force initial GUI update
573 //--------------------------------
575 updateLameAlgoQuality(ui
->sliderLameAlgoQuality
->value());
576 updateMaximumInstances(ui
->sliderMaxInstances
->value());
577 toneAdjustTrebleChanged(ui
->spinBoxToneAdjustTreble
->value());
578 toneAdjustBassChanged(ui
->spinBoxToneAdjustBass
->value());
579 normalizationEnabledChanged(ui
->checkBoxNormalizationFilterEnabled
->isChecked());
580 customParamsChanged();
582 //--------------------------------
583 // Initialize actions
584 //--------------------------------
586 //Activate file menu actions
587 ui
->actionOpenFolder
->setData(QVariant::fromValue
<bool>(false));
588 ui
->actionOpenFolderRecursively
->setData(QVariant::fromValue
<bool>(true));
589 connect(ui
->actionOpenFolder
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
590 connect(ui
->actionOpenFolderRecursively
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
592 //Activate view menu actions
593 m_tabActionGroup
= new QActionGroup(this);
594 m_tabActionGroup
->addAction(ui
->actionSourceFiles
);
595 m_tabActionGroup
->addAction(ui
->actionOutputDirectory
);
596 m_tabActionGroup
->addAction(ui
->actionCompression
);
597 m_tabActionGroup
->addAction(ui
->actionMetaData
);
598 m_tabActionGroup
->addAction(ui
->actionAdvancedOptions
);
599 ui
->actionSourceFiles
->setData(0);
600 ui
->actionOutputDirectory
->setData(1);
601 ui
->actionMetaData
->setData(2);
602 ui
->actionCompression
->setData(3);
603 ui
->actionAdvancedOptions
->setData(4);
604 ui
->actionSourceFiles
->setChecked(true);
605 connect(m_tabActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(tabActionActivated(QAction
*)));
607 //Activate style menu actions
608 m_styleActionGroup
= new QActionGroup(this);
609 m_styleActionGroup
->addAction(ui
->actionStylePlastique
);
610 m_styleActionGroup
->addAction(ui
->actionStyleCleanlooks
);
611 m_styleActionGroup
->addAction(ui
->actionStyleWindowsVista
);
612 m_styleActionGroup
->addAction(ui
->actionStyleWindowsXP
);
613 m_styleActionGroup
->addAction(ui
->actionStyleWindowsClassic
);
614 ui
->actionStylePlastique
->setData(0);
615 ui
->actionStyleCleanlooks
->setData(1);
616 ui
->actionStyleWindowsVista
->setData(2);
617 ui
->actionStyleWindowsXP
->setData(3);
618 ui
->actionStyleWindowsClassic
->setData(4);
619 ui
->actionStylePlastique
->setChecked(true);
620 ui
->actionStyleWindowsXP
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_XP
&& MUtils::GUI::themes_enabled());
621 ui
->actionStyleWindowsVista
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_VISTA
&& MUtils::GUI::themes_enabled());
622 connect(m_styleActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(styleActionActivated(QAction
*)));
623 styleActionActivated(NULL
);
625 //Populate the language menu
626 m_languageActionGroup
= new QActionGroup(this);
627 QStringList translations
;
628 if(MUtils::Translation::enumerate(translations
) > 0)
630 for(QStringList::ConstIterator iter
= translations
.constBegin(); iter
!= translations
.constEnd(); iter
++)
632 QAction
*currentLanguage
= new QAction(this);
633 currentLanguage
->setData(*iter
);
634 currentLanguage
->setText(MUtils::Translation::get_name(*iter
));
635 currentLanguage
->setIcon(QIcon(QString(":/flags/%1.png").arg(*iter
)));
636 currentLanguage
->setCheckable(true);
637 currentLanguage
->setChecked(false);
638 m_languageActionGroup
->addAction(currentLanguage
);
639 ui
->menuLanguage
->insertAction(ui
->actionLoadTranslationFromFile
, currentLanguage
);
642 ui
->menuLanguage
->insertSeparator(ui
->actionLoadTranslationFromFile
);
643 connect(ui
->actionLoadTranslationFromFile
, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
644 connect(m_languageActionGroup
, SIGNAL(triggered(QAction
*)), this, SLOT(languageActionActivated(QAction
*)));
645 ui
->actionLoadTranslationFromFile
->setChecked(false);
647 //Activate tools menu actions
648 ui
->actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
649 ui
->actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
650 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
651 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
652 ui
->actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
653 ui
->actionDisableShellIntegration
->setDisabled(lamexp_version_portable() && ui
->actionDisableShellIntegration
->isChecked());
654 ui
->actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta() || lamexp_version_demo());
655 ui
->actionCheckForBetaUpdates
->setEnabled(!lamexp_version_demo());
656 ui
->actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
657 ui
->actionHibernateComputer
->setEnabled(MUtils::OS::is_hibernation_supported());
658 connect(ui
->actionDisableUpdateReminder
, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
659 connect(ui
->actionDisableSounds
, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
660 connect(ui
->actionDisableNeroAacNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
661 connect(ui
->actionDisableSlowStartupNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
662 connect(ui
->actionDisableShellIntegration
, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
663 connect(ui
->actionShowDropBoxWidget
, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
664 connect(ui
->actionHibernateComputer
, SIGNAL(triggered(bool)), this, SLOT(hibernateComputerActionTriggered(bool)));
665 connect(ui
->actionCheckForBetaUpdates
, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
666 connect(ui
->actionImportCueSheet
, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
668 //Activate help menu actions
669 ui
->actionVisitHomepage
->setData(QString::fromLatin1(lamexp_website_url()));
670 ui
->actionVisitSupport
->setData(QString::fromLatin1(lamexp_support_url()));
671 ui
->actionVisitMuldersSite
->setData(QString::fromLatin1(lamexp_mulders_url()));
672 ui
->actionVisitTracker
->setData(QString::fromLatin1(lamexp_tracker_url()));
673 ui
->actionVisitHAK
->setData(QString::fromLatin1(g_hydrogen_audio_url
));
674 ui
->actionDocumentManual
->setData(QString("%1/Manual.html") .arg(QApplication::applicationDirPath()));
675 ui
->actionDocumentChangelog
->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
676 ui
->actionDocumentTranslate
->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
677 connect(ui
->actionCheckUpdates
, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
678 connect(ui
->actionVisitSupport
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
679 connect(ui
->actionVisitTracker
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
680 connect(ui
->actionVisitHomepage
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
681 connect(ui
->actionVisitMuldersSite
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
682 connect(ui
->actionVisitHAK
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
683 connect(ui
->actionDocumentManual
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
684 connect(ui
->actionDocumentChangelog
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
685 connect(ui
->actionDocumentTranslate
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
687 //--------------------------------
688 // Prepare to show window
689 //--------------------------------
691 //Center window in screen
692 QRect desktopRect
= QApplication::desktop()->screenGeometry();
693 QRect thisRect
= this->geometry();
694 move((desktopRect
.width() - thisRect
.width()) / 2, (desktopRect
.height() - thisRect
.height()) / 2);
695 setMinimumSize(thisRect
.width(), thisRect
.height());
697 //Create DropBox widget
698 m_dropBox
= new DropBox(this, m_fileListModel
, m_settings
);
699 connect(m_fileListModel
, SIGNAL(modelReset()), m_dropBox
, SLOT(modelChanged()));
700 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), m_dropBox
, SLOT(modelChanged()));
701 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), m_dropBox
, SLOT(modelChanged()));
702 connect(m_fileListModel
, SIGNAL(rowAppended()), m_dropBox
, SLOT(modelChanged()));
704 //Create message handler thread
705 m_messageHandler
= new MessageHandlerThread(ipcChannel
);
706 connect(m_messageHandler
, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection
);
707 connect(m_messageHandler
, SIGNAL(fileReceived(QString
)), this, SLOT(addFileDelayed(QString
)), Qt::QueuedConnection
);
708 connect(m_messageHandler
, SIGNAL(folderReceived(QString
, bool)), this, SLOT(addFolderDelayed(QString
, bool)), Qt::QueuedConnection
);
709 connect(m_messageHandler
, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection
);
710 m_messageHandler
->start();
712 //Init delayed file handling
713 m_delayedFileList
= new QStringList();
714 m_delayedFileTimer
= new QTimer();
715 m_delayedFileTimer
->setSingleShot(true);
716 m_delayedFileTimer
->setInterval(5000);
717 connect(m_delayedFileTimer
, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
720 initializeTranslation();
722 //Re-translate (make sure we translate once)
723 QEvent
languageChangeEvent(QEvent::LanguageChange
);
724 changeEvent(&languageChangeEvent
);
727 m_droppedFileList
= new QList
<QUrl
>();
728 this->setAcceptDrops(true);
731 ////////////////////////////////////////////////////////////
733 ////////////////////////////////////////////////////////////
735 MainWindow::~MainWindow(void)
737 //Stop message handler thread
738 if(m_messageHandler
&& m_messageHandler
->isRunning())
740 m_messageHandler
->stop();
741 if(!m_messageHandler
->wait(2500))
743 m_messageHandler
->terminate();
744 m_messageHandler
->wait();
749 SET_MODEL(ui
->sourceFileView
, NULL
);
750 SET_MODEL(ui
->outputFolderView
, NULL
);
751 SET_MODEL(ui
->metaDataView
, NULL
);
754 MUTILS_DELETE(m_tabActionGroup
);
755 MUTILS_DELETE(m_styleActionGroup
);
756 MUTILS_DELETE(m_languageActionGroup
);
757 MUTILS_DELETE(m_banner
);
758 MUTILS_DELETE(m_fileSystemModel
);
759 MUTILS_DELETE(m_messageHandler
);
760 MUTILS_DELETE(m_droppedFileList
);
761 MUTILS_DELETE(m_delayedFileList
);
762 MUTILS_DELETE(m_delayedFileTimer
);
763 MUTILS_DELETE(m_metaInfoModel
);
764 MUTILS_DELETE(m_encoderButtonGroup
);
765 MUTILS_DELETE(m_modeButtonGroup
);
766 MUTILS_DELETE(m_overwriteButtonGroup
);
767 MUTILS_DELETE(m_sourceFilesContextMenu
);
768 MUTILS_DELETE(m_outputFolderFavoritesMenu
);
769 MUTILS_DELETE(m_outputFolderContextMenu
);
770 MUTILS_DELETE(m_dropBox
);
771 MUTILS_DELETE(m_evenFilterCornerWidget
);
772 MUTILS_DELETE(m_evenFilterCustumParamsHelp
);
773 MUTILS_DELETE(m_evenFilterOutputFolderMouse
);
774 MUTILS_DELETE(m_evenFilterOutputFolderView
);
775 MUTILS_DELETE(m_evenFilterCompressionTab
);
777 //Un-initialize the dialog
781 ////////////////////////////////////////////////////////////
783 ////////////////////////////////////////////////////////////
786 * Add file to source list
788 void MainWindow::addFiles(const QStringList
&files
)
795 WITH_BLOCKED_SIGNALS(ui
->tabWidget
, setCurrentIndex
, 0);
796 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
799 FileAnalyzer
*analyzer
= new FileAnalyzer(files
);
801 connect(analyzer
, SIGNAL(fileSelected(QString
)), m_banner
, SLOT(setText(QString
)), Qt::QueuedConnection
);
802 connect(analyzer
, SIGNAL(progressValChanged(unsigned int)), m_banner
, SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection
);
803 connect(analyzer
, SIGNAL(progressMaxChanged(unsigned int)), m_banner
, SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection
);
804 connect(analyzer
, SIGNAL(fileAnalyzed(AudioFileModel
)), m_fileListModel
, SLOT(addFile(AudioFileModel
)), Qt::QueuedConnection
);
805 connect(m_banner
, SIGNAL(userAbort()), analyzer
, SLOT(abortProcess()), Qt::DirectConnection
);
809 m_fileListModel
->setBlockUpdates(true);
810 QTime startTime
= QTime::currentTime();
811 m_banner
->show(tr("Adding file(s), please wait..."), analyzer
);
815 /* ignore any exceptions that may occur */
818 m_fileListModel
->setBlockUpdates(false);
819 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
820 ui
->sourceFileView
->update();
821 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
822 ui
->sourceFileView
->scrollToBottom();
823 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
825 if(analyzer
->filesDenied())
827 QMessageBox::warning(this, tr("Access Denied"), QString("%1<br>%2").arg(NOBR(tr("%n file(s) have been rejected, because read access was not granted!", "", analyzer
->filesDenied())), NOBR(tr("This usually means the file is locked by another process."))));
829 if(analyzer
->filesDummyCDDA())
831 QMessageBox::warning(this, tr("CDDA Files"), QString("%1<br><br>%2<br>%3").arg(NOBR(tr("%n file(s) have been rejected, because they are dummy CDDA files!", "", 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>"))));
833 if(analyzer
->filesCueSheet())
835 QMessageBox::warning(this, tr("Cue Sheet"), QString("%1<br>%2").arg(NOBR(tr("%n file(s) have been rejected, because they appear to be Cue Sheet images!", "",analyzer
->filesCueSheet())), NOBR(tr("Please use LameXP's Cue Sheet wizard for importing Cue Sheet files."))));
837 if(analyzer
->filesRejected())
839 QMessageBox::warning(this, tr("Files Rejected"), QString("%1<br>%2").arg(NOBR(tr("%n file(s) have been rejected, because the file format could not be recognized!", "", analyzer
->filesRejected())), NOBR(tr("This usually means the file is damaged or the file format is not supported."))));
842 MUTILS_DELETE(analyzer
);
847 * Add folder to source list
849 void MainWindow::addFolder(const QString
&path
, bool recursive
, bool delayed
)
851 QFileInfoList folderInfoList
;
852 folderInfoList
<< QFileInfo(path
);
853 QStringList fileList
;
855 SHOW_BANNER(tr("Scanning folder(s) for files, please wait..."));
857 QApplication::processEvents();
858 MUtils::OS::check_key_state_esc();
860 while(!folderInfoList
.isEmpty())
862 if(MUtils::OS::check_key_state_esc())
864 qWarning("Operation cancelled by user!");
865 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
870 QDir
currentDir(folderInfoList
.takeFirst().canonicalFilePath());
871 QFileInfoList fileInfoList
= currentDir
.entryInfoList(QDir::Files
| QDir::NoSymLinks
);
873 while(!fileInfoList
.isEmpty())
875 fileList
<< fileInfoList
.takeFirst().canonicalFilePath();
878 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
882 folderInfoList
.append(currentDir
.entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
));
883 QApplication::processEvents();
888 QApplication::processEvents();
890 if(!fileList
.isEmpty())
894 addFilesDelayed(fileList
);
906 bool MainWindow::checkForUpdates(void)
908 bool bReadyToInstall
= false;
910 UpdateDialog
*updateDialog
= new UpdateDialog(m_settings
, this);
911 updateDialog
->exec();
913 if(updateDialog
->getSuccess())
915 SHOW_CORNER_WIDGET(false);
916 m_settings
->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate
));
917 bReadyToInstall
= updateDialog
->updateReadyToInstall();
920 MUTILS_DELETE(updateDialog
);
921 return bReadyToInstall
;
925 * Refresh list of favorites
927 void MainWindow::refreshFavorites(void)
929 QList
<QAction
*> folderList
= m_outputFolderFavoritesMenu
->actions();
930 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
931 while(favorites
.count() > 6) favorites
.removeFirst();
933 while(!folderList
.isEmpty())
935 QAction
*currentItem
= folderList
.takeFirst();
936 if(currentItem
->isSeparator()) break;
937 m_outputFolderFavoritesMenu
->removeAction(currentItem
);
938 MUTILS_DELETE(currentItem
);
941 QAction
*lastItem
= m_outputFolderFavoritesMenu
->actions().first();
943 while(!favorites
.isEmpty())
945 QString path
= favorites
.takeLast();
946 if(QDir(path
).exists())
948 QAction
*action
= new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path
), this);
949 action
->setData(path
);
950 m_outputFolderFavoritesMenu
->insertAction(lastItem
, action
);
951 connect(action
, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
958 * Initilaize translation
960 void MainWindow::initializeTranslation(void)
962 bool translationLoaded
= false;
964 //Try to load "external" translation file
965 if(!m_settings
->currentLanguageFile().isEmpty())
967 const QString qmFilePath
= QFileInfo(m_settings
->currentLanguageFile()).canonicalFilePath();
968 if((!qmFilePath
.isEmpty()) && QFileInfo(qmFilePath
).exists() && QFileInfo(qmFilePath
).isFile() && (QFileInfo(qmFilePath
).suffix().compare("qm", Qt::CaseInsensitive
) == 0))
970 if(MUtils::Translation::install_translator_from_file(qmFilePath
))
972 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
973 while(!actions
.isEmpty()) actions
.takeFirst()->setChecked(false);
974 ui
->actionLoadTranslationFromFile
->setChecked(true);
975 translationLoaded
= true;
980 //Try to load "built-in" translation file
981 if(!translationLoaded
)
983 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
984 while(!languageActions
.isEmpty())
986 QAction
*currentLanguage
= languageActions
.takeFirst();
987 if(currentLanguage
->data().toString().compare(m_settings
->currentLanguage(), Qt::CaseInsensitive
) == 0)
989 currentLanguage
->setChecked(true);
990 languageActionActivated(currentLanguage
);
991 translationLoaded
= true;
996 //Fallback to default translation
997 if(!translationLoaded
)
999 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
1000 while(!languageActions
.isEmpty())
1002 QAction
*currentLanguage
= languageActions
.takeFirst();
1003 if(currentLanguage
->data().toString().compare(MUtils::Translation::DEFAULT_LANGID
, Qt::CaseInsensitive
) == 0)
1005 currentLanguage
->setChecked(true);
1006 languageActionActivated(currentLanguage
);
1007 translationLoaded
= true;
1012 //Make sure we loaded some translation
1013 if(!translationLoaded
)
1015 qFatal("Failed to load any translation, this is NOT supposed to happen!");
1020 * Open a document link
1022 void MainWindow::openDocumentLink(QAction
*const action
)
1024 if(!(action
->data().isValid() && (action
->data().type() == QVariant::String
)))
1026 qWarning("Cannot open document for this QAction!");
1030 //Try to open exitsing document file
1031 const QFileInfo
document(action
->data().toString());
1032 if(document
.exists() && document
.isFile() && (document
.size() >= 1024))
1034 QDesktopServices::openUrl(QUrl::fromLocalFile(document
.canonicalFilePath()));
1038 //Document not found -> fallback mode!
1039 qWarning("Document '%s' not found -> redirecting to the website!", MUTILS_UTF8(document
.fileName()));
1040 const QUrl
url(QString("%1/%2").arg(QString::fromLatin1(g_documents_base_url
), document
.fileName()));
1041 QDesktopServices::openUrl(url
);
1044 ////////////////////////////////////////////////////////////
1046 ////////////////////////////////////////////////////////////
1049 * Window is about to be shown
1051 void MainWindow::showEvent(QShowEvent
*event
)
1055 sourceModelChanged();
1057 if(!event
->spontaneous())
1059 WITH_BLOCKED_SIGNALS(ui
->tabWidget
, setCurrentIndex
, 0);
1060 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
1063 if(m_firstTimeShown
)
1065 m_firstTimeShown
= false;
1066 QTimer::singleShot(0, this, SLOT(windowShown()));
1070 if(m_settings
->dropBoxWidgetEnabled())
1072 m_dropBox
->setVisible(true);
1078 * Re-translate the UI
1080 void MainWindow::changeEvent(QEvent
*e
)
1082 QMainWindow::changeEvent(e
);
1083 if(e
->type() != QEvent::LanguageChange
)
1088 int comboBoxIndex
[6];
1090 //Backup combobox indices, as retranslateUi() resets
1091 comboBoxIndex
[0] = ui
->comboBoxMP3ChannelMode
->currentIndex();
1092 comboBoxIndex
[1] = ui
->comboBoxSamplingRate
->currentIndex();
1093 comboBoxIndex
[2] = ui
->comboBoxAACProfile
->currentIndex();
1094 comboBoxIndex
[3] = ui
->comboBoxAftenCodingMode
->currentIndex();
1095 comboBoxIndex
[4] = ui
->comboBoxAftenDRCMode
->currentIndex();
1096 comboBoxIndex
[5] = ui
->comboBoxOpusFramesize
->currentIndex();
1098 //Re-translate from UIC
1099 ui
->retranslateUi(this);
1101 //Restore combobox indices
1102 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(comboBoxIndex
[0]);
1103 ui
->comboBoxSamplingRate
->setCurrentIndex(comboBoxIndex
[1]);
1104 ui
->comboBoxAACProfile
->setCurrentIndex(comboBoxIndex
[2]);
1105 ui
->comboBoxAftenCodingMode
->setCurrentIndex(comboBoxIndex
[3]);
1106 ui
->comboBoxAftenDRCMode
->setCurrentIndex(comboBoxIndex
[4]);
1107 ui
->comboBoxOpusFramesize
->setCurrentIndex(comboBoxIndex
[5]);
1109 //Update the window title
1112 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
1114 else if(lamexp_version_demo())
1116 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
1119 //Manually re-translate widgets that UIC doesn't handle
1120 m_outputFolderNoteBox
->setText(tr("Initializing directory outline, please be patient..."));
1121 m_dropNoteLabel
->setText(QString("<br><img src=\":/images/DropZone.png\"><br><br>%1").arg(tr("You can drop in audio files here!")));
1122 if(QLabel
*cornerWidget
= dynamic_cast<QLabel
*>(ui
->menubar
->cornerWidget()))
1124 cornerWidget
->setText(QString("<nobr><img src=\":/icons/exclamation_small.png\"> <b style=\"color:darkred\">%1</b> </nobr>").arg(tr("Check for Updates")));
1126 m_showDetailsContextAction
->setText(tr("Show Details"));
1127 m_previewContextAction
->setText(tr("Open File in External Application"));
1128 m_findFileContextAction
->setText(tr("Browse File Location"));
1129 m_showFolderContextAction
->setText(tr("Browse Selected Folder"));
1130 m_refreshFolderContextAction
->setText(tr("Refresh Directory Outline"));
1131 m_goUpFolderContextAction
->setText(tr("Go To Parent Directory"));
1132 m_addFavoriteFolderAction
->setText(tr("Bookmark Current Output Folder"));
1133 m_exportCsvContextAction
->setText(tr("Export Meta Tags to CSV File"));
1134 m_importCsvContextAction
->setText(tr("Import Meta Tags from CSV File"));
1137 m_metaInfoModel
->clearData();
1138 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
1139 updateEncoder(m_settings
->compressionEncoder());
1140 updateLameAlgoQuality(ui
->sliderLameAlgoQuality
->value());
1141 updateMaximumInstances(ui
->sliderMaxInstances
->value());
1142 renameOutputPatternChanged(ui
->lineEditRenamePattern
->text(), true);
1144 //Re-install shell integration
1145 if(m_settings
->shellIntegrationEnabled())
1147 ShellIntegration::install();
1150 //Translate system menu
1151 MUtils::GUI::sysmenu_update(this, IDM_ABOUTBOX
, ui
->buttonAbout
->text());
1153 //Force resize event
1154 QApplication::postEvent(this, new QResizeEvent(this->size(), QSize()));
1155 for(QObjectList::ConstIterator iter
= this->children().constBegin(); iter
!= this->children().constEnd(); iter
++)
1157 if(QWidget
*child
= dynamic_cast<QWidget
*>(*iter
))
1159 QApplication::postEvent(child
, new QResizeEvent(child
->size(), QSize()));
1163 //Force tabe page change
1164 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
1168 * File dragged over window
1170 void MainWindow::dragEnterEvent(QDragEnterEvent
*event
)
1172 QStringList formats
= event
->mimeData()->formats();
1174 if(formats
.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive
) && formats
.contains("text/uri-list", Qt::CaseInsensitive
))
1176 event
->acceptProposedAction();
1181 * File dropped onto window
1183 void MainWindow::dropEvent(QDropEvent
*event
)
1185 m_droppedFileList
->clear();
1186 (*m_droppedFileList
) << event
->mimeData()->urls();
1187 if(!m_droppedFileList
->isEmpty())
1189 PLAY_SOUND_OPTIONAL("drop", true);
1190 QTimer::singleShot(0, this, SLOT(handleDroppedFiles()));
1195 * Window tries to close
1197 void MainWindow::closeEvent(QCloseEvent
*event
)
1199 if(BANNER_VISIBLE
|| m_delayedFileTimer
->isActive())
1201 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
1212 * Window was resized
1214 void MainWindow::resizeEvent(QResizeEvent
*event
)
1216 if(event
) QMainWindow::resizeEvent(event
);
1218 if(QWidget
*port
= ui
->sourceFileView
->viewport())
1220 m_dropNoteLabel
->setGeometry(port
->geometry());
1223 if(QWidget
*port
= ui
->outputFolderView
->viewport())
1225 m_outputFolderNoteBox
->setGeometry(16, (port
->height() - 64) / 2, port
->width() - 32, 64);
1230 * Key press event filter
1232 void MainWindow::keyPressEvent(QKeyEvent
*e
)
1234 if(e
->key() == Qt::Key_Delete
)
1236 if(ui
->sourceFileView
->isVisible())
1238 QTimer::singleShot(0, this, SLOT(removeFileButtonClicked()));
1243 if(e
->modifiers().testFlag(Qt::ControlModifier
) && (e
->key() == Qt::Key_F5
))
1245 initializeTranslation();
1246 MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
1250 if(e
->key() == Qt::Key_F5
)
1252 if(ui
->outputFolderView
->isVisible())
1254 QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
1259 QMainWindow::keyPressEvent(e
);
1265 bool MainWindow::eventFilter(QObject
*obj
, QEvent
*event
)
1267 if(obj
== m_fileSystemModel
)
1269 if(QApplication::overrideCursor() == NULL
)
1271 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
1272 QTimer::singleShot(250, this, SLOT(restoreCursor()));
1276 return QMainWindow::eventFilter(obj
, event
);
1279 bool MainWindow::event(QEvent
*e
)
1283 case MUtils::GUI::USER_EVENT_QUERYENDSESSION
:
1284 qWarning("System is shutting down, main window prepares to close...");
1285 if(BANNER_VISIBLE
) m_banner
->close();
1286 if(m_delayedFileTimer
->isActive()) m_delayedFileTimer
->stop();
1288 case MUtils::GUI::USER_EVENT_ENDSESSION
:
1289 qWarning("System is shutting down, main window will close now...");
1294 QApplication::processEvents(QEventLoop::WaitForMoreEvents
& QEventLoop::ExcludeUserInputEvents
);
1297 m_fileListModel
->clearFiles();
1299 case QEvent::MouseButtonPress
:
1300 if(ui
->outputFolderEdit
->isVisible())
1302 QTimer::singleShot(0, this, SLOT(outputFolderEditFinished()));
1305 return QMainWindow::event(e
);
1309 bool MainWindow::winEvent(MSG
*message
, long *result
)
1311 if(MUtils::GUI::sysmenu_check_msg(message
, IDM_ABOUTBOX
))
1313 QTimer::singleShot(0, ui
->buttonAbout
, SLOT(click()));
1320 ////////////////////////////////////////////////////////////
1322 ////////////////////////////////////////////////////////////
1324 // =========================================================
1325 // Show window slots
1326 // =========================================================
1331 void MainWindow::windowShown(void)
1333 const MUtils::OS::ArgumentMap
&arguments
= MUtils::OS::arguments(); //QApplication::arguments();
1335 //Force resize event
1339 const bool firstRun
= arguments
.contains("first-run");
1342 if((m_settings
->licenseAccepted() <= 0) || firstRun
)
1344 int iAccepted
= m_settings
->licenseAccepted();
1346 if((iAccepted
== 0) || firstRun
)
1348 AboutDialog
*about
= new AboutDialog(m_settings
, this, true);
1349 iAccepted
= about
->exec();
1350 if(iAccepted
<= 0) iAccepted
= -2;
1351 MUTILS_DELETE(about
);
1356 m_settings
->licenseAccepted(++iAccepted
);
1357 m_settings
->syncNow();
1358 QApplication::processEvents();
1359 MUtils::Sound::play_sound("whammy", false);
1360 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
1361 QFileInfo uninstallerInfo
= QFileInfo(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()));
1362 if(uninstallerInfo
.exists())
1364 QString uninstallerDir
= uninstallerInfo
.canonicalPath();
1365 QString uninstallerPath
= uninstallerInfo
.canonicalFilePath();
1366 for(int i
= 0; i
< 3; i
++)
1368 if(MUtils::OS::shell_open(this, QDir::toNativeSeparators(uninstallerPath
), "/Force", QDir::toNativeSeparators(uninstallerDir
))) break;
1371 QApplication::quit();
1375 MUtils::Sound::play_sound("woohoo", false);
1376 m_settings
->licenseAccepted(1);
1377 m_settings
->syncNow();
1378 if(lamexp_version_demo()) showAnnounceBox();
1381 //Check for expiration
1382 if(lamexp_version_demo())
1384 if(MUtils::OS::current_date() >= lamexp_version_expires())
1386 qWarning("Binary has expired !!!");
1387 MUtils::Sound::play_sound("whammy", false);
1388 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)
1392 QApplication::quit();
1397 //Slow startup indicator
1398 if(m_settings
->slowStartup() && m_settings
->antivirNotificationsEnabled())
1401 message
+= NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
1402 message
+= NOBR(tr("Please refer to the %1 document for details and solutions!")).arg("<a href=\"http://lamexp.sourceforge.net/doc/FAQ.html#df406578\">F.A.Q.</a>").append("<br>");
1403 if(QMessageBox::warning(this, tr("Slow Startup"), message
, tr("Discard"), tr("Don't Show Again")) == 1)
1405 m_settings
->antivirNotificationsEnabled(false);
1406 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
1411 if(MUtils::OS::current_date() >= MUtils::Version::app_build_date().addYears(1))
1413 qWarning("Binary is more than a year old, time to update!");
1414 SHOW_CORNER_WIDGET(true);
1415 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"));
1419 if(checkForUpdates())
1421 QApplication::quit();
1426 QApplication::quit();
1429 QEventLoop loop
; QTimer::singleShot(7000, &loop
, SLOT(quit()));
1430 MUtils::Sound::play_sound("waiting", true);
1431 SHOW_BANNER_ARG(tr("Skipping update check this time, please be patient..."), &loop
);
1437 QDate lastUpdateCheck
= QDate::fromString(m_settings
->autoUpdateLastCheck(), Qt::ISODate
);
1438 if((!firstRun
) && ((!lastUpdateCheck
.isValid()) || (MUtils::OS::current_date() >= lastUpdateCheck
.addDays(14))))
1440 SHOW_CORNER_WIDGET(true);
1441 if(m_settings
->autoUpdateEnabled())
1443 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)
1445 if(checkForUpdates())
1447 QApplication::quit();
1455 //Check for AAC support
1456 const int aacEncoder
= EncoderRegistry::getAacEncoder();
1457 if(aacEncoder
== SettingsModel::AAC_ENCODER_NERO
)
1459 if(m_settings
->neroAacNotificationsEnabled())
1461 if(lamexp_tools_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1463 QString messageText
;
1464 messageText
+= NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1465 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_tools_version("neroAacEnc.exe"), tr("n/a")))).append("<br><br>");
1466 messageText
+= NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1467 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br><br>";
1468 messageText
+= NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
1469 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText
);
1475 if(m_settings
->neroAacNotificationsEnabled() && (aacEncoder
<= SettingsModel::AAC_ENCODER_NONE
))
1477 QString appPath
= QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1478 if(appPath
.isEmpty()) appPath
= QCoreApplication::applicationDirPath();
1479 QString messageText
;
1480 messageText
+= NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1481 messageText
+= NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1482 messageText
+= NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1483 messageText
+= QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath
)));
1484 messageText
+= NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1485 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br>";
1486 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText
, tr("Discard"), tr("Don't Show Again")) == 1)
1488 m_settings
->neroAacNotificationsEnabled(false);
1489 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1494 //Add files from the command-line
1495 QStringList addedFiles
;
1496 foreach(const QString
&value
, arguments
.values("add"))
1498 if(!value
.isEmpty())
1500 QFileInfo
currentFile(value
);
1501 qDebug("Adding file from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1502 addedFiles
.append(currentFile
.absoluteFilePath());
1505 if(!addedFiles
.isEmpty())
1507 addFilesDelayed(addedFiles
);
1510 //Add folders from the command-line
1511 foreach(const QString
&value
, arguments
.values("add-folder"))
1513 if(!value
.isEmpty())
1515 const QFileInfo
currentFile(value
);
1516 qDebug("Adding folder from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1517 addFolder(currentFile
.absoluteFilePath(), false, true);
1520 foreach(const QString
&value
, arguments
.values("add-recursive"))
1522 if(!value
.isEmpty())
1524 const QFileInfo
currentFile(value
);
1525 qDebug("Adding folder recursively from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1526 addFolder(currentFile
.absoluteFilePath(), true, true);
1530 //Enable shell integration
1531 if(m_settings
->shellIntegrationEnabled())
1533 ShellIntegration::install();
1536 //Make DropBox visible
1537 if(m_settings
->dropBoxWidgetEnabled())
1539 m_dropBox
->setVisible(true);
1546 void MainWindow::showAnnounceBox(void)
1548 const unsigned int timeout
= 8U;
1550 const QString announceText
= QString("%1<br><br>%2<br><nobr><tt>%3</tt></nobr><br>").arg
1552 NOBR("We are still looking for LameXP translators!"),
1553 NOBR("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:"),
1554 LINK("http://lamexp.sourceforge.net/doc/Translate.html")
1557 QMessageBox
*announceBox
= new QMessageBox(QMessageBox::Warning
, "We want you!", announceText
, QMessageBox::NoButton
, this);
1558 announceBox
->setWindowFlags(Qt::Window
| Qt::WindowTitleHint
| Qt::CustomizeWindowHint
);
1559 announceBox
->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1561 QTimer
*timers
[timeout
+1];
1562 QPushButton
*buttons
[timeout
+1];
1564 for(unsigned int i
= 0; i
<= timeout
; i
++)
1566 QString text
= (i
> 0) ? QString("%1 (%2)").arg(tr("Discard"), QString::number(i
)) : tr("Discard");
1567 buttons
[i
] = announceBox
->addButton(text
, (i
> 0) ? QMessageBox::NoRole
: QMessageBox::AcceptRole
);
1570 for(unsigned int i
= 0; i
<= timeout
; i
++)
1572 buttons
[i
]->setEnabled(i
== 0);
1573 buttons
[i
]->setVisible(i
== timeout
);
1576 for(unsigned int i
= 0; i
< timeout
; i
++)
1578 timers
[i
] = new QTimer(this);
1579 timers
[i
]->setSingleShot(true);
1580 timers
[i
]->setInterval(1000);
1581 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
+1], SLOT(hide()));
1582 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
], SLOT(show()));
1585 connect(timers
[i
], SIGNAL(timeout()), timers
[i
-1], SLOT(start()));
1589 timers
[timeout
-1]->start();
1590 announceBox
->exec();
1592 for(unsigned int i
= 0; i
< timeout
; i
++)
1595 MUTILS_DELETE(timers
[i
]);
1598 MUTILS_DELETE(announceBox
);
1601 // =========================================================
1602 // Main button solots
1603 // =========================================================
1608 void MainWindow::encodeButtonClicked(void)
1610 static const unsigned __int64 oneGigabyte
= 1073741824ui
64;
1611 static const unsigned __int64 minimumFreeDiskspaceMultiplier
= 2ui
64;
1612 static const char *writeTestBuffer
= "LAMEXP_WRITE_TEST";
1616 if(m_fileListModel
->rowCount() < 1)
1618 QMessageBox::warning(this, tr("LameXP"), NOBR(tr("You must add at least one file to the list before proceeding!")));
1619 ui
->tabWidget
->setCurrentIndex(0);
1623 QString tempFolder
= m_settings
->customTempPathEnabled() ? m_settings
->customTempPath() : MUtils::temp_folder();
1624 if(!QFileInfo(tempFolder
).exists() || !QFileInfo(tempFolder
).isDir())
1626 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)
1628 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabledDefault()));
1633 quint64 currentFreeDiskspace
= 0;
1634 if(MUtils::OS::free_diskspace(tempFolder
, currentFreeDiskspace
))
1636 if(currentFreeDiskspace
< (oneGigabyte
* minimumFreeDiskspaceMultiplier
))
1638 QStringList tempFolderParts
= tempFolder
.split("/", QString::SkipEmptyParts
, Qt::CaseInsensitive
);
1639 tempFolderParts
.takeLast();
1640 PLAY_SOUND_OPTIONAL("whammy", false);
1641 QString lowDiskspaceMsg
= QString("%1<br>%2<br><br>%3<br>%4<br>").arg
1643 NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier
))),
1644 NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")),
1645 NOBR(tr("Your TEMP folder is located at:")),
1646 QString("<nobr><tt>%1</tt></nobr>").arg(FSLINK(tempFolderParts
.join("\\")))
1648 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg
, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1651 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER
)), QStringList() << "/D" << tempFolderParts
.first());
1656 QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!")));
1662 switch(m_settings
->compressionEncoder())
1664 case SettingsModel::MP3Encoder
:
1665 case SettingsModel::VorbisEncoder
:
1666 case SettingsModel::AACEncoder
:
1667 case SettingsModel::AC3Encoder
:
1668 case SettingsModel::FLACEncoder
:
1669 case SettingsModel::OpusEncoder
:
1670 case SettingsModel::DCAEncoder
:
1671 case SettingsModel::MACEncoder
:
1672 case SettingsModel::PCMEncoder
:
1675 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1676 ui
->tabWidget
->setCurrentIndex(3);
1680 if(!m_settings
->outputToSourceDir())
1682 QFile
writeTest(QString("%1/~%2.txt").arg(m_settings
->outputDir(), MUtils::rand_str()));
1683 if(!(writeTest
.open(QIODevice::ReadWrite
) && (writeTest
.write(writeTestBuffer
) == strlen(writeTestBuffer
))))
1685 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!")));
1686 ui
->tabWidget
->setCurrentIndex(1);
1703 void MainWindow::aboutButtonClicked(void)
1709 AboutDialog
*aboutBox
= new AboutDialog(m_settings
, this);
1711 MUTILS_DELETE(aboutBox
);
1718 void MainWindow::closeButtonClicked(void)
1724 // =========================================================
1726 // =========================================================
1731 void MainWindow::tabPageChanged(int idx
, const bool silent
)
1735 //Update "view" menu
1736 QList
<QAction
*> actions
= m_tabActionGroup
->actions();
1737 for(int i
= 0; i
< actions
.count(); i
++)
1740 int actionIndex
= actions
.at(i
)->data().toInt(&ok
);
1741 if(ok
&& actionIndex
== idx
)
1743 actions
.at(i
)->setChecked(true);
1750 PLAY_SOUND_OPTIONAL("tick", true);
1753 int initialWidth
= this->width();
1754 int maximumWidth
= QApplication::desktop()->availableGeometry().width();
1756 //Make sure all tab headers are fully visible
1757 if(this->isVisible())
1759 int delta
= ui
->tabWidget
->sizeHint().width() - ui
->tabWidget
->width();
1762 this->resize(qMin(this->width() + delta
, maximumWidth
), this->height());
1766 //Tab specific operations
1767 if(idx
== ui
->tabWidget
->indexOf(ui
->tabOptions
) && ui
->scrollArea
->widget() && this->isVisible())
1769 ui
->scrollArea
->widget()->updateGeometry();
1770 ui
->scrollArea
->viewport()->updateGeometry();
1771 qApp
->processEvents();
1772 int delta
= ui
->scrollArea
->widget()->width() - ui
->scrollArea
->viewport()->width();
1775 this->resize(qMin(this->width() + delta
, maximumWidth
), this->height());
1778 else if(idx
== ui
->tabWidget
->indexOf(ui
->tabSourceFiles
))
1780 m_dropNoteLabel
->setGeometry(0, 0, ui
->sourceFileView
->width(), ui
->sourceFileView
->height());
1782 else if(idx
== ui
->tabWidget
->indexOf(ui
->tabOutputDir
))
1784 if(!m_fileSystemModel
)
1786 QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
1790 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
1794 //Center window around previous position
1795 if(initialWidth
< this->width())
1797 QPoint prevPos
= this->pos();
1798 int delta
= (this->width() - initialWidth
) >> 2;
1799 move(prevPos
.x() - delta
, prevPos
.y());
1804 * Tab action triggered
1806 void MainWindow::tabActionActivated(QAction
*action
)
1808 if(action
&& action
->data().isValid())
1811 int index
= action
->data().toInt(&ok
);
1814 ui
->tabWidget
->setCurrentIndex(index
);
1819 // =========================================================
1821 // =========================================================
1824 * Handle corner widget Event
1826 void MainWindow::cornerWidgetEventOccurred(QWidget
*sender
, QEvent
*event
)
1828 if(event
->type() == QEvent::MouseButtonPress
)
1830 QTimer::singleShot(0, this, SLOT(checkUpdatesActionActivated()));
1834 // =========================================================
1836 // =========================================================
1839 * Style action triggered
1841 void MainWindow::styleActionActivated(QAction
*action
)
1843 //Change style setting
1844 if(action
&& action
->data().isValid())
1847 int actionIndex
= action
->data().toInt(&ok
);
1850 m_settings
->interfaceStyle(actionIndex
);
1854 //Set up the new style
1855 switch(m_settings
->interfaceStyle())
1858 if(ui
->actionStyleCleanlooks
->isEnabled())
1860 ui
->actionStyleCleanlooks
->setChecked(true);
1861 QApplication::setStyle(new QCleanlooksStyle());
1865 if(ui
->actionStyleWindowsVista
->isEnabled())
1867 ui
->actionStyleWindowsVista
->setChecked(true);
1868 QApplication::setStyle(new QWindowsVistaStyle());
1872 if(ui
->actionStyleWindowsXP
->isEnabled())
1874 ui
->actionStyleWindowsXP
->setChecked(true);
1875 QApplication::setStyle(new QWindowsXPStyle());
1879 if(ui
->actionStyleWindowsClassic
->isEnabled())
1881 ui
->actionStyleWindowsClassic
->setChecked(true);
1882 QApplication::setStyle(new QWindowsStyle());
1886 ui
->actionStylePlastique
->setChecked(true);
1887 QApplication::setStyle(new QPlastiqueStyle());
1891 //Force re-translate after style change
1892 if(QEvent
*e
= new QEvent(QEvent::LanguageChange
))
1899 const type_info
&styleType
= typeid(*qApp
->style());
1900 const bool bTransparent
= ((typeid(QWindowsVistaStyle
) == styleType
) || (typeid(QWindowsXPStyle
) == styleType
));
1901 MAKE_TRANSPARENT(ui
->scrollArea
, bTransparent
);
1903 //Also force a re-size event
1904 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
1909 * Language action triggered
1911 void MainWindow::languageActionActivated(QAction
*action
)
1913 if(action
->data().type() == QVariant::String
)
1915 QString langId
= action
->data().toString();
1917 if(MUtils::Translation::install_translator(langId
))
1919 action
->setChecked(true);
1920 ui
->actionLoadTranslationFromFile
->setChecked(false);
1921 m_settings
->currentLanguage(langId
);
1922 m_settings
->currentLanguageFile(QString());
1928 * Load language from file action triggered
1930 void MainWindow::languageFromFileActionActivated(bool checked
)
1932 QFileDialog
dialog(this, tr("Load Translation"));
1933 dialog
.setFileMode(QFileDialog::ExistingFile
);
1934 dialog
.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
1938 QStringList selectedFiles
= dialog
.selectedFiles();
1939 const QString qmFile
= QFileInfo(selectedFiles
.first()).canonicalFilePath();
1940 if(MUtils::Translation::install_translator_from_file(qmFile
))
1942 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
1943 while(!actions
.isEmpty())
1945 actions
.takeFirst()->setChecked(false);
1947 ui
->actionLoadTranslationFromFile
->setChecked(true);
1948 m_settings
->currentLanguageFile(qmFile
);
1952 languageActionActivated(m_languageActionGroup
->actions().first());
1957 // =========================================================
1959 // =========================================================
1962 * Disable update reminder action
1964 void MainWindow::disableUpdateReminderActionTriggered(bool checked
)
1968 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))
1970 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!"))));
1971 m_settings
->autoUpdateEnabled(false);
1975 m_settings
->autoUpdateEnabled(true);
1980 QMessageBox::information(this, tr("Update Reminder"), NOBR(tr("The update reminder has been re-enabled.")));
1981 m_settings
->autoUpdateEnabled(true);
1984 ui
->actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
1988 * Disable sound effects action
1990 void MainWindow::disableSoundsActionTriggered(bool checked
)
1994 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))
1996 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("All sound effects have been disabled.")));
1997 m_settings
->soundsEnabled(false);
2001 m_settings
->soundsEnabled(true);
2006 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("The sound effects have been re-enabled.")));
2007 m_settings
->soundsEnabled(true);
2010 ui
->actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
2014 * Disable Nero AAC encoder action
2016 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked
)
2020 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))
2022 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("All Nero AAC Encoder notifications have been disabled.")));
2023 m_settings
->neroAacNotificationsEnabled(false);
2027 m_settings
->neroAacNotificationsEnabled(true);
2032 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("The Nero AAC Encoder notifications have been re-enabled.")));
2033 m_settings
->neroAacNotificationsEnabled(true);
2036 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
2040 * Disable slow startup action
2042 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked
)
2046 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))
2048 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been disabled.")));
2049 m_settings
->antivirNotificationsEnabled(false);
2053 m_settings
->antivirNotificationsEnabled(true);
2058 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been re-enabled.")));
2059 m_settings
->antivirNotificationsEnabled(true);
2062 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
2066 * Import a Cue Sheet file
2068 void MainWindow::importCueSheetActionTriggered(bool checked
)
2077 QString selectedCueFile
;
2079 if(MUtils::GUI::themes_enabled())
2081 selectedCueFile
= QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings
->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
2085 QFileDialog
dialog(this, tr("Open Cue Sheet"));
2086 dialog
.setFileMode(QFileDialog::ExistingFile
);
2087 dialog
.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
2088 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2091 selectedCueFile
= dialog
.selectedFiles().first();
2095 if(!selectedCueFile
.isEmpty())
2097 m_settings
->mostRecentInputPath(QFileInfo(selectedCueFile
).canonicalPath());
2098 CueImportDialog
*cueImporter
= new CueImportDialog(this, m_fileListModel
, selectedCueFile
, m_settings
);
2099 result
= cueImporter
->exec();
2100 MUTILS_DELETE(cueImporter
);
2103 if(result
== QDialog::Accepted
)
2105 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2106 ui
->sourceFileView
->update();
2107 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2108 ui
->sourceFileView
->scrollToBottom();
2109 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2112 if(result
!= (-1)) break;
2118 * Show the "drop box" widget
2120 void MainWindow::showDropBoxWidgetActionTriggered(bool checked
)
2122 m_settings
->dropBoxWidgetEnabled(true);
2124 if(!m_dropBox
->isVisible())
2127 QTimer::singleShot(2500, m_dropBox
, SLOT(showToolTip()));
2130 MUtils::GUI::blink_window(m_dropBox
);
2134 * Check for beta (pre-release) updates
2136 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked
)
2138 bool checkUpdatesNow
= false;
2142 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))
2144 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")))
2146 checkUpdatesNow
= true;
2148 m_settings
->autoUpdateCheckBeta(true);
2152 m_settings
->autoUpdateCheckBeta(false);
2157 QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on.")));
2158 m_settings
->autoUpdateCheckBeta(false);
2161 ui
->actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta());
2165 if(checkForUpdates())
2167 QApplication::quit();
2173 * Hibernate computer action
2175 void MainWindow::hibernateComputerActionTriggered(bool checked
)
2179 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))
2181 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will hibernate the computer on shutdown from now on.")));
2182 m_settings
->hibernateComputer(true);
2186 m_settings
->hibernateComputer(false);
2191 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will <i>not</i> hibernate the computer on shutdown from now on.")));
2192 m_settings
->hibernateComputer(false);
2195 ui
->actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
2199 * Disable shell integration action
2201 void MainWindow::disableShellIntegrationActionTriggered(bool checked
)
2205 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))
2207 ShellIntegration::remove();
2208 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been disabled.")));
2209 m_settings
->shellIntegrationEnabled(false);
2213 m_settings
->shellIntegrationEnabled(true);
2218 ShellIntegration::install();
2219 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been re-enabled.")));
2220 m_settings
->shellIntegrationEnabled(true);
2223 ui
->actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
2225 if(lamexp_version_portable() && ui
->actionDisableShellIntegration
->isChecked())
2227 ui
->actionDisableShellIntegration
->setEnabled(false);
2231 // =========================================================
2233 // =========================================================
2236 * Visit homepage action
2238 void MainWindow::visitHomepageActionActivated(void)
2240 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2242 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
2244 QDesktopServices::openUrl(QUrl(action
->data().toString()));
2252 void MainWindow::documentActionActivated(void)
2254 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2256 openDocumentLink(action
);
2261 * Check for updates action
2263 void MainWindow::checkUpdatesActionActivated(void)
2270 bFlag
= checkForUpdates();
2275 QApplication::quit();
2279 // =========================================================
2280 // Source file slots
2281 // =========================================================
2284 * Add file(s) button
2286 void MainWindow::addFilesButtonClicked(void)
2292 if(MUtils::GUI::themes_enabled())
2294 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2295 QStringList selectedFiles
= QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings
->mostRecentInputPath(), fileTypeFilters
.join(";;"));
2296 if(!selectedFiles
.isEmpty())
2298 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2299 addFiles(selectedFiles
);
2304 QFileDialog
dialog(this, tr("Add file(s)"));
2305 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2306 dialog
.setFileMode(QFileDialog::ExistingFiles
);
2307 dialog
.setNameFilter(fileTypeFilters
.join(";;"));
2308 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2311 QStringList selectedFiles
= dialog
.selectedFiles();
2312 if(!selectedFiles
.isEmpty())
2314 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2315 addFiles(selectedFiles
);
2323 * Open folder action
2325 void MainWindow::openFolderActionActivated(void)
2328 QString selectedFolder
;
2330 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2334 if(MUtils::GUI::themes_enabled())
2336 selectedFolder
= QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings
->mostRecentInputPath());
2340 QFileDialog
dialog(this, tr("Add Folder"));
2341 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
2342 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2345 selectedFolder
= dialog
.selectedFiles().first();
2349 if(!selectedFolder
.isEmpty())
2351 m_settings
->mostRecentInputPath(QDir(selectedFolder
).canonicalPath());
2352 addFolder(selectedFolder
, action
->data().toBool());
2359 * Remove file button
2361 void MainWindow::removeFileButtonClicked(void)
2363 if(ui
->sourceFileView
->currentIndex().isValid())
2365 int iRow
= ui
->sourceFileView
->currentIndex().row();
2366 m_fileListModel
->removeFile(ui
->sourceFileView
->currentIndex());
2367 ui
->sourceFileView
->selectRow(iRow
< m_fileListModel
->rowCount() ? iRow
: m_fileListModel
->rowCount()-1);
2372 * Clear files button
2374 void MainWindow::clearFilesButtonClicked(void)
2376 m_fileListModel
->clearFiles();
2380 * Move file up button
2382 void MainWindow::fileUpButtonClicked(void)
2384 if(ui
->sourceFileView
->currentIndex().isValid())
2386 int iRow
= ui
->sourceFileView
->currentIndex().row() - 1;
2387 m_fileListModel
->moveFile(ui
->sourceFileView
->currentIndex(), -1);
2388 ui
->sourceFileView
->selectRow(iRow
>= 0 ? iRow
: 0);
2393 * Move file down button
2395 void MainWindow::fileDownButtonClicked(void)
2397 if(ui
->sourceFileView
->currentIndex().isValid())
2399 int iRow
= ui
->sourceFileView
->currentIndex().row() + 1;
2400 m_fileListModel
->moveFile(ui
->sourceFileView
->currentIndex(), 1);
2401 ui
->sourceFileView
->selectRow(iRow
< m_fileListModel
->rowCount() ? iRow
: m_fileListModel
->rowCount()-1);
2406 * Show details button
2408 void MainWindow::showDetailsButtonClicked(void)
2413 MetaInfoDialog
*metaInfoDialog
= new MetaInfoDialog(this);
2414 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2416 while(index
.isValid())
2420 index
= m_fileListModel
->index(index
.row() + 1, index
.column());
2421 ui
->sourceFileView
->selectRow(index
.row());
2425 index
= m_fileListModel
->index(index
.row() - 1, index
.column());
2426 ui
->sourceFileView
->selectRow(index
.row());
2429 AudioFileModel
&file
= (*m_fileListModel
)[index
];
2432 iResult
= metaInfoDialog
->exec(file
, index
.row() > 0, index
.row() < m_fileListModel
->rowCount() - 1);
2435 //Copy all info to Meta Info tab
2436 if(iResult
== INT_MAX
)
2438 m_metaInfoModel
->assignInfoFrom(file
);
2439 ui
->tabWidget
->setCurrentIndex(ui
->tabWidget
->indexOf(ui
->tabMetaData
));
2446 MUTILS_DELETE(metaInfoDialog
);
2447 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2448 sourceFilesScrollbarMoved(0);
2452 * Show context menu for source files
2454 void MainWindow::sourceFilesContextMenu(const QPoint
&pos
)
2456 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
2457 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
2461 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
2463 m_sourceFilesContextMenu
->popup(sender
->mapToGlobal(pos
));
2469 * Scrollbar of source files moved
2471 void MainWindow::sourceFilesScrollbarMoved(int)
2473 ui
->sourceFileView
->resizeColumnToContents(0);
2477 * Open selected file in external player
2479 void MainWindow::previewContextActionTriggered(void)
2481 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2482 if(!index
.isValid())
2487 if(!MUtils::OS::open_media_file(m_fileListModel
->getFile(index
).filePath()))
2489 qDebug("Player not found, falling back to default application...");
2490 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel
->getFile(index
).filePath()));
2495 * Find selected file in explorer
2497 void MainWindow::findFileContextActionTriggered(void)
2499 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2502 QString systemRootPath
;
2504 QDir
systemRoot(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER
));
2505 if(systemRoot
.exists() && systemRoot
.cdUp())
2507 systemRootPath
= systemRoot
.canonicalPath();
2510 if(!systemRootPath
.isEmpty())
2512 QFileInfo
explorer(QString("%1/explorer.exe").arg(systemRootPath
));
2513 if(explorer
.exists() && explorer
.isFile())
2515 QProcess::execute(explorer
.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
2521 qWarning("SystemRoot directory could not be detected!");
2527 * Add all dropped files
2529 void MainWindow::handleDroppedFiles(void)
2533 static const int MIN_COUNT
= 16;
2534 const QString bannerText
= tr("Loading dropped files or folders, please wait...");
2535 bool bUseBanner
= false;
2537 SHOW_BANNER_CONDITIONALLY(bUseBanner
, (m_droppedFileList
->count() >= MIN_COUNT
), bannerText
);
2539 QStringList droppedFiles
;
2540 while(!m_droppedFileList
->isEmpty())
2542 QFileInfo
file(m_droppedFileList
->takeFirst().toLocalFile());
2543 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2552 qDebug("Dropped File: %s", MUTILS_UTF8(file
.canonicalFilePath()));
2553 droppedFiles
<< file
.canonicalFilePath();
2559 qDebug("Dropped Folder: %s", MUTILS_UTF8(file
.canonicalFilePath()));
2560 QFileInfoList list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Files
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
);
2561 if(list
.count() > 0)
2563 SHOW_BANNER_CONDITIONALLY(bUseBanner
, (list
.count() >= MIN_COUNT
), bannerText
);
2564 for(QFileInfoList::ConstIterator iter
= list
.constBegin(); iter
!= list
.constEnd(); iter
++)
2566 droppedFiles
<< (*iter
).canonicalFilePath();
2571 list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
);
2572 SHOW_BANNER_CONDITIONALLY(bUseBanner
, (list
.count() >= MIN_COUNT
), bannerText
);
2573 for(QFileInfoList::ConstIterator iter
= list
.constBegin(); iter
!= list
.constEnd(); iter
++)
2575 qDebug("Descending to Folder: %s", MUTILS_UTF8((*iter
).canonicalFilePath()));
2576 m_droppedFileList
->prepend(QUrl::fromLocalFile((*iter
).canonicalFilePath()));
2587 if(!droppedFiles
.isEmpty())
2589 addFiles(droppedFiles
);
2594 * Add all pending files
2596 void MainWindow::handleDelayedFiles(void)
2598 m_delayedFileTimer
->stop();
2600 if(m_delayedFileList
->isEmpty())
2607 m_delayedFileTimer
->start(5000);
2611 WITH_BLOCKED_SIGNALS(ui
->tabWidget
, setCurrentIndex
, 0);
2612 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
2614 QStringList selectedFiles
;
2615 while(!m_delayedFileList
->isEmpty())
2617 QFileInfo currentFile
= QFileInfo(m_delayedFileList
->takeFirst());
2618 if(!currentFile
.exists() || !currentFile
.isFile())
2622 selectedFiles
<< currentFile
.canonicalFilePath();
2625 addFiles(selectedFiles
);
2629 * Export Meta tags to CSV file
2631 void MainWindow::exportCsvContextActionTriggered(void)
2635 QString selectedCsvFile
;
2637 if(MUtils::GUI::themes_enabled())
2639 selectedCsvFile
= QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2643 QFileDialog
dialog(this, tr("Save CSV file"));
2644 dialog
.setFileMode(QFileDialog::AnyFile
);
2645 dialog
.setAcceptMode(QFileDialog::AcceptSave
);
2646 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2647 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2650 selectedCsvFile
= dialog
.selectedFiles().first();
2654 if(!selectedCsvFile
.isEmpty())
2656 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2657 switch(m_fileListModel
->exportToCsv(selectedCsvFile
))
2659 case FileListModel::CsvError_NoTags
:
2660 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, there are no meta tags that can be exported!")));
2662 case FileListModel::CsvError_FileOpen
:
2663 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to open CSV file for writing!")));
2665 case FileListModel::CsvError_FileWrite
:
2666 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to write to the CSV file!")));
2668 case FileListModel::CsvError_OK
:
2669 QMessageBox::information(this, tr("CSV Export"), NOBR(tr("The CSV files was created successfully!")));
2672 qWarning("exportToCsv: Unknown return code!");
2680 * Import Meta tags from CSV file
2682 void MainWindow::importCsvContextActionTriggered(void)
2686 QString selectedCsvFile
;
2688 if(MUtils::GUI::themes_enabled())
2690 selectedCsvFile
= QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2694 QFileDialog
dialog(this, tr("Open CSV file"));
2695 dialog
.setFileMode(QFileDialog::ExistingFile
);
2696 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2697 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2700 selectedCsvFile
= dialog
.selectedFiles().first();
2704 if(!selectedCsvFile
.isEmpty())
2706 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2707 switch(m_fileListModel
->importFromCsv(this, selectedCsvFile
))
2709 case FileListModel::CsvError_FileOpen
:
2710 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to open CSV file for reading!")));
2712 case FileListModel::CsvError_FileRead
:
2713 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to read from the CSV file!")));
2715 case FileListModel::CsvError_NoTags
:
2716 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, the CSV file does not contain any known fields!")));
2718 case FileListModel::CsvError_Incomplete
:
2719 QMessageBox::warning(this, tr("CSV Import"), NOBR(tr("CSV file is incomplete. Not all files were updated!")));
2721 case FileListModel::CsvError_OK
:
2722 QMessageBox::information(this, tr("CSV Import"), NOBR(tr("The CSV files was imported successfully!")));
2724 case FileListModel::CsvError_Aborted
:
2725 /* User aborted, ignore! */
2728 qWarning("exportToCsv: Unknown return code!");
2735 * Show or hide Drag'n'Drop notice after model reset
2737 void MainWindow::sourceModelChanged(void)
2739 m_dropNoteLabel
->setVisible(m_fileListModel
->rowCount() <= 0);
2742 // =========================================================
2743 // Output folder slots
2744 // =========================================================
2747 * Output folder changed (mouse clicked)
2749 void MainWindow::outputFolderViewClicked(const QModelIndex
&index
)
2751 if(index
.isValid() && (ui
->outputFolderView
->currentIndex() != index
))
2753 ui
->outputFolderView
->setCurrentIndex(index
);
2756 if(m_fileSystemModel
&& index
.isValid())
2758 QString selectedDir
= m_fileSystemModel
->filePath(index
);
2759 if(selectedDir
.length() < 3) selectedDir
.append(QDir::separator());
2760 ui
->outputFolderLabel
->setText(QDir::toNativeSeparators(selectedDir
));
2761 ui
->outputFolderLabel
->setToolTip(ui
->outputFolderLabel
->text());
2762 m_settings
->outputDir(selectedDir
);
2766 ui
->outputFolderLabel
->setText(QDir::toNativeSeparators(m_settings
->outputDir()));
2767 ui
->outputFolderLabel
->setToolTip(ui
->outputFolderLabel
->text());
2772 * Output folder changed (mouse moved)
2774 void MainWindow::outputFolderViewMoved(const QModelIndex
&index
)
2776 if(QApplication::mouseButtons() & Qt::LeftButton
)
2778 outputFolderViewClicked(index
);
2783 * Goto desktop button
2785 void MainWindow::gotoDesktopButtonClicked(void)
2787 if(!m_fileSystemModel
)
2789 qWarning("File system model not initialized yet!");
2793 QString desktopPath
= QDesktopServices::storageLocation(QDesktopServices::DesktopLocation
);
2795 if(!desktopPath
.isEmpty() && QDir(desktopPath
).exists())
2797 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(desktopPath
));
2798 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2799 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2803 ui
->buttonGotoDesktop
->setEnabled(false);
2808 * Goto home folder button
2810 void MainWindow::gotoHomeFolderButtonClicked(void)
2812 if(!m_fileSystemModel
)
2814 qWarning("File system model not initialized yet!");
2818 QString homePath
= QDesktopServices::storageLocation(QDesktopServices::HomeLocation
);
2820 if(!homePath
.isEmpty() && QDir(homePath
).exists())
2822 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(homePath
));
2823 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2824 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2828 ui
->buttonGotoHome
->setEnabled(false);
2833 * Goto music folder button
2835 void MainWindow::gotoMusicFolderButtonClicked(void)
2837 if(!m_fileSystemModel
)
2839 qWarning("File system model not initialized yet!");
2843 QString musicPath
= QDesktopServices::storageLocation(QDesktopServices::MusicLocation
);
2845 if(!musicPath
.isEmpty() && QDir(musicPath
).exists())
2847 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(musicPath
));
2848 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2849 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2853 ui
->buttonGotoMusic
->setEnabled(false);
2858 * Goto music favorite output folder
2860 void MainWindow::gotoFavoriteFolder(void)
2862 if(!m_fileSystemModel
)
2864 qWarning("File system model not initialized yet!");
2868 QAction
*item
= dynamic_cast<QAction
*>(QObject::sender());
2872 QDir
path(item
->data().toString());
2875 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(path
.canonicalPath()));
2876 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2877 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2881 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
2882 m_outputFolderFavoritesMenu
->removeAction(item
);
2883 item
->deleteLater();
2889 * Make folder button
2891 void MainWindow::makeFolderButtonClicked(void)
2895 if(!m_fileSystemModel
)
2897 qWarning("File system model not initialized yet!");
2901 QDir
basePath(m_fileSystemModel
->fileInfo(ui
->outputFolderView
->currentIndex()).absoluteFilePath());
2902 QString suggestedName
= tr("New Folder");
2904 if(!m_metaData
->artist().isEmpty() && !m_metaData
->album().isEmpty())
2906 suggestedName
= QString("%1 - %2").arg(m_metaData
->artist(),m_metaData
->album());
2908 else if(!m_metaData
->artist().isEmpty())
2910 suggestedName
= m_metaData
->artist();
2912 else if(!m_metaData
->album().isEmpty())
2914 suggestedName
=m_metaData
->album();
2918 for(int i
= 0; i
< m_fileListModel
->rowCount(); i
++)
2920 const AudioFileModel
&audioFile
= m_fileListModel
->getFile(m_fileListModel
->index(i
, 0));
2921 const AudioFileModel_MetaInfo
&fileMetaInfo
= audioFile
.metaInfo();
2923 if(!fileMetaInfo
.album().isEmpty() || !fileMetaInfo
.artist().isEmpty())
2925 if(!fileMetaInfo
.artist().isEmpty() && !fileMetaInfo
.album().isEmpty())
2927 suggestedName
= QString("%1 - %2").arg(fileMetaInfo
.artist(), fileMetaInfo
.album());
2929 else if(!fileMetaInfo
.artist().isEmpty())
2931 suggestedName
= fileMetaInfo
.artist();
2933 else if(!fileMetaInfo
.album().isEmpty())
2935 suggestedName
= fileMetaInfo
.album();
2942 suggestedName
= MUtils::clean_file_name(suggestedName
);
2946 bool bApplied
= false;
2947 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();
2951 folderName
= MUtils::clean_file_path(folderName
.simplified());
2953 if(folderName
.isEmpty())
2955 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
2960 QString newFolder
= folderName
;
2962 while(basePath
.exists(newFolder
))
2964 newFolder
= QString(folderName
).append(QString().sprintf(" (%d)", ++i
));
2967 if(basePath
.mkpath(newFolder
))
2969 QDir createdDir
= basePath
;
2970 if(createdDir
.cd(newFolder
))
2972 QModelIndex newIndex
= m_fileSystemModel
->index(createdDir
.canonicalPath());
2973 ui
->outputFolderView
->setCurrentIndex(newIndex
);
2974 outputFolderViewClicked(newIndex
);
2975 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2980 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!")));
2988 * Output to source dir changed
2990 void MainWindow::saveToSourceFolderChanged(void)
2992 m_settings
->outputToSourceDir(ui
->saveToSourceFolderCheckBox
->isChecked());
2996 * Prepend relative source file path to output file name changed
2998 void MainWindow::prependRelativePathChanged(void)
3000 m_settings
->prependRelativeSourcePath(ui
->prependRelativePathCheckBox
->isChecked());
3004 * Show context menu for output folder
3006 void MainWindow::outputFolderContextMenu(const QPoint
&pos
)
3008 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
3009 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
3011 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
3013 m_outputFolderContextMenu
->popup(sender
->mapToGlobal(pos
));
3018 * Show selected folder in explorer
3020 void MainWindow::showFolderContextActionTriggered(void)
3022 if(!m_fileSystemModel
)
3024 qWarning("File system model not initialized yet!");
3028 QString path
= QDir::toNativeSeparators(m_fileSystemModel
->filePath(ui
->outputFolderView
->currentIndex()));
3029 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
3030 MUtils::OS::shell_open(this, path
, true);
3034 * Refresh the directory outline
3036 void MainWindow::refreshFolderContextActionTriggered(void)
3038 //force re-initialization
3039 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
3043 * Go one directory up
3045 void MainWindow::goUpFolderContextActionTriggered(void)
3047 QModelIndex current
= ui
->outputFolderView
->currentIndex();
3048 if(current
.isValid())
3050 QModelIndex parent
= current
.parent();
3051 if(parent
.isValid())
3054 ui
->outputFolderView
->setCurrentIndex(parent
);
3055 outputFolderViewClicked(parent
);
3059 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
3061 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3066 * Add current folder to favorites
3068 void MainWindow::addFavoriteFolderActionTriggered(void)
3070 QString path
= m_fileSystemModel
->filePath(ui
->outputFolderView
->currentIndex());
3071 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
3073 if(!favorites
.contains(path
, Qt::CaseInsensitive
))
3075 favorites
.append(path
);
3076 while(favorites
.count() > 6) favorites
.removeFirst();
3080 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
3083 m_settings
->favoriteOutputFolders(favorites
.join("|"));
3088 * Output folder edit finished
3090 void MainWindow::outputFolderEditFinished(void)
3092 if(ui
->outputFolderEdit
->isHidden())
3094 return; //Not currently in edit mode!
3099 QString text
= QDir::fromNativeSeparators(ui
->outputFolderEdit
->text().trimmed());
3100 while(text
.startsWith('"') || text
.startsWith('/')) text
= text
.right(text
.length() - 1).trimmed();
3101 while(text
.endsWith('"') || text
.endsWith('/')) text
= text
.left(text
.length() - 1).trimmed();
3103 static const char *str
= "?*<>|\"";
3104 for(size_t i
= 0; str
[i
]; i
++) text
.replace(str
[i
], "_");
3106 if(!((text
.length() >= 2) && text
.at(0).isLetter() && text
.at(1) == QChar(':')))
3108 text
= QString("%1/%2").arg(QDir::fromNativeSeparators(ui
->outputFolderLabel
->text()), text
);
3111 if(text
.length() == 2) text
+= "/"; /* "X:" => "X:/" */
3113 while(text
.length() > 2)
3115 QFileInfo
info(text
);
3116 if(info
.exists() && info
.isDir())
3118 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalFilePath()).absoluteFilePath());
3122 ui
->outputFolderView
->setCurrentIndex(index
);
3123 outputFolderViewClicked(index
);
3127 else if(info
.exists() && info
.isFile())
3129 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalPath()).absoluteFilePath());
3133 ui
->outputFolderView
->setCurrentIndex(index
);
3134 outputFolderViewClicked(index
);
3139 text
= text
.left(text
.length() - 1).trimmed();
3142 ui
->outputFolderEdit
->setVisible(false);
3143 ui
->outputFolderLabel
->setVisible(true);
3144 ui
->outputFolderView
->setEnabled(true);
3146 if(!ok
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
3147 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3151 * Initialize file system model
3153 void MainWindow::initOutputFolderModel(void)
3155 if(m_outputFolderNoteBox
->isHidden())
3157 m_outputFolderNoteBox
->show();
3158 m_outputFolderNoteBox
->repaint();
3159 m_outputFolderViewInitCounter
= 4;
3161 if(m_fileSystemModel
)
3163 SET_MODEL(ui
->outputFolderView
, NULL
);
3164 MUTILS_DELETE(m_fileSystemModel
);
3165 ui
->outputFolderView
->repaint();
3168 if(m_fileSystemModel
= new QFileSystemModelEx())
3170 m_fileSystemModel
->installEventFilter(this);
3171 connect(m_fileSystemModel
, SIGNAL(directoryLoaded(QString
)), this, SLOT(outputFolderDirectoryLoaded(QString
)));
3172 connect(m_fileSystemModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(outputFolderRowsInserted(QModelIndex
,int,int)));
3174 SET_MODEL(ui
->outputFolderView
, m_fileSystemModel
);
3175 ui
->outputFolderView
->header()->setStretchLastSection(true);
3176 ui
->outputFolderView
->header()->hideSection(1);
3177 ui
->outputFolderView
->header()->hideSection(2);
3178 ui
->outputFolderView
->header()->hideSection(3);
3180 m_fileSystemModel
->setRootPath("");
3181 QModelIndex index
= m_fileSystemModel
->index(m_settings
->outputDir());
3182 if(index
.isValid()) ui
->outputFolderView
->setCurrentIndex(index
);
3183 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3186 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3187 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3192 * Initialize file system model (do NOT call this one directly!)
3194 void MainWindow::initOutputFolderModel_doAsync(void)
3196 if(m_outputFolderViewInitCounter
> 0)
3198 m_outputFolderViewInitCounter
--;
3199 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3203 QTimer::singleShot(125, m_outputFolderNoteBox
, SLOT(hide()));
3204 ui
->outputFolderView
->setFocus();
3209 * Center current folder in view
3211 void MainWindow::centerOutputFolderModel(void)
3213 if(ui
->outputFolderView
->isVisible())
3215 centerOutputFolderModel_doAsync();
3216 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel_doAsync()));
3221 * Center current folder in view (do NOT call this one directly!)
3223 void MainWindow::centerOutputFolderModel_doAsync(void)
3225 if(ui
->outputFolderView
->isVisible())
3227 m_outputFolderViewCentering
= true;
3228 const QModelIndex index
= ui
->outputFolderView
->currentIndex();
3229 ui
->outputFolderView
->scrollTo(index
, QAbstractItemView::PositionAtCenter
);
3230 ui
->outputFolderView
->setFocus();
3235 * File system model asynchronously loaded a dir
3237 void MainWindow::outputFolderDirectoryLoaded(const QString
&path
)
3239 if(m_outputFolderViewCentering
)
3241 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3246 * File system model inserted new items
3248 void MainWindow::outputFolderRowsInserted(const QModelIndex
&parent
, int start
, int end
)
3250 if(m_outputFolderViewCentering
)
3252 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3257 * Directory view item was expanded by user
3259 void MainWindow::outputFolderItemExpanded(const QModelIndex
&item
)
3261 //We need to stop centering as soon as the user has expanded an item manually!
3262 m_outputFolderViewCentering
= false;
3266 * View event for output folder control occurred
3268 void MainWindow::outputFolderViewEventOccurred(QWidget
*sender
, QEvent
*event
)
3270 switch(event
->type())
3274 case QEvent::KeyPress
:
3275 case QEvent::KeyRelease
:
3276 case QEvent::FocusIn
:
3277 case QEvent::FocusOut
:
3278 case QEvent::TouchEnd
:
3279 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3285 * Mouse event for output folder control occurred
3287 void MainWindow::outputFolderMouseEventOccurred(QWidget
*sender
, QEvent
*event
)
3289 QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
);
3290 QPoint pos
= (mouseEvent
) ? mouseEvent
->pos() : QPoint();
3292 if(sender
== ui
->outputFolderLabel
)
3294 switch(event
->type())
3296 case QEvent::MouseButtonPress
:
3297 if(mouseEvent
&& (mouseEvent
->button() == Qt::LeftButton
))
3299 QString path
= ui
->outputFolderLabel
->text();
3300 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
3301 MUtils::OS::shell_open(this, path
, true);
3305 ui
->outputFolderLabel
->setForegroundRole(QPalette::Link
);
3308 ui
->outputFolderLabel
->setForegroundRole(QPalette::WindowText
);
3313 if((sender
== ui
->outputFoldersFovoritesLabel
) || (sender
== ui
->outputFoldersEditorLabel
) || (sender
== ui
->outputFoldersGoUpLabel
))
3315 const type_info
&styleType
= typeid(*qApp
->style());
3316 if((typeid(QPlastiqueStyle
) == styleType
) || (typeid(QWindowsStyle
) == styleType
))
3318 switch(event
->type())
3321 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Raised
: QFrame::Plain
);
3323 case QEvent::MouseButtonPress
:
3324 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Sunken
: QFrame::Plain
);
3326 case QEvent::MouseButtonRelease
:
3327 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Raised
: QFrame::Plain
);
3330 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Plain
: QFrame::Plain
);
3336 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(QFrame::Plain
);
3339 if((event
->type() == QEvent::MouseButtonRelease
) && ui
->outputFolderView
->isEnabled() && (mouseEvent
))
3341 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
)
3343 if(sender
== ui
->outputFoldersFovoritesLabel
)
3345 m_outputFolderFavoritesMenu
->popup(sender
->mapToGlobal(pos
));
3347 else if(sender
== ui
->outputFoldersEditorLabel
)
3349 ui
->outputFolderView
->setEnabled(false);
3350 ui
->outputFolderLabel
->setVisible(false);
3351 ui
->outputFolderEdit
->setVisible(true);
3352 ui
->outputFolderEdit
->setText(ui
->outputFolderLabel
->text());
3353 ui
->outputFolderEdit
->selectAll();
3354 ui
->outputFolderEdit
->setFocus();
3356 else if(sender
== ui
->outputFoldersGoUpLabel
)
3358 QTimer::singleShot(0, this, SLOT(goUpFolderContextActionTriggered()));
3362 MUTILS_THROW("Oups, this is not supposed to happen!");
3369 // =========================================================
3370 // Metadata tab slots
3371 // =========================================================
3374 * Edit meta button clicked
3376 void MainWindow::editMetaButtonClicked(void)
3380 const QModelIndex index
= ui
->metaDataView
->currentIndex();
3384 m_metaInfoModel
->editItem(index
, this);
3386 if(index
.row() == 4)
3388 m_settings
->metaInfoPosition(m_metaData
->position());
3394 * Reset meta button clicked
3396 void MainWindow::clearMetaButtonClicked(void)
3399 m_metaInfoModel
->clearData();
3403 * Meta tags enabled changed
3405 void MainWindow::metaTagsEnabledChanged(void)
3407 m_settings
->writeMetaTags(ui
->writeMetaDataCheckBox
->isChecked());
3411 * Playlist enabled changed
3413 void MainWindow::playlistEnabledChanged(void)
3415 m_settings
->createPlaylist(ui
->generatePlaylistCheckBox
->isChecked());
3418 // =========================================================
3419 // Compression tab slots
3420 // =========================================================
3425 void MainWindow::updateEncoder(int id
)
3427 /*qWarning("\nupdateEncoder(%d)", id);*/
3429 m_settings
->compressionEncoder(id
);
3430 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(id
);
3432 //Update UI controls
3433 ui
->radioButtonModeQuality
->setEnabled(info
->isModeSupported(SettingsModel::VBRMode
));
3434 ui
->radioButtonModeAverageBitrate
->setEnabled(info
->isModeSupported(SettingsModel::ABRMode
));
3435 ui
->radioButtonConstBitrate
->setEnabled(info
->isModeSupported(SettingsModel::CBRMode
));
3437 //Initialize checkbox state
3438 if(ui
->radioButtonModeQuality
->isEnabled()) ui
->radioButtonModeQuality
->setChecked(true);
3439 else if(ui
->radioButtonModeAverageBitrate
->isEnabled()) ui
->radioButtonModeAverageBitrate
->setChecked(true);
3440 else if(ui
->radioButtonConstBitrate
->isEnabled()) ui
->radioButtonConstBitrate
->setChecked(true);
3441 else MUTILS_THROW("It appears that the encoder does not support *any* RC mode!");
3443 //Apply current RC mode
3444 const int currentRCMode
= EncoderRegistry::loadEncoderMode(m_settings
, id
);
3445 switch(currentRCMode
)
3447 case SettingsModel::VBRMode
: if(ui
->radioButtonModeQuality
->isEnabled()) ui
->radioButtonModeQuality
->setChecked(true); break;
3448 case SettingsModel::ABRMode
: if(ui
->radioButtonModeAverageBitrate
->isEnabled()) ui
->radioButtonModeAverageBitrate
->setChecked(true); break;
3449 case SettingsModel::CBRMode
: if(ui
->radioButtonConstBitrate
->isEnabled()) ui
->radioButtonConstBitrate
->setChecked(true); break;
3450 default: MUTILS_THROW("updateEncoder(): Unknown rc-mode encountered!");
3453 //Display encoder description
3454 if(const char* description
= info
->description())
3456 ui
->labelEncoderInfo
->setVisible(true);
3457 ui
->labelEncoderInfo
->setText(tr("Current Encoder: %1").arg(QString::fromUtf8(description
)));
3461 ui
->labelEncoderInfo
->setVisible(false);
3465 updateRCMode(m_modeButtonGroup
->checkedId());
3469 * Update rate-control mode
3471 void MainWindow::updateRCMode(int id
)
3473 /*qWarning("updateRCMode(%d)", id);*/
3476 const int currentEncoder
= m_encoderButtonGroup
->checkedId();
3477 EncoderRegistry::saveEncoderMode(m_settings
, currentEncoder
, id
);
3479 //Fetch encoder info
3480 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(currentEncoder
);
3481 const int valueCount
= info
->valueCount(id
);
3484 if(!info
->isModeSupported(id
))
3486 qWarning("Attempting to use an unsupported RC mode (%d) with current encoder (%d)!", id
, currentEncoder
);
3487 ui
->labelBitrate
->setText("(ERROR)");
3491 //Update slider min/max values
3494 WITH_BLOCKED_SIGNALS(ui
->sliderBitrate
, setEnabled
, true);
3495 WITH_BLOCKED_SIGNALS(ui
->sliderBitrate
, setMinimum
, 0);
3496 WITH_BLOCKED_SIGNALS(ui
->sliderBitrate
, setMaximum
, valueCount
-1);
3500 WITH_BLOCKED_SIGNALS(ui
->sliderBitrate
, setEnabled
, false);
3501 WITH_BLOCKED_SIGNALS(ui
->sliderBitrate
, setMinimum
, 0);
3502 WITH_BLOCKED_SIGNALS(ui
->sliderBitrate
, setMaximum
, 2);
3505 //Now update bitrate/quality value!
3508 const int currentValue
= EncoderRegistry::loadEncoderValue(m_settings
, currentEncoder
, id
);
3509 ui
->sliderBitrate
->setValue(qBound(0, currentValue
, valueCount
-1));
3510 updateBitrate(qBound(0, currentValue
, valueCount
-1));
3514 ui
->sliderBitrate
->setValue(1);
3522 void MainWindow::updateBitrate(int value
)
3524 /*qWarning("updateBitrate(%d)", value);*/
3526 //Load current encoder and RC mode
3527 const int currentEncoder
= m_encoderButtonGroup
->checkedId();
3528 const int currentRCMode
= m_modeButtonGroup
->checkedId();
3530 //Fetch encoder info
3531 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(currentEncoder
);
3532 const int valueCount
= info
->valueCount(currentRCMode
);
3535 if(!info
->isModeSupported(currentRCMode
))
3537 qWarning("Attempting to use an unsupported RC mode (%d) with current encoder (%d)!", currentRCMode
, currentEncoder
);
3538 ui
->labelBitrate
->setText("(ERROR)");
3542 //Store new bitrate value
3545 EncoderRegistry::saveEncoderValue(m_settings
, currentEncoder
, currentRCMode
, qBound(0, value
, valueCount
-1));
3548 //Update bitrate value
3549 const int displayValue
= (valueCount
> 0) ? info
->valueAt(currentRCMode
, qBound(0, value
, valueCount
-1)) : INT_MAX
;
3550 switch(info
->valueType(currentRCMode
))
3552 case AbstractEncoderInfo::TYPE_BITRATE
:
3553 ui
->labelBitrate
->setText(QString("%1 kbps").arg(QString::number(displayValue
)));
3555 case AbstractEncoderInfo::TYPE_APPROX_BITRATE
:
3556 ui
->labelBitrate
->setText(QString("≈ %1 kbps").arg(QString::number(displayValue
)));
3558 case AbstractEncoderInfo::TYPE_QUALITY_LEVEL_INT
:
3559 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(QString::number(displayValue
)));
3561 case AbstractEncoderInfo::TYPE_QUALITY_LEVEL_FLT
:
3562 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", double(displayValue
)/100.0)));
3564 case AbstractEncoderInfo::TYPE_COMPRESSION_LEVEL
:
3565 ui
->labelBitrate
->setText(tr("Compression %1").arg(QString::number(displayValue
)));
3567 case AbstractEncoderInfo::TYPE_UNCOMPRESSED
:
3568 ui
->labelBitrate
->setText(tr("Uncompressed"));
3571 MUTILS_THROW("Unknown display value type encountered!");
3577 * Event for compression tab occurred
3579 void MainWindow::compressionTabEventOccurred(QWidget
*sender
, QEvent
*event
)
3581 static const QUrl
helpUrl("http://lamexp.sourceforge.net/doc/FAQ.html#054010d9");
3583 if((sender
== ui
->labelCompressionHelp
) && (event
->type() == QEvent::MouseButtonPress
))
3585 QDesktopServices::openUrl(helpUrl
);
3587 else if((sender
== ui
->labelResetEncoders
) && (event
->type() == QEvent::MouseButtonPress
))
3589 PLAY_SOUND_OPTIONAL("blast", true);
3590 EncoderRegistry::resetAllEncoders(m_settings
);
3591 m_settings
->compressionEncoder(SettingsModel::MP3Encoder
);
3592 ui
->radioButtonEncoderMP3
->setChecked(true);
3593 QTimer::singleShot(0, this, SLOT(updateEncoder()));
3597 // =========================================================
3598 // Advanced option slots
3599 // =========================================================
3602 * Lame algorithm quality changed
3604 void MainWindow::updateLameAlgoQuality(int value
)
3611 text
= tr("Best Quality (Slow)");
3614 text
= tr("High Quality (Recommended)");
3617 text
= tr("Acceptable Quality (Fast)");
3620 text
= tr("Poor Quality (Very Fast)");
3626 m_settings
->lameAlgoQuality(value
);
3627 ui
->labelLameAlgoQuality
->setText(text
);
3630 bool warning
= (value
== 0), notice
= (value
== 3);
3631 ui
->labelLameAlgoQualityWarning
->setVisible(warning
);
3632 ui
->labelLameAlgoQualityWarningIcon
->setVisible(warning
);
3633 ui
->labelLameAlgoQualityNotice
->setVisible(notice
);
3634 ui
->labelLameAlgoQualityNoticeIcon
->setVisible(notice
);
3635 ui
->labelLameAlgoQualitySpacer
->setVisible(warning
|| notice
);
3639 * Bitrate management endabled/disabled
3641 void MainWindow::bitrateManagementEnabledChanged(bool checked
)
3643 m_settings
->bitrateManagementEnabled(checked
);
3647 * Minimum bitrate has changed
3649 void MainWindow::bitrateManagementMinChanged(int value
)
3651 if(value
> ui
->spinBoxBitrateManagementMax
->value())
3653 ui
->spinBoxBitrateManagementMin
->setValue(ui
->spinBoxBitrateManagementMax
->value());
3654 m_settings
->bitrateManagementMinRate(ui
->spinBoxBitrateManagementMax
->value());
3658 m_settings
->bitrateManagementMinRate(value
);
3663 * Maximum bitrate has changed
3665 void MainWindow::bitrateManagementMaxChanged(int value
)
3667 if(value
< ui
->spinBoxBitrateManagementMin
->value())
3669 ui
->spinBoxBitrateManagementMax
->setValue(ui
->spinBoxBitrateManagementMin
->value());
3670 m_settings
->bitrateManagementMaxRate(ui
->spinBoxBitrateManagementMin
->value());
3674 m_settings
->bitrateManagementMaxRate(value
);
3679 * Channel mode has changed
3681 void MainWindow::channelModeChanged(int value
)
3683 if(value
>= 0) m_settings
->lameChannelMode(value
);
3687 * Sampling rate has changed
3689 void MainWindow::samplingRateChanged(int value
)
3691 if(value
>= 0) m_settings
->samplingRate(value
);
3695 * Nero AAC 2-Pass mode changed
3697 void MainWindow::neroAAC2PassChanged(bool checked
)
3699 m_settings
->neroAACEnable2Pass(checked
);
3703 * Nero AAC profile mode changed
3705 void MainWindow::neroAACProfileChanged(int value
)
3707 if(value
>= 0) m_settings
->aacEncProfile(value
);
3711 * Aften audio coding mode changed
3713 void MainWindow::aftenCodingModeChanged(int value
)
3715 if(value
>= 0) m_settings
->aftenAudioCodingMode(value
);
3719 * Aften DRC mode changed
3721 void MainWindow::aftenDRCModeChanged(int value
)
3723 if(value
>= 0) m_settings
->aftenDynamicRangeCompression(value
);
3727 * Aften exponent search size changed
3729 void MainWindow::aftenSearchSizeChanged(int value
)
3731 if(value
>= 0) m_settings
->aftenExponentSearchSize(value
);
3735 * Aften fast bit allocation changed
3737 void MainWindow::aftenFastAllocationChanged(bool checked
)
3739 m_settings
->aftenFastBitAllocation(checked
);
3744 * Opus encoder settings changed
3746 void MainWindow::opusSettingsChanged(void)
3748 m_settings
->opusFramesize(ui
->comboBoxOpusFramesize
->currentIndex());
3749 m_settings
->opusComplexity(ui
->spinBoxOpusComplexity
->value());
3750 m_settings
->opusDisableResample(ui
->checkBoxOpusDisableResample
->isChecked());
3754 * Normalization filter enabled changed
3756 void MainWindow::normalizationEnabledChanged(bool checked
)
3758 m_settings
->normalizationFilterEnabled(checked
);
3759 normalizationDynamicChanged(ui
->checkBoxNormalizationFilterDynamic
->isChecked());
3763 * Dynamic normalization enabled changed
3765 void MainWindow::normalizationDynamicChanged(bool checked
)
3767 ui
->spinBoxNormalizationFilterSize
->setEnabled(ui
->checkBoxNormalizationFilterEnabled
->isChecked() && checked
);
3768 m_settings
->normalizationFilterDynamic(checked
);
3772 * Normalization max. volume changed
3774 void MainWindow::normalizationMaxVolumeChanged(double value
)
3776 m_settings
->normalizationFilterMaxVolume(static_cast<int>(value
* 100.0));
3780 * Normalization equalization mode changed
3782 void MainWindow::normalizationCoupledChanged(bool checked
)
3784 m_settings
->normalizationFilterCoupled(checked
);
3788 * Normalization filter size changed
3790 void MainWindow::normalizationFilterSizeChanged(int value
)
3792 m_settings
->normalizationFilterSize(value
);
3796 * Normalization filter size editing finished
3798 void MainWindow::normalizationFilterSizeFinished(void)
3800 const int value
= ui
->spinBoxNormalizationFilterSize
->value();
3801 if((value
% 2) != 1)
3803 bool rnd
= MUtils::parity(MUtils::next_rand32());
3804 ui
->spinBoxNormalizationFilterSize
->setValue(rnd
? value
+1 : value
-1);
3809 * Tone adjustment has changed (Bass)
3811 void MainWindow::toneAdjustBassChanged(double value
)
3813 m_settings
->toneAdjustBass(static_cast<int>(value
* 100.0));
3814 ui
->spinBoxToneAdjustBass
->setPrefix((value
> 0) ? "+" : QString());
3818 * Tone adjustment has changed (Treble)
3820 void MainWindow::toneAdjustTrebleChanged(double value
)
3822 m_settings
->toneAdjustTreble(static_cast<int>(value
* 100.0));
3823 ui
->spinBoxToneAdjustTreble
->setPrefix((value
> 0) ? "+" : QString());
3827 * Tone adjustment has been reset
3829 void MainWindow::toneAdjustTrebleReset(void)
3831 ui
->spinBoxToneAdjustBass
->setValue(m_settings
->toneAdjustBassDefault());
3832 ui
->spinBoxToneAdjustTreble
->setValue(m_settings
->toneAdjustTrebleDefault());
3833 toneAdjustBassChanged(ui
->spinBoxToneAdjustBass
->value());
3834 toneAdjustTrebleChanged(ui
->spinBoxToneAdjustTreble
->value());
3838 * Custom encoder parameters changed
3840 void MainWindow::customParamsChanged(void)
3842 ui
->lineEditCustomParamLAME
->setText(ui
->lineEditCustomParamLAME
->text().simplified());
3843 ui
->lineEditCustomParamOggEnc
->setText(ui
->lineEditCustomParamOggEnc
->text().simplified());
3844 ui
->lineEditCustomParamNeroAAC
->setText(ui
->lineEditCustomParamNeroAAC
->text().simplified());
3845 ui
->lineEditCustomParamFLAC
->setText(ui
->lineEditCustomParamFLAC
->text().simplified());
3846 ui
->lineEditCustomParamAften
->setText(ui
->lineEditCustomParamAften
->text().simplified());
3847 ui
->lineEditCustomParamOpus
->setText(ui
->lineEditCustomParamOpus
->text().simplified());
3849 bool customParamsUsed
= false;
3850 if(!ui
->lineEditCustomParamLAME
->text().isEmpty()) customParamsUsed
= true;
3851 if(!ui
->lineEditCustomParamOggEnc
->text().isEmpty()) customParamsUsed
= true;
3852 if(!ui
->lineEditCustomParamNeroAAC
->text().isEmpty()) customParamsUsed
= true;
3853 if(!ui
->lineEditCustomParamFLAC
->text().isEmpty()) customParamsUsed
= true;
3854 if(!ui
->lineEditCustomParamAften
->text().isEmpty()) customParamsUsed
= true;
3855 if(!ui
->lineEditCustomParamOpus
->text().isEmpty()) customParamsUsed
= true;
3857 ui
->labelCustomParamsIcon
->setVisible(customParamsUsed
);
3858 ui
->labelCustomParamsText
->setVisible(customParamsUsed
);
3859 ui
->labelCustomParamsSpacer
->setVisible(customParamsUsed
);
3861 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::MP3Encoder
, ui
->lineEditCustomParamLAME
->text());
3862 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::VorbisEncoder
, ui
->lineEditCustomParamOggEnc
->text());
3863 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::AACEncoder
, ui
->lineEditCustomParamNeroAAC
->text());
3864 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::FLACEncoder
, ui
->lineEditCustomParamFLAC
->text());
3865 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::AC3Encoder
, ui
->lineEditCustomParamAften
->text());
3866 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::OpusEncoder
, ui
->lineEditCustomParamOpus
->text());
3870 * One of the rename buttons has been clicked
3872 void MainWindow::renameButtonClicked(bool checked
)
3874 if(QPushButton
*const button
= dynamic_cast<QPushButton
*>(QObject::sender()))
3876 QWidget
*pages
[] = { ui
->pageRename_Rename
, ui
->pageRename_RegExp
, ui
->pageRename_FileEx
};
3877 QPushButton
*buttons
[] = { ui
->buttonRename_Rename
, ui
->buttonRename_RegExp
, ui
->buttonRename_FileEx
};
3878 for(int i
= 0; i
< 3; i
++)
3880 const bool match
= (button
== buttons
[i
]);
3881 buttons
[i
]->setChecked(match
);
3882 if(match
&& checked
) ui
->stackedWidget
->setCurrentWidget(pages
[i
]);
3888 * Rename output files enabled changed
3890 void MainWindow::renameOutputEnabledChanged(bool checked
)
3892 m_settings
->renameOutputFilesEnabled(checked
);
3896 * Rename output files patterm changed
3898 void MainWindow::renameOutputPatternChanged(void)
3900 QString temp
= ui
->lineEditRenamePattern
->text().simplified();
3901 ui
->lineEditRenamePattern
->setText(temp
.isEmpty() ? m_settings
->renameOutputFilesPatternDefault() : temp
);
3902 m_settings
->renameOutputFilesPattern(ui
->lineEditRenamePattern
->text());
3906 * Rename output files patterm changed
3908 void MainWindow::renameOutputPatternChanged(const QString
&text
, bool silent
)
3910 QString
pattern(text
.simplified());
3912 pattern
.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive
);
3913 pattern
.replace("<TrackNo>", "04", Qt::CaseInsensitive
);
3914 pattern
.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive
);
3915 pattern
.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive
);
3916 pattern
.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive
);
3917 pattern
.replace("<Year>", "2001", Qt::CaseInsensitive
);
3918 pattern
.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive
);
3920 const QString patternClean
= MUtils::clean_file_name(pattern
);
3922 if(pattern
.compare(patternClean
))
3924 if(ui
->lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::red
)
3926 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
3927 SET_TEXT_COLOR(ui
->lineEditRenamePattern
, Qt::red
);
3932 if(ui
->lineEditRenamePattern
->palette() != QPalette())
3934 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
3935 ui
->lineEditRenamePattern
->setPalette(QPalette());
3939 ui
->labelRanameExample
->setText(patternClean
);
3943 * Show list of rename macros
3945 void MainWindow::showRenameMacros(const QString
&text
)
3947 if(text
.compare("reset", Qt::CaseInsensitive
) == 0)
3949 ui
->lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPatternDefault());
3953 if(text
.compare("regexp", Qt::CaseInsensitive
) == 0)
3955 MUtils::OS::shell_open(this, "http://www.regular-expressions.info/quickstart.html");
3959 const QString format
= QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
3961 QString message
= QString("<table>");
3962 message
+= QString(format
).arg("BaseName", tr("File name without extension"));
3963 message
+= QString(format
).arg("TrackNo", tr("Track number with leading zero"));
3964 message
+= QString(format
).arg("Title", tr("Track title"));
3965 message
+= QString(format
).arg("Artist", tr("Artist name"));
3966 message
+= QString(format
).arg("Album", tr("Album name"));
3967 message
+= QString(format
).arg("Year", tr("Year with (at least) four digits"));
3968 message
+= QString(format
).arg("Comment", tr("Comment"));
3969 message
+= "</table><br><br>";
3970 message
+= QString("%1<br>").arg(tr("Characters forbidden in file names:"));
3971 message
+= "<b><tt>\\ / : * ? < > |<br>";
3973 QMessageBox::information(this, tr("Rename Macros"), message
, tr("Discard"));
3976 void MainWindow::forceStereoDownmixEnabledChanged(bool checked
)
3978 m_settings
->forceStereoDownmix(checked
);
3982 * Maximum number of instances changed
3984 void MainWindow::updateMaximumInstances(int value
)
3986 ui
->labelMaxInstances
->setText(tr("%n Instance(s)", "", value
));
3987 m_settings
->maximumInstances(ui
->checkBoxAutoDetectInstances
->isChecked() ? NULL
: value
);
3991 * Auto-detect number of instances
3993 void MainWindow::autoDetectInstancesChanged(bool checked
)
3995 m_settings
->maximumInstances(checked
? NULL
: ui
->sliderMaxInstances
->value());
3999 * Browse for custom TEMP folder button clicked
4001 void MainWindow::browseCustomTempFolderButtonClicked(void)
4003 QString newTempFolder
;
4005 if(MUtils::GUI::themes_enabled())
4007 newTempFolder
= QFileDialog::getExistingDirectory(this, QString(), m_settings
->customTempPath());
4011 QFileDialog
dialog(this);
4012 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
4013 dialog
.setDirectory(m_settings
->customTempPath());
4016 newTempFolder
= dialog
.selectedFiles().first();
4020 if(!newTempFolder
.isEmpty())
4022 QFile
writeTest(QString("%1/~%2.tmp").arg(newTempFolder
, MUtils::rand_str()));
4023 if(writeTest
.open(QIODevice::ReadWrite
))
4026 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(newTempFolder
));
4030 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
4036 * Custom TEMP folder changed
4038 void MainWindow::customTempFolderChanged(const QString
&text
)
4040 m_settings
->customTempPath(QDir::fromNativeSeparators(text
));
4044 * Use custom TEMP folder option changed
4046 void MainWindow::useCustomTempFolderChanged(bool checked
)
4048 m_settings
->customTempPathEnabled(!checked
);
4052 * Help for custom parameters was requested
4054 void MainWindow::customParamsHelpRequested(QWidget
*obj
, QEvent
*event
)
4056 if(event
->type() != QEvent::MouseButtonRelease
)
4061 if(QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
))
4063 QPoint pos
= mouseEvent
->pos();
4064 if(!(pos
.x() <= obj
->width() && pos
.y() <= obj
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
))
4070 if(obj
== ui
->helpCustomParamLAME
) showCustomParamsHelpScreen("lame.exe", "--longhelp");
4071 else if(obj
== ui
->helpCustomParamOggEnc
) showCustomParamsHelpScreen("oggenc2.exe", "--help");
4072 else if(obj
== ui
->helpCustomParamNeroAAC
)
4074 switch(EncoderRegistry::getAacEncoder())
4076 case SettingsModel::AAC_ENCODER_QAAC
: showCustomParamsHelpScreen("qaac.exe", "--help"); break;
4077 case SettingsModel::AAC_ENCODER_FHG
: showCustomParamsHelpScreen("fhgaacenc.exe", "" ); break;
4078 case SettingsModel::AAC_ENCODER_FDK
: showCustomParamsHelpScreen("fdkaac.exe", "--help"); break;
4079 case SettingsModel::AAC_ENCODER_NERO
: showCustomParamsHelpScreen("neroAacEnc.exe", "-help" ); break;
4080 default: MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
); break;
4083 else if(obj
== ui
->helpCustomParamFLAC
) showCustomParamsHelpScreen("flac.exe", "--help");
4084 else if(obj
== ui
->helpCustomParamAften
) showCustomParamsHelpScreen("aften.exe", "-h" );
4085 else if(obj
== ui
->helpCustomParamOpus
) showCustomParamsHelpScreen("opusenc.exe", "--help");
4086 else MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4090 * Show help for custom parameters
4092 void MainWindow::showCustomParamsHelpScreen(const QString
&toolName
, const QString
&command
)
4094 const QString binary
= lamexp_tools_lookup(toolName
);
4095 if(binary
.isEmpty())
4097 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4098 qWarning("customParamsHelpRequested: Binary could not be found!");
4103 MUtils::init_process(process
, QFileInfo(binary
).absolutePath());
4105 process
.start(binary
, command
.isEmpty() ? QStringList() : QStringList() << command
);
4107 qApp
->setOverrideCursor(QCursor(Qt::WaitCursor
));
4109 if(process
.waitForStarted(15000))
4111 qApp
->processEvents();
4112 process
.waitForFinished(15000);
4115 if(process
.state() != QProcess::NotRunning
)
4118 process
.waitForFinished(-1);
4121 qApp
->restoreOverrideCursor();
4122 QStringList output
; bool spaceFlag
= true;
4124 while(process
.canReadLine())
4126 QString temp
= QString::fromUtf8(process
.readLine());
4127 TRIM_STRING_RIGHT(temp
);
4130 if(!spaceFlag
) { output
<< temp
; spaceFlag
= true; }
4134 output
<< temp
; spaceFlag
= false;
4138 if(output
.count() < 1)
4140 qWarning("Empty output, cannot show help screen!");
4141 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4144 LogViewDialog
*dialog
= new LogViewDialog(this);
4145 TEMP_HIDE_DROPBOX( dialog
->exec(output
); );
4146 MUTILS_DELETE(dialog
);
4149 void MainWindow::overwriteModeChanged(int id
)
4151 if((id
== SettingsModel::Overwrite_Replaces
) && (m_settings
->overwriteMode() != SettingsModel::Overwrite_Replaces
))
4153 if(QMessageBox::warning(this, tr("Overwrite Mode"), tr("Warning: This mode may overwrite existing files with no way to revert!"), tr("Continue"), tr("Revert"), QString(), 1) != 0)
4155 ui
->radioButtonOverwriteModeKeepBoth
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_KeepBoth
);
4156 ui
->radioButtonOverwriteModeSkipFile
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_SkipFile
);
4161 m_settings
->overwriteMode(id
);
4165 * Reset all advanced options to their defaults
4167 void MainWindow::resetAdvancedOptionsButtonClicked(void)
4169 PLAY_SOUND_OPTIONAL("blast", true);
4171 ui
->sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQualityDefault());
4172 ui
->spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRateDefault());
4173 ui
->spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRateDefault());
4174 ui
->spinBoxNormalizationFilterPeak
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolumeDefault()) / 100.0);
4175 ui
->spinBoxNormalizationFilterSize
->setValue(m_settings
->normalizationFilterSizeDefault());
4176 ui
->spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBassDefault()) / 100.0);
4177 ui
->spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTrebleDefault()) / 100.0);
4178 ui
->spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSizeDefault());
4179 ui
->spinBoxOpusComplexity
->setValue(m_settings
->opusComplexityDefault());
4180 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelModeDefault());
4181 ui
->comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRateDefault());
4182 ui
->comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfileDefault());
4183 ui
->comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingModeDefault());
4184 ui
->comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompressionDefault());
4185 ui
->comboBoxOpusFramesize
->setCurrentIndex(m_settings
->opusFramesizeDefault());
4187 SET_CHECKBOX_STATE(ui
->checkBoxBitrateManagement
, m_settings
->bitrateManagementEnabledDefault());
4188 SET_CHECKBOX_STATE(ui
->checkBoxNeroAAC2PassMode
, m_settings
->neroAACEnable2PassDefault());
4189 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterEnabled
, m_settings
->normalizationFilterEnabledDefault());
4190 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterDynamic
, m_settings
->normalizationFilterDynamicDefault());
4191 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterCoupled
, m_settings
->normalizationFilterCoupledDefault());
4192 SET_CHECKBOX_STATE(ui
->checkBoxAutoDetectInstances
, (m_settings
->maximumInstancesDefault() < 1));
4193 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabledDefault()));
4194 SET_CHECKBOX_STATE(ui
->checkBoxAftenFastAllocation
, m_settings
->aftenFastBitAllocationDefault());
4195 SET_CHECKBOX_STATE(ui
->checkBoxRename_Rename
, m_settings
->renameOutputFilesEnabledDefault());
4196 SET_CHECKBOX_STATE(ui
->checkBoxForceStereoDownmix
, m_settings
->forceStereoDownmixDefault());
4197 SET_CHECKBOX_STATE(ui
->checkBoxOpusDisableResample
, m_settings
->opusDisableResampleDefault());
4199 ui
->lineEditCustomParamLAME
->setText(m_settings
->customParametersLAMEDefault());
4200 ui
->lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEncDefault());
4201 ui
->lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEncDefault());
4202 ui
->lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLACDefault());
4203 ui
->lineEditCustomParamOpus
->setText(m_settings
->customParametersOpusEncDefault());
4204 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPathDefault()));
4205 ui
->lineEditRenamePattern
->setText(m_settings
->renameOutputFilesPatternDefault());
4207 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_KeepBoth
) ui
->radioButtonOverwriteModeKeepBoth
->click();
4208 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_SkipFile
) ui
->radioButtonOverwriteModeSkipFile
->click();
4209 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_Replaces
) ui
->radioButtonOverwriteModeReplaces
->click();
4211 customParamsChanged();
4212 ui
->scrollArea
->verticalScrollBar()->setValue(0);
4215 // =========================================================
4216 // Multi-instance handling slots
4217 // =========================================================
4220 * Other instance detected
4222 void MainWindow::notifyOtherInstance(void)
4224 if(!(BANNER_VISIBLE
))
4226 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
);
4232 * Add file from another instance
4234 void MainWindow::addFileDelayed(const QString
&filePath
, bool tryASAP
)
4236 if(tryASAP
&& !m_delayedFileTimer
->isActive())
4238 qDebug("Received file: %s", MUTILS_UTF8(filePath
));
4239 m_delayedFileList
->append(filePath
);
4240 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4243 m_delayedFileTimer
->stop();
4244 qDebug("Received file: %s", MUTILS_UTF8(filePath
));
4245 m_delayedFileList
->append(filePath
);
4246 m_delayedFileTimer
->start(5000);
4250 * Add files from another instance
4252 void MainWindow::addFilesDelayed(const QStringList
&filePaths
, bool tryASAP
)
4254 if(tryASAP
&& (!m_delayedFileTimer
->isActive()))
4256 qDebug("Received %d file(s).", filePaths
.count());
4257 m_delayedFileList
->append(filePaths
);
4258 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4262 m_delayedFileTimer
->stop();
4263 qDebug("Received %d file(s).", filePaths
.count());
4264 m_delayedFileList
->append(filePaths
);
4265 m_delayedFileTimer
->start(5000);
4270 * Add folder from another instance
4272 void MainWindow::addFolderDelayed(const QString
&folderPath
, bool recursive
)
4274 if(!(BANNER_VISIBLE
))
4276 addFolder(folderPath
, recursive
, true);
4280 // =========================================================
4282 // =========================================================
4285 * Restore the override cursor
4287 void MainWindow::restoreCursor(void)
4289 QApplication::restoreOverrideCursor();