~neon/kdenetwork/trunk

« back to all changes in this revision

Viewing changes to kopete/protocols/oscar/liboscar/tasks/typingnotifytask.cpp

  • Committer: uwolfer
  • Date: 2013-06-08 10:12:41 UTC
  • Revision ID: svn-v4:283d02a7-25f6-0310-bc7c-ecb5cbfe19da:trunk/KDE/kdenetwork:1357331
kdenetwork has moved to Git

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    typingnotifytask.h  - Send/Receive typing notifications
3
 
 
4
 
    Copyright (c) 2004 by Matt Rogers <mattr@kde.org>
5
 
    Kopete    (c) 2002-2004 by the Kopete developers  <kopete-devel@kde.org>
6
 
 
7
 
    *************************************************************************
8
 
    *                                                                       *
9
 
    * This program is free software; you can redistribute it and/or modify  *
10
 
    * it under the terms of the GNU General Public License as published by  *
11
 
    * the Free Software Foundation; either version 2 of the License, or     *
12
 
    * (at your option) any later version.                                   *
13
 
    *                                                                       *
14
 
    *************************************************************************
15
 
*/
16
 
 
17
 
#include "typingnotifytask.h"
18
 
 
19
 
#include <qstring.h>
20
 
#include <kdebug.h>
21
 
#include "transfer.h"
22
 
#include "buffer.h"
23
 
#include "connection.h"
24
 
 
25
 
 
26
 
 
27
 
 
28
 
TypingNotifyTask::TypingNotifyTask( Task* parent )
29
 
: Task( parent )
30
 
{
31
 
        m_notificationType = 0x0000;
32
 
}
33
 
 
34
 
TypingNotifyTask::~TypingNotifyTask()
35
 
{
36
 
}
37
 
 
38
 
bool TypingNotifyTask::forMe( const Transfer* transfer ) const
39
 
{
40
 
        const SnacTransfer* st = dynamic_cast<const SnacTransfer*>( transfer );
41
 
        if ( !st )
42
 
                return false;
43
 
        
44
 
        if ( st->snacService() == 0x0004  && st->snacSubtype() == 0x0014 )
45
 
                return true;
46
 
        else
47
 
                return false;
48
 
}
49
 
 
50
 
bool TypingNotifyTask::take( Transfer* transfer )
51
 
{
52
 
        if ( forMe( transfer ) )
53
 
        {
54
 
                setTransfer( transfer );
55
 
                handleNotification();
56
 
                setTransfer( 0 );
57
 
                return true;
58
 
        }
59
 
        
60
 
        return false;
61
 
}
62
 
 
63
 
void TypingNotifyTask::onGo()
64
 
{
65
 
        FLAP f = { 0x02, 0, 0 };
66
 
        SNAC s = { 0x0004, 0x0014, 0x0000, client()->snacSequence() };
67
 
        Buffer* b = new Buffer();
68
 
        
69
 
        //notification id cookie. it's a quad-word 
70
 
        b->addDWord( 0x00000000 );
71
 
        b->addDWord( 0x00000000 );
72
 
        
73
 
        b->addWord( 0x0001 ); //mtn messages are always sent as type 1 messages
74
 
        
75
 
        b->addBUIN( m_contact.toLatin1() );
76
 
        
77
 
        b->addWord( m_notificationType );
78
 
        
79
 
        Transfer* t = createTransfer( f, s, b );
80
 
        send( t );
81
 
        
82
 
        setSuccess( 0, QString() );
83
 
}
84
 
 
85
 
void TypingNotifyTask::handleNotification()
86
 
{
87
 
        /* NB ICQ5 (windows) seems to only send 0x0002 and 0x0001, so I'm interpreting 0x001 as typing finished here - Will */
88
 
        Buffer* b = transfer()->buffer();
89
 
        
90
 
        //I don't care about the QWORD or the channel
91
 
        b->skipBytes( 10 );
92
 
        
93
 
        QString contact( b->getBUIN() );
94
 
        
95
 
        quint32 word = b->getWord();
96
 
        switch ( word )
97
 
        {
98
 
        case 0x0000:
99
 
                kDebug(OSCAR_RAW_DEBUG) << contact << " has finished typing";
100
 
                emit typingFinished( contact );
101
 
                break;
102
 
        case 0x0001:
103
 
                kDebug(OSCAR_RAW_DEBUG) << contact << " has typed a word";
104
 
                emit typingFinished( contact );
105
 
                break;
106
 
        case 0x0002:
107
 
                kDebug(OSCAR_RAW_DEBUG) << contact << " has started typing";
108
 
                emit typingStarted( contact );
109
 
                break;
110
 
        default:
111
 
                kDebug(OSCAR_RAW_DEBUG) << contact << " typed an unknown typing notification - " << word;
112
 
        }
113
 
}
114
 
 
115
 
void TypingNotifyTask::setParams( const QString& contact, int notifyType )
116
 
{
117
 
        m_contact = contact;
118
 
        m_notificationType = notifyType;
119
 
}
120
 
 
121
 
#include "typingnotifytask.moc"
122
 
 
123
 
// kate: indent-mode csands; space-indent off; replace-tabs off;
124