Fix functionality broken by commit fd0046c4

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/78/head
Michele Calgaro 1 year ago
parent fd0046c407
commit 0e1649599e
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -41,10 +41,8 @@ KNGroupBrowser::KNGroupBrowser(TQWidget *parent, const TQString &caption, KNNntp
{ {
refilterTimer = new TQTimer(); refilterTimer = new TQTimer();
allList=new TQPtrList<KNGroupInfo>; allList = new std::list<KNGroupInfo*>();
allList->setAutoDelete(true); matchList = new std::list<KNGroupInfo*>();
matchList=new TQPtrList<KNGroupInfo>;
matchList->setAutoDelete(false);
//create Widgets //create Widgets
page=new TQWidget(this); page=new TQWidget(this);
@ -148,7 +146,16 @@ KNGroupBrowser::~KNGroupBrowser()
knGlobals.netAccess()->stopJobsNntp(KNJobData::JTCheckNewGroups); knGlobals.netAccess()->stopJobsNntp(KNJobData::JTCheckNewGroups);
delete matchList; delete matchList;
for (KNGroupInfo *g : *allList)
{
if (g)
{
delete g;
}
}
delete allList; delete allList;
delete refilterTimer; delete refilterTimer;
} }
@ -159,6 +166,13 @@ void KNGroupBrowser::slotReceiveList(KNGroupListData* d)
enableButton(User2,true); enableButton(User2,true);
if (d) { // d==0 if something has gone wrong... if (d) { // d==0 if something has gone wrong...
for (KNGroupInfo *g : *allList)
{
if (g)
{
delete g;
}
}
delete allList; delete allList;
allList = d->extractList(); allList = d->extractList();
incrementalFilter=false; incrementalFilter=false;
@ -206,8 +220,8 @@ void KNGroupBrowser::createListItems(TQListViewItem *parent)
} }
} }
for(KNGroupInfo *gn=matchList->first(); gn; gn=matchList->next()) { for (KNGroupInfo *gn : *matchList)
{
if(!prefix.isEmpty() && !gn->name.startsWith(prefix)) if(!prefix.isEmpty() && !gn->name.startsWith(prefix))
if(!compare.isNull()) if(!compare.isNull())
break; break;
@ -321,14 +335,14 @@ void KNGroupBrowser::slotFilter(const TQString &txt)
bool doIncrementalUpdate = (!isRegexp && incrementalFilter && (filtertxt.left(lastFilter.length())==lastFilter)); bool doIncrementalUpdate = (!isRegexp && incrementalFilter && (filtertxt.left(lastFilter.length())==lastFilter));
if (doIncrementalUpdate) { if (doIncrementalUpdate) {
TQPtrList<KNGroupInfo> *tempList = new TQPtrList<KNGroupInfo>(); std::list<KNGroupInfo*> *tempList = new std::list<KNGroupInfo*>();
tempList->setAutoDelete(false);
for(KNGroupInfo *g=matchList->first(); g; g=matchList->next()) { for (KNGroupInfo *g : *matchList)
{
if ((notCheckSub||g->subscribed)&& if ((notCheckSub||g->subscribed)&&
(notCheckNew||g->newGroup)&& (notCheckNew||g->newGroup)&&
(notCheckStr||(g->name.find(filtertxt)!=-1))) (notCheckStr||(g->name.find(filtertxt)!=-1)))
tempList->append(g); tempList->push_back(g);
} }
delete matchList; delete matchList;
@ -336,18 +350,20 @@ void KNGroupBrowser::slotFilter(const TQString &txt)
} else { } else {
matchList->clear(); matchList->clear();
for(KNGroupInfo *g=allList->first(); g; g=allList->next()) { for (KNGroupInfo *g : *allList)
{
if ((notCheckSub||g->subscribed)&& if ((notCheckSub||g->subscribed)&&
(notCheckNew||g->newGroup)&& (notCheckNew||g->newGroup)&&
(notCheckStr||(isRegexp? (reg.search(g->name,0) != -1):(g->name.find(filtertxt)!=-1)))) (notCheckStr||(isRegexp? (reg.search(g->name,0) != -1):(g->name.find(filtertxt)!=-1))))
matchList->append(g); matchList->push_back(g);
} }
} }
groupView->clear(); groupView->clear();
if((matchList->count() < MIN_FOR_TREE) || noTreeCB->isChecked()) { if((matchList->size() < MIN_FOR_TREE) || noTreeCB->isChecked()) {
for(KNGroupInfo *g=matchList->first(); g; g=matchList->next()) { for (KNGroupInfo *g : *matchList)
{
cit=new CheckItem(groupView, *g, this); cit=new CheckItem(groupView, *g, this);
updateItemState(cit); updateItemState(cit);
} }
@ -358,7 +374,7 @@ void KNGroupBrowser::slotFilter(const TQString &txt)
lastFilter = filtertxt; lastFilter = filtertxt;
incrementalFilter = !isRegexp; incrementalFilter = !isRegexp;
leftLabel->setText(i18n("Groups on %1: (%2 displayed)").arg(a_ccount->name()).arg(matchList->count())); leftLabel->setText(i18n("Groups on %1: (%2 displayed)").arg(a_ccount->name()).arg(matchList->size()));
arrowBtn1->setEnabled(false); arrowBtn1->setEnabled(false);
arrowBtn2->setEnabled(false); arrowBtn2->setEnabled(false);

@ -98,7 +98,7 @@ class KNGroupBrowser : public KDialogBase {
bool incrementalFilter; bool incrementalFilter;
KNNntpAccount *a_ccount; KNNntpAccount *a_ccount;
TQPtrList<KNGroupInfo> *allList, *matchList; std::list<KNGroupInfo*> *allList, *matchList;
protected slots: protected slots:
void slotLoadList(); void slotLoadList();

@ -121,18 +121,17 @@ void KNGroupDialog::updateItemState(CheckItem *it)
void KNGroupDialog::toSubscribe(TQPtrList<KNGroupInfo> *l) void KNGroupDialog::toSubscribe(std::list<KNGroupInfo*> *l)
{ {
KNGroupInfo *info; KNGroupInfo *info;
l->clear(); l->clear();
l->setAutoDelete(true);
bool moderated=false; bool moderated=false;
TQListViewItemIterator it(subView); TQListViewItemIterator it(subView);
for(; it.current(); ++it) { for(; it.current(); ++it) {
info = new KNGroupInfo(); info = new KNGroupInfo();
*info = ((static_cast<GroupItem*>(it.current()))->info); *info = ((static_cast<GroupItem*>(it.current()))->info);
l->append(info); l->push_back(info);
if (info->status==KNGroup::moderated) if (info->status==KNGroup::moderated)
moderated=true; moderated=true;
} }

@ -29,7 +29,7 @@ class KNGroupDialog : public KNGroupBrowser {
KNGroupDialog(TQWidget *parent, KNNntpAccount *a); KNGroupDialog(TQWidget *parent, KNNntpAccount *a);
~KNGroupDialog(); ~KNGroupDialog();
void toSubscribe(TQPtrList<KNGroupInfo> *l); void toSubscribe(std::list<KNGroupInfo*> *l);
void toUnsubscribe(TQStringList *l); void toUnsubscribe(TQStringList *l);
protected: protected:

@ -12,6 +12,7 @@
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/ */
#include <algorithm>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <tqdir.h> #include <tqdir.h>
@ -74,6 +75,10 @@ bool KNGroupInfo::operator< (const KNGroupInfo &gi2)
return (name < gi2.name); return (name < gi2.name);
} }
bool KNGroupInfo::PtrCompFn(KNGroupInfo *a, KNGroupInfo *b)
{
return *a < *b;
}
//=============================================================================== //===============================================================================
@ -81,16 +86,25 @@ bool KNGroupInfo::operator< (const KNGroupInfo &gi2)
KNGroupListData::KNGroupListData() KNGroupListData::KNGroupListData()
: codecForDescriptions(0) : codecForDescriptions(0)
{ {
groups = new TQPtrList<KNGroupInfo>; groups = new std::list<KNGroupInfo*>();
groups->setAutoDelete(true);
} }
KNGroupListData::~KNGroupListData() KNGroupListData::~KNGroupListData()
{ {
if (groups)
{
for (KNGroupInfo *g : *groups)
{
if (g)
{
delete g;
}
}
delete groups; delete groups;
} }
}
@ -145,7 +159,7 @@ bool KNGroupListData::readIn(KNProtocolClient *client)
} else } else
sub = false; sub = false;
groups->append(new KNGroupInfo(name,description,false,sub,status)); groups->push_back(new KNGroupInfo(name,description,false,sub,status));
if (timer.elapsed() > 200) { // don't flicker if (timer.elapsed() > 200) { // don't flicker
timer.restart(); timer.restart();
@ -169,7 +183,8 @@ bool KNGroupListData::writeOut()
TQCString temp; TQCString temp;
if(f.open(IO_WriteOnly)) { if(f.open(IO_WriteOnly)) {
for (KNGroupInfo *i=groups->first(); i; i=groups->next()) { for (KNGroupInfo *i : *groups)
{
temp = i->name.utf8(); temp = i->name.utf8();
switch (i->status) { switch (i->status) {
case KNGroup::unknown: temp += " u "; case KNGroup::unknown: temp += " u ";
@ -196,27 +211,33 @@ bool KNGroupListData::writeOut()
// merge in new groups, we want to preserve the "subscribed"-flag // merge in new groups, we want to preserve the "subscribed"-flag
// of the loaded groups and the "new"-flag of the new groups. // of the loaded groups and the "new"-flag of the new groups.
void KNGroupListData::merge(TQPtrList<KNGroupInfo>* newGroups) void KNGroupListData::merge(std::list<KNGroupInfo*> *newGroups)
{ {
bool subscribed; bool subscribed;
for (KNGroupInfo *i=newGroups->first(); i; i=newGroups->next()) { for (KNGroupInfo *i : *newGroups)
if (groups->find(i)>=0) { {
subscribed = groups->current()->subscribed; std::list<KNGroupInfo*>::iterator ngIt = std::find(groups->begin(), groups->end(), i);
groups->remove(); // avoid duplicates
if (ngIt != std::end(*groups))
{
KNGroupInfo *newGr = *ngIt;
subscribed = newGr->subscribed;
groups->erase(ngIt); // avoid duplicates
delete newGr;
} else } else
subscribed = false; subscribed = false;
groups->append(new KNGroupInfo(i->name,i->description,true,subscribed,i->status)); groups->push_back(new KNGroupInfo(i->name,i->description,true,subscribed,i->status));
} }
groups->sort(); groups->sort(KNGroupInfo::PtrCompFn);
} }
TQPtrList<KNGroupInfo>* KNGroupListData::extractList() std::list<KNGroupInfo*>* KNGroupListData::extractList()
{ {
TQPtrList<KNGroupInfo>* temp = groups; std::list<KNGroupInfo*>* temp = groups;
groups = 0; groups = nullptr;
return temp; return temp;
} }
@ -417,10 +438,12 @@ void KNGroupManager::showGroupDialog(KNNntpAccount *a, TQWidget *parent)
} }
} }
TQPtrList<KNGroupInfo> lst2; std::list<KNGroupInfo*> lst2;
gDialog->toSubscribe(&lst2); gDialog->toSubscribe(&lst2);
for(KNGroupInfo *var=lst2.first(); var; var=lst2.next()) { for (KNGroupInfo *var : lst2)
{
subscribeGroup(var, a); subscribeGroup(var, a);
delete var;
} }
} }
@ -593,7 +616,8 @@ void KNGroupManager::processJob(KNJobData *j)
// update the descriptions of the subscribed groups // update the descriptions of the subscribed groups
for ( TQValueList<KNGroup*>::Iterator it = mGroupList.begin(); it != mGroupList.end(); ++it ) { for ( TQValueList<KNGroup*>::Iterator it = mGroupList.begin(); it != mGroupList.end(); ++it ) {
if ( (*it)->account() == j->account() ) { if ( (*it)->account() == j->account() ) {
for ( KNGroupInfo* inf = d->groups->first(); inf; inf = d->groups->next() ) for (KNGroupInfo *inf : *d->groups)
{
if ( inf->name == (*it)->groupname() ) { if ( inf->name == (*it)->groupname() ) {
(*it)->setDescription( inf->description ); (*it)->setDescription( inf->description );
(*it)->setStatus( inf->status ); (*it)->setStatus( inf->status );
@ -602,6 +626,7 @@ void KNGroupManager::processJob(KNJobData *j)
} }
} }
} }
}
emit(newListReady(d)); emit(newListReady(d));
} else { } else {
KMessageBox::error(knGlobals.topWidget, j->errorString()); KMessageBox::error(knGlobals.topWidget, j->errorString());

@ -15,8 +15,9 @@
#ifndef KNGROUPMANAGER_H #ifndef KNGROUPMANAGER_H
#define KNGROUPMANAGER_H #define KNGROUPMANAGER_H
#include <list>
#include <tqobject.h> #include <tqobject.h>
#include <tqptrlist.h>
#include "knjobdata.h" #include "knjobdata.h"
#include "kngroup.h" #include "kngroup.h"
@ -48,6 +49,8 @@ class KNGroupInfo {
bool operator== (const KNGroupInfo &gi2); bool operator== (const KNGroupInfo &gi2);
bool operator< (const KNGroupInfo &gi2); bool operator< (const KNGroupInfo &gi2);
static bool PtrCompFn(KNGroupInfo *a, KNGroupInfo *b);
}; };
@ -59,13 +62,13 @@ class KNGroupListData : public KNJobItem {
bool readIn(KNProtocolClient *client=0); bool readIn(KNProtocolClient *client=0);
bool writeOut(); bool writeOut();
void merge(TQPtrList<KNGroupInfo>* newGroups); void merge(std::list<KNGroupInfo*> *newGroups);
TQPtrList<KNGroupInfo>* extractList(); std::list<KNGroupInfo*>* extractList();
TQStringList subscribed; TQStringList subscribed;
TQString path; TQString path;
TQPtrList<KNGroupInfo> *groups; std::list<KNGroupInfo*> *groups;
TQDate fetchSince; TQDate fetchSince;
bool getDescriptions; bool getDescriptions;
TQTextCodec *codecForDescriptions; TQTextCodec *codecForDescriptions;

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

@ -20,8 +20,6 @@
#include <tqfile.h> #include <tqfile.h>
#include <tqglobal.h> #include <tqglobal.h>
#include <tqptrvector.h>
#include <tqptrlist.h>
class TQWidget; class TQWidget;
class TQString; class TQString;

Loading…
Cancel
Save