OSDN Git Service

More detailed error output when process failed to create + use UUID's to index jobs.
[lamexp/LameXP.git] / src / Model_Progress.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2010 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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Model_Progress.h"
23
24 #include <QUuid>
25
26 ProgressModel::ProgressModel(void) :
27         m_iconRunning(":/icons/media_play.png"),
28         m_iconPaused(":/icons/control_pause_blue.png"),
29         m_iconComplete(":/icons/tick.png"),
30         m_iconFailed(":/icons/exclamation.png")
31 {
32 }
33
34 ProgressModel::~ProgressModel(void)
35 {
36 }
37
38 int ProgressModel::columnCount(const QModelIndex &parent) const
39 {
40         return 2;
41 }
42
43 int ProgressModel::rowCount(const QModelIndex &parent) const
44 {
45         return m_jobList.count();
46 }
47
48 QVariant ProgressModel::data(const QModelIndex &index, int role) const
49 {
50         if(index.row() >= 0 && index.row() < m_jobList.count())
51         {
52                 if(role == Qt::DisplayRole)
53                 {
54                         switch(index.column())
55                         {
56                         case 0:
57                                 return m_jobName.value(m_jobList.at(index.row()));
58                                 break;
59                         case 1:
60                                 return m_jobStatus.value(m_jobList.at(index.row()));
61                                 break;
62                         default:
63                                 return QVariant();
64                                 break;
65                         }
66                 }
67                 else if(role == Qt::DecorationRole && index.column() == 0)
68                 {
69                         switch(m_jobState.value(m_jobList.at(index.row())))
70                         {
71                         case JobRunning:
72                                 return m_iconRunning;
73                                 break;
74                         case JobPaused:
75                                 return m_iconPaused;
76                                 break;
77                         case JobComplete:
78                                 return m_iconComplete;
79                                 break;
80                         default:
81                                 return m_iconFailed;
82                                 break;
83                         }
84                 }
85         }
86         
87         return QVariant();
88 }
89
90 QVariant ProgressModel::headerData(int section, Qt::Orientation orientation, int role) const
91 {
92         if(role == Qt::DisplayRole)
93         {
94                 if(orientation == Qt::Horizontal)
95                 {
96                         switch(section)
97                         {
98                         case 0:
99                                 return "Job";
100                                 break;
101                         case 1:
102                                 return "Status";
103                                 break;
104                         default:
105                                 return QVariant();
106                                 break;
107                         }
108                 }
109                 if(orientation == Qt::Vertical)
110                 {
111                         return QString::number(section + 1);
112                 }
113         }
114
115         return QVariant();
116 }
117
118 void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState)
119 {
120         if(m_jobList.contains(jobId))
121         {
122                 return;
123         }
124
125         beginResetModel();
126         m_jobList.append(jobId);
127         m_jobName.insert(jobId, jobName);
128         m_jobStatus.insert(jobId, jobInitialStatus);
129         m_jobState.insert(jobId, jobInitialState);
130         endResetModel();
131 }
132
133 void ProgressModel::updateJob(const QUuid &jobId, const QString &newStatus, int newState)
134 {
135         if(!m_jobList.contains(jobId))
136         {
137                 return;
138         }
139
140         beginResetModel();
141         if(!newStatus.isEmpty()) m_jobStatus.insert(jobId, newStatus);
142         if(newState >= 0) m_jobState.insert(jobId, newState);
143         endResetModel();
144 }