1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "model_jobList.h"
23 #include "thread_encode.h"
27 JobListModel::JobListModel(void)
31 JobListModel::~JobListModel(void)
35 ///////////////////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////////////////
39 int JobListModel::columnCount(const QModelIndex &parent) const
44 int JobListModel::rowCount(const QModelIndex &parent) const
46 return m_jobs.count();
49 QVariant JobListModel::headerData(int section, Qt::Orientation orientation, int role) const
51 if((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
56 return QVariant::fromValue<QString>(tr("Job"));
59 return QVariant::fromValue<QString>(tr("Status"));
62 return QVariant::fromValue<QString>(tr("Progress"));
73 QModelIndex JobListModel::index(int row, int column, const QModelIndex &parent) const
75 return createIndex(row, column, NULL);
78 QModelIndex JobListModel::parent(const QModelIndex &index) const
83 QVariant JobListModel::data(const QModelIndex &index, int role) const
85 if(role == Qt::DisplayRole)
87 if(index.row() >= 0 && index.row() < m_jobs.count())
89 switch(index.column())
92 return m_jobs.at(index.row()).toString();
95 switch(m_status.value(m_jobs.at(index.row())))
97 case EncodeThread::JobStatus_Enqueued:
98 return QVariant::fromValue<QString>(tr("Enqueued."));
100 case EncodeThread::JobStatus_Starting:
101 return QVariant::fromValue<QString>(tr("Starting..."));
103 case EncodeThread::JobStatus_Indexing:
104 return QVariant::fromValue<QString>(tr("Indexing..."));
106 case EncodeThread::JobStatus_Running:
107 return QVariant::fromValue<QString>(tr("Running..."));
109 case EncodeThread::JobStatus_Completed:
110 return QVariant::fromValue<QString>(tr("Completed."));
112 case EncodeThread::JobStatus_Failed:
113 return QVariant::fromValue<QString>(tr("Failed!"));
115 case EncodeThread::JobStatus_Aborted:
116 return QVariant::fromValue<QString>(tr("Aborted!"));
119 return QVariant::fromValue<QString>(tr("(Unknown)"));
124 return QString().sprintf("%d%%", m_progress.value(m_jobs.at(index.row())));
132 else if(role == Qt::DecorationRole)
134 if(index.row() >= 0 && index.row() < m_jobs.count() && index.column() == 0)
136 switch(m_status.value(m_jobs.at(index.row())))
138 case EncodeThread::JobStatus_Enqueued:
139 return QIcon(":/buttons/clock_pause.png");
141 case EncodeThread::JobStatus_Starting:
142 return QIcon(":/buttons/lightning.png");
144 case EncodeThread::JobStatus_Indexing:
145 return QIcon(":/buttons/find.png");
147 case EncodeThread::JobStatus_Running:
148 return QIcon(":/buttons/play.png");
150 case EncodeThread::JobStatus_Completed:
151 return QIcon(":/buttons/accept.png");
153 case EncodeThread::JobStatus_Failed:
154 return QIcon(":/buttons/exclamation.png");
156 case EncodeThread::JobStatus_Aborted:
157 return QIcon(":/buttons/error.png");
169 ///////////////////////////////////////////////////////////////////////////////
171 ///////////////////////////////////////////////////////////////////////////////
173 bool JobListModel::insertJob(EncodeThread *thread)
175 QUuid id = thread->getId();
176 LogFileModel *logFile = NULL;
178 if(m_jobs.contains(id))
183 beginInsertRows(QModelIndex(), m_jobs.count(), m_jobs.count());
185 m_status.insert(id, EncodeThread::JobStatus_Enqueued);
186 m_progress.insert(id, 0);
187 m_threads.insert(id, thread);
188 m_logFile.insert(id, (logFile = new LogFileModel));
191 connect(thread, SIGNAL(statusChanged(QUuid, EncodeThread::JobStatus)), this, SLOT(updateStatus(QUuid, EncodeThread::JobStatus)), Qt::QueuedConnection);
192 connect(thread, SIGNAL(progressChanged(QUuid, unsigned int)), this, SLOT(updateProgress(QUuid, unsigned int)), Qt::QueuedConnection);
193 connect(thread, SIGNAL(messageLogged(QUuid, QString)), logFile, SLOT(addLogMessage(QUuid, QString)), Qt::QueuedConnection);
198 LogFileModel *JobListModel::getLogFile(const QModelIndex &index)
200 if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
202 return m_logFile.value(m_jobs.at(index.row()));
206 ///////////////////////////////////////////////////////////////////////////////
208 ///////////////////////////////////////////////////////////////////////////////
210 void JobListModel::updateStatus(const QUuid &jobId, EncodeThread::JobStatus newStatus)
214 if((index = m_jobs.indexOf(jobId)) >= 0)
216 m_status.insert(jobId, newStatus);
217 emit dataChanged(createIndex(index, 0), createIndex(index, 1));
221 void JobListModel::updateProgress(const QUuid &jobId, unsigned int newProgress)
225 if((index = m_jobs.indexOf(jobId)) >= 0)
227 m_progress.insert(jobId, newProgress);
228 emit dataChanged(createIndex(index, 2), createIndex(index, 2));