2 bonjourcontact.cpp - Kopete Bonjour Protocol
4 Copyright (c) 2007 by Tejas Dinkar <tejas@gja.in>
5 Copyright (c) 2003 by Will Stephenson <will@stevello.free-online.co.uk>
6 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
8 *************************************************************************
10 * This library is free software; you can redistribute it and/or *
11 * modify it under the terms of the GNU 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. *
15 *************************************************************************
18 #include "bonjourcontact.h"
21 #include <QHostAddress>
27 #include <kopeteaccount.h>
28 #include <kopetechatsessionmanager.h>
29 #include <kopetemetacontact.h>
31 #include "bonjouraccount.h"
32 #include "bonjourprotocol.h"
34 // FIXME: Here, we hardcode the icon (bonjour_protocol) into the constructor.
35 // This shouldn't be necessary
36 BonjourContact::BonjourContact( Kopete::Account
* _account
, const QString
&uniqueName
,
37 const QString
&displayName
, Kopete::MetaContact
*parent
)
38 : Kopete::Contact( _account
, uniqueName
, parent
, QString("bonjour_protocol") )
40 kDebug()<< " uniqueName: " << uniqueName
<< ", displayName: " << displayName
;
42 // FIXME: ? setDisplayName( displayName );
45 setOnlineStatus( BonjourProtocol::protocol()->bonjourOffline
);
51 BonjourContact::~BonjourContact()
53 kDebug()<<"Deleting Contact!";
60 bool BonjourContact::isReachable()
65 void BonjourContact::serialize( QMap
< QString
, QString
> &serializedData
, QMap
< QString
, QString
> & /* addressBookData */ )
70 Kopete::ChatSession
* BonjourContact::manager( CanCreateFlags canCreateFlags
)
77 else if ( canCreateFlags
== CanCreate
)
79 QList
<Kopete::Contact
*> contacts
;
80 contacts
.append(this);
81 Kopete::ChatSession::Form form
= ( Kopete::ChatSession::Small
);
82 m_msgManager
= Kopete::ChatSessionManager::self()->create(account()->myself(), contacts
, protocol(), form
);
83 connect(m_msgManager
, SIGNAL(messageSent(Kopete::Message
&, Kopete::ChatSession
*)),
84 this, SLOT( sendMessage( Kopete::Message
& ) ) );
85 connect(m_msgManager
, SIGNAL(destroyed()), this, SLOT(slotChatSessionDestroyed()));
95 QList
<KAction
*> *BonjourContact::customContextMenuActions() //OBSOLETE
97 //FIXME!!! this function is obsolete, we should use XMLGUI instead
98 /*m_actionCollection = new KActionCollection( this, "userColl" );
99 m_actionPrefs = new KAction(i18n( "&Contact Settings" ), 0, this,
100 SLOT( showContactSettings( )), m_actionCollection, "contactSettings" );
102 return m_actionCollection;*/
106 void BonjourContact::showContactSettings()
108 //BonjourContactSettings* p = new BonjourContactSettings( this );
112 void BonjourContact::sendMessage( Kopete::Message
&message
)
116 // This is Blocking, we may lose upto 5 seconds here
118 QString localName
= account()->property("username").toString();
119 setConnection(new BonjourContactConnection(remoteAddress
, remotePort
, localName
, username
));
122 // Blocking Again. Upto another 3 seconds
123 connection
->sendMessage(message
);
125 // give it back to the manager to display
126 manager()->appendMessage( message
);
127 // tell the manager it was sent successfully
128 manager()->messageSucceeded();
131 void BonjourContact::receivedMessage(Kopete::Message message
)
133 Kopete::ChatSession
*session
= manager(CanCreate
);
134 session
->appendMessage(message
);
137 void BonjourContact::slotChatSessionDestroyed()
139 //FIXME: the chat window was closed? Take appropriate steps.
142 connection
->sayGoodBye();
150 void BonjourContact::setremoteHostName(const QString
&nremoteHostName
)
152 remoteHostName
= nremoteHostName
;
155 const QString
BonjourContact::getremoteHostName() const
157 return remoteHostName
;
160 void BonjourContact::setremoteAddress(const QHostAddress
&nremoteAddress
)
162 remoteAddress
= nremoteAddress
;
165 const QHostAddress
BonjourContact::getremoteAddress() const
167 return remoteAddress
;
170 void BonjourContact::setremotePort(const short int &nremotePort
)
172 remotePort
= nremotePort
;
175 short int BonjourContact::getremotePort() const
180 void BonjourContact::setusername(const QString
&n_username
)
182 username
= n_username
;
185 const QString
BonjourContact::getusername() const
190 void BonjourContact::settextdata(const QMap
<QString
, QByteArray
> &n_textdata
)
192 textdata
= n_textdata
;
195 const QMap
<QString
, QByteArray
> BonjourContact::gettextdata() const
200 bool BonjourContact::isRemoteAddress(const QHostAddress
&host
) const
202 if (remoteAddress
== host
)
208 void BonjourContact::setConnection(BonjourContactConnection
*c
)
215 // We set the parent of the socket to us, so that we ensure that only we
216 // can delete the connection (and the socket hence)
217 connection
->setParent(this);
219 connect(connection
, SIGNAL(disconnected(BonjourContactConnection
*)),
220 this, SLOT(connectionDisconnected(BonjourContactConnection
*)));
222 connect(connection
, SIGNAL(messageReceived(Kopete::Message
)),
223 this, SLOT(receivedMessage(Kopete::Message
)));
226 void BonjourContact::connectionDisconnected(BonjourContactConnection
*c
)
228 if (c
== connection
) {
234 #include "bonjourcontact.moc"
236 // vim: set noet ts=4 sts=4 sw=4: