Changeset View
Changeset View
Standalone View
Standalone View
libkcups/JobModel.cpp
Show First 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 152 | const static QStringList attrs({ | |||
---|---|---|---|---|---|
169 | KCUPS_JOB_PRINTER_STATE_MESSAGE, | 169 | KCUPS_JOB_PRINTER_STATE_MESSAGE, | ||
170 | KCUPS_JOB_PRESERVED | 170 | KCUPS_JOB_PRESERVED | ||
171 | }); | 171 | }); | ||
172 | m_jobRequest->getJobs(m_destName, false, m_whichjobs, attrs); | 172 | m_jobRequest->getJobs(m_destName, false, m_whichjobs, attrs); | ||
173 | 173 | | |||
174 | m_processingJob.clear(); | 174 | m_processingJob.clear(); | ||
175 | } | 175 | } | ||
176 | 176 | | |||
177 | static KCupsJobs sanitizeJobs(KCupsJobs jobs) | ||||
178 | { | ||||
179 | // For some reason sometimes cups has broken job queues with jobs with duplicated id | ||||
180 | // our model doesn't like that at all so sanitize the job list before processing it | ||||
181 | QVector<int> seenIds; | ||||
182 | int i = 0; | ||||
183 | while (i < jobs.count()) { | ||||
184 | const int jobId = jobs.at(i).id(); | ||||
185 | if (seenIds.contains(jobId)) { | ||||
186 | qCWarning(LIBKCUPS) << "Found job with duplicated id" << jobId; | ||||
187 | jobs.removeAt(i); | ||||
188 | } else { | ||||
189 | seenIds << jobId; | ||||
190 | ++i; | ||||
191 | } | ||||
192 | } | ||||
193 | return jobs; | ||||
194 | } | ||||
195 | | ||||
177 | void JobModel::getJobFinished(KCupsRequest *request) | 196 | void JobModel::getJobFinished(KCupsRequest *request) | ||
178 | { | 197 | { | ||
179 | if (request) { | 198 | if (request) { | ||
180 | if (request->hasError()) { | 199 | if (request->hasError()) { | ||
181 | // clear the model after so that the proper widget can be shown | 200 | // clear the model after so that the proper widget can be shown | ||
182 | clear(); | 201 | clear(); | ||
183 | } else { | 202 | } else { | ||
184 | const KCupsJobs jobs = request->jobs(); | 203 | const KCupsJobs jobs = sanitizeJobs(request->jobs()); | ||
185 | qCDebug(LIBKCUPS) << jobs.size(); | 204 | qCDebug(LIBKCUPS) << jobs.size(); | ||
186 | for (int i = 0; i < jobs.size(); ++i) { | 205 | for (int i = 0; i < jobs.size(); ++i) { | ||
187 | const KCupsJob job = jobs.at(i); | 206 | const KCupsJob job = jobs.at(i); | ||
188 | if (job.state() == IPP_JOB_PROCESSING) { | 207 | if (job.state() == IPP_JOB_PROCESSING) { | ||
189 | m_processingJob = job.name(); | 208 | m_processingJob = job.name(); | ||
190 | } | 209 | } | ||
191 | 210 | | |||
192 | // try to find the job row | 211 | // try to find the job row | ||
Show All 9 Lines | 220 | if (job_row != i) { | |||
202 | // found at wrong position | 221 | // found at wrong position | ||
203 | // take it and insert on the right position | 222 | // take it and insert on the right position | ||
204 | const QList<QStandardItem *> row = takeRow(job_row); | 223 | const QList<QStandardItem *> row = takeRow(job_row); | ||
205 | insertRow(i, row); | 224 | insertRow(i, row); | ||
206 | } | 225 | } | ||
207 | } | 226 | } | ||
208 | } | 227 | } | ||
209 | 228 | | |||
210 | // remove old printers | 229 | // remove old jobs | ||
211 | // The above code starts from 0 and make sure | 230 | // The above code starts from 0 and make sure | ||
212 | // dest == modelIndex(x) and if it's not the | 231 | // dest == modelIndex(x) and if it's not the | ||
213 | // case it either inserts or moves it. | 232 | // case it either inserts or moves it. | ||
214 | // so any item > num_jobs can be safely deleted | 233 | // so any item > num_jobs can be safely deleted | ||
215 | while (rowCount() > jobs.size()) { | 234 | while (rowCount() > jobs.size()) { | ||
216 | removeRow(rowCount() - 1); | 235 | removeRow(rowCount() - 1); | ||
217 | } | 236 | } | ||
218 | } | 237 | } | ||
▲ Show 20 Lines • Show All 423 Lines • Show Last 20 Lines |