1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Dialog_MainWindow.h"
26 #include "UIC_MainWindow.h"
30 #include "Dialog_WorkingBanner.h"
31 #include "Dialog_MetaInfo.h"
32 #include "Dialog_About.h"
33 #include "Dialog_Update.h"
34 #include "Dialog_DropBox.h"
35 #include "Dialog_CueImport.h"
36 #include "Dialog_LogView.h"
37 #include "Thread_FileAnalyzer.h"
38 #include "Thread_MessageHandler.h"
39 #include "Model_MetaInfo.h"
40 #include "Model_Settings.h"
41 #include "Model_FileList.h"
42 #include "Model_FileSystem.h"
43 #include "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)); \
132 #define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "−"))
133 #define FSLINK(PATH) QString("<a href=\"file:///%1\">%2</a>").arg(PATH).arg(QString(PATH).replace("-", "−"))
134 #define CENTER_CURRENT_OUTPUT_FOLDER_DELAYED QTimer::singleShot(125, this, SLOT(centerOutputFolderModel()))
136 ////////////////////////////////////////////////////////////
138 ////////////////////////////////////////////////////////////
140 static inline void SET_TEXT_COLOR(QWidget
*const widget
, const QColor
&color
)
142 QPalette _palette
= widget
->palette();
143 _palette
.setColor(QPalette::WindowText
, (color
));
144 _palette
.setColor(QPalette::Text
, (color
));
145 widget
->setPalette(_palette
);
148 static inline void SET_FONT_BOLD(QWidget
*const widget
, const bool &bold
)
150 QFont _font
= widget
->font();
152 widget
->setFont(_font
);
155 static inline void SET_FONT_BOLD(QAction
*const widget
, const bool &bold
)
157 QFont _font
= widget
->font();
159 widget
->setFont(_font
);
162 static inline void SET_MODEL(QAbstractItemView
*const view
, QAbstractItemModel
*const model
)
164 QItemSelectionModel
*_tmp
= view
->selectionModel();
165 view
->setModel(model
);
169 static inline void SET_CHECKBOX_STATE(QCheckBox
*const chckbx
, const bool &state
)
171 const bool isDisabled
= (!chckbx
->isEnabled());
174 chckbx
->setEnabled(true);
176 if(chckbx
->isChecked() != state
)
180 if(chckbx
->isChecked() != state
)
182 qWarning("Warning: Failed to set checkbox %p state!", chckbx
);
186 chckbx
->setEnabled(false);
190 static inline void TRIM_STRING_RIGHT(QString
&str
)
192 while((str
.length() > 0) && str
[str
.length()-1].isSpace())
198 static inline void MAKE_TRANSPARENT(QWidget
*const widget
, const bool &flag
)
200 QPalette _p
= widget
->palette(); \
201 _p
.setColor(QPalette::Background
, Qt::transparent
);
202 widget
->setPalette(flag
? _p
: QPalette());
205 template <typename T
>
206 static QList
<T
>& INVERT_LIST(QList
<T
> &list
)
210 const int limit
= list
.size() / 2, maxIdx
= list
.size() - 1;
211 for(int k
= 0; k
< limit
; k
++) list
.swap(k
, maxIdx
- k
);
216 ////////////////////////////////////////////////////////////
218 ////////////////////////////////////////////////////////////
220 class WidgetHideHelper
223 WidgetHideHelper(QWidget
*const widget
) : m_widget(widget
), m_visible(widget
&& widget
->isVisible()) { if(m_widget
&& m_visible
) m_widget
->hide(); }
224 ~WidgetHideHelper(void) { if(m_widget
&& m_visible
) m_widget
->show(); }
226 QWidget
*const m_widget
;
227 const bool m_visible
;
230 class SignalBlockHelper
233 SignalBlockHelper(QObject
*const object
) : m_object(object
), m_flag(object
&& object
->blockSignals(true)) {}
234 ~SignalBlockHelper(void) { if(m_object
&& (!m_flag
)) m_object
->blockSignals(false); }
236 QObject
*const m_object
;
240 class FileListBlockHelper
243 FileListBlockHelper(FileListModel
*const fileList
) : m_fileList(fileList
) { if(m_fileList
) m_fileList
->setBlockUpdates(true); }
244 ~FileListBlockHelper(void) { if(m_fileList
) m_fileList
->setBlockUpdates(false); }
246 FileListModel
*const m_fileList
;
249 ////////////////////////////////////////////////////////////
251 ////////////////////////////////////////////////////////////
253 MainWindow::MainWindow(MUtils::IPCChannel
*const ipcChannel
, FileListModel
*const fileListModel
, AudioFileModel_MetaInfo
*const metaInfo
, SettingsModel
*const settingsModel
, QWidget
*const parent
)
256 ui(new Ui::MainWindow
),
257 m_fileListModel(fileListModel
),
258 m_metaData(metaInfo
),
259 m_settings(settingsModel
),
261 m_firstTimeShown(true),
262 m_outputFolderViewCentering(false),
263 m_outputFolderViewInitCounter(0)
265 //Init the dialog, from the .ui file
267 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint
);
270 MUtils::GUI::set_window_icon(this, lamexp_app_icon(), true);
272 //Register meta types
273 qRegisterMetaType
<AudioFileModel
>("AudioFileModel");
275 //Enabled main buttons
276 connect(ui
->buttonAbout
, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
277 connect(ui
->buttonStart
, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
278 connect(ui
->buttonQuit
, SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
281 ui
->tabWidget
->setCurrentIndex(0);
282 connect(ui
->tabWidget
, SIGNAL(currentChanged(int)), this, SLOT(tabPageChanged(int)));
285 MUtils::GUI::sysmenu_append(this, IDM_ABOUTBOX
, "About...");
287 //Setup corner widget
288 QLabel
*cornerWidget
= new QLabel(ui
->menubar
);
289 m_evenFilterCornerWidget
.reset(new CustomEventFilter
);
290 cornerWidget
->setText("N/A");
291 cornerWidget
->setFixedHeight(ui
->menubar
->height());
292 cornerWidget
->setCursor(QCursor(Qt::PointingHandCursor
));
293 cornerWidget
->hide();
294 cornerWidget
->installEventFilter(m_evenFilterCornerWidget
.data());
295 connect(m_evenFilterCornerWidget
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(cornerWidgetEventOccurred(QWidget
*, QEvent
*)));
296 ui
->menubar
->setCornerWidget(cornerWidget
);
298 //--------------------------------
299 // Setup "Source" tab
300 //--------------------------------
302 ui
->sourceFileView
->setModel(m_fileListModel
);
303 ui
->sourceFileView
->verticalHeader() ->setResizeMode(QHeaderView::ResizeToContents
);
304 ui
->sourceFileView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
305 ui
->sourceFileView
->setContextMenuPolicy(Qt::CustomContextMenu
);
306 ui
->sourceFileView
->viewport()->installEventFilter(this);
307 m_dropNoteLabel
.reset(new QLabel(ui
->sourceFileView
));
308 m_dropNoteLabel
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
309 SET_FONT_BOLD(m_dropNoteLabel
.data(), true);
310 SET_TEXT_COLOR(m_dropNoteLabel
.data(), Qt::darkGray
);
311 m_sourceFilesContextMenu
.reset(new QMenu());
312 m_showDetailsContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
313 m_previewContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/sound.png"), "N/A");
314 m_findFileContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_go.png"), "N/A");
315 m_sourceFilesContextMenu
->addSeparator();
316 m_exportCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/table_save.png"), "N/A");
317 m_importCsvContextAction
= m_sourceFilesContextMenu
->addAction(QIcon(":/icons/folder_table.png"), "N/A");
318 SET_FONT_BOLD(m_showDetailsContextAction
, true);
320 connect(ui
->buttonAddFiles
, SIGNAL(clicked()), this, SLOT(addFilesButtonClicked()));
321 connect(ui
->buttonRemoveFile
, SIGNAL(clicked()), this, SLOT(removeFileButtonClicked()));
322 connect(ui
->buttonClearFiles
, SIGNAL(clicked()), this, SLOT(clearFilesButtonClicked()));
323 connect(ui
->buttonFileUp
, SIGNAL(clicked()), this, SLOT(fileUpButtonClicked()));
324 connect(ui
->buttonFileDown
, SIGNAL(clicked()), this, SLOT(fileDownButtonClicked()));
325 connect(ui
->buttonShowDetails
, SIGNAL(clicked()), this, SLOT(showDetailsButtonClicked()));
326 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
327 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), this, SLOT(sourceModelChanged()));
328 connect(m_fileListModel
, SIGNAL(modelReset()), this, SLOT(sourceModelChanged()));
329 connect(ui
->sourceFileView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(sourceFilesContextMenu(QPoint
)));
330 connect(ui
->sourceFileView
->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
331 connect(ui
->sourceFileView
->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(sourceFilesScrollbarMoved(int)));
332 connect(m_showDetailsContextAction
, SIGNAL(triggered(bool)), this, SLOT(showDetailsButtonClicked()));
333 connect(m_previewContextAction
, SIGNAL(triggered(bool)), this, SLOT(previewContextActionTriggered()));
334 connect(m_findFileContextAction
, SIGNAL(triggered(bool)), this, SLOT(findFileContextActionTriggered()));
335 connect(m_exportCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(exportCsvContextActionTriggered()));
336 connect(m_importCsvContextAction
, SIGNAL(triggered(bool)), this, SLOT(importCsvContextActionTriggered()));
338 //--------------------------------
339 // Setup "Output" tab
340 //--------------------------------
342 ui
->outputFolderView
->setHeaderHidden(true);
343 ui
->outputFolderView
->setAnimated(false);
344 ui
->outputFolderView
->setMouseTracking(false);
345 ui
->outputFolderView
->setContextMenuPolicy(Qt::CustomContextMenu
);
346 ui
->outputFolderView
->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn
);
348 m_evenFilterOutputFolderMouse
.reset(new CustomEventFilter
);
349 ui
->outputFoldersGoUpLabel
->installEventFilter(m_evenFilterOutputFolderMouse
.data());
350 ui
->outputFoldersEditorLabel
->installEventFilter(m_evenFilterOutputFolderMouse
.data());
351 ui
->outputFoldersFovoritesLabel
->installEventFilter(m_evenFilterOutputFolderMouse
.data());
352 ui
->outputFolderLabel
->installEventFilter(m_evenFilterOutputFolderMouse
.data());
354 m_evenFilterOutputFolderView
.reset(new CustomEventFilter
);
355 ui
->outputFolderView
->installEventFilter(m_evenFilterOutputFolderView
.data());
357 SET_CHECKBOX_STATE(ui
->saveToSourceFolderCheckBox
, m_settings
->outputToSourceDir());
358 ui
->prependRelativePathCheckBox
->setChecked(m_settings
->prependRelativeSourcePath());
360 connect(ui
->outputFolderView
, SIGNAL(clicked(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
361 connect(ui
->outputFolderView
, SIGNAL(activated(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
362 connect(ui
->outputFolderView
, SIGNAL(pressed(QModelIndex
)), this, SLOT(outputFolderViewClicked(QModelIndex
)));
363 connect(ui
->outputFolderView
, SIGNAL(entered(QModelIndex
)), this, SLOT(outputFolderViewMoved(QModelIndex
)));
364 connect(ui
->outputFolderView
, SIGNAL(expanded(QModelIndex
)), this, SLOT(outputFolderItemExpanded(QModelIndex
)));
365 connect(ui
->buttonMakeFolder
, SIGNAL(clicked()), this, SLOT(makeFolderButtonClicked()));
366 connect(ui
->buttonGotoHome
, SIGNAL(clicked()), this, SLOT(gotoHomeFolderButtonClicked()));
367 connect(ui
->buttonGotoDesktop
, SIGNAL(clicked()), this, SLOT(gotoDesktopButtonClicked()));
368 connect(ui
->buttonGotoMusic
, SIGNAL(clicked()), this, SLOT(gotoMusicFolderButtonClicked()));
369 connect(ui
->saveToSourceFolderCheckBox
, SIGNAL(clicked()), this, SLOT(saveToSourceFolderChanged()));
370 connect(ui
->prependRelativePathCheckBox
, SIGNAL(clicked()), this, SLOT(prependRelativePathChanged()));
371 connect(ui
->outputFolderEdit
, SIGNAL(editingFinished()), this, SLOT(outputFolderEditFinished()));
372 connect(m_evenFilterOutputFolderMouse
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(outputFolderMouseEventOccurred(QWidget
*, QEvent
*)));
373 connect(m_evenFilterOutputFolderView
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(outputFolderViewEventOccurred(QWidget
*, QEvent
*)));
375 m_outputFolderContextMenu
.reset(new QMenu());
376 m_showFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/zoom.png"), "N/A");
377 m_goUpFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/folder_up.png"), "N/A");
378 m_outputFolderContextMenu
->addSeparator();
379 m_refreshFolderContextAction
= m_outputFolderContextMenu
->addAction(QIcon(":/icons/arrow_refresh.png"), "N/A");
380 m_outputFolderContextMenu
->setDefaultAction(m_showFolderContextAction
);
381 connect(ui
->outputFolderView
, SIGNAL(customContextMenuRequested(QPoint
)), this, SLOT(outputFolderContextMenu(QPoint
)));
382 connect(m_showFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(showFolderContextActionTriggered()));
383 connect(m_refreshFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(refreshFolderContextActionTriggered()));
384 connect(m_goUpFolderContextAction
, SIGNAL(triggered(bool)), this, SLOT(goUpFolderContextActionTriggered()));
386 m_outputFolderFavoritesMenu
.reset(new QMenu());
387 m_addFavoriteFolderAction
= m_outputFolderFavoritesMenu
->addAction(QIcon(":/icons/add.png"), "N/A");
388 m_outputFolderFavoritesMenu
->insertSeparator(m_addFavoriteFolderAction
);
389 connect(m_addFavoriteFolderAction
, SIGNAL(triggered(bool)), this, SLOT(addFavoriteFolderActionTriggered()));
391 ui
->outputFolderEdit
->setVisible(false);
392 m_outputFolderNoteBox
.reset(new QLabel(ui
->outputFolderView
));
393 m_outputFolderNoteBox
->setAutoFillBackground(true);
394 m_outputFolderNoteBox
->setAlignment(Qt::AlignHCenter
| Qt::AlignVCenter
);
395 m_outputFolderNoteBox
->setFrameShape(QFrame::StyledPanel
);
396 SET_FONT_BOLD(m_outputFolderNoteBox
.data(), true);
397 m_outputFolderNoteBox
->hide();
399 outputFolderViewClicked(QModelIndex());
402 //--------------------------------
403 // Setup "Meta Data" tab
404 //--------------------------------
406 m_metaInfoModel
.reset(new MetaInfoModel(m_metaData
));
407 m_metaInfoModel
->clearData();
408 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
409 ui
->metaDataView
->setModel(m_metaInfoModel
.data());
410 ui
->metaDataView
->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
411 ui
->metaDataView
->verticalHeader()->hide();
412 ui
->metaDataView
->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents
);
413 SET_CHECKBOX_STATE(ui
->writeMetaDataCheckBox
, m_settings
->writeMetaTags());
414 ui
->generatePlaylistCheckBox
->setChecked(m_settings
->createPlaylist());
415 connect(ui
->buttonEditMeta
, SIGNAL(clicked()), this, SLOT(editMetaButtonClicked()));
416 connect(ui
->buttonClearMeta
, SIGNAL(clicked()), this, SLOT(clearMetaButtonClicked()));
417 connect(ui
->writeMetaDataCheckBox
, SIGNAL(clicked()), this, SLOT(metaTagsEnabledChanged()));
418 connect(ui
->generatePlaylistCheckBox
, SIGNAL(clicked()), this, SLOT(playlistEnabledChanged()));
420 //--------------------------------
421 //Setup "Compression" tab
422 //--------------------------------
424 m_encoderButtonGroup
.reset(new QButtonGroup(this));
425 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderMP3
, SettingsModel::MP3Encoder
);
426 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderVorbis
, SettingsModel::VorbisEncoder
);
427 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAAC
, SettingsModel::AACEncoder
);
428 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAC3
, SettingsModel::AC3Encoder
);
429 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderFLAC
, SettingsModel::FLACEncoder
);
430 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderAPE
, SettingsModel::MACEncoder
);
431 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderOpus
, SettingsModel::OpusEncoder
);
432 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderDCA
, SettingsModel::DCAEncoder
);
433 m_encoderButtonGroup
->addButton(ui
->radioButtonEncoderPCM
, SettingsModel::PCMEncoder
);
435 const int aacEncoder
= EncoderRegistry::getAacEncoder();
436 ui
->radioButtonEncoderAAC
->setEnabled(aacEncoder
> SettingsModel::AAC_ENCODER_NONE
);
438 m_modeButtonGroup
.reset(new QButtonGroup(this));
439 m_modeButtonGroup
->addButton(ui
->radioButtonModeQuality
, SettingsModel::VBRMode
);
440 m_modeButtonGroup
->addButton(ui
->radioButtonModeAverageBitrate
, SettingsModel::ABRMode
);
441 m_modeButtonGroup
->addButton(ui
->radioButtonConstBitrate
, SettingsModel::CBRMode
);
443 ui
->radioButtonEncoderMP3
->setChecked(true);
444 foreach(QAbstractButton
*currentButton
, m_encoderButtonGroup
->buttons())
446 if(currentButton
->isEnabled() && (m_encoderButtonGroup
->id(currentButton
) == m_settings
->compressionEncoder()))
448 currentButton
->setChecked(true);
453 m_evenFilterCompressionTab
.reset(new CustomEventFilter());
454 ui
->labelCompressionHelp
->installEventFilter(m_evenFilterCompressionTab
.data());
455 ui
->labelResetEncoders
->installEventFilter(m_evenFilterCompressionTab
.data());
457 connect(m_encoderButtonGroup
.data(), SIGNAL(buttonClicked(int)), this, SLOT(updateEncoder(int)));
458 connect(m_modeButtonGroup
.data(), SIGNAL(buttonClicked(int)), this, SLOT(updateRCMode(int)));
459 connect(m_evenFilterCompressionTab
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(compressionTabEventOccurred(QWidget
*, QEvent
*)));
460 connect(ui
->sliderBitrate
, SIGNAL(valueChanged(int)), this, SLOT(updateBitrate(int)));
462 updateEncoder(m_encoderButtonGroup
->checkedId());
464 //--------------------------------
465 //Setup "Advanced Options" tab
466 //--------------------------------
468 ui
->sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQuality());
469 if(m_settings
->maximumInstances() > 0) ui
->sliderMaxInstances
->setValue(m_settings
->maximumInstances());
471 ui
->spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRate());
472 ui
->spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRate());
473 ui
->spinBoxNormalizationFilterPeak
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolume()) / 100.0);
474 ui
->spinBoxNormalizationFilterSize
->setValue(m_settings
->normalizationFilterSize());
475 ui
->spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBass()) / 100.0);
476 ui
->spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTreble()) / 100.0);
477 ui
->spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSize());
478 ui
->spinBoxOpusComplexity
->setValue(m_settings
->opusComplexity());
480 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelMode());
481 ui
->comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRate());
482 ui
->comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfile());
483 ui
->comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingMode());
484 ui
->comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompression());
485 ui
->comboBoxOpusFramesize
->setCurrentIndex(m_settings
->opusFramesize());
487 SET_CHECKBOX_STATE(ui
->checkBoxBitrateManagement
, m_settings
->bitrateManagementEnabled());
488 SET_CHECKBOX_STATE(ui
->checkBoxNeroAAC2PassMode
, m_settings
->neroAACEnable2Pass());
489 SET_CHECKBOX_STATE(ui
->checkBoxAftenFastAllocation
, m_settings
->aftenFastBitAllocation());
490 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterEnabled
, m_settings
->normalizationFilterEnabled());
491 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterDynamic
, m_settings
->normalizationFilterDynamic());
492 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterCoupled
, m_settings
->normalizationFilterCoupled());
493 SET_CHECKBOX_STATE(ui
->checkBoxAutoDetectInstances
, (m_settings
->maximumInstances() < 1));
494 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabled()));
495 SET_CHECKBOX_STATE(ui
->checkBoxRename_Rename
, m_settings
->renameFiles_renameEnabled());
496 SET_CHECKBOX_STATE(ui
->checkBoxRename_RegExp
, m_settings
->renameFiles_regExpEnabled());
497 SET_CHECKBOX_STATE(ui
->checkBoxForceStereoDownmix
, m_settings
->forceStereoDownmix());
498 SET_CHECKBOX_STATE(ui
->checkBoxOpusDisableResample
, m_settings
->opusDisableResample());
500 ui
->checkBoxNeroAAC2PassMode
->setEnabled(aacEncoder
== SettingsModel::AAC_ENCODER_NERO
);
502 ui
->lineEditCustomParamLAME
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::MP3Encoder
));
503 ui
->lineEditCustomParamOggEnc
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::VorbisEncoder
));
504 ui
->lineEditCustomParamNeroAAC
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::AACEncoder
));
505 ui
->lineEditCustomParamFLAC
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::FLACEncoder
));
506 ui
->lineEditCustomParamAften
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::AC3Encoder
));
507 ui
->lineEditCustomParamOpus
->setText(EncoderRegistry::loadEncoderCustomParams(m_settings
, SettingsModel::OpusEncoder
));
508 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPath()));
509 ui
->lineEditRenamePattern
->setText(m_settings
->renameFiles_renamePattern());
510 ui
->lineEditRenameRegExp_Search
->setText(m_settings
->renameFiles_regExpSearch ());
511 ui
->lineEditRenameRegExp_Replace
->setText(m_settings
->renameFiles_regExpReplace());
513 m_evenFilterCustumParamsHelp
.reset(new CustomEventFilter());
514 ui
->helpCustomParamLAME
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
515 ui
->helpCustomParamOggEnc
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
516 ui
->helpCustomParamNeroAAC
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
517 ui
->helpCustomParamFLAC
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
518 ui
->helpCustomParamAften
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
519 ui
->helpCustomParamOpus
->installEventFilter(m_evenFilterCustumParamsHelp
.data());
521 m_overwriteButtonGroup
.reset(new QButtonGroup(this));
522 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeKeepBoth
, SettingsModel::Overwrite_KeepBoth
);
523 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeSkipFile
, SettingsModel::Overwrite_SkipFile
);
524 m_overwriteButtonGroup
->addButton(ui
->radioButtonOverwriteModeReplaces
, SettingsModel::Overwrite_Replaces
);
526 ui
->radioButtonOverwriteModeKeepBoth
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_KeepBoth
);
527 ui
->radioButtonOverwriteModeSkipFile
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_SkipFile
);
528 ui
->radioButtonOverwriteModeReplaces
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_Replaces
);
530 FileExtsModel
*fileExtModel
= new FileExtsModel(this);
531 fileExtModel
->importItems(m_settings
->renameFiles_fileExtension());
532 ui
->tableViewFileExts
->setModel(fileExtModel
);
533 ui
->tableViewFileExts
->verticalHeader() ->setResizeMode(QHeaderView::ResizeToContents
);
534 ui
->tableViewFileExts
->horizontalHeader()->setResizeMode(QHeaderView::Stretch
);
536 connect(ui
->sliderLameAlgoQuality
, SIGNAL(valueChanged(int)), this, SLOT(updateLameAlgoQuality(int)));
537 connect(ui
->checkBoxBitrateManagement
, SIGNAL(clicked(bool)), this, SLOT(bitrateManagementEnabledChanged(bool)));
538 connect(ui
->spinBoxBitrateManagementMin
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMinChanged(int)));
539 connect(ui
->spinBoxBitrateManagementMax
, SIGNAL(valueChanged(int)), this, SLOT(bitrateManagementMaxChanged(int)));
540 connect(ui
->comboBoxMP3ChannelMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(channelModeChanged(int)));
541 connect(ui
->comboBoxSamplingRate
, SIGNAL(currentIndexChanged(int)), this, SLOT(samplingRateChanged(int)));
542 connect(ui
->checkBoxNeroAAC2PassMode
, SIGNAL(clicked(bool)), this, SLOT(neroAAC2PassChanged(bool)));
543 connect(ui
->comboBoxAACProfile
, SIGNAL(currentIndexChanged(int)), this, SLOT(neroAACProfileChanged(int)));
544 connect(ui
->checkBoxNormalizationFilterEnabled
, SIGNAL(clicked(bool)), this, SLOT(normalizationEnabledChanged(bool)));
545 connect(ui
->checkBoxNormalizationFilterDynamic
, SIGNAL(clicked(bool)), this, SLOT(normalizationDynamicChanged(bool)));
546 connect(ui
->checkBoxNormalizationFilterCoupled
, SIGNAL(clicked(bool)), this, SLOT(normalizationCoupledChanged(bool)));
547 connect(ui
->comboBoxAftenCodingMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenCodingModeChanged(int)));
548 connect(ui
->comboBoxAftenDRCMode
, SIGNAL(currentIndexChanged(int)), this, SLOT(aftenDRCModeChanged(int)));
549 connect(ui
->spinBoxAftenSearchSize
, SIGNAL(valueChanged(int)), this, SLOT(aftenSearchSizeChanged(int)));
550 connect(ui
->checkBoxAftenFastAllocation
, SIGNAL(clicked(bool)), this, SLOT(aftenFastAllocationChanged(bool)));
551 connect(ui
->spinBoxNormalizationFilterPeak
, SIGNAL(valueChanged(double)), this, SLOT(normalizationMaxVolumeChanged(double)));
552 connect(ui
->spinBoxNormalizationFilterSize
, SIGNAL(valueChanged(int)), this, SLOT(normalizationFilterSizeChanged(int)));
553 connect(ui
->spinBoxNormalizationFilterSize
, SIGNAL(editingFinished()), this, SLOT(normalizationFilterSizeFinished()));
554 connect(ui
->spinBoxToneAdjustBass
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustBassChanged(double)));
555 connect(ui
->spinBoxToneAdjustTreble
, SIGNAL(valueChanged(double)), this, SLOT(toneAdjustTrebleChanged(double)));
556 connect(ui
->buttonToneAdjustReset
, SIGNAL(clicked()), this, SLOT(toneAdjustTrebleReset()));
557 connect(ui
->lineEditCustomParamLAME
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
558 connect(ui
->lineEditCustomParamOggEnc
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
559 connect(ui
->lineEditCustomParamNeroAAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
560 connect(ui
->lineEditCustomParamFLAC
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
561 connect(ui
->lineEditCustomParamAften
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
562 connect(ui
->lineEditCustomParamOpus
, SIGNAL(editingFinished()), this, SLOT(customParamsChanged()));
563 connect(ui
->sliderMaxInstances
, SIGNAL(valueChanged(int)), this, SLOT(updateMaximumInstances(int)));
564 connect(ui
->checkBoxAutoDetectInstances
, SIGNAL(clicked(bool)), this, SLOT(autoDetectInstancesChanged(bool)));
565 connect(ui
->buttonBrowseCustomTempFolder
, SIGNAL(clicked()), this, SLOT(browseCustomTempFolderButtonClicked()));
566 connect(ui
->lineEditCustomTempFolder
, SIGNAL(textChanged(QString
)), this, SLOT(customTempFolderChanged(QString
)));
567 connect(ui
->checkBoxUseSystemTempFolder
, SIGNAL(clicked(bool)), this, SLOT(useCustomTempFolderChanged(bool)));
568 connect(ui
->buttonResetAdvancedOptions
, SIGNAL(clicked()), this, SLOT(resetAdvancedOptionsButtonClicked()));
569 connect(ui
->checkBoxRename_Rename
, SIGNAL(clicked(bool)), this, SLOT(renameOutputEnabledChanged(bool)));
570 connect(ui
->checkBoxRename_RegExp
, SIGNAL(clicked(bool)), this, SLOT(renameRegExpEnabledChanged(bool)));
571 connect(ui
->lineEditRenamePattern
, SIGNAL(editingFinished()), this, SLOT(renameOutputPatternChanged()));
572 connect(ui
->lineEditRenamePattern
, SIGNAL(textChanged(QString
)), this, SLOT(renameOutputPatternChanged(QString
)));
573 connect(ui
->lineEditRenameRegExp_Search
, SIGNAL(editingFinished()), this, SLOT(renameRegExpValueChanged()));
574 connect(ui
->lineEditRenameRegExp_Search
, SIGNAL(textChanged(QString
)), this, SLOT(renameRegExpSearchChanged(QString
)));
575 connect(ui
->lineEditRenameRegExp_Replace
, SIGNAL(editingFinished()), this, SLOT(renameRegExpValueChanged()));
576 connect(ui
->lineEditRenameRegExp_Replace
, SIGNAL(textChanged(QString
)), this, SLOT(renameRegExpReplaceChanged(QString
)));
577 connect(ui
->labelShowRenameMacros
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
578 connect(ui
->labelShowRegExpHelp
, SIGNAL(linkActivated(QString
)), this, SLOT(showRenameMacros(QString
)));
579 connect(ui
->checkBoxForceStereoDownmix
, SIGNAL(clicked(bool)), this, SLOT(forceStereoDownmixEnabledChanged(bool)));
580 connect(ui
->comboBoxOpusFramesize
, SIGNAL(currentIndexChanged(int)), this, SLOT(opusSettingsChanged()));
581 connect(ui
->spinBoxOpusComplexity
, SIGNAL(valueChanged(int)), this, SLOT(opusSettingsChanged()));
582 connect(ui
->checkBoxOpusDisableResample
, SIGNAL(clicked(bool)), this, SLOT(opusSettingsChanged()));
583 connect(ui
->buttonRename_Rename
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
584 connect(ui
->buttonRename_RegExp
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
585 connect(ui
->buttonRename_FileEx
, SIGNAL(clicked(bool)), this, SLOT(renameButtonClicked(bool)));
586 connect(ui
->buttonFileExts_Add
, SIGNAL(clicked()), this, SLOT(fileExtAddButtonClicked()));
587 connect(ui
->buttonFileExts_Remove
, SIGNAL(clicked()), this, SLOT(fileExtRemoveButtonClicked()));
588 connect(m_overwriteButtonGroup
.data(), SIGNAL(buttonClicked(int)), this, SLOT(overwriteModeChanged(int)));
589 connect(m_evenFilterCustumParamsHelp
.data(), SIGNAL(eventOccurred(QWidget
*, QEvent
*)), this, SLOT(customParamsHelpRequested(QWidget
*, QEvent
*)));
590 connect(fileExtModel
, SIGNAL(modelReset()), this, SLOT(fileExtModelChanged()));
592 //--------------------------------
593 // Force initial GUI update
594 //--------------------------------
596 updateLameAlgoQuality(ui
->sliderLameAlgoQuality
->value());
597 updateMaximumInstances(ui
->sliderMaxInstances
->value());
598 toneAdjustTrebleChanged(ui
->spinBoxToneAdjustTreble
->value());
599 toneAdjustBassChanged(ui
->spinBoxToneAdjustBass
->value());
600 normalizationEnabledChanged(ui
->checkBoxNormalizationFilterEnabled
->isChecked());
601 customParamsChanged();
603 //--------------------------------
604 // Initialize actions
605 //--------------------------------
607 //Activate file menu actions
608 ui
->actionOpenFolder
->setData(QVariant::fromValue
<bool>(false));
609 ui
->actionOpenFolderRecursively
->setData(QVariant::fromValue
<bool>(true));
610 connect(ui
->actionOpenFolder
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
611 connect(ui
->actionOpenFolderRecursively
, SIGNAL(triggered()), this, SLOT(openFolderActionActivated()));
613 //Activate view menu actions
614 m_tabActionGroup
.reset(new QActionGroup(this));
615 m_tabActionGroup
->addAction(ui
->actionSourceFiles
);
616 m_tabActionGroup
->addAction(ui
->actionOutputDirectory
);
617 m_tabActionGroup
->addAction(ui
->actionCompression
);
618 m_tabActionGroup
->addAction(ui
->actionMetaData
);
619 m_tabActionGroup
->addAction(ui
->actionAdvancedOptions
);
620 ui
->actionSourceFiles
->setData(0);
621 ui
->actionOutputDirectory
->setData(1);
622 ui
->actionMetaData
->setData(2);
623 ui
->actionCompression
->setData(3);
624 ui
->actionAdvancedOptions
->setData(4);
625 ui
->actionSourceFiles
->setChecked(true);
626 connect(m_tabActionGroup
.data(), SIGNAL(triggered(QAction
*)), this, SLOT(tabActionActivated(QAction
*)));
628 //Activate style menu actions
629 m_styleActionGroup
.reset(new QActionGroup(this));
630 m_styleActionGroup
->addAction(ui
->actionStylePlastique
);
631 m_styleActionGroup
->addAction(ui
->actionStyleCleanlooks
);
632 m_styleActionGroup
->addAction(ui
->actionStyleWindowsVista
);
633 m_styleActionGroup
->addAction(ui
->actionStyleWindowsXP
);
634 m_styleActionGroup
->addAction(ui
->actionStyleWindowsClassic
);
635 ui
->actionStylePlastique
->setData(0);
636 ui
->actionStyleCleanlooks
->setData(1);
637 ui
->actionStyleWindowsVista
->setData(2);
638 ui
->actionStyleWindowsXP
->setData(3);
639 ui
->actionStyleWindowsClassic
->setData(4);
640 ui
->actionStylePlastique
->setChecked(true);
641 ui
->actionStyleWindowsXP
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_XP
&& MUtils::GUI::themes_enabled());
642 ui
->actionStyleWindowsVista
->setEnabled((QSysInfo::windowsVersion() & QSysInfo::WV_NT_based
) >= QSysInfo::WV_VISTA
&& MUtils::GUI::themes_enabled());
643 connect(m_styleActionGroup
.data(), SIGNAL(triggered(QAction
*)), this, SLOT(styleActionActivated(QAction
*)));
644 styleActionActivated(NULL
);
646 //Populate the language menu
647 m_languageActionGroup
.reset(new QActionGroup(this));
648 QStringList translations
;
649 if(MUtils::Translation::enumerate(translations
) > 0)
651 for(QStringList::ConstIterator iter
= translations
.constBegin(); iter
!= translations
.constEnd(); iter
++)
653 QAction
*currentLanguage
= new QAction(this);
654 currentLanguage
->setData(*iter
);
655 currentLanguage
->setText(MUtils::Translation::get_name(*iter
));
656 currentLanguage
->setIcon(QIcon(QString(":/flags/%1.png").arg(*iter
)));
657 currentLanguage
->setCheckable(true);
658 currentLanguage
->setChecked(false);
659 m_languageActionGroup
->addAction(currentLanguage
);
660 ui
->menuLanguage
->insertAction(ui
->actionLoadTranslationFromFile
, currentLanguage
);
663 ui
->menuLanguage
->insertSeparator(ui
->actionLoadTranslationFromFile
);
664 connect(ui
->actionLoadTranslationFromFile
, SIGNAL(triggered(bool)), this, SLOT(languageFromFileActionActivated(bool)));
665 connect(m_languageActionGroup
.data(), SIGNAL(triggered(QAction
*)), this, SLOT(languageActionActivated(QAction
*)));
666 ui
->actionLoadTranslationFromFile
->setChecked(false);
668 //Activate tools menu actions
669 ui
->actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
670 ui
->actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
671 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
672 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
673 ui
->actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
674 ui
->actionDisableShellIntegration
->setDisabled(lamexp_version_portable() && ui
->actionDisableShellIntegration
->isChecked());
675 ui
->actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta() || lamexp_version_demo());
676 ui
->actionCheckForBetaUpdates
->setEnabled(!lamexp_version_demo());
677 ui
->actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
678 ui
->actionHibernateComputer
->setEnabled(MUtils::OS::is_hibernation_supported());
679 connect(ui
->actionDisableUpdateReminder
, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool)));
680 connect(ui
->actionDisableSounds
, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool)));
681 connect(ui
->actionDisableNeroAacNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool)));
682 connect(ui
->actionDisableSlowStartupNotifications
, SIGNAL(triggered(bool)), this, SLOT(disableSlowStartupNotificationsActionTriggered(bool)));
683 connect(ui
->actionDisableShellIntegration
, SIGNAL(triggered(bool)), this, SLOT(disableShellIntegrationActionTriggered(bool)));
684 connect(ui
->actionShowDropBoxWidget
, SIGNAL(triggered(bool)), this, SLOT(showDropBoxWidgetActionTriggered(bool)));
685 connect(ui
->actionHibernateComputer
, SIGNAL(triggered(bool)), this, SLOT(hibernateComputerActionTriggered(bool)));
686 connect(ui
->actionCheckForBetaUpdates
, SIGNAL(triggered(bool)), this, SLOT(checkForBetaUpdatesActionTriggered(bool)));
687 connect(ui
->actionImportCueSheet
, SIGNAL(triggered(bool)), this, SLOT(importCueSheetActionTriggered(bool)));
689 //Activate help menu actions
690 ui
->actionVisitHomepage
->setData(QString::fromLatin1(lamexp_website_url()));
691 ui
->actionVisitSupport
->setData(QString::fromLatin1(lamexp_support_url()));
692 ui
->actionVisitMuldersSite
->setData(QString::fromLatin1(lamexp_mulders_url()));
693 ui
->actionVisitTracker
->setData(QString::fromLatin1(lamexp_tracker_url()));
694 ui
->actionVisitHAK
->setData(QString::fromLatin1(g_hydrogen_audio_url
));
695 ui
->actionDocumentManual
->setData(QString("%1/Manual.html") .arg(QApplication::applicationDirPath()));
696 ui
->actionDocumentChangelog
->setData(QString("%1/Changelog.html").arg(QApplication::applicationDirPath()));
697 ui
->actionDocumentTranslate
->setData(QString("%1/Translate.html").arg(QApplication::applicationDirPath()));
698 connect(ui
->actionCheckUpdates
, SIGNAL(triggered()), this, SLOT(checkUpdatesActionActivated()));
699 connect(ui
->actionVisitSupport
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
700 connect(ui
->actionVisitTracker
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
701 connect(ui
->actionVisitHomepage
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
702 connect(ui
->actionVisitMuldersSite
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
703 connect(ui
->actionVisitHAK
, SIGNAL(triggered()), this, SLOT(visitHomepageActionActivated()));
704 connect(ui
->actionDocumentManual
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
705 connect(ui
->actionDocumentChangelog
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
706 connect(ui
->actionDocumentTranslate
, SIGNAL(triggered()), this, SLOT(documentActionActivated()));
708 //--------------------------------
709 // Prepare to show window
710 //--------------------------------
712 //Center window in screen
713 QRect desktopRect
= QApplication::desktop()->screenGeometry();
714 QRect thisRect
= this->geometry();
715 move((desktopRect
.width() - thisRect
.width()) / 2, (desktopRect
.height() - thisRect
.height()) / 2);
716 setMinimumSize(thisRect
.width(), thisRect
.height());
718 //Create DropBox widget
719 m_dropBox
.reset(new DropBox(this, m_fileListModel
, m_settings
));
720 connect(m_fileListModel
, SIGNAL(modelReset()), m_dropBox
.data(), SLOT(modelChanged()));
721 connect(m_fileListModel
, SIGNAL(rowsInserted(QModelIndex
,int,int)), m_dropBox
.data(), SLOT(modelChanged()));
722 connect(m_fileListModel
, SIGNAL(rowsRemoved(QModelIndex
,int,int)), m_dropBox
.data(), SLOT(modelChanged()));
723 connect(m_fileListModel
, SIGNAL(rowAppended()), m_dropBox
.data(), SLOT(modelChanged()));
725 //Create message handler thread
726 m_messageHandler
.reset(new MessageHandlerThread(ipcChannel
));
727 connect(m_messageHandler
.data(), SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection
);
728 connect(m_messageHandler
.data(), SIGNAL(fileReceived(QString
)), this, SLOT(addFileDelayed(QString
)), Qt::QueuedConnection
);
729 connect(m_messageHandler
.data(), SIGNAL(folderReceived(QString
, bool)), this, SLOT(addFolderDelayed(QString
, bool)), Qt::QueuedConnection
);
730 connect(m_messageHandler
.data(), SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection
);
731 m_messageHandler
->start();
733 //Init delayed file handling
734 m_delayedFileList
.reset(new QStringList());
735 m_delayedFileTimer
.reset(new QTimer());
736 m_delayedFileTimer
->setSingleShot(true);
737 m_delayedFileTimer
->setInterval(5000);
738 connect(m_delayedFileTimer
.data(), SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
741 initializeTranslation();
743 //Re-translate (make sure we translate once)
744 QEvent
languageChangeEvent(QEvent::LanguageChange
);
745 changeEvent(&languageChangeEvent
);
748 m_droppedFileList
.reset(new QList
<QUrl
>());
749 this->setAcceptDrops(true);
752 ////////////////////////////////////////////////////////////
754 ////////////////////////////////////////////////////////////
756 MainWindow::~MainWindow(void)
758 //Stop message handler thread
759 if(m_messageHandler
&& m_messageHandler
->isRunning())
761 m_messageHandler
->stop();
762 if(!m_messageHandler
->wait(2500))
764 m_messageHandler
->terminate();
765 m_messageHandler
->wait();
770 SET_MODEL(ui
->sourceFileView
, NULL
);
771 SET_MODEL(ui
->outputFolderView
, NULL
);
772 SET_MODEL(ui
->metaDataView
, NULL
);
774 //Un-initialize the dialog
778 ////////////////////////////////////////////////////////////
780 ////////////////////////////////////////////////////////////
783 * Add file to source list
785 void MainWindow::addFiles(const QStringList
&files
)
792 if(ui
->tabWidget
->currentIndex() != 0)
794 SignalBlockHelper
signalBlockHelper(ui
->tabWidget
);
795 ui
->tabWidget
->setCurrentIndex(0);
796 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
800 QScopedPointer
<FileAnalyzer
> analyzer(new FileAnalyzer(files
));
802 connect(analyzer
.data(), SIGNAL(fileSelected(QString
)), m_banner
.data(), SLOT(setText(QString
)), Qt::QueuedConnection
);
803 connect(analyzer
.data(), SIGNAL(progressValChanged(unsigned int)), m_banner
.data(), SLOT(setProgressVal(unsigned int)), Qt::QueuedConnection
);
804 connect(analyzer
.data(), SIGNAL(progressMaxChanged(unsigned int)), m_banner
.data(), SLOT(setProgressMax(unsigned int)), Qt::QueuedConnection
);
805 connect(analyzer
.data(), SIGNAL(fileAnalyzed(AudioFileModel
)), m_fileListModel
, SLOT(addFile(AudioFileModel
)), Qt::QueuedConnection
);
806 connect(m_banner
.data(), SIGNAL(userAbort()), analyzer
.data(), SLOT(abortProcess()), Qt::DirectConnection
);
808 if(!analyzer
.isNull())
810 FileListBlockHelper
fileListBlocker(m_fileListModel
);
811 m_banner
->show(tr("Adding file(s), please wait..."), analyzer
.data());
814 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
815 ui
->sourceFileView
->update();
816 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
817 ui
->sourceFileView
->scrollToBottom();
818 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
820 if(analyzer
->filesDenied())
822 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."))));
824 if(analyzer
->filesDummyCDDA())
826 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>"))));
828 if(analyzer
->filesCueSheet())
830 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."))));
832 if(analyzer
->filesRejected())
834 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."))));
841 * Add folder to source list
843 void MainWindow::addFolder(const QString
&path
, bool recursive
, bool delayed
, QString filter
)
845 QFileInfoList folderInfoList
;
846 folderInfoList
<< QFileInfo(path
);
847 QStringList fileList
;
849 showBanner(tr("Scanning folder(s) for files, please wait..."));
851 QApplication::processEvents();
852 MUtils::OS::check_key_state_esc();
854 while(!folderInfoList
.isEmpty())
856 if(MUtils::OS::check_key_state_esc())
858 qWarning("Operation cancelled by user!");
859 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
864 QDir
currentDir(folderInfoList
.takeFirst().canonicalFilePath());
865 QFileInfoList fileInfoList
= currentDir
.entryInfoList(QDir::Files
| QDir::NoSymLinks
);
867 for(QFileInfoList::ConstIterator iter
= fileInfoList
.constBegin(); iter
!= fileInfoList
.constEnd(); iter
++)
869 if(filter
.isEmpty() || (iter
->suffix().compare(filter
, Qt::CaseInsensitive
) == 0))
871 fileList
<< iter
->canonicalFilePath();
875 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
879 folderInfoList
.append(currentDir
.entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
));
880 QApplication::processEvents();
885 QApplication::processEvents();
887 if(!fileList
.isEmpty())
891 addFilesDelayed(fileList
);
903 bool MainWindow::checkForUpdates(void)
905 bool bReadyToInstall
= false;
907 UpdateDialog
*updateDialog
= new UpdateDialog(m_settings
, this);
908 updateDialog
->exec();
910 if(updateDialog
->getSuccess())
912 SHOW_CORNER_WIDGET(false);
913 m_settings
->autoUpdateLastCheck(QDate::currentDate().toString(Qt::ISODate
));
914 bReadyToInstall
= updateDialog
->updateReadyToInstall();
917 MUTILS_DELETE(updateDialog
);
918 return bReadyToInstall
;
922 * Refresh list of favorites
924 void MainWindow::refreshFavorites(void)
926 QList
<QAction
*> folderList
= m_outputFolderFavoritesMenu
->actions();
927 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
928 while(favorites
.count() > 6) favorites
.removeFirst();
930 while(!folderList
.isEmpty())
932 QAction
*currentItem
= folderList
.takeFirst();
933 if(currentItem
->isSeparator()) break;
934 m_outputFolderFavoritesMenu
->removeAction(currentItem
);
935 MUTILS_DELETE(currentItem
);
938 QAction
*lastItem
= m_outputFolderFavoritesMenu
->actions().first();
940 while(!favorites
.isEmpty())
942 QString path
= favorites
.takeLast();
943 if(QDir(path
).exists())
945 QAction
*action
= new QAction(QIcon(":/icons/folder_go.png"), QDir::toNativeSeparators(path
), this);
946 action
->setData(path
);
947 m_outputFolderFavoritesMenu
->insertAction(lastItem
, action
);
948 connect(action
, SIGNAL(triggered(bool)), this, SLOT(gotoFavoriteFolder()));
955 * Initilaize translation
957 void MainWindow::initializeTranslation(void)
959 bool translationLoaded
= false;
961 //Try to load "external" translation file
962 if(!m_settings
->currentLanguageFile().isEmpty())
964 const QString qmFilePath
= QFileInfo(m_settings
->currentLanguageFile()).canonicalFilePath();
965 if((!qmFilePath
.isEmpty()) && QFileInfo(qmFilePath
).exists() && QFileInfo(qmFilePath
).isFile() && (QFileInfo(qmFilePath
).suffix().compare("qm", Qt::CaseInsensitive
) == 0))
967 if(MUtils::Translation::install_translator_from_file(qmFilePath
))
969 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
970 while(!actions
.isEmpty()) actions
.takeFirst()->setChecked(false);
971 ui
->actionLoadTranslationFromFile
->setChecked(true);
972 translationLoaded
= true;
977 //Try to load "built-in" translation file
978 if(!translationLoaded
)
980 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
981 while(!languageActions
.isEmpty())
983 QAction
*currentLanguage
= languageActions
.takeFirst();
984 if(currentLanguage
->data().toString().compare(m_settings
->currentLanguage(), Qt::CaseInsensitive
) == 0)
986 currentLanguage
->setChecked(true);
987 languageActionActivated(currentLanguage
);
988 translationLoaded
= true;
993 //Fallback to default translation
994 if(!translationLoaded
)
996 QList
<QAction
*> languageActions
= m_languageActionGroup
->actions();
997 while(!languageActions
.isEmpty())
999 QAction
*currentLanguage
= languageActions
.takeFirst();
1000 if(currentLanguage
->data().toString().compare(MUtils::Translation::DEFAULT_LANGID
, Qt::CaseInsensitive
) == 0)
1002 currentLanguage
->setChecked(true);
1003 languageActionActivated(currentLanguage
);
1004 translationLoaded
= true;
1009 //Make sure we loaded some translation
1010 if(!translationLoaded
)
1012 qFatal("Failed to load any translation, this is NOT supposed to happen!");
1017 * Open a document link
1019 void MainWindow::openDocumentLink(QAction
*const action
)
1021 if(!(action
->data().isValid() && (action
->data().type() == QVariant::String
)))
1023 qWarning("Cannot open document for this QAction!");
1027 //Try to open exitsing document file
1028 const QFileInfo
document(action
->data().toString());
1029 if(document
.exists() && document
.isFile() && (document
.size() >= 1024))
1031 QDesktopServices::openUrl(QUrl::fromLocalFile(document
.canonicalFilePath()));
1035 //Document not found -> fallback mode!
1036 qWarning("Document '%s' not found -> redirecting to the website!", MUTILS_UTF8(document
.fileName()));
1037 const QUrl
url(QString("%1/%2").arg(QString::fromLatin1(g_documents_base_url
), document
.fileName()));
1038 QDesktopServices::openUrl(url
);
1042 * Move selected files up/down
1044 void MainWindow::moveSelectedFiles(const bool &up
)
1046 QItemSelectionModel
*const selection
= ui
->sourceFileView
->selectionModel();
1047 if(selection
&& selection
->hasSelection())
1049 const QModelIndexList selectedRows
= up
? selection
->selectedRows() : INVERT_LIST(selection
->selectedRows());
1050 if((up
&& (selectedRows
.first().row() > 0)) || ((!up
) && (selectedRows
.first().row() < m_fileListModel
->rowCount() - 1)))
1052 const int delta
= up
? (-1) : 1;
1053 const int firstIndex
= (up
? selectedRows
.first() : selectedRows
.last()).row() + delta
;
1054 const int selectionCount
= selectedRows
.count();
1057 FileListBlockHelper
fileListBlocker(m_fileListModel
);
1058 for(QModelIndexList::ConstIterator iter
= selectedRows
.constBegin(); iter
!= selectedRows
.constEnd(); iter
++)
1060 if(!m_fileListModel
->moveFile((*iter
), delta
))
1066 selection
->clearSelection();
1067 for(int i
= 0; i
< selectionCount
; i
++)
1069 const QModelIndex item
= m_fileListModel
->index(firstIndex
+ i
, 0);
1070 selection
->select(QItemSelection(item
, item
), QItemSelectionModel::Select
| QItemSelectionModel::Rows
);
1075 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
1079 * Show banner popup dialog
1081 void MainWindow::showBanner(const QString
&text
)
1084 m_banner
->show(text
);
1088 * Show banner popup dialog
1090 void MainWindow::showBanner(const QString
&text
, QThread
*const thread
)
1093 m_banner
->show(text
, thread
);
1097 * Show banner popup dialog
1099 void MainWindow::showBanner(const QString
&text
, QEventLoop
*const eventLoop
)
1102 m_banner
->show(text
, eventLoop
);
1106 * Show banner popup dialog
1108 void MainWindow::showBanner(const QString
&text
, bool &flag
, const bool &test
)
1110 if((!flag
) && (test
))
1113 m_banner
->show(text
);
1118 ////////////////////////////////////////////////////////////
1120 ////////////////////////////////////////////////////////////
1123 * Window is about to be shown
1125 void MainWindow::showEvent(QShowEvent
*event
)
1129 sourceModelChanged();
1131 if(!event
->spontaneous())
1133 SignalBlockHelper
signalBlockHelper(ui
->tabWidget
);
1134 ui
->tabWidget
->setCurrentIndex(0);
1135 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
1138 if(m_firstTimeShown
)
1140 m_firstTimeShown
= false;
1141 QTimer::singleShot(0, this, SLOT(windowShown()));
1145 if(m_settings
->dropBoxWidgetEnabled())
1147 m_dropBox
->setVisible(true);
1153 * Re-translate the UI
1155 void MainWindow::changeEvent(QEvent
*e
)
1157 QMainWindow::changeEvent(e
);
1158 if(e
->type() != QEvent::LanguageChange
)
1163 int comboBoxIndex
[6];
1165 //Backup combobox indices, as retranslateUi() resets
1166 comboBoxIndex
[0] = ui
->comboBoxMP3ChannelMode
->currentIndex();
1167 comboBoxIndex
[1] = ui
->comboBoxSamplingRate
->currentIndex();
1168 comboBoxIndex
[2] = ui
->comboBoxAACProfile
->currentIndex();
1169 comboBoxIndex
[3] = ui
->comboBoxAftenCodingMode
->currentIndex();
1170 comboBoxIndex
[4] = ui
->comboBoxAftenDRCMode
->currentIndex();
1171 comboBoxIndex
[5] = ui
->comboBoxOpusFramesize
->currentIndex();
1173 //Re-translate from UIC
1174 ui
->retranslateUi(this);
1176 //Restore combobox indices
1177 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(comboBoxIndex
[0]);
1178 ui
->comboBoxSamplingRate
->setCurrentIndex(comboBoxIndex
[1]);
1179 ui
->comboBoxAACProfile
->setCurrentIndex(comboBoxIndex
[2]);
1180 ui
->comboBoxAftenCodingMode
->setCurrentIndex(comboBoxIndex
[3]);
1181 ui
->comboBoxAftenDRCMode
->setCurrentIndex(comboBoxIndex
[4]);
1182 ui
->comboBoxOpusFramesize
->setCurrentIndex(comboBoxIndex
[5]);
1184 //Update the window title
1187 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
1189 else if(lamexp_version_demo())
1191 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
1194 //Manually re-translate widgets that UIC doesn't handle
1195 m_outputFolderNoteBox
->setText(tr("Initializing directory outline, please be patient..."));
1196 m_dropNoteLabel
->setText(QString("<br><img src=\":/images/DropZone.png\"><br><br>%1").arg(tr("You can drop in audio files here!")));
1197 if(QLabel
*cornerWidget
= dynamic_cast<QLabel
*>(ui
->menubar
->cornerWidget()))
1199 cornerWidget
->setText(QString("<nobr><img src=\":/icons/exclamation_small.png\"> <b style=\"color:darkred\">%1</b> </nobr>").arg(tr("Check for Updates")));
1201 m_showDetailsContextAction
->setText(tr("Show Details"));
1202 m_previewContextAction
->setText(tr("Open File in External Application"));
1203 m_findFileContextAction
->setText(tr("Browse File Location"));
1204 m_showFolderContextAction
->setText(tr("Browse Selected Folder"));
1205 m_refreshFolderContextAction
->setText(tr("Refresh Directory Outline"));
1206 m_goUpFolderContextAction
->setText(tr("Go To Parent Directory"));
1207 m_addFavoriteFolderAction
->setText(tr("Bookmark Current Output Folder"));
1208 m_exportCsvContextAction
->setText(tr("Export Meta Tags to CSV File"));
1209 m_importCsvContextAction
->setText(tr("Import Meta Tags from CSV File"));
1212 m_metaInfoModel
->clearData();
1213 m_metaInfoModel
->setData(m_metaInfoModel
->index(4, 1), m_settings
->metaInfoPosition());
1214 updateEncoder(m_settings
->compressionEncoder());
1215 updateLameAlgoQuality(ui
->sliderLameAlgoQuality
->value());
1216 updateMaximumInstances(ui
->sliderMaxInstances
->value());
1217 renameOutputPatternChanged(ui
->lineEditRenamePattern
->text(), true);
1218 renameRegExpSearchChanged (ui
->lineEditRenameRegExp_Search
->text(), true);
1219 renameRegExpReplaceChanged(ui
->lineEditRenameRegExp_Replace
->text(), true);
1221 //Re-install shell integration
1222 if(m_settings
->shellIntegrationEnabled())
1224 ShellIntegration::install();
1227 //Translate system menu
1228 MUtils::GUI::sysmenu_update(this, IDM_ABOUTBOX
, ui
->buttonAbout
->text());
1230 //Force resize event
1231 QApplication::postEvent(this, new QResizeEvent(this->size(), QSize()));
1232 for(QObjectList::ConstIterator iter
= this->children().constBegin(); iter
!= this->children().constEnd(); iter
++)
1234 if(QWidget
*child
= dynamic_cast<QWidget
*>(*iter
))
1236 QApplication::postEvent(child
, new QResizeEvent(child
->size(), QSize()));
1240 //Force tabe page change
1241 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
1245 * File dragged over window
1247 void MainWindow::dragEnterEvent(QDragEnterEvent
*event
)
1249 QStringList formats
= event
->mimeData()->formats();
1251 if(formats
.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive
) && formats
.contains("text/uri-list", Qt::CaseInsensitive
))
1253 event
->acceptProposedAction();
1258 * File dropped onto window
1260 void MainWindow::dropEvent(QDropEvent
*event
)
1262 m_droppedFileList
->clear();
1263 (*m_droppedFileList
) << event
->mimeData()->urls();
1264 if(!m_droppedFileList
->isEmpty())
1266 PLAY_SOUND_OPTIONAL("drop", true);
1267 QTimer::singleShot(0, this, SLOT(handleDroppedFiles()));
1272 * Window tries to close
1274 void MainWindow::closeEvent(QCloseEvent
*event
)
1276 if(BANNER_VISIBLE
|| m_delayedFileTimer
->isActive())
1278 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
1289 * Window was resized
1291 void MainWindow::resizeEvent(QResizeEvent
*event
)
1293 if(event
) QMainWindow::resizeEvent(event
);
1295 if(QWidget
*port
= ui
->sourceFileView
->viewport())
1297 m_dropNoteLabel
->setGeometry(port
->geometry());
1300 if(QWidget
*port
= ui
->outputFolderView
->viewport())
1302 m_outputFolderNoteBox
->setGeometry(16, (port
->height() - 64) / 2, port
->width() - 32, 64);
1307 * Key press event filter
1309 void MainWindow::keyPressEvent(QKeyEvent
*e
)
1311 if(e
->key() == Qt::Key_Delete
)
1313 if(ui
->sourceFileView
->isVisible())
1315 QTimer::singleShot(0, this, SLOT(removeFileButtonClicked()));
1320 if(e
->modifiers().testFlag(Qt::ControlModifier
) && (e
->key() == Qt::Key_F5
))
1322 initializeTranslation();
1323 MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
1327 if(e
->key() == Qt::Key_F5
)
1329 if(ui
->outputFolderView
->isVisible())
1331 QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
1336 QMainWindow::keyPressEvent(e
);
1342 bool MainWindow::eventFilter(QObject
*obj
, QEvent
*event
)
1344 if(obj
== m_fileSystemModel
.data())
1346 if(QApplication::overrideCursor() == NULL
)
1348 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor
));
1349 QTimer::singleShot(250, this, SLOT(restoreCursor()));
1353 return QMainWindow::eventFilter(obj
, event
);
1356 bool MainWindow::event(QEvent
*e
)
1360 case MUtils::GUI::USER_EVENT_QUERYENDSESSION
:
1361 qWarning("System is shutting down, main window prepares to close...");
1362 if(BANNER_VISIBLE
) m_banner
->close();
1363 if(m_delayedFileTimer
->isActive()) m_delayedFileTimer
->stop();
1365 case MUtils::GUI::USER_EVENT_ENDSESSION
:
1366 qWarning("System is shutting down, main window will close now...");
1371 QApplication::processEvents(QEventLoop::WaitForMoreEvents
& QEventLoop::ExcludeUserInputEvents
);
1374 m_fileListModel
->clearFiles();
1376 case QEvent::MouseButtonPress
:
1377 if(ui
->outputFolderEdit
->isVisible())
1379 QTimer::singleShot(0, this, SLOT(outputFolderEditFinished()));
1382 return QMainWindow::event(e
);
1386 bool MainWindow::winEvent(MSG
*message
, long *result
)
1388 if(MUtils::GUI::sysmenu_check_msg(message
, IDM_ABOUTBOX
))
1390 QTimer::singleShot(0, ui
->buttonAbout
, SLOT(click()));
1397 ////////////////////////////////////////////////////////////
1399 ////////////////////////////////////////////////////////////
1401 // =========================================================
1402 // Show window slots
1403 // =========================================================
1408 void MainWindow::windowShown(void)
1410 const MUtils::OS::ArgumentMap
&arguments
= MUtils::OS::arguments(); //QApplication::arguments();
1412 //Force resize event
1416 const bool firstRun
= arguments
.contains("first-run");
1419 if((m_settings
->licenseAccepted() <= 0) || firstRun
)
1421 int iAccepted
= m_settings
->licenseAccepted();
1423 if((iAccepted
== 0) || firstRun
)
1425 AboutDialog
*about
= new AboutDialog(m_settings
, this, true);
1426 iAccepted
= about
->exec();
1427 if(iAccepted
<= 0) iAccepted
= -2;
1428 MUTILS_DELETE(about
);
1433 m_settings
->licenseAccepted(++iAccepted
);
1434 m_settings
->syncNow();
1435 QApplication::processEvents();
1436 MUtils::Sound::play_sound("whammy", false);
1437 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
1438 QFileInfo uninstallerInfo
= QFileInfo(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()));
1439 if(uninstallerInfo
.exists())
1441 QString uninstallerDir
= uninstallerInfo
.canonicalPath();
1442 QString uninstallerPath
= uninstallerInfo
.canonicalFilePath();
1443 for(int i
= 0; i
< 3; i
++)
1445 if(MUtils::OS::shell_open(this, QDir::toNativeSeparators(uninstallerPath
), "/Force", QDir::toNativeSeparators(uninstallerDir
))) break;
1448 QApplication::quit();
1452 MUtils::Sound::play_sound("woohoo", false);
1453 m_settings
->licenseAccepted(1);
1454 m_settings
->syncNow();
1455 if(lamexp_version_demo()) showAnnounceBox();
1458 //Check for expiration
1459 if(lamexp_version_demo())
1461 if(MUtils::OS::current_date() >= lamexp_version_expires())
1463 qWarning("Binary has expired !!!");
1464 MUtils::Sound::play_sound("whammy", false);
1465 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)
1469 QApplication::quit();
1474 //Slow startup indicator
1475 if(m_settings
->slowStartup() && m_settings
->antivirNotificationsEnabled())
1478 message
+= NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
1479 message
+= NOBR(tr("Please refer to the %1 document for details and solutions!")).arg("<a href=\"http://lamexp.sourceforge.net/doc/FAQ.html#df406578\">F.A.Q.</a>").append("<br>");
1480 if(QMessageBox::warning(this, tr("Slow Startup"), message
, tr("Discard"), tr("Don't Show Again")) == 1)
1482 m_settings
->antivirNotificationsEnabled(false);
1483 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
1488 if(MUtils::OS::current_date() >= MUtils::Version::app_build_date().addYears(1))
1490 qWarning("Binary is more than a year old, time to update!");
1491 SHOW_CORNER_WIDGET(true);
1492 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"));
1496 if(checkForUpdates())
1498 QApplication::quit();
1503 QApplication::quit();
1506 QEventLoop loop
; QTimer::singleShot(7000, &loop
, SLOT(quit()));
1507 MUtils::Sound::play_sound("waiting", true);
1508 showBanner(tr("Skipping update check this time, please be patient..."), &loop
);
1514 QDate lastUpdateCheck
= QDate::fromString(m_settings
->autoUpdateLastCheck(), Qt::ISODate
);
1515 if((!firstRun
) && ((!lastUpdateCheck
.isValid()) || (MUtils::OS::current_date() >= lastUpdateCheck
.addDays(14))))
1517 SHOW_CORNER_WIDGET(true);
1518 if(m_settings
->autoUpdateEnabled())
1520 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)
1522 if(checkForUpdates())
1524 QApplication::quit();
1532 //Check for AAC support
1533 const int aacEncoder
= EncoderRegistry::getAacEncoder();
1534 if(aacEncoder
== SettingsModel::AAC_ENCODER_NERO
)
1536 if(m_settings
->neroAacNotificationsEnabled())
1538 if(lamexp_tools_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1540 QString messageText
;
1541 messageText
+= NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1542 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>");
1543 messageText
+= NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1544 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br><br>";
1545 messageText
+= NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
1546 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText
);
1552 if(m_settings
->neroAacNotificationsEnabled() && (aacEncoder
<= SettingsModel::AAC_ENCODER_NONE
))
1554 QString appPath
= QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1555 if(appPath
.isEmpty()) appPath
= QCoreApplication::applicationDirPath();
1556 QString messageText
;
1557 messageText
+= NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1558 messageText
+= NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1559 messageText
+= NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1560 messageText
+= QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath
)));
1561 messageText
+= NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1562 messageText
+= "<nobr><tt>" + LINK(AboutDialog::neroAacUrl
) + "</tt></nobr><br>";
1563 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText
, tr("Discard"), tr("Don't Show Again")) == 1)
1565 m_settings
->neroAacNotificationsEnabled(false);
1566 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
1571 //Add files from the command-line
1572 QStringList addedFiles
;
1573 foreach(const QString
&value
, arguments
.values("add"))
1575 if(!value
.isEmpty())
1577 QFileInfo
currentFile(value
);
1578 qDebug("Adding file from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1579 addedFiles
.append(currentFile
.absoluteFilePath());
1582 if(!addedFiles
.isEmpty())
1584 addFilesDelayed(addedFiles
);
1587 //Add folders from the command-line
1588 foreach(const QString
&value
, arguments
.values("add-folder"))
1590 if(!value
.isEmpty())
1592 const QFileInfo
currentFile(value
);
1593 qDebug("Adding folder from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1594 addFolder(currentFile
.absoluteFilePath(), false, true);
1597 foreach(const QString
&value
, arguments
.values("add-recursive"))
1599 if(!value
.isEmpty())
1601 const QFileInfo
currentFile(value
);
1602 qDebug("Adding folder recursively from CLI: %s", MUTILS_UTF8(currentFile
.absoluteFilePath()));
1603 addFolder(currentFile
.absoluteFilePath(), true, true);
1607 //Enable shell integration
1608 if(m_settings
->shellIntegrationEnabled())
1610 ShellIntegration::install();
1613 //Make DropBox visible
1614 if(m_settings
->dropBoxWidgetEnabled())
1616 m_dropBox
->setVisible(true);
1623 void MainWindow::showAnnounceBox(void)
1625 const unsigned int timeout
= 8U;
1627 const QString announceText
= QString("%1<br><br>%2<br><nobr><tt>%3</tt></nobr><br>").arg
1629 NOBR("We are still looking for LameXP translators!"),
1630 NOBR("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:"),
1631 LINK("http://lamexp.sourceforge.net/doc/Translate.html")
1634 QMessageBox
*announceBox
= new QMessageBox(QMessageBox::Warning
, "We want you!", announceText
, QMessageBox::NoButton
, this);
1635 announceBox
->setWindowFlags(Qt::Window
| Qt::WindowTitleHint
| Qt::CustomizeWindowHint
);
1636 announceBox
->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1638 QTimer
*timers
[timeout
+1];
1639 QPushButton
*buttons
[timeout
+1];
1641 for(unsigned int i
= 0; i
<= timeout
; i
++)
1643 QString text
= (i
> 0) ? QString("%1 (%2)").arg(tr("Discard"), QString::number(i
)) : tr("Discard");
1644 buttons
[i
] = announceBox
->addButton(text
, (i
> 0) ? QMessageBox::NoRole
: QMessageBox::AcceptRole
);
1647 for(unsigned int i
= 0; i
<= timeout
; i
++)
1649 buttons
[i
]->setEnabled(i
== 0);
1650 buttons
[i
]->setVisible(i
== timeout
);
1653 for(unsigned int i
= 0; i
< timeout
; i
++)
1655 timers
[i
] = new QTimer(this);
1656 timers
[i
]->setSingleShot(true);
1657 timers
[i
]->setInterval(1000);
1658 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
+1], SLOT(hide()));
1659 connect(timers
[i
], SIGNAL(timeout()), buttons
[i
], SLOT(show()));
1662 connect(timers
[i
], SIGNAL(timeout()), timers
[i
-1], SLOT(start()));
1666 timers
[timeout
-1]->start();
1667 announceBox
->exec();
1669 for(unsigned int i
= 0; i
< timeout
; i
++)
1672 MUTILS_DELETE(timers
[i
]);
1675 MUTILS_DELETE(announceBox
);
1678 // =========================================================
1679 // Main button solots
1680 // =========================================================
1685 void MainWindow::encodeButtonClicked(void)
1687 static const unsigned __int64 oneGigabyte
= 1073741824ui
64;
1688 static const unsigned __int64 minimumFreeDiskspaceMultiplier
= 2ui
64;
1689 static const char *writeTestBuffer
= "LAMEXP_WRITE_TEST";
1693 if(m_fileListModel
->rowCount() < 1)
1695 QMessageBox::warning(this, tr("LameXP"), NOBR(tr("You must add at least one file to the list before proceeding!")));
1696 ui
->tabWidget
->setCurrentIndex(0);
1700 QString tempFolder
= m_settings
->customTempPathEnabled() ? m_settings
->customTempPath() : MUtils::temp_folder();
1701 if(!QFileInfo(tempFolder
).exists() || !QFileInfo(tempFolder
).isDir())
1703 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)
1705 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabledDefault()));
1710 quint64 currentFreeDiskspace
= 0;
1711 if(MUtils::OS::free_diskspace(tempFolder
, currentFreeDiskspace
))
1713 if(currentFreeDiskspace
< (oneGigabyte
* minimumFreeDiskspaceMultiplier
))
1715 QStringList tempFolderParts
= tempFolder
.split("/", QString::SkipEmptyParts
, Qt::CaseInsensitive
);
1716 tempFolderParts
.takeLast();
1717 PLAY_SOUND_OPTIONAL("whammy", false);
1718 QString lowDiskspaceMsg
= QString("%1<br>%2<br><br>%3<br>%4<br>").arg
1720 NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier
))),
1721 NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")),
1722 NOBR(tr("Your TEMP folder is located at:")),
1723 QString("<nobr><tt>%1</tt></nobr>").arg(FSLINK(tempFolderParts
.join("\\")))
1725 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg
, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1728 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER
)), QStringList() << "/D" << tempFolderParts
.first());
1733 QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!")));
1739 switch(m_settings
->compressionEncoder())
1741 case SettingsModel::MP3Encoder
:
1742 case SettingsModel::VorbisEncoder
:
1743 case SettingsModel::AACEncoder
:
1744 case SettingsModel::AC3Encoder
:
1745 case SettingsModel::FLACEncoder
:
1746 case SettingsModel::OpusEncoder
:
1747 case SettingsModel::DCAEncoder
:
1748 case SettingsModel::MACEncoder
:
1749 case SettingsModel::PCMEncoder
:
1752 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1753 ui
->tabWidget
->setCurrentIndex(3);
1757 if(!m_settings
->outputToSourceDir())
1759 QFile
writeTest(QString("%1/~%2.txt").arg(m_settings
->outputDir(), MUtils::rand_str()));
1760 if(!(writeTest
.open(QIODevice::ReadWrite
) && (writeTest
.write(writeTestBuffer
) == strlen(writeTestBuffer
))))
1762 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!")));
1763 ui
->tabWidget
->setCurrentIndex(1);
1780 void MainWindow::aboutButtonClicked(void)
1783 WidgetHideHelper
hiderHelper(m_dropBox
.data());
1784 QScopedPointer
<AboutDialog
> aboutBox(new AboutDialog(m_settings
, this));
1791 void MainWindow::closeButtonClicked(void)
1797 // =========================================================
1799 // =========================================================
1804 void MainWindow::tabPageChanged(int idx
, const bool silent
)
1808 //Update "view" menu
1809 QList
<QAction
*> actions
= m_tabActionGroup
->actions();
1810 for(int i
= 0; i
< actions
.count(); i
++)
1813 int actionIndex
= actions
.at(i
)->data().toInt(&ok
);
1814 if(ok
&& actionIndex
== idx
)
1816 actions
.at(i
)->setChecked(true);
1823 PLAY_SOUND_OPTIONAL("tick", true);
1826 int initialWidth
= this->width();
1827 int maximumWidth
= QApplication::desktop()->availableGeometry().width();
1829 //Make sure all tab headers are fully visible
1830 if(this->isVisible())
1832 int delta
= ui
->tabWidget
->sizeHint().width() - ui
->tabWidget
->width();
1835 this->resize(qMin(this->width() + delta
, maximumWidth
), this->height());
1839 //Tab specific operations
1840 if(idx
== ui
->tabWidget
->indexOf(ui
->tabOptions
) && ui
->scrollArea
->widget() && this->isVisible())
1842 ui
->scrollArea
->widget()->updateGeometry();
1843 ui
->scrollArea
->viewport()->updateGeometry();
1844 qApp
->processEvents();
1845 int delta
= ui
->scrollArea
->widget()->width() - ui
->scrollArea
->viewport()->width();
1848 this->resize(qMin(this->width() + delta
, maximumWidth
), this->height());
1851 else if(idx
== ui
->tabWidget
->indexOf(ui
->tabSourceFiles
))
1853 m_dropNoteLabel
->setGeometry(0, 0, ui
->sourceFileView
->width(), ui
->sourceFileView
->height());
1855 else if(idx
== ui
->tabWidget
->indexOf(ui
->tabOutputDir
))
1857 if(!m_fileSystemModel
)
1859 QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
1863 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
1867 //Center window around previous position
1868 if(initialWidth
< this->width())
1870 QPoint prevPos
= this->pos();
1871 int delta
= (this->width() - initialWidth
) >> 2;
1872 move(prevPos
.x() - delta
, prevPos
.y());
1877 * Tab action triggered
1879 void MainWindow::tabActionActivated(QAction
*action
)
1881 if(action
&& action
->data().isValid())
1884 int index
= action
->data().toInt(&ok
);
1887 ui
->tabWidget
->setCurrentIndex(index
);
1892 // =========================================================
1894 // =========================================================
1897 * Handle corner widget Event
1899 void MainWindow::cornerWidgetEventOccurred(QWidget
*sender
, QEvent
*event
)
1901 if(event
->type() == QEvent::MouseButtonPress
)
1903 QTimer::singleShot(0, this, SLOT(checkUpdatesActionActivated()));
1907 // =========================================================
1909 // =========================================================
1912 * Style action triggered
1914 void MainWindow::styleActionActivated(QAction
*action
)
1916 //Change style setting
1917 if(action
&& action
->data().isValid())
1920 int actionIndex
= action
->data().toInt(&ok
);
1923 m_settings
->interfaceStyle(actionIndex
);
1927 //Set up the new style
1928 switch(m_settings
->interfaceStyle())
1931 if(ui
->actionStyleCleanlooks
->isEnabled())
1933 ui
->actionStyleCleanlooks
->setChecked(true);
1934 QApplication::setStyle(new QCleanlooksStyle());
1938 if(ui
->actionStyleWindowsVista
->isEnabled())
1940 ui
->actionStyleWindowsVista
->setChecked(true);
1941 QApplication::setStyle(new QWindowsVistaStyle());
1945 if(ui
->actionStyleWindowsXP
->isEnabled())
1947 ui
->actionStyleWindowsXP
->setChecked(true);
1948 QApplication::setStyle(new QWindowsXPStyle());
1952 if(ui
->actionStyleWindowsClassic
->isEnabled())
1954 ui
->actionStyleWindowsClassic
->setChecked(true);
1955 QApplication::setStyle(new QWindowsStyle());
1959 ui
->actionStylePlastique
->setChecked(true);
1960 QApplication::setStyle(new QPlastiqueStyle());
1964 //Force re-translate after style change
1965 if(QEvent
*e
= new QEvent(QEvent::LanguageChange
))
1972 const type_info
&styleType
= typeid(*qApp
->style());
1973 const bool bTransparent
= ((typeid(QWindowsVistaStyle
) == styleType
) || (typeid(QWindowsXPStyle
) == styleType
));
1974 MAKE_TRANSPARENT(ui
->scrollArea
, bTransparent
);
1976 //Also force a re-size event
1977 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
1982 * Language action triggered
1984 void MainWindow::languageActionActivated(QAction
*action
)
1986 if(action
->data().type() == QVariant::String
)
1988 QString langId
= action
->data().toString();
1990 if(MUtils::Translation::install_translator(langId
))
1992 action
->setChecked(true);
1993 ui
->actionLoadTranslationFromFile
->setChecked(false);
1994 m_settings
->currentLanguage(langId
);
1995 m_settings
->currentLanguageFile(QString());
2001 * Load language from file action triggered
2003 void MainWindow::languageFromFileActionActivated(bool checked
)
2005 QFileDialog
dialog(this, tr("Load Translation"));
2006 dialog
.setFileMode(QFileDialog::ExistingFile
);
2007 dialog
.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
2011 QStringList selectedFiles
= dialog
.selectedFiles();
2012 const QString qmFile
= QFileInfo(selectedFiles
.first()).canonicalFilePath();
2013 if(MUtils::Translation::install_translator_from_file(qmFile
))
2015 QList
<QAction
*> actions
= m_languageActionGroup
->actions();
2016 while(!actions
.isEmpty())
2018 actions
.takeFirst()->setChecked(false);
2020 ui
->actionLoadTranslationFromFile
->setChecked(true);
2021 m_settings
->currentLanguageFile(qmFile
);
2025 languageActionActivated(m_languageActionGroup
->actions().first());
2030 // =========================================================
2032 // =========================================================
2035 * Disable update reminder action
2037 void MainWindow::disableUpdateReminderActionTriggered(bool checked
)
2041 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))
2043 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!"))));
2044 m_settings
->autoUpdateEnabled(false);
2048 m_settings
->autoUpdateEnabled(true);
2053 QMessageBox::information(this, tr("Update Reminder"), NOBR(tr("The update reminder has been re-enabled.")));
2054 m_settings
->autoUpdateEnabled(true);
2057 ui
->actionDisableUpdateReminder
->setChecked(!m_settings
->autoUpdateEnabled());
2061 * Disable sound effects action
2063 void MainWindow::disableSoundsActionTriggered(bool checked
)
2067 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))
2069 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("All sound effects have been disabled.")));
2070 m_settings
->soundsEnabled(false);
2074 m_settings
->soundsEnabled(true);
2079 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("The sound effects have been re-enabled.")));
2080 m_settings
->soundsEnabled(true);
2083 ui
->actionDisableSounds
->setChecked(!m_settings
->soundsEnabled());
2087 * Disable Nero AAC encoder action
2089 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked
)
2093 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))
2095 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("All Nero AAC Encoder notifications have been disabled.")));
2096 m_settings
->neroAacNotificationsEnabled(false);
2100 m_settings
->neroAacNotificationsEnabled(true);
2105 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("The Nero AAC Encoder notifications have been re-enabled.")));
2106 m_settings
->neroAacNotificationsEnabled(true);
2109 ui
->actionDisableNeroAacNotifications
->setChecked(!m_settings
->neroAacNotificationsEnabled());
2113 * Disable slow startup action
2115 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked
)
2119 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))
2121 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been disabled.")));
2122 m_settings
->antivirNotificationsEnabled(false);
2126 m_settings
->antivirNotificationsEnabled(true);
2131 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been re-enabled.")));
2132 m_settings
->antivirNotificationsEnabled(true);
2135 ui
->actionDisableSlowStartupNotifications
->setChecked(!m_settings
->antivirNotificationsEnabled());
2139 * Import a Cue Sheet file
2141 void MainWindow::importCueSheetActionTriggered(bool checked
)
2144 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2149 QString selectedCueFile
;
2151 if(MUtils::GUI::themes_enabled())
2153 selectedCueFile
= QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings
->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
2157 QFileDialog
dialog(this, tr("Open Cue Sheet"));
2158 dialog
.setFileMode(QFileDialog::ExistingFile
);
2159 dialog
.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
2160 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2163 selectedCueFile
= dialog
.selectedFiles().first();
2167 if(!selectedCueFile
.isEmpty())
2169 m_settings
->mostRecentInputPath(QFileInfo(selectedCueFile
).canonicalPath());
2170 FileListBlockHelper
fileListBlocker(m_fileListModel
);
2171 QScopedPointer
<CueImportDialog
> cueImporter(new CueImportDialog(this, m_fileListModel
, selectedCueFile
, m_settings
));
2172 result
= cueImporter
->exec();
2177 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2178 ui
->sourceFileView
->update();
2179 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2180 ui
->sourceFileView
->scrollToBottom();
2181 qApp
->processEvents(QEventLoop::ExcludeUserInputEvents
);
2188 * Show the "drop box" widget
2190 void MainWindow::showDropBoxWidgetActionTriggered(bool checked
)
2192 m_settings
->dropBoxWidgetEnabled(true);
2194 if(!m_dropBox
->isVisible())
2197 QTimer::singleShot(2500, m_dropBox
.data(), SLOT(showToolTip()));
2200 MUtils::GUI::blink_window(m_dropBox
.data());
2204 * Check for beta (pre-release) updates
2206 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked
)
2208 bool checkUpdatesNow
= false;
2212 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))
2214 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")))
2216 checkUpdatesNow
= true;
2218 m_settings
->autoUpdateCheckBeta(true);
2222 m_settings
->autoUpdateCheckBeta(false);
2227 QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on.")));
2228 m_settings
->autoUpdateCheckBeta(false);
2231 ui
->actionCheckForBetaUpdates
->setChecked(m_settings
->autoUpdateCheckBeta());
2235 if(checkForUpdates())
2237 QApplication::quit();
2243 * Hibernate computer action
2245 void MainWindow::hibernateComputerActionTriggered(bool checked
)
2249 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))
2251 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will hibernate the computer on shutdown from now on.")));
2252 m_settings
->hibernateComputer(true);
2256 m_settings
->hibernateComputer(false);
2261 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will <i>not</i> hibernate the computer on shutdown from now on.")));
2262 m_settings
->hibernateComputer(false);
2265 ui
->actionHibernateComputer
->setChecked(m_settings
->hibernateComputer());
2269 * Disable shell integration action
2271 void MainWindow::disableShellIntegrationActionTriggered(bool checked
)
2275 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))
2277 ShellIntegration::remove();
2278 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been disabled.")));
2279 m_settings
->shellIntegrationEnabled(false);
2283 m_settings
->shellIntegrationEnabled(true);
2288 ShellIntegration::install();
2289 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been re-enabled.")));
2290 m_settings
->shellIntegrationEnabled(true);
2293 ui
->actionDisableShellIntegration
->setChecked(!m_settings
->shellIntegrationEnabled());
2295 if(lamexp_version_portable() && ui
->actionDisableShellIntegration
->isChecked())
2297 ui
->actionDisableShellIntegration
->setEnabled(false);
2301 // =========================================================
2303 // =========================================================
2306 * Visit homepage action
2308 void MainWindow::visitHomepageActionActivated(void)
2310 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2312 if(action
->data().isValid() && (action
->data().type() == QVariant::String
))
2314 QDesktopServices::openUrl(QUrl(action
->data().toString()));
2322 void MainWindow::documentActionActivated(void)
2324 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2326 openDocumentLink(action
);
2331 * Check for updates action
2333 void MainWindow::checkUpdatesActionActivated(void)
2336 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2338 if(checkForUpdates())
2340 QApplication::quit();
2344 // =========================================================
2345 // Source file slots
2346 // =========================================================
2349 * Add file(s) button
2351 void MainWindow::addFilesButtonClicked(void)
2354 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2356 if(MUtils::GUI::themes_enabled() && (!MUTILS_DEBUG
))
2358 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2359 QStringList selectedFiles
= QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings
->mostRecentInputPath(), fileTypeFilters
.join(";;"));
2360 if(!selectedFiles
.isEmpty())
2362 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2363 addFiles(selectedFiles
);
2368 QFileDialog
dialog(this, tr("Add file(s)"));
2369 QStringList fileTypeFilters
= DecoderRegistry::getSupportedTypes();
2370 dialog
.setFileMode(QFileDialog::ExistingFiles
);
2371 dialog
.setNameFilter(fileTypeFilters
.join(";;"));
2372 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2375 QStringList selectedFiles
= dialog
.selectedFiles();
2376 if(!selectedFiles
.isEmpty())
2378 m_settings
->mostRecentInputPath(QFileInfo(selectedFiles
.first()).canonicalPath());
2379 addFiles(selectedFiles
);
2386 * Open folder action
2388 void MainWindow::openFolderActionActivated(void)
2391 QString selectedFolder
;
2393 if(QAction
*action
= dynamic_cast<QAction
*>(QObject::sender()))
2395 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2396 if(MUtils::GUI::themes_enabled())
2398 selectedFolder
= QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings
->mostRecentInputPath());
2402 QFileDialog
dialog(this, tr("Add Folder"));
2403 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
2404 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2407 selectedFolder
= dialog
.selectedFiles().first();
2411 if(selectedFolder
.isEmpty())
2416 QStringList filterItems
= DecoderRegistry::getSupportedExts();
2417 filterItems
.prepend("*.*");
2420 QString filterStr
= QInputDialog::getItem(this, tr("Filter Files"), tr("Select filename filter:"), filterItems
, 0, false, &okay
).trimmed();
2426 QRegExp
regExp("\\*\\.([A-Za-z0-9]+)", Qt::CaseInsensitive
);
2427 if(regExp
.lastIndexIn(filterStr
) >= 0)
2429 filterStr
= regExp
.cap(1).trimmed();
2436 m_settings
->mostRecentInputPath(QDir(selectedFolder
).canonicalPath());
2437 addFolder(selectedFolder
, action
->data().toBool(), false, filterStr
);
2442 * Remove file button
2444 void MainWindow::removeFileButtonClicked(void)
2446 const QModelIndex current
= ui
->sourceFileView
->currentIndex();
2447 if(current
.isValid())
2449 const QItemSelectionModel
*const selection
= ui
->sourceFileView
->selectionModel();
2450 if(selection
&& selection
->hasSelection())
2452 const QModelIndexList selectedRows
= INVERT_LIST(selection
->selectedRows());
2453 FileListBlockHelper
fileListBlocker(m_fileListModel
);
2454 for(QModelIndexList::ConstIterator iter
= selectedRows
.constBegin(); iter
!= selectedRows
.constEnd(); iter
++)
2456 m_fileListModel
->removeFile(*iter
);
2459 if(m_fileListModel
->rowCount() > 0)
2461 ui
->sourceFileView
->selectRow((current
.row() < m_fileListModel
->rowCount()) ? current
.row() : (m_fileListModel
->rowCount() - 1));
2462 ui
->sourceFileView
->scrollTo(ui
->sourceFileView
->currentIndex());
2467 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
2472 * Clear files button
2474 void MainWindow::clearFilesButtonClicked(void)
2476 m_fileListModel
->clearFiles();
2480 * Move file up button
2482 void MainWindow::fileUpButtonClicked(void)
2484 moveSelectedFiles(true);
2488 * Move file down button
2490 void MainWindow::fileDownButtonClicked(void)
2492 moveSelectedFiles(false);
2496 * Show details button
2498 void MainWindow::showDetailsButtonClicked(void)
2503 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2507 ui
->sourceFileView
->selectRow(index
.row());
2508 QScopedPointer
<MetaInfoDialog
> metaInfoDialog(new MetaInfoDialog(this));
2511 AudioFileModel
&file
= (*m_fileListModel
)[index
];
2512 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2513 iResult
= metaInfoDialog
->exec(file
, index
.row() > 0, index
.row() < m_fileListModel
->rowCount() - 1);
2515 //Copy all info to Meta Info tab
2516 if(iResult
== INT_MAX
)
2518 m_metaInfoModel
->assignInfoFrom(file
);
2519 ui
->tabWidget
->setCurrentIndex(ui
->tabWidget
->indexOf(ui
->tabMetaData
));
2525 index
= m_fileListModel
->index(index
.row() + 1, index
.column());
2526 ui
->sourceFileView
->selectRow(index
.row());
2529 else if(iResult
< 0)
2531 index
= m_fileListModel
->index(index
.row() - 1, index
.column());
2532 ui
->sourceFileView
->selectRow(index
.row());
2536 break; /*close dilalog now*/
2540 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2541 sourceFilesScrollbarMoved(0);
2545 * Show context menu for source files
2547 void MainWindow::sourceFilesContextMenu(const QPoint
&pos
)
2549 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
2550 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
2554 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
2556 m_sourceFilesContextMenu
->popup(sender
->mapToGlobal(pos
));
2562 * Scrollbar of source files moved
2564 void MainWindow::sourceFilesScrollbarMoved(int)
2566 ui
->sourceFileView
->resizeColumnToContents(0);
2570 * Open selected file in external player
2572 void MainWindow::previewContextActionTriggered(void)
2574 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2575 if(!index
.isValid())
2580 if(!MUtils::OS::open_media_file(m_fileListModel
->getFile(index
).filePath()))
2582 qDebug("Player not found, falling back to default application...");
2583 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel
->getFile(index
).filePath()));
2588 * Find selected file in explorer
2590 void MainWindow::findFileContextActionTriggered(void)
2592 QModelIndex index
= ui
->sourceFileView
->currentIndex();
2595 QString systemRootPath
;
2597 QDir
systemRoot(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER
));
2598 if(systemRoot
.exists() && systemRoot
.cdUp())
2600 systemRootPath
= systemRoot
.canonicalPath();
2603 if(!systemRootPath
.isEmpty())
2605 QFileInfo
explorer(QString("%1/explorer.exe").arg(systemRootPath
));
2606 if(explorer
.exists() && explorer
.isFile())
2608 QProcess::execute(explorer
.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel
->getFile(index
).filePath()));
2614 qWarning("SystemRoot directory could not be detected!");
2620 * Add all dropped files
2622 void MainWindow::handleDroppedFiles(void)
2626 static const int MIN_COUNT
= 16;
2627 const QString bannerText
= tr("Loading dropped files or folders, please wait...");
2628 bool bUseBanner
= false;
2630 showBanner(bannerText
, bUseBanner
, (m_droppedFileList
->count() >= MIN_COUNT
));
2632 QStringList droppedFiles
;
2633 while(!m_droppedFileList
->isEmpty())
2635 QFileInfo
file(m_droppedFileList
->takeFirst().toLocalFile());
2636 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents
);
2645 qDebug("Dropped File: %s", MUTILS_UTF8(file
.canonicalFilePath()));
2646 droppedFiles
<< file
.canonicalFilePath();
2652 qDebug("Dropped Folder: %s", MUTILS_UTF8(file
.canonicalFilePath()));
2653 QFileInfoList list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Files
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
);
2654 if(list
.count() > 0)
2656 showBanner(bannerText
, bUseBanner
, (list
.count() >= MIN_COUNT
));
2657 for(QFileInfoList::ConstIterator iter
= list
.constBegin(); iter
!= list
.constEnd(); iter
++)
2659 droppedFiles
<< (*iter
).canonicalFilePath();
2664 list
= QDir(file
.canonicalFilePath()).entryInfoList(QDir::Dirs
| QDir::NoDotAndDotDot
| QDir::NoSymLinks
);
2665 showBanner(bannerText
, bUseBanner
, (list
.count() >= MIN_COUNT
));
2666 for(QFileInfoList::ConstIterator iter
= list
.constBegin(); iter
!= list
.constEnd(); iter
++)
2668 qDebug("Descending to Folder: %s", MUTILS_UTF8((*iter
).canonicalFilePath()));
2669 m_droppedFileList
->prepend(QUrl::fromLocalFile((*iter
).canonicalFilePath()));
2680 if(!droppedFiles
.isEmpty())
2682 addFiles(droppedFiles
);
2687 * Add all pending files
2689 void MainWindow::handleDelayedFiles(void)
2691 m_delayedFileTimer
->stop();
2693 if(m_delayedFileList
->isEmpty())
2700 m_delayedFileTimer
->start(5000);
2704 if(ui
->tabWidget
->currentIndex() != 0)
2706 SignalBlockHelper
signalBlockHelper(ui
->tabWidget
);
2707 ui
->tabWidget
->setCurrentIndex(0);
2708 tabPageChanged(ui
->tabWidget
->currentIndex(), true);
2711 QStringList selectedFiles
;
2712 while(!m_delayedFileList
->isEmpty())
2714 QFileInfo currentFile
= QFileInfo(m_delayedFileList
->takeFirst());
2715 if(!currentFile
.exists() || !currentFile
.isFile())
2719 selectedFiles
<< currentFile
.canonicalFilePath();
2722 addFiles(selectedFiles
);
2726 * Export Meta tags to CSV file
2728 void MainWindow::exportCsvContextActionTriggered(void)
2731 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2733 QString selectedCsvFile
;
2734 if(MUtils::GUI::themes_enabled())
2736 selectedCsvFile
= QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2740 QFileDialog
dialog(this, tr("Save CSV file"));
2741 dialog
.setFileMode(QFileDialog::AnyFile
);
2742 dialog
.setAcceptMode(QFileDialog::AcceptSave
);
2743 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2744 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2747 selectedCsvFile
= dialog
.selectedFiles().first();
2751 if(!selectedCsvFile
.isEmpty())
2753 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2754 switch(m_fileListModel
->exportToCsv(selectedCsvFile
))
2756 case FileListModel::CsvError_NoTags
:
2757 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, there are no meta tags that can be exported!")));
2759 case FileListModel::CsvError_FileOpen
:
2760 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to open CSV file for writing!")));
2762 case FileListModel::CsvError_FileWrite
:
2763 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to write to the CSV file!")));
2765 case FileListModel::CsvError_OK
:
2766 QMessageBox::information(this, tr("CSV Export"), NOBR(tr("The CSV files was created successfully!")));
2769 qWarning("exportToCsv: Unknown return code!");
2776 * Import Meta tags from CSV file
2778 void MainWindow::importCsvContextActionTriggered(void)
2781 WidgetHideHelper
hiderHelper(m_dropBox
.data());
2783 QString selectedCsvFile
;
2784 if(MUtils::GUI::themes_enabled())
2786 selectedCsvFile
= QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings
->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2790 QFileDialog
dialog(this, tr("Open CSV file"));
2791 dialog
.setFileMode(QFileDialog::ExistingFile
);
2792 dialog
.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2793 dialog
.setDirectory(m_settings
->mostRecentInputPath());
2796 selectedCsvFile
= dialog
.selectedFiles().first();
2800 if(!selectedCsvFile
.isEmpty())
2802 m_settings
->mostRecentInputPath(QFileInfo(selectedCsvFile
).canonicalPath());
2803 switch(m_fileListModel
->importFromCsv(this, selectedCsvFile
))
2805 case FileListModel::CsvError_FileOpen
:
2806 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to open CSV file for reading!")));
2808 case FileListModel::CsvError_FileRead
:
2809 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to read from the CSV file!")));
2811 case FileListModel::CsvError_NoTags
:
2812 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, the CSV file does not contain any known fields!")));
2814 case FileListModel::CsvError_Incomplete
:
2815 QMessageBox::warning(this, tr("CSV Import"), NOBR(tr("CSV file is incomplete. Not all files were updated!")));
2817 case FileListModel::CsvError_OK
:
2818 QMessageBox::information(this, tr("CSV Import"), NOBR(tr("The CSV files was imported successfully!")));
2820 case FileListModel::CsvError_Aborted
:
2821 /* User aborted, ignore! */
2824 qWarning("exportToCsv: Unknown return code!");
2830 * Show or hide Drag'n'Drop notice after model reset
2832 void MainWindow::sourceModelChanged(void)
2834 m_dropNoteLabel
->setVisible(m_fileListModel
->rowCount() <= 0);
2837 // =========================================================
2838 // Output folder slots
2839 // =========================================================
2842 * Output folder changed (mouse clicked)
2844 void MainWindow::outputFolderViewClicked(const QModelIndex
&index
)
2846 if(index
.isValid() && (ui
->outputFolderView
->currentIndex() != index
))
2848 ui
->outputFolderView
->setCurrentIndex(index
);
2851 if(m_fileSystemModel
&& index
.isValid())
2853 QString selectedDir
= m_fileSystemModel
->filePath(index
);
2854 if(selectedDir
.length() < 3) selectedDir
.append(QDir::separator());
2855 ui
->outputFolderLabel
->setText(QDir::toNativeSeparators(selectedDir
));
2856 ui
->outputFolderLabel
->setToolTip(ui
->outputFolderLabel
->text());
2857 m_settings
->outputDir(selectedDir
);
2861 ui
->outputFolderLabel
->setText(QDir::toNativeSeparators(m_settings
->outputDir()));
2862 ui
->outputFolderLabel
->setToolTip(ui
->outputFolderLabel
->text());
2867 * Output folder changed (mouse moved)
2869 void MainWindow::outputFolderViewMoved(const QModelIndex
&index
)
2871 if(QApplication::mouseButtons() & Qt::LeftButton
)
2873 outputFolderViewClicked(index
);
2878 * Goto desktop button
2880 void MainWindow::gotoDesktopButtonClicked(void)
2882 if(!m_fileSystemModel
)
2884 qWarning("File system model not initialized yet!");
2888 QString desktopPath
= QDesktopServices::storageLocation(QDesktopServices::DesktopLocation
);
2890 if(!desktopPath
.isEmpty() && QDir(desktopPath
).exists())
2892 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(desktopPath
));
2893 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2894 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2898 ui
->buttonGotoDesktop
->setEnabled(false);
2903 * Goto home folder button
2905 void MainWindow::gotoHomeFolderButtonClicked(void)
2907 if(!m_fileSystemModel
)
2909 qWarning("File system model not initialized yet!");
2913 QString homePath
= QDesktopServices::storageLocation(QDesktopServices::HomeLocation
);
2915 if(!homePath
.isEmpty() && QDir(homePath
).exists())
2917 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(homePath
));
2918 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2919 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2923 ui
->buttonGotoHome
->setEnabled(false);
2928 * Goto music folder button
2930 void MainWindow::gotoMusicFolderButtonClicked(void)
2932 if(!m_fileSystemModel
)
2934 qWarning("File system model not initialized yet!");
2938 QString musicPath
= QDesktopServices::storageLocation(QDesktopServices::MusicLocation
);
2940 if(!musicPath
.isEmpty() && QDir(musicPath
).exists())
2942 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(musicPath
));
2943 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2944 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2948 ui
->buttonGotoMusic
->setEnabled(false);
2953 * Goto music favorite output folder
2955 void MainWindow::gotoFavoriteFolder(void)
2957 if(!m_fileSystemModel
)
2959 qWarning("File system model not initialized yet!");
2963 QAction
*item
= dynamic_cast<QAction
*>(QObject::sender());
2967 QDir
path(item
->data().toString());
2970 ui
->outputFolderView
->setCurrentIndex(m_fileSystemModel
->index(path
.canonicalPath()));
2971 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
2972 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
2976 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
2977 m_outputFolderFavoritesMenu
->removeAction(item
);
2978 item
->deleteLater();
2984 * Make folder button
2986 void MainWindow::makeFolderButtonClicked(void)
2990 if(!m_fileSystemModel
)
2992 qWarning("File system model not initialized yet!");
2996 QDir
basePath(m_fileSystemModel
->fileInfo(ui
->outputFolderView
->currentIndex()).absoluteFilePath());
2997 QString suggestedName
= tr("New Folder");
2999 if(!m_metaData
->artist().isEmpty() && !m_metaData
->album().isEmpty())
3001 suggestedName
= QString("%1 - %2").arg(m_metaData
->artist(),m_metaData
->album());
3003 else if(!m_metaData
->artist().isEmpty())
3005 suggestedName
= m_metaData
->artist();
3007 else if(!m_metaData
->album().isEmpty())
3009 suggestedName
=m_metaData
->album();
3013 for(int i
= 0; i
< m_fileListModel
->rowCount(); i
++)
3015 const AudioFileModel
&audioFile
= m_fileListModel
->getFile(m_fileListModel
->index(i
, 0));
3016 const AudioFileModel_MetaInfo
&fileMetaInfo
= audioFile
.metaInfo();
3018 if(!fileMetaInfo
.album().isEmpty() || !fileMetaInfo
.artist().isEmpty())
3020 if(!fileMetaInfo
.artist().isEmpty() && !fileMetaInfo
.album().isEmpty())
3022 suggestedName
= QString("%1 - %2").arg(fileMetaInfo
.artist(), fileMetaInfo
.album());
3024 else if(!fileMetaInfo
.artist().isEmpty())
3026 suggestedName
= fileMetaInfo
.artist();
3028 else if(!fileMetaInfo
.album().isEmpty())
3030 suggestedName
= fileMetaInfo
.album();
3037 suggestedName
= MUtils::clean_file_name(suggestedName
);
3041 bool bApplied
= false;
3042 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();
3046 folderName
= MUtils::clean_file_path(folderName
.simplified());
3048 if(folderName
.isEmpty())
3050 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
3055 QString newFolder
= folderName
;
3057 while(basePath
.exists(newFolder
))
3059 newFolder
= QString(folderName
).append(QString().sprintf(" (%d)", ++i
));
3062 if(basePath
.mkpath(newFolder
))
3064 QDir createdDir
= basePath
;
3065 if(createdDir
.cd(newFolder
))
3067 QModelIndex newIndex
= m_fileSystemModel
->index(createdDir
.canonicalPath());
3068 ui
->outputFolderView
->setCurrentIndex(newIndex
);
3069 outputFolderViewClicked(newIndex
);
3070 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3075 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!")));
3083 * Output to source dir changed
3085 void MainWindow::saveToSourceFolderChanged(void)
3087 m_settings
->outputToSourceDir(ui
->saveToSourceFolderCheckBox
->isChecked());
3091 * Prepend relative source file path to output file name changed
3093 void MainWindow::prependRelativePathChanged(void)
3095 m_settings
->prependRelativeSourcePath(ui
->prependRelativePathCheckBox
->isChecked());
3099 * Show context menu for output folder
3101 void MainWindow::outputFolderContextMenu(const QPoint
&pos
)
3103 QAbstractScrollArea
*scrollArea
= dynamic_cast<QAbstractScrollArea
*>(QObject::sender());
3104 QWidget
*sender
= scrollArea
? scrollArea
->viewport() : dynamic_cast<QWidget
*>(QObject::sender());
3106 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0)
3108 m_outputFolderContextMenu
->popup(sender
->mapToGlobal(pos
));
3113 * Show selected folder in explorer
3115 void MainWindow::showFolderContextActionTriggered(void)
3117 if(!m_fileSystemModel
)
3119 qWarning("File system model not initialized yet!");
3123 QString path
= QDir::toNativeSeparators(m_fileSystemModel
->filePath(ui
->outputFolderView
->currentIndex()));
3124 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
3125 MUtils::OS::shell_open(this, path
, true);
3129 * Refresh the directory outline
3131 void MainWindow::refreshFolderContextActionTriggered(void)
3133 //force re-initialization
3134 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
3138 * Go one directory up
3140 void MainWindow::goUpFolderContextActionTriggered(void)
3142 QModelIndex current
= ui
->outputFolderView
->currentIndex();
3143 if(current
.isValid())
3145 QModelIndex parent
= current
.parent();
3146 if(parent
.isValid())
3149 ui
->outputFolderView
->setCurrentIndex(parent
);
3150 outputFolderViewClicked(parent
);
3154 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
3156 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3161 * Add current folder to favorites
3163 void MainWindow::addFavoriteFolderActionTriggered(void)
3165 QString path
= m_fileSystemModel
->filePath(ui
->outputFolderView
->currentIndex());
3166 QStringList favorites
= m_settings
->favoriteOutputFolders().split("|", QString::SkipEmptyParts
);
3168 if(!favorites
.contains(path
, Qt::CaseInsensitive
))
3170 favorites
.append(path
);
3171 while(favorites
.count() > 6) favorites
.removeFirst();
3175 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN
);
3178 m_settings
->favoriteOutputFolders(favorites
.join("|"));
3183 * Output folder edit finished
3185 void MainWindow::outputFolderEditFinished(void)
3187 if(ui
->outputFolderEdit
->isHidden())
3189 return; //Not currently in edit mode!
3194 QString text
= QDir::fromNativeSeparators(ui
->outputFolderEdit
->text().trimmed());
3195 while(text
.startsWith('"') || text
.startsWith('/')) text
= text
.right(text
.length() - 1).trimmed();
3196 while(text
.endsWith('"') || text
.endsWith('/')) text
= text
.left(text
.length() - 1).trimmed();
3198 static const char *str
= "?*<>|\"";
3199 for(size_t i
= 0; str
[i
]; i
++) text
.replace(str
[i
], "_");
3201 if(!((text
.length() >= 2) && text
.at(0).isLetter() && text
.at(1) == QChar(':')))
3203 text
= QString("%1/%2").arg(QDir::fromNativeSeparators(ui
->outputFolderLabel
->text()), text
);
3206 if(text
.length() == 2) text
+= "/"; /* "X:" => "X:/" */
3208 while(text
.length() > 2)
3210 QFileInfo
info(text
);
3211 if(info
.exists() && info
.isDir())
3213 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalFilePath()).absoluteFilePath());
3217 ui
->outputFolderView
->setCurrentIndex(index
);
3218 outputFolderViewClicked(index
);
3222 else if(info
.exists() && info
.isFile())
3224 QModelIndex index
= m_fileSystemModel
->index(QFileInfo(info
.canonicalPath()).absoluteFilePath());
3228 ui
->outputFolderView
->setCurrentIndex(index
);
3229 outputFolderViewClicked(index
);
3234 text
= text
.left(text
.length() - 1).trimmed();
3237 ui
->outputFolderEdit
->setVisible(false);
3238 ui
->outputFolderLabel
->setVisible(true);
3239 ui
->outputFolderView
->setEnabled(true);
3241 if(!ok
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
3242 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3246 * Initialize file system model
3248 void MainWindow::initOutputFolderModel(void)
3250 if(m_outputFolderNoteBox
->isHidden())
3252 m_outputFolderNoteBox
->show();
3253 m_outputFolderNoteBox
->repaint();
3254 m_outputFolderViewInitCounter
= 4;
3256 if(m_fileSystemModel
)
3258 SET_MODEL(ui
->outputFolderView
, NULL
);
3259 ui
->outputFolderView
->repaint();
3262 m_fileSystemModel
.reset(new QFileSystemModelEx());
3263 if(!m_fileSystemModel
.isNull())
3265 m_fileSystemModel
->installEventFilter(this);
3266 connect(m_fileSystemModel
.data(), SIGNAL(directoryLoaded(QString
)), this, SLOT(outputFolderDirectoryLoaded(QString
)));
3267 connect(m_fileSystemModel
.data(), SIGNAL(rowsInserted(QModelIndex
,int,int)), this, SLOT(outputFolderRowsInserted(QModelIndex
,int,int)));
3269 SET_MODEL(ui
->outputFolderView
, m_fileSystemModel
.data());
3270 ui
->outputFolderView
->header()->setStretchLastSection(true);
3271 ui
->outputFolderView
->header()->hideSection(1);
3272 ui
->outputFolderView
->header()->hideSection(2);
3273 ui
->outputFolderView
->header()->hideSection(3);
3275 m_fileSystemModel
->setRootPath("");
3276 QModelIndex index
= m_fileSystemModel
->index(m_settings
->outputDir());
3277 if(index
.isValid()) ui
->outputFolderView
->setCurrentIndex(index
);
3278 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3281 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3282 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3287 * Initialize file system model (do NOT call this one directly!)
3289 void MainWindow::initOutputFolderModel_doAsync(void)
3291 if(m_outputFolderViewInitCounter
> 0)
3293 m_outputFolderViewInitCounter
--;
3294 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3298 QTimer::singleShot(125, m_outputFolderNoteBox
.data(), SLOT(hide()));
3299 ui
->outputFolderView
->setFocus();
3304 * Center current folder in view
3306 void MainWindow::centerOutputFolderModel(void)
3308 if(ui
->outputFolderView
->isVisible())
3310 centerOutputFolderModel_doAsync();
3311 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel_doAsync()));
3316 * Center current folder in view (do NOT call this one directly!)
3318 void MainWindow::centerOutputFolderModel_doAsync(void)
3320 if(ui
->outputFolderView
->isVisible())
3322 m_outputFolderViewCentering
= true;
3323 const QModelIndex index
= ui
->outputFolderView
->currentIndex();
3324 ui
->outputFolderView
->scrollTo(index
, QAbstractItemView::PositionAtCenter
);
3325 ui
->outputFolderView
->setFocus();
3330 * File system model asynchronously loaded a dir
3332 void MainWindow::outputFolderDirectoryLoaded(const QString
&path
)
3334 if(m_outputFolderViewCentering
)
3336 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3341 * File system model inserted new items
3343 void MainWindow::outputFolderRowsInserted(const QModelIndex
&parent
, int start
, int end
)
3345 if(m_outputFolderViewCentering
)
3347 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED
;
3352 * Directory view item was expanded by user
3354 void MainWindow::outputFolderItemExpanded(const QModelIndex
&item
)
3356 //We need to stop centering as soon as the user has expanded an item manually!
3357 m_outputFolderViewCentering
= false;
3361 * View event for output folder control occurred
3363 void MainWindow::outputFolderViewEventOccurred(QWidget
*sender
, QEvent
*event
)
3365 switch(event
->type())
3369 case QEvent::KeyPress
:
3370 case QEvent::KeyRelease
:
3371 case QEvent::FocusIn
:
3372 case QEvent::FocusOut
:
3373 case QEvent::TouchEnd
:
3374 outputFolderViewClicked(ui
->outputFolderView
->currentIndex());
3380 * Mouse event for output folder control occurred
3382 void MainWindow::outputFolderMouseEventOccurred(QWidget
*sender
, QEvent
*event
)
3384 QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
);
3385 QPoint pos
= (mouseEvent
) ? mouseEvent
->pos() : QPoint();
3387 if(sender
== ui
->outputFolderLabel
)
3389 switch(event
->type())
3391 case QEvent::MouseButtonPress
:
3392 if(mouseEvent
&& (mouseEvent
->button() == Qt::LeftButton
))
3394 QString path
= ui
->outputFolderLabel
->text();
3395 if(!path
.endsWith(QDir::separator())) path
.append(QDir::separator());
3396 MUtils::OS::shell_open(this, path
, true);
3400 ui
->outputFolderLabel
->setForegroundRole(QPalette::Link
);
3403 ui
->outputFolderLabel
->setForegroundRole(QPalette::WindowText
);
3408 if((sender
== ui
->outputFoldersFovoritesLabel
) || (sender
== ui
->outputFoldersEditorLabel
) || (sender
== ui
->outputFoldersGoUpLabel
))
3410 const type_info
&styleType
= typeid(*qApp
->style());
3411 if((typeid(QPlastiqueStyle
) == styleType
) || (typeid(QWindowsStyle
) == styleType
))
3413 switch(event
->type())
3416 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Raised
: QFrame::Plain
);
3418 case QEvent::MouseButtonPress
:
3419 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Sunken
: QFrame::Plain
);
3421 case QEvent::MouseButtonRelease
:
3422 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Raised
: QFrame::Plain
);
3425 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(ui
->outputFolderView
->isEnabled() ? QFrame::Plain
: QFrame::Plain
);
3431 dynamic_cast<QLabel
*>(sender
)->setFrameShadow(QFrame::Plain
);
3434 if((event
->type() == QEvent::MouseButtonRelease
) && ui
->outputFolderView
->isEnabled() && (mouseEvent
))
3436 if(pos
.x() <= sender
->width() && pos
.y() <= sender
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
)
3438 if(sender
== ui
->outputFoldersFovoritesLabel
)
3440 m_outputFolderFavoritesMenu
->popup(sender
->mapToGlobal(pos
));
3442 else if(sender
== ui
->outputFoldersEditorLabel
)
3444 ui
->outputFolderView
->setEnabled(false);
3445 ui
->outputFolderLabel
->setVisible(false);
3446 ui
->outputFolderEdit
->setVisible(true);
3447 ui
->outputFolderEdit
->setText(ui
->outputFolderLabel
->text());
3448 ui
->outputFolderEdit
->selectAll();
3449 ui
->outputFolderEdit
->setFocus();
3451 else if(sender
== ui
->outputFoldersGoUpLabel
)
3453 QTimer::singleShot(0, this, SLOT(goUpFolderContextActionTriggered()));
3457 MUTILS_THROW("Oups, this is not supposed to happen!");
3464 // =========================================================
3465 // Metadata tab slots
3466 // =========================================================
3469 * Edit meta button clicked
3471 void MainWindow::editMetaButtonClicked(void)
3475 const QModelIndex index
= ui
->metaDataView
->currentIndex();
3479 m_metaInfoModel
->editItem(index
, this);
3481 if(index
.row() == 4)
3483 m_settings
->metaInfoPosition(m_metaData
->position());
3489 * Reset meta button clicked
3491 void MainWindow::clearMetaButtonClicked(void)
3494 m_metaInfoModel
->clearData();
3498 * Meta tags enabled changed
3500 void MainWindow::metaTagsEnabledChanged(void)
3502 m_settings
->writeMetaTags(ui
->writeMetaDataCheckBox
->isChecked());
3506 * Playlist enabled changed
3508 void MainWindow::playlistEnabledChanged(void)
3510 m_settings
->createPlaylist(ui
->generatePlaylistCheckBox
->isChecked());
3513 // =========================================================
3514 // Compression tab slots
3515 // =========================================================
3520 void MainWindow::updateEncoder(int id
)
3522 /*qWarning("\nupdateEncoder(%d)", id);*/
3524 m_settings
->compressionEncoder(id
);
3525 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(id
);
3527 //Update UI controls
3528 ui
->radioButtonModeQuality
->setEnabled(info
->isModeSupported(SettingsModel::VBRMode
));
3529 ui
->radioButtonModeAverageBitrate
->setEnabled(info
->isModeSupported(SettingsModel::ABRMode
));
3530 ui
->radioButtonConstBitrate
->setEnabled(info
->isModeSupported(SettingsModel::CBRMode
));
3532 //Initialize checkbox state
3533 if(ui
->radioButtonModeQuality
->isEnabled()) ui
->radioButtonModeQuality
->setChecked(true);
3534 else if(ui
->radioButtonModeAverageBitrate
->isEnabled()) ui
->radioButtonModeAverageBitrate
->setChecked(true);
3535 else if(ui
->radioButtonConstBitrate
->isEnabled()) ui
->radioButtonConstBitrate
->setChecked(true);
3536 else MUTILS_THROW("It appears that the encoder does not support *any* RC mode!");
3538 //Apply current RC mode
3539 const int currentRCMode
= EncoderRegistry::loadEncoderMode(m_settings
, id
);
3540 switch(currentRCMode
)
3542 case SettingsModel::VBRMode
: if(ui
->radioButtonModeQuality
->isEnabled()) ui
->radioButtonModeQuality
->setChecked(true); break;
3543 case SettingsModel::ABRMode
: if(ui
->radioButtonModeAverageBitrate
->isEnabled()) ui
->radioButtonModeAverageBitrate
->setChecked(true); break;
3544 case SettingsModel::CBRMode
: if(ui
->radioButtonConstBitrate
->isEnabled()) ui
->radioButtonConstBitrate
->setChecked(true); break;
3545 default: MUTILS_THROW("updateEncoder(): Unknown rc-mode encountered!");
3548 //Display encoder description
3549 if(const char* description
= info
->description())
3551 ui
->labelEncoderInfo
->setVisible(true);
3552 ui
->labelEncoderInfo
->setText(tr("Current Encoder: %1").arg(QString::fromUtf8(description
)));
3556 ui
->labelEncoderInfo
->setVisible(false);
3560 updateRCMode(m_modeButtonGroup
->checkedId());
3564 * Update rate-control mode
3566 void MainWindow::updateRCMode(int id
)
3568 /*qWarning("updateRCMode(%d)", id);*/
3571 const int currentEncoder
= m_encoderButtonGroup
->checkedId();
3572 EncoderRegistry::saveEncoderMode(m_settings
, currentEncoder
, id
);
3574 //Fetch encoder info
3575 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(currentEncoder
);
3576 const int valueCount
= info
->valueCount(id
);
3579 if(!info
->isModeSupported(id
))
3581 qWarning("Attempting to use an unsupported RC mode (%d) with current encoder (%d)!", id
, currentEncoder
);
3582 ui
->labelBitrate
->setText("(ERROR)");
3586 //Update slider min/max values
3589 SignalBlockHelper
signalBlockHelper(ui
->sliderBitrate
);
3590 ui
->sliderBitrate
->setEnabled(true);
3591 ui
->sliderBitrate
->setMinimum(0);
3592 ui
->sliderBitrate
->setMaximum(valueCount
-1);
3596 SignalBlockHelper
signalBlockHelper(ui
->sliderBitrate
);
3597 ui
->sliderBitrate
->setEnabled(false);
3598 ui
->sliderBitrate
->setMinimum(0);
3599 ui
->sliderBitrate
->setMaximum(2);
3602 //Now update bitrate/quality value!
3605 const int currentValue
= EncoderRegistry::loadEncoderValue(m_settings
, currentEncoder
, id
);
3606 ui
->sliderBitrate
->setValue(qBound(0, currentValue
, valueCount
-1));
3607 updateBitrate(qBound(0, currentValue
, valueCount
-1));
3611 ui
->sliderBitrate
->setValue(1);
3619 void MainWindow::updateBitrate(int value
)
3621 /*qWarning("updateBitrate(%d)", value);*/
3623 //Load current encoder and RC mode
3624 const int currentEncoder
= m_encoderButtonGroup
->checkedId();
3625 const int currentRCMode
= m_modeButtonGroup
->checkedId();
3627 //Fetch encoder info
3628 const AbstractEncoderInfo
*info
= EncoderRegistry::getEncoderInfo(currentEncoder
);
3629 const int valueCount
= info
->valueCount(currentRCMode
);
3632 if(!info
->isModeSupported(currentRCMode
))
3634 qWarning("Attempting to use an unsupported RC mode (%d) with current encoder (%d)!", currentRCMode
, currentEncoder
);
3635 ui
->labelBitrate
->setText("(ERROR)");
3639 //Store new bitrate value
3642 EncoderRegistry::saveEncoderValue(m_settings
, currentEncoder
, currentRCMode
, qBound(0, value
, valueCount
-1));
3645 //Update bitrate value
3646 const int displayValue
= (valueCount
> 0) ? info
->valueAt(currentRCMode
, qBound(0, value
, valueCount
-1)) : INT_MAX
;
3647 switch(info
->valueType(currentRCMode
))
3649 case AbstractEncoderInfo::TYPE_BITRATE
:
3650 ui
->labelBitrate
->setText(QString("%1 kbps").arg(QString::number(displayValue
)));
3652 case AbstractEncoderInfo::TYPE_APPROX_BITRATE
:
3653 ui
->labelBitrate
->setText(QString("≈ %1 kbps").arg(QString::number(displayValue
)));
3655 case AbstractEncoderInfo::TYPE_QUALITY_LEVEL_INT
:
3656 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(QString::number(displayValue
)));
3658 case AbstractEncoderInfo::TYPE_QUALITY_LEVEL_FLT
:
3659 ui
->labelBitrate
->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", double(displayValue
)/100.0)));
3661 case AbstractEncoderInfo::TYPE_COMPRESSION_LEVEL
:
3662 ui
->labelBitrate
->setText(tr("Compression %1").arg(QString::number(displayValue
)));
3664 case AbstractEncoderInfo::TYPE_UNCOMPRESSED
:
3665 ui
->labelBitrate
->setText(tr("Uncompressed"));
3668 MUTILS_THROW("Unknown display value type encountered!");
3674 * Event for compression tab occurred
3676 void MainWindow::compressionTabEventOccurred(QWidget
*sender
, QEvent
*event
)
3678 static const QUrl
helpUrl("http://lamexp.sourceforge.net/doc/FAQ.html#054010d9");
3680 if((sender
== ui
->labelCompressionHelp
) && (event
->type() == QEvent::MouseButtonPress
))
3682 QDesktopServices::openUrl(helpUrl
);
3684 else if((sender
== ui
->labelResetEncoders
) && (event
->type() == QEvent::MouseButtonPress
))
3686 PLAY_SOUND_OPTIONAL("blast", true);
3687 EncoderRegistry::resetAllEncoders(m_settings
);
3688 m_settings
->compressionEncoder(SettingsModel::MP3Encoder
);
3689 ui
->radioButtonEncoderMP3
->setChecked(true);
3690 QTimer::singleShot(0, this, SLOT(updateEncoder()));
3694 // =========================================================
3695 // Advanced option slots
3696 // =========================================================
3699 * Lame algorithm quality changed
3701 void MainWindow::updateLameAlgoQuality(int value
)
3708 text
= tr("Best Quality (Slow)");
3711 text
= tr("High Quality (Recommended)");
3714 text
= tr("Acceptable Quality (Fast)");
3717 text
= tr("Poor Quality (Very Fast)");
3723 m_settings
->lameAlgoQuality(value
);
3724 ui
->labelLameAlgoQuality
->setText(text
);
3727 bool warning
= (value
== 0), notice
= (value
== 3);
3728 ui
->labelLameAlgoQualityWarning
->setVisible(warning
);
3729 ui
->labelLameAlgoQualityWarningIcon
->setVisible(warning
);
3730 ui
->labelLameAlgoQualityNotice
->setVisible(notice
);
3731 ui
->labelLameAlgoQualityNoticeIcon
->setVisible(notice
);
3732 ui
->labelLameAlgoQualitySpacer
->setVisible(warning
|| notice
);
3736 * Bitrate management endabled/disabled
3738 void MainWindow::bitrateManagementEnabledChanged(bool checked
)
3740 m_settings
->bitrateManagementEnabled(checked
);
3744 * Minimum bitrate has changed
3746 void MainWindow::bitrateManagementMinChanged(int value
)
3748 if(value
> ui
->spinBoxBitrateManagementMax
->value())
3750 ui
->spinBoxBitrateManagementMin
->setValue(ui
->spinBoxBitrateManagementMax
->value());
3751 m_settings
->bitrateManagementMinRate(ui
->spinBoxBitrateManagementMax
->value());
3755 m_settings
->bitrateManagementMinRate(value
);
3760 * Maximum bitrate has changed
3762 void MainWindow::bitrateManagementMaxChanged(int value
)
3764 if(value
< ui
->spinBoxBitrateManagementMin
->value())
3766 ui
->spinBoxBitrateManagementMax
->setValue(ui
->spinBoxBitrateManagementMin
->value());
3767 m_settings
->bitrateManagementMaxRate(ui
->spinBoxBitrateManagementMin
->value());
3771 m_settings
->bitrateManagementMaxRate(value
);
3776 * Channel mode has changed
3778 void MainWindow::channelModeChanged(int value
)
3780 if(value
>= 0) m_settings
->lameChannelMode(value
);
3784 * Sampling rate has changed
3786 void MainWindow::samplingRateChanged(int value
)
3788 if(value
>= 0) m_settings
->samplingRate(value
);
3792 * Nero AAC 2-Pass mode changed
3794 void MainWindow::neroAAC2PassChanged(bool checked
)
3796 m_settings
->neroAACEnable2Pass(checked
);
3800 * Nero AAC profile mode changed
3802 void MainWindow::neroAACProfileChanged(int value
)
3804 if(value
>= 0) m_settings
->aacEncProfile(value
);
3808 * Aften audio coding mode changed
3810 void MainWindow::aftenCodingModeChanged(int value
)
3812 if(value
>= 0) m_settings
->aftenAudioCodingMode(value
);
3816 * Aften DRC mode changed
3818 void MainWindow::aftenDRCModeChanged(int value
)
3820 if(value
>= 0) m_settings
->aftenDynamicRangeCompression(value
);
3824 * Aften exponent search size changed
3826 void MainWindow::aftenSearchSizeChanged(int value
)
3828 if(value
>= 0) m_settings
->aftenExponentSearchSize(value
);
3832 * Aften fast bit allocation changed
3834 void MainWindow::aftenFastAllocationChanged(bool checked
)
3836 m_settings
->aftenFastBitAllocation(checked
);
3841 * Opus encoder settings changed
3843 void MainWindow::opusSettingsChanged(void)
3845 m_settings
->opusFramesize(ui
->comboBoxOpusFramesize
->currentIndex());
3846 m_settings
->opusComplexity(ui
->spinBoxOpusComplexity
->value());
3847 m_settings
->opusDisableResample(ui
->checkBoxOpusDisableResample
->isChecked());
3851 * Normalization filter enabled changed
3853 void MainWindow::normalizationEnabledChanged(bool checked
)
3855 m_settings
->normalizationFilterEnabled(checked
);
3856 normalizationDynamicChanged(ui
->checkBoxNormalizationFilterDynamic
->isChecked());
3860 * Dynamic normalization enabled changed
3862 void MainWindow::normalizationDynamicChanged(bool checked
)
3864 ui
->spinBoxNormalizationFilterSize
->setEnabled(ui
->checkBoxNormalizationFilterEnabled
->isChecked() && checked
);
3865 m_settings
->normalizationFilterDynamic(checked
);
3869 * Normalization max. volume changed
3871 void MainWindow::normalizationMaxVolumeChanged(double value
)
3873 m_settings
->normalizationFilterMaxVolume(static_cast<int>(value
* 100.0));
3877 * Normalization equalization mode changed
3879 void MainWindow::normalizationCoupledChanged(bool checked
)
3881 m_settings
->normalizationFilterCoupled(checked
);
3885 * Normalization filter size changed
3887 void MainWindow::normalizationFilterSizeChanged(int value
)
3889 m_settings
->normalizationFilterSize(value
);
3893 * Normalization filter size editing finished
3895 void MainWindow::normalizationFilterSizeFinished(void)
3897 const int value
= ui
->spinBoxNormalizationFilterSize
->value();
3898 if((value
% 2) != 1)
3900 bool rnd
= MUtils::parity(MUtils::next_rand32());
3901 ui
->spinBoxNormalizationFilterSize
->setValue(rnd
? value
+1 : value
-1);
3906 * Tone adjustment has changed (Bass)
3908 void MainWindow::toneAdjustBassChanged(double value
)
3910 m_settings
->toneAdjustBass(static_cast<int>(value
* 100.0));
3911 ui
->spinBoxToneAdjustBass
->setPrefix((value
> 0) ? "+" : QString());
3915 * Tone adjustment has changed (Treble)
3917 void MainWindow::toneAdjustTrebleChanged(double value
)
3919 m_settings
->toneAdjustTreble(static_cast<int>(value
* 100.0));
3920 ui
->spinBoxToneAdjustTreble
->setPrefix((value
> 0) ? "+" : QString());
3924 * Tone adjustment has been reset
3926 void MainWindow::toneAdjustTrebleReset(void)
3928 ui
->spinBoxToneAdjustBass
->setValue(m_settings
->toneAdjustBassDefault());
3929 ui
->spinBoxToneAdjustTreble
->setValue(m_settings
->toneAdjustTrebleDefault());
3930 toneAdjustBassChanged(ui
->spinBoxToneAdjustBass
->value());
3931 toneAdjustTrebleChanged(ui
->spinBoxToneAdjustTreble
->value());
3935 * Custom encoder parameters changed
3937 void MainWindow::customParamsChanged(void)
3939 ui
->lineEditCustomParamLAME
->setText(ui
->lineEditCustomParamLAME
->text().simplified());
3940 ui
->lineEditCustomParamOggEnc
->setText(ui
->lineEditCustomParamOggEnc
->text().simplified());
3941 ui
->lineEditCustomParamNeroAAC
->setText(ui
->lineEditCustomParamNeroAAC
->text().simplified());
3942 ui
->lineEditCustomParamFLAC
->setText(ui
->lineEditCustomParamFLAC
->text().simplified());
3943 ui
->lineEditCustomParamAften
->setText(ui
->lineEditCustomParamAften
->text().simplified());
3944 ui
->lineEditCustomParamOpus
->setText(ui
->lineEditCustomParamOpus
->text().simplified());
3946 bool customParamsUsed
= false;
3947 if(!ui
->lineEditCustomParamLAME
->text().isEmpty()) customParamsUsed
= true;
3948 if(!ui
->lineEditCustomParamOggEnc
->text().isEmpty()) customParamsUsed
= true;
3949 if(!ui
->lineEditCustomParamNeroAAC
->text().isEmpty()) customParamsUsed
= true;
3950 if(!ui
->lineEditCustomParamFLAC
->text().isEmpty()) customParamsUsed
= true;
3951 if(!ui
->lineEditCustomParamAften
->text().isEmpty()) customParamsUsed
= true;
3952 if(!ui
->lineEditCustomParamOpus
->text().isEmpty()) customParamsUsed
= true;
3954 ui
->labelCustomParamsIcon
->setVisible(customParamsUsed
);
3955 ui
->labelCustomParamsText
->setVisible(customParamsUsed
);
3956 ui
->labelCustomParamsSpacer
->setVisible(customParamsUsed
);
3958 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::MP3Encoder
, ui
->lineEditCustomParamLAME
->text());
3959 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::VorbisEncoder
, ui
->lineEditCustomParamOggEnc
->text());
3960 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::AACEncoder
, ui
->lineEditCustomParamNeroAAC
->text());
3961 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::FLACEncoder
, ui
->lineEditCustomParamFLAC
->text());
3962 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::AC3Encoder
, ui
->lineEditCustomParamAften
->text());
3963 EncoderRegistry::saveEncoderCustomParams(m_settings
, SettingsModel::OpusEncoder
, ui
->lineEditCustomParamOpus
->text());
3967 * One of the rename buttons has been clicked
3969 void MainWindow::renameButtonClicked(bool checked
)
3971 if(QPushButton
*const button
= dynamic_cast<QPushButton
*>(QObject::sender()))
3973 QWidget
*pages
[] = { ui
->pageRename_Rename
, ui
->pageRename_RegExp
, ui
->pageRename_FileEx
};
3974 QPushButton
*buttons
[] = { ui
->buttonRename_Rename
, ui
->buttonRename_RegExp
, ui
->buttonRename_FileEx
};
3975 for(int i
= 0; i
< 3; i
++)
3977 const bool match
= (button
== buttons
[i
]);
3978 buttons
[i
]->setChecked(match
);
3979 if(match
&& checked
) ui
->stackedWidget
->setCurrentWidget(pages
[i
]);
3985 * Rename output files enabled changed
3987 void MainWindow::renameOutputEnabledChanged(const bool &checked
)
3989 m_settings
->renameFiles_renameEnabled(checked
);
3993 * Rename output files patterm changed
3995 void MainWindow::renameOutputPatternChanged(void)
3997 QString temp
= ui
->lineEditRenamePattern
->text().simplified();
3998 ui
->lineEditRenamePattern
->setText(temp
.isEmpty() ? m_settings
->renameFiles_renamePatternDefault() : temp
);
3999 m_settings
->renameFiles_renamePattern(ui
->lineEditRenamePattern
->text());
4003 * Rename output files patterm changed
4005 void MainWindow::renameOutputPatternChanged(const QString
&text
, const bool &silent
)
4007 QString
pattern(text
.simplified());
4009 pattern
.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive
);
4010 pattern
.replace("<TrackNo>", "04", Qt::CaseInsensitive
);
4011 pattern
.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive
);
4012 pattern
.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive
);
4013 pattern
.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive
);
4014 pattern
.replace("<Year>", "2001", Qt::CaseInsensitive
);
4015 pattern
.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive
);
4017 const QString patternClean
= MUtils::clean_file_name(pattern
);
4019 if(pattern
.compare(patternClean
))
4021 if(ui
->lineEditRenamePattern
->palette().color(QPalette::Text
) != Qt::red
)
4023 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4024 SET_TEXT_COLOR(ui
->lineEditRenamePattern
, Qt::red
);
4029 if(ui
->lineEditRenamePattern
->palette() != QPalette())
4031 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
4032 ui
->lineEditRenamePattern
->setPalette(QPalette());
4036 ui
->labelRanameExample
->setText(patternClean
);
4040 * Regular expression enabled changed
4042 void MainWindow::renameRegExpEnabledChanged(const bool &checked
)
4044 m_settings
->renameFiles_regExpEnabled(checked
);
4048 * Regular expression value has changed
4050 void MainWindow::renameRegExpValueChanged(void)
4052 const QString search
= ui
->lineEditRenameRegExp_Search
->text() .trimmed();
4053 const QString replace
= ui
->lineEditRenameRegExp_Replace
->text().simplified();
4054 ui
->lineEditRenameRegExp_Search
->setText(search
.isEmpty() ? m_settings
->renameFiles_regExpSearchDefault() : search
);
4055 ui
->lineEditRenameRegExp_Replace
->setText(replace
.isEmpty() ? m_settings
->renameFiles_regExpReplaceDefault() : replace
);
4056 m_settings
->renameFiles_regExpSearch (ui
->lineEditRenameRegExp_Search
->text());
4057 m_settings
->renameFiles_regExpReplace(ui
->lineEditRenameRegExp_Replace
->text());
4061 * Regular expression search pattern has changed
4063 void MainWindow::renameRegExpSearchChanged(const QString
&text
, const bool &silent
)
4065 const QString
pattern(text
.trimmed());
4067 if((!pattern
.isEmpty()) && (!QRegExp(pattern
.trimmed()).isValid()))
4069 if(ui
->lineEditRenameRegExp_Search
->palette().color(QPalette::Text
) != Qt::red
)
4071 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4072 SET_TEXT_COLOR(ui
->lineEditRenameRegExp_Search
, Qt::red
);
4077 if(ui
->lineEditRenameRegExp_Search
->palette() != QPalette())
4079 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
4080 ui
->lineEditRenameRegExp_Search
->setPalette(QPalette());
4084 renameRegExpReplaceChanged(ui
->lineEditRenameRegExp_Replace
->text(), silent
);
4088 * Regular expression replacement string changed
4090 void MainWindow::renameRegExpReplaceChanged(const QString
&text
, const bool &silent
)
4092 QString
replacement(text
.simplified());
4093 const QString
search(ui
->lineEditRenameRegExp_Search
->text().trimmed());
4095 if(!search
.isEmpty())
4097 const QRegExp
regexp(search
);
4098 if(regexp
.isValid())
4100 const int count
= regexp
.captureCount();
4101 const QString blank
;
4102 for(int i
= 0; i
< count
; i
++)
4104 replacement
.replace(QString("\\%0").arg(QString::number(i
+1)), blank
);
4109 if(replacement
.compare(MUtils::clean_file_name(replacement
)))
4111 if(ui
->lineEditRenameRegExp_Replace
->palette().color(QPalette::Text
) != Qt::red
)
4113 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4114 SET_TEXT_COLOR(ui
->lineEditRenameRegExp_Replace
, Qt::red
);
4119 if(ui
->lineEditRenameRegExp_Replace
->palette() != QPalette())
4121 if(!silent
) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO
);
4122 ui
->lineEditRenameRegExp_Replace
->setPalette(QPalette());
4128 * Show list of rename macros
4130 void MainWindow::showRenameMacros(const QString
&text
)
4132 if(text
.compare("reset", Qt::CaseInsensitive
) == 0)
4134 ui
->lineEditRenamePattern
->setText(m_settings
->renameFiles_renamePatternDefault());
4138 if(text
.compare("regexp", Qt::CaseInsensitive
) == 0)
4140 MUtils::OS::shell_open(this, "http://www.regular-expressions.info/quickstart.html");
4144 const QString format
= QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
4146 QString message
= QString("<table>");
4147 message
+= QString(format
).arg("BaseName", tr("File name without extension"));
4148 message
+= QString(format
).arg("TrackNo", tr("Track number with leading zero"));
4149 message
+= QString(format
).arg("Title", tr("Track title"));
4150 message
+= QString(format
).arg("Artist", tr("Artist name"));
4151 message
+= QString(format
).arg("Album", tr("Album name"));
4152 message
+= QString(format
).arg("Year", tr("Year with (at least) four digits"));
4153 message
+= QString(format
).arg("Comment", tr("Comment"));
4154 message
+= "</table><br><br>";
4155 message
+= QString("%1<br>").arg(tr("Characters forbidden in file names:"));
4156 message
+= "<b><tt>\\ / : * ? < > |<br>";
4158 QMessageBox::information(this, tr("Rename Macros"), message
, tr("Discard"));
4161 void MainWindow::fileExtAddButtonClicked(void)
4163 if(FileExtsModel
*const model
= dynamic_cast<FileExtsModel
*>(ui
->tableViewFileExts
->model()))
4165 model
->addOverwrite(this);
4169 void MainWindow::fileExtRemoveButtonClicked(void)
4171 if(FileExtsModel
*const model
= dynamic_cast<FileExtsModel
*>(ui
->tableViewFileExts
->model()))
4173 const QModelIndex selected
= ui
->tableViewFileExts
->currentIndex();
4174 if(selected
.isValid())
4176 model
->removeOverwrite(selected
);
4180 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4185 void MainWindow::fileExtModelChanged(void)
4187 if(FileExtsModel
*const model
= dynamic_cast<FileExtsModel
*>(ui
->tableViewFileExts
->model()))
4189 m_settings
->renameFiles_fileExtension(model
->exportItems());
4193 void MainWindow::forceStereoDownmixEnabledChanged(bool checked
)
4195 m_settings
->forceStereoDownmix(checked
);
4199 * Maximum number of instances changed
4201 void MainWindow::updateMaximumInstances(int value
)
4203 ui
->labelMaxInstances
->setText(tr("%n Instance(s)", "", value
));
4204 m_settings
->maximumInstances(ui
->checkBoxAutoDetectInstances
->isChecked() ? NULL
: value
);
4208 * Auto-detect number of instances
4210 void MainWindow::autoDetectInstancesChanged(bool checked
)
4212 m_settings
->maximumInstances(checked
? NULL
: ui
->sliderMaxInstances
->value());
4216 * Browse for custom TEMP folder button clicked
4218 void MainWindow::browseCustomTempFolderButtonClicked(void)
4220 QString newTempFolder
;
4222 if(MUtils::GUI::themes_enabled())
4224 newTempFolder
= QFileDialog::getExistingDirectory(this, QString(), m_settings
->customTempPath());
4228 QFileDialog
dialog(this);
4229 dialog
.setFileMode(QFileDialog::DirectoryOnly
);
4230 dialog
.setDirectory(m_settings
->customTempPath());
4233 newTempFolder
= dialog
.selectedFiles().first();
4237 if(!newTempFolder
.isEmpty())
4239 QFile
writeTest(QString("%1/~%2.tmp").arg(newTempFolder
, MUtils::rand_str()));
4240 if(writeTest
.open(QIODevice::ReadWrite
))
4243 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(newTempFolder
));
4247 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
4253 * Custom TEMP folder changed
4255 void MainWindow::customTempFolderChanged(const QString
&text
)
4257 m_settings
->customTempPath(QDir::fromNativeSeparators(text
));
4261 * Use custom TEMP folder option changed
4263 void MainWindow::useCustomTempFolderChanged(bool checked
)
4265 m_settings
->customTempPathEnabled(!checked
);
4269 * Help for custom parameters was requested
4271 void MainWindow::customParamsHelpRequested(QWidget
*obj
, QEvent
*event
)
4273 if(event
->type() != QEvent::MouseButtonRelease
)
4278 if(QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
))
4280 QPoint pos
= mouseEvent
->pos();
4281 if(!(pos
.x() <= obj
->width() && pos
.y() <= obj
->height() && pos
.x() >= 0 && pos
.y() >= 0 && mouseEvent
->button() != Qt::MidButton
))
4287 if(obj
== ui
->helpCustomParamLAME
) showCustomParamsHelpScreen("lame.exe", "--longhelp");
4288 else if(obj
== ui
->helpCustomParamOggEnc
) showCustomParamsHelpScreen("oggenc2.exe", "--help");
4289 else if(obj
== ui
->helpCustomParamNeroAAC
)
4291 switch(EncoderRegistry::getAacEncoder())
4293 case SettingsModel::AAC_ENCODER_QAAC
: showCustomParamsHelpScreen("qaac64.exe|qaac.exe", "--help"); break;
4294 case SettingsModel::AAC_ENCODER_FHG
: showCustomParamsHelpScreen("fhgaacenc.exe", "" ); break;
4295 case SettingsModel::AAC_ENCODER_FDK
: showCustomParamsHelpScreen("fdkaac.exe", "--help"); break;
4296 case SettingsModel::AAC_ENCODER_NERO
: showCustomParamsHelpScreen("neroAacEnc.exe", "-help" ); break;
4297 default: MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
); break;
4300 else if(obj
== ui
->helpCustomParamFLAC
) showCustomParamsHelpScreen("flac.exe", "--help");
4301 else if(obj
== ui
->helpCustomParamAften
) showCustomParamsHelpScreen("aften.exe", "-h" );
4302 else if(obj
== ui
->helpCustomParamOpus
) showCustomParamsHelpScreen("opusenc.exe", "--help");
4303 else MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4307 * Show help for custom parameters
4309 void MainWindow::showCustomParamsHelpScreen(const QString
&toolName
, const QString
&command
)
4311 const QStringList toolNames
= toolName
.split('|', QString::SkipEmptyParts
);
4313 for(QStringList::ConstIterator iter
= toolNames
.constBegin(); iter
!= toolNames
.constEnd(); iter
++)
4315 if(lamexp_tools_check(*iter
))
4317 binary
= lamexp_tools_lookup(*iter
);
4322 if(binary
.isEmpty())
4324 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4325 qWarning("customParamsHelpRequested: Binary could not be found!");
4330 MUtils::init_process(process
, QFileInfo(binary
).absolutePath());
4332 process
.start(binary
, command
.isEmpty() ? QStringList() : QStringList() << command
);
4334 qApp
->setOverrideCursor(QCursor(Qt::WaitCursor
));
4336 if(process
.waitForStarted(15000))
4338 qApp
->processEvents();
4339 process
.waitForFinished(15000);
4342 if(process
.state() != QProcess::NotRunning
)
4345 process
.waitForFinished(-1);
4348 qApp
->restoreOverrideCursor();
4349 QStringList output
; bool spaceFlag
= true;
4351 while(process
.canReadLine())
4353 QString temp
= QString::fromUtf8(process
.readLine());
4354 TRIM_STRING_RIGHT(temp
);
4357 if(!spaceFlag
) { output
<< temp
; spaceFlag
= true; }
4361 output
<< temp
; spaceFlag
= false;
4365 if(output
.count() < 1)
4367 qWarning("Empty output, cannot show help screen!");
4368 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR
);
4371 WidgetHideHelper
hiderHelper(m_dropBox
.data());
4372 QScopedPointer
<LogViewDialog
> dialog(new LogViewDialog(this));
4373 dialog
->exec(output
);
4376 void MainWindow::overwriteModeChanged(int id
)
4378 if((id
== SettingsModel::Overwrite_Replaces
) && (m_settings
->overwriteMode() != SettingsModel::Overwrite_Replaces
))
4380 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)
4382 ui
->radioButtonOverwriteModeKeepBoth
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_KeepBoth
);
4383 ui
->radioButtonOverwriteModeSkipFile
->setChecked(m_settings
->overwriteMode() == SettingsModel::Overwrite_SkipFile
);
4388 m_settings
->overwriteMode(id
);
4392 * Reset all advanced options to their defaults
4394 void MainWindow::resetAdvancedOptionsButtonClicked(void)
4396 PLAY_SOUND_OPTIONAL("blast", true);
4398 ui
->sliderLameAlgoQuality
->setValue(m_settings
->lameAlgoQualityDefault());
4399 ui
->spinBoxBitrateManagementMin
->setValue(m_settings
->bitrateManagementMinRateDefault());
4400 ui
->spinBoxBitrateManagementMax
->setValue(m_settings
->bitrateManagementMaxRateDefault());
4401 ui
->spinBoxNormalizationFilterPeak
->setValue(static_cast<double>(m_settings
->normalizationFilterMaxVolumeDefault()) / 100.0);
4402 ui
->spinBoxNormalizationFilterSize
->setValue(m_settings
->normalizationFilterSizeDefault());
4403 ui
->spinBoxToneAdjustBass
->setValue(static_cast<double>(m_settings
->toneAdjustBassDefault()) / 100.0);
4404 ui
->spinBoxToneAdjustTreble
->setValue(static_cast<double>(m_settings
->toneAdjustTrebleDefault()) / 100.0);
4405 ui
->spinBoxAftenSearchSize
->setValue(m_settings
->aftenExponentSearchSizeDefault());
4406 ui
->spinBoxOpusComplexity
->setValue(m_settings
->opusComplexityDefault());
4407 ui
->comboBoxMP3ChannelMode
->setCurrentIndex(m_settings
->lameChannelModeDefault());
4408 ui
->comboBoxSamplingRate
->setCurrentIndex(m_settings
->samplingRateDefault());
4409 ui
->comboBoxAACProfile
->setCurrentIndex(m_settings
->aacEncProfileDefault());
4410 ui
->comboBoxAftenCodingMode
->setCurrentIndex(m_settings
->aftenAudioCodingModeDefault());
4411 ui
->comboBoxAftenDRCMode
->setCurrentIndex(m_settings
->aftenDynamicRangeCompressionDefault());
4412 ui
->comboBoxOpusFramesize
->setCurrentIndex(m_settings
->opusFramesizeDefault());
4414 SET_CHECKBOX_STATE(ui
->checkBoxBitrateManagement
, m_settings
->bitrateManagementEnabledDefault());
4415 SET_CHECKBOX_STATE(ui
->checkBoxNeroAAC2PassMode
, m_settings
->neroAACEnable2PassDefault());
4416 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterEnabled
, m_settings
->normalizationFilterEnabledDefault());
4417 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterDynamic
, m_settings
->normalizationFilterDynamicDefault());
4418 SET_CHECKBOX_STATE(ui
->checkBoxNormalizationFilterCoupled
, m_settings
->normalizationFilterCoupledDefault());
4419 SET_CHECKBOX_STATE(ui
->checkBoxAutoDetectInstances
, (m_settings
->maximumInstancesDefault() < 1));
4420 SET_CHECKBOX_STATE(ui
->checkBoxUseSystemTempFolder
, (!m_settings
->customTempPathEnabledDefault()));
4421 SET_CHECKBOX_STATE(ui
->checkBoxAftenFastAllocation
, m_settings
->aftenFastBitAllocationDefault());
4422 SET_CHECKBOX_STATE(ui
->checkBoxRename_Rename
, m_settings
->renameFiles_renameEnabledDefault());
4423 SET_CHECKBOX_STATE(ui
->checkBoxRename_RegExp
, m_settings
->renameFiles_regExpEnabledDefault());
4424 SET_CHECKBOX_STATE(ui
->checkBoxForceStereoDownmix
, m_settings
->forceStereoDownmixDefault());
4425 SET_CHECKBOX_STATE(ui
->checkBoxOpusDisableResample
, m_settings
->opusDisableResampleDefault());
4427 ui
->lineEditCustomParamLAME
->setText(m_settings
->customParametersLAMEDefault());
4428 ui
->lineEditCustomParamOggEnc
->setText(m_settings
->customParametersOggEncDefault());
4429 ui
->lineEditCustomParamNeroAAC
->setText(m_settings
->customParametersAacEncDefault());
4430 ui
->lineEditCustomParamFLAC
->setText(m_settings
->customParametersFLACDefault());
4431 ui
->lineEditCustomParamOpus
->setText(m_settings
->customParametersOpusEncDefault());
4432 ui
->lineEditCustomTempFolder
->setText(QDir::toNativeSeparators(m_settings
->customTempPathDefault()));
4433 ui
->lineEditRenamePattern
->setText(m_settings
->renameFiles_renamePatternDefault());
4434 ui
->lineEditRenameRegExp_Search
->setText(m_settings
->renameFiles_regExpSearchDefault());
4435 ui
->lineEditRenameRegExp_Replace
->setText(m_settings
->renameFiles_regExpReplaceDefault());
4437 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_KeepBoth
) ui
->radioButtonOverwriteModeKeepBoth
->click();
4438 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_SkipFile
) ui
->radioButtonOverwriteModeSkipFile
->click();
4439 if(m_settings
->overwriteModeDefault() == SettingsModel::Overwrite_Replaces
) ui
->radioButtonOverwriteModeReplaces
->click();
4441 if(FileExtsModel
*const model
= dynamic_cast<FileExtsModel
*>(ui
->tableViewFileExts
->model()))
4443 model
->importItems(m_settings
->renameFiles_fileExtensionDefault());
4446 ui
->scrollArea
->verticalScrollBar()->setValue(0);
4447 ui
->buttonRename_Rename
->click();
4448 customParamsChanged();
4449 renameOutputPatternChanged();
4450 renameRegExpValueChanged();
4453 // =========================================================
4454 // Multi-instance handling slots
4455 // =========================================================
4458 * Other instance detected
4460 void MainWindow::notifyOtherInstance(void)
4462 if(!(BANNER_VISIBLE
))
4464 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
);
4470 * Add file from another instance
4472 void MainWindow::addFileDelayed(const QString
&filePath
, bool tryASAP
)
4474 if(tryASAP
&& !m_delayedFileTimer
->isActive())
4476 qDebug("Received file: %s", MUTILS_UTF8(filePath
));
4477 m_delayedFileList
->append(filePath
);
4478 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4481 m_delayedFileTimer
->stop();
4482 qDebug("Received file: %s", MUTILS_UTF8(filePath
));
4483 m_delayedFileList
->append(filePath
);
4484 m_delayedFileTimer
->start(5000);
4488 * Add files from another instance
4490 void MainWindow::addFilesDelayed(const QStringList
&filePaths
, bool tryASAP
)
4492 if(tryASAP
&& (!m_delayedFileTimer
->isActive()))
4494 qDebug("Received %d file(s).", filePaths
.count());
4495 m_delayedFileList
->append(filePaths
);
4496 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4500 m_delayedFileTimer
->stop();
4501 qDebug("Received %d file(s).", filePaths
.count());
4502 m_delayedFileList
->append(filePaths
);
4503 m_delayedFileTimer
->start(5000);
4508 * Add folder from another instance
4510 void MainWindow::addFolderDelayed(const QString
&folderPath
, bool recursive
)
4512 if(!(BANNER_VISIBLE
))
4514 addFolder(folderPath
, recursive
, true);
4518 // =========================================================
4520 // =========================================================
4523 * Restore the override cursor
4525 void MainWindow::restoreCursor(void)
4527 QApplication::restoreOverrideCursor();