summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/oscar/liboscar/userinfotask.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/oscar/liboscar/userinfotask.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/oscar/liboscar/userinfotask.cpp')
-rw-r--r--kopete/protocols/oscar/liboscar/userinfotask.cpp156
1 files changed, 156 insertions, 0 deletions
diff --git a/kopete/protocols/oscar/liboscar/userinfotask.cpp b/kopete/protocols/oscar/liboscar/userinfotask.cpp
new file mode 100644
index 00000000..a204c475
--- /dev/null
+++ b/kopete/protocols/oscar/liboscar/userinfotask.cpp
@@ -0,0 +1,156 @@
+/*
+Kopete Oscar Protocol
+userinfotask.h - Handle sending and receiving info requests for users
+
+Copyright (c) 2004-2005 Matt Rogers <mattr@kde.org>
+
+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 "userinfotask.h"
+
+#include <kdebug.h>
+
+#include "buffer.h"
+#include "connection.h"
+#include "transfer.h"
+#include "userdetails.h"
+
+
+
+UserInfoTask::UserInfoTask( Task* parent )
+: Task( parent )
+{
+}
+
+
+UserInfoTask::~UserInfoTask()
+{
+}
+
+bool UserInfoTask::forMe( const Transfer * transfer ) const
+{
+ const SnacTransfer* st = dynamic_cast<const SnacTransfer*>( transfer );
+ if ( !st )
+ return false;
+
+ if ( st->snacService() == 0x0002 && st->snacSubtype() == 0x0006 )
+ {
+ if ( m_contactSequenceMap.find( st->snacRequest() ) == m_contactSequenceMap.end() )
+ return false;
+ else
+ {
+ //kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Found sequence. taking packet" << endl;
+ return true;
+ }
+ }
+ else
+ return false;
+}
+
+bool UserInfoTask::take( Transfer * transfer )
+{
+ if ( forMe( transfer ) )
+ {
+ setTransfer( transfer );
+ Q_UINT16 seq = 0;
+ SnacTransfer* st = dynamic_cast<SnacTransfer*>( transfer );
+ if ( st )
+ seq = st->snacRequest();
+
+ if ( seq != 0 )
+ {
+ //AFAIK location info packets always have user info
+ Buffer* b = transfer->buffer();
+ UserDetails ud;
+ ud.fill( b );
+ m_sequenceInfoMap[seq] = ud;
+ emit gotInfo( seq );
+
+ QValueList<TLV> list = b->getTLVList();
+ QValueList<TLV>::iterator it = list.begin();
+ QString profile;
+ QString away;
+ for ( ; ( *it ); ++it )
+ {
+ switch( ( *it ).type )
+ {
+ case 0x0001: //profile text encoding
+ kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "text encoding is " << QString( ( *it ).data )<< endl;
+ break;
+ case 0x0002: //profile text
+ kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "The profile is '" << QString( ( *it ).data ) << "'" << endl;
+ profile = QString( ( *it ).data ); // aim always seems to use us-ascii encoding
+ emit receivedProfile( m_contactSequenceMap[seq], profile );
+ break;
+ case 0x0003: //away message encoding
+ kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Away message encoding is " << QString( ( *it ).data ) << endl;
+ break;
+ case 0x0004: //away message
+ kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Away message is '" << QString( ( *it ).data ) << "'" << endl;
+ away = QString( (*it ).data ); // aim always seems to use us-ascii encoding
+ emit receivedAwayMessage( m_contactSequenceMap[seq], away );
+ break;
+ case 0x0005: //capabilities
+ break;
+ default: //unknown
+ kdDebug(14151) << k_funcinfo << "Unknown user info type " << ( *it ).type << endl;
+ break;
+ };
+ }
+ list.clear();
+ }
+ setTransfer( 0 );
+ return true;
+ }
+ return false;
+}
+
+void UserInfoTask::onGo()
+{
+ if ( m_contactSequenceMap[m_seq].isEmpty() )
+ {
+ kdDebug( OSCAR_RAW_DEBUG ) << k_funcinfo << "Info requested for empty contact!" << endl;
+ return;
+ }
+
+ FLAP f = { 0x02, 0, 0 };
+ SNAC s = { 0x0002, 0x0005, 0, m_seq };
+ Buffer* buffer = new Buffer();
+
+ buffer->addWord( m_typesSequenceMap[m_seq] );
+ buffer->addBUIN( m_contactSequenceMap[m_seq].local8Bit() );
+
+ Transfer* t = createTransfer( f, s, buffer );
+ send( t );
+}
+
+void UserInfoTask::requestInfoFor( const QString& contact, unsigned int types )
+{
+ Q_UINT16 seq = client()->snacSequence();
+ kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "setting sequence " << seq << " for contact " << contact << endl;
+ m_contactSequenceMap[seq] = contact;
+ m_typesSequenceMap[seq] = types;
+ m_seq = seq;
+ onGo();
+}
+
+UserDetails UserInfoTask::getInfoFor( Q_UINT16 sequence ) const
+{
+ return m_sequenceInfoMap[sequence];
+}
+
+
+
+//kate: indent-mode csands; tab-width 4;
+
+
+#include "userinfotask.moc"