2012-01-28 18:55:40 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Simple x264 Launcher
|
2015-01-31 19:56:04 +01:00
|
|
|
// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
|
2012-01-28 18:55:40 +01:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-02-02 22:11:06 +01:00
|
|
|
//Internal
|
2012-01-28 23:24:41 +01:00
|
|
|
#include "global.h"
|
2013-07-01 03:03:21 +02:00
|
|
|
#include "model_jobList.h"
|
2012-01-28 18:55:40 +01:00
|
|
|
#include "thread_encode.h"
|
2012-02-04 01:12:21 +01:00
|
|
|
#include "model_options.h"
|
2013-07-03 21:34:21 +02:00
|
|
|
#include "model_preferences.h"
|
2013-07-01 03:03:21 +02:00
|
|
|
#include "resource.h"
|
2012-01-28 18:55:40 +01:00
|
|
|
|
2015-02-02 22:11:06 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/Sound.h>
|
|
|
|
|
|
|
|
//Qt
|
2012-01-28 19:59:04 +01:00
|
|
|
#include <QIcon>
|
2012-01-29 15:57:23 +01:00
|
|
|
#include <QFileInfo>
|
2014-04-18 14:41:20 +02:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
static const char *KEY_ENTRY_COUNT = "entry_count";
|
|
|
|
static const char *KEY_SOURCE_FILE = "source_file";
|
|
|
|
static const char *KEY_OUTPUT_FILE = "output_file";
|
|
|
|
static const char *KEY_ENC_OPTIONS = "enc_options";
|
|
|
|
|
|
|
|
static const char *JOB_TEMPLATE = "job_%08x";
|
2012-01-28 19:59:04 +01:00
|
|
|
|
2014-04-20 17:38:55 +02:00
|
|
|
#define VALID_INDEX(INDEX) ((INDEX).isValid() && ((INDEX).row() >= 0) && ((INDEX).row() < m_jobs.count()))
|
|
|
|
|
2013-07-03 21:34:21 +02:00
|
|
|
JobListModel::JobListModel(PreferencesModel *preferences)
|
2012-01-28 18:55:40 +01:00
|
|
|
{
|
2013-07-01 03:03:21 +02:00
|
|
|
m_preferences = preferences;
|
2012-01-28 18:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JobListModel::~JobListModel(void)
|
|
|
|
{
|
2012-01-28 23:24:41 +01:00
|
|
|
while(!m_jobs.isEmpty())
|
|
|
|
{
|
2012-01-29 01:28:41 +01:00
|
|
|
QUuid id = m_jobs.takeFirst();
|
|
|
|
EncodeThread *thread = m_threads.value(id, NULL);
|
|
|
|
LogFileModel *logFile = m_logFile.value(id, NULL);
|
2015-02-02 22:11:06 +01:00
|
|
|
MUTILS_DELETE(thread);
|
|
|
|
MUTILS_DELETE(logFile);
|
2012-01-28 23:24:41 +01:00
|
|
|
}
|
2012-01-28 18:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Model interface
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int JobListModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
2012-01-28 23:24:41 +01:00
|
|
|
return 4;
|
2012-01-28 18:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int JobListModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return m_jobs.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant JobListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
|
|
|
|
{
|
|
|
|
switch(section)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return QVariant::fromValue<QString>(tr("Job"));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return QVariant::fromValue<QString>(tr("Status"));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return QVariant::fromValue<QString>(tr("Progress"));
|
|
|
|
break;
|
2012-01-28 23:24:41 +01:00
|
|
|
case 3:
|
2012-01-29 00:57:47 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Details"));
|
2012-01-28 23:24:41 +01:00
|
|
|
break;
|
2012-01-28 18:55:40 +01:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex JobListModel::index(int row, int column, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return createIndex(row, column, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex JobListModel::parent(const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant JobListModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
if(index.row() >= 0 && index.row() < m_jobs.count())
|
|
|
|
{
|
|
|
|
switch(index.column())
|
|
|
|
{
|
|
|
|
case 0:
|
2012-01-29 15:57:23 +01:00
|
|
|
return m_name.value(m_jobs.at(index.row()));
|
2012-01-28 18:55:40 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
switch(m_status.value(m_jobs.at(index.row())))
|
|
|
|
{
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Enqueued:
|
2012-01-28 19:59:04 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Enqueued."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Starting:
|
2012-01-28 18:55:40 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Starting..."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Indexing:
|
2012-01-28 18:55:40 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Indexing..."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Running:
|
2012-01-28 18:55:40 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Running..."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Running_Pass1:
|
2012-01-29 00:57:47 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Running... (Pass 1)"));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Running_Pass2:
|
2012-01-29 00:57:47 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Running... (Pass 2)"));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Completed:
|
2012-01-28 18:55:40 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Completed."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Failed:
|
2012-01-28 18:55:40 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Failed!"));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Pausing:
|
2012-02-02 02:13:02 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Pausing..."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Paused:
|
2012-02-02 02:13:02 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Paused."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Resuming:
|
2012-02-02 02:13:02 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Resuming..."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Aborting:
|
2012-01-28 23:24:41 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Aborting..."));
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Aborted:
|
2012-01-28 18:55:40 +01:00
|
|
|
return QVariant::fromValue<QString>(tr("Aborted!"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QVariant::fromValue<QString>(tr("(Unknown)"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return QString().sprintf("%d%%", m_progress.value(m_jobs.at(index.row())));
|
|
|
|
break;
|
2012-01-28 23:24:41 +01:00
|
|
|
case 3:
|
|
|
|
return m_details.value(m_jobs.at(index.row()));
|
|
|
|
break;
|
2012-01-28 18:55:40 +01:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-28 19:59:04 +01:00
|
|
|
else if(role == Qt::DecorationRole)
|
|
|
|
{
|
|
|
|
if(index.row() >= 0 && index.row() < m_jobs.count() && index.column() == 0)
|
|
|
|
{
|
|
|
|
switch(m_status.value(m_jobs.at(index.row())))
|
|
|
|
{
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Enqueued:
|
2012-02-02 02:13:02 +01:00
|
|
|
return QIcon(":/buttons/hourglass.png");
|
2012-01-28 19:59:04 +01:00
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Starting:
|
2012-01-28 19:59:04 +01:00
|
|
|
return QIcon(":/buttons/lightning.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Indexing:
|
2012-01-28 19:59:04 +01:00
|
|
|
return QIcon(":/buttons/find.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Running:
|
|
|
|
case JobStatus_Running_Pass1:
|
|
|
|
case JobStatus_Running_Pass2:
|
2012-01-28 19:59:04 +01:00
|
|
|
return QIcon(":/buttons/play.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Completed:
|
2012-01-28 19:59:04 +01:00
|
|
|
return QIcon(":/buttons/accept.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Failed:
|
2012-01-28 19:59:04 +01:00
|
|
|
return QIcon(":/buttons/exclamation.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Pausing:
|
2012-02-02 02:13:02 +01:00
|
|
|
return QIcon(":/buttons/clock_pause.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Paused:
|
2012-02-02 02:13:02 +01:00
|
|
|
return QIcon(":/buttons/suspended.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Resuming:
|
2012-02-02 02:13:02 +01:00
|
|
|
return QIcon(":/buttons/clock_play.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Aborting:
|
2012-01-28 23:24:41 +01:00
|
|
|
return QIcon(":/buttons/clock_stop.png");
|
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Aborted:
|
2012-01-28 19:59:04 +01:00
|
|
|
return QIcon(":/buttons/error.png");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-28 18:55:40 +01:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Public interface
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-28 23:24:41 +01:00
|
|
|
QModelIndex JobListModel::insertJob(EncodeThread *thread)
|
2012-01-28 18:55:40 +01:00
|
|
|
{
|
|
|
|
QUuid id = thread->getId();
|
|
|
|
|
|
|
|
if(m_jobs.contains(id))
|
|
|
|
{
|
2012-01-28 23:24:41 +01:00
|
|
|
return QModelIndex();
|
2012-01-28 18:55:40 +01:00
|
|
|
}
|
2012-02-04 01:12:21 +01:00
|
|
|
|
|
|
|
QString config = "N/A";
|
|
|
|
|
2014-04-18 14:41:20 +02:00
|
|
|
switch(thread->options()->rcMode())
|
|
|
|
{
|
|
|
|
case OptionsModel::EncType_X264:
|
|
|
|
config = QString("x264");
|
|
|
|
break;
|
|
|
|
case OptionsModel::EncType_X265:
|
|
|
|
config = QString("x265");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-04 01:12:21 +01:00
|
|
|
switch(thread->options()->rcMode())
|
|
|
|
{
|
|
|
|
case OptionsModel::RCMode_CRF:
|
2014-04-18 14:41:20 +02:00
|
|
|
config = QString("%1 CRF@%2") .arg(config, QString::number(thread->options()->quantizer()));
|
2012-02-04 01:12:21 +01:00
|
|
|
break;
|
2012-02-04 19:09:27 +01:00
|
|
|
case OptionsModel::RCMode_CQ:
|
2014-04-18 14:41:20 +02:00
|
|
|
config = QString("%1 CQ@%2") .arg(config, QString::number(qRound(thread->options()->quantizer())));
|
2012-02-04 19:09:27 +01:00
|
|
|
break;
|
2012-02-04 01:12:21 +01:00
|
|
|
case OptionsModel::RCMode_2Pass:
|
2014-04-18 14:41:20 +02:00
|
|
|
config = QString("%1 2Pass@%2").arg(config, QString::number(thread->options()->bitrate()));
|
2012-02-04 01:12:21 +01:00
|
|
|
break;
|
|
|
|
case OptionsModel::RCMode_ABR:
|
2014-04-18 14:41:20 +02:00
|
|
|
config = QString("%1 ABR@%2") .arg(config, QString::number(thread->options()->bitrate()));
|
2012-02-04 01:12:21 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-30 17:50:19 +01:00
|
|
|
int n = 2;
|
2012-02-04 22:44:19 +01:00
|
|
|
QString jobName = QString("%1 (%2)").arg(QFileInfo(thread->sourceFileName()).completeBaseName().simplified(), config);
|
2012-01-30 17:50:19 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-02-04 22:44:19 +01:00
|
|
|
jobName = QString("%1 %2 (%3)").arg(QFileInfo(thread->sourceFileName()).completeBaseName().simplified(), QString::number(n++), config);
|
2012-01-30 17:50:19 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-05-11 21:52:07 +02:00
|
|
|
|
|
|
|
LogFileModel *logFile = new LogFileModel(thread->sourceFileName(), thread->outputFileName(), config);
|
|
|
|
|
2012-01-28 18:55:40 +01:00
|
|
|
beginInsertRows(QModelIndex(), m_jobs.count(), m_jobs.count());
|
|
|
|
m_jobs.append(id);
|
2012-01-30 17:50:19 +01:00
|
|
|
m_name.insert(id, jobName);
|
2013-07-03 21:52:19 +02:00
|
|
|
m_status.insert(id, JobStatus_Enqueued);
|
2012-01-28 18:55:40 +01:00
|
|
|
m_progress.insert(id, 0);
|
|
|
|
m_threads.insert(id, thread);
|
2013-05-11 21:52:07 +02:00
|
|
|
m_logFile.insert(id, logFile);
|
2012-01-28 23:24:41 +01:00
|
|
|
m_details.insert(id, tr("Not started yet."));
|
2012-01-28 18:55:40 +01:00
|
|
|
endInsertRows();
|
|
|
|
|
2013-07-03 23:56:41 +02:00
|
|
|
connect(thread, SIGNAL(statusChanged(QUuid, JobStatus)), this, SLOT(updateStatus(QUuid, JobStatus)), Qt::QueuedConnection);
|
2012-01-28 18:55:40 +01:00
|
|
|
connect(thread, SIGNAL(progressChanged(QUuid, unsigned int)), this, SLOT(updateProgress(QUuid, unsigned int)), Qt::QueuedConnection);
|
2012-01-28 19:59:04 +01:00
|
|
|
connect(thread, SIGNAL(messageLogged(QUuid, QString)), logFile, SLOT(addLogMessage(QUuid, QString)), Qt::QueuedConnection);
|
2012-01-28 23:24:41 +01:00
|
|
|
connect(thread, SIGNAL(detailsChanged(QUuid, QString)), this, SLOT(updateDetails(QUuid, QString)), Qt::QueuedConnection);
|
2012-01-28 19:59:04 +01:00
|
|
|
|
2012-01-28 23:24:41 +01:00
|
|
|
return createIndex(m_jobs.count() - 1, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JobListModel::startJob(const QModelIndex &index)
|
|
|
|
{
|
2014-04-20 17:38:55 +02:00
|
|
|
if(VALID_INDEX(index))
|
2012-01-28 23:24:41 +01:00
|
|
|
{
|
|
|
|
QUuid id = m_jobs.at(index.row());
|
2013-07-03 21:52:19 +02:00
|
|
|
if(m_status.value(id) == JobStatus_Enqueued)
|
2012-01-28 23:24:41 +01:00
|
|
|
{
|
2013-07-03 21:52:19 +02:00
|
|
|
updateStatus(id, JobStatus_Starting);
|
2012-01-28 23:24:41 +01:00
|
|
|
updateDetails(id, tr("Starting up, please wait..."));
|
|
|
|
m_threads.value(id)->start();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:13:02 +01:00
|
|
|
bool JobListModel::pauseJob(const QModelIndex &index)
|
|
|
|
{
|
2014-04-20 17:38:55 +02:00
|
|
|
if(VALID_INDEX(index))
|
2012-02-02 02:13:02 +01:00
|
|
|
{
|
|
|
|
QUuid id = m_jobs.at(index.row());
|
2013-07-03 21:52:19 +02:00
|
|
|
JobStatus status = m_status.value(id);
|
|
|
|
if((status == JobStatus_Indexing) || (status == JobStatus_Running) ||
|
|
|
|
(status == JobStatus_Running_Pass1) || (status == JobStatus_Running_Pass2))
|
2012-02-02 02:13:02 +01:00
|
|
|
{
|
2013-07-03 21:52:19 +02:00
|
|
|
updateStatus(id, JobStatus_Pausing);
|
2012-02-02 02:13:02 +01:00
|
|
|
m_threads.value(id)->pauseJob();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JobListModel::resumeJob(const QModelIndex &index)
|
|
|
|
{
|
2014-04-20 17:38:55 +02:00
|
|
|
if(VALID_INDEX(index))
|
2012-02-02 02:13:02 +01:00
|
|
|
{
|
|
|
|
QUuid id = m_jobs.at(index.row());
|
2013-07-03 21:52:19 +02:00
|
|
|
JobStatus status = m_status.value(id);
|
|
|
|
if(status == JobStatus_Paused)
|
2012-02-02 02:13:02 +01:00
|
|
|
{
|
2013-07-03 21:52:19 +02:00
|
|
|
updateStatus(id, JobStatus_Resuming);
|
2012-02-02 02:13:02 +01:00
|
|
|
m_threads.value(id)->resumeJob();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-28 23:24:41 +01:00
|
|
|
bool JobListModel::abortJob(const QModelIndex &index)
|
|
|
|
{
|
2014-04-20 17:38:55 +02:00
|
|
|
if(VALID_INDEX(index))
|
2012-01-28 23:24:41 +01:00
|
|
|
{
|
|
|
|
QUuid id = m_jobs.at(index.row());
|
2013-07-03 21:52:19 +02:00
|
|
|
if(m_status.value(id) == JobStatus_Indexing || m_status.value(id) == JobStatus_Running ||
|
|
|
|
m_status.value(id) == JobStatus_Running_Pass1 || JobStatus_Running_Pass2)
|
2012-01-28 23:24:41 +01:00
|
|
|
{
|
2013-07-03 21:52:19 +02:00
|
|
|
updateStatus(id, JobStatus_Aborting);
|
2012-01-28 23:24:41 +01:00
|
|
|
m_threads.value(id)->abortJob();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-01-28 18:55:40 +01:00
|
|
|
}
|
|
|
|
|
2012-02-02 22:53:40 +01:00
|
|
|
bool JobListModel::deleteJob(const QModelIndex &index)
|
|
|
|
{
|
2014-04-20 17:38:55 +02:00
|
|
|
if(VALID_INDEX(index))
|
2012-02-02 22:53:40 +01:00
|
|
|
{
|
|
|
|
QUuid id = m_jobs.at(index.row());
|
2013-07-03 21:52:19 +02:00
|
|
|
if(m_status.value(id) == JobStatus_Completed || m_status.value(id) == JobStatus_Failed ||
|
|
|
|
m_status.value(id) == JobStatus_Aborted || m_status.value(id) == JobStatus_Enqueued)
|
2012-02-02 22:53:40 +01:00
|
|
|
{
|
|
|
|
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();
|
2015-02-02 22:11:06 +01:00
|
|
|
MUTILS_DELETE(thread);
|
|
|
|
MUTILS_DELETE(logFile);
|
2012-02-02 22:53:40 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-20 17:38:55 +02:00
|
|
|
bool JobListModel::moveJob(const QModelIndex &index, const int &direction)
|
|
|
|
{
|
|
|
|
if(VALID_INDEX(index))
|
|
|
|
{
|
|
|
|
if((direction == MOVE_UP) && (index.row() > 0))
|
|
|
|
{
|
|
|
|
beginMoveRows(QModelIndex(), index.row(), index.row(), QModelIndex(), index.row() - 1);
|
|
|
|
m_jobs.swap(index.row(), index.row() - 1);
|
|
|
|
endMoveRows();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if((direction == MOVE_DOWN) && (index.row() < m_jobs.size() - 1))
|
|
|
|
{
|
|
|
|
beginMoveRows(QModelIndex(), index.row(), index.row(), QModelIndex(), index.row() + 2);
|
|
|
|
m_jobs.swap(index.row(), index.row() + 1);
|
|
|
|
endMoveRows();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-28 19:59:04 +01:00
|
|
|
LogFileModel *JobListModel::getLogFile(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
|
|
|
|
{
|
|
|
|
return m_logFile.value(m_jobs.at(index.row()));
|
|
|
|
}
|
2012-01-28 23:24:41 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-14 23:36:44 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-02-02 22:53:40 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-03 21:52:19 +02:00
|
|
|
JobStatus JobListModel::getJobStatus(const QModelIndex &index)
|
2012-01-28 23:24:41 +01:00
|
|
|
{
|
|
|
|
if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
|
|
|
|
{
|
|
|
|
return m_status.value(m_jobs.at(index.row()));
|
|
|
|
}
|
|
|
|
|
2013-07-03 21:52:19 +02:00
|
|
|
return static_cast<JobStatus>(-1);
|
2012-01-28 23:24:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int JobListModel::getJobProgress(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
|
|
|
|
{
|
|
|
|
return m_progress.value(m_jobs.at(index.row()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-14 23:36:44 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-28 23:24:41 +01:00
|
|
|
QModelIndex JobListModel::getJobIndexById(const QUuid &id)
|
|
|
|
{
|
|
|
|
if(m_jobs.contains(id))
|
|
|
|
{
|
|
|
|
return createIndex(m_jobs.indexOf(id), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QModelIndex();
|
2012-01-28 19:59:04 +01:00
|
|
|
}
|
|
|
|
|
2012-01-28 18:55:40 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Slots
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-07-03 21:52:19 +02:00
|
|
|
void JobListModel::updateStatus(const QUuid &jobId, JobStatus newStatus)
|
2012-01-28 18:55:40 +01:00
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
if((index = m_jobs.indexOf(jobId)) >= 0)
|
|
|
|
{
|
|
|
|
m_status.insert(jobId, newStatus);
|
2012-01-28 19:59:04 +01:00
|
|
|
emit dataChanged(createIndex(index, 0), createIndex(index, 1));
|
2013-07-01 03:03:21 +02:00
|
|
|
|
2014-02-14 00:01:00 +01:00
|
|
|
if(m_preferences->getEnableSounds())
|
2013-07-01 03:03:21 +02:00
|
|
|
{
|
|
|
|
switch(newStatus)
|
|
|
|
{
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Completed:
|
2015-02-02 22:11:06 +01:00
|
|
|
MUtils::Sound::play_sound("tada", true);
|
2013-07-01 03:03:21 +02:00
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Aborted:
|
2015-02-02 22:11:06 +01:00
|
|
|
MUtils::Sound::play_sound("shattering", true);
|
2013-07-01 03:03:21 +02:00
|
|
|
break;
|
2013-07-03 21:52:19 +02:00
|
|
|
case JobStatus_Failed:
|
2015-02-02 22:11:06 +01:00
|
|
|
MUtils::Sound::play_sound("failure", true);
|
2013-07-01 03:03:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-28 18:55:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JobListModel::updateProgress(const QUuid &jobId, unsigned int newProgress)
|
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
if((index = m_jobs.indexOf(jobId)) >= 0)
|
|
|
|
{
|
2012-01-29 21:31:09 +01:00
|
|
|
m_progress.insert(jobId, qBound(0U, newProgress, 100U));
|
2012-01-28 18:55:40 +01:00
|
|
|
emit dataChanged(createIndex(index, 2), createIndex(index, 2));
|
|
|
|
}
|
|
|
|
}
|
2012-01-28 23:24:41 +01:00
|
|
|
|
|
|
|
void JobListModel::updateDetails(const QUuid &jobId, const QString &details)
|
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
if((index = m_jobs.indexOf(jobId)) >= 0)
|
|
|
|
{
|
|
|
|
m_details.insert(jobId, details);
|
|
|
|
emit dataChanged(createIndex(index, 3), createIndex(index, 3));
|
|
|
|
}
|
|
|
|
}
|
2014-04-18 14:41:20 +02:00
|
|
|
|
|
|
|
size_t JobListModel::saveQueuedJobs(void)
|
|
|
|
{
|
|
|
|
const QString appDir = x264_data_path();
|
|
|
|
QSettings settings(QString("%1/queue.ini").arg(appDir), QSettings::IniFormat);
|
|
|
|
|
|
|
|
settings.clear();
|
|
|
|
settings.setValue(KEY_ENTRY_COUNT, 0);
|
|
|
|
size_t jobCounter = 0;
|
|
|
|
|
|
|
|
for(QList<QUuid>::ConstIterator iter = m_jobs.constBegin(); iter != m_jobs.constEnd(); iter++)
|
|
|
|
{
|
|
|
|
if(m_status.value(*iter) == JobStatus_Enqueued)
|
|
|
|
{
|
|
|
|
if(const EncodeThread *thread = m_threads.value(*iter))
|
|
|
|
{
|
|
|
|
settings.beginGroup(QString().sprintf(JOB_TEMPLATE, jobCounter++));
|
|
|
|
settings.setValue(KEY_SOURCE_FILE, thread->sourceFileName());
|
|
|
|
settings.setValue(KEY_OUTPUT_FILE, thread->outputFileName());
|
|
|
|
|
|
|
|
settings.beginGroup(KEY_ENC_OPTIONS);
|
|
|
|
OptionsModel::saveOptions(thread->options(), settings);
|
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
settings.setValue(KEY_ENTRY_COUNT, jobCounter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.sync();
|
|
|
|
return jobCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t JobListModel::loadQueuedJobs(const SysinfoModel *sysinfo)
|
|
|
|
{
|
|
|
|
const QString appDir = x264_data_path();
|
|
|
|
QSettings settings(QString("%1/queue.ini").arg(appDir), QSettings::IniFormat);
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
const size_t jobCounter = settings.value(KEY_ENTRY_COUNT, 0).toUInt(&ok);
|
|
|
|
|
|
|
|
if((!ok) || (jobCounter < 1))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-20 17:38:55 +02:00
|
|
|
const QStringList groups = settings.childGroups();
|
|
|
|
for(size_t i = 0; i < jobCounter; i++)
|
|
|
|
{
|
|
|
|
if(!groups.contains(QString().sprintf(JOB_TEMPLATE, i)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2014-04-18 14:41:20 +02:00
|
|
|
|
2014-04-20 17:38:55 +02:00
|
|
|
size_t jobsCreated = 0;
|
2014-04-18 14:41:20 +02:00
|
|
|
for(size_t i = 0; i < jobCounter; i++)
|
|
|
|
{
|
|
|
|
settings.beginGroup(QString().sprintf(JOB_TEMPLATE, i));
|
|
|
|
const QString sourceFileName = settings.value(KEY_SOURCE_FILE, QString()).toString().trimmed();
|
|
|
|
const QString outputFileName = settings.value(KEY_OUTPUT_FILE, QString()).toString().trimmed();
|
|
|
|
|
|
|
|
if(sourceFileName.isEmpty() || outputFileName.isEmpty())
|
|
|
|
{
|
|
|
|
settings.endGroup();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.beginGroup(KEY_ENC_OPTIONS);
|
|
|
|
OptionsModel options(sysinfo);
|
|
|
|
const bool okay = OptionsModel::loadOptions(&options, settings);
|
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
if(okay)
|
|
|
|
{
|
|
|
|
EncodeThread *thread = new EncodeThread(sourceFileName, outputFileName, &options, sysinfo, m_preferences);
|
|
|
|
insertJob(thread);
|
|
|
|
jobsCreated++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return jobsCreated;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JobListModel::clearQueuedJobs(void)
|
|
|
|
{
|
|
|
|
const QString appDir = x264_data_path();
|
|
|
|
QSettings settings(QString("%1/queue.ini").arg(appDir), QSettings::IniFormat);
|
|
|
|
settings.clear();
|
2014-04-20 17:38:55 +02:00
|
|
|
settings.setValue(KEY_ENTRY_COUNT, 0);
|
|
|
|
settings.sync();
|
2014-04-18 14:41:20 +02:00
|
|
|
}
|