Port things from MSN to WLM plugin:
[kdenetwork.git] / kopete / protocols / groupwise / libgroupwise / userdetailsmanager.cpp
bloba1b4f306eb17d4c2a32d58dd582a0b38c426bc88
1 /*
2 userdetailsmanager.cpp - Storage of all user details seen during this session
4 Copyright (c) 2004 SUSE Linux AG http://www.suse.com
6 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
9 * *
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU Lesser General Public *
12 * License as published by the Free Software Foundation; either *
13 * version 2 of the License, or (at your option) any later version. *
14 * *
15 *************************************************************************
18 #include "client.h"
19 #include "tasks/getdetailstask.h"
21 #include "userdetailsmanager.h"
23 UserDetailsManager::UserDetailsManager( Client * parent)
24 : QObject(parent), m_client( parent )
28 UserDetailsManager::~UserDetailsManager()
32 void UserDetailsManager::dump( const QStringList & list )
34 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
36 m_client->debug( QString( " - %1" ).arg (*it) );
40 bool UserDetailsManager::known( const QString & dn )
42 if ( dn == m_client->userDN() )
43 return true;
44 // we always know the local user's details, so don't look them up
45 return ( m_detailsMap.keys().contains( dn ) );
48 ContactDetails UserDetailsManager::details( const QString & dn )
50 // qDebug() << "UserDetailsManager::details() requested for " << dn.toLatin1();
51 return m_detailsMap[ dn ];
54 QStringList UserDetailsManager::knownDNs()
56 return m_detailsMap.keys();
59 void UserDetailsManager::addDetails( const ContactDetails & details )
61 // qDebug() << "UserDetailsManager::addDetails, got " << details.dn;
62 m_detailsMap.insert( details.dn, details );
63 /* QStringList keys = m_detailsMap.keys();
64 dump( keys );
65 qDebug( "UserDetailsManager::addContact, pending: " );
66 dump( m_pendingDNs );*/
69 void UserDetailsManager::removeContact( const QString & dn )
71 m_detailsMap.remove( dn );
74 void UserDetailsManager::requestDetails( const QStringList & dnList, bool onlyUnknown )
76 // build a list of DNs that are not already subject to a pending request
77 QStringList requestList;
78 QStringListIterator it( dnList );
79 while ( it.hasNext() )
81 QString dn = it.next();
82 // don't request our own details
83 if ( dn == m_client->userDN() )
84 break;
85 // don't request details we already have unless the caller specified this
86 if ( onlyUnknown && known( dn ) )
87 break;
88 if ( !m_pendingDNs.contains( dn ) )
90 m_client->debug( QString( "UserDetailsManager::requestDetails - including %1" ).arg( dn ) );
91 requestList.append( dn);
92 m_pendingDNs.append( dn );
95 if ( !requestList.empty() )
97 GetDetailsTask * gdt = new GetDetailsTask( m_client->rootTask() );
98 gdt->userDNs( requestList );
99 connect( gdt, SIGNAL( gotContactUserDetails( const GroupWise::ContactDetails & ) ),
100 SLOT( slotReceiveContactDetails( const GroupWise::ContactDetails & ) ) );
101 // TODO: connect to gdt's finished() signal, check for failures, expand gdt to maintain a list of not found DNs?
102 gdt->go( true );
104 else
106 m_client->debug( "UserDetailsManager::requestDetails - all requested contacts are already available or pending" );
110 void UserDetailsManager::requestDetails( const QString & dn, bool onlyUnknown )
112 m_client->debug( QString( "UserDetailsManager::requestDetails for %1" ).arg( dn ) );
113 QStringList list;
114 list.append( dn );
115 requestDetails( list, onlyUnknown );
118 void UserDetailsManager::slotReceiveContactDetails( const GroupWise::ContactDetails & details )
120 m_client->debug( "UserDetailsManager::slotReceiveContactDetails()" );
121 m_pendingDNs.removeAll( details.dn );
122 /*client()->userDetailsManager()->*/
123 addDetails( details );
124 kDebug()
125 << " Auth attribute: " << details.authAttribute
126 << " , Away message: " << details.awayMessage
127 << " , CN" << details.cn
128 << " , DN" << details.dn
129 << " , fullName" << details.fullName
130 << " , surname" << details.surname
131 << " , givenname" << details.givenName
132 << " , status" << details.status
133 << endl;
134 //emit temporaryContact( details );
135 emit gotContactDetails( details );
138 #include "userdetailsmanager.moc"