1 /*
2 	Kopete Oscar Protocol
3 	onlinenotifiertask.cpp - handles all the status notifications
4 
5 	Copyright (c) 2004 by Matt Rogers <mattr@kde.org>
6 
7 	Based on code Copyright (c) 2004 SuSE Linux AG <http://www.suse.com>
8 	Based on Iris, Copyright (C) 2003  Justin Karneges <justin@affinix.com>
9 
10 	Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
11 
12 	*************************************************************************
13 	*                                                                       *
14 	* This library is free software; you can redistribute it and/or         *
15 	* modify it under the terms of the GNU Lesser General Public            *
16 	* License as published by the Free Software Foundation; either          *
17 	* version 2 of the License, or (at your option) any later version.      *
18 	*                                                                       *
19 	*************************************************************************
20 */
21 #include "onlinenotifiertask.h"
22 #include "buffer.h"
23 #include "connection.h"
24 #include "oscartypes.h"
25 #include "transfer.h"
26 
27 #include <kdebug.h>
28 
OnlineNotifierTask(Task * parent)29 OnlineNotifierTask::OnlineNotifierTask( Task* parent ) : Task( parent )
30 {
31 }
32 
~OnlineNotifierTask()33 OnlineNotifierTask::~OnlineNotifierTask()
34 {
35 }
36 
forMe(const Transfer * transfer) const37 bool OnlineNotifierTask::forMe( const Transfer* transfer ) const
38 {
39 	const SnacTransfer* st = dynamic_cast<const SnacTransfer*>( transfer );
40 	if ( !st )
41 		return false;
42 
43 	if ( st->snacService() == 0x0003 )
44 	{
45 		switch ( st->snacSubtype() )
46 		{
47 		case 0x000B:
48 		case 0x000C:
49 			return true;
50 		};
51 	}
52 	return false;
53 }
54 
take(Transfer * transfer)55 bool OnlineNotifierTask::take( Transfer* transfer )
56 {
57 	if ( forMe( transfer ) )
58 	{
59 		SnacTransfer* st = dynamic_cast<SnacTransfer*>( transfer );
60 		if ( st )
61 		{
62 			setTransfer( transfer );
63 
64 			if ( st->snacSubtype() == 0x000B )
65 				userOnline();
66 			else
67 				userOffline();
68 
69 			setTransfer( 0 );
70 		}
71 		return true;
72 	}
73 	return false;
74 }
75 
userOnline()76 void OnlineNotifierTask::userOnline()
77 {
78 	Buffer* buffer = transfer()->buffer();
79 	UserDetails ud;
80 	ud.fill( buffer );
81 	QString user = ud.userId();
82 	//kDebug( OSCAR_RAW_DEBUG ) << user << " is now online";
83 	emit userIsOnline( user, ud );
84 }
85 
userOffline()86 void OnlineNotifierTask::userOffline()
87 {
88 	Buffer* buffer = transfer()->buffer();
89 	UserDetails ud;
90 	ud.fill( buffer );
91 	QString user = ud.userId();
92 	//kDebug( OSCAR_RAW_DEBUG ) << user << " is now offline";
93 	emit userIsOffline( user, ud );
94 }
95 
96