diff options
Diffstat (limited to 'knode/kngroupmanager.cpp')
-rw-r--r-- | knode/kngroupmanager.cpp | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/knode/kngroupmanager.cpp b/knode/kngroupmanager.cpp index 188a8e1b1..d2d21762a 100644 --- a/knode/kngroupmanager.cpp +++ b/knode/kngroupmanager.cpp @@ -12,6 +12,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US */ +#include <algorithm> #include <stdio.h> #include <stdlib.h> #include <tqdir.h> @@ -74,6 +75,10 @@ bool KNGroupInfo::operator< (const KNGroupInfo &gi2) return (name < gi2.name); } +bool KNGroupInfo::PtrCompFn(KNGroupInfo *a, KNGroupInfo *b) +{ + return *a < *b; +} //=============================================================================== @@ -81,15 +86,24 @@ bool KNGroupInfo::operator< (const KNGroupInfo &gi2) KNGroupListData::KNGroupListData() : codecForDescriptions(0) { - groups = new TQPtrList<KNGroupInfo>; - groups->setAutoDelete(true); + groups = new std::list<KNGroupInfo*>(); } KNGroupListData::~KNGroupListData() { - delete groups; + if (groups) + { + for (KNGroupInfo *g : *groups) + { + if (g) + { + delete g; + } + } + delete groups; + } } @@ -145,7 +159,7 @@ bool KNGroupListData::readIn(KNProtocolClient *client) } else 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 timer.restart(); @@ -169,7 +183,8 @@ bool KNGroupListData::writeOut() TQCString temp; if(f.open(IO_WriteOnly)) { - for (KNGroupInfo *i=groups->first(); i; i=groups->next()) { + for (KNGroupInfo *i : *groups) + { temp = i->name.utf8(); switch (i->status) { case KNGroup::unknown: temp += " u "; @@ -196,27 +211,33 @@ bool KNGroupListData::writeOut() // merge in new groups, we want to preserve the "subscribed"-flag // 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; - for (KNGroupInfo *i=newGroups->first(); i; i=newGroups->next()) { - if (groups->find(i)>=0) { - subscribed = groups->current()->subscribed; - groups->remove(); // avoid duplicates + for (KNGroupInfo *i : *newGroups) + { + std::list<KNGroupInfo*>::iterator ngIt = std::find(groups->begin(), groups->end(), i); + + if (ngIt != std::end(*groups)) + { + KNGroupInfo *newGr = *ngIt; + subscribed = newGr->subscribed; + groups->erase(ngIt); // avoid duplicates + delete newGr; } else 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; - groups = 0; + std::list<KNGroupInfo*>* temp = groups; + groups = nullptr; return temp; } @@ -417,10 +438,12 @@ void KNGroupManager::showGroupDialog(KNNntpAccount *a, TQWidget *parent) } } - TQPtrList<KNGroupInfo> lst2; + std::list<KNGroupInfo*> lst2; gDialog->toSubscribe(&lst2); - for(KNGroupInfo *var=lst2.first(); var; var=lst2.next()) { + for (KNGroupInfo *var : lst2) + { subscribeGroup(var, a); + delete var; } } @@ -593,12 +616,14 @@ void KNGroupManager::processJob(KNJobData *j) // update the descriptions of the subscribed groups for ( TQValueList<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() ) + for (KNGroupInfo *inf : *d->groups) + { if ( inf->name == (*it)->groupname() ) { (*it)->setDescription( inf->description ); (*it)->setStatus( inf->status ); break; } + } } } } |