summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/userdetailsmanager.cpp
blob: f87cfa25601f56fab15e5d78090ecd7f309a1343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
    userdetailsmanager.cpp - Storage of all user details seen during this session
   
    Copyright (c) 2004      SUSE Linux AG	 	 http://www.suse.com

    Kopete (c) 2002-2004 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 "client.h"
#include "tasks/getdetailstask.h"

#include "userdetailsmanager.h"

UserDetailsManager::UserDetailsManager( Client * parent, const char *name)
 : TQObject(parent, name), m_client( parent )
{
}

UserDetailsManager::~UserDetailsManager()
{
}

void UserDetailsManager::dump( const TQStringList & list )
{
	for ( TQStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
	{
		m_client->debug( TQString( " - %1" ).arg (*it) );
	}
}

bool UserDetailsManager::known( const TQString & dn )
{
	if ( dn == m_client->userDN() )
		return true;
	// TODO: replace with m_detailsMap.contains( dn );
	TQStringList::Iterator found = m_detailsMap.keys().find( dn );
	// we always know the local user's details, so don't look them up
	return ( found !=m_detailsMap.keys().end() );
}

ContactDetails UserDetailsManager::details( const TQString & dn )
{
	return m_detailsMap[ dn ];
}

TQStringList UserDetailsManager::knownDNs()
{
	return m_detailsMap.keys();
}

void UserDetailsManager::addDetails( const ContactDetails & details )
{
	//qDebug( "UserDetailsManager::addContact, got %s, we now know: ", details.dn.ascii() );
	m_detailsMap.insert( details.dn, details );
/*	TQStringList keys = m_detailsMap.keys();
	dump( keys );
	qDebug( "UserDetailsManager::addContact, pending: " );
	dump( m_pendingDNs );*/
}

void UserDetailsManager::removeContact( const TQString & dn )
{
	m_detailsMap.remove( dn );
}

void UserDetailsManager::requestDetails( const TQStringList & dnList, bool onlyUnknown )
{
	// build a list of DNs that are not already subject to a pending request
	TQStringList requestList;
	TQValueListConstIterator<TQString> end = dnList.end();
	for ( TQValueListConstIterator<TQString> it = dnList.begin(); it != end; ++it )
	{
		// don't request our own details
		if ( *it == m_client->userDN() )
			break;
		// don't request details we already have unless the caller specified this
		if ( onlyUnknown && known( *it ) )
			break;
		TQStringList::Iterator found = m_pendingDNs.find( *it );
		if ( found == m_pendingDNs.end() )
		{
			m_client->debug( TQString( "UserDetailsManager::requestDetails - including %1" ).tqarg( (*it) ) );
			requestList.append( *it );
			m_pendingDNs.append( *it );
		}
	}
	if ( !requestList.empty() )
	{
		GetDetailsTask * gdt = new GetDetailsTask( m_client->rootTask() );
		gdt->userDNs( requestList );
		connect( gdt, TQT_SIGNAL( gotContactUserDetails( const GroupWise::ContactDetails & ) ), 
			TQT_SLOT( slotReceiveContactDetails( const GroupWise::ContactDetails & ) ) );
		// TODO: connect to gdt's finished() signal, check for failures, expand gdt to maintain a list of not found DNs?
		gdt->go( true );
	}
	else
	{
		m_client->debug( "UserDetailsManager::requestDetails - all requested contacts are already available or pending" );
	}
}

void UserDetailsManager::requestDetails( const TQString & dn, bool onlyUnknown )
{
	m_client->debug( TQString( "UserDetailsManager::requestDetails for %1" ).tqarg( dn ) );
	TQStringList list;
	list.append( dn );
	requestDetails( list, onlyUnknown );
}

void UserDetailsManager::slotReceiveContactDetails( const GroupWise::ContactDetails & details )
{
	m_client->debug( "UserDetailsManager::slotReceiveContactDetails()" );
	m_pendingDNs.remove( details.dn );
	/*client()->userDetailsManager()->*/
	addDetails( details );
	//emit temporaryContact( details );
	emit gotContactDetails( details );
}

#include "userdetailsmanager.moc"