Changeset View
Changeset View
Standalone View
Standalone View
libkcups/JobModel.cpp
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Line(s) | 186 | for (int i = 0; i < jobs.size(); ++i) { | |||
---|---|---|---|---|---|
188 | if (job.state() == IPP_JOB_PROCESSING) { | 188 | if (job.state() == IPP_JOB_PROCESSING) { | ||
189 | m_processingJob = job.name(); | 189 | m_processingJob = job.name(); | ||
190 | } | 190 | } | ||
191 | 191 | | |||
192 | // try to find the job row | 192 | // try to find the job row | ||
193 | const int job_row = jobRow(job.id()); | 193 | const int job_row = jobRow(job.id()); | ||
194 | if (job_row == -1) { | 194 | if (job_row == -1) { | ||
195 | // not found, insert new one | 195 | // not found, insert new one | ||
196 | insertJob(i, job); | 196 | appendJob(job); | ||
197 | } else { | 197 | } else { | ||
198 | // update the job | 198 | // update the job | ||
199 | updateJob(job_row, job); | 199 | updateJob(job_row, job); | ||
200 | | ||||
201 | if (job_row != i) { | | |||
202 | // found at wrong position | | |||
203 | // take it and insert on the right position | | |||
204 | const QList<QStandardItem *> row = takeRow(job_row); | | |||
205 | insertRow(i, row); | | |||
206 | } | | |||
207 | } | 200 | } | ||
208 | } | 201 | } | ||
209 | 202 | | |||
210 | // remove old printers | 203 | // remove old printers | ||
211 | // The above code starts from 0 and make sure | 204 | // The above code starts from 0 and make sure | ||
212 | // dest == modelIndex(x) and if it's not the | 205 | // dest == modelIndex(x) and if it's not the | ||
213 | // case it either inserts or moves it. | 206 | // case it either inserts or moves it. | ||
214 | // so any item > num_jobs can be safely deleted | 207 | // so any item > num_jobs can be safely deleted | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 259 | { | |||
276 | Q_UNUSED(jobStateReasons) | 269 | Q_UNUSED(jobStateReasons) | ||
277 | Q_UNUSED(jobName) | 270 | Q_UNUSED(jobName) | ||
278 | Q_UNUSED(jobImpressionsCompleted) | 271 | Q_UNUSED(jobImpressionsCompleted) | ||
279 | 272 | | |||
280 | // We grab all jobs again | 273 | // We grab all jobs again | ||
281 | getJobs(); | 274 | getJobs(); | ||
282 | } | 275 | } | ||
283 | 276 | | |||
284 | void JobModel::insertJob(int pos, const KCupsJob &job) | 277 | void JobModel::appendJob(const KCupsJob &job) | ||
285 | { | 278 | { | ||
286 | // insert the first column which has the job state and id | 279 | // insert the first column which has the job state and id | ||
287 | QList<QStandardItem*> row; | 280 | QList<QStandardItem*> row; | ||
288 | ipp_jstate_e jobState = job.state(); | 281 | ipp_jstate_e jobState = job.state(); | ||
289 | auto statusItem = new QStandardItem(jobStatus(jobState)); | 282 | auto statusItem = new QStandardItem(jobStatus(jobState)); | ||
290 | statusItem->setData(jobState, RoleJobState); | 283 | statusItem->setData(jobState, RoleJobState); | ||
291 | statusItem->setData(job.id(), RoleJobId); | 284 | statusItem->setData(job.id(), RoleJobId); | ||
292 | statusItem->setData(job.name(), RoleJobName); | 285 | statusItem->setData(job.name(), RoleJobName); | ||
Show All 21 Lines | |||||
314 | 307 | | |||
315 | row << statusItem; | 308 | row << statusItem; | ||
316 | for (int i = ColName; i < LastColumn; i++) { | 309 | for (int i = ColName; i < LastColumn; i++) { | ||
317 | // adds all Items to the model | 310 | // adds all Items to the model | ||
318 | row << new QStandardItem; | 311 | row << new QStandardItem; | ||
319 | } | 312 | } | ||
320 | 313 | | |||
321 | // insert the whole row | 314 | // insert the whole row | ||
315 | const int pos = rowCount(); | ||||
322 | insertRow(pos, row); | 316 | insertRow(pos, row); | ||
323 | 317 | | |||
324 | // update the items | 318 | // update the items | ||
325 | updateJob(pos, job); | 319 | updateJob(pos, job); | ||
326 | } | 320 | } | ||
327 | 321 | | |||
328 | void JobModel::updateJob(int pos, const KCupsJob &job) | 322 | void JobModel::updateJob(int pos, const KCupsJob &job) | ||
329 | { | 323 | { | ||
▲ Show 20 Lines • Show All 312 Lines • Show Last 20 Lines |