OSDN Git Service

Added option to choose between 8-Bit and 10-Bit encoding at runtime. We now include...
[x264-launcher/x264-launcher.git] / src / model_jobList.cpp
index 4b6773d..f5b359a 100644 (file)
 #include "model_jobList.h"
 #include "global.h"
 #include "thread_encode.h"
+#include "model_options.h"
 
 #include <QIcon>
+#include <QFileInfo>
 
 JobListModel::JobListModel(void)
 {
@@ -101,7 +103,7 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const
                        switch(index.column())
                        {
                        case 0:
-                               return m_jobs.at(index.row()).toString();
+                               return m_name.value(m_jobs.at(index.row()));
                                break;
                        case 1:
                                switch(m_status.value(m_jobs.at(index.row())))
@@ -130,6 +132,15 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const
                                case EncodeThread::JobStatus_Failed:
                                        return QVariant::fromValue<QString>(tr("Failed!"));
                                        break;
+                               case EncodeThread::JobStatus_Pausing:
+                                       return QVariant::fromValue<QString>(tr("Pausing..."));
+                                       break;
+                               case EncodeThread::JobStatus_Paused:
+                                       return QVariant::fromValue<QString>(tr("Paused."));
+                                       break;
+                               case EncodeThread::JobStatus_Resuming:
+                                       return QVariant::fromValue<QString>(tr("Resuming..."));
+                                       break;
                                case EncodeThread::JobStatus_Aborting:
                                        return QVariant::fromValue<QString>(tr("Aborting..."));
                                        break;
@@ -160,7 +171,7 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const
                        switch(m_status.value(m_jobs.at(index.row())))
                        {
                        case EncodeThread::JobStatus_Enqueued:
-                               return QIcon(":/buttons/clock_pause.png");
+                               return QIcon(":/buttons/hourglass.png");
                                break;
                        case EncodeThread::JobStatus_Starting:
                                return QIcon(":/buttons/lightning.png");
@@ -179,6 +190,15 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const
                        case EncodeThread::JobStatus_Failed:
                                return QIcon(":/buttons/exclamation.png");
                                break;
+                       case EncodeThread::JobStatus_Pausing:
+                               return QIcon(":/buttons/clock_pause.png");
+                               break;
+                       case EncodeThread::JobStatus_Paused:
+                               return QIcon(":/buttons/suspended.png");
+                               break;
+                       case EncodeThread::JobStatus_Resuming:
+                               return QIcon(":/buttons/clock_play.png");
+                               break;
                        case EncodeThread::JobStatus_Aborting:
                                return QIcon(":/buttons/clock_stop.png");
                                break;
@@ -208,9 +228,50 @@ QModelIndex JobListModel::insertJob(EncodeThread *thread)
        {
                return QModelIndex();
        }
-               
+       
+       QString config = "N/A";
+
+       switch(thread->options()->rcMode())
+       {
+       case OptionsModel::RCMode_CRF:
+               config = QString("CRF@%1").arg(QString::number(thread->options()->quantizer()));
+               break;
+       case OptionsModel::RCMode_CQ:
+               config = QString("CQ@%1").arg(QString::number(qRound(thread->options()->quantizer())));
+               break;
+       case OptionsModel::RCMode_2Pass:
+               config = QString("2Pass@%1").arg(QString::number(thread->options()->bitrate()));
+               break;
+       case OptionsModel::RCMode_ABR:
+               config = QString("ABR@%1").arg(QString::number(thread->options()->bitrate()));
+               break;
+       }
+
+       int n = 2;
+       QString jobName = QString("%1 (%2)").arg(QFileInfo(thread->sourceFileName()).completeBaseName().simplified(), config);
+
+       forever
+       {
+               bool unique = true;
+               for(int i = 0; i < m_jobs.count(); i++)
+               {
+                       if(m_name.value(m_jobs.at(i)).compare(jobName, Qt::CaseInsensitive) == 0)
+                       {
+                               unique = false;
+                               break;
+                       }
+               }
+               if(!unique)
+               {
+                       jobName = QString("%1 %2 (%3)").arg(QFileInfo(thread->sourceFileName()).completeBaseName().simplified(), QString::number(n++), config);
+                       continue;
+               }
+               break;
+       }
+
        beginInsertRows(QModelIndex(), m_jobs.count(), m_jobs.count());
        m_jobs.append(id);
+       m_name.insert(id, jobName);
        m_status.insert(id, EncodeThread::JobStatus_Enqueued);
        m_progress.insert(id, 0);
        m_threads.insert(id, thread);
@@ -243,12 +304,48 @@ bool JobListModel::startJob(const QModelIndex &index)
        return false;
 }
 
+bool JobListModel::pauseJob(const QModelIndex &index)
+{
+       if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
+       {
+               QUuid id = m_jobs.at(index.row());
+               EncodeThread::JobStatus status = m_status.value(id);
+               if((status == EncodeThread::JobStatus_Indexing) || (status == EncodeThread::JobStatus_Running) ||
+                       (status == EncodeThread::JobStatus_Running_Pass1) || (status == EncodeThread::JobStatus_Running_Pass2))
+               {
+                       updateStatus(id, EncodeThread::JobStatus_Pausing);
+                       m_threads.value(id)->pauseJob();
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+bool JobListModel::resumeJob(const QModelIndex &index)
+{
+       if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
+       {
+               QUuid id = m_jobs.at(index.row());
+               EncodeThread::JobStatus status = m_status.value(id);
+               if(status == EncodeThread::JobStatus_Paused)
+               {
+                       updateStatus(id, EncodeThread::JobStatus_Resuming);
+                       m_threads.value(id)->resumeJob();
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 bool JobListModel::abortJob(const QModelIndex &index)
 {
        if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
        {
                QUuid id = m_jobs.at(index.row());
-               if(m_status.value(id) == EncodeThread::JobStatus_Indexing || m_status.value(id) == EncodeThread::JobStatus_Running)
+               if(m_status.value(id) == EncodeThread::JobStatus_Indexing || m_status.value(id) == EncodeThread::JobStatus_Running ||
+                       m_status.value(id) == EncodeThread::JobStatus_Running_Pass1 || EncodeThread::JobStatus_Running_Pass2)
                {
                        updateStatus(id, EncodeThread::JobStatus_Aborting);
                        m_threads.value(id)->abortJob();
@@ -259,6 +356,40 @@ bool JobListModel::abortJob(const QModelIndex &index)
        return false;
 }
 
+bool JobListModel::deleteJob(const QModelIndex &index)
+{
+       if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
+       {
+               QUuid id = m_jobs.at(index.row());
+               if(m_status.value(id) == EncodeThread::JobStatus_Completed || m_status.value(id) == EncodeThread::JobStatus_Failed ||
+                       m_status.value(id) == EncodeThread::JobStatus_Aborted || m_status.value(id) == EncodeThread::JobStatus_Enqueued)
+               {
+                       int idx = index.row();
+                       QUuid id = m_jobs.at(idx);
+                       EncodeThread *thread = m_threads.value(id, NULL);
+                       LogFileModel *logFile = m_logFile.value(id, NULL);
+                       if((thread == NULL) || (!thread->isRunning()))
+                       {
+                               
+                               beginRemoveRows(QModelIndex(), idx, idx);
+                               m_jobs.removeAt(index.row());
+                               m_name.remove(id);
+                               m_threads.remove(id);
+                               m_status.remove(id);
+                               m_progress.remove(id);
+                               m_logFile.remove(id);
+                               m_details.remove(id);
+                               endRemoveRows();
+                               X264_DELETE(thread);
+                               X264_DELETE(logFile);
+                               return true;
+                       }
+               }
+       }
+
+       return false;
+}
+
 LogFileModel *JobListModel::getLogFile(const QModelIndex &index)
 {
        if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
@@ -269,6 +400,32 @@ LogFileModel *JobListModel::getLogFile(const QModelIndex &index)
        return NULL;
 }
 
+const QString &JobListModel::getJobSourceFile(const QModelIndex &index)
+{
+       static QString nullStr;
+       
+       if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
+       {
+               EncodeThread *thread = m_threads.value(m_jobs.at(index.row()));
+               return (thread != NULL) ? thread->sourceFileName() : nullStr;
+       }
+
+       return nullStr;
+}
+
+const QString &JobListModel::getJobOutputFile(const QModelIndex &index)
+{
+       static QString nullStr;
+       
+       if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
+       {
+               EncodeThread *thread = m_threads.value(m_jobs.at(index.row()));
+               return (thread != NULL) ? thread->outputFileName() : nullStr;
+       }
+
+       return nullStr;
+}
+
 EncodeThread::JobStatus JobListModel::getJobStatus(const QModelIndex &index)
 {
        if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
@@ -289,6 +446,19 @@ unsigned int JobListModel::getJobProgress(const QModelIndex &index)
        return 0;
 }
 
+const OptionsModel *JobListModel::getJobOptions(const QModelIndex &index)
+{
+       static QString nullStr;
+       
+       if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
+       {
+               EncodeThread *thread = m_threads.value(m_jobs.at(index.row()));
+               return (thread != NULL) ? thread->options() : NULL;
+       }
+
+       return NULL;
+}
+
 QModelIndex JobListModel::getJobIndexById(const QUuid &id)
 {
        if(m_jobs.contains(id))
@@ -320,7 +490,7 @@ void JobListModel::updateProgress(const QUuid &jobId, unsigned int newProgress)
 
        if((index = m_jobs.indexOf(jobId)) >= 0)
        {
-               m_progress.insert(jobId, newProgress);
+               m_progress.insert(jobId, qBound(0U, newProgress, 100U));
                emit dataChanged(createIndex(index, 2), createIndex(index, 2));
        }
 }