diff options
Diffstat (limited to 'knode/knnntpclient.cpp')
| -rw-r--r-- | knode/knnntpclient.cpp | 86 | 
1 files changed, 58 insertions, 28 deletions
| diff --git a/knode/knnntpclient.cpp b/knode/knnntpclient.cpp index 2ba465be..0755dc96 100644 --- a/knode/knnntpclient.cpp +++ b/knode/knnntpclient.cpp @@ -15,6 +15,9 @@  */  #include <stdlib.h> +#include <algorithm> +#include <vector> +  #include <tdelocale.h>  #include <tqtextcodec.h>  #include <tqmutex.h> @@ -132,7 +135,7 @@ void KNNntpClient::doFetchGroups()          default  : status = KNGroup::unknown;        } -      target->groups->append(new KNGroupInfo(name,TQString(),false,subscribed,status)); +      target->groups->push_back(new KNGroupInfo(name,TQString(),false,subscribed,status));      }      doneLines++;    } @@ -140,15 +143,18 @@ void KNNntpClient::doFetchGroups()    if (!job->success() || job->canceled())      return;     // stopped... -  TQSortedVector<KNGroupInfo> tempVector; -  target->groups->toVector(&tempVector); -  tempVector.sort(); +  std::vector<KNGroupInfo*> tempVector; +  for (KNGroupInfo *g : *target->groups) +  { +    tempVector.push_back(g); +  } +  std::sort(tempVector.begin(), tempVector.end(), KNGroupInfo::PtrCompFn);    if (target->getDescriptions) {      errorPrefix = i18n("The group descriptions could not be retrieved.\nThe following error occurred:\n");      progressValue = 100;      doneLines = 0; -    predictedLines = target->groups->count(); +    predictedLines = target->groups->size();      sendSignal(TSdownloadDesc);      sendSignal(TSprogressUpdate); @@ -189,8 +195,11 @@ void KNNntpClient::doFetchGroups()              description = TQString::fromLocal8Bit(s);            info.name = name; -          if ((pos=tempVector.bsearch(&info))!=-1) -            tempVector[pos]->description = description; +          if (std::binary_search(tempVector.begin(), tempVector.end(), &info, KNGroupInfo::PtrCompFn)) +          { +            KNGroupInfo *posGroup = *std::lower_bound(tempVector.begin(), tempVector.end(), &info, KNGroupInfo::PtrCompFn); +            posGroup->description = description; +          }          }          doneLines++;        } @@ -200,9 +209,11 @@ void KNNntpClient::doFetchGroups()        return;     // stopped...    } -  target->groups->setAutoDelete(false); -  tempVector.toList(target->groups); -  target->groups->setAutoDelete(true); +  target->groups->clear(); +  for (KNGroupInfo *g : tempVector) +  { +    target->groups->push_back(g); +  }    sendSignal(TSwriteGrouplist);    if (!target->writeOut()) @@ -229,8 +240,7 @@ void KNNntpClient::doCheckNewGroups()    char *s, *line;    TQString name;    KNGroup::Status status; -  TQSortedList<KNGroupInfo> tmpList; -  tmpList.setAutoDelete(true); +  std::list<KNGroupInfo*> tmpList;    while (getNextLine()) {      line = getCurrentLine(); @@ -261,19 +271,23 @@ void KNNntpClient::doCheckNewGroups()          default  : status = KNGroup::unknown;        } -      tmpList.append(new KNGroupInfo(name,TQString(),true,false,status)); +      tmpList.push_back(new KNGroupInfo(name,TQString(),true,false,status));      }      doneLines++;    } +  bool statusOk = true; +    if (!job->success() || job->canceled()) -    return;     // stopped... +  { +    statusOk = false;     // stopped... +  } -  if (target->getDescriptions) { +  if (statusOk && target->getDescriptions) {      errorPrefix = i18n("The group descriptions could not be retrieved.\nThe following error occurred:\n");      progressValue = 100;      doneLines = 0; -    predictedLines = tmpList.count()*3; +    predictedLines = tmpList.size()*3;      sendSignal(TSdownloadDesc);      sendSignal(TSprogressUpdate); @@ -283,14 +297,21 @@ void KNNntpClient::doCheckNewGroups()      char *s;      int rep; -    for (KNGroupInfo *group=tmpList.first(); group; group=tmpList.next()) { +    for (KNGroupInfo *group : tmpList) +    {        if (!sendCommand(cmd+group->name.utf8(),rep)) -        return; +      { +        statusOk = false; +        break; +      }        if (rep != 215)        // 215 informations follows          break;        desList.clear();        if (!getMsg(desList)) -        return; +      { +        statusOk = false; +        break; +      }        if (desList.count()>0) {        // group has a description          s = desList.first(); @@ -310,17 +331,26 @@ void KNNntpClient::doCheckNewGroups()      }    } -  sendSignal(TSloadGrouplist); +  if (statusOk) +  { +    sendSignal(TSloadGrouplist); -  if (!target->readIn()) { -    job->setErrorString(i18n("Unable to read the group list file")); -    return; +    if (!target->readIn()) { +      job->setErrorString(i18n("Unable to read the group list file")); +    } +    else +    { +      target->merge(&tmpList); +      sendSignal(TSwriteGrouplist); +      if (!target->writeOut()) { +        job->setErrorString(i18n("Unable to write the group list file")); +      } +    }    } -  target->merge(&tmpList); -  sendSignal(TSwriteGrouplist); -  if (!target->writeOut()) { -    job->setErrorString(i18n("Unable to write the group list file")); -    return; + +  for (KNGroupInfo *group : tmpList) +  { +    delete group;    }  } | 
