1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
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_Progress.h"
26 #define MAX_DISPLAY_ITEMS 48
28 ProgressModel::ProgressModel(void)
30 m_iconRunning(":/icons/media_play.png"),
31 m_iconPaused(":/icons/control_pause_blue.png"),
32 m_iconComplete(":/icons/tick.png"),
33 m_iconFailed(":/icons/exclamation.png"),
34 m_iconSystem(":/icons/computer.png"),
35 m_iconWarning(":/icons/error.png"),
36 m_iconPerformance(":/icons/clock.png"),
37 m_iconSkipped(":/icons/step_over.png")
41 ProgressModel::~ProgressModel(void)
45 int ProgressModel::columnCount(const QModelIndex &parent) const
50 int ProgressModel::rowCount(const QModelIndex &parent) const
52 return m_jobList.count();
55 QVariant ProgressModel::data(const QModelIndex &index, int role) const
57 if(index.row() >= 0 && index.row() < m_jobList.count())
59 if(role == Qt::DisplayRole)
61 switch(index.column())
64 return m_jobName.value(m_jobList.at(index.row()));
67 return m_jobStatus.value(m_jobList.at(index.row()));
74 else if(role == Qt::DecorationRole && index.column() == 0)
76 switch(m_jobState.value(m_jobList.at(index.row())))
85 return m_iconComplete;
94 return m_iconPerformance;
104 else if(role == Qt::TextAlignmentRole)
106 return (index.column() == 1) ? QVariant(Qt::AlignHCenter | Qt::AlignVCenter) : QVariant();
113 QVariant ProgressModel::headerData(int section, Qt::Orientation orientation, int role) const
115 if(role == Qt::DisplayRole)
117 if(orientation == Qt::Horizontal)
132 if(orientation == Qt::Vertical)
134 return QString::number(section + 1);
141 void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState)
143 if(m_jobIdentifiers.contains(jobId))
148 while(m_jobList.count() >= MAX_DISPLAY_ITEMS)
150 beginRemoveRows(QModelIndex(), 0, 0);
151 m_jobListHidden.append(m_jobList.takeFirst());
152 m_jobIndexCache.clear();
156 int newIndex = m_jobList.count();
157 beginInsertRows(QModelIndex(), newIndex, newIndex);
159 m_jobList.append(jobId);
160 m_jobName.insert(jobId, jobName);
161 m_jobStatus.insert(jobId, jobInitialStatus);
162 m_jobState.insert(jobId, jobInitialState);
163 m_jobLogFile.insert(jobId, QStringList());
164 m_jobIdentifiers.insert(jobId);
169 void ProgressModel::updateJob(const QUuid &jobId, const QString &newStatus, int newState)
171 if(!m_jobIdentifiers.contains(jobId))
176 if(!newStatus.isEmpty()) m_jobStatus.insert(jobId, newStatus);
177 if(newState >= 0) m_jobState.insert(jobId, newState);
179 const int row = m_jobIndexCache.value(jobId, -1);
183 emit dataChanged(index(row, 0), index(row, 1));
187 const int tmp = m_jobList.indexOf(jobId);
190 m_jobIndexCache.insert(jobId, tmp);
191 emit dataChanged(index(tmp, 0), index(tmp, 1));
196 void ProgressModel::appendToLog(const QUuid &jobId, const QString &line)
198 if(m_jobIdentifiers.contains(jobId))
200 m_jobLogFile[jobId].append(line.split('\n'));
204 const QStringList &ProgressModel::getLogFile(const QModelIndex &index)
206 if(index.row() < m_jobList.count())
208 QUuid id = m_jobList.at(index.row());
209 return m_jobLogFile[id];
212 return *(reinterpret_cast<QStringList*>(NULL));
215 const QUuid &ProgressModel::getJobId(const QModelIndex &index)
217 if(index.row() < m_jobList.count())
219 return m_jobList.at(index.row());
222 return *(reinterpret_cast<QUuid*>(NULL));
225 const ProgressModel::JobState ProgressModel::getJobState(const QModelIndex &index) const
227 if(index.row() < m_jobList.count())
229 return static_cast<JobState>(m_jobState.value(m_jobList.at(index.row()), -1));
232 return static_cast<JobState>(NULL);
235 void ProgressModel::addSystemMessage(const QString &text, int type)
237 const QUuid &jobId = QUuid::createUuid();
239 if(m_jobIdentifiers.contains(jobId))
244 while(m_jobList.count() >= MAX_DISPLAY_ITEMS)
246 beginRemoveRows(QModelIndex(), 0, 0);
247 m_jobListHidden.append(m_jobList.takeFirst());
248 m_jobIndexCache.clear();
252 int newIndex = m_jobList.count();
253 JobState jobState = JobState(-1);
258 jobState = JobWarning;
260 case SysMsg_Performance:
261 jobState = JobPerformance;
264 jobState = JobSystem;
268 beginInsertRows(QModelIndex(), newIndex, newIndex);
270 m_jobList.append(jobId);
271 m_jobName.insert(jobId, text);
272 m_jobStatus.insert(jobId, QString());
273 m_jobState.insert(jobId, jobState);
274 m_jobLogFile.insert(jobId, QStringList());
275 m_jobIdentifiers.insert(jobId);
280 void ProgressModel::restoreHiddenItems(void)
282 if(!m_jobListHidden.isEmpty())
285 while(!m_jobListHidden.isEmpty())
287 m_jobList.prepend(m_jobListHidden.takeLast());
289 m_jobIndexCache.clear();