OSDN Git Service

Merge branch 'master' of github.com:lordmulder/LameXP
[lamexp/LameXP.git] / src / Dialog_Processing.cpp
index 39850e5..eaf03bb 100644 (file)
@@ -21,6 +21,9 @@
 
 #include "Dialog_Processing.h"
 
+//UIC includes
+#include "../tmp/UIC_ProcessingDialog.h"
+
 #include "Global.h"
 #include "Resource.h"
 #include "Model_FileList.h"
@@ -41,6 +44,7 @@
 #include "Encoder_Vorbis.h"
 #include "Encoder_Opus.h"
 #include "Encoder_Wave.h"
+#include "Registry_Decoder.h"
 #include "Filter_Downmix.h"
 #include "Filter_Normalize.h"
 #include "Filter_Resample.h"
@@ -63,6 +67,7 @@
 #include <QSystemTrayIcon>
 #include <QProcess>
 #include <QProgressDialog>
+#include <QResizeEvent>
 #include <QTime>
 
 #include <MMSystem.h>
@@ -79,21 +84,55 @@ static int cores2instances(int cores);
 
 ////////////////////////////////////////////////////////////
 
-#define CHANGE_BACKGROUND_COLOR(WIDGET, COLOR) \
+#define CHANGE_BACKGROUND_COLOR(WIDGET, COLOR) do \
 { \
        QPalette palette = WIDGET->palette(); \
        palette.setColor(QPalette::Background, COLOR); \
        WIDGET->setPalette(palette); \
-}
+} \
+while(0)
 
-#define SET_PROGRESS_TEXT(TXT) \
+#define SET_PROGRESS_TEXT(TXT) do \
 { \
-       label_progress->setText(TXT); \
+       ui->label_progress->setText(TXT); \
        m_systemTray->setToolTip(QString().sprintf("LameXP v%d.%02d\n%ls", lamexp_version_major(), lamexp_version_minor(), QString(TXT).utf16())); \
-}
+} \
+while(0)
+
+#define SET_FONT_BOLD(WIDGET,BOLD) do \
+{ \
+       QFont _font = WIDGET->font(); \
+       _font.setBold(BOLD); WIDGET->setFont(_font); \
+} \
+while(0)
+
+#define SET_TEXT_COLOR(WIDGET, COLOR) do \
+{ \
+       QPalette _palette = WIDGET->palette(); \
+       _palette.setColor(QPalette::WindowText, (COLOR)); \
+       _palette.setColor(QPalette::Text, (COLOR)); \
+       WIDGET->setPalette(_palette); \
+} \
+while(0)
+
+#define UPDATE_MIN_WIDTH(WIDGET) do \
+{ \
+       if(WIDGET->width() > WIDGET->minimumWidth()) WIDGET->setMinimumWidth(WIDGET->width()); \
+} \
+while(0)
+
+////////////////////////////////////////////////////////////
 
-#define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
-#define UPDATE_MIN_WIDTH(WIDGET) { if(WIDGET->width() > WIDGET->minimumWidth()) WIDGET->setMinimumWidth(WIDGET->width()); }
+//Dummy class for UserData
+class IntUserData : public QObjectUserData
+{
+public:
+       IntUserData(int value) : m_value(value) {/*NOP*/}
+       int value(void) { return m_value; }
+       void setValue(int value) { m_value = value; }
+private:
+       int m_value;
+};
 
 ////////////////////////////////////////////////////////////
 // Constructor
@@ -102,6 +141,7 @@ static int cores2instances(int cores);
 ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settings, QWidget *parent)
 :
        QDialog(parent),
+       ui(new Ui::ProcessingDialog),
        m_systemTray(new QSystemTrayIcon(QIcon(":/icons/cd_go.png"), this)),
        m_settings(settings),
        m_metaInfo(metaInfo),
@@ -109,18 +149,19 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        m_diskObserver(NULL),
        m_cpuObserver(NULL),
        m_ramObserver(NULL),
+       m_progressViewFilter(-1),
        m_firstShow(true)
 {
        //Init the dialog, from the .ui file
-       setupUi(this);
+       ui->setupUi(this);
        setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
        
        //Update header icon
-       label_headerIcon->setPixmap(lamexp_app_icon().pixmap(label_headerIcon->size()));
+       ui->label_headerIcon->setPixmap(lamexp_app_icon().pixmap(ui->label_headerIcon->size()));
        
        //Setup version info
-       label_versionInfo->setText(QString().sprintf("v%d.%02d %s (Build %d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build()));
-       label_versionInfo->installEventFilter(this);
+       ui->label_versionInfo->setText(QString().sprintf("v%d.%02d %s (Build %d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build()));
+       ui->label_versionInfo->installEventFilter(this);
 
        //Register meta type
        qRegisterMetaType<QUuid>("QUuid");
@@ -132,37 +173,85 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        setMinimumSize(thisRect.width(), thisRect.height());
 
        //Enable buttons
-       connect(button_AbortProcess, SIGNAL(clicked()), this, SLOT(abortEncoding()));
+       connect(ui->button_AbortProcess, SIGNAL(clicked()), this, SLOT(abortEncoding()));
        
        //Init progress indicator
        m_progressIndicator = new QMovie(":/images/Working.gif");
        m_progressIndicator->setCacheMode(QMovie::CacheAll);
        m_progressIndicator->setSpeed(50);
-       label_headerWorking->setMovie(m_progressIndicator);
-       progressBar->setValue(0);
+       ui->label_headerWorking->setMovie(m_progressIndicator);
+       ui->progressBar->setValue(0);
 
        //Init progress model
        m_progressModel = new ProgressModel();
-       view_log->setModel(m_progressModel);
-       view_log->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
-       view_log->verticalHeader()->hide();
-       view_log->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
-       view_log->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
-       view_log->viewport()->installEventFilter(this);
+       ui->view_log->setModel(m_progressModel);
+       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(view_log, SIGNAL(activated(QModelIndex)), this, SLOT(logViewDoubleClicked(QModelIndex)));
-       connect(view_log->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(logViewSectionSizeChanged(int,int,int)));
+       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"));
        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);
+       QAction *contextMenuFilterAction[5] = {NULL, NULL, NULL, NULL, NULL};
+       if(QMenu *filterMenu = m_contextMenu->addMenu(QIcon(":/icons/filter.png"), tr("Filter Log Items")))
+       {
+               contextMenuFilterAction[0] = filterMenu->addAction(m_progressModel->getIcon(ProgressModel::JobRunning), tr("Show Running Only"));
+               contextMenuFilterAction[1] = filterMenu->addAction(m_progressModel->getIcon(ProgressModel::JobComplete), tr("Show Succeeded Only"));
+               contextMenuFilterAction[2] = filterMenu->addAction(m_progressModel->getIcon(ProgressModel::JobFailed), tr("Show Failed Only"));
+               contextMenuFilterAction[3] = filterMenu->addAction(m_progressModel->getIcon(ProgressModel::JobSkipped), tr("Show Skipped Only"));
+               contextMenuFilterAction[4] = filterMenu->addAction(m_progressModel->getIcon(ProgressModel::JobState(-1)), tr("Show All Items"));
+               if(QAction *act = contextMenuFilterAction[0]) { m_progressViewFilterGroup->addAction(act); act->setCheckable(true); act->setData(ProgressModel::JobRunning); }
+               if(QAction *act = contextMenuFilterAction[1]) { m_progressViewFilterGroup->addAction(act); act->setCheckable(true); act->setData(ProgressModel::JobComplete); }
+               if(QAction *act = contextMenuFilterAction[2]) { m_progressViewFilterGroup->addAction(act); act->setCheckable(true); act->setData(ProgressModel::JobFailed); }
+               if(QAction *act = contextMenuFilterAction[3]) { m_progressViewFilterGroup->addAction(act); act->setCheckable(true); act->setData(ProgressModel::JobSkipped); }
+               if(QAction *act = contextMenuFilterAction[4]) { m_progressViewFilterGroup->addAction(act); act->setCheckable(true); act->setData(-1); act->setChecked(true); }
+       }
+
+       //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();
+       }
 
-       view_log->setContextMenuPolicy(Qt::CustomContextMenu);
-       connect(view_log, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTriggered(QPoint)));
+       //Connect context menu
+       ui->view_log->setContextMenuPolicy(Qt::CustomContextMenu);
+       connect(ui->view_log, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTriggered(QPoint)));
        connect(contextMenuDetailsAction, SIGNAL(triggered(bool)), this, SLOT(contextMenuDetailsActionTriggered()));
        connect(contextMenuShowFileAction, SIGNAL(triggered(bool)), this, SLOT(contextMenuShowFileActionTriggered()));
+       for(size_t i = 0; i < 5; i++)
+       {
+               if(contextMenuFilterAction[i]) connect(contextMenuFilterAction[i], SIGNAL(triggered(bool)), this, SLOT(contextMenuFilterActionTriggered()));
+       }
        SET_FONT_BOLD(contextMenuDetailsAction, true);
 
        //Enque jobs
@@ -175,7 +264,7 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        }
 
        //Translate
-       label_headerStatus->setText(QString("<b>%1</b><br>%2").arg(tr("Encoding Files"), tr("Your files are being encoded, please be patient...")));
+       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)));
@@ -186,6 +275,7 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
        m_allJobs.clear();
        m_succeededJobs.clear();
        m_failedJobs.clear();
+       m_skippedJobs.clear();
        m_userAborted = false;
        m_forcedAbort = false;
        m_timerStart = 0I64;
@@ -197,7 +287,7 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
 
 ProcessingDialog::~ProcessingDialog(void)
 {
-       view_log->setModel(NULL);
+       ui->view_log->setModel(NULL);
 
        if(m_progressIndicator)
        {
@@ -232,24 +322,29 @@ ProcessingDialog::~ProcessingDialog(void)
                }
        }
 
+       while(!m_threadList.isEmpty())
+       {
+               ProcessThread *thread = m_threadList.takeFirst();
+               thread->terminate();
+               thread->wait(15000);
+               delete thread;
+       }
+
        LAMEXP_DELETE(m_progressIndicator);
-       LAMEXP_DELETE(m_progressModel);
-       LAMEXP_DELETE(m_contextMenu);
        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);
 
-       while(!m_threadList.isEmpty())
-       {
-               ProcessThread *thread = m_threadList.takeFirst();
-               thread->terminate();
-               thread->wait(15000);
-               delete thread;
-       }
+       LAMEXP_DELETE(ui);
 }
 
 ////////////////////////////////////////////////////////////
@@ -265,8 +360,8 @@ void ProcessingDialog::showEvent(QShowEvent *event)
                static const char *NA = " N/A";
        
                setCloseButtonEnabled(false);
-               button_closeDialog->setEnabled(false);
-               button_AbortProcess->setEnabled(false);
+               ui->button_closeDialog->setEnabled(false);
+               ui->button_AbortProcess->setEnabled(false);
                m_systemTray->setVisible(true);
        
                if(!SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS))
@@ -274,18 +369,21 @@ void ProcessingDialog::showEvent(QShowEvent *event)
                        SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
                }
 
-               label_cpu->setText(NA);
-               label_disk->setText(NA);
-               label_ram->setText(NA);
+               ui->label_cpu->setText(NA);
+               ui->label_disk->setText(NA);
+               ui->label_ram->setText(NA);
 
                QTimer::singleShot(1000, this, SLOT(initEncoding()));
                m_firstShow = false;
        }
+
+       //Force update geometry
+       resizeEvent(NULL);
 }
 
 void ProcessingDialog::closeEvent(QCloseEvent *event)
 {
-       if(!button_closeDialog->isEnabled())
+       if(!ui->button_closeDialog->isEnabled())
        {
                event->ignore();
        }
@@ -299,20 +397,20 @@ bool ProcessingDialog::eventFilter(QObject *obj, QEvent *event)
 {
        static QColor defaultColor = QColor();
 
-       if(obj == label_versionInfo)
+       if(obj == ui->label_versionInfo)
        {
                if(event->type() == QEvent::Enter)
                {
-                       QPalette palette = label_versionInfo->palette();
+                       QPalette palette = ui->label_versionInfo->palette();
                        defaultColor = palette.color(QPalette::Normal, QPalette::WindowText);
                        palette.setColor(QPalette::Normal, QPalette::WindowText, Qt::red);
-                       label_versionInfo->setPalette(palette);
+                       ui->label_versionInfo->setPalette(palette);
                }
                else if(event->type() == QEvent::Leave)
                {
-                       QPalette palette = label_versionInfo->palette();
+                       QPalette palette = ui->label_versionInfo->palette();
                        palette.setColor(QPalette::Normal, QPalette::WindowText, defaultColor);
-                       label_versionInfo->setPalette(palette);
+                       ui->label_versionInfo->setPalette(palette);
                }
                else if(event->type() == QEvent::MouseButtonPress)
                {
@@ -349,6 +447,21 @@ bool ProcessingDialog::event(QEvent *e)
        }
 }
 
+/*
+ * Window was resized
+ */
+void ProcessingDialog::resizeEvent(QResizeEvent *event)
+{
+       if(event) QDialog::resizeEvent(event);
+
+       if(QWidget *port = ui->view_log->viewport())
+       {
+               QRect geom = port->geometry();
+               m_filterInfoLabel->setGeometry(geom.left() + 16, geom.top() + 16, geom.width() - 32, 48);
+               m_filterInfoLabelIcon->setGeometry(geom.left() + 16, geom.top() + 64, geom.width() - 32, geom.height() - 80);
+       }
+}
+
 bool ProcessingDialog::winEvent(MSG *message, long *result)
 {
        return WinSevenTaskbar::handleWinEvent(message, result);
@@ -367,19 +480,22 @@ void ProcessingDialog::initEncoding(void)
        m_allJobs.clear();
        m_succeededJobs.clear();
        m_failedJobs.clear();
+       m_skippedJobs.clear();
        m_userAborted = false;
        m_forcedAbort = false;
        m_playList.clear();
-       
-       CHANGE_BACKGROUND_COLOR(frame_header, QColor(Qt::white));
+
+       DecoderRegistry::configureDecoders(m_settings);
+
+       CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor(Qt::white));
        SET_PROGRESS_TEXT(tr("Encoding files, please wait..."));
        m_progressIndicator->start();
        
-       button_closeDialog->setEnabled(false);
-       button_AbortProcess->setEnabled(true);
-       progressBar->setRange(0, m_pendingJobs.count());
-       checkBox_shutdownComputer->setEnabled(true);
-       checkBox_shutdownComputer->setChecked(false);
+       ui->button_closeDialog->setEnabled(false);
+       ui->button_AbortProcess->setEnabled(true);
+       ui->progressBar->setRange(0, m_pendingJobs.count());
+       ui->checkBox_shutdownComputer->setEnabled(true);
+       ui->checkBox_shutdownComputer->setChecked(false);
 
        WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
        WinSevenTaskbar::setTaskbarProgress(this, 0, m_pendingJobs.count());
@@ -421,6 +537,7 @@ void ProcessingDialog::initEncoding(void)
        for(unsigned int i = 0; i < maximumInstances; i++)
        {
                startNextJob();
+               qApp->processEvents();
        }
 
        LARGE_INTEGER counter;
@@ -434,7 +551,7 @@ void ProcessingDialog::abortEncoding(bool force)
 {
        m_userAborted = true;
        if(force) m_forcedAbort = true;
-       button_AbortProcess->setEnabled(false);
+       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++)
@@ -446,12 +563,12 @@ void ProcessingDialog::abortEncoding(bool force)
 void ProcessingDialog::doneEncoding(void)
 {
        m_runningThreads--;
-       progressBar->setValue(progressBar->value() + 1);
+       ui->progressBar->setValue(ui->progressBar->value() + 1);
        
        if(!m_userAborted)
        {
-               SET_PROGRESS_TEXT(tr("Encoding: %1 files of %2 completed so far, please wait...").arg(QString::number(progressBar->value()), QString::number(progressBar->maximum())));
-               WinSevenTaskbar::setTaskbarProgress(this, progressBar->value(), progressBar->maximum());
+               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());
        }
        
        int index = m_threadList.indexOf(dynamic_cast<ProcessThread*>(QWidget::sender()));
@@ -485,10 +602,10 @@ void ProcessingDialog::doneEncoding(void)
        
        if(m_userAborted)
        {
-               CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFF3BA"));
+               CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#FFF3BA"));
                WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
                WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/error.png"));
-               SET_PROGRESS_TEXT((m_succeededJobs.count() > 0) ? tr("Process was aborted by the user after %1 file(s)!").arg(QString::number(m_succeededJobs.count())) : tr("Process was aborted prematurely by the user!"));
+               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();
@@ -511,10 +628,17 @@ void ProcessingDialog::doneEncoding(void)
 
                if(m_failedJobs.count() > 0)
                {
-                       CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFBABA"));
+                       CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#FFBABA"));
                        WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
                        WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/exclamation.png"));
-                       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())));
+                       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())));
+                       }
+                       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())));
+                       }
                        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();
@@ -522,10 +646,17 @@ void ProcessingDialog::doneEncoding(void)
                }
                else
                {
-                       CHANGE_BACKGROUND_COLOR(frame_header, QColor("#E0FFE2"));
+                       CHANGE_BACKGROUND_COLOR(ui->frame_header, QColor("#E0FFE2"));
                        WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
                        WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/accept.png"));
-                       SET_PROGRESS_TEXT(tr("All files completed successfully."));
+                       if(m_skippedJobs.count() > 0)
+                       {
+                               SET_PROGRESS_TEXT(tr("All files completed successfully. Skipped %1 files.").arg(QString::number(m_skippedJobs.count())));
+                       }
+                       else
+                       {
+                               SET_PROGRESS_TEXT(tr("All files completed successfully."));
+                       }
                        m_systemTray->showMessage(tr("LameXP - Done"), tr("All files completed successfully."), QSystemTrayIcon::Information);
                        m_systemTray->setIcon(QIcon(":/icons/cd_add.png"));
                        QApplication::processEvents();
@@ -534,19 +665,19 @@ void ProcessingDialog::doneEncoding(void)
        }
        
        setCloseButtonEnabled(true);
-       button_closeDialog->setEnabled(true);
-       button_AbortProcess->setEnabled(false);
-       checkBox_shutdownComputer->setEnabled(false);
+       ui->button_closeDialog->setEnabled(true);
+       ui->button_AbortProcess->setEnabled(false);
+       ui->checkBox_shutdownComputer->setEnabled(false);
 
        m_progressModel->restoreHiddenItems();
-       view_log->scrollToBottom();
+       ui->view_log->scrollToBottom();
        m_progressIndicator->stop();
-       progressBar->setValue(progressBar->maximum());
-       WinSevenTaskbar::setTaskbarProgress(this, progressBar->value(), progressBar->maximum());
+       ui->progressBar->setValue(ui->progressBar->maximum());
+       WinSevenTaskbar::setTaskbarProgress(this, ui->progressBar->value(), ui->progressBar->maximum());
 
        QApplication::restoreOverrideCursor();
 
-       if(!m_userAborted && checkBox_shutdownComputer->isChecked())
+       if(!m_userAborted && ui->checkBox_shutdownComputer->isChecked())
        {
                if(shutdownComputer())
                {
@@ -556,22 +687,39 @@ void ProcessingDialog::doneEncoding(void)
        }
 }
 
-void ProcessingDialog::processFinished(const QUuid &jobId, const QString &outFileName, bool success)
+void ProcessingDialog::processFinished(const QUuid &jobId, const QString &outFileName, int success)
 {
-       if(success)
+       if(success > 0)
        {
                m_playList.insert(jobId, outFileName);
                m_succeededJobs.append(jobId);
        }
+       else if(success < 0)
+       {
+               m_playList.insert(jobId, outFileName);
+               m_skippedJobs.append(jobId);
+       }
        else
        {
                m_failedJobs.append(jobId);
        }
+
+       //Update filter as soon as a job finished!
+       if(m_progressViewFilter >= 0)
+       {
+               QTimer::singleShot(0, this, SLOT(progressViewFilterChanged()));
+       }
 }
 
 void ProcessingDialog::progressModelChanged(void)
 {
-       view_log->scrollToBottom();
+       //Update filter as soon as the model changes!
+       if(m_progressViewFilter >= 0)
+       {
+               QTimer::singleShot(0, this, SLOT(progressViewFilterChanged()));
+       }
+
+       QTimer::singleShot(0, ui->view_log, SLOT(scrollToBottom()));
 }
 
 void ProcessingDialog::logViewDoubleClicked(const QModelIndex &index)
@@ -602,7 +750,7 @@ void ProcessingDialog::logViewSectionSizeChanged(int logicalIndex, int oldSize,
 {
        if(logicalIndex == 1)
        {
-               if(QHeaderView *hdr = view_log->horizontalHeader())
+               if(QHeaderView *hdr = ui->view_log->horizontalHeader())
                {
                        hdr->setMinimumSectionSize(qMax(hdr->minimumSectionSize(), hdr->sectionSize(1)));
                }
@@ -622,14 +770,14 @@ void ProcessingDialog::contextMenuTriggered(const QPoint &pos)
 
 void ProcessingDialog::contextMenuDetailsActionTriggered(void)
 {
-       QModelIndex index = view_log->indexAt(view_log->viewport()->mapFromGlobal(m_contextMenu->pos()));
-       logViewDoubleClicked(index.isValid() ? index : view_log->currentIndex());
+       QModelIndex index = ui->view_log->indexAt(ui->view_log->viewport()->mapFromGlobal(m_contextMenu->pos()));
+       logViewDoubleClicked(index.isValid() ? index : ui->view_log->currentIndex());
 }
 
 void ProcessingDialog::contextMenuShowFileActionTriggered(void)
 {
-       QModelIndex index = view_log->indexAt(view_log->viewport()->mapFromGlobal(m_contextMenu->pos()));
-       const QUuid &jobId = m_progressModel->getJobId(index.isValid() ? index : view_log->currentIndex());
+       QModelIndex index = ui->view_log->indexAt(ui->view_log->viewport()->mapFromGlobal(m_contextMenu->pos()));
+       const QUuid &jobId = m_progressModel->getJobId(index.isValid() ? index : ui->view_log->currentIndex());
        QString filePath = m_playList.value(jobId, QString());
 
        if(filePath.isEmpty())
@@ -669,6 +817,54 @@ void ProcessingDialog::contextMenuShowFileActionTriggered(void)
        }
 }
 
+void ProcessingDialog::contextMenuFilterActionTriggered(void)
+{
+       if(QAction *action = dynamic_cast<QAction*>(QObject::sender()))
+       {
+               if(action->data().type() == QVariant::Int)
+               {
+                       m_progressViewFilter = action->data().toInt();
+                       progressViewFilterChanged();
+                       QTimer::singleShot(0, this, SLOT(progressViewFilterChanged()));
+                       QTimer::singleShot(0, ui->view_log, SLOT(scrollToBottom()));
+                       action->setChecked(true);
+               }
+       }
+}
+
+/*
+ * Filter progress items
+ */
+void ProcessingDialog::progressViewFilterChanged(void)
+{
+       bool matchFound = false;
+
+       for(int i = 0; i < ui->view_log->model()->rowCount(); i++)
+       {
+               QModelIndex index = (m_progressViewFilter >= 0) ? m_progressModel->index(i, 0) : QModelIndex();
+               const bool bHide = index.isValid() ? (m_progressModel->getJobState(index) != m_progressViewFilter) : false;
+               ui->view_log->setRowHidden(i, bHide); matchFound = matchFound || (!bHide);
+       }
+
+       if((m_progressViewFilter >= 0) && (!matchFound))
+       {
+               if(m_filterInfoLabel->isHidden() || (dynamic_cast<IntUserData*>(m_filterInfoLabel->userData(0))->value() != m_progressViewFilter))
+               {
+                       dynamic_cast<IntUserData*>(m_filterInfoLabel->userData(0))->setValue(m_progressViewFilter);
+                       m_filterInfoLabel->setText(QString("<p>&raquo; %1 &laquo;</p>").arg(tr("None of the items matches the current filtering rules")));
+                       m_filterInfoLabel->show();
+                       m_filterInfoLabelIcon->setPixmap(m_progressModel->getIcon(static_cast<ProgressModel::JobState>(m_progressViewFilter)).pixmap(16, 16, QIcon::Disabled));
+                       m_filterInfoLabelIcon->show();
+                       resizeEvent(NULL);
+               }
+       }
+       else if(!m_filterInfoLabel->isHidden())
+       {
+               m_filterInfoLabel->hide();
+               m_filterInfoLabelIcon->hide();
+       }
+}
+
 ////////////////////////////////////////////////////////////
 // Private Functions
 ////////////////////////////////////////////////////////////
@@ -721,6 +917,10 @@ void ProcessingDialog::startNextJob(void)
        {
                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());
@@ -729,12 +929,18 @@ void ProcessingDialog::startNextJob(void)
        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,bool)), this, SLOT(processFinished(QUuid,QString,bool)), 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)
@@ -844,8 +1050,7 @@ AbstractEncoder *ProcessingDialog::makeEncoder(bool *nativeResampling)
                        opusEncoder->setOptimizeFor(m_settings->opusOptimizeFor());
                        opusEncoder->setEncodeComplexity(m_settings->opusComplexity());
                        opusEncoder->setFrameSize(m_settings->opusFramesize());
-                       opusEncoder->setExpAnalysisOn(m_settings->opusExpAnalysis());
-                       //TODO: opusEncoder->setCustomParams(m_settings->customParametersOpus());
+                       opusEncoder->setCustomParams(m_settings->customParametersOpus());
                        encoder = opusEncoder;
                }
                break;  case SettingsModel::DCAEncoder:
@@ -991,15 +1196,15 @@ void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason rea
 void ProcessingDialog::cpuUsageHasChanged(const double val)
 {
        
-       this->label_cpu->setText(QString().sprintf(" %d%%", qRound(val * 100.0)));
-       UPDATE_MIN_WIDTH(label_cpu);
+       ui->label_cpu->setText(QString().sprintf(" %d%%", qRound(val * 100.0)));
+       UPDATE_MIN_WIDTH(ui->label_cpu);
 }
 
 void ProcessingDialog::ramUsageHasChanged(const double val)
 {
        
-       this->label_ram->setText(QString().sprintf(" %d%%", qRound(val * 100.0)));
-       UPDATE_MIN_WIDTH(label_ram);
+       ui->label_ram->setText(QString().sprintf(" %d%%", qRound(val * 100.0)));
+       UPDATE_MIN_WIDTH(ui->label_ram);
 }
 
 void ProcessingDialog::diskUsageHasChanged(const quint64 val)
@@ -1014,8 +1219,8 @@ void ProcessingDialog::diskUsageHasChanged(const quint64 val)
                postfix++;
        }
 
-       this->label_disk->setText(QString().sprintf(" %3.1f %s", space, postfixStr[postfix]));
-       UPDATE_MIN_WIDTH(label_disk);
+       ui->label_disk->setText(QString().sprintf(" %3.1f %s", space, postfixStr[postfix]));
+       UPDATE_MIN_WIDTH(ui->label_disk);
 }
 
 bool ProcessingDialog::shutdownComputer(void)
@@ -1076,27 +1281,28 @@ QString ProcessingDialog::time2text(const double timeVal) const
 {
        double intPart = 0;
        double frcPart = modf(timeVal, &intPart);
-       int x = 0, y = 0; QString a, b;
 
        QTime time = QTime().addSecs(qRound(intPart)).addMSecs(qRound(frcPart * 1000.0));
 
+       QString a, b;
+
        if(time.hour() > 0)
        {
-               x = time.hour();   a = tr("hour(s)");
-               y = time.minute(); b = tr("minute(s)");
+               a = tr("%n hour(s)", "", time.hour());
+               b = tr("%n minute(s)", "", time.minute());
        }
        else if(time.minute() > 0)
        {
-               x = time.minute(); a = tr("minute(s)");
-               y = time.second(); b = tr("second(s)");
+               a = tr("%n minute(s)", "", time.minute());
+               b = tr("%n second(s)", "", time.second());
        }
        else
        {
-               x = time.second(); a = tr("second(s)");
-               y = time.msec();   b = tr("millisecond(s)");
+               a = tr("%n second(s)", "", time.second());
+               b = tr("%n millisecond(s)", "", time.msec());
        }
 
-       return QString("%1 %2, %3 %4").arg(QString::number(x), a, QString::number(y), b);
+       return QString("%1, %2").arg(a, b);
 }
 
 ////////////////////////////////////////////////////////////