void PrintQueueModel::getJobFinished() { KCupsRequest *request = static_cast<KCupsRequest *>(sender()); if (request) { if (request->hasError()) { // emit error(request->error(), request->serverError(), request->errorMsg()); // clear the model after so that the proper widget can be shown // clear();// TODO remove also in printerModel } else { KCupsJobs jobs = request->jobs(); kDebug() << jobs.size(); for (int i = 0; i < jobs.size(); ++i) { if (jobs.at(i).state() == IPP_JOB_PROCESSING) { m_processingJob = jobs.at(i).name(); } // try to find the job row int job_row = jobRow(jobs.at(i).id()); if (job_row == -1) { // not found, insert new one insertJob(i, jobs.at(i)); } else if (job_row == i) { // update the job updateJob(i, jobs.at(i)); } else { // found at wrong position // take it and insert on the right position QList<QStandardItem *> row = takeRow(job_row); insertRow(i, row); updateJob(i, jobs.at(i)); } } // remove old printers // The above code starts from 0 and make sure // dest == modelIndex(x) and if it's not the // case it either inserts or moves it. // so any item > num_jobs can be safely deleted while (rowCount() > jobs.size()) { removeRow(rowCount() - 1); } } request->deleteLater(); } else { kWarning() << "Should not be called from a non KCupsRequest class" << sender(); } m_jobRequest = 0; }
inline id_type nextWorkUnit() { if (updateJob()) { boost::mutex::scoped_lock lock(m_CacheMutex); m_SharedCache.discardPending(); } return m_SharedWorkUnitItr.next(); }
void updateMask(bool isHidden) { /** * Depending on whether the mask is hidden we should either * update it entirely via the setDirty() call, or we can use a * lightweight approach by directly regenerating the * precalculated static image using * KisRecalculateTransformMaskJob. */ if (!isHidden) { KisRecalculateTransformMaskJob updateJob(m_mask); updateJob.run(); } else { m_mask->recaclulateStaticImage(); QRect updateRect = m_mask->extent(); KisNodeSP parent = m_mask->parent(); if (parent && parent->original()) { updateRect |= parent->original()->defaultBounds()->bounds(); } m_mask->setDirty(updateRect); } }
void StratumClient::processLoginResponce(const QJsonObject& _responceObject, const JsonRpcRequest& _request) { if (_responceObject.contains(JSON_RPC_TAG_NAME_ERROR) && !_responceObject.value(JSON_RPC_TAG_NAME_ERROR).isNull()) { qDebug() << "Login failed. JsonRPC error. Reconnecting..."; reconnect(); return; } if (_responceObject.value(JSON_RPC_TAG_NAME_RESULT).toObject().value(STRATUM_LOGIN_PARAM_NAME_STATUS).toString() != "OK") { qDebug() << "Login failed. Invalid status. Reconnecting..."; reconnect(); return; } m_currentSessionId = _responceObject.value(JSON_RPC_TAG_NAME_RESULT).toObject().value(STRATUM_LOGIN_PARAM_NAME_SESSION_ID).toString(); updateJob(_responceObject.value(JSON_RPC_TAG_NAME_RESULT).toObject().value(STRATUM_LOGIN_PARAM_NAME_JOB).toObject().toVariantMap()); }
void PrintQueueModel::insertJob(int pos, const KCupsJob &job) { // insert the first column which has the job state and id QList<QStandardItem*> row; ipp_jstate_e jobState = job.state(); QStandardItem *statusItem = new QStandardItem(jobStatus(jobState)); statusItem->setData(jobState, JobState); statusItem->setData(job.id(), JobId); row << statusItem; for (int i = ColName; i < LastColumn; i++) { // adds all Items to the model row << new QStandardItem; } // insert the whole row insertRow(pos, row); // update the items updateJob(pos, job); }
void BulkLoad::cancel(quint64 seq) { if (job->seq == seq) { m_cancel = true; } else { QLinkedList<BulkLoadDetails*>::iterator it; for (it = jobList.begin(); it != jobList.end(); ++it) { if ((*it)->seq == seq) { emit updateJob(JobList::BulkLoad, JobList::Cancelled, seq); jobList.erase(it); break; } } } return; }
bool BulkHeaderGroup::BulkHeaderGroupBody() { // belt and braces key.set_data(keymem); data.set_data(datamem); if (m_cancel) { emit updateJob(JobList::BulkHeaderGroup, JobList::Cancelled, job->seq); return false; } emit updateJob(JobList::BulkHeaderGroup, JobList::Running, job->seq); NewsGroup* ng = job->ng; Db* db = ng->getDb(); MultiPartHeader mph; SinglePartHeader sph; HeaderBase* hb = 0; HeaderGroup* headerGroup = 0; HeaderGroup* advancedHeaderGroup = 0; // typedef QMap<QString, QString> HeaderGroupIndexes; // subj, headerGroup index // typedef QMap<QString, HeaderGroup*> HeaderGroups; // headerGroup index, headerGroup * HeaderGroupIndexes headerGroupIndexes; HeaderGroups headerGroups; DBC *dbcp = 0; DBT ckey, cdata; memset(&ckey, 0, sizeof(ckey)); memset(&cdata, 0, sizeof(cdata)); size_t retklen, retdlen; void *retkey = 0, *retdata = 0; int ret, t_ret; void *p = 0; quint64 count=0; cdata.data = (void *) new char[HEADER_BULK_BUFFER_LENGTH]; cdata.ulen = HEADER_BULK_BUFFER_LENGTH; cdata.flags = DB_DBT_USERMEM; ckey.data = (void *) new char[HEADER_BULK_BUFFER_LENGTH]; ckey.ulen = HEADER_BULK_BUFFER_LENGTH; ckey.flags = DB_DBT_USERMEM; /* Acquire a cursor for the database. */ if ((ret = db->get_DB()->cursor(db->get_DB(), NULL, &dbcp, DB_CURSOR_BULK)) != 0) { db->err(ret, "DB->cursor"); char* ptr = 0; ptr = (char*)(ckey.data); Q_DELETE_ARRAY(ptr); ptr = (char*)(cdata.data); Q_DELETE_ARRAY(ptr); return false; } // To save the group records ng->articlesNeedDeleting(false); // Store the data in the database - flush first ... u_int32_t delCount; uchar keymem[KEYMEM_SIZE]; uchar datamem[DATAMEM_SIZE]; Dbt key, data; char* p2 = 0; QByteArray ba; const char *k = 0; key.set_flags(DB_DBT_USERMEM); key.set_data(&keymem); key.set_ulen(KEYMEM_SIZE); data.set_flags(DB_DBT_USERMEM); data.set_ulen(DATAMEM_SIZE); data.set_data(&datamem); QString subj = "MDQuban", from = "MDQuban"; //QString rs1 = "^(.*)(\".*\")"; //QString rs2 = "^(.*)\\s-\\s(.*)$"; //QString rs3 = "^(\\S+.*)\\[.*\\].*(\".*\")"; //QString rs3 = "^(.*)\\s-\\s.*\\s-\\s(.*)$"; QRegExp rx[3]; bool rxPosBack[3]; bool noRegexpGrouping; QString recKey, storeIndex; QString prevSubj = "MDQuban", prevFrom = "MDQuban"; int pos; bool newGroup = false; bool mphFound = false; quint32 grouped = 0, single = 0, numGroups = 0; qint16 stringDiff = -1; bool prevGroup = false; bool advancedPlacement = false; bool skipAdvanced = false; noRegexpGrouping = ng->isThereNoRegexOnGrouping(); if (noRegexpGrouping == false) // need regex for grouping { rx[0].setPattern(ng->getGroupRE1()); rx[1].setPattern(ng->getGroupRE2()); rx[2].setPattern(ng->getGroupRE3()); rxPosBack[0] = ng->getGroupRE1Back(); rxPosBack[1] = ng->getGroupRE2Back(); rxPosBack[2] = ng->getGroupRE3Back(); } ng->getGroupingDb()->truncate(0, &delCount, 0); qDebug() << "Deleted " << delCount << " records from group db"; QMapIterator<QString, QString> it(headerGroupIndexes); QString advancedIndex; for (;;) { /* * Acquire the next set of key/data pairs. This code * does not handle single key/data pairs that won't fit * in a BUFFER_LENGTH size buffer, instead returning * DB_BUFFER_SMALL to our caller. */ if ((ret = dbcp->get(dbcp, &ckey, &cdata, DB_MULTIPLE_KEY | DB_NEXT)) != 0) { if (ret != DB_NOTFOUND) db->err(ret, "DBcursor->get"); break; } for (DB_MULTIPLE_INIT(p, &cdata);;) { DB_MULTIPLE_KEY_NEXT(p, &cdata, retkey, retklen, retdata, retdlen); if (p == NULL) break; if (retdlen){;} // MD TODO compiler .... unused variable recKey = QString::fromLocal8Bit((char*)retkey, retklen); if (*((char *)retdata) == 'm') { MultiPartHeader::getMultiPartHeader((unsigned int)retklen, (char *)retkey, (char *)retdata, &mph); hb = (HeaderBase*)&mph; mphFound = true; } else if (*((char *)retdata) == 's') { SinglePartHeader::getSinglePartHeader((unsigned int)retklen, (char *)retkey, (char *)retdata, &sph); hb = (HeaderBase*)&sph; mphFound = false; } else { // What have we found ????? qDebug() << "Found unexpected identifier for header : " << (char)*((char *)retdata); continue; } ++count; prevSubj = subj; prevFrom = from; subj = hb->getSubj(); from = hb->getFrom(); if (noRegexpGrouping == false) // need regex for grouping { for (int i=0; i<3; ++i) { if (rx[i].isEmpty() == false) { if (rxPosBack[i] == true) // from the back { pos = subj.lastIndexOf(rx[i]); if (pos != -1) subj.truncate(pos); } else // from the front { pos = rx[i].indexIn(subj); if (pos > -1) subj = rx[i].cap(0); } } } } //qDebug() << "Stripped down to: " << subj; stringDiff = -1; if (prevFrom != from) // change of contributor { newGroup = true; } else // same contributor { if ((stringDiff = levenshteinDistance(prevSubj, subj)) > ng->getMatchDistance()) // no match ... newGroup = true; else newGroup = false; //qDebug() << "Diff between " << prevSubj << " and " << subj << " is " << stringDiff; } if (newGroup) { if (ng->isThereAdvancedGrouping()) { it.toFront(); // decide if we can match to a previous group while (it.hasNext()) { it.next(); if ((stringDiff = levenshteinDistance(it.key(), subj)) <= ng->getMatchDistance()) // match ... { // The index for this group is in it.value() // See if we have the HeaderGroup in our cache headerGroups) if (headerGroups.contains(it.value())) { advancedHeaderGroup = headerGroups.value(it.value()); } else // not in cache { advancedIndex = it.value(); advancedHeaderGroup = getGroup(ng, advancedIndex); if (advancedHeaderGroup) { headerGroups.insert(advancedIndex, advancedHeaderGroup); } else // db read failed .. { skipAdvanced = true; } } if (skipAdvanced == false) { if (mphFound) advancedHeaderGroup->addMphKey(recKey); else advancedHeaderGroup->addSphKey(recKey); advancedPlacement = true; subj = prevSubj; // ignore this header as it's been placed out of sequence from = prevFrom; newGroup = false; // as we managed to relocate to an existing group break; // stop looking at previous groups } else skipAdvanced = false; } } } } if (newGroup) { if (prevGroup) // save before moving on { ba = storeIndex.toLocal8Bit(); k= ba.constData(); memcpy(keymem, k, storeIndex.length()); key.set_size(storeIndex.length()); p2=headerGroup->data(); data.set_data(p2); data.set_size(headerGroup->getRecordSize()); ret=ng->getGroupingDb()->put(NULL, &key, &data, 0); if (ret!=0) qDebug("Error updating record: %d", ret); if (ng->isThereAdvancedGrouping()) headerGroupIndexes.insert(storeIndex.section('\n', 0, 0), storeIndex); Q_DELETE_ARRAY(p2); Q_DELETE(headerGroup); numGroups++; } prevGroup = true; storeIndex = subj % "\n" % from; headerGroup = new HeaderGroup(); headerGroup->setDisplayName(subj); headerGroup->setPostingDate(hb->getPostingDate()); headerGroup->setDownloadDate(hb->getDownloadDate()); headerGroup->setStatus(hb->getStatus()); headerGroup->setNextDistance(stringDiff); } // if we've found somewhere else to place this header then don't add again if (!advancedPlacement) { if (mphFound) headerGroup->addMphKey(recKey); else headerGroup->addSphKey(recKey); } else advancedPlacement = false; if (count % 250 == 0) { QCoreApplication::processEvents(); emit updateJob(JobList::BulkHeaderGroup, tr("Header bulk grouping for newsgroup ") + job->ng->getAlias() + ": " + QString::number(count) + " out of " + QString::number(ng->getTotal()) + tr(" grouped"), job->seq); } if (m_cancel) { emit updateJob(JobList::BulkHeaderGroup, JobList::Cancelled, job->seq); return false; } } if (m_cancel) { emit updateJob(JobList::BulkHeaderGroup, JobList::Cancelled, job->seq); return false; } } if ((t_ret = dbcp->close(dbcp)) != 0) { db->err(ret, "DBcursor->close"); if (ret == 0) ret = t_ret; } char* ptr = ((char*)ckey.data); Q_DELETE_ARRAY(ptr); ptr = ((char*)cdata.data); Q_DELETE_ARRAY(ptr); if (headerGroups.count()) { qDeleteAll(headerGroups); headerGroups.clear(); } qDebug() << "Multi = " << grouped << ", single = " << single; ng->setHeadersNeedGrouping(false); // Finally update the newsgroup emit saveGroup(ng); emit updateJob(JobList::BulkHeaderGroup, tr("Header bulk grouping for newsgroup ") + job->ng->getAlias() + ": " + QString::number(count) + " out of " + QString::number(ng->getTotal()) + tr(" grouped"), job->seq); if (m_cancel) { emit updateJob(JobList::BulkHeaderGroup, JobList::Cancelled, job->seq); return false; } emit logEvent(tr("Bulk grouping of ") + ng->getTotal() + tr(" articles completed successfully.")); emit updateJob(JobList::BulkHeaderGroup, JobList::Finished_Ok, job->seq); ng->setTotalGroups(numGroups); Q_DELETE(headerGroup); return true; }
void StratumClient::processJobNotification(const QJsonObject& _notificationObject) { updateJob(_notificationObject.value(JSON_RPC_TAG_NAME_PARAMS).toObject().toVariantMap()); }
bool BulkLoad::bulkLoadBody() { if (m_cancel) { emit updateJob(JobList::BulkLoad, JobList::Cancelled, job->seq); return false; } emit updateJob(JobList::BulkLoad, JobList::Running, job->seq); NewsGroup* ng = job->ng; HeaderList* hl = job->headerList; mphDeletionsList = 0; sphDeletionsList = 0; DBC *dbcp = 0; MultiPartHeader mph; SinglePartHeader sph; HeaderBase* hb = 0; memset(&ckey, 0, sizeof(ckey)); memset(&cdata, 0, sizeof(cdata)); cdata.data = (void *) dataBuffer; cdata.ulen = HEADER_BULK_BUFFER_LENGTH; cdata.flags = DB_DBT_USERMEM; ckey.data = (void *) keyBuffer; ckey.ulen = HEADER_BULK_BUFFER_LENGTH; ckey.flags = DB_DBT_USERMEM; size_t retklen, retdlen; void *retkey = 0, *retdata = 0; int ret, t_ret; void *p = 0; quint64 count=0; QTime start = QTime::currentTime(); qDebug() << "Loading started: " << start.toString(); /* Acquire a cursor for the database. */ if ((ret = ng->getDb()->get_DB()->cursor(ng->getDb()->get_DB(), NULL, &dbcp, DB_CURSOR_BULK)) != 0) { ng->getDb()->err(ret, "DB->cursor"); return false; } quint32 numIgnored = 0; bool mphFound = false; for (;;) { /* * Acquire the next set of key/data pairs. This code * does not handle single key/data pairs that won't fit * in a BUFFER_LENGTH size buffer, instead returning * DB_BUFFER_SMALL to our caller. */ if ((ret = dbcp->get(dbcp, &ckey, &cdata, DB_MULTIPLE_KEY | DB_NEXT)) != 0) { if (ret != DB_NOTFOUND) ng->getDb()->err(ret, "DBcursor->get"); break; } for (DB_MULTIPLE_INIT(p, &cdata);;) { DB_MULTIPLE_KEY_NEXT(p, &cdata, retkey, retklen, retdata, retdlen); if (p == NULL) break; if (retdlen){;} // MD TODO compiler .... unused variable if (*((char *)retdata) == 'm') { MultiPartHeader::getMultiPartHeader((unsigned int)retklen, (char *)retkey, (char *)retdata, &mph); hb = (HeaderBase*)&mph; mphFound = true; } else if (*((char *)retdata) == 's') { SinglePartHeader::getSinglePartHeader((unsigned int)retklen, (char *)retkey, (char *)retdata, &sph); hb = (HeaderBase*)&sph; mphFound = false; // qDebug() << "Single index = " << sph.getIndex(); } else { // What have we found ????? qDebug() << "Found unexpected identifier for header : " << (char)*((char *)retdata); continue; } if (hb->getStatus() & HeaderBase::MarkedForDeletion) { // ignore this header, garbage collection will remove it ... ++numIgnored; ++count; // ... but still count it as bulk delete will reduce the count if (numIgnored == 1) { // These two will be freed by bulk delete mphDeletionsList = new QList<QString>; sphDeletionsList = new QList<QString>; } if (mphFound) mphDeletionsList->append(hb->getIndex()); else sphDeletionsList->append(hb->getIndex()); continue; } if (m_cancel) break; hl->headerTreeModel->setupTopLevelItem(hb); ++count; if (count % 50 == 0) { QString labelText = tr("Loaded ") + QString("%L1").arg(count) + " of " + QString("%L1").arg(ng->getTotal()) + " articles."; emit progress(job->seq, count, labelText); QCoreApplication::processEvents(); } } if (m_cancel) break; } if ((t_ret = dbcp->close(dbcp)) != 0) { ng->getDb()->err(ret, "DBcursor->close"); if (ret == 0) ret = t_ret; } emit loadReady(job->seq); QString labelText = tr("Loaded ") + QString("%L1").arg(count) + " of " + QString("%L1").arg(ng->getTotal()) + " articles."; emit progress(job->seq, count, labelText); QCoreApplication::processEvents(); if (!m_cancel) { quint64 totalArticles = ng->getTotal(); if (totalArticles != count || ng->unread() > count) { qint64 difference = count - totalArticles; // may be negative quint64 unread = (quint64)qMax((qint64)(ng->unread() + difference), (qint64)0); if (unread > count) unread = count; ng->setTotal(count); ng->setUnread(unread); emit updateArticleCounts(ng); } } qDebug() << "Loading finished. Seconds: " << start.secsTo(QTime::currentTime()); qDebug() << "Ignored " << numIgnored << " articles"; qDebug() << "Loaded " << count << " articles"; if (mphDeletionsList) // need bulk deletion emit addBulkJob(JobList::BulkDelete, ng, hl, mphDeletionsList, sphDeletionsList); if (m_cancel) { emit updateJob(JobList::BulkLoad, JobList::Cancelled, job->seq); return false; } emit updateJob(JobList::BulkLoad, JobList::Finished_Ok, job->seq); return true; }