blob: 08f04b40218f537235efb17e7f06ae2fae107530 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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 <tqmap.h>
#include <kdebug.h>
#include "gwfield.h"
#include "response.h"
#include "chatcountstask.h"
using namespace GroupWise;
ChatCountsTask::ChatCountsTask(Task* tqparent): RequestTask(tqparent)
{
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.tqfind( NM_A_FA_CHAT );
it != end;
it = counts.tqfind( ++it, NM_A_FA_CHAT ) )
{
Field::MultiField * mf = static_cast<Field::MultiField *>( *it );
Field::FieldList chat = mf->fields();
TQString 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;
}
TQMap< TQString, int > ChatCountsTask::results()
{
return m_results;
}
#include "chatcountstask.moc"
|