diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bcb704366cb5e333a626c18c308c7e0448a8e69f (patch) | |
tree | f0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp | |
download | tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp')
-rw-r--r-- | kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp b/kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp new file mode 100644 index 00000000..9e9837f7 --- /dev/null +++ b/kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp @@ -0,0 +1,87 @@ +/* + Kopete Groupwise Protocol + ChatCountsTask.cpp - Task to update chatroom participant counts + + Copyright (c) 2005 SUSE Linux Products GmbH http://www.suse.com + + Kopete (c) 2002-2005 by the Kopete developers <[email protected]> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include <qmap.h> +#include <kdebug.h> + +#include "gwfield.h" +#include "response.h" + +#include "chatcountstask.h" + +using namespace GroupWise; + +ChatCountsTask::ChatCountsTask(Task* parent): RequestTask(parent) +{ + Field::FieldList lst; + createTransfer( "chatcounts", lst ); +} + + +ChatCountsTask::~ChatCountsTask() +{ +} + +bool ChatCountsTask::take( Transfer * transfer ) +{ + if ( !forMe( transfer ) ) + return false; + Response * response = dynamic_cast<Response *>( transfer ); + if ( !response ) + return false; + if ( response->resultCode() ) + { + setError( response->resultCode() ); + return true; + } + + Field::FieldList responseFields = response->fields(); + Field::MultiField * resultsArray = responseFields.findMultiField( NM_A_FA_RESULTS ); + if ( !resultsArray ) + { + setError( Protocol ); + return true; + } + Field::FieldList counts = resultsArray->fields(); + const Field::FieldListIterator end = counts.end(); + for ( Field::FieldListIterator it = counts.find( NM_A_FA_CHAT ); + it != end; + it = counts.find( ++it, NM_A_FA_CHAT ) ) + { + Field::MultiField * mf = static_cast<Field::MultiField *>( *it ); + Field::FieldList chat = mf->fields(); + QString roomName; + int participants; + // read the supplied fields, set metadata and status. + Field::SingleField * sf; + if ( ( sf = chat.findSingleField ( NM_A_DISPLAY_NAME ) ) ) + roomName = sf->value().toString(); + if ( ( sf = chat.findSingleField ( NM_A_UD_PARTICIPANTS ) ) ) + participants = sf->value().toInt(); + + m_results.insert( roomName, participants ); + } + return true; +} + +QMap< QString, int > ChatCountsTask::results() +{ + return m_results; +} + +#include "chatcountstask.moc" |