Show notification in progress window, if multi-threading is activated.
[LameXP.git] / src / Model_Progress.cpp
blob58233c1853888e0f4f52f7b9b35fe5439d0a2cab
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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"
24 #include <QUuid>
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
42 return 2;
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())
58 case 0:
59 return m_jobName.value(m_jobList.at(index.row()));
60 break;
61 case 1:
62 return m_jobStatus.value(m_jobList.at(index.row()));
63 break;
64 default:
65 return QVariant();
66 break;
69 else if(role == Qt::DecorationRole && index.column() == 0)
71 switch(m_jobState.value(m_jobList.at(index.row())))
73 case JobRunning:
74 return m_iconRunning;
75 break;
76 case JobPaused:
77 return m_iconPaused;
78 break;
79 case JobComplete:
80 return m_iconComplete;
81 break;
82 case JobSystem:
83 return m_iconSystem;
84 break;
85 default:
86 return m_iconFailed;
87 break;
90 else if(role == Qt::TextAlignmentRole)
92 return (index.column() == 1) ? QVariant(Qt::AlignHCenter | Qt::AlignVCenter) : QVariant();
96 return QVariant();
99 QVariant ProgressModel::headerData(int section, Qt::Orientation orientation, int role) const
101 if(role == Qt::DisplayRole)
103 if(orientation == Qt::Horizontal)
105 switch(section)
107 case 0:
108 return tr("Job");
109 break;
110 case 1:
111 return tr("Status");
112 break;
113 default:
114 return QVariant();
115 break;
118 if(orientation == Qt::Vertical)
120 return QString::number(section + 1);
124 return QVariant();
127 void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState)
129 if(m_jobList.contains(jobId))
131 return;
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());
143 endInsertRows();
146 void ProgressModel::updateJob(const QUuid &jobId, const QString &newStatus, int newState)
148 int row = m_jobList.indexOf(jobId);
150 if(row < 0)
152 return;
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))
186 return;
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());
198 endInsertRows();