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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
/*
gwcontact.cpp - Kopete GroupWise Protocol
Copyright (c) 2006 Novell, Inc http://www.opensuse.org
Copyright (c) 2004 SUSE Linux AG http://www.suse.com
Based on Testbed
Copyright (c) 2003 by Will Stephenson <will@stevello.free-online.co.uk>
Blocking status taken from MSN
Copyright (c) 2003 by Will Stephenson <will@stevello.free-online.co.uk>
Copyright (c) 2002 by Duncan Mac-Vicar Prett <duncan@kde.org>
Copyright (c) 2002 by Ryan Cumming <bodnar42@phalynx.dhs.org>
Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
Copyright (c) 2002-2004 by Olivier Goffart <ogoffart@kde.org>
Kopete (c) 2002-2007 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 General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
*************************************************************************
*/
#include "gwcontact.h"
#include <qmap.h>
#include <kaction.h>
#include <KActionCollection>
#include <kdebug.h>
#include <kicon.h>
#include <klocale.h>
#include <kopetemetacontact.h>
#include <kopeteuiglobal.h>
#include <kopeteprotocol.h>
#include "client.h"
#include "gwaccount.h"
#include "gwprotocol.h"
#include "privacymanager.h"
#include "userdetailsmanager.h"
#include "tasks/updatecontacttask.h"
#include "ui/gwcontactproperties.h"
using namespace GroupWise;
GroupWiseContact::GroupWiseContact( Kopete::Account* account, const QString &dn,
Kopete::MetaContact *parent,
const int objectId, const int parentId, const int sequence )
: Kopete::Contact( account, GroupWiseProtocol::dnToDotted( dn ), parent ), m_objectId( objectId ), m_parentId( parentId ),
m_sequence( sequence ), m_actionBlock( 0 ), m_archiving( false ), m_deleting( false ), m_messageReceivedOffline( false )
{
if ( dn.indexOf( '=' ) != -1 )
{
m_dn = dn;
}
connect( static_cast< GroupWiseAccount *>( account ), SIGNAL(privacyChanged(QString,bool)),
SLOT(receivePrivacyChanged(QString,bool)) );
setOnlineStatus( ( parent && parent->isTemporary() ) ? protocol()->groupwiseUnknown : protocol()->groupwiseOffline );
}
GroupWiseContact::~GroupWiseContact()
{
}
QString GroupWiseContact::dn() const
{
return m_dn;
}
void GroupWiseContact::updateDetails( const ContactDetails & details )
{
kDebug() ;
if ( !details.cn.isNull() )
setProperty( protocol()->propCN, QVariant(details.cn) );
if ( !details.dn.isNull() )
m_dn = details.dn;
if ( !details.givenName.isNull() )
setProperty( protocol()->propGivenName, QVariant(details.givenName) );
if ( !details.surname.isNull() )
setProperty( protocol()->propLastName, QVariant(details.surname) );
if ( !details.fullName.isNull() )
setProperty( protocol()->propFullName, QVariant(details.fullName) );
m_archiving = details.archive;
if ( !details.awayMessage.isNull() )
setStatusMessage( details.awayMessage );
m_serverProperties = details.properties;
// work phone number
if ( m_serverProperties.contains( "telephoneNumber" ) )
setProperty( protocol()->propPhoneWork, QVariant(m_serverProperties.value( "telephoneNumber" )) );
// mobile phone number
if ( m_serverProperties.contains( "mobile" ) )
setProperty( protocol()->propPhoneMobile, QVariant(m_serverProperties.value( "mobile" )) );
// email
if ( m_serverProperties.contains( "Internet EMail Address" ) )
setProperty( protocol()->propEmail, QVariant(m_serverProperties.value( "Internet EMail Address" )) );
if ( details.status != GroupWise::Invalid )
{
Kopete::OnlineStatus status = protocol()->gwStatusToKOS( details.status );
setOnlineStatus( status );
}
}
GroupWiseProtocol *GroupWiseContact::protocol()
{
return static_cast<GroupWiseProtocol *>( Kopete::Contact::protocol() );
}
GroupWiseAccount *GroupWiseContact::account()
{
return static_cast<GroupWiseAccount *>( Kopete::Contact::account() );
}
bool GroupWiseContact::isReachable()
{
// When we are invisible we can't start a chat with others, but we don't make isReachable return false, because then we
// don't get any notification when we click on someone in the contact list. Instead we warn the user when they try to send a message,
// in GWChatSession
// (This is a GroupWise rule, not a problem in Kopete)
if ( account()->isConnected() && ( isOnline() || messageReceivedOffline() ) /* && account()->myself()->onlineStatus() != protocol()->groupwiseAppearOffline */)
return true;
if ( !account()->isConnected()/* || account()->myself()->onlineStatus() == protocol()->groupwiseAppearOffline*/ )
return false;
// fallback, something went wrong
return false;
}
void GroupWiseContact::serialize( QMap< QString, QString > &serializedData, QMap< QString, QString > & /* addressBookData */ )
{
serializedData[ "DN" ] = m_dn;
}
Kopete::ChatSession * GroupWiseContact::manager( Kopete::Contact::CanCreateFlags canCreate )
{
//kDebug() << "called, canCreate: " << canCreate;
Kopete::ContactPtrList chatMembers;
chatMembers.append( this );
return account()->chatSession( chatMembers, QString("")/*FIXME Check this is right*/, canCreate );
}
QList<KAction*> *GroupWiseContact::customContextMenuActions()
{
QList<KAction *> * actions = new QList<KAction *>;
// Block/unblock contact
QString label = account()->isContactBlocked( m_dn ) ? i18n( "Unblock User" ) : i18n( "Block User" );
if( !m_actionBlock )
{
m_actionBlock = new KAction( KIcon( "msn_blocked" ), label, 0 );
QObject::connect( m_actionBlock, SIGNAL(triggered(bool)), SLOT(slotBlock()) );
}
else
m_actionBlock->setText( label );
m_actionBlock->setEnabled( account()->isConnected() );
actions->append( m_actionBlock );
// temporary action collection, used to apply Kiosk policy to the actions
KActionCollection tempCollection((QObject*)0);
tempCollection.addAction(QLatin1String("contactBlock"), m_actionBlock);
return actions;
}
void GroupWiseContact::slotUserInfo()
{
GroupWiseContactProperties *p = new GroupWiseContactProperties( this, Kopete::UI::Global::mainWidget() );
p->setObjectName( "gwcontactproperties" );
}
QMap< QString, QVariant > GroupWiseContact::serverProperties()
{
return m_serverProperties;
}
void GroupWiseContact::sendMessage( Kopete::Message &message )
{
kDebug() ;
manager()->appendMessage( message );
// tell the manager it was sent successfully
manager()->messageSucceeded();
}
void GroupWiseContact::deleteContact()
{
account()->deleteContact( this );
}
void GroupWiseContact::sync( unsigned int)
{
account()->syncContact( this );
}
void GroupWiseContact::slotBlock()
{
kDebug() ;
if ( account()->isConnected() )
{
if ( account()->isContactBlocked( m_dn ) )
account()->client()->privacyManager()->setAllow( m_dn );
else
account()->client()->privacyManager()->setDeny( m_dn );
}
}
void GroupWiseContact::receivePrivacyChanged( const QString & dn, bool allow )
{
Q_UNUSED( allow );
if ( dn == m_dn ) // set the online status back to itself. this will set the blocking state
setOnlineStatus( this->onlineStatus() );
}
void GroupWiseContact::setOnlineStatus( const Kopete::OnlineStatus& status )
{
setMessageReceivedOffline( false );
if ( status == protocol()->groupwiseAwayIdle && status != onlineStatus() )
setIdleTime( 1 );
else if ( onlineStatus() == protocol()->groupwiseAwayIdle && status != onlineStatus() )
setIdleTime( 0 );
if ( account()->isContactBlocked( m_dn ) && status.internalStatus() < 15 )
{
Kopete::Contact::setOnlineStatus(Kopete::OnlineStatus(status.status(), (status.weight()==0) ? 0 : (status.weight() -1),
protocol() , status.internalStatus()+15 , QStringList("msn_blocked"),
i18n("%1|Blocked", status.description() ) ) );
}
else
{
if(status.internalStatus() >= 15)
{ //the user is not blocked, but the status is blocked
switch(status.internalStatus()-15)
{
case 0:
Kopete::Contact::setOnlineStatus( GroupWiseProtocol::protocol()->groupwiseUnknown );
break;
case 1:
Kopete::Contact::setOnlineStatus( GroupWiseProtocol::protocol()->groupwiseOffline );
break;
case 2:
Kopete::Contact::setOnlineStatus( GroupWiseProtocol::protocol()->groupwiseAvailable );
break;
case 3:
Kopete::Contact::setOnlineStatus( GroupWiseProtocol::protocol()->groupwiseBusy );
break;
case 4:
Kopete::Contact::setOnlineStatus( GroupWiseProtocol::protocol()->groupwiseAway );
break;
case 5:
Kopete::Contact::setOnlineStatus( GroupWiseProtocol::protocol()->groupwiseAwayIdle );
break;
default:
Kopete::Contact::setOnlineStatus( GroupWiseProtocol::protocol()->groupwiseUnknown );
break;
}
}
else
Kopete::Contact::setOnlineStatus(status);
}
}
bool GroupWiseContact::archiving() const
{
return m_archiving;
}
bool GroupWiseContact::deleting() const
{
return m_deleting;
}
void GroupWiseContact::setDeleting( bool deleting )
{
m_deleting = deleting;
}
void GroupWiseContact::renamedOnServer()
{
UpdateContactTask * uct = ( UpdateContactTask * )sender();
if ( uct->success() )
{
setNickName( uct->displayName() );
}
else
kDebug() << "rename failed, return code: " << uct->statusCode();
}
void GroupWiseContact::setMessageReceivedOffline( bool on )
{
m_messageReceivedOffline = on;
}
bool GroupWiseContact::messageReceivedOffline() const
{
return m_messageReceivedOffline;
}
#include "gwcontact.moc"
// vim: set noet ts=4 sts=4 sw=4:
|