void KNGroupManager::loadGroups(KNNntpAccount *a) { KNGroup *group; QString dir(a->path()); if(dir.isNull()) return; QDir d(dir); QStringList entries(d.entryList("*.grpinfo")); for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) { group = new KNGroup(a); if(group->readInfo(dir + (*it))) { mGroupList.append(group); emit groupAdded(group); } else { delete group; kdError(5003) << "Unable to load " << (*it) << "!" << endl; } } }
void KNArticleManager::rescoreArticles(KNRemoteArticle::List &l) { if ( l.isEmpty() ) return; KNGroup *g = static_cast<KNGroup*>( l.first()->collection() ); KScoringManager *sm = knGlobals.scoringManager(); sm->initCache(g->groupname()); for ( KNRemoteArticle::List::Iterator it = l.begin(); it != l.end(); ++it ) { int defScore = 0; if ( (*it)->isIgnored()) defScore = knGlobals.settings()->ignoredThreshold(); else if ( (*it)->isWatched() ) defScore = knGlobals.settings()->watchedThreshold(); (*it)->setScore(defScore); bool read = (*it)->isRead(); KNScorableArticle sa( (*it) ); sm->applyRules(sa); (*it)->updateListItem(); (*it)->setChanged( true ); if ( !read && (*it)->isRead() != read ) g_roup->incReadCount(); } }
void KNGroupManager::subscribeGroup(const KNGroupInfo *gi, KNNntpAccount *a) { KNGroup *grp; grp = new KNGroup(a); grp->setGroupname(gi->name); grp->setDescription(gi->description); grp->setStatus(gi->status); grp->saveInfo(); mGroupList.append(grp); emit groupAdded(grp); }
void KNNntpClient::doFetchNewHeaders() { KNGroup *target = static_cast<KNGroup *>(job->data()); char *s; int first = 0, last = 0, oldlast = 0, toFetch = 0, rep = 0; QCString cmd; target->setLastFetchCount(0); sendSignal(TSdownloadNew); errorPrefix = i18n("No new articles could be retrieved for\n%1/%2.\nThe following error occurred:\n") .arg(account.server()).arg(target->groupname()); cmd = "GROUP "; cmd += target->groupname().utf8(); if(!sendCommandWCheck(cmd, 211)) // 211 n f l s group selected { return; } currentGroup = target->groupname(); progressValue = 90; s = strchr(getCurrentLine(), ' '); if(s) { s++; s = strchr(s, ' '); } if(s) { s++; first = atoi(s); target->setFirstNr(first); s = strchr(s, ' '); } if(s) { last = atoi(s); } else { QString tmp = i18n("No new articles could be retrieved.\nThe server sent a malformatted response:\n"); tmp += getCurrentLine(); job->setErrorString(tmp); closeConnection(); return; } if(target->lastNr() == 0) //first fetch { if(first > 0) oldlast = first - 1; else oldlast = first; } else oldlast = target->lastNr(); toFetch = last - oldlast; //qDebug("knode: last %d oldlast %d toFetch %d\n",last,oldlast,toFetch); if(toFetch <= 0) { //qDebug("knode: No new Articles in group\n"); target->setLastNr(last); // don't get stuck when the article numbers wrap return; } if(toFetch > target->maxFetch()) { toFetch = target->maxFetch(); //qDebug("knode: Fetching only %d articles\n",toFetch); } progressValue = 100; predictedLines = toFetch; // get list of additional headers provided by the XOVER command // see RFC 2980 section 2.1.7 QStrList headerformat; cmd = "LIST OVERVIEW.FMT"; if(sendCommand(cmd, rep) && rep == 215) { QStrList tmp; if(getMsg(tmp)) { for(QCString s = tmp.first(); s; s = tmp.next()) { s = s.stripWhiteSpace(); // remove the mandatory xover header if(s == "Subject:" || s == "From:" || s == "Date:" || s == "Message-ID:" || s == "References:" || s == "Bytes:" || s == "Lines:") continue; else headerformat.append(s); } } } //qDebug("knode: KNNntpClient::doFetchNewHeaders() : xover %d-%d", last-toFetch+1, last); cmd.sprintf("xover %d-%d", last - toFetch + 1, last); if(!sendCommand(cmd, rep)) return; // no articles in selected range... if(rep == 420) // 420 No article(s) selected { target->setLastNr(last); return; } else if(rep != 224) // 224 success { handleErrors(); return; } QStrList headers; if(!getMsg(headers)) { return; } progressValue = 1000; sendSignal(TSprogressUpdate); sendSignal(TSsortNew); mutex.lock(); target->insortNewHeaders(&headers, &headerformat, this); target->setLastNr(last); mutex.unlock(); }
void KNGroupManager::processJob(KNJobData *j) { if((j->type() == KNJobData::JTLoadGroups) || (j->type() == KNJobData::JTFetchGroups) || (j->type() == KNJobData::JTCheckNewGroups)) { KNGroupListData *d = static_cast<KNGroupListData *>(j->data()); if(!j->canceled()) { if(j->success()) { if((j->type() == KNJobData::JTFetchGroups) || (j->type() == KNJobData::JTCheckNewGroups)) { // update the descriptions of the subscribed groups for(QValueList<KNGroup *>::Iterator it = mGroupList.begin(); it != mGroupList.end(); ++it) { if((*it)->account() == j->account()) { for(KNGroupInfo *inf = d->groups->first(); inf; inf = d->groups->next()) if(inf->name == (*it)->groupname()) { (*it)->setDescription(inf->description); (*it)->setStatus(inf->status); break; } } } } emit(newListReady(d)); } else { KMessageBox::error(knGlobals.topWidget, j->errorString()); emit(newListReady(0)); } } else emit(newListReady(0)); delete j; delete d; } else //KNJobData::JTfetchNewHeaders or KNJobData::JTsilentFetchNewHeaders { KNGroup *group = static_cast<KNGroup *>(j->data()); if(!j->canceled()) { if(j->success()) { if(group->lastFetchCount() > 0) { group->scoreArticles(); group->processXPostBuffer(true); emit groupUpdated(group); group->saveInfo(); knGlobals.memoryManager()->updateCacheEntry(group); } } else { // ok, hack (?): // stop all other active fetch jobs, this prevents that // we show multiple error dialogs if a server is unavailable knGlobals.netAccess()->stopJobsNntp(KNJobData::JTfetchNewHeaders); knGlobals.netAccess()->stopJobsNntp(KNJobData::JTsilentFetchNewHeaders); if(!(j->type() == KNJobData::JTsilentFetchNewHeaders)) { KMessageBox::error(knGlobals.topWidget, j->errorString()); } } } if(group == c_urrentGroup) a_rticleMgr->showHdrs(false); delete j; } }
bool KNArticleManager::toggleIgnored(KNRemoteArticle::List &l) { if(l.isEmpty()) return true; KNRemoteArticle *ref = 0; bool ignore = !l.first()->isIgnored(); KNGroup *g = static_cast<KNGroup*>( l.first()->collection() ); int changeCnt = 0, idRef = 0; for ( KNRemoteArticle::List::Iterator it = l.begin(); it != l.end(); ++it ) { (*it)->setWatched(false); if ( (*it)->isIgnored() != ignore ) { (*it)->setIgnored( ignore ); if ( !(*it)->getReadFlag() ) { changeCnt++; idRef = (*it)->idRef(); while ( idRef != 0 ) { ref = g->byId( idRef ); if ( ignore ) { ref->decUnreadFollowUps(); if ( (*it)->isNew() ) ref->decNewFollowUps(); } else { ref->incUnreadFollowUps(); if ( (*it)->isNew() ) ref->incNewFollowUps(); } if(ref->listItem() && ((ref->unreadFollowUps()==0 || ref->unreadFollowUps()==1) || (ref->newFollowUps()==0 || ref->newFollowUps()==1))) ref->updateListItem(); idRef=ref->idRef(); } if ( ignore ) { g->incReadCount(); if ( (*it)->isNew() ) g->decNewCount(); } else { g->decReadCount(); if ( (*it)->isNew() ) g->incNewCount(); } } } (*it)->updateListItem(); (*it)->setChanged(true); } if(changeCnt>0) { g->updateListItem(); if(g==g_roup) updateStatusString(); } return ignore; }