1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 Model for listing Jobs, typically in a QTreeView.
4 Copyright : (C) 2006 by Gary Cramblitt <garycramblitt@comcast.net>
6 Original author: Gary Cramblitt <garycramblitt@comcast.net>
7 Current Maintainer: Gary Cramblitt <garycramblitt@comcast.net>
8 ******************************************************************************/
10 /******************************************************************************
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 *******************************************************************************/
26 // JobInfoListModel includes.
27 #include "jobinfolistmodel.h"
28 #include "jobinfolistmodel.moc"
40 // ----------------------------------------------------------------------------
42 JobInfoListModel::JobInfoListModel(JobInfoList jobs
, QObject
*parent
) :
43 QAbstractListModel(parent
),
48 int JobInfoListModel::rowCount(const QModelIndex
&parent
) const
50 if (!parent
.isValid())
51 return m_jobs
.count();
56 int JobInfoListModel::columnCount(const QModelIndex
&parent
) const
62 QModelIndex
JobInfoListModel::index(int row
, int column
, const QModelIndex
&parent
) const
64 if (!parent
.isValid())
65 return createIndex(row
, column
, 0);
70 QModelIndex
JobInfoListModel::parent(const QModelIndex
& index
) const
76 QVariant
JobInfoListModel::data(const QModelIndex
&index
, int role
) const
81 if (index
.row() < 0 || index
.row() >= m_jobs
.count())
84 if (index
.column() < 0 || index
.column() >= 8)
87 if (role
== Qt::DisplayRole
)
88 return dataColumn(m_jobs
.at(index
.row()), index
.column());
93 QVariant
JobInfoListModel::dataColumn(const JobInfo
& job
, int column
) const
97 case 0: return job
.jobNum
; break;
98 case 1: return job
.applicationName
; break;
99 case 2: return priorityToStr(job
.priority
); break;
100 case 3: return job
.talkerID
; break;
101 case 4: return stateToStr(job
.state
); break;
102 case 5: return job
.sentenceNum
; break;
103 case 6: return job
.sentenceCount
; break;
108 Qt::ItemFlags
JobInfoListModel::flags(const QModelIndex
&index
) const
110 if (!index
.isValid())
111 return Qt::ItemIsEnabled
;
113 return Qt::ItemIsEnabled
| Qt::ItemIsSelectable
;
116 QVariant
JobInfoListModel::headerData(int section
, Qt::Orientation orientation
, int role
) const
118 if (orientation
== Qt::Horizontal
&& role
== Qt::DisplayRole
)
121 case 0: return i18n("Job Num");
122 case 1: return i18n("Owner");
123 case 2: return i18n("Priority");
124 case 3: return i18n("Talker ID");
125 case 4: return i18n("State");
126 case 5: return i18n("Position");
127 case 6: return i18n("Sentences");
133 bool JobInfoListModel::removeRow(int row
, const QModelIndex
& parent
)
135 beginRemoveRows(parent
, row
, row
);
136 m_jobs
.removeAt(row
);
141 void JobInfoListModel::setDatastore(JobInfoList jobs
)
147 JobInfo
JobInfoListModel::getRow(int row
) const
149 if (row
< 0 || row
>= rowCount()) return JobInfo();
153 bool JobInfoListModel::appendRow(JobInfo
& job
)
155 beginInsertRows(QModelIndex(), m_jobs
.count(), m_jobs
.count());
161 bool JobInfoListModel::updateRow(int row
, JobInfo
& job
)
163 m_jobs
.replace(row
, job
);
164 emit
dataChanged(index(row
, 0, QModelIndex()), index(row
, columnCount()-1, QModelIndex()));
168 bool JobInfoListModel::swap(int i
, int j
)
171 emit
dataChanged(index(i
, 0, QModelIndex()), index(j
, columnCount()-1, QModelIndex()));
175 void JobInfoListModel::clear()
181 QModelIndex
JobInfoListModel::jobNumToIndex(int jobNum
)
183 for (int row
= 0; row
< m_jobs
.count(); ++row
)
184 if (getRow(row
).jobNum
== jobNum
)
185 return createIndex(row
, 0);
186 return QModelIndex();
190 * Convert a KTTSD job state integer into a display string.
191 * @param state KTTSD job state
192 * @return Display string for the state.
194 QString
JobInfoListModel::stateToStr(int state
) const
198 case KSpeech::jsQueued
: return i18n("Queued");
199 case KSpeech::jsFiltering
: return i18n("Filtering");
200 case KSpeech::jsSpeakable
: return i18n("Waiting");
201 case KSpeech::jsSpeaking
: return i18n("Speaking");
202 case KSpeech::jsPaused
: return i18n("Paused");
203 case KSpeech::jsInterrupted
: return i18n("Interrupted");
204 case KSpeech::jsFinished
: return i18n("Finished");
205 default: return i18n("Unknown");
210 * Convert a KTTSD job priority into a display string.
211 * @param priority KTTSD job priority.
212 * @return Display string for priority.
214 QString
JobInfoListModel::priorityToStr(int priority
) const
218 case KSpeech::jpAll
: return i18n("All");
219 case KSpeech::jpScreenReaderOutput
: return i18n("Screen Reader");
220 case KSpeech::jpWarning
: return i18n("Warning");
221 case KSpeech::jpMessage
: return i18n("Message");
222 case KSpeech::jpText
: return i18n("Text");
223 default: return i18n("Unknown");