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);
1072 ui->sourceFileView->scrollTo(m_fileListModel->index((up ? firstIndex : firstIndex + selectionCount - 1), 0), QAbstractItemView::PositionAtCenter);
1076 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
1080 * Show banner popup dialog
1082 void MainWindow::showBanner(const QString &text)
1085 m_banner->show(text);
1089 * Show banner popup dialog
1091 void MainWindow::showBanner(const QString &text, QThread *const thread)
1094 m_banner->show(text, thread);
1098 * Show banner popup dialog
1100 void MainWindow::showBanner(const QString &text, QEventLoop *const eventLoop)
1103 m_banner->show(text, eventLoop);
1107 * Show banner popup dialog
1109 void MainWindow::showBanner(const QString &text, bool &flag, const bool &test)
1111 if((!flag) && (test))
1114 m_banner->show(text);
1119 ////////////////////////////////////////////////////////////
1121 ////////////////////////////////////////////////////////////
1124 * Window is about to be shown
1126 void MainWindow::showEvent(QShowEvent *event)
1130 sourceModelChanged();
1132 if(!event->spontaneous())
1134 SignalBlockHelper signalBlockHelper(ui->tabWidget);
1135 ui->tabWidget->setCurrentIndex(0);
1136 tabPageChanged(ui->tabWidget->currentIndex(), true);
1139 if(m_firstTimeShown)
1141 m_firstTimeShown = false;
1142 QTimer::singleShot(0, this, SLOT(windowShown()));
1146 if(m_settings->dropBoxWidgetEnabled())
1148 m_dropBox->setVisible(true);
1154 * Re-translate the UI
1156 void MainWindow::changeEvent(QEvent *e)
1158 QMainWindow::changeEvent(e);
1159 if(e->type() != QEvent::LanguageChange)
1164 int comboBoxIndex[6];
1166 //Backup combobox indices, as retranslateUi() resets
1167 comboBoxIndex[0] = ui->comboBoxMP3ChannelMode->currentIndex();
1168 comboBoxIndex[1] = ui->comboBoxSamplingRate->currentIndex();
1169 comboBoxIndex[2] = ui->comboBoxAACProfile->currentIndex();
1170 comboBoxIndex[3] = ui->comboBoxAftenCodingMode->currentIndex();
1171 comboBoxIndex[4] = ui->comboBoxAftenDRCMode->currentIndex();
1172 comboBoxIndex[5] = ui->comboBoxOpusFramesize->currentIndex();
1174 //Re-translate from UIC
1175 ui->retranslateUi(this);
1177 //Restore combobox indices
1178 ui->comboBoxMP3ChannelMode->setCurrentIndex(comboBoxIndex[0]);
1179 ui->comboBoxSamplingRate->setCurrentIndex(comboBoxIndex[1]);
1180 ui->comboBoxAACProfile->setCurrentIndex(comboBoxIndex[2]);
1181 ui->comboBoxAftenCodingMode->setCurrentIndex(comboBoxIndex[3]);
1182 ui->comboBoxAftenDRCMode->setCurrentIndex(comboBoxIndex[4]);
1183 ui->comboBoxOpusFramesize->setCurrentIndex(comboBoxIndex[5]);
1185 //Update the window title
1188 setWindowTitle(QString("%1 [!!! DEBUG BUILD !!!]").arg(windowTitle()));
1190 else if(lamexp_version_demo())
1192 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), tr("DEMO VERSION")));
1195 //Manually re-translate widgets that UIC doesn't handle
1196 m_outputFolderNoteBox->setText(tr("Initializing directory outline, please be patient..."));
1197 m_dropNoteLabel->setText(QString("<br><img src=\":/images/DropZone.png\"><br><br>%1").arg(tr("You can drop in audio files here!")));
1198 if(QLabel *cornerWidget = dynamic_cast<QLabel*>(ui->menubar->cornerWidget()))
1200 cornerWidget->setText(QString("<nobr><img src=\":/icons/exclamation_small.png\"> <b style=\"color:darkred\">%1</b> </nobr>").arg(tr("Check for Updates")));
1202 m_showDetailsContextAction->setText(tr("Show Details"));
1203 m_previewContextAction->setText(tr("Open File in External Application"));
1204 m_findFileContextAction->setText(tr("Browse File Location"));
1205 m_showFolderContextAction->setText(tr("Browse Selected Folder"));
1206 m_refreshFolderContextAction->setText(tr("Refresh Directory Outline"));
1207 m_goUpFolderContextAction->setText(tr("Go To Parent Directory"));
1208 m_addFavoriteFolderAction->setText(tr("Bookmark Current Output Folder"));
1209 m_exportCsvContextAction->setText(tr("Export Meta Tags to CSV File"));
1210 m_importCsvContextAction->setText(tr("Import Meta Tags from CSV File"));
1213 m_metaInfoModel->clearData();
1214 m_metaInfoModel->setData(m_metaInfoModel->index(4, 1), m_settings->metaInfoPosition());
1215 updateEncoder(m_settings->compressionEncoder());
1216 updateLameAlgoQuality(ui->sliderLameAlgoQuality->value());
1217 updateMaximumInstances(ui->sliderMaxInstances->value());
1218 renameOutputPatternChanged(ui->lineEditRenamePattern->text(), true);
1219 renameRegExpSearchChanged (ui->lineEditRenameRegExp_Search ->text(), true);
1220 renameRegExpReplaceChanged(ui->lineEditRenameRegExp_Replace->text(), true);
1222 //Re-install shell integration
1223 if(m_settings->shellIntegrationEnabled())
1225 ShellIntegration::install();
1228 //Translate system menu
1229 MUtils::GUI::sysmenu_update(this, IDM_ABOUTBOX, ui->buttonAbout->text());
1231 //Force resize event
1232 QApplication::postEvent(this, new QResizeEvent(this->size(), QSize()));
1233 for(QObjectList::ConstIterator iter = this->children().constBegin(); iter != this->children().constEnd(); iter++)
1235 if(QWidget *child = dynamic_cast<QWidget*>(*iter))
1237 QApplication::postEvent(child, new QResizeEvent(child->size(), QSize()));
1241 //Force tabe page change
1242 tabPageChanged(ui->tabWidget->currentIndex(), true);
1246 * File dragged over window
1248 void MainWindow::dragEnterEvent(QDragEnterEvent *event)
1250 QStringList formats = event->mimeData()->formats();
1252 if(formats.contains("application/x-qt-windows-mime;value=\"FileNameW\"", Qt::CaseInsensitive) && formats.contains("text/uri-list", Qt::CaseInsensitive))
1254 event->acceptProposedAction();
1259 * File dropped onto window
1261 void MainWindow::dropEvent(QDropEvent *event)
1263 m_droppedFileList->clear();
1264 (*m_droppedFileList) << event->mimeData()->urls();
1265 if(!m_droppedFileList->isEmpty())
1267 PLAY_SOUND_OPTIONAL("drop", true);
1268 QTimer::singleShot(0, this, SLOT(handleDroppedFiles()));
1273 * Window tries to close
1275 void MainWindow::closeEvent(QCloseEvent *event)
1277 if(BANNER_VISIBLE || m_delayedFileTimer->isActive())
1279 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
1290 * Window was resized
1292 void MainWindow::resizeEvent(QResizeEvent *event)
1294 if(event) QMainWindow::resizeEvent(event);
1296 if(QWidget *port = ui->sourceFileView->viewport())
1298 m_dropNoteLabel->setGeometry(port->geometry());
1301 if(QWidget *port = ui->outputFolderView->viewport())
1303 m_outputFolderNoteBox->setGeometry(16, (port->height() - 64) / 2, port->width() - 32, 64);
1308 * Key press event filter
1310 void MainWindow::keyPressEvent(QKeyEvent *e)
1312 if(e->key() == Qt::Key_Delete)
1314 if(ui->sourceFileView->isVisible())
1316 QTimer::singleShot(0, this, SLOT(removeFileButtonClicked()));
1321 if(e->modifiers().testFlag(Qt::ControlModifier) && (e->key() == Qt::Key_F5))
1323 initializeTranslation();
1324 MUtils::Sound::beep(MUtils::Sound::BEEP_NFO);
1328 if(e->key() == Qt::Key_F5)
1330 if(ui->outputFolderView->isVisible())
1332 QTimer::singleShot(0, this, SLOT(refreshFolderContextActionTriggered()));
1337 QMainWindow::keyPressEvent(e);
1343 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
1345 if(obj == m_fileSystemModel.data())
1347 if(QApplication::overrideCursor() == NULL)
1349 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1350 QTimer::singleShot(250, this, SLOT(restoreCursor()));
1354 return QMainWindow::eventFilter(obj, event);
1357 bool MainWindow::event(QEvent *e)
1361 case MUtils::GUI::USER_EVENT_QUERYENDSESSION:
1362 qWarning("System is shutting down, main window prepares to close...");
1363 if(BANNER_VISIBLE) m_banner->close();
1364 if(m_delayedFileTimer->isActive()) m_delayedFileTimer->stop();
1366 case MUtils::GUI::USER_EVENT_ENDSESSION:
1367 qWarning("System is shutting down, main window will close now...");
1372 QApplication::processEvents(QEventLoop::WaitForMoreEvents & QEventLoop::ExcludeUserInputEvents);
1375 m_fileListModel->clearFiles();
1377 case QEvent::MouseButtonPress:
1378 if(ui->outputFolderEdit->isVisible())
1380 QTimer::singleShot(0, this, SLOT(outputFolderEditFinished()));
1383 return QMainWindow::event(e);
1387 bool MainWindow::winEvent(MSG *message, long *result)
1389 if(MUtils::GUI::sysmenu_check_msg(message, IDM_ABOUTBOX))
1391 QTimer::singleShot(0, ui->buttonAbout, SLOT(click()));
1398 ////////////////////////////////////////////////////////////
1400 ////////////////////////////////////////////////////////////
1402 // =========================================================
1403 // Show window slots
1404 // =========================================================
1409 void MainWindow::windowShown(void)
1411 const MUtils::OS::ArgumentMap &arguments = MUtils::OS::arguments(); //QApplication::arguments();
1413 //Force resize event
1417 const bool firstRun = arguments.contains("first-run");
1420 if((m_settings->licenseAccepted() <= 0) || firstRun)
1422 int iAccepted = m_settings->licenseAccepted();
1424 if((iAccepted == 0) || firstRun)
1426 AboutDialog *about = new AboutDialog(m_settings, this, true);
1427 iAccepted = about->exec();
1428 if(iAccepted <= 0) iAccepted = -2;
1429 MUTILS_DELETE(about);
1434 m_settings->licenseAccepted(++iAccepted);
1435 m_settings->syncNow();
1436 QApplication::processEvents();
1437 MUtils::Sound::play_sound("whammy", false);
1438 QMessageBox::critical(this, tr("License Declined"), tr("You have declined the license. Consequently the application will exit now!"), tr("Goodbye!"));
1439 QFileInfo uninstallerInfo = QFileInfo(QString("%1/Uninstall.exe").arg(QApplication::applicationDirPath()));
1440 if(uninstallerInfo.exists())
1442 QString uninstallerDir = uninstallerInfo.canonicalPath();
1443 QString uninstallerPath = uninstallerInfo.canonicalFilePath();
1444 for(int i = 0; i < 3; i++)
1446 if(MUtils::OS::shell_open(this, QDir::toNativeSeparators(uninstallerPath), "/Force", QDir::toNativeSeparators(uninstallerDir))) break;
1449 QApplication::quit();
1453 MUtils::Sound::play_sound("woohoo", false);
1454 m_settings->licenseAccepted(1);
1455 m_settings->syncNow();
1456 if(lamexp_version_demo()) showAnnounceBox();
1459 //Check for expiration
1460 if(lamexp_version_demo())
1462 if(MUtils::OS::current_date() >= lamexp_version_expires())
1464 qWarning("Binary has expired !!!");
1465 MUtils::Sound::play_sound("whammy", false);
1466 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)
1470 QApplication::quit();
1475 //Slow startup indicator
1476 if(m_settings->slowStartup() && m_settings->antivirNotificationsEnabled())
1479 message += NOBR(tr("It seems that a bogus anti-virus software is slowing down the startup of LameXP.")).append("<br>");
1480 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>");
1481 if(QMessageBox::warning(this, tr("Slow Startup"), message, tr("Discard"), tr("Don't Show Again")) == 1)
1483 m_settings->antivirNotificationsEnabled(false);
1484 ui->actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
1489 if(MUtils::OS::current_date() >= MUtils::Version::app_build_date().addYears(1))
1491 qWarning("Binary is more than a year old, time to update!");
1492 SHOW_CORNER_WIDGET(true);
1493 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"));
1497 if(checkForUpdates())
1499 QApplication::quit();
1504 QApplication::quit();
1507 QEventLoop loop; QTimer::singleShot(7000, &loop, SLOT(quit()));
1508 MUtils::Sound::play_sound("waiting", true);
1509 showBanner(tr("Skipping update check this time, please be patient..."), &loop);
1515 QDate lastUpdateCheck = QDate::fromString(m_settings->autoUpdateLastCheck(), Qt::ISODate);
1516 if((!firstRun) && ((!lastUpdateCheck.isValid()) || (MUtils::OS::current_date() >= lastUpdateCheck.addDays(14))))
1518 SHOW_CORNER_WIDGET(true);
1519 if(m_settings->autoUpdateEnabled())
1521 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)
1523 if(checkForUpdates())
1525 QApplication::quit();
1533 //Check for AAC support
1534 const int aacEncoder = EncoderRegistry::getAacEncoder();
1535 if(aacEncoder == SettingsModel::AAC_ENCODER_NERO)
1537 if(m_settings->neroAacNotificationsEnabled())
1539 if(lamexp_tools_version("neroAacEnc.exe") < lamexp_toolver_neroaac())
1541 QString messageText;
1542 messageText += NOBR(tr("LameXP detected that your version of the Nero AAC encoder is outdated!")).append("<br>");
1543 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>");
1544 messageText += NOBR(tr("You can download the latest version of the Nero AAC encoder from the Nero website at:")).append("<br>");
1545 messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br><br>";
1546 messageText += NOBR(tr("(Hint: Please ignore the name of the downloaded ZIP file and check the included 'changelog.txt' instead!)")).append("<br>");
1547 QMessageBox::information(this, tr("AAC Encoder Outdated"), messageText);
1553 if(m_settings->neroAacNotificationsEnabled() && (aacEncoder <= SettingsModel::AAC_ENCODER_NONE))
1555 QString appPath = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
1556 if(appPath.isEmpty()) appPath = QCoreApplication::applicationDirPath();
1557 QString messageText;
1558 messageText += NOBR(tr("The Nero AAC encoder could not be found. AAC encoding support will be disabled.")).append("<br>");
1559 messageText += NOBR(tr("Please put 'neroAacEnc.exe', 'neroAacDec.exe' and 'neroAacTag.exe' into the LameXP directory!")).append("<br><br>");
1560 messageText += NOBR(tr("Your LameXP directory is located here:")).append("<br>");
1561 messageText += QString("<nobr><tt>%1</tt></nobr><br><br>").arg(FSLINK(QDir::toNativeSeparators(appPath)));
1562 messageText += NOBR(tr("You can download the Nero AAC encoder for free from the official Nero website at:")).append("<br>");
1563 messageText += "<nobr><tt>" + LINK(AboutDialog::neroAacUrl) + "</tt></nobr><br>";
1564 if(QMessageBox::information(this, tr("AAC Support Disabled"), messageText, tr("Discard"), tr("Don't Show Again")) == 1)
1566 m_settings->neroAacNotificationsEnabled(false);
1567 ui->actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
1572 //Add files from the command-line
1573 QStringList addedFiles;
1574 foreach(const QString &value, arguments.values("add"))
1576 if(!value.isEmpty())
1578 QFileInfo currentFile(value);
1579 qDebug("Adding file from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
1580 addedFiles.append(currentFile.absoluteFilePath());
1583 if(!addedFiles.isEmpty())
1585 addFilesDelayed(addedFiles);
1588 //Add folders from the command-line
1589 foreach(const QString &value, arguments.values("add-folder"))
1591 if(!value.isEmpty())
1593 const QFileInfo currentFile(value);
1594 qDebug("Adding folder from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
1595 addFolder(currentFile.absoluteFilePath(), false, true);
1598 foreach(const QString &value, arguments.values("add-recursive"))
1600 if(!value.isEmpty())
1602 const QFileInfo currentFile(value);
1603 qDebug("Adding folder recursively from CLI: %s", MUTILS_UTF8(currentFile.absoluteFilePath()));
1604 addFolder(currentFile.absoluteFilePath(), true, true);
1608 //Enable shell integration
1609 if(m_settings->shellIntegrationEnabled())
1611 ShellIntegration::install();
1614 //Make DropBox visible
1615 if(m_settings->dropBoxWidgetEnabled())
1617 m_dropBox->setVisible(true);
1624 void MainWindow::showAnnounceBox(void)
1626 const unsigned int timeout = 8U;
1628 const QString announceText = QString("%1<br><br>%2<br><nobr><tt>%3</tt></nobr><br>").arg
1630 NOBR("We are still looking for LameXP translators!"),
1631 NOBR("If you are willing to translate LameXP to your language or to complete an existing translation, please refer to:"),
1632 LINK("http://lamexp.sourceforge.net/doc/Translate.html")
1635 QMessageBox *announceBox = new QMessageBox(QMessageBox::Warning, "We want you!", announceText, QMessageBox::NoButton, this);
1636 announceBox->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
1637 announceBox->setIconPixmap(QIcon(":/images/Announcement.png").pixmap(64,79));
1639 QTimer *timers[timeout+1];
1640 QPushButton *buttons[timeout+1];
1642 for(unsigned int i = 0; i <= timeout; i++)
1644 QString text = (i > 0) ? QString("%1 (%2)").arg(tr("Discard"), QString::number(i)) : tr("Discard");
1645 buttons[i] = announceBox->addButton(text, (i > 0) ? QMessageBox::NoRole : QMessageBox::AcceptRole);
1648 for(unsigned int i = 0; i <= timeout; i++)
1650 buttons[i]->setEnabled(i == 0);
1651 buttons[i]->setVisible(i == timeout);
1654 for(unsigned int i = 0; i < timeout; i++)
1656 timers[i] = new QTimer(this);
1657 timers[i]->setSingleShot(true);
1658 timers[i]->setInterval(1000);
1659 connect(timers[i], SIGNAL(timeout()), buttons[i+1], SLOT(hide()));
1660 connect(timers[i], SIGNAL(timeout()), buttons[i], SLOT(show()));
1663 connect(timers[i], SIGNAL(timeout()), timers[i-1], SLOT(start()));
1667 timers[timeout-1]->start();
1668 announceBox->exec();
1670 for(unsigned int i = 0; i < timeout; i++)
1673 MUTILS_DELETE(timers[i]);
1676 MUTILS_DELETE(announceBox);
1679 // =========================================================
1680 // Main button solots
1681 // =========================================================
1686 void MainWindow::encodeButtonClicked(void)
1688 static const unsigned __int64 oneGigabyte = 1073741824ui64;
1689 static const unsigned __int64 minimumFreeDiskspaceMultiplier = 2ui64;
1690 static const char *writeTestBuffer = "LAMEXP_WRITE_TEST";
1694 if(m_fileListModel->rowCount() < 1)
1696 QMessageBox::warning(this, tr("LameXP"), NOBR(tr("You must add at least one file to the list before proceeding!")));
1697 ui->tabWidget->setCurrentIndex(0);
1701 QString tempFolder = m_settings->customTempPathEnabled() ? m_settings->customTempPath() : MUtils::temp_folder();
1702 if(!QFileInfo(tempFolder).exists() || !QFileInfo(tempFolder).isDir())
1704 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)
1706 SET_CHECKBOX_STATE(ui->checkBoxUseSystemTempFolder, (!m_settings->customTempPathEnabledDefault()));
1711 quint64 currentFreeDiskspace = 0;
1712 if(MUtils::OS::free_diskspace(tempFolder, currentFreeDiskspace))
1714 if(currentFreeDiskspace < (oneGigabyte * minimumFreeDiskspaceMultiplier))
1716 QStringList tempFolderParts = tempFolder.split("/", QString::SkipEmptyParts, Qt::CaseInsensitive);
1717 tempFolderParts.takeLast();
1718 PLAY_SOUND_OPTIONAL("whammy", false);
1719 QString lowDiskspaceMsg = QString("%1<br>%2<br><br>%3<br>%4<br>").arg
1721 NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier))),
1722 NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")),
1723 NOBR(tr("Your TEMP folder is located at:")),
1724 QString("<nobr><tt>%1</tt></nobr>").arg(FSLINK(tempFolderParts.join("\\")))
1726 switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore")))
1729 QProcess::startDetached(QString("%1/cleanmgr.exe").arg(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER)), QStringList() << "/D" << tempFolderParts.first());
1734 QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!")));
1740 switch(m_settings->compressionEncoder())
1742 case SettingsModel::MP3Encoder:
1743 case SettingsModel::VorbisEncoder:
1744 case SettingsModel::AACEncoder:
1745 case SettingsModel::AC3Encoder:
1746 case SettingsModel::FLACEncoder:
1747 case SettingsModel::OpusEncoder:
1748 case SettingsModel::DCAEncoder:
1749 case SettingsModel::MACEncoder:
1750 case SettingsModel::PCMEncoder:
1753 QMessageBox::warning(this, tr("LameXP"), tr("Sorry, an unsupported encoder has been chosen!"));
1754 ui->tabWidget->setCurrentIndex(3);
1758 if(!m_settings->outputToSourceDir())
1760 QFile writeTest(QString("%1/~%2.txt").arg(m_settings->outputDir(), MUtils::rand_str()));
1761 if(!(writeTest.open(QIODevice::ReadWrite) && (writeTest.write(writeTestBuffer) == strlen(writeTestBuffer))))
1763 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!")));
1764 ui->tabWidget->setCurrentIndex(1);
1781 void MainWindow::aboutButtonClicked(void)
1784 WidgetHideHelper hiderHelper(m_dropBox.data());
1785 QScopedPointer<AboutDialog> aboutBox(new AboutDialog(m_settings, this));
1792 void MainWindow::closeButtonClicked(void)
1798 // =========================================================
1800 // =========================================================
1805 void MainWindow::tabPageChanged(int idx, const bool silent)
1809 //Update "view" menu
1810 QList<QAction*> actions = m_tabActionGroup->actions();
1811 for(int i = 0; i < actions.count(); i++)
1814 int actionIndex = actions.at(i)->data().toInt(&ok);
1815 if(ok && actionIndex == idx)
1817 actions.at(i)->setChecked(true);
1824 PLAY_SOUND_OPTIONAL("tick", true);
1827 int initialWidth = this->width();
1828 int maximumWidth = QApplication::desktop()->availableGeometry().width();
1830 //Make sure all tab headers are fully visible
1831 if(this->isVisible())
1833 int delta = ui->tabWidget->sizeHint().width() - ui->tabWidget->width();
1836 this->resize(qMin(this->width() + delta, maximumWidth), this->height());
1840 //Tab specific operations
1841 if(idx == ui->tabWidget->indexOf(ui->tabOptions) && ui->scrollArea->widget() && this->isVisible())
1843 ui->scrollArea->widget()->updateGeometry();
1844 ui->scrollArea->viewport()->updateGeometry();
1845 qApp->processEvents();
1846 int delta = ui->scrollArea->widget()->width() - ui->scrollArea->viewport()->width();
1849 this->resize(qMin(this->width() + delta, maximumWidth), this->height());
1852 else if(idx == ui->tabWidget->indexOf(ui->tabSourceFiles))
1854 m_dropNoteLabel->setGeometry(0, 0, ui->sourceFileView->width(), ui->sourceFileView->height());
1856 else if(idx == ui->tabWidget->indexOf(ui->tabOutputDir))
1858 if(!m_fileSystemModel)
1860 QTimer::singleShot(125, this, SLOT(initOutputFolderModel()));
1864 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
1868 //Center window around previous position
1869 if(initialWidth < this->width())
1871 QPoint prevPos = this->pos();
1872 int delta = (this->width() - initialWidth) >> 2;
1873 move(prevPos.x() - delta, prevPos.y());
1878 * Tab action triggered
1880 void MainWindow::tabActionActivated(QAction *action)
1882 if(action && action->data().isValid())
1885 int index = action->data().toInt(&ok);
1888 ui->tabWidget->setCurrentIndex(index);
1893 // =========================================================
1895 // =========================================================
1898 * Handle corner widget Event
1900 void MainWindow::cornerWidgetEventOccurred(QWidget *sender, QEvent *event)
1902 if(event->type() == QEvent::MouseButtonPress)
1904 QTimer::singleShot(0, this, SLOT(checkUpdatesActionActivated()));
1908 // =========================================================
1910 // =========================================================
1913 * Style action triggered
1915 void MainWindow::styleActionActivated(QAction *action)
1917 //Change style setting
1918 if(action && action->data().isValid())
1921 int actionIndex = action->data().toInt(&ok);
1924 m_settings->interfaceStyle(actionIndex);
1928 //Set up the new style
1929 switch(m_settings->interfaceStyle())
1932 if(ui->actionStyleCleanlooks->isEnabled())
1934 ui->actionStyleCleanlooks->setChecked(true);
1935 QApplication::setStyle(new QCleanlooksStyle());
1939 if(ui->actionStyleWindowsVista->isEnabled())
1941 ui->actionStyleWindowsVista->setChecked(true);
1942 QApplication::setStyle(new QWindowsVistaStyle());
1946 if(ui->actionStyleWindowsXP->isEnabled())
1948 ui->actionStyleWindowsXP->setChecked(true);
1949 QApplication::setStyle(new QWindowsXPStyle());
1953 if(ui->actionStyleWindowsClassic->isEnabled())
1955 ui->actionStyleWindowsClassic->setChecked(true);
1956 QApplication::setStyle(new QWindowsStyle());
1960 ui->actionStylePlastique->setChecked(true);
1961 QApplication::setStyle(new QPlastiqueStyle());
1965 //Force re-translate after style change
1966 if(QEvent *e = new QEvent(QEvent::LanguageChange))
1973 const type_info &styleType = typeid(*qApp->style());
1974 const bool bTransparent = ((typeid(QWindowsVistaStyle) == styleType) || (typeid(QWindowsXPStyle) == styleType));
1975 MAKE_TRANSPARENT(ui->scrollArea, bTransparent);
1977 //Also force a re-size event
1978 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1983 * Language action triggered
1985 void MainWindow::languageActionActivated(QAction *action)
1987 if(action->data().type() == QVariant::String)
1989 QString langId = action->data().toString();
1991 if(MUtils::Translation::install_translator(langId))
1993 action->setChecked(true);
1994 ui->actionLoadTranslationFromFile->setChecked(false);
1995 m_settings->currentLanguage(langId);
1996 m_settings->currentLanguageFile(QString());
2002 * Load language from file action triggered
2004 void MainWindow::languageFromFileActionActivated(bool checked)
2006 QFileDialog dialog(this, tr("Load Translation"));
2007 dialog.setFileMode(QFileDialog::ExistingFile);
2008 dialog.setNameFilter(QString("%1 (*.qm)").arg(tr("Translation Files")));
2012 QStringList selectedFiles = dialog.selectedFiles();
2013 const QString qmFile = QFileInfo(selectedFiles.first()).canonicalFilePath();
2014 if(MUtils::Translation::install_translator_from_file(qmFile))
2016 QList<QAction*> actions = m_languageActionGroup->actions();
2017 while(!actions.isEmpty())
2019 actions.takeFirst()->setChecked(false);
2021 ui->actionLoadTranslationFromFile->setChecked(true);
2022 m_settings->currentLanguageFile(qmFile);
2026 languageActionActivated(m_languageActionGroup->actions().first());
2031 // =========================================================
2033 // =========================================================
2036 * Disable update reminder action
2038 void MainWindow::disableUpdateReminderActionTriggered(bool checked)
2042 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))
2044 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!"))));
2045 m_settings->autoUpdateEnabled(false);
2049 m_settings->autoUpdateEnabled(true);
2054 QMessageBox::information(this, tr("Update Reminder"), NOBR(tr("The update reminder has been re-enabled.")));
2055 m_settings->autoUpdateEnabled(true);
2058 ui->actionDisableUpdateReminder->setChecked(!m_settings->autoUpdateEnabled());
2062 * Disable sound effects action
2064 void MainWindow::disableSoundsActionTriggered(bool checked)
2068 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))
2070 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("All sound effects have been disabled.")));
2071 m_settings->soundsEnabled(false);
2075 m_settings->soundsEnabled(true);
2080 QMessageBox::information(this, tr("Sound Effects"), NOBR(tr("The sound effects have been re-enabled.")));
2081 m_settings->soundsEnabled(true);
2084 ui->actionDisableSounds->setChecked(!m_settings->soundsEnabled());
2088 * Disable Nero AAC encoder action
2090 void MainWindow::disableNeroAacNotificationsActionTriggered(bool checked)
2094 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))
2096 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("All Nero AAC Encoder notifications have been disabled.")));
2097 m_settings->neroAacNotificationsEnabled(false);
2101 m_settings->neroAacNotificationsEnabled(true);
2106 QMessageBox::information(this, tr("Nero AAC Notifications"), NOBR(tr("The Nero AAC Encoder notifications have been re-enabled.")));
2107 m_settings->neroAacNotificationsEnabled(true);
2110 ui->actionDisableNeroAacNotifications->setChecked(!m_settings->neroAacNotificationsEnabled());
2114 * Disable slow startup action
2116 void MainWindow::disableSlowStartupNotificationsActionTriggered(bool checked)
2120 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))
2122 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been disabled.")));
2123 m_settings->antivirNotificationsEnabled(false);
2127 m_settings->antivirNotificationsEnabled(true);
2132 QMessageBox::information(this, tr("Slow Startup Notifications"), NOBR(tr("The slow startup notifications have been re-enabled.")));
2133 m_settings->antivirNotificationsEnabled(true);
2136 ui->actionDisableSlowStartupNotifications->setChecked(!m_settings->antivirNotificationsEnabled());
2140 * Import a Cue Sheet file
2142 void MainWindow::importCueSheetActionTriggered(bool checked)
2145 WidgetHideHelper hiderHelper(m_dropBox.data());
2150 QString selectedCueFile;
2152 if(MUtils::GUI::themes_enabled())
2154 selectedCueFile = QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), m_settings->mostRecentInputPath(), QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
2158 QFileDialog dialog(this, tr("Open Cue Sheet"));
2159 dialog.setFileMode(QFileDialog::ExistingFile);
2160 dialog.setNameFilter(QString("%1 (*.cue)").arg(tr("Cue Sheet File")));
2161 dialog.setDirectory(m_settings->mostRecentInputPath());
2164 selectedCueFile = dialog.selectedFiles().first();
2168 if(!selectedCueFile.isEmpty())
2170 m_settings->mostRecentInputPath(QFileInfo(selectedCueFile).canonicalPath());
2171 FileListBlockHelper fileListBlocker(m_fileListModel);
2172 QScopedPointer<CueImportDialog> cueImporter(new CueImportDialog(this, m_fileListModel, selectedCueFile, m_settings));
2173 result = cueImporter->exec();
2178 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
2179 ui->sourceFileView->update();
2180 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
2181 ui->sourceFileView->scrollToBottom();
2182 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
2189 * Show the "drop box" widget
2191 void MainWindow::showDropBoxWidgetActionTriggered(bool checked)
2193 m_settings->dropBoxWidgetEnabled(true);
2195 if(!m_dropBox->isVisible())
2198 QTimer::singleShot(2500, m_dropBox.data(), SLOT(showToolTip()));
2201 MUtils::GUI::blink_window(m_dropBox.data());
2205 * Check for beta (pre-release) updates
2207 void MainWindow::checkForBetaUpdatesActionTriggered(bool checked)
2209 bool checkUpdatesNow = false;
2213 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))
2215 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")))
2217 checkUpdatesNow = true;
2219 m_settings->autoUpdateCheckBeta(true);
2223 m_settings->autoUpdateCheckBeta(false);
2228 QMessageBox::information(this, tr("Beta Updates"), NOBR(tr("LameXP will <i>not</i> check for Beta (pre-release) updates from now on.")));
2229 m_settings->autoUpdateCheckBeta(false);
2232 ui->actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta());
2236 if(checkForUpdates())
2238 QApplication::quit();
2244 * Hibernate computer action
2246 void MainWindow::hibernateComputerActionTriggered(bool checked)
2250 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))
2252 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will hibernate the computer on shutdown from now on.")));
2253 m_settings->hibernateComputer(true);
2257 m_settings->hibernateComputer(false);
2262 QMessageBox::information(this, tr("Hibernate Computer"), NOBR(tr("LameXP will <i>not</i> hibernate the computer on shutdown from now on.")));
2263 m_settings->hibernateComputer(false);
2266 ui->actionHibernateComputer->setChecked(m_settings->hibernateComputer());
2270 * Disable shell integration action
2272 void MainWindow::disableShellIntegrationActionTriggered(bool checked)
2276 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))
2278 ShellIntegration::remove();
2279 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been disabled.")));
2280 m_settings->shellIntegrationEnabled(false);
2284 m_settings->shellIntegrationEnabled(true);
2289 ShellIntegration::install();
2290 QMessageBox::information(this, tr("Shell Integration"), NOBR(tr("The LameXP shell integration has been re-enabled.")));
2291 m_settings->shellIntegrationEnabled(true);
2294 ui->actionDisableShellIntegration->setChecked(!m_settings->shellIntegrationEnabled());
2296 if(lamexp_version_portable() && ui->actionDisableShellIntegration->isChecked())
2298 ui->actionDisableShellIntegration->setEnabled(false);
2302 // =========================================================
2304 // =========================================================
2307 * Visit homepage action
2309 void MainWindow::visitHomepageActionActivated(void)
2311 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
2313 if(action->data().isValid() && (action->data().type() == QVariant::String))
2315 QDesktopServices::openUrl(QUrl(action->data().toString()));
2323 void MainWindow::documentActionActivated(void)
2325 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
2327 openDocumentLink(action);
2332 * Check for updates action
2334 void MainWindow::checkUpdatesActionActivated(void)
2337 WidgetHideHelper hiderHelper(m_dropBox.data());
2339 if(checkForUpdates())
2341 QApplication::quit();
2345 // =========================================================
2346 // Source file slots
2347 // =========================================================
2350 * Add file(s) button
2352 void MainWindow::addFilesButtonClicked(void)
2355 WidgetHideHelper hiderHelper(m_dropBox.data());
2357 if(MUtils::GUI::themes_enabled() && (!MUTILS_DEBUG))
2359 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
2360 QStringList selectedFiles = QFileDialog::getOpenFileNames(this, tr("Add file(s)"), m_settings->mostRecentInputPath(), fileTypeFilters.join(";;"));
2361 if(!selectedFiles.isEmpty())
2363 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
2364 addFiles(selectedFiles);
2369 QFileDialog dialog(this, tr("Add file(s)"));
2370 QStringList fileTypeFilters = DecoderRegistry::getSupportedTypes();
2371 dialog.setFileMode(QFileDialog::ExistingFiles);
2372 dialog.setNameFilter(fileTypeFilters.join(";;"));
2373 dialog.setDirectory(m_settings->mostRecentInputPath());
2376 QStringList selectedFiles = dialog.selectedFiles();
2377 if(!selectedFiles.isEmpty())
2379 m_settings->mostRecentInputPath(QFileInfo(selectedFiles.first()).canonicalPath());
2380 addFiles(selectedFiles);
2387 * Open folder action
2389 void MainWindow::openFolderActionActivated(void)
2392 QString selectedFolder;
2394 if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
2396 WidgetHideHelper hiderHelper(m_dropBox.data());
2397 if(MUtils::GUI::themes_enabled())
2399 selectedFolder = QFileDialog::getExistingDirectory(this, tr("Add Folder"), m_settings->mostRecentInputPath());
2403 QFileDialog dialog(this, tr("Add Folder"));
2404 dialog.setFileMode(QFileDialog::DirectoryOnly);
2405 dialog.setDirectory(m_settings->mostRecentInputPath());
2408 selectedFolder = dialog.selectedFiles().first();
2412 if(selectedFolder.isEmpty())
2417 QStringList filterItems = DecoderRegistry::getSupportedExts();
2418 filterItems.prepend("*.*");
2421 QString filterStr = QInputDialog::getItem(this, tr("Filter Files"), tr("Select filename filter:"), filterItems, 0, false, &okay).trimmed();
2427 QRegExp regExp("\\*\\.([A-Za-z0-9]+)", Qt::CaseInsensitive);
2428 if(regExp.lastIndexIn(filterStr) >= 0)
2430 filterStr = regExp.cap(1).trimmed();
2437 m_settings->mostRecentInputPath(QDir(selectedFolder).canonicalPath());
2438 addFolder(selectedFolder, action->data().toBool(), false, filterStr);
2443 * Remove file button
2445 void MainWindow::removeFileButtonClicked(void)
2447 const QItemSelectionModel *const selection = ui->sourceFileView->selectionModel();
2448 if(selection && selection->hasSelection())
2451 const QModelIndexList selectedRows = INVERT_LIST(selection->selectedRows());
2452 if(!selectedRows.isEmpty())
2454 FileListBlockHelper fileListBlocker(m_fileListModel);
2455 firstRow = selectedRows.last().row();
2456 for(QModelIndexList::ConstIterator iter = selectedRows.constBegin(); iter != selectedRows.constEnd(); iter++)
2458 if(!m_fileListModel->removeFile(*iter))
2464 if(m_fileListModel->rowCount() > 0)
2466 const QModelIndex position = m_fileListModel->index(((firstRow >= 0) && (firstRow < m_fileListModel->rowCount())) ? firstRow : (m_fileListModel->rowCount() - 1), 0);
2467 ui->sourceFileView->selectRow(position.row());
2468 ui->sourceFileView->scrollTo(position, QAbstractItemView::PositionAtCenter);
2473 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
2478 * Clear files button
2480 void MainWindow::clearFilesButtonClicked(void)
2482 if(m_fileListModel->rowCount() > 0)
2484 m_fileListModel->clearFiles();
2488 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
2493 * Move file up button
2495 void MainWindow::fileUpButtonClicked(void)
2497 moveSelectedFiles(true);
2501 * Move file down button
2503 void MainWindow::fileDownButtonClicked(void)
2505 moveSelectedFiles(false);
2509 * Show details button
2511 void MainWindow::showDetailsButtonClicked(void)
2516 QModelIndex index = ui->sourceFileView->currentIndex();
2520 ui->sourceFileView->selectRow(index.row());
2521 QScopedPointer<MetaInfoDialog> metaInfoDialog(new MetaInfoDialog(this));
2524 AudioFileModel &file = (*m_fileListModel)[index];
2525 WidgetHideHelper hiderHelper(m_dropBox.data());
2526 iResult = metaInfoDialog->exec(file, index.row() > 0, index.row() < m_fileListModel->rowCount() - 1);
2528 //Copy all info to Meta Info tab
2529 if(iResult == INT_MAX)
2531 m_metaInfoModel->assignInfoFrom(file);
2532 ui->tabWidget->setCurrentIndex(ui->tabWidget->indexOf(ui->tabMetaData));
2538 index = m_fileListModel->index(index.row() + 1, index.column());
2539 ui->sourceFileView->selectRow(index.row());
2542 else if(iResult < 0)
2544 index = m_fileListModel->index(index.row() - 1, index.column());
2545 ui->sourceFileView->selectRow(index.row());
2549 break; /*close dilalog now*/
2554 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
2557 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2558 sourceFilesScrollbarMoved(0);
2562 * Show context menu for source files
2564 void MainWindow::sourceFilesContextMenu(const QPoint &pos)
2566 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
2567 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
2571 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
2573 m_sourceFilesContextMenu->popup(sender->mapToGlobal(pos));
2579 * Scrollbar of source files moved
2581 void MainWindow::sourceFilesScrollbarMoved(int)
2583 ui->sourceFileView->resizeColumnToContents(0);
2587 * Open selected file in external player
2589 void MainWindow::previewContextActionTriggered(void)
2591 QModelIndex index = ui->sourceFileView->currentIndex();
2592 if(!index.isValid())
2597 if(!MUtils::OS::open_media_file(m_fileListModel->getFile(index).filePath()))
2599 qDebug("Player not found, falling back to default application...");
2600 QDesktopServices::openUrl(QString("file:///").append(m_fileListModel->getFile(index).filePath()));
2605 * Find selected file in explorer
2607 void MainWindow::findFileContextActionTriggered(void)
2609 QModelIndex index = ui->sourceFileView->currentIndex();
2612 QString systemRootPath;
2614 QDir systemRoot(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER));
2615 if(systemRoot.exists() && systemRoot.cdUp())
2617 systemRootPath = systemRoot.canonicalPath();
2620 if(!systemRootPath.isEmpty())
2622 QFileInfo explorer(QString("%1/explorer.exe").arg(systemRootPath));
2623 if(explorer.exists() && explorer.isFile())
2625 QProcess::execute(explorer.canonicalFilePath(), QStringList() << "/select," << QDir::toNativeSeparators(m_fileListModel->getFile(index).filePath()));
2631 qWarning("SystemRoot directory could not be detected!");
2637 * Add all dropped files
2639 void MainWindow::handleDroppedFiles(void)
2643 static const int MIN_COUNT = 16;
2644 const QString bannerText = tr("Loading dropped files or folders, please wait...");
2645 bool bUseBanner = false;
2647 showBanner(bannerText, bUseBanner, (m_droppedFileList->count() >= MIN_COUNT));
2649 QStringList droppedFiles;
2650 while(!m_droppedFileList->isEmpty())
2652 QFileInfo file(m_droppedFileList->takeFirst().toLocalFile());
2653 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2662 qDebug("Dropped File: %s", MUTILS_UTF8(file.canonicalFilePath()));
2663 droppedFiles << file.canonicalFilePath();
2669 qDebug("Dropped Folder: %s", MUTILS_UTF8(file.canonicalFilePath()));
2670 QFileInfoList list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
2671 if(list.count() > 0)
2673 showBanner(bannerText, bUseBanner, (list.count() >= MIN_COUNT));
2674 for(QFileInfoList::ConstIterator iter = list.constBegin(); iter != list.constEnd(); iter++)
2676 droppedFiles << (*iter).canonicalFilePath();
2681 list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
2682 showBanner(bannerText, bUseBanner, (list.count() >= MIN_COUNT));
2683 for(QFileInfoList::ConstIterator iter = list.constBegin(); iter != list.constEnd(); iter++)
2685 qDebug("Descending to Folder: %s", MUTILS_UTF8((*iter).canonicalFilePath()));
2686 m_droppedFileList->prepend(QUrl::fromLocalFile((*iter).canonicalFilePath()));
2697 if(!droppedFiles.isEmpty())
2699 addFiles(droppedFiles);
2704 * Add all pending files
2706 void MainWindow::handleDelayedFiles(void)
2708 m_delayedFileTimer->stop();
2710 if(m_delayedFileList->isEmpty())
2717 m_delayedFileTimer->start(5000);
2721 if(ui->tabWidget->currentIndex() != 0)
2723 SignalBlockHelper signalBlockHelper(ui->tabWidget);
2724 ui->tabWidget->setCurrentIndex(0);
2725 tabPageChanged(ui->tabWidget->currentIndex(), true);
2728 QStringList selectedFiles;
2729 while(!m_delayedFileList->isEmpty())
2731 QFileInfo currentFile = QFileInfo(m_delayedFileList->takeFirst());
2732 if(!currentFile.exists() || !currentFile.isFile())
2736 selectedFiles << currentFile.canonicalFilePath();
2739 addFiles(selectedFiles);
2743 * Export Meta tags to CSV file
2745 void MainWindow::exportCsvContextActionTriggered(void)
2748 WidgetHideHelper hiderHelper(m_dropBox.data());
2750 QString selectedCsvFile;
2751 if(MUtils::GUI::themes_enabled())
2753 selectedCsvFile = QFileDialog::getSaveFileName(this, tr("Save CSV file"), m_settings->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2757 QFileDialog dialog(this, tr("Save CSV file"));
2758 dialog.setFileMode(QFileDialog::AnyFile);
2759 dialog.setAcceptMode(QFileDialog::AcceptSave);
2760 dialog.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2761 dialog.setDirectory(m_settings->mostRecentInputPath());
2764 selectedCsvFile = dialog.selectedFiles().first();
2768 if(!selectedCsvFile.isEmpty())
2770 m_settings->mostRecentInputPath(QFileInfo(selectedCsvFile).canonicalPath());
2771 switch(m_fileListModel->exportToCsv(selectedCsvFile))
2773 case FileListModel::CsvError_NoTags:
2774 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, there are no meta tags that can be exported!")));
2776 case FileListModel::CsvError_FileOpen:
2777 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to open CSV file for writing!")));
2779 case FileListModel::CsvError_FileWrite:
2780 QMessageBox::critical(this, tr("CSV Export"), NOBR(tr("Sorry, failed to write to the CSV file!")));
2782 case FileListModel::CsvError_OK:
2783 QMessageBox::information(this, tr("CSV Export"), NOBR(tr("The CSV files was created successfully!")));
2786 qWarning("exportToCsv: Unknown return code!");
2793 * Import Meta tags from CSV file
2795 void MainWindow::importCsvContextActionTriggered(void)
2798 WidgetHideHelper hiderHelper(m_dropBox.data());
2800 QString selectedCsvFile;
2801 if(MUtils::GUI::themes_enabled())
2803 selectedCsvFile = QFileDialog::getOpenFileName(this, tr("Open CSV file"), m_settings->mostRecentInputPath(), QString("%1 (*.csv)").arg(tr("CSV File")));
2807 QFileDialog dialog(this, tr("Open CSV file"));
2808 dialog.setFileMode(QFileDialog::ExistingFile);
2809 dialog.setNameFilter(QString("%1 (*.csv)").arg(tr("CSV File")));
2810 dialog.setDirectory(m_settings->mostRecentInputPath());
2813 selectedCsvFile = dialog.selectedFiles().first();
2817 if(!selectedCsvFile.isEmpty())
2819 m_settings->mostRecentInputPath(QFileInfo(selectedCsvFile).canonicalPath());
2820 switch(m_fileListModel->importFromCsv(this, selectedCsvFile))
2822 case FileListModel::CsvError_FileOpen:
2823 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to open CSV file for reading!")));
2825 case FileListModel::CsvError_FileRead:
2826 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, failed to read from the CSV file!")));
2828 case FileListModel::CsvError_NoTags:
2829 QMessageBox::critical(this, tr("CSV Import"), NOBR(tr("Sorry, the CSV file does not contain any known fields!")));
2831 case FileListModel::CsvError_Incomplete:
2832 QMessageBox::warning(this, tr("CSV Import"), NOBR(tr("CSV file is incomplete. Not all files were updated!")));
2834 case FileListModel::CsvError_OK:
2835 QMessageBox::information(this, tr("CSV Import"), NOBR(tr("The CSV files was imported successfully!")));
2837 case FileListModel::CsvError_Aborted:
2838 /* User aborted, ignore! */
2841 qWarning("exportToCsv: Unknown return code!");
2847 * Show or hide Drag'n'Drop notice after model reset
2849 void MainWindow::sourceModelChanged(void)
2851 m_dropNoteLabel->setVisible(m_fileListModel->rowCount() <= 0);
2854 // =========================================================
2855 // Output folder slots
2856 // =========================================================
2859 * Output folder changed (mouse clicked)
2861 void MainWindow::outputFolderViewClicked(const QModelIndex &index)
2863 if(index.isValid() && (ui->outputFolderView->currentIndex() != index))
2865 ui->outputFolderView->setCurrentIndex(index);
2868 if(m_fileSystemModel && index.isValid())
2870 QString selectedDir = m_fileSystemModel->filePath(index);
2871 if(selectedDir.length() < 3) selectedDir.append(QDir::separator());
2872 ui->outputFolderLabel->setText(QDir::toNativeSeparators(selectedDir));
2873 ui->outputFolderLabel->setToolTip(ui->outputFolderLabel->text());
2874 m_settings->outputDir(selectedDir);
2878 ui->outputFolderLabel->setText(QDir::toNativeSeparators(m_settings->outputDir()));
2879 ui->outputFolderLabel->setToolTip(ui->outputFolderLabel->text());
2884 * Output folder changed (mouse moved)
2886 void MainWindow::outputFolderViewMoved(const QModelIndex &index)
2888 if(QApplication::mouseButtons() & Qt::LeftButton)
2890 outputFolderViewClicked(index);
2895 * Goto desktop button
2897 void MainWindow::gotoDesktopButtonClicked(void)
2899 if(!m_fileSystemModel)
2901 qWarning("File system model not initialized yet!");
2905 QString desktopPath = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
2907 if(!desktopPath.isEmpty() && QDir(desktopPath).exists())
2909 ui->outputFolderView->setCurrentIndex(m_fileSystemModel->index(desktopPath));
2910 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2911 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2915 ui->buttonGotoDesktop->setEnabled(false);
2920 * Goto home folder button
2922 void MainWindow::gotoHomeFolderButtonClicked(void)
2924 if(!m_fileSystemModel)
2926 qWarning("File system model not initialized yet!");
2930 QString homePath = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
2932 if(!homePath.isEmpty() && QDir(homePath).exists())
2934 ui->outputFolderView->setCurrentIndex(m_fileSystemModel->index(homePath));
2935 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2936 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2940 ui->buttonGotoHome->setEnabled(false);
2945 * Goto music folder button
2947 void MainWindow::gotoMusicFolderButtonClicked(void)
2949 if(!m_fileSystemModel)
2951 qWarning("File system model not initialized yet!");
2955 QString musicPath = QDesktopServices::storageLocation(QDesktopServices::MusicLocation);
2957 if(!musicPath.isEmpty() && QDir(musicPath).exists())
2959 ui->outputFolderView->setCurrentIndex(m_fileSystemModel->index(musicPath));
2960 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2961 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2965 ui->buttonGotoMusic->setEnabled(false);
2970 * Goto music favorite output folder
2972 void MainWindow::gotoFavoriteFolder(void)
2974 if(!m_fileSystemModel)
2976 qWarning("File system model not initialized yet!");
2980 QAction *item = dynamic_cast<QAction*>(QObject::sender());
2984 QDir path(item->data().toString());
2987 ui->outputFolderView->setCurrentIndex(m_fileSystemModel->index(path.canonicalPath()));
2988 outputFolderViewClicked(ui->outputFolderView->currentIndex());
2989 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
2993 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
2994 m_outputFolderFavoritesMenu->removeAction(item);
2995 item->deleteLater();
3001 * Make folder button
3003 void MainWindow::makeFolderButtonClicked(void)
3007 if(!m_fileSystemModel)
3009 qWarning("File system model not initialized yet!");
3013 QDir basePath(m_fileSystemModel->fileInfo(ui->outputFolderView->currentIndex()).absoluteFilePath());
3014 QString suggestedName = tr("New Folder");
3016 if(!m_metaData->artist().isEmpty() && !m_metaData->album().isEmpty())
3018 suggestedName = QString("%1 - %2").arg(m_metaData->artist(),m_metaData->album());
3020 else if(!m_metaData->artist().isEmpty())
3022 suggestedName = m_metaData->artist();
3024 else if(!m_metaData->album().isEmpty())
3026 suggestedName =m_metaData->album();
3030 for(int i = 0; i < m_fileListModel->rowCount(); i++)
3032 const AudioFileModel &audioFile = m_fileListModel->getFile(m_fileListModel->index(i, 0));
3033 const AudioFileModel_MetaInfo &fileMetaInfo = audioFile.metaInfo();
3035 if(!fileMetaInfo.album().isEmpty() || !fileMetaInfo.artist().isEmpty())
3037 if(!fileMetaInfo.artist().isEmpty() && !fileMetaInfo.album().isEmpty())
3039 suggestedName = QString("%1 - %2").arg(fileMetaInfo.artist(), fileMetaInfo.album());
3041 else if(!fileMetaInfo.artist().isEmpty())
3043 suggestedName = fileMetaInfo.artist();
3045 else if(!fileMetaInfo.album().isEmpty())
3047 suggestedName = fileMetaInfo.album();
3054 suggestedName = MUtils::clean_file_name(suggestedName);
3058 bool bApplied = false;
3059 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();
3063 folderName = MUtils::clean_file_path(folderName.simplified());
3065 if(folderName.isEmpty())
3067 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
3072 QString newFolder = folderName;
3074 while(basePath.exists(newFolder))
3076 newFolder = QString(folderName).append(QString().sprintf(" (%d)", ++i));
3079 if(basePath.mkpath(newFolder))
3081 QDir createdDir = basePath;
3082 if(createdDir.cd(newFolder))
3084 QModelIndex newIndex = m_fileSystemModel->index(createdDir.canonicalPath());
3085 ui->outputFolderView->setCurrentIndex(newIndex);
3086 outputFolderViewClicked(newIndex);
3087 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
3092 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!")));
3100 * Output to source dir changed
3102 void MainWindow::saveToSourceFolderChanged(void)
3104 m_settings->outputToSourceDir(ui->saveToSourceFolderCheckBox->isChecked());
3108 * Prepend relative source file path to output file name changed
3110 void MainWindow::prependRelativePathChanged(void)
3112 m_settings->prependRelativeSourcePath(ui->prependRelativePathCheckBox->isChecked());
3116 * Show context menu for output folder
3118 void MainWindow::outputFolderContextMenu(const QPoint &pos)
3120 QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
3121 QWidget *sender = scrollArea ? scrollArea->viewport() : dynamic_cast<QWidget*>(QObject::sender());
3123 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0)
3125 m_outputFolderContextMenu->popup(sender->mapToGlobal(pos));
3130 * Show selected folder in explorer
3132 void MainWindow::showFolderContextActionTriggered(void)
3134 if(!m_fileSystemModel)
3136 qWarning("File system model not initialized yet!");
3140 QString path = QDir::toNativeSeparators(m_fileSystemModel->filePath(ui->outputFolderView->currentIndex()));
3141 if(!path.endsWith(QDir::separator())) path.append(QDir::separator());
3142 MUtils::OS::shell_open(this, path, true);
3146 * Refresh the directory outline
3148 void MainWindow::refreshFolderContextActionTriggered(void)
3150 //force re-initialization
3151 QTimer::singleShot(0, this, SLOT(initOutputFolderModel()));
3155 * Go one directory up
3157 void MainWindow::goUpFolderContextActionTriggered(void)
3159 QModelIndex current = ui->outputFolderView->currentIndex();
3160 if(current.isValid())
3162 QModelIndex parent = current.parent();
3163 if(parent.isValid())
3166 ui->outputFolderView->setCurrentIndex(parent);
3167 outputFolderViewClicked(parent);
3171 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
3173 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
3178 * Add current folder to favorites
3180 void MainWindow::addFavoriteFolderActionTriggered(void)
3182 QString path = m_fileSystemModel->filePath(ui->outputFolderView->currentIndex());
3183 QStringList favorites = m_settings->favoriteOutputFolders().split("|", QString::SkipEmptyParts);
3185 if(!favorites.contains(path, Qt::CaseInsensitive))
3187 favorites.append(path);
3188 while(favorites.count() > 6) favorites.removeFirst();
3192 MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
3195 m_settings->favoriteOutputFolders(favorites.join("|"));
3200 * Output folder edit finished
3202 void MainWindow::outputFolderEditFinished(void)
3204 if(ui->outputFolderEdit->isHidden())
3206 return; //Not currently in edit mode!
3211 QString text = QDir::fromNativeSeparators(ui->outputFolderEdit->text().trimmed());
3212 while(text.startsWith('"') || text.startsWith('/')) text = text.right(text.length() - 1).trimmed();
3213 while(text.endsWith('"') || text.endsWith('/')) text = text.left(text.length() - 1).trimmed();
3215 static const char *str = "?*<>|\"";
3216 for(size_t i = 0; str[i]; i++) text.replace(str[i], "_");
3218 if(!((text.length() >= 2) && text.at(0).isLetter() && text.at(1) == QChar(':')))
3220 text = QString("%1/%2").arg(QDir::fromNativeSeparators(ui->outputFolderLabel->text()), text);
3223 if(text.length() == 2) text += "/"; /* "X:" => "X:/" */
3225 while(text.length() > 2)
3227 QFileInfo info(text);
3228 if(info.exists() && info.isDir())
3230 QModelIndex index = m_fileSystemModel->index(QFileInfo(info.canonicalFilePath()).absoluteFilePath());
3234 ui->outputFolderView->setCurrentIndex(index);
3235 outputFolderViewClicked(index);
3239 else if(info.exists() && info.isFile())
3241 QModelIndex index = m_fileSystemModel->index(QFileInfo(info.canonicalPath()).absoluteFilePath());
3245 ui->outputFolderView->setCurrentIndex(index);
3246 outputFolderViewClicked(index);
3251 text = text.left(text.length() - 1).trimmed();
3254 ui->outputFolderEdit->setVisible(false);
3255 ui->outputFolderLabel->setVisible(true);
3256 ui->outputFolderView->setEnabled(true);
3258 if(!ok) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
3259 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
3263 * Initialize file system model
3265 void MainWindow::initOutputFolderModel(void)
3267 if(m_outputFolderNoteBox->isHidden())
3269 m_outputFolderNoteBox->show();
3270 m_outputFolderNoteBox->repaint();
3271 m_outputFolderViewInitCounter = 4;
3273 if(m_fileSystemModel)
3275 SET_MODEL(ui->outputFolderView, NULL);
3276 ui->outputFolderView->repaint();
3279 m_fileSystemModel.reset(new QFileSystemModelEx());
3280 if(!m_fileSystemModel.isNull())
3282 m_fileSystemModel->installEventFilter(this);
3283 connect(m_fileSystemModel.data(), SIGNAL(directoryLoaded(QString)), this, SLOT(outputFolderDirectoryLoaded(QString)));
3284 connect(m_fileSystemModel.data(), SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(outputFolderRowsInserted(QModelIndex,int,int)));
3286 SET_MODEL(ui->outputFolderView, m_fileSystemModel.data());
3287 ui->outputFolderView->header()->setStretchLastSection(true);
3288 ui->outputFolderView->header()->hideSection(1);
3289 ui->outputFolderView->header()->hideSection(2);
3290 ui->outputFolderView->header()->hideSection(3);
3292 m_fileSystemModel->setRootPath("");
3293 QModelIndex index = m_fileSystemModel->index(m_settings->outputDir());
3294 if(index.isValid()) ui->outputFolderView->setCurrentIndex(index);
3295 outputFolderViewClicked(ui->outputFolderView->currentIndex());
3298 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
3299 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3304 * Initialize file system model (do NOT call this one directly!)
3306 void MainWindow::initOutputFolderModel_doAsync(void)
3308 if(m_outputFolderViewInitCounter > 0)
3310 m_outputFolderViewInitCounter--;
3311 QTimer::singleShot(125, this, SLOT(initOutputFolderModel_doAsync()));
3315 QTimer::singleShot(125, m_outputFolderNoteBox.data(), SLOT(hide()));
3316 ui->outputFolderView->setFocus();
3321 * Center current folder in view
3323 void MainWindow::centerOutputFolderModel(void)
3325 if(ui->outputFolderView->isVisible())
3327 centerOutputFolderModel_doAsync();
3328 QTimer::singleShot(125, this, SLOT(centerOutputFolderModel_doAsync()));
3333 * Center current folder in view (do NOT call this one directly!)
3335 void MainWindow::centerOutputFolderModel_doAsync(void)
3337 if(ui->outputFolderView->isVisible())
3339 m_outputFolderViewCentering = true;
3340 const QModelIndex index = ui->outputFolderView->currentIndex();
3341 ui->outputFolderView->scrollTo(index, QAbstractItemView::PositionAtCenter);
3342 ui->outputFolderView->setFocus();
3347 * File system model asynchronously loaded a dir
3349 void MainWindow::outputFolderDirectoryLoaded(const QString &path)
3351 if(m_outputFolderViewCentering)
3353 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
3358 * File system model inserted new items
3360 void MainWindow::outputFolderRowsInserted(const QModelIndex &parent, int start, int end)
3362 if(m_outputFolderViewCentering)
3364 CENTER_CURRENT_OUTPUT_FOLDER_DELAYED;
3369 * Directory view item was expanded by user
3371 void MainWindow::outputFolderItemExpanded(const QModelIndex &item)
3373 //We need to stop centering as soon as the user has expanded an item manually!
3374 m_outputFolderViewCentering = false;
3378 * View event for output folder control occurred
3380 void MainWindow::outputFolderViewEventOccurred(QWidget *sender, QEvent *event)
3382 switch(event->type())
3386 case QEvent::KeyPress:
3387 case QEvent::KeyRelease:
3388 case QEvent::FocusIn:
3389 case QEvent::FocusOut:
3390 case QEvent::TouchEnd:
3391 outputFolderViewClicked(ui->outputFolderView->currentIndex());
3397 * Mouse event for output folder control occurred
3399 void MainWindow::outputFolderMouseEventOccurred(QWidget *sender, QEvent *event)
3401 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
3402 QPoint pos = (mouseEvent) ? mouseEvent->pos() : QPoint();
3404 if(sender == ui->outputFolderLabel)
3406 switch(event->type())
3408 case QEvent::MouseButtonPress:
3409 if(mouseEvent && (mouseEvent->button() == Qt::LeftButton))
3411 QString path = ui->outputFolderLabel->text();
3412 if(!path.endsWith(QDir::separator())) path.append(QDir::separator());
3413 MUtils::OS::shell_open(this, path, true);
3417 ui->outputFolderLabel->setForegroundRole(QPalette::Link);
3420 ui->outputFolderLabel->setForegroundRole(QPalette::WindowText);
3425 if((sender == ui->outputFoldersFovoritesLabel) || (sender == ui->outputFoldersEditorLabel) || (sender == ui->outputFoldersGoUpLabel))
3427 const type_info &styleType = typeid(*qApp->style());
3428 if((typeid(QPlastiqueStyle) == styleType) || (typeid(QWindowsStyle) == styleType))
3430 switch(event->type())
3433 dynamic_cast<QLabel*>(sender)->setFrameShadow(ui->outputFolderView->isEnabled() ? QFrame::Raised : QFrame::Plain);
3435 case QEvent::MouseButtonPress:
3436 dynamic_cast<QLabel*>(sender)->setFrameShadow(ui->outputFolderView->isEnabled() ? QFrame::Sunken : QFrame::Plain);
3438 case QEvent::MouseButtonRelease:
3439 dynamic_cast<QLabel*>(sender)->setFrameShadow(ui->outputFolderView->isEnabled() ? QFrame::Raised : QFrame::Plain);
3442 dynamic_cast<QLabel*>(sender)->setFrameShadow(ui->outputFolderView->isEnabled() ? QFrame::Plain : QFrame::Plain);
3448 dynamic_cast<QLabel*>(sender)->setFrameShadow(QFrame::Plain);
3451 if((event->type() == QEvent::MouseButtonRelease) && ui->outputFolderView->isEnabled() && (mouseEvent))
3453 if(pos.x() <= sender->width() && pos.y() <= sender->height() && pos.x() >= 0 && pos.y() >= 0 && mouseEvent->button() != Qt::MidButton)
3455 if(sender == ui->outputFoldersFovoritesLabel)
3457 m_outputFolderFavoritesMenu->popup(sender->mapToGlobal(pos));
3459 else if(sender == ui->outputFoldersEditorLabel)
3461 ui->outputFolderView->setEnabled(false);
3462 ui->outputFolderLabel->setVisible(false);
3463 ui->outputFolderEdit->setVisible(true);
3464 ui->outputFolderEdit->setText(ui->outputFolderLabel->text());
3465 ui->outputFolderEdit->selectAll();
3466 ui->outputFolderEdit->setFocus();
3468 else if(sender == ui->outputFoldersGoUpLabel)
3470 QTimer::singleShot(0, this, SLOT(goUpFolderContextActionTriggered()));
3474 MUTILS_THROW("Oups, this is not supposed to happen!");
3481 // =========================================================
3482 // Metadata tab slots
3483 // =========================================================
3486 * Edit meta button clicked
3488 void MainWindow::editMetaButtonClicked(void)
3492 const QModelIndex index = ui->metaDataView->currentIndex();
3496 m_metaInfoModel->editItem(index, this);
3498 if(index.row() == 4)
3500 m_settings->metaInfoPosition(m_metaData->position());
3506 * Reset meta button clicked
3508 void MainWindow::clearMetaButtonClicked(void)
3511 m_metaInfoModel->clearData();
3515 * Meta tags enabled changed
3517 void MainWindow::metaTagsEnabledChanged(void)
3519 m_settings->writeMetaTags(ui->writeMetaDataCheckBox->isChecked());
3523 * Playlist enabled changed
3525 void MainWindow::playlistEnabledChanged(void)
3527 m_settings->createPlaylist(ui->generatePlaylistCheckBox->isChecked());
3530 // =========================================================
3531 // Compression tab slots
3532 // =========================================================
3537 void MainWindow::updateEncoder(int id)
3539 /*qWarning("\nupdateEncoder(%d)", id);*/
3541 m_settings->compressionEncoder(id);
3542 const AbstractEncoderInfo *info = EncoderRegistry::getEncoderInfo(id);
3544 //Update UI controls
3545 ui->radioButtonModeQuality ->setEnabled(info->isModeSupported(SettingsModel::VBRMode));
3546 ui->radioButtonModeAverageBitrate->setEnabled(info->isModeSupported(SettingsModel::ABRMode));
3547 ui->radioButtonConstBitrate ->setEnabled(info->isModeSupported(SettingsModel::CBRMode));
3549 //Initialize checkbox state
3550 if(ui->radioButtonModeQuality->isEnabled()) ui->radioButtonModeQuality->setChecked(true);
3551 else if(ui->radioButtonModeAverageBitrate->isEnabled()) ui->radioButtonModeAverageBitrate->setChecked(true);
3552 else if(ui->radioButtonConstBitrate->isEnabled()) ui->radioButtonConstBitrate->setChecked(true);
3553 else MUTILS_THROW("It appears that the encoder does not support *any* RC mode!");
3555 //Apply current RC mode
3556 const int currentRCMode = EncoderRegistry::loadEncoderMode(m_settings, id);
3557 switch(currentRCMode)
3559 case SettingsModel::VBRMode: if(ui->radioButtonModeQuality->isEnabled()) ui->radioButtonModeQuality->setChecked(true); break;
3560 case SettingsModel::ABRMode: if(ui->radioButtonModeAverageBitrate->isEnabled()) ui->radioButtonModeAverageBitrate->setChecked(true); break;
3561 case SettingsModel::CBRMode: if(ui->radioButtonConstBitrate->isEnabled()) ui->radioButtonConstBitrate->setChecked(true); break;
3562 default: MUTILS_THROW("updateEncoder(): Unknown rc-mode encountered!");
3565 //Display encoder description
3566 if(const char* description = info->description())
3568 ui->labelEncoderInfo->setVisible(true);
3569 ui->labelEncoderInfo->setText(tr("Current Encoder: %1").arg(QString::fromUtf8(description)));
3573 ui->labelEncoderInfo->setVisible(false);
3577 updateRCMode(m_modeButtonGroup->checkedId());
3581 * Update rate-control mode
3583 void MainWindow::updateRCMode(int id)
3585 /*qWarning("updateRCMode(%d)", id);*/
3588 const int currentEncoder = m_encoderButtonGroup->checkedId();
3589 EncoderRegistry::saveEncoderMode(m_settings, currentEncoder, id);
3591 //Fetch encoder info
3592 const AbstractEncoderInfo *info = EncoderRegistry::getEncoderInfo(currentEncoder);
3593 const int valueCount = info->valueCount(id);
3596 if(!info->isModeSupported(id))
3598 qWarning("Attempting to use an unsupported RC mode (%d) with current encoder (%d)!", id, currentEncoder);
3599 ui->labelBitrate->setText("(ERROR)");
3603 //Update slider min/max values
3606 SignalBlockHelper signalBlockHelper(ui->sliderBitrate);
3607 ui->sliderBitrate->setEnabled(true);
3608 ui->sliderBitrate->setMinimum(0);
3609 ui->sliderBitrate->setMaximum(valueCount-1);
3613 SignalBlockHelper signalBlockHelper(ui->sliderBitrate);
3614 ui->sliderBitrate->setEnabled(false);
3615 ui->sliderBitrate->setMinimum(0);
3616 ui->sliderBitrate->setMaximum(2);
3619 //Now update bitrate/quality value!
3622 const int currentValue = EncoderRegistry::loadEncoderValue(m_settings, currentEncoder, id);
3623 ui->sliderBitrate->setValue(qBound(0, currentValue, valueCount-1));
3624 updateBitrate(qBound(0, currentValue, valueCount-1));
3628 ui->sliderBitrate->setValue(1);
3636 void MainWindow::updateBitrate(int value)
3638 /*qWarning("updateBitrate(%d)", value);*/
3640 //Load current encoder and RC mode
3641 const int currentEncoder = m_encoderButtonGroup->checkedId();
3642 const int currentRCMode = m_modeButtonGroup->checkedId();
3644 //Fetch encoder info
3645 const AbstractEncoderInfo *info = EncoderRegistry::getEncoderInfo(currentEncoder);
3646 const int valueCount = info->valueCount(currentRCMode);
3649 if(!info->isModeSupported(currentRCMode))
3651 qWarning("Attempting to use an unsupported RC mode (%d) with current encoder (%d)!", currentRCMode, currentEncoder);
3652 ui->labelBitrate->setText("(ERROR)");
3656 //Store new bitrate value
3659 EncoderRegistry::saveEncoderValue(m_settings, currentEncoder, currentRCMode, qBound(0, value, valueCount-1));
3662 //Update bitrate value
3663 const int displayValue = (valueCount > 0) ? info->valueAt(currentRCMode, qBound(0, value, valueCount-1)) : INT_MAX;
3664 switch(info->valueType(currentRCMode))
3666 case AbstractEncoderInfo::TYPE_BITRATE:
3667 ui->labelBitrate->setText(QString("%1 kbps").arg(QString::number(displayValue)));
3669 case AbstractEncoderInfo::TYPE_APPROX_BITRATE:
3670 ui->labelBitrate->setText(QString("≈ %1 kbps").arg(QString::number(displayValue)));
3672 case AbstractEncoderInfo::TYPE_QUALITY_LEVEL_INT:
3673 ui->labelBitrate->setText(tr("Quality Level %1").arg(QString::number(displayValue)));
3675 case AbstractEncoderInfo::TYPE_QUALITY_LEVEL_FLT:
3676 ui->labelBitrate->setText(tr("Quality Level %1").arg(QString().sprintf("%.2f", double(displayValue)/100.0)));
3678 case AbstractEncoderInfo::TYPE_COMPRESSION_LEVEL:
3679 ui->labelBitrate->setText(tr("Compression %1").arg(QString::number(displayValue)));
3681 case AbstractEncoderInfo::TYPE_UNCOMPRESSED:
3682 ui->labelBitrate->setText(tr("Uncompressed"));
3685 MUTILS_THROW("Unknown display value type encountered!");
3691 * Event for compression tab occurred
3693 void MainWindow::compressionTabEventOccurred(QWidget *sender, QEvent *event)
3695 static const QUrl helpUrl("http://lamexp.sourceforge.net/doc/FAQ.html#054010d9");
3697 if((sender == ui->labelCompressionHelp) && (event->type() == QEvent::MouseButtonPress))
3699 QDesktopServices::openUrl(helpUrl);
3701 else if((sender == ui->labelResetEncoders) && (event->type() == QEvent::MouseButtonPress))
3703 PLAY_SOUND_OPTIONAL("blast", true);
3704 EncoderRegistry::resetAllEncoders(m_settings);
3705 m_settings->compressionEncoder(SettingsModel::MP3Encoder);
3706 ui->radioButtonEncoderMP3->setChecked(true);
3707 QTimer::singleShot(0, this, SLOT(updateEncoder()));
3711 // =========================================================
3712 // Advanced option slots
3713 // =========================================================
3716 * Lame algorithm quality changed
3718 void MainWindow::updateLameAlgoQuality(int value)
3725 text = tr("Best Quality (Slow)");
3728 text = tr("High Quality (Recommended)");
3731 text = tr("Acceptable Quality (Fast)");
3734 text = tr("Poor Quality (Very Fast)");
3740 m_settings->lameAlgoQuality(value);
3741 ui->labelLameAlgoQuality->setText(text);
3744 bool warning = (value == 0), notice = (value == 3);
3745 ui->labelLameAlgoQualityWarning->setVisible(warning);
3746 ui->labelLameAlgoQualityWarningIcon->setVisible(warning);
3747 ui->labelLameAlgoQualityNotice->setVisible(notice);
3748 ui->labelLameAlgoQualityNoticeIcon->setVisible(notice);
3749 ui->labelLameAlgoQualitySpacer->setVisible(warning || notice);
3753 * Bitrate management endabled/disabled
3755 void MainWindow::bitrateManagementEnabledChanged(bool checked)
3757 m_settings->bitrateManagementEnabled(checked);
3761 * Minimum bitrate has changed
3763 void MainWindow::bitrateManagementMinChanged(int value)
3765 if(value > ui->spinBoxBitrateManagementMax->value())
3767 ui->spinBoxBitrateManagementMin->setValue(ui->spinBoxBitrateManagementMax->value());
3768 m_settings->bitrateManagementMinRate(ui->spinBoxBitrateManagementMax->value());
3772 m_settings->bitrateManagementMinRate(value);
3777 * Maximum bitrate has changed
3779 void MainWindow::bitrateManagementMaxChanged(int value)
3781 if(value < ui->spinBoxBitrateManagementMin->value())
3783 ui->spinBoxBitrateManagementMax->setValue(ui->spinBoxBitrateManagementMin->value());
3784 m_settings->bitrateManagementMaxRate(ui->spinBoxBitrateManagementMin->value());
3788 m_settings->bitrateManagementMaxRate(value);
3793 * Channel mode has changed
3795 void MainWindow::channelModeChanged(int value)
3797 if(value >= 0) m_settings->lameChannelMode(value);
3801 * Sampling rate has changed
3803 void MainWindow::samplingRateChanged(int value)
3805 if(value >= 0) m_settings->samplingRate(value);
3809 * Nero AAC 2-Pass mode changed
3811 void MainWindow::neroAAC2PassChanged(bool checked)
3813 m_settings->neroAACEnable2Pass(checked);
3817 * Nero AAC profile mode changed
3819 void MainWindow::neroAACProfileChanged(int value)
3821 if(value >= 0) m_settings->aacEncProfile(value);
3825 * Aften audio coding mode changed
3827 void MainWindow::aftenCodingModeChanged(int value)
3829 if(value >= 0) m_settings->aftenAudioCodingMode(value);
3833 * Aften DRC mode changed
3835 void MainWindow::aftenDRCModeChanged(int value)
3837 if(value >= 0) m_settings->aftenDynamicRangeCompression(value);
3841 * Aften exponent search size changed
3843 void MainWindow::aftenSearchSizeChanged(int value)
3845 if(value >= 0) m_settings->aftenExponentSearchSize(value);
3849 * Aften fast bit allocation changed
3851 void MainWindow::aftenFastAllocationChanged(bool checked)
3853 m_settings->aftenFastBitAllocation(checked);
3858 * Opus encoder settings changed
3860 void MainWindow::opusSettingsChanged(void)
3862 m_settings->opusFramesize(ui->comboBoxOpusFramesize->currentIndex());
3863 m_settings->opusComplexity(ui->spinBoxOpusComplexity->value());
3864 m_settings->opusDisableResample(ui->checkBoxOpusDisableResample->isChecked());
3868 * Normalization filter enabled changed
3870 void MainWindow::normalizationEnabledChanged(bool checked)
3872 m_settings->normalizationFilterEnabled(checked);
3873 normalizationDynamicChanged(ui->checkBoxNormalizationFilterDynamic->isChecked());
3877 * Dynamic normalization enabled changed
3879 void MainWindow::normalizationDynamicChanged(bool checked)
3881 ui->spinBoxNormalizationFilterSize->setEnabled(ui->checkBoxNormalizationFilterEnabled->isChecked() && checked);
3882 m_settings->normalizationFilterDynamic(checked);
3886 * Normalization max. volume changed
3888 void MainWindow::normalizationMaxVolumeChanged(double value)
3890 m_settings->normalizationFilterMaxVolume(static_cast<int>(value * 100.0));
3894 * Normalization equalization mode changed
3896 void MainWindow::normalizationCoupledChanged(bool checked)
3898 m_settings->normalizationFilterCoupled(checked);
3902 * Normalization filter size changed
3904 void MainWindow::normalizationFilterSizeChanged(int value)
3906 m_settings->normalizationFilterSize(value);
3910 * Normalization filter size editing finished
3912 void MainWindow::normalizationFilterSizeFinished(void)
3914 const int value = ui->spinBoxNormalizationFilterSize->value();
3915 if((value % 2) != 1)
3917 bool rnd = MUtils::parity(MUtils::next_rand32());
3918 ui->spinBoxNormalizationFilterSize->setValue(rnd ? value+1 : value-1);
3923 * Tone adjustment has changed (Bass)
3925 void MainWindow::toneAdjustBassChanged(double value)
3927 m_settings->toneAdjustBass(static_cast<int>(value * 100.0));
3928 ui->spinBoxToneAdjustBass->setPrefix((value > 0) ? "+" : QString());
3932 * Tone adjustment has changed (Treble)
3934 void MainWindow::toneAdjustTrebleChanged(double value)
3936 m_settings->toneAdjustTreble(static_cast<int>(value * 100.0));
3937 ui->spinBoxToneAdjustTreble->setPrefix((value > 0) ? "+" : QString());
3941 * Tone adjustment has been reset
3943 void MainWindow::toneAdjustTrebleReset(void)
3945 ui->spinBoxToneAdjustBass->setValue(m_settings->toneAdjustBassDefault());
3946 ui->spinBoxToneAdjustTreble->setValue(m_settings->toneAdjustTrebleDefault());
3947 toneAdjustBassChanged(ui->spinBoxToneAdjustBass->value());
3948 toneAdjustTrebleChanged(ui->spinBoxToneAdjustTreble->value());
3952 * Custom encoder parameters changed
3954 void MainWindow::customParamsChanged(void)
3956 ui->lineEditCustomParamLAME->setText(ui->lineEditCustomParamLAME->text().simplified());
3957 ui->lineEditCustomParamOggEnc->setText(ui->lineEditCustomParamOggEnc->text().simplified());
3958 ui->lineEditCustomParamNeroAAC->setText(ui->lineEditCustomParamNeroAAC->text().simplified());
3959 ui->lineEditCustomParamFLAC->setText(ui->lineEditCustomParamFLAC->text().simplified());
3960 ui->lineEditCustomParamAften->setText(ui->lineEditCustomParamAften->text().simplified());
3961 ui->lineEditCustomParamOpus->setText(ui->lineEditCustomParamOpus->text().simplified());
3963 bool customParamsUsed = false;
3964 if(!ui->lineEditCustomParamLAME->text().isEmpty()) customParamsUsed = true;
3965 if(!ui->lineEditCustomParamOggEnc->text().isEmpty()) customParamsUsed = true;
3966 if(!ui->lineEditCustomParamNeroAAC->text().isEmpty()) customParamsUsed = true;
3967 if(!ui->lineEditCustomParamFLAC->text().isEmpty()) customParamsUsed = true;
3968 if(!ui->lineEditCustomParamAften->text().isEmpty()) customParamsUsed = true;
3969 if(!ui->lineEditCustomParamOpus->text().isEmpty()) customParamsUsed = true;
3971 ui->labelCustomParamsIcon->setVisible(customParamsUsed);
3972 ui->labelCustomParamsText->setVisible(customParamsUsed);
3973 ui->labelCustomParamsSpacer->setVisible(customParamsUsed);
3975 EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::MP3Encoder, ui->lineEditCustomParamLAME->text());
3976 EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::VorbisEncoder, ui->lineEditCustomParamOggEnc->text());
3977 EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::AACEncoder, ui->lineEditCustomParamNeroAAC->text());
3978 EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::FLACEncoder, ui->lineEditCustomParamFLAC->text());
3979 EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::AC3Encoder, ui->lineEditCustomParamAften->text());
3980 EncoderRegistry::saveEncoderCustomParams(m_settings, SettingsModel::OpusEncoder, ui->lineEditCustomParamOpus->text());
3984 * One of the rename buttons has been clicked
3986 void MainWindow::renameButtonClicked(bool checked)
3988 if(QPushButton *const button = dynamic_cast<QPushButton*>(QObject::sender()))
3990 QWidget *pages[] = { ui->pageRename_Rename, ui->pageRename_RegExp, ui->pageRename_FileEx };
3991 QPushButton *buttons[] = { ui->buttonRename_Rename, ui->buttonRename_RegExp, ui->buttonRename_FileEx };
3992 for(int i = 0; i < 3; i++)
3994 const bool match = (button == buttons[i]);
3995 buttons[i]->setChecked(match);
3996 if(match && checked) ui->stackedWidget->setCurrentWidget(pages[i]);
4002 * Rename output files enabled changed
4004 void MainWindow::renameOutputEnabledChanged(const bool &checked)
4006 m_settings->renameFiles_renameEnabled(checked);
4010 * Rename output files patterm changed
4012 void MainWindow::renameOutputPatternChanged(void)
4014 QString temp = ui->lineEditRenamePattern->text().simplified();
4015 ui->lineEditRenamePattern->setText(temp.isEmpty() ? m_settings->renameFiles_renamePatternDefault() : temp);
4016 m_settings->renameFiles_renamePattern(ui->lineEditRenamePattern->text());
4020 * Rename output files patterm changed
4022 void MainWindow::renameOutputPatternChanged(const QString &text, const bool &silent)
4024 QString pattern(text.simplified());
4026 pattern.replace("<BaseName>", "The_White_Stripes_-_Fell_In_Love_With_A_Girl", Qt::CaseInsensitive);
4027 pattern.replace("<TrackNo>", "04", Qt::CaseInsensitive);
4028 pattern.replace("<Title>", "Fell In Love With A Girl", Qt::CaseInsensitive);
4029 pattern.replace("<Artist>", "The White Stripes", Qt::CaseInsensitive);
4030 pattern.replace("<Album>", "White Blood Cells", Qt::CaseInsensitive);
4031 pattern.replace("<Year>", "2001", Qt::CaseInsensitive);
4032 pattern.replace("<Comment>", "Encoded by LameXP", Qt::CaseInsensitive);
4034 const QString patternClean = MUtils::clean_file_name(pattern);
4036 if(pattern.compare(patternClean))
4038 if(ui->lineEditRenamePattern->palette().color(QPalette::Text) != Qt::red)
4040 if(!silent) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
4041 SET_TEXT_COLOR(ui->lineEditRenamePattern, Qt::red);
4046 if(ui->lineEditRenamePattern->palette() != QPalette())
4048 if(!silent) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO);
4049 ui->lineEditRenamePattern->setPalette(QPalette());
4053 ui->labelRanameExample->setText(patternClean);
4057 * Regular expression enabled changed
4059 void MainWindow::renameRegExpEnabledChanged(const bool &checked)
4061 m_settings->renameFiles_regExpEnabled(checked);
4065 * Regular expression value has changed
4067 void MainWindow::renameRegExpValueChanged(void)
4069 const QString search = ui->lineEditRenameRegExp_Search->text() .trimmed();
4070 const QString replace = ui->lineEditRenameRegExp_Replace->text().simplified();
4071 ui->lineEditRenameRegExp_Search ->setText(search.isEmpty() ? m_settings->renameFiles_regExpSearchDefault() : search);
4072 ui->lineEditRenameRegExp_Replace->setText(replace.isEmpty() ? m_settings->renameFiles_regExpReplaceDefault() : replace);
4073 m_settings->renameFiles_regExpSearch (ui->lineEditRenameRegExp_Search ->text());
4074 m_settings->renameFiles_regExpReplace(ui->lineEditRenameRegExp_Replace->text());
4078 * Regular expression search pattern has changed
4080 void MainWindow::renameRegExpSearchChanged(const QString &text, const bool &silent)
4082 const QString pattern(text.trimmed());
4084 if((!pattern.isEmpty()) && (!QRegExp(pattern.trimmed()).isValid()))
4086 if(ui->lineEditRenameRegExp_Search->palette().color(QPalette::Text) != Qt::red)
4088 if(!silent) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
4089 SET_TEXT_COLOR(ui->lineEditRenameRegExp_Search, Qt::red);
4094 if(ui->lineEditRenameRegExp_Search->palette() != QPalette())
4096 if(!silent) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO);
4097 ui->lineEditRenameRegExp_Search->setPalette(QPalette());
4101 renameRegExpReplaceChanged(ui->lineEditRenameRegExp_Replace->text(), silent);
4105 * Regular expression replacement string changed
4107 void MainWindow::renameRegExpReplaceChanged(const QString &text, const bool &silent)
4109 QString replacement(text.simplified());
4110 const QString search(ui->lineEditRenameRegExp_Search->text().trimmed());
4112 if(!search.isEmpty())
4114 const QRegExp regexp(search);
4115 if(regexp.isValid())
4117 const int count = regexp.captureCount();
4118 const QString blank;
4119 for(int i = 0; i < count; i++)
4121 replacement.replace(QString("\\%0").arg(QString::number(i+1)), blank);
4126 if(replacement.compare(MUtils::clean_file_name(replacement)))
4128 if(ui->lineEditRenameRegExp_Replace->palette().color(QPalette::Text) != Qt::red)
4130 if(!silent) MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
4131 SET_TEXT_COLOR(ui->lineEditRenameRegExp_Replace, Qt::red);
4136 if(ui->lineEditRenameRegExp_Replace->palette() != QPalette())
4138 if(!silent) MUtils::Sound::beep(MUtils::Sound::BEEP_NFO);
4139 ui->lineEditRenameRegExp_Replace->setPalette(QPalette());
4145 * Show list of rename macros
4147 void MainWindow::showRenameMacros(const QString &text)
4149 if(text.compare("reset", Qt::CaseInsensitive) == 0)
4151 ui->lineEditRenamePattern->setText(m_settings->renameFiles_renamePatternDefault());
4155 if(text.compare("regexp", Qt::CaseInsensitive) == 0)
4157 MUtils::OS::shell_open(this, "http://www.regular-expressions.info/quickstart.html");
4161 const QString format = QString("<tr><td><tt><%1></tt></td><td> </td><td>%2</td></tr>");
4163 QString message = QString("<table>");
4164 message += QString(format).arg("BaseName", tr("File name without extension"));
4165 message += QString(format).arg("TrackNo", tr("Track number with leading zero"));
4166 message += QString(format).arg("Title", tr("Track title"));
4167 message += QString(format).arg("Artist", tr("Artist name"));
4168 message += QString(format).arg("Album", tr("Album name"));
4169 message += QString(format).arg("Year", tr("Year with (at least) four digits"));
4170 message += QString(format).arg("Comment", tr("Comment"));
4171 message += "</table><br><br>";
4172 message += QString("%1<br>").arg(tr("Characters forbidden in file names:"));
4173 message += "<b><tt>\\ / : * ? < > |<br>";
4175 QMessageBox::information(this, tr("Rename Macros"), message, tr("Discard"));
4178 void MainWindow::fileExtAddButtonClicked(void)
4180 if(FileExtsModel *const model = dynamic_cast<FileExtsModel*>(ui->tableViewFileExts->model()))
4182 model->addOverwrite(this);
4186 void MainWindow::fileExtRemoveButtonClicked(void)
4188 if(FileExtsModel *const model = dynamic_cast<FileExtsModel*>(ui->tableViewFileExts->model()))
4190 const QModelIndex selected = ui->tableViewFileExts->currentIndex();
4191 if(selected.isValid())
4193 model->removeOverwrite(selected);
4197 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
4202 void MainWindow::fileExtModelChanged(void)
4204 if(FileExtsModel *const model = dynamic_cast<FileExtsModel*>(ui->tableViewFileExts->model()))
4206 m_settings->renameFiles_fileExtension(model->exportItems());
4210 void MainWindow::forceStereoDownmixEnabledChanged(bool checked)
4212 m_settings->forceStereoDownmix(checked);
4216 * Maximum number of instances changed
4218 void MainWindow::updateMaximumInstances(int value)
4220 ui->labelMaxInstances->setText(tr("%n Instance(s)", "", value));
4221 m_settings->maximumInstances(ui->checkBoxAutoDetectInstances->isChecked() ? NULL : value);
4225 * Auto-detect number of instances
4227 void MainWindow::autoDetectInstancesChanged(bool checked)
4229 m_settings->maximumInstances(checked ? NULL : ui->sliderMaxInstances->value());
4233 * Browse for custom TEMP folder button clicked
4235 void MainWindow::browseCustomTempFolderButtonClicked(void)
4237 QString newTempFolder;
4239 if(MUtils::GUI::themes_enabled())
4241 newTempFolder = QFileDialog::getExistingDirectory(this, QString(), m_settings->customTempPath());
4245 QFileDialog dialog(this);
4246 dialog.setFileMode(QFileDialog::DirectoryOnly);
4247 dialog.setDirectory(m_settings->customTempPath());
4250 newTempFolder = dialog.selectedFiles().first();
4254 if(!newTempFolder.isEmpty())
4256 QFile writeTest(QString("%1/~%2.tmp").arg(newTempFolder, MUtils::rand_str()));
4257 if(writeTest.open(QIODevice::ReadWrite))
4260 ui->lineEditCustomTempFolder->setText(QDir::toNativeSeparators(newTempFolder));
4264 QMessageBox::warning(this, tr("Access Denied"), tr("Cannot write to the selected directory. Please choose another directory!"));
4270 * Custom TEMP folder changed
4272 void MainWindow::customTempFolderChanged(const QString &text)
4274 m_settings->customTempPath(QDir::fromNativeSeparators(text));
4278 * Use custom TEMP folder option changed
4280 void MainWindow::useCustomTempFolderChanged(bool checked)
4282 m_settings->customTempPathEnabled(!checked);
4286 * Help for custom parameters was requested
4288 void MainWindow::customParamsHelpRequested(QWidget *obj, QEvent *event)
4290 if(event->type() != QEvent::MouseButtonRelease)
4295 if(QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event))
4297 QPoint pos = mouseEvent->pos();
4298 if(!(pos.x() <= obj->width() && pos.y() <= obj->height() && pos.x() >= 0 && pos.y() >= 0 && mouseEvent->button() != Qt::MidButton))
4304 if(obj == ui->helpCustomParamLAME) showCustomParamsHelpScreen("lame.exe", "--longhelp");
4305 else if(obj == ui->helpCustomParamOggEnc) showCustomParamsHelpScreen("oggenc2.exe", "--help");
4306 else if(obj == ui->helpCustomParamNeroAAC)
4308 switch(EncoderRegistry::getAacEncoder())
4310 case SettingsModel::AAC_ENCODER_QAAC: showCustomParamsHelpScreen("qaac64.exe|qaac.exe", "--help"); break;
4311 case SettingsModel::AAC_ENCODER_FHG : showCustomParamsHelpScreen("fhgaacenc.exe", "" ); break;
4312 case SettingsModel::AAC_ENCODER_FDK : showCustomParamsHelpScreen("fdkaac.exe", "--help"); break;
4313 case SettingsModel::AAC_ENCODER_NERO: showCustomParamsHelpScreen("neroAacEnc.exe", "-help" ); break;
4314 default: MUtils::Sound::beep(MUtils::Sound::BEEP_ERR); break;
4317 else if(obj == ui->helpCustomParamFLAC) showCustomParamsHelpScreen("flac.exe", "--help");
4318 else if(obj == ui->helpCustomParamAften) showCustomParamsHelpScreen("aften.exe", "-h" );
4319 else if(obj == ui->helpCustomParamOpus) showCustomParamsHelpScreen("opusenc.exe", "--help");
4320 else MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
4324 * Show help for custom parameters
4326 void MainWindow::showCustomParamsHelpScreen(const QString &toolName, const QString &command)
4328 const QStringList toolNames = toolName.split('|', QString::SkipEmptyParts);
4330 for(QStringList::ConstIterator iter = toolNames.constBegin(); iter != toolNames.constEnd(); iter++)
4332 if(lamexp_tools_check(*iter))
4334 binary = lamexp_tools_lookup(*iter);
4339 if(binary.isEmpty())
4341 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
4342 qWarning("customParamsHelpRequested: Binary could not be found!");
4347 MUtils::init_process(process, QFileInfo(binary).absolutePath());
4349 process.start(binary, command.isEmpty() ? QStringList() : QStringList() << command);
4351 qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
4353 if(process.waitForStarted(15000))
4355 qApp->processEvents();
4356 process.waitForFinished(15000);
4359 if(process.state() != QProcess::NotRunning)
4362 process.waitForFinished(-1);
4365 qApp->restoreOverrideCursor();
4366 QStringList output; bool spaceFlag = true;
4368 while(process.canReadLine())
4370 QString temp = QString::fromUtf8(process.readLine());
4371 TRIM_STRING_RIGHT(temp);
4374 if(!spaceFlag) { output << temp; spaceFlag = true; }
4378 output << temp; spaceFlag = false;
4382 if(output.count() < 1)
4384 qWarning("Empty output, cannot show help screen!");
4385 MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
4388 WidgetHideHelper hiderHelper(m_dropBox.data());
4389 QScopedPointer<LogViewDialog> dialog(new LogViewDialog(this));
4390 dialog->exec(output);
4393 void MainWindow::overwriteModeChanged(int id)
4395 if((id == SettingsModel::Overwrite_Replaces) && (m_settings->overwriteMode() != SettingsModel::Overwrite_Replaces))
4397 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)
4399 ui->radioButtonOverwriteModeKeepBoth->setChecked(m_settings->overwriteMode() == SettingsModel::Overwrite_KeepBoth);
4400 ui->radioButtonOverwriteModeSkipFile->setChecked(m_settings->overwriteMode() == SettingsModel::Overwrite_SkipFile);
4405 m_settings->overwriteMode(id);
4409 * Reset all advanced options to their defaults
4411 void MainWindow::resetAdvancedOptionsButtonClicked(void)
4413 PLAY_SOUND_OPTIONAL("blast", true);
4415 ui->sliderLameAlgoQuality ->setValue(m_settings->lameAlgoQualityDefault());
4416 ui->spinBoxBitrateManagementMin ->setValue(m_settings->bitrateManagementMinRateDefault());
4417 ui->spinBoxBitrateManagementMax ->setValue(m_settings->bitrateManagementMaxRateDefault());
4418 ui->spinBoxNormalizationFilterPeak->setValue(static_cast<double>(m_settings->normalizationFilterMaxVolumeDefault()) / 100.0);
4419 ui->spinBoxNormalizationFilterSize->setValue(m_settings->normalizationFilterSizeDefault());
4420 ui->spinBoxToneAdjustBass ->setValue(static_cast<double>(m_settings->toneAdjustBassDefault()) / 100.0);
4421 ui->spinBoxToneAdjustTreble ->setValue(static_cast<double>(m_settings->toneAdjustTrebleDefault()) / 100.0);
4422 ui->spinBoxAftenSearchSize ->setValue(m_settings->aftenExponentSearchSizeDefault());
4423 ui->spinBoxOpusComplexity ->setValue(m_settings->opusComplexityDefault());
4424 ui->comboBoxMP3ChannelMode ->setCurrentIndex(m_settings->lameChannelModeDefault());
4425 ui->comboBoxSamplingRate ->setCurrentIndex(m_settings->samplingRateDefault());
4426 ui->comboBoxAACProfile ->setCurrentIndex(m_settings->aacEncProfileDefault());
4427 ui->comboBoxAftenCodingMode ->setCurrentIndex(m_settings->aftenAudioCodingModeDefault());
4428 ui->comboBoxAftenDRCMode ->setCurrentIndex(m_settings->aftenDynamicRangeCompressionDefault());
4429 ui->comboBoxOpusFramesize ->setCurrentIndex(m_settings->opusFramesizeDefault());
4431 SET_CHECKBOX_STATE(ui->checkBoxBitrateManagement, m_settings->bitrateManagementEnabledDefault());
4432 SET_CHECKBOX_STATE(ui->checkBoxNeroAAC2PassMode, m_settings->neroAACEnable2PassDefault());
4433 SET_CHECKBOX_STATE(ui->checkBoxNormalizationFilterEnabled, m_settings->normalizationFilterEnabledDefault());
4434 SET_CHECKBOX_STATE(ui->checkBoxNormalizationFilterDynamic, m_settings->normalizationFilterDynamicDefault());
4435 SET_CHECKBOX_STATE(ui->checkBoxNormalizationFilterCoupled, m_settings->normalizationFilterCoupledDefault());
4436 SET_CHECKBOX_STATE(ui->checkBoxAutoDetectInstances, (m_settings->maximumInstancesDefault() < 1));
4437 SET_CHECKBOX_STATE(ui->checkBoxUseSystemTempFolder, (!m_settings->customTempPathEnabledDefault()));
4438 SET_CHECKBOX_STATE(ui->checkBoxAftenFastAllocation, m_settings->aftenFastBitAllocationDefault());
4439 SET_CHECKBOX_STATE(ui->checkBoxRename_Rename, m_settings->renameFiles_renameEnabledDefault());
4440 SET_CHECKBOX_STATE(ui->checkBoxRename_RegExp, m_settings->renameFiles_regExpEnabledDefault());
4441 SET_CHECKBOX_STATE(ui->checkBoxForceStereoDownmix, m_settings->forceStereoDownmixDefault());
4442 SET_CHECKBOX_STATE(ui->checkBoxOpusDisableResample, m_settings->opusDisableResampleDefault());
4444 ui->lineEditCustomParamLAME ->setText(m_settings->customParametersLAMEDefault());
4445 ui->lineEditCustomParamOggEnc ->setText(m_settings->customParametersOggEncDefault());
4446 ui->lineEditCustomParamNeroAAC ->setText(m_settings->customParametersAacEncDefault());
4447 ui->lineEditCustomParamFLAC ->setText(m_settings->customParametersFLACDefault());
4448 ui->lineEditCustomParamOpus ->setText(m_settings->customParametersOpusEncDefault());
4449 ui->lineEditCustomTempFolder ->setText(QDir::toNativeSeparators(m_settings->customTempPathDefault()));
4450 ui->lineEditRenamePattern ->setText(m_settings->renameFiles_renamePatternDefault());
4451 ui->lineEditRenameRegExp_Search ->setText(m_settings->renameFiles_regExpSearchDefault());
4452 ui->lineEditRenameRegExp_Replace->setText(m_settings->renameFiles_regExpReplaceDefault());
4454 if(m_settings->overwriteModeDefault() == SettingsModel::Overwrite_KeepBoth) ui->radioButtonOverwriteModeKeepBoth->click();
4455 if(m_settings->overwriteModeDefault() == SettingsModel::Overwrite_SkipFile) ui->radioButtonOverwriteModeSkipFile->click();
4456 if(m_settings->overwriteModeDefault() == SettingsModel::Overwrite_Replaces) ui->radioButtonOverwriteModeReplaces->click();
4458 if(FileExtsModel *const model = dynamic_cast<FileExtsModel*>(ui->tableViewFileExts->model()))
4460 model->importItems(m_settings->renameFiles_fileExtensionDefault());
4463 ui->scrollArea->verticalScrollBar()->setValue(0);
4464 ui->buttonRename_Rename->click();
4465 customParamsChanged();
4466 renameOutputPatternChanged();
4467 renameRegExpValueChanged();
4470 // =========================================================
4471 // Multi-instance handling slots
4472 // =========================================================
4475 * Other instance detected
4477 void MainWindow::notifyOtherInstance(void)
4479 if(!(BANNER_VISIBLE))
4481 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);
4487 * Add file from another instance
4489 void MainWindow::addFileDelayed(const QString &filePath, bool tryASAP)
4491 if(tryASAP && !m_delayedFileTimer->isActive())
4493 qDebug("Received file: %s", MUTILS_UTF8(filePath));
4494 m_delayedFileList->append(filePath);
4495 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4498 m_delayedFileTimer->stop();
4499 qDebug("Received file: %s", MUTILS_UTF8(filePath));
4500 m_delayedFileList->append(filePath);
4501 m_delayedFileTimer->start(5000);
4505 * Add files from another instance
4507 void MainWindow::addFilesDelayed(const QStringList &filePaths, bool tryASAP)
4509 if(tryASAP && (!m_delayedFileTimer->isActive()))
4511 qDebug("Received %d file(s).", filePaths.count());
4512 m_delayedFileList->append(filePaths);
4513 QTimer::singleShot(0, this, SLOT(handleDelayedFiles()));
4517 m_delayedFileTimer->stop();
4518 qDebug("Received %d file(s).", filePaths.count());
4519 m_delayedFileList->append(filePaths);
4520 m_delayedFileTimer->start(5000);
4525 * Add folder from another instance
4527 void MainWindow::addFolderDelayed(const QString &folderPath, bool recursive)
4529 if(!(BANNER_VISIBLE))
4531 addFolder(folderPath, recursive, true);
4535 // =========================================================
4537 // =========================================================
4540 * Restore the override cursor
4542 void MainWindow::restoreCursor(void)
4544 QApplication::restoreOverrideCursor();