2 Kopete Groupwise Protocol
3 privacymanager.cpp - stores the user's privacy information and maintains it on the server
5 Copyright (c) 2004 SUSE Linux AG http://www.suse.com
7 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of the GNU Lesser General Public *
13 * License as published by the Free Software Foundation; either *
14 * version 2 of the License, or (at your option) any later version. *
16 *************************************************************************
20 #include "tasks/privacyitemtask.h"
21 #include "userdetailsmanager.h"
23 #include "privacymanager.h"
25 PrivacyManager::PrivacyManager( Client
* client
)
26 : QObject(client
), m_client( client
)
30 PrivacyManager::~PrivacyManager()
34 bool PrivacyManager::defaultAllow()
36 return !m_defaultDeny
;
39 bool PrivacyManager::defaultDeny()
44 QStringList
PrivacyManager::allowList()
49 QStringList
PrivacyManager::denyList()
54 bool PrivacyManager::isPrivacyLocked()
59 bool PrivacyManager::isBlocked( const QString
& dn
)
62 return !m_allowList
.contains( dn
);
64 return m_denyList
.contains( dn
);
67 void PrivacyManager::setAllow( const QString
& dn
)
71 if ( !m_allowList
.contains( dn
) )
76 if ( m_denyList
.contains( dn
) )
81 void PrivacyManager::setDeny( const QString
& dn
)
85 if ( m_allowList
.contains( dn
) )
90 if ( !m_denyList
.contains( dn
) )
96 void PrivacyManager::setDefaultAllow( bool allow
)
98 PrivacyItemTask
* pit
= new PrivacyItemTask( m_client
->rootTask() );
99 pit
->defaultPolicy( !allow
);
100 connect( pit
, SIGNAL( finished() ), SLOT( slotDefaultPolicyChanged() ) );
104 void PrivacyManager::setDefaultDeny( bool deny
)
106 PrivacyItemTask
* pit
= new PrivacyItemTask( m_client
->rootTask() );
107 pit
->defaultPolicy( deny
);
108 connect( pit
, SIGNAL( finished() ), SLOT( slotDefaultPolicyChanged() ) );
112 void PrivacyManager::addAllow( const QString
& dn
)
114 // start off a CreatePrivacyItemTask
115 PrivacyItemTask
* pit
= new PrivacyItemTask( m_client
->rootTask() );
117 connect( pit
, SIGNAL( finished() ), SLOT( slotAllowAdded() ) );
121 void PrivacyManager::addDeny( const QString
& dn
)
123 // start off a CreatePrivacyItemTask
124 PrivacyItemTask
* pit
= new PrivacyItemTask( m_client
->rootTask() );
126 connect( pit
, SIGNAL( finished() ), SLOT( slotDenyAdded() ) );
130 void PrivacyManager::removeAllow( const QString
& dn
)
132 PrivacyItemTask
* pit
= new PrivacyItemTask( m_client
->rootTask() );
133 pit
->removeAllow( dn
);
134 connect( pit
, SIGNAL( finished() ), SLOT( slotAllowRemoved() ) );
138 void PrivacyManager::removeDeny( const QString
& dn
)
140 // start off a CreatePrivacyItemTask
141 PrivacyItemTask
* pit
= new PrivacyItemTask( m_client
->rootTask() );
142 pit
->removeDeny( dn
);
143 connect( pit
, SIGNAL( finished() ), SLOT( slotDenyRemoved() ) );
147 void PrivacyManager::setPrivacy( bool defaultIsDeny
, const QStringList
& allowList
, const QStringList
& denyList
)
149 if ( defaultIsDeny
!= m_defaultDeny
)
150 setDefaultDeny( defaultIsDeny
);
151 // find the DNs no longer in the allow list
152 QStringList allowsToRemove
= difference( m_allowList
, allowList
);
153 // find the DNs no longer in the deny list
154 QStringList denysToRemove
= difference( m_denyList
, denyList
);
155 // find the DNs new in the allow list
156 QStringList allowsToAdd
= difference( allowList
, m_allowList
);
157 // find the DNs new in the deny list
158 QStringList denysToAdd
= difference( denyList
, m_denyList
);
160 QStringList::ConstIterator end
= allowsToRemove
.constEnd();
161 for ( QStringList::ConstIterator it
= allowsToRemove
.constBegin(); it
!= end
; ++it
)
163 end
= denysToRemove
.constEnd();
164 for ( QStringList::ConstIterator it
= denysToRemove
.constBegin(); it
!= end
; ++it
)
166 end
= allowsToAdd
.constEnd();
167 for ( QStringList::ConstIterator it
= allowsToAdd
.constBegin(); it
!= end
; ++it
)
169 end
= denysToAdd
.constEnd();
170 for ( QStringList::ConstIterator it
= denysToAdd
.constBegin(); it
!= end
; ++it
)
174 void PrivacyManager::slotGotPrivacySettings( bool locked
, bool defaultDeny
, const QStringList
& allowList
, const QStringList
& denyList
)
177 m_defaultDeny
= defaultDeny
;
178 m_allowList
= allowList
;
179 m_denyList
= denyList
;
182 void PrivacyManager::getDetailsForPrivacyLists()
184 if ( !m_allowList
.isEmpty() )
186 m_client
->userDetailsManager()->requestDetails( m_allowList
);
188 if ( !m_denyList
.isEmpty() )
189 m_client
->userDetailsManager()->requestDetails( m_denyList
);
192 void PrivacyManager::slotDefaultPolicyChanged()
194 PrivacyItemTask
* pit
= ( PrivacyItemTask
* )sender();
195 if ( pit
->success() )
196 m_defaultDeny
= pit
->defaultDeny();
199 void PrivacyManager::slotAllowAdded()
201 PrivacyItemTask
* pit
= ( PrivacyItemTask
* )sender();
202 if ( pit
->success() )
204 m_allowList
.append( pit
->dn() );
205 emit
privacyChanged( pit
->dn(), isBlocked( pit
->dn() ) );
209 void PrivacyManager::slotDenyAdded()
211 PrivacyItemTask
* pit
= ( PrivacyItemTask
* )sender();
212 if ( pit
->success() )
214 m_denyList
.append( pit
->dn() );
215 emit
privacyChanged( pit
->dn(), isBlocked( pit
->dn() ) );
219 void PrivacyManager::slotAllowRemoved()
221 PrivacyItemTask
* pit
= ( PrivacyItemTask
* )sender();
222 if ( pit
->success() )
224 m_allowList
.removeAll( pit
->dn() );
225 emit
privacyChanged( pit
->dn(), isBlocked( pit
->dn() ) );
229 void PrivacyManager::slotDenyRemoved()
231 PrivacyItemTask
* pit
= ( PrivacyItemTask
* )sender();
232 if ( pit
->success() )
234 m_denyList
.removeAll( pit
->dn() );
235 emit
privacyChanged( pit
->dn(), isBlocked( pit
->dn() ) );
239 QStringList
PrivacyManager::difference( const QStringList
& lhs
, const QStringList
& rhs
)
242 const QStringList::ConstIterator lhsEnd
= lhs
.constEnd();
243 const QStringList::ConstIterator rhsEnd
= rhs
.constEnd();
244 for ( QStringList::ConstIterator lhsIt
= lhs
.constBegin(); lhsIt
!= lhsEnd
; ++lhsIt
)
246 if ( !rhs
.contains( *lhsIt
) )
247 diff
.append( *lhsIt
);
251 #include "privacymanager.moc"