2 telepathyaddpendingcontactjob.cpp - Telepathy Add Pending Contact Job
4 Copyright (c) 2006 by Michaƫl Larouche <larouche@kde.org>
6 Kopete (c) 2002-2006 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 *************************************************************************
17 #include "telepathyaddpendingcontactjob.h"
20 #include <QtCore/QPointer>
26 #include <kopeteaddedinfoevent.h>
27 #include <kopetemetacontact.h>
28 #include <kopetecontactlist.h>
31 #include <QtTapioca/Contact>
34 #include "telepathyprotocol.h"
35 #include "telepathyaccount.h"
36 #include "telepathycontact.h"
38 using namespace Kopete::UI
;
40 class TelepathyAddPendingContactJob::Private
44 : authorizationOnly(false)
47 QPointer
<QtTapioca::Contact
> pendingContact
;
48 QPointer
<TelepathyAccount
> account
;
49 bool authorizationOnly
;
52 TelepathyAddPendingContactJob::TelepathyAddPendingContactJob(TelepathyAccount
*parent
)
53 : KJob(parent
), d(new Private
)
58 TelepathyAddPendingContactJob::~TelepathyAddPendingContactJob()
63 void TelepathyAddPendingContactJob::setPendingContact(QtTapioca::Contact
*contact
)
65 d
->pendingContact
= contact
;
68 void TelepathyAddPendingContactJob::setAuthorizeOnly(bool value
)
70 d
->authorizationOnly
= value
;
73 void TelepathyAddPendingContactJob::start()
75 kDebug(TELEPATHY_DEBUG_AREA
) ;
77 Q_ASSERT( !d
->pendingContact
.isNull() );
79 Kopete::AddedInfoEvent::ShowActionOptions actions
= Kopete::AddedInfoEvent::AuthorizeAction
;
80 if( !d
->authorizationOnly
)
82 actions
|= Kopete::AddedInfoEvent::AddAction
;
85 Kopete::AddedInfoEvent
* event
= new Kopete::AddedInfoEvent( d
->pendingContact
->uri(), d
->account
);
86 QObject::connect( event
, SIGNAL(actionActivated(uint
)),
87 this, SLOT(slotAddedInfoEventActionActivated(uint
)) );
88 QObject::connect( event
, SIGNAL(eventClosed(Kopete::InfoEvent
*)),
89 this, SLOT(slotAddedInfoEventClosed()) );
91 event
->showActions( actions
);
92 event
->setContactNickname( d
->pendingContact
->alias() );
96 void TelepathyAddPendingContactJob::slotAddedInfoEventActionActivated( uint actionId
)
98 const Kopete::AddedInfoEvent
*event
= dynamic_cast<const Kopete::AddedInfoEvent
*>(sender());
101 setError( KJob::UserDefinedError
);
105 if ( actionId
== Kopete::AddedInfoEvent::AddContactAction
)
107 // Get the new metacontact
108 Kopete::MetaContact
*newMetaContact
= event
->addContact();
110 // Set internal contact pointer to new contact
111 QString contactUri
= d
->pendingContact
->uri();
112 TelepathyContact
*newContact
= static_cast<TelepathyContact
*>( d
->account
->contacts()[contactUri
] );
115 newContact
->setInternalContact( d
->pendingContact
);
116 // Subscribe to contact presence.
117 d
->pendingContact
->subscribe(true);
119 // Add to contact list
120 Kopete::ContactList::self()->addMetaContact( newMetaContact
);
124 kDebug(TELEPATHY_DEBUG_AREA
) << "Could not find new Telepathy contact " << contactUri
;
125 setError( KJob::UserDefinedError
);
128 else if ( actionId
== Kopete::AddedInfoEvent::AuthorizeAction
)
130 // Authorize new contact
131 d
->pendingContact
->authorize(true);
135 void TelepathyAddPendingContactJob::slotAddedInfoEventClosed()
140 #include "telepathyaddpendingcontactjob.moc"