1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2017 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 "Model_FileExts.h"
44 #include "Registry_Encoder.h"
45 #include "Registry_Decoder.h"
46 #include "Encoder_Abstract.h"
47 #include "ShellIntegration.h"
48 #include "CustomEventFilter.h"
51 #include <MUtils/Global.h>
52 #include <MUtils/OSSupport.h>
53 #include <MUtils/GUI.h>
54 #include <MUtils/Exception.h>
55 #include <MUtils/Sound.h>
56 #include <MUtils/Translation.h>
57 #include <MUtils/Version.h>
60 #include <QMessageBox>
62 #include <QDesktopWidget>
64 #include <QFileDialog>
65 #include <QInputDialog>
66 #include <QFileSystemModel>
67 #include <QDesktopServices>
69 #include <QPlastiqueStyle>
70 #include <QCleanlooksStyle>
71 #include <QWindowsVistaStyle>
72 #include <QWindowsStyle>
74 #include <QDragEnterEvent>
78 #include <QProcessEnvironment>
79 #include <QCryptographicHash>
80 #include <QTranslator>
84 ////////////////////////////////////////////////////////////
86 ////////////////////////////////////////////////////////////
88 static const unsigned int IDM_ABOUTBOX
= 0xEFF0;
89 static const char *g_hydrogen_audio_url
= "http://wiki.hydrogenaud.io/index.php?title=Main_Page";
90 static const char *g_documents_base_url
= "http://lamexp.sourceforge.net/doc";
92 ////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////
96 #define BANNER_VISIBLE ((!m_banner.isNull()) && m_banner->isVisible())
98 #define INIT_BANNER() do \
100 if(m_banner.isNull()) \
102 m_banner.reset(new WorkingBanner(this)); \
107 #define ABORT_IF_BUSY do \
109 if(BANNER_VISIBLE || m_delayedFileTimer->isActive() || (QApplication::activeModalWidget() != NULL)) \
111 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN); \
117 #define PLAY_SOUND_OPTIONAL(NAME, ASYNC) do \
119 if(m_settings->soundsEnabled()) MUtils::Sound::play_sound((NAME), (ASYNC)); \
123 #define SHOW_CORNER_WIDGET(FLAG) do \
125 if(QWidget *cornerWidget = ui->menubar->cornerWidget()) \
127 cornerWidget->setVisible((FLAG)); \
133 (QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "−")))
135 #define LINK_EX(URL, NAME) \
136 (QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(NAME).replace("-", "−")))
138 #define FSLINK(PATH) \
139 (QString("<a href=\"file:///%1\">%2</a>").arg(PATH).arg(QString(PATH).replace("-", "−")))
141 #define CENTER_CURRENT_OUTPUT_FOLDER_DELAYED() \
142 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel()))
144 ////////////////////////////////////////////////////////////
146 ////////////////////////////////////////////////////////////
148 static inline void SET_TEXT_COLOR(QWidget
*const widget
, const QColor
&color
)
150 QPalette _palette
= widget
->palette();
151 _palette
.setColor(QPalette::WindowText
, (color
));
152 _palette
.setColor(QPalette::Text
, (color
));
153 widget
->setPalette(_palette
);
156 static inline void SET_FONT_BOLD(QWidget
*const widget
, const bool &bold
)
158 QFont _font
= widget
->font();
160 widget
->setFont(_font
);
163 static inline void SET_FONT_BOLD(QAction
*const widget
, const bool &bold
)
165 QFont _font
= widget
->font();
167 widget
->setFont(_font
);
170 static inline void SET_MODEL(QAbstractItemView
*const view
, QAbstractItemModel
*const model
)
172 QItemSelectionModel
*_tmp
= view
->selectionModel();
173 view
->setModel(model
);
177 static inline void SET_CHECKBOX_STATE(QCheckBox
*const chckbx
, const bool &state
)
179 const bool isDisabled
= (!chckbx
->isEnabled());
182 chckbx
->setEnabled(true);
184 if(chckbx
->isChecked() != state
)
188 if(chckbx
->isChecked() != state
)
190 qWarning("Warning: Failed to set checkbox %p state!", chckbx
);
194 chckbx
->setEnabled(false);
198 static inline void TRIM_STRING_RIGHT(QString
&str
)
200 while((str
.length() > 0) && str
[str
.length()-1].isSpace())
206 static inline void MAKE_TRANSPARENT(QWidget
*const widget
, const bool &flag
)
208 QPalette _p
= widget
->palette(); \
209 _p
.setColor(QPalette::Background
, Qt::transparent
);
210 widget
->setPalette(flag
? _p
: QPalette());
213 template <typename T
>
214 static QList
<T
>& INVERT_LIST(QList
<T
> &list
)
218 const int limit
= list
.size() / 2, maxIdx
= list
.size() - 1;
219 for(int k
= 0; k
< limit
; k
++) list
.swap(k
, maxIdx
- k
);
224 static quint32
encodeInstances(quint32 instances
)
228 instances
-= (instances
- 16U) / 2U;
231 instances
-= (instances
- 24U) / 2U;
237 static quint32
decodeInstances(quint32 instances
)
241 instances
+= instances
- 16U;
244 instances
+= instances
- 32U;
250 ////////////////////////////////////////////////////////////
252 ////////////////////////////////////////////////////////////
254 class WidgetHideHelper
257 WidgetHideHelper(QWidget
*const widget
) : m_widget(widget
), m_visible(widget
&& widget
->isVisible()) { if(m_widget
&& m_visible
) m_widget
->hide(); }
258 ~WidgetHideHelper(void) { if(m_widget
&& m_visible
) m_widget
->show(); }
260 QWidget
*const m_widget
;
261 const bool m_visible
;
264 class SignalBlockHelper
267 SignalBlockHelper(QObject
*const object
) : m_object(object
), m_flag(object
&& object
->blockSignals(true)) {}
268 ~SignalBlockHelper(void) { if(m_object
&& (!m_flag
)) m_object
->blockSignals(false); }
270 QObject
*const m_object
;
274 class FileListBlockHelper
277 FileListBlockHelper(FileListModel
*const fileList
) : m_fileList(fileList
) { if(m_fileList
) m_fileList
->setBlockUpdates(true); }
278 ~FileListBlockHelper(void) { if(m_fileList
) m_fileList
->setBlockUpdates(false); }
280 FileListModel
*const m_fileList
;
283 ////////////////////////////////////////////////////////////
285 ////////////////////////////////////////////////////////////
287 MainWindow::MainWindow(MUtils::IPCChannel
*const ipcChannel
, FileListModel
*const fileListModel
, AudioFileModel_MetaInfo
*const metaInfo
, SettingsModel
*const settingsModel
, QWidget
*const parent
)
290 ui(new Ui::MainWindow
),
291 m_fileListModel(fileListModel
),
292 m_metaData(metaInfo
),
293 m_settings(settingsModel
),
295 m_firstTimeShown(true),
296 m_outputFolderViewCentering(false),
297 m_outputFolderViewInitCounter(0)
299 //Init the dialog, from the .ui file
301 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint
);
302 setMinimumSize(this->size());
305 MUtils::GUI::set_window_icon(this, lamexp_app_icon(), true);
307 //Register meta types
308 qRegisterMetaType
<AudioFileModel
>("AudioFileModel");
310 //Enabled main buttons
311 connect(ui
->buttonAbout
, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
312 connect(ui
->buttonStart
, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
313 connect(ui
->buttonQuit
, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
316 ui
->tabWidget
->setCurrentIndex(0);
317 connect(ui
->tabWidget
, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
320 MUtils::GUI::sysmenu_append(this, IDM_ABOUTBOX
, "About...");
322 //Setup corner widget
323 QLabel
*cornerWidget
= new QLabel(ui
->menubar
);
324 m_evenFilterCornerWidget
.reset(new CustomEventFilter
);
325 cornerWidget
->setText("N/A");
326 cornerWidget
->setFixedHeight(ui
->menubar
->height());
327 cornerWidget
->setCursor(QCursor(Qt::PointingHandCursor
));
328 cornerWidget
->hide();
329 cornerWidget
->installEventFilter(m_evenFilterCornerWidget
.data());
330 connect(m_evenFilterCornerWidget
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(cornerWidgetEventOccurred(QWidget
*, QEvent
*)));
331 ui
->menubar
->setCornerWidget(cornerWidget
);
333 //--------------------------------
334 // Setup "Source" tab
335 //--------------------------------
337 ui
->sourceFileView
->setModel(m_fileListModel
);
338 ui
->sourceFileView
->verticalHeader() ->setResizeMode(QHeaderView::ResizeToContents
);
339 ui
->sourceFileView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
340 ui
->sourceFileView
->setContextMenuPolicy(Qt::CustomContextMenu
);
341 ui
->sourceFileView
->viewport()->installEventFilter(this);
342 m_dropNoteLabel
.reset(new QLabel(ui
->sourceFileView
));
343 m_dropNoteLabel
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
344 SET_FONT_BOLD(m_dropNoteLabel
.data(), true);
345 SET_TEXT_COLOR(m_dropNoteLabel
.data(), Qt::darkGray
);
346 m_sourceFilesContextMenu
.reset(new QMenu());
347 m_showDetailsContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
348 m_previewContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/sound.png"), "N/A");
349 m_findFileContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_go.png"), "N/A");
350 m_sourceFilesContextMenu
->addSeparator();
351 m_exportCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/table_save.png"), "N/A");
352 m_importCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_table.png"), "N/A");
353 SET_FONT_BOLD(m_showDetailsContextAction
, true);
355 connect(ui
->buttonAddFiles
, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
356 connect(ui
->buttonRemoveFile
, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
357 connect(ui
->buttonClearFiles
, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
358 connect(ui
->buttonFileUp
, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
359 connect(ui
->buttonFileDown
, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
360 connect(ui
->buttonShowDetails
, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
361 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
362 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
363 connect(m_fileListModel
, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
364 connect(ui
->sourceFileView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(sourceFilesContextMenu(QPoint
)));
365 connect(ui
->sourceFileView
->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
366 connect(ui
->sourceFileView
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
367 connect(m_showDetailsContextAction
, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
368 connect(m_previewContextAction
, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
369 connect(m_findFileContextAction
, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
370 connect(m_exportCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(exportCsvContextActionTriggered()));
371 connect(m_importCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(importCsvContextActionTriggered()));
373 //--------------------------------
374 // Setup "Output" tab
375 //--------------------------------
377 ui
->outputFolderView
->setHeaderHidden(true);
378 ui
->outputFolderView
->setAnimated(false);
379 ui
->outputFolderView
->setMouseTracking(false);
380 ui
->outputFolderView
->setContextMenuPolicy(Qt::CustomContextMenu
);
381 ui
->outputFolderView
->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn
);
383 m_evenFilterOutputFolderMouse
.reset(new CustomEventFilter
);
384 ui
->outputFoldersGoUpLabel
->installEventFilter(m_evenFilterOutputFolderMouse
.data());
385 ui
->outputFoldersEditorLabel
->installEventFilter(m_evenFilterOutputFolderMouse
.data());
386 ui
->outputFoldersFovoritesLabel
->installEventFilter(m_evenFilterOutputFolderMouse
.data());
387 ui
->outputFolderLabel
->installEventFilter(m_evenFilterOutputFolderMouse
.data());
389 m_evenFilterOutputFolderView
.reset(new CustomEventFilter
);
390 ui
->outputFolderView
->installEventFilter(m_evenFilterOutputFolderView
.data());
392 SET_CHECKBOX_STATE(ui
->saveToSourceFolderCheckBox
, m_settings
->outputToSourceDir());
393 ui
->prependRelativePathCheckBox
->setChecked(m_settings
->prependRelativeSourcePath());
395 connect(ui
->outputFolderView
, SIGNAL(clicked(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
396 connect(ui
->outputFolderView
, SIGNAL(activated(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
397 connect(ui
->outputFolderView
, SIGNAL(pressed(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
398 connect(ui
->outputFolderView
, SIGNAL(entered(QModelIndex
)), this, SLOT(outputFolderViewMoved(QModelIndex
)));
399 connect(ui
->outputFolderView
, SIGNAL(expanded(QModelIndex
)), this, SLOT(outputFolderItemExpanded(QModelIndex
)));
400 connect(ui
->buttonMakeFolder
, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
401 connect(ui
->buttonGotoHome
, SIGNAL(clicked()), this, SLOT(gotoHomeFolderButtonClicked()));
402 connect(ui
->buttonGotoDesktop
, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
403 connect(ui
->buttonGotoMusic
, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
404 connect(ui
->saveToSourceFolderCheckBox
, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
405 connect(ui
->prependRelativePathCheckBox
, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
406 connect(ui
->outputFolderEdit
, SIGNAL(editingFinished()), this, SLOT(outputFolderEditFinished()));
407 connect(m_evenFilterOutputFolderMouse
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(outputFolderMouseEventOccurred(QWidget
*, QEvent
*)));
408 connect(m_evenFilterOutputFolderView
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(outputFolderViewEventOccurred(QWidget
*, QEvent
*)));
410 m_outputFolderContextMenu
.reset(new QMenu());
411 m_showFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
412 m_goUpFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/folder_up.png"), "N/A");
413 m_outputFolderContextMenu
->addSeparator();
414 m_refreshFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/arrow_refresh.png"), "N/A");
415 m_outputFolderContextMenu
->setDefaultAction(m_showFolderContextAction
);
416 connect(ui
->outputFolderView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(outputFolderContextMenu(QPoint
)));
417 connect(m_showFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
418 connect(m_refreshFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(refreshFolderContextActionTriggered()));
419 connect(m_goUpFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(goUpFolderContextActionTriggered()));
421 m_outputFolderFavoritesMenu
.reset(new QMenu());
422 m_addFavoriteFolderAction
= m_outputFolderFavoritesMenu
->addAction(QIcon(":/icons/add.png"), "N/A");
423 m_outputFolderFavoritesMenu
->insertSeparator(m_addFavoriteFolderAction
);
424 connect(m_addFavoriteFolderAction
, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
426 ui
->outputFolderEdit
->setVisible(false);
427 m_outputFolderNoteBox
.reset(new QLabel(ui
->outputFolderView
));
428 m_outputFolderNoteBox
->setAutoFillBackground(true);
429 m_outputFolderNoteBox
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
430 m_outputFolderNoteBox
->setFrameShape(QFrame::StyledPanel
);
431 SET_FONT_BOLD(m_outputFolderNoteBox
.data(), true);
432 m_outputFolderNoteBox
->hide();
434 outputFolderViewClicked(QModelIndex());
437 //--------------------------------
438 // Setup "Meta Data" tab
439 //--------------------------------
441 m_metaInfoModel
.reset(new MetaInfoModel(m_metaData
));
442 m_metaInfoModel
->clearData();
443 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
444 ui
->metaDataView
->setModel(m_metaInfoModel
.data());
445 ui
->metaDataView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
446 ui
->metaDataView
->verticalHeader()->hide();
447 ui
->metaDataView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
448 SET_CHECKBOX_STATE(ui
->writeMetaDataCheckBox
, m_settings
->writeMetaTags());
449 ui
->generatePlaylistCheckBox
->setChecked(m_settings
->createPlaylist());
450 connect(ui
->buttonEditMeta
, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
451 connect(ui
->buttonClearMeta
, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
452 connect(ui
->writeMetaDataCheckBox
, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
453 connect(ui
->generatePlaylistCheckBox
, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
455 //--------------------------------
456 //Setup "Compression" tab
457 //--------------------------------
459 m_encoderButtonGroup
.reset(new QButtonGroup(this));
460 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderMP3
, SettingsModel::MP3Encoder
);
461 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderVorbis
, SettingsModel::VorbisEncoder
);
462 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAAC
, SettingsModel::AACEncoder
);
463 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAC3
, SettingsModel::AC3Encoder
);
464 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderFLAC
, SettingsModel::FLACEncoder
);
465 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAPE
, SettingsModel::MACEncoder
);
466 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderOpus
, SettingsModel::OpusEncoder
);
467 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderDCA
, SettingsModel::DCAEncoder
);
468 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderPCM
, SettingsModel::PCMEncoder
);
470 const int aacEncoder
= EncoderRegistry::getAacEncoder();
471 ui
->radioButtonEncoderAAC
->setEnabled(aacEncoder
> SettingsModel::AAC_ENCODER_NONE
);
473 m_modeButtonGroup
.reset(new QButtonGroup(this));
474 m_modeButtonGroup
->addButton(ui
->radioButtonModeQuality
, SettingsModel::VBRMode
);
475 m_modeButtonGroup
->addButton(ui
->radioButtonModeAverageBitrate
, SettingsModel::ABRMode
);
476 m_modeButtonGroup
->addButton(ui
->radioButtonConstBitrate
, SettingsModel::CBRMode
);
478 ui
->radioButtonEncoderMP3
->setChecked(true);
479 foreach(QAbstractButton
*currentButton
, m_encoderButtonGroup
->buttons())
481 if(currentButton
->isEnabled() && (m_encoderButtonGroup
->id(currentButton
) == m_settings
->compressionEncoder()))
483 currentButton
->setChecked(true);
488 m_evenFilterCompressionTab
.reset(new CustomEventFilter());
489 ui
->labelCompressionHelp
->installEventFilter(m_evenFilterCompressionTab
.data());
490 ui
->labelResetEncoders
->installEventFilter(m_evenFilterCompressionTab
.data());
492 connect(m_encoderButtonGroup
.data(), SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
493 connect(m_modeButtonGroup
.data(), SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
494 connect(m_evenFilterCompressionTab
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(compressionTabEventOccurred(QWidget
*, QEvent
*)));
495 connect(ui
->sliderBitrate
, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
497 updateEncoder(m_encoderButtonGroup
->checkedId());
499 //--------------------------------
500 //Setup "Advanced Options" tab
501 //--------------------------------
503 ui
->sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQuality());
504 if (m_settings
->maximumInstances() > 0U)
506 ui
->sliderMaxInstances
->setValue(static_cast<int>(encodeInstances(m_settings
->maximumInstances())));
509 ui
->spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRate());
510 ui
->spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRate());
511 ui
->spinBoxNormalizationFilterPeak
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolume()) / 100.0);
512 ui
->spinBoxNormalizationFilterSize
->setValue(m_settings
->normalizationFilterSize());
513 ui
->spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBass()) / 100.0);
514 ui
->spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTreble()) / 100.0);
515 ui
->spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSize());
516 ui
->spinBoxOpusComplexity
->setValue(m_settings
->opusComplexity());
518 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelMode());
519 ui
->comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRate());
520 ui
->comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfile());
521 ui
->comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingMode());
522 ui
->comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompression());
523 ui
->comboBoxOpusFramesize
->setCurrentIndex(m_settings
->opusFramesize());
525 SET_CHECKBOX_STATE(ui
->checkBoxBitrateManagement
, m_settings
->bitrateManagementEnabled());
526 SET_CHECKBOX_STATE(ui
->checkBoxNeroAAC2PassMode
, m_settings
->neroAACEnable2Pass());
527 SET_CHECKBOX_STATE(ui
->checkBoxAftenFastAllocation
, m_settings
->aftenFastBitAllocation());
528 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterEnabled
, m_settings
->normalizationFilterEnabled());
529 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterDynamic
, m_settings
->normalizationFilterDynamic());
530 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterCoupled
, m_settings
->normalizationFilterCoupled());
531 SET_CHECKBOX_STATE(ui
->checkBoxAutoDetectInstances
, (m_settings
->maximumInstances() < 1));
532 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabled()));
533 SET_CHECKBOX_STATE(ui
->checkBoxRename_Rename
, m_settings
->renameFiles_renameEnabled());
534 SET_CHECKBOX_STATE(ui
->checkBoxRename_RegExp
, m_settings
->renameFiles_regExpEnabled());
535 SET_CHECKBOX_STATE(ui
->checkBoxForceStereoDownmix
, m_settings
->forceStereoDownmix());
536 SET_CHECKBOX_STATE(ui
->checkBoxOpusDisableResample
, m_settings
->opusDisableResample());
537 SET_CHECKBOX_STATE(ui
->checkBoxKeepOriginalDateTime
, m_settings
->keepOriginalDataTime());
539 ui
->checkBoxNeroAAC2PassMode
->setEnabled(aacEncoder
== SettingsModel::AAC_ENCODER_NERO
);
541 ui
->lineEditCustomParamLAME
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::MP3Encoder
));
542 ui
->lineEditCustomParamOggEnc
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::VorbisEncoder
));
543 ui
->lineEditCustomParamNeroAAC
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::AACEncoder
));
544 ui
->lineEditCustomParamFLAC
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::FLACEncoder
));
545 ui
->lineEditCustomParamAften
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::AC3Encoder
));
546 ui
->lineEditCustomParamOpus
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::OpusEncoder
));
547 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPath()));
548 ui
->lineEditRenamePattern
->setText(m_settings
->renameFiles_renamePattern());
549 ui
->lineEditRenameRegExp_Search
->setText(m_settings
->renameFiles_regExpSearch ());
550 ui
->lineEditRenameRegExp_Replace
->setText(m_settings
->renameFiles_regExpReplace());
552 m_evenFilterCustumParamsHelp
.reset(new CustomEventFilter());
553 ui
->helpCustomParamLAME
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
554 ui
->helpCustomParamOggEnc
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
555 ui
->helpCustomParamNeroAAC
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
556 ui
->helpCustomParamFLAC
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
557 ui
->helpCustomParamAften
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
558 ui
->helpCustomParamOpus
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
560 m_overwriteButtonGroup
.reset(new QButtonGroup(this));
561 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeKeepBoth
, SettingsModel::Overwrite_KeepBoth
);
562 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeSkipFile
, SettingsModel::Overwrite_SkipFile
);
563 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeReplaces
, SettingsModel::Overwrite_Replaces
);
565 ui
->radioButtonOverwriteModeKeepBoth
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_KeepBoth
);
566 ui
->radioButtonOverwriteModeSkipFile
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_SkipFile
);
567 ui
->radioButtonOverwriteModeReplaces
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_Replaces
);
569 FileExtsModel
*fileExtModel
= new FileExtsModel(this);
570 fileExtModel
->importItems(m_settings
->renameFiles_fileExtension());
571 ui
->tableViewFileExts
->setModel(fileExtModel
);
572 ui
->tableViewFileExts
->verticalHeader() ->setResizeMode(QHeaderView::ResizeToContents
);
573 ui
->tableViewFileExts
->horizontalHeader()->setResizeMode(QHeaderView::Stretch
);
575 connect(ui
->sliderLameAlgoQuality
, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
576 connect(ui
->checkBoxBitrateManagement
, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
577 connect(ui
->spinBoxBitrateManagementMin
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
578 connect(ui
->spinBoxBitrateManagementMax
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
579 connect(ui
->comboBoxMP3ChannelMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
580 connect(ui
->comboBoxSamplingRate
, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
581 connect(ui
->checkBoxNeroAAC2PassMode
, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
582 connect(ui
->comboBoxAACProfile
, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
583 connect(ui
->checkBoxNormalizationFilterEnabled
, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
584 connect(ui
->checkBoxNormalizationFilterDynamic
, SIGNAL(clicked(bool)), this, SLOT(normalizationDynamicChanged(bool)));
585 connect(ui
->checkBoxNormalizationFilterCoupled
, SIGNAL(clicked(bool)), this, SLOT(normalizationCoupledChanged(bool)));
586 connect(ui
->comboBoxAftenCodingMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
587 connect(ui
->comboBoxAftenDRCMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
588 connect(ui
->spinBoxAftenSearchSize
, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
589 connect(ui
->checkBoxAftenFastAllocation
, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
590 connect(ui
->spinBoxNormalizationFilterPeak
, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
591 connect(ui
->spinBoxNormalizationFilterSize
, SIGNAL(valueChanged(int)), this, SLOT(normalizationFilterSizeChanged(int)));
592 connect(ui
->spinBoxNormalizationFilterSize
, SIGNAL(editingFinished()), this, SLOT(normalizationFilterSizeFinished()));
593 connect(ui
->spinBoxToneAdjustBass
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
594 connect(ui
->spinBoxToneAdjustTreble
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
595 connect(ui
->buttonToneAdjustReset
, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
596 connect(ui
->lineEditCustomParamLAME
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
597 connect(ui
->lineEditCustomParamOggEnc
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
598 connect(ui
->lineEditCustomParamNeroAAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
599 connect(ui
->lineEditCustomParamFLAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
600 connect(ui
->lineEditCustomParamAften
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
601 connect(ui
->lineEditCustomParamOpus
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
602 connect(ui
->sliderMaxInstances
, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
603 connect(ui
->checkBoxAutoDetectInstances
, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
604 connect(ui
->buttonBrowseCustomTempFolder
, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
605 connect(ui
->lineEditCustomTempFolder
, SIGNAL(textChanged(QString
)), this, SLOT(customTempFolderChanged(QString
)));
606 connect(ui
->checkBoxUseSystemTempFolder
, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
607 connect(ui
->buttonResetAdvancedOptions
, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
608 connect(ui
->checkBoxRename_Rename
, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
609 connect(ui
->checkBoxRename_RegExp
, SIGNAL(clicked(bool)), this, SLOT(renameRegExpEnabledChanged(bool)));
610 connect(ui
->lineEditRenamePattern
, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
611 connect(ui
->lineEditRenamePattern
, SIGNAL(textChanged(QString
)), this, SLOT(renameOutputPatternChanged(QString
)));
612 connect(ui
->lineEditRenameRegExp_Search
, SIGNAL(editingFinished()), this, SLOT(renameRegExpValueChanged()));
613 connect(ui
->lineEditRenameRegExp_Search
, SIGNAL(textChanged(QString
)), this, SLOT(renameRegExpSearchChanged(QString
)));
614 connect(ui
->lineEditRenameRegExp_Replace
, SIGNAL(editingFinished()), this, SLOT(renameRegExpValueChanged()));
615 connect(ui
->lineEditRenameRegExp_Replace
, SIGNAL(textChanged(QString
)), this, SLOT(renameRegExpReplaceChanged(QString
)));
616 connect(ui
->labelShowRenameMacros
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
617 connect(ui
->labelShowRegExpHelp
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
618 connect(ui
->checkBoxForceStereoDownmix
, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
619 connect(ui
->comboBoxOpusFramesize
, SIGNAL(currentIndexChanged(int)), this, SLOT(opusSettingsChanged()));
620 connect(ui
->spinBoxOpusComplexity
, SIGNAL(valueChanged(int)), this, SLOT(opusSettingsChanged()));
621 connect(ui
->checkBoxOpusDisableResample
, SIGNAL(clicked(bool)), this, SLOT(opusSettingsChanged()));
622 connect(ui
->buttonRename_Rename
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
623 connect(ui
->buttonRename_RegExp
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
624 connect(ui
->buttonRename_FileEx
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
625 connect(ui
->buttonFileExts_Add
, SIGNAL(clicked()), this, SLOT(fileExtAddButtonClicked()));
626 connect(ui
->buttonFileExts_Remove
, SIGNAL(clicked()), this, SLOT(fileExtRemoveButtonClicked()));
627 connect(ui
->checkBoxKeepOriginalDateTime
, SIGNAL(clicked(bool)), this, SLOT(keepOriginalDateTimeChanged(bool)));
628 connect(m_overwriteButtonGroup
.data(), SIGNAL(buttonClicked(int)), this, SLOT(overwriteModeChanged(int)));
629 connect(m_evenFilterCustumParamsHelp
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(customParamsHelpRequested(QWidget
*, QEvent
*)));
630 connect(fileExtModel
, SIGNAL(modelReset()), this, SLOT(fileExtModelChanged()));
632 //--------------------------------
633 // Force initial GUI update
634 //--------------------------------
636 updateLameAlgoQuality(ui
->sliderLameAlgoQuality
->value());
637 updateMaximumInstances(ui
->sliderMaxInstances
->value());
638 toneAdjustTrebleChanged(ui
->spinBoxToneAdjustTreble
->value());
639 toneAdjustBassChanged(ui
->spinBoxToneAdjustBass
->value());
640 normalizationEnabledChanged(ui
->checkBoxNormalizationFilterEnabled
->isChecked());
641 customParamsChanged();
643 //--------------------------------
644 // Initialize actions
645 //--------------------------------
647 //Activate file menu actions
648 ui
->actionOpenFolder
->setData(QVariant::fromValue
<bool>(false));
649 ui
->actionOpenFolderRecursively
->setData(QVariant::fromValue
<bool>(true));
650 connect(ui
->actionOpenFolder
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
651 connect(ui
->actionOpenFolderRecursively
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
653 //Activate view menu actions
654 m_tabActionGroup
.reset(new QActionGroup(this));
655 m_tabActionGroup
->addAction(ui
->actionSourceFiles
);
656 m_tabActionGroup
->addAction(ui
->actionOutputDirectory
);
657 m_tabActionGroup
->addAction(ui
->actionCompression
);
658 m_tabActionGroup
->addAction(ui
->actionMetaData
);
659 m_tabActionGroup
->addAction(ui
->actionAdvancedOptions
);
660 ui
->actionSourceFiles
->setData(0);
661 ui
->actionOutputDirectory
->setData(1);
662 ui
->actionMetaData
->setData(2);
663 ui
->actionCompression
->setData(3);
664 ui
->actionAdvancedOptions
->setData(4);
665 ui
->actionSourceFiles
->setChecked(true);
666 connect(m_tabActionGroup
.data(), SIGNAL(triggered(QAction
*)), this, SLOT(tabActionActivated(QAction
*)));
668 //Activate style menu actions
669 m_styleActionGroup
.reset(new QActionGroup(this));
670 m_styleActionGroup
->addAction(ui
->actionStylePlastique
);
671 m_styleActionGroup
->addAction(ui
->actionStyleCleanlooks
);
672 m_styleActionGroup
->addAction(ui
->actionStyleWindowsVista
);
673 m_styleActionGroup
->addAction(ui
->actionStyleWindowsXP
);
674 m_styleActionGroup
->addAction(ui
->actionStyleWindowsClassic
);
675 ui
->actionStylePlastique
->setData(0);
676 ui
->actionStyleCleanlooks
->setData(1);
677 ui
->actionStyleWindowsVista
->setData(2);
678 ui
->actionStyleWindowsXP
->setData(3);
679 ui
->actionStyleWindowsClassic
->setData(4);
680 ui
->actionStylePlastique
->setChecked(true);
681 ui
->actionStyleWindowsXP
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_XP
&& MUtils::GUI::themes_enabled());
682 ui
->actionStyleWindowsVista
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_VISTA
&& MUtils::GUI::themes_enabled());
683 connect(m_styleActionGroup
.data(), SIGNAL(triggered(QAction
*)), this, SLOT(styleActionActivated(QAction
*)));
684 styleActionActivated(NULL
);
686 //Populate the language menu
687 m_languageActionGroup
.reset(new QActionGroup(this));
688 QStringList translations
;
689 if(MUtils::Translation::enumerate(translations
) > 0)
691 for(QStringList::ConstIterator iter
= translations
.constBegin(); iter
!= translations
.constEnd(); iter
++)
693 QAction
*currentLanguage
= new QAction(this);
694 currentLanguage
->setData(*iter
);
695 currentLanguage
->setText(MUtils::Translation::get_name(*iter
));
696 currentLanguage
->setIcon(QIcon(QString(":/flags/%1.png").arg(*iter
)));
697 currentLanguage
->setCheckable(true);
698 currentLanguage
->setChecked(false);
699 m_languageActionGroup
->addAction(currentLanguage
);
700 ui
->menuLanguage
->insertAction(ui
->actionLoadTranslationFromFile
, currentLanguage
);
703 ui
->menuLanguage
->insertSeparator(ui
->actionLoadTranslationFromFile
);
704 connect(ui
->actionLoadTranslationFromFile
, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
705 connect(m_languageActionGroup
.data(), SIGNAL(triggered(QAction
*)), this, SLOT(languageActionActivated(QAction
*)));
706 ui
->actionLoadTranslationFromFile
->setChecked(false);
708 //Activate tools menu actions
709 ui
->actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
710 ui
->actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
711 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
712 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
713 ui
->actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
714 ui
->actionDisableShellIntegration
->setDisabled(lamexp_version_portable() && ui
->actionDisableShellIntegration
->isChecked());
715 ui
->actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta() || lamexp_version_demo());
716 ui
->actionCheckForBetaUpdates
->setEnabled(!lamexp_version_demo());
717 ui
->actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
718 ui
->actionHibernateComputer
->setEnabled(MUtils::OS::is_hibernation_supported());
719 connect(ui
->actionDisableUpdateReminder
, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
720 connect(ui
->actionDisableSounds
, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
721 connect(ui
->actionDisableNeroAacNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
722 connect(ui
->actionDisableSlowStartupNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
723 connect(ui
->actionDisableShellIntegration
, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
724 connect(ui
->actionShowDropBoxWidget
, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
725 connect(ui
->actionHibernateComputer
, SIGNAL(triggered(bool)), this, SLOT(hibernateComputerActionTriggered(bool)));
726 connect(ui
->actionCheckForBetaUpdates
, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
727 connect(ui
->actionImportCueSheet
, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
729 //Activate help menu actions
730 ui
->actionVisitHomepage
->setData(QString::fromLatin1(lamexp_website_url()));
731 ui
->actionVisitSupport
->setData(QString::fromLatin1(lamexp_support_url()));
732 ui
->actionVisitMuldersSite
->setData(QString::fromLatin1(lamexp_mulders_url()));
733 ui
->actionVisitTracker
->setData(QString::fromLatin1(lamexp_tracker_url()));
734 ui
->actionVisitHAK
->setData(QString::fromLatin1(g_hydrogen_audio_url
));
735 ui
->actionDocumentManual
->setData(QString("%1/Manual.html") .arg(QApplication::applicationDirPath()));
736 ui
->actionDocumentChangelog
->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
737 ui
->actionDocumentTranslate
->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
738 connect(ui
->actionCheckUpdates
, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
739 connect(ui
->actionVisitSupport
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
740 connect(ui
->actionVisitTracker
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
741 connect(ui
->actionVisitHomepage
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
742 connect(ui
->actionVisitMuldersSite
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
743 connect(ui
->actionVisitHAK
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
744 connect(ui
->actionDocumentManual
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
745 connect(ui
->actionDocumentChangelog
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
746 connect(ui
->actionDocumentTranslate
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
748 //--------------------------------
749 // Prepare to show window
750 //--------------------------------
752 //Adjust size to DPI settings and re-center
753 MUtils::GUI::scale_widget(this);
755 //Create DropBox widget
756 m_dropBox
.reset(new DropBox(this, m_fileListModel
, m_settings
));
757 connect(m_fileListModel
, SIGNAL(modelReset()), m_dropBox
.data(), SLOT(modelChanged()));
758 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), m_dropBox
.data(), SLOT(modelChanged()));
759 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), m_dropBox
.data(), SLOT(modelChanged()));
760 connect(m_fileListModel
, SIGNAL(rowAppended()), m_dropBox
.data(), SLOT(modelChanged()));
762 //Create message handler thread
763 m_messageHandler
.reset(new MessageHandlerThread(ipcChannel
));
764 connect(m_messageHandler
.data(), SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection
);
765 connect(m_messageHandler
.data(), SIGNAL(fileReceived(QString
)), this, SLOT(addFileDelayed(QString
)), Qt::QueuedConnection
);
766 connect(m_messageHandler
.data(), SIGNAL(folderReceived(QString
, bool)), this, SLOT(addFolderDelayed(QString
, bool)), Qt::QueuedConnection
);
767 connect(m_messageHandler
.data(), SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection
);
768 m_messageHandler
->start();
770 //Init delayed file handling
771 m_delayedFileList
.reset(new QStringList());
772 m_delayedFileTimer
.reset(new QTimer());
773 m_delayedFileTimer
->setSingleShot(true);
774 m_delayedFileTimer
->setInterval(5000);
775 connect(m_delayedFileTimer
.data(), SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
778 initializeTranslation();
780 //Re-translate (make sure we translate once)
781 QEvent
languageChangeEvent(QEvent::LanguageChange
);
782 changeEvent(&languageChangeEvent
);
785 m_droppedFileList
.reset(new QList
<QUrl
>());
786 this->setAcceptDrops(true);
789 ////////////////////////////////////////////////////////////
791 ////////////////////////////////////////////////////////////
793 MainWindow::~MainWindow(void)
795 //Stop message handler thread
796 if(m_messageHandler
&& m_messageHandler
->isRunning())
798 m_messageHandler
->stop();
799 if(!m_messageHandler
->wait(2500))
801 m_messageHandler
->terminate();
802 m_messageHandler
->wait();
807 SET_MODEL(ui
->sourceFileView
, NULL
);
808 SET_MODEL(ui
->outputFolderView
, NULL
);
809 SET_MODEL(ui
->metaDataView
, NULL
);
811 //Un-initialize the dialog
815 ////////////////////////////////////////////////////////////
817 ////////////////////////////////////////////////////////////
820 * Add file to source list
822 void MainWindow::addFiles(const QStringList
&files
)
829 if(ui
->tabWidget
->currentIndex() != 0)
831 SignalBlockHelper
signalBlockHelper(ui
->tabWidget
);
832 ui
->tabWidget
->setCurrentIndex(0);
833 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
837 QScopedPointer
<FileAnalyzer
> analyzer(new FileAnalyzer(files
));
839 connect(analyzer
.data(), SIGNAL(fileSelected(QString
)), m_banner
.data(), SLOT(setText(QString
)), Qt::QueuedConnection
);
840 connect(analyzer
.data(), SIGNAL(progressValChanged(unsigned int)), m_banner
.data(), SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection
);
841 connect(analyzer
.data(), SIGNAL(progressMaxChanged(unsigned int)), m_banner
.data(), SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection
);
842 connect(analyzer
.data(), SIGNAL(fileAnalyzed(AudioFileModel
)), m_fileListModel
, SLOT(addFile(AudioFileModel
)), Qt::QueuedConnection
);
843 connect(m_banner
.data(), SIGNAL(userAbort()), analyzer
.data(), SLOT(abortProcess()), Qt::DirectConnection
);
845 if(!analyzer
.isNull())
847 FileListBlockHelper
fileListBlocker(m_fileListModel
);
848 m_banner
->show(tr("Adding file(s), please wait..."), analyzer
.data());
851 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
852 ui
->sourceFileView
->update();
853 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
854 ui
->sourceFileView
->scrollToBottom();
855 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
857 if(analyzer
->filesDenied())
859 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."))));
861 if(analyzer
->filesDummyCDDA())
863 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>"))));
865 if(analyzer
->filesCueSheet())
867 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."))));
869 if(analyzer
->filesRejected())
871 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."))));
878 * Add folder to source list
880 void MainWindow::addFolder(const QString
&path
, bool recursive
, bool delayed
, QString filter
)
882 QFileInfoList folderInfoList
;
883 folderInfoList
<< QFileInfo(path
);
884 QStringList fileList
;
886 showBanner(tr("Scanning folder(s) for files, please wait..."));
888 QApplication::processEvents();
889 MUtils::OS::check_key_state_esc();
891 while(!folderInfoList
.isEmpty())
893 if(MUtils::OS::check_key_state_esc())
895 qWarning("Operation cancelled by user!");
896 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
901 QDir
currentDir(folderInfoList
.takeFirst().canonicalFilePath());
902 QFileInfoList fileInfoList
= currentDir
.entryInfoList(QDir::Files
| QDir::NoSymLinks
);
904 for(QFileInfoList::ConstIterator iter
= fileInfoList
.constBegin(); iter
!= fileInfoList
.constEnd(); iter
++)
906 if(filter
.isEmpty() || (iter
->suffix().compare(filter
, Qt::CaseInsensitive
) == 0))
908 fileList
<< iter
->canonicalFilePath();
912 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
916 folderInfoList
.append(currentDir
.entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
));
917 QApplication::processEvents();
922 QApplication::processEvents();
924 if(!fileList
.isEmpty())
928 addFilesDelayed(fileList
);
940 bool MainWindow::checkForUpdates(void)
942 bool bReadyToInstall
= false;
944 UpdateDialog
*updateDialog
= new UpdateDialog(m_settings
, this);
945 updateDialog
->exec();
947 if(updateDialog
->getSuccess())
949 SHOW_CORNER_WIDGET(false);
950 m_settings
->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate
));
951 bReadyToInstall
= updateDialog
->updateReadyToInstall();
954 MUTILS_DELETE(updateDialog
);
955 return bReadyToInstall
;
959 * Refresh list of favorites
961 void MainWindow::refreshFavorites(void)
963 QList
<QAction
*> folderList
= m_outputFolderFavoritesMenu
->actions();
964 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
965 while(favorites
.count() > 6) favorites
.removeFirst();
967 while(!folderList
.isEmpty())
969 QAction
*currentItem
= folderList
.takeFirst();
970 if(currentItem
->isSeparator()) break;
971 m_outputFolderFavoritesMenu
->removeAction(currentItem
);
972 MUTILS_DELETE(currentItem
);
975 QAction
*lastItem
= m_outputFolderFavoritesMenu
->actions().first();
977 while(!favorites
.isEmpty())
979 QString path
= favorites
.takeLast();
980 if(QDir(path
).exists())
982 QAction
*action
= new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path
), this);
983 action
->setData(path
);
984 m_outputFolderFavoritesMenu
->insertAction(lastItem
, action
);
985 connect(action
, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
992 * Initilaize translation
994 void MainWindow::initializeTranslation(void)
996 bool translationLoaded
= false;
998 //Try to load "external" translation file
999 if(!m_settings
->currentLanguageFile().isEmpty())
1001 const QString qmFilePath
= QFileInfo(m_settings
->currentLanguageFile()).canonicalFilePath();
1002 if((!qmFilePath
.isEmpty()) && QFileInfo(qmFilePath
).exists() && QFileInfo(qmFilePath
).isFile() && (QFileInfo(qmFilePath
).suffix().compare("qm", Qt::CaseInsensitive
) == 0))
1004 if(MUtils::Translation::install_translator_from_file(qmFilePath
))
1006 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
1007 while(!actions
.isEmpty()) actions
.takeFirst()->setChecked(false);
1008 ui
->actionLoadTranslationFromFile
->setChecked(true);
1009 translationLoaded
= true;
1014 //Try to load "built-in" translation file
1015 if(!translationLoaded
)
1017 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
1018 while(!languageActions
.isEmpty())
1020 QAction
*currentLanguage
= languageActions
.takeFirst();
1021 if(currentLanguage
->data().toString().compare(m_settings
->currentLanguage(), Qt::CaseInsensitive
) == 0)
1023 currentLanguage
->setChecked(true);
1024 languageActionActivated(currentLanguage
);
1025 translationLoaded
= true;
1030 //Fallback to default translation
1031 if(!translationLoaded
)
1033 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
1034 while(!languageActions
.isEmpty())
1036 QAction
*currentLanguage
= languageActions
.takeFirst();
1037 if(currentLanguage
->data().toString().compare(MUtils::Translation::DEFAULT_LANGID
, Qt::CaseInsensitive
) == 0)
1039 currentLanguage
->setChecked(true);
1040 languageActionActivated(currentLanguage
);
1041 translationLoaded
= true;
1046 //Make sure we loaded some translation
1047 if(!translationLoaded
)
1049 qFatal("Failed to load any translation, this is NOT supposed to happen!");
1054 * Open a document link
1056 void MainWindow::openDocumentLink(QAction
*const action
)
1058 if(!(action
->data().isValid() && (action
->data().type() == QVariant::String
)))
1060 qWarning("Cannot open document for this QAction!");
1064 //Try to open exitsing document file
1065 const QFileInfo
document(action
->data().toString());
1066 if(document
.exists() && document
.isFile() && (document
.size() >= 1024))
1068 QDesktopServices::openUrl(QUrl::fromLocalFile(document
.canonicalFilePath()));
1072 //Document not found -> fallback mode!
1073 qWarning("Document '%s' not found -> redirecting to the website!", MUTILS_UTF8(document
.fileName()));
1074 const QUrl
url(QString("%1/%2").arg(QString::fromLatin1(g_documents_base_url
), document
.fileName()));
1075 QDesktopServices::openUrl(url
);
1079 * Move selected files up/down
1081 void MainWindow::moveSelectedFiles(const bool &up
)
1083 QItemSelectionModel
*const selection
= ui
->sourceFileView
->selectionModel();
1084 if(selection
&& selection
->hasSelection())
1086 const QModelIndexList selectedRows
= up
? selection
->selectedRows() : INVERT_LIST(selection
->selectedRows());
1087 if((up
&& (selectedRows
.first().row() > 0)) || ((!up
) && (selectedRows
.first().row() < m_fileListModel
->rowCount() - 1)))
1089 const int delta
= up
? (-1) : 1;
1090 const int firstIndex
= (up
? selectedRows
.first() : selectedRows
.last()).row() + delta
;
1091 const int selectionCount
= selectedRows
.count();
1094 FileListBlockHelper
fileListBlocker(m_fileListModel
);
1095 for(QModelIndexList::ConstIterator iter
= selectedRows
.constBegin(); iter
!= selectedRows
.constEnd(); iter
++)
1097 if(!m_fileListModel
->moveFile((*iter
), delta
))
1103 selection
->clearSelection();
1104 for(int i
= 0; i
< selectionCount
; i
++)
1106 const QModelIndex item
= m_fileListModel
->index(firstIndex
+ i
, 0);
1107 selection
->select(QItemSelection(item
, item
), QItemSelectionModel::Select
| QItemSelectionModel::Rows
);
1109 ui
->sourceFileView
->scrollTo(m_fileListModel
->index((up
? firstIndex
: firstIndex
+ selectionCount
- 1), 0), QAbstractItemView::PositionAtCenter
);
1113 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
1117 * Show banner popup dialog
1119 void MainWindow::showBanner(const QString
&text
)
1122 m_banner
->show(text
);
1126 * Show banner popup dialog
1128 void MainWindow::showBanner(const QString
&text
, QThread
*const thread
)
1131 m_banner
->show(text
, thread
);
1135 * Show banner popup dialog
1137 void MainWindow::showBanner(const QString
&text
, QEventLoop
*const eventLoop
)
1140 m_banner
->show(text
, eventLoop
);
1144 * Show banner popup dialog
1146 void MainWindow::showBanner(const QString
&text
, bool &flag
, const bool &test
)
1148 if((!flag
) && (test
))
1151 m_banner
->show(text
);
1156 ////////////////////////////////////////////////////////////
1158 ////////////////////////////////////////////////////////////
1161 * Window is about to be shown
1163 void MainWindow::showEvent(QShowEvent
*event
)
1167 sourceModelChanged();
1169 if(!event
->spontaneous())
1171 SignalBlockHelper
signalBlockHelper(ui
->tabWidget
);
1172 ui
->tabWidget
->setCurrentIndex(0);
1173 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
1176 if(m_firstTimeShown
)
1178 m_firstTimeShown
= false;
1179 QTimer::singleShot(0, this, SLOT(windowShown()));
1183 if(m_settings
->dropBoxWidgetEnabled())
1185 m_dropBox
->setVisible(true);
1191 * Re-translate the UI
1193 void MainWindow::changeEvent(QEvent
*e
)
1195 QMainWindow::changeEvent(e
);
1196 if(e
->type() != QEvent::LanguageChange
)
1201 int comboBoxIndex
[6];
1203 //Backup combobox indices, as retranslateUi() resets
1204 comboBoxIndex
[0] = ui
->comboBoxMP3ChannelMode
->currentIndex();
1205 comboBoxIndex
[1] = ui
->comboBoxSamplingRate
->currentIndex();
1206 comboBoxIndex
[2] = ui
->comboBoxAACProfile
->currentIndex();
1207 comboBoxIndex
[3] = ui
->comboBoxAftenCodingMode
->currentIndex();
1208 comboBoxIndex
[4] = ui
->comboBoxAftenDRCMode
->currentIndex();
1209 comboBoxIndex
[5] = ui
->comboBoxOpusFramesize
->currentIndex();
1211 //Re-translate from UIC
1212 ui
->retranslateUi(this);
1214 //Restore combobox indices
1215 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(comboBoxIndex
[0]);
1216 ui
->comboBoxSamplingRate
->setCurrentIndex(comboBoxIndex
[1]);
1217 ui
->comboBoxAACProfile
->setCurrentIndex(comboBoxIndex
[2]);
1218 ui
->comboBoxAftenCodingMode
->setCurrentIndex(comboBoxIndex
[3]);
1219 ui
->comboBoxAftenDRCMode
->setCurrentIndex(comboBoxIndex
[4]);
1220 ui
->comboBoxOpusFramesize
->setCurrentIndex(comboBoxIndex
[5]);
1222 //Update the window title
1225 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
1227 else if(lamexp_version_demo())
1229 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
1232 //Manually re-translate widgets that UIC doesn't handle
1233 m_outputFolderNoteBox
->setText(tr("Initializing directory outline, please be patient..."));
1234 m_dropNoteLabel
->setText(QString("<br><img src=\":/images/DropZone.png\"><br><br>%1").arg(tr("You can drop in audio files here!")));
1235 if(QLabel
*cornerWidget
= dynamic_cast<QLabel
*>(ui
->menubar
->cornerWidget()))
1237 cornerWidget
->setText(QString("<nobr><img src=\":/icons/exclamation_small.png\"> <b style=\"color:darkred\">%1</b> </nobr>").arg(tr("Check for Updates")));
1239 m_showDetailsContextAction
->setText(tr("Show Details"));
1240 m_previewContextAction
->setText(tr("Open File in External Application"));
1241 m_findFileContextAction
->setText(tr("Browse File Location"));
1242 m_showFolderContextAction
->setText(tr("Browse Selected Folder"));
1243 m_refreshFolderContextAction
->setText(tr("Refresh Directory Outline"));
1244 m_goUpFolderContextAction
->setText(tr("Go To Parent Directory"));
1245 m_addFavoriteFolderAction
->setText(tr("Bookmark Current Output Folder"));
1246 m_exportCsvContextAction
->setText(tr("Export Meta Tags to CSV File"));
1247 m_importCsvContextAction
->setText(tr("Import Meta Tags from CSV File"));
1250 m_metaInfoModel
->clearData();
1251 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
1252 updateEncoder(m_settings
->compressionEncoder());
1253 updateLameAlgoQuality(ui
->sliderLameAlgoQuality
->value());
1254 updateMaximumInstances(ui
->sliderMaxInstances
->value());
1255 renameOutputPatternChanged(ui
->lineEditRenamePattern
->text(), true);
1256 renameRegExpSearchChanged (ui
->lineEditRenameRegExp_Search
->text(), true);
1257 renameRegExpReplaceChanged(ui
->lineEditRenameRegExp_Replace
->text(), true);
1259 //Re-install shell integration
1260 if(m_settings
->shellIntegrationEnabled())
1262 ShellIntegration::install();
1265 //Translate system menu
1266 MUtils::GUI::sysmenu_update(this, IDM_ABOUTBOX
, ui
->buttonAbout
->text());
1268 //Force resize event
1269 QApplication::postEvent(this, new QResizeEvent(this->size(), QSize()));
1270 for(QObjectList::ConstIterator iter
= this->children().constBegin(); iter
!= this->children().constEnd(); iter
++)
1272 if(QWidget
*child
= dynamic_cast<QWidget
*>(*iter
))
1274 QApplication::postEvent(child
, new QResizeEvent(child
->size(), QSize()));
1278 //Force tabe page change
1279 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
1283 * File dragged over window
1285 void MainWindow::dragEnterEvent(QDragEnterEvent
*event
)
1287 QStringList formats
= event
->mimeData()->formats();
1289 if(formats
.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive
) && formats
.contains("text/uri-list", Qt::CaseInsensitive
))
1291 event
->acceptProposedAction();
1296 * File dropped onto window
1298 void MainWindow::dropEvent(QDropEvent
*event
)
1300 m_droppedFileList
->clear();
1301 (*m_droppedFileList
) << event
->mimeData()->urls();
1302 if(!m_droppedFileList
->isEmpty())
1304 PLAY_SOUND_OPTIONAL("drop", true);
1305 QTimer::singleShot(0, this, SLOT(handleDroppedFiles()));
1310 * Window tries to close
1312 void MainWindow::closeEvent(QCloseEvent
*event
)
1314 if(BANNER_VISIBLE
|| m_delayedFileTimer
->isActive())
1316 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
1327 * Window was resized
1329 void MainWindow::resizeEvent(QResizeEvent
*event
)
1331 if(event
) QMainWindow::resizeEvent(event
);
1333 if(QWidget
*port
= ui
->sourceFileView
->viewport())
1335 m_dropNoteLabel
->setGeometry(port
->geometry());
1338 if(QWidget
*port
= ui
->outputFolderView
->viewport())
1340 m_outputFolderNoteBox
->setGeometry(16, (port
->height() - 64) / 2, port
->width() - 32, 64);
1345 * Key press event filter
1347 void MainWindow::keyPressEvent(QKeyEvent
*e
)
1349 if(e
->key() == Qt::Key_Delete
)
1351 if(ui
->sourceFileView
->isVisible())
1353 QTimer::singleShot(0, this, SLOT(removeFileButtonClicked()));
1358 if(e
->modifiers().testFlag(Qt::ControlModifier
) && (e
->key() == Qt::Key_F5
))
1360 initializeTranslation();
1361 MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
1365 if(e
->key() == Qt::Key_F5
)
1367 if(ui
->outputFolderView
->isVisible())
1369 QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
1374 QMainWindow::keyPressEvent(e
);
1380 bool MainWindow::eventFilter(QObject
*obj
, QEvent
*event
)
1382 if(obj
== m_fileSystemModel
.data())
1384 if(QApplication::overrideCursor() == NULL
)
1386 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
1387 QTimer::singleShot(250, this, SLOT(restoreCursor()));
1391 return QMainWindow::eventFilter(obj
, event
);
1394 bool MainWindow::event(QEvent
*e
)
1398 case MUtils::GUI::USER_EVENT_QUERYENDSESSION
:
1399 qWarning("System is shutting down, main window prepares to close...");
1400 if(BANNER_VISIBLE
) m_banner
->close();
1401 if(m_delayedFileTimer
->isActive()) m_delayedFileTimer
->stop();
1403 case MUtils::GUI::USER_EVENT_ENDSESSION
:
1404 qWarning("System is shutting down, main window will close now...");
1409 QApplication::processEvents(QEventLoop::WaitForMoreEvents
& QEventLoop::ExcludeUserInputEvents
);
1412 m_fileListModel
->clearFiles();
1414 case QEvent::MouseButtonPress
:
1415 if(ui
->outputFolderEdit
->isVisible())
1417 QTimer::singleShot(0, this, SLOT(outputFolderEditFinished()));
1420 return QMainWindow::event(e
);
1424 bool MainWindow::winEvent(MSG
*message
, long *result
)
1426 if(MUtils::GUI::sysmenu_check_msg(message
, IDM_ABOUTBOX
))
1428 QTimer::singleShot(0, ui
->buttonAbout
, SLOT(click()));
1435 ////////////////////////////////////////////////////////////
1437 ////////////////////////////////////////////////////////////
1439 // =========================================================
1440 // Show window slots
1441 // =========================================================
1446 void MainWindow::windowShown(void)
1448 const MUtils::OS::ArgumentMap
&arguments
= MUtils::OS::arguments(); //QApplication::arguments();
1450 //Force resize event
1454 const bool firstRun
= arguments
.contains("first-run");
1457 if((m_settings
->licenseAccepted() <= 0) || firstRun
)
1459 int iAccepted
= m_settings
->licenseAccepted();
1461 if((iAccepted
== 0) || firstRun
)
1463 AboutDialog
*about
= new AboutDialog(m_settings
, this, true);
1464 iAccepted
= about
->exec();
1465 if(iAccepted
<= 0) iAccepted
= -2;
1466 MUTILS_DELETE(about
);
1471 m_settings
->licenseAccepted(++iAccepted
);
1472 m_settings
->syncNow();
1473 QApplication::processEvents();
1474 MUtils::Sound::play_sound("whammy", false);
1475 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
1476 QFileInfo uninstallerInfo
= QFileInfo(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()));
1477 if(uninstallerInfo
.exists())
1479 QString uninstallerDir
= uninstallerInfo
.canonicalPath();
1480 QString uninstallerPath
= uninstallerInfo
.canonicalFilePath();
1481 for(int i
= 0; i
< 3; i
++)
1483 if(MUtils::OS::shell_open(this, QDir::toNativeSeparators(uninstallerPath
), "/Force", QDir::toNativeSeparators(uninstallerDir
))) break;
1486 QApplication::quit();
1490 MUtils::Sound::play_sound("woohoo", false);
1491 m_settings
->licenseAccepted(1);
1492 m_settings
->syncNow();
1493 if(lamexp_version_demo()) showAnnounceBox();
1496 //Check for expiration
1497 if(lamexp_version_demo())
1499 if(MUtils::OS::current_date() >= lamexp_version_expires())
1501 qWarning("Binary has expired !!!");
1502 MUtils::Sound::play_sound("whammy", false);
1503 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)
1507 QApplication::quit();
1512 //Slow startup indicator
1513 if(m_settings
->slowStartup() && m_settings
->antivirNotificationsEnabled())
1516 message
+= NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
1517 message
+= NOBR(tr("Please refer to the %1 document for details and solutions!")).arg(LINK_EX(QString("%1/Manual.html#performance-issues").arg(g_documents_base_url
), tr("Manual"))).append("<br>");
1518 if(QMessageBox::warning(this, tr("Slow Startup"), message
, tr("Discard"), tr("Don't Show Again")) == 1)
1520 m_settings
->antivirNotificationsEnabled(false);
1521 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
1526 if(MUtils::OS::current_date() >= MUtils::Version::app_build_date().addYears(1))
1528 qWarning("Binary is more than a year old, time to update!");
1529 SHOW_CORNER_WIDGET(true);
1530 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"));
1534 if(checkForUpdates())
1536 QApplication::quit();
1541 QApplication::quit();
1544 QEventLoop loop
; QTimer::singleShot(7000, &loop
, SLOT(quit()));
1545 MUtils::Sound::play_sound("waiting", true);
1546 showBanner(tr("Skipping update check this time, please be patient..."), &loop
);
1552 QDate lastUpdateCheck
= QDate::fromString(m_settings
->autoUpdateLastCheck(), Qt::ISODate
);
1553 if((!firstRun
) && ((!lastUpdateCheck
.isValid()) || (MUtils::OS::current_date() >= lastUpdateCheck
.addDays(14))))
1555 SHOW_CORNER_WIDGET(true);
1556 if(m_settings
->autoUpdateEnabled())
1558 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)
1560 if(checkForUpdates())
1562 QApplication::quit();
1570 //Check for AAC support
1571 const int aacEncoder
= EncoderRegistry::getAacEncoder();
1572 if(aacEncoder
== SettingsModel::AAC_ENCODER_NERO
)
1574 if(m_settings
->neroAacNotificationsEnabled())
1576 if(lamexp_tools_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1578 QString messageText
;
1579 messageText
+= NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1580 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>");
1581 messageText
+= NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1582 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br><br>";
1583 messageText
+= NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
1584 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText
);
1590 if(m_settings
->neroAacNotificationsEnabled() && (aacEncoder
<= SettingsModel::AAC_ENCODER_NONE
))
1592 QString appPath
= QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1593 if(appPath
.isEmpty()) appPath
= QCoreApplication::applicationDirPath();
1594 QString messageText
;
1595 messageText
+= NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1596 messageText
+= NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1597 messageText
+= NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1598 messageText
+= QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath
)));
1599 messageText
+= NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1600 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br>";
1601 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText
, tr("Discard"), tr("Don't Show Again")) == 1)
1603 m_settings
->neroAacNotificationsEnabled(false);
1604 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1609 //Add files from the command-line
1610 QStringList addedFiles
;
1611 foreach(const QString
&value
, arguments
.values("add"))
1613 if(!value
.isEmpty())
1615 QFileInfo
currentFile(value
);
1616 qDebug("Adding file from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1617 addedFiles
.append(currentFile
.absoluteFilePath());
1620 if(!addedFiles
.isEmpty())
1622 addFilesDelayed(addedFiles
);
1625 //Add folders from the command-line
1626 foreach(const QString
&value
, arguments
.values("add-folder"))
1628 if(!value
.isEmpty())
1630 const QFileInfo
currentFile(value
);
1631 qDebug("Adding folder from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1632 addFolder(currentFile
.absoluteFilePath(), false, true);
1635 foreach(const QString
&value
, arguments
.values("add-recursive"))
1637 if(!value
.isEmpty())
1639 const QFileInfo
currentFile(value
);
1640 qDebug("Adding folder recursively from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1641 addFolder(currentFile
.absoluteFilePath(), true, true);
1645 //Enable shell integration
1646 if(m_settings
->shellIntegrationEnabled())
1648 ShellIntegration::install();
1651 //Make DropBox visible
1652 if(m_settings
->dropBoxWidgetEnabled())
1654 m_dropBox
->setVisible(true);
1661 void MainWindow::showAnnounceBox(void)
1663 const unsigned int timeout
= 8U;
1665 const QString announceText
= QString("%1<br><br>%2<br><nobr><tt>%3</tt></nobr><br>").arg
1667 NOBR("We are still looking for LameXP translators!"),
1668 NOBR("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:"),
1669 LINK("http://lamexp.sourceforge.net/doc/Translate.html")
1672 QMessageBox
*announceBox
= new QMessageBox(QMessageBox::Warning
, "We want you!", announceText
, QMessageBox::NoButton
, this);
1673 announceBox
->setWindowFlags(Qt::Window
| Qt::WindowTitleHint
| Qt::CustomizeWindowHint
);
1674 announceBox
->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1676 QTimer
*timers
[timeout
+1];
1677 QPushButton
*buttons
[timeout
+1];
1679 for(unsigned int i
= 0; i
<= timeout
; i
++)
1681 QString text
= (i
> 0) ? QString("%1 (%2)").arg(tr("Discard"), QString::number(i
)) : tr("Discard");
1682 buttons
[i
] = announceBox
->addButton(text
, (i
> 0) ? QMessageBox::NoRole
: QMessageBox::AcceptRole
);
1685 for(unsigned int i
= 0; i
<= timeout
; i
++)
1687 buttons
[i
]->setEnabled(i
== 0);
1688 buttons
[i
]->setVisible(i
== timeout
);
1691 for(unsigned int i
= 0; i
< timeout
; i
++)
1693 timers
[i
] = new QTimer(this);
1694 timers
[i
]->setSingleShot(true);
1695 timers
[i
]->setInterval(1000);
1696 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
+1], SLOT(hide()));
1697 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
], SLOT(show()));
1700 connect(timers
[i
], SIGNAL(timeout()), timers
[i
-1], SLOT(start()));
1704 timers
[timeout
-1]->start();
1705 announceBox
->exec();
1707 for(unsigned int i
= 0; i
< timeout
; i
++)
1710 MUTILS_DELETE(timers
[i
]);
1713 MUTILS_DELETE(announceBox
);
1716 // =========================================================
1717 // Main button solots
1718 // =========================================================
1723 void MainWindow::encodeButtonClicked(void)
1725 static const unsigned __int64 oneGigabyte
= 1073741824ui
64;
1726 static const unsigned __int64 minimumFreeDiskspaceMultiplier
= 2ui
64;
1727 static const char *writeTestBuffer
= "LAMEXP_WRITE_TEST";
1731 if(m_fileListModel
->rowCount() < 1)
1733 QMessageBox::warning(this, tr("LameXP"), NOBR(tr("You must add at least one file to the list before proceeding!")));
1734 ui
->tabWidget
->setCurrentIndex(0);
1738 QString tempFolder
= m_settings
->customTempPathEnabled() ? m_settings
->customTempPath() : MUtils::temp_folder();
1739 if(!QFileInfo(tempFolder
).exists() || !QFileInfo(tempFolder
).isDir())
1741 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)
1743 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabledDefault()));
1748 quint64 currentFreeDiskspace
= 0;
1749 if(MUtils::OS::free_diskspace(tempFolder
, currentFreeDiskspace
))
1751 if(currentFreeDiskspace
< (oneGigabyte
* minimumFreeDiskspaceMultiplier
))
1753 QStringList tempFolderParts
= tempFolder
.split("/", QString::SkipEmptyParts
, Qt::CaseInsensitive
);
1754 tempFolderParts
.takeLast();
1755 PLAY_SOUND_OPTIONAL("whammy", false);
1756 QString lowDiskspaceMsg
= QString("%1<br>%2<br><br>%3<br>%4<br>").arg
1758 NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier
))),
1759 NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")),
1760 NOBR(tr("Your TEMP folder is located at:")),
1761 QString("<nobr><tt>%1</tt></nobr>").arg(FSLINK(tempFolderParts
.join("\\")))
1763 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg
, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1766 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER
)), QStringList() << "/D" << tempFolderParts
.first());
1771 QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!")));
1777 switch(m_settings
->compressionEncoder())
1779 case SettingsModel::MP3Encoder
:
1780 case SettingsModel::VorbisEncoder
:
1781 case SettingsModel::AACEncoder
:
1782 case SettingsModel::AC3Encoder
:
1783 case SettingsModel::FLACEncoder
:
1784 case SettingsModel::OpusEncoder
:
1785 case SettingsModel::DCAEncoder
:
1786 case SettingsModel::MACEncoder
:
1787 case SettingsModel::PCMEncoder
:
1790 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1791 ui
->tabWidget
->setCurrentIndex(3);
1795 if(!m_settings
->outputToSourceDir())
1797 QFile
writeTest(QString("%1/~%2.txt").arg(m_settings
->outputDir(), MUtils::next_rand_str()));
1798 if(!(writeTest
.open(QIODevice::ReadWrite
) && (writeTest
.write(writeTestBuffer
) == strlen(writeTestBuffer
))))
1800 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!")));
1801 ui
->tabWidget
->setCurrentIndex(1);
1818 void MainWindow::aboutButtonClicked(void)
1821 WidgetHideHelper
hiderHelper(m_dropBox
.data());
1822 QScopedPointer
<AboutDialog
> aboutBox(new AboutDialog(m_settings
, this));
1829 void MainWindow::closeButtonClicked(void)
1835 // =========================================================
1837 // =========================================================
1842 void MainWindow::tabPageChanged(int idx
, const bool silent
)
1846 //Update "view" menu
1847 QList
<QAction
*> actions
= m_tabActionGroup
->actions();
1848 for(int i
= 0; i
< actions
.count(); i
++)
1851 int actionIndex
= actions
.at(i
)->data().toInt(&ok
);
1852 if(ok
&& actionIndex
== idx
)
1854 actions
.at(i
)->setChecked(true);
1861 PLAY_SOUND_OPTIONAL("tick", true);
1864 int initialWidth
= this->width();
1865 int maximumWidth
= QApplication::desktop()->availableGeometry().width();
1867 //Make sure all tab headers are fully visible
1868 if(this->isVisible())
1870 int delta
= ui
->tabWidget
->sizeHint().width() - ui
->tabWidget
->width();
1873 this->resize(qMin(this->width() + delta
, maximumWidth
), this->height());
1877 //Tab specific operations
1878 if(idx
== ui
->tabWidget
->indexOf(ui
->tabOptions
) && ui
->scrollArea
->widget() && this->isVisible())
1880 ui
->scrollArea
->widget()->updateGeometry();
1881 ui
->scrollArea
->viewport()->updateGeometry();
1882 qApp
->processEvents();
1883 int delta
= ui
->scrollArea
->widget()->width() - ui
->scrollArea
->viewport()->width();
1886 this->resize(qMin(this->width() + delta
, maximumWidth
), this->height());
1889 else if(idx
== ui
->tabWidget
->indexOf(ui
->tabSourceFiles
))
1891 m_dropNoteLabel
->setGeometry(0, 0, ui
->sourceFileView
->width(), ui
->sourceFileView
->height());
1893 else if(idx
== ui
->tabWidget
->indexOf(ui
->tabOutputDir
))
1895 if(!m_fileSystemModel
)
1897 QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
1901 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
1905 //Center window around previous position
1906 if(initialWidth
< this->width())
1908 QPoint prevPos
= this->pos();
1909 int delta
= (this->width() - initialWidth
) >> 2;
1910 move(prevPos
.x() - delta
, prevPos
.y());
1915 * Tab action triggered
1917 void MainWindow::tabActionActivated(QAction
*action
)
1919 if(action
&& action
->data().isValid())
1922 int index
= action
->data().toInt(&ok
);
1925 ui
->tabWidget
->setCurrentIndex(index
);
1930 // =========================================================
1932 // =========================================================
1935 * Handle corner widget Event
1937 void MainWindow::cornerWidgetEventOccurred(QWidget
*sender
, QEvent
*event
)
1939 if(event
->type() == QEvent::MouseButtonPress
)
1941 QTimer::singleShot(0, this, SLOT(checkUpdatesActionActivated()));
1945 // =========================================================
1947 // =========================================================
1950 * Style action triggered
1952 void MainWindow::styleActionActivated(QAction
*action
)
1954 //Change style setting
1955 if(action
&& action
->data().isValid())
1958 int actionIndex
= action
->data().toInt(&ok
);
1961 m_settings
->interfaceStyle(actionIndex
);
1965 //Set up the new style
1966 switch(m_settings
->interfaceStyle())
1969 if(ui
->actionStyleCleanlooks
->isEnabled())
1971 ui
->actionStyleCleanlooks
->setChecked(true);
1972 QApplication::setStyle(new QCleanlooksStyle());
1976 if(ui
->actionStyleWindowsVista
->isEnabled())
1978 ui
->actionStyleWindowsVista
->setChecked(true);
1979 QApplication::setStyle(new QWindowsVistaStyle());
1983 if(ui
->actionStyleWindowsXP
->isEnabled())
1985 ui
->actionStyleWindowsXP
->setChecked(true);
1986 QApplication::setStyle(new QWindowsXPStyle());
1990 if(ui
->actionStyleWindowsClassic
->isEnabled())
1992 ui
->actionStyleWindowsClassic
->setChecked(true);
1993 QApplication::setStyle(new QWindowsStyle());
1997 ui
->actionStylePlastique
->setChecked(true);
1998 QApplication::setStyle(new QPlastiqueStyle());
2002 //Force re-translate after style change
2003 if(QEvent
*e
= new QEvent(QEvent::LanguageChange
))
2010 const type_info
&styleType
= typeid(*qApp
->style());
2011 const bool bTransparent
= ((typeid(QWindowsVistaStyle
) == styleType
) || (typeid(QWindowsXPStyle
) == styleType
));
2012 MAKE_TRANSPARENT(ui
->scrollArea
, bTransparent
);
2014 //Also force a re-size event
2015 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2020 * Language action triggered
2022 void MainWindow::languageActionActivated(QAction
*action
)
2024 if(action
->data().type() == QVariant::String
)
2026 QString langId
= action
->data().toString();
2028 if(MUtils::Translation::install_translator(langId
))
2030 action
->setChecked(true);
2031 ui
->actionLoadTranslationFromFile
->setChecked(false);
2032 m_settings
->currentLanguage(langId
);
2033 m_settings
->currentLanguageFile(QString());
2039 * Load language from file action triggered
2041 void MainWindow::languageFromFileActionActivated(bool checked
)
2043 QFileDialog
dialog(this, tr("Load Translation"));
2044 dialog
.setFileMode(QFileDialog::ExistingFile
);
2045 dialog
.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
2049 QStringList selectedFiles
= dialog
.selectedFiles();
2050 const QString qmFile
= QFileInfo(selectedFiles
.first()).canonicalFilePath();
2051 if(MUtils::Translation::install_translator_from_file(qmFile
))
2053 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
2054 while(!actions
.isEmpty())
2056 actions
.takeFirst()->setChecked(false);
2058 ui
->actionLoadTranslationFromFile
->setChecked(true);
2059 m_settings
->currentLanguageFile(qmFile
);
2063 languageActionActivated(m_languageActionGroup
->actions().first());
2068 // =========================================================
2070 // =========================================================
2073 * Disable update reminder action
2075 void MainWindow::disableUpdateReminderActionTriggered(bool checked
)
2079 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))
2081 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!"))));
2082 m_settings
->autoUpdateEnabled(false);
2086 m_settings
->autoUpdateEnabled(true);
2091 QMessageBox::information(this, tr("Update Reminder"), NOBR(tr("The update reminder has been re-enabled.")));
2092 m_settings
->autoUpdateEnabled(true);
2095 ui
->actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
2099 * Disable sound effects action
2101 void MainWindow::disableSoundsActionTriggered(bool checked
)
2105 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))
2107 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("All sound effects have been disabled.")));
2108 m_settings
->soundsEnabled(false);
2112 m_settings
->soundsEnabled(true);
2117 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("The sound effects have been re-enabled.")));
2118 m_settings
->soundsEnabled(true);
2121 ui
->actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
2125 * Disable Nero AAC encoder action
2127 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked
)
2131 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))
2133 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("All Nero AAC Encoder notifications have been disabled.")));
2134 m_settings
->neroAacNotificationsEnabled(false);
2138 m_settings
->neroAacNotificationsEnabled(true);
2143 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("The Nero AAC Encoder notifications have been re-enabled.")));
2144 m_settings
->neroAacNotificationsEnabled(true);
2147 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
2151 * Disable slow startup action
2153 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked
)
2157 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))
2159 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been disabled.")));
2160 m_settings
->antivirNotificationsEnabled(false);
2164 m_settings
->antivirNotificationsEnabled(true);
2169 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been re-enabled.")));
2170 m_settings
->antivirNotificationsEnabled(true);
2173 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
2177 * Import a Cue Sheet file
2179 void MainWindow::importCueSheetActionTriggered(bool checked
)
2182 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2187 QString selectedCueFile
;
2189 if(MUtils::GUI::themes_enabled())
2191 selectedCueFile
= QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings
->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
2195 QFileDialog
dialog(this, tr("Open Cue Sheet"));
2196 dialog
.setFileMode(QFileDialog::ExistingFile
);
2197 dialog
.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
2198 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2201 selectedCueFile
= dialog
.selectedFiles().first();
2205 if(!selectedCueFile
.isEmpty())
2207 m_settings
->mostRecentInputPath(QFileInfo(selectedCueFile
).canonicalPath());
2208 FileListBlockHelper
fileListBlocker(m_fileListModel
);
2209 QScopedPointer
<CueImportDialog
> cueImporter(new CueImportDialog(this, m_fileListModel
, selectedCueFile
, m_settings
));
2210 result
= cueImporter
->exec();
2215 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2216 ui
->sourceFileView
->update();
2217 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2218 ui
->sourceFileView
->scrollToBottom();
2219 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2226 * Show the "drop box" widget
2228 void MainWindow::showDropBoxWidgetActionTriggered(bool checked
)
2230 m_settings
->dropBoxWidgetEnabled(true);
2232 if(!m_dropBox
->isVisible())
2235 QTimer::singleShot(2500, m_dropBox
.data(), SLOT(showToolTip()));
2238 MUtils::GUI::blink_window(m_dropBox
.data());
2242 * Check for beta (pre-release) updates
2244 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked
)
2246 bool checkUpdatesNow
= false;
2250 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))
2252 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")))
2254 checkUpdatesNow
= true;
2256 m_settings
->autoUpdateCheckBeta(true);
2260 m_settings
->autoUpdateCheckBeta(false);
2265 QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on.")));
2266 m_settings
->autoUpdateCheckBeta(false);
2269 ui
->actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta());
2273 if(checkForUpdates())
2275 QApplication::quit();
2281 * Hibernate computer action
2283 void MainWindow::hibernateComputerActionTriggered(bool checked
)
2287 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))
2289 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will hibernate the computer on shutdown from now on.")));
2290 m_settings
->hibernateComputer(true);
2294 m_settings
->hibernateComputer(false);
2299 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will <i>not</i> hibernate the computer on shutdown from now on.")));
2300 m_settings
->hibernateComputer(false);
2303 ui
->actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
2307 * Disable shell integration action
2309 void MainWindow::disableShellIntegrationActionTriggered(bool checked
)
2313 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))
2315 ShellIntegration::remove();
2316 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been disabled.")));
2317 m_settings
->shellIntegrationEnabled(false);
2321 m_settings
->shellIntegrationEnabled(true);
2326 ShellIntegration::install();
2327 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been re-enabled.")));
2328 m_settings
->shellIntegrationEnabled(true);
2331 ui
->actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
2333 if(lamexp_version_portable() && ui
->actionDisableShellIntegration
->isChecked())
2335 ui
->actionDisableShellIntegration
->setEnabled(false);
2339 // =========================================================
2341 // =========================================================
2344 * Visit homepage action
2346 void MainWindow::visitHomepageActionActivated(void)
2348 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2350 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
2352 QDesktopServices::openUrl(QUrl(action
->data().toString()));
2360 void MainWindow::documentActionActivated(void)
2362 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2364 openDocumentLink(action
);
2369 * Check for updates action
2371 void MainWindow::checkUpdatesActionActivated(void)
2374 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2376 if(checkForUpdates())
2378 QApplication::quit();
2382 // =========================================================
2383 // Source file slots
2384 // =========================================================
2387 * Add file(s) button
2389 void MainWindow::addFilesButtonClicked(void)
2392 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2394 if(MUtils::GUI::themes_enabled() && (!MUTILS_DEBUG
))
2396 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2397 QStringList selectedFiles
= QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings
->mostRecentInputPath(), fileTypeFilters
.join(";;"));
2398 if(!selectedFiles
.isEmpty())
2400 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2401 addFiles(selectedFiles
);
2406 QFileDialog
dialog(this, tr("Add file(s)"));
2407 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2408 dialog
.setFileMode(QFileDialog::ExistingFiles
);
2409 dialog
.setNameFilter(fileTypeFilters
.join(";;"));
2410 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2413 QStringList selectedFiles
= dialog
.selectedFiles();
2414 if(!selectedFiles
.isEmpty())
2416 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2417 addFiles(selectedFiles
);
2424 * Open folder action
2426 void MainWindow::openFolderActionActivated(void)
2429 QString selectedFolder
;
2431 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2433 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2434 if(MUtils::GUI::themes_enabled())
2436 selectedFolder
= QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings
->mostRecentInputPath());
2440 QFileDialog
dialog(this, tr("Add Folder"));
2441 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
2442 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2445 selectedFolder
= dialog
.selectedFiles().first();
2449 if(selectedFolder
.isEmpty())
2454 QStringList filterItems
= DecoderRegistry::getSupportedExts();
2455 filterItems
.prepend("*.*");
2458 QString filterStr
= QInputDialog::getItem(this, tr("Filter Files"), tr("Select filename filter:"), filterItems
, 0, false, &okay
).trimmed();
2464 QRegExp
regExp("\\*\\.([A-Za-z0-9]+)", Qt::CaseInsensitive
);
2465 if(regExp
.lastIndexIn(filterStr
) >= 0)
2467 filterStr
= regExp
.cap(1).trimmed();
2474 m_settings
->mostRecentInputPath(QDir(selectedFolder
).canonicalPath());
2475 addFolder(selectedFolder
, action
->data().toBool(), false, filterStr
);
2480 * Remove file button
2482 void MainWindow::removeFileButtonClicked(void)
2484 const QItemSelectionModel
*const selection
= ui
->sourceFileView
->selectionModel();
2485 if(selection
&& selection
->hasSelection())
2488 const QModelIndexList selectedRows
= INVERT_LIST(selection
->selectedRows());
2489 if(!selectedRows
.isEmpty())
2491 FileListBlockHelper
fileListBlocker(m_fileListModel
);
2492 firstRow
= selectedRows
.last().row();
2493 for(QModelIndexList::ConstIterator iter
= selectedRows
.constBegin(); iter
!= selectedRows
.constEnd(); iter
++)
2495 if(!m_fileListModel
->removeFile(*iter
))
2501 if(m_fileListModel
->rowCount() > 0)
2503 const QModelIndex position
= m_fileListModel
->index(((firstRow
>= 0) && (firstRow
< m_fileListModel
->rowCount())) ? firstRow
: (m_fileListModel
->rowCount() - 1), 0);
2504 ui
->sourceFileView
->selectRow(position
.row());
2505 ui
->sourceFileView
->scrollTo(position
, QAbstractItemView::PositionAtCenter
);
2510 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
2515 * Clear files button
2517 void MainWindow::clearFilesButtonClicked(void)
2519 if(m_fileListModel
->rowCount() > 0)
2521 m_fileListModel
->clearFiles();
2525 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
2530 * Move file up button
2532 void MainWindow::fileUpButtonClicked(void)
2534 moveSelectedFiles(true);
2538 * Move file down button
2540 void MainWindow::fileDownButtonClicked(void)
2542 moveSelectedFiles(false);
2546 * Show details button
2548 void MainWindow::showDetailsButtonClicked(void)
2553 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2557 ui
->sourceFileView
->selectRow(index
.row());
2558 QScopedPointer
<MetaInfoDialog
> metaInfoDialog(new MetaInfoDialog(this));
2561 AudioFileModel
&file
= (*m_fileListModel
)[index
];
2562 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2563 iResult
= metaInfoDialog
->exec(file
, index
.row() > 0, index
.row() < m_fileListModel
->rowCount() - 1);
2565 //Copy all info to Meta Info tab
2566 if(iResult
== INT_MAX
)
2568 m_metaInfoModel
->assignInfoFrom(file
);
2569 ui
->tabWidget
->setCurrentIndex(ui
->tabWidget
->indexOf(ui
->tabMetaData
));
2575 index
= m_fileListModel
->index(index
.row() + 1, index
.column());
2576 ui
->sourceFileView
->selectRow(index
.row());
2579 else if(iResult
< 0)
2581 index
= m_fileListModel
->index(index
.row() - 1, index
.column());
2582 ui
->sourceFileView
->selectRow(index
.row());
2586 break; /*close dilalog now*/
2591 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
2594 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2595 sourceFilesScrollbarMoved(0);
2599 * Show context menu for source files
2601 void MainWindow::sourceFilesContextMenu(const QPoint
&pos
)
2603 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
2604 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
2608 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
2610 m_sourceFilesContextMenu
->popup(sender
->mapToGlobal(pos
));
2616 * Scrollbar of source files moved
2618 void MainWindow::sourceFilesScrollbarMoved(int)
2620 ui
->sourceFileView
->resizeColumnToContents(0);
2624 * Open selected file in external player
2626 void MainWindow::previewContextActionTriggered(void)
2628 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2629 if(!index
.isValid())
2634 if(!MUtils::OS::open_media_file(m_fileListModel
->getFile(index
).filePath()))
2636 qDebug("Player not found, falling back to default application...");
2637 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel
->getFile(index
).filePath()));
2642 * Find selected file in explorer
2644 void MainWindow::findFileContextActionTriggered(void)
2646 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2649 QString systemRootPath
;
2651 QDir
systemRoot(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER
));
2652 if(systemRoot
.exists() && systemRoot
.cdUp())
2654 systemRootPath
= systemRoot
.canonicalPath();
2657 if(!systemRootPath
.isEmpty())
2659 QFileInfo
explorer(QString("%1/explorer.exe").arg(systemRootPath
));
2660 if(explorer
.exists() && explorer
.isFile())
2662 QProcess::execute(explorer
.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
2668 qWarning("SystemRoot directory could not be detected!");
2674 * Add all dropped files
2676 void MainWindow::handleDroppedFiles(void)
2680 static const int MIN_COUNT
= 16;
2681 const QString bannerText
= tr("Loading dropped files or folders, please wait...");
2682 bool bUseBanner
= false;
2684 showBanner(bannerText
, bUseBanner
, (m_droppedFileList
->count() >= MIN_COUNT
));
2686 QStringList droppedFiles
;
2687 while(!m_droppedFileList
->isEmpty())
2689 QFileInfo
file(m_droppedFileList
->takeFirst().toLocalFile());
2690 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2696 qDebug("Dropped File: %s", MUTILS_UTF8(file
.canonicalFilePath()));
2697 droppedFiles
<< file
.canonicalFilePath();
2700 else if(file
.isDir())
2702 qDebug("Dropped Folder: %s", MUTILS_UTF8(file
.canonicalFilePath()));
2703 QFileInfoList list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Files
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
);
2704 if(list
.count() > 0)
2706 showBanner(bannerText
, bUseBanner
, (list
.count() >= MIN_COUNT
));
2707 for(QFileInfoList::ConstIterator iter
= list
.constBegin(); iter
!= list
.constEnd(); iter
++)
2709 droppedFiles
<< (*iter
).canonicalFilePath();
2721 if(!droppedFiles
.isEmpty())
2723 addFiles(droppedFiles
);
2728 * Add all pending files
2730 void MainWindow::handleDelayedFiles(void)
2732 m_delayedFileTimer
->stop();
2734 if(m_delayedFileList
->isEmpty())
2741 m_delayedFileTimer
->start(5000);
2745 if(ui
->tabWidget
->currentIndex() != 0)
2747 SignalBlockHelper
signalBlockHelper(ui
->tabWidget
);
2748 ui
->tabWidget
->setCurrentIndex(0);
2749 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
2752 QStringList selectedFiles
;
2753 while(!m_delayedFileList
->isEmpty())
2755 QFileInfo currentFile
= QFileInfo(m_delayedFileList
->takeFirst());
2756 if(!currentFile
.exists() || !currentFile
.isFile())
2760 selectedFiles
<< currentFile
.canonicalFilePath();
2763 addFiles(selectedFiles
);
2767 * Export Meta tags to CSV file
2769 void MainWindow::exportCsvContextActionTriggered(void)
2772 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2774 QString selectedCsvFile
;
2775 if(MUtils::GUI::themes_enabled())
2777 selectedCsvFile
= QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2781 QFileDialog
dialog(this, tr("Save CSV file"));
2782 dialog
.setFileMode(QFileDialog::AnyFile
);
2783 dialog
.setAcceptMode(QFileDialog::AcceptSave
);
2784 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2785 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2788 selectedCsvFile
= dialog
.selectedFiles().first();
2792 if(!selectedCsvFile
.isEmpty())
2794 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2795 switch(m_fileListModel
->exportToCsv(selectedCsvFile
))
2797 case FileListModel::CsvError_NoTags
:
2798 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, there are no meta tags that can be exported!")));
2800 case FileListModel::CsvError_FileOpen
:
2801 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to open CSV file for writing!")));
2803 case FileListModel::CsvError_FileWrite
:
2804 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to write to the CSV file!")));
2806 case FileListModel::CsvError_OK
:
2807 QMessageBox::information(this, tr("CSV Export"), NOBR(tr("The CSV files was created successfully!")));
2810 qWarning("exportToCsv: Unknown return code!");
2817 * Import Meta tags from CSV file
2819 void MainWindow::importCsvContextActionTriggered(void)
2822 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2824 QString selectedCsvFile
;
2825 if(MUtils::GUI::themes_enabled())
2827 selectedCsvFile
= QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2831 QFileDialog
dialog(this, tr("Open CSV file"));
2832 dialog
.setFileMode(QFileDialog::ExistingFile
);
2833 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2834 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2837 selectedCsvFile
= dialog
.selectedFiles().first();
2841 if(!selectedCsvFile
.isEmpty())
2843 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2844 switch(m_fileListModel
->importFromCsv(this, selectedCsvFile
))
2846 case FileListModel::CsvError_FileOpen
:
2847 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to open CSV file for reading!")));
2849 case FileListModel::CsvError_FileRead
:
2850 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to read from the CSV file!")));
2852 case FileListModel::CsvError_NoTags
:
2853 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, the CSV file does not contain any known fields!")));
2855 case FileListModel::CsvError_Incomplete
:
2856 QMessageBox::warning(this, tr("CSV Import"), NOBR(tr("CSV file is incomplete. Not all files were updated!")));
2858 case FileListModel::CsvError_OK
:
2859 QMessageBox::information(this, tr("CSV Import"), NOBR(tr("The CSV files was imported successfully!")));
2861 case FileListModel::CsvError_Aborted
:
2862 /* User aborted, ignore! */
2865 qWarning("exportToCsv: Unknown return code!");
2871 * Show or hide Drag'n'Drop notice after model reset
2873 void MainWindow::sourceModelChanged(void)
2875 m_dropNoteLabel
->setVisible(m_fileListModel
->rowCount() <= 0);
2878 // =========================================================
2879 // Output folder slots
2880 // =========================================================
2883 * Output folder changed (mouse clicked)
2885 void MainWindow::outputFolderViewClicked(const QModelIndex
&index
)
2887 if(index
.isValid() && (ui
->outputFolderView
->currentIndex() != index
))
2889 ui
->outputFolderView
->setCurrentIndex(index
);
2892 if(m_fileSystemModel
&& index
.isValid())
2894 QString selectedDir
= m_fileSystemModel
->filePath(index
);
2895 if(selectedDir
.length() < 3) selectedDir
.append(QDir::separator());
2896 ui
->outputFolderLabel
->setText(QDir::toNativeSeparators(selectedDir
));
2897 ui
->outputFolderLabel
->setToolTip(ui
->outputFolderLabel
->text());
2898 m_settings
->outputDir(selectedDir
);
2902 ui
->outputFolderLabel
->setText(QDir::toNativeSeparators(m_settings
->outputDir()));
2903 ui
->outputFolderLabel
->setToolTip(ui
->outputFolderLabel
->text());
2908 * Output folder changed (mouse moved)
2910 void MainWindow::outputFolderViewMoved(const QModelIndex
&index
)
2912 if(QApplication::mouseButtons() & Qt::LeftButton
)
2914 outputFolderViewClicked(index
);
2919 * Goto desktop button
2921 void MainWindow::gotoDesktopButtonClicked(void)
2923 if(!m_fileSystemModel
)
2925 qWarning("File system model not initialized yet!");
2929 QString desktopPath
= QDesktopServices::storageLocation(QDesktopServices::DesktopLocation
);
2931 if(!desktopPath
.isEmpty() && QDir(desktopPath
).exists())
2933 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(desktopPath
));
2934 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2935 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
2939 ui
->buttonGotoDesktop
->setEnabled(false);
2944 * Goto home folder button
2946 void MainWindow::gotoHomeFolderButtonClicked(void)
2948 if(!m_fileSystemModel
)
2950 qWarning("File system model not initialized yet!");
2954 QString homePath
= QDesktopServices::storageLocation(QDesktopServices::HomeLocation
);
2956 if(!homePath
.isEmpty() && QDir(homePath
).exists())
2958 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(homePath
));
2959 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2960 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
2964 ui
->buttonGotoHome
->setEnabled(false);
2969 * Goto music folder button
2971 void MainWindow::gotoMusicFolderButtonClicked(void)
2973 if(!m_fileSystemModel
)
2975 qWarning("File system model not initialized yet!");
2979 QString musicPath
= QDesktopServices::storageLocation(QDesktopServices::MusicLocation
);
2981 if(!musicPath
.isEmpty() && QDir(musicPath
).exists())
2983 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(musicPath
));
2984 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2985 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
2989 ui
->buttonGotoMusic
->setEnabled(false);
2994 * Goto music favorite output folder
2996 void MainWindow::gotoFavoriteFolder(void)
2998 if(!m_fileSystemModel
)
3000 qWarning("File system model not initialized yet!");
3004 QAction
*item
= dynamic_cast<QAction
*>(QObject::sender());
3008 QDir
path(item
->data().toString());
3011 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(path
.canonicalPath()));
3012 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3013 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
3017 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
3018 m_outputFolderFavoritesMenu
->removeAction(item
);
3019 item
->deleteLater();
3025 * Make folder button
3027 void MainWindow::makeFolderButtonClicked(void)
3031 if(m_fileSystemModel
.isNull())
3033 qWarning("File system model not initialized yet!");
3037 QDir
basePath(m_fileSystemModel
->fileInfo(ui
->outputFolderView
->currentIndex()).absoluteFilePath());
3038 QString suggestedName
= tr("New Folder");
3040 if(!m_metaData
->artist().isEmpty() && !m_metaData
->album().isEmpty())
3042 suggestedName
= QString("%1 - %2").arg(m_metaData
->artist(),m_metaData
->album());
3044 else if(!m_metaData
->artist().isEmpty())
3046 suggestedName
= m_metaData
->artist();
3048 else if(!m_metaData
->album().isEmpty())
3050 suggestedName
= m_metaData
->album();
3054 for(int i
= 0; i
< m_fileListModel
->rowCount(); i
++)
3056 const AudioFileModel
&audioFile
= m_fileListModel
->getFile(m_fileListModel
->index(i
, 0));
3057 const AudioFileModel_MetaInfo
&fileMetaInfo
= audioFile
.metaInfo();
3059 if(!fileMetaInfo
.album().isEmpty() || !fileMetaInfo
.artist().isEmpty())
3061 if(!fileMetaInfo
.artist().isEmpty() && !fileMetaInfo
.album().isEmpty())
3063 suggestedName
= QString("%1 - %2").arg(fileMetaInfo
.artist(), fileMetaInfo
.album());
3065 else if(!fileMetaInfo
.artist().isEmpty())
3067 suggestedName
= fileMetaInfo
.artist();
3069 else if(!fileMetaInfo
.album().isEmpty())
3071 suggestedName
= fileMetaInfo
.album();
3078 suggestedName
= MUtils::clean_file_name(suggestedName
, true);
3082 bool bApplied
= false;
3083 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();
3087 folderName
= MUtils::clean_file_path(folderName
.simplified(), true);
3089 if(folderName
.isEmpty())
3091 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
3096 QString newFolder
= folderName
;
3098 while(basePath
.exists(newFolder
))
3100 newFolder
= QString(folderName
).append(QString().sprintf(" (%d)", ++i
));
3103 if(basePath
.mkpath(newFolder
))
3105 QDir createdDir
= basePath
;
3106 if(createdDir
.cd(newFolder
))
3108 QModelIndex newIndex
= m_fileSystemModel
->index(createdDir
.canonicalPath());
3109 ui
->outputFolderView
->setCurrentIndex(newIndex
);
3110 outputFolderViewClicked(newIndex
);
3111 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
3116 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!")));
3124 * Output to source dir changed
3126 void MainWindow::saveToSourceFolderChanged(void)
3128 m_settings
->outputToSourceDir(ui
->saveToSourceFolderCheckBox
->isChecked());
3132 * Prepend relative source file path to output file name changed
3134 void MainWindow::prependRelativePathChanged(void)
3136 m_settings
->prependRelativeSourcePath(ui
->prependRelativePathCheckBox
->isChecked());
3140 * Show context menu for output folder
3142 void MainWindow::outputFolderContextMenu(const QPoint
&pos
)
3144 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
3145 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
3147 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
3149 m_outputFolderContextMenu
->popup(sender
->mapToGlobal(pos
));
3154 * Show selected folder in explorer
3156 void MainWindow::showFolderContextActionTriggered(void)
3158 if(!m_fileSystemModel
)
3160 qWarning("File system model not initialized yet!");
3164 QString path
= QDir::toNativeSeparators(m_fileSystemModel
->filePath(ui
->outputFolderView
->currentIndex()));
3165 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
3166 MUtils::OS::shell_open(this, path
, true);
3170 * Refresh the directory outline
3172 void MainWindow::refreshFolderContextActionTriggered(void)
3174 //force re-initialization
3175 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
3179 * Go one directory up
3181 void MainWindow::goUpFolderContextActionTriggered(void)
3183 QModelIndex current
= ui
->outputFolderView
->currentIndex();
3184 if(current
.isValid())
3186 QModelIndex parent
= current
.parent();
3187 if(parent
.isValid())
3190 ui
->outputFolderView
->setCurrentIndex(parent
);
3191 outputFolderViewClicked(parent
);
3195 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
3197 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
3202 * Add current folder to favorites
3204 void MainWindow::addFavoriteFolderActionTriggered(void)
3206 QString path
= m_fileSystemModel
->filePath(ui
->outputFolderView
->currentIndex());
3207 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
3209 if(!favorites
.contains(path
, Qt::CaseInsensitive
))
3211 favorites
.append(path
);
3212 while(favorites
.count() > 6) favorites
.removeFirst();
3216 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
3219 m_settings
->favoriteOutputFolders(favorites
.join("|"));
3224 * Output folder edit finished
3226 void MainWindow::outputFolderEditFinished(void)
3228 if(ui
->outputFolderEdit
->isHidden())
3230 return; //Not currently in edit mode!
3235 QString text
= QDir::fromNativeSeparators(ui
->outputFolderEdit
->text().trimmed());
3236 while(text
.startsWith('"') || text
.startsWith('/')) text
= text
.right(text
.length() - 1).trimmed();
3237 while(text
.endsWith('"') || text
.endsWith('/')) text
= text
.left(text
.length() - 1).trimmed();
3239 static const char *str
= "?*<>|\"";
3240 for(size_t i
= 0; str
[i
]; i
++) text
.replace(str
[i
], "_");
3242 if(!((text
.length() >= 2) && text
.at(0).isLetter() && text
.at(1) == QChar(':')))
3244 text
= QString("%1/%2").arg(QDir::fromNativeSeparators(ui
->outputFolderLabel
->text()), text
);
3247 if(text
.length() == 2) text
+= "/"; /* "X:" => "X:/" */
3249 while(text
.length() > 2)
3251 QFileInfo
info(text
);
3252 if(info
.exists() && info
.isDir())
3254 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalFilePath()).absoluteFilePath());
3258 ui
->outputFolderView
->setCurrentIndex(index
);
3259 outputFolderViewClicked(index
);
3263 else if(info
.exists() && info
.isFile())
3265 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalPath()).absoluteFilePath());
3269 ui
->outputFolderView
->setCurrentIndex(index
);
3270 outputFolderViewClicked(index
);
3275 text
= text
.left(text
.length() - 1).trimmed();
3278 ui
->outputFolderEdit
->setVisible(false);
3279 ui
->outputFolderLabel
->setVisible(true);
3280 ui
->outputFolderView
->setEnabled(true);
3282 if(!ok
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
3283 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
3287 * Initialize file system model
3289 void MainWindow::initOutputFolderModel(void)
3291 if(m_outputFolderNoteBox
->isHidden())
3293 m_outputFolderNoteBox
->show();
3294 m_outputFolderNoteBox
->repaint();
3295 m_outputFolderViewInitCounter
= 4;
3297 if(m_fileSystemModel
)
3299 SET_MODEL(ui
->outputFolderView
, NULL
);
3300 ui
->outputFolderView
->repaint();
3303 m_fileSystemModel
.reset(new QFileSystemModelEx());
3304 if(!m_fileSystemModel
.isNull())
3306 m_fileSystemModel
->installEventFilter(this);
3307 connect(m_fileSystemModel
.data(), SIGNAL(directoryLoaded(QString
)), this, SLOT(outputFolderDirectoryLoaded(QString
)));
3308 connect(m_fileSystemModel
.data(), SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(outputFolderRowsInserted(QModelIndex
,int,int)));
3310 SET_MODEL(ui
->outputFolderView
, m_fileSystemModel
.data());
3311 ui
->outputFolderView
->header()->setStretchLastSection(true);
3312 ui
->outputFolderView
->header()->hideSection(1);
3313 ui
->outputFolderView
->header()->hideSection(2);
3314 ui
->outputFolderView
->header()->hideSection(3);
3316 m_fileSystemModel
->setRootPath("");
3317 QModelIndex index
= m_fileSystemModel
->index(m_settings
->outputDir());
3318 if(index
.isValid()) ui
->outputFolderView
->setCurrentIndex(index
);
3319 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3322 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
3323 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3328 * Initialize file system model (do NOT call this one directly!)
3330 void MainWindow::initOutputFolderModel_doAsync(void)
3332 if(m_outputFolderViewInitCounter
> 0)
3334 m_outputFolderViewInitCounter
--;
3335 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3339 QTimer::singleShot(125, m_outputFolderNoteBox
.data(), SLOT(hide()));
3340 ui
->outputFolderView
->setFocus();
3345 * Center current folder in view
3347 void MainWindow::centerOutputFolderModel(void)
3349 if(ui
->outputFolderView
->isVisible())
3351 centerOutputFolderModel_doAsync();
3352 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel_doAsync()));
3357 * Center current folder in view (do NOT call this one directly!)
3359 void MainWindow::centerOutputFolderModel_doAsync(void)
3361 if(ui
->outputFolderView
->isVisible())
3363 m_outputFolderViewCentering
= true;
3364 const QModelIndex index
= ui
->outputFolderView
->currentIndex();
3365 ui
->outputFolderView
->scrollTo(index
, QAbstractItemView::PositionAtCenter
);
3366 ui
->outputFolderView
->setFocus();
3371 * File system model asynchronously loaded a dir
3373 void MainWindow::outputFolderDirectoryLoaded(const QString
&path
)
3375 if(m_outputFolderViewCentering
)
3377 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
3382 * File system model inserted new items
3384 void MainWindow::outputFolderRowsInserted(const QModelIndex
&parent
, int start
, int end
)
3386 if(m_outputFolderViewCentering
)
3388 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED();
3393 * Directory view item was expanded by user
3395 void MainWindow::outputFolderItemExpanded(const QModelIndex
&item
)
3397 //We need to stop centering as soon as the user has expanded an item manually!
3398 m_outputFolderViewCentering
= false;
3402 * View event for output folder control occurred
3404 void MainWindow::outputFolderViewEventOccurred(QWidget
*sender
, QEvent
*event
)
3406 switch(event
->type())
3410 case QEvent::KeyPress
:
3411 case QEvent::KeyRelease
:
3412 case QEvent::FocusIn
:
3413 case QEvent::FocusOut
:
3414 case QEvent::TouchEnd
:
3415 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3421 * Mouse event for output folder control occurred
3423 void MainWindow::outputFolderMouseEventOccurred(QWidget
*sender
, QEvent
*event
)
3425 QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
);
3426 QPoint pos
= (mouseEvent
) ? mouseEvent
->pos() : QPoint();
3428 if(sender
== ui
->outputFolderLabel
)
3430 switch(event
->type())
3432 case QEvent::MouseButtonPress
:
3433 if(mouseEvent
&& (mouseEvent
->button() == Qt::LeftButton
))
3435 QString path
= ui
->outputFolderLabel
->text();
3436 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
3437 MUtils::OS::shell_open(this, path
, true);
3441 ui
->outputFolderLabel
->setForegroundRole(QPalette::Link
);
3444 ui
->outputFolderLabel
->setForegroundRole(QPalette::WindowText
);
3449 if((sender
== ui
->outputFoldersFovoritesLabel
) || (sender
== ui
->outputFoldersEditorLabel
) || (sender
== ui
->outputFoldersGoUpLabel
))
3451 const type_info
&styleType
= typeid(*qApp
->style());
3452 if((typeid(QPlastiqueStyle
) == styleType
) || (typeid(QWindowsStyle
) == styleType
))
3454 switch(event
->type())
3457 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Raised
: QFrame::Plain
);
3459 case QEvent::MouseButtonPress
:
3460 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Sunken
: QFrame::Plain
);
3462 case QEvent::MouseButtonRelease
:
3463 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Raised
: QFrame::Plain
);
3466 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Plain
: QFrame::Plain
);
3472 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(QFrame::Plain
);
3475 if((event
->type() == QEvent::MouseButtonRelease
) && ui
->outputFolderView
->isEnabled() && (mouseEvent
))
3477 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
)
3479 if(sender
== ui
->outputFoldersFovoritesLabel
)
3481 m_outputFolderFavoritesMenu
->popup(sender
->mapToGlobal(pos
));
3483 else if(sender
== ui
->outputFoldersEditorLabel
)
3485 ui
->outputFolderView
->setEnabled(false);
3486 ui
->outputFolderLabel
->setVisible(false);
3487 ui
->outputFolderEdit
->setVisible(true);
3488 ui
->outputFolderEdit
->setText(ui
->outputFolderLabel
->text());
3489 ui
->outputFolderEdit
->selectAll();
3490 ui
->outputFolderEdit
->setFocus();
3492 else if(sender
== ui
->outputFoldersGoUpLabel
)
3494 QTimer::singleShot(0, this, SLOT(goUpFolderContextActionTriggered()));
3498 MUTILS_THROW("Oups, this is not supposed to happen!");
3505 // =========================================================
3506 // Metadata tab slots
3507 // =========================================================
3510 * Edit meta button clicked
3512 void MainWindow::editMetaButtonClicked(void)
3516 const QModelIndex index
= ui
->metaDataView
->currentIndex();
3520 m_metaInfoModel
->editItem(index
, this);
3522 if(index
.row() == 4)
3524 m_settings
->metaInfoPosition(m_metaData
->position());
3530 * Reset meta button clicked
3532 void MainWindow::clearMetaButtonClicked(void)
3535 m_metaInfoModel
->clearData();
3539 * Meta tags enabled changed
3541 void MainWindow::metaTagsEnabledChanged(void)
3543 m_settings
->writeMetaTags(ui
->writeMetaDataCheckBox
->isChecked());
3547 * Playlist enabled changed
3549 void MainWindow::playlistEnabledChanged(void)
3551 m_settings
->createPlaylist(ui
->generatePlaylistCheckBox
->isChecked());
3554 // =========================================================
3555 // Compression tab slots
3556 // =========================================================
3561 void MainWindow::updateEncoder(int id
)
3563 /*qWarning("\nupdateEncoder(%d)", id);*/
3565 m_settings
->compressionEncoder(id
);
3566 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(id
);
3568 //Update UI controls
3569 ui
->radioButtonModeQuality
->setEnabled(info
->isModeSupported(SettingsModel::VBRMode
));
3570 ui
->radioButtonModeAverageBitrate
->setEnabled(info
->isModeSupported(SettingsModel::ABRMode
));
3571 ui
->radioButtonConstBitrate
->setEnabled(info
->isModeSupported(SettingsModel::CBRMode
));
3573 //Initialize checkbox state
3574 if(ui
->radioButtonModeQuality
->isEnabled()) ui
->radioButtonModeQuality
->setChecked(true);
3575 else if(ui
->radioButtonModeAverageBitrate
->isEnabled()) ui
->radioButtonModeAverageBitrate
->setChecked(true);
3576 else if(ui
->radioButtonConstBitrate
->isEnabled()) ui
->radioButtonConstBitrate
->setChecked(true);
3577 else MUTILS_THROW("It appears that the encoder does not support *any* RC mode!");
3579 //Apply current RC mode
3580 const int currentRCMode
= EncoderRegistry::loadEncoderMode(m_settings
, id
);
3581 switch(currentRCMode
)
3583 case SettingsModel::VBRMode
: if(ui
->radioButtonModeQuality
->isEnabled()) ui
->radioButtonModeQuality
->setChecked(true); break;
3584 case SettingsModel::ABRMode
: if(ui
->radioButtonModeAverageBitrate
->isEnabled()) ui
->radioButtonModeAverageBitrate
->setChecked(true); break;
3585 case SettingsModel::CBRMode
: if(ui
->radioButtonConstBitrate
->isEnabled()) ui
->radioButtonConstBitrate
->setChecked(true); break;
3586 default: MUTILS_THROW("updateEncoder(): Unknown rc-mode encountered!");
3589 //Display encoder description
3590 if(const char* description
= info
->description())
3592 ui
->labelEncoderInfo
->setVisible(true);
3593 ui
->labelEncoderInfo
->setText(tr("Current Encoder: %1").arg(QString::fromUtf8(description
)));
3597 ui
->labelEncoderInfo
->setVisible(false);
3601 updateRCMode(m_modeButtonGroup
->checkedId());
3605 * Update rate-control mode
3607 void MainWindow::updateRCMode(int id
)
3609 /*qWarning("updateRCMode(%d)", id);*/
3612 const int currentEncoder
= m_encoderButtonGroup
->checkedId();
3613 EncoderRegistry::saveEncoderMode(m_settings
, currentEncoder
, id
);
3615 //Fetch encoder info
3616 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(currentEncoder
);
3617 const int valueCount
= info
->valueCount(id
);
3620 if(!info
->isModeSupported(id
))
3622 qWarning("Attempting to use an unsupported RC mode (%d) with current encoder (%d)!", id
, currentEncoder
);
3623 ui
->labelBitrate
->setText("(ERROR)");
3627 //Update slider min/max values
3630 SignalBlockHelper
signalBlockHelper(ui
->sliderBitrate
);
3631 ui
->sliderBitrate
->setEnabled(true);
3632 ui
->sliderBitrate
->setMinimum(0);
3633 ui
->sliderBitrate
->setMaximum(valueCount
-1);
3637 SignalBlockHelper
signalBlockHelper(ui
->sliderBitrate
);
3638 ui
->sliderBitrate
->setEnabled(false);
3639 ui
->sliderBitrate
->setMinimum(0);
3640 ui
->sliderBitrate
->setMaximum(2);
3643 //Now update bitrate/quality value!
3646 const int currentValue
= EncoderRegistry::loadEncoderValue(m_settings
, currentEncoder
, id
);
3647 ui
->sliderBitrate
->setValue(qBound(0, currentValue
, valueCount
-1));
3648 updateBitrate(qBound(0, currentValue
, valueCount
-1));
3652 ui
->sliderBitrate
->setValue(1);
3660 void MainWindow::updateBitrate(int value
)
3662 /*qWarning("updateBitrate(%d)", value);*/
3664 //Load current encoder and RC mode
3665 const int currentEncoder
= m_encoderButtonGroup
->checkedId();
3666 const int currentRCMode
= m_modeButtonGroup
->checkedId();
3668 //Fetch encoder info
3669 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(currentEncoder
);
3670 const int valueCount
= info
->valueCount(currentRCMode
);
3673 if(!info
->isModeSupported(currentRCMode
))
3675 qWarning("Attempting to use an unsupported RC mode (%d) with current encoder (%d)!", currentRCMode
, currentEncoder
);
3676 ui
->labelBitrate
->setText("(ERROR)");
3680 //Store new bitrate value
3683 EncoderRegistry::saveEncoderValue(m_settings
, currentEncoder
, currentRCMode
, qBound(0, value
, valueCount
-1));
3686 //Update bitrate value
3687 const int displayValue
= (valueCount
> 0) ? info
->valueAt(currentRCMode
, qBound(0, value
, valueCount
-1)) : INT_MAX
;
3688 switch(info
->valueType(currentRCMode
))
3690 case AbstractEncoderInfo::TYPE_BITRATE
:
3691 ui
->labelBitrate
->setText(QString("%1 kbps").arg(QString::number(displayValue
)));
3693 case AbstractEncoderInfo::TYPE_APPROX_BITRATE
:
3694 ui
->labelBitrate
->setText(QString("≈ %1 kbps").arg(QString::number(displayValue
)));
3696 case AbstractEncoderInfo::TYPE_QUALITY_LEVEL_INT
:
3697 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(QString::number(displayValue
)));
3699 case AbstractEncoderInfo::TYPE_QUALITY_LEVEL_FLT
:
3700 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", double(displayValue
)/100.0)));
3702 case AbstractEncoderInfo::TYPE_COMPRESSION_LEVEL
:
3703 ui
->labelBitrate
->setText(tr("Compression %1").arg(QString::number(displayValue
)));
3705 case AbstractEncoderInfo::TYPE_UNCOMPRESSED
:
3706 ui
->labelBitrate
->setText(tr("Uncompressed"));
3709 MUTILS_THROW("Unknown display value type encountered!");
3715 * Event for compression tab occurred
3717 void MainWindow::compressionTabEventOccurred(QWidget
*sender
, QEvent
*event
)
3719 static const QUrl
helpUrl("http://lamexp.sourceforge.net/doc/FAQ.html#054010d9");
3721 if((sender
== ui
->labelCompressionHelp
) && (event
->type() == QEvent::MouseButtonPress
))
3723 QDesktopServices::openUrl(helpUrl
);
3725 else if((sender
== ui
->labelResetEncoders
) && (event
->type() == QEvent::MouseButtonPress
))
3727 PLAY_SOUND_OPTIONAL("blast", true);
3728 EncoderRegistry::resetAllEncoders(m_settings
);
3729 m_settings
->compressionEncoder(SettingsModel::MP3Encoder
);
3730 ui
->radioButtonEncoderMP3
->setChecked(true);
3731 QTimer::singleShot(0, this, SLOT(updateEncoder()));
3735 // =========================================================
3736 // Advanced option slots
3737 // =========================================================
3740 * Lame algorithm quality changed
3742 void MainWindow::updateLameAlgoQuality(int value
)
3749 text
= tr("Best Quality (Slow)");
3752 text
= tr("High Quality (Recommended)");
3755 text
= tr("Acceptable Quality (Fast)");
3758 text
= tr("Poor Quality (Very Fast)");
3764 m_settings
->lameAlgoQuality(value
);
3765 ui
->labelLameAlgoQuality
->setText(text
);
3768 bool warning
= (value
== 0), notice
= (value
== 3);
3769 ui
->labelLameAlgoQualityWarning
->setVisible(warning
);
3770 ui
->labelLameAlgoQualityWarningIcon
->setVisible(warning
);
3771 ui
->labelLameAlgoQualityNotice
->setVisible(notice
);
3772 ui
->labelLameAlgoQualityNoticeIcon
->setVisible(notice
);
3773 ui
->labelLameAlgoQualitySpacer
->setVisible(warning
|| notice
);
3777 * Bitrate management endabled/disabled
3779 void MainWindow::bitrateManagementEnabledChanged(bool checked
)
3781 m_settings
->bitrateManagementEnabled(checked
);
3785 * Minimum bitrate has changed
3787 void MainWindow::bitrateManagementMinChanged(int value
)
3789 if(value
> ui
->spinBoxBitrateManagementMax
->value())
3791 ui
->spinBoxBitrateManagementMin
->setValue(ui
->spinBoxBitrateManagementMax
->value());
3792 m_settings
->bitrateManagementMinRate(ui
->spinBoxBitrateManagementMax
->value());
3796 m_settings
->bitrateManagementMinRate(value
);
3801 * Maximum bitrate has changed
3803 void MainWindow::bitrateManagementMaxChanged(int value
)
3805 if(value
< ui
->spinBoxBitrateManagementMin
->value())
3807 ui
->spinBoxBitrateManagementMax
->setValue(ui
->spinBoxBitrateManagementMin
->value());
3808 m_settings
->bitrateManagementMaxRate(ui
->spinBoxBitrateManagementMin
->value());
3812 m_settings
->bitrateManagementMaxRate(value
);
3817 * Channel mode has changed
3819 void MainWindow::channelModeChanged(int value
)
3821 if(value
>= 0) m_settings
->lameChannelMode(value
);
3825 * Sampling rate has changed
3827 void MainWindow::samplingRateChanged(int value
)
3829 if(value
>= 0) m_settings
->samplingRate(value
);
3833 * Nero AAC 2-Pass mode changed
3835 void MainWindow::neroAAC2PassChanged(bool checked
)
3837 m_settings
->neroAACEnable2Pass(checked
);
3841 * Nero AAC profile mode changed
3843 void MainWindow::neroAACProfileChanged(int value
)
3845 if(value
>= 0) m_settings
->aacEncProfile(value
);
3849 * Aften audio coding mode changed
3851 void MainWindow::aftenCodingModeChanged(int value
)
3853 if(value
>= 0) m_settings
->aftenAudioCodingMode(value
);
3857 * Aften DRC mode changed
3859 void MainWindow::aftenDRCModeChanged(int value
)
3861 if(value
>= 0) m_settings
->aftenDynamicRangeCompression(value
);
3865 * Aften exponent search size changed
3867 void MainWindow::aftenSearchSizeChanged(int value
)
3869 if(value
>= 0) m_settings
->aftenExponentSearchSize(value
);
3873 * Aften fast bit allocation changed
3875 void MainWindow::aftenFastAllocationChanged(bool checked
)
3877 m_settings
->aftenFastBitAllocation(checked
);
3882 * Opus encoder settings changed
3884 void MainWindow::opusSettingsChanged(void)
3886 m_settings
->opusFramesize(ui
->comboBoxOpusFramesize
->currentIndex());
3887 m_settings
->opusComplexity(ui
->spinBoxOpusComplexity
->value());
3888 m_settings
->opusDisableResample(ui
->checkBoxOpusDisableResample
->isChecked());
3892 * Normalization filter enabled changed
3894 void MainWindow::normalizationEnabledChanged(bool checked
)
3896 m_settings
->normalizationFilterEnabled(checked
);
3897 normalizationDynamicChanged(ui
->checkBoxNormalizationFilterDynamic
->isChecked());
3901 * Dynamic normalization enabled changed
3903 void MainWindow::normalizationDynamicChanged(bool checked
)
3905 ui
->spinBoxNormalizationFilterSize
->setEnabled(ui
->checkBoxNormalizationFilterEnabled
->isChecked() && checked
);
3906 m_settings
->normalizationFilterDynamic(checked
);
3910 * Normalization max. volume changed
3912 void MainWindow::normalizationMaxVolumeChanged(double value
)
3914 m_settings
->normalizationFilterMaxVolume(static_cast<int>(value
* 100.0));
3918 * Normalization equalization mode changed
3920 void MainWindow::normalizationCoupledChanged(bool checked
)
3922 m_settings
->normalizationFilterCoupled(checked
);
3926 * Normalization filter size changed
3928 void MainWindow::normalizationFilterSizeChanged(int value
)
3930 m_settings
->normalizationFilterSize(value
);
3934 * Normalization filter size editing finished
3936 void MainWindow::normalizationFilterSizeFinished(void)
3938 const int value
= ui
->spinBoxNormalizationFilterSize
->value();
3939 if((value
% 2) != 1)
3941 bool rnd
= MUtils::parity(MUtils::next_rand_u32());
3942 ui
->spinBoxNormalizationFilterSize
->setValue(rnd
? value
+1 : value
-1);
3947 * Tone adjustment has changed (Bass)
3949 void MainWindow::toneAdjustBassChanged(double value
)
3951 m_settings
->toneAdjustBass(static_cast<int>(value
* 100.0));
3952 ui
->spinBoxToneAdjustBass
->setPrefix((value
> 0) ? "+" : QString());
3956 * Tone adjustment has changed (Treble)
3958 void MainWindow::toneAdjustTrebleChanged(double value
)
3960 m_settings
->toneAdjustTreble(static_cast<int>(value
* 100.0));
3961 ui
->spinBoxToneAdjustTreble
->setPrefix((value
> 0) ? "+" : QString());
3965 * Tone adjustment has been reset
3967 void MainWindow::toneAdjustTrebleReset(void)
3969 ui
->spinBoxToneAdjustBass
->setValue(m_settings
->toneAdjustBassDefault());
3970 ui
->spinBoxToneAdjustTreble
->setValue(m_settings
->toneAdjustTrebleDefault());
3971 toneAdjustBassChanged(ui
->spinBoxToneAdjustBass
->value());
3972 toneAdjustTrebleChanged(ui
->spinBoxToneAdjustTreble
->value());
3976 * Custom encoder parameters changed
3978 void MainWindow::customParamsChanged(void)
3980 ui
->lineEditCustomParamLAME
->setText(ui
->lineEditCustomParamLAME
->text().simplified());
3981 ui
->lineEditCustomParamOggEnc
->setText(ui
->lineEditCustomParamOggEnc
->text().simplified());
3982 ui
->lineEditCustomParamNeroAAC
->setText(ui
->lineEditCustomParamNeroAAC
->text().simplified());
3983 ui
->lineEditCustomParamFLAC
->setText(ui
->lineEditCustomParamFLAC
->text().simplified());
3984 ui
->lineEditCustomParamAften
->setText(ui
->lineEditCustomParamAften
->text().simplified());
3985 ui
->lineEditCustomParamOpus
->setText(ui
->lineEditCustomParamOpus
->text().simplified());
3987 bool customParamsUsed
= false;
3988 if(!ui
->lineEditCustomParamLAME
->text().isEmpty()) customParamsUsed
= true;
3989 if(!ui
->lineEditCustomParamOggEnc
->text().isEmpty()) customParamsUsed
= true;
3990 if(!ui
->lineEditCustomParamNeroAAC
->text().isEmpty()) customParamsUsed
= true;
3991 if(!ui
->lineEditCustomParamFLAC
->text().isEmpty()) customParamsUsed
= true;
3992 if(!ui
->lineEditCustomParamAften
->text().isEmpty()) customParamsUsed
= true;
3993 if(!ui
->lineEditCustomParamOpus
->text().isEmpty()) customParamsUsed
= true;
3995 ui
->labelCustomParamsIcon
->setVisible(customParamsUsed
);
3996 ui
->labelCustomParamsText
->setVisible(customParamsUsed
);
3997 ui
->labelCustomParamsSpacer
->setVisible(customParamsUsed
);
3999 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::MP3Encoder
, ui
->lineEditCustomParamLAME
->text());
4000 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::VorbisEncoder
, ui
->lineEditCustomParamOggEnc
->text());
4001 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::AACEncoder
, ui
->lineEditCustomParamNeroAAC
->text());
4002 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::FLACEncoder
, ui
->lineEditCustomParamFLAC
->text());
4003 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::AC3Encoder
, ui
->lineEditCustomParamAften
->text());
4004 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::OpusEncoder
, ui
->lineEditCustomParamOpus
->text());
4008 * One of the rename buttons has been clicked
4010 void MainWindow::renameButtonClicked(bool checked
)
4012 if(QPushButton
*const button
= dynamic_cast<QPushButton
*>(QObject::sender()))
4014 QWidget
*pages
[] = { ui
->pageRename_Rename
, ui
->pageRename_RegExp
, ui
->pageRename_FileEx
};
4015 QPushButton
*buttons
[] = { ui
->buttonRename_Rename
, ui
->buttonRename_RegExp
, ui
->buttonRename_FileEx
};
4016 for(int i
= 0; i
< 3; i
++)
4018 const bool match
= (button
== buttons
[i
]);
4019 buttons
[i
]->setChecked(match
);
4020 if(match
&& checked
) ui
->stackedWidget
->setCurrentWidget(pages
[i
]);
4026 * Rename output files enabled changed
4028 void MainWindow::renameOutputEnabledChanged(const bool &checked
)
4030 m_settings
->renameFiles_renameEnabled(checked
);
4034 * Rename output files patterm changed
4036 void MainWindow::renameOutputPatternChanged(void)
4038 QString temp
= ui
->lineEditRenamePattern
->text().simplified();
4039 ui
->lineEditRenamePattern
->setText(temp
.isEmpty() ? m_settings
->renameFiles_renamePatternDefault() : temp
);
4040 m_settings
->renameFiles_renamePattern(ui
->lineEditRenamePattern
->text());
4044 * Rename output files patterm changed
4046 void MainWindow::renameOutputPatternChanged(const QString
&text
, const bool &silent
)
4048 QString
pattern(text
.simplified());
4050 pattern
.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive
);
4051 pattern
.replace("<TrackNo>", "04", Qt::CaseInsensitive
);
4052 pattern
.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive
);
4053 pattern
.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive
);
4054 pattern
.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive
);
4055 pattern
.replace("<Year>", "2001", Qt::CaseInsensitive
);
4056 pattern
.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive
);
4058 const QString patternClean
= MUtils::clean_file_name(pattern
, false);
4060 if(pattern
.compare(patternClean
))
4062 if(ui
->lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::red
)
4064 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4065 SET_TEXT_COLOR(ui
->lineEditRenamePattern
, Qt::red
);
4070 if(ui
->lineEditRenamePattern
->palette() != QPalette())
4072 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
4073 ui
->lineEditRenamePattern
->setPalette(QPalette());
4077 ui
->labelRanameExample
->setText(patternClean
);
4081 * Regular expression enabled changed
4083 void MainWindow::renameRegExpEnabledChanged(const bool &checked
)
4085 m_settings
->renameFiles_regExpEnabled(checked
);
4089 * Regular expression value has changed
4091 void MainWindow::renameRegExpValueChanged(void)
4093 const QString search
= ui
->lineEditRenameRegExp_Search
->text() .trimmed();
4094 const QString replace
= ui
->lineEditRenameRegExp_Replace
->text().simplified();
4095 ui
->lineEditRenameRegExp_Search
->setText(search
.isEmpty() ? m_settings
->renameFiles_regExpSearchDefault() : search
);
4096 ui
->lineEditRenameRegExp_Replace
->setText(replace
.isEmpty() ? m_settings
->renameFiles_regExpReplaceDefault() : replace
);
4097 m_settings
->renameFiles_regExpSearch (ui
->lineEditRenameRegExp_Search
->text());
4098 m_settings
->renameFiles_regExpReplace(ui
->lineEditRenameRegExp_Replace
->text());
4102 * Regular expression search pattern has changed
4104 void MainWindow::renameRegExpSearchChanged(const QString
&text
, const bool &silent
)
4106 const QString
pattern(text
.trimmed());
4108 if((!pattern
.isEmpty()) && (!QRegExp(pattern
.trimmed()).isValid()))
4110 if(ui
->lineEditRenameRegExp_Search
->palette().color(QPalette::Text
) != Qt::red
)
4112 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4113 SET_TEXT_COLOR(ui
->lineEditRenameRegExp_Search
, Qt::red
);
4118 if(ui
->lineEditRenameRegExp_Search
->palette() != QPalette())
4120 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
4121 ui
->lineEditRenameRegExp_Search
->setPalette(QPalette());
4125 renameRegExpReplaceChanged(ui
->lineEditRenameRegExp_Replace
->text(), silent
);
4129 * Regular expression replacement string changed
4131 void MainWindow::renameRegExpReplaceChanged(const QString
&text
, const bool &silent
)
4133 QString
replacement(text
.simplified());
4134 const QString
search(ui
->lineEditRenameRegExp_Search
->text().trimmed());
4136 if(!search
.isEmpty())
4138 const QRegExp
regexp(search
);
4139 if(regexp
.isValid())
4141 const int count
= regexp
.captureCount();
4142 const QString blank
;
4143 for(int i
= 0; i
< count
; i
++)
4145 replacement
.replace(QString("\\%0").arg(QString::number(i
+1)), blank
);
4150 if(replacement
.compare(MUtils::clean_file_name(replacement
, false)))
4152 if(ui
->lineEditRenameRegExp_Replace
->palette().color(QPalette::Text
) != Qt::red
)
4154 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4155 SET_TEXT_COLOR(ui
->lineEditRenameRegExp_Replace
, Qt::red
);
4160 if(ui
->lineEditRenameRegExp_Replace
->palette() != QPalette())
4162 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
4163 ui
->lineEditRenameRegExp_Replace
->setPalette(QPalette());
4169 * Show list of rename macros
4171 void MainWindow::showRenameMacros(const QString
&text
)
4173 if(text
.compare("reset", Qt::CaseInsensitive
) == 0)
4175 ui
->lineEditRenamePattern
->setText(m_settings
->renameFiles_renamePatternDefault());
4179 if(text
.compare("regexp", Qt::CaseInsensitive
) == 0)
4181 MUtils::OS::shell_open(this, "http://www.regular-expressions.info/quickstart.html");
4185 const QString format
= QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
4187 QString message
= QString("<table>");
4188 message
+= QString(format
).arg("BaseName", tr("File name without extension"));
4189 message
+= QString(format
).arg("TrackNo", tr("Track number with leading zero"));
4190 message
+= QString(format
).arg("Title", tr("Track title"));
4191 message
+= QString(format
).arg("Artist", tr("Artist name"));
4192 message
+= QString(format
).arg("Album", tr("Album name"));
4193 message
+= QString(format
).arg("Year", tr("Year with (at least) four digits"));
4194 message
+= QString(format
).arg("Comment", tr("Comment"));
4195 message
+= "</table><br><br>";
4196 message
+= QString("%1<br>").arg(tr("Characters forbidden in file names:"));
4197 message
+= "<b><tt>\\ / : * ? < > |<br>";
4199 QMessageBox::information(this, tr("Rename Macros"), message
, tr("Discard"));
4202 void MainWindow::fileExtAddButtonClicked(void)
4204 if(FileExtsModel
*const model
= dynamic_cast<FileExtsModel
*>(ui
->tableViewFileExts
->model()))
4206 model
->addOverwrite(this);
4210 void MainWindow::fileExtRemoveButtonClicked(void)
4212 if(FileExtsModel
*const model
= dynamic_cast<FileExtsModel
*>(ui
->tableViewFileExts
->model()))
4214 const QModelIndex selected
= ui
->tableViewFileExts
->currentIndex();
4215 if(selected
.isValid())
4217 model
->removeOverwrite(selected
);
4221 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4226 void MainWindow::fileExtModelChanged(void)
4228 if(FileExtsModel
*const model
= dynamic_cast<FileExtsModel
*>(ui
->tableViewFileExts
->model()))
4230 m_settings
->renameFiles_fileExtension(model
->exportItems());
4234 void MainWindow::forceStereoDownmixEnabledChanged(bool checked
)
4236 m_settings
->forceStereoDownmix(checked
);
4240 * Maximum number of instances changed
4242 void MainWindow::updateMaximumInstances(const int value
)
4244 const quint32 instances
= decodeInstances(qBound(1U, static_cast<quint32
>(value
), 32U));
4245 m_settings
->maximumInstances(ui
->checkBoxAutoDetectInstances
->isChecked() ? 0U : instances
);
4246 ui
->labelMaxInstances
->setText(tr("%n Instance(s)", "", static_cast<int>(instances
)));
4250 * Auto-detect number of instances
4252 void MainWindow::autoDetectInstancesChanged(const bool checked
)
4254 m_settings
->maximumInstances(checked
? 0U : decodeInstances(qBound(1U, static_cast<quint32
>(ui
->sliderMaxInstances
->value()), 32U)));
4258 * Browse for custom TEMP folder button clicked
4260 void MainWindow::browseCustomTempFolderButtonClicked(void)
4262 QString newTempFolder
;
4264 if(MUtils::GUI::themes_enabled())
4266 newTempFolder
= QFileDialog::getExistingDirectory(this, QString(), m_settings
->customTempPath());
4270 QFileDialog
dialog(this);
4271 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
4272 dialog
.setDirectory(m_settings
->customTempPath());
4275 newTempFolder
= dialog
.selectedFiles().first();
4279 if(!newTempFolder
.isEmpty())
4281 QFile
writeTest(QString("%1/~%2.tmp").arg(newTempFolder
, MUtils::next_rand_str()));
4282 if(writeTest
.open(QIODevice::ReadWrite
))
4285 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(newTempFolder
));
4289 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
4295 * Custom TEMP folder changed
4297 void MainWindow::customTempFolderChanged(const QString
&text
)
4299 m_settings
->customTempPath(QDir::fromNativeSeparators(text
));
4303 * Use custom TEMP folder option changed
4305 void MainWindow::useCustomTempFolderChanged(bool checked
)
4307 m_settings
->customTempPathEnabled(!checked
);
4311 * Help for custom parameters was requested
4313 void MainWindow::customParamsHelpRequested(QWidget
*obj
, QEvent
*event
)
4315 if(event
->type() != QEvent::MouseButtonRelease
)
4320 if(QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
))
4322 QPoint pos
= mouseEvent
->pos();
4323 if(!(pos
.x() <= obj
->width() && pos
.y() <= obj
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
))
4329 if(obj
== ui
->helpCustomParamLAME
) showCustomParamsHelpScreen("lame.exe", "--longhelp");
4330 else if(obj
== ui
->helpCustomParamOggEnc
) showCustomParamsHelpScreen("oggenc2.exe", "--help");
4331 else if(obj
== ui
->helpCustomParamNeroAAC
)
4333 switch(EncoderRegistry::getAacEncoder())
4335 case SettingsModel::AAC_ENCODER_QAAC
: showCustomParamsHelpScreen("qaac64.exe|qaac.exe", "--help"); break;
4336 case SettingsModel::AAC_ENCODER_FHG
: showCustomParamsHelpScreen("fhgaacenc.exe", "" ); break;
4337 case SettingsModel::AAC_ENCODER_FDK
: showCustomParamsHelpScreen("fdkaac.exe", "--help"); break;
4338 case SettingsModel::AAC_ENCODER_NERO
: showCustomParamsHelpScreen("neroAacEnc.exe", "-help" ); break;
4339 default: MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
); break;
4342 else if(obj
== ui
->helpCustomParamFLAC
) showCustomParamsHelpScreen("flac.exe", "--help");
4343 else if(obj
== ui
->helpCustomParamAften
) showCustomParamsHelpScreen("aften.exe", "-h" );
4344 else if(obj
== ui
->helpCustomParamOpus
) showCustomParamsHelpScreen("opusenc.exe", "--help");
4345 else MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4349 * Show help for custom parameters
4351 void MainWindow::showCustomParamsHelpScreen(const QString
&toolName
, const QString
&command
)
4353 const QStringList toolNames
= toolName
.split('|', QString::SkipEmptyParts
);
4355 for(QStringList::ConstIterator iter
= toolNames
.constBegin(); iter
!= toolNames
.constEnd(); iter
++)
4357 if(lamexp_tools_check(*iter
))
4359 binary
= lamexp_tools_lookup(*iter
);
4364 if(binary
.isEmpty())
4366 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4367 qWarning("customParamsHelpRequested: Binary could not be found!");
4372 MUtils::init_process(process
, QFileInfo(binary
).absolutePath());
4374 process
.start(binary
, command
.isEmpty() ? QStringList() : QStringList() << command
);
4376 qApp
->setOverrideCursor(QCursor(Qt::WaitCursor
));
4378 if(process
.waitForStarted(15000))
4380 qApp
->processEvents();
4381 process
.waitForFinished(15000);
4384 if(process
.state() != QProcess::NotRunning
)
4387 process
.waitForFinished(-1);
4390 qApp
->restoreOverrideCursor();
4391 QStringList output
; bool spaceFlag
= true;
4393 while(process
.canReadLine())
4395 QString temp
= QString::fromUtf8(process
.readLine());
4396 TRIM_STRING_RIGHT(temp
);
4399 if(!spaceFlag
) { output
<< temp
; spaceFlag
= true; }
4403 output
<< temp
; spaceFlag
= false;
4407 if(output
.count() < 1)
4409 qWarning("Empty output, cannot show help screen!");
4410 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4413 WidgetHideHelper
hiderHelper(m_dropBox
.data());
4414 QScopedPointer
<LogViewDialog
> dialog(new LogViewDialog(this));
4415 dialog
->exec(output
);
4419 * File overwrite mode has changed
4422 void MainWindow::overwriteModeChanged(int id
)
4424 if((id
== SettingsModel::Overwrite_Replaces
) && (m_settings
->overwriteMode() != SettingsModel::Overwrite_Replaces
))
4426 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)
4428 ui
->radioButtonOverwriteModeKeepBoth
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_KeepBoth
);
4429 ui
->radioButtonOverwriteModeSkipFile
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_SkipFile
);
4434 m_settings
->overwriteMode(id
);
4438 * Keep original date/time opertion changed
4440 void MainWindow::keepOriginalDateTimeChanged(bool checked
)
4442 m_settings
->keepOriginalDataTime(checked
);
4446 * Reset all advanced options to their defaults
4448 void MainWindow::resetAdvancedOptionsButtonClicked(void)
4450 PLAY_SOUND_OPTIONAL("blast", true);
4452 ui
->sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQualityDefault());
4453 ui
->spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRateDefault());
4454 ui
->spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRateDefault());
4455 ui
->spinBoxNormalizationFilterPeak
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolumeDefault()) / 100.0);
4456 ui
->spinBoxNormalizationFilterSize
->setValue(m_settings
->normalizationFilterSizeDefault());
4457 ui
->spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBassDefault()) / 100.0);
4458 ui
->spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTrebleDefault()) / 100.0);
4459 ui
->spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSizeDefault());
4460 ui
->spinBoxOpusComplexity
->setValue(m_settings
->opusComplexityDefault());
4461 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelModeDefault());
4462 ui
->comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRateDefault());
4463 ui
->comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfileDefault());
4464 ui
->comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingModeDefault());
4465 ui
->comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompressionDefault());
4466 ui
->comboBoxOpusFramesize
->setCurrentIndex(m_settings
->opusFramesizeDefault());
4468 SET_CHECKBOX_STATE(ui
->checkBoxBitrateManagement
, m_settings
->bitrateManagementEnabledDefault());
4469 SET_CHECKBOX_STATE(ui
->checkBoxNeroAAC2PassMode
, m_settings
->neroAACEnable2PassDefault());
4470 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterEnabled
, m_settings
->normalizationFilterEnabledDefault());
4471 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterDynamic
, m_settings
->normalizationFilterDynamicDefault());
4472 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterCoupled
, m_settings
->normalizationFilterCoupledDefault());
4473 SET_CHECKBOX_STATE(ui
->checkBoxAutoDetectInstances
, (m_settings
->maximumInstancesDefault() < 1));
4474 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabledDefault()));
4475 SET_CHECKBOX_STATE(ui
->checkBoxAftenFastAllocation
, m_settings
->aftenFastBitAllocationDefault());
4476 SET_CHECKBOX_STATE(ui
->checkBoxRename_Rename
, m_settings
->renameFiles_renameEnabledDefault());
4477 SET_CHECKBOX_STATE(ui
->checkBoxRename_RegExp
, m_settings
->renameFiles_regExpEnabledDefault());
4478 SET_CHECKBOX_STATE(ui
->checkBoxForceStereoDownmix
, m_settings
->forceStereoDownmixDefault());
4479 SET_CHECKBOX_STATE(ui
->checkBoxOpusDisableResample
, m_settings
->opusDisableResampleDefault());
4480 SET_CHECKBOX_STATE(ui
->checkBoxKeepOriginalDateTime
, m_settings
->keepOriginalDataTimeDefault());
4482 ui
->lineEditCustomParamLAME
->setText(m_settings
->customParametersLAMEDefault());
4483 ui
->lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEncDefault());
4484 ui
->lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEncDefault());
4485 ui
->lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLACDefault());
4486 ui
->lineEditCustomParamOpus
->setText(m_settings
->customParametersOpusEncDefault());
4487 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPathDefault()));
4488 ui
->lineEditRenamePattern
->setText(m_settings
->renameFiles_renamePatternDefault());
4489 ui
->lineEditRenameRegExp_Search
->setText(m_settings
->renameFiles_regExpSearchDefault());
4490 ui
->lineEditRenameRegExp_Replace
->setText(m_settings
->renameFiles_regExpReplaceDefault());
4492 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_KeepBoth
) ui
->radioButtonOverwriteModeKeepBoth
->click();
4493 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_SkipFile
) ui
->radioButtonOverwriteModeSkipFile
->click();
4494 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_Replaces
) ui
->radioButtonOverwriteModeReplaces
->click();
4496 if(FileExtsModel
*const model
= dynamic_cast<FileExtsModel
*>(ui
->tableViewFileExts
->model()))
4498 model
->importItems(m_settings
->renameFiles_fileExtensionDefault());
4501 ui
->scrollArea
->verticalScrollBar()->setValue(0);
4502 ui
->buttonRename_Rename
->click();
4503 customParamsChanged();
4504 renameOutputPatternChanged();
4505 renameRegExpValueChanged();
4508 // =========================================================
4509 // Multi-instance handling slots
4510 // =========================================================
4513 * Other instance detected
4515 void MainWindow::notifyOtherInstance(void)
4517 if(!(BANNER_VISIBLE
))
4519 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
);
4525 * Add file from another instance
4527 void MainWindow::addFileDelayed(const QString
&filePath
, bool tryASAP
)
4529 if(tryASAP
&& !m_delayedFileTimer
->isActive())
4531 qDebug("Received file: %s", MUTILS_UTF8(filePath
));
4532 m_delayedFileList
->append(filePath
);
4533 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4536 m_delayedFileTimer
->stop();
4537 qDebug("Received file: %s", MUTILS_UTF8(filePath
));
4538 m_delayedFileList
->append(filePath
);
4539 m_delayedFileTimer
->start(5000);
4543 * Add files from another instance
4545 void MainWindow::addFilesDelayed(const QStringList
&filePaths
, bool tryASAP
)
4547 if(tryASAP
&& (!m_delayedFileTimer
->isActive()))
4549 qDebug("Received %d file(s).", filePaths
.count());
4550 m_delayedFileList
->append(filePaths
);
4551 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4555 m_delayedFileTimer
->stop();
4556 qDebug("Received %d file(s).", filePaths
.count());
4557 m_delayedFileList
->append(filePaths
);
4558 m_delayedFileTimer
->start(5000);
4563 * Add folder from another instance
4565 void MainWindow::addFolderDelayed(const QString
&folderPath
, bool recursive
)
4567 if(!(BANNER_VISIBLE
))
4569 addFolder(folderPath
, recursive
, true);
4573 // =========================================================
4575 // =========================================================
4578 * Restore the override cursor
4580 void MainWindow::restoreCursor(void)
4582 QApplication::restoreOverrideCursor();