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
TypingNotifyTask(Task * parent)25 TypingNotifyTask::TypingNotifyTask( Task* parent )
26 : Task( parent )
27 {
28 m_notificationType = 0x0000;
29 }
30
~TypingNotifyTask()31 TypingNotifyTask::~TypingNotifyTask()
32 {
33 }
34
forMe(const Transfer * transfer) const35 bool TypingNotifyTask::forMe( const Transfer* transfer ) const
36 {
37 const SnacTransfer* st = dynamic_cast<const SnacTransfer*>( transfer );
38 if ( !st )
39 return false;
40
41 if ( st->snacService() == 0x0004 && st->snacSubtype() == 0x0014 )
42 return true;
43 else
44 return false;
45 }
46
take(Transfer * transfer)47 bool TypingNotifyTask::take( Transfer* transfer )
48 {
49 if ( forMe( transfer ) )
50 {
51 setTransfer( transfer );
52 handleNotification();
53 setTransfer( 0 );
54 return true;
55 }
56
57 return false;
58 }
59
onGo()60 void TypingNotifyTask::onGo()
61 {
62 FLAP f = { 0x02, 0, 0 };
63 SNAC s = { 0x0004, 0x0014, 0x0000, client()->snacSequence() };
64 Buffer* b = new Buffer();
65
66 //notification id cookie. it's a quad-word
67 b->addDWord( 0x00000000 );
68 b->addDWord( 0x00000000 );
69
70 b->addWord( 0x0001 ); //mtn messages are always sent as type 1 messages
71
72 b->addBUIN( m_contact.toLatin1() );
73
74 b->addWord( m_notificationType );
75
76 Transfer* t = createTransfer( f, s, b );
77 send( t );
78
79 setSuccess( 0, QString() );
80 }
81
handleNotification()82 void TypingNotifyTask::handleNotification()
83 {
84 /* NB ICQ5 (windows) seems to only send 0x0002 and 0x0001, so I'm interpreting 0x001 as typing finished here - Will */
85 Buffer* b = transfer()->buffer();
86
87 //I don't care about the QWORD or the channel
88 b->skipBytes( 10 );
89
90 QString contact( b->getBUIN() );
91
92 quint32 word = b->getWord();
93 switch ( word )
94 {
95 case 0x0000:
96 kDebug(OSCAR_RAW_DEBUG) << contact << " has finished typing";
97 emit typingFinished( contact );
98 break;
99 case 0x0001:
100 kDebug(OSCAR_RAW_DEBUG) << contact << " has typed a word";
101 emit typingFinished( contact );
102 break;
103 case 0x0002:
104 kDebug(OSCAR_RAW_DEBUG) << contact << " has started typing";
105 emit typingStarted( contact );
106 break;
107 default:
108 kDebug(OSCAR_RAW_DEBUG) << contact << " typed an unknown typing notification - " << word;
109 }
110 }
111
setParams(const QString & contact,int notifyType)112 void TypingNotifyTask::setParams( const QString& contact, int notifyType )
113 {
114 m_contact = contact;
115 m_notificationType = notifyType;
116 }
117
118 // kate: indent-mode csands; space-indent off; replace-tabs off;
119
120