summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/tasks/getchatsearchresultstask.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/protocols/groupwise/libgroupwise/tasks/getchatsearchresultstask.cpp
downloadtdenetwork-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/getchatsearchresultstask.cpp')
-rw-r--r--kopete/protocols/groupwise/libgroupwise/tasks/getchatsearchresultstask.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/kopete/protocols/groupwise/libgroupwise/tasks/getchatsearchresultstask.cpp b/kopete/protocols/groupwise/libgroupwise/tasks/getchatsearchresultstask.cpp
new file mode 100644
index 00000000..fe1d61f9
--- /dev/null
+++ b/kopete/protocols/groupwise/libgroupwise/tasks/getchatsearchresultstask.cpp
@@ -0,0 +1,122 @@
+/*
+ Kopete Groupwise Protocol
+ getchatsearchresultstask.cpp - Poll the server to see if it has processed our search yet.
+
+ Copyright (c) 2004 SUSE Linux AG http://www.suse.com
+
+ Based on Iris, Copyright (C) 2003 Justin Karneges
+
+ Kopete (c) 2002-2004 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 <kdebug.h>
+
+#include "gwfield.h"
+#include "response.h"
+
+#include "logintask.h"
+
+#include "getchatsearchresultstask.h"
+
+using namespace GroupWise;
+
+GetChatSearchResultsTask::GetChatSearchResultsTask(Task* parent): RequestTask(parent)
+{
+}
+
+
+GetChatSearchResultsTask::~GetChatSearchResultsTask()
+{
+}
+
+void GetChatSearchResultsTask::poll( int queryHandle )
+{
+ Field::FieldList lst;
+ lst.append( new Field::SingleField( NM_A_UD_OBJECT_ID, 0, NMFIELD_TYPE_UDWORD, queryHandle ) );
+ lst.append( new Field::SingleField( NM_A_UD_QUERY_COUNT, 0, NMFIELD_TYPE_UDWORD, 10 ) );
+ createTransfer( "getchatsearchresults", lst );
+}
+
+bool GetChatSearchResultsTask::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;
+ }
+
+ // look for the status code
+ Field::FieldList responseFields = response->fields();
+ Field::SingleField * sf = responseFields.findSingleField( NM_A_UW_STATUS );
+ m_queryStatus = (SearchResultCode)sf->value().toInt();
+
+ Field::MultiField * resultsArray = responseFields.findMultiField( NM_A_FA_RESULTS );
+ if ( !resultsArray )
+ {
+ setError( Protocol );
+ return true;
+ }
+ Field::FieldList matches = resultsArray->fields();
+ const Field::FieldListIterator end = matches.end();
+ for ( Field::FieldListIterator it = matches.find( NM_A_FA_CHAT );
+ it != end;
+ it = matches.find( ++it, NM_A_FA_CHAT ) )
+ {
+ Field::MultiField * mf = static_cast<Field::MultiField *>( *it );
+ Field::FieldList chat = mf->fields();
+ GroupWise::ChatroomSearchResult cd = extractChatDetails( chat );
+ m_results.append( cd );
+ }
+
+ if ( m_queryStatus != DataRetrieved )
+ setError( m_queryStatus );
+ else
+ {
+ kdDebug ( GROUPWISE_DEBUG_GLOBAL ) << " we won!" << endl;
+ setSuccess( m_queryStatus );
+ }
+ return true;
+}
+
+QValueList< GroupWise::ChatroomSearchResult > GetChatSearchResultsTask::results()
+{
+ return m_results;
+}
+
+int GetChatSearchResultsTask::queryStatus()
+{
+ return m_queryStatus;
+}
+
+GroupWise::ChatroomSearchResult GetChatSearchResultsTask::extractChatDetails( Field::FieldList & fields )
+{
+ ChatroomSearchResult csr;
+ csr.participants = 0;
+ // read the supplied fields, set metadata and status.
+ Field::SingleField * sf;
+ if ( ( sf = fields.findSingleField ( NM_A_DISPLAY_NAME ) ) )
+ csr.name = sf->value().toString();
+ if ( ( sf = fields.findSingleField ( NM_A_CHAT_OWNER_DN ) ) )
+ csr.ownerDN = sf->value().toString().lower(); // HACK: lowercased DN
+ if ( ( sf = fields.findSingleField ( NM_A_UD_PARTICIPANTS ) ) )
+ csr.participants = sf->value().toInt();
+
+ kdDebug( GROUPWISE_DEBUG_GLOBAL ) << csr.name << ", " << csr.ownerDN << ", " << csr.participants << endl;
+ return csr;
+}
+
+#include "getchatsearchresultstask.moc"