OSDN Git Service

Added an "advanced" option to apply the original file's "creation" and "last modified...
[lamexp/LameXP.git] / src / Dialog_Processing.cpp
index eaf03bb..7640ed4 100644 (file)
@@ -1,11 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 // the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// (at your option) any later version, but always including the *additional*
+// restrictions defined in the "License.txt" file.
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include "Dialog_Processing.h"
 
 //UIC includes
-#include "../tmp/UIC_ProcessingDialog.h"
+#include "UIC_ProcessingDialog.h"
 
+//Internal
 #include "Global.h"
-#include "Resource.h"
 #include "Model_FileList.h"
 #include "Model_Progress.h"
 #include "Model_Settings.h"
+#include "Model_FileExts.h"
 #include "Thread_Process.h"
 #include "Thread_CPUObserver.h"
 #include "Thread_RAMObserver.h"
 #include "Thread_DiskObserver.h"
 #include "Dialog_LogView.h"
-#include "Encoder_AAC.h"
-#include "Encoder_AAC_FHG.h"
-#include "Encoder_AAC_QAAC.h"
-#include "Encoder_AC3.h"
-#include "Encoder_DCA.h"
-#include "Encoder_FLAC.h"
-#include "Encoder_MP3.h"
-#include "Encoder_Vorbis.h"
-#include "Encoder_Opus.h"
-#include "Encoder_Wave.h"
 #include "Registry_Decoder.h"
+#include "Registry_Encoder.h"
 #include "Filter_Downmix.h"
 #include "Filter_Normalize.h"
 #include "Filter_Resample.h"
 #include "Filter_ToneAdjust.h"
-#include "WinSevenTaskbar.h"
 
+//MUtils
+#include <MUtils/Global.h>
+#include <MUtils/OSSupport.h>
+#include <MUtils/GUI.h>
+#include <MUtils/CPUFeatures.h>
+#include <MUtils/Sound.h>
+#include <MUtils/Taskbar7.h>
+
+//Qt
 #include <QApplication>
 #include <QRect>
 #include <QDesktopWidget>
 #include <QProgressDialog>
 #include <QResizeEvent>
 #include <QTime>
+#include <QElapsedTimer>
+#include <QThreadPool>
 
-#include <MMSystem.h>
 #include <math.h>
 #include <float.h>
+#include <stdint.h>
 
 ////////////////////////////////////////////////////////////
 
 //Maximum number of parallel instances
-#define MAX_INSTANCES 16U
+#define MAX_INSTANCES 32U
 
 //Function to calculate the number of instances
 static int cores2instances(int cores);
@@ -121,6 +124,14 @@ while(0)
 } \
 while(0)
 
+#define PLAY_SOUND_OPTIONAL(NAME, ASYNC) do \
+{ \
+       if(m_settings->soundsEnabled()) MUtils::Sound::play_sound((NAME), (ASYNC)); \
+} \
+while(0)
+
+#define IS_VBR(RC_MODE) ((RC_MODE) == SettingsModel::VBRMode)
+
 ////////////////////////////////////////////////////////////
 
 //Dummy class for UserData
@@ -138,24 +149,27 @@ private:
 // Constructor
 ////////////////////////////////////////////////////////////
 
-ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settings, QWidget *parent)
+ProcessingDialog::ProcessingDialog(FileListModel *const fileListModel, const AudioFileModel_MetaInfo *const metaInfo, const SettingsModel *const settings, QWidget *const parent)
 :
        QDialog(parent),
        ui(new Ui::ProcessingDialog),
        m_systemTray(new QSystemTrayIcon(QIcon(":/icons/cd_go.png"), this)),
+       m_taskbar(new MUtils::Taskbar7(this)),
        m_settings(settings),
        m_metaInfo(metaInfo),
-       m_shutdownFlag(shutdownFlag_None),
-       m_diskObserver(NULL),
-       m_cpuObserver(NULL),
-       m_ramObserver(NULL),
+       m_shutdownFlag(SHUTDOWN_FLAG_NONE),
        m_progressViewFilter(-1),
+       m_initThreads(0),
+       m_defaultColor(new QColor()),
        m_firstShow(true)
 {
        //Init the dialog, from the .ui file
        ui->setupUi(this);
        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
        
+       //Update the window icon
+       MUtils::GUI::set_window_icon(this, lamexp_app_icon(), true);
+
        //Update header icon
        ui->label_headerIcon->setPixmap(lamexp_app_icon().pixmap(ui->label_headerIcon->size()));
        
@@ -176,35 +190,34 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        connect(ui->button_AbortProcess, SIGNAL(clicked()), this, SLOT(abortEncoding()));
        
        //Init progress indicator
-       m_progressIndicator = new QMovie(":/images/Working.gif");
+       m_progressIndicator.reset(new QMovie(":/images/Working.gif"));
        m_progressIndicator->setCacheMode(QMovie::CacheAll);
-       m_progressIndicator->setSpeed(50);
-       ui->label_headerWorking->setMovie(m_progressIndicator);
+       ui->label_headerWorking->setMovie(m_progressIndicator.data());
        ui->progressBar->setValue(0);
 
        //Init progress model
-       m_progressModel = new ProgressModel();
-       ui->view_log->setModel(m_progressModel);
+       m_progressModel.reset(new ProgressModel());
+       ui->view_log->setModel(m_progressModel.data());
        ui->view_log->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
        ui->view_log->verticalHeader()->hide();
        ui->view_log->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
        ui->view_log->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
        ui->view_log->viewport()->installEventFilter(this);
-       connect(m_progressModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(progressModelChanged()));
-       connect(m_progressModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(progressModelChanged()));
-       connect(m_progressModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(progressModelChanged()));
-       connect(m_progressModel, SIGNAL(modelReset()), this, SLOT(progressModelChanged()));
+       connect(m_progressModel.data(), SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(progressModelChanged()));
+       connect(m_progressModel.data(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SLOT(progressModelChanged()));
+       connect(m_progressModel.data(), SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(progressModelChanged()));
+       connect(m_progressModel.data(), SIGNAL(modelReset()), this, SLOT(progressModelChanged()));
        connect(ui->view_log, SIGNAL(activated(QModelIndex)), this, SLOT(logViewDoubleClicked(QModelIndex)));
        connect(ui->view_log->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(logViewSectionSizeChanged(int,int,int)));
 
        //Create context menu
-       m_contextMenu = new QMenu();
-       QAction *contextMenuDetailsAction = m_contextMenu->addAction(QIcon(":/icons/zoom.png"), tr("Show details for selected job"));
+       m_contextMenu.reset(new QMenu());
+       QAction *contextMenuDetailsAction  = m_contextMenu->addAction(QIcon(":/icons/zoom.png"), tr("Show details for selected job"));
        QAction *contextMenuShowFileAction = m_contextMenu->addAction(QIcon(":/icons/folder_go.png"), tr("Browse Output File Location"));
        m_contextMenu->addSeparator();
 
        //Create "filter" context menu
-       m_progressViewFilterGroup = new QActionGroup(this);
+       m_progressViewFilterGroup.reset(new QActionGroup(this));
        QAction *contextMenuFilterAction[5] = {NULL, NULL, NULL, NULL, NULL};
        if(QMenu *filterMenu = m_contextMenu->addMenu(QIcon(":/icons/filter.png"), tr("Filter Log Items")))
        {
@@ -221,27 +234,24 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        }
 
        //Create info label
-       if(m_filterInfoLabel = new QLabel(ui->view_log))
-       {
-               m_filterInfoLabel->setFrameShape(QFrame::NoFrame);
-               m_filterInfoLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
-               m_filterInfoLabel->setUserData(0, new IntUserData(-1));
-               SET_FONT_BOLD(m_filterInfoLabel, true);
-               SET_TEXT_COLOR(m_filterInfoLabel, Qt::darkGray);
-               m_filterInfoLabel->setContextMenuPolicy(Qt::CustomContextMenu);
-               connect(m_filterInfoLabel, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTriggered(QPoint)));
-               m_filterInfoLabel->hide();
-       }
-       if(m_filterInfoLabelIcon = new QLabel(ui->view_log))
-       {
-               m_filterInfoLabelIcon->setFrameShape(QFrame::NoFrame);
-               m_filterInfoLabelIcon->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
-               m_filterInfoLabelIcon->setContextMenuPolicy(Qt::CustomContextMenu);
-               const QIcon &ico = m_progressModel->getIcon(ProgressModel::JobState(-1));
-               m_filterInfoLabelIcon->setPixmap(ico.pixmap(16, 16));
-               connect(m_filterInfoLabelIcon, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTriggered(QPoint)));
-               m_filterInfoLabelIcon->hide();
-       }
+       m_filterInfoLabel.reset(new QLabel(ui->view_log));
+       m_filterInfoLabel->setFrameShape(QFrame::NoFrame);
+       m_filterInfoLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
+       m_filterInfoLabel->setUserData(0, new IntUserData(-1));
+       SET_FONT_BOLD(m_filterInfoLabel, true);
+       SET_TEXT_COLOR(m_filterInfoLabel, Qt::darkGray);
+       m_filterInfoLabel->setContextMenuPolicy(Qt::CustomContextMenu);
+       connect(m_filterInfoLabel.data(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTriggered(QPoint)));
+       m_filterInfoLabel->hide();
+
+       m_filterInfoLabelIcon .reset(new QLabel(ui->view_log));
+       m_filterInfoLabelIcon->setFrameShape(QFrame::NoFrame);
+       m_filterInfoLabelIcon->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
+       m_filterInfoLabelIcon->setContextMenuPolicy(Qt::CustomContextMenu);
+       const QIcon &ico = m_progressModel->getIcon(ProgressModel::JobState(-1));
+       m_filterInfoLabelIcon->setPixmap(ico.pixmap(16, 16));
+       connect(m_filterInfoLabelIcon.data(), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTriggered(QPoint)));
+       m_filterInfoLabelIcon->hide();
 
        //Connect context menu
        ui->view_log->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -254,6 +264,13 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        }
        SET_FONT_BOLD(contextMenuDetailsAction, true);
 
+       //Setup file extensions
+       if(!m_settings->renameFiles_fileExtension().isEmpty())
+       {
+               m_fileExts.reset(new FileExtsModel());
+               m_fileExts->importItems(m_settings->renameFiles_fileExtension());
+       }
+
        //Enque jobs
        if(fileListModel)
        {
@@ -267,7 +284,7 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        ui->label_headerStatus->setText(QString("<b>%1</b><br>%2").arg(tr("Encoding Files"), tr("Your files are being encoded, please be patient...")));
        
        //Enable system tray icon
-       connect(m_systemTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systemTrayActivated(QSystemTrayIcon::ActivationReason)));
+       connect(m_systemTray.data(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systemTrayActivated(QSystemTrayIcon::ActivationReason)));
 
        //Init other vars
        m_runningThreads = 0;
@@ -278,7 +295,6 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        m_skippedJobs.clear();
        m_userAborted = false;
        m_forcedAbort = false;
-       m_timerStart = 0I64;
 }
 
 ////////////////////////////////////////////////////////////
@@ -289,12 +305,12 @@ ProcessingDialog::~ProcessingDialog(void)
 {
        ui->view_log->setModel(NULL);
 
-       if(m_progressIndicator)
+       if(!m_progressIndicator.isNull())
        {
                m_progressIndicator->stop();
        }
 
-       if(m_diskObserver)
+       if(!m_diskObserver.isNull())
        {
                m_diskObserver->stop();
                if(!m_diskObserver->wait(15000))
@@ -303,7 +319,8 @@ ProcessingDialog::~ProcessingDialog(void)
                        m_diskObserver->wait();
                }
        }
-       if(m_cpuObserver)
+
+       if(!m_cpuObserver.isNull())
        {
                m_cpuObserver->stop();
                if(!m_cpuObserver->wait(15000))
@@ -312,7 +329,8 @@ ProcessingDialog::~ProcessingDialog(void)
                        m_cpuObserver->wait();
                }
        }
-       if(m_ramObserver)
+
+       if(!m_ramObserver.isNull())
        {
                m_ramObserver->stop();
                if(!m_ramObserver->wait(15000))
@@ -322,29 +340,19 @@ ProcessingDialog::~ProcessingDialog(void)
                }
        }
 
-       while(!m_threadList.isEmpty())
+       if(!m_threadPool.isNull())
        {
-               ProcessThread *thread = m_threadList.takeFirst();
-               thread->terminate();
-               thread->wait(15000);
-               delete thread;
+               if(!m_threadPool->waitForDone(100))
+               {
+                       emit abortRunningTasks();
+                       m_threadPool->waitForDone();
+               }
        }
 
-       LAMEXP_DELETE(m_progressIndicator);
-       LAMEXP_DELETE(m_systemTray);
-       LAMEXP_DELETE(m_diskObserver);
-       LAMEXP_DELETE(m_cpuObserver);
-       LAMEXP_DELETE(m_ramObserver);
-       LAMEXP_DELETE(m_progressViewFilterGroup);
-       LAMEXP_DELETE(m_filterInfoLabel);
-       LAMEXP_DELETE(m_filterInfoLabelIcon);
-       LAMEXP_DELETE(m_contextMenu);
-       LAMEXP_DELETE(m_progressModel);
-
-       WinSevenTaskbar::setOverlayIcon(this, NULL);
-       WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNoState);
-
-       LAMEXP_DELETE(ui);
+       m_taskbar->setOverlayIcon(NULL);
+       m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NONE);
+       
+       MUTILS_DELETE(ui);
 }
 
 ////////////////////////////////////////////////////////////
@@ -358,22 +366,20 @@ void ProcessingDialog::showEvent(QShowEvent *event)
        if(m_firstShow)
        {
                static const char *NA = " N/A";
-       
-               setCloseButtonEnabled(false);
+
+               MUtils::GUI::enable_close_button(this, false);
                ui->button_closeDialog->setEnabled(false);
                ui->button_AbortProcess->setEnabled(false);
+               m_progressIndicator->start();
                m_systemTray->setVisible(true);
-       
-               if(!SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS))
-               {
-                       SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
-               }
-
+               
+               MUtils::OS::change_process_priority(1);
+               
                ui->label_cpu->setText(NA);
                ui->label_disk->setText(NA);
                ui->label_ram->setText(NA);
 
-               QTimer::singleShot(1000, this, SLOT(initEncoding()));
+               QTimer::singleShot(500, this, SLOT(initEncoding()));
                m_firstShow = false;
        }
 
@@ -395,21 +401,19 @@ void ProcessingDialog::closeEvent(QCloseEvent *event)
 
 bool ProcessingDialog::eventFilter(QObject *obj, QEvent *event)
 {
-       static QColor defaultColor = QColor();
-
        if(obj == ui->label_versionInfo)
        {
                if(event->type() == QEvent::Enter)
                {
                        QPalette palette = ui->label_versionInfo->palette();
-                       defaultColor = palette.color(QPalette::Normal, QPalette::WindowText);
+                       *m_defaultColor = palette.color(QPalette::Normal, QPalette::WindowText);
                        palette.setColor(QPalette::Normal, QPalette::WindowText, Qt::red);
                        ui->label_versionInfo->setPalette(palette);
                }
                else if(event->type() == QEvent::Leave)
                {
                        QPalette palette = ui->label_versionInfo->palette();
-                       palette.setColor(QPalette::Normal, QPalette::WindowText, defaultColor);
+                       palette.setColor(QPalette::Normal, QPalette::WindowText, *m_defaultColor);
                        ui->label_versionInfo->setPalette(palette);
                }
                else if(event->type() == QEvent::MouseButtonPress)
@@ -426,18 +430,18 @@ bool ProcessingDialog::event(QEvent *e)
 {
        switch(e->type())
        {
-       case lamexp_event_queryendsession:
+       case MUtils::GUI::USER_EVENT_QUERYENDSESSION:
                qWarning("System is shutting down, preparing to abort...");
                if(!m_userAborted) abortEncoding(true);
                return true;
-       case lamexp_event_endsession:
+       case MUtils::GUI::USER_EVENT_ENDSESSION:
                qWarning("System is shutting down, encoding will be aborted now...");
                if(isVisible())
                {
                        while(!close())
                        {
                                if(!m_userAborted) abortEncoding(true);
-                               QApplication::processEvents(QEventLoop::WaitForMoreEvents & QEventLoop::ExcludeUserInputEvents);
+                               qApp->processEvents(QEventLoop::WaitForMoreEvents | QEventLoop::ExcludeUserInputEvents);
                        }
                }
                m_pendingJobs.clear();
@@ -462,11 +466,6 @@ void ProcessingDialog::resizeEvent(QResizeEvent *event)
        }
 }
 
-bool ProcessingDialog::winEvent(MSG *message, long *result)
-{
-       return WinSevenTaskbar::handleWinEvent(message, result);
-}
-
 ////////////////////////////////////////////////////////////
 // SLOTS
 ////////////////////////////////////////////////////////////
@@ -489,7 +488,6 @@ void ProcessingDialog::initEncoding(void)
 
        CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor(Qt::white));
        SET_PROGRESS_TEXT(tr("Encoding files, please wait..."));
-       m_progressIndicator->start();
        
        ui->button_closeDialog->setEnabled(false);
        ui->button_AbortProcess->setEnabled(true);
@@ -497,53 +495,156 @@ void ProcessingDialog::initEncoding(void)
        ui->checkBox_shutdownComputer->setEnabled(true);
        ui->checkBox_shutdownComputer->setChecked(false);
 
-       WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
-       WinSevenTaskbar::setTaskbarProgress(this, 0, m_pendingJobs.count());
-       WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/control_play_blue.png"));
+       m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NORMAL);
+       m_taskbar->setTaskbarProgress(0, m_pendingJobs.count());
+       m_taskbar->setOverlayIcon(&QIcon(":/icons/control_play_blue.png"));
 
        if(!m_diskObserver)
        {
-               m_diskObserver = new DiskObserverThread(m_settings->customTempPathEnabled() ? m_settings->customTempPath() : lamexp_temp_folder2());
-               connect(m_diskObserver, SIGNAL(messageLogged(QString,int)), m_progressModel, SLOT(addSystemMessage(QString,int)), Qt::QueuedConnection);
-               connect(m_diskObserver, SIGNAL(freeSpaceChanged(quint64)), this, SLOT(diskUsageHasChanged(quint64)), Qt::QueuedConnection);
+               m_diskObserver.reset(new DiskObserverThread(m_settings->customTempPathEnabled() ? m_settings->customTempPath() : MUtils::temp_folder()));
+               connect(m_diskObserver.data(), SIGNAL(messageLogged(QString,int)), m_progressModel.data(), SLOT(addSystemMessage(QString,int)), Qt::QueuedConnection);
+               connect(m_diskObserver.data(), SIGNAL(freeSpaceChanged(quint64)), this, SLOT(diskUsageHasChanged(quint64)), Qt::QueuedConnection);
                m_diskObserver->start();
        }
        if(!m_cpuObserver)
        {
-               m_cpuObserver = new CPUObserverThread();
-               connect(m_cpuObserver, SIGNAL(currentUsageChanged(double)), this, SLOT(cpuUsageHasChanged(double)), Qt::QueuedConnection);
+               m_cpuObserver.reset(new CPUObserverThread());
+               connect(m_cpuObserver.data(), SIGNAL(currentUsageChanged(double)), this, SLOT(cpuUsageHasChanged(double)), Qt::QueuedConnection);
                m_cpuObserver->start();
        }
        if(!m_ramObserver)
        {
-               m_ramObserver = new RAMObserverThread();
-               connect(m_ramObserver, SIGNAL(currentUsageChanged(double)), this, SLOT(ramUsageHasChanged(double)), Qt::QueuedConnection);
+               m_ramObserver.reset(new RAMObserverThread());
+               connect(m_ramObserver.data(), SIGNAL(currentUsageChanged(double)), this, SLOT(ramUsageHasChanged(double)), Qt::QueuedConnection);
                m_ramObserver->start();
        }
+
+       if(m_threadPool.isNull())
+       {
+               unsigned int maximumInstances = qBound(0U, m_settings->maximumInstances(), MAX_INSTANCES);
+               if(maximumInstances < 1)
+               {
+                       const MUtils::CPUFetaures::cpu_info_t cpuFeatures = MUtils::CPUFetaures::detect();
+                       maximumInstances = cores2instances(qBound(1U, cpuFeatures.count, 64U));
+               }
+
+               maximumInstances = qBound(1U, maximumInstances, static_cast<unsigned int>(m_pendingJobs.count()));
+               if(maximumInstances > 1)
+               {
+                       m_progressModel->addSystemMessage(tr("Multi-threading enabled: Running %1 instances in parallel!").arg(QString::number(maximumInstances)));
+               }
+
+               m_threadPool.reset(new QThreadPool());
+               m_threadPool->setMaxThreadCount(maximumInstances);
+       }
+
+       m_initThreads = m_threadPool->maxThreadCount();
+       QTimer::singleShot(100, this, SLOT(initNextJob()));
        
-       unsigned int maximumInstances = qBound(0U, m_settings->maximumInstances(), MAX_INSTANCES);
-       if(maximumInstances < 1)
+       m_totalTime.reset(new QElapsedTimer());
+       m_totalTime->start();
+}
+
+void ProcessingDialog::initNextJob(void)
+{
+       if((m_initThreads > 0) && (!m_userAborted))
+       {
+               startNextJob();
+               if(--m_initThreads > 0)
+               {
+                       QTimer::singleShot(32, this, SLOT(initNextJob()));
+               }
+       }
+}
+
+void ProcessingDialog::startNextJob(void)
+{
+       if(m_pendingJobs.isEmpty())
        {
-               lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features(lamexp_arguments());
-               maximumInstances = cores2instances(qBound(1, cpuFeatures.count, 64));
+               qWarning("No more files left, unable to start another job!");
+               return;
        }
+       
+       m_currentFile++;
+       m_runningThreads++;
 
-       maximumInstances = qBound(1U, maximumInstances, static_cast<unsigned int>(m_pendingJobs.count()));
-       if(maximumInstances > 1)
+       AudioFileModel currentFile = updateMetaInfo(m_pendingJobs.takeFirst());
+       bool nativeResampling = false;
+
+       //Create encoder instance
+       AbstractEncoder *encoder = EncoderRegistry::createInstance(m_settings->compressionEncoder(), m_settings, &nativeResampling);
+
+       //Create processing thread
+       ProcessThread *thread = new ProcessThread
+       (
+               currentFile,
+               (m_settings->outputToSourceDir() ? QFileInfo(currentFile.filePath()).absolutePath() : m_settings->outputDir()),
+               (m_settings->customTempPathEnabled() ? m_settings->customTempPath() : MUtils::temp_folder()),
+               encoder,
+               m_settings->prependRelativeSourcePath() && (!m_settings->outputToSourceDir())
+       );
+
+       //Add audio filters
+       if(m_settings->forceStereoDownmix())
+       {
+               thread->addFilter(new DownmixFilter());
+       }
+       if((m_settings->samplingRate() > 0) && !nativeResampling)
        {
-               m_progressModel->addSystemMessage(tr("Multi-threading enabled: Running %1 instances in parallel!").arg(QString::number(maximumInstances)));
+               if(SettingsModel::samplingRates[m_settings->samplingRate()] != currentFile.techInfo().audioSamplerate() || currentFile.techInfo().audioSamplerate() == 0)
+               {
+                       thread->addFilter(new ResampleFilter(SettingsModel::samplingRates[m_settings->samplingRate()]));
+               }
        }
+       if((m_settings->toneAdjustBass() != 0) || (m_settings->toneAdjustTreble() != 0))
+       {
+               thread->addFilter(new ToneAdjustFilter(m_settings->toneAdjustBass(), m_settings->toneAdjustTreble()));
+       }
+       if(m_settings->normalizationFilterEnabled())
+       {
+               thread->addFilter(new NormalizeFilter(m_settings->normalizationFilterMaxVolume(), m_settings->normalizationFilterDynamic(), m_settings->normalizationFilterCoupled(), m_settings->normalizationFilterSize()));
+       }
+       if(m_settings->renameFiles_renameEnabled() && (!m_settings->renameFiles_renamePattern().simplified().isEmpty()))
+       {
+               thread->setRenamePattern(m_settings->renameFiles_renamePattern());
+       }
+       if(m_settings->renameFiles_regExpEnabled() && (!m_settings->renameFiles_regExpSearch().trimmed().isEmpty()) && (!m_settings->renameFiles_regExpReplace().simplified().isEmpty()))
+       {
+               thread->setRenameRegExp(m_settings->renameFiles_regExpSearch(), m_settings->renameFiles_regExpReplace());
+       }
+       if(!m_fileExts.isNull())
+       {
+               thread->setRenameFileExt(m_fileExts->apply(QString::fromUtf8(EncoderRegistry::getEncoderInfo(m_settings->compressionEncoder())->extension())));
+       }
+       if(m_settings->overwriteMode() != SettingsModel::Overwrite_KeepBoth)
+       {
+               thread->setOverwriteMode((m_settings->overwriteMode() == SettingsModel::Overwrite_SkipFile), (m_settings->overwriteMode() == SettingsModel::Overwrite_Replaces));
+       }
+       if (m_settings->keepOriginalDataTime())
+       {
+               thread->setKeepDateTime(m_settings->keepOriginalDataTime());
+       }
+
+       m_allJobs.append(thread->getId());
+       
+       //Connect thread signals
+       connect(thread, SIGNAL(processFinished()), this, SLOT(doneEncoding()), Qt::QueuedConnection);
+       connect(thread, SIGNAL(processStateInitialized(QUuid,QString,QString,int)), m_progressModel.data(), SLOT(addJob(QUuid,QString,QString,int)), Qt::QueuedConnection);
+       connect(thread, SIGNAL(processStateChanged(QUuid,QString,int)), m_progressModel.data(), SLOT(updateJob(QUuid,QString,int)), Qt::QueuedConnection);
+       connect(thread, SIGNAL(processStateFinished(QUuid,QString,int)), this, SLOT(processFinished(QUuid,QString,int)), Qt::QueuedConnection);
+       connect(thread, SIGNAL(processMessageLogged(QUuid,QString)), m_progressModel.data(), SLOT(appendToLog(QUuid,QString)), Qt::QueuedConnection);
+       connect(this, SIGNAL(abortRunningTasks()), thread, SLOT(abort()), Qt::DirectConnection);
 
-       for(unsigned int i = 0; i < maximumInstances; i++)
+       //Initialize thread object
+       if(!thread->init())
        {
-               startNextJob();
-               qApp->processEvents();
+               qFatal("Fatal Error: Thread initialization has failed!");
        }
 
-       LARGE_INTEGER counter;
-       if(QueryPerformanceCounter(&counter))
+       //Give it a go!
+       if(!thread->start(m_threadPool.data()))
        {
-               m_timerStart = counter.QuadPart;
+               qWarning("Job failed to start or file was skipped!");
        }
 }
 
@@ -553,11 +654,7 @@ void ProcessingDialog::abortEncoding(bool force)
        if(force) m_forcedAbort = true;
        ui->button_AbortProcess->setEnabled(false);
        SET_PROGRESS_TEXT(tr("Aborted! Waiting for running jobs to terminate..."));
-
-       for(int i = 0; i < m_threadList.count(); i++)
-       {
-               m_threadList.at(i)->abort();
-       }
+       emit abortRunningTasks();
 }
 
 void ProcessingDialog::doneEncoding(void)
@@ -568,25 +665,19 @@ void ProcessingDialog::doneEncoding(void)
        if(!m_userAborted)
        {
                SET_PROGRESS_TEXT(tr("Encoding: %n file(s) of %1 completed so far, please wait...", "", ui->progressBar->value()).arg(QString::number(ui->progressBar->maximum())));
-               WinSevenTaskbar::setTaskbarProgress(this, ui->progressBar->value(), ui->progressBar->maximum());
+               m_taskbar->setTaskbarProgress(ui->progressBar->value(), ui->progressBar->maximum());
        }
        
-       int index = m_threadList.indexOf(dynamic_cast<ProcessThread*>(QWidget::sender()));
-       if(index >= 0)
+       if((!m_pendingJobs.isEmpty()) && (!m_userAborted))
        {
-               m_threadList.takeAt(index)->deleteLater();
-       }
-
-       if(!m_pendingJobs.isEmpty() && !m_userAborted)
-       {
-               startNextJob();
-               qDebug("Running jobs: %u", m_runningThreads);
+               QTimer::singleShot(0, this, SLOT(startNextJob()));
+               qDebug("%d files left, starting next job...", m_pendingJobs.count());
                return;
        }
        
        if(m_runningThreads > 0)
        {
-               qDebug("Running jobs: %u", m_runningThreads);
+               qDebug("No files left, but still have %u running jobs.", m_runningThreads);
                return;
        }
 
@@ -596,62 +687,55 @@ void ProcessingDialog::doneEncoding(void)
        if(!m_userAborted && m_settings->createPlaylist() && !m_settings->outputToSourceDir())
        {
                SET_PROGRESS_TEXT(tr("Creating the playlist file, please wait..."));
-               QApplication::processEvents();
+               qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
                writePlayList();
        }
        
        if(m_userAborted)
        {
-               CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#FFF3BA"));
-               WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
-               WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/error.png"));
+               CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#FFFFE0"));
+               m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_ERROR);
+               m_taskbar->setOverlayIcon(&QIcon(":/icons/error.png"));
                SET_PROGRESS_TEXT((m_succeededJobs.count() > 0) ? tr("Process was aborted by the user after %n file(s)!", "", m_succeededJobs.count()) : tr("Process was aborted prematurely by the user!"));
                m_systemTray->showMessage(tr("LameXP - Aborted"), tr("Process was aborted by the user."), QSystemTrayIcon::Warning);
                m_systemTray->setIcon(QIcon(":/icons/cd_delete.png"));
-               QApplication::processEvents();
-               if(m_settings->soundsEnabled() && !m_forcedAbort)
-               {
-                       PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABORTED), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
-               }
+               qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+               if(!m_forcedAbort) PLAY_SOUND_OPTIONAL("aborted", false);
        }
        else
        {
-               LARGE_INTEGER counter, frequency;
-               if(QueryPerformanceCounter(&counter) && QueryPerformanceFrequency(&frequency))
+               if((!m_totalTime.isNull()) && m_totalTime->isValid())
                {
-                       if((m_timerStart > 0I64) && (frequency.QuadPart > 0I64) && (m_timerStart < counter.QuadPart))
-                       {
-                               double timeElapsed = static_cast<double>(counter.QuadPart - m_timerStart) / static_cast<double>(frequency.QuadPart);
-                               m_progressModel->addSystemMessage(tr("Process finished after %1.").arg(time2text(timeElapsed)), ProgressModel::SysMsg_Performance);
-                       }
+                       m_progressModel->addSystemMessage(tr("Process finished after %1.").arg(time2text(m_totalTime->elapsed())), ProgressModel::SysMsg_Performance);
+                       m_totalTime->invalidate();
                }
 
                if(m_failedJobs.count() > 0)
                {
-                       CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#FFBABA"));
-                       WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
-                       WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/exclamation.png"));
+                       CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#FFF0F0"));
+                       m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_ERROR);
+                       m_taskbar->setOverlayIcon(&QIcon(":/icons/exclamation.png"));
                        if(m_skippedJobs.count() > 0)
                        {
-                               SET_PROGRESS_TEXT(tr("Error: %1 of %2 files failed (%3 files skipped). Double-click failed items for detailed information!").arg(QString::number(m_failedJobs.count()), QString::number(m_failedJobs.count() + m_succeededJobs.count() + m_skippedJobs.count()), QString::number(m_skippedJobs.count())));
+                               SET_PROGRESS_TEXT(tr("Error: %1 of %n file(s) failed (%2). Double-click failed items for detailed information!", "", m_failedJobs.count() + m_succeededJobs.count() + m_skippedJobs.count()).arg(QString::number(m_failedJobs.count()), tr("%n file(s) skipped", "", m_skippedJobs.count())));
                        }
                        else
                        {
-                               SET_PROGRESS_TEXT(tr("Error: %1 of %2 files failed. Double-click failed items for detailed information!").arg(QString::number(m_failedJobs.count()), QString::number(m_failedJobs.count() + m_succeededJobs.count())));
+                               SET_PROGRESS_TEXT(tr("Error: %1 of %n file(s) failed. Double-click failed items for detailed information!", "", m_failedJobs.count() + m_succeededJobs.count()).arg(QString::number(m_failedJobs.count())));
                        }
                        m_systemTray->showMessage(tr("LameXP - Error"), tr("At least one file has failed!"), QSystemTrayIcon::Critical);
                        m_systemTray->setIcon(QIcon(":/icons/cd_delete.png"));
-                       QApplication::processEvents();
-                       if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
+                       qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+                       PLAY_SOUND_OPTIONAL("error", false);
                }
                else
                {
-                       CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#E0FFE2"));
-                       WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
-                       WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/accept.png"));
+                       CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#F0FFF0"));
+                       m_taskbar->setTaskbarState(MUtils::Taskbar7::TASKBAR_STATE_NORMAL);
+                       m_taskbar->setOverlayIcon(&QIcon(":/icons/accept.png"));
                        if(m_skippedJobs.count() > 0)
                        {
-                               SET_PROGRESS_TEXT(tr("All files completed successfully. Skipped %1 files.").arg(QString::number(m_skippedJobs.count())));
+                               SET_PROGRESS_TEXT(tr("All files completed successfully. Skipped %n file(s).", "", m_skippedJobs.count()));
                        }
                        else
                        {
@@ -659,12 +743,12 @@ void ProcessingDialog::doneEncoding(void)
                        }
                        m_systemTray->showMessage(tr("LameXP - Done"), tr("All files completed successfully."), QSystemTrayIcon::Information);
                        m_systemTray->setIcon(QIcon(":/icons/cd_add.png"));
-                       QApplication::processEvents();
-                       if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_SUCCESS), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
+                       qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+                       PLAY_SOUND_OPTIONAL("success", false);
                }
        }
        
-       setCloseButtonEnabled(true);
+       MUtils::GUI::enable_close_button(this, true);
        ui->button_closeDialog->setEnabled(true);
        ui->button_AbortProcess->setEnabled(false);
        ui->checkBox_shutdownComputer->setEnabled(false);
@@ -673,7 +757,7 @@ void ProcessingDialog::doneEncoding(void)
        ui->view_log->scrollToBottom();
        m_progressIndicator->stop();
        ui->progressBar->setValue(ui->progressBar->maximum());
-       WinSevenTaskbar::setTaskbarProgress(this, ui->progressBar->value(), ui->progressBar->maximum());
+       m_taskbar->setTaskbarProgress(ui->progressBar->value(), ui->progressBar->maximum());
 
        QApplication::restoreOverrideCursor();
 
@@ -681,7 +765,7 @@ void ProcessingDialog::doneEncoding(void)
        {
                if(shutdownComputer())
                {
-                       m_shutdownFlag = m_settings->hibernateComputer() ? shutdownFlag_Hibernate : shutdownFlag_TurnPowerOff;
+                       m_shutdownFlag = m_settings->hibernateComputer() ? SHUTDOWN_FLAG_HIBERNATE : SHUTDOWN_FLAG_POWER_OFF;
                        accept();
                }
        }
@@ -733,7 +817,7 @@ void ProcessingDialog::logViewDoubleClicked(const QModelIndex &index)
                        LogViewDialog *logView = new LogViewDialog(this);
                        logView->setWindowTitle(QString("LameXP - [%1]").arg(m_progressModel->data(index, Qt::DisplayRole).toString()));
                        logView->exec(logFile);
-                       LAMEXP_DELETE(logView);
+                       MUTILS_DELETE(logView);
                }
                else
                {
@@ -742,7 +826,7 @@ void ProcessingDialog::logViewDoubleClicked(const QModelIndex &index)
        }
        else
        {
-               MessageBeep(MB_ICONWARNING);
+               MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
        }
 }
 
@@ -782,7 +866,7 @@ void ProcessingDialog::contextMenuShowFileActionTriggered(void)
 
        if(filePath.isEmpty())
        {
-               MessageBeep(MB_ICONWARNING);
+               MUtils::Sound::beep(MUtils::Sound::BEEP_WRN);
                return;
        }
 
@@ -790,7 +874,7 @@ void ProcessingDialog::contextMenuShowFileActionTriggered(void)
        {
                QString systemRootPath;
 
-               QDir systemRoot(lamexp_known_folder(lamexp_folder_systemfolder));
+               QDir systemRoot(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER));
                if(systemRoot.exists() && systemRoot.cdUp())
                {
                        systemRootPath = systemRoot.canonicalPath();
@@ -813,7 +897,7 @@ void ProcessingDialog::contextMenuShowFileActionTriggered(void)
        else
        {
                qWarning("File not found: %s", filePath.toLatin1().constData());
-               MessageBeep(MB_ICONERROR);
+               MUtils::Sound::beep(MUtils::Sound::BEEP_ERR);
        }
 }
 
@@ -869,213 +953,6 @@ void ProcessingDialog::progressViewFilterChanged(void)
 // Private Functions
 ////////////////////////////////////////////////////////////
 
-void ProcessingDialog::startNextJob(void)
-{
-       if(m_pendingJobs.isEmpty())
-       {
-               return;
-       }
-       
-       m_currentFile++;
-       AudioFileModel currentFile = updateMetaInfo(m_pendingJobs.takeFirst());
-       bool nativeResampling = false;
-
-       //Create encoder instance
-       AbstractEncoder *encoder = makeEncoder(&nativeResampling);
-
-       //Create processing thread
-       ProcessThread *thread = new ProcessThread
-       (
-               currentFile,
-               (m_settings->outputToSourceDir() ? QFileInfo(currentFile.filePath()).absolutePath() : m_settings->outputDir()),
-               (m_settings->customTempPathEnabled() ? m_settings->customTempPath() : lamexp_temp_folder2()),
-               encoder,
-               m_settings->prependRelativeSourcePath() && (!m_settings->outputToSourceDir())
-       );
-
-       //Add audio filters
-       if(m_settings->forceStereoDownmix())
-       {
-               thread->addFilter(new DownmixFilter());
-       }
-       if((m_settings->samplingRate() > 0) && !nativeResampling)
-       {
-               if(SettingsModel::samplingRates[m_settings->samplingRate()] != currentFile.formatAudioSamplerate() || currentFile.formatAudioSamplerate() == 0)
-               {
-                       thread->addFilter(new ResampleFilter(SettingsModel::samplingRates[m_settings->samplingRate()]));
-               }
-       }
-       if((m_settings->toneAdjustBass() != 0) || (m_settings->toneAdjustTreble() != 0))
-       {
-               thread->addFilter(new ToneAdjustFilter(m_settings->toneAdjustBass(), m_settings->toneAdjustTreble()));
-       }
-       if(m_settings->normalizationFilterEnabled())
-       {
-               thread->addFilter(new NormalizeFilter(m_settings->normalizationFilterMaxVolume(), m_settings->normalizationFilterEqualizationMode()));
-       }
-       if(m_settings->renameOutputFilesEnabled() && (!m_settings->renameOutputFilesPattern().simplified().isEmpty()))
-       {
-               thread->setRenamePattern(m_settings->renameOutputFilesPattern());
-       }
-       if(m_settings->overwriteMode() != SettingsModel::Overwrite_KeepBoth)
-       {
-               thread->setOverwriteMode((m_settings->overwriteMode() == SettingsModel::Overwrite_SkipFile), (m_settings->overwriteMode() == SettingsModel::Overwrite_Replaces));
-       }
-
-       m_threadList.append(thread);
-       m_allJobs.append(thread->getId());
-       
-       //Connect thread signals
-       connect(thread, SIGNAL(finished()), this, SLOT(doneEncoding()), Qt::QueuedConnection);
-       connect(thread, SIGNAL(processStateInitialized(QUuid,QString,QString,int)), m_progressModel, SLOT(addJob(QUuid,QString,QString,int)), Qt::QueuedConnection);
-       connect(thread, SIGNAL(processStateChanged(QUuid,QString,int)), m_progressModel, SLOT(updateJob(QUuid,QString,int)), Qt::QueuedConnection);
-       connect(thread, SIGNAL(processStateFinished(QUuid,QString,int)), this, SLOT(processFinished(QUuid,QString,int)), Qt::QueuedConnection);
-       connect(thread, SIGNAL(processMessageLogged(QUuid,QString)), m_progressModel, SLOT(appendToLog(QUuid,QString)), Qt::QueuedConnection);
-       
-       //Give it a go!
-       m_runningThreads++;
-       thread->start();
-
-       //Give thread some advance
-       for(unsigned int i = 0; i < MAX_INSTANCES; i++)
-       {
-               QThread::yieldCurrentThread();
-       }
-}
-
-AbstractEncoder *ProcessingDialog::makeEncoder(bool *nativeResampling)
-{
-       AbstractEncoder *encoder =  NULL;
-       *nativeResampling = false;
-       
-       switch(m_settings->compressionEncoder())
-       {
-       case SettingsModel::MP3Encoder:
-               {
-                       MP3Encoder *mp3Encoder = new MP3Encoder();
-                       mp3Encoder->setBitrate(m_settings->compressionBitrate());
-                       mp3Encoder->setRCMode(m_settings->compressionRCMode());
-                       mp3Encoder->setAlgoQuality(m_settings->lameAlgoQuality());
-                       if(m_settings->bitrateManagementEnabled())
-                       {
-                               mp3Encoder->setBitrateLimits(m_settings->bitrateManagementMinRate(), m_settings->bitrateManagementMaxRate());
-                       }
-                       if(m_settings->samplingRate() > 0)
-                       {
-                               mp3Encoder->setSamplingRate(SettingsModel::samplingRates[m_settings->samplingRate()]);
-                               *nativeResampling = true;
-                       }
-                       mp3Encoder->setChannelMode(m_settings->lameChannelMode());
-                       mp3Encoder->setCustomParams(m_settings->customParametersLAME());
-                       encoder = mp3Encoder;
-               }
-               break;
-       case SettingsModel::VorbisEncoder:
-               {
-                       VorbisEncoder *vorbisEncoder = new VorbisEncoder();
-                       vorbisEncoder->setBitrate(m_settings->compressionBitrate());
-                       vorbisEncoder->setRCMode(m_settings->compressionRCMode());
-                       if(m_settings->bitrateManagementEnabled())
-                       {
-                               vorbisEncoder->setBitrateLimits(m_settings->bitrateManagementMinRate(), m_settings->bitrateManagementMaxRate());
-                       }
-                       if(m_settings->samplingRate() > 0)
-                       {
-                               vorbisEncoder->setSamplingRate(SettingsModel::samplingRates[m_settings->samplingRate()]);
-                               *nativeResampling = true;
-                       }
-                       vorbisEncoder->setCustomParams(m_settings->customParametersOggEnc());
-                       encoder = vorbisEncoder;
-               }
-               break;
-       case SettingsModel::AACEncoder:
-               {
-                       if(lamexp_check_tool("qaac.exe") && lamexp_check_tool("libsoxrate.dll"))
-                       {
-                               QAACEncoder *aacEncoder = new QAACEncoder();
-                               aacEncoder->setBitrate(m_settings->compressionBitrate());
-                               aacEncoder->setRCMode(m_settings->compressionRCMode());
-                               aacEncoder->setProfile(m_settings->aacEncProfile());
-                               aacEncoder->setCustomParams(m_settings->customParametersAacEnc());
-                               encoder = aacEncoder;
-                       }
-                       else if(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll"))
-                       {
-                               FHGAACEncoder *aacEncoder = new FHGAACEncoder();
-                               aacEncoder->setBitrate(m_settings->compressionBitrate());
-                               aacEncoder->setRCMode(m_settings->compressionRCMode());
-                               aacEncoder->setProfile(m_settings->aacEncProfile());
-                               aacEncoder->setCustomParams(m_settings->customParametersAacEnc());
-                               encoder = aacEncoder;
-                       }
-                       else
-                       {
-                               AACEncoder *aacEncoder = new AACEncoder();
-                               aacEncoder->setBitrate(m_settings->compressionBitrate());
-                               aacEncoder->setRCMode(m_settings->compressionRCMode());
-                               aacEncoder->setEnable2Pass(m_settings->neroAACEnable2Pass());
-                               aacEncoder->setProfile(m_settings->aacEncProfile());
-                               aacEncoder->setCustomParams(m_settings->customParametersAacEnc());
-                               encoder = aacEncoder;
-                       }
-               }
-               break;
-       case SettingsModel::AC3Encoder:
-               {
-                       AC3Encoder *ac3Encoder = new AC3Encoder();
-                       ac3Encoder->setBitrate(m_settings->compressionBitrate());
-                       ac3Encoder->setRCMode(m_settings->compressionRCMode());
-                       ac3Encoder->setCustomParams(m_settings->customParametersAften());
-                       ac3Encoder->setAudioCodingMode(m_settings->aftenAudioCodingMode());
-                       ac3Encoder->setDynamicRangeCompression(m_settings->aftenDynamicRangeCompression());
-                       ac3Encoder->setExponentSearchSize(m_settings->aftenExponentSearchSize());
-                       ac3Encoder->setFastBitAllocation(m_settings->aftenFastBitAllocation());
-                       encoder = ac3Encoder;
-               }
-               break;
-       case SettingsModel::FLACEncoder:
-               {
-                       FLACEncoder *flacEncoder = new FLACEncoder();
-                       flacEncoder->setBitrate(m_settings->compressionBitrate());
-                       flacEncoder->setRCMode(m_settings->compressionRCMode());
-                       flacEncoder->setCustomParams(m_settings->customParametersFLAC());
-                       encoder = flacEncoder;
-               }
-               break;
-       case SettingsModel::OpusEncoder:
-               {
-                       OpusEncoder *opusEncoder = new OpusEncoder();
-                       opusEncoder->setBitrate(m_settings->compressionBitrate());
-                       opusEncoder->setRCMode(m_settings->compressionRCMode());
-                       opusEncoder->setOptimizeFor(m_settings->opusOptimizeFor());
-                       opusEncoder->setEncodeComplexity(m_settings->opusComplexity());
-                       opusEncoder->setFrameSize(m_settings->opusFramesize());
-                       opusEncoder->setCustomParams(m_settings->customParametersOpus());
-                       encoder = opusEncoder;
-               }
-               break;  case SettingsModel::DCAEncoder:
-               {
-                       DCAEncoder *dcaEncoder = new DCAEncoder();
-                       dcaEncoder->setBitrate(m_settings->compressionBitrate());
-                       dcaEncoder->setRCMode(m_settings->compressionRCMode());
-                       encoder = dcaEncoder;
-               }
-               break;
-       case SettingsModel::PCMEncoder:
-               {
-                       WaveEncoder *waveEncoder = new WaveEncoder();
-                       waveEncoder->setBitrate(m_settings->compressionBitrate());
-                       waveEncoder->setRCMode(m_settings->compressionRCMode());
-                       encoder = waveEncoder;
-               }
-               break;
-       default:
-               throw "Unsupported encoder!";
-       }
-
-       return encoder;
-}
-
 void ProcessingDialog::writePlayList(void)
 {
        if(m_succeededJobs.count() <= 0 || m_allJobs.count() <= 0)
@@ -1094,14 +971,14 @@ void ProcessingDialog::writePlayList(void)
        int counter = 1;
 
        //Generate playlist name
-       QString playListName = (m_metaInfo->fileAlbum().isEmpty() ? "Playlist" : m_metaInfo->fileAlbum());
-       if(!m_metaInfo->fileArtist().isEmpty())
+       QString playListName = (m_metaInfo->album().isEmpty() ? "Playlist" : m_metaInfo->album());
+       if(!m_metaInfo->artist().isEmpty())
        {
-               playListName = QString("%1 - %2").arg(m_metaInfo->fileArtist(), playListName);
+               playListName = QString("%1 - %2").arg(m_metaInfo->artist(), playListName);
        }
 
        //Clean playlist name
-       playListName = lamexp_clean_filename(playListName);
+       playListName = MUtils::clean_file_name(playListName);
 
        //Create list of audio files
        for(int i = 0; i < m_allJobs.count(); i++)
@@ -1125,7 +1002,7 @@ void ProcessingDialog::writePlayList(void)
        //Do we need an UTF-8 playlist?
        for(int i = 0; i < list.count(); i++)
        {
-               if(wcscmp(QWCHAR(QString::fromLatin1(list.at(i).toLatin1().constData())), QWCHAR(list.at(i))))
+               if(wcscmp(MUTILS_WCHR(QString::fromLatin1(list.at(i).toLatin1().constData())), MUTILS_WCHR(list.at(i))))
                {
                        useUtf8 = true;
                        break;
@@ -1150,7 +1027,7 @@ void ProcessingDialog::writePlayList(void)
                playList.write("#EXTM3U\r\n");
                while(!list.isEmpty())
                {
-                       playList.write(useUtf8 ? list.takeFirst().toUtf8().constData() : list.takeFirst().toLatin1().constData());
+                       playList.write(useUtf8 ? MUTILS_UTF8(list.takeFirst()) : list.takeFirst().toLatin1().constData());
                        playList.write("\r\n");
                }
                playList.close();
@@ -1161,35 +1038,29 @@ void ProcessingDialog::writePlayList(void)
        }
 }
 
-AudioFileModel ProcessingDialog::updateMetaInfo(const AudioFileModel &audioFile)
+AudioFileModel ProcessingDialog::updateMetaInfo(AudioFileModel &audioFile)
 {
        if(!m_settings->writeMetaTags())
        {
-               return AudioFileModel(audioFile, false);
+               audioFile.metaInfo().reset();
+               return audioFile;
        }
        
-       AudioFileModel result = audioFile;
-       result.updateMetaInfo(*m_metaInfo);
+       audioFile.metaInfo().update(*m_metaInfo, true);
        
-       if(m_metaInfo->filePosition() == UINT_MAX)
+       if(audioFile.metaInfo().position() == UINT_MAX)
        {
-               result.setFilePosition(m_currentFile);
+               audioFile.metaInfo().setPosition(m_currentFile);
        }
 
-       return result;
-}
-
-void ProcessingDialog::setCloseButtonEnabled(bool enabled)
-{
-       HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);
-       EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED));
+       return audioFile;
 }
 
 void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason reason)
 {
        if(reason == QSystemTrayIcon::DoubleClick)
        {
-               SetForegroundWindow(reinterpret_cast<HWND>(this->winId()));
+               MUtils::GUI::bring_to_front(this);
        }
 }
 
@@ -1241,14 +1112,11 @@ bool ProcessingDialog::shutdownComputer(void)
        progressDialog.setCancelButton(cancelButton);
        progressDialog.show();
        
-       QApplication::processEvents();
+       qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
 
-       if(m_settings->soundsEnabled())
-       {
-               QApplication::setOverrideCursor(Qt::WaitCursor);
-               PlaySound(MAKEINTRESOURCE(IDR_WAVE_SHUTDOWN), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
-               QApplication::restoreOverrideCursor();
-       }
+       QApplication::setOverrideCursor(Qt::WaitCursor);
+       PLAY_SOUND_OPTIONAL("shutdown", false);
+       QApplication::restoreOverrideCursor();
 
        QTimer timer;
        timer.setInterval(1000);
@@ -1269,26 +1137,24 @@ bool ProcessingDialog::shutdownComputer(void)
                progressDialog.setValue(i+1);
                progressDialog.setLabelText(text.arg(iTimeout-i));
                if(iTimeout-i == 3) progressDialog.setCancelButton(NULL);
-               QApplication::processEvents();
-               PlaySound(MAKEINTRESOURCE((i < iTimeout) ? IDR_WAVE_BEEP : IDR_WAVE_BEEP_LONG), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
+               qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+               PLAY_SOUND_OPTIONAL(((i < iTimeout) ? "beep" : "beep2"), false);
        }
        
        progressDialog.close();
        return true;
 }
 
-QString ProcessingDialog::time2text(const double timeVal) const
+QString ProcessingDialog::time2text(const qint64 &msec) const
 {
-       double intPart = 0;
-       double frcPart = modf(timeVal, &intPart);
-
-       QTime time = QTime().addSecs(qRound(intPart)).addMSecs(qRound(frcPart * 1000.0));
+       const qint64 MILLISECONDS_PER_DAY = 86399999;   //24x60x60x1000 - 1
+       const QTime time = QTime().addMSecs(qMin(msec, MILLISECONDS_PER_DAY));
 
        QString a, b;
 
        if(time.hour() > 0)
        {
-               a = tr("%n hour(s)", "", time.hour());
+               a = tr("%n hour(s)",   "", time.hour());
                b = tr("%n minute(s)", "", time.minute());
        }
        else if(time.minute() > 0)
@@ -1298,7 +1164,7 @@ QString ProcessingDialog::time2text(const double timeVal) const
        }
        else
        {
-               a = tr("%n second(s)", "", time.second());
+               a = tr("%n second(s)",      "", time.second());
                b = tr("%n millisecond(s)", "", time.msec());
        }