1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 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 ProgressModel::ProgressModel(void)
28 m_iconRunning(":/icons/media_play.png"),
29 m_iconPaused(":/icons/control_pause_blue.png"),
30 m_iconComplete(":/icons/tick.png"),
31 m_iconFailed(":/icons/exclamation.png"),
32 m_iconSystem(":/icons/computer.png"),
33 m_iconWarning(":/icons/error.png")
37 ProgressModel::~ProgressModel(void)
41 int ProgressModel::columnCount(const QModelIndex &parent) const
46 int ProgressModel::rowCount(const QModelIndex &parent) const
48 return m_jobList.count();
51 QVariant ProgressModel::data(const QModelIndex &index, int role) const
53 if(index.row() >= 0 && index.row() < m_jobList.count())
55 if(role == Qt::DisplayRole)
57 switch(index.column())
60 return m_jobName.value(m_jobList.at(index.row()));
63 return m_jobStatus.value(m_jobList.at(index.row()));
70 else if(role == Qt::DecorationRole && index.column() == 0)
72 switch(m_jobState.value(m_jobList.at(index.row())))
81 return m_iconComplete;
94 else if(role == Qt::TextAlignmentRole)
96 return (index.column() == 1) ? QVariant(Qt::AlignHCenter | Qt::AlignVCenter) : QVariant();
103 QVariant ProgressModel::headerData(int section, Qt::Orientation orientation, int role) const
105 if(role == Qt::DisplayRole)
107 if(orientation == Qt::Horizontal)
122 if(orientation == Qt::Vertical)
124 return QString::number(section + 1);
131 void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState)
133 if(m_jobList.contains(jobId))
138 int newIndex = m_jobList.count();
139 beginInsertRows(QModelIndex(), newIndex, newIndex);
141 m_jobList.append(jobId);
142 m_jobName.insert(jobId, jobName);
143 m_jobStatus.insert(jobId, jobInitialStatus);
144 m_jobState.insert(jobId, jobInitialState);
145 m_jobLogFile.insert(jobId, QStringList());
150 void ProgressModel::updateJob(const QUuid &jobId, const QString &newStatus, int newState)
152 int row = m_jobList.indexOf(jobId);
159 if(!newStatus.isEmpty()) m_jobStatus.insert(jobId, newStatus);
160 if(newState >= 0) m_jobState.insert(jobId, newState);
162 emit dataChanged(index(row, 0), index(row, 1));
165 void ProgressModel::appendToLog(const QUuid &jobId, const QString &line)
167 if(m_jobList.contains(jobId))
169 m_jobLogFile[jobId].append(line.split('\n'));
173 const QStringList &ProgressModel::getLogFile(const QModelIndex &index)
175 if(index.row() < m_jobList.count())
177 QUuid id = m_jobList.at(index.row());
178 return m_jobLogFile[id];
181 return *(reinterpret_cast<QStringList*>(NULL));
184 const QUuid &ProgressModel::getJobId(const QModelIndex &index)
186 if(index.row() < m_jobList.count())
188 return m_jobList.at(index.row());
191 return *(reinterpret_cast<QUuid*>(NULL));
194 void ProgressModel::addSystemMessage(const QString &text, bool isWarning)
196 const QUuid &jobId = QUuid::createUuid();
198 if(m_jobList.contains(jobId))
203 int newIndex = m_jobList.count();
204 beginInsertRows(QModelIndex(), newIndex, newIndex);
206 m_jobList.append(jobId);
207 m_jobName.insert(jobId, text);
208 m_jobStatus.insert(jobId, QString());
209 m_jobState.insert(jobId, isWarning ? JobWarning : JobSystem);
210 m_jobLogFile.insert(jobId, QStringList());