summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp')
-rw-r--r--kopete/protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp87
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 <kopete-devel@kde.org>
+
+ *************************************************************************
+ * *
+ * 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"