summaryrefslogtreecommitdiffstats
path: root/knode/kngroupmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'knode/kngroupmanager.cpp')
-rw-r--r--knode/kngroupmanager.cpp69
1 files changed, 47 insertions, 22 deletions
diff --git a/knode/kngroupmanager.cpp b/knode/kngroupmanager.cpp
index b429bd6c..e4c7aed6 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 TQSortedList<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(TQSortedList<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);
}
-TQSortedList<KNGroupInfo>* KNGroupListData::extractList()
+std::list<KNGroupInfo*>* KNGroupListData::extractList()
{
- TQSortedList<KNGroupInfo>* temp = groups;
- groups = 0;
+ std::list<KNGroupInfo*>* temp = groups;
+ groups = nullptr;
return temp;
}
@@ -397,10 +418,10 @@ void KNGroupManager::showGroupDialog(KNNntpAccount *a, TQWidget *parent)
{
KNGroupDialog* gDialog=new KNGroupDialog((parent!=0)? parent:knGlobals.topWidget, a);
- connect(gDialog, TQT_SIGNAL(loadList(KNNntpAccount*)), this, TQT_SLOT(slotLoadGroupList(KNNntpAccount*)));
- connect(gDialog, TQT_SIGNAL(fetchList(KNNntpAccount*)), this, TQT_SLOT(slotFetchGroupList(KNNntpAccount*)));
- connect(gDialog, TQT_SIGNAL(checkNew(KNNntpAccount*,TQDate)), this, TQT_SLOT(slotCheckForNewGroups(KNNntpAccount*,TQDate)));
- connect(this, TQT_SIGNAL(newListReady(KNGroupListData*)), gDialog, TQT_SLOT(slotReceiveList(KNGroupListData*)));
+ connect(gDialog, TQ_SIGNAL(loadList(KNNntpAccount*)), this, TQ_SLOT(slotLoadGroupList(KNNntpAccount*)));
+ connect(gDialog, TQ_SIGNAL(fetchList(KNNntpAccount*)), this, TQ_SLOT(slotFetchGroupList(KNNntpAccount*)));
+ connect(gDialog, TQ_SIGNAL(checkNew(KNNntpAccount*,TQDate)), this, TQ_SLOT(slotCheckForNewGroups(KNNntpAccount*,TQDate)));
+ connect(this, TQ_SIGNAL(newListReady(KNGroupListData*)), gDialog, TQ_SLOT(slotReceiveList(KNGroupListData*)));
if(gDialog->exec()) {
KNGroup *g=0;
@@ -417,10 +438,12 @@ void KNGroupManager::showGroupDialog(KNNntpAccount *a, TQWidget *parent)
}
}
- TQSortedList<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;
}
+ }
}
}
}