2010-11-17 20:39:10 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2011-01-01 17:04:25 +01:00
|
|
|
// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-17 20:39:10 +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
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Model_Progress.h"
|
|
|
|
|
2010-11-18 22:37:35 +01:00
|
|
|
#include <QUuid>
|
|
|
|
|
2011-02-02 22:56:45 +01:00
|
|
|
ProgressModel::ProgressModel(void)
|
|
|
|
:
|
2010-11-18 00:32:46 +01:00
|
|
|
m_iconRunning(":/icons/media_play.png"),
|
2010-11-17 20:39:10 +01:00
|
|
|
m_iconPaused(":/icons/control_pause_blue.png"),
|
2010-11-18 00:32:46 +01:00
|
|
|
m_iconComplete(":/icons/tick.png"),
|
2011-02-02 22:56:45 +01:00
|
|
|
m_iconFailed(":/icons/exclamation.png"),
|
2011-03-28 04:26:47 +02:00
|
|
|
m_iconSystem(":/icons/computer.png"),
|
|
|
|
m_iconWarning(":/icons/error.png")
|
2010-11-17 20:39:10 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressModel::~ProgressModel(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProgressModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ProgressModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return m_jobList.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ProgressModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if(index.row() >= 0 && index.row() < m_jobList.count())
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
switch(index.column())
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return m_jobName.value(m_jobList.at(index.row()));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return m_jobStatus.value(m_jobList.at(index.row()));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(role == Qt::DecorationRole && index.column() == 0)
|
|
|
|
{
|
|
|
|
switch(m_jobState.value(m_jobList.at(index.row())))
|
|
|
|
{
|
|
|
|
case JobRunning:
|
2010-11-18 00:32:46 +01:00
|
|
|
return m_iconRunning;
|
2010-11-17 20:39:10 +01:00
|
|
|
break;
|
|
|
|
case JobPaused:
|
2010-11-18 00:32:46 +01:00
|
|
|
return m_iconPaused;
|
2010-11-17 20:39:10 +01:00
|
|
|
break;
|
|
|
|
case JobComplete:
|
2010-11-18 00:32:46 +01:00
|
|
|
return m_iconComplete;
|
2010-11-17 20:39:10 +01:00
|
|
|
break;
|
2011-02-02 22:56:45 +01:00
|
|
|
case JobSystem:
|
|
|
|
return m_iconSystem;
|
|
|
|
break;
|
2011-03-28 04:26:47 +02:00
|
|
|
case JobWarning:
|
|
|
|
return m_iconWarning;
|
|
|
|
break;
|
2010-11-17 20:39:10 +01:00
|
|
|
default:
|
2010-11-18 00:32:46 +01:00
|
|
|
return m_iconFailed;
|
2010-11-17 20:39:10 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-11-20 02:14:22 +01:00
|
|
|
else if(role == Qt::TextAlignmentRole)
|
|
|
|
{
|
|
|
|
return (index.column() == 1) ? QVariant(Qt::AlignHCenter | Qt::AlignVCenter) : QVariant();
|
|
|
|
}
|
2010-11-17 20:39:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ProgressModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if(role == Qt::DisplayRole)
|
|
|
|
{
|
|
|
|
if(orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
switch(section)
|
|
|
|
{
|
|
|
|
case 0:
|
2011-01-02 01:09:05 +01:00
|
|
|
return tr("Job");
|
2010-11-17 20:39:10 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-01-02 01:09:05 +01:00
|
|
|
return tr("Status");
|
2010-11-17 20:39:10 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(orientation == Qt::Vertical)
|
|
|
|
{
|
|
|
|
return QString::number(section + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2010-11-18 22:37:35 +01:00
|
|
|
void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState)
|
2010-11-17 20:39:10 +01:00
|
|
|
{
|
2010-11-18 22:37:35 +01:00
|
|
|
if(m_jobList.contains(jobId))
|
2010-11-17 20:39:10 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-06 18:29:34 +01:00
|
|
|
int newIndex = m_jobList.count();
|
|
|
|
beginInsertRows(QModelIndex(), newIndex, newIndex);
|
|
|
|
|
2010-11-18 22:37:35 +01:00
|
|
|
m_jobList.append(jobId);
|
|
|
|
m_jobName.insert(jobId, jobName);
|
|
|
|
m_jobStatus.insert(jobId, jobInitialStatus);
|
|
|
|
m_jobState.insert(jobId, jobInitialState);
|
2010-11-22 21:45:00 +01:00
|
|
|
m_jobLogFile.insert(jobId, QStringList());
|
2010-12-06 18:29:34 +01:00
|
|
|
|
|
|
|
endInsertRows();
|
2010-11-17 20:39:10 +01:00
|
|
|
}
|
|
|
|
|
2010-11-18 22:37:35 +01:00
|
|
|
void ProgressModel::updateJob(const QUuid &jobId, const QString &newStatus, int newState)
|
2010-11-17 20:39:10 +01:00
|
|
|
{
|
2010-11-21 21:51:22 +01:00
|
|
|
int row = m_jobList.indexOf(jobId);
|
|
|
|
|
|
|
|
if(row < 0)
|
2010-11-17 20:39:10 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-11-18 22:37:35 +01:00
|
|
|
|
|
|
|
if(!newStatus.isEmpty()) m_jobStatus.insert(jobId, newStatus);
|
|
|
|
if(newState >= 0) m_jobState.insert(jobId, newState);
|
2010-11-22 21:45:00 +01:00
|
|
|
|
2010-11-21 21:51:22 +01:00
|
|
|
emit dataChanged(index(row, 0), index(row, 1));
|
2010-11-17 20:39:10 +01:00
|
|
|
}
|
2010-11-22 21:45:00 +01:00
|
|
|
|
|
|
|
void ProgressModel::appendToLog(const QUuid &jobId, const QString &line)
|
|
|
|
{
|
|
|
|
if(m_jobList.contains(jobId))
|
|
|
|
{
|
2010-11-25 16:56:32 +01:00
|
|
|
m_jobLogFile[jobId].append(line.split('\n'));
|
2010-11-22 21:45:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QStringList &ProgressModel::getLogFile(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
if(index.row() < m_jobList.count())
|
|
|
|
{
|
|
|
|
QUuid id = m_jobList.at(index.row());
|
|
|
|
return m_jobLogFile[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
return *(reinterpret_cast<QStringList*>(NULL));
|
|
|
|
}
|
2011-02-02 22:56:45 +01:00
|
|
|
|
2011-02-11 23:16:11 +01:00
|
|
|
const QUuid &ProgressModel::getJobId(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
if(index.row() < m_jobList.count())
|
|
|
|
{
|
|
|
|
return m_jobList.at(index.row());
|
|
|
|
}
|
|
|
|
|
|
|
|
return *(reinterpret_cast<QUuid*>(NULL));
|
|
|
|
}
|
|
|
|
|
2011-03-28 04:26:47 +02:00
|
|
|
void ProgressModel::addSystemMessage(const QString &text, bool isWarning)
|
2011-02-02 22:56:45 +01:00
|
|
|
{
|
|
|
|
const QUuid &jobId = QUuid::createUuid();
|
|
|
|
|
|
|
|
if(m_jobList.contains(jobId))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int newIndex = m_jobList.count();
|
|
|
|
beginInsertRows(QModelIndex(), newIndex, newIndex);
|
|
|
|
|
|
|
|
m_jobList.append(jobId);
|
|
|
|
m_jobName.insert(jobId, text);
|
|
|
|
m_jobStatus.insert(jobId, QString());
|
2011-03-28 04:26:47 +02:00
|
|
|
m_jobState.insert(jobId, isWarning ? JobWarning : JobSystem);
|
2011-02-02 22:56:45 +01:00
|
|
|
m_jobLogFile.insert(jobId, QStringList());
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
}
|