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")
36 ProgressModel::~ProgressModel(void)
40 int ProgressModel::columnCount(const QModelIndex
&parent
) const
45 int ProgressModel::rowCount(const QModelIndex
&parent
) const
47 return m_jobList
.count();
50 QVariant
ProgressModel::data(const QModelIndex
&index
, int role
) const
52 if(index
.row() >= 0 && index
.row() < m_jobList
.count())
54 if(role
== Qt::DisplayRole
)
56 switch(index
.column())
59 return m_jobName
.value(m_jobList
.at(index
.row()));
62 return m_jobStatus
.value(m_jobList
.at(index
.row()));
69 else if(role
== Qt::DecorationRole
&& index
.column() == 0)
71 switch(m_jobState
.value(m_jobList
.at(index
.row())))
80 return m_iconComplete
;
90 else if(role
== Qt::TextAlignmentRole
)
92 return (index
.column() == 1) ? QVariant(Qt::AlignHCenter
| Qt::AlignVCenter
) : QVariant();
99 QVariant
ProgressModel::headerData(int section
, Qt::Orientation orientation
, int role
) const
101 if(role
== Qt::DisplayRole
)
103 if(orientation
== Qt::Horizontal
)
118 if(orientation
== Qt::Vertical
)
120 return QString::number(section
+ 1);
127 void ProgressModel::addJob(const QUuid
&jobId
, const QString
&jobName
, const QString
&jobInitialStatus
, int jobInitialState
)
129 if(m_jobList
.contains(jobId
))
134 int newIndex
= m_jobList
.count();
135 beginInsertRows(QModelIndex(), newIndex
, newIndex
);
137 m_jobList
.append(jobId
);
138 m_jobName
.insert(jobId
, jobName
);
139 m_jobStatus
.insert(jobId
, jobInitialStatus
);
140 m_jobState
.insert(jobId
, jobInitialState
);
141 m_jobLogFile
.insert(jobId
, QStringList());
146 void ProgressModel::updateJob(const QUuid
&jobId
, const QString
&newStatus
, int newState
)
148 int row
= m_jobList
.indexOf(jobId
);
155 if(!newStatus
.isEmpty()) m_jobStatus
.insert(jobId
, newStatus
);
156 if(newState
>= 0) m_jobState
.insert(jobId
, newState
);
158 emit
dataChanged(index(row
, 0), index(row
, 1));
161 void ProgressModel::appendToLog(const QUuid
&jobId
, const QString
&line
)
163 if(m_jobList
.contains(jobId
))
165 m_jobLogFile
[jobId
].append(line
.split('\n'));
169 const QStringList
&ProgressModel::getLogFile(const QModelIndex
&index
)
171 if(index
.row() < m_jobList
.count())
173 QUuid id
= m_jobList
.at(index
.row());
174 return m_jobLogFile
[id
];
177 return *(reinterpret_cast<QStringList
*>(NULL
));
180 void ProgressModel::addSystemMessage(const QString
&text
)
182 const QUuid
&jobId
= QUuid::createUuid();
184 if(m_jobList
.contains(jobId
))
189 int newIndex
= m_jobList
.count();
190 beginInsertRows(QModelIndex(), newIndex
, newIndex
);
192 m_jobList
.append(jobId
);
193 m_jobName
.insert(jobId
, text
);
194 m_jobStatus
.insert(jobId
, QString());
195 m_jobState
.insert(jobId
, JobSystem
);
196 m_jobLogFile
.insert(jobId
, QStringList());