~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/groupwise/libgroupwise/tasks/chatcountstask.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Kopete Groupwise Protocol
 
3
    ChatCountsTask.cpp - Task to update chatroom participant counts
 
4
 
 
5
    Copyright (c) 2005      SUSE Linux Products GmbH     http://www.suse.com
 
6
 
 
7
    Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
 
8
 
 
9
    *************************************************************************
 
10
    *                                                                       *
 
11
    * This library is free software; you can redistribute it and/or         *
 
12
    * modify it under the terms of the GNU Lesser General Public            *
 
13
    * License as published by the Free Software Foundation; either          *
 
14
    * version 2 of the License, or (at your option) any later version.      *
 
15
    *                                                                       *
 
16
    *************************************************************************
 
17
*/
 
18
 
 
19
#include <qmap.h>
 
20
#include <kdebug.h>
 
21
 
 
22
#include "gwfield.h"
 
23
#include "response.h"
 
24
 
 
25
#include "chatcountstask.h"
 
26
 
 
27
ChatCountsTask::ChatCountsTask(Task* parent): RequestTask(parent)
 
28
{
 
29
        Field::FieldList lst;
 
30
        createTransfer( "chatcounts", lst );
 
31
}
 
32
 
 
33
 
 
34
ChatCountsTask::~ChatCountsTask()
 
35
{
 
36
}
 
37
 
 
38
bool ChatCountsTask::take( Transfer * transfer )
 
39
{
 
40
        if ( !forMe( transfer ) )
 
41
                return false;
 
42
        Response * response = dynamic_cast<Response *>( transfer );
 
43
        if ( !response )
 
44
                return false;
 
45
        if ( response->resultCode() )
 
46
        {
 
47
                setError( response->resultCode() );
 
48
                return true;
 
49
        }
 
50
        
 
51
        Field::FieldList responseFields = response->fields();
 
52
        Field::MultiField * resultsArray = responseFields.findMultiField( Field::NM_A_FA_RESULTS );
 
53
        if ( !resultsArray )
 
54
        {
 
55
                setError( GroupWise::Protocol );
 
56
                return true;
 
57
        }
 
58
        Field::FieldList counts = resultsArray->fields();
 
59
        const Field::FieldListIterator end = counts.end();
 
60
        for ( Field::FieldListIterator it = counts.find( Field::NM_A_FA_CHAT );
 
61
                         it != end;
 
62
                         it = counts.find( ++it, Field::NM_A_FA_CHAT ) )
 
63
        {
 
64
                Field::MultiField * mf = static_cast<Field::MultiField *>( *it );
 
65
                Field::FieldList chat = mf->fields();
 
66
                QString roomName;
 
67
                int participants;
 
68
                // read the supplied fields, set metadata and status.
 
69
                Field::SingleField * sf;
 
70
                if ( ( sf = chat.findSingleField ( Field::NM_A_DISPLAY_NAME ) ) )
 
71
                        roomName = sf->value().toString();
 
72
                if ( ( sf = chat.findSingleField ( Field::NM_A_UD_PARTICIPANTS ) ) )
 
73
                        participants = sf->value().toInt();
 
74
                
 
75
                m_results.insert( roomName, participants );
 
76
        }
 
77
        return true;
 
78
}
 
79
 
 
80
QMap< QString, int > ChatCountsTask::results()
 
81
{
 
82
        return m_results;
 
83
}
 
84
 
 
85
#include "chatcountstask.moc"