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")
40 ProgressModel::~ProgressModel(void)
44 int ProgressModel::columnCount(const QModelIndex
&parent
) const
49 int ProgressModel::rowCount(const QModelIndex
&parent
) const
51 return m_jobList
.count();
54 QVariant
ProgressModel::data(const QModelIndex
&index
, int role
) const
56 if(index
.row() >= 0 && index
.row() < m_jobList
.count())
58 if(role
== Qt::DisplayRole
)
60 switch(index
.column())
63 return m_jobName
.value(m_jobList
.at(index
.row()));
66 return m_jobStatus
.value(m_jobList
.at(index
.row()));
73 else if(role
== Qt::DecorationRole
&& index
.column() == 0)
75 switch(m_jobState
.value(m_jobList
.at(index
.row())))
84 return m_iconComplete
;
93 return m_iconPerformance
;
100 else if(role
== Qt::TextAlignmentRole
)
102 return (index
.column() == 1) ? QVariant(Qt::AlignHCenter
| Qt::AlignVCenter
) : QVariant();
109 QVariant
ProgressModel::headerData(int section
, Qt::Orientation orientation
, int role
) const
111 if(role
== Qt::DisplayRole
)
113 if(orientation
== Qt::Horizontal
)
128 if(orientation
== Qt::Vertical
)
130 return QString::number(section
+ 1);
137 void ProgressModel::addJob(const QUuid
&jobId
, const QString
&jobName
, const QString
&jobInitialStatus
, int jobInitialState
)
139 if(m_jobIdentifiers
.contains(jobId
))
144 while(m_jobList
.count() >= MAX_DISPLAY_ITEMS
)
146 beginRemoveRows(QModelIndex(), 0, 0);
147 m_jobListHidden
.append(m_jobList
.takeFirst());
148 m_jobIndexCache
.clear();
152 int newIndex
= m_jobList
.count();
153 beginInsertRows(QModelIndex(), newIndex
, newIndex
);
155 m_jobList
.append(jobId
);
156 m_jobName
.insert(jobId
, jobName
);
157 m_jobStatus
.insert(jobId
, jobInitialStatus
);
158 m_jobState
.insert(jobId
, jobInitialState
);
159 m_jobLogFile
.insert(jobId
, QStringList());
160 m_jobIdentifiers
.insert(jobId
);
165 void ProgressModel::updateJob(const QUuid
&jobId
, const QString
&newStatus
, int newState
)
167 if(!m_jobIdentifiers
.contains(jobId
))
172 if(!newStatus
.isEmpty()) m_jobStatus
.insert(jobId
, newStatus
);
173 if(newState
>= 0) m_jobState
.insert(jobId
, newState
);
175 const int row
= m_jobIndexCache
.value(jobId
, -1);
179 emit
dataChanged(index(row
, 0), index(row
, 1));
183 const int tmp
= m_jobList
.indexOf(jobId
);
186 m_jobIndexCache
.insert(jobId
, tmp
);
187 emit
dataChanged(index(tmp
, 0), index(tmp
, 1));
192 void ProgressModel::appendToLog(const QUuid
&jobId
, const QString
&line
)
194 if(m_jobIdentifiers
.contains(jobId
))
196 m_jobLogFile
[jobId
].append(line
.split('\n'));
200 const QStringList
&ProgressModel::getLogFile(const QModelIndex
&index
)
202 if(index
.row() < m_jobList
.count())
204 QUuid id
= m_jobList
.at(index
.row());
205 return m_jobLogFile
[id
];
208 return *(reinterpret_cast<QStringList
*>(NULL
));
211 const QUuid
&ProgressModel::getJobId(const QModelIndex
&index
)
213 if(index
.row() < m_jobList
.count())
215 return m_jobList
.at(index
.row());
218 return *(reinterpret_cast<QUuid
*>(NULL
));
221 void ProgressModel::addSystemMessage(const QString
&text
, int type
)
223 const QUuid
&jobId
= QUuid::createUuid();
225 if(m_jobIdentifiers
.contains(jobId
))
230 while(m_jobList
.count() >= MAX_DISPLAY_ITEMS
)
232 beginRemoveRows(QModelIndex(), 0, 0);
233 m_jobListHidden
.append(m_jobList
.takeFirst());
234 m_jobIndexCache
.clear();
238 int newIndex
= m_jobList
.count();
239 JobState jobState
= JobState(-1);
244 jobState
= JobWarning
;
246 case SysMsg_Performance
:
247 jobState
= JobPerformance
;
250 jobState
= JobSystem
;
254 beginInsertRows(QModelIndex(), newIndex
, newIndex
);
256 m_jobList
.append(jobId
);
257 m_jobName
.insert(jobId
, text
);
258 m_jobStatus
.insert(jobId
, QString());
259 m_jobState
.insert(jobId
, jobState
);
260 m_jobLogFile
.insert(jobId
, QStringList());
261 m_jobIdentifiers
.insert(jobId
);
266 void ProgressModel::restoreHiddenItems(void)
268 if(!m_jobListHidden
.isEmpty())
271 while(!m_jobListHidden
.isEmpty())
273 m_jobList
.prepend(m_jobListHidden
.takeLast());
275 m_jobIndexCache
.clear();